CodeGenFunction.h revision 2f77b3d57031ded0de2b7b977fb63b4660f82624
1bd012ff1fa088181646a784f385b28867372d434Daniel Dunbar//===-- CodeGenFunction.h - Per-Function state for LLVM CodeGen -*- C++ -*-===// 25f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 35f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// The LLVM Compiler Infrastructure 45f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 50bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// This file is distributed under the University of Illinois Open Source 60bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// License. See LICENSE.TXT for details. 75f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 85f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 95f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 100dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump// This is the internal per-function state used for llvm translation. 115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 14ef52a2fb2ace36c92f88c6e125bd7defa17dafa5Chris Lattner#ifndef CLANG_CODEGEN_CODEGENFUNCTION_H 15ef52a2fb2ace36c92f88c6e125bd7defa17dafa5Chris Lattner#define CLANG_CODEGEN_CODEGENFUNCTION_H 165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 17391d77a26382dddf25da73e29fc1fa5aaaea4c6fChris Lattner#include "clang/AST/Type.h" 18e3a09e6ad09f8d1387ecaa008aaf85527909da0aArgyrios Kyrtzidis#include "clang/AST/ExprCXX.h" 195549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek#include "clang/AST/ExprObjC.h" 20199c3d6cd16aebbb9c7f0d42af9d922c9628bf70Ken Dyck#include "clang/AST/CharUnits.h" 21f85e193739c953358c865005855253af4f68a497John McCall#include "clang/Frontend/CodeGenOptions.h" 2214110477887e3dc168ffc6c191e72d705051f99ePeter Collingbourne#include "clang/Basic/ABI.h" 23481769b5dc102b0256b35581e787909ad5edfab5Chris Lattner#include "clang/Basic/TargetInfo.h" 244c7d9f1507d0f102bd4133bba63348636facd469Jay Foad#include "llvm/ADT/ArrayRef.h" 25481769b5dc102b0256b35581e787909ad5edfab5Chris Lattner#include "llvm/ADT/DenseMap.h" 26481769b5dc102b0256b35581e787909ad5edfab5Chris Lattner#include "llvm/ADT/SmallVector.h" 27481769b5dc102b0256b35581e787909ad5edfab5Chris Lattner#include "llvm/Support/ValueHandle.h" 28c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher#include "llvm/Support/Debug.h" 2969243825cb5c91ec7207256aa57ae327cfaf8cb2Owen Anderson#include "CodeGenModule.h" 3045d196b8387dcefc4df26cda114fa34c6528e928Daniel Dunbar#include "CGBuilder.h" 31c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher#include "CGDebugInfo.h" 328f2926b73ed635afecd020da787af6a837601a2bDaniel Dunbar#include "CGValue.h" 338f2926b73ed635afecd020da787af6a837601a2bDaniel Dunbar 345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace llvm { 35c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar class BasicBlock; 36f21efe9088a0b3eda1209d1706529f6cb2073092Benjamin Kramer class LLVMContext; 37dd5c98f709837e5dd3da08d44d1ce407975df2cfDavid Chisnall class MDNode; 385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class Module; 39898d508d4c9e9d45914952473e39196b20830a9fDaniel Dunbar class SwitchInst; 40259e9ccf882d11491ad149aec5e6d7a061c9f938Daniel Dunbar class Twine; 41ed3849b456d64d124bddc7ac044f3ce590bd9d69Daniel Dunbar class Value; 42f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall class CallSite; 435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang { 468d308384a220c7dc81755c47cdcbdd87dac25d5bDevang Patel class APValue; 475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class ASTContext; 481a343ebbf413e8eae6b2737b2b2d79cbf5765571John McCall class BlockDecl; 497267c1693abe7875b0c57268be05005ae013c6c9Anders Carlsson class CXXDestructorDecl; 50ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith class CXXForRangeStmt; 516815e941998659a55c20c147861b0f437928c3d8Anders Carlsson class CXXTryStmt; 525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class Decl; 53ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner class LabelDecl; 54c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar class EnumConstantDecl; 555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class FunctionDecl; 5672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor class FunctionProtoType; 57c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar class LabelStmt; 58679a502d462ef819e6175b58e255ca3f3391e7cfFariborz Jahanian class ObjCContainerDecl; 5929e0bccf2bcce22b877f8b2ed173f564c116b97eDaniel Dunbar class ObjCInterfaceDecl; 6029e0bccf2bcce22b877f8b2ed173f564c116b97eDaniel Dunbar class ObjCIvarDecl; 61391d77a26382dddf25da73e29fc1fa5aaaea4c6fChris Lattner class ObjCMethodDecl; 62fef30b55230064d334a669a065a1c9acdb87cdfeFariborz Jahanian class ObjCImplementationDecl; 63af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar class ObjCPropertyImplDecl; 645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class TargetInfo; 65492c4f998d848673d3d6c9e6416115df4036a71dJohn McCall class TargetCodeGenInfo; 66c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar class VarDecl; 6716f0049415ec596504891259e2a83e19871c0d52Chris Lattner class ObjCForCollectionStmt; 6816f0049415ec596504891259e2a83e19871c0d52Chris Lattner class ObjCAtTryStmt; 6916f0049415ec596504891259e2a83e19871c0d52Chris Lattner class ObjCAtThrowStmt; 7016f0049415ec596504891259e2a83e19871c0d52Chris Lattner class ObjCAtSynchronizedStmt; 71f85e193739c953358c865005855253af4f68a497John McCall class ObjCAutoreleasePoolStmt; 725549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek 735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace CodeGen { 74b84a06e68ffd71da22e3c75b6e4bbdba37816413Devang Patel class CodeGenTypes; 75bb36d331f439f49859efcfb4435c61762fbba6f9Daniel Dunbar class CGFunctionInfo; 760dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump class CGRecordLayout; 77ee5042903d53fa7b0fbc1902d0ea07d57c7775b1John McCall class CGBlockInfo; 784c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall class CGCXXABI; 79d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall class BlockFlags; 80d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall class BlockFieldFlags; 810dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 82f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall/// A branch fixup. These are required when emitting a goto to a 83f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall/// label which hasn't been emitted yet. The goto is optimistically 84f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall/// emitted as a branch to the basic block for the label, and (if it 85f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall/// occurs in a scope with non-trivial cleanups) a fixup is added to 86f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall/// the innermost cleanup. When a (normal) cleanup is popped, any 87f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall/// unresolved fixups in that scope are threaded through the cleanup. 88f1549f66a8216a78112286e3978cea2c29d6334cJohn McCallstruct BranchFixup { 89ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall /// The block containing the terminator which needs to be modified 90ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall /// into a switch if this fixup is resolved into the current scope. 91ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall /// If null, LatestBranch points directly to the destination. 92ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall llvm::BasicBlock *OptimisticBranchBlock; 93f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 94ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall /// The ultimate destination of the branch. 95f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// 96f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// This can be set to null to indicate that this fixup was 97f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// successfully resolved. 98f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall llvm::BasicBlock *Destination; 99f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 100ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall /// The destination index value. 101ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall unsigned DestinationIndex; 102ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall 103ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall /// The initial branch of the fixup. 104ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall llvm::BranchInst *InitialBranch; 105f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall}; 106f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 107804b807ea918184d6de63bd745e1ff75a9bfc679John McCalltemplate <class T> struct InvariantValue { 108150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall typedef T type; 109150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall typedef T saved_type; 110150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall static bool needsSaving(type value) { return false; } 111150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall static saved_type save(CodeGenFunction &CGF, type value) { return value; } 112150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall static type restore(CodeGenFunction &CGF, saved_type value) { return value; } 113150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall}; 114804b807ea918184d6de63bd745e1ff75a9bfc679John McCall 115804b807ea918184d6de63bd745e1ff75a9bfc679John McCall/// A metaprogramming class for ensuring that a value will dominate an 116804b807ea918184d6de63bd745e1ff75a9bfc679John McCall/// arbitrary position in a function. 117804b807ea918184d6de63bd745e1ff75a9bfc679John McCalltemplate <class T> struct DominatingValue : InvariantValue<T> {}; 118804b807ea918184d6de63bd745e1ff75a9bfc679John McCall 119804b807ea918184d6de63bd745e1ff75a9bfc679John McCalltemplate <class T, bool mightBeInstruction = 120804b807ea918184d6de63bd745e1ff75a9bfc679John McCall llvm::is_base_of<llvm::Value, T>::value && 121804b807ea918184d6de63bd745e1ff75a9bfc679John McCall !llvm::is_base_of<llvm::Constant, T>::value && 122804b807ea918184d6de63bd745e1ff75a9bfc679John McCall !llvm::is_base_of<llvm::BasicBlock, T>::value> 123804b807ea918184d6de63bd745e1ff75a9bfc679John McCallstruct DominatingPointer; 124804b807ea918184d6de63bd745e1ff75a9bfc679John McCalltemplate <class T> struct DominatingPointer<T,false> : InvariantValue<T*> {}; 125804b807ea918184d6de63bd745e1ff75a9bfc679John McCall// template <class T> struct DominatingPointer<T,true> at end of file 126804b807ea918184d6de63bd745e1ff75a9bfc679John McCall 127804b807ea918184d6de63bd745e1ff75a9bfc679John McCalltemplate <class T> struct DominatingValue<T*> : DominatingPointer<T> {}; 128150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall 129cd2d2b7814e0104ed41a8da159a06a8ca77b70d8John McCallenum CleanupKind { 130cd2d2b7814e0104ed41a8da159a06a8ca77b70d8John McCall EHCleanup = 0x1, 131cd2d2b7814e0104ed41a8da159a06a8ca77b70d8John McCall NormalCleanup = 0x2, 132cd2d2b7814e0104ed41a8da159a06a8ca77b70d8John McCall NormalAndEHCleanup = EHCleanup | NormalCleanup, 133cd2d2b7814e0104ed41a8da159a06a8ca77b70d8John McCall 134cd2d2b7814e0104ed41a8da159a06a8ca77b70d8John McCall InactiveCleanup = 0x4, 135cd2d2b7814e0104ed41a8da159a06a8ca77b70d8John McCall InactiveEHCleanup = EHCleanup | InactiveCleanup, 136cd2d2b7814e0104ed41a8da159a06a8ca77b70d8John McCall InactiveNormalCleanup = NormalCleanup | InactiveCleanup, 137cd2d2b7814e0104ed41a8da159a06a8ca77b70d8John McCall InactiveNormalAndEHCleanup = NormalAndEHCleanup | InactiveCleanup 138cd2d2b7814e0104ed41a8da159a06a8ca77b70d8John McCall}; 139da65ea86482bc116906edfb9ba1d7124f76cc867John McCall 140f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall/// A stack of scopes which respond to exceptions, including cleanups 141f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall/// and catch blocks. 142f1549f66a8216a78112286e3978cea2c29d6334cJohn McCallclass EHScopeStack { 143f1549f66a8216a78112286e3978cea2c29d6334cJohn McCallpublic: 144f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// A saved depth on the scope stack. This is necessary because 145f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// pushing scopes onto the stack invalidates iterators. 146f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall class stable_iterator { 147f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall friend class EHScopeStack; 148f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 149f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// Offset from StartOfData to EndOfBuffer. 150f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall ptrdiff_t Size; 151f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 152f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall stable_iterator(ptrdiff_t Size) : Size(Size) {} 153f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 154f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall public: 155f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall static stable_iterator invalid() { return stable_iterator(-1); } 156f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall stable_iterator() : Size(-1) {} 157f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 158f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall bool isValid() const { return Size >= 0; } 159f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 160838d796d020f6a8cd2b2d1e2a0a85c83bbf29543John McCall /// Returns true if this scope encloses I. 161838d796d020f6a8cd2b2d1e2a0a85c83bbf29543John McCall /// Returns false if I is invalid. 162838d796d020f6a8cd2b2d1e2a0a85c83bbf29543John McCall /// This scope must be valid. 163ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall bool encloses(stable_iterator I) const { return Size <= I.Size; } 164838d796d020f6a8cd2b2d1e2a0a85c83bbf29543John McCall 165838d796d020f6a8cd2b2d1e2a0a85c83bbf29543John McCall /// Returns true if this scope strictly encloses I: that is, 166838d796d020f6a8cd2b2d1e2a0a85c83bbf29543John McCall /// if it encloses I and is not I. 167838d796d020f6a8cd2b2d1e2a0a85c83bbf29543John McCall /// Returns false is I is invalid. 168838d796d020f6a8cd2b2d1e2a0a85c83bbf29543John McCall /// This scope must be valid. 169ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall bool strictlyEncloses(stable_iterator I) const { return Size < I.Size; } 1701bda662cb37d9fe24be4b3cf8ea0f4e550e1f889John McCall 171f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall friend bool operator==(stable_iterator A, stable_iterator B) { 172f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall return A.Size == B.Size; 173f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall } 174f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall friend bool operator!=(stable_iterator A, stable_iterator B) { 175f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall return A.Size != B.Size; 176f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall } 177f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall }; 178f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 1791f0fca54676cfa8616e7f3cd7a26788ab937e3cdJohn McCall /// Information for lazily generating a cleanup. Subclasses must be 1801f0fca54676cfa8616e7f3cd7a26788ab937e3cdJohn McCall /// POD-like: cleanups will not be destructed, and they will be 1811f0fca54676cfa8616e7f3cd7a26788ab937e3cdJohn McCall /// allocated on the cleanup stack and freely copied and moved 1821f0fca54676cfa8616e7f3cd7a26788ab937e3cdJohn McCall /// around. 183da65ea86482bc116906edfb9ba1d7124f76cc867John McCall /// 1841f0fca54676cfa8616e7f3cd7a26788ab937e3cdJohn McCall /// Cleanup implementations should generally be declared in an 185da65ea86482bc116906edfb9ba1d7124f76cc867John McCall /// anonymous namespace. 1861f0fca54676cfa8616e7f3cd7a26788ab937e3cdJohn McCall class Cleanup { 187c4a1a8450a3613ef256a71b9d8305b41f79eef50John McCall // Anchor the construction vtable. 188c4a1a8450a3613ef256a71b9d8305b41f79eef50John McCall virtual void anchor(); 189da65ea86482bc116906edfb9ba1d7124f76cc867John McCall public: 190ad346f4f678ab1c3222425641d851dc63e9dfa1aJohn McCall /// Generation flags. 191ad346f4f678ab1c3222425641d851dc63e9dfa1aJohn McCall class Flags { 192ad346f4f678ab1c3222425641d851dc63e9dfa1aJohn McCall enum { 193ad346f4f678ab1c3222425641d851dc63e9dfa1aJohn McCall F_IsForEH = 0x1, 194ad346f4f678ab1c3222425641d851dc63e9dfa1aJohn McCall F_IsNormalCleanupKind = 0x2, 195ad346f4f678ab1c3222425641d851dc63e9dfa1aJohn McCall F_IsEHCleanupKind = 0x4 196ad346f4f678ab1c3222425641d851dc63e9dfa1aJohn McCall }; 197ad346f4f678ab1c3222425641d851dc63e9dfa1aJohn McCall unsigned flags; 198ad346f4f678ab1c3222425641d851dc63e9dfa1aJohn McCall 199ad346f4f678ab1c3222425641d851dc63e9dfa1aJohn McCall public: 200ad346f4f678ab1c3222425641d851dc63e9dfa1aJohn McCall Flags() : flags(0) {} 201ad346f4f678ab1c3222425641d851dc63e9dfa1aJohn McCall 202ad346f4f678ab1c3222425641d851dc63e9dfa1aJohn McCall /// isForEH - true if the current emission is for an EH cleanup. 203ad346f4f678ab1c3222425641d851dc63e9dfa1aJohn McCall bool isForEHCleanup() const { return flags & F_IsForEH; } 204ad346f4f678ab1c3222425641d851dc63e9dfa1aJohn McCall bool isForNormalCleanup() const { return !isForEHCleanup(); } 205ad346f4f678ab1c3222425641d851dc63e9dfa1aJohn McCall void setIsForEHCleanup() { flags |= F_IsForEH; } 206ad346f4f678ab1c3222425641d851dc63e9dfa1aJohn McCall 207ad346f4f678ab1c3222425641d851dc63e9dfa1aJohn McCall bool isNormalCleanupKind() const { return flags & F_IsNormalCleanupKind; } 208ad346f4f678ab1c3222425641d851dc63e9dfa1aJohn McCall void setIsNormalCleanupKind() { flags |= F_IsNormalCleanupKind; } 209ad346f4f678ab1c3222425641d851dc63e9dfa1aJohn McCall 210ad346f4f678ab1c3222425641d851dc63e9dfa1aJohn McCall /// isEHCleanupKind - true if the cleanup was pushed as an EH 211ad346f4f678ab1c3222425641d851dc63e9dfa1aJohn McCall /// cleanup. 212ad346f4f678ab1c3222425641d851dc63e9dfa1aJohn McCall bool isEHCleanupKind() const { return flags & F_IsEHCleanupKind; } 213ad346f4f678ab1c3222425641d851dc63e9dfa1aJohn McCall void setIsEHCleanupKind() { flags |= F_IsEHCleanupKind; } 214ad346f4f678ab1c3222425641d851dc63e9dfa1aJohn McCall }; 215ad346f4f678ab1c3222425641d851dc63e9dfa1aJohn McCall 216c4a1a8450a3613ef256a71b9d8305b41f79eef50John McCall // Provide a virtual destructor to suppress a very common warning 217c4a1a8450a3613ef256a71b9d8305b41f79eef50John McCall // that unfortunately cannot be suppressed without this. Cleanups 218c4a1a8450a3613ef256a71b9d8305b41f79eef50John McCall // should not rely on this destructor ever being called. 219c4a1a8450a3613ef256a71b9d8305b41f79eef50John McCall virtual ~Cleanup() {} 2203e29f96988b0438e42dba3790f61fb3df42d90cbJohn McCall 221da65ea86482bc116906edfb9ba1d7124f76cc867John McCall /// Emit the cleanup. For normal cleanups, this is run in the 222da65ea86482bc116906edfb9ba1d7124f76cc867John McCall /// same EH context as when the cleanup was pushed, i.e. the 223da65ea86482bc116906edfb9ba1d7124f76cc867John McCall /// immediately-enclosing context of the cleanup scope. For 224da65ea86482bc116906edfb9ba1d7124f76cc867John McCall /// EH cleanups, this is run in a terminate context. 225da65ea86482bc116906edfb9ba1d7124f76cc867John McCall /// 226da65ea86482bc116906edfb9ba1d7124f76cc867John McCall // \param IsForEHCleanup true if this is for an EH cleanup, false 227da65ea86482bc116906edfb9ba1d7124f76cc867John McCall /// if for a normal cleanup. 228ad346f4f678ab1c3222425641d851dc63e9dfa1aJohn McCall virtual void Emit(CodeGenFunction &CGF, Flags flags) = 0; 229da65ea86482bc116906edfb9ba1d7124f76cc867John McCall }; 230da65ea86482bc116906edfb9ba1d7124f76cc867John McCall 231150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall /// ConditionalCleanupN stores the saved form of its N parameters, 232150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall /// then restores them and performs the cleanup. 2333ad32c8d93eb65d1d4943d7df567fc9b4f55d137John McCall template <class T, class A0> 2343ad32c8d93eb65d1d4943d7df567fc9b4f55d137John McCall class ConditionalCleanup1 : public Cleanup { 235804b807ea918184d6de63bd745e1ff75a9bfc679John McCall typedef typename DominatingValue<A0>::saved_type A0_saved; 2363ad32c8d93eb65d1d4943d7df567fc9b4f55d137John McCall A0_saved a0_saved; 2373ad32c8d93eb65d1d4943d7df567fc9b4f55d137John McCall 238ad346f4f678ab1c3222425641d851dc63e9dfa1aJohn McCall void Emit(CodeGenFunction &CGF, Flags flags) { 239804b807ea918184d6de63bd745e1ff75a9bfc679John McCall A0 a0 = DominatingValue<A0>::restore(CGF, a0_saved); 240ad346f4f678ab1c3222425641d851dc63e9dfa1aJohn McCall T(a0).Emit(CGF, flags); 2413ad32c8d93eb65d1d4943d7df567fc9b4f55d137John McCall } 2423ad32c8d93eb65d1d4943d7df567fc9b4f55d137John McCall 2433ad32c8d93eb65d1d4943d7df567fc9b4f55d137John McCall public: 2443ad32c8d93eb65d1d4943d7df567fc9b4f55d137John McCall ConditionalCleanup1(A0_saved a0) 2453ad32c8d93eb65d1d4943d7df567fc9b4f55d137John McCall : a0_saved(a0) {} 2463ad32c8d93eb65d1d4943d7df567fc9b4f55d137John McCall }; 2473ad32c8d93eb65d1d4943d7df567fc9b4f55d137John McCall 248150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall template <class T, class A0, class A1> 2493ad32c8d93eb65d1d4943d7df567fc9b4f55d137John McCall class ConditionalCleanup2 : public Cleanup { 250804b807ea918184d6de63bd745e1ff75a9bfc679John McCall typedef typename DominatingValue<A0>::saved_type A0_saved; 251804b807ea918184d6de63bd745e1ff75a9bfc679John McCall typedef typename DominatingValue<A1>::saved_type A1_saved; 2524bbcbda302cba8b1b0d88c20d735d09b483bd005John McCall A0_saved a0_saved; 2534bbcbda302cba8b1b0d88c20d735d09b483bd005John McCall A1_saved a1_saved; 254150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall 255ad346f4f678ab1c3222425641d851dc63e9dfa1aJohn McCall void Emit(CodeGenFunction &CGF, Flags flags) { 256804b807ea918184d6de63bd745e1ff75a9bfc679John McCall A0 a0 = DominatingValue<A0>::restore(CGF, a0_saved); 257804b807ea918184d6de63bd745e1ff75a9bfc679John McCall A1 a1 = DominatingValue<A1>::restore(CGF, a1_saved); 258ad346f4f678ab1c3222425641d851dc63e9dfa1aJohn McCall T(a0, a1).Emit(CGF, flags); 259150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall } 260150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall 261150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall public: 2623ad32c8d93eb65d1d4943d7df567fc9b4f55d137John McCall ConditionalCleanup2(A0_saved a0, A1_saved a1) 2633ad32c8d93eb65d1d4943d7df567fc9b4f55d137John McCall : a0_saved(a0), a1_saved(a1) {} 264150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall }; 265150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall 266d7b23167763f43d3e76b0de26141b1e52613ee3cDouglas Gregor template <class T, class A0, class A1, class A2> 267d7b23167763f43d3e76b0de26141b1e52613ee3cDouglas Gregor class ConditionalCleanup3 : public Cleanup { 268d7b23167763f43d3e76b0de26141b1e52613ee3cDouglas Gregor typedef typename DominatingValue<A0>::saved_type A0_saved; 269d7b23167763f43d3e76b0de26141b1e52613ee3cDouglas Gregor typedef typename DominatingValue<A1>::saved_type A1_saved; 270d7b23167763f43d3e76b0de26141b1e52613ee3cDouglas Gregor typedef typename DominatingValue<A2>::saved_type A2_saved; 271d7b23167763f43d3e76b0de26141b1e52613ee3cDouglas Gregor A0_saved a0_saved; 272d7b23167763f43d3e76b0de26141b1e52613ee3cDouglas Gregor A1_saved a1_saved; 273d7b23167763f43d3e76b0de26141b1e52613ee3cDouglas Gregor A2_saved a2_saved; 274d7b23167763f43d3e76b0de26141b1e52613ee3cDouglas Gregor 275ad346f4f678ab1c3222425641d851dc63e9dfa1aJohn McCall void Emit(CodeGenFunction &CGF, Flags flags) { 276d7b23167763f43d3e76b0de26141b1e52613ee3cDouglas Gregor A0 a0 = DominatingValue<A0>::restore(CGF, a0_saved); 277d7b23167763f43d3e76b0de26141b1e52613ee3cDouglas Gregor A1 a1 = DominatingValue<A1>::restore(CGF, a1_saved); 278d7b23167763f43d3e76b0de26141b1e52613ee3cDouglas Gregor A2 a2 = DominatingValue<A2>::restore(CGF, a2_saved); 279ad346f4f678ab1c3222425641d851dc63e9dfa1aJohn McCall T(a0, a1, a2).Emit(CGF, flags); 280d7b23167763f43d3e76b0de26141b1e52613ee3cDouglas Gregor } 281d7b23167763f43d3e76b0de26141b1e52613ee3cDouglas Gregor 282d7b23167763f43d3e76b0de26141b1e52613ee3cDouglas Gregor public: 283d7b23167763f43d3e76b0de26141b1e52613ee3cDouglas Gregor ConditionalCleanup3(A0_saved a0, A1_saved a1, A2_saved a2) 284c4a1a8450a3613ef256a71b9d8305b41f79eef50John McCall : a0_saved(a0), a1_saved(a1), a2_saved(a2) {} 285d7b23167763f43d3e76b0de26141b1e52613ee3cDouglas Gregor }; 286d7b23167763f43d3e76b0de26141b1e52613ee3cDouglas Gregor 2879928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall template <class T, class A0, class A1, class A2, class A3> 2889928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall class ConditionalCleanup4 : public Cleanup { 2899928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall typedef typename DominatingValue<A0>::saved_type A0_saved; 2909928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall typedef typename DominatingValue<A1>::saved_type A1_saved; 2919928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall typedef typename DominatingValue<A2>::saved_type A2_saved; 2929928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall typedef typename DominatingValue<A3>::saved_type A3_saved; 2939928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall A0_saved a0_saved; 2949928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall A1_saved a1_saved; 2959928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall A2_saved a2_saved; 2969928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall A3_saved a3_saved; 2979928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall 298ad346f4f678ab1c3222425641d851dc63e9dfa1aJohn McCall void Emit(CodeGenFunction &CGF, Flags flags) { 2999928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall A0 a0 = DominatingValue<A0>::restore(CGF, a0_saved); 3009928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall A1 a1 = DominatingValue<A1>::restore(CGF, a1_saved); 3019928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall A2 a2 = DominatingValue<A2>::restore(CGF, a2_saved); 3029928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall A3 a3 = DominatingValue<A3>::restore(CGF, a3_saved); 303ad346f4f678ab1c3222425641d851dc63e9dfa1aJohn McCall T(a0, a1, a2, a3).Emit(CGF, flags); 3049928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall } 3059928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall 3069928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall public: 3079928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall ConditionalCleanup4(A0_saved a0, A1_saved a1, A2_saved a2, A3_saved a3) 3089928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall : a0_saved(a0), a1_saved(a1), a2_saved(a2), a3_saved(a3) {} 3099928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall }; 3109928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall 311f1549f66a8216a78112286e3978cea2c29d6334cJohn McCallprivate: 312f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall // The implementation for this class is in CGException.h and 313f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall // CGException.cpp; the definition is here because it's used as a 314f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall // member of CodeGenFunction. 315f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 316f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// The start of the scope-stack buffer, i.e. the allocated pointer 317f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// for the buffer. All of these pointers are either simultaneously 318f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// null or simultaneously valid. 319f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall char *StartOfBuffer; 320f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 321f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// The end of the buffer. 322f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall char *EndOfBuffer; 323f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 324f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// The first valid entry in the buffer. 325f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall char *StartOfData; 326f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 327f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// The innermost normal cleanup on the stack. 328f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall stable_iterator InnermostNormalCleanup; 329f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 330777d6e56ad9b1fed9866daf3ee6486d85c5b7d32John McCall /// The innermost EH scope on the stack. 331777d6e56ad9b1fed9866daf3ee6486d85c5b7d32John McCall stable_iterator InnermostEHScope; 332ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall 333f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// The current set of branch fixups. A branch fixup is a jump to 334f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// an as-yet unemitted label, i.e. a label for which we don't yet 335f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// know the EH stack depth. Whenever we pop a cleanup, we have 336f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// to thread all the current branch fixups through it. 337f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// 338f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// Fixups are recorded as the Use of the respective branch or 339f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// switch statement. The use points to the final destination. 340f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// When popping out of a cleanup, these uses are threaded through 341f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// the cleanup and adjusted to point to the new cleanup. 342f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// 343f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// Note that branches are allowed to jump into protected scopes 344f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// in certain situations; e.g. the following code is legal: 345f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// struct A { ~A(); }; // trivial ctor, non-trivial dtor 346f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// goto foo; 347f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// A a; 348f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// foo: 349f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// bar(); 350686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVector<BranchFixup, 8> BranchFixups; 351f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 352f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall char *allocate(size_t Size); 353f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 3541f0fca54676cfa8616e7f3cd7a26788ab937e3cdJohn McCall void *pushCleanup(CleanupKind K, size_t DataSize); 355da65ea86482bc116906edfb9ba1d7124f76cc867John McCall 356f1549f66a8216a78112286e3978cea2c29d6334cJohn McCallpublic: 357f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall EHScopeStack() : StartOfBuffer(0), EndOfBuffer(0), StartOfData(0), 358f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall InnermostNormalCleanup(stable_end()), 359777d6e56ad9b1fed9866daf3ee6486d85c5b7d32John McCall InnermostEHScope(stable_end()) {} 360f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall ~EHScopeStack() { delete[] StartOfBuffer; } 361f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 362da65ea86482bc116906edfb9ba1d7124f76cc867John McCall // Variadic templates would make this not terrible. 363da65ea86482bc116906edfb9ba1d7124f76cc867John McCall 364da65ea86482bc116906edfb9ba1d7124f76cc867John McCall /// Push a lazily-created cleanup on the stack. 3658e3f86193995c47ee0d229e4336c3382410f09f5John McCall template <class T> 3661f0fca54676cfa8616e7f3cd7a26788ab937e3cdJohn McCall void pushCleanup(CleanupKind Kind) { 3671f0fca54676cfa8616e7f3cd7a26788ab937e3cdJohn McCall void *Buffer = pushCleanup(Kind, sizeof(T)); 3681f0fca54676cfa8616e7f3cd7a26788ab937e3cdJohn McCall Cleanup *Obj = new(Buffer) T(); 3698e3f86193995c47ee0d229e4336c3382410f09f5John McCall (void) Obj; 3708e3f86193995c47ee0d229e4336c3382410f09f5John McCall } 3718e3f86193995c47ee0d229e4336c3382410f09f5John McCall 3728e3f86193995c47ee0d229e4336c3382410f09f5John McCall /// Push a lazily-created cleanup on the stack. 3738e3f86193995c47ee0d229e4336c3382410f09f5John McCall template <class T, class A0> 3741f0fca54676cfa8616e7f3cd7a26788ab937e3cdJohn McCall void pushCleanup(CleanupKind Kind, A0 a0) { 3751f0fca54676cfa8616e7f3cd7a26788ab937e3cdJohn McCall void *Buffer = pushCleanup(Kind, sizeof(T)); 3761f0fca54676cfa8616e7f3cd7a26788ab937e3cdJohn McCall Cleanup *Obj = new(Buffer) T(a0); 3778e3f86193995c47ee0d229e4336c3382410f09f5John McCall (void) Obj; 3788e3f86193995c47ee0d229e4336c3382410f09f5John McCall } 3798e3f86193995c47ee0d229e4336c3382410f09f5John McCall 3808e3f86193995c47ee0d229e4336c3382410f09f5John McCall /// Push a lazily-created cleanup on the stack. 381da65ea86482bc116906edfb9ba1d7124f76cc867John McCall template <class T, class A0, class A1> 3821f0fca54676cfa8616e7f3cd7a26788ab937e3cdJohn McCall void pushCleanup(CleanupKind Kind, A0 a0, A1 a1) { 3831f0fca54676cfa8616e7f3cd7a26788ab937e3cdJohn McCall void *Buffer = pushCleanup(Kind, sizeof(T)); 3841f0fca54676cfa8616e7f3cd7a26788ab937e3cdJohn McCall Cleanup *Obj = new(Buffer) T(a0, a1); 385da65ea86482bc116906edfb9ba1d7124f76cc867John McCall (void) Obj; 386da65ea86482bc116906edfb9ba1d7124f76cc867John McCall } 387da65ea86482bc116906edfb9ba1d7124f76cc867John McCall 388da65ea86482bc116906edfb9ba1d7124f76cc867John McCall /// Push a lazily-created cleanup on the stack. 389da65ea86482bc116906edfb9ba1d7124f76cc867John McCall template <class T, class A0, class A1, class A2> 3901f0fca54676cfa8616e7f3cd7a26788ab937e3cdJohn McCall void pushCleanup(CleanupKind Kind, A0 a0, A1 a1, A2 a2) { 3911f0fca54676cfa8616e7f3cd7a26788ab937e3cdJohn McCall void *Buffer = pushCleanup(Kind, sizeof(T)); 3921f0fca54676cfa8616e7f3cd7a26788ab937e3cdJohn McCall Cleanup *Obj = new(Buffer) T(a0, a1, a2); 393da65ea86482bc116906edfb9ba1d7124f76cc867John McCall (void) Obj; 394da65ea86482bc116906edfb9ba1d7124f76cc867John McCall } 395da65ea86482bc116906edfb9ba1d7124f76cc867John McCall 396da65ea86482bc116906edfb9ba1d7124f76cc867John McCall /// Push a lazily-created cleanup on the stack. 397da65ea86482bc116906edfb9ba1d7124f76cc867John McCall template <class T, class A0, class A1, class A2, class A3> 3981f0fca54676cfa8616e7f3cd7a26788ab937e3cdJohn McCall void pushCleanup(CleanupKind Kind, A0 a0, A1 a1, A2 a2, A3 a3) { 3991f0fca54676cfa8616e7f3cd7a26788ab937e3cdJohn McCall void *Buffer = pushCleanup(Kind, sizeof(T)); 4001f0fca54676cfa8616e7f3cd7a26788ab937e3cdJohn McCall Cleanup *Obj = new(Buffer) T(a0, a1, a2, a3); 401da65ea86482bc116906edfb9ba1d7124f76cc867John McCall (void) Obj; 402da65ea86482bc116906edfb9ba1d7124f76cc867John McCall } 403da65ea86482bc116906edfb9ba1d7124f76cc867John McCall 40477199713ab56f87ffad9a535ff2a0877704eed87John McCall /// Push a lazily-created cleanup on the stack. 40577199713ab56f87ffad9a535ff2a0877704eed87John McCall template <class T, class A0, class A1, class A2, class A3, class A4> 4061f0fca54676cfa8616e7f3cd7a26788ab937e3cdJohn McCall void pushCleanup(CleanupKind Kind, A0 a0, A1 a1, A2 a2, A3 a3, A4 a4) { 4071f0fca54676cfa8616e7f3cd7a26788ab937e3cdJohn McCall void *Buffer = pushCleanup(Kind, sizeof(T)); 4081f0fca54676cfa8616e7f3cd7a26788ab937e3cdJohn McCall Cleanup *Obj = new(Buffer) T(a0, a1, a2, a3, a4); 40977199713ab56f87ffad9a535ff2a0877704eed87John McCall (void) Obj; 41077199713ab56f87ffad9a535ff2a0877704eed87John McCall } 41177199713ab56f87ffad9a535ff2a0877704eed87John McCall 4127d8647f194ae4f2499e5bcd40dcfea34cd21ebc6John McCall // Feel free to add more variants of the following: 4137d8647f194ae4f2499e5bcd40dcfea34cd21ebc6John McCall 4147d8647f194ae4f2499e5bcd40dcfea34cd21ebc6John McCall /// Push a cleanup with non-constant storage requirements on the 4157d8647f194ae4f2499e5bcd40dcfea34cd21ebc6John McCall /// stack. The cleanup type must provide an additional static method: 4167d8647f194ae4f2499e5bcd40dcfea34cd21ebc6John McCall /// static size_t getExtraSize(size_t); 4177d8647f194ae4f2499e5bcd40dcfea34cd21ebc6John McCall /// The argument to this method will be the value N, which will also 4187d8647f194ae4f2499e5bcd40dcfea34cd21ebc6John McCall /// be passed as the first argument to the constructor. 4197d8647f194ae4f2499e5bcd40dcfea34cd21ebc6John McCall /// 4207d8647f194ae4f2499e5bcd40dcfea34cd21ebc6John McCall /// The data stored in the extra storage must obey the same 4217d8647f194ae4f2499e5bcd40dcfea34cd21ebc6John McCall /// restrictions as normal cleanup member data. 4227d8647f194ae4f2499e5bcd40dcfea34cd21ebc6John McCall /// 4237d8647f194ae4f2499e5bcd40dcfea34cd21ebc6John McCall /// The pointer returned from this method is valid until the cleanup 4247d8647f194ae4f2499e5bcd40dcfea34cd21ebc6John McCall /// stack is modified. 4257d8647f194ae4f2499e5bcd40dcfea34cd21ebc6John McCall template <class T, class A0, class A1, class A2> 4267d8647f194ae4f2499e5bcd40dcfea34cd21ebc6John McCall T *pushCleanupWithExtra(CleanupKind Kind, size_t N, A0 a0, A1 a1, A2 a2) { 4277d8647f194ae4f2499e5bcd40dcfea34cd21ebc6John McCall void *Buffer = pushCleanup(Kind, sizeof(T) + T::getExtraSize(N)); 4287d8647f194ae4f2499e5bcd40dcfea34cd21ebc6John McCall return new (Buffer) T(N, a0, a1, a2); 4297d8647f194ae4f2499e5bcd40dcfea34cd21ebc6John McCall } 4307d8647f194ae4f2499e5bcd40dcfea34cd21ebc6John McCall 431777d6e56ad9b1fed9866daf3ee6486d85c5b7d32John McCall /// Pops a cleanup scope off the stack. This is private to CGCleanup.cpp. 432f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall void popCleanup(); 433f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 434f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// Push a set of catch handlers on the stack. The catch is 435f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// uninitialized and will need to have the given number of handlers 436f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// set on it. 437f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall class EHCatchScope *pushCatch(unsigned NumHandlers); 438f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 439777d6e56ad9b1fed9866daf3ee6486d85c5b7d32John McCall /// Pops a catch scope off the stack. This is private to CGException.cpp. 440f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall void popCatch(); 441f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 442f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// Push an exceptions filter on the stack. 443f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall class EHFilterScope *pushFilter(unsigned NumFilters); 444f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 445f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// Pops an exceptions filter off the stack. 446f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall void popFilter(); 447f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 448f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// Push a terminate handler on the stack. 449f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall void pushTerminate(); 450f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 451f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// Pops a terminate handler off the stack. 452f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall void popTerminate(); 453f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 454f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// Determines whether the exception-scopes stack is empty. 455f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall bool empty() const { return StartOfData == EndOfBuffer; } 456f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 457f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall bool requiresLandingPad() const { 458777d6e56ad9b1fed9866daf3ee6486d85c5b7d32John McCall return InnermostEHScope != stable_end(); 459f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall } 460f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 461f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// Determines whether there are any normal cleanups on the stack. 462f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall bool hasNormalCleanups() const { 463f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall return InnermostNormalCleanup != stable_end(); 464f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall } 465f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 466f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// Returns the innermost normal cleanup on the stack, or 467f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// stable_end() if there are no normal cleanups. 468f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall stable_iterator getInnermostNormalCleanup() const { 469f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall return InnermostNormalCleanup; 470f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall } 471777d6e56ad9b1fed9866daf3ee6486d85c5b7d32John McCall stable_iterator getInnermostActiveNormalCleanup() const; 472f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 473777d6e56ad9b1fed9866daf3ee6486d85c5b7d32John McCall stable_iterator getInnermostEHScope() const { 474777d6e56ad9b1fed9866daf3ee6486d85c5b7d32John McCall return InnermostEHScope; 475f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall } 476f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 477777d6e56ad9b1fed9866daf3ee6486d85c5b7d32John McCall stable_iterator getInnermostActiveEHScope() const; 478f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 479f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// An unstable reference to a scope-stack depth. Invalidated by 480f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// pushes but not pops. 481f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall class iterator; 482f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 483f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// Returns an iterator pointing to the innermost EH scope. 484f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall iterator begin() const; 485f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 486f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// Returns an iterator pointing to the outermost EH scope. 487f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall iterator end() const; 488f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 489f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// Create a stable reference to the top of the EH stack. The 490f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// returned reference is valid until that scope is popped off the 491f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// stack. 492f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall stable_iterator stable_begin() const { 493f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall return stable_iterator(EndOfBuffer - StartOfData); 494f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall } 495f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 496f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// Create a stable reference to the bottom of the EH stack. 497f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall static stable_iterator stable_end() { 498f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall return stable_iterator(0); 499f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall } 500f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 501f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// Translates an iterator into a stable_iterator. 502f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall stable_iterator stabilize(iterator it) const; 503f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 504f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// Turn a stable reference to a scope depth into a unstable pointer 505f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// to the EH stack. 506f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall iterator find(stable_iterator save) const; 507f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 508f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// Removes the cleanup pointed to by the given stable_iterator. 509f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall void removeCleanup(stable_iterator save); 510f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 511f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// Add a branch fixup to the current cleanup scope. 512f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall BranchFixup &addBranchFixup() { 513f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall assert(hasNormalCleanups() && "adding fixup in scope without cleanups"); 514f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall BranchFixups.push_back(BranchFixup()); 515f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall return BranchFixups.back(); 516f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall } 517f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 518f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall unsigned getNumBranchFixups() const { return BranchFixups.size(); } 519f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall BranchFixup &getBranchFixup(unsigned I) { 520f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall assert(I < getNumBranchFixups()); 521f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall return BranchFixups[I]; 522f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall } 523f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 524ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall /// Pops lazily-removed fixups from the end of the list. This 525ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall /// should only be called by procedures which have just popped a 526ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall /// cleanup or resolved one or more fixups. 527ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall void popNullFixups(); 528ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall 529ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall /// Clears the branch-fixups list. This should only be called by 5308abdbd8118e37e759d1ce3f5814ee0a24b1589e8John McCall /// ResolveAllBranchFixups. 531ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall void clearFixups() { BranchFixups.clear(); } 532f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall}; 533f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 5345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// CodeGenFunction - This class organizes the per-function state that is used 5355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// while generating LLVM code. 5365936e33bf74dd6bf126ceee0f6169a2593d03a69John McCallclass CodeGenFunction : public CodeGenTypeCache { 5378a219ceda2b5afd447e7199b9c53079bead31b89Anders Carlsson CodeGenFunction(const CodeGenFunction&); // DO NOT IMPLEMENT 5388a219ceda2b5afd447e7199b9c53079bead31b89Anders Carlsson void operator=(const CodeGenFunction&); // DO NOT IMPLEMENT 5394c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall 5404c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall friend class CGCXXABI; 541bfc0c1ae4b505b52b36f572a9641f99e76879cabChris Lattnerpublic: 542ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall /// A jump destination is an abstract label, branching to which may 543ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall /// require a jump out through normal cleanups. 544f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall struct JumpDest { 545ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall JumpDest() : Block(0), ScopeDepth(), Index(0) {} 546ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall JumpDest(llvm::BasicBlock *Block, 547ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall EHScopeStack::stable_iterator Depth, 548ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall unsigned Index) 549ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall : Block(Block), ScopeDepth(Depth), Index(Index) {} 550ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall 551ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall bool isValid() const { return Block != 0; } 552ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall llvm::BasicBlock *getBlock() const { return Block; } 553ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall EHScopeStack::stable_iterator getScopeDepth() const { return ScopeDepth; } 554ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall unsigned getDestIndex() const { return Index; } 5559cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer 556ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall private: 557f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall llvm::BasicBlock *Block; 558f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall EHScopeStack::stable_iterator ScopeDepth; 559ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall unsigned Index; 560ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall }; 561ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall 5625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer CodeGenModule &CGM; // Per-module state. 563444be7366d0a1e172c0290a1ea54c1cb16b5947cDaniel Dunbar const TargetInfo &Target; 5640dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 56558dee10ed2eee34035f62d1c2d32b3639e9182f8Chris Lattner typedef std::pair<llvm::Value *, llvm::Value *> ComplexPairTy; 56645d196b8387dcefc4df26cda114fa34c6528e928Daniel Dunbar CGBuilderTy Builder; 5670dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 568b5437d238752dc297e42410e98d38d5250fe0463Chris Lattner /// CurFuncDecl - Holds the Decl for the current function or ObjC method. 569b5437d238752dc297e42410e98d38d5250fe0463Chris Lattner /// This excludes BlockDecls. 5704111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner const Decl *CurFuncDecl; 571b5437d238752dc297e42410e98d38d5250fe0463Chris Lattner /// CurCodeDecl - This is the inner-most code context, which includes blocks. 572b5437d238752dc297e42410e98d38d5250fe0463Chris Lattner const Decl *CurCodeDecl; 57388b5396b0897f28d22ae3debf4a0d97b33b6c362Daniel Dunbar const CGFunctionInfo *CurFnInfo; 574391d77a26382dddf25da73e29fc1fa5aaaea4c6fChris Lattner QualType FnRetTy; 5755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer llvm::Function *CurFn; 5765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5776a1e0eb557d47e85185e09bdf8721f53f4bf9c9cMike Stump /// CurGD - The GlobalDecl for the current function being compiled. 5786a1e0eb557d47e85185e09bdf8721f53f4bf9c9cMike Stump GlobalDecl CurGD; 5796a1e0eb557d47e85185e09bdf8721f53f4bf9c9cMike Stump 580f85e193739c953358c865005855253af4f68a497John McCall /// PrologueCleanupDepth - The cleanup depth enclosing all the 581f85e193739c953358c865005855253af4f68a497John McCall /// cleanups associated with the parameters. 582f85e193739c953358c865005855253af4f68a497John McCall EHScopeStack::stable_iterator PrologueCleanupDepth; 583f85e193739c953358c865005855253af4f68a497John McCall 5845ca2084cf9b529563209429857f01fdae9dcdfa5Daniel Dunbar /// ReturnBlock - Unified return block. 585f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall JumpDest ReturnBlock; 586f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 5870dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// ReturnValue - The temporary alloca to hold the return value. This is null 5880dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// iff the function has no return value. 589b17daf9ab790ae71aacad2cc4aa11cd8d86c25d1Eli Friedman llvm::Value *ReturnValue; 5900dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 5915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// AllocaInsertPoint - This is an instruction in the entry block before which 5925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// we prefer to insert allocas. 593481769b5dc102b0256b35581e787909ad5edfab5Chris Lattner llvm::AssertingVH<llvm::Instruction> AllocaInsertPt; 5940ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar 5959c276ae0f24d4cee8f7954069d4b8eae45d0447dMike Stump bool CatchUndefined; 5969cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer 597f85e193739c953358c865005855253af4f68a497John McCall /// In ARC, whether we should autorelease the return value. 598f85e193739c953358c865005855253af4f68a497John McCall bool AutoreleaseResult; 599f85e193739c953358c865005855253af4f68a497John McCall 600d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall const CodeGen::CGBlockInfo *BlockInfo; 601d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall llvm::Value *BlockPointer; 602d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall 6033d91bbcdab155181556969cad6ec97014405acedDouglas Gregor /// \brief A mapping from NRVO variables to the flags used to indicate 6043d91bbcdab155181556969cad6ec97014405acedDouglas Gregor /// when the NRVO has been applied to this variable. 6053d91bbcdab155181556969cad6ec97014405acedDouglas Gregor llvm::DenseMap<const VarDecl *, llvm::Value *> NRVOFlags; 6069cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer 607f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall EHScopeStack EHStack; 6080dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 609ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall /// i32s containing the indexes of the cleanup destinations. 610ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall llvm::AllocaInst *NormalCleanupDest; 611ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall 612ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall unsigned NextCleanupDestIndex; 613ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall 6141a343ebbf413e8eae6b2737b2b2d79cbf5765571John McCall /// FirstBlockInfo - The head of a singly-linked-list of block layouts. 6151a343ebbf413e8eae6b2737b2b2d79cbf5765571John McCall CGBlockInfo *FirstBlockInfo; 6161a343ebbf413e8eae6b2737b2b2d79cbf5765571John McCall 617777d6e56ad9b1fed9866daf3ee6486d85c5b7d32John McCall /// EHResumeBlock - Unified block containing a call to llvm.eh.resume. 618777d6e56ad9b1fed9866daf3ee6486d85c5b7d32John McCall llvm::BasicBlock *EHResumeBlock; 619777d6e56ad9b1fed9866daf3ee6486d85c5b7d32John McCall 620285cfd8953d4ca4da613a47a0d691f7234068f8cBill Wendling /// The exception slot. All landing pads write the current exception pointer 621285cfd8953d4ca4da613a47a0d691f7234068f8cBill Wendling /// into this alloca. 622f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall llvm::Value *ExceptionSlot; 6230dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 624285cfd8953d4ca4da613a47a0d691f7234068f8cBill Wendling /// The selector slot. Under the MandatoryCleanup model, all landing pads 625285cfd8953d4ca4da613a47a0d691f7234068f8cBill Wendling /// write the current selector value into this alloca. 62693c332a8ba2c193c435b293966d343dab15f555bJohn McCall llvm::AllocaInst *EHSelectorSlot; 62793c332a8ba2c193c435b293966d343dab15f555bJohn McCall 628f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// Emits a landing pad for the current EH stack. 629f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall llvm::BasicBlock *EmitLandingPad(); 6300dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 631f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall llvm::BasicBlock *getInvokeDestImpl(); 63299533834ba8f3658559f334e68a518ebb6388ceaMike Stump 633150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall template <class T> 634804b807ea918184d6de63bd745e1ff75a9bfc679John McCall typename DominatingValue<T>::saved_type saveValueInCond(T value) { 635804b807ea918184d6de63bd745e1ff75a9bfc679John McCall return DominatingValue<T>::save(*this, value); 636150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall } 637150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall 638f1549f66a8216a78112286e3978cea2c29d6334cJohn McCallpublic: 639f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// ObjCEHValueStack - Stack of Objective-C exception values, used for 640f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// rethrows. 641686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVector<llvm::Value*, 8> ObjCEHValueStack; 642bb66f9f2e454135b86462d121629275b6ac38e96Anders Carlsson 643d768e9d29abe1ac1ccc3ed63f2dce835d9bab342John McCall /// A class controlling the emission of a finally block. 644d768e9d29abe1ac1ccc3ed63f2dce835d9bab342John McCall class FinallyInfo { 645d768e9d29abe1ac1ccc3ed63f2dce835d9bab342John McCall /// Where the catchall's edge through the cleanup should go. 646d768e9d29abe1ac1ccc3ed63f2dce835d9bab342John McCall JumpDest RethrowDest; 647d768e9d29abe1ac1ccc3ed63f2dce835d9bab342John McCall 648d768e9d29abe1ac1ccc3ed63f2dce835d9bab342John McCall /// A function to call to enter the catch. 649d768e9d29abe1ac1ccc3ed63f2dce835d9bab342John McCall llvm::Constant *BeginCatchFn; 650d768e9d29abe1ac1ccc3ed63f2dce835d9bab342John McCall 651d768e9d29abe1ac1ccc3ed63f2dce835d9bab342John McCall /// An i1 variable indicating whether or not the @finally is 652d768e9d29abe1ac1ccc3ed63f2dce835d9bab342John McCall /// running for an exception. 653d768e9d29abe1ac1ccc3ed63f2dce835d9bab342John McCall llvm::AllocaInst *ForEHVar; 654d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump 655d768e9d29abe1ac1ccc3ed63f2dce835d9bab342John McCall /// An i8* variable into which the exception pointer to rethrow 656d768e9d29abe1ac1ccc3ed63f2dce835d9bab342John McCall /// has been saved. 657d768e9d29abe1ac1ccc3ed63f2dce835d9bab342John McCall llvm::AllocaInst *SavedExnVar; 658d768e9d29abe1ac1ccc3ed63f2dce835d9bab342John McCall 659d768e9d29abe1ac1ccc3ed63f2dce835d9bab342John McCall public: 660d768e9d29abe1ac1ccc3ed63f2dce835d9bab342John McCall void enter(CodeGenFunction &CGF, const Stmt *Finally, 661d768e9d29abe1ac1ccc3ed63f2dce835d9bab342John McCall llvm::Constant *beginCatchFn, llvm::Constant *endCatchFn, 662d768e9d29abe1ac1ccc3ed63f2dce835d9bab342John McCall llvm::Constant *rethrowFn); 663d768e9d29abe1ac1ccc3ed63f2dce835d9bab342John McCall void exit(CodeGenFunction &CGF); 664d768e9d29abe1ac1ccc3ed63f2dce835d9bab342John McCall }; 665f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 666150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall /// pushFullExprCleanup - Push a cleanup to be run at the end of the 667150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall /// current full-expression. Safe against the possibility that 668150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall /// we're currently inside a conditionally-evaluated expression. 6693ad32c8d93eb65d1d4943d7df567fc9b4f55d137John McCall template <class T, class A0> 6703ad32c8d93eb65d1d4943d7df567fc9b4f55d137John McCall void pushFullExprCleanup(CleanupKind kind, A0 a0) { 6713ad32c8d93eb65d1d4943d7df567fc9b4f55d137John McCall // If we're not in a conditional branch, or if none of the 6723ad32c8d93eb65d1d4943d7df567fc9b4f55d137John McCall // arguments requires saving, then use the unconditional cleanup. 673c4a1a8450a3613ef256a71b9d8305b41f79eef50John McCall if (!isInConditionalBranch()) 674c4a1a8450a3613ef256a71b9d8305b41f79eef50John McCall return EHStack.pushCleanup<T>(kind, a0); 6753ad32c8d93eb65d1d4943d7df567fc9b4f55d137John McCall 676804b807ea918184d6de63bd745e1ff75a9bfc679John McCall typename DominatingValue<A0>::saved_type a0_saved = saveValueInCond(a0); 6773ad32c8d93eb65d1d4943d7df567fc9b4f55d137John McCall 6783ad32c8d93eb65d1d4943d7df567fc9b4f55d137John McCall typedef EHScopeStack::ConditionalCleanup1<T, A0> CleanupType; 6793ad32c8d93eb65d1d4943d7df567fc9b4f55d137John McCall EHStack.pushCleanup<CleanupType>(kind, a0_saved); 6803ad32c8d93eb65d1d4943d7df567fc9b4f55d137John McCall initFullExprCleanup(); 6813ad32c8d93eb65d1d4943d7df567fc9b4f55d137John McCall } 6823ad32c8d93eb65d1d4943d7df567fc9b4f55d137John McCall 6833ad32c8d93eb65d1d4943d7df567fc9b4f55d137John McCall /// pushFullExprCleanup - Push a cleanup to be run at the end of the 6843ad32c8d93eb65d1d4943d7df567fc9b4f55d137John McCall /// current full-expression. Safe against the possibility that 6853ad32c8d93eb65d1d4943d7df567fc9b4f55d137John McCall /// we're currently inside a conditionally-evaluated expression. 686150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall template <class T, class A0, class A1> 687150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall void pushFullExprCleanup(CleanupKind kind, A0 a0, A1 a1) { 688150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall // If we're not in a conditional branch, or if none of the 689150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall // arguments requires saving, then use the unconditional cleanup. 690c4a1a8450a3613ef256a71b9d8305b41f79eef50John McCall if (!isInConditionalBranch()) 691c4a1a8450a3613ef256a71b9d8305b41f79eef50John McCall return EHStack.pushCleanup<T>(kind, a0, a1); 692150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall 693804b807ea918184d6de63bd745e1ff75a9bfc679John McCall typename DominatingValue<A0>::saved_type a0_saved = saveValueInCond(a0); 694804b807ea918184d6de63bd745e1ff75a9bfc679John McCall typename DominatingValue<A1>::saved_type a1_saved = saveValueInCond(a1); 695150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall 696150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall typedef EHScopeStack::ConditionalCleanup2<T, A0, A1> CleanupType; 6973ad32c8d93eb65d1d4943d7df567fc9b4f55d137John McCall EHStack.pushCleanup<CleanupType>(kind, a0_saved, a1_saved); 6983ad32c8d93eb65d1d4943d7df567fc9b4f55d137John McCall initFullExprCleanup(); 699150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall } 700150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall 701d7b23167763f43d3e76b0de26141b1e52613ee3cDouglas Gregor /// pushFullExprCleanup - Push a cleanup to be run at the end of the 702d7b23167763f43d3e76b0de26141b1e52613ee3cDouglas Gregor /// current full-expression. Safe against the possibility that 703d7b23167763f43d3e76b0de26141b1e52613ee3cDouglas Gregor /// we're currently inside a conditionally-evaluated expression. 704d7b23167763f43d3e76b0de26141b1e52613ee3cDouglas Gregor template <class T, class A0, class A1, class A2> 705d7b23167763f43d3e76b0de26141b1e52613ee3cDouglas Gregor void pushFullExprCleanup(CleanupKind kind, A0 a0, A1 a1, A2 a2) { 706d7b23167763f43d3e76b0de26141b1e52613ee3cDouglas Gregor // If we're not in a conditional branch, or if none of the 707d7b23167763f43d3e76b0de26141b1e52613ee3cDouglas Gregor // arguments requires saving, then use the unconditional cleanup. 708d7b23167763f43d3e76b0de26141b1e52613ee3cDouglas Gregor if (!isInConditionalBranch()) { 709c4a1a8450a3613ef256a71b9d8305b41f79eef50John McCall return EHStack.pushCleanup<T>(kind, a0, a1, a2); 710d7b23167763f43d3e76b0de26141b1e52613ee3cDouglas Gregor } 711d7b23167763f43d3e76b0de26141b1e52613ee3cDouglas Gregor 712d7b23167763f43d3e76b0de26141b1e52613ee3cDouglas Gregor typename DominatingValue<A0>::saved_type a0_saved = saveValueInCond(a0); 713d7b23167763f43d3e76b0de26141b1e52613ee3cDouglas Gregor typename DominatingValue<A1>::saved_type a1_saved = saveValueInCond(a1); 714d7b23167763f43d3e76b0de26141b1e52613ee3cDouglas Gregor typename DominatingValue<A2>::saved_type a2_saved = saveValueInCond(a2); 715d7b23167763f43d3e76b0de26141b1e52613ee3cDouglas Gregor 716d7b23167763f43d3e76b0de26141b1e52613ee3cDouglas Gregor typedef EHScopeStack::ConditionalCleanup3<T, A0, A1, A2> CleanupType; 717d7b23167763f43d3e76b0de26141b1e52613ee3cDouglas Gregor EHStack.pushCleanup<CleanupType>(kind, a0_saved, a1_saved, a2_saved); 718d7b23167763f43d3e76b0de26141b1e52613ee3cDouglas Gregor initFullExprCleanup(); 719d7b23167763f43d3e76b0de26141b1e52613ee3cDouglas Gregor } 720d7b23167763f43d3e76b0de26141b1e52613ee3cDouglas Gregor 7219928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall /// pushFullExprCleanup - Push a cleanup to be run at the end of the 7229928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall /// current full-expression. Safe against the possibility that 7239928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall /// we're currently inside a conditionally-evaluated expression. 7249928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall template <class T, class A0, class A1, class A2, class A3> 7259928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall void pushFullExprCleanup(CleanupKind kind, A0 a0, A1 a1, A2 a2, A3 a3) { 7269928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall // If we're not in a conditional branch, or if none of the 7279928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall // arguments requires saving, then use the unconditional cleanup. 7289928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall if (!isInConditionalBranch()) { 7299928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall return EHStack.pushCleanup<T>(kind, a0, a1, a2, a3); 7309928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall } 7319928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall 7329928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall typename DominatingValue<A0>::saved_type a0_saved = saveValueInCond(a0); 7339928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall typename DominatingValue<A1>::saved_type a1_saved = saveValueInCond(a1); 7349928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall typename DominatingValue<A2>::saved_type a2_saved = saveValueInCond(a2); 7359928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall typename DominatingValue<A3>::saved_type a3_saved = saveValueInCond(a3); 7369928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall 7379928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall typedef EHScopeStack::ConditionalCleanup4<T, A0, A1, A2, A3> CleanupType; 7389928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall EHStack.pushCleanup<CleanupType>(kind, a0_saved, a1_saved, 7399928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall a2_saved, a3_saved); 7409928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall initFullExprCleanup(); 7419928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall } 7429928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall 7436f103ba42cb69d50005a977c5ea583984ab63fc4John McCall /// Set up the last cleaup that was pushed as a conditional 7446f103ba42cb69d50005a977c5ea583984ab63fc4John McCall /// full-expression cleanup. 7456f103ba42cb69d50005a977c5ea583984ab63fc4John McCall void initFullExprCleanup(); 7466f103ba42cb69d50005a977c5ea583984ab63fc4John McCall 747f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// PushDestructorCleanup - Push a cleanup to call the 748f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// complete-object destructor of an object of the given type at the 749f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// given address. Does nothing if T is not a C++ class type with a 750f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// non-trivial destructor. 751f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall void PushDestructorCleanup(QualType T, llvm::Value *Addr); 752f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 75381407d404a3fc8d24d0e2a052d85cae183033e2bJohn McCall /// PushDestructorCleanup - Push a cleanup to call the 75481407d404a3fc8d24d0e2a052d85cae183033e2bJohn McCall /// complete-object variant of the given destructor on the object at 75581407d404a3fc8d24d0e2a052d85cae183033e2bJohn McCall /// the given address. 75681407d404a3fc8d24d0e2a052d85cae183033e2bJohn McCall void PushDestructorCleanup(const CXXDestructorDecl *Dtor, 75781407d404a3fc8d24d0e2a052d85cae183033e2bJohn McCall llvm::Value *Addr); 75881407d404a3fc8d24d0e2a052d85cae183033e2bJohn McCall 759f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// PopCleanupBlock - Will pop the cleanup entry on the stack and 760f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// process all branch fixups. 761ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall void PopCleanupBlock(bool FallThroughIsBranchThrough = false); 762f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 7637d8647f194ae4f2499e5bcd40dcfea34cd21ebc6John McCall /// DeactivateCleanupBlock - Deactivates the given cleanup block. 7647d8647f194ae4f2499e5bcd40dcfea34cd21ebc6John McCall /// The block cannot be reactivated. Pops it if it's the top of the 7657d8647f194ae4f2499e5bcd40dcfea34cd21ebc6John McCall /// stack. 7666f103ba42cb69d50005a977c5ea583984ab63fc4John McCall /// 7676f103ba42cb69d50005a977c5ea583984ab63fc4John McCall /// \param DominatingIP - An instruction which is known to 7686f103ba42cb69d50005a977c5ea583984ab63fc4John McCall /// dominate the current IP (if set) and which lies along 7696f103ba42cb69d50005a977c5ea583984ab63fc4John McCall /// all paths of execution between the current IP and the 7706f103ba42cb69d50005a977c5ea583984ab63fc4John McCall /// the point at which the cleanup comes into scope. 7716f103ba42cb69d50005a977c5ea583984ab63fc4John McCall void DeactivateCleanupBlock(EHScopeStack::stable_iterator Cleanup, 7726f103ba42cb69d50005a977c5ea583984ab63fc4John McCall llvm::Instruction *DominatingIP); 7737d8647f194ae4f2499e5bcd40dcfea34cd21ebc6John McCall 7747d8647f194ae4f2499e5bcd40dcfea34cd21ebc6John McCall /// ActivateCleanupBlock - Activates an initially-inactive cleanup. 7757d8647f194ae4f2499e5bcd40dcfea34cd21ebc6John McCall /// Cannot be used to resurrect a deactivated cleanup. 7766f103ba42cb69d50005a977c5ea583984ab63fc4John McCall /// 7776f103ba42cb69d50005a977c5ea583984ab63fc4John McCall /// \param DominatingIP - An instruction which is known to 7786f103ba42cb69d50005a977c5ea583984ab63fc4John McCall /// dominate the current IP (if set) and which lies along 7796f103ba42cb69d50005a977c5ea583984ab63fc4John McCall /// all paths of execution between the current IP and the 7806f103ba42cb69d50005a977c5ea583984ab63fc4John McCall /// the point at which the cleanup comes into scope. 7816f103ba42cb69d50005a977c5ea583984ab63fc4John McCall void ActivateCleanupBlock(EHScopeStack::stable_iterator Cleanup, 7826f103ba42cb69d50005a977c5ea583984ab63fc4John McCall llvm::Instruction *DominatingIP); 783cd2d2b7814e0104ed41a8da159a06a8ca77b70d8John McCall 784f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// \brief Enters a new scope for capturing cleanups, all of which 785f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// will be executed once the scope is exited. 786f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall class RunCleanupsScope { 787f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall EHScopeStack::stable_iterator CleanupStackDepth; 78801234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor bool OldDidCallStackSave; 7895656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor bool PerformCleanup; 79001234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor 791f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall RunCleanupsScope(const RunCleanupsScope &); // DO NOT IMPLEMENT 792f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall RunCleanupsScope &operator=(const RunCleanupsScope &); // DO NOT IMPLEMENT 79301234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor 794c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher protected: 795c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher CodeGenFunction& CGF; 796c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher 79701234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor public: 79801234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor /// \brief Enter a new cleanup scope. 7999cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer explicit RunCleanupsScope(CodeGenFunction &CGF) 800c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher : PerformCleanup(true), CGF(CGF) 8015656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor { 802f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall CleanupStackDepth = CGF.EHStack.stable_begin(); 80301234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor OldDidCallStackSave = CGF.DidCallStackSave; 8044ada2ca7d82dab68d3646f3eb6dcdfee072e8ea4Argyrios Kyrtzidis CGF.DidCallStackSave = false; 80501234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor } 80601234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor 80701234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor /// \brief Exit this cleanup scope, emitting any accumulated 80801234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor /// cleanups. 809f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall ~RunCleanupsScope() { 8105656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor if (PerformCleanup) { 8115656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor CGF.DidCallStackSave = OldDidCallStackSave; 812f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall CGF.PopCleanupBlocks(CleanupStackDepth); 8135656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor } 8145656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor } 8155656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor 8165656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor /// \brief Determine whether this scope requires any cleanups. 8175656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor bool requiresCleanups() const { 818f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall return CGF.EHStack.stable_begin() != CleanupStackDepth; 8195656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor } 8205656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor 8215656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor /// \brief Force the emission of cleanups now, instead of waiting 8225656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor /// until this object is destroyed. 8235656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor void ForceCleanup() { 8245656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor assert(PerformCleanup && "Already forced cleanup"); 82501234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor CGF.DidCallStackSave = OldDidCallStackSave; 826f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall CGF.PopCleanupBlocks(CleanupStackDepth); 8275656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor PerformCleanup = false; 82801234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor } 82901234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor }; 83001234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor 831c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher class LexicalScope: protected RunCleanupsScope { 832c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher SourceRange Range; 833c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher bool PopDebugStack; 834c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher 835c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher LexicalScope(const LexicalScope &); // DO NOT IMPLEMENT THESE 836c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher LexicalScope &operator=(const LexicalScope &); 837c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher 838c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher public: 839c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher /// \brief Enter a new cleanup scope. 840c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher explicit LexicalScope(CodeGenFunction &CGF, SourceRange Range) 841c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher : RunCleanupsScope(CGF), Range(Range), PopDebugStack(true) { 842c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher if (CGDebugInfo *DI = CGF.getDebugInfo()) 843c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher DI->EmitLexicalBlockStart(CGF.Builder, Range.getBegin()); 844c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher } 845c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher 846c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher /// \brief Exit this cleanup scope, emitting any accumulated 847c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher /// cleanups. 848c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher ~LexicalScope() { 849c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher if (PopDebugStack) { 850c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher CGDebugInfo *DI = CGF.getDebugInfo(); 851c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher if (DI) DI->EmitLexicalBlockEnd(CGF.Builder, Range.getEnd()); 852c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher } 853c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher } 854c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher 855c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher /// \brief Force the emission of cleanups now, instead of waiting 856c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher /// until this object is destroyed. 857c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher void ForceCleanup() { 858c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher RunCleanupsScope::ForceCleanup(); 859c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher if (CGDebugInfo *DI = CGF.getDebugInfo()) { 860c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher DI->EmitLexicalBlockEnd(CGF.Builder, Range.getEnd()); 861c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher PopDebugStack = false; 862c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher } 863c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher } 864c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher }; 865c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher 86644ec82b4a1597802f5bf17721481b8c265bc8dc5Anders Carlsson 867f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// PopCleanupBlocks - Takes the old cleanup stack size and emits 868f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// the cleanup blocks that have been added. 869f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall void PopCleanupBlocks(EHScopeStack::stable_iterator OldCleanupStackSize); 87044ec82b4a1597802f5bf17721481b8c265bc8dc5Anders Carlsson 871ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall void ResolveBranchFixups(llvm::BasicBlock *Target); 872ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall 873f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// The given basic block lies in the current EH scope, but may be a 874f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// target of a potentially scope-crossing jump; get a stable handle 875f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// to which we can perform this jump later. 876ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall JumpDest getJumpDestInCurrentScope(llvm::BasicBlock *Target) { 877413e67778d593215d2f2161a4e712c8568f1ddd0John McCall return JumpDest(Target, 878413e67778d593215d2f2161a4e712c8568f1ddd0John McCall EHStack.getInnermostNormalCleanup(), 879413e67778d593215d2f2161a4e712c8568f1ddd0John McCall NextCleanupDestIndex++); 880f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall } 881c71c845fe77ee1f891d60232ec320912d88557eeAnders Carlsson 882f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// The given basic block lies in the current EH scope, but may be a 883f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// target of a potentially scope-crossing jump; get a stable handle 884f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// to which we can perform this jump later. 885686775deca8b8685eb90801495880e3abdd844c2Chris Lattner JumpDest getJumpDestInCurrentScope(StringRef Name = StringRef()) { 886ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall return getJumpDestInCurrentScope(createBasicBlock(Name)); 887f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall } 888f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 889f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// EmitBranchThroughCleanup - Emit a branch from the current insert 890f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// block through the normal cleanup handling code (if any) and then 891f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// on to \arg Dest. 892f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall void EmitBranchThroughCleanup(JumpDest Dest); 893b11f9198111796ada02b57f62cdea92134fde9f7Chris Lattner 894b11f9198111796ada02b57f62cdea92134fde9f7Chris Lattner /// isObviouslyBranchWithoutCleanups - Return true if a branch to the 895b11f9198111796ada02b57f62cdea92134fde9f7Chris Lattner /// specified destination obviously has no cleanups to run. 'false' is always 896b11f9198111796ada02b57f62cdea92134fde9f7Chris Lattner /// a conservatively correct answer for this method. 897b11f9198111796ada02b57f62cdea92134fde9f7Chris Lattner bool isObviouslyBranchWithoutCleanups(JumpDest Dest) const; 898f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 899777d6e56ad9b1fed9866daf3ee6486d85c5b7d32John McCall /// popCatchScope - Pops the catch scope at the top of the EHScope 900777d6e56ad9b1fed9866daf3ee6486d85c5b7d32John McCall /// stack, emitting any required code (other than the catch handlers 901777d6e56ad9b1fed9866daf3ee6486d85c5b7d32John McCall /// themselves). 902777d6e56ad9b1fed9866daf3ee6486d85c5b7d32John McCall void popCatchScope(); 903ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall 904777d6e56ad9b1fed9866daf3ee6486d85c5b7d32John McCall llvm::BasicBlock *getEHResumeBlock(); 905777d6e56ad9b1fed9866daf3ee6486d85c5b7d32John McCall llvm::BasicBlock *getEHDispatchBlock(EHScopeStack::stable_iterator scope); 9060dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 907150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall /// An object to manage conditionally-evaluated expressions. 908150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall class ConditionalEvaluation { 909150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall llvm::BasicBlock *StartBB; 9101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 911150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall public: 912150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall ConditionalEvaluation(CodeGenFunction &CGF) 913150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall : StartBB(CGF.Builder.GetInsertBlock()) {} 9149cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer 915150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall void begin(CodeGenFunction &CGF) { 916150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall assert(CGF.OutermostConditional != this); 917150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall if (!CGF.OutermostConditional) 918150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall CGF.OutermostConditional = this; 919150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall } 920150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall 921150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall void end(CodeGenFunction &CGF) { 922150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall assert(CGF.OutermostConditional != 0); 923150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall if (CGF.OutermostConditional == this) 924150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall CGF.OutermostConditional = 0; 925150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall } 926150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall 927150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall /// Returns a block which will be executed prior to each 928150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall /// evaluation of the conditional code. 929150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall llvm::BasicBlock *getStartingBlock() const { 930150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall return StartBB; 931150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall } 932150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall }; 9331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 9343019c444c672938c57f5573840071ecd73425ee7John McCall /// isInConditionalBranch - Return true if we're currently emitting 9353019c444c672938c57f5573840071ecd73425ee7John McCall /// one branch or the other of a conditional expression. 936150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall bool isInConditionalBranch() const { return OutermostConditional != 0; } 937150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall 9386f103ba42cb69d50005a977c5ea583984ab63fc4John McCall void setBeforeOutermostConditional(llvm::Value *value, llvm::Value *addr) { 9396f103ba42cb69d50005a977c5ea583984ab63fc4John McCall assert(isInConditionalBranch()); 9406f103ba42cb69d50005a977c5ea583984ab63fc4John McCall llvm::BasicBlock *block = OutermostConditional->getStartingBlock(); 9416f103ba42cb69d50005a977c5ea583984ab63fc4John McCall new llvm::StoreInst(value, addr, &block->back()); 9426f103ba42cb69d50005a977c5ea583984ab63fc4John McCall } 9436f103ba42cb69d50005a977c5ea583984ab63fc4John McCall 944150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall /// An RAII object to record that we're evaluating a statement 945150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall /// expression. 946150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall class StmtExprEvaluation { 947150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall CodeGenFunction &CGF; 948150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall 949150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall /// We have to save the outermost conditional: cleanups in a 950150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall /// statement expression aren't conditional just because the 951150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall /// StmtExpr is. 952150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall ConditionalEvaluation *SavedOutermostConditional; 953150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall 954150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall public: 955150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall StmtExprEvaluation(CodeGenFunction &CGF) 956150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall : CGF(CGF), SavedOutermostConditional(CGF.OutermostConditional) { 957150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall CGF.OutermostConditional = 0; 958150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall } 959150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall 960150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall ~StmtExprEvaluation() { 961150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall CGF.OutermostConditional = SavedOutermostConditional; 962150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall CGF.EnsureInsertPoint(); 963150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall } 964150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall }; 965e996ffd240f20a1048179d7727a6ee3227261921John McCall 96656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// An object which temporarily prevents a value from being 96756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// destroyed by aggressive peephole optimizations that assume that 96856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// all uses of a value have been realized in the IR. 96956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall class PeepholeProtection { 97056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall llvm::Instruction *Inst; 97156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall friend class CodeGenFunction; 97256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 97356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall public: 97456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall PeepholeProtection() : Inst(0) {} 9754b9c2d235fb9449e249d74f48ecfec601650de93John McCall }; 97656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 9774b9c2d235fb9449e249d74f48ecfec601650de93John McCall /// A non-RAII class containing all the information about a bound 9784b9c2d235fb9449e249d74f48ecfec601650de93John McCall /// opaque value. OpaqueValueMapping, below, is a RAII wrapper for 9794b9c2d235fb9449e249d74f48ecfec601650de93John McCall /// this which makes individual mappings very simple; using this 9804b9c2d235fb9449e249d74f48ecfec601650de93John McCall /// class directly is useful when you have a variable number of 9814b9c2d235fb9449e249d74f48ecfec601650de93John McCall /// opaque values or don't want the RAII functionality for some 9824b9c2d235fb9449e249d74f48ecfec601650de93John McCall /// reason. 9834b9c2d235fb9449e249d74f48ecfec601650de93John McCall class OpaqueValueMappingData { 984e996ffd240f20a1048179d7727a6ee3227261921John McCall const OpaqueValueExpr *OpaqueValue; 98556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall bool BoundLValue; 98656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall CodeGenFunction::PeepholeProtection Protection; 987e996ffd240f20a1048179d7727a6ee3227261921John McCall 9884b9c2d235fb9449e249d74f48ecfec601650de93John McCall OpaqueValueMappingData(const OpaqueValueExpr *ov, 9894b9c2d235fb9449e249d74f48ecfec601650de93John McCall bool boundLValue) 9904b9c2d235fb9449e249d74f48ecfec601650de93John McCall : OpaqueValue(ov), BoundLValue(boundLValue) {} 991e996ffd240f20a1048179d7727a6ee3227261921John McCall public: 9924b9c2d235fb9449e249d74f48ecfec601650de93John McCall OpaqueValueMappingData() : OpaqueValue(0) {} 9934b9c2d235fb9449e249d74f48ecfec601650de93John McCall 99456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall static bool shouldBindAsLValue(const Expr *expr) { 995a5493f885095bd63d525a7035ad1c224de3ae5f2John McCall // gl-values should be bound as l-values for obvious reasons. 996a5493f885095bd63d525a7035ad1c224de3ae5f2John McCall // Records should be bound as l-values because IR generation 997a5493f885095bd63d525a7035ad1c224de3ae5f2John McCall // always keeps them in memory. Expressions of function type 998a5493f885095bd63d525a7035ad1c224de3ae5f2John McCall // act exactly like l-values but are formally required to be 999a5493f885095bd63d525a7035ad1c224de3ae5f2John McCall // r-values in C. 1000a5493f885095bd63d525a7035ad1c224de3ae5f2John McCall return expr->isGLValue() || 1001a5493f885095bd63d525a7035ad1c224de3ae5f2John McCall expr->getType()->isRecordType() || 1002a5493f885095bd63d525a7035ad1c224de3ae5f2John McCall expr->getType()->isFunctionType(); 100356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 100456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 10054b9c2d235fb9449e249d74f48ecfec601650de93John McCall static OpaqueValueMappingData bind(CodeGenFunction &CGF, 10064b9c2d235fb9449e249d74f48ecfec601650de93John McCall const OpaqueValueExpr *ov, 10074b9c2d235fb9449e249d74f48ecfec601650de93John McCall const Expr *e) { 10084b9c2d235fb9449e249d74f48ecfec601650de93John McCall if (shouldBindAsLValue(ov)) 10094b9c2d235fb9449e249d74f48ecfec601650de93John McCall return bind(CGF, ov, CGF.EmitLValue(e)); 10104b9c2d235fb9449e249d74f48ecfec601650de93John McCall return bind(CGF, ov, CGF.EmitAnyExpr(e)); 10114b9c2d235fb9449e249d74f48ecfec601650de93John McCall } 10124b9c2d235fb9449e249d74f48ecfec601650de93John McCall 10134b9c2d235fb9449e249d74f48ecfec601650de93John McCall static OpaqueValueMappingData bind(CodeGenFunction &CGF, 10144b9c2d235fb9449e249d74f48ecfec601650de93John McCall const OpaqueValueExpr *ov, 10154b9c2d235fb9449e249d74f48ecfec601650de93John McCall const LValue &lv) { 10164b9c2d235fb9449e249d74f48ecfec601650de93John McCall assert(shouldBindAsLValue(ov)); 10174b9c2d235fb9449e249d74f48ecfec601650de93John McCall CGF.OpaqueLValues.insert(std::make_pair(ov, lv)); 10184b9c2d235fb9449e249d74f48ecfec601650de93John McCall return OpaqueValueMappingData(ov, true); 10194b9c2d235fb9449e249d74f48ecfec601650de93John McCall } 10204b9c2d235fb9449e249d74f48ecfec601650de93John McCall 10214b9c2d235fb9449e249d74f48ecfec601650de93John McCall static OpaqueValueMappingData bind(CodeGenFunction &CGF, 10224b9c2d235fb9449e249d74f48ecfec601650de93John McCall const OpaqueValueExpr *ov, 10234b9c2d235fb9449e249d74f48ecfec601650de93John McCall const RValue &rv) { 10244b9c2d235fb9449e249d74f48ecfec601650de93John McCall assert(!shouldBindAsLValue(ov)); 10254b9c2d235fb9449e249d74f48ecfec601650de93John McCall CGF.OpaqueRValues.insert(std::make_pair(ov, rv)); 10264b9c2d235fb9449e249d74f48ecfec601650de93John McCall 10274b9c2d235fb9449e249d74f48ecfec601650de93John McCall OpaqueValueMappingData data(ov, false); 10284b9c2d235fb9449e249d74f48ecfec601650de93John McCall 10294b9c2d235fb9449e249d74f48ecfec601650de93John McCall // Work around an extremely aggressive peephole optimization in 10304b9c2d235fb9449e249d74f48ecfec601650de93John McCall // EmitScalarConversion which assumes that all other uses of a 10314b9c2d235fb9449e249d74f48ecfec601650de93John McCall // value are extant. 10324b9c2d235fb9449e249d74f48ecfec601650de93John McCall data.Protection = CGF.protectFromPeepholes(rv); 10334b9c2d235fb9449e249d74f48ecfec601650de93John McCall 10344b9c2d235fb9449e249d74f48ecfec601650de93John McCall return data; 10354b9c2d235fb9449e249d74f48ecfec601650de93John McCall } 10364b9c2d235fb9449e249d74f48ecfec601650de93John McCall 10374b9c2d235fb9449e249d74f48ecfec601650de93John McCall bool isValid() const { return OpaqueValue != 0; } 10384b9c2d235fb9449e249d74f48ecfec601650de93John McCall void clear() { OpaqueValue = 0; } 10394b9c2d235fb9449e249d74f48ecfec601650de93John McCall 10404b9c2d235fb9449e249d74f48ecfec601650de93John McCall void unbind(CodeGenFunction &CGF) { 10414b9c2d235fb9449e249d74f48ecfec601650de93John McCall assert(OpaqueValue && "no data to unbind!"); 10424b9c2d235fb9449e249d74f48ecfec601650de93John McCall 10434b9c2d235fb9449e249d74f48ecfec601650de93John McCall if (BoundLValue) { 10444b9c2d235fb9449e249d74f48ecfec601650de93John McCall CGF.OpaqueLValues.erase(OpaqueValue); 10454b9c2d235fb9449e249d74f48ecfec601650de93John McCall } else { 10464b9c2d235fb9449e249d74f48ecfec601650de93John McCall CGF.OpaqueRValues.erase(OpaqueValue); 10474b9c2d235fb9449e249d74f48ecfec601650de93John McCall CGF.unprotectFromPeepholes(Protection); 10484b9c2d235fb9449e249d74f48ecfec601650de93John McCall } 10494b9c2d235fb9449e249d74f48ecfec601650de93John McCall } 10504b9c2d235fb9449e249d74f48ecfec601650de93John McCall }; 10514b9c2d235fb9449e249d74f48ecfec601650de93John McCall 10524b9c2d235fb9449e249d74f48ecfec601650de93John McCall /// An RAII object to set (and then clear) a mapping for an OpaqueValueExpr. 10534b9c2d235fb9449e249d74f48ecfec601650de93John McCall class OpaqueValueMapping { 10544b9c2d235fb9449e249d74f48ecfec601650de93John McCall CodeGenFunction &CGF; 10554b9c2d235fb9449e249d74f48ecfec601650de93John McCall OpaqueValueMappingData Data; 10564b9c2d235fb9449e249d74f48ecfec601650de93John McCall 10574b9c2d235fb9449e249d74f48ecfec601650de93John McCall public: 10584b9c2d235fb9449e249d74f48ecfec601650de93John McCall static bool shouldBindAsLValue(const Expr *expr) { 10594b9c2d235fb9449e249d74f48ecfec601650de93John McCall return OpaqueValueMappingData::shouldBindAsLValue(expr); 10604b9c2d235fb9449e249d74f48ecfec601650de93John McCall } 10614b9c2d235fb9449e249d74f48ecfec601650de93John McCall 106256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// Build the opaque value mapping for the given conditional 106356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// operator if it's the GNU ?: extension. This is a common 106456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// enough pattern that the convenience operator is really 106556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// helpful. 106656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// 106756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall OpaqueValueMapping(CodeGenFunction &CGF, 106856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall const AbstractConditionalOperator *op) : CGF(CGF) { 10694b9c2d235fb9449e249d74f48ecfec601650de93John McCall if (isa<ConditionalOperator>(op)) 10704b9c2d235fb9449e249d74f48ecfec601650de93John McCall // Leave Data empty. 107156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return; 107256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 107356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall const BinaryConditionalOperator *e = cast<BinaryConditionalOperator>(op); 10744b9c2d235fb9449e249d74f48ecfec601650de93John McCall Data = OpaqueValueMappingData::bind(CGF, e->getOpaqueValue(), 10754b9c2d235fb9449e249d74f48ecfec601650de93John McCall e->getCommon()); 107656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 107756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 1078e996ffd240f20a1048179d7727a6ee3227261921John McCall OpaqueValueMapping(CodeGenFunction &CGF, 1079e996ffd240f20a1048179d7727a6ee3227261921John McCall const OpaqueValueExpr *opaqueValue, 108056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall LValue lvalue) 10814b9c2d235fb9449e249d74f48ecfec601650de93John McCall : CGF(CGF), Data(OpaqueValueMappingData::bind(CGF, opaqueValue, lvalue)) { 108256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 108356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 108456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall OpaqueValueMapping(CodeGenFunction &CGF, 108556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall const OpaqueValueExpr *opaqueValue, 108656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall RValue rvalue) 10874b9c2d235fb9449e249d74f48ecfec601650de93John McCall : CGF(CGF), Data(OpaqueValueMappingData::bind(CGF, opaqueValue, rvalue)) { 1088e996ffd240f20a1048179d7727a6ee3227261921John McCall } 1089e996ffd240f20a1048179d7727a6ee3227261921John McCall 1090e996ffd240f20a1048179d7727a6ee3227261921John McCall void pop() { 10914b9c2d235fb9449e249d74f48ecfec601650de93John McCall Data.unbind(CGF); 10924b9c2d235fb9449e249d74f48ecfec601650de93John McCall Data.clear(); 1093e996ffd240f20a1048179d7727a6ee3227261921John McCall } 1094e996ffd240f20a1048179d7727a6ee3227261921John McCall 1095e996ffd240f20a1048179d7727a6ee3227261921John McCall ~OpaqueValueMapping() { 10964b9c2d235fb9449e249d74f48ecfec601650de93John McCall if (Data.isValid()) Data.unbind(CGF); 1097e996ffd240f20a1048179d7727a6ee3227261921John McCall } 1098e996ffd240f20a1048179d7727a6ee3227261921John McCall }; 1099e220455a059d926953befe72857b9525273717efFariborz Jahanian 1100e220455a059d926953befe72857b9525273717efFariborz Jahanian /// getByrefValueFieldNumber - Given a declaration, returns the LLVM field 1101e220455a059d926953befe72857b9525273717efFariborz Jahanian /// number that holds the value. 1102e220455a059d926953befe72857b9525273717efFariborz Jahanian unsigned getByRefValueLLVMField(const ValueDecl *VD) const; 110352a80e19ad688091723a52ad53337767bb0ac684Fariborz Jahanian 110452a80e19ad688091723a52ad53337767bb0ac684Fariborz Jahanian /// BuildBlockByrefAddress - Computes address location of the 110552a80e19ad688091723a52ad53337767bb0ac684Fariborz Jahanian /// variable which is declared as __block. 110652a80e19ad688091723a52ad53337767bb0ac684Fariborz Jahanian llvm::Value *BuildBlockByrefAddress(llvm::Value *BaseAddr, 110752a80e19ad688091723a52ad53337767bb0ac684Fariborz Jahanian const VarDecl *V); 11087f02f721d48772e4eee4fccd8af4f800be1bbc1eChris Lattnerprivate: 1109d9becd1846e2c72bf6ad283faa1b048f33dd3afeChris Lattner CGDebugInfo *DebugInfo; 1110aa11289f754d220c9c155b68a4f84cdcfcefef6aDevang Patel bool DisableDebugInfo; 111109429b962811f2c0a7a81a1b0a89f96f5878b20cMike Stump 111293c332a8ba2c193c435b293966d343dab15f555bJohn McCall /// DidCallStackSave - Whether llvm.stacksave has been called. Used to avoid 111393c332a8ba2c193c435b293966d343dab15f555bJohn McCall /// calling llvm.stacksave for multiple VLAs in the same scope. 111493c332a8ba2c193c435b293966d343dab15f555bJohn McCall bool DidCallStackSave; 111593c332a8ba2c193c435b293966d343dab15f555bJohn McCall 1116f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump /// IndirectBranch - The first time an indirect goto is seen we create a block 1117f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump /// with an indirect branch. Every time we see the address of a label taken, 1118f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump /// we add the label to the indirect goto. Every subsequent indirect goto is 1119f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump /// codegen'd as a jump to the IndirectBranch's basic block. 1120d9becd1846e2c72bf6ad283faa1b048f33dd3afeChris Lattner llvm::IndirectBrInst *IndirectBranch; 11210ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar 11220dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// LocalDeclMap - This keeps track of the LLVM allocas or globals for local C 11230dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// decls. 11246b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall typedef llvm::DenseMap<const Decl*, llvm::Value*> DeclMapTy; 11256b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall DeclMapTy LocalDeclMap; 11265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// LabelMap - This keeps track of the LLVM basic block for each C label. 1128ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner llvm::DenseMap<const LabelDecl*, JumpDest> LabelMap; 11290dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 11300dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump // BreakContinueStack - This keeps track of where break and continue 1131e4b6d342c29d5cb9d311756100df1603810fa892Anders Carlsson // statements should jump to. 1132da13870e99fe33934b2122f06528a5063f78ae4cChris Lattner struct BreakContinue { 1133f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall BreakContinue(JumpDest Break, JumpDest Continue) 1134f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall : BreakBlock(Break), ContinueBlock(Continue) {} 11350dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 1136f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall JumpDest BreakBlock; 1137f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall JumpDest ContinueBlock; 11380dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump }; 1139686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVector<BreakContinue, 8> BreakContinueStack; 114018ccc7776ad6288c5f630dc7967fb99d099c9cd9Daniel Dunbar 11410dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// SwitchInsn - This is nearest current switch instruction. It is null if if 11420dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// current context is not in a switch. 114351b09f2c528c8460b5465c676173324e44176d62Devang Patel llvm::SwitchInst *SwitchInsn; 114451b09f2c528c8460b5465c676173324e44176d62Devang Patel 11450dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// CaseRangeBlock - This block holds if condition check for last case 114680fd5f96e6805ac43aab99faabd5b4c8b19551b7Devang Patel /// statement range in current switch instruction. 1147c049e4f406a7f7179eba98659044a32508e53289Devang Patel llvm::BasicBlock *CaseRangeBlock; 1148c049e4f406a7f7179eba98659044a32508e53289Devang Patel 114956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// OpaqueLValues - Keeps track of the current set of opaque value 1150e996ffd240f20a1048179d7727a6ee3227261921John McCall /// expressions. 115156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall llvm::DenseMap<const OpaqueValueExpr *, LValue> OpaqueLValues; 115256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall llvm::DenseMap<const OpaqueValueExpr *, RValue> OpaqueRValues; 1153e996ffd240f20a1048179d7727a6ee3227261921John McCall 11540dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump // VLASizeMap - This keeps track of the associated size for each VLA type. 1155bbed6b964414145b29e7b60b3e538093734ea3f8Eli Friedman // We track this by the size expression rather than the type itself because 1156bbed6b964414145b29e7b60b3e538093734ea3f8Eli Friedman // in certain situations, like a const qualifier applied to an VLA typedef, 1157bbed6b964414145b29e7b60b3e538093734ea3f8Eli Friedman // multiple VLA types can share the same size expression. 11580dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump // FIXME: Maybe this could be a stack of maps that is pushed/popped as we 11590dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump // enter/leave scopes. 1160bbed6b964414145b29e7b60b3e538093734ea3f8Eli Friedman llvm::DenseMap<const Expr*, llvm::Value*> VLASizeMap; 11610dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 1162f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// A block containing a single 'unreachable' instruction. Created 1163f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// lazily by getUnreachableBlock(). 1164f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall llvm::BasicBlock *UnreachableBlock; 11650dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 1166f6c56e2323c3f973253805a2f35629f3253ebed4Anders Carlsson /// CXXThisDecl - When generating code for a C++ member function, 1167f6c56e2323c3f973253805a2f35629f3253ebed4Anders Carlsson /// this will hold the implicit 'this' declaration. 11682b77ba8bc7a842829ad9193816dc1d7d5e9c5be6Anders Carlsson ImplicitParamDecl *CXXThisDecl; 11692504941793b549323f9d29c62507cf21d865fadeJohn McCall llvm::Value *CXXThisValue; 11701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1171f6c56e2323c3f973253805a2f35629f3253ebed4Anders Carlsson /// CXXVTTDecl - When generating code for a base object constructor or 1172f6c56e2323c3f973253805a2f35629f3253ebed4Anders Carlsson /// base object destructor with virtual bases, this will hold the implicit 1173f6c56e2323c3f973253805a2f35629f3253ebed4Anders Carlsson /// VTT parameter. 1174f6c56e2323c3f973253805a2f35629f3253ebed4Anders Carlsson ImplicitParamDecl *CXXVTTDecl; 11752504941793b549323f9d29c62507cf21d865fadeJohn McCall llvm::Value *CXXVTTValue; 11769cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer 1177150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall /// OutermostConditional - Points to the outermost active 1178150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall /// conditional control. This is used so that we know if a 1179150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall /// temporary should be destroyed conditionally. 1180150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall ConditionalEvaluation *OutermostConditional; 11811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11827dfa4079f4b37507048b19bfc693d3b015d9dd11Anders Carlsson 11837dfa4079f4b37507048b19bfc693d3b015d9dd11Anders Carlsson /// ByrefValueInfoMap - For each __block variable, contains a pair of the LLVM 11847dfa4079f4b37507048b19bfc693d3b015d9dd11Anders Carlsson /// type as well as the field number that contains the actual data. 11852acc6e3feda5e4f7d9009bdcf8b1cd777fecfe2dChris Lattner llvm::DenseMap<const ValueDecl *, std::pair<llvm::Type *, 11867dfa4079f4b37507048b19bfc693d3b015d9dd11Anders Carlsson unsigned> > ByRefValueInfo; 11879cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer 1188f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall llvm::BasicBlock *TerminateLandingPad; 1189182f383db1782af752ecaf607fdff72a8542088bMike Stump llvm::BasicBlock *TerminateHandler; 119083252dcfe61aaebcb6bc117e71dc12968729513fChris Lattner llvm::BasicBlock *TrapBB; 1191940670512d7c3d93389bb38a426abcb7ef44271eEli Friedman 11925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 11935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer CodeGenFunction(CodeGenModule &cgm); 11941a343ebbf413e8eae6b2737b2b2d79cbf5765571John McCall ~CodeGenFunction(); 11950dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 11961e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall CodeGenTypes &getTypes() const { return CGM.getTypes(); } 1197f2aac84709c418189e476ad591848dad50291885John McCall ASTContext &getContext() const { return CGM.getContext(); } 1198aa11289f754d220c9c155b68a4f84cdcfcefef6aDevang Patel CGDebugInfo *getDebugInfo() { 1199aa11289f754d220c9c155b68a4f84cdcfcefef6aDevang Patel if (DisableDebugInfo) 1200aa11289f754d220c9c155b68a4f84cdcfcefef6aDevang Patel return NULL; 1201aa11289f754d220c9c155b68a4f84cdcfcefef6aDevang Patel return DebugInfo; 1202aa11289f754d220c9c155b68a4f84cdcfcefef6aDevang Patel } 1203aa11289f754d220c9c155b68a4f84cdcfcefef6aDevang Patel void disableDebugInfo() { DisableDebugInfo = true; } 1204aa11289f754d220c9c155b68a4f84cdcfcefef6aDevang Patel void enableDebugInfo() { DisableDebugInfo = false; } 1205aa11289f754d220c9c155b68a4f84cdcfcefef6aDevang Patel 1206f85e193739c953358c865005855253af4f68a497John McCall bool shouldUseFusedARCCalls() { 1207f85e193739c953358c865005855253af4f68a497John McCall return CGM.getCodeGenOpts().OptimizationLevel == 0; 1208f85e193739c953358c865005855253af4f68a497John McCall } 12095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1210d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall const LangOptions &getLangOptions() const { return CGM.getLangOptions(); } 1211d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall 1212285cfd8953d4ca4da613a47a0d691f7234068f8cBill Wendling /// Returns a pointer to the function's exception object and selector slot, 1213285cfd8953d4ca4da613a47a0d691f7234068f8cBill Wendling /// which is assigned in every landing pad. 1214f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall llvm::Value *getExceptionSlot(); 121593c332a8ba2c193c435b293966d343dab15f555bJohn McCall llvm::Value *getEHSelectorSlot(); 1216f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 1217ae270598d5c7a9a283d4b3ddce53b151c6e2b182Bill Wendling /// Returns the contents of the function's exception object and selector 1218ae270598d5c7a9a283d4b3ddce53b151c6e2b182Bill Wendling /// slots. 1219ae270598d5c7a9a283d4b3ddce53b151c6e2b182Bill Wendling llvm::Value *getExceptionFromSlot(); 1220ae270598d5c7a9a283d4b3ddce53b151c6e2b182Bill Wendling llvm::Value *getSelectorFromSlot(); 1221ae270598d5c7a9a283d4b3ddce53b151c6e2b182Bill Wendling 1222ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall llvm::Value *getNormalCleanupDestSlot(); 1223ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall 1224f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall llvm::BasicBlock *getUnreachableBlock() { 1225f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall if (!UnreachableBlock) { 1226f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall UnreachableBlock = createBasicBlock("unreachable"); 1227f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall new llvm::UnreachableInst(getLLVMContext(), UnreachableBlock); 1228f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall } 1229f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall return UnreachableBlock; 1230f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall } 1231f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 1232f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall llvm::BasicBlock *getInvokeDest() { 1233f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall if (!EHStack.requiresLandingPad()) return 0; 1234f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall return getInvokeDestImpl(); 1235f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall } 12369834ffbe54788239c8361d3cfe5826fd277ddfb2Daniel Dunbar 1237d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall llvm::LLVMContext &getLLVMContext() { return CGM.getLLVMContext(); } 123869243825cb5c91ec7207256aa57ae327cfaf8cb2Owen Anderson 12399834ffbe54788239c8361d3cfe5826fd277ddfb2Daniel Dunbar //===--------------------------------------------------------------------===// 1240bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall // Cleanups 1241bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall //===--------------------------------------------------------------------===// 1242bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall 1243bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall typedef void Destroyer(CodeGenFunction &CGF, llvm::Value *addr, QualType ty); 1244bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall 12452673c68aa58e277ebc755b71d81aca618cdedbf9John McCall void pushIrregularPartialArrayCleanup(llvm::Value *arrayBegin, 12462673c68aa58e277ebc755b71d81aca618cdedbf9John McCall llvm::Value *arrayEndPointer, 12472673c68aa58e277ebc755b71d81aca618cdedbf9John McCall QualType elementType, 12482673c68aa58e277ebc755b71d81aca618cdedbf9John McCall Destroyer &destroyer); 12492673c68aa58e277ebc755b71d81aca618cdedbf9John McCall void pushRegularPartialArrayCleanup(llvm::Value *arrayBegin, 12502673c68aa58e277ebc755b71d81aca618cdedbf9John McCall llvm::Value *arrayEnd, 12512673c68aa58e277ebc755b71d81aca618cdedbf9John McCall QualType elementType, 12522673c68aa58e277ebc755b71d81aca618cdedbf9John McCall Destroyer &destroyer); 1253bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall 12549928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall void pushDestroy(QualType::DestructionKind dtorKind, 12559928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall llvm::Value *addr, QualType type); 1256bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall void pushDestroy(CleanupKind kind, llvm::Value *addr, QualType type, 12572673c68aa58e277ebc755b71d81aca618cdedbf9John McCall Destroyer &destroyer, bool useEHCleanupForArray); 12582673c68aa58e277ebc755b71d81aca618cdedbf9John McCall void emitDestroy(llvm::Value *addr, QualType type, Destroyer &destroyer, 12592673c68aa58e277ebc755b71d81aca618cdedbf9John McCall bool useEHCleanupForArray); 1260a91f6661c4685fecee6dc09bdaef73254c1aaa06John McCall llvm::Function *generateDestroyHelper(llvm::Constant *addr, 1261a91f6661c4685fecee6dc09bdaef73254c1aaa06John McCall QualType type, 1262a91f6661c4685fecee6dc09bdaef73254c1aaa06John McCall Destroyer &destroyer, 1263a91f6661c4685fecee6dc09bdaef73254c1aaa06John McCall bool useEHCleanupForArray); 1264bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall void emitArrayDestroy(llvm::Value *begin, llvm::Value *end, 12652673c68aa58e277ebc755b71d81aca618cdedbf9John McCall QualType type, Destroyer &destroyer, 1266fbf780a9d1dbb191fc40c8af967c590e08724b74John McCall bool checkZeroLength, bool useEHCleanup); 1267bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall 12689928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall Destroyer &getDestroyer(QualType::DestructionKind destructionKind); 12699928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall 1270bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall /// Determines whether an EH cleanup is required to destroy a type 1271bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall /// with the given destruction kind. 1272bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall bool needsEHCleanup(QualType::DestructionKind kind) { 1273bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall switch (kind) { 1274bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall case QualType::DK_none: 1275bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall return false; 1276bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall case QualType::DK_cxx_destructor: 1277bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall case QualType::DK_objc_weak_lifetime: 1278bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall return getLangOptions().Exceptions; 1279bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall case QualType::DK_objc_strong_lifetime: 1280bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall return getLangOptions().Exceptions && 1281bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall CGM.getCodeGenOpts().ObjCAutoRefCountExceptions; 1282bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall } 1283bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall llvm_unreachable("bad destruction kind"); 1284bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall } 1285bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall 12869928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall CleanupKind getCleanupKind(QualType::DestructionKind kind) { 12879928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall return (needsEHCleanup(kind) ? NormalAndEHCleanup : NormalCleanup); 12889928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall } 12899928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall 1290bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall //===--------------------------------------------------------------------===// 12919834ffbe54788239c8361d3cfe5826fd277ddfb2Daniel Dunbar // Objective-C 12929834ffbe54788239c8361d3cfe5826fd277ddfb2Daniel Dunbar //===--------------------------------------------------------------------===// 12939834ffbe54788239c8361d3cfe5826fd277ddfb2Daniel Dunbar 1294391d77a26382dddf25da73e29fc1fa5aaaea4c6fChris Lattner void GenerateObjCMethod(const ObjCMethodDecl *OMD); 1295af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar 12960dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump void StartObjCMethod(const ObjCMethodDecl *MD, 12978d3f8979e46f9d0b8735566eabe471db0e1e0e53Devang Patel const ObjCContainerDecl *CD, 12988d3f8979e46f9d0b8735566eabe471db0e1e0e53Devang Patel SourceLocation StartLoc); 1299af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar 13000dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// GenerateObjCGetter - Synthesize an Objective-C property getter function. 1301fef30b55230064d334a669a065a1c9acdb87cdfeFariborz Jahanian void GenerateObjCGetter(ObjCImplementationDecl *IMP, 1302fef30b55230064d334a669a065a1c9acdb87cdfeFariborz Jahanian const ObjCPropertyImplDecl *PID); 13031e1f4871535f2cadcbf8c9af8cc48a2213192320John McCall void generateObjCGetterBody(const ObjCImplementationDecl *classImpl, 13041e1f4871535f2cadcbf8c9af8cc48a2213192320John McCall const ObjCPropertyImplDecl *propImpl); 13052846b97965e980ad2e7c8d444b82cc21d733a699Fariborz Jahanian 1306109dfc6ca6652f60c55ed0f2631aebf323d0200dFariborz Jahanian void GenerateObjCCtorDtorMethod(ObjCImplementationDecl *IMP, 1307109dfc6ca6652f60c55ed0f2631aebf323d0200dFariborz Jahanian ObjCMethodDecl *MD, bool ctor); 1308af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar 13090dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// GenerateObjCSetter - Synthesize an Objective-C property setter function 13100dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// for the given property. 1311fef30b55230064d334a669a065a1c9acdb87cdfeFariborz Jahanian void GenerateObjCSetter(ObjCImplementationDecl *IMP, 1312fef30b55230064d334a669a065a1c9acdb87cdfeFariborz Jahanian const ObjCPropertyImplDecl *PID); 131371c758d3f4ecc8b511e6ae4a7210486aa994c182John McCall void generateObjCSetterBody(const ObjCImplementationDecl *classImpl, 131471c758d3f4ecc8b511e6ae4a7210486aa994c182John McCall const ObjCPropertyImplDecl *propImpl); 13150b2bd47151ee9205ad6c66d1ffb921918106088aFariborz Jahanian bool IndirectObjCSetterArg(const CGFunctionInfo &FI); 131615bd58842adaa4f8cca4e58047ed18e033858d9bFariborz Jahanian bool IvarTypeWithAggrGCObjects(QualType Ty); 1317af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar 13184e7a1f7682d94811bd41fca8aefccc38f686db23Mike Stump //===--------------------------------------------------------------------===// 13194e7a1f7682d94811bd41fca8aefccc38f686db23Mike Stump // Block Bits 13204e7a1f7682d94811bd41fca8aefccc38f686db23Mike Stump //===--------------------------------------------------------------------===// 13214e7a1f7682d94811bd41fca8aefccc38f686db23Mike Stump 13226b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall llvm::Value *EmitBlockLiteral(const BlockExpr *); 13231a343ebbf413e8eae6b2737b2b2d79cbf5765571John McCall llvm::Value *EmitBlockLiteral(const CGBlockInfo &Info); 13241a343ebbf413e8eae6b2737b2b2d79cbf5765571John McCall static void destroyBlockInfos(CGBlockInfo *info); 13252a7eb28397148079cbc8e54e8a3871ef01c4f4bcBlaine Garst llvm::Constant *BuildDescriptorBlockDecl(const BlockExpr *, 132689ecd41e0a6bfb3b0913dbe41c3c666340b308c7Fariborz Jahanian const CGBlockInfo &Info, 13272acc6e3feda5e4f7d9009bdcf8b1cd777fecfe2dChris Lattner llvm::StructType *, 1328d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall llvm::Constant *BlockVarLayout); 13294e7a1f7682d94811bd41fca8aefccc38f686db23Mike Stump 1330564360be450b319aeafc26698be9811837bfb826Fariborz Jahanian llvm::Function *GenerateBlockFunction(GlobalDecl GD, 13316b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall const CGBlockInfo &Info, 13326cc88f78fd36d3511b89412b193494b3e423cbffMike Stump const Decl *OuterFuncDecl, 13336b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall const DeclMapTy &ldm); 13344e7a1f7682d94811bd41fca8aefccc38f686db23Mike Stump 1335d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall llvm::Constant *GenerateCopyHelperFunction(const CGBlockInfo &blockInfo); 1336d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall llvm::Constant *GenerateDestroyHelperFunction(const CGBlockInfo &blockInfo); 1337d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall 1338d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall void BuildBlockRelease(llvm::Value *DeclPtr, BlockFieldFlags flags); 1339d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall 13405af02db5a48476e0748f135369663080eae87c64John McCall class AutoVarEmission; 13415af02db5a48476e0748f135369663080eae87c64John McCall 13425af02db5a48476e0748f135369663080eae87c64John McCall void emitByrefStructureInit(const AutoVarEmission &emission); 13435af02db5a48476e0748f135369663080eae87c64John McCall void enterByrefCleanup(const AutoVarEmission &emission); 13445af02db5a48476e0748f135369663080eae87c64John McCall 13456b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall llvm::Value *LoadBlockStruct() { 13466b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall assert(BlockPointer && "no block pointer set!"); 13476b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall return BlockPointer; 13486b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall } 13494e7a1f7682d94811bd41fca8aefccc38f686db23Mike Stump 1350ea1471e0e967548c596a71469702f8846dbaf3c0John McCall void AllocateBlockCXXThisPointer(const CXXThisExpr *E); 1351ea1471e0e967548c596a71469702f8846dbaf3c0John McCall void AllocateBlockDecl(const BlockDeclRefExpr *E); 1352ee5042903d53fa7b0fbc1902d0ea07d57c7775b1John McCall llvm::Value *GetAddrOfBlockDecl(const BlockDeclRefExpr *E) { 1353ee5042903d53fa7b0fbc1902d0ea07d57c7775b1John McCall return GetAddrOfBlockDecl(E->getDecl(), E->isByRef()); 1354ee5042903d53fa7b0fbc1902d0ea07d57c7775b1John McCall } 13556b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall llvm::Value *GetAddrOfBlockDecl(const VarDecl *var, bool ByRef); 13562acc6e3feda5e4f7d9009bdcf8b1cd777fecfe2dChris Lattner llvm::Type *BuildByRefType(const VarDecl *var); 1357dab514fc30242c7afd6c03956e46136c400fb0d3Mike Stump 1358d26bc76c98006609002d9930f8840490e88ac5b5John McCall void GenerateCode(GlobalDecl GD, llvm::Function *Fn, 1359d26bc76c98006609002d9930f8840490e88ac5b5John McCall const CGFunctionInfo &FnInfo); 13600ff8bafde95f6fa51ccea70738c1b99db870bddcAnders Carlsson void StartFunction(GlobalDecl GD, QualType RetTy, 13617c086516f3cc9fba2733b1919973206c6ba4b171Daniel Dunbar llvm::Function *Fn, 1362d26bc76c98006609002d9930f8840490e88ac5b5John McCall const CGFunctionInfo &FnInfo, 13632284ac9ec80299fcdefae9a2787cf85105a0f203Daniel Dunbar const FunctionArgList &Args, 13649c6082fe89c61af697f017aa80937581cc2128d8Tilmann Scheller SourceLocation StartLoc); 1365a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar 13669fc6a7774643a810c8501dae2323e863fefb623eJohn McCall void EmitConstructorBody(FunctionArgList &Args); 13679fc6a7774643a810c8501dae2323e863fefb623eJohn McCall void EmitDestructorBody(FunctionArgList &Args); 13689fc6a7774643a810c8501dae2323e863fefb623eJohn McCall void EmitFunctionBody(FunctionArgList &Args); 1369a355e07454463b19829ac92ffd115a097faff0e0John McCall 13700dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// EmitReturnBlock - Emit the unified return block, trying to avoid its 13710dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// emission when possible. 13721c1d6074f5a0296dd273362655b1b8f9057289e3Daniel Dunbar void EmitReturnBlock(); 13731c1d6074f5a0296dd273362655b1b8f9057289e3Daniel Dunbar 13740dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// FinishFunction - Complete IR generation of the current function. It is 13750dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// legal to call this function even if there is no current insertion point. 1376af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar void FinishFunction(SourceLocation EndLoc=SourceLocation()); 137717b708d61827cd86278e9580b041dd6cbadf07d3Daniel Dunbar 1378519c32880b99396034ecaedc0cd86db2e8485003Anders Carlsson /// GenerateThunk - Generate a thunk for the given method. 1379d26bc76c98006609002d9930f8840490e88ac5b5John McCall void GenerateThunk(llvm::Function *Fn, const CGFunctionInfo &FnInfo, 1380d26bc76c98006609002d9930f8840490e88ac5b5John McCall GlobalDecl GD, const ThunkInfo &Thunk); 13819cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer 13827dcdf5ba9324a9577461eae302e88fdd52e310c5Eli Friedman void GenerateVarArgsThunk(llvm::Function *Fn, const CGFunctionInfo &FnInfo, 13837dcdf5ba9324a9577461eae302e88fdd52e310c5Eli Friedman GlobalDecl GD, const ThunkInfo &Thunk); 13847dcdf5ba9324a9577461eae302e88fdd52e310c5Eli Friedman 1385fb8cc253420e93cee33d29df5a2bdae6aaf16e39Douglas Gregor void EmitCtorPrologue(const CXXConstructorDecl *CD, CXXCtorType Type, 1386fb8cc253420e93cee33d29df5a2bdae6aaf16e39Douglas Gregor FunctionArgList &Args); 13871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1388d103f9f9b401b419e756f8c1849683cd77586067Anders Carlsson /// InitializeVTablePointer - Initialize the vtable pointer of the given 1389d103f9f9b401b419e756f8c1849683cd77586067Anders Carlsson /// subobject. 1390d103f9f9b401b419e756f8c1849683cd77586067Anders Carlsson /// 13919cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer void InitializeVTablePointer(BaseSubobject Base, 1392b3b772ea15a4cd54879e244629aa685ead9548bbAnders Carlsson const CXXRecordDecl *NearestVBase, 1393d6fb21fa1053e5d616af55b181bb03c50d4b0d24Ken Dyck CharUnits OffsetFromNearestVBase, 1394d103f9f9b401b419e756f8c1849683cd77586067Anders Carlsson llvm::Constant *VTable, 1395d103f9f9b401b419e756f8c1849683cd77586067Anders Carlsson const CXXRecordDecl *VTableClass); 1396d103f9f9b401b419e756f8c1849683cd77586067Anders Carlsson 1397d103f9f9b401b419e756f8c1849683cd77586067Anders Carlsson typedef llvm::SmallPtrSet<const CXXRecordDecl *, 4> VisitedVirtualBasesSetTy; 13989cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer void InitializeVTablePointers(BaseSubobject Base, 1399b3b772ea15a4cd54879e244629aa685ead9548bbAnders Carlsson const CXXRecordDecl *NearestVBase, 1400d6fb21fa1053e5d616af55b181bb03c50d4b0d24Ken Dyck CharUnits OffsetFromNearestVBase, 1401603d6d12cc4cba1ef219a3d55c698c7c87f87adfAnders Carlsson bool BaseIsNonVirtualPrimaryBase, 1402603d6d12cc4cba1ef219a3d55c698c7c87f87adfAnders Carlsson llvm::Constant *VTable, 1403603d6d12cc4cba1ef219a3d55c698c7c87f87adfAnders Carlsson const CXXRecordDecl *VTableClass, 1404603d6d12cc4cba1ef219a3d55c698c7c87f87adfAnders Carlsson VisitedVirtualBasesSetTy& VBases); 140577a259c6dbf582949af8a243b472c0c7faa373a6Eli Friedman 1406603d6d12cc4cba1ef219a3d55c698c7c87f87adfAnders Carlsson void InitializeVTablePointers(const CXXRecordDecl *ClassDecl); 1407d103f9f9b401b419e756f8c1849683cd77586067Anders Carlsson 1408043fb9a1fc0609285f60f0f87e5a18195408f34cDan Gohman /// GetVTablePtr - Return the Value of the vtable pointer member pointed 1409043fb9a1fc0609285f60f0f87e5a18195408f34cDan Gohman /// to by This. 14102acc6e3feda5e4f7d9009bdcf8b1cd777fecfe2dChris Lattner llvm::Value *GetVTablePtr(llvm::Value *This, llvm::Type *Ty); 1411d103f9f9b401b419e756f8c1849683cd77586067Anders Carlsson 141250da2cadcc6da86abff6772de65280ace2cabc94John McCall /// EnterDtorCleanups - Enter the cleanups necessary to complete the 141350da2cadcc6da86abff6772de65280ace2cabc94John McCall /// given phase of destruction for a destructor. The end result 141450da2cadcc6da86abff6772de65280ace2cabc94John McCall /// should call destructors on members and base classes in reverse 141550da2cadcc6da86abff6772de65280ace2cabc94John McCall /// order of their construction. 141650da2cadcc6da86abff6772de65280ace2cabc94John McCall void EnterDtorCleanups(const CXXDestructorDecl *Dtor, CXXDtorType Type); 14171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 14187255a2d997b15beae82e627052fdb1b2474495c2Chris Lattner /// ShouldInstrumentFunction - Return true if the current function should be 14197255a2d997b15beae82e627052fdb1b2474495c2Chris Lattner /// instrumented with __cyg_profile_func_* calls 14207255a2d997b15beae82e627052fdb1b2474495c2Chris Lattner bool ShouldInstrumentFunction(); 14217255a2d997b15beae82e627052fdb1b2474495c2Chris Lattner 14227255a2d997b15beae82e627052fdb1b2474495c2Chris Lattner /// EmitFunctionInstrumentation - Emit LLVM code to call the specified 14237255a2d997b15beae82e627052fdb1b2474495c2Chris Lattner /// instrumentation function with the current function and the call site, if 14247255a2d997b15beae82e627052fdb1b2474495c2Chris Lattner /// function instrumentation is enabled. 14257255a2d997b15beae82e627052fdb1b2474495c2Chris Lattner void EmitFunctionInstrumentation(const char *Fn); 14267255a2d997b15beae82e627052fdb1b2474495c2Chris Lattner 1427be4c8705e499b55548467eb7adaa23cbc6edfef9Roman Divacky /// EmitMCountInstrumentation - Emit call to .mcount. 1428be4c8705e499b55548467eb7adaa23cbc6edfef9Roman Divacky void EmitMCountInstrumentation(); 1429be4c8705e499b55548467eb7adaa23cbc6edfef9Roman Divacky 14300dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// EmitFunctionProlog - Emit the target specific LLVM code to load the 14310dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// arguments for the given function. This is also responsible for naming the 14320dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// LLVM function arguments. 143388b5396b0897f28d22ae3debf4a0d97b33b6c362Daniel Dunbar void EmitFunctionProlog(const CGFunctionInfo &FI, 143488b5396b0897f28d22ae3debf4a0d97b33b6c362Daniel Dunbar llvm::Function *Fn, 143517b708d61827cd86278e9580b041dd6cbadf07d3Daniel Dunbar const FunctionArgList &Args); 143617b708d61827cd86278e9580b041dd6cbadf07d3Daniel Dunbar 14370dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// EmitFunctionEpilog - Emit the target specific LLVM code to return the 14380dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// given temporary. 143935b21b884e5c3447a52a74d7ffaba966b07ac81fChris Lattner void EmitFunctionEpilog(const CGFunctionInfo &FI); 144017b708d61827cd86278e9580b041dd6cbadf07d3Daniel Dunbar 1441cce3d4f9812182ed4e551b7cf0fc86576be8d9c5Mike Stump /// EmitStartEHSpec - Emit the start of the exception spec. 1442cce3d4f9812182ed4e551b7cf0fc86576be8d9c5Mike Stump void EmitStartEHSpec(const Decl *D); 1443cce3d4f9812182ed4e551b7cf0fc86576be8d9c5Mike Stump 1444cce3d4f9812182ed4e551b7cf0fc86576be8d9c5Mike Stump /// EmitEndEHSpec - Emit the end of the exception spec. 1445cce3d4f9812182ed4e551b7cf0fc86576be8d9c5Mike Stump void EmitEndEHSpec(const Decl *D); 1446cce3d4f9812182ed4e551b7cf0fc86576be8d9c5Mike Stump 1447f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// getTerminateLandingPad - Return a landing pad that just calls terminate. 1448f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall llvm::BasicBlock *getTerminateLandingPad(); 1449f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 1450f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// getTerminateHandler - Return a handler (not a landing pad, just 1451f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// a catch handler) that just calls terminate. This is used when 1452f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// a terminate scope encloses a try. 14539b39c51ae3c547568ac42325f94b4197618f6b18Mike Stump llvm::BasicBlock *getTerminateHandler(); 14549b39c51ae3c547568ac42325f94b4197618f6b18Mike Stump 14559cbe4f0ba01ec304e1e3d071c071f7bca33631c0Chris Lattner llvm::Type *ConvertTypeForMem(QualType T); 14569cbe4f0ba01ec304e1e3d071c071f7bca33631c0Chris Lattner llvm::Type *ConvertType(QualType T); 14579cbe4f0ba01ec304e1e3d071c071f7bca33631c0Chris Lattner llvm::Type *ConvertType(const TypeDecl *T) { 1458bff225ecf77fb891596ecb1b27196310d268365eJohn McCall return ConvertType(getContext().getTypeDeclType(T)); 1459bff225ecf77fb891596ecb1b27196310d268365eJohn McCall } 1460c8aa5f1f264fb230c38182adab944232bb160c2bChris Lattner 14610dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// LoadObjCSelf - Load the value of self. This function is only valid while 14620dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// generating code for an Objective-C method. 1463c8aa5f1f264fb230c38182adab944232bb160c2bChris Lattner llvm::Value *LoadObjCSelf(); 14640dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 14650dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// TypeOfSelfObject - Return type of object that this self represents. 146645012a7ef5abf1042c893f3f2fa5c23cb5485ea9Fariborz Jahanian QualType TypeOfSelfObject(); 14674111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner 14685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// hasAggregateLLVMType - Return true if the specified AST type will map into 14695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// an aggregate LLVM type or is void. 14705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool hasAggregateLLVMType(QualType T); 147155e874299f2ad827646a4ca9ea38c402aaeb38c9Daniel Dunbar 147255e874299f2ad827646a4ca9ea38c402aaeb38c9Daniel Dunbar /// createBasicBlock - Create an LLVM basic block. 1473686775deca8b8685eb90801495880e3abdd844c2Chris Lattner llvm::BasicBlock *createBasicBlock(StringRef name = "", 1474d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall llvm::Function *parent = 0, 1475d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall llvm::BasicBlock *before = 0) { 147629ea6729155c759836be4b5453bee9ef8e1e97eeDaniel Dunbar#ifdef NDEBUG 1477d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall return llvm::BasicBlock::Create(getLLVMContext(), "", parent, before); 147829ea6729155c759836be4b5453bee9ef8e1e97eeDaniel Dunbar#else 1479d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall return llvm::BasicBlock::Create(getLLVMContext(), name, parent, before); 148029ea6729155c759836be4b5453bee9ef8e1e97eeDaniel Dunbar#endif 148155e874299f2ad827646a4ca9ea38c402aaeb38c9Daniel Dunbar } 14820dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 14835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getBasicBlockForLabel - Return the LLVM basicblock that the specified 14845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// label maps to. 1485ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner JumpDest getJumpDestForLabel(const LabelDecl *S); 14860dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 1487f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump /// SimplifyForwardingBlocks - If the given basic block is only a branch to 1488f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump /// another basic block, simplify it. This assumes that no other code could 1489f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump /// potentially reference the basic block. 1490aa5bd87f1fd5f9ca47924248817c89325759b30eDaniel Dunbar void SimplifyForwardingBlocks(llvm::BasicBlock *BB); 1491aa5bd87f1fd5f9ca47924248817c89325759b30eDaniel Dunbar 14920dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// EmitBlock - Emit the given block \arg BB and set it as the insert point, 14930dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// adding a fall-through branch from the current insert block if 14940dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// necessary. It is legal to call this function even if there is no current 14950dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// insertion point. 1496a0c21a8faa79e88ac432d116eca58f7a7217195dDaniel Dunbar /// 14970dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// IsFinished - If true, indicates that the caller has finished emitting 14980dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// branches to the given block and does not expect to emit code into it. This 14990dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// means the block can be ignored if it is unreachable. 1500a0c21a8faa79e88ac432d116eca58f7a7217195dDaniel Dunbar void EmitBlock(llvm::BasicBlock *BB, bool IsFinished=false); 1501824e3bd76b2e32db2ec6e4d2d113413e518d1c63Daniel Dunbar 1502777d6e56ad9b1fed9866daf3ee6486d85c5b7d32John McCall /// EmitBlockAfterUses - Emit the given block somewhere hopefully 1503777d6e56ad9b1fed9866daf3ee6486d85c5b7d32John McCall /// near its uses, and leave the insertion point in it. 1504777d6e56ad9b1fed9866daf3ee6486d85c5b7d32John McCall void EmitBlockAfterUses(llvm::BasicBlock *BB); 1505777d6e56ad9b1fed9866daf3ee6486d85c5b7d32John McCall 15060dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// EmitBranch - Emit a branch to the specified basic block from the current 15070dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// insert block, taking care to avoid creation of branches from dummy 15080dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// blocks. It is legal to call this function even if there is no current 15090dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// insertion point. 15105e08ad3cc62ab94649959ae227a9a411a729bf49Daniel Dunbar /// 15110dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// This function clears the current insertion point. The caller should follow 15120dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// calls to this function with calls to Emit*Block prior to generation new 15130dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// code. 1514d57a871339c7c98d58d93108b806f59bdf4e13e2Daniel Dunbar void EmitBranch(llvm::BasicBlock *Block); 1515d57a871339c7c98d58d93108b806f59bdf4e13e2Daniel Dunbar 15160dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// HaveInsertPoint - True if an insertion point is defined. If not, this 15170dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// indicates that the current code being emitted is unreachable. 15180dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump bool HaveInsertPoint() const { 1519a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar return Builder.GetInsertBlock() != 0; 1520a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar } 1521a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar 15220dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// EnsureInsertPoint - Ensure that an insertion point is defined so that 15230dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// emitted IR has a place to go. Note that by definition, if this function 15240dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// creates a block then that block is unreachable; callers may do better to 15250dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// detect when no insertion point is defined and simply skip IR generation. 1526a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar void EnsureInsertPoint() { 1527a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar if (!HaveInsertPoint()) 1528a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar EmitBlock(createBasicBlock()); 1529a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar } 15300dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 1531488e993a135ce700b982bf099c3d6b856301d642Daniel Dunbar /// ErrorUnsupported - Print out an error that codegen doesn't support the 1532dc5e8268292046114ffe02e48773572a91a310f1Chris Lattner /// specified stmt yet. 153390df4b6661968a84bf64baee489bb2f6d948fcc1Daniel Dunbar void ErrorUnsupported(const Stmt *S, const char *Type, 153490df4b6661968a84bf64baee489bb2f6d948fcc1Daniel Dunbar bool OmitOnError=false); 15355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 15365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 15375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Helpers 15385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 15390dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 1540983e3d7dac99aed376939f1a4daadef98e09c3b9Daniel Dunbar LValue MakeAddrLValue(llvm::Value *V, QualType T, unsigned Alignment = 0) { 15413d5aff5d3036b0ff09d114857cd2276134b3d8c9Dan Gohman return LValue::MakeAddr(V, T, Alignment, getContext(), 15423d5aff5d3036b0ff09d114857cd2276134b3d8c9Dan Gohman CGM.getTBAAInfo(T)); 15432f77b3d57031ded0de2b7b977fb63b4660f82624Eli Friedman } 15442f77b3d57031ded0de2b7b977fb63b4660f82624Eli Friedman LValue MakeNaturalAlignAddrLValue(llvm::Value *V, QualType T) { 15452f77b3d57031ded0de2b7b977fb63b4660f82624Eli Friedman unsigned Alignment; 15462f77b3d57031ded0de2b7b977fb63b4660f82624Eli Friedman if (T->isIncompleteType()) 15472f77b3d57031ded0de2b7b977fb63b4660f82624Eli Friedman Alignment = 0; 15482f77b3d57031ded0de2b7b977fb63b4660f82624Eli Friedman else 15492f77b3d57031ded0de2b7b977fb63b4660f82624Eli Friedman Alignment = getContext().getTypeAlignInChars(T).getQuantity(); 15502f77b3d57031ded0de2b7b977fb63b4660f82624Eli Friedman return LValue::MakeAddr(V, T, Alignment, getContext(), 15512f77b3d57031ded0de2b7b977fb63b4660f82624Eli Friedman CGM.getTBAAInfo(T)); 15525cf8bfec711116b3c4acc70a00717b2e119e7550Daniel Dunbar } 15535cf8bfec711116b3c4acc70a00717b2e119e7550Daniel Dunbar 15545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// CreateTempAlloca - This creates a alloca and inserts it into the entry 1555195337d2e5d4625ae9dc1328c7cdbc7115b0261bDaniel Dunbar /// block. The caller is responsible for setting an appropriate alignment on 1556195337d2e5d4625ae9dc1328c7cdbc7115b0261bDaniel Dunbar /// the alloca. 15572acc6e3feda5e4f7d9009bdcf8b1cd777fecfe2dChris Lattner llvm::AllocaInst *CreateTempAlloca(llvm::Type *Ty, 15588cc488fefb2fb04bc8d5398da29f0182f97934cfChris Lattner const Twine &Name = "tmp"); 15590dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 1560ac418162692a951ca3796d6830496a85a2d12493John McCall /// InitTempAlloca - Provide an initial value for the given alloca. 1561ac418162692a951ca3796d6830496a85a2d12493John McCall void InitTempAlloca(llvm::AllocaInst *Alloca, llvm::Value *Value); 1562ac418162692a951ca3796d6830496a85a2d12493John McCall 15639bd4da2cfa8b956b851200db8f9a37e175edbb15Daniel Dunbar /// CreateIRTemp - Create a temporary IR object of the given type, with 15649bd4da2cfa8b956b851200db8f9a37e175edbb15Daniel Dunbar /// appropriate alignment. This routine should only be used when an temporary 15659bd4da2cfa8b956b851200db8f9a37e175edbb15Daniel Dunbar /// value needs to be stored into an alloca (for example, to avoid explicit 15669bd4da2cfa8b956b851200db8f9a37e175edbb15Daniel Dunbar /// PHI construction), but the type is the IR type, not the type appropriate 15679bd4da2cfa8b956b851200db8f9a37e175edbb15Daniel Dunbar /// for storing in memory. 15688cc488fefb2fb04bc8d5398da29f0182f97934cfChris Lattner llvm::AllocaInst *CreateIRTemp(QualType T, const Twine &Name = "tmp"); 15699bd4da2cfa8b956b851200db8f9a37e175edbb15Daniel Dunbar 1570195337d2e5d4625ae9dc1328c7cdbc7115b0261bDaniel Dunbar /// CreateMemTemp - Create a temporary memory object of the given type, with 1571195337d2e5d4625ae9dc1328c7cdbc7115b0261bDaniel Dunbar /// appropriate alignment. 15728cc488fefb2fb04bc8d5398da29f0182f97934cfChris Lattner llvm::AllocaInst *CreateMemTemp(QualType T, const Twine &Name = "tmp"); 1573195337d2e5d4625ae9dc1328c7cdbc7115b0261bDaniel Dunbar 1574558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall /// CreateAggTemp - Create a temporary memory object for the given 1575558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall /// aggregate type. 15768cc488fefb2fb04bc8d5398da29f0182f97934cfChris Lattner AggValueSlot CreateAggTemp(QualType T, const Twine &Name = "tmp") { 1577f85e193739c953358c865005855253af4f68a497John McCall return AggValueSlot::forAddr(CreateMemTemp(T, Name), T.getQualifiers(), 15787c2349be2d11143a2e59a167fd43362a3bf4585eJohn McCall AggValueSlot::IsNotDestructed, 1579410ffb2bc5f072d58a73c14560345bcf77dec1ccJohn McCall AggValueSlot::DoesNotNeedGCBarriers, 1580410ffb2bc5f072d58a73c14560345bcf77dec1ccJohn McCall AggValueSlot::IsNotAliased); 1581558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall } 1582558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall 1583d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall /// Emit a cast to void* in the appropriate address space. 1584d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall llvm::Value *EmitCastToVoidPtr(llvm::Value *value); 1585d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall 15865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// EvaluateExprAsBool - Perform the usual unary conversions on the specified 15875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// expression and compare the result against zero, returning an Int1Ty value. 15885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer llvm::Value *EvaluateExprAsBool(const Expr *E); 15895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 15902a41637a995affa1563f4d82a8b026e326a2faa0John McCall /// EmitIgnoredExpr - Emit an expression in a context which ignores the result. 15912a41637a995affa1563f4d82a8b026e326a2faa0John McCall void EmitIgnoredExpr(const Expr *E); 15922a41637a995affa1563f4d82a8b026e326a2faa0John McCall 15939b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner /// EmitAnyExpr - Emit code to compute the specified expression which can have 15949b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner /// any type. The result is returned as an RValue struct. If this is an 15959b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner /// aggregate expression, the aggloc/agglocvolatile arguments indicate where 15969b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner /// the result should be returned. 159749d1cd5a09ed3df353371fd7f206674a85e0fb45Mike Stump /// 159849d1cd5a09ed3df353371fd7f206674a85e0fb45Mike Stump /// \param IgnoreResult - True if the resulting value isn't used. 1599558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall RValue EmitAnyExpr(const Expr *E, 1600558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall AggValueSlot AggSlot = AggValueSlot::ignored(), 1601558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall bool IgnoreResult = false); 1602d9363c3a80168283b3da518b4e17f545a6246857Devang Patel 16030dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump // EmitVAListRef - Emit a "reference" to a va_list; this is either the address 16040dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump // or the value of the expression, depending on how va_list is defined. 16054fd0aa5803357d8c72eeac2cae15e12649ea08feEli Friedman llvm::Value *EmitVAListRef(const Expr *E); 16064fd0aa5803357d8c72eeac2cae15e12649ea08feEli Friedman 16070dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// EmitAnyExprToTemp - Similary to EmitAnyExpr(), however, the result will 16080dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// always be accessible even if no aggregate location is provided. 1609558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall RValue EmitAnyExprToTemp(const Expr *E); 161046f45b9bec4a265ad8400a538e5ec3a5683617f1Daniel Dunbar 161160d3365b46eb826fba44483583c0051ac5c41fe3John McCall /// EmitAnyExprToMem - Emits the code necessary to evaluate an 16123d3ec1c099ec8bfac3aa1fb0126fe515b7c7fa05John McCall /// arbitrary expression into the given memory location. 16133d3ec1c099ec8bfac3aa1fb0126fe515b7c7fa05John McCall void EmitAnyExprToMem(const Expr *E, llvm::Value *Location, 1614f85e193739c953358c865005855253af4f68a497John McCall Qualifiers Quals, bool IsInitializer); 16153d3ec1c099ec8bfac3aa1fb0126fe515b7c7fa05John McCall 161660d3365b46eb826fba44483583c0051ac5c41fe3John McCall /// EmitExprAsInit - Emits the code necessary to initialize a 161760d3365b46eb826fba44483583c0051ac5c41fe3John McCall /// location in memory with the given initializer. 1618f85e193739c953358c865005855253af4f68a497John McCall void EmitExprAsInit(const Expr *init, const ValueDecl *D, 1619a07398ed98ea2b55ad7a505a3aab18aed93b149fJohn McCall LValue lvalue, bool capturedByInit); 162060d3365b46eb826fba44483583c0051ac5c41fe3John McCall 162127fe2e6c97a3782a0639d87b460741e8ba5d076dMike Stump /// EmitAggregateCopy - Emit an aggrate copy. 162227fe2e6c97a3782a0639d87b460741e8ba5d076dMike Stump /// 162327fe2e6c97a3782a0639d87b460741e8ba5d076dMike Stump /// \param isVolatile - True iff either the source or the destination is 162427fe2e6c97a3782a0639d87b460741e8ba5d076dMike Stump /// volatile. 16257482d12c345c6391f8956850545e2d4aa7701ce6Daniel Dunbar void EmitAggregateCopy(llvm::Value *DestPtr, llvm::Value *SrcPtr, 162627fe2e6c97a3782a0639d87b460741e8ba5d076dMike Stump QualType EltTy, bool isVolatile=false); 16277482d12c345c6391f8956850545e2d4aa7701ce6Daniel Dunbar 162851b09f2c528c8460b5465c676173324e44176d62Devang Patel /// StartBlock - Start new block named N. If insert block is a dummy block 162951b09f2c528c8460b5465c676173324e44176d62Devang Patel /// then reuse it. 163051b09f2c528c8460b5465c676173324e44176d62Devang Patel void StartBlock(const char *N); 163151b09f2c528c8460b5465c676173324e44176d62Devang Patel 1632813733577d33ec56479667b49e1bff42dc6bba90Lauro Ramos Venancio /// GetAddrOfStaticLocalVar - Return the address of a static local variable. 16334c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall llvm::Constant *GetAddrOfStaticLocalVar(const VarDecl *BVD) { 16344c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall return cast<llvm::Constant>(GetAddrOfLocalVar(BVD)); 16354c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall } 16364f8d123e3e2c260de3377208106ddba87cee28b4Dan Gohman 1637dde0a94120915fa925d1ffcdb997c7b44dc9fa21Anders Carlsson /// GetAddrOfLocalVar - Return the address of a local variable. 16384c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall llvm::Value *GetAddrOfLocalVar(const VarDecl *VD) { 16394c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall llvm::Value *Res = LocalDeclMap[VD]; 16404c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall assert(Res && "Invalid argument to GetAddrOfLocalVar(), no decl!"); 16414c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall return Res; 16424c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall } 16430dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 164456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// getOpaqueLValueMapping - Given an opaque value expression (which 164556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// must be mapped to an l-value), return its mapping. 164656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall const LValue &getOpaqueLValueMapping(const OpaqueValueExpr *e) { 164756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall assert(OpaqueValueMapping::shouldBindAsLValue(e)); 164856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 164956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall llvm::DenseMap<const OpaqueValueExpr*,LValue>::iterator 165056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall it = OpaqueLValues.find(e); 165156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall assert(it != OpaqueLValues.end() && "no mapping for opaque value!"); 165256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return it->second; 165356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 165456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 165556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// getOpaqueRValueMapping - Given an opaque value expression (which 165656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// must be mapped to an r-value), return its mapping. 165756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall const RValue &getOpaqueRValueMapping(const OpaqueValueExpr *e) { 165856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall assert(!OpaqueValueMapping::shouldBindAsLValue(e)); 165956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 166056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall llvm::DenseMap<const OpaqueValueExpr*,RValue>::iterator 166156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall it = OpaqueRValues.find(e); 166256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall assert(it != OpaqueRValues.end() && "no mapping for opaque value!"); 1663e996ffd240f20a1048179d7727a6ee3227261921John McCall return it->second; 1664e996ffd240f20a1048179d7727a6ee3227261921John McCall } 1665e996ffd240f20a1048179d7727a6ee3227261921John McCall 16664f8d123e3e2c260de3377208106ddba87cee28b4Dan Gohman /// getAccessedFieldNo - Given an encoded value and a result number, return 16674f8d123e3e2c260de3377208106ddba87cee28b4Dan Gohman /// the input field number being accessed. 16684f8d123e3e2c260de3377208106ddba87cee28b4Dan Gohman static unsigned getAccessedFieldNo(unsigned Idx, const llvm::Constant *Elts); 16694f8d123e3e2c260de3377208106ddba87cee28b4Dan Gohman 1670ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner llvm::BlockAddress *GetAddrOfLabel(const LabelDecl *L); 16713d00fdc82fd550ae4bfbb2e700a1fc85bbd6d6fdChris Lattner llvm::BasicBlock *GetIndirectGotoBlock(); 16720ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar 16731884eb0b5c55edda4893ddec45e7dbad79758782Anders Carlsson /// EmitNullInitialization - Generate code to set a value of the given type to 16741884eb0b5c55edda4893ddec45e7dbad79758782Anders Carlsson /// null, If the type contains data member pointers, they will be initialized 16751884eb0b5c55edda4893ddec45e7dbad79758782Anders Carlsson /// to -1 in accordance with the Itanium C++ ABI. 16761884eb0b5c55edda4893ddec45e7dbad79758782Anders Carlsson void EmitNullInitialization(llvm::Value *DestPtr, QualType Ty); 1677ddf7cac45d85b73127adbbd91a2b28fc7291c57eAnders Carlsson 1678ddf7cac45d85b73127adbbd91a2b28fc7291c57eAnders Carlsson // EmitVAArg - Generate code to get an argument from the passed in pointer 1679ddf7cac45d85b73127adbbd91a2b28fc7291c57eAnders Carlsson // and update it accordingly. The return value is a pointer to the argument. 1680ddf7cac45d85b73127adbbd91a2b28fc7291c57eAnders Carlsson // FIXME: We should be able to get rid of this method and use the va_arg 16810dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump // instruction in LLVM instead once it works well enough. 1682ddf7cac45d85b73127adbbd91a2b28fc7291c57eAnders Carlsson llvm::Value *EmitVAArg(llvm::Value *VAListAddr, QualType Ty); 1683f666b7780d04186521adcaedb0e15dfa4d5e6933Anders Carlsson 1684bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall /// emitArrayLength - Compute the length of an array, even if it's a 1685bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall /// VLA, and drill down to the base element type. 1686bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall llvm::Value *emitArrayLength(const ArrayType *arrayType, 1687bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall QualType &baseType, 1688bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall llvm::Value *&addr); 1689bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall 1690bc8d40d85f3fa1e34569834916f18fecaa635152John McCall /// EmitVLASize - Capture all the sizes for the VLA expressions in 1691bc8d40d85f3fa1e34569834916f18fecaa635152John McCall /// the given variably-modified type and store them in the VLASizeMap. 1692d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar /// 1693d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar /// This function can be called with a null (unreachable) insert point. 1694bc8d40d85f3fa1e34569834916f18fecaa635152John McCall void EmitVariablyModifiedType(QualType Ty); 1695bc8d40d85f3fa1e34569834916f18fecaa635152John McCall 1696bc8d40d85f3fa1e34569834916f18fecaa635152John McCall /// getVLASize - Returns an LLVM value that corresponds to the size, 1697bc8d40d85f3fa1e34569834916f18fecaa635152John McCall /// in non-variably-sized elements, of a variable length array type, 1698bc8d40d85f3fa1e34569834916f18fecaa635152John McCall /// plus that largest non-variably-sized element type. Assumes that 1699bc8d40d85f3fa1e34569834916f18fecaa635152John McCall /// the type has already been emitted with EmitVariablyModifiedType. 1700bc8d40d85f3fa1e34569834916f18fecaa635152John McCall std::pair<llvm::Value*,QualType> getVLASize(const VariableArrayType *vla); 1701bc8d40d85f3fa1e34569834916f18fecaa635152John McCall std::pair<llvm::Value*,QualType> getVLASize(QualType vla); 1702dcc90d87e6430c643b4311ae5b0089535bca41f7Anders Carlsson 17035f4307b7ba164b03c853c8d3eb4674d33f8967a6Anders Carlsson /// LoadCXXThis - Load the value of 'this'. This function is only valid while 17045f4307b7ba164b03c853c8d3eb4674d33f8967a6Anders Carlsson /// generating code for an C++ member function. 17052504941793b549323f9d29c62507cf21d865fadeJohn McCall llvm::Value *LoadCXXThis() { 17062504941793b549323f9d29c62507cf21d865fadeJohn McCall assert(CXXThisValue && "no 'this' value for this function"); 17072504941793b549323f9d29c62507cf21d865fadeJohn McCall return CXXThisValue; 17082504941793b549323f9d29c62507cf21d865fadeJohn McCall } 17091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1710c997d4278d329e18891aac9698fb991b2d4622ebAnders Carlsson /// LoadCXXVTT - Load the VTT parameter to base constructors/destructors have 1711c997d4278d329e18891aac9698fb991b2d4622ebAnders Carlsson /// virtual bases. 17122504941793b549323f9d29c62507cf21d865fadeJohn McCall llvm::Value *LoadCXXVTT() { 17132504941793b549323f9d29c62507cf21d865fadeJohn McCall assert(CXXVTTValue && "no VTT value for this function"); 17142504941793b549323f9d29c62507cf21d865fadeJohn McCall return CXXVTTValue; 17152504941793b549323f9d29c62507cf21d865fadeJohn McCall } 1716bff225ecf77fb891596ecb1b27196310d268365eJohn McCall 1717bff225ecf77fb891596ecb1b27196310d268365eJohn McCall /// GetAddressOfBaseOfCompleteClass - Convert the given pointer to a 17188561a8666c70f924c8f0209c41b9b77bbbf90607Anders Carlsson /// complete class to the given direct base. 17198561a8666c70f924c8f0209c41b9b77bbbf90607Anders Carlsson llvm::Value * 17208561a8666c70f924c8f0209c41b9b77bbbf90607Anders Carlsson GetAddressOfDirectBaseInCompleteClass(llvm::Value *Value, 17218561a8666c70f924c8f0209c41b9b77bbbf90607Anders Carlsson const CXXRecordDecl *Derived, 17228561a8666c70f924c8f0209c41b9b77bbbf90607Anders Carlsson const CXXRecordDecl *Base, 17238561a8666c70f924c8f0209c41b9b77bbbf90607Anders Carlsson bool BaseIsVirtual); 1724a88ad5618fcb07c5374c79d6781a33234984b039Anders Carlsson 1725f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump /// GetAddressOfBaseClass - This function will add the necessary delta to the 1726f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump /// load of 'this' and returns address of the base class. 17279cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer llvm::Value *GetAddressOfBaseClass(llvm::Value *Value, 17288561a8666c70f924c8f0209c41b9b77bbbf90607Anders Carlsson const CXXRecordDecl *Derived, 1729f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall CastExpr::path_const_iterator PathBegin, 1730f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall CastExpr::path_const_iterator PathEnd, 173134a2d384c745ebc39cae45dc1c0c4a6a7012e09bAnders Carlsson bool NullCheckValue); 173234a2d384c745ebc39cae45dc1c0c4a6a7012e09bAnders Carlsson 1733a3697c9c155bda93fd2802f37084b620f4738822Anders Carlsson llvm::Value *GetAddressOfDerivedClass(llvm::Value *Value, 17348561a8666c70f924c8f0209c41b9b77bbbf90607Anders Carlsson const CXXRecordDecl *Derived, 1735f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall CastExpr::path_const_iterator PathBegin, 1736f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall CastExpr::path_const_iterator PathEnd, 17375a0f49ebc83e7fe0da07b9964c44b0a7fae270cbAnders Carlsson bool NullCheckValue); 1738a3697c9c155bda93fd2802f37084b620f4738822Anders Carlsson 1739bb7e17b52ffaa4097b4c4d7935746d23539ffe2aAnders Carlsson llvm::Value *GetVirtualBaseClassOffset(llvm::Value *This, 1740bb7e17b52ffaa4097b4c4d7935746d23539ffe2aAnders Carlsson const CXXRecordDecl *ClassDecl, 1741bb7e17b52ffaa4097b4c4d7935746d23539ffe2aAnders Carlsson const CXXRecordDecl *BaseClassDecl); 17429cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer 1743c0bf462cf35fe050bddbd8bff967298e4a67e79dJohn McCall void EmitDelegateCXXConstructorCall(const CXXConstructorDecl *Ctor, 1744c0bf462cf35fe050bddbd8bff967298e4a67e79dJohn McCall CXXCtorType CtorType, 1745c0bf462cf35fe050bddbd8bff967298e4a67e79dJohn McCall const FunctionArgList &Args); 1746059ce0d92eb5a7da900ae735dc0a2ea3d64f4b0bSean Hunt // It's important not to confuse this and the previous function. Delegating 1747059ce0d92eb5a7da900ae735dc0a2ea3d64f4b0bSean Hunt // constructors are the C++0x feature. The constructor delegate optimization 1748059ce0d92eb5a7da900ae735dc0a2ea3d64f4b0bSean Hunt // is used to reduce duplication in the base and complete consturctors where 1749059ce0d92eb5a7da900ae735dc0a2ea3d64f4b0bSean Hunt // they are substantially the same. 1750059ce0d92eb5a7da900ae735dc0a2ea3d64f4b0bSean Hunt void EmitDelegatingCXXConstructorCall(const CXXConstructorDecl *Ctor, 1751059ce0d92eb5a7da900ae735dc0a2ea3d64f4b0bSean Hunt const FunctionArgList &Args); 1752155ed4a23366f4514befb1c9f5f89d16f8b8b6dbAnders Carlsson void EmitCXXConstructorCall(const CXXConstructorDecl *D, CXXCtorType Type, 1753155ed4a23366f4514befb1c9f5f89d16f8b8b6dbAnders Carlsson bool ForVirtualBase, llvm::Value *This, 1754b14095aa98c6fedd3625920c4ce834bcaf24d9f7Anders Carlsson CallExpr::const_arg_iterator ArgBeg, 1755b14095aa98c6fedd3625920c4ce834bcaf24d9f7Anders Carlsson CallExpr::const_arg_iterator ArgEnd); 175634999876e215b22febc240b1a6dc054215d12f9cFariborz Jahanian 175734999876e215b22febc240b1a6dc054215d12f9cFariborz Jahanian void EmitSynthesizedCXXCopyCtorCall(const CXXConstructorDecl *D, 175834999876e215b22febc240b1a6dc054215d12f9cFariborz Jahanian llvm::Value *This, llvm::Value *Src, 175934999876e215b22febc240b1a6dc054215d12f9cFariborz Jahanian CallExpr::const_arg_iterator ArgBeg, 176034999876e215b22febc240b1a6dc054215d12f9cFariborz Jahanian CallExpr::const_arg_iterator ArgEnd); 17611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1762288dcaf329c49b01dacd5c1dd9f35609555feecdFariborz Jahanian void EmitCXXAggrConstructorCall(const CXXConstructorDecl *D, 1763569c1f4a6c703eaa8b963bed7d5c2fd5d4569e93Anders Carlsson const ConstantArrayType *ArrayTy, 17645d4d946ec2d88696fd8422aeb64dc29688e6a2c1Anders Carlsson llvm::Value *ArrayPtr, 17655d4d946ec2d88696fd8422aeb64dc29688e6a2c1Anders Carlsson CallExpr::const_arg_iterator ArgBeg, 176659174c0633fb5cde41735cfbff5744bdf837e8d9Douglas Gregor CallExpr::const_arg_iterator ArgEnd, 176759174c0633fb5cde41735cfbff5744bdf837e8d9Douglas Gregor bool ZeroInitialization = false); 17689cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer 1769569c1f4a6c703eaa8b963bed7d5c2fd5d4569e93Anders Carlsson void EmitCXXAggrConstructorCall(const CXXConstructorDecl *D, 1770569c1f4a6c703eaa8b963bed7d5c2fd5d4569e93Anders Carlsson llvm::Value *NumElements, 17715d4d946ec2d88696fd8422aeb64dc29688e6a2c1Anders Carlsson llvm::Value *ArrayPtr, 17725d4d946ec2d88696fd8422aeb64dc29688e6a2c1Anders Carlsson CallExpr::const_arg_iterator ArgBeg, 177359174c0633fb5cde41735cfbff5744bdf837e8d9Douglas Gregor CallExpr::const_arg_iterator ArgEnd, 177459174c0633fb5cde41735cfbff5744bdf837e8d9Douglas Gregor bool ZeroInitialization = false); 1775b14095aa98c6fedd3625920c4ce834bcaf24d9f7Anders Carlsson 1776bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall static Destroyer destroyCXXObject; 1777bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall 17787267c1693abe7875b0c57268be05005ae013c6c9Anders Carlsson void EmitCXXDestructorCall(const CXXDestructorDecl *D, CXXDtorType Type, 17798e6404ca28d6bbb76e97ea2a53a74816c2a74665Anders Carlsson bool ForVirtualBase, llvm::Value *This); 17809cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer 1781197056726ed6412501130c2ef2ff69009772aa65John McCall void EmitNewArrayInitializer(const CXXNewExpr *E, QualType elementType, 1782197056726ed6412501130c2ef2ff69009772aa65John McCall llvm::Value *NewPtr, llvm::Value *NumElements); 17831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1784f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall void EmitCXXTemporary(const CXXTemporary *Temporary, llvm::Value *Ptr); 17851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1786a00703dccbdc6cc4a293db38477dea7db5538c7eAnders Carlsson llvm::Value *EmitCXXNewExpr(const CXXNewExpr *E); 178760e282cc1e508be327b0481cecedc206873cb86aAnders Carlsson void EmitCXXDeleteExpr(const CXXDeleteExpr *E); 17881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 17894bf8152799ec41796f989ea1b94f6f1bac349117Eli Friedman void EmitDeleteCall(const FunctionDecl *DeleteFD, llvm::Value *Ptr, 17904bf8152799ec41796f989ea1b94f6f1bac349117Eli Friedman QualType DeleteTy); 17914bf8152799ec41796f989ea1b94f6f1bac349117Eli Friedman 1792c2e84ae9a6d25cea3e583c768e576b4c981ec028Mike Stump llvm::Value* EmitCXXTypeidExpr(const CXXTypeidExpr *E); 1793c849c052d6b4b70f2651c1969531861a5f230053Mike Stump llvm::Value *EmitDynamicCast(llvm::Value *V, const CXXDynamicCastExpr *DCE); 1794c2e84ae9a6d25cea3e583c768e576b4c981ec028Mike Stump 1795b14e62d5aee7522b98c410ee65bd750c2cfe6f01Mike Stump void EmitCheck(llvm::Value *, unsigned Size); 1796b14e62d5aee7522b98c410ee65bd750c2cfe6f01Mike Stump 1797dd36d328730d8c02915d0884541b45ec6ca0049dChris Lattner llvm::Value *EmitScalarPrePostIncDec(const UnaryOperator *E, LValue LV, 1798dd36d328730d8c02915d0884541b45ec6ca0049dChris Lattner bool isInc, bool isPre); 1799dd36d328730d8c02915d0884541b45ec6ca0049dChris Lattner ComplexPairTy EmitComplexPrePostIncDec(const UnaryOperator *E, LValue LV, 1800dd36d328730d8c02915d0884541b45ec6ca0049dChris Lattner bool isInc, bool isPre); 18015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 18025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Declaration Emission 18035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 18040dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 1805d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar /// EmitDecl - Emit a declaration. 1806d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar /// 1807d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar /// This function can be called with a null (unreachable) insert point. 18085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void EmitDecl(const Decl &D); 1809d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar 1810b6bbcc9995186799a60ce17d0c1acff31601653aJohn McCall /// EmitVarDecl - Emit a local variable declaration. 1811d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar /// 1812d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar /// This function can be called with a null (unreachable) insert point. 1813b6bbcc9995186799a60ce17d0c1acff31601653aJohn McCall void EmitVarDecl(const VarDecl &D); 1814d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar 1815f85e193739c953358c865005855253af4f68a497John McCall void EmitScalarInit(const Expr *init, const ValueDecl *D, 1816a07398ed98ea2b55ad7a505a3aab18aed93b149fJohn McCall LValue lvalue, bool capturedByInit); 18177acddacc921cd0b3f813443a8641eeddb82dfbd4John McCall void EmitScalarInit(llvm::Value *init, LValue lvalue); 1818f85e193739c953358c865005855253af4f68a497John McCall 1819f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall typedef void SpecialInitFn(CodeGenFunction &Init, const VarDecl &D, 1820f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall llvm::Value *Address); 1821f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 1822b6bbcc9995186799a60ce17d0c1acff31601653aJohn McCall /// EmitAutoVarDecl - Emit an auto variable declaration. 1823d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar /// 1824d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar /// This function can be called with a null (unreachable) insert point. 182534695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall void EmitAutoVarDecl(const VarDecl &D); 182634695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall 182734695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall class AutoVarEmission { 182834695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall friend class CodeGenFunction; 182934695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall 183057b3b6a60856eaec30fd876a8a3face8f7e3ad7bJohn McCall const VarDecl *Variable; 183134695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall 183234695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall /// The alignment of the variable. 183334695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall CharUnits Alignment; 183434695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall 183534695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall /// The address of the alloca. Null if the variable was emitted 183634695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall /// as a global constant. 183734695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall llvm::Value *Address; 183834695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall 183934695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall llvm::Value *NRVOFlag; 184034695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall 184134695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall /// True if the variable is a __block variable. 184234695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall bool IsByRef; 184334695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall 184434695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall /// True if the variable is of aggregate type and has a constant 184534695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall /// initializer. 184634695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall bool IsConstantAggregate; 184734695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall 184857b3b6a60856eaec30fd876a8a3face8f7e3ad7bJohn McCall struct Invalid {}; 184957b3b6a60856eaec30fd876a8a3face8f7e3ad7bJohn McCall AutoVarEmission(Invalid) : Variable(0) {} 185057b3b6a60856eaec30fd876a8a3face8f7e3ad7bJohn McCall 185134695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall AutoVarEmission(const VarDecl &variable) 185257b3b6a60856eaec30fd876a8a3face8f7e3ad7bJohn McCall : Variable(&variable), Address(0), NRVOFlag(0), 185334695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall IsByRef(false), IsConstantAggregate(false) {} 185434695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall 185534695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall bool wasEmittedAsGlobal() const { return Address == 0; } 185634695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall 185734695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall public: 185857b3b6a60856eaec30fd876a8a3face8f7e3ad7bJohn McCall static AutoVarEmission invalid() { return AutoVarEmission(Invalid()); } 185957b3b6a60856eaec30fd876a8a3face8f7e3ad7bJohn McCall 186034695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall /// Returns the address of the object within this declaration. 186134695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall /// Note that this does not chase the forwarding pointer for 186234695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall /// __block decls. 186334695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall llvm::Value *getObjectAddress(CodeGenFunction &CGF) const { 186434695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall if (!IsByRef) return Address; 186534695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall 186634695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall return CGF.Builder.CreateStructGEP(Address, 186757b3b6a60856eaec30fd876a8a3face8f7e3ad7bJohn McCall CGF.getByRefValueLLVMField(Variable), 186857b3b6a60856eaec30fd876a8a3face8f7e3ad7bJohn McCall Variable->getNameAsString()); 186934695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall } 187034695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall }; 187134695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall AutoVarEmission EmitAutoVarAlloca(const VarDecl &var); 187234695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall void EmitAutoVarInit(const AutoVarEmission &emission); 187334695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall void EmitAutoVarCleanups(const AutoVarEmission &emission); 1874bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall void emitAutoVarTypeCleanup(const AutoVarEmission &emission, 1875bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall QualType::DestructionKind dtorKind); 1876d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar 1877b6bbcc9995186799a60ce17d0c1acff31601653aJohn McCall void EmitStaticVarDecl(const VarDecl &D, 1878b6bbcc9995186799a60ce17d0c1acff31601653aJohn McCall llvm::GlobalValue::LinkageTypes Linkage); 1879b7ec246872b412f0e7bb9e93eacfd78cfa6adfb3Daniel Dunbar 1880b7ec246872b412f0e7bb9e93eacfd78cfa6adfb3Daniel Dunbar /// EmitParmDecl - Emit a ParmVarDecl or an ImplicitParamDecl. 1881093ac461b37a573dcf226fa55faed96f318169b9Devang Patel void EmitParmDecl(const VarDecl &D, llvm::Value *Arg, unsigned ArgNo); 18820dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 188356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// protectFromPeepholes - Protect a value that we're intending to 188456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// store to the side, but which will probably be used later, from 188556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// aggressive peepholing optimizations that might delete it. 188656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// 188756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// Pass the result to unprotectFromPeepholes to declare that 188856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// protection is no longer required. 188956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// 189056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// There's no particular reason why this shouldn't apply to 189156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// l-values, it's just that no existing peepholes work on pointers. 189256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall PeepholeProtection protectFromPeepholes(RValue rvalue); 189356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall void unprotectFromPeepholes(PeepholeProtection protection); 189456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 18955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 18965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Statement Emission 18975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 18985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 18990dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// EmitStopPoint - Emit a debug stoppoint if we are emitting debug info. 19000912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar void EmitStopPoint(const Stmt *S); 19010912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar 19020dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// EmitStmt - Emit the code for the statement \arg S. It is legal to call 19030dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// this function even if there is no current insertion point. 19040dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// 19050dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// This function may clear the current insertion point; callers should use 19060dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// EnsureInsertPoint if they wish to subsequently generate code without first 19070dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// calling EmitBlock, EmitBranch, or EmitStmt. 19085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void EmitStmt(const Stmt *S); 1909a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar 19100912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar /// EmitSimpleStmt - Try to emit a "simple" statement which does not 19110dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// necessarily require an insertion point or debug information; typically 19120dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// because the statement amounts to a jump or a container of other 19130dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// statements. 19140912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar /// 19150912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar /// \return True if the statement was handled. 19160912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar bool EmitSimpleStmt(const Stmt *S); 19170912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar 19189b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner RValue EmitCompoundStmt(const CompoundStmt &S, bool GetLast = false, 1919558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall AggValueSlot AVS = AggValueSlot::ignored()); 1920a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar 19210dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// EmitLabel - Emit the block for the given label. It is legal to call this 19220dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// function even if there is no current insertion point. 1923ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner void EmitLabel(const LabelDecl *D); // helper for EmitLabelStmt. 1924a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar 19255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void EmitLabelStmt(const LabelStmt &S); 19265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void EmitGotoStmt(const GotoStmt &S); 19270ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar void EmitIndirectGotoStmt(const IndirectGotoStmt &S); 19285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void EmitIfStmt(const IfStmt &S); 19295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void EmitWhileStmt(const WhileStmt &S); 19305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void EmitDoStmt(const DoStmt &S); 19315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void EmitForStmt(const ForStmt &S); 19325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void EmitReturnStmt(const ReturnStmt &S); 19335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void EmitDeclStmt(const DeclStmt &S); 19340912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar void EmitBreakStmt(const BreakStmt &S); 19350912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar void EmitContinueStmt(const ContinueStmt &S); 193651b09f2c528c8460b5465c676173324e44176d62Devang Patel void EmitSwitchStmt(const SwitchStmt &S); 193751b09f2c528c8460b5465c676173324e44176d62Devang Patel void EmitDefaultStmt(const DefaultStmt &S); 193851b09f2c528c8460b5465c676173324e44176d62Devang Patel void EmitCaseStmt(const CaseStmt &S); 1939c049e4f406a7f7179eba98659044a32508e53289Devang Patel void EmitCaseStmtRange(const CaseStmt &S); 1940fb1aeb804c08d5288a923fb278161783e6abdc66Anders Carlsson void EmitAsmStmt(const AsmStmt &S); 19410dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 19423d8400d9a61aa4b63ff35e5cede405b32a41425eAnders Carlsson void EmitObjCForCollectionStmt(const ObjCForCollectionStmt &S); 194364d5d6c5903157c521af496479d06dc26032d718Anders Carlsson void EmitObjCAtTryStmt(const ObjCAtTryStmt &S); 194464d5d6c5903157c521af496479d06dc26032d718Anders Carlsson void EmitObjCAtThrowStmt(const ObjCAtThrowStmt &S); 194510cac6f7115b59a466bb8d2d51cdddeb38aadc37Chris Lattner void EmitObjCAtSynchronizedStmt(const ObjCAtSynchronizedStmt &S); 1946f85e193739c953358c865005855253af4f68a497John McCall void EmitObjCAutoreleasePoolStmt(const ObjCAutoreleasePoolStmt &S); 19470dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 194893c332a8ba2c193c435b293966d343dab15f555bJohn McCall llvm::Constant *getUnwindResumeFn(); 194986a3a03667bdb0dcab7e6a2877dfd234b07a6d43Douglas Gregor llvm::Constant *getUnwindResumeOrRethrowFn(); 195059a7000a79118e4c140885ccbb2ac6a686a73092John McCall void EnterCXXTryStmt(const CXXTryStmt &S, bool IsFnTryBlock = false); 195159a7000a79118e4c140885ccbb2ac6a686a73092John McCall void ExitCXXTryStmt(const CXXTryStmt &S, bool IsFnTryBlock = false); 19529fc6a7774643a810c8501dae2323e863fefb623eJohn McCall 19536815e941998659a55c20c147861b0f437928c3d8Anders Carlsson void EmitCXXTryStmt(const CXXTryStmt &S); 1954ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith void EmitCXXForRangeStmt(const CXXForRangeStmt &S); 19559cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer 19565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 19575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // LValue Expression Emission 19585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 19595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 196013e81737a433b23f8c662d10d1d57356122a8caaDaniel Dunbar /// GetUndefRValue - Get an appropriate 'undef' rvalue for the given type. 196113e81737a433b23f8c662d10d1d57356122a8caaDaniel Dunbar RValue GetUndefRValue(QualType Ty); 196213e81737a433b23f8c662d10d1d57356122a8caaDaniel Dunbar 1963ce1d38b8163650e473d7084e0686ed5a7956057bDaniel Dunbar /// EmitUnsupportedRValue - Emit a dummy r-value using the type of E 1964ce1d38b8163650e473d7084e0686ed5a7956057bDaniel Dunbar /// and issue an ErrorUnsupported style diagnostic (using the 1965ce1d38b8163650e473d7084e0686ed5a7956057bDaniel Dunbar /// provided Name). 1966ce1d38b8163650e473d7084e0686ed5a7956057bDaniel Dunbar RValue EmitUnsupportedRValue(const Expr *E, 1967ce1d38b8163650e473d7084e0686ed5a7956057bDaniel Dunbar const char *Name); 1968ce1d38b8163650e473d7084e0686ed5a7956057bDaniel Dunbar 19690dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// EmitUnsupportedLValue - Emit a dummy l-value using the type of E and issue 19700dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// an ErrorUnsupported style diagnostic (using the provided Name). 19716ba82a4a4b295e54cf192c3e98b28f39990c6194Daniel Dunbar LValue EmitUnsupportedLValue(const Expr *E, 19726ba82a4a4b295e54cf192c3e98b28f39990c6194Daniel Dunbar const char *Name); 19736ba82a4a4b295e54cf192c3e98b28f39990c6194Daniel Dunbar 19745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// EmitLValue - Emit code to compute a designator that specifies the location 19755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// of the expression. 19765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 19775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// This can return one of two things: a simple address or a bitfield 19785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// reference. In either case, the LLVM Value* in the LValue structure is 19795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// guaranteed to be an LLVM pointer type. 19805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 19815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// If this returns a bitfield reference, nothing about the pointee type of 19825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// the LLVM value is known: For example, it may not be a pointer to an 19835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// integer. 19845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 19855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// If this returns a normal address, and if the lvalue's C type is fixed 19865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// size, this method guarantees that the returned pointer type will point to 19875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// an LLVM type of the same size of the lvalue's type. If the lvalue has a 19885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// variable length type, this is not possible. 19895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 19905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LValue EmitLValue(const Expr *E); 19910dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 1992b14e62d5aee7522b98c410ee65bd750c2cfe6f01Mike Stump /// EmitCheckedLValue - Same as EmitLValue but additionally we generate 1993b14e62d5aee7522b98c410ee65bd750c2cfe6f01Mike Stump /// checking code to guard against undefined behavior. This is only 1994b14e62d5aee7522b98c410ee65bd750c2cfe6f01Mike Stump /// suitable when we know that the address will be used to access the 1995b14e62d5aee7522b98c410ee65bd750c2cfe6f01Mike Stump /// object. 1996b14e62d5aee7522b98c410ee65bd750c2cfe6f01Mike Stump LValue EmitCheckedLValue(const Expr *E); 1997b14e62d5aee7522b98c410ee65bd750c2cfe6f01Mike Stump 199826815d97c5743481e317f17a8d53a6819d061862John McCall /// EmitToMemory - Change a scalar value from its value 199926815d97c5743481e317f17a8d53a6819d061862John McCall /// representation to its in-memory representation. 200026815d97c5743481e317f17a8d53a6819d061862John McCall llvm::Value *EmitToMemory(llvm::Value *Value, QualType Ty); 200126815d97c5743481e317f17a8d53a6819d061862John McCall 200226815d97c5743481e317f17a8d53a6819d061862John McCall /// EmitFromMemory - Change a scalar value from its memory 200326815d97c5743481e317f17a8d53a6819d061862John McCall /// representation to its value representation. 200426815d97c5743481e317f17a8d53a6819d061862John McCall llvm::Value *EmitFromMemory(llvm::Value *Value, QualType Ty); 200526815d97c5743481e317f17a8d53a6819d061862John McCall 20069d9cc874bcc168474757a8f90476684b4a93ed76Daniel Dunbar /// EmitLoadOfScalar - Load a scalar value from an address, taking 20079d9cc874bcc168474757a8f90476684b4a93ed76Daniel Dunbar /// care to appropriately convert from the memory representation to 20089d9cc874bcc168474757a8f90476684b4a93ed76Daniel Dunbar /// the LLVM value representation. 200909429b962811f2c0a7a81a1b0a89f96f5878b20cMike Stump llvm::Value *EmitLoadOfScalar(llvm::Value *Addr, bool Volatile, 20103d5aff5d3036b0ff09d114857cd2276134b3d8c9Dan Gohman unsigned Alignment, QualType Ty, 20113d5aff5d3036b0ff09d114857cd2276134b3d8c9Dan Gohman llvm::MDNode *TBAAInfo = 0); 2012545d996ec5a3113f046944f11b27cc2d6cb055b4John McCall 2013545d996ec5a3113f046944f11b27cc2d6cb055b4John McCall /// EmitLoadOfScalar - Load a scalar value from an address, taking 2014545d996ec5a3113f046944f11b27cc2d6cb055b4John McCall /// care to appropriately convert from the memory representation to 2015545d996ec5a3113f046944f11b27cc2d6cb055b4John McCall /// the LLVM value representation. The l-value must be a simple 2016545d996ec5a3113f046944f11b27cc2d6cb055b4John McCall /// l-value. 2017a07398ed98ea2b55ad7a505a3aab18aed93b149fJohn McCall llvm::Value *EmitLoadOfScalar(LValue lvalue); 20189d9cc874bcc168474757a8f90476684b4a93ed76Daniel Dunbar 20199d9cc874bcc168474757a8f90476684b4a93ed76Daniel Dunbar /// EmitStoreOfScalar - Store a scalar value to an address, taking 20209d9cc874bcc168474757a8f90476684b4a93ed76Daniel Dunbar /// care to appropriately convert from the memory representation to 20219d9cc874bcc168474757a8f90476684b4a93ed76Daniel Dunbar /// the LLVM value representation. 202209429b962811f2c0a7a81a1b0a89f96f5878b20cMike Stump void EmitStoreOfScalar(llvm::Value *Value, llvm::Value *Addr, 20233d5aff5d3036b0ff09d114857cd2276134b3d8c9Dan Gohman bool Volatile, unsigned Alignment, QualType Ty, 20243d5aff5d3036b0ff09d114857cd2276134b3d8c9Dan Gohman llvm::MDNode *TBAAInfo = 0); 2025545d996ec5a3113f046944f11b27cc2d6cb055b4John McCall 2026545d996ec5a3113f046944f11b27cc2d6cb055b4John McCall /// EmitStoreOfScalar - Store a scalar value to an address, taking 2027545d996ec5a3113f046944f11b27cc2d6cb055b4John McCall /// care to appropriately convert from the memory representation to 2028545d996ec5a3113f046944f11b27cc2d6cb055b4John McCall /// the LLVM value representation. The l-value must be a simple 2029545d996ec5a3113f046944f11b27cc2d6cb055b4John McCall /// l-value. 2030a07398ed98ea2b55ad7a505a3aab18aed93b149fJohn McCall void EmitStoreOfScalar(llvm::Value *value, LValue lvalue); 20319d9cc874bcc168474757a8f90476684b4a93ed76Daniel Dunbar 20325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// EmitLoadOfLValue - Given an expression that represents a value lvalue, 20335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// this method emits the address of the lvalue, then loads the result as an 20345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// rvalue, returning the rvalue. 2035545d996ec5a3113f046944f11b27cc2d6cb055b4John McCall RValue EmitLoadOfLValue(LValue V); 2036545d996ec5a3113f046944f11b27cc2d6cb055b4John McCall RValue EmitLoadOfExtVectorElementLValue(LValue V); 2037545d996ec5a3113f046944f11b27cc2d6cb055b4John McCall RValue EmitLoadOfBitfieldLValue(LValue LV); 20380dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 20395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// EmitStoreThroughLValue - Store the specified rvalue into the specified 20405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// lvalue, where both are guaranteed to the have the same type, and that type 20415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// is 'Ty'. 2042545d996ec5a3113f046944f11b27cc2d6cb055b4John McCall void EmitStoreThroughLValue(RValue Src, LValue Dst); 2043545d996ec5a3113f046944f11b27cc2d6cb055b4John McCall void EmitStoreThroughExtVectorComponentLValue(RValue Src, LValue Dst); 2044ed3849b456d64d124bddc7ac044f3ce590bd9d69Daniel Dunbar 20450dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// EmitStoreThroughLValue - Store Src into Dst with same constraints as 20460dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// EmitStoreThroughLValue. 2047ed3849b456d64d124bddc7ac044f3ce590bd9d69Daniel Dunbar /// 20480dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// \param Result [out] - If non-null, this will be set to a Value* for the 20490dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// bit-field contents after the store, appropriate for use as the result of 20500dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// an assignment to the bit-field. 2051545d996ec5a3113f046944f11b27cc2d6cb055b4John McCall void EmitStoreThroughBitfieldLValue(RValue Src, LValue Dst, 2052ed3849b456d64d124bddc7ac044f3ce590bd9d69Daniel Dunbar llvm::Value **Result=0); 20530dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 205483ce9d4a552987d34cbd500e983db8d770232379John McCall /// Emit an l-value for an assignment (simple or compound) of complex type. 205583ce9d4a552987d34cbd500e983db8d770232379John McCall LValue EmitComplexAssignmentLValue(const BinaryOperator *E); 20562a41637a995affa1563f4d82a8b026e326a2faa0John McCall LValue EmitComplexCompoundAssignmentLValue(const CompoundAssignOperator *E); 205783ce9d4a552987d34cbd500e983db8d770232379John McCall 2058fc8f0e14ad142ed811e90fbd9a30e419e301c717Chris Lattner // Note: only available for agg return types 205980e62c29fe21cd06c93eba6e72b7e32dca06fcf9Daniel Dunbar LValue EmitBinaryOperatorLValue(const BinaryOperator *E); 20602a41637a995affa1563f4d82a8b026e326a2faa0John McCall LValue EmitCompoundAssignmentLValue(const CompoundAssignOperator *E); 20615b5c9ef865607e179413462dcd71bcebb5b7daaeDaniel Dunbar // Note: only available for agg return types 206222c940ee588a420cd2e6c8f68be2ac3cc80061ffChristopher Lamb LValue EmitCallExprLValue(const CallExpr *E); 20635b5c9ef865607e179413462dcd71bcebb5b7daaeDaniel Dunbar // Note: only available for agg return types 20645b5c9ef865607e179413462dcd71bcebb5b7daaeDaniel Dunbar LValue EmitVAArgExprLValue(const VAArgExpr *E); 20655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LValue EmitDeclRefLValue(const DeclRefExpr *E); 20665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LValue EmitStringLiteralLValue(const StringLiteral *E); 2067eaf2bb89eb2aad3b80673de30febe52df43c10ecChris Lattner LValue EmitObjCEncodeExprLValue(const ObjCEncodeExpr *E); 2068d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner LValue EmitPredefinedLValue(const PredefinedExpr *E); 20695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LValue EmitUnaryOpLValue(const UnaryOperator *E); 20705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LValue EmitArraySubscriptExpr(const ArraySubscriptExpr *E); 2071213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman LValue EmitExtVectorElementExpr(const ExtVectorElementExpr *E); 2072b84a06e68ffd71da22e3c75b6e4bbdba37816413Devang Patel LValue EmitMemberExpr(const MemberExpr *E); 2073820bca41c3899374775d2a1dfc2ef2e22aaf1c7bFariborz Jahanian LValue EmitObjCIsaExpr(const ObjCIsaExpr *E); 207406e863f2902b8ba55b056308875c19f7ba3dab25Eli Friedman LValue EmitCompoundLiteralLValue(const CompoundLiteralExpr *E); 207556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall LValue EmitConditionalOperatorLValue(const AbstractConditionalOperator *E); 207675dfedaf702822c9e51a4f3c5d3ecf2d2ad99272Chris Lattner LValue EmitCastLValue(const CastExpr *E); 2077ed8abf18329df67b0abcbb3a10458bd8c1d2a595Douglas Gregor LValue EmitNullInitializationLValue(const CXXScalarValueInitExpr *E); 207803e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor LValue EmitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *E); 2079e996ffd240f20a1048179d7727a6ee3227261921John McCall LValue EmitOpaqueValueLValue(const OpaqueValueExpr *e); 20809cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer 20814b9c2d235fb9449e249d74f48ecfec601650de93John McCall RValue EmitPseudoObjectRValue(const PseudoObjectExpr *e, 20824b9c2d235fb9449e249d74f48ecfec601650de93John McCall AggValueSlot slot = AggValueSlot::ignored()); 20834b9c2d235fb9449e249d74f48ecfec601650de93John McCall LValue EmitPseudoObjectLValue(const PseudoObjectExpr *e); 20844b9c2d235fb9449e249d74f48ecfec601650de93John McCall 20852a03192a02dbf4fdff438d1e658356bde871aba4Daniel Dunbar llvm::Value *EmitIvarOffset(const ObjCInterfaceDecl *Interface, 208629e0bccf2bcce22b877f8b2ed173f564c116b97eDaniel Dunbar const ObjCIvarDecl *Ivar); 2087a9976d3b192690db20f59dc44099ac4ca939bdb7John McCall LValue EmitLValueForAnonRecordField(llvm::Value* Base, 208800eb3f9c5b33e3d99aee1f8b75dd9c9678fdd66bFrancois Pichet const IndirectFieldDecl* Field, 2089a9976d3b192690db20f59dc44099ac4ca939bdb7John McCall unsigned CVRQualifiers); 20900ed303c918915cbe2c611cddbfabd00404664831Anders Carlsson LValue EmitLValueForField(llvm::Value* Base, const FieldDecl* Field, 2091e6d2a534851a649485cb087e9dfcaf8a65886858Anders Carlsson unsigned CVRQualifiers); 20929cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer 209306a2970e9480c6d02b367b2f970baff29b9f9721Anders Carlsson /// EmitLValueForFieldInitialization - Like EmitLValueForField, except that 209406a2970e9480c6d02b367b2f970baff29b9f9721Anders Carlsson /// if the Field is a reference, this will return the address of the reference 209506a2970e9480c6d02b367b2f970baff29b9f9721Anders Carlsson /// and not the address of the value stored in the reference. 20969cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer LValue EmitLValueForFieldInitialization(llvm::Value* Base, 209706a2970e9480c6d02b367b2f970baff29b9f9721Anders Carlsson const FieldDecl* Field, 209806a2970e9480c6d02b367b2f970baff29b9f9721Anders Carlsson unsigned CVRQualifiers); 20999cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer 210045012a7ef5abf1042c893f3f2fa5c23cb5485ea9Fariborz Jahanian LValue EmitLValueForIvar(QualType ObjectTy, 210145012a7ef5abf1042c893f3f2fa5c23cb5485ea9Fariborz Jahanian llvm::Value* Base, const ObjCIvarDecl *Ivar, 210229e0bccf2bcce22b877f8b2ed173f564c116b97eDaniel Dunbar unsigned CVRQualifiers); 210329e0bccf2bcce22b877f8b2ed173f564c116b97eDaniel Dunbar 21040ed303c918915cbe2c611cddbfabd00404664831Anders Carlsson LValue EmitLValueForBitfield(llvm::Value* Base, const FieldDecl* Field, 2105598d3f61b6ca854e9d3c2f3359e24468502a61aaFariborz Jahanian unsigned CVRQualifiers); 2106fd64bb635dc221baa19f81d5d2a084f7eb269f7fFariborz Jahanian 2107a99038c0757a836c6faeeddaa5dfd249b32f6e9eMike Stump LValue EmitBlockDeclRefLValue(const BlockDeclRefExpr *E); 2108a99038c0757a836c6faeeddaa5dfd249b32f6e9eMike Stump 2109b58d017f2b9eeed33f2ab3ede968b89cf5296bf2Anders Carlsson LValue EmitCXXConstructLValue(const CXXConstructExpr *E); 2110e61c9e80a108b5db7e5f0e702f0e455d737c6390Anders Carlsson LValue EmitCXXBindTemporaryLValue(const CXXBindTemporaryExpr *E); 2111c2e84ae9a6d25cea3e583c768e576b4c981ec028Mike Stump LValue EmitCXXTypeidLValue(const CXXTypeidExpr *E); 21129cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer 21130a04d77bde7e3a661c2b41b60630d125d09ed6efDaniel Dunbar LValue EmitObjCMessageExprLValue(const ObjCMessageExpr *E); 2114391d77a26382dddf25da73e29fc1fa5aaaea4c6fChris Lattner LValue EmitObjCIvarRefLValue(const ObjCIvarRefExpr *E); 2115654599454c8e6cc83b1b9b3af43c49c2f66a26cbChris Lattner LValue EmitStmtExprLValue(const StmtExpr *E); 21168bfd31f9dad09cd52225d868bbd92a9bebe87775Fariborz Jahanian LValue EmitPointerToDataMemberBinaryExpr(const BinaryOperator *E); 211703b2960c14aede6ac82bdef32247094ebb72fa69Fariborz Jahanian LValue EmitObjCSelectorLValue(const ObjCSelectorExpr *E); 2118189d6ef40eff11b83b2cda941d5ed89a5cef09b2John McCall void EmitDeclRefExprDbgValue(const DeclRefExpr *E, llvm::Constant *Init); 211956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 21205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 2121883f6a7cc7dccb1d675e27121a82614d63492a8dChris Lattner // Scalar Expression Emission 21225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 21235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 21240dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// EmitCall - Generate a call of the given function, expecting the given 21250dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// result type, and using the given argument list which specifies both the 21260dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// LLVM arguments and the types they were derived from. 2127c0ef9f59937c3971c48b6fed37cf5bd8985c024bDaniel Dunbar /// 2128f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump /// \param TargetDecl - If given, the decl of the function in a direct call; 2129f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump /// used to set attributes on the call (noreturn, etc.). 213088b5396b0897f28d22ae3debf4a0d97b33b6c362Daniel Dunbar RValue EmitCall(const CGFunctionInfo &FnInfo, 213188b5396b0897f28d22ae3debf4a0d97b33b6c362Daniel Dunbar llvm::Value *Callee, 2132f3c47c9525153aea2de0ec4bd615b9cf2d81c103Anders Carlsson ReturnValueSlot ReturnValue, 2133c0ef9f59937c3971c48b6fed37cf5bd8985c024bDaniel Dunbar const CallArgList &Args, 2134dd5c98f709837e5dd3da08d44d1ce407975df2cfDavid Chisnall const Decl *TargetDecl = 0, 21354b02afcb45cd1a384de7d45f440a8be091dd500bDavid Chisnall llvm::Instruction **callOrInvoke = 0); 21361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 213731777a2540879051a3c643b90e02c3fd3d315243Anders Carlsson RValue EmitCall(QualType FnType, llvm::Value *Callee, 2138d2490a91341b57df7a7e54f8a707e7ecde2eeb4eAnders Carlsson ReturnValueSlot ReturnValue, 2139986477149db76e6d9f8d3c9859c9880c11b680aeAnders Carlsson CallExpr::const_arg_iterator ArgBeg, 2140986477149db76e6d9f8d3c9859c9880c11b680aeAnders Carlsson CallExpr::const_arg_iterator ArgEnd, 2141986477149db76e6d9f8d3c9859c9880c11b680aeAnders Carlsson const Decl *TargetDecl = 0); 21429cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer RValue EmitCallExpr(const CallExpr *E, 2143d2490a91341b57df7a7e54f8a707e7ecde2eeb4eAnders Carlsson ReturnValueSlot ReturnValue = ReturnValueSlot()); 21441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2145f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall llvm::CallSite EmitCallOrInvoke(llvm::Value *Callee, 21462d3ba4f5a923a90c3fc290ddfba5e36c2d0a9b46Chris Lattner ArrayRef<llvm::Value *> Args, 21478cc488fefb2fb04bc8d5398da29f0182f97934cfChris Lattner const Twine &Name = ""); 21484c7d9f1507d0f102bd4133bba63348636facd469Jay Foad llvm::CallSite EmitCallOrInvoke(llvm::Value *Callee, 21498cc488fefb2fb04bc8d5398da29f0182f97934cfChris Lattner const Twine &Name = ""); 2150f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 2151566abee1e9828a7700b51e4d17ea08234fde3bb4Anders Carlsson llvm::Value *BuildVirtualCall(const CXXMethodDecl *MD, llvm::Value *This, 21522acc6e3feda5e4f7d9009bdcf8b1cd777fecfe2dChris Lattner llvm::Type *Ty); 21539cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer llvm::Value *BuildVirtualCall(const CXXDestructorDecl *DD, CXXDtorType Type, 21542acc6e3feda5e4f7d9009bdcf8b1cd777fecfe2dChris Lattner llvm::Value *This, llvm::Type *Ty); 21552726267f094a0c1f5ac5b501ec5a9898c58876bfFariborz Jahanian llvm::Value *BuildAppleKextVirtualCall(const CXXMethodDecl *MD, 21562726267f094a0c1f5ac5b501ec5a9898c58876bfFariborz Jahanian NestedNameSpecifier *Qual, 21572acc6e3feda5e4f7d9009bdcf8b1cd777fecfe2dChris Lattner llvm::Type *Ty); 2158ccd5259d33cbbdd6f5fbf7ccab4cb4a2702309eaFariborz Jahanian 2159ccd5259d33cbbdd6f5fbf7ccab4cb4a2702309eaFariborz Jahanian llvm::Value *BuildAppleKextVirtualDestructorCall(const CXXDestructorDecl *DD, 2160ccd5259d33cbbdd6f5fbf7ccab4cb4a2702309eaFariborz Jahanian CXXDtorType Type, 2161771c678c04f5f685b4f188ec6c2fd88ad0f7457fFariborz Jahanian const CXXRecordDecl *RD); 2162566abee1e9828a7700b51e4d17ea08234fde3bb4Anders Carlsson 2163b9de2c55b2a33776e2bee8ee57df7599b374c8a5Anders Carlsson RValue EmitCXXMemberCall(const CXXMethodDecl *MD, 2164b9de2c55b2a33776e2bee8ee57df7599b374c8a5Anders Carlsson llvm::Value *Callee, 2165a1736c0c750d4514a5d8fda36670addf1e4de54aAnders Carlsson ReturnValueSlot ReturnValue, 2166b9de2c55b2a33776e2bee8ee57df7599b374c8a5Anders Carlsson llvm::Value *This, 2167c997d4278d329e18891aac9698fb991b2d4622ebAnders Carlsson llvm::Value *VTT, 2168b9de2c55b2a33776e2bee8ee57df7599b374c8a5Anders Carlsson CallExpr::const_arg_iterator ArgBeg, 2169b9de2c55b2a33776e2bee8ee57df7599b374c8a5Anders Carlsson CallExpr::const_arg_iterator ArgEnd); 2170a1736c0c750d4514a5d8fda36670addf1e4de54aAnders Carlsson RValue EmitCXXMemberCallExpr(const CXXMemberCallExpr *E, 2171a1736c0c750d4514a5d8fda36670addf1e4de54aAnders Carlsson ReturnValueSlot ReturnValue); 2172a1736c0c750d4514a5d8fda36670addf1e4de54aAnders Carlsson RValue EmitCXXMemberPointerCallExpr(const CXXMemberCallExpr *E, 2173a1736c0c750d4514a5d8fda36670addf1e4de54aAnders Carlsson ReturnValueSlot ReturnValue); 21745549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek 2175a2447e0d1e28669cd637204a871f15b1215277fdAnders Carlsson llvm::Value *EmitCXXOperatorMemberCallee(const CXXOperatorCallExpr *E, 2176a2447e0d1e28669cd637204a871f15b1215277fdAnders Carlsson const CXXMethodDecl *MD, 2177a2447e0d1e28669cd637204a871f15b1215277fdAnders Carlsson llvm::Value *This); 21780f294632f36459174199b77699e339715244b5abAnders Carlsson RValue EmitCXXOperatorMemberCallExpr(const CXXOperatorCallExpr *E, 2179a1736c0c750d4514a5d8fda36670addf1e4de54aAnders Carlsson const CXXMethodDecl *MD, 2180a1736c0c750d4514a5d8fda36670addf1e4de54aAnders Carlsson ReturnValueSlot ReturnValue); 21811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21826c0aa5ff6e6253db0f993053599e2a52b5b93b2dPeter Collingbourne RValue EmitCUDAKernelCallExpr(const CUDAKernelCallExpr *E, 21836c0aa5ff6e6253db0f993053599e2a52b5b93b2dPeter Collingbourne ReturnValueSlot ReturnValue); 21846c0aa5ff6e6253db0f993053599e2a52b5b93b2dPeter Collingbourne 21859cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer 21861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump RValue EmitBuiltinExpr(const FunctionDecl *FD, 2187ef2abfee3ea16ec74942dc09e9e425f46aeb2582Daniel Dunbar unsigned BuiltinID, const CallExpr *E); 21885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2189a1736c0c750d4514a5d8fda36670addf1e4de54aAnders Carlsson RValue EmitBlockCallExpr(const CallExpr *E, ReturnValueSlot ReturnValue); 219009429b962811f2c0a7a81a1b0a89f96f5878b20cMike Stump 21910dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// EmitTargetBuiltinExpr - Emit the given builtin call. Returns 0 if the call 21920dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// is unhandled by the current target. 2193f02e9ddf5efc75917af712b3c7f909581205f0a5Daniel Dunbar llvm::Value *EmitTargetBuiltinExpr(unsigned BuiltinID, const CallExpr *E); 2194f02e9ddf5efc75917af712b3c7f909581205f0a5Daniel Dunbar 21952752c0137d95aa2f4ee1cdff4b564bac842e041bChris Lattner llvm::Value *EmitARMBuiltinExpr(unsigned BuiltinID, const CallExpr *E); 21969cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer llvm::Value *EmitNeonCall(llvm::Function *F, 2197686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVectorImpl<llvm::Value*> &O, 2198db3d4d036037f379f12643e067b229862d61e932Bob Wilson const char *name, 219961eecf5aea018ea65c9ab0bccacd2996b15c632dNate Begeman unsigned shift = 0, bool rightshift = false); 2200cf55652cf668c1402eee0b12edd2e5a1bc34d7a1Bob Wilson llvm::Value *EmitNeonSplat(llvm::Value *V, llvm::Constant *Idx); 22012acc6e3feda5e4f7d9009bdcf8b1cd777fecfe2dChris Lattner llvm::Value *EmitNeonShiftVector(llvm::Value *V, llvm::Type *Ty, 220261eecf5aea018ea65c9ab0bccacd2996b15c632dNate Begeman bool negateForRightShift); 22039cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer 2204686775deca8b8685eb90801495880e3abdd844c2Chris Lattner llvm::Value *BuildVector(const SmallVectorImpl<llvm::Value*> &Ops); 2205564f1de67d7ba43646b8740db86d6269e3dfbe0bAnders Carlsson llvm::Value *EmitX86BuiltinExpr(unsigned BuiltinID, const CallExpr *E); 2206564f1de67d7ba43646b8740db86d6269e3dfbe0bAnders Carlsson llvm::Value *EmitPPCBuiltinExpr(unsigned BuiltinID, const CallExpr *E); 22070dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 2208ed7c618f849e2541b1d0288c43154937652c5b15Daniel Dunbar llvm::Value *EmitObjCProtocolExpr(const ObjCProtocolExpr *E); 22097f02f721d48772e4eee4fccd8af4f800be1bbc1eChris Lattner llvm::Value *EmitObjCStringLiteral(const ObjCStringLiteral *E); 22108fdf32822be2238aa7db62d40e75b168b637ab7dChris Lattner llvm::Value *EmitObjCSelectorExpr(const ObjCSelectorExpr *E); 2211ef072fd2f3347cfd857d6eb787b245b950771430John McCall RValue EmitObjCMessageExpr(const ObjCMessageExpr *E, 2212ef072fd2f3347cfd857d6eb787b245b950771430John McCall ReturnValueSlot Return = ReturnValueSlot()); 22138fdf32822be2238aa7db62d40e75b168b637ab7dChris Lattner 2214f85e193739c953358c865005855253af4f68a497John McCall /// Retrieves the default cleanup kind for an ARC cleanup. 2215f85e193739c953358c865005855253af4f68a497John McCall /// Except under -fobjc-arc-eh, ARC cleanups are normal-only. 2216f85e193739c953358c865005855253af4f68a497John McCall CleanupKind getARCCleanupKind() { 2217f85e193739c953358c865005855253af4f68a497John McCall return CGM.getCodeGenOpts().ObjCAutoRefCountExceptions 2218f85e193739c953358c865005855253af4f68a497John McCall ? NormalAndEHCleanup : NormalCleanup; 2219f85e193739c953358c865005855253af4f68a497John McCall } 2220f85e193739c953358c865005855253af4f68a497John McCall 2221f85e193739c953358c865005855253af4f68a497John McCall // ARC primitives. 2222f85e193739c953358c865005855253af4f68a497John McCall void EmitARCInitWeak(llvm::Value *value, llvm::Value *addr); 2223f85e193739c953358c865005855253af4f68a497John McCall void EmitARCDestroyWeak(llvm::Value *addr); 2224f85e193739c953358c865005855253af4f68a497John McCall llvm::Value *EmitARCLoadWeak(llvm::Value *addr); 2225f85e193739c953358c865005855253af4f68a497John McCall llvm::Value *EmitARCLoadWeakRetained(llvm::Value *addr); 2226f85e193739c953358c865005855253af4f68a497John McCall llvm::Value *EmitARCStoreWeak(llvm::Value *value, llvm::Value *addr, 2227f85e193739c953358c865005855253af4f68a497John McCall bool ignored); 2228f85e193739c953358c865005855253af4f68a497John McCall void EmitARCCopyWeak(llvm::Value *dst, llvm::Value *src); 2229f85e193739c953358c865005855253af4f68a497John McCall void EmitARCMoveWeak(llvm::Value *dst, llvm::Value *src); 2230f85e193739c953358c865005855253af4f68a497John McCall llvm::Value *EmitARCRetainAutorelease(QualType type, llvm::Value *value); 2231f85e193739c953358c865005855253af4f68a497John McCall llvm::Value *EmitARCRetainAutoreleaseNonBlock(llvm::Value *value); 2232545d996ec5a3113f046944f11b27cc2d6cb055b4John McCall llvm::Value *EmitARCStoreStrong(LValue lvalue, llvm::Value *value, 2233545d996ec5a3113f046944f11b27cc2d6cb055b4John McCall bool ignored); 2234f85e193739c953358c865005855253af4f68a497John McCall llvm::Value *EmitARCStoreStrongCall(llvm::Value *addr, llvm::Value *value, 2235f85e193739c953358c865005855253af4f68a497John McCall bool ignored); 2236f85e193739c953358c865005855253af4f68a497John McCall llvm::Value *EmitARCRetain(QualType type, llvm::Value *value); 2237f85e193739c953358c865005855253af4f68a497John McCall llvm::Value *EmitARCRetainNonBlock(llvm::Value *value); 2238348f16fc7c71f0d9b651cb79fd1012843073493fJohn McCall llvm::Value *EmitARCRetainBlock(llvm::Value *value, bool mandatory); 2239f85e193739c953358c865005855253af4f68a497John McCall void EmitARCRelease(llvm::Value *value, bool precise); 2240f85e193739c953358c865005855253af4f68a497John McCall llvm::Value *EmitARCAutorelease(llvm::Value *value); 2241f85e193739c953358c865005855253af4f68a497John McCall llvm::Value *EmitARCAutoreleaseReturnValue(llvm::Value *value); 2242f85e193739c953358c865005855253af4f68a497John McCall llvm::Value *EmitARCRetainAutoreleaseReturnValue(llvm::Value *value); 2243f85e193739c953358c865005855253af4f68a497John McCall llvm::Value *EmitARCRetainAutoreleasedReturnValue(llvm::Value *value); 2244f85e193739c953358c865005855253af4f68a497John McCall 2245f85e193739c953358c865005855253af4f68a497John McCall std::pair<LValue,llvm::Value*> 2246f85e193739c953358c865005855253af4f68a497John McCall EmitARCStoreAutoreleasing(const BinaryOperator *e); 2247f85e193739c953358c865005855253af4f68a497John McCall std::pair<LValue,llvm::Value*> 2248f85e193739c953358c865005855253af4f68a497John McCall EmitARCStoreStrong(const BinaryOperator *e, bool ignored); 2249f85e193739c953358c865005855253af4f68a497John McCall 22502b014d6c0c6b8ac94b416ac37dfc7931f20777a7John McCall llvm::Value *EmitObjCThrowOperand(const Expr *expr); 22512b014d6c0c6b8ac94b416ac37dfc7931f20777a7John McCall 2252f85e193739c953358c865005855253af4f68a497John McCall llvm::Value *EmitObjCProduceObject(QualType T, llvm::Value *Ptr); 2253f85e193739c953358c865005855253af4f68a497John McCall llvm::Value *EmitObjCConsumeObject(QualType T, llvm::Value *Ptr); 2254f85e193739c953358c865005855253af4f68a497John McCall llvm::Value *EmitObjCExtendObjectLifetime(QualType T, llvm::Value *Ptr); 2255f85e193739c953358c865005855253af4f68a497John McCall 2256348f16fc7c71f0d9b651cb79fd1012843073493fJohn McCall llvm::Value *EmitARCExtendBlockObject(const Expr *expr); 2257f85e193739c953358c865005855253af4f68a497John McCall llvm::Value *EmitARCRetainScalarExpr(const Expr *expr); 2258f85e193739c953358c865005855253af4f68a497John McCall llvm::Value *EmitARCRetainAutoreleaseScalarExpr(const Expr *expr); 2259f85e193739c953358c865005855253af4f68a497John McCall 2260bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall static Destroyer destroyARCStrongImprecise; 2261bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall static Destroyer destroyARCStrongPrecise; 2262bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall static Destroyer destroyARCWeak; 2263bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall 2264f85e193739c953358c865005855253af4f68a497John McCall void EmitObjCAutoreleasePoolPop(llvm::Value *Ptr); 2265f85e193739c953358c865005855253af4f68a497John McCall llvm::Value *EmitObjCAutoreleasePoolPush(); 2266f85e193739c953358c865005855253af4f68a497John McCall llvm::Value *EmitObjCMRRAutoreleasePoolPush(); 2267f85e193739c953358c865005855253af4f68a497John McCall void EmitObjCAutoreleasePoolCleanup(llvm::Value *Ptr); 2268f85e193739c953358c865005855253af4f68a497John McCall void EmitObjCMRRAutoreleasePoolPop(llvm::Value *Ptr); 2269f85e193739c953358c865005855253af4f68a497John McCall 22704029ca7ae9d3ffd7738fe2ed8782bebc30f36fd6Anders Carlsson /// EmitReferenceBindingToExpr - Emits a reference binding to the passed in 22714029ca7ae9d3ffd7738fe2ed8782bebc30f36fd6Anders Carlsson /// expression. Will emit a temporary variable if E is not an LValue. 22729cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer RValue EmitReferenceBindingToExpr(const Expr* E, 227332f36baa6c8d491c374af622b4e3ac28d597453cAnders Carlsson const NamedDecl *InitializedDecl); 22743aba09376c5f49c4c8d176109ea4835bc2c528eeAnders Carlsson 2275883f6a7cc7dccb1d675e27121a82614d63492a8dChris Lattner //===--------------------------------------------------------------------===// 2276bfc0c1ae4b505b52b36f572a9641f99e76879cabChris Lattner // Expression Emission 2277883f6a7cc7dccb1d675e27121a82614d63492a8dChris Lattner //===--------------------------------------------------------------------===// 2278bfc0c1ae4b505b52b36f572a9641f99e76879cabChris Lattner 2279bfc0c1ae4b505b52b36f572a9641f99e76879cabChris Lattner // Expressions are broken into three classes: scalar, complex, aggregate. 22800dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 22810dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// EmitScalarExpr - Emit the computation of the specified expression of LLVM 22820dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// scalar type, returning the result. 228314c5cbf59cffee52275230922283a247de407712Anders Carlsson llvm::Value *EmitScalarExpr(const Expr *E , bool IgnoreResultAssign = false); 22840dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 22853707b255f8993fb362904c9cff87b0e9bc6ca317Chris Lattner /// EmitScalarConversion - Emit a conversion from the specified type to the 22863707b255f8993fb362904c9cff87b0e9bc6ca317Chris Lattner /// specified destination type, both of which are LLVM scalar types. 22873707b255f8993fb362904c9cff87b0e9bc6ca317Chris Lattner llvm::Value *EmitScalarConversion(llvm::Value *Src, QualType SrcTy, 22883707b255f8993fb362904c9cff87b0e9bc6ca317Chris Lattner QualType DstTy); 22890dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 22904f1a7b380809b4ca19ad2daff61bc11cd1e979d8Chris Lattner /// EmitComplexToScalarConversion - Emit a conversion from the specified 22910dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// complex type to the specified destination type, where the destination type 22920dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// is an LLVM scalar type. 22934f1a7b380809b4ca19ad2daff61bc11cd1e979d8Chris Lattner llvm::Value *EmitComplexToScalarConversion(ComplexPairTy Src, QualType SrcTy, 22944f1a7b380809b4ca19ad2daff61bc11cd1e979d8Chris Lattner QualType DstTy); 22950dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 22960dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 2297558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall /// EmitAggExpr - Emit the computation of the specified expression 2298558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall /// of aggregate type. The result is computed into the given slot, 2299558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall /// which may be null to indicate that the value is not needed. 2300474e2fe4957e6e72cee36ed189eaf21878ad0e91Fariborz Jahanian void EmitAggExpr(const Expr *E, AggValueSlot AS, bool IgnoreResult = false); 23010dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 230218aba0dd518e486d8b50523e7dafb4b5657135d2Daniel Dunbar /// EmitAggExprToLValue - Emit the computation of the specified expression of 230318aba0dd518e486d8b50523e7dafb4b5657135d2Daniel Dunbar /// aggregate type into a temporary LValue. 230418aba0dd518e486d8b50523e7dafb4b5657135d2Daniel Dunbar LValue EmitAggExprToLValue(const Expr *E); 230518aba0dd518e486d8b50523e7dafb4b5657135d2Daniel Dunbar 2306082b02e8403d3ee9d2ded969fbe0e5d472f04cd8Fariborz Jahanian /// EmitGCMemmoveCollectable - Emit special API for structs with object 2307082b02e8403d3ee9d2ded969fbe0e5d472f04cd8Fariborz Jahanian /// pointers. 2308082b02e8403d3ee9d2ded969fbe0e5d472f04cd8Fariborz Jahanian void EmitGCMemmoveCollectable(llvm::Value *DestPtr, llvm::Value *SrcPtr, 230908c321380fff07d476a19daab6d29522c046cd49Fariborz Jahanian QualType Ty); 2310082b02e8403d3ee9d2ded969fbe0e5d472f04cd8Fariborz Jahanian 23110c24c808e4dce43e88abf2d5f98546b901bd4315John McCall /// EmitExtendGCLifetime - Given a pointer to an Objective-C object, 23120c24c808e4dce43e88abf2d5f98546b901bd4315John McCall /// make sure it survives garbage collection until this point. 23130c24c808e4dce43e88abf2d5f98546b901bd4315John McCall void EmitExtendGCLifetime(llvm::Value *object); 23140c24c808e4dce43e88abf2d5f98546b901bd4315John McCall 2315b6ef18a2b06d6760459e1756a61f79ff496cee19Chris Lattner /// EmitComplexExpr - Emit the computation of the specified expression of 231623b1cdb0b5e089468bb8475b8ec9287af67b4b59Chris Lattner /// complex type, returning the result. 2317b418d74c11498b7e1044103131e2e3be4d63512eJohn McCall ComplexPairTy EmitComplexExpr(const Expr *E, 2318b418d74c11498b7e1044103131e2e3be4d63512eJohn McCall bool IgnoreReal = false, 2319b418d74c11498b7e1044103131e2e3be4d63512eJohn McCall bool IgnoreImag = false); 23200dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 232123b1cdb0b5e089468bb8475b8ec9287af67b4b59Chris Lattner /// EmitComplexExprIntoAddr - Emit the computation of the specified expression 232223b1cdb0b5e089468bb8475b8ec9287af67b4b59Chris Lattner /// of complex type, storing into the specified Value*. 2323190dbe203c2e892ac40f1786035c6c9be3f44a4cChris Lattner void EmitComplexExprIntoAddr(const Expr *E, llvm::Value *DestAddr, 2324190dbe203c2e892ac40f1786035c6c9be3f44a4cChris Lattner bool DestIsVolatile); 23257f8ea5c5b3a6a4332a841eefdd86b0726722ea7bDaniel Dunbar 23267f8ea5c5b3a6a4332a841eefdd86b0726722ea7bDaniel Dunbar /// StoreComplexToAddr - Store a complex number into the specified address. 23277f8ea5c5b3a6a4332a841eefdd86b0726722ea7bDaniel Dunbar void StoreComplexToAddr(ComplexPairTy V, llvm::Value *DestAddr, 23287f8ea5c5b3a6a4332a841eefdd86b0726722ea7bDaniel Dunbar bool DestIsVolatile); 23299b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner /// LoadComplexFromAddr - Load a complex number from the specified address. 23309b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner ComplexPairTy LoadComplexFromAddr(llvm::Value *SrcAddr, bool SrcIsVolatile); 23312621fd1d6d3c5eadcae246859f62738645df7540Chris Lattner 2332b6bbcc9995186799a60ce17d0c1acff31601653aJohn McCall /// CreateStaticVarDecl - Create a zero-initialized LLVM global for 2333b6bbcc9995186799a60ce17d0c1acff31601653aJohn McCall /// a static local variable. 2334b6bbcc9995186799a60ce17d0c1acff31601653aJohn McCall llvm::GlobalVariable *CreateStaticVarDecl(const VarDecl &D, 2335b6bbcc9995186799a60ce17d0c1acff31601653aJohn McCall const char *Separator, 2336f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump llvm::GlobalValue::LinkageTypes Linkage); 23379cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer 2338b6bbcc9995186799a60ce17d0c1acff31601653aJohn McCall /// AddInitializerToStaticVarDecl - Add the initializer for 'D' to the 2339761acc19d966a67f2175783d09412d6ac9463400Chris Lattner /// global variable that has already been created for it. If the initializer 2340761acc19d966a67f2175783d09412d6ac9463400Chris Lattner /// has a different type than GV does, this may free GV and return a different 2341761acc19d966a67f2175783d09412d6ac9463400Chris Lattner /// one. Otherwise it just returns GV. 2342761acc19d966a67f2175783d09412d6ac9463400Chris Lattner llvm::GlobalVariable * 2343b6bbcc9995186799a60ce17d0c1acff31601653aJohn McCall AddInitializerToStaticVarDecl(const VarDecl &D, 2344b6bbcc9995186799a60ce17d0c1acff31601653aJohn McCall llvm::GlobalVariable *GV); 23459cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer 23460096acf421c4609ce7f43e8b05f8c5ca866d4611Daniel Dunbar 23473b2e16b3d25f6b311dba2871e2a566c96238c3d2Anders Carlsson /// EmitCXXGlobalVarDeclInit - Create the initializer for a C++ 23483b2e16b3d25f6b311dba2871e2a566c96238c3d2Anders Carlsson /// variable with global storage. 23493b2e16b3d25f6b311dba2871e2a566c96238c3d2Anders Carlsson void EmitCXXGlobalVarDeclInit(const VarDecl &D, llvm::Constant *DeclPtr); 23503b2e16b3d25f6b311dba2871e2a566c96238c3d2Anders Carlsson 23513b2e16b3d25f6b311dba2871e2a566c96238c3d2Anders Carlsson /// EmitCXXGlobalDtorRegistration - Emits a call to register the global ptr 23523b2e16b3d25f6b311dba2871e2a566c96238c3d2Anders Carlsson /// with the C++ runtime so that its destructor will be called at exit. 235388f4280f6b60edcbdea6a38a3da8b17d66473ad6Fariborz Jahanian void EmitCXXGlobalDtorRegistration(llvm::Constant *DtorFn, 23543b2e16b3d25f6b311dba2871e2a566c96238c3d2Anders Carlsson llvm::Constant *DeclPtr); 23551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 23563030eb82593097502469a8b3fc26112c79c75605John McCall /// Emit code in this function to perform a guarded variable 23573030eb82593097502469a8b3fc26112c79c75605John McCall /// initialization. Guarded initializations are used when it's not 23583030eb82593097502469a8b3fc26112c79c75605John McCall /// possible to prove that an initialization will be done exactly 23593030eb82593097502469a8b3fc26112c79c75605John McCall /// once, e.g. with a static local variable or a static data member 23603030eb82593097502469a8b3fc26112c79c75605John McCall /// of a class template. 23613030eb82593097502469a8b3fc26112c79c75605John McCall void EmitCXXGuardedInit(const VarDecl &D, llvm::GlobalVariable *DeclPtr); 23625cd91b513455fd7753e8815b54f0a49bbca6602dJohn McCall 2363efb0fa9e11f75af51744a6159530ef7cc8efa24aDaniel Dunbar /// GenerateCXXGlobalInitFunc - Generates code for initializing global 2364efb0fa9e11f75af51744a6159530ef7cc8efa24aDaniel Dunbar /// variables. 2365efb0fa9e11f75af51744a6159530ef7cc8efa24aDaniel Dunbar void GenerateCXXGlobalInitFunc(llvm::Function *Fn, 2366efb0fa9e11f75af51744a6159530ef7cc8efa24aDaniel Dunbar llvm::Constant **Decls, 2367efb0fa9e11f75af51744a6159530ef7cc8efa24aDaniel Dunbar unsigned NumDecls); 2368efb0fa9e11f75af51744a6159530ef7cc8efa24aDaniel Dunbar 2369efb0fa9e11f75af51744a6159530ef7cc8efa24aDaniel Dunbar /// GenerateCXXGlobalDtorFunc - Generates code for destroying global 2370efb0fa9e11f75af51744a6159530ef7cc8efa24aDaniel Dunbar /// variables. 2371efb0fa9e11f75af51744a6159530ef7cc8efa24aDaniel Dunbar void GenerateCXXGlobalDtorFunc(llvm::Function *Fn, 2372810112e28dc839715d17b0a786f23aaa19600ac0Chris Lattner const std::vector<std::pair<llvm::WeakVH, 2373efb0fa9e11f75af51744a6159530ef7cc8efa24aDaniel Dunbar llvm::Constant*> > &DtorsAndObjects); 2374efb0fa9e11f75af51744a6159530ef7cc8efa24aDaniel Dunbar 2375d26bc76c98006609002d9930f8840490e88ac5b5John McCall void GenerateCXXGlobalVarDeclInitFunc(llvm::Function *Fn, 2376d26bc76c98006609002d9930f8840490e88ac5b5John McCall const VarDecl *D, 23773030eb82593097502469a8b3fc26112c79c75605John McCall llvm::GlobalVariable *Addr); 2378efb0fa9e11f75af51744a6159530ef7cc8efa24aDaniel Dunbar 2379558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall void EmitCXXConstructExpr(const CXXConstructExpr *E, AggValueSlot Dest); 238034999876e215b22febc240b1a6dc054215d12f9cFariborz Jahanian 238134999876e215b22febc240b1a6dc054215d12f9cFariborz Jahanian void EmitSynthesizedCXXCopyCtor(llvm::Value *Dest, llvm::Value *Src, 2382830937bc1100fba7682f7c32c40512085870f50cFariborz Jahanian const Expr *Exp); 23831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 23841a343ebbf413e8eae6b2737b2b2d79cbf5765571John McCall void enterFullExpression(const ExprWithCleanups *E) { 23851a343ebbf413e8eae6b2737b2b2d79cbf5765571John McCall if (E->getNumObjects() == 0) return; 23861a343ebbf413e8eae6b2737b2b2d79cbf5765571John McCall enterNonTrivialFullExpression(E); 23871a343ebbf413e8eae6b2737b2b2d79cbf5765571John McCall } 23881a343ebbf413e8eae6b2737b2b2d79cbf5765571John McCall void enterNonTrivialFullExpression(const ExprWithCleanups *E); 23891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2390756b5c4f9d52642d87d1948bee58f97a4f795b24Anders Carlsson void EmitCXXThrowExpr(const CXXThrowExpr *E); 23911eb2e59338c4b9c0429fc39ca98662adc9e7a3f2Douglas Gregor 2392276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman RValue EmitAtomicExpr(AtomicExpr *E, llvm::Value *Dest = 0); 2393276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman 23940ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar //===--------------------------------------------------------------------===// 239577f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge // Annotations Emission 239677f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge //===--------------------------------------------------------------------===// 239777f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge 239877f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge /// Emit an annotation call (intrinsic or builtin). 239977f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge llvm::Value *EmitAnnotationCall(llvm::Value *AnnotationFn, 240077f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge llvm::Value *AnnotatedVal, 240177f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge llvm::StringRef AnnotationStr, 240277f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge SourceLocation Location); 240377f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge 240477f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge /// Emit local annotations for the local variable V, declared by D. 240577f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge void EmitVarAnnotations(const VarDecl *D, llvm::Value *V); 240677f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge 240777f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge /// Emit field annotations for the given field & value. Returns the 240877f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge /// annotation result. 240977f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge llvm::Value *EmitFieldAnnotations(const FieldDecl *D, llvm::Value *V); 241077f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge 241177f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge //===--------------------------------------------------------------------===// 24120ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar // Internal Helpers 24130ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar //===--------------------------------------------------------------------===// 24140dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 24150946ccd1e58c1f1da31ddbca67c5b6301ac8b255Chris Lattner /// ContainsLabel - Return true if the statement contains a label in it. If 24160946ccd1e58c1f1da31ddbca67c5b6301ac8b255Chris Lattner /// this statement is not executed normally, it not containing a label means 24170946ccd1e58c1f1da31ddbca67c5b6301ac8b255Chris Lattner /// that we can just remove the code. 24180946ccd1e58c1f1da31ddbca67c5b6301ac8b255Chris Lattner static bool ContainsLabel(const Stmt *S, bool IgnoreCaseStmts = false); 24190dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 2420ef425a69006afaa87751ee41ccf8ff405d9ede70Chris Lattner /// containsBreak - Return true if the statement contains a break out of it. 2421ef425a69006afaa87751ee41ccf8ff405d9ede70Chris Lattner /// If the statement (recursively) contains a switch or loop with a break 2422ef425a69006afaa87751ee41ccf8ff405d9ede70Chris Lattner /// inside of it, this is fine. 2423ef425a69006afaa87751ee41ccf8ff405d9ede70Chris Lattner static bool containsBreak(const Stmt *S); 2424ef425a69006afaa87751ee41ccf8ff405d9ede70Chris Lattner 24254bc0455d826e9634b7a68c0d06146edd633c9453Daniel Dunbar /// ConstantFoldsToSimpleInteger - If the specified expression does not fold 2426c2c90011a688c04a4e980282f08c267e081c4b00Chris Lattner /// to a constant, or if it does but contains a label, return false. If it 2427c2c90011a688c04a4e980282f08c267e081c4b00Chris Lattner /// constant folds return true and set the boolean result in Result. 2428c2c90011a688c04a4e980282f08c267e081c4b00Chris Lattner bool ConstantFoldsToSimpleInteger(const Expr *Cond, bool &Result); 24290dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 2430ef425a69006afaa87751ee41ccf8ff405d9ede70Chris Lattner /// ConstantFoldsToSimpleInteger - If the specified expression does not fold 2431ef425a69006afaa87751ee41ccf8ff405d9ede70Chris Lattner /// to a constant, or if it does but contains a label, return false. If it 2432ef425a69006afaa87751ee41ccf8ff405d9ede70Chris Lattner /// constant folds return true and set the folded value. 2433ef425a69006afaa87751ee41ccf8ff405d9ede70Chris Lattner bool ConstantFoldsToSimpleInteger(const Expr *Cond, llvm::APInt &Result); 2434ef425a69006afaa87751ee41ccf8ff405d9ede70Chris Lattner 243531a0984b5cb4af99d2407c0f25bf5af68df681c6Chris Lattner /// EmitBranchOnBoolExpr - Emit a branch on a boolean condition (e.g. for an 243631a0984b5cb4af99d2407c0f25bf5af68df681c6Chris Lattner /// if statement) to the specified blocks. Based on the condition, this might 243731a0984b5cb4af99d2407c0f25bf5af68df681c6Chris Lattner /// try to simplify the codegen of the conditional based on the branch. 24389bc47e29dce8f095be7a6d07dbb02a5a7a112949Chris Lattner void EmitBranchOnBoolExpr(const Expr *Cond, llvm::BasicBlock *TrueBlock, 24394bc0455d826e9634b7a68c0d06146edd633c9453Daniel Dunbar llvm::BasicBlock *FalseBlock); 2440be07f60131bc6f8d6696f4644df1ef667a1730d5Mike Stump 244115037caa1542bb810ad54c653aeb80f61df7b00cMike Stump /// getTrapBB - Create a basic block that will call the trap intrinsic. We'll 244215037caa1542bb810ad54c653aeb80f61df7b00cMike Stump /// generate a branch around the created basic block as necessary. 24436c552c1d5f47fbba00e6268d96a26ad026f2da2aChris Lattner llvm::BasicBlock *getTrapBB(); 24449cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer 244521c9ad9d29d08a287292c670e7c52bc522c7f8bbAnders Carlsson /// EmitCallArg - Emit a single call argument. 2446413ebdb1af6fb0d81845b61254daf02ba0449afdJohn McCall void EmitCallArg(CallArgList &args, const Expr *E, QualType ArgType); 244721c9ad9d29d08a287292c670e7c52bc522c7f8bbAnders Carlsson 24482736071ea3a46f90e65c93418961611d96c10ab9John McCall /// EmitDelegateCallArg - We are performing a delegate call; that 24492736071ea3a46f90e65c93418961611d96c10ab9John McCall /// is, the current function is delegating to another one. Produce 24502736071ea3a46f90e65c93418961611d96c10ab9John McCall /// a r-value suitable for passing the given parameter. 2451413ebdb1af6fb0d81845b61254daf02ba0449afdJohn McCall void EmitDelegateCallArg(CallArgList &args, const VarDecl *param); 24522736071ea3a46f90e65c93418961611d96c10ab9John McCall 2453c5096cbf7a42e0f9012945b00d9037a5b5a88d72Peter Collingbourne /// SetFPAccuracy - Set the minimum required accuracy of the given floating 2454c5096cbf7a42e0f9012945b00d9037a5b5a88d72Peter Collingbourne /// point operation, expressed as the maximum relative error in ulp. 2455c5096cbf7a42e0f9012945b00d9037a5b5a88d72Peter Collingbourne void SetFPAccuracy(llvm::Value *Val, unsigned AccuracyN, 2456c5096cbf7a42e0f9012945b00d9037a5b5a88d72Peter Collingbourne unsigned AccuracyD = 1); 2457c5096cbf7a42e0f9012945b00d9037a5b5a88d72Peter Collingbourne 245831a0984b5cb4af99d2407c0f25bf5af68df681c6Chris Lattnerprivate: 245929e0bccf2bcce22b877f8b2ed173f564c116b97eDaniel Dunbar void EmitReturnOfRValue(RValue RV, QualType Ty); 246029e0bccf2bcce22b877f8b2ed173f564c116b97eDaniel Dunbar 24615627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar /// ExpandTypeFromArgs - Reconstruct a structure of type \arg Ty 24625627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar /// from function arguments into \arg Dst. See ABIArgInfo::Expand. 24635627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar /// 24645627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar /// \param AI - The first function argument of the expansion. 24655627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar /// \return The argument following the last expanded function 24665627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar /// argument. 24670dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump llvm::Function::arg_iterator 24685627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar ExpandTypeFromArgs(QualType Ty, LValue Dst, 24695627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar llvm::Function::arg_iterator AI); 24705627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar 24710dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// ExpandTypeToArgs - Expand an RValue \arg Src, with the LLVM type for \arg 24720dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// Ty, into individual arguments on the provided vector \arg Args. See 24730dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// ABIArgInfo::Expand. 24740dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump void ExpandTypeToArgs(QualType Ty, RValue Src, 2475686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVector<llvm::Value*, 16> &Args, 2476811bf3669f4d82c57fe3cd3c49050fdbc95d0affChris Lattner llvm::FunctionType *IRFuncTy); 2477c8c7b187adcd989e01a9fba1ebead6c2abd770c9Anders Carlsson 24781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump llvm::Value* EmitAsmInput(const AsmStmt &S, 2479b84e8a670ad1d00c0a34295c42ac700cdde04815Daniel Dunbar const TargetInfo::ConstraintInfo &Info, 2480c8c7b187adcd989e01a9fba1ebead6c2abd770c9Anders Carlsson const Expr *InputExpr, std::string &ConstraintStr); 24810dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 24826d7cfd7ef82e42ff30ee1dafd2883fd94e9f8294Eli Friedman llvm::Value* EmitAsmInputLValue(const AsmStmt &S, 24836d7cfd7ef82e42ff30ee1dafd2883fd94e9f8294Eli Friedman const TargetInfo::ConstraintInfo &Info, 24846d7cfd7ef82e42ff30ee1dafd2883fd94e9f8294Eli Friedman LValue InputValue, QualType InputType, 24856d7cfd7ef82e42ff30ee1dafd2883fd94e9f8294Eli Friedman std::string &ConstraintStr); 24866d7cfd7ef82e42ff30ee1dafd2883fd94e9f8294Eli Friedman 24870139bb96494b4c4ba0824617d5d2495dc7e44c76Anders Carlsson /// EmitCallArgs - Emit call arguments for a function. 24881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// The CallArgTypeInfo parameter is used for iterating over the known 2489af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson /// argument types of the function being called. 2490af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson template<typename T> 2491af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson void EmitCallArgs(CallArgList& Args, const T* CallArgTypeInfo, 24920139bb96494b4c4ba0824617d5d2495dc7e44c76Anders Carlsson CallExpr::const_arg_iterator ArgBeg, 2493af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson CallExpr::const_arg_iterator ArgEnd) { 2494af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson CallExpr::const_arg_iterator Arg = ArgBeg; 2495af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson 2496af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson // First, use the argument types that the type info knows about 2497af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson if (CallArgTypeInfo) { 2498af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson for (typename T::arg_type_iterator I = CallArgTypeInfo->arg_type_begin(), 2499af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson E = CallArgTypeInfo->arg_type_end(); I != E; ++I, ++Arg) { 250044b0a3e858af7b19f489619e52cd58970611cd15Eli Friedman assert(Arg != ArgEnd && "Running over edge of argument list!"); 2501af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson QualType ArgType = *I; 2502745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian#ifndef NDEBUG 2503745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian QualType ActualArgType = Arg->getType(); 2504745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian if (ArgType->isPointerType() && ActualArgType->isPointerType()) { 25059cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer QualType ActualBaseType = 2506745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian ActualArgType->getAs<PointerType>()->getPointeeType(); 25079cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer QualType ArgBaseType = 2508745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian ArgType->getAs<PointerType>()->getPointeeType(); 2509745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian if (ArgBaseType->isVariableArrayType()) { 2510745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian if (const VariableArrayType *VAT = 2511745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian getContext().getAsVariableArrayType(ActualBaseType)) { 2512745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian if (!VAT->getSizeExpr()) 2513745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian ActualArgType = ArgType; 2514745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian } 2515745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian } 2516745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian } 2517af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson assert(getContext().getCanonicalType(ArgType.getNonReferenceType()). 25181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump getTypePtr() == 2519745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian getContext().getCanonicalType(ActualArgType).getTypePtr() && 2520af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson "type mismatch in call argument!"); 2521745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian#endif 2522413ebdb1af6fb0d81845b61254daf02ba0449afdJohn McCall EmitCallArg(Args, *Arg, ArgType); 2523af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson } 25241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 25251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // Either we've emitted all the call args, or we have a call to a 2526af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson // variadic function. 25271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump assert((Arg == ArgEnd || CallArgTypeInfo->isVariadic()) && 2528af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson "Extra arguments in non-variadic function!"); 25291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2530af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson } 25311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2532af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson // If we still have any arguments, emit them using the type of the argument. 2533413ebdb1af6fb0d81845b61254daf02ba0449afdJohn McCall for (; Arg != ArgEnd; ++Arg) 2534413ebdb1af6fb0d81845b61254daf02ba0449afdJohn McCall EmitCallArg(Args, *Arg, Arg->getType()); 2535af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson } 2536492c4f998d848673d3d6c9e6416115df4036a71dJohn McCall 2537492c4f998d848673d3d6c9e6416115df4036a71dJohn McCall const TargetCodeGenInfo &getTargetHooks() const { 2538492c4f998d848673d3d6c9e6416115df4036a71dJohn McCall return CGM.getTargetCodeGenInfo(); 2539492c4f998d848673d3d6c9e6416115df4036a71dJohn McCall } 2540744016dde06fcffd50931e94a98c850f8b12cd87John McCall 2541744016dde06fcffd50931e94a98c850f8b12cd87John McCall void EmitDeclMetadata(); 2542f0c11f7e6848f023ced6a5b51399ba787c7d4d0bJohn McCall 2543f0c11f7e6848f023ced6a5b51399ba787c7d4d0bJohn McCall CodeGenModule::ByrefHelpers * 25442acc6e3feda5e4f7d9009bdcf8b1cd777fecfe2dChris Lattner buildByrefHelpers(llvm::StructType &byrefType, 2545f0c11f7e6848f023ced6a5b51399ba787c7d4d0bJohn McCall const AutoVarEmission &emission); 25465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 25471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2548150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall/// Helper class with most of the code for saving a value for a 2549150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall/// conditional expression cleanup. 2550804b807ea918184d6de63bd745e1ff75a9bfc679John McCallstruct DominatingLLVMValue { 2551150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall typedef llvm::PointerIntPair<llvm::Value*, 1, bool> saved_type; 2552150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall 2553150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall /// Answer whether the given value needs extra work to be saved. 2554150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall static bool needsSaving(llvm::Value *value) { 2555150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall // If it's not an instruction, we don't need to save. 2556150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall if (!isa<llvm::Instruction>(value)) return false; 2557150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall 2558150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall // If it's an instruction in the entry block, we don't need to save. 2559150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall llvm::BasicBlock *block = cast<llvm::Instruction>(value)->getParent(); 2560150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall return (block != &block->getParent()->getEntryBlock()); 2561150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall } 2562150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall 2563150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall /// Try to save the given value. 2564150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall static saved_type save(CodeGenFunction &CGF, llvm::Value *value) { 2565150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall if (!needsSaving(value)) return saved_type(value, false); 2566150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall 2567150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall // Otherwise we need an alloca. 2568150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall llvm::Value *alloca = 2569150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall CGF.CreateTempAlloca(value->getType(), "cond-cleanup.save"); 2570150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall CGF.Builder.CreateStore(value, alloca); 2571150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall 2572150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall return saved_type(alloca, true); 2573150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall } 2574150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall 2575150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall static llvm::Value *restore(CodeGenFunction &CGF, saved_type value) { 2576150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall if (!value.getInt()) return value.getPointer(); 2577150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall return CGF.Builder.CreateLoad(value.getPointer()); 2578150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall } 2579150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall}; 2580150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall 2581804b807ea918184d6de63bd745e1ff75a9bfc679John McCall/// A partial specialization of DominatingValue for llvm::Values that 2582804b807ea918184d6de63bd745e1ff75a9bfc679John McCall/// might be llvm::Instructions. 2583804b807ea918184d6de63bd745e1ff75a9bfc679John McCalltemplate <class T> struct DominatingPointer<T,true> : DominatingLLVMValue { 2584804b807ea918184d6de63bd745e1ff75a9bfc679John McCall typedef T *type; 2585804b807ea918184d6de63bd745e1ff75a9bfc679John McCall static type restore(CodeGenFunction &CGF, saved_type value) { 2586804b807ea918184d6de63bd745e1ff75a9bfc679John McCall return static_cast<T*>(DominatingLLVMValue::restore(CGF, value)); 2587804b807ea918184d6de63bd745e1ff75a9bfc679John McCall } 2588804b807ea918184d6de63bd745e1ff75a9bfc679John McCall}; 2589804b807ea918184d6de63bd745e1ff75a9bfc679John McCall 2590804b807ea918184d6de63bd745e1ff75a9bfc679John McCall/// A specialization of DominatingValue for RValue. 2591804b807ea918184d6de63bd745e1ff75a9bfc679John McCalltemplate <> struct DominatingValue<RValue> { 2592804b807ea918184d6de63bd745e1ff75a9bfc679John McCall typedef RValue type; 2593804b807ea918184d6de63bd745e1ff75a9bfc679John McCall class saved_type { 2594804b807ea918184d6de63bd745e1ff75a9bfc679John McCall enum Kind { ScalarLiteral, ScalarAddress, AggregateLiteral, 2595804b807ea918184d6de63bd745e1ff75a9bfc679John McCall AggregateAddress, ComplexAddress }; 2596804b807ea918184d6de63bd745e1ff75a9bfc679John McCall 2597804b807ea918184d6de63bd745e1ff75a9bfc679John McCall llvm::Value *Value; 2598804b807ea918184d6de63bd745e1ff75a9bfc679John McCall Kind K; 2599804b807ea918184d6de63bd745e1ff75a9bfc679John McCall saved_type(llvm::Value *v, Kind k) : Value(v), K(k) {} 2600804b807ea918184d6de63bd745e1ff75a9bfc679John McCall 2601804b807ea918184d6de63bd745e1ff75a9bfc679John McCall public: 2602804b807ea918184d6de63bd745e1ff75a9bfc679John McCall static bool needsSaving(RValue value); 2603804b807ea918184d6de63bd745e1ff75a9bfc679John McCall static saved_type save(CodeGenFunction &CGF, RValue value); 2604804b807ea918184d6de63bd745e1ff75a9bfc679John McCall RValue restore(CodeGenFunction &CGF); 2605804b807ea918184d6de63bd745e1ff75a9bfc679John McCall 2606804b807ea918184d6de63bd745e1ff75a9bfc679John McCall // implementations in CGExprCXX.cpp 2607804b807ea918184d6de63bd745e1ff75a9bfc679John McCall }; 2608804b807ea918184d6de63bd745e1ff75a9bfc679John McCall 2609804b807ea918184d6de63bd745e1ff75a9bfc679John McCall static bool needsSaving(type value) { 2610804b807ea918184d6de63bd745e1ff75a9bfc679John McCall return saved_type::needsSaving(value); 2611804b807ea918184d6de63bd745e1ff75a9bfc679John McCall } 2612804b807ea918184d6de63bd745e1ff75a9bfc679John McCall static saved_type save(CodeGenFunction &CGF, type value) { 2613804b807ea918184d6de63bd745e1ff75a9bfc679John McCall return saved_type::save(CGF, value); 2614804b807ea918184d6de63bd745e1ff75a9bfc679John McCall } 2615150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall static type restore(CodeGenFunction &CGF, saved_type value) { 2616804b807ea918184d6de63bd745e1ff75a9bfc679John McCall return value.restore(CGF); 2617150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall } 2618150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall}; 2619150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall 26205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} // end namespace CodeGen 26215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} // end namespace clang 26225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 26235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif 2624