CodeGenFunction.h revision 9d232c884ea9872d6555df0fd7359699819bc1f1
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 1755fc873017f10f6f566b182b70f6fc22aefa3464Chandler Carruth#include "CGBuilder.h" 1855fc873017f10f6f566b182b70f6fc22aefa3464Chandler Carruth#include "CGDebugInfo.h" 1955fc873017f10f6f566b182b70f6fc22aefa3464Chandler Carruth#include "CGValue.h" 2055fc873017f10f6f566b182b70f6fc22aefa3464Chandler Carruth#include "CodeGenModule.h" 2155fc873017f10f6f566b182b70f6fc22aefa3464Chandler Carruth#include "clang/AST/CharUnits.h" 22e3a09e6ad09f8d1387ecaa008aaf85527909da0aArgyrios Kyrtzidis#include "clang/AST/ExprCXX.h" 235549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek#include "clang/AST/ExprObjC.h" 2455fc873017f10f6f566b182b70f6fc22aefa3464Chandler Carruth#include "clang/AST/Type.h" 2514110477887e3dc168ffc6c191e72d705051f99ePeter Collingbourne#include "clang/Basic/ABI.h" 26481769b5dc102b0256b35581e787909ad5edfab5Chris Lattner#include "clang/Basic/TargetInfo.h" 2755fc873017f10f6f566b182b70f6fc22aefa3464Chandler Carruth#include "clang/Frontend/CodeGenOptions.h" 284c7d9f1507d0f102bd4133bba63348636facd469Jay Foad#include "llvm/ADT/ArrayRef.h" 29481769b5dc102b0256b35581e787909ad5edfab5Chris Lattner#include "llvm/ADT/DenseMap.h" 30481769b5dc102b0256b35581e787909ad5edfab5Chris Lattner#include "llvm/ADT/SmallVector.h" 31c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher#include "llvm/Support/Debug.h" 3255fc873017f10f6f566b182b70f6fc22aefa3464Chandler Carruth#include "llvm/Support/ValueHandle.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 { 465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class ASTContext; 471a343ebbf413e8eae6b2737b2b2d79cbf5765571John McCall class BlockDecl; 487267c1693abe7875b0c57268be05005ae013c6c9Anders Carlsson class CXXDestructorDecl; 49ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith class CXXForRangeStmt; 506815e941998659a55c20c147861b0f437928c3d8Anders Carlsson class CXXTryStmt; 515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class Decl; 52ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner class LabelDecl; 53c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar class EnumConstantDecl; 545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class FunctionDecl; 5572564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor class FunctionProtoType; 56c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar class LabelStmt; 57679a502d462ef819e6175b58e255ca3f3391e7cfFariborz Jahanian class ObjCContainerDecl; 5829e0bccf2bcce22b877f8b2ed173f564c116b97eDaniel Dunbar class ObjCInterfaceDecl; 5929e0bccf2bcce22b877f8b2ed173f564c116b97eDaniel Dunbar class ObjCIvarDecl; 60391d77a26382dddf25da73e29fc1fa5aaaea4c6fChris Lattner class ObjCMethodDecl; 61fef30b55230064d334a669a065a1c9acdb87cdfeFariborz Jahanian class ObjCImplementationDecl; 62af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar class ObjCPropertyImplDecl; 635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class TargetInfo; 64492c4f998d848673d3d6c9e6416115df4036a71dJohn McCall class TargetCodeGenInfo; 65c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar class VarDecl; 6616f0049415ec596504891259e2a83e19871c0d52Chris Lattner class ObjCForCollectionStmt; 6716f0049415ec596504891259e2a83e19871c0d52Chris Lattner class ObjCAtTryStmt; 6816f0049415ec596504891259e2a83e19871c0d52Chris Lattner class ObjCAtThrowStmt; 6916f0049415ec596504891259e2a83e19871c0d52Chris Lattner class ObjCAtSynchronizedStmt; 70f85e193739c953358c865005855253af4f68a497John McCall class ObjCAutoreleasePoolStmt; 715549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek 725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace CodeGen { 73b84a06e68ffd71da22e3c75b6e4bbdba37816413Devang Patel class CodeGenTypes; 74bb36d331f439f49859efcfb4435c61762fbba6f9Daniel Dunbar class CGFunctionInfo; 750dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump class CGRecordLayout; 76ee5042903d53fa7b0fbc1902d0ea07d57c7775b1John McCall class CGBlockInfo; 774c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall class CGCXXABI; 78d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall class BlockFlags; 79d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall class BlockFieldFlags; 800dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 819d232c884ea9872d6555df0fd7359699819bc1f1John McCall/// The kind of evaluation to perform on values of a particular 829d232c884ea9872d6555df0fd7359699819bc1f1John McCall/// type. Basically, is the code in CGExprScalar, CGExprComplex, or 839d232c884ea9872d6555df0fd7359699819bc1f1John McCall/// CGExprAgg? 849d232c884ea9872d6555df0fd7359699819bc1f1John McCall/// 859d232c884ea9872d6555df0fd7359699819bc1f1John McCall/// TODO: should vectors maybe be split out into their own thing? 869d232c884ea9872d6555df0fd7359699819bc1f1John McCallenum TypeEvaluationKind { 879d232c884ea9872d6555df0fd7359699819bc1f1John McCall TEK_Scalar, 889d232c884ea9872d6555df0fd7359699819bc1f1John McCall TEK_Complex, 899d232c884ea9872d6555df0fd7359699819bc1f1John McCall TEK_Aggregate 909d232c884ea9872d6555df0fd7359699819bc1f1John McCall}; 919d232c884ea9872d6555df0fd7359699819bc1f1John McCall 92f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall/// A branch fixup. These are required when emitting a goto to a 93f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall/// label which hasn't been emitted yet. The goto is optimistically 94f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall/// emitted as a branch to the basic block for the label, and (if it 95f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall/// occurs in a scope with non-trivial cleanups) a fixup is added to 96f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall/// the innermost cleanup. When a (normal) cleanup is popped, any 97f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall/// unresolved fixups in that scope are threaded through the cleanup. 98f1549f66a8216a78112286e3978cea2c29d6334cJohn McCallstruct BranchFixup { 99ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall /// The block containing the terminator which needs to be modified 100ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall /// into a switch if this fixup is resolved into the current scope. 101ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall /// If null, LatestBranch points directly to the destination. 102ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall llvm::BasicBlock *OptimisticBranchBlock; 103f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 104ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall /// The ultimate destination of the branch. 105f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// 106f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// This can be set to null to indicate that this fixup was 107f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// successfully resolved. 108f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall llvm::BasicBlock *Destination; 109f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 110ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall /// The destination index value. 111ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall unsigned DestinationIndex; 112ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall 113ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall /// The initial branch of the fixup. 114ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall llvm::BranchInst *InitialBranch; 115f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall}; 116f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 117804b807ea918184d6de63bd745e1ff75a9bfc679John McCalltemplate <class T> struct InvariantValue { 118150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall typedef T type; 119150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall typedef T saved_type; 120150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall static bool needsSaving(type value) { return false; } 121150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall static saved_type save(CodeGenFunction &CGF, type value) { return value; } 122150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall static type restore(CodeGenFunction &CGF, saved_type value) { return value; } 123150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall}; 124804b807ea918184d6de63bd745e1ff75a9bfc679John McCall 125804b807ea918184d6de63bd745e1ff75a9bfc679John McCall/// A metaprogramming class for ensuring that a value will dominate an 126804b807ea918184d6de63bd745e1ff75a9bfc679John McCall/// arbitrary position in a function. 127804b807ea918184d6de63bd745e1ff75a9bfc679John McCalltemplate <class T> struct DominatingValue : InvariantValue<T> {}; 128804b807ea918184d6de63bd745e1ff75a9bfc679John McCall 129804b807ea918184d6de63bd745e1ff75a9bfc679John McCalltemplate <class T, bool mightBeInstruction = 130804b807ea918184d6de63bd745e1ff75a9bfc679John McCall llvm::is_base_of<llvm::Value, T>::value && 131804b807ea918184d6de63bd745e1ff75a9bfc679John McCall !llvm::is_base_of<llvm::Constant, T>::value && 132804b807ea918184d6de63bd745e1ff75a9bfc679John McCall !llvm::is_base_of<llvm::BasicBlock, T>::value> 133804b807ea918184d6de63bd745e1ff75a9bfc679John McCallstruct DominatingPointer; 134804b807ea918184d6de63bd745e1ff75a9bfc679John McCalltemplate <class T> struct DominatingPointer<T,false> : InvariantValue<T*> {}; 135804b807ea918184d6de63bd745e1ff75a9bfc679John McCall// template <class T> struct DominatingPointer<T,true> at end of file 136804b807ea918184d6de63bd745e1ff75a9bfc679John McCall 137804b807ea918184d6de63bd745e1ff75a9bfc679John McCalltemplate <class T> struct DominatingValue<T*> : DominatingPointer<T> {}; 138150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall 139cd2d2b7814e0104ed41a8da159a06a8ca77b70d8John McCallenum CleanupKind { 140cd2d2b7814e0104ed41a8da159a06a8ca77b70d8John McCall EHCleanup = 0x1, 141cd2d2b7814e0104ed41a8da159a06a8ca77b70d8John McCall NormalCleanup = 0x2, 142cd2d2b7814e0104ed41a8da159a06a8ca77b70d8John McCall NormalAndEHCleanup = EHCleanup | NormalCleanup, 143cd2d2b7814e0104ed41a8da159a06a8ca77b70d8John McCall 144cd2d2b7814e0104ed41a8da159a06a8ca77b70d8John McCall InactiveCleanup = 0x4, 145cd2d2b7814e0104ed41a8da159a06a8ca77b70d8John McCall InactiveEHCleanup = EHCleanup | InactiveCleanup, 146cd2d2b7814e0104ed41a8da159a06a8ca77b70d8John McCall InactiveNormalCleanup = NormalCleanup | InactiveCleanup, 147cd2d2b7814e0104ed41a8da159a06a8ca77b70d8John McCall InactiveNormalAndEHCleanup = NormalAndEHCleanup | InactiveCleanup 148cd2d2b7814e0104ed41a8da159a06a8ca77b70d8John McCall}; 149da65ea86482bc116906edfb9ba1d7124f76cc867John McCall 150f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall/// A stack of scopes which respond to exceptions, including cleanups 151f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall/// and catch blocks. 152f1549f66a8216a78112286e3978cea2c29d6334cJohn McCallclass EHScopeStack { 153f1549f66a8216a78112286e3978cea2c29d6334cJohn McCallpublic: 154f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// A saved depth on the scope stack. This is necessary because 155f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// pushing scopes onto the stack invalidates iterators. 156f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall class stable_iterator { 157f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall friend class EHScopeStack; 158f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 159f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// Offset from StartOfData to EndOfBuffer. 160f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall ptrdiff_t Size; 161f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 162f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall stable_iterator(ptrdiff_t Size) : Size(Size) {} 163f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 164f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall public: 165f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall static stable_iterator invalid() { return stable_iterator(-1); } 166f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall stable_iterator() : Size(-1) {} 167f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 168f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall bool isValid() const { return Size >= 0; } 169f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 170838d796d020f6a8cd2b2d1e2a0a85c83bbf29543John McCall /// Returns true if this scope encloses I. 171838d796d020f6a8cd2b2d1e2a0a85c83bbf29543John McCall /// Returns false if I is invalid. 172838d796d020f6a8cd2b2d1e2a0a85c83bbf29543John McCall /// This scope must be valid. 173ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall bool encloses(stable_iterator I) const { return Size <= I.Size; } 174838d796d020f6a8cd2b2d1e2a0a85c83bbf29543John McCall 175838d796d020f6a8cd2b2d1e2a0a85c83bbf29543John McCall /// Returns true if this scope strictly encloses I: that is, 176838d796d020f6a8cd2b2d1e2a0a85c83bbf29543John McCall /// if it encloses I and is not I. 177838d796d020f6a8cd2b2d1e2a0a85c83bbf29543John McCall /// Returns false is I is invalid. 178838d796d020f6a8cd2b2d1e2a0a85c83bbf29543John McCall /// This scope must be valid. 179ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall bool strictlyEncloses(stable_iterator I) const { return Size < I.Size; } 1801bda662cb37d9fe24be4b3cf8ea0f4e550e1f889John McCall 181f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall friend bool operator==(stable_iterator A, stable_iterator B) { 182f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall return A.Size == B.Size; 183f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall } 184f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall friend bool operator!=(stable_iterator A, stable_iterator B) { 185f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall return A.Size != B.Size; 186f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall } 187f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall }; 188f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 1891f0fca54676cfa8616e7f3cd7a26788ab937e3cdJohn McCall /// Information for lazily generating a cleanup. Subclasses must be 1901f0fca54676cfa8616e7f3cd7a26788ab937e3cdJohn McCall /// POD-like: cleanups will not be destructed, and they will be 1911f0fca54676cfa8616e7f3cd7a26788ab937e3cdJohn McCall /// allocated on the cleanup stack and freely copied and moved 1921f0fca54676cfa8616e7f3cd7a26788ab937e3cdJohn McCall /// around. 193da65ea86482bc116906edfb9ba1d7124f76cc867John McCall /// 1941f0fca54676cfa8616e7f3cd7a26788ab937e3cdJohn McCall /// Cleanup implementations should generally be declared in an 195da65ea86482bc116906edfb9ba1d7124f76cc867John McCall /// anonymous namespace. 1961f0fca54676cfa8616e7f3cd7a26788ab937e3cdJohn McCall class Cleanup { 197c4a1a8450a3613ef256a71b9d8305b41f79eef50John McCall // Anchor the construction vtable. 198c4a1a8450a3613ef256a71b9d8305b41f79eef50John McCall virtual void anchor(); 199da65ea86482bc116906edfb9ba1d7124f76cc867John McCall public: 200ad346f4f678ab1c3222425641d851dc63e9dfa1aJohn McCall /// Generation flags. 201ad346f4f678ab1c3222425641d851dc63e9dfa1aJohn McCall class Flags { 202ad346f4f678ab1c3222425641d851dc63e9dfa1aJohn McCall enum { 203ad346f4f678ab1c3222425641d851dc63e9dfa1aJohn McCall F_IsForEH = 0x1, 204ad346f4f678ab1c3222425641d851dc63e9dfa1aJohn McCall F_IsNormalCleanupKind = 0x2, 205ad346f4f678ab1c3222425641d851dc63e9dfa1aJohn McCall F_IsEHCleanupKind = 0x4 206ad346f4f678ab1c3222425641d851dc63e9dfa1aJohn McCall }; 207ad346f4f678ab1c3222425641d851dc63e9dfa1aJohn McCall unsigned flags; 208ad346f4f678ab1c3222425641d851dc63e9dfa1aJohn McCall 209ad346f4f678ab1c3222425641d851dc63e9dfa1aJohn McCall public: 210ad346f4f678ab1c3222425641d851dc63e9dfa1aJohn McCall Flags() : flags(0) {} 211ad346f4f678ab1c3222425641d851dc63e9dfa1aJohn McCall 212ad346f4f678ab1c3222425641d851dc63e9dfa1aJohn McCall /// isForEH - true if the current emission is for an EH cleanup. 213ad346f4f678ab1c3222425641d851dc63e9dfa1aJohn McCall bool isForEHCleanup() const { return flags & F_IsForEH; } 214ad346f4f678ab1c3222425641d851dc63e9dfa1aJohn McCall bool isForNormalCleanup() const { return !isForEHCleanup(); } 215ad346f4f678ab1c3222425641d851dc63e9dfa1aJohn McCall void setIsForEHCleanup() { flags |= F_IsForEH; } 216ad346f4f678ab1c3222425641d851dc63e9dfa1aJohn McCall 217ad346f4f678ab1c3222425641d851dc63e9dfa1aJohn McCall bool isNormalCleanupKind() const { return flags & F_IsNormalCleanupKind; } 218ad346f4f678ab1c3222425641d851dc63e9dfa1aJohn McCall void setIsNormalCleanupKind() { flags |= F_IsNormalCleanupKind; } 219ad346f4f678ab1c3222425641d851dc63e9dfa1aJohn McCall 220ad346f4f678ab1c3222425641d851dc63e9dfa1aJohn McCall /// isEHCleanupKind - true if the cleanup was pushed as an EH 221ad346f4f678ab1c3222425641d851dc63e9dfa1aJohn McCall /// cleanup. 222ad346f4f678ab1c3222425641d851dc63e9dfa1aJohn McCall bool isEHCleanupKind() const { return flags & F_IsEHCleanupKind; } 223ad346f4f678ab1c3222425641d851dc63e9dfa1aJohn McCall void setIsEHCleanupKind() { flags |= F_IsEHCleanupKind; } 224ad346f4f678ab1c3222425641d851dc63e9dfa1aJohn McCall }; 225ad346f4f678ab1c3222425641d851dc63e9dfa1aJohn McCall 226c4a1a8450a3613ef256a71b9d8305b41f79eef50John McCall // Provide a virtual destructor to suppress a very common warning 227c4a1a8450a3613ef256a71b9d8305b41f79eef50John McCall // that unfortunately cannot be suppressed without this. Cleanups 228c4a1a8450a3613ef256a71b9d8305b41f79eef50John McCall // should not rely on this destructor ever being called. 229c4a1a8450a3613ef256a71b9d8305b41f79eef50John McCall virtual ~Cleanup() {} 2303e29f96988b0438e42dba3790f61fb3df42d90cbJohn McCall 231da65ea86482bc116906edfb9ba1d7124f76cc867John McCall /// Emit the cleanup. For normal cleanups, this is run in the 232da65ea86482bc116906edfb9ba1d7124f76cc867John McCall /// same EH context as when the cleanup was pushed, i.e. the 233da65ea86482bc116906edfb9ba1d7124f76cc867John McCall /// immediately-enclosing context of the cleanup scope. For 234da65ea86482bc116906edfb9ba1d7124f76cc867John McCall /// EH cleanups, this is run in a terminate context. 235da65ea86482bc116906edfb9ba1d7124f76cc867John McCall /// 23670517ca5c07c4b41ff8662b94ee22047b0299f8cDmitri Gribenko // \param flags cleanup kind. 237ad346f4f678ab1c3222425641d851dc63e9dfa1aJohn McCall virtual void Emit(CodeGenFunction &CGF, Flags flags) = 0; 238da65ea86482bc116906edfb9ba1d7124f76cc867John McCall }; 239da65ea86482bc116906edfb9ba1d7124f76cc867John McCall 240150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall /// ConditionalCleanupN stores the saved form of its N parameters, 241150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall /// then restores them and performs the cleanup. 2423ad32c8d93eb65d1d4943d7df567fc9b4f55d137John McCall template <class T, class A0> 2433ad32c8d93eb65d1d4943d7df567fc9b4f55d137John McCall class ConditionalCleanup1 : public Cleanup { 244804b807ea918184d6de63bd745e1ff75a9bfc679John McCall typedef typename DominatingValue<A0>::saved_type A0_saved; 2453ad32c8d93eb65d1d4943d7df567fc9b4f55d137John McCall A0_saved a0_saved; 2463ad32c8d93eb65d1d4943d7df567fc9b4f55d137John McCall 247ad346f4f678ab1c3222425641d851dc63e9dfa1aJohn McCall void Emit(CodeGenFunction &CGF, Flags flags) { 248804b807ea918184d6de63bd745e1ff75a9bfc679John McCall A0 a0 = DominatingValue<A0>::restore(CGF, a0_saved); 249ad346f4f678ab1c3222425641d851dc63e9dfa1aJohn McCall T(a0).Emit(CGF, flags); 2503ad32c8d93eb65d1d4943d7df567fc9b4f55d137John McCall } 2513ad32c8d93eb65d1d4943d7df567fc9b4f55d137John McCall 2523ad32c8d93eb65d1d4943d7df567fc9b4f55d137John McCall public: 2533ad32c8d93eb65d1d4943d7df567fc9b4f55d137John McCall ConditionalCleanup1(A0_saved a0) 2543ad32c8d93eb65d1d4943d7df567fc9b4f55d137John McCall : a0_saved(a0) {} 2553ad32c8d93eb65d1d4943d7df567fc9b4f55d137John McCall }; 2563ad32c8d93eb65d1d4943d7df567fc9b4f55d137John McCall 257150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall template <class T, class A0, class A1> 2583ad32c8d93eb65d1d4943d7df567fc9b4f55d137John McCall class ConditionalCleanup2 : public Cleanup { 259804b807ea918184d6de63bd745e1ff75a9bfc679John McCall typedef typename DominatingValue<A0>::saved_type A0_saved; 260804b807ea918184d6de63bd745e1ff75a9bfc679John McCall typedef typename DominatingValue<A1>::saved_type A1_saved; 2614bbcbda302cba8b1b0d88c20d735d09b483bd005John McCall A0_saved a0_saved; 2624bbcbda302cba8b1b0d88c20d735d09b483bd005John McCall A1_saved a1_saved; 263150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall 264ad346f4f678ab1c3222425641d851dc63e9dfa1aJohn McCall void Emit(CodeGenFunction &CGF, Flags flags) { 265804b807ea918184d6de63bd745e1ff75a9bfc679John McCall A0 a0 = DominatingValue<A0>::restore(CGF, a0_saved); 266804b807ea918184d6de63bd745e1ff75a9bfc679John McCall A1 a1 = DominatingValue<A1>::restore(CGF, a1_saved); 267ad346f4f678ab1c3222425641d851dc63e9dfa1aJohn McCall T(a0, a1).Emit(CGF, flags); 268150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall } 269150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall 270150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall public: 2713ad32c8d93eb65d1d4943d7df567fc9b4f55d137John McCall ConditionalCleanup2(A0_saved a0, A1_saved a1) 2723ad32c8d93eb65d1d4943d7df567fc9b4f55d137John McCall : a0_saved(a0), a1_saved(a1) {} 273150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall }; 274150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall 275d7b23167763f43d3e76b0de26141b1e52613ee3cDouglas Gregor template <class T, class A0, class A1, class A2> 276d7b23167763f43d3e76b0de26141b1e52613ee3cDouglas Gregor class ConditionalCleanup3 : public Cleanup { 277d7b23167763f43d3e76b0de26141b1e52613ee3cDouglas Gregor typedef typename DominatingValue<A0>::saved_type A0_saved; 278d7b23167763f43d3e76b0de26141b1e52613ee3cDouglas Gregor typedef typename DominatingValue<A1>::saved_type A1_saved; 279d7b23167763f43d3e76b0de26141b1e52613ee3cDouglas Gregor typedef typename DominatingValue<A2>::saved_type A2_saved; 280d7b23167763f43d3e76b0de26141b1e52613ee3cDouglas Gregor A0_saved a0_saved; 281d7b23167763f43d3e76b0de26141b1e52613ee3cDouglas Gregor A1_saved a1_saved; 282d7b23167763f43d3e76b0de26141b1e52613ee3cDouglas Gregor A2_saved a2_saved; 283d7b23167763f43d3e76b0de26141b1e52613ee3cDouglas Gregor 284ad346f4f678ab1c3222425641d851dc63e9dfa1aJohn McCall void Emit(CodeGenFunction &CGF, Flags flags) { 285d7b23167763f43d3e76b0de26141b1e52613ee3cDouglas Gregor A0 a0 = DominatingValue<A0>::restore(CGF, a0_saved); 286d7b23167763f43d3e76b0de26141b1e52613ee3cDouglas Gregor A1 a1 = DominatingValue<A1>::restore(CGF, a1_saved); 287d7b23167763f43d3e76b0de26141b1e52613ee3cDouglas Gregor A2 a2 = DominatingValue<A2>::restore(CGF, a2_saved); 288ad346f4f678ab1c3222425641d851dc63e9dfa1aJohn McCall T(a0, a1, a2).Emit(CGF, flags); 289d7b23167763f43d3e76b0de26141b1e52613ee3cDouglas Gregor } 290d7b23167763f43d3e76b0de26141b1e52613ee3cDouglas Gregor 291d7b23167763f43d3e76b0de26141b1e52613ee3cDouglas Gregor public: 292d7b23167763f43d3e76b0de26141b1e52613ee3cDouglas Gregor ConditionalCleanup3(A0_saved a0, A1_saved a1, A2_saved a2) 293c4a1a8450a3613ef256a71b9d8305b41f79eef50John McCall : a0_saved(a0), a1_saved(a1), a2_saved(a2) {} 294d7b23167763f43d3e76b0de26141b1e52613ee3cDouglas Gregor }; 295d7b23167763f43d3e76b0de26141b1e52613ee3cDouglas Gregor 2969928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall template <class T, class A0, class A1, class A2, class A3> 2979928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall class ConditionalCleanup4 : public Cleanup { 2989928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall typedef typename DominatingValue<A0>::saved_type A0_saved; 2999928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall typedef typename DominatingValue<A1>::saved_type A1_saved; 3009928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall typedef typename DominatingValue<A2>::saved_type A2_saved; 3019928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall typedef typename DominatingValue<A3>::saved_type A3_saved; 3029928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall A0_saved a0_saved; 3039928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall A1_saved a1_saved; 3049928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall A2_saved a2_saved; 3059928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall A3_saved a3_saved; 3069928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall 307ad346f4f678ab1c3222425641d851dc63e9dfa1aJohn McCall void Emit(CodeGenFunction &CGF, Flags flags) { 3089928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall A0 a0 = DominatingValue<A0>::restore(CGF, a0_saved); 3099928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall A1 a1 = DominatingValue<A1>::restore(CGF, a1_saved); 3109928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall A2 a2 = DominatingValue<A2>::restore(CGF, a2_saved); 3119928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall A3 a3 = DominatingValue<A3>::restore(CGF, a3_saved); 312ad346f4f678ab1c3222425641d851dc63e9dfa1aJohn McCall T(a0, a1, a2, a3).Emit(CGF, flags); 3139928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall } 3149928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall 3159928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall public: 3169928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall ConditionalCleanup4(A0_saved a0, A1_saved a1, A2_saved a2, A3_saved a3) 3179928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall : a0_saved(a0), a1_saved(a1), a2_saved(a2), a3_saved(a3) {} 3189928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall }; 3199928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall 320f1549f66a8216a78112286e3978cea2c29d6334cJohn McCallprivate: 321f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall // The implementation for this class is in CGException.h and 322f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall // CGException.cpp; the definition is here because it's used as a 323f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall // member of CodeGenFunction. 324f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 325f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// The start of the scope-stack buffer, i.e. the allocated pointer 326f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// for the buffer. All of these pointers are either simultaneously 327f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// null or simultaneously valid. 328f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall char *StartOfBuffer; 329f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 330f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// The end of the buffer. 331f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall char *EndOfBuffer; 332f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 333f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// The first valid entry in the buffer. 334f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall char *StartOfData; 335f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 336f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// The innermost normal cleanup on the stack. 337f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall stable_iterator InnermostNormalCleanup; 338f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 339777d6e56ad9b1fed9866daf3ee6486d85c5b7d32John McCall /// The innermost EH scope on the stack. 340777d6e56ad9b1fed9866daf3ee6486d85c5b7d32John McCall stable_iterator InnermostEHScope; 341ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall 342f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// The current set of branch fixups. A branch fixup is a jump to 343f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// an as-yet unemitted label, i.e. a label for which we don't yet 344f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// know the EH stack depth. Whenever we pop a cleanup, we have 345f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// to thread all the current branch fixups through it. 346f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// 347f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// Fixups are recorded as the Use of the respective branch or 348f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// switch statement. The use points to the final destination. 349f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// When popping out of a cleanup, these uses are threaded through 350f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// the cleanup and adjusted to point to the new cleanup. 351f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// 352f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// Note that branches are allowed to jump into protected scopes 353f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// in certain situations; e.g. the following code is legal: 354f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// struct A { ~A(); }; // trivial ctor, non-trivial dtor 355f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// goto foo; 356f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// A a; 357f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// foo: 358f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// bar(); 359686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVector<BranchFixup, 8> BranchFixups; 360f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 361f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall char *allocate(size_t Size); 362f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 3631f0fca54676cfa8616e7f3cd7a26788ab937e3cdJohn McCall void *pushCleanup(CleanupKind K, size_t DataSize); 364da65ea86482bc116906edfb9ba1d7124f76cc867John McCall 365f1549f66a8216a78112286e3978cea2c29d6334cJohn McCallpublic: 366f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall EHScopeStack() : StartOfBuffer(0), EndOfBuffer(0), StartOfData(0), 367f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall InnermostNormalCleanup(stable_end()), 368777d6e56ad9b1fed9866daf3ee6486d85c5b7d32John McCall InnermostEHScope(stable_end()) {} 369f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall ~EHScopeStack() { delete[] StartOfBuffer; } 370f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 371da65ea86482bc116906edfb9ba1d7124f76cc867John McCall // Variadic templates would make this not terrible. 372da65ea86482bc116906edfb9ba1d7124f76cc867John McCall 373da65ea86482bc116906edfb9ba1d7124f76cc867John McCall /// Push a lazily-created cleanup on the stack. 3748e3f86193995c47ee0d229e4336c3382410f09f5John McCall template <class T> 3751f0fca54676cfa8616e7f3cd7a26788ab937e3cdJohn McCall void pushCleanup(CleanupKind Kind) { 3761f0fca54676cfa8616e7f3cd7a26788ab937e3cdJohn McCall void *Buffer = pushCleanup(Kind, sizeof(T)); 3771f0fca54676cfa8616e7f3cd7a26788ab937e3cdJohn McCall Cleanup *Obj = new(Buffer) T(); 3788e3f86193995c47ee0d229e4336c3382410f09f5John McCall (void) Obj; 3798e3f86193995c47ee0d229e4336c3382410f09f5John McCall } 3808e3f86193995c47ee0d229e4336c3382410f09f5John McCall 3818e3f86193995c47ee0d229e4336c3382410f09f5John McCall /// Push a lazily-created cleanup on the stack. 3828e3f86193995c47ee0d229e4336c3382410f09f5John McCall template <class T, class A0> 3831f0fca54676cfa8616e7f3cd7a26788ab937e3cdJohn McCall void pushCleanup(CleanupKind Kind, A0 a0) { 3841f0fca54676cfa8616e7f3cd7a26788ab937e3cdJohn McCall void *Buffer = pushCleanup(Kind, sizeof(T)); 3851f0fca54676cfa8616e7f3cd7a26788ab937e3cdJohn McCall Cleanup *Obj = new(Buffer) T(a0); 3868e3f86193995c47ee0d229e4336c3382410f09f5John McCall (void) Obj; 3878e3f86193995c47ee0d229e4336c3382410f09f5John McCall } 3888e3f86193995c47ee0d229e4336c3382410f09f5John McCall 3898e3f86193995c47ee0d229e4336c3382410f09f5John McCall /// Push a lazily-created cleanup on the stack. 390da65ea86482bc116906edfb9ba1d7124f76cc867John McCall template <class T, class A0, class A1> 3911f0fca54676cfa8616e7f3cd7a26788ab937e3cdJohn McCall void pushCleanup(CleanupKind Kind, A0 a0, A1 a1) { 3921f0fca54676cfa8616e7f3cd7a26788ab937e3cdJohn McCall void *Buffer = pushCleanup(Kind, sizeof(T)); 3931f0fca54676cfa8616e7f3cd7a26788ab937e3cdJohn McCall Cleanup *Obj = new(Buffer) T(a0, a1); 394da65ea86482bc116906edfb9ba1d7124f76cc867John McCall (void) Obj; 395da65ea86482bc116906edfb9ba1d7124f76cc867John McCall } 396da65ea86482bc116906edfb9ba1d7124f76cc867John McCall 397da65ea86482bc116906edfb9ba1d7124f76cc867John McCall /// Push a lazily-created cleanup on the stack. 398da65ea86482bc116906edfb9ba1d7124f76cc867John McCall template <class T, class A0, class A1, class A2> 3991f0fca54676cfa8616e7f3cd7a26788ab937e3cdJohn McCall void pushCleanup(CleanupKind Kind, A0 a0, A1 a1, A2 a2) { 4001f0fca54676cfa8616e7f3cd7a26788ab937e3cdJohn McCall void *Buffer = pushCleanup(Kind, sizeof(T)); 4011f0fca54676cfa8616e7f3cd7a26788ab937e3cdJohn McCall Cleanup *Obj = new(Buffer) T(a0, a1, a2); 402da65ea86482bc116906edfb9ba1d7124f76cc867John McCall (void) Obj; 403da65ea86482bc116906edfb9ba1d7124f76cc867John McCall } 404da65ea86482bc116906edfb9ba1d7124f76cc867John McCall 405da65ea86482bc116906edfb9ba1d7124f76cc867John McCall /// Push a lazily-created cleanup on the stack. 406da65ea86482bc116906edfb9ba1d7124f76cc867John McCall template <class T, class A0, class A1, class A2, class A3> 4071f0fca54676cfa8616e7f3cd7a26788ab937e3cdJohn McCall void pushCleanup(CleanupKind Kind, A0 a0, A1 a1, A2 a2, A3 a3) { 4081f0fca54676cfa8616e7f3cd7a26788ab937e3cdJohn McCall void *Buffer = pushCleanup(Kind, sizeof(T)); 4091f0fca54676cfa8616e7f3cd7a26788ab937e3cdJohn McCall Cleanup *Obj = new(Buffer) T(a0, a1, a2, a3); 410da65ea86482bc116906edfb9ba1d7124f76cc867John McCall (void) Obj; 411da65ea86482bc116906edfb9ba1d7124f76cc867John McCall } 412da65ea86482bc116906edfb9ba1d7124f76cc867John McCall 41377199713ab56f87ffad9a535ff2a0877704eed87John McCall /// Push a lazily-created cleanup on the stack. 41477199713ab56f87ffad9a535ff2a0877704eed87John McCall template <class T, class A0, class A1, class A2, class A3, class A4> 4151f0fca54676cfa8616e7f3cd7a26788ab937e3cdJohn McCall void pushCleanup(CleanupKind Kind, A0 a0, A1 a1, A2 a2, A3 a3, A4 a4) { 4161f0fca54676cfa8616e7f3cd7a26788ab937e3cdJohn McCall void *Buffer = pushCleanup(Kind, sizeof(T)); 4171f0fca54676cfa8616e7f3cd7a26788ab937e3cdJohn McCall Cleanup *Obj = new(Buffer) T(a0, a1, a2, a3, a4); 41877199713ab56f87ffad9a535ff2a0877704eed87John McCall (void) Obj; 41977199713ab56f87ffad9a535ff2a0877704eed87John McCall } 42077199713ab56f87ffad9a535ff2a0877704eed87John McCall 4217d8647f194ae4f2499e5bcd40dcfea34cd21ebc6John McCall // Feel free to add more variants of the following: 4227d8647f194ae4f2499e5bcd40dcfea34cd21ebc6John McCall 4237d8647f194ae4f2499e5bcd40dcfea34cd21ebc6John McCall /// Push a cleanup with non-constant storage requirements on the 4247d8647f194ae4f2499e5bcd40dcfea34cd21ebc6John McCall /// stack. The cleanup type must provide an additional static method: 4257d8647f194ae4f2499e5bcd40dcfea34cd21ebc6John McCall /// static size_t getExtraSize(size_t); 4267d8647f194ae4f2499e5bcd40dcfea34cd21ebc6John McCall /// The argument to this method will be the value N, which will also 4277d8647f194ae4f2499e5bcd40dcfea34cd21ebc6John McCall /// be passed as the first argument to the constructor. 4287d8647f194ae4f2499e5bcd40dcfea34cd21ebc6John McCall /// 4297d8647f194ae4f2499e5bcd40dcfea34cd21ebc6John McCall /// The data stored in the extra storage must obey the same 4307d8647f194ae4f2499e5bcd40dcfea34cd21ebc6John McCall /// restrictions as normal cleanup member data. 4317d8647f194ae4f2499e5bcd40dcfea34cd21ebc6John McCall /// 4327d8647f194ae4f2499e5bcd40dcfea34cd21ebc6John McCall /// The pointer returned from this method is valid until the cleanup 4337d8647f194ae4f2499e5bcd40dcfea34cd21ebc6John McCall /// stack is modified. 4347d8647f194ae4f2499e5bcd40dcfea34cd21ebc6John McCall template <class T, class A0, class A1, class A2> 4357d8647f194ae4f2499e5bcd40dcfea34cd21ebc6John McCall T *pushCleanupWithExtra(CleanupKind Kind, size_t N, A0 a0, A1 a1, A2 a2) { 4367d8647f194ae4f2499e5bcd40dcfea34cd21ebc6John McCall void *Buffer = pushCleanup(Kind, sizeof(T) + T::getExtraSize(N)); 4377d8647f194ae4f2499e5bcd40dcfea34cd21ebc6John McCall return new (Buffer) T(N, a0, a1, a2); 4387d8647f194ae4f2499e5bcd40dcfea34cd21ebc6John McCall } 4397d8647f194ae4f2499e5bcd40dcfea34cd21ebc6John McCall 440777d6e56ad9b1fed9866daf3ee6486d85c5b7d32John McCall /// Pops a cleanup scope off the stack. This is private to CGCleanup.cpp. 441f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall void popCleanup(); 442f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 443f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// Push a set of catch handlers on the stack. The catch is 444f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// uninitialized and will need to have the given number of handlers 445f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// set on it. 446f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall class EHCatchScope *pushCatch(unsigned NumHandlers); 447f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 448777d6e56ad9b1fed9866daf3ee6486d85c5b7d32John McCall /// Pops a catch scope off the stack. This is private to CGException.cpp. 449f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall void popCatch(); 450f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 451f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// Push an exceptions filter on the stack. 452f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall class EHFilterScope *pushFilter(unsigned NumFilters); 453f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 454f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// Pops an exceptions filter off the stack. 455f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall void popFilter(); 456f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 457f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// Push a terminate handler on the stack. 458f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall void pushTerminate(); 459f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 460f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// Pops a terminate handler off the stack. 461f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall void popTerminate(); 462f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 463f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// Determines whether the exception-scopes stack is empty. 464f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall bool empty() const { return StartOfData == EndOfBuffer; } 465f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 466f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall bool requiresLandingPad() const { 467777d6e56ad9b1fed9866daf3ee6486d85c5b7d32John McCall return InnermostEHScope != stable_end(); 468f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall } 469f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 470f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// Determines whether there are any normal cleanups on the stack. 471f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall bool hasNormalCleanups() const { 472f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall return InnermostNormalCleanup != stable_end(); 473f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall } 474f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 475f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// Returns the innermost normal cleanup on the stack, or 476f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// stable_end() if there are no normal cleanups. 477f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall stable_iterator getInnermostNormalCleanup() const { 478f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall return InnermostNormalCleanup; 479f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall } 480777d6e56ad9b1fed9866daf3ee6486d85c5b7d32John McCall stable_iterator getInnermostActiveNormalCleanup() const; 481f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 482777d6e56ad9b1fed9866daf3ee6486d85c5b7d32John McCall stable_iterator getInnermostEHScope() const { 483777d6e56ad9b1fed9866daf3ee6486d85c5b7d32John McCall return InnermostEHScope; 484f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall } 485f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 486777d6e56ad9b1fed9866daf3ee6486d85c5b7d32John McCall stable_iterator getInnermostActiveEHScope() const; 487f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 488f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// An unstable reference to a scope-stack depth. Invalidated by 489f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// pushes but not pops. 490f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall class iterator; 491f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 492f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// Returns an iterator pointing to the innermost EH scope. 493f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall iterator begin() const; 494f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 495f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// Returns an iterator pointing to the outermost EH scope. 496f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall iterator end() const; 497f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 498f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// Create a stable reference to the top of the EH stack. The 499f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// returned reference is valid until that scope is popped off the 500f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// stack. 501f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall stable_iterator stable_begin() const { 502f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall return stable_iterator(EndOfBuffer - StartOfData); 503f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall } 504f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 505f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// Create a stable reference to the bottom of the EH stack. 506f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall static stable_iterator stable_end() { 507f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall return stable_iterator(0); 508f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall } 509f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 510f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// Translates an iterator into a stable_iterator. 511f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall stable_iterator stabilize(iterator it) const; 512f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 513f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// Turn a stable reference to a scope depth into a unstable pointer 514f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// to the EH stack. 515f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall iterator find(stable_iterator save) const; 516f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 517f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// Removes the cleanup pointed to by the given stable_iterator. 518f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall void removeCleanup(stable_iterator save); 519f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 520f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// Add a branch fixup to the current cleanup scope. 521f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall BranchFixup &addBranchFixup() { 522f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall assert(hasNormalCleanups() && "adding fixup in scope without cleanups"); 523f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall BranchFixups.push_back(BranchFixup()); 524f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall return BranchFixups.back(); 525f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall } 526f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 527f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall unsigned getNumBranchFixups() const { return BranchFixups.size(); } 528f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall BranchFixup &getBranchFixup(unsigned I) { 529f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall assert(I < getNumBranchFixups()); 530f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall return BranchFixups[I]; 531f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall } 532f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 533ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall /// Pops lazily-removed fixups from the end of the list. This 534ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall /// should only be called by procedures which have just popped a 535ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall /// cleanup or resolved one or more fixups. 536ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall void popNullFixups(); 537ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall 538ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall /// Clears the branch-fixups list. This should only be called by 5398abdbd8118e37e759d1ce3f5814ee0a24b1589e8John McCall /// ResolveAllBranchFixups. 540ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall void clearFixups() { BranchFixups.clear(); } 541f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall}; 542f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 5435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// CodeGenFunction - This class organizes the per-function state that is used 5445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// while generating LLVM code. 5455936e33bf74dd6bf126ceee0f6169a2593d03a69John McCallclass CodeGenFunction : public CodeGenTypeCache { 546f56faa01936b9cf909623d7f06e3c2569ca4a78eDmitri Gribenko CodeGenFunction(const CodeGenFunction &) LLVM_DELETED_FUNCTION; 547f56faa01936b9cf909623d7f06e3c2569ca4a78eDmitri Gribenko void operator=(const CodeGenFunction &) LLVM_DELETED_FUNCTION; 5484c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall 5494c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall friend class CGCXXABI; 550bfc0c1ae4b505b52b36f572a9641f99e76879cabChris Lattnerpublic: 551ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall /// A jump destination is an abstract label, branching to which may 552ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall /// require a jump out through normal cleanups. 553f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall struct JumpDest { 554ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall JumpDest() : Block(0), ScopeDepth(), Index(0) {} 555ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall JumpDest(llvm::BasicBlock *Block, 556ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall EHScopeStack::stable_iterator Depth, 557ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall unsigned Index) 558ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall : Block(Block), ScopeDepth(Depth), Index(Index) {} 559ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall 560ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall bool isValid() const { return Block != 0; } 561ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall llvm::BasicBlock *getBlock() const { return Block; } 562ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall EHScopeStack::stable_iterator getScopeDepth() const { return ScopeDepth; } 563ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall unsigned getDestIndex() const { return Index; } 5649cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer 565ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall private: 566f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall llvm::BasicBlock *Block; 567f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall EHScopeStack::stable_iterator ScopeDepth; 568ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall unsigned Index; 569ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall }; 570ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall 5715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer CodeGenModule &CGM; // Per-module state. 572444be7366d0a1e172c0290a1ea54c1cb16b5947cDaniel Dunbar const TargetInfo &Target; 5730dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 57458dee10ed2eee34035f62d1c2d32b3639e9182f8Chris Lattner typedef std::pair<llvm::Value *, llvm::Value *> ComplexPairTy; 57545d196b8387dcefc4df26cda114fa34c6528e928Daniel Dunbar CGBuilderTy Builder; 5760dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 577b5437d238752dc297e42410e98d38d5250fe0463Chris Lattner /// CurFuncDecl - Holds the Decl for the current function or ObjC method. 578b5437d238752dc297e42410e98d38d5250fe0463Chris Lattner /// This excludes BlockDecls. 5794111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner const Decl *CurFuncDecl; 580b5437d238752dc297e42410e98d38d5250fe0463Chris Lattner /// CurCodeDecl - This is the inner-most code context, which includes blocks. 581b5437d238752dc297e42410e98d38d5250fe0463Chris Lattner const Decl *CurCodeDecl; 58288b5396b0897f28d22ae3debf4a0d97b33b6c362Daniel Dunbar const CGFunctionInfo *CurFnInfo; 583391d77a26382dddf25da73e29fc1fa5aaaea4c6fChris Lattner QualType FnRetTy; 5845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer llvm::Function *CurFn; 5855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5866a1e0eb557d47e85185e09bdf8721f53f4bf9c9cMike Stump /// CurGD - The GlobalDecl for the current function being compiled. 5876a1e0eb557d47e85185e09bdf8721f53f4bf9c9cMike Stump GlobalDecl CurGD; 5886a1e0eb557d47e85185e09bdf8721f53f4bf9c9cMike Stump 589f85e193739c953358c865005855253af4f68a497John McCall /// PrologueCleanupDepth - The cleanup depth enclosing all the 590f85e193739c953358c865005855253af4f68a497John McCall /// cleanups associated with the parameters. 591f85e193739c953358c865005855253af4f68a497John McCall EHScopeStack::stable_iterator PrologueCleanupDepth; 592f85e193739c953358c865005855253af4f68a497John McCall 5935ca2084cf9b529563209429857f01fdae9dcdfa5Daniel Dunbar /// ReturnBlock - Unified return block. 594f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall JumpDest ReturnBlock; 595f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 5960dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// ReturnValue - The temporary alloca to hold the return value. This is null 597f3477c13eeaf11b32a41f181398fb5deffd0dd73Sylvestre Ledru /// iff the function has no return value. 598b17daf9ab790ae71aacad2cc4aa11cd8d86c25d1Eli Friedman llvm::Value *ReturnValue; 5990dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 6005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// AllocaInsertPoint - This is an instruction in the entry block before which 6015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// we prefer to insert allocas. 602481769b5dc102b0256b35581e787909ad5edfab5Chris Lattner llvm::AssertingVH<llvm::Instruction> AllocaInsertPt; 6030ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar 604b3198a841e7f356f171f1e11faff014b2deb1eb8Nuno Lopes /// BoundsChecking - Emit run-time bounds checks. Higher values mean 605b3198a841e7f356f171f1e11faff014b2deb1eb8Nuno Lopes /// potentially higher performance penalties. 606b3198a841e7f356f171f1e11faff014b2deb1eb8Nuno Lopes unsigned char BoundsChecking; 607b3198a841e7f356f171f1e11faff014b2deb1eb8Nuno Lopes 608d6396a681c9acbe56bc41bbc2bed2db45755bcd7Richard Smith /// \brief Whether any type-checking sanitizers are enabled. If \c false, 609d6396a681c9acbe56bc41bbc2bed2db45755bcd7Richard Smith /// calls to EmitTypeCheck can be skipped. 610d6396a681c9acbe56bc41bbc2bed2db45755bcd7Richard Smith bool SanitizePerformTypeCheck; 6119cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer 6124f45bc099f2665bc6e4bcbb169aa452390dbf3feWill Dietz /// \brief Sanitizer options to use for this function. 6134f45bc099f2665bc6e4bcbb169aa452390dbf3feWill Dietz const SanitizerOptions *SanOpts; 6144f45bc099f2665bc6e4bcbb169aa452390dbf3feWill Dietz 615f85e193739c953358c865005855253af4f68a497John McCall /// In ARC, whether we should autorelease the return value. 616f85e193739c953358c865005855253af4f68a497John McCall bool AutoreleaseResult; 617f85e193739c953358c865005855253af4f68a497John McCall 618d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall const CodeGen::CGBlockInfo *BlockInfo; 619d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall llvm::Value *BlockPointer; 620d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall 621cec5ebd4a6a89a7023d04cec728fd340b541ed61Eli Friedman llvm::DenseMap<const VarDecl *, FieldDecl *> LambdaCaptureFields; 622cec5ebd4a6a89a7023d04cec728fd340b541ed61Eli Friedman FieldDecl *LambdaThisCaptureField; 623cec5ebd4a6a89a7023d04cec728fd340b541ed61Eli Friedman 6243d91bbcdab155181556969cad6ec97014405acedDouglas Gregor /// \brief A mapping from NRVO variables to the flags used to indicate 6253d91bbcdab155181556969cad6ec97014405acedDouglas Gregor /// when the NRVO has been applied to this variable. 6263d91bbcdab155181556969cad6ec97014405acedDouglas Gregor llvm::DenseMap<const VarDecl *, llvm::Value *> NRVOFlags; 6279cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer 628f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall EHScopeStack EHStack; 6290dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 630ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall /// i32s containing the indexes of the cleanup destinations. 631ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall llvm::AllocaInst *NormalCleanupDest; 632ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall 633ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall unsigned NextCleanupDestIndex; 634ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall 6351a343ebbf413e8eae6b2737b2b2d79cbf5765571John McCall /// FirstBlockInfo - The head of a singly-linked-list of block layouts. 6361a343ebbf413e8eae6b2737b2b2d79cbf5765571John McCall CGBlockInfo *FirstBlockInfo; 6371a343ebbf413e8eae6b2737b2b2d79cbf5765571John McCall 638777d6e56ad9b1fed9866daf3ee6486d85c5b7d32John McCall /// EHResumeBlock - Unified block containing a call to llvm.eh.resume. 639777d6e56ad9b1fed9866daf3ee6486d85c5b7d32John McCall llvm::BasicBlock *EHResumeBlock; 640777d6e56ad9b1fed9866daf3ee6486d85c5b7d32John McCall 641285cfd8953d4ca4da613a47a0d691f7234068f8cBill Wendling /// The exception slot. All landing pads write the current exception pointer 642285cfd8953d4ca4da613a47a0d691f7234068f8cBill Wendling /// into this alloca. 643f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall llvm::Value *ExceptionSlot; 6440dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 645285cfd8953d4ca4da613a47a0d691f7234068f8cBill Wendling /// The selector slot. Under the MandatoryCleanup model, all landing pads 646285cfd8953d4ca4da613a47a0d691f7234068f8cBill Wendling /// write the current selector value into this alloca. 64793c332a8ba2c193c435b293966d343dab15f555bJohn McCall llvm::AllocaInst *EHSelectorSlot; 64893c332a8ba2c193c435b293966d343dab15f555bJohn McCall 649f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// Emits a landing pad for the current EH stack. 650f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall llvm::BasicBlock *EmitLandingPad(); 6510dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 652f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall llvm::BasicBlock *getInvokeDestImpl(); 65399533834ba8f3658559f334e68a518ebb6388ceaMike Stump 654150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall template <class T> 655804b807ea918184d6de63bd745e1ff75a9bfc679John McCall typename DominatingValue<T>::saved_type saveValueInCond(T value) { 656804b807ea918184d6de63bd745e1ff75a9bfc679John McCall return DominatingValue<T>::save(*this, value); 657150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall } 658150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall 659f1549f66a8216a78112286e3978cea2c29d6334cJohn McCallpublic: 660f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// ObjCEHValueStack - Stack of Objective-C exception values, used for 661f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// rethrows. 662686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVector<llvm::Value*, 8> ObjCEHValueStack; 663bb66f9f2e454135b86462d121629275b6ac38e96Anders Carlsson 664d768e9d29abe1ac1ccc3ed63f2dce835d9bab342John McCall /// A class controlling the emission of a finally block. 665d768e9d29abe1ac1ccc3ed63f2dce835d9bab342John McCall class FinallyInfo { 666d768e9d29abe1ac1ccc3ed63f2dce835d9bab342John McCall /// Where the catchall's edge through the cleanup should go. 667d768e9d29abe1ac1ccc3ed63f2dce835d9bab342John McCall JumpDest RethrowDest; 668d768e9d29abe1ac1ccc3ed63f2dce835d9bab342John McCall 669d768e9d29abe1ac1ccc3ed63f2dce835d9bab342John McCall /// A function to call to enter the catch. 670d768e9d29abe1ac1ccc3ed63f2dce835d9bab342John McCall llvm::Constant *BeginCatchFn; 671d768e9d29abe1ac1ccc3ed63f2dce835d9bab342John McCall 672d768e9d29abe1ac1ccc3ed63f2dce835d9bab342John McCall /// An i1 variable indicating whether or not the @finally is 673d768e9d29abe1ac1ccc3ed63f2dce835d9bab342John McCall /// running for an exception. 674d768e9d29abe1ac1ccc3ed63f2dce835d9bab342John McCall llvm::AllocaInst *ForEHVar; 675d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump 676d768e9d29abe1ac1ccc3ed63f2dce835d9bab342John McCall /// An i8* variable into which the exception pointer to rethrow 677d768e9d29abe1ac1ccc3ed63f2dce835d9bab342John McCall /// has been saved. 678d768e9d29abe1ac1ccc3ed63f2dce835d9bab342John McCall llvm::AllocaInst *SavedExnVar; 679d768e9d29abe1ac1ccc3ed63f2dce835d9bab342John McCall 680d768e9d29abe1ac1ccc3ed63f2dce835d9bab342John McCall public: 681d768e9d29abe1ac1ccc3ed63f2dce835d9bab342John McCall void enter(CodeGenFunction &CGF, const Stmt *Finally, 682d768e9d29abe1ac1ccc3ed63f2dce835d9bab342John McCall llvm::Constant *beginCatchFn, llvm::Constant *endCatchFn, 683d768e9d29abe1ac1ccc3ed63f2dce835d9bab342John McCall llvm::Constant *rethrowFn); 684d768e9d29abe1ac1ccc3ed63f2dce835d9bab342John McCall void exit(CodeGenFunction &CGF); 685d768e9d29abe1ac1ccc3ed63f2dce835d9bab342John McCall }; 686f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 687150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall /// pushFullExprCleanup - Push a cleanup to be run at the end of the 688150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall /// current full-expression. Safe against the possibility that 689150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall /// we're currently inside a conditionally-evaluated expression. 6903ad32c8d93eb65d1d4943d7df567fc9b4f55d137John McCall template <class T, class A0> 6913ad32c8d93eb65d1d4943d7df567fc9b4f55d137John McCall void pushFullExprCleanup(CleanupKind kind, A0 a0) { 6923ad32c8d93eb65d1d4943d7df567fc9b4f55d137John McCall // If we're not in a conditional branch, or if none of the 6933ad32c8d93eb65d1d4943d7df567fc9b4f55d137John McCall // arguments requires saving, then use the unconditional cleanup. 694c4a1a8450a3613ef256a71b9d8305b41f79eef50John McCall if (!isInConditionalBranch()) 695c4a1a8450a3613ef256a71b9d8305b41f79eef50John McCall return EHStack.pushCleanup<T>(kind, a0); 6963ad32c8d93eb65d1d4943d7df567fc9b4f55d137John McCall 697804b807ea918184d6de63bd745e1ff75a9bfc679John McCall typename DominatingValue<A0>::saved_type a0_saved = saveValueInCond(a0); 6983ad32c8d93eb65d1d4943d7df567fc9b4f55d137John McCall 6993ad32c8d93eb65d1d4943d7df567fc9b4f55d137John McCall typedef EHScopeStack::ConditionalCleanup1<T, A0> CleanupType; 7003ad32c8d93eb65d1d4943d7df567fc9b4f55d137John McCall EHStack.pushCleanup<CleanupType>(kind, a0_saved); 7013ad32c8d93eb65d1d4943d7df567fc9b4f55d137John McCall initFullExprCleanup(); 7023ad32c8d93eb65d1d4943d7df567fc9b4f55d137John McCall } 7033ad32c8d93eb65d1d4943d7df567fc9b4f55d137John McCall 7043ad32c8d93eb65d1d4943d7df567fc9b4f55d137John McCall /// pushFullExprCleanup - Push a cleanup to be run at the end of the 7053ad32c8d93eb65d1d4943d7df567fc9b4f55d137John McCall /// current full-expression. Safe against the possibility that 7063ad32c8d93eb65d1d4943d7df567fc9b4f55d137John McCall /// we're currently inside a conditionally-evaluated expression. 707150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall template <class T, class A0, class A1> 708150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall void pushFullExprCleanup(CleanupKind kind, A0 a0, A1 a1) { 709150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall // If we're not in a conditional branch, or if none of the 710150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall // arguments requires saving, then use the unconditional cleanup. 711c4a1a8450a3613ef256a71b9d8305b41f79eef50John McCall if (!isInConditionalBranch()) 712c4a1a8450a3613ef256a71b9d8305b41f79eef50John McCall return EHStack.pushCleanup<T>(kind, a0, a1); 713150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall 714804b807ea918184d6de63bd745e1ff75a9bfc679John McCall typename DominatingValue<A0>::saved_type a0_saved = saveValueInCond(a0); 715804b807ea918184d6de63bd745e1ff75a9bfc679John McCall typename DominatingValue<A1>::saved_type a1_saved = saveValueInCond(a1); 716150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall 717150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall typedef EHScopeStack::ConditionalCleanup2<T, A0, A1> CleanupType; 7183ad32c8d93eb65d1d4943d7df567fc9b4f55d137John McCall EHStack.pushCleanup<CleanupType>(kind, a0_saved, a1_saved); 7193ad32c8d93eb65d1d4943d7df567fc9b4f55d137John McCall initFullExprCleanup(); 720150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall } 721150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall 722d7b23167763f43d3e76b0de26141b1e52613ee3cDouglas Gregor /// pushFullExprCleanup - Push a cleanup to be run at the end of the 723d7b23167763f43d3e76b0de26141b1e52613ee3cDouglas Gregor /// current full-expression. Safe against the possibility that 724d7b23167763f43d3e76b0de26141b1e52613ee3cDouglas Gregor /// we're currently inside a conditionally-evaluated expression. 725d7b23167763f43d3e76b0de26141b1e52613ee3cDouglas Gregor template <class T, class A0, class A1, class A2> 726d7b23167763f43d3e76b0de26141b1e52613ee3cDouglas Gregor void pushFullExprCleanup(CleanupKind kind, A0 a0, A1 a1, A2 a2) { 727d7b23167763f43d3e76b0de26141b1e52613ee3cDouglas Gregor // If we're not in a conditional branch, or if none of the 728d7b23167763f43d3e76b0de26141b1e52613ee3cDouglas Gregor // arguments requires saving, then use the unconditional cleanup. 729d7b23167763f43d3e76b0de26141b1e52613ee3cDouglas Gregor if (!isInConditionalBranch()) { 730c4a1a8450a3613ef256a71b9d8305b41f79eef50John McCall return EHStack.pushCleanup<T>(kind, a0, a1, a2); 731d7b23167763f43d3e76b0de26141b1e52613ee3cDouglas Gregor } 732d7b23167763f43d3e76b0de26141b1e52613ee3cDouglas Gregor 733d7b23167763f43d3e76b0de26141b1e52613ee3cDouglas Gregor typename DominatingValue<A0>::saved_type a0_saved = saveValueInCond(a0); 734d7b23167763f43d3e76b0de26141b1e52613ee3cDouglas Gregor typename DominatingValue<A1>::saved_type a1_saved = saveValueInCond(a1); 735d7b23167763f43d3e76b0de26141b1e52613ee3cDouglas Gregor typename DominatingValue<A2>::saved_type a2_saved = saveValueInCond(a2); 736d7b23167763f43d3e76b0de26141b1e52613ee3cDouglas Gregor 737d7b23167763f43d3e76b0de26141b1e52613ee3cDouglas Gregor typedef EHScopeStack::ConditionalCleanup3<T, A0, A1, A2> CleanupType; 738d7b23167763f43d3e76b0de26141b1e52613ee3cDouglas Gregor EHStack.pushCleanup<CleanupType>(kind, a0_saved, a1_saved, a2_saved); 739d7b23167763f43d3e76b0de26141b1e52613ee3cDouglas Gregor initFullExprCleanup(); 740d7b23167763f43d3e76b0de26141b1e52613ee3cDouglas Gregor } 741d7b23167763f43d3e76b0de26141b1e52613ee3cDouglas Gregor 7429928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall /// pushFullExprCleanup - Push a cleanup to be run at the end of the 7439928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall /// current full-expression. Safe against the possibility that 7449928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall /// we're currently inside a conditionally-evaluated expression. 7459928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall template <class T, class A0, class A1, class A2, class A3> 7469928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall void pushFullExprCleanup(CleanupKind kind, A0 a0, A1 a1, A2 a2, A3 a3) { 7479928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall // If we're not in a conditional branch, or if none of the 7489928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall // arguments requires saving, then use the unconditional cleanup. 7499928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall if (!isInConditionalBranch()) { 7509928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall return EHStack.pushCleanup<T>(kind, a0, a1, a2, a3); 7519928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall } 7529928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall 7539928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall typename DominatingValue<A0>::saved_type a0_saved = saveValueInCond(a0); 7549928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall typename DominatingValue<A1>::saved_type a1_saved = saveValueInCond(a1); 7559928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall typename DominatingValue<A2>::saved_type a2_saved = saveValueInCond(a2); 7569928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall typename DominatingValue<A3>::saved_type a3_saved = saveValueInCond(a3); 7579928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall 7589928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall typedef EHScopeStack::ConditionalCleanup4<T, A0, A1, A2, A3> CleanupType; 7599928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall EHStack.pushCleanup<CleanupType>(kind, a0_saved, a1_saved, 7609928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall a2_saved, a3_saved); 7619928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall initFullExprCleanup(); 7629928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall } 7639928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall 7646f103ba42cb69d50005a977c5ea583984ab63fc4John McCall /// Set up the last cleaup that was pushed as a conditional 7656f103ba42cb69d50005a977c5ea583984ab63fc4John McCall /// full-expression cleanup. 7666f103ba42cb69d50005a977c5ea583984ab63fc4John McCall void initFullExprCleanup(); 7676f103ba42cb69d50005a977c5ea583984ab63fc4John McCall 768f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// PushDestructorCleanup - Push a cleanup to call the 769f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// complete-object destructor of an object of the given type at the 770f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// given address. Does nothing if T is not a C++ class type with a 771f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// non-trivial destructor. 772f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall void PushDestructorCleanup(QualType T, llvm::Value *Addr); 773f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 77481407d404a3fc8d24d0e2a052d85cae183033e2bJohn McCall /// PushDestructorCleanup - Push a cleanup to call the 77581407d404a3fc8d24d0e2a052d85cae183033e2bJohn McCall /// complete-object variant of the given destructor on the object at 77681407d404a3fc8d24d0e2a052d85cae183033e2bJohn McCall /// the given address. 77781407d404a3fc8d24d0e2a052d85cae183033e2bJohn McCall void PushDestructorCleanup(const CXXDestructorDecl *Dtor, 77881407d404a3fc8d24d0e2a052d85cae183033e2bJohn McCall llvm::Value *Addr); 77981407d404a3fc8d24d0e2a052d85cae183033e2bJohn McCall 780f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// PopCleanupBlock - Will pop the cleanup entry on the stack and 781f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// process all branch fixups. 782ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall void PopCleanupBlock(bool FallThroughIsBranchThrough = false); 783f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 7847d8647f194ae4f2499e5bcd40dcfea34cd21ebc6John McCall /// DeactivateCleanupBlock - Deactivates the given cleanup block. 7857d8647f194ae4f2499e5bcd40dcfea34cd21ebc6John McCall /// The block cannot be reactivated. Pops it if it's the top of the 7867d8647f194ae4f2499e5bcd40dcfea34cd21ebc6John McCall /// stack. 7876f103ba42cb69d50005a977c5ea583984ab63fc4John McCall /// 7886f103ba42cb69d50005a977c5ea583984ab63fc4John McCall /// \param DominatingIP - An instruction which is known to 7896f103ba42cb69d50005a977c5ea583984ab63fc4John McCall /// dominate the current IP (if set) and which lies along 7906f103ba42cb69d50005a977c5ea583984ab63fc4John McCall /// all paths of execution between the current IP and the 7916f103ba42cb69d50005a977c5ea583984ab63fc4John McCall /// the point at which the cleanup comes into scope. 7926f103ba42cb69d50005a977c5ea583984ab63fc4John McCall void DeactivateCleanupBlock(EHScopeStack::stable_iterator Cleanup, 7936f103ba42cb69d50005a977c5ea583984ab63fc4John McCall llvm::Instruction *DominatingIP); 7947d8647f194ae4f2499e5bcd40dcfea34cd21ebc6John McCall 7957d8647f194ae4f2499e5bcd40dcfea34cd21ebc6John McCall /// ActivateCleanupBlock - Activates an initially-inactive cleanup. 7967d8647f194ae4f2499e5bcd40dcfea34cd21ebc6John McCall /// Cannot be used to resurrect a deactivated cleanup. 7976f103ba42cb69d50005a977c5ea583984ab63fc4John McCall /// 7986f103ba42cb69d50005a977c5ea583984ab63fc4John McCall /// \param DominatingIP - An instruction which is known to 7996f103ba42cb69d50005a977c5ea583984ab63fc4John McCall /// dominate the current IP (if set) and which lies along 8006f103ba42cb69d50005a977c5ea583984ab63fc4John McCall /// all paths of execution between the current IP and the 8016f103ba42cb69d50005a977c5ea583984ab63fc4John McCall /// the point at which the cleanup comes into scope. 8026f103ba42cb69d50005a977c5ea583984ab63fc4John McCall void ActivateCleanupBlock(EHScopeStack::stable_iterator Cleanup, 8036f103ba42cb69d50005a977c5ea583984ab63fc4John McCall llvm::Instruction *DominatingIP); 804cd2d2b7814e0104ed41a8da159a06a8ca77b70d8John McCall 805f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// \brief Enters a new scope for capturing cleanups, all of which 806f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// will be executed once the scope is exited. 807f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall class RunCleanupsScope { 808f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall EHScopeStack::stable_iterator CleanupStackDepth; 80901234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor bool OldDidCallStackSave; 810ed383135bcffdb8849418896b742fbca7fa2b787John McCall protected: 8115656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor bool PerformCleanup; 812ed383135bcffdb8849418896b742fbca7fa2b787John McCall private: 81301234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor 814f56faa01936b9cf909623d7f06e3c2569ca4a78eDmitri Gribenko RunCleanupsScope(const RunCleanupsScope &) LLVM_DELETED_FUNCTION; 815f56faa01936b9cf909623d7f06e3c2569ca4a78eDmitri Gribenko void operator=(const RunCleanupsScope &) LLVM_DELETED_FUNCTION; 81601234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor 817c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher protected: 818c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher CodeGenFunction& CGF; 8194f45bc099f2665bc6e4bcbb169aa452390dbf3feWill Dietz 82001234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor public: 82101234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor /// \brief Enter a new cleanup scope. 8229cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer explicit RunCleanupsScope(CodeGenFunction &CGF) 823c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher : PerformCleanup(true), CGF(CGF) 8245656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor { 825f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall CleanupStackDepth = CGF.EHStack.stable_begin(); 82601234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor OldDidCallStackSave = CGF.DidCallStackSave; 8274ada2ca7d82dab68d3646f3eb6dcdfee072e8ea4Argyrios Kyrtzidis CGF.DidCallStackSave = false; 82801234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor } 82901234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor 83001234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor /// \brief Exit this cleanup scope, emitting any accumulated 83101234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor /// cleanups. 832f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall ~RunCleanupsScope() { 8335656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor if (PerformCleanup) { 8345656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor CGF.DidCallStackSave = OldDidCallStackSave; 835f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall CGF.PopCleanupBlocks(CleanupStackDepth); 8365656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor } 8375656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor } 8385656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor 8395656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor /// \brief Determine whether this scope requires any cleanups. 8405656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor bool requiresCleanups() const { 841f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall return CGF.EHStack.stable_begin() != CleanupStackDepth; 8425656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor } 8435656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor 8445656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor /// \brief Force the emission of cleanups now, instead of waiting 8455656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor /// until this object is destroyed. 8465656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor void ForceCleanup() { 8475656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor assert(PerformCleanup && "Already forced cleanup"); 84801234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor CGF.DidCallStackSave = OldDidCallStackSave; 849f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall CGF.PopCleanupBlocks(CleanupStackDepth); 8505656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor PerformCleanup = false; 85101234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor } 85201234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor }; 85301234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor 854c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher class LexicalScope: protected RunCleanupsScope { 855c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher SourceRange Range; 856c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher 857f56faa01936b9cf909623d7f06e3c2569ca4a78eDmitri Gribenko LexicalScope(const LexicalScope &) LLVM_DELETED_FUNCTION; 858f56faa01936b9cf909623d7f06e3c2569ca4a78eDmitri Gribenko void operator=(const LexicalScope &) LLVM_DELETED_FUNCTION; 859c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher 860c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher public: 861c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher /// \brief Enter a new cleanup scope. 862c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher explicit LexicalScope(CodeGenFunction &CGF, SourceRange Range) 863ed383135bcffdb8849418896b742fbca7fa2b787John McCall : RunCleanupsScope(CGF), Range(Range) { 864c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher if (CGDebugInfo *DI = CGF.getDebugInfo()) 865c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher DI->EmitLexicalBlockStart(CGF.Builder, Range.getBegin()); 866c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher } 867c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher 868c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher /// \brief Exit this cleanup scope, emitting any accumulated 869c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher /// cleanups. 870c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher ~LexicalScope() { 871ed383135bcffdb8849418896b742fbca7fa2b787John McCall if (PerformCleanup) endLexicalScope(); 872c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher } 873c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher 874c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher /// \brief Force the emission of cleanups now, instead of waiting 875c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher /// until this object is destroyed. 876c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher void ForceCleanup() { 877c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher RunCleanupsScope::ForceCleanup(); 8784a68c7bc86bcaf44f6aee5a470c743b47c11716eJohn McCall endLexicalScope(); 879ed383135bcffdb8849418896b742fbca7fa2b787John McCall } 880ed383135bcffdb8849418896b742fbca7fa2b787John McCall 881ed383135bcffdb8849418896b742fbca7fa2b787John McCall private: 882ed383135bcffdb8849418896b742fbca7fa2b787John McCall void endLexicalScope() { 883ed383135bcffdb8849418896b742fbca7fa2b787John McCall if (CGDebugInfo *DI = CGF.getDebugInfo()) 884c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher DI->EmitLexicalBlockEnd(CGF.Builder, Range.getEnd()); 885c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher } 886c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher }; 887c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher 88844ec82b4a1597802f5bf17721481b8c265bc8dc5Anders Carlsson 889f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// PopCleanupBlocks - Takes the old cleanup stack size and emits 890f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// the cleanup blocks that have been added. 891f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall void PopCleanupBlocks(EHScopeStack::stable_iterator OldCleanupStackSize); 89244ec82b4a1597802f5bf17721481b8c265bc8dc5Anders Carlsson 893ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall void ResolveBranchFixups(llvm::BasicBlock *Target); 894ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall 895f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// The given basic block lies in the current EH scope, but may be a 896f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// target of a potentially scope-crossing jump; get a stable handle 897f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// to which we can perform this jump later. 898ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall JumpDest getJumpDestInCurrentScope(llvm::BasicBlock *Target) { 899413e67778d593215d2f2161a4e712c8568f1ddd0John McCall return JumpDest(Target, 900413e67778d593215d2f2161a4e712c8568f1ddd0John McCall EHStack.getInnermostNormalCleanup(), 901413e67778d593215d2f2161a4e712c8568f1ddd0John McCall NextCleanupDestIndex++); 902f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall } 903c71c845fe77ee1f891d60232ec320912d88557eeAnders Carlsson 904f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// The given basic block lies in the current EH scope, but may be a 905f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// target of a potentially scope-crossing jump; get a stable handle 906f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// to which we can perform this jump later. 907686775deca8b8685eb90801495880e3abdd844c2Chris Lattner JumpDest getJumpDestInCurrentScope(StringRef Name = StringRef()) { 908ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall return getJumpDestInCurrentScope(createBasicBlock(Name)); 909f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall } 910f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 911f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// EmitBranchThroughCleanup - Emit a branch from the current insert 912f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// block through the normal cleanup handling code (if any) and then 913f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// on to \arg Dest. 914f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall void EmitBranchThroughCleanup(JumpDest Dest); 915b11f9198111796ada02b57f62cdea92134fde9f7Chris Lattner 916b11f9198111796ada02b57f62cdea92134fde9f7Chris Lattner /// isObviouslyBranchWithoutCleanups - Return true if a branch to the 917b11f9198111796ada02b57f62cdea92134fde9f7Chris Lattner /// specified destination obviously has no cleanups to run. 'false' is always 918b11f9198111796ada02b57f62cdea92134fde9f7Chris Lattner /// a conservatively correct answer for this method. 919b11f9198111796ada02b57f62cdea92134fde9f7Chris Lattner bool isObviouslyBranchWithoutCleanups(JumpDest Dest) const; 920f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 921777d6e56ad9b1fed9866daf3ee6486d85c5b7d32John McCall /// popCatchScope - Pops the catch scope at the top of the EHScope 922777d6e56ad9b1fed9866daf3ee6486d85c5b7d32John McCall /// stack, emitting any required code (other than the catch handlers 923777d6e56ad9b1fed9866daf3ee6486d85c5b7d32John McCall /// themselves). 924777d6e56ad9b1fed9866daf3ee6486d85c5b7d32John McCall void popCatchScope(); 925ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall 926c686004145b1f4dbeb38173a0886ba7040ae0089David Chisnall llvm::BasicBlock *getEHResumeBlock(bool isCleanup); 927777d6e56ad9b1fed9866daf3ee6486d85c5b7d32John McCall llvm::BasicBlock *getEHDispatchBlock(EHScopeStack::stable_iterator scope); 9280dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 929150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall /// An object to manage conditionally-evaluated expressions. 930150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall class ConditionalEvaluation { 931150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall llvm::BasicBlock *StartBB; 9321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 933150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall public: 934150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall ConditionalEvaluation(CodeGenFunction &CGF) 935150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall : StartBB(CGF.Builder.GetInsertBlock()) {} 9369cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer 937150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall void begin(CodeGenFunction &CGF) { 938150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall assert(CGF.OutermostConditional != this); 939150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall if (!CGF.OutermostConditional) 940150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall CGF.OutermostConditional = this; 941150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall } 942150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall 943150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall void end(CodeGenFunction &CGF) { 944150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall assert(CGF.OutermostConditional != 0); 945150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall if (CGF.OutermostConditional == this) 946150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall CGF.OutermostConditional = 0; 947150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall } 948150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall 949150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall /// Returns a block which will be executed prior to each 950150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall /// evaluation of the conditional code. 951150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall llvm::BasicBlock *getStartingBlock() const { 952150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall return StartBB; 953150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall } 954150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall }; 9551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 9563019c444c672938c57f5573840071ecd73425ee7John McCall /// isInConditionalBranch - Return true if we're currently emitting 9573019c444c672938c57f5573840071ecd73425ee7John McCall /// one branch or the other of a conditional expression. 958150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall bool isInConditionalBranch() const { return OutermostConditional != 0; } 959150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall 9606f103ba42cb69d50005a977c5ea583984ab63fc4John McCall void setBeforeOutermostConditional(llvm::Value *value, llvm::Value *addr) { 9616f103ba42cb69d50005a977c5ea583984ab63fc4John McCall assert(isInConditionalBranch()); 9626f103ba42cb69d50005a977c5ea583984ab63fc4John McCall llvm::BasicBlock *block = OutermostConditional->getStartingBlock(); 9636f103ba42cb69d50005a977c5ea583984ab63fc4John McCall new llvm::StoreInst(value, addr, &block->back()); 9646f103ba42cb69d50005a977c5ea583984ab63fc4John McCall } 9656f103ba42cb69d50005a977c5ea583984ab63fc4John McCall 966150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall /// An RAII object to record that we're evaluating a statement 967150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall /// expression. 968150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall class StmtExprEvaluation { 969150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall CodeGenFunction &CGF; 970150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall 971150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall /// We have to save the outermost conditional: cleanups in a 972150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall /// statement expression aren't conditional just because the 973150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall /// StmtExpr is. 974150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall ConditionalEvaluation *SavedOutermostConditional; 975150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall 976150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall public: 977150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall StmtExprEvaluation(CodeGenFunction &CGF) 978150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall : CGF(CGF), SavedOutermostConditional(CGF.OutermostConditional) { 979150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall CGF.OutermostConditional = 0; 980150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall } 981150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall 982150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall ~StmtExprEvaluation() { 983150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall CGF.OutermostConditional = SavedOutermostConditional; 984150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall CGF.EnsureInsertPoint(); 985150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall } 986150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall }; 987e996ffd240f20a1048179d7727a6ee3227261921John McCall 98856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// An object which temporarily prevents a value from being 98956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// destroyed by aggressive peephole optimizations that assume that 99056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// all uses of a value have been realized in the IR. 99156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall class PeepholeProtection { 99256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall llvm::Instruction *Inst; 99356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall friend class CodeGenFunction; 99456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 99556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall public: 99656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall PeepholeProtection() : Inst(0) {} 9974b9c2d235fb9449e249d74f48ecfec601650de93John McCall }; 99856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 9994b9c2d235fb9449e249d74f48ecfec601650de93John McCall /// A non-RAII class containing all the information about a bound 10004b9c2d235fb9449e249d74f48ecfec601650de93John McCall /// opaque value. OpaqueValueMapping, below, is a RAII wrapper for 10014b9c2d235fb9449e249d74f48ecfec601650de93John McCall /// this which makes individual mappings very simple; using this 10024b9c2d235fb9449e249d74f48ecfec601650de93John McCall /// class directly is useful when you have a variable number of 10034b9c2d235fb9449e249d74f48ecfec601650de93John McCall /// opaque values or don't want the RAII functionality for some 10044b9c2d235fb9449e249d74f48ecfec601650de93John McCall /// reason. 10054b9c2d235fb9449e249d74f48ecfec601650de93John McCall class OpaqueValueMappingData { 1006e996ffd240f20a1048179d7727a6ee3227261921John McCall const OpaqueValueExpr *OpaqueValue; 100756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall bool BoundLValue; 100856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall CodeGenFunction::PeepholeProtection Protection; 1009e996ffd240f20a1048179d7727a6ee3227261921John McCall 10104b9c2d235fb9449e249d74f48ecfec601650de93John McCall OpaqueValueMappingData(const OpaqueValueExpr *ov, 10114b9c2d235fb9449e249d74f48ecfec601650de93John McCall bool boundLValue) 10124b9c2d235fb9449e249d74f48ecfec601650de93John McCall : OpaqueValue(ov), BoundLValue(boundLValue) {} 1013e996ffd240f20a1048179d7727a6ee3227261921John McCall public: 10144b9c2d235fb9449e249d74f48ecfec601650de93John McCall OpaqueValueMappingData() : OpaqueValue(0) {} 10154b9c2d235fb9449e249d74f48ecfec601650de93John McCall 101656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall static bool shouldBindAsLValue(const Expr *expr) { 1017a5493f885095bd63d525a7035ad1c224de3ae5f2John McCall // gl-values should be bound as l-values for obvious reasons. 1018a5493f885095bd63d525a7035ad1c224de3ae5f2John McCall // Records should be bound as l-values because IR generation 1019a5493f885095bd63d525a7035ad1c224de3ae5f2John McCall // always keeps them in memory. Expressions of function type 1020a5493f885095bd63d525a7035ad1c224de3ae5f2John McCall // act exactly like l-values but are formally required to be 1021a5493f885095bd63d525a7035ad1c224de3ae5f2John McCall // r-values in C. 1022a5493f885095bd63d525a7035ad1c224de3ae5f2John McCall return expr->isGLValue() || 1023a5493f885095bd63d525a7035ad1c224de3ae5f2John McCall expr->getType()->isRecordType() || 1024a5493f885095bd63d525a7035ad1c224de3ae5f2John McCall expr->getType()->isFunctionType(); 102556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 102656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 10274b9c2d235fb9449e249d74f48ecfec601650de93John McCall static OpaqueValueMappingData bind(CodeGenFunction &CGF, 10284b9c2d235fb9449e249d74f48ecfec601650de93John McCall const OpaqueValueExpr *ov, 10294b9c2d235fb9449e249d74f48ecfec601650de93John McCall const Expr *e) { 10304b9c2d235fb9449e249d74f48ecfec601650de93John McCall if (shouldBindAsLValue(ov)) 10314b9c2d235fb9449e249d74f48ecfec601650de93John McCall return bind(CGF, ov, CGF.EmitLValue(e)); 10324b9c2d235fb9449e249d74f48ecfec601650de93John McCall return bind(CGF, ov, CGF.EmitAnyExpr(e)); 10334b9c2d235fb9449e249d74f48ecfec601650de93John McCall } 10344b9c2d235fb9449e249d74f48ecfec601650de93John McCall 10354b9c2d235fb9449e249d74f48ecfec601650de93John McCall static OpaqueValueMappingData bind(CodeGenFunction &CGF, 10364b9c2d235fb9449e249d74f48ecfec601650de93John McCall const OpaqueValueExpr *ov, 10374b9c2d235fb9449e249d74f48ecfec601650de93John McCall const LValue &lv) { 10384b9c2d235fb9449e249d74f48ecfec601650de93John McCall assert(shouldBindAsLValue(ov)); 10394b9c2d235fb9449e249d74f48ecfec601650de93John McCall CGF.OpaqueLValues.insert(std::make_pair(ov, lv)); 10404b9c2d235fb9449e249d74f48ecfec601650de93John McCall return OpaqueValueMappingData(ov, true); 10414b9c2d235fb9449e249d74f48ecfec601650de93John McCall } 10424b9c2d235fb9449e249d74f48ecfec601650de93John McCall 10434b9c2d235fb9449e249d74f48ecfec601650de93John McCall static OpaqueValueMappingData bind(CodeGenFunction &CGF, 10444b9c2d235fb9449e249d74f48ecfec601650de93John McCall const OpaqueValueExpr *ov, 10454b9c2d235fb9449e249d74f48ecfec601650de93John McCall const RValue &rv) { 10464b9c2d235fb9449e249d74f48ecfec601650de93John McCall assert(!shouldBindAsLValue(ov)); 10474b9c2d235fb9449e249d74f48ecfec601650de93John McCall CGF.OpaqueRValues.insert(std::make_pair(ov, rv)); 10484b9c2d235fb9449e249d74f48ecfec601650de93John McCall 10494b9c2d235fb9449e249d74f48ecfec601650de93John McCall OpaqueValueMappingData data(ov, false); 10504b9c2d235fb9449e249d74f48ecfec601650de93John McCall 10514b9c2d235fb9449e249d74f48ecfec601650de93John McCall // Work around an extremely aggressive peephole optimization in 10524b9c2d235fb9449e249d74f48ecfec601650de93John McCall // EmitScalarConversion which assumes that all other uses of a 10534b9c2d235fb9449e249d74f48ecfec601650de93John McCall // value are extant. 10544b9c2d235fb9449e249d74f48ecfec601650de93John McCall data.Protection = CGF.protectFromPeepholes(rv); 10554b9c2d235fb9449e249d74f48ecfec601650de93John McCall 10564b9c2d235fb9449e249d74f48ecfec601650de93John McCall return data; 10574b9c2d235fb9449e249d74f48ecfec601650de93John McCall } 10584b9c2d235fb9449e249d74f48ecfec601650de93John McCall 10594b9c2d235fb9449e249d74f48ecfec601650de93John McCall bool isValid() const { return OpaqueValue != 0; } 10604b9c2d235fb9449e249d74f48ecfec601650de93John McCall void clear() { OpaqueValue = 0; } 10614b9c2d235fb9449e249d74f48ecfec601650de93John McCall 10624b9c2d235fb9449e249d74f48ecfec601650de93John McCall void unbind(CodeGenFunction &CGF) { 10634b9c2d235fb9449e249d74f48ecfec601650de93John McCall assert(OpaqueValue && "no data to unbind!"); 10644b9c2d235fb9449e249d74f48ecfec601650de93John McCall 10654b9c2d235fb9449e249d74f48ecfec601650de93John McCall if (BoundLValue) { 10664b9c2d235fb9449e249d74f48ecfec601650de93John McCall CGF.OpaqueLValues.erase(OpaqueValue); 10674b9c2d235fb9449e249d74f48ecfec601650de93John McCall } else { 10684b9c2d235fb9449e249d74f48ecfec601650de93John McCall CGF.OpaqueRValues.erase(OpaqueValue); 10694b9c2d235fb9449e249d74f48ecfec601650de93John McCall CGF.unprotectFromPeepholes(Protection); 10704b9c2d235fb9449e249d74f48ecfec601650de93John McCall } 10714b9c2d235fb9449e249d74f48ecfec601650de93John McCall } 10724b9c2d235fb9449e249d74f48ecfec601650de93John McCall }; 10734b9c2d235fb9449e249d74f48ecfec601650de93John McCall 10744b9c2d235fb9449e249d74f48ecfec601650de93John McCall /// An RAII object to set (and then clear) a mapping for an OpaqueValueExpr. 10754b9c2d235fb9449e249d74f48ecfec601650de93John McCall class OpaqueValueMapping { 10764b9c2d235fb9449e249d74f48ecfec601650de93John McCall CodeGenFunction &CGF; 10774b9c2d235fb9449e249d74f48ecfec601650de93John McCall OpaqueValueMappingData Data; 10784b9c2d235fb9449e249d74f48ecfec601650de93John McCall 10794b9c2d235fb9449e249d74f48ecfec601650de93John McCall public: 10804b9c2d235fb9449e249d74f48ecfec601650de93John McCall static bool shouldBindAsLValue(const Expr *expr) { 10814b9c2d235fb9449e249d74f48ecfec601650de93John McCall return OpaqueValueMappingData::shouldBindAsLValue(expr); 10824b9c2d235fb9449e249d74f48ecfec601650de93John McCall } 10834b9c2d235fb9449e249d74f48ecfec601650de93John McCall 108456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// Build the opaque value mapping for the given conditional 108556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// operator if it's the GNU ?: extension. This is a common 108656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// enough pattern that the convenience operator is really 108756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// helpful. 108856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// 108956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall OpaqueValueMapping(CodeGenFunction &CGF, 109056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall const AbstractConditionalOperator *op) : CGF(CGF) { 10914b9c2d235fb9449e249d74f48ecfec601650de93John McCall if (isa<ConditionalOperator>(op)) 10924b9c2d235fb9449e249d74f48ecfec601650de93John McCall // Leave Data empty. 109356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return; 109456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 109556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall const BinaryConditionalOperator *e = cast<BinaryConditionalOperator>(op); 10964b9c2d235fb9449e249d74f48ecfec601650de93John McCall Data = OpaqueValueMappingData::bind(CGF, e->getOpaqueValue(), 10974b9c2d235fb9449e249d74f48ecfec601650de93John McCall e->getCommon()); 109856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 109956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 1100e996ffd240f20a1048179d7727a6ee3227261921John McCall OpaqueValueMapping(CodeGenFunction &CGF, 1101e996ffd240f20a1048179d7727a6ee3227261921John McCall const OpaqueValueExpr *opaqueValue, 110256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall LValue lvalue) 11034b9c2d235fb9449e249d74f48ecfec601650de93John McCall : CGF(CGF), Data(OpaqueValueMappingData::bind(CGF, opaqueValue, lvalue)) { 110456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 110556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 110656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall OpaqueValueMapping(CodeGenFunction &CGF, 110756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall const OpaqueValueExpr *opaqueValue, 110856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall RValue rvalue) 11094b9c2d235fb9449e249d74f48ecfec601650de93John McCall : CGF(CGF), Data(OpaqueValueMappingData::bind(CGF, opaqueValue, rvalue)) { 1110e996ffd240f20a1048179d7727a6ee3227261921John McCall } 1111e996ffd240f20a1048179d7727a6ee3227261921John McCall 1112e996ffd240f20a1048179d7727a6ee3227261921John McCall void pop() { 11134b9c2d235fb9449e249d74f48ecfec601650de93John McCall Data.unbind(CGF); 11144b9c2d235fb9449e249d74f48ecfec601650de93John McCall Data.clear(); 1115e996ffd240f20a1048179d7727a6ee3227261921John McCall } 1116e996ffd240f20a1048179d7727a6ee3227261921John McCall 1117e996ffd240f20a1048179d7727a6ee3227261921John McCall ~OpaqueValueMapping() { 11184b9c2d235fb9449e249d74f48ecfec601650de93John McCall if (Data.isValid()) Data.unbind(CGF); 1119e996ffd240f20a1048179d7727a6ee3227261921John McCall } 1120e996ffd240f20a1048179d7727a6ee3227261921John McCall }; 1121e220455a059d926953befe72857b9525273717efFariborz Jahanian 1122e220455a059d926953befe72857b9525273717efFariborz Jahanian /// getByrefValueFieldNumber - Given a declaration, returns the LLVM field 1123e220455a059d926953befe72857b9525273717efFariborz Jahanian /// number that holds the value. 1124e220455a059d926953befe72857b9525273717efFariborz Jahanian unsigned getByRefValueLLVMField(const ValueDecl *VD) const; 112552a80e19ad688091723a52ad53337767bb0ac684Fariborz Jahanian 112652a80e19ad688091723a52ad53337767bb0ac684Fariborz Jahanian /// BuildBlockByrefAddress - Computes address location of the 112752a80e19ad688091723a52ad53337767bb0ac684Fariborz Jahanian /// variable which is declared as __block. 112852a80e19ad688091723a52ad53337767bb0ac684Fariborz Jahanian llvm::Value *BuildBlockByrefAddress(llvm::Value *BaseAddr, 112952a80e19ad688091723a52ad53337767bb0ac684Fariborz Jahanian const VarDecl *V); 11307f02f721d48772e4eee4fccd8af4f800be1bbc1eChris Lattnerprivate: 1131d9becd1846e2c72bf6ad283faa1b048f33dd3afeChris Lattner CGDebugInfo *DebugInfo; 1132aa11289f754d220c9c155b68a4f84cdcfcefef6aDevang Patel bool DisableDebugInfo; 113309429b962811f2c0a7a81a1b0a89f96f5878b20cMike Stump 113493c332a8ba2c193c435b293966d343dab15f555bJohn McCall /// DidCallStackSave - Whether llvm.stacksave has been called. Used to avoid 113593c332a8ba2c193c435b293966d343dab15f555bJohn McCall /// calling llvm.stacksave for multiple VLAs in the same scope. 113693c332a8ba2c193c435b293966d343dab15f555bJohn McCall bool DidCallStackSave; 113793c332a8ba2c193c435b293966d343dab15f555bJohn McCall 1138f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump /// IndirectBranch - The first time an indirect goto is seen we create a block 1139f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump /// with an indirect branch. Every time we see the address of a label taken, 1140f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump /// we add the label to the indirect goto. Every subsequent indirect goto is 1141f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump /// codegen'd as a jump to the IndirectBranch's basic block. 1142d9becd1846e2c72bf6ad283faa1b048f33dd3afeChris Lattner llvm::IndirectBrInst *IndirectBranch; 11430ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar 11440dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// LocalDeclMap - This keeps track of the LLVM allocas or globals for local C 11450dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// decls. 11466b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall typedef llvm::DenseMap<const Decl*, llvm::Value*> DeclMapTy; 11476b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall DeclMapTy LocalDeclMap; 11485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// LabelMap - This keeps track of the LLVM basic block for each C label. 1150ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner llvm::DenseMap<const LabelDecl*, JumpDest> LabelMap; 11510dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 11520dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump // BreakContinueStack - This keeps track of where break and continue 1153e4b6d342c29d5cb9d311756100df1603810fa892Anders Carlsson // statements should jump to. 1154da13870e99fe33934b2122f06528a5063f78ae4cChris Lattner struct BreakContinue { 1155f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall BreakContinue(JumpDest Break, JumpDest Continue) 1156f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall : BreakBlock(Break), ContinueBlock(Continue) {} 11570dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 1158f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall JumpDest BreakBlock; 1159f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall JumpDest ContinueBlock; 11600dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump }; 1161686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVector<BreakContinue, 8> BreakContinueStack; 116218ccc7776ad6288c5f630dc7967fb99d099c9cd9Daniel Dunbar 1163170fd49294b85ab10f820721d99ff9d109c7230dZhongxing Xu /// SwitchInsn - This is nearest current switch instruction. It is null if 11640dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// current context is not in a switch. 116551b09f2c528c8460b5465c676173324e44176d62Devang Patel llvm::SwitchInst *SwitchInsn; 116651b09f2c528c8460b5465c676173324e44176d62Devang Patel 11670dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// CaseRangeBlock - This block holds if condition check for last case 116880fd5f96e6805ac43aab99faabd5b4c8b19551b7Devang Patel /// statement range in current switch instruction. 1169c049e4f406a7f7179eba98659044a32508e53289Devang Patel llvm::BasicBlock *CaseRangeBlock; 1170c049e4f406a7f7179eba98659044a32508e53289Devang Patel 117156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// OpaqueLValues - Keeps track of the current set of opaque value 1172e996ffd240f20a1048179d7727a6ee3227261921John McCall /// expressions. 117356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall llvm::DenseMap<const OpaqueValueExpr *, LValue> OpaqueLValues; 117456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall llvm::DenseMap<const OpaqueValueExpr *, RValue> OpaqueRValues; 1175e996ffd240f20a1048179d7727a6ee3227261921John McCall 11760dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump // VLASizeMap - This keeps track of the associated size for each VLA type. 1177bbed6b964414145b29e7b60b3e538093734ea3f8Eli Friedman // We track this by the size expression rather than the type itself because 1178bbed6b964414145b29e7b60b3e538093734ea3f8Eli Friedman // in certain situations, like a const qualifier applied to an VLA typedef, 1179bbed6b964414145b29e7b60b3e538093734ea3f8Eli Friedman // multiple VLA types can share the same size expression. 11800dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump // FIXME: Maybe this could be a stack of maps that is pushed/popped as we 11810dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump // enter/leave scopes. 1182bbed6b964414145b29e7b60b3e538093734ea3f8Eli Friedman llvm::DenseMap<const Expr*, llvm::Value*> VLASizeMap; 11830dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 1184f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// A block containing a single 'unreachable' instruction. Created 1185f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// lazily by getUnreachableBlock(). 1186f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall llvm::BasicBlock *UnreachableBlock; 11870dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 1188f6c56e2323c3f973253805a2f35629f3253ebed4Anders Carlsson /// CXXThisDecl - When generating code for a C++ member function, 1189f6c56e2323c3f973253805a2f35629f3253ebed4Anders Carlsson /// this will hold the implicit 'this' declaration. 1190cec5ebd4a6a89a7023d04cec728fd340b541ed61Eli Friedman ImplicitParamDecl *CXXABIThisDecl; 1191cec5ebd4a6a89a7023d04cec728fd340b541ed61Eli Friedman llvm::Value *CXXABIThisValue; 11922504941793b549323f9d29c62507cf21d865fadeJohn McCall llvm::Value *CXXThisValue; 11931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 119459660c21178b6af518bd4b564e032d5c9cc218cbTimur Iskhodzhanov /// CXXStructorImplicitParamDecl - When generating code for a constructor or 119559660c21178b6af518bd4b564e032d5c9cc218cbTimur Iskhodzhanov /// destructor, this will hold the implicit argument (e.g. VTT). 119659660c21178b6af518bd4b564e032d5c9cc218cbTimur Iskhodzhanov ImplicitParamDecl *CXXStructorImplicitParamDecl; 119759660c21178b6af518bd4b564e032d5c9cc218cbTimur Iskhodzhanov llvm::Value *CXXStructorImplicitParamValue; 11989cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer 1199150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall /// OutermostConditional - Points to the outermost active 1200150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall /// conditional control. This is used so that we know if a 1201150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall /// temporary should be destroyed conditionally. 1202150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall ConditionalEvaluation *OutermostConditional; 12031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12047dfa4079f4b37507048b19bfc693d3b015d9dd11Anders Carlsson 12057dfa4079f4b37507048b19bfc693d3b015d9dd11Anders Carlsson /// ByrefValueInfoMap - For each __block variable, contains a pair of the LLVM 12067dfa4079f4b37507048b19bfc693d3b015d9dd11Anders Carlsson /// type as well as the field number that contains the actual data. 12072acc6e3feda5e4f7d9009bdcf8b1cd777fecfe2dChris Lattner llvm::DenseMap<const ValueDecl *, std::pair<llvm::Type *, 12087dfa4079f4b37507048b19bfc693d3b015d9dd11Anders Carlsson unsigned> > ByRefValueInfo; 12099cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer 1210f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall llvm::BasicBlock *TerminateLandingPad; 1211182f383db1782af752ecaf607fdff72a8542088bMike Stump llvm::BasicBlock *TerminateHandler; 121283252dcfe61aaebcb6bc117e71dc12968729513fChris Lattner llvm::BasicBlock *TrapBB; 1213940670512d7c3d93389bb38a426abcb7ef44271eEli Friedman 12140df579ec000ffe52e0cddf1e7ee5e50a55256835Tanya Lattner /// Add a kernel metadata node to the named metadata node 'opencl.kernels'. 12150df579ec000ffe52e0cddf1e7ee5e50a55256835Tanya Lattner /// In the kernel metadata node, reference the kernel function and metadata 12160df579ec000ffe52e0cddf1e7ee5e50a55256835Tanya Lattner /// nodes for its optional attribute qualifiers (OpenCL 1.1 6.7.2): 12170df579ec000ffe52e0cddf1e7ee5e50a55256835Tanya Lattner /// - A node for the work_group_size_hint(X,Y,Z) qualifier contains string 12180df579ec000ffe52e0cddf1e7ee5e50a55256835Tanya Lattner /// "work_group_size_hint", and three 32-bit integers X, Y and Z. 12190df579ec000ffe52e0cddf1e7ee5e50a55256835Tanya Lattner /// - A node for the reqd_work_group_size(X,Y,Z) qualifier contains string 12200df579ec000ffe52e0cddf1e7ee5e50a55256835Tanya Lattner /// "reqd_work_group_size", and three 32-bit integers X, Y and Z. 12210df579ec000ffe52e0cddf1e7ee5e50a55256835Tanya Lattner void EmitOpenCLKernelMetadata(const FunctionDecl *FD, 12220df579ec000ffe52e0cddf1e7ee5e50a55256835Tanya Lattner llvm::Function *Fn); 12230df579ec000ffe52e0cddf1e7ee5e50a55256835Tanya Lattner 12245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 12254904bf4e84cfb48080270ebaa9005327f18ab0e5Fariborz Jahanian CodeGenFunction(CodeGenModule &cgm, bool suppressNewContext=false); 12261a343ebbf413e8eae6b2737b2b2d79cbf5765571John McCall ~CodeGenFunction(); 12270dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 12281e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall CodeGenTypes &getTypes() const { return CGM.getTypes(); } 1229f2aac84709c418189e476ad591848dad50291885John McCall ASTContext &getContext() const { return CGM.getContext(); } 1230a240df2ec1b374b3e9e7f760875ffb17cd64506fAlexey Samsonov /// Returns true if DebugInfo is actually initialized. 1231a240df2ec1b374b3e9e7f760875ffb17cd64506fAlexey Samsonov bool maybeInitializeDebugInfo() { 1232a240df2ec1b374b3e9e7f760875ffb17cd64506fAlexey Samsonov if (CGM.getModuleDebugInfo()) { 1233a240df2ec1b374b3e9e7f760875ffb17cd64506fAlexey Samsonov DebugInfo = CGM.getModuleDebugInfo(); 1234a240df2ec1b374b3e9e7f760875ffb17cd64506fAlexey Samsonov return true; 1235a240df2ec1b374b3e9e7f760875ffb17cd64506fAlexey Samsonov } 1236a240df2ec1b374b3e9e7f760875ffb17cd64506fAlexey Samsonov return false; 1237a240df2ec1b374b3e9e7f760875ffb17cd64506fAlexey Samsonov } 1238aa11289f754d220c9c155b68a4f84cdcfcefef6aDevang Patel CGDebugInfo *getDebugInfo() { 1239aa11289f754d220c9c155b68a4f84cdcfcefef6aDevang Patel if (DisableDebugInfo) 1240aa11289f754d220c9c155b68a4f84cdcfcefef6aDevang Patel return NULL; 1241aa11289f754d220c9c155b68a4f84cdcfcefef6aDevang Patel return DebugInfo; 1242aa11289f754d220c9c155b68a4f84cdcfcefef6aDevang Patel } 1243aa11289f754d220c9c155b68a4f84cdcfcefef6aDevang Patel void disableDebugInfo() { DisableDebugInfo = true; } 1244aa11289f754d220c9c155b68a4f84cdcfcefef6aDevang Patel void enableDebugInfo() { DisableDebugInfo = false; } 1245aa11289f754d220c9c155b68a4f84cdcfcefef6aDevang Patel 1246f85e193739c953358c865005855253af4f68a497John McCall bool shouldUseFusedARCCalls() { 1247f85e193739c953358c865005855253af4f68a497John McCall return CGM.getCodeGenOpts().OptimizationLevel == 0; 1248f85e193739c953358c865005855253af4f68a497John McCall } 12495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 12504e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie const LangOptions &getLangOpts() const { return CGM.getLangOpts(); } 1251d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall 1252285cfd8953d4ca4da613a47a0d691f7234068f8cBill Wendling /// Returns a pointer to the function's exception object and selector slot, 1253285cfd8953d4ca4da613a47a0d691f7234068f8cBill Wendling /// which is assigned in every landing pad. 1254f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall llvm::Value *getExceptionSlot(); 125593c332a8ba2c193c435b293966d343dab15f555bJohn McCall llvm::Value *getEHSelectorSlot(); 1256f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 1257ae270598d5c7a9a283d4b3ddce53b151c6e2b182Bill Wendling /// Returns the contents of the function's exception object and selector 1258ae270598d5c7a9a283d4b3ddce53b151c6e2b182Bill Wendling /// slots. 1259ae270598d5c7a9a283d4b3ddce53b151c6e2b182Bill Wendling llvm::Value *getExceptionFromSlot(); 1260ae270598d5c7a9a283d4b3ddce53b151c6e2b182Bill Wendling llvm::Value *getSelectorFromSlot(); 1261ae270598d5c7a9a283d4b3ddce53b151c6e2b182Bill Wendling 1262ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall llvm::Value *getNormalCleanupDestSlot(); 1263ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall 1264f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall llvm::BasicBlock *getUnreachableBlock() { 1265f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall if (!UnreachableBlock) { 1266f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall UnreachableBlock = createBasicBlock("unreachable"); 1267f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall new llvm::UnreachableInst(getLLVMContext(), UnreachableBlock); 1268f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall } 1269f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall return UnreachableBlock; 1270f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall } 1271f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 1272f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall llvm::BasicBlock *getInvokeDest() { 1273f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall if (!EHStack.requiresLandingPad()) return 0; 1274f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall return getInvokeDestImpl(); 1275f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall } 12769834ffbe54788239c8361d3cfe5826fd277ddfb2Daniel Dunbar 1277d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall llvm::LLVMContext &getLLVMContext() { return CGM.getLLVMContext(); } 127869243825cb5c91ec7207256aa57ae327cfaf8cb2Owen Anderson 12799834ffbe54788239c8361d3cfe5826fd277ddfb2Daniel Dunbar //===--------------------------------------------------------------------===// 1280bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall // Cleanups 1281bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall //===--------------------------------------------------------------------===// 1282bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall 1283bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall typedef void Destroyer(CodeGenFunction &CGF, llvm::Value *addr, QualType ty); 1284bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall 12852673c68aa58e277ebc755b71d81aca618cdedbf9John McCall void pushIrregularPartialArrayCleanup(llvm::Value *arrayBegin, 12862673c68aa58e277ebc755b71d81aca618cdedbf9John McCall llvm::Value *arrayEndPointer, 12872673c68aa58e277ebc755b71d81aca618cdedbf9John McCall QualType elementType, 1288516bbd42e62d709013824d6fb8445a0cfda3129aPeter Collingbourne Destroyer *destroyer); 12892673c68aa58e277ebc755b71d81aca618cdedbf9John McCall void pushRegularPartialArrayCleanup(llvm::Value *arrayBegin, 12902673c68aa58e277ebc755b71d81aca618cdedbf9John McCall llvm::Value *arrayEnd, 12912673c68aa58e277ebc755b71d81aca618cdedbf9John McCall QualType elementType, 1292516bbd42e62d709013824d6fb8445a0cfda3129aPeter Collingbourne Destroyer *destroyer); 1293bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall 12949928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall void pushDestroy(QualType::DestructionKind dtorKind, 12959928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall llvm::Value *addr, QualType type); 1296074cae0861a87bf96d8ea56d02e34839d9ccbd0aJohn McCall void pushEHDestroy(QualType::DestructionKind dtorKind, 1297074cae0861a87bf96d8ea56d02e34839d9ccbd0aJohn McCall llvm::Value *addr, QualType type); 1298bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall void pushDestroy(CleanupKind kind, llvm::Value *addr, QualType type, 1299516bbd42e62d709013824d6fb8445a0cfda3129aPeter Collingbourne Destroyer *destroyer, bool useEHCleanupForArray); 1300516bbd42e62d709013824d6fb8445a0cfda3129aPeter Collingbourne void emitDestroy(llvm::Value *addr, QualType type, Destroyer *destroyer, 13012673c68aa58e277ebc755b71d81aca618cdedbf9John McCall bool useEHCleanupForArray); 1302a91f6661c4685fecee6dc09bdaef73254c1aaa06John McCall llvm::Function *generateDestroyHelper(llvm::Constant *addr, 1303a91f6661c4685fecee6dc09bdaef73254c1aaa06John McCall QualType type, 1304516bbd42e62d709013824d6fb8445a0cfda3129aPeter Collingbourne Destroyer *destroyer, 1305a91f6661c4685fecee6dc09bdaef73254c1aaa06John McCall bool useEHCleanupForArray); 1306bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall void emitArrayDestroy(llvm::Value *begin, llvm::Value *end, 1307516bbd42e62d709013824d6fb8445a0cfda3129aPeter Collingbourne QualType type, Destroyer *destroyer, 1308fbf780a9d1dbb191fc40c8af967c590e08724b74John McCall bool checkZeroLength, bool useEHCleanup); 1309bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall 1310516bbd42e62d709013824d6fb8445a0cfda3129aPeter Collingbourne Destroyer *getDestroyer(QualType::DestructionKind destructionKind); 13119928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall 1312bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall /// Determines whether an EH cleanup is required to destroy a type 1313bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall /// with the given destruction kind. 1314bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall bool needsEHCleanup(QualType::DestructionKind kind) { 1315bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall switch (kind) { 1316bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall case QualType::DK_none: 1317bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall return false; 1318bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall case QualType::DK_cxx_destructor: 1319bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall case QualType::DK_objc_weak_lifetime: 13204e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie return getLangOpts().Exceptions; 1321bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall case QualType::DK_objc_strong_lifetime: 13224e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie return getLangOpts().Exceptions && 1323bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall CGM.getCodeGenOpts().ObjCAutoRefCountExceptions; 1324bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall } 1325bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall llvm_unreachable("bad destruction kind"); 1326bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall } 1327bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall 13289928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall CleanupKind getCleanupKind(QualType::DestructionKind kind) { 13299928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall return (needsEHCleanup(kind) ? NormalAndEHCleanup : NormalCleanup); 13309928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall } 13319928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall 1332bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall //===--------------------------------------------------------------------===// 13339834ffbe54788239c8361d3cfe5826fd277ddfb2Daniel Dunbar // Objective-C 13349834ffbe54788239c8361d3cfe5826fd277ddfb2Daniel Dunbar //===--------------------------------------------------------------------===// 13359834ffbe54788239c8361d3cfe5826fd277ddfb2Daniel Dunbar 1336391d77a26382dddf25da73e29fc1fa5aaaea4c6fChris Lattner void GenerateObjCMethod(const ObjCMethodDecl *OMD); 1337af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar 13380dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump void StartObjCMethod(const ObjCMethodDecl *MD, 13398d3f8979e46f9d0b8735566eabe471db0e1e0e53Devang Patel const ObjCContainerDecl *CD, 13408d3f8979e46f9d0b8735566eabe471db0e1e0e53Devang Patel SourceLocation StartLoc); 1341af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar 13420dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// GenerateObjCGetter - Synthesize an Objective-C property getter function. 1343fef30b55230064d334a669a065a1c9acdb87cdfeFariborz Jahanian void GenerateObjCGetter(ObjCImplementationDecl *IMP, 1344fef30b55230064d334a669a065a1c9acdb87cdfeFariborz Jahanian const ObjCPropertyImplDecl *PID); 13451e1f4871535f2cadcbf8c9af8cc48a2213192320John McCall void generateObjCGetterBody(const ObjCImplementationDecl *classImpl, 1346b6e5fe3cae9bf456f084c555c3ecc256f4181cc5Fariborz Jahanian const ObjCPropertyImplDecl *propImpl, 1347490a52b4947381879a47b4251db5fb81cdf5d02bFariborz Jahanian const ObjCMethodDecl *GetterMothodDecl, 1348b6e5fe3cae9bf456f084c555c3ecc256f4181cc5Fariborz Jahanian llvm::Constant *AtomicHelperFn); 13492846b97965e980ad2e7c8d444b82cc21d733a699Fariborz Jahanian 1350109dfc6ca6652f60c55ed0f2631aebf323d0200dFariborz Jahanian void GenerateObjCCtorDtorMethod(ObjCImplementationDecl *IMP, 1351109dfc6ca6652f60c55ed0f2631aebf323d0200dFariborz Jahanian ObjCMethodDecl *MD, bool ctor); 1352af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar 13530dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// GenerateObjCSetter - Synthesize an Objective-C property setter function 13540dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// for the given property. 1355fef30b55230064d334a669a065a1c9acdb87cdfeFariborz Jahanian void GenerateObjCSetter(ObjCImplementationDecl *IMP, 1356fef30b55230064d334a669a065a1c9acdb87cdfeFariborz Jahanian const ObjCPropertyImplDecl *PID); 135771c758d3f4ecc8b511e6ae4a7210486aa994c182John McCall void generateObjCSetterBody(const ObjCImplementationDecl *classImpl, 1358cd93b96bc51c255d104095bc6a6d8eac74a84b1eFariborz Jahanian const ObjCPropertyImplDecl *propImpl, 1359cd93b96bc51c255d104095bc6a6d8eac74a84b1eFariborz Jahanian llvm::Constant *AtomicHelperFn); 13600b2bd47151ee9205ad6c66d1ffb921918106088aFariborz Jahanian bool IndirectObjCSetterArg(const CGFunctionInfo &FI); 136115bd58842adaa4f8cca4e58047ed18e033858d9bFariborz Jahanian bool IvarTypeWithAggrGCObjects(QualType Ty); 1362af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar 13634e7a1f7682d94811bd41fca8aefccc38f686db23Mike Stump //===--------------------------------------------------------------------===// 13644e7a1f7682d94811bd41fca8aefccc38f686db23Mike Stump // Block Bits 13654e7a1f7682d94811bd41fca8aefccc38f686db23Mike Stump //===--------------------------------------------------------------------===// 13664e7a1f7682d94811bd41fca8aefccc38f686db23Mike Stump 13676b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall llvm::Value *EmitBlockLiteral(const BlockExpr *); 13681a343ebbf413e8eae6b2737b2b2d79cbf5765571John McCall llvm::Value *EmitBlockLiteral(const CGBlockInfo &Info); 13691a343ebbf413e8eae6b2737b2b2d79cbf5765571John McCall static void destroyBlockInfos(CGBlockInfo *info); 13702a7eb28397148079cbc8e54e8a3871ef01c4f4bcBlaine Garst llvm::Constant *BuildDescriptorBlockDecl(const BlockExpr *, 137189ecd41e0a6bfb3b0913dbe41c3c666340b308c7Fariborz Jahanian const CGBlockInfo &Info, 13722acc6e3feda5e4f7d9009bdcf8b1cd777fecfe2dChris Lattner llvm::StructType *, 1373d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall llvm::Constant *BlockVarLayout); 13744e7a1f7682d94811bd41fca8aefccc38f686db23Mike Stump 1375564360be450b319aeafc26698be9811837bfb826Fariborz Jahanian llvm::Function *GenerateBlockFunction(GlobalDecl GD, 13766b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall const CGBlockInfo &Info, 13776cc88f78fd36d3511b89412b193494b3e423cbffMike Stump const Decl *OuterFuncDecl, 137864bee65a3436e3f0c352fcfe2130676f3502cffeEli Friedman const DeclMapTy &ldm, 137964bee65a3436e3f0c352fcfe2130676f3502cffeEli Friedman bool IsLambdaConversionToBlock); 13804e7a1f7682d94811bd41fca8aefccc38f686db23Mike Stump 1381d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall llvm::Constant *GenerateCopyHelperFunction(const CGBlockInfo &blockInfo); 1382d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall llvm::Constant *GenerateDestroyHelperFunction(const CGBlockInfo &blockInfo); 138320abee6b95c4f5a61e471b4b616439280ca4a81bFariborz Jahanian llvm::Constant *GenerateObjCAtomicSetterCopyHelperFunction( 138420abee6b95c4f5a61e471b4b616439280ca4a81bFariborz Jahanian const ObjCPropertyImplDecl *PID); 138520abee6b95c4f5a61e471b4b616439280ca4a81bFariborz Jahanian llvm::Constant *GenerateObjCAtomicGetterCopyHelperFunction( 138620abee6b95c4f5a61e471b4b616439280ca4a81bFariborz Jahanian const ObjCPropertyImplDecl *PID); 1387cae40c4d448529fe65de3d87bdbe97d3b54b4d98Eli Friedman llvm::Value *EmitBlockCopyAndAutorelease(llvm::Value *Block, QualType Ty); 1388d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall 1389d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall void BuildBlockRelease(llvm::Value *DeclPtr, BlockFieldFlags flags); 1390d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall 13915af02db5a48476e0748f135369663080eae87c64John McCall class AutoVarEmission; 13925af02db5a48476e0748f135369663080eae87c64John McCall 13935af02db5a48476e0748f135369663080eae87c64John McCall void emitByrefStructureInit(const AutoVarEmission &emission); 13945af02db5a48476e0748f135369663080eae87c64John McCall void enterByrefCleanup(const AutoVarEmission &emission); 13955af02db5a48476e0748f135369663080eae87c64John McCall 13966b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall llvm::Value *LoadBlockStruct() { 13976b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall assert(BlockPointer && "no block pointer set!"); 13986b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall return BlockPointer; 13996b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall } 14004e7a1f7682d94811bd41fca8aefccc38f686db23Mike Stump 1401ea1471e0e967548c596a71469702f8846dbaf3c0John McCall void AllocateBlockCXXThisPointer(const CXXThisExpr *E); 1402f4b88a45902af1802a1cb42ba48b1c474474f228John McCall void AllocateBlockDecl(const DeclRefExpr *E); 14036b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall llvm::Value *GetAddrOfBlockDecl(const VarDecl *var, bool ByRef); 14042acc6e3feda5e4f7d9009bdcf8b1cd777fecfe2dChris Lattner llvm::Type *BuildByRefType(const VarDecl *var); 1405dab514fc30242c7afd6c03956e46136c400fb0d3Mike Stump 1406d26bc76c98006609002d9930f8840490e88ac5b5John McCall void GenerateCode(GlobalDecl GD, llvm::Function *Fn, 1407d26bc76c98006609002d9930f8840490e88ac5b5John McCall const CGFunctionInfo &FnInfo); 14080ff8bafde95f6fa51ccea70738c1b99db870bddcAnders Carlsson void StartFunction(GlobalDecl GD, QualType RetTy, 14097c086516f3cc9fba2733b1919973206c6ba4b171Daniel Dunbar llvm::Function *Fn, 1410d26bc76c98006609002d9930f8840490e88ac5b5John McCall const CGFunctionInfo &FnInfo, 14112284ac9ec80299fcdefae9a2787cf85105a0f203Daniel Dunbar const FunctionArgList &Args, 14129c6082fe89c61af697f017aa80937581cc2128d8Tilmann Scheller SourceLocation StartLoc); 1413a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar 14149fc6a7774643a810c8501dae2323e863fefb623eJohn McCall void EmitConstructorBody(FunctionArgList &Args); 14159fc6a7774643a810c8501dae2323e863fefb623eJohn McCall void EmitDestructorBody(FunctionArgList &Args); 141656c00c4868831c9a137ca7b0e16d063cf986d110Lang Hames void emitImplicitAssignmentOperatorBody(FunctionArgList &Args); 14179fc6a7774643a810c8501dae2323e863fefb623eJohn McCall void EmitFunctionBody(FunctionArgList &Args); 1418a355e07454463b19829ac92ffd115a097faff0e0John McCall 141964bee65a3436e3f0c352fcfe2130676f3502cffeEli Friedman void EmitForwardingCallToLambda(const CXXRecordDecl *Lambda, 142064bee65a3436e3f0c352fcfe2130676f3502cffeEli Friedman CallArgList &CallArgs); 1421bd89f8c2caa9550e41daa1aa9bf30f0f1e0dfaf7Eli Friedman void EmitLambdaToBlockPointerBody(FunctionArgList &Args); 142264bee65a3436e3f0c352fcfe2130676f3502cffeEli Friedman void EmitLambdaBlockInvokeBody(); 142327dd7d962bbf774988bc5e59d04a7743ed503514Douglas Gregor void EmitLambdaDelegatingInvokeBody(const CXXMethodDecl *MD); 142427dd7d962bbf774988bc5e59d04a7743ed503514Douglas Gregor void EmitLambdaStaticInvokeFunction(const CXXMethodDecl *MD); 1425bd89f8c2caa9550e41daa1aa9bf30f0f1e0dfaf7Eli Friedman 14260dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// EmitReturnBlock - Emit the unified return block, trying to avoid its 14270dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// emission when possible. 14280a0f93c90fd397a1aa9f97283c55f8ba0062bf55David Blaikie void EmitReturnBlock(); 14291c1d6074f5a0296dd273362655b1b8f9057289e3Daniel Dunbar 14300dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// FinishFunction - Complete IR generation of the current function. It is 14310dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// legal to call this function even if there is no current insertion point. 1432af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar void FinishFunction(SourceLocation EndLoc=SourceLocation()); 143317b708d61827cd86278e9580b041dd6cbadf07d3Daniel Dunbar 1434519c32880b99396034ecaedc0cd86db2e8485003Anders Carlsson /// GenerateThunk - Generate a thunk for the given method. 1435d26bc76c98006609002d9930f8840490e88ac5b5John McCall void GenerateThunk(llvm::Function *Fn, const CGFunctionInfo &FnInfo, 1436d26bc76c98006609002d9930f8840490e88ac5b5John McCall GlobalDecl GD, const ThunkInfo &Thunk); 14379cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer 14387dcdf5ba9324a9577461eae302e88fdd52e310c5Eli Friedman void GenerateVarArgsThunk(llvm::Function *Fn, const CGFunctionInfo &FnInfo, 14397dcdf5ba9324a9577461eae302e88fdd52e310c5Eli Friedman GlobalDecl GD, const ThunkInfo &Thunk); 14407dcdf5ba9324a9577461eae302e88fdd52e310c5Eli Friedman 1441fb8cc253420e93cee33d29df5a2bdae6aaf16e39Douglas Gregor void EmitCtorPrologue(const CXXConstructorDecl *CD, CXXCtorType Type, 1442fb8cc253420e93cee33d29df5a2bdae6aaf16e39Douglas Gregor FunctionArgList &Args); 14431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1444b74ed087469db042325bad76fdf3ff6ed67dec09Eli Friedman void EmitInitializerForField(FieldDecl *Field, LValue LHS, Expr *Init, 1445b74ed087469db042325bad76fdf3ff6ed67dec09Eli Friedman ArrayRef<VarDecl *> ArrayIndexes); 1446b74ed087469db042325bad76fdf3ff6ed67dec09Eli Friedman 1447d103f9f9b401b419e756f8c1849683cd77586067Anders Carlsson /// InitializeVTablePointer - Initialize the vtable pointer of the given 1448d103f9f9b401b419e756f8c1849683cd77586067Anders Carlsson /// subobject. 1449d103f9f9b401b419e756f8c1849683cd77586067Anders Carlsson /// 14509cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer void InitializeVTablePointer(BaseSubobject Base, 1451b3b772ea15a4cd54879e244629aa685ead9548bbAnders Carlsson const CXXRecordDecl *NearestVBase, 1452d6fb21fa1053e5d616af55b181bb03c50d4b0d24Ken Dyck CharUnits OffsetFromNearestVBase, 1453d103f9f9b401b419e756f8c1849683cd77586067Anders Carlsson llvm::Constant *VTable, 1454d103f9f9b401b419e756f8c1849683cd77586067Anders Carlsson const CXXRecordDecl *VTableClass); 1455d103f9f9b401b419e756f8c1849683cd77586067Anders Carlsson 1456d103f9f9b401b419e756f8c1849683cd77586067Anders Carlsson typedef llvm::SmallPtrSet<const CXXRecordDecl *, 4> VisitedVirtualBasesSetTy; 14579cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer void InitializeVTablePointers(BaseSubobject Base, 1458b3b772ea15a4cd54879e244629aa685ead9548bbAnders Carlsson const CXXRecordDecl *NearestVBase, 1459d6fb21fa1053e5d616af55b181bb03c50d4b0d24Ken Dyck CharUnits OffsetFromNearestVBase, 1460603d6d12cc4cba1ef219a3d55c698c7c87f87adfAnders Carlsson bool BaseIsNonVirtualPrimaryBase, 1461603d6d12cc4cba1ef219a3d55c698c7c87f87adfAnders Carlsson llvm::Constant *VTable, 1462603d6d12cc4cba1ef219a3d55c698c7c87f87adfAnders Carlsson const CXXRecordDecl *VTableClass, 1463603d6d12cc4cba1ef219a3d55c698c7c87f87adfAnders Carlsson VisitedVirtualBasesSetTy& VBases); 146477a259c6dbf582949af8a243b472c0c7faa373a6Eli Friedman 1465603d6d12cc4cba1ef219a3d55c698c7c87f87adfAnders Carlsson void InitializeVTablePointers(const CXXRecordDecl *ClassDecl); 1466d103f9f9b401b419e756f8c1849683cd77586067Anders Carlsson 1467043fb9a1fc0609285f60f0f87e5a18195408f34cDan Gohman /// GetVTablePtr - Return the Value of the vtable pointer member pointed 1468043fb9a1fc0609285f60f0f87e5a18195408f34cDan Gohman /// to by This. 14692acc6e3feda5e4f7d9009bdcf8b1cd777fecfe2dChris Lattner llvm::Value *GetVTablePtr(llvm::Value *This, llvm::Type *Ty); 1470d103f9f9b401b419e756f8c1849683cd77586067Anders Carlsson 147150da2cadcc6da86abff6772de65280ace2cabc94John McCall /// EnterDtorCleanups - Enter the cleanups necessary to complete the 147250da2cadcc6da86abff6772de65280ace2cabc94John McCall /// given phase of destruction for a destructor. The end result 147350da2cadcc6da86abff6772de65280ace2cabc94John McCall /// should call destructors on members and base classes in reverse 147450da2cadcc6da86abff6772de65280ace2cabc94John McCall /// order of their construction. 147550da2cadcc6da86abff6772de65280ace2cabc94John McCall void EnterDtorCleanups(const CXXDestructorDecl *Dtor, CXXDtorType Type); 14761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 14777255a2d997b15beae82e627052fdb1b2474495c2Chris Lattner /// ShouldInstrumentFunction - Return true if the current function should be 14787255a2d997b15beae82e627052fdb1b2474495c2Chris Lattner /// instrumented with __cyg_profile_func_* calls 14797255a2d997b15beae82e627052fdb1b2474495c2Chris Lattner bool ShouldInstrumentFunction(); 14807255a2d997b15beae82e627052fdb1b2474495c2Chris Lattner 14817255a2d997b15beae82e627052fdb1b2474495c2Chris Lattner /// EmitFunctionInstrumentation - Emit LLVM code to call the specified 14827255a2d997b15beae82e627052fdb1b2474495c2Chris Lattner /// instrumentation function with the current function and the call site, if 14837255a2d997b15beae82e627052fdb1b2474495c2Chris Lattner /// function instrumentation is enabled. 14847255a2d997b15beae82e627052fdb1b2474495c2Chris Lattner void EmitFunctionInstrumentation(const char *Fn); 14857255a2d997b15beae82e627052fdb1b2474495c2Chris Lattner 1486be4c8705e499b55548467eb7adaa23cbc6edfef9Roman Divacky /// EmitMCountInstrumentation - Emit call to .mcount. 1487be4c8705e499b55548467eb7adaa23cbc6edfef9Roman Divacky void EmitMCountInstrumentation(); 1488be4c8705e499b55548467eb7adaa23cbc6edfef9Roman Divacky 14890dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// EmitFunctionProlog - Emit the target specific LLVM code to load the 14900dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// arguments for the given function. This is also responsible for naming the 14910dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// LLVM function arguments. 149288b5396b0897f28d22ae3debf4a0d97b33b6c362Daniel Dunbar void EmitFunctionProlog(const CGFunctionInfo &FI, 149388b5396b0897f28d22ae3debf4a0d97b33b6c362Daniel Dunbar llvm::Function *Fn, 149417b708d61827cd86278e9580b041dd6cbadf07d3Daniel Dunbar const FunctionArgList &Args); 149517b708d61827cd86278e9580b041dd6cbadf07d3Daniel Dunbar 14960dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// EmitFunctionEpilog - Emit the target specific LLVM code to return the 14970dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// given temporary. 149835b21b884e5c3447a52a74d7ffaba966b07ac81fChris Lattner void EmitFunctionEpilog(const CGFunctionInfo &FI); 149917b708d61827cd86278e9580b041dd6cbadf07d3Daniel Dunbar 1500cce3d4f9812182ed4e551b7cf0fc86576be8d9c5Mike Stump /// EmitStartEHSpec - Emit the start of the exception spec. 1501cce3d4f9812182ed4e551b7cf0fc86576be8d9c5Mike Stump void EmitStartEHSpec(const Decl *D); 1502cce3d4f9812182ed4e551b7cf0fc86576be8d9c5Mike Stump 1503cce3d4f9812182ed4e551b7cf0fc86576be8d9c5Mike Stump /// EmitEndEHSpec - Emit the end of the exception spec. 1504cce3d4f9812182ed4e551b7cf0fc86576be8d9c5Mike Stump void EmitEndEHSpec(const Decl *D); 1505cce3d4f9812182ed4e551b7cf0fc86576be8d9c5Mike Stump 1506f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// getTerminateLandingPad - Return a landing pad that just calls terminate. 1507f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall llvm::BasicBlock *getTerminateLandingPad(); 1508f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 1509f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// getTerminateHandler - Return a handler (not a landing pad, just 1510f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// a catch handler) that just calls terminate. This is used when 1511f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// a terminate scope encloses a try. 15129b39c51ae3c547568ac42325f94b4197618f6b18Mike Stump llvm::BasicBlock *getTerminateHandler(); 15139b39c51ae3c547568ac42325f94b4197618f6b18Mike Stump 15149cbe4f0ba01ec304e1e3d071c071f7bca33631c0Chris Lattner llvm::Type *ConvertTypeForMem(QualType T); 15159cbe4f0ba01ec304e1e3d071c071f7bca33631c0Chris Lattner llvm::Type *ConvertType(QualType T); 15169cbe4f0ba01ec304e1e3d071c071f7bca33631c0Chris Lattner llvm::Type *ConvertType(const TypeDecl *T) { 1517bff225ecf77fb891596ecb1b27196310d268365eJohn McCall return ConvertType(getContext().getTypeDeclType(T)); 1518bff225ecf77fb891596ecb1b27196310d268365eJohn McCall } 1519c8aa5f1f264fb230c38182adab944232bb160c2bChris Lattner 15200dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// LoadObjCSelf - Load the value of self. This function is only valid while 15210dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// generating code for an Objective-C method. 1522c8aa5f1f264fb230c38182adab944232bb160c2bChris Lattner llvm::Value *LoadObjCSelf(); 15230dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 15240dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// TypeOfSelfObject - Return type of object that this self represents. 152545012a7ef5abf1042c893f3f2fa5c23cb5485ea9Fariborz Jahanian QualType TypeOfSelfObject(); 15264111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner 15275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// hasAggregateLLVMType - Return true if the specified AST type will map into 15285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// an aggregate LLVM type or is void. 15299d232c884ea9872d6555df0fd7359699819bc1f1John McCall static TypeEvaluationKind getEvaluationKind(QualType T); 15309d232c884ea9872d6555df0fd7359699819bc1f1John McCall 15319d232c884ea9872d6555df0fd7359699819bc1f1John McCall static bool hasScalarEvaluationKind(QualType T) { 15329d232c884ea9872d6555df0fd7359699819bc1f1John McCall return getEvaluationKind(T) == TEK_Scalar; 15339d232c884ea9872d6555df0fd7359699819bc1f1John McCall } 15349d232c884ea9872d6555df0fd7359699819bc1f1John McCall 15359d232c884ea9872d6555df0fd7359699819bc1f1John McCall static bool hasAggregateEvaluationKind(QualType T) { 15369d232c884ea9872d6555df0fd7359699819bc1f1John McCall return getEvaluationKind(T) == TEK_Aggregate; 15379d232c884ea9872d6555df0fd7359699819bc1f1John McCall } 153855e874299f2ad827646a4ca9ea38c402aaeb38c9Daniel Dunbar 153955e874299f2ad827646a4ca9ea38c402aaeb38c9Daniel Dunbar /// createBasicBlock - Create an LLVM basic block. 15404def70d3040e73707c738f7c366737a986135edfRichard Smith llvm::BasicBlock *createBasicBlock(const Twine &name = "", 1541d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall llvm::Function *parent = 0, 1542d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall llvm::BasicBlock *before = 0) { 154329ea6729155c759836be4b5453bee9ef8e1e97eeDaniel Dunbar#ifdef NDEBUG 1544d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall return llvm::BasicBlock::Create(getLLVMContext(), "", parent, before); 154529ea6729155c759836be4b5453bee9ef8e1e97eeDaniel Dunbar#else 1546d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall return llvm::BasicBlock::Create(getLLVMContext(), name, parent, before); 154729ea6729155c759836be4b5453bee9ef8e1e97eeDaniel Dunbar#endif 154855e874299f2ad827646a4ca9ea38c402aaeb38c9Daniel Dunbar } 15490dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 15505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getBasicBlockForLabel - Return the LLVM basicblock that the specified 15515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// label maps to. 1552ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner JumpDest getJumpDestForLabel(const LabelDecl *S); 15530dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 1554f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump /// SimplifyForwardingBlocks - If the given basic block is only a branch to 1555f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump /// another basic block, simplify it. This assumes that no other code could 1556f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump /// potentially reference the basic block. 1557aa5bd87f1fd5f9ca47924248817c89325759b30eDaniel Dunbar void SimplifyForwardingBlocks(llvm::BasicBlock *BB); 1558aa5bd87f1fd5f9ca47924248817c89325759b30eDaniel Dunbar 15590dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// EmitBlock - Emit the given block \arg BB and set it as the insert point, 15600dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// adding a fall-through branch from the current insert block if 15610dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// necessary. It is legal to call this function even if there is no current 15620dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// insertion point. 1563a0c21a8faa79e88ac432d116eca58f7a7217195dDaniel Dunbar /// 15640dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// IsFinished - If true, indicates that the caller has finished emitting 15650dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// branches to the given block and does not expect to emit code into it. This 15660dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// means the block can be ignored if it is unreachable. 1567a0c21a8faa79e88ac432d116eca58f7a7217195dDaniel Dunbar void EmitBlock(llvm::BasicBlock *BB, bool IsFinished=false); 1568824e3bd76b2e32db2ec6e4d2d113413e518d1c63Daniel Dunbar 1569777d6e56ad9b1fed9866daf3ee6486d85c5b7d32John McCall /// EmitBlockAfterUses - Emit the given block somewhere hopefully 1570777d6e56ad9b1fed9866daf3ee6486d85c5b7d32John McCall /// near its uses, and leave the insertion point in it. 1571777d6e56ad9b1fed9866daf3ee6486d85c5b7d32John McCall void EmitBlockAfterUses(llvm::BasicBlock *BB); 1572777d6e56ad9b1fed9866daf3ee6486d85c5b7d32John McCall 15730dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// EmitBranch - Emit a branch to the specified basic block from the current 15740dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// insert block, taking care to avoid creation of branches from dummy 15750dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// blocks. It is legal to call this function even if there is no current 15760dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// insertion point. 15775e08ad3cc62ab94649959ae227a9a411a729bf49Daniel Dunbar /// 15780dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// This function clears the current insertion point. The caller should follow 15790dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// calls to this function with calls to Emit*Block prior to generation new 15800dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// code. 1581d57a871339c7c98d58d93108b806f59bdf4e13e2Daniel Dunbar void EmitBranch(llvm::BasicBlock *Block); 1582d57a871339c7c98d58d93108b806f59bdf4e13e2Daniel Dunbar 15830dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// HaveInsertPoint - True if an insertion point is defined. If not, this 15840dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// indicates that the current code being emitted is unreachable. 15850dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump bool HaveInsertPoint() const { 1586a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar return Builder.GetInsertBlock() != 0; 1587a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar } 1588a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar 15890dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// EnsureInsertPoint - Ensure that an insertion point is defined so that 15900dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// emitted IR has a place to go. Note that by definition, if this function 15910dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// creates a block then that block is unreachable; callers may do better to 15920dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// detect when no insertion point is defined and simply skip IR generation. 1593a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar void EnsureInsertPoint() { 1594a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar if (!HaveInsertPoint()) 1595a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar EmitBlock(createBasicBlock()); 1596a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar } 15970dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 1598488e993a135ce700b982bf099c3d6b856301d642Daniel Dunbar /// ErrorUnsupported - Print out an error that codegen doesn't support the 1599dc5e8268292046114ffe02e48773572a91a310f1Chris Lattner /// specified stmt yet. 160090df4b6661968a84bf64baee489bb2f6d948fcc1Daniel Dunbar void ErrorUnsupported(const Stmt *S, const char *Type, 160190df4b6661968a84bf64baee489bb2f6d948fcc1Daniel Dunbar bool OmitOnError=false); 16025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 16035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 16045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Helpers 16055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 16060dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 16076da2c716017d5c8530ec99779524491ebc5dadb8Eli Friedman LValue MakeAddrLValue(llvm::Value *V, QualType T, 16086da2c716017d5c8530ec99779524491ebc5dadb8Eli Friedman CharUnits Alignment = CharUnits()) { 16093d5aff5d3036b0ff09d114857cd2276134b3d8c9Dan Gohman return LValue::MakeAddr(V, T, Alignment, getContext(), 16103d5aff5d3036b0ff09d114857cd2276134b3d8c9Dan Gohman CGM.getTBAAInfo(T)); 16112f77b3d57031ded0de2b7b977fb63b4660f82624Eli Friedman } 1612e0c1168ec7910a1a7ed08df4d4f0c58c2fa2ecd1John McCall 16132f77b3d57031ded0de2b7b977fb63b4660f82624Eli Friedman LValue MakeNaturalAlignAddrLValue(llvm::Value *V, QualType T) { 16146da2c716017d5c8530ec99779524491ebc5dadb8Eli Friedman CharUnits Alignment; 16156da2c716017d5c8530ec99779524491ebc5dadb8Eli Friedman if (!T->isIncompleteType()) 16166da2c716017d5c8530ec99779524491ebc5dadb8Eli Friedman Alignment = getContext().getTypeAlignInChars(T); 16172f77b3d57031ded0de2b7b977fb63b4660f82624Eli Friedman return LValue::MakeAddr(V, T, Alignment, getContext(), 16182f77b3d57031ded0de2b7b977fb63b4660f82624Eli Friedman CGM.getTBAAInfo(T)); 16195cf8bfec711116b3c4acc70a00717b2e119e7550Daniel Dunbar } 16205cf8bfec711116b3c4acc70a00717b2e119e7550Daniel Dunbar 16215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// CreateTempAlloca - This creates a alloca and inserts it into the entry 1622195337d2e5d4625ae9dc1328c7cdbc7115b0261bDaniel Dunbar /// block. The caller is responsible for setting an appropriate alignment on 1623195337d2e5d4625ae9dc1328c7cdbc7115b0261bDaniel Dunbar /// the alloca. 16242acc6e3feda5e4f7d9009bdcf8b1cd777fecfe2dChris Lattner llvm::AllocaInst *CreateTempAlloca(llvm::Type *Ty, 16258cc488fefb2fb04bc8d5398da29f0182f97934cfChris Lattner const Twine &Name = "tmp"); 16260dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 1627ac418162692a951ca3796d6830496a85a2d12493John McCall /// InitTempAlloca - Provide an initial value for the given alloca. 1628ac418162692a951ca3796d6830496a85a2d12493John McCall void InitTempAlloca(llvm::AllocaInst *Alloca, llvm::Value *Value); 1629ac418162692a951ca3796d6830496a85a2d12493John McCall 16309bd4da2cfa8b956b851200db8f9a37e175edbb15Daniel Dunbar /// CreateIRTemp - Create a temporary IR object of the given type, with 16319bd4da2cfa8b956b851200db8f9a37e175edbb15Daniel Dunbar /// appropriate alignment. This routine should only be used when an temporary 16329bd4da2cfa8b956b851200db8f9a37e175edbb15Daniel Dunbar /// value needs to be stored into an alloca (for example, to avoid explicit 16339bd4da2cfa8b956b851200db8f9a37e175edbb15Daniel Dunbar /// PHI construction), but the type is the IR type, not the type appropriate 16349bd4da2cfa8b956b851200db8f9a37e175edbb15Daniel Dunbar /// for storing in memory. 16358cc488fefb2fb04bc8d5398da29f0182f97934cfChris Lattner llvm::AllocaInst *CreateIRTemp(QualType T, const Twine &Name = "tmp"); 16369bd4da2cfa8b956b851200db8f9a37e175edbb15Daniel Dunbar 1637195337d2e5d4625ae9dc1328c7cdbc7115b0261bDaniel Dunbar /// CreateMemTemp - Create a temporary memory object of the given type, with 1638195337d2e5d4625ae9dc1328c7cdbc7115b0261bDaniel Dunbar /// appropriate alignment. 16398cc488fefb2fb04bc8d5398da29f0182f97934cfChris Lattner llvm::AllocaInst *CreateMemTemp(QualType T, const Twine &Name = "tmp"); 1640195337d2e5d4625ae9dc1328c7cdbc7115b0261bDaniel Dunbar 1641558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall /// CreateAggTemp - Create a temporary memory object for the given 1642558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall /// aggregate type. 16438cc488fefb2fb04bc8d5398da29f0182f97934cfChris Lattner AggValueSlot CreateAggTemp(QualType T, const Twine &Name = "tmp") { 1644d7722d9d76a851e7897f4127626616d3b1b8e530Eli Friedman CharUnits Alignment = getContext().getTypeAlignInChars(T); 1645f394078fde147dcf27e9b6a7965517388d64dcb6Eli Friedman return AggValueSlot::forAddr(CreateMemTemp(T, Name), Alignment, 1646f394078fde147dcf27e9b6a7965517388d64dcb6Eli Friedman T.getQualifiers(), 16477c2349be2d11143a2e59a167fd43362a3bf4585eJohn McCall AggValueSlot::IsNotDestructed, 1648410ffb2bc5f072d58a73c14560345bcf77dec1ccJohn McCall AggValueSlot::DoesNotNeedGCBarriers, 1649649b4a1a9b5e6f768ca0cb84bd97b00f51083e15Chad Rosier AggValueSlot::IsNotAliased); 1650558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall } 1651558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall 1652d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall /// Emit a cast to void* in the appropriate address space. 1653d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall llvm::Value *EmitCastToVoidPtr(llvm::Value *value); 1654d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall 16555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// EvaluateExprAsBool - Perform the usual unary conversions on the specified 16565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// expression and compare the result against zero, returning an Int1Ty value. 16575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer llvm::Value *EvaluateExprAsBool(const Expr *E); 16585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 16592a41637a995affa1563f4d82a8b026e326a2faa0John McCall /// EmitIgnoredExpr - Emit an expression in a context which ignores the result. 16602a41637a995affa1563f4d82a8b026e326a2faa0John McCall void EmitIgnoredExpr(const Expr *E); 16612a41637a995affa1563f4d82a8b026e326a2faa0John McCall 16629b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner /// EmitAnyExpr - Emit code to compute the specified expression which can have 16639b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner /// any type. The result is returned as an RValue struct. If this is an 16649b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner /// aggregate expression, the aggloc/agglocvolatile arguments indicate where 16659b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner /// the result should be returned. 166649d1cd5a09ed3df353371fd7f206674a85e0fb45Mike Stump /// 166770517ca5c07c4b41ff8662b94ee22047b0299f8cDmitri Gribenko /// \param ignoreResult True if the resulting value isn't used. 1668558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall RValue EmitAnyExpr(const Expr *E, 1669e0c1168ec7910a1a7ed08df4d4f0c58c2fa2ecd1John McCall AggValueSlot aggSlot = AggValueSlot::ignored(), 1670e0c1168ec7910a1a7ed08df4d4f0c58c2fa2ecd1John McCall bool ignoreResult = false); 1671d9363c3a80168283b3da518b4e17f545a6246857Devang Patel 16720dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump // EmitVAListRef - Emit a "reference" to a va_list; this is either the address 16730dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump // or the value of the expression, depending on how va_list is defined. 16744fd0aa5803357d8c72eeac2cae15e12649ea08feEli Friedman llvm::Value *EmitVAListRef(const Expr *E); 16754fd0aa5803357d8c72eeac2cae15e12649ea08feEli Friedman 16760dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// EmitAnyExprToTemp - Similary to EmitAnyExpr(), however, the result will 16770dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// always be accessible even if no aggregate location is provided. 1678558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall RValue EmitAnyExprToTemp(const Expr *E); 167946f45b9bec4a265ad8400a538e5ec3a5683617f1Daniel Dunbar 168060d3365b46eb826fba44483583c0051ac5c41fe3John McCall /// EmitAnyExprToMem - Emits the code necessary to evaluate an 1681649b4a1a9b5e6f768ca0cb84bd97b00f51083e15Chad Rosier /// arbitrary expression into the given memory location. 16823d3ec1c099ec8bfac3aa1fb0126fe515b7c7fa05John McCall void EmitAnyExprToMem(const Expr *E, llvm::Value *Location, 1683649b4a1a9b5e6f768ca0cb84bd97b00f51083e15Chad Rosier Qualifiers Quals, bool IsInitializer); 16843d3ec1c099ec8bfac3aa1fb0126fe515b7c7fa05John McCall 168560d3365b46eb826fba44483583c0051ac5c41fe3John McCall /// EmitExprAsInit - Emits the code necessary to initialize a 168660d3365b46eb826fba44483583c0051ac5c41fe3John McCall /// location in memory with the given initializer. 1687f85e193739c953358c865005855253af4f68a497John McCall void EmitExprAsInit(const Expr *init, const ValueDecl *D, 1688a07398ed98ea2b55ad7a505a3aab18aed93b149fJohn McCall LValue lvalue, bool capturedByInit); 168960d3365b46eb826fba44483583c0051ac5c41fe3John McCall 16903ac83d69c61238cd0d38e90fcdd03390530ab2fbFariborz Jahanian /// hasVolatileMember - returns true if aggregate type has a volatile 16913ac83d69c61238cd0d38e90fcdd03390530ab2fbFariborz Jahanian /// member. 16923ac83d69c61238cd0d38e90fcdd03390530ab2fbFariborz Jahanian bool hasVolatileMember(QualType T) { 16933ac83d69c61238cd0d38e90fcdd03390530ab2fbFariborz Jahanian if (const RecordType *RT = T->getAs<RecordType>()) { 16943ac83d69c61238cd0d38e90fcdd03390530ab2fbFariborz Jahanian const RecordDecl *RD = cast<RecordDecl>(RT->getDecl()); 16953ac83d69c61238cd0d38e90fcdd03390530ab2fbFariborz Jahanian return RD->hasVolatileMember(); 16963ac83d69c61238cd0d38e90fcdd03390530ab2fbFariborz Jahanian } 16973ac83d69c61238cd0d38e90fcdd03390530ab2fbFariborz Jahanian return false; 16983ac83d69c61238cd0d38e90fcdd03390530ab2fbFariborz Jahanian } 16998fcbb8dfbc28b6279d22144e10ade401a6c03e9eArnaud A. de Grandmaison /// EmitAggregateCopy - Emit an aggregate assignment. 17006cacae8bf9597b8124cd40aedc189c04484e1990Benjamin Kramer /// 17016cacae8bf9597b8124cd40aedc189c04484e1990Benjamin Kramer /// The difference to EmitAggregateCopy is that tail padding is not copied. 17026cacae8bf9597b8124cd40aedc189c04484e1990Benjamin Kramer /// This is required for correctness when assigning non-POD structures in C++. 17036cacae8bf9597b8124cd40aedc189c04484e1990Benjamin Kramer void EmitAggregateAssign(llvm::Value *DestPtr, llvm::Value *SrcPtr, 17043ac83d69c61238cd0d38e90fcdd03390530ab2fbFariborz Jahanian QualType EltTy) { 17053ac83d69c61238cd0d38e90fcdd03390530ab2fbFariborz Jahanian bool IsVolatile = hasVolatileMember(EltTy); 17063ac83d69c61238cd0d38e90fcdd03390530ab2fbFariborz Jahanian EmitAggregateCopy(DestPtr, SrcPtr, EltTy, IsVolatile, CharUnits::Zero(), 17073ac83d69c61238cd0d38e90fcdd03390530ab2fbFariborz Jahanian true); 17086cacae8bf9597b8124cd40aedc189c04484e1990Benjamin Kramer } 17096cacae8bf9597b8124cd40aedc189c04484e1990Benjamin Kramer 17108fcbb8dfbc28b6279d22144e10ade401a6c03e9eArnaud A. de Grandmaison /// EmitAggregateCopy - Emit an aggregate copy. 171127fe2e6c97a3782a0639d87b460741e8ba5d076dMike Stump /// 1712f3477c13eeaf11b32a41f181398fb5deffd0dd73Sylvestre Ledru /// \param isVolatile - True iff either the source or the destination is 171327fe2e6c97a3782a0639d87b460741e8ba5d076dMike Stump /// volatile. 17146cacae8bf9597b8124cd40aedc189c04484e1990Benjamin Kramer /// \param isAssignment - If false, allow padding to be copied. This often 17156cacae8bf9597b8124cd40aedc189c04484e1990Benjamin Kramer /// yields more efficient. 17167482d12c345c6391f8956850545e2d4aa7701ce6Daniel Dunbar void EmitAggregateCopy(llvm::Value *DestPtr, llvm::Value *SrcPtr, 1717bd7d82878c1588afccbee6c68fa6e17bbbab7f2cEli Friedman QualType EltTy, bool isVolatile=false, 17186cacae8bf9597b8124cd40aedc189c04484e1990Benjamin Kramer CharUnits Alignment = CharUnits::Zero(), 17196cacae8bf9597b8124cd40aedc189c04484e1990Benjamin Kramer bool isAssignment = false); 17207482d12c345c6391f8956850545e2d4aa7701ce6Daniel Dunbar 172151b09f2c528c8460b5465c676173324e44176d62Devang Patel /// StartBlock - Start new block named N. If insert block is a dummy block 172251b09f2c528c8460b5465c676173324e44176d62Devang Patel /// then reuse it. 172351b09f2c528c8460b5465c676173324e44176d62Devang Patel void StartBlock(const char *N); 172451b09f2c528c8460b5465c676173324e44176d62Devang Patel 1725dde0a94120915fa925d1ffcdb997c7b44dc9fa21Anders Carlsson /// GetAddrOfLocalVar - Return the address of a local variable. 17264c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall llvm::Value *GetAddrOfLocalVar(const VarDecl *VD) { 17274c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall llvm::Value *Res = LocalDeclMap[VD]; 17284c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall assert(Res && "Invalid argument to GetAddrOfLocalVar(), no decl!"); 17294c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall return Res; 17304c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall } 17310dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 173256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// getOpaqueLValueMapping - Given an opaque value expression (which 173356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// must be mapped to an l-value), return its mapping. 173456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall const LValue &getOpaqueLValueMapping(const OpaqueValueExpr *e) { 173556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall assert(OpaqueValueMapping::shouldBindAsLValue(e)); 173656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 173756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall llvm::DenseMap<const OpaqueValueExpr*,LValue>::iterator 173856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall it = OpaqueLValues.find(e); 173956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall assert(it != OpaqueLValues.end() && "no mapping for opaque value!"); 174056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return it->second; 174156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 174256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 174356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// getOpaqueRValueMapping - Given an opaque value expression (which 174456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// must be mapped to an r-value), return its mapping. 174556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall const RValue &getOpaqueRValueMapping(const OpaqueValueExpr *e) { 174656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall assert(!OpaqueValueMapping::shouldBindAsLValue(e)); 174756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 174856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall llvm::DenseMap<const OpaqueValueExpr*,RValue>::iterator 174956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall it = OpaqueRValues.find(e); 175056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall assert(it != OpaqueRValues.end() && "no mapping for opaque value!"); 1751e996ffd240f20a1048179d7727a6ee3227261921John McCall return it->second; 1752e996ffd240f20a1048179d7727a6ee3227261921John McCall } 1753e996ffd240f20a1048179d7727a6ee3227261921John McCall 17544f8d123e3e2c260de3377208106ddba87cee28b4Dan Gohman /// getAccessedFieldNo - Given an encoded value and a result number, return 17554f8d123e3e2c260de3377208106ddba87cee28b4Dan Gohman /// the input field number being accessed. 17564f8d123e3e2c260de3377208106ddba87cee28b4Dan Gohman static unsigned getAccessedFieldNo(unsigned Idx, const llvm::Constant *Elts); 17574f8d123e3e2c260de3377208106ddba87cee28b4Dan Gohman 1758ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner llvm::BlockAddress *GetAddrOfLabel(const LabelDecl *L); 17593d00fdc82fd550ae4bfbb2e700a1fc85bbd6d6fdChris Lattner llvm::BasicBlock *GetIndirectGotoBlock(); 17600ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar 17611884eb0b5c55edda4893ddec45e7dbad79758782Anders Carlsson /// EmitNullInitialization - Generate code to set a value of the given type to 17621884eb0b5c55edda4893ddec45e7dbad79758782Anders Carlsson /// null, If the type contains data member pointers, they will be initialized 17631884eb0b5c55edda4893ddec45e7dbad79758782Anders Carlsson /// to -1 in accordance with the Itanium C++ ABI. 17641884eb0b5c55edda4893ddec45e7dbad79758782Anders Carlsson void EmitNullInitialization(llvm::Value *DestPtr, QualType Ty); 1765ddf7cac45d85b73127adbbd91a2b28fc7291c57eAnders Carlsson 1766ddf7cac45d85b73127adbbd91a2b28fc7291c57eAnders Carlsson // EmitVAArg - Generate code to get an argument from the passed in pointer 1767ddf7cac45d85b73127adbbd91a2b28fc7291c57eAnders Carlsson // and update it accordingly. The return value is a pointer to the argument. 1768ddf7cac45d85b73127adbbd91a2b28fc7291c57eAnders Carlsson // FIXME: We should be able to get rid of this method and use the va_arg 17690dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump // instruction in LLVM instead once it works well enough. 1770ddf7cac45d85b73127adbbd91a2b28fc7291c57eAnders Carlsson llvm::Value *EmitVAArg(llvm::Value *VAListAddr, QualType Ty); 1771f666b7780d04186521adcaedb0e15dfa4d5e6933Anders Carlsson 1772bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall /// emitArrayLength - Compute the length of an array, even if it's a 1773bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall /// VLA, and drill down to the base element type. 1774bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall llvm::Value *emitArrayLength(const ArrayType *arrayType, 1775bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall QualType &baseType, 1776bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall llvm::Value *&addr); 1777bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall 1778bc8d40d85f3fa1e34569834916f18fecaa635152John McCall /// EmitVLASize - Capture all the sizes for the VLA expressions in 1779bc8d40d85f3fa1e34569834916f18fecaa635152John McCall /// the given variably-modified type and store them in the VLASizeMap. 1780d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar /// 1781d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar /// This function can be called with a null (unreachable) insert point. 1782bc8d40d85f3fa1e34569834916f18fecaa635152John McCall void EmitVariablyModifiedType(QualType Ty); 1783bc8d40d85f3fa1e34569834916f18fecaa635152John McCall 1784bc8d40d85f3fa1e34569834916f18fecaa635152John McCall /// getVLASize - Returns an LLVM value that corresponds to the size, 1785bc8d40d85f3fa1e34569834916f18fecaa635152John McCall /// in non-variably-sized elements, of a variable length array type, 1786bc8d40d85f3fa1e34569834916f18fecaa635152John McCall /// plus that largest non-variably-sized element type. Assumes that 1787bc8d40d85f3fa1e34569834916f18fecaa635152John McCall /// the type has already been emitted with EmitVariablyModifiedType. 1788bc8d40d85f3fa1e34569834916f18fecaa635152John McCall std::pair<llvm::Value*,QualType> getVLASize(const VariableArrayType *vla); 1789bc8d40d85f3fa1e34569834916f18fecaa635152John McCall std::pair<llvm::Value*,QualType> getVLASize(QualType vla); 1790dcc90d87e6430c643b4311ae5b0089535bca41f7Anders Carlsson 17915f4307b7ba164b03c853c8d3eb4674d33f8967a6Anders Carlsson /// LoadCXXThis - Load the value of 'this'. This function is only valid while 17925f4307b7ba164b03c853c8d3eb4674d33f8967a6Anders Carlsson /// generating code for an C++ member function. 17932504941793b549323f9d29c62507cf21d865fadeJohn McCall llvm::Value *LoadCXXThis() { 17942504941793b549323f9d29c62507cf21d865fadeJohn McCall assert(CXXThisValue && "no 'this' value for this function"); 17952504941793b549323f9d29c62507cf21d865fadeJohn McCall return CXXThisValue; 17962504941793b549323f9d29c62507cf21d865fadeJohn McCall } 17971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1798c997d4278d329e18891aac9698fb991b2d4622ebAnders Carlsson /// LoadCXXVTT - Load the VTT parameter to base constructors/destructors have 1799c997d4278d329e18891aac9698fb991b2d4622ebAnders Carlsson /// virtual bases. 180059660c21178b6af518bd4b564e032d5c9cc218cbTimur Iskhodzhanov // FIXME: Every place that calls LoadCXXVTT is something 180159660c21178b6af518bd4b564e032d5c9cc218cbTimur Iskhodzhanov // that needs to be abstracted properly. 18022504941793b549323f9d29c62507cf21d865fadeJohn McCall llvm::Value *LoadCXXVTT() { 180359660c21178b6af518bd4b564e032d5c9cc218cbTimur Iskhodzhanov assert(CXXStructorImplicitParamValue && "no VTT value for this function"); 180459660c21178b6af518bd4b564e032d5c9cc218cbTimur Iskhodzhanov return CXXStructorImplicitParamValue; 180559660c21178b6af518bd4b564e032d5c9cc218cbTimur Iskhodzhanov } 180659660c21178b6af518bd4b564e032d5c9cc218cbTimur Iskhodzhanov 180759660c21178b6af518bd4b564e032d5c9cc218cbTimur Iskhodzhanov /// LoadCXXStructorImplicitParam - Load the implicit parameter 180859660c21178b6af518bd4b564e032d5c9cc218cbTimur Iskhodzhanov /// for a constructor/destructor. 180959660c21178b6af518bd4b564e032d5c9cc218cbTimur Iskhodzhanov llvm::Value *LoadCXXStructorImplicitParam() { 181059660c21178b6af518bd4b564e032d5c9cc218cbTimur Iskhodzhanov assert(CXXStructorImplicitParamValue && 181159660c21178b6af518bd4b564e032d5c9cc218cbTimur Iskhodzhanov "no implicit argument value for this function"); 181259660c21178b6af518bd4b564e032d5c9cc218cbTimur Iskhodzhanov return CXXStructorImplicitParamValue; 18132504941793b549323f9d29c62507cf21d865fadeJohn McCall } 1814bff225ecf77fb891596ecb1b27196310d268365eJohn McCall 1815bff225ecf77fb891596ecb1b27196310d268365eJohn McCall /// GetAddressOfBaseOfCompleteClass - Convert the given pointer to a 18168561a8666c70f924c8f0209c41b9b77bbbf90607Anders Carlsson /// complete class to the given direct base. 18178561a8666c70f924c8f0209c41b9b77bbbf90607Anders Carlsson llvm::Value * 18188561a8666c70f924c8f0209c41b9b77bbbf90607Anders Carlsson GetAddressOfDirectBaseInCompleteClass(llvm::Value *Value, 18198561a8666c70f924c8f0209c41b9b77bbbf90607Anders Carlsson const CXXRecordDecl *Derived, 18208561a8666c70f924c8f0209c41b9b77bbbf90607Anders Carlsson const CXXRecordDecl *Base, 18218561a8666c70f924c8f0209c41b9b77bbbf90607Anders Carlsson bool BaseIsVirtual); 1822a88ad5618fcb07c5374c79d6781a33234984b039Anders Carlsson 1823f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump /// GetAddressOfBaseClass - This function will add the necessary delta to the 1824f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump /// load of 'this' and returns address of the base class. 18259cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer llvm::Value *GetAddressOfBaseClass(llvm::Value *Value, 18268561a8666c70f924c8f0209c41b9b77bbbf90607Anders Carlsson const CXXRecordDecl *Derived, 1827f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall CastExpr::path_const_iterator PathBegin, 1828f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall CastExpr::path_const_iterator PathEnd, 182934a2d384c745ebc39cae45dc1c0c4a6a7012e09bAnders Carlsson bool NullCheckValue); 183034a2d384c745ebc39cae45dc1c0c4a6a7012e09bAnders Carlsson 1831a3697c9c155bda93fd2802f37084b620f4738822Anders Carlsson llvm::Value *GetAddressOfDerivedClass(llvm::Value *Value, 18328561a8666c70f924c8f0209c41b9b77bbbf90607Anders Carlsson const CXXRecordDecl *Derived, 1833f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall CastExpr::path_const_iterator PathBegin, 1834f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall CastExpr::path_const_iterator PathEnd, 18355a0f49ebc83e7fe0da07b9964c44b0a7fae270cbAnders Carlsson bool NullCheckValue); 1836a3697c9c155bda93fd2802f37084b620f4738822Anders Carlsson 1837bb7e17b52ffaa4097b4c4d7935746d23539ffe2aAnders Carlsson llvm::Value *GetVirtualBaseClassOffset(llvm::Value *This, 1838bb7e17b52ffaa4097b4c4d7935746d23539ffe2aAnders Carlsson const CXXRecordDecl *ClassDecl, 1839bb7e17b52ffaa4097b4c4d7935746d23539ffe2aAnders Carlsson const CXXRecordDecl *BaseClassDecl); 18409cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer 18411d4fff5551c2347010b955b4337a2aa7d65a050eTimur Iskhodzhanov /// GetVTTParameter - Return the VTT parameter that should be passed to a 18421d4fff5551c2347010b955b4337a2aa7d65a050eTimur Iskhodzhanov /// base constructor/destructor with virtual bases. 18431d4fff5551c2347010b955b4337a2aa7d65a050eTimur Iskhodzhanov /// FIXME: VTTs are Itanium ABI-specific, so the definition should move 18441d4fff5551c2347010b955b4337a2aa7d65a050eTimur Iskhodzhanov /// to ItaniumCXXABI.cpp together with all the references to VTT. 18451d4fff5551c2347010b955b4337a2aa7d65a050eTimur Iskhodzhanov llvm::Value *GetVTTParameter(GlobalDecl GD, bool ForVirtualBase, 18461d4fff5551c2347010b955b4337a2aa7d65a050eTimur Iskhodzhanov bool Delegating); 18471d4fff5551c2347010b955b4337a2aa7d65a050eTimur Iskhodzhanov 1848c0bf462cf35fe050bddbd8bff967298e4a67e79dJohn McCall void EmitDelegateCXXConstructorCall(const CXXConstructorDecl *Ctor, 1849c0bf462cf35fe050bddbd8bff967298e4a67e79dJohn McCall CXXCtorType CtorType, 1850c0bf462cf35fe050bddbd8bff967298e4a67e79dJohn McCall const FunctionArgList &Args); 1851059ce0d92eb5a7da900ae735dc0a2ea3d64f4b0bSean Hunt // It's important not to confuse this and the previous function. Delegating 1852059ce0d92eb5a7da900ae735dc0a2ea3d64f4b0bSean Hunt // constructors are the C++0x feature. The constructor delegate optimization 1853059ce0d92eb5a7da900ae735dc0a2ea3d64f4b0bSean Hunt // is used to reduce duplication in the base and complete consturctors where 1854059ce0d92eb5a7da900ae735dc0a2ea3d64f4b0bSean Hunt // they are substantially the same. 1855059ce0d92eb5a7da900ae735dc0a2ea3d64f4b0bSean Hunt void EmitDelegatingCXXConstructorCall(const CXXConstructorDecl *Ctor, 1856059ce0d92eb5a7da900ae735dc0a2ea3d64f4b0bSean Hunt const FunctionArgList &Args); 1857155ed4a23366f4514befb1c9f5f89d16f8b8b6dbAnders Carlsson void EmitCXXConstructorCall(const CXXConstructorDecl *D, CXXCtorType Type, 1858378e1e739aed97e9b278beeb20e9f5bbe34c0232Douglas Gregor bool ForVirtualBase, bool Delegating, 1859378e1e739aed97e9b278beeb20e9f5bbe34c0232Douglas Gregor llvm::Value *This, 1860b14095aa98c6fedd3625920c4ce834bcaf24d9f7Anders Carlsson CallExpr::const_arg_iterator ArgBeg, 1861b14095aa98c6fedd3625920c4ce834bcaf24d9f7Anders Carlsson CallExpr::const_arg_iterator ArgEnd); 186234999876e215b22febc240b1a6dc054215d12f9cFariborz Jahanian 186334999876e215b22febc240b1a6dc054215d12f9cFariborz Jahanian void EmitSynthesizedCXXCopyCtorCall(const CXXConstructorDecl *D, 186434999876e215b22febc240b1a6dc054215d12f9cFariborz Jahanian llvm::Value *This, llvm::Value *Src, 186534999876e215b22febc240b1a6dc054215d12f9cFariborz Jahanian CallExpr::const_arg_iterator ArgBeg, 186634999876e215b22febc240b1a6dc054215d12f9cFariborz Jahanian CallExpr::const_arg_iterator ArgEnd); 18671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1868288dcaf329c49b01dacd5c1dd9f35609555feecdFariborz Jahanian void EmitCXXAggrConstructorCall(const CXXConstructorDecl *D, 1869569c1f4a6c703eaa8b963bed7d5c2fd5d4569e93Anders Carlsson const ConstantArrayType *ArrayTy, 18705d4d946ec2d88696fd8422aeb64dc29688e6a2c1Anders Carlsson llvm::Value *ArrayPtr, 18715d4d946ec2d88696fd8422aeb64dc29688e6a2c1Anders Carlsson CallExpr::const_arg_iterator ArgBeg, 187259174c0633fb5cde41735cfbff5744bdf837e8d9Douglas Gregor CallExpr::const_arg_iterator ArgEnd, 187359174c0633fb5cde41735cfbff5744bdf837e8d9Douglas Gregor bool ZeroInitialization = false); 18749cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer 1875569c1f4a6c703eaa8b963bed7d5c2fd5d4569e93Anders Carlsson void EmitCXXAggrConstructorCall(const CXXConstructorDecl *D, 1876569c1f4a6c703eaa8b963bed7d5c2fd5d4569e93Anders Carlsson llvm::Value *NumElements, 18775d4d946ec2d88696fd8422aeb64dc29688e6a2c1Anders Carlsson llvm::Value *ArrayPtr, 18785d4d946ec2d88696fd8422aeb64dc29688e6a2c1Anders Carlsson CallExpr::const_arg_iterator ArgBeg, 187959174c0633fb5cde41735cfbff5744bdf837e8d9Douglas Gregor CallExpr::const_arg_iterator ArgEnd, 188059174c0633fb5cde41735cfbff5744bdf837e8d9Douglas Gregor bool ZeroInitialization = false); 1881b14095aa98c6fedd3625920c4ce834bcaf24d9f7Anders Carlsson 1882bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall static Destroyer destroyCXXObject; 1883bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall 18847267c1693abe7875b0c57268be05005ae013c6c9Anders Carlsson void EmitCXXDestructorCall(const CXXDestructorDecl *D, CXXDtorType Type, 1885378e1e739aed97e9b278beeb20e9f5bbe34c0232Douglas Gregor bool ForVirtualBase, bool Delegating, 1886378e1e739aed97e9b278beeb20e9f5bbe34c0232Douglas Gregor llvm::Value *This); 18879cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer 1888197056726ed6412501130c2ef2ff69009772aa65John McCall void EmitNewArrayInitializer(const CXXNewExpr *E, QualType elementType, 1889197056726ed6412501130c2ef2ff69009772aa65John McCall llvm::Value *NewPtr, llvm::Value *NumElements); 18901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 189186811609d9353e3aed198045d56e790eb3b6118cPeter Collingbourne void EmitCXXTemporary(const CXXTemporary *Temporary, QualType TempType, 189286811609d9353e3aed198045d56e790eb3b6118cPeter Collingbourne llvm::Value *Ptr); 18931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1894a00703dccbdc6cc4a293db38477dea7db5538c7eAnders Carlsson llvm::Value *EmitCXXNewExpr(const CXXNewExpr *E); 189560e282cc1e508be327b0481cecedc206873cb86aAnders Carlsson void EmitCXXDeleteExpr(const CXXDeleteExpr *E); 18961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 18974bf8152799ec41796f989ea1b94f6f1bac349117Eli Friedman void EmitDeleteCall(const FunctionDecl *DeleteFD, llvm::Value *Ptr, 18984bf8152799ec41796f989ea1b94f6f1bac349117Eli Friedman QualType DeleteTy); 18994bf8152799ec41796f989ea1b94f6f1bac349117Eli Friedman 1900c2e84ae9a6d25cea3e583c768e576b4c981ec028Mike Stump llvm::Value* EmitCXXTypeidExpr(const CXXTypeidExpr *E); 1901c849c052d6b4b70f2651c1969531861a5f230053Mike Stump llvm::Value *EmitDynamicCast(llvm::Value *V, const CXXDynamicCastExpr *DCE); 1902c5f804636e367ef744fd24cf88f7c956a5af0434Nico Weber llvm::Value* EmitCXXUuidofExpr(const CXXUuidofExpr *E); 1903c2e84ae9a6d25cea3e583c768e576b4c981ec028Mike Stump 1904972edf0534d8a50f87fac1d0ff34eb22f593df11Sebastian Redl void MaybeEmitStdInitializerListCleanup(llvm::Value *loc, const Expr *init); 1905af130fd78267ee9e2395b758a7d827b07ce317a0Sebastian Redl void EmitStdInitializerListCleanup(llvm::Value *loc, 1906af130fd78267ee9e2395b758a7d827b07ce317a0Sebastian Redl const InitListExpr *init); 190732cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl 19082c9f87ca5cccbfdaad82762368af5b2323320653Richard Smith /// \brief Situations in which we might emit a check for the suitability of a 19092c9f87ca5cccbfdaad82762368af5b2323320653Richard Smith /// pointer or glvalue. 19107ac9ef1c82c779a5348ed11b3d10e01c58803b35Richard Smith enum TypeCheckKind { 19112c9f87ca5cccbfdaad82762368af5b2323320653Richard Smith /// Checking the operand of a load. Must be suitably sized and aligned. 19127ac9ef1c82c779a5348ed11b3d10e01c58803b35Richard Smith TCK_Load, 19132c9f87ca5cccbfdaad82762368af5b2323320653Richard Smith /// Checking the destination of a store. Must be suitably sized and aligned. 19147ac9ef1c82c779a5348ed11b3d10e01c58803b35Richard Smith TCK_Store, 19152c9f87ca5cccbfdaad82762368af5b2323320653Richard Smith /// Checking the bound value in a reference binding. Must be suitably sized 19162c9f87ca5cccbfdaad82762368af5b2323320653Richard Smith /// and aligned, but is not required to refer to an object (until the 19172c9f87ca5cccbfdaad82762368af5b2323320653Richard Smith /// reference is used), per core issue 453. 19187ac9ef1c82c779a5348ed11b3d10e01c58803b35Richard Smith TCK_ReferenceBinding, 19192c9f87ca5cccbfdaad82762368af5b2323320653Richard Smith /// Checking the object expression in a non-static data member access. Must 19202c9f87ca5cccbfdaad82762368af5b2323320653Richard Smith /// be an object within its lifetime. 19217ac9ef1c82c779a5348ed11b3d10e01c58803b35Richard Smith TCK_MemberAccess, 19222c9f87ca5cccbfdaad82762368af5b2323320653Richard Smith /// Checking the 'this' pointer for a call to a non-static member function. 19232c9f87ca5cccbfdaad82762368af5b2323320653Richard Smith /// Must be an object within its lifetime. 19248e1cee6f23e2552b96b81e5ef419ab3f69c5b5c2Richard Smith TCK_MemberCall, 19258e1cee6f23e2552b96b81e5ef419ab3f69c5b5c2Richard Smith /// Checking the 'this' pointer for a constructor call. 1926c764830bdb6de82baed068889096bd3e52d4cbdaRichard Smith TCK_ConstructorCall, 1927c764830bdb6de82baed068889096bd3e52d4cbdaRichard Smith /// Checking the operand of a static_cast to a derived pointer type. Must be 1928c764830bdb6de82baed068889096bd3e52d4cbdaRichard Smith /// null or an object within its lifetime. 1929c764830bdb6de82baed068889096bd3e52d4cbdaRichard Smith TCK_DowncastPointer, 1930c764830bdb6de82baed068889096bd3e52d4cbdaRichard Smith /// Checking the operand of a static_cast to a derived reference type. Must 1931c764830bdb6de82baed068889096bd3e52d4cbdaRichard Smith /// be an object within its lifetime. 1932c764830bdb6de82baed068889096bd3e52d4cbdaRichard Smith TCK_DowncastReference 19332c9f87ca5cccbfdaad82762368af5b2323320653Richard Smith }; 19342c9f87ca5cccbfdaad82762368af5b2323320653Richard Smith 19357ac9ef1c82c779a5348ed11b3d10e01c58803b35Richard Smith /// \brief Emit a check that \p V is the address of storage of the 19362c9f87ca5cccbfdaad82762368af5b2323320653Richard Smith /// appropriate size and alignment for an object of type \p Type. 19374def70d3040e73707c738f7c366737a986135edfRichard Smith void EmitTypeCheck(TypeCheckKind TCK, SourceLocation Loc, llvm::Value *V, 19387ac9ef1c82c779a5348ed11b3d10e01c58803b35Richard Smith QualType Type, CharUnits Alignment = CharUnits::Zero()); 1939b14e62d5aee7522b98c410ee65bd750c2cfe6f01Mike Stump 1940a0a628f839cf50844cc0f226bd9cb72485f98f91Richard Smith /// \brief Emit a check that \p Base points into an array object, which 1941a0a628f839cf50844cc0f226bd9cb72485f98f91Richard Smith /// we can access at index \p Index. \p Accessed should be \c false if we 1942a0a628f839cf50844cc0f226bd9cb72485f98f91Richard Smith /// this expression is used as an lvalue, for instance in "&Arr[Idx]". 1943a0a628f839cf50844cc0f226bd9cb72485f98f91Richard Smith void EmitBoundsCheck(const Expr *E, const Expr *Base, llvm::Value *Index, 1944a0a628f839cf50844cc0f226bd9cb72485f98f91Richard Smith QualType IndexType, bool Accessed); 1945a0a628f839cf50844cc0f226bd9cb72485f98f91Richard Smith 1946dd36d328730d8c02915d0884541b45ec6ca0049dChris Lattner llvm::Value *EmitScalarPrePostIncDec(const UnaryOperator *E, LValue LV, 1947dd36d328730d8c02915d0884541b45ec6ca0049dChris Lattner bool isInc, bool isPre); 1948dd36d328730d8c02915d0884541b45ec6ca0049dChris Lattner ComplexPairTy EmitComplexPrePostIncDec(const UnaryOperator *E, LValue LV, 1949dd36d328730d8c02915d0884541b45ec6ca0049dChris Lattner bool isInc, bool isPre); 19505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 19515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Declaration Emission 19525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 19530dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 1954d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar /// EmitDecl - Emit a declaration. 1955d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar /// 1956d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar /// This function can be called with a null (unreachable) insert point. 19575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void EmitDecl(const Decl &D); 1958d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar 1959b6bbcc9995186799a60ce17d0c1acff31601653aJohn McCall /// EmitVarDecl - Emit a local variable declaration. 1960d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar /// 1961d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar /// This function can be called with a null (unreachable) insert point. 1962b6bbcc9995186799a60ce17d0c1acff31601653aJohn McCall void EmitVarDecl(const VarDecl &D); 1963d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar 1964f85e193739c953358c865005855253af4f68a497John McCall void EmitScalarInit(const Expr *init, const ValueDecl *D, 1965a07398ed98ea2b55ad7a505a3aab18aed93b149fJohn McCall LValue lvalue, bool capturedByInit); 19667acddacc921cd0b3f813443a8641eeddb82dfbd4John McCall void EmitScalarInit(llvm::Value *init, LValue lvalue); 1967f85e193739c953358c865005855253af4f68a497John McCall 1968f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall typedef void SpecialInitFn(CodeGenFunction &Init, const VarDecl &D, 1969f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall llvm::Value *Address); 1970f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 1971b6bbcc9995186799a60ce17d0c1acff31601653aJohn McCall /// EmitAutoVarDecl - Emit an auto variable declaration. 1972d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar /// 1973d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar /// This function can be called with a null (unreachable) insert point. 197434695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall void EmitAutoVarDecl(const VarDecl &D); 197534695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall 197634695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall class AutoVarEmission { 197734695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall friend class CodeGenFunction; 197834695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall 197957b3b6a60856eaec30fd876a8a3face8f7e3ad7bJohn McCall const VarDecl *Variable; 198034695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall 198134695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall /// The alignment of the variable. 198234695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall CharUnits Alignment; 198334695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall 198434695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall /// The address of the alloca. Null if the variable was emitted 198534695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall /// as a global constant. 198634695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall llvm::Value *Address; 198734695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall 198834695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall llvm::Value *NRVOFlag; 198934695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall 199034695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall /// True if the variable is a __block variable. 199134695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall bool IsByRef; 199234695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall 199334695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall /// True if the variable is of aggregate type and has a constant 199434695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall /// initializer. 199534695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall bool IsConstantAggregate; 199634695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall 199757b3b6a60856eaec30fd876a8a3face8f7e3ad7bJohn McCall struct Invalid {}; 199857b3b6a60856eaec30fd876a8a3face8f7e3ad7bJohn McCall AutoVarEmission(Invalid) : Variable(0) {} 199957b3b6a60856eaec30fd876a8a3face8f7e3ad7bJohn McCall 200034695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall AutoVarEmission(const VarDecl &variable) 200157b3b6a60856eaec30fd876a8a3face8f7e3ad7bJohn McCall : Variable(&variable), Address(0), NRVOFlag(0), 200234695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall IsByRef(false), IsConstantAggregate(false) {} 200334695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall 200434695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall bool wasEmittedAsGlobal() const { return Address == 0; } 200534695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall 200634695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall public: 200757b3b6a60856eaec30fd876a8a3face8f7e3ad7bJohn McCall static AutoVarEmission invalid() { return AutoVarEmission(Invalid()); } 200857b3b6a60856eaec30fd876a8a3face8f7e3ad7bJohn McCall 200934695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall /// Returns the address of the object within this declaration. 201034695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall /// Note that this does not chase the forwarding pointer for 201134695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall /// __block decls. 201234695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall llvm::Value *getObjectAddress(CodeGenFunction &CGF) const { 201334695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall if (!IsByRef) return Address; 201434695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall 201534695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall return CGF.Builder.CreateStructGEP(Address, 201657b3b6a60856eaec30fd876a8a3face8f7e3ad7bJohn McCall CGF.getByRefValueLLVMField(Variable), 201757b3b6a60856eaec30fd876a8a3face8f7e3ad7bJohn McCall Variable->getNameAsString()); 201834695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall } 201934695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall }; 202034695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall AutoVarEmission EmitAutoVarAlloca(const VarDecl &var); 202134695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall void EmitAutoVarInit(const AutoVarEmission &emission); 202234695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall void EmitAutoVarCleanups(const AutoVarEmission &emission); 2023bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall void emitAutoVarTypeCleanup(const AutoVarEmission &emission, 2024bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall QualType::DestructionKind dtorKind); 2025d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar 2026b6bbcc9995186799a60ce17d0c1acff31601653aJohn McCall void EmitStaticVarDecl(const VarDecl &D, 2027b6bbcc9995186799a60ce17d0c1acff31601653aJohn McCall llvm::GlobalValue::LinkageTypes Linkage); 2028b7ec246872b412f0e7bb9e93eacfd78cfa6adfb3Daniel Dunbar 2029b7ec246872b412f0e7bb9e93eacfd78cfa6adfb3Daniel Dunbar /// EmitParmDecl - Emit a ParmVarDecl or an ImplicitParamDecl. 2030093ac461b37a573dcf226fa55faed96f318169b9Devang Patel void EmitParmDecl(const VarDecl &D, llvm::Value *Arg, unsigned ArgNo); 20310dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 203256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// protectFromPeepholes - Protect a value that we're intending to 203356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// store to the side, but which will probably be used later, from 203456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// aggressive peepholing optimizations that might delete it. 203556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// 203656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// Pass the result to unprotectFromPeepholes to declare that 203756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// protection is no longer required. 203856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// 203956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// There's no particular reason why this shouldn't apply to 204056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// l-values, it's just that no existing peepholes work on pointers. 204156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall PeepholeProtection protectFromPeepholes(RValue rvalue); 204256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall void unprotectFromPeepholes(PeepholeProtection protection); 204356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 20445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 20455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Statement Emission 20465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 20475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 20480dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// EmitStopPoint - Emit a debug stoppoint if we are emitting debug info. 20490912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar void EmitStopPoint(const Stmt *S); 20500912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar 20510dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// EmitStmt - Emit the code for the statement \arg S. It is legal to call 20520dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// this function even if there is no current insertion point. 20530dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// 20540dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// This function may clear the current insertion point; callers should use 20550dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// EnsureInsertPoint if they wish to subsequently generate code without first 20560dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// calling EmitBlock, EmitBranch, or EmitStmt. 20575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void EmitStmt(const Stmt *S); 2058a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar 20590912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar /// EmitSimpleStmt - Try to emit a "simple" statement which does not 20600dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// necessarily require an insertion point or debug information; typically 20610dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// because the statement amounts to a jump or a container of other 20620dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// statements. 20630912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar /// 20640912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar /// \return True if the statement was handled. 20650912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar bool EmitSimpleStmt(const Stmt *S); 20660912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar 20679b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner RValue EmitCompoundStmt(const CompoundStmt &S, bool GetLast = false, 2068558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall AggValueSlot AVS = AggValueSlot::ignored()); 2069a6504853d297c30cfa271f4710af5a3d5db59449David Blaikie RValue EmitCompoundStmtWithoutScope(const CompoundStmt &S, 2070a6504853d297c30cfa271f4710af5a3d5db59449David Blaikie bool GetLast = false, AggValueSlot AVS = 2071a6504853d297c30cfa271f4710af5a3d5db59449David Blaikie AggValueSlot::ignored()); 2072a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar 20730dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// EmitLabel - Emit the block for the given label. It is legal to call this 20740dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// function even if there is no current insertion point. 2075ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner void EmitLabel(const LabelDecl *D); // helper for EmitLabelStmt. 2076a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar 20775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void EmitLabelStmt(const LabelStmt &S); 2078534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith void EmitAttributedStmt(const AttributedStmt &S); 20795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void EmitGotoStmt(const GotoStmt &S); 20800ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar void EmitIndirectGotoStmt(const IndirectGotoStmt &S); 20815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void EmitIfStmt(const IfStmt &S); 20825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void EmitWhileStmt(const WhileStmt &S); 20835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void EmitDoStmt(const DoStmt &S); 20845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void EmitForStmt(const ForStmt &S); 20855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void EmitReturnStmt(const ReturnStmt &S); 20865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void EmitDeclStmt(const DeclStmt &S); 20870912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar void EmitBreakStmt(const BreakStmt &S); 20880912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar void EmitContinueStmt(const ContinueStmt &S); 208951b09f2c528c8460b5465c676173324e44176d62Devang Patel void EmitSwitchStmt(const SwitchStmt &S); 209051b09f2c528c8460b5465c676173324e44176d62Devang Patel void EmitDefaultStmt(const DefaultStmt &S); 209151b09f2c528c8460b5465c676173324e44176d62Devang Patel void EmitCaseStmt(const CaseStmt &S); 2092c049e4f406a7f7179eba98659044a32508e53289Devang Patel void EmitCaseStmtRange(const CaseStmt &S); 2093a23b91d542e336be5051ac54f394e860fb756911Chad Rosier void EmitAsmStmt(const AsmStmt &S); 20940dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 20953d8400d9a61aa4b63ff35e5cede405b32a41425eAnders Carlsson void EmitObjCForCollectionStmt(const ObjCForCollectionStmt &S); 209664d5d6c5903157c521af496479d06dc26032d718Anders Carlsson void EmitObjCAtTryStmt(const ObjCAtTryStmt &S); 209764d5d6c5903157c521af496479d06dc26032d718Anders Carlsson void EmitObjCAtThrowStmt(const ObjCAtThrowStmt &S); 209810cac6f7115b59a466bb8d2d51cdddeb38aadc37Chris Lattner void EmitObjCAtSynchronizedStmt(const ObjCAtSynchronizedStmt &S); 2099f85e193739c953358c865005855253af4f68a497John McCall void EmitObjCAutoreleasePoolStmt(const ObjCAutoreleasePoolStmt &S); 21000dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 210193c332a8ba2c193c435b293966d343dab15f555bJohn McCall llvm::Constant *getUnwindResumeFn(); 210286a3a03667bdb0dcab7e6a2877dfd234b07a6d43Douglas Gregor llvm::Constant *getUnwindResumeOrRethrowFn(); 210359a7000a79118e4c140885ccbb2ac6a686a73092John McCall void EnterCXXTryStmt(const CXXTryStmt &S, bool IsFnTryBlock = false); 210459a7000a79118e4c140885ccbb2ac6a686a73092John McCall void ExitCXXTryStmt(const CXXTryStmt &S, bool IsFnTryBlock = false); 21059fc6a7774643a810c8501dae2323e863fefb623eJohn McCall 21066815e941998659a55c20c147861b0f437928c3d8Anders Carlsson void EmitCXXTryStmt(const CXXTryStmt &S); 2107ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith void EmitCXXForRangeStmt(const CXXForRangeStmt &S); 21089cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer 21095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 21105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // LValue Expression Emission 21115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 21125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 211313e81737a433b23f8c662d10d1d57356122a8caaDaniel Dunbar /// GetUndefRValue - Get an appropriate 'undef' rvalue for the given type. 211413e81737a433b23f8c662d10d1d57356122a8caaDaniel Dunbar RValue GetUndefRValue(QualType Ty); 211513e81737a433b23f8c662d10d1d57356122a8caaDaniel Dunbar 2116ce1d38b8163650e473d7084e0686ed5a7956057bDaniel Dunbar /// EmitUnsupportedRValue - Emit a dummy r-value using the type of E 2117ce1d38b8163650e473d7084e0686ed5a7956057bDaniel Dunbar /// and issue an ErrorUnsupported style diagnostic (using the 2118ce1d38b8163650e473d7084e0686ed5a7956057bDaniel Dunbar /// provided Name). 2119ce1d38b8163650e473d7084e0686ed5a7956057bDaniel Dunbar RValue EmitUnsupportedRValue(const Expr *E, 2120ce1d38b8163650e473d7084e0686ed5a7956057bDaniel Dunbar const char *Name); 2121ce1d38b8163650e473d7084e0686ed5a7956057bDaniel Dunbar 21220dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// EmitUnsupportedLValue - Emit a dummy l-value using the type of E and issue 21230dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// an ErrorUnsupported style diagnostic (using the provided Name). 21246ba82a4a4b295e54cf192c3e98b28f39990c6194Daniel Dunbar LValue EmitUnsupportedLValue(const Expr *E, 21256ba82a4a4b295e54cf192c3e98b28f39990c6194Daniel Dunbar const char *Name); 21266ba82a4a4b295e54cf192c3e98b28f39990c6194Daniel Dunbar 21275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// EmitLValue - Emit code to compute a designator that specifies the location 21285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// of the expression. 21295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 21305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// This can return one of two things: a simple address or a bitfield 21315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// reference. In either case, the LLVM Value* in the LValue structure is 21325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// guaranteed to be an LLVM pointer type. 21335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 21345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// If this returns a bitfield reference, nothing about the pointee type of 21355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// the LLVM value is known: For example, it may not be a pointer to an 21365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// integer. 21375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 21385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// If this returns a normal address, and if the lvalue's C type is fixed 21395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// size, this method guarantees that the returned pointer type will point to 21405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// an LLVM type of the same size of the lvalue's type. If the lvalue has a 21415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// variable length type, this is not possible. 21425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 21435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LValue EmitLValue(const Expr *E); 21440dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 21457ac9ef1c82c779a5348ed11b3d10e01c58803b35Richard Smith /// \brief Same as EmitLValue but additionally we generate checking code to 21467ac9ef1c82c779a5348ed11b3d10e01c58803b35Richard Smith /// guard against undefined behavior. This is only suitable when we know 21477ac9ef1c82c779a5348ed11b3d10e01c58803b35Richard Smith /// that the address will be used to access the object. 21487ac9ef1c82c779a5348ed11b3d10e01c58803b35Richard Smith LValue EmitCheckedLValue(const Expr *E, TypeCheckKind TCK); 2149b14e62d5aee7522b98c410ee65bd750c2cfe6f01Mike Stump 21509d232c884ea9872d6555df0fd7359699819bc1f1John McCall RValue convertTempToRValue(llvm::Value *addr, QualType type); 21519d232c884ea9872d6555df0fd7359699819bc1f1John McCall 215226815d97c5743481e317f17a8d53a6819d061862John McCall /// EmitToMemory - Change a scalar value from its value 215326815d97c5743481e317f17a8d53a6819d061862John McCall /// representation to its in-memory representation. 215426815d97c5743481e317f17a8d53a6819d061862John McCall llvm::Value *EmitToMemory(llvm::Value *Value, QualType Ty); 215526815d97c5743481e317f17a8d53a6819d061862John McCall 215626815d97c5743481e317f17a8d53a6819d061862John McCall /// EmitFromMemory - Change a scalar value from its memory 215726815d97c5743481e317f17a8d53a6819d061862John McCall /// representation to its value representation. 215826815d97c5743481e317f17a8d53a6819d061862John McCall llvm::Value *EmitFromMemory(llvm::Value *Value, QualType Ty); 215926815d97c5743481e317f17a8d53a6819d061862John McCall 21609d9cc874bcc168474757a8f90476684b4a93ed76Daniel Dunbar /// EmitLoadOfScalar - Load a scalar value from an address, taking 21619d9cc874bcc168474757a8f90476684b4a93ed76Daniel Dunbar /// care to appropriately convert from the memory representation to 21629d9cc874bcc168474757a8f90476684b4a93ed76Daniel Dunbar /// the LLVM value representation. 216309429b962811f2c0a7a81a1b0a89f96f5878b20cMike Stump llvm::Value *EmitLoadOfScalar(llvm::Value *Addr, bool Volatile, 21643d5aff5d3036b0ff09d114857cd2276134b3d8c9Dan Gohman unsigned Alignment, QualType Ty, 21653d5aff5d3036b0ff09d114857cd2276134b3d8c9Dan Gohman llvm::MDNode *TBAAInfo = 0); 2166545d996ec5a3113f046944f11b27cc2d6cb055b4John McCall 2167545d996ec5a3113f046944f11b27cc2d6cb055b4John McCall /// EmitLoadOfScalar - Load a scalar value from an address, taking 2168545d996ec5a3113f046944f11b27cc2d6cb055b4John McCall /// care to appropriately convert from the memory representation to 2169545d996ec5a3113f046944f11b27cc2d6cb055b4John McCall /// the LLVM value representation. The l-value must be a simple 2170545d996ec5a3113f046944f11b27cc2d6cb055b4John McCall /// l-value. 2171a07398ed98ea2b55ad7a505a3aab18aed93b149fJohn McCall llvm::Value *EmitLoadOfScalar(LValue lvalue); 21729d9cc874bcc168474757a8f90476684b4a93ed76Daniel Dunbar 21739d9cc874bcc168474757a8f90476684b4a93ed76Daniel Dunbar /// EmitStoreOfScalar - Store a scalar value to an address, taking 21749d9cc874bcc168474757a8f90476684b4a93ed76Daniel Dunbar /// care to appropriately convert from the memory representation to 21759d9cc874bcc168474757a8f90476684b4a93ed76Daniel Dunbar /// the LLVM value representation. 217609429b962811f2c0a7a81a1b0a89f96f5878b20cMike Stump void EmitStoreOfScalar(llvm::Value *Value, llvm::Value *Addr, 21773d5aff5d3036b0ff09d114857cd2276134b3d8c9Dan Gohman bool Volatile, unsigned Alignment, QualType Ty, 21787a7ee3033e44b45630981355460ef89efa0bdcc4David Chisnall llvm::MDNode *TBAAInfo = 0, bool isInit=false); 2179545d996ec5a3113f046944f11b27cc2d6cb055b4John McCall 2180545d996ec5a3113f046944f11b27cc2d6cb055b4John McCall /// EmitStoreOfScalar - Store a scalar value to an address, taking 2181545d996ec5a3113f046944f11b27cc2d6cb055b4John McCall /// care to appropriately convert from the memory representation to 2182545d996ec5a3113f046944f11b27cc2d6cb055b4John McCall /// the LLVM value representation. The l-value must be a simple 21837a7ee3033e44b45630981355460ef89efa0bdcc4David Chisnall /// l-value. The isInit flag indicates whether this is an initialization. 21847a7ee3033e44b45630981355460ef89efa0bdcc4David Chisnall /// If so, atomic qualifiers are ignored and the store is always non-atomic. 21857a7ee3033e44b45630981355460ef89efa0bdcc4David Chisnall void EmitStoreOfScalar(llvm::Value *value, LValue lvalue, bool isInit=false); 21869d9cc874bcc168474757a8f90476684b4a93ed76Daniel Dunbar 21875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// EmitLoadOfLValue - Given an expression that represents a value lvalue, 21885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// this method emits the address of the lvalue, then loads the result as an 21895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// rvalue, returning the rvalue. 2190545d996ec5a3113f046944f11b27cc2d6cb055b4John McCall RValue EmitLoadOfLValue(LValue V); 2191545d996ec5a3113f046944f11b27cc2d6cb055b4John McCall RValue EmitLoadOfExtVectorElementLValue(LValue V); 2192545d996ec5a3113f046944f11b27cc2d6cb055b4John McCall RValue EmitLoadOfBitfieldLValue(LValue LV); 21930dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 21945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// EmitStoreThroughLValue - Store the specified rvalue into the specified 21955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// lvalue, where both are guaranteed to the have the same type, and that type 21965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// is 'Ty'. 21977a7ee3033e44b45630981355460ef89efa0bdcc4David Chisnall void EmitStoreThroughLValue(RValue Src, LValue Dst, bool isInit=false); 2198545d996ec5a3113f046944f11b27cc2d6cb055b4John McCall void EmitStoreThroughExtVectorComponentLValue(RValue Src, LValue Dst); 2199ed3849b456d64d124bddc7ac044f3ce590bd9d69Daniel Dunbar 22000dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// EmitStoreThroughLValue - Store Src into Dst with same constraints as 22010dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// EmitStoreThroughLValue. 2202ed3849b456d64d124bddc7ac044f3ce590bd9d69Daniel Dunbar /// 22030dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// \param Result [out] - If non-null, this will be set to a Value* for the 22040dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// bit-field contents after the store, appropriate for use as the result of 22050dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// an assignment to the bit-field. 2206545d996ec5a3113f046944f11b27cc2d6cb055b4John McCall void EmitStoreThroughBitfieldLValue(RValue Src, LValue Dst, 2207ed3849b456d64d124bddc7ac044f3ce590bd9d69Daniel Dunbar llvm::Value **Result=0); 22080dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 220983ce9d4a552987d34cbd500e983db8d770232379John McCall /// Emit an l-value for an assignment (simple or compound) of complex type. 221083ce9d4a552987d34cbd500e983db8d770232379John McCall LValue EmitComplexAssignmentLValue(const BinaryOperator *E); 22112a41637a995affa1563f4d82a8b026e326a2faa0John McCall LValue EmitComplexCompoundAssignmentLValue(const CompoundAssignOperator *E); 221283ce9d4a552987d34cbd500e983db8d770232379John McCall 2213fc8f0e14ad142ed811e90fbd9a30e419e301c717Chris Lattner // Note: only available for agg return types 221480e62c29fe21cd06c93eba6e72b7e32dca06fcf9Daniel Dunbar LValue EmitBinaryOperatorLValue(const BinaryOperator *E); 22152a41637a995affa1563f4d82a8b026e326a2faa0John McCall LValue EmitCompoundAssignmentLValue(const CompoundAssignOperator *E); 22165b5c9ef865607e179413462dcd71bcebb5b7daaeDaniel Dunbar // Note: only available for agg return types 221722c940ee588a420cd2e6c8f68be2ac3cc80061ffChristopher Lamb LValue EmitCallExprLValue(const CallExpr *E); 22185b5c9ef865607e179413462dcd71bcebb5b7daaeDaniel Dunbar // Note: only available for agg return types 22195b5c9ef865607e179413462dcd71bcebb5b7daaeDaniel Dunbar LValue EmitVAArgExprLValue(const VAArgExpr *E); 22205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LValue EmitDeclRefLValue(const DeclRefExpr *E); 22215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LValue EmitStringLiteralLValue(const StringLiteral *E); 2222eaf2bb89eb2aad3b80673de30febe52df43c10ecChris Lattner LValue EmitObjCEncodeExprLValue(const ObjCEncodeExpr *E); 2223d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner LValue EmitPredefinedLValue(const PredefinedExpr *E); 22245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LValue EmitUnaryOpLValue(const UnaryOperator *E); 2225a0a628f839cf50844cc0f226bd9cb72485f98f91Richard Smith LValue EmitArraySubscriptExpr(const ArraySubscriptExpr *E, 2226a0a628f839cf50844cc0f226bd9cb72485f98f91Richard Smith bool Accessed = false); 2227213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman LValue EmitExtVectorElementExpr(const ExtVectorElementExpr *E); 2228b84a06e68ffd71da22e3c75b6e4bbdba37816413Devang Patel LValue EmitMemberExpr(const MemberExpr *E); 2229820bca41c3899374775d2a1dfc2ef2e22aaf1c7bFariborz Jahanian LValue EmitObjCIsaExpr(const ObjCIsaExpr *E); 223006e863f2902b8ba55b056308875c19f7ba3dab25Eli Friedman LValue EmitCompoundLiteralLValue(const CompoundLiteralExpr *E); 223113ec9100ca6bc03b5ce8832e4a0fcb724d47bcb1Richard Smith LValue EmitInitListLValue(const InitListExpr *E); 223256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall LValue EmitConditionalOperatorLValue(const AbstractConditionalOperator *E); 223375dfedaf702822c9e51a4f3c5d3ecf2d2ad99272Chris Lattner LValue EmitCastLValue(const CastExpr *E); 2234ed8abf18329df67b0abcbb3a10458bd8c1d2a595Douglas Gregor LValue EmitNullInitializationLValue(const CXXScalarValueInitExpr *E); 223503e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor LValue EmitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *E); 2236e996ffd240f20a1048179d7727a6ee3227261921John McCall LValue EmitOpaqueValueLValue(const OpaqueValueExpr *e); 22379cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer 2238377ecc7996dce6803f7b7b6208cab5e197c9c5b8Eli Friedman RValue EmitRValueForField(LValue LV, const FieldDecl *FD); 2239eaf856db5d1a272dc7188937206ef4572836f82aAnton Korobeynikov 2240dd2ecee313b558a9b621ec003b45e0fbc83508d7John McCall class ConstantEmission { 2241dd2ecee313b558a9b621ec003b45e0fbc83508d7John McCall llvm::PointerIntPair<llvm::Constant*, 1, bool> ValueAndIsReference; 2242dd2ecee313b558a9b621ec003b45e0fbc83508d7John McCall ConstantEmission(llvm::Constant *C, bool isReference) 2243dd2ecee313b558a9b621ec003b45e0fbc83508d7John McCall : ValueAndIsReference(C, isReference) {} 2244dd2ecee313b558a9b621ec003b45e0fbc83508d7John McCall public: 2245dd2ecee313b558a9b621ec003b45e0fbc83508d7John McCall ConstantEmission() {} 2246dd2ecee313b558a9b621ec003b45e0fbc83508d7John McCall static ConstantEmission forReference(llvm::Constant *C) { 2247dd2ecee313b558a9b621ec003b45e0fbc83508d7John McCall return ConstantEmission(C, true); 2248dd2ecee313b558a9b621ec003b45e0fbc83508d7John McCall } 2249dd2ecee313b558a9b621ec003b45e0fbc83508d7John McCall static ConstantEmission forValue(llvm::Constant *C) { 2250dd2ecee313b558a9b621ec003b45e0fbc83508d7John McCall return ConstantEmission(C, false); 2251dd2ecee313b558a9b621ec003b45e0fbc83508d7John McCall } 2252dd2ecee313b558a9b621ec003b45e0fbc83508d7John McCall 2253dd2ecee313b558a9b621ec003b45e0fbc83508d7John McCall operator bool() const { return ValueAndIsReference.getOpaqueValue() != 0; } 2254dd2ecee313b558a9b621ec003b45e0fbc83508d7John McCall 2255dd2ecee313b558a9b621ec003b45e0fbc83508d7John McCall bool isReference() const { return ValueAndIsReference.getInt(); } 2256dd2ecee313b558a9b621ec003b45e0fbc83508d7John McCall LValue getReferenceLValue(CodeGenFunction &CGF, Expr *refExpr) const { 2257dd2ecee313b558a9b621ec003b45e0fbc83508d7John McCall assert(isReference()); 2258dd2ecee313b558a9b621ec003b45e0fbc83508d7John McCall return CGF.MakeNaturalAlignAddrLValue(ValueAndIsReference.getPointer(), 2259dd2ecee313b558a9b621ec003b45e0fbc83508d7John McCall refExpr->getType()); 2260dd2ecee313b558a9b621ec003b45e0fbc83508d7John McCall } 2261dd2ecee313b558a9b621ec003b45e0fbc83508d7John McCall 2262dd2ecee313b558a9b621ec003b45e0fbc83508d7John McCall llvm::Constant *getValue() const { 2263dd2ecee313b558a9b621ec003b45e0fbc83508d7John McCall assert(!isReference()); 2264dd2ecee313b558a9b621ec003b45e0fbc83508d7John McCall return ValueAndIsReference.getPointer(); 2265dd2ecee313b558a9b621ec003b45e0fbc83508d7John McCall } 2266dd2ecee313b558a9b621ec003b45e0fbc83508d7John McCall }; 2267dd2ecee313b558a9b621ec003b45e0fbc83508d7John McCall 2268f4b88a45902af1802a1cb42ba48b1c474474f228John McCall ConstantEmission tryEmitAsConstant(DeclRefExpr *refExpr); 2269dd2ecee313b558a9b621ec003b45e0fbc83508d7John McCall 22704b9c2d235fb9449e249d74f48ecfec601650de93John McCall RValue EmitPseudoObjectRValue(const PseudoObjectExpr *e, 22714b9c2d235fb9449e249d74f48ecfec601650de93John McCall AggValueSlot slot = AggValueSlot::ignored()); 22724b9c2d235fb9449e249d74f48ecfec601650de93John McCall LValue EmitPseudoObjectLValue(const PseudoObjectExpr *e); 22734b9c2d235fb9449e249d74f48ecfec601650de93John McCall 22742a03192a02dbf4fdff438d1e658356bde871aba4Daniel Dunbar llvm::Value *EmitIvarOffset(const ObjCInterfaceDecl *Interface, 227529e0bccf2bcce22b877f8b2ed173f564c116b97eDaniel Dunbar const ObjCIvarDecl *Ivar); 2276377ecc7996dce6803f7b7b6208cab5e197c9c5b8Eli Friedman LValue EmitLValueForField(LValue Base, const FieldDecl* Field); 22779cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer 227806a2970e9480c6d02b367b2f970baff29b9f9721Anders Carlsson /// EmitLValueForFieldInitialization - Like EmitLValueForField, except that 227906a2970e9480c6d02b367b2f970baff29b9f9721Anders Carlsson /// if the Field is a reference, this will return the address of the reference 228006a2970e9480c6d02b367b2f970baff29b9f9721Anders Carlsson /// and not the address of the value stored in the reference. 2281377ecc7996dce6803f7b7b6208cab5e197c9c5b8Eli Friedman LValue EmitLValueForFieldInitialization(LValue Base, 2282377ecc7996dce6803f7b7b6208cab5e197c9c5b8Eli Friedman const FieldDecl* Field); 22839cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer 228445012a7ef5abf1042c893f3f2fa5c23cb5485ea9Fariborz Jahanian LValue EmitLValueForIvar(QualType ObjectTy, 228545012a7ef5abf1042c893f3f2fa5c23cb5485ea9Fariborz Jahanian llvm::Value* Base, const ObjCIvarDecl *Ivar, 228629e0bccf2bcce22b877f8b2ed173f564c116b97eDaniel Dunbar unsigned CVRQualifiers); 2287fd64bb635dc221baa19f81d5d2a084f7eb269f7fFariborz Jahanian 2288b58d017f2b9eeed33f2ab3ede968b89cf5296bf2Anders Carlsson LValue EmitCXXConstructLValue(const CXXConstructExpr *E); 2289e61c9e80a108b5db7e5f0e702f0e455d737c6390Anders Carlsson LValue EmitCXXBindTemporaryLValue(const CXXBindTemporaryExpr *E); 229031a3702618ab49578542cffee20ba0c8859b9d1eEli Friedman LValue EmitLambdaLValue(const LambdaExpr *E); 2291c2e84ae9a6d25cea3e583c768e576b4c981ec028Mike Stump LValue EmitCXXTypeidLValue(const CXXTypeidExpr *E); 2292c5f804636e367ef744fd24cf88f7c956a5af0434Nico Weber LValue EmitCXXUuidofLValue(const CXXUuidofExpr *E); 22939cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer 22940a04d77bde7e3a661c2b41b60630d125d09ed6efDaniel Dunbar LValue EmitObjCMessageExprLValue(const ObjCMessageExpr *E); 2295391d77a26382dddf25da73e29fc1fa5aaaea4c6fChris Lattner LValue EmitObjCIvarRefLValue(const ObjCIvarRefExpr *E); 2296654599454c8e6cc83b1b9b3af43c49c2f66a26cbChris Lattner LValue EmitStmtExprLValue(const StmtExpr *E); 22978bfd31f9dad09cd52225d868bbd92a9bebe87775Fariborz Jahanian LValue EmitPointerToDataMemberBinaryExpr(const BinaryOperator *E); 229803b2960c14aede6ac82bdef32247094ebb72fa69Fariborz Jahanian LValue EmitObjCSelectorLValue(const ObjCSelectorExpr *E); 2299189d6ef40eff11b83b2cda941d5ed89a5cef09b2John McCall void EmitDeclRefExprDbgValue(const DeclRefExpr *E, llvm::Constant *Init); 230056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 23015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 2302883f6a7cc7dccb1d675e27121a82614d63492a8dChris Lattner // Scalar Expression Emission 23035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 23045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 23050dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// EmitCall - Generate a call of the given function, expecting the given 23060dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// result type, and using the given argument list which specifies both the 23070dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// LLVM arguments and the types they were derived from. 2308c0ef9f59937c3971c48b6fed37cf5bd8985c024bDaniel Dunbar /// 2309f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump /// \param TargetDecl - If given, the decl of the function in a direct call; 2310f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump /// used to set attributes on the call (noreturn, etc.). 231188b5396b0897f28d22ae3debf4a0d97b33b6c362Daniel Dunbar RValue EmitCall(const CGFunctionInfo &FnInfo, 231288b5396b0897f28d22ae3debf4a0d97b33b6c362Daniel Dunbar llvm::Value *Callee, 2313f3c47c9525153aea2de0ec4bd615b9cf2d81c103Anders Carlsson ReturnValueSlot ReturnValue, 2314c0ef9f59937c3971c48b6fed37cf5bd8985c024bDaniel Dunbar const CallArgList &Args, 2315dd5c98f709837e5dd3da08d44d1ce407975df2cfDavid Chisnall const Decl *TargetDecl = 0, 23164b02afcb45cd1a384de7d45f440a8be091dd500bDavid Chisnall llvm::Instruction **callOrInvoke = 0); 23171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 231831777a2540879051a3c643b90e02c3fd3d315243Anders Carlsson RValue EmitCall(QualType FnType, llvm::Value *Callee, 2319d2490a91341b57df7a7e54f8a707e7ecde2eeb4eAnders Carlsson ReturnValueSlot ReturnValue, 2320986477149db76e6d9f8d3c9859c9880c11b680aeAnders Carlsson CallExpr::const_arg_iterator ArgBeg, 2321986477149db76e6d9f8d3c9859c9880c11b680aeAnders Carlsson CallExpr::const_arg_iterator ArgEnd, 2322986477149db76e6d9f8d3c9859c9880c11b680aeAnders Carlsson const Decl *TargetDecl = 0); 23239cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer RValue EmitCallExpr(const CallExpr *E, 2324d2490a91341b57df7a7e54f8a707e7ecde2eeb4eAnders Carlsson ReturnValueSlot ReturnValue = ReturnValueSlot()); 23251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2326bd7370a78604e9a20d698bfe328c1e43f12a0613John McCall llvm::CallInst *EmitRuntimeCall(llvm::Value *callee, 2327bd7370a78604e9a20d698bfe328c1e43f12a0613John McCall const Twine &name = ""); 2328bd7370a78604e9a20d698bfe328c1e43f12a0613John McCall llvm::CallInst *EmitRuntimeCall(llvm::Value *callee, 2329bd7370a78604e9a20d698bfe328c1e43f12a0613John McCall ArrayRef<llvm::Value*> args, 2330bd7370a78604e9a20d698bfe328c1e43f12a0613John McCall const Twine &name = ""); 2331bd7370a78604e9a20d698bfe328c1e43f12a0613John McCall llvm::CallInst *EmitNounwindRuntimeCall(llvm::Value *callee, 2332bd7370a78604e9a20d698bfe328c1e43f12a0613John McCall const Twine &name = ""); 2333bd7370a78604e9a20d698bfe328c1e43f12a0613John McCall llvm::CallInst *EmitNounwindRuntimeCall(llvm::Value *callee, 2334bd7370a78604e9a20d698bfe328c1e43f12a0613John McCall ArrayRef<llvm::Value*> args, 2335bd7370a78604e9a20d698bfe328c1e43f12a0613John McCall const Twine &name = ""); 2336bd7370a78604e9a20d698bfe328c1e43f12a0613John McCall 2337f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall llvm::CallSite EmitCallOrInvoke(llvm::Value *Callee, 23382d3ba4f5a923a90c3fc290ddfba5e36c2d0a9b46Chris Lattner ArrayRef<llvm::Value *> Args, 23398cc488fefb2fb04bc8d5398da29f0182f97934cfChris Lattner const Twine &Name = ""); 23404c7d9f1507d0f102bd4133bba63348636facd469Jay Foad llvm::CallSite EmitCallOrInvoke(llvm::Value *Callee, 23418cc488fefb2fb04bc8d5398da29f0182f97934cfChris Lattner const Twine &Name = ""); 2342bd7370a78604e9a20d698bfe328c1e43f12a0613John McCall llvm::CallSite EmitRuntimeCallOrInvoke(llvm::Value *callee, 2343bd7370a78604e9a20d698bfe328c1e43f12a0613John McCall ArrayRef<llvm::Value*> args, 2344bd7370a78604e9a20d698bfe328c1e43f12a0613John McCall const Twine &name = ""); 2345bd7370a78604e9a20d698bfe328c1e43f12a0613John McCall llvm::CallSite EmitRuntimeCallOrInvoke(llvm::Value *callee, 2346bd7370a78604e9a20d698bfe328c1e43f12a0613John McCall const Twine &name = ""); 2347bd7370a78604e9a20d698bfe328c1e43f12a0613John McCall void EmitNoreturnRuntimeCallOrInvoke(llvm::Value *callee, 2348bd7370a78604e9a20d698bfe328c1e43f12a0613John McCall ArrayRef<llvm::Value*> args); 2349f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 2350566abee1e9828a7700b51e4d17ea08234fde3bb4Anders Carlsson llvm::Value *BuildVirtualCall(const CXXMethodDecl *MD, llvm::Value *This, 23512acc6e3feda5e4f7d9009bdcf8b1cd777fecfe2dChris Lattner llvm::Type *Ty); 23529cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer llvm::Value *BuildVirtualCall(const CXXDestructorDecl *DD, CXXDtorType Type, 23532acc6e3feda5e4f7d9009bdcf8b1cd777fecfe2dChris Lattner llvm::Value *This, llvm::Type *Ty); 23542726267f094a0c1f5ac5b501ec5a9898c58876bfFariborz Jahanian llvm::Value *BuildAppleKextVirtualCall(const CXXMethodDecl *MD, 23552726267f094a0c1f5ac5b501ec5a9898c58876bfFariborz Jahanian NestedNameSpecifier *Qual, 23562acc6e3feda5e4f7d9009bdcf8b1cd777fecfe2dChris Lattner llvm::Type *Ty); 2357ccd5259d33cbbdd6f5fbf7ccab4cb4a2702309eaFariborz Jahanian 2358ccd5259d33cbbdd6f5fbf7ccab4cb4a2702309eaFariborz Jahanian llvm::Value *BuildAppleKextVirtualDestructorCall(const CXXDestructorDecl *DD, 2359ccd5259d33cbbdd6f5fbf7ccab4cb4a2702309eaFariborz Jahanian CXXDtorType Type, 2360771c678c04f5f685b4f188ec6c2fd88ad0f7457fFariborz Jahanian const CXXRecordDecl *RD); 2361566abee1e9828a7700b51e4d17ea08234fde3bb4Anders Carlsson 2362b9de2c55b2a33776e2bee8ee57df7599b374c8a5Anders Carlsson RValue EmitCXXMemberCall(const CXXMethodDecl *MD, 23634def70d3040e73707c738f7c366737a986135edfRichard Smith SourceLocation CallLoc, 2364b9de2c55b2a33776e2bee8ee57df7599b374c8a5Anders Carlsson llvm::Value *Callee, 2365a1736c0c750d4514a5d8fda36670addf1e4de54aAnders Carlsson ReturnValueSlot ReturnValue, 2366b9de2c55b2a33776e2bee8ee57df7599b374c8a5Anders Carlsson llvm::Value *This, 236759660c21178b6af518bd4b564e032d5c9cc218cbTimur Iskhodzhanov llvm::Value *ImplicitParam, 236859660c21178b6af518bd4b564e032d5c9cc218cbTimur Iskhodzhanov QualType ImplicitParamTy, 2369b9de2c55b2a33776e2bee8ee57df7599b374c8a5Anders Carlsson CallExpr::const_arg_iterator ArgBeg, 2370b9de2c55b2a33776e2bee8ee57df7599b374c8a5Anders Carlsson CallExpr::const_arg_iterator ArgEnd); 2371a1736c0c750d4514a5d8fda36670addf1e4de54aAnders Carlsson RValue EmitCXXMemberCallExpr(const CXXMemberCallExpr *E, 2372a1736c0c750d4514a5d8fda36670addf1e4de54aAnders Carlsson ReturnValueSlot ReturnValue); 2373a1736c0c750d4514a5d8fda36670addf1e4de54aAnders Carlsson RValue EmitCXXMemberPointerCallExpr(const CXXMemberCallExpr *E, 2374a1736c0c750d4514a5d8fda36670addf1e4de54aAnders Carlsson ReturnValueSlot ReturnValue); 23755549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek 2376a2447e0d1e28669cd637204a871f15b1215277fdAnders Carlsson llvm::Value *EmitCXXOperatorMemberCallee(const CXXOperatorCallExpr *E, 2377a2447e0d1e28669cd637204a871f15b1215277fdAnders Carlsson const CXXMethodDecl *MD, 2378a2447e0d1e28669cd637204a871f15b1215277fdAnders Carlsson llvm::Value *This); 23790f294632f36459174199b77699e339715244b5abAnders Carlsson RValue EmitCXXOperatorMemberCallExpr(const CXXOperatorCallExpr *E, 2380a1736c0c750d4514a5d8fda36670addf1e4de54aAnders Carlsson const CXXMethodDecl *MD, 2381a1736c0c750d4514a5d8fda36670addf1e4de54aAnders Carlsson ReturnValueSlot ReturnValue); 23821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 23836c0aa5ff6e6253db0f993053599e2a52b5b93b2dPeter Collingbourne RValue EmitCUDAKernelCallExpr(const CUDAKernelCallExpr *E, 23846c0aa5ff6e6253db0f993053599e2a52b5b93b2dPeter Collingbourne ReturnValueSlot ReturnValue); 23856c0aa5ff6e6253db0f993053599e2a52b5b93b2dPeter Collingbourne 23869cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer 23871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump RValue EmitBuiltinExpr(const FunctionDecl *FD, 2388ef2abfee3ea16ec74942dc09e9e425f46aeb2582Daniel Dunbar unsigned BuiltinID, const CallExpr *E); 23895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2390a1736c0c750d4514a5d8fda36670addf1e4de54aAnders Carlsson RValue EmitBlockCallExpr(const CallExpr *E, ReturnValueSlot ReturnValue); 239109429b962811f2c0a7a81a1b0a89f96f5878b20cMike Stump 23920dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// EmitTargetBuiltinExpr - Emit the given builtin call. Returns 0 if the call 23930dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// is unhandled by the current target. 2394f02e9ddf5efc75917af712b3c7f909581205f0a5Daniel Dunbar llvm::Value *EmitTargetBuiltinExpr(unsigned BuiltinID, const CallExpr *E); 2395f02e9ddf5efc75917af712b3c7f909581205f0a5Daniel Dunbar 23962752c0137d95aa2f4ee1cdff4b564bac842e041bChris Lattner llvm::Value *EmitARMBuiltinExpr(unsigned BuiltinID, const CallExpr *E); 23979cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer llvm::Value *EmitNeonCall(llvm::Function *F, 2398686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVectorImpl<llvm::Value*> &O, 2399db3d4d036037f379f12643e067b229862d61e932Bob Wilson const char *name, 240061eecf5aea018ea65c9ab0bccacd2996b15c632dNate Begeman unsigned shift = 0, bool rightshift = false); 2401cf55652cf668c1402eee0b12edd2e5a1bc34d7a1Bob Wilson llvm::Value *EmitNeonSplat(llvm::Value *V, llvm::Constant *Idx); 24022acc6e3feda5e4f7d9009bdcf8b1cd777fecfe2dChris Lattner llvm::Value *EmitNeonShiftVector(llvm::Value *V, llvm::Type *Ty, 240361eecf5aea018ea65c9ab0bccacd2996b15c632dNate Begeman bool negateForRightShift); 24049cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer 2405795b10062c2eaffae9e04241fb1a73cdbcb24a37Bill Wendling llvm::Value *BuildVector(ArrayRef<llvm::Value*> Ops); 2406564f1de67d7ba43646b8740db86d6269e3dfbe0bAnders Carlsson llvm::Value *EmitX86BuiltinExpr(unsigned BuiltinID, const CallExpr *E); 2407564f1de67d7ba43646b8740db86d6269e3dfbe0bAnders Carlsson llvm::Value *EmitPPCBuiltinExpr(unsigned BuiltinID, const CallExpr *E); 24080dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 2409ed7c618f849e2541b1d0288c43154937652c5b15Daniel Dunbar llvm::Value *EmitObjCProtocolExpr(const ObjCProtocolExpr *E); 24107f02f721d48772e4eee4fccd8af4f800be1bbc1eChris Lattner llvm::Value *EmitObjCStringLiteral(const ObjCStringLiteral *E); 2411eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard llvm::Value *EmitObjCBoxedExpr(const ObjCBoxedExpr *E); 2412ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek llvm::Value *EmitObjCArrayLiteral(const ObjCArrayLiteral *E); 2413ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek llvm::Value *EmitObjCDictionaryLiteral(const ObjCDictionaryLiteral *E); 2414ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek llvm::Value *EmitObjCCollectionLiteral(const Expr *E, 2415ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek const ObjCMethodDecl *MethodWithObjects); 24168fdf32822be2238aa7db62d40e75b168b637ab7dChris Lattner llvm::Value *EmitObjCSelectorExpr(const ObjCSelectorExpr *E); 2417ef072fd2f3347cfd857d6eb787b245b950771430John McCall RValue EmitObjCMessageExpr(const ObjCMessageExpr *E, 2418ef072fd2f3347cfd857d6eb787b245b950771430John McCall ReturnValueSlot Return = ReturnValueSlot()); 24198fdf32822be2238aa7db62d40e75b168b637ab7dChris Lattner 2420f85e193739c953358c865005855253af4f68a497John McCall /// Retrieves the default cleanup kind for an ARC cleanup. 2421f85e193739c953358c865005855253af4f68a497John McCall /// Except under -fobjc-arc-eh, ARC cleanups are normal-only. 2422f85e193739c953358c865005855253af4f68a497John McCall CleanupKind getARCCleanupKind() { 2423f85e193739c953358c865005855253af4f68a497John McCall return CGM.getCodeGenOpts().ObjCAutoRefCountExceptions 2424f85e193739c953358c865005855253af4f68a497John McCall ? NormalAndEHCleanup : NormalCleanup; 2425f85e193739c953358c865005855253af4f68a497John McCall } 2426f85e193739c953358c865005855253af4f68a497John McCall 2427f85e193739c953358c865005855253af4f68a497John McCall // ARC primitives. 2428f85e193739c953358c865005855253af4f68a497John McCall void EmitARCInitWeak(llvm::Value *value, llvm::Value *addr); 2429f85e193739c953358c865005855253af4f68a497John McCall void EmitARCDestroyWeak(llvm::Value *addr); 2430f85e193739c953358c865005855253af4f68a497John McCall llvm::Value *EmitARCLoadWeak(llvm::Value *addr); 2431f85e193739c953358c865005855253af4f68a497John McCall llvm::Value *EmitARCLoadWeakRetained(llvm::Value *addr); 2432f85e193739c953358c865005855253af4f68a497John McCall llvm::Value *EmitARCStoreWeak(llvm::Value *value, llvm::Value *addr, 2433f85e193739c953358c865005855253af4f68a497John McCall bool ignored); 2434f85e193739c953358c865005855253af4f68a497John McCall void EmitARCCopyWeak(llvm::Value *dst, llvm::Value *src); 2435f85e193739c953358c865005855253af4f68a497John McCall void EmitARCMoveWeak(llvm::Value *dst, llvm::Value *src); 2436f85e193739c953358c865005855253af4f68a497John McCall llvm::Value *EmitARCRetainAutorelease(QualType type, llvm::Value *value); 2437f85e193739c953358c865005855253af4f68a497John McCall llvm::Value *EmitARCRetainAutoreleaseNonBlock(llvm::Value *value); 2438545d996ec5a3113f046944f11b27cc2d6cb055b4John McCall llvm::Value *EmitARCStoreStrong(LValue lvalue, llvm::Value *value, 2439545d996ec5a3113f046944f11b27cc2d6cb055b4John McCall bool ignored); 2440f85e193739c953358c865005855253af4f68a497John McCall llvm::Value *EmitARCStoreStrongCall(llvm::Value *addr, llvm::Value *value, 2441f85e193739c953358c865005855253af4f68a497John McCall bool ignored); 2442f85e193739c953358c865005855253af4f68a497John McCall llvm::Value *EmitARCRetain(QualType type, llvm::Value *value); 2443f85e193739c953358c865005855253af4f68a497John McCall llvm::Value *EmitARCRetainNonBlock(llvm::Value *value); 2444348f16fc7c71f0d9b651cb79fd1012843073493fJohn McCall llvm::Value *EmitARCRetainBlock(llvm::Value *value, bool mandatory); 2445015f33b6741ffceba3a71ee2d71d46418a7dc34cJohn McCall void EmitARCDestroyStrong(llvm::Value *addr, bool precise); 2446f85e193739c953358c865005855253af4f68a497John McCall void EmitARCRelease(llvm::Value *value, bool precise); 2447f85e193739c953358c865005855253af4f68a497John McCall llvm::Value *EmitARCAutorelease(llvm::Value *value); 2448f85e193739c953358c865005855253af4f68a497John McCall llvm::Value *EmitARCAutoreleaseReturnValue(llvm::Value *value); 2449f85e193739c953358c865005855253af4f68a497John McCall llvm::Value *EmitARCRetainAutoreleaseReturnValue(llvm::Value *value); 2450f85e193739c953358c865005855253af4f68a497John McCall llvm::Value *EmitARCRetainAutoreleasedReturnValue(llvm::Value *value); 2451f85e193739c953358c865005855253af4f68a497John McCall 2452f85e193739c953358c865005855253af4f68a497John McCall std::pair<LValue,llvm::Value*> 2453f85e193739c953358c865005855253af4f68a497John McCall EmitARCStoreAutoreleasing(const BinaryOperator *e); 2454f85e193739c953358c865005855253af4f68a497John McCall std::pair<LValue,llvm::Value*> 2455f85e193739c953358c865005855253af4f68a497John McCall EmitARCStoreStrong(const BinaryOperator *e, bool ignored); 2456f85e193739c953358c865005855253af4f68a497John McCall 24572b014d6c0c6b8ac94b416ac37dfc7931f20777a7John McCall llvm::Value *EmitObjCThrowOperand(const Expr *expr); 24582b014d6c0c6b8ac94b416ac37dfc7931f20777a7John McCall 2459f85e193739c953358c865005855253af4f68a497John McCall llvm::Value *EmitObjCProduceObject(QualType T, llvm::Value *Ptr); 2460f85e193739c953358c865005855253af4f68a497John McCall llvm::Value *EmitObjCConsumeObject(QualType T, llvm::Value *Ptr); 2461f85e193739c953358c865005855253af4f68a497John McCall llvm::Value *EmitObjCExtendObjectLifetime(QualType T, llvm::Value *Ptr); 2462f85e193739c953358c865005855253af4f68a497John McCall 2463348f16fc7c71f0d9b651cb79fd1012843073493fJohn McCall llvm::Value *EmitARCExtendBlockObject(const Expr *expr); 2464f85e193739c953358c865005855253af4f68a497John McCall llvm::Value *EmitARCRetainScalarExpr(const Expr *expr); 2465f85e193739c953358c865005855253af4f68a497John McCall llvm::Value *EmitARCRetainAutoreleaseScalarExpr(const Expr *expr); 2466f85e193739c953358c865005855253af4f68a497John McCall 2467bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall static Destroyer destroyARCStrongImprecise; 2468bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall static Destroyer destroyARCStrongPrecise; 2469bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall static Destroyer destroyARCWeak; 2470bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall 2471f85e193739c953358c865005855253af4f68a497John McCall void EmitObjCAutoreleasePoolPop(llvm::Value *Ptr); 2472f85e193739c953358c865005855253af4f68a497John McCall llvm::Value *EmitObjCAutoreleasePoolPush(); 2473f85e193739c953358c865005855253af4f68a497John McCall llvm::Value *EmitObjCMRRAutoreleasePoolPush(); 2474f85e193739c953358c865005855253af4f68a497John McCall void EmitObjCAutoreleasePoolCleanup(llvm::Value *Ptr); 2475f85e193739c953358c865005855253af4f68a497John McCall void EmitObjCMRRAutoreleasePoolPop(llvm::Value *Ptr); 2476f85e193739c953358c865005855253af4f68a497John McCall 24774029ca7ae9d3ffd7738fe2ed8782bebc30f36fd6Anders Carlsson /// EmitReferenceBindingToExpr - Emits a reference binding to the passed in 24784029ca7ae9d3ffd7738fe2ed8782bebc30f36fd6Anders Carlsson /// expression. Will emit a temporary variable if E is not an LValue. 24799cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer RValue EmitReferenceBindingToExpr(const Expr* E, 248032f36baa6c8d491c374af622b4e3ac28d597453cAnders Carlsson const NamedDecl *InitializedDecl); 24813aba09376c5f49c4c8d176109ea4835bc2c528eeAnders Carlsson 2482883f6a7cc7dccb1d675e27121a82614d63492a8dChris Lattner //===--------------------------------------------------------------------===// 2483bfc0c1ae4b505b52b36f572a9641f99e76879cabChris Lattner // Expression Emission 2484883f6a7cc7dccb1d675e27121a82614d63492a8dChris Lattner //===--------------------------------------------------------------------===// 2485bfc0c1ae4b505b52b36f572a9641f99e76879cabChris Lattner 2486bfc0c1ae4b505b52b36f572a9641f99e76879cabChris Lattner // Expressions are broken into three classes: scalar, complex, aggregate. 24870dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 24880dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// EmitScalarExpr - Emit the computation of the specified expression of LLVM 24890dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// scalar type, returning the result. 249014c5cbf59cffee52275230922283a247de407712Anders Carlsson llvm::Value *EmitScalarExpr(const Expr *E , bool IgnoreResultAssign = false); 24910dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 24923707b255f8993fb362904c9cff87b0e9bc6ca317Chris Lattner /// EmitScalarConversion - Emit a conversion from the specified type to the 24933707b255f8993fb362904c9cff87b0e9bc6ca317Chris Lattner /// specified destination type, both of which are LLVM scalar types. 24943707b255f8993fb362904c9cff87b0e9bc6ca317Chris Lattner llvm::Value *EmitScalarConversion(llvm::Value *Src, QualType SrcTy, 24953707b255f8993fb362904c9cff87b0e9bc6ca317Chris Lattner QualType DstTy); 24960dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 24974f1a7b380809b4ca19ad2daff61bc11cd1e979d8Chris Lattner /// EmitComplexToScalarConversion - Emit a conversion from the specified 24980dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// complex type to the specified destination type, where the destination type 24990dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// is an LLVM scalar type. 25004f1a7b380809b4ca19ad2daff61bc11cd1e979d8Chris Lattner llvm::Value *EmitComplexToScalarConversion(ComplexPairTy Src, QualType SrcTy, 25014f1a7b380809b4ca19ad2daff61bc11cd1e979d8Chris Lattner QualType DstTy); 25020dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 25030dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 2504558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall /// EmitAggExpr - Emit the computation of the specified expression 2505558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall /// of aggregate type. The result is computed into the given slot, 2506558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall /// which may be null to indicate that the value is not needed. 2507e0c1168ec7910a1a7ed08df4d4f0c58c2fa2ecd1John McCall void EmitAggExpr(const Expr *E, AggValueSlot AS); 25080dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 250918aba0dd518e486d8b50523e7dafb4b5657135d2Daniel Dunbar /// EmitAggExprToLValue - Emit the computation of the specified expression of 251018aba0dd518e486d8b50523e7dafb4b5657135d2Daniel Dunbar /// aggregate type into a temporary LValue. 251118aba0dd518e486d8b50523e7dafb4b5657135d2Daniel Dunbar LValue EmitAggExprToLValue(const Expr *E); 251218aba0dd518e486d8b50523e7dafb4b5657135d2Daniel Dunbar 2513082b02e8403d3ee9d2ded969fbe0e5d472f04cd8Fariborz Jahanian /// EmitGCMemmoveCollectable - Emit special API for structs with object 2514082b02e8403d3ee9d2ded969fbe0e5d472f04cd8Fariborz Jahanian /// pointers. 2515082b02e8403d3ee9d2ded969fbe0e5d472f04cd8Fariborz Jahanian void EmitGCMemmoveCollectable(llvm::Value *DestPtr, llvm::Value *SrcPtr, 251608c321380fff07d476a19daab6d29522c046cd49Fariborz Jahanian QualType Ty); 2517082b02e8403d3ee9d2ded969fbe0e5d472f04cd8Fariborz Jahanian 25180c24c808e4dce43e88abf2d5f98546b901bd4315John McCall /// EmitExtendGCLifetime - Given a pointer to an Objective-C object, 25190c24c808e4dce43e88abf2d5f98546b901bd4315John McCall /// make sure it survives garbage collection until this point. 25200c24c808e4dce43e88abf2d5f98546b901bd4315John McCall void EmitExtendGCLifetime(llvm::Value *object); 25210c24c808e4dce43e88abf2d5f98546b901bd4315John McCall 2522b6ef18a2b06d6760459e1756a61f79ff496cee19Chris Lattner /// EmitComplexExpr - Emit the computation of the specified expression of 252323b1cdb0b5e089468bb8475b8ec9287af67b4b59Chris Lattner /// complex type, returning the result. 2524b418d74c11498b7e1044103131e2e3be4d63512eJohn McCall ComplexPairTy EmitComplexExpr(const Expr *E, 2525b418d74c11498b7e1044103131e2e3be4d63512eJohn McCall bool IgnoreReal = false, 2526b418d74c11498b7e1044103131e2e3be4d63512eJohn McCall bool IgnoreImag = false); 25270dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 25289d232c884ea9872d6555df0fd7359699819bc1f1John McCall /// EmitComplexExprIntoLValue - Emit the given expression of complex 25299d232c884ea9872d6555df0fd7359699819bc1f1John McCall /// type and place its result into the specified l-value. 25309d232c884ea9872d6555df0fd7359699819bc1f1John McCall void EmitComplexExprIntoLValue(const Expr *E, LValue dest, bool isInit); 25319d232c884ea9872d6555df0fd7359699819bc1f1John McCall 25329d232c884ea9872d6555df0fd7359699819bc1f1John McCall /// EmitStoreOfComplex - Store a complex number into the specified l-value. 25339d232c884ea9872d6555df0fd7359699819bc1f1John McCall void EmitStoreOfComplex(ComplexPairTy V, LValue dest, bool isInit); 25347f8ea5c5b3a6a4332a841eefdd86b0726722ea7bDaniel Dunbar 25359d232c884ea9872d6555df0fd7359699819bc1f1John McCall /// EmitLoadOfComplex - Load a complex number from the specified l-value. 25369d232c884ea9872d6555df0fd7359699819bc1f1John McCall ComplexPairTy EmitLoadOfComplex(LValue src); 25372621fd1d6d3c5eadcae246859f62738645df7540Chris Lattner 2538b6bbcc9995186799a60ce17d0c1acff31601653aJohn McCall /// CreateStaticVarDecl - Create a zero-initialized LLVM global for 2539b6bbcc9995186799a60ce17d0c1acff31601653aJohn McCall /// a static local variable. 25400f30a12ce7b3d4d86c9ca9072f587da77c8eef34Chandler Carruth llvm::GlobalVariable *CreateStaticVarDecl(const VarDecl &D, 25410f30a12ce7b3d4d86c9ca9072f587da77c8eef34Chandler Carruth const char *Separator, 25420f30a12ce7b3d4d86c9ca9072f587da77c8eef34Chandler Carruth llvm::GlobalValue::LinkageTypes Linkage); 25439cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer 25440f30a12ce7b3d4d86c9ca9072f587da77c8eef34Chandler Carruth /// AddInitializerToStaticVarDecl - Add the initializer for 'D' to the 25450f30a12ce7b3d4d86c9ca9072f587da77c8eef34Chandler Carruth /// global variable that has already been created for it. If the initializer 25460f30a12ce7b3d4d86c9ca9072f587da77c8eef34Chandler Carruth /// has a different type than GV does, this may free GV and return a different 25470f30a12ce7b3d4d86c9ca9072f587da77c8eef34Chandler Carruth /// one. Otherwise it just returns GV. 25480f30a12ce7b3d4d86c9ca9072f587da77c8eef34Chandler Carruth llvm::GlobalVariable * 25490f30a12ce7b3d4d86c9ca9072f587da77c8eef34Chandler Carruth AddInitializerToStaticVarDecl(const VarDecl &D, 25500f30a12ce7b3d4d86c9ca9072f587da77c8eef34Chandler Carruth llvm::GlobalVariable *GV); 25519cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer 25520096acf421c4609ce7f43e8b05f8c5ca866d4611Daniel Dunbar 25533b2e16b3d25f6b311dba2871e2a566c96238c3d2Anders Carlsson /// EmitCXXGlobalVarDeclInit - Create the initializer for a C++ 25543b2e16b3d25f6b311dba2871e2a566c96238c3d2Anders Carlsson /// variable with global storage. 25557ca4850a3e3530fa6c93b64b740446e32c97f992Richard Smith void EmitCXXGlobalVarDeclInit(const VarDecl &D, llvm::Constant *DeclPtr, 25567ca4850a3e3530fa6c93b64b740446e32c97f992Richard Smith bool PerformInit); 25573b2e16b3d25f6b311dba2871e2a566c96238c3d2Anders Carlsson 255820bb175cb8ae5844034828db094fb948c0e3454aJohn McCall /// Call atexit() with a function that passes the given argument to 255920bb175cb8ae5844034828db094fb948c0e3454aJohn McCall /// the given function. 256020bb175cb8ae5844034828db094fb948c0e3454aJohn McCall void registerGlobalDtorWithAtExit(llvm::Constant *fn, llvm::Constant *addr); 25611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 25623030eb82593097502469a8b3fc26112c79c75605John McCall /// Emit code in this function to perform a guarded variable 25633030eb82593097502469a8b3fc26112c79c75605John McCall /// initialization. Guarded initializations are used when it's not 25643030eb82593097502469a8b3fc26112c79c75605John McCall /// possible to prove that an initialization will be done exactly 25653030eb82593097502469a8b3fc26112c79c75605John McCall /// once, e.g. with a static local variable or a static data member 25663030eb82593097502469a8b3fc26112c79c75605John McCall /// of a class template. 25670f30a12ce7b3d4d86c9ca9072f587da77c8eef34Chandler Carruth void EmitCXXGuardedInit(const VarDecl &D, llvm::GlobalVariable *DeclPtr, 25687ca4850a3e3530fa6c93b64b740446e32c97f992Richard Smith bool PerformInit); 25695cd91b513455fd7753e8815b54f0a49bbca6602dJohn McCall 2570efb0fa9e11f75af51744a6159530ef7cc8efa24aDaniel Dunbar /// GenerateCXXGlobalInitFunc - Generates code for initializing global 2571efb0fa9e11f75af51744a6159530ef7cc8efa24aDaniel Dunbar /// variables. 2572efb0fa9e11f75af51744a6159530ef7cc8efa24aDaniel Dunbar void GenerateCXXGlobalInitFunc(llvm::Function *Fn, 2573efb0fa9e11f75af51744a6159530ef7cc8efa24aDaniel Dunbar llvm::Constant **Decls, 2574efb0fa9e11f75af51744a6159530ef7cc8efa24aDaniel Dunbar unsigned NumDecls); 2575efb0fa9e11f75af51744a6159530ef7cc8efa24aDaniel Dunbar 25763f88f686e32949ffe02ccb551f482f9cf810358bJohn McCall /// GenerateCXXGlobalDtorsFunc - Generates code for destroying global 2577efb0fa9e11f75af51744a6159530ef7cc8efa24aDaniel Dunbar /// variables. 25783f88f686e32949ffe02ccb551f482f9cf810358bJohn McCall void GenerateCXXGlobalDtorsFunc(llvm::Function *Fn, 25793f88f686e32949ffe02ccb551f482f9cf810358bJohn McCall const std::vector<std::pair<llvm::WeakVH, 25803f88f686e32949ffe02ccb551f482f9cf810358bJohn McCall llvm::Constant*> > &DtorsAndObjects); 2581efb0fa9e11f75af51744a6159530ef7cc8efa24aDaniel Dunbar 2582d26bc76c98006609002d9930f8840490e88ac5b5John McCall void GenerateCXXGlobalVarDeclInitFunc(llvm::Function *Fn, 2583d26bc76c98006609002d9930f8840490e88ac5b5John McCall const VarDecl *D, 25847ca4850a3e3530fa6c93b64b740446e32c97f992Richard Smith llvm::GlobalVariable *Addr, 25857ca4850a3e3530fa6c93b64b740446e32c97f992Richard Smith bool PerformInit); 2586efb0fa9e11f75af51744a6159530ef7cc8efa24aDaniel Dunbar 2587558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall void EmitCXXConstructExpr(const CXXConstructExpr *E, AggValueSlot Dest); 258834999876e215b22febc240b1a6dc054215d12f9cFariborz Jahanian 258934999876e215b22febc240b1a6dc054215d12f9cFariborz Jahanian void EmitSynthesizedCXXCopyCtor(llvm::Value *Dest, llvm::Value *Src, 2590830937bc1100fba7682f7c32c40512085870f50cFariborz Jahanian const Expr *Exp); 25911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 25921a343ebbf413e8eae6b2737b2b2d79cbf5765571John McCall void enterFullExpression(const ExprWithCleanups *E) { 25931a343ebbf413e8eae6b2737b2b2d79cbf5765571John McCall if (E->getNumObjects() == 0) return; 25941a343ebbf413e8eae6b2737b2b2d79cbf5765571John McCall enterNonTrivialFullExpression(E); 25951a343ebbf413e8eae6b2737b2b2d79cbf5765571John McCall } 25961a343ebbf413e8eae6b2737b2b2d79cbf5765571John McCall void enterNonTrivialFullExpression(const ExprWithCleanups *E); 25971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2598756b5c4f9d52642d87d1948bee58f97a4f795b24Anders Carlsson void EmitCXXThrowExpr(const CXXThrowExpr *E); 25991eb2e59338c4b9c0429fc39ca98662adc9e7a3f2Douglas Gregor 26004c5d8afd100189b6cce4fd89bfb8aec5700acb50Eli Friedman void EmitLambdaExpr(const LambdaExpr *E, AggValueSlot Dest); 26014c5d8afd100189b6cce4fd89bfb8aec5700acb50Eli Friedman 2602276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman RValue EmitAtomicExpr(AtomicExpr *E, llvm::Value *Dest = 0); 2603276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman 26040ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar //===--------------------------------------------------------------------===// 260577f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge // Annotations Emission 260677f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge //===--------------------------------------------------------------------===// 260777f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge 260877f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge /// Emit an annotation call (intrinsic or builtin). 260977f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge llvm::Value *EmitAnnotationCall(llvm::Value *AnnotationFn, 261077f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge llvm::Value *AnnotatedVal, 2611cfa88f893915ceb8ae4ce2f17c46c24a4d67502fDmitri Gribenko StringRef AnnotationStr, 261277f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge SourceLocation Location); 261377f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge 261477f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge /// Emit local annotations for the local variable V, declared by D. 261577f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge void EmitVarAnnotations(const VarDecl *D, llvm::Value *V); 261677f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge 261777f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge /// Emit field annotations for the given field & value. Returns the 261877f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge /// annotation result. 261977f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge llvm::Value *EmitFieldAnnotations(const FieldDecl *D, llvm::Value *V); 262077f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge 262177f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge //===--------------------------------------------------------------------===// 26220ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar // Internal Helpers 26230ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar //===--------------------------------------------------------------------===// 26240dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 26250946ccd1e58c1f1da31ddbca67c5b6301ac8b255Chris Lattner /// ContainsLabel - Return true if the statement contains a label in it. If 26260946ccd1e58c1f1da31ddbca67c5b6301ac8b255Chris Lattner /// this statement is not executed normally, it not containing a label means 26270946ccd1e58c1f1da31ddbca67c5b6301ac8b255Chris Lattner /// that we can just remove the code. 26280946ccd1e58c1f1da31ddbca67c5b6301ac8b255Chris Lattner static bool ContainsLabel(const Stmt *S, bool IgnoreCaseStmts = false); 26290dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 2630ef425a69006afaa87751ee41ccf8ff405d9ede70Chris Lattner /// containsBreak - Return true if the statement contains a break out of it. 2631ef425a69006afaa87751ee41ccf8ff405d9ede70Chris Lattner /// If the statement (recursively) contains a switch or loop with a break 2632ef425a69006afaa87751ee41ccf8ff405d9ede70Chris Lattner /// inside of it, this is fine. 2633ef425a69006afaa87751ee41ccf8ff405d9ede70Chris Lattner static bool containsBreak(const Stmt *S); 2634ef425a69006afaa87751ee41ccf8ff405d9ede70Chris Lattner 26354bc0455d826e9634b7a68c0d06146edd633c9453Daniel Dunbar /// ConstantFoldsToSimpleInteger - If the specified expression does not fold 2636c2c90011a688c04a4e980282f08c267e081c4b00Chris Lattner /// to a constant, or if it does but contains a label, return false. If it 2637c2c90011a688c04a4e980282f08c267e081c4b00Chris Lattner /// constant folds return true and set the boolean result in Result. 2638c2c90011a688c04a4e980282f08c267e081c4b00Chris Lattner bool ConstantFoldsToSimpleInteger(const Expr *Cond, bool &Result); 26390dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 2640ef425a69006afaa87751ee41ccf8ff405d9ede70Chris Lattner /// ConstantFoldsToSimpleInteger - If the specified expression does not fold 2641ef425a69006afaa87751ee41ccf8ff405d9ede70Chris Lattner /// to a constant, or if it does but contains a label, return false. If it 2642ef425a69006afaa87751ee41ccf8ff405d9ede70Chris Lattner /// constant folds return true and set the folded value. 2643e1ecdc168175719d74e112bcacd4aae5e12d4631Richard Trieu bool ConstantFoldsToSimpleInteger(const Expr *Cond, llvm::APSInt &Result); 2644ef425a69006afaa87751ee41ccf8ff405d9ede70Chris Lattner 264531a0984b5cb4af99d2407c0f25bf5af68df681c6Chris Lattner /// EmitBranchOnBoolExpr - Emit a branch on a boolean condition (e.g. for an 264631a0984b5cb4af99d2407c0f25bf5af68df681c6Chris Lattner /// if statement) to the specified blocks. Based on the condition, this might 264731a0984b5cb4af99d2407c0f25bf5af68df681c6Chris Lattner /// try to simplify the codegen of the conditional based on the branch. 26489bc47e29dce8f095be7a6d07dbb02a5a7a112949Chris Lattner void EmitBranchOnBoolExpr(const Expr *Cond, llvm::BasicBlock *TrueBlock, 26494bc0455d826e9634b7a68c0d06146edd633c9453Daniel Dunbar llvm::BasicBlock *FalseBlock); 2650be07f60131bc6f8d6696f4644df1ef667a1730d5Mike Stump 26514def70d3040e73707c738f7c366737a986135edfRichard Smith /// \brief Emit a description of a type in a format suitable for passing to 26524def70d3040e73707c738f7c366737a986135edfRichard Smith /// a runtime sanitizer handler. 26534def70d3040e73707c738f7c366737a986135edfRichard Smith llvm::Constant *EmitCheckTypeDescriptor(QualType T); 26544def70d3040e73707c738f7c366737a986135edfRichard Smith 26554def70d3040e73707c738f7c366737a986135edfRichard Smith /// \brief Convert a value into a format suitable for passing to a runtime 26564def70d3040e73707c738f7c366737a986135edfRichard Smith /// sanitizer handler. 26574def70d3040e73707c738f7c366737a986135edfRichard Smith llvm::Value *EmitCheckValue(llvm::Value *V); 26584def70d3040e73707c738f7c366737a986135edfRichard Smith 26594def70d3040e73707c738f7c366737a986135edfRichard Smith /// \brief Emit a description of a source location in a format suitable for 26604def70d3040e73707c738f7c366737a986135edfRichard Smith /// passing to a runtime sanitizer handler. 26614def70d3040e73707c738f7c366737a986135edfRichard Smith llvm::Constant *EmitCheckSourceLocation(SourceLocation Loc); 26624def70d3040e73707c738f7c366737a986135edfRichard Smith 2663ad95481b2769ad61f23afc5e2c31f11c66090657Will Dietz /// \brief Specify under what conditions this check can be recovered 2664ad95481b2769ad61f23afc5e2c31f11c66090657Will Dietz enum CheckRecoverableKind { 2665ad95481b2769ad61f23afc5e2c31f11c66090657Will Dietz /// Always terminate program execution if this check fails 2666ad95481b2769ad61f23afc5e2c31f11c66090657Will Dietz CRK_Unrecoverable, 2667ad95481b2769ad61f23afc5e2c31f11c66090657Will Dietz /// Check supports recovering, allows user to specify which 2668ad95481b2769ad61f23afc5e2c31f11c66090657Will Dietz CRK_Recoverable, 2669ad95481b2769ad61f23afc5e2c31f11c66090657Will Dietz /// Runtime conditionally aborts, always need to support recovery. 2670ad95481b2769ad61f23afc5e2c31f11c66090657Will Dietz CRK_AlwaysRecoverable 2671ad95481b2769ad61f23afc5e2c31f11c66090657Will Dietz }; 2672ad95481b2769ad61f23afc5e2c31f11c66090657Will Dietz 2673cc305617e952f8c3a06b63d9225d0dd7769341b7Richard Smith /// \brief Create a basic block that will call a handler function in a 2674cc305617e952f8c3a06b63d9225d0dd7769341b7Richard Smith /// sanitizer runtime with the provided arguments, and create a conditional 2675cc305617e952f8c3a06b63d9225d0dd7769341b7Richard Smith /// branch to it. 26764def70d3040e73707c738f7c366737a986135edfRichard Smith void EmitCheck(llvm::Value *Checked, StringRef CheckName, 2677cfa88f893915ceb8ae4ce2f17c46c24a4d67502fDmitri Gribenko ArrayRef<llvm::Constant *> StaticArgs, 2678cfa88f893915ceb8ae4ce2f17c46c24a4d67502fDmitri Gribenko ArrayRef<llvm::Value *> DynamicArgs, 2679ad95481b2769ad61f23afc5e2c31f11c66090657Will Dietz CheckRecoverableKind Recoverable); 26809cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer 2681cc305617e952f8c3a06b63d9225d0dd7769341b7Richard Smith /// \brief Create a basic block that will call the trap intrinsic, and emit a 2682cc305617e952f8c3a06b63d9225d0dd7769341b7Richard Smith /// conditional branch to it, for the -ftrapv checks. 268378d85b1c5830a881c0a20a1b3fea99ee73149590Chad Rosier void EmitTrapCheck(llvm::Value *Checked); 2684cc305617e952f8c3a06b63d9225d0dd7769341b7Richard Smith 268521c9ad9d29d08a287292c670e7c52bc522c7f8bbAnders Carlsson /// EmitCallArg - Emit a single call argument. 2686413ebdb1af6fb0d81845b61254daf02ba0449afdJohn McCall void EmitCallArg(CallArgList &args, const Expr *E, QualType ArgType); 268721c9ad9d29d08a287292c670e7c52bc522c7f8bbAnders Carlsson 26882736071ea3a46f90e65c93418961611d96c10ab9John McCall /// EmitDelegateCallArg - We are performing a delegate call; that 26892736071ea3a46f90e65c93418961611d96c10ab9John McCall /// is, the current function is delegating to another one. Produce 26902736071ea3a46f90e65c93418961611d96c10ab9John McCall /// a r-value suitable for passing the given parameter. 2691413ebdb1af6fb0d81845b61254daf02ba0449afdJohn McCall void EmitDelegateCallArg(CallArgList &args, const VarDecl *param); 26922736071ea3a46f90e65c93418961611d96c10ab9John McCall 2693c5096cbf7a42e0f9012945b00d9037a5b5a88d72Peter Collingbourne /// SetFPAccuracy - Set the minimum required accuracy of the given floating 2694c5096cbf7a42e0f9012945b00d9037a5b5a88d72Peter Collingbourne /// point operation, expressed as the maximum relative error in ulp. 26958250016fb9491fcfde7fce05230d66e267944484Duncan Sands void SetFPAccuracy(llvm::Value *Val, float Accuracy); 2696c5096cbf7a42e0f9012945b00d9037a5b5a88d72Peter Collingbourne 269731a0984b5cb4af99d2407c0f25bf5af68df681c6Chris Lattnerprivate: 2698c3f8955d7da1019dbe16b0bdf3e49d2e08d988e9Rafael Espindola llvm::MDNode *getRangeForLoadFromType(QualType Ty); 269929e0bccf2bcce22b877f8b2ed173f564c116b97eDaniel Dunbar void EmitReturnOfRValue(RValue RV, QualType Ty); 270029e0bccf2bcce22b877f8b2ed173f564c116b97eDaniel Dunbar 27015627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar /// ExpandTypeFromArgs - Reconstruct a structure of type \arg Ty 27025627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar /// from function arguments into \arg Dst. See ABIArgInfo::Expand. 27035627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar /// 27045627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar /// \param AI - The first function argument of the expansion. 27055627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar /// \return The argument following the last expanded function 27065627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar /// argument. 27070dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump llvm::Function::arg_iterator 27085627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar ExpandTypeFromArgs(QualType Ty, LValue Dst, 27095627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar llvm::Function::arg_iterator AI); 27105627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar 27110dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// ExpandTypeToArgs - Expand an RValue \arg Src, with the LLVM type for \arg 27120dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// Ty, into individual arguments on the provided vector \arg Args. See 27130dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// ABIArgInfo::Expand. 27140dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump void ExpandTypeToArgs(QualType Ty, RValue Src, 2715686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVector<llvm::Value*, 16> &Args, 2716811bf3669f4d82c57fe3cd3c49050fdbc95d0affChris Lattner llvm::FunctionType *IRFuncTy); 2717c8c7b187adcd989e01a9fba1ebead6c2abd770c9Anders Carlsson 271842b60551eff3a424e191b293bfd606559dc96bffChad Rosier llvm::Value* EmitAsmInput(const TargetInfo::ConstraintInfo &Info, 2719c8c7b187adcd989e01a9fba1ebead6c2abd770c9Anders Carlsson const Expr *InputExpr, std::string &ConstraintStr); 27200dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 272142b60551eff3a424e191b293bfd606559dc96bffChad Rosier llvm::Value* EmitAsmInputLValue(const TargetInfo::ConstraintInfo &Info, 27226d7cfd7ef82e42ff30ee1dafd2883fd94e9f8294Eli Friedman LValue InputValue, QualType InputType, 27236d7cfd7ef82e42ff30ee1dafd2883fd94e9f8294Eli Friedman std::string &ConstraintStr); 27246d7cfd7ef82e42ff30ee1dafd2883fd94e9f8294Eli Friedman 27250139bb96494b4c4ba0824617d5d2495dc7e44c76Anders Carlsson /// EmitCallArgs - Emit call arguments for a function. 27261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// The CallArgTypeInfo parameter is used for iterating over the known 2727af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson /// argument types of the function being called. 2728af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson template<typename T> 2729af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson void EmitCallArgs(CallArgList& Args, const T* CallArgTypeInfo, 27300139bb96494b4c4ba0824617d5d2495dc7e44c76Anders Carlsson CallExpr::const_arg_iterator ArgBeg, 2731af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson CallExpr::const_arg_iterator ArgEnd) { 2732af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson CallExpr::const_arg_iterator Arg = ArgBeg; 2733af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson 2734af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson // First, use the argument types that the type info knows about 2735af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson if (CallArgTypeInfo) { 2736af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson for (typename T::arg_type_iterator I = CallArgTypeInfo->arg_type_begin(), 2737af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson E = CallArgTypeInfo->arg_type_end(); I != E; ++I, ++Arg) { 273844b0a3e858af7b19f489619e52cd58970611cd15Eli Friedman assert(Arg != ArgEnd && "Running over edge of argument list!"); 2739af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson QualType ArgType = *I; 2740745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian#ifndef NDEBUG 2741745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian QualType ActualArgType = Arg->getType(); 2742745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian if (ArgType->isPointerType() && ActualArgType->isPointerType()) { 27439cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer QualType ActualBaseType = 2744745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian ActualArgType->getAs<PointerType>()->getPointeeType(); 27459cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer QualType ArgBaseType = 2746745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian ArgType->getAs<PointerType>()->getPointeeType(); 2747745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian if (ArgBaseType->isVariableArrayType()) { 2748745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian if (const VariableArrayType *VAT = 2749745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian getContext().getAsVariableArrayType(ActualBaseType)) { 2750745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian if (!VAT->getSizeExpr()) 2751745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian ActualArgType = ArgType; 2752745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian } 2753745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian } 2754745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian } 2755af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson assert(getContext().getCanonicalType(ArgType.getNonReferenceType()). 27561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump getTypePtr() == 2757745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian getContext().getCanonicalType(ActualArgType).getTypePtr() && 2758af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson "type mismatch in call argument!"); 2759745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian#endif 2760413ebdb1af6fb0d81845b61254daf02ba0449afdJohn McCall EmitCallArg(Args, *Arg, ArgType); 2761af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson } 27621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 27631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // Either we've emitted all the call args, or we have a call to a 2764af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson // variadic function. 27651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump assert((Arg == ArgEnd || CallArgTypeInfo->isVariadic()) && 2766af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson "Extra arguments in non-variadic function!"); 27671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2768af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson } 27691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2770af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson // If we still have any arguments, emit them using the type of the argument. 2771413ebdb1af6fb0d81845b61254daf02ba0449afdJohn McCall for (; Arg != ArgEnd; ++Arg) 2772413ebdb1af6fb0d81845b61254daf02ba0449afdJohn McCall EmitCallArg(Args, *Arg, Arg->getType()); 2773af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson } 2774492c4f998d848673d3d6c9e6416115df4036a71dJohn McCall 2775492c4f998d848673d3d6c9e6416115df4036a71dJohn McCall const TargetCodeGenInfo &getTargetHooks() const { 2776492c4f998d848673d3d6c9e6416115df4036a71dJohn McCall return CGM.getTargetCodeGenInfo(); 2777492c4f998d848673d3d6c9e6416115df4036a71dJohn McCall } 2778744016dde06fcffd50931e94a98c850f8b12cd87John McCall 2779744016dde06fcffd50931e94a98c850f8b12cd87John McCall void EmitDeclMetadata(); 2780f0c11f7e6848f023ced6a5b51399ba787c7d4d0bJohn McCall 2781f0c11f7e6848f023ced6a5b51399ba787c7d4d0bJohn McCall CodeGenModule::ByrefHelpers * 27822acc6e3feda5e4f7d9009bdcf8b1cd777fecfe2dChris Lattner buildByrefHelpers(llvm::StructType &byrefType, 2783f0c11f7e6848f023ced6a5b51399ba787c7d4d0bJohn McCall const AutoVarEmission &emission); 2784b49bd27b334a6c4e3bf9d810a7d5b022578f1194Dan Gohman 2785b49bd27b334a6c4e3bf9d810a7d5b022578f1194Dan Gohman void AddObjCARCExceptionMetadata(llvm::Instruction *Inst); 2786f4c3db175101cbf94dad59419c3ed7aed51bf606Jay Foad 2787ea93e40785ffeadfac66b948c95f9490ec26207aEli Friedman /// GetPointeeAlignment - Given an expression with a pointer type, emit the 2788ea93e40785ffeadfac66b948c95f9490ec26207aEli Friedman /// value and compute our best estimate of the alignment of the pointee. 2789ea93e40785ffeadfac66b948c95f9490ec26207aEli Friedman std::pair<llvm::Value*, unsigned> EmitPointerWithAlignment(const Expr *Addr); 27905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 27911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2792150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall/// Helper class with most of the code for saving a value for a 2793150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall/// conditional expression cleanup. 2794804b807ea918184d6de63bd745e1ff75a9bfc679John McCallstruct DominatingLLVMValue { 2795150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall typedef llvm::PointerIntPair<llvm::Value*, 1, bool> saved_type; 2796150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall 2797150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall /// Answer whether the given value needs extra work to be saved. 2798150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall static bool needsSaving(llvm::Value *value) { 2799150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall // If it's not an instruction, we don't need to save. 2800150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall if (!isa<llvm::Instruction>(value)) return false; 2801150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall 2802150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall // If it's an instruction in the entry block, we don't need to save. 2803150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall llvm::BasicBlock *block = cast<llvm::Instruction>(value)->getParent(); 2804150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall return (block != &block->getParent()->getEntryBlock()); 2805150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall } 2806150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall 2807150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall /// Try to save the given value. 2808150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall static saved_type save(CodeGenFunction &CGF, llvm::Value *value) { 2809150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall if (!needsSaving(value)) return saved_type(value, false); 2810150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall 2811150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall // Otherwise we need an alloca. 2812150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall llvm::Value *alloca = 2813150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall CGF.CreateTempAlloca(value->getType(), "cond-cleanup.save"); 2814150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall CGF.Builder.CreateStore(value, alloca); 2815150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall 2816150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall return saved_type(alloca, true); 2817150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall } 2818150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall 2819150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall static llvm::Value *restore(CodeGenFunction &CGF, saved_type value) { 2820150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall if (!value.getInt()) return value.getPointer(); 2821150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall return CGF.Builder.CreateLoad(value.getPointer()); 2822150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall } 2823150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall}; 2824150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall 2825804b807ea918184d6de63bd745e1ff75a9bfc679John McCall/// A partial specialization of DominatingValue for llvm::Values that 2826804b807ea918184d6de63bd745e1ff75a9bfc679John McCall/// might be llvm::Instructions. 2827804b807ea918184d6de63bd745e1ff75a9bfc679John McCalltemplate <class T> struct DominatingPointer<T,true> : DominatingLLVMValue { 2828804b807ea918184d6de63bd745e1ff75a9bfc679John McCall typedef T *type; 2829804b807ea918184d6de63bd745e1ff75a9bfc679John McCall static type restore(CodeGenFunction &CGF, saved_type value) { 2830804b807ea918184d6de63bd745e1ff75a9bfc679John McCall return static_cast<T*>(DominatingLLVMValue::restore(CGF, value)); 2831804b807ea918184d6de63bd745e1ff75a9bfc679John McCall } 2832804b807ea918184d6de63bd745e1ff75a9bfc679John McCall}; 2833804b807ea918184d6de63bd745e1ff75a9bfc679John McCall 2834804b807ea918184d6de63bd745e1ff75a9bfc679John McCall/// A specialization of DominatingValue for RValue. 2835804b807ea918184d6de63bd745e1ff75a9bfc679John McCalltemplate <> struct DominatingValue<RValue> { 2836804b807ea918184d6de63bd745e1ff75a9bfc679John McCall typedef RValue type; 2837804b807ea918184d6de63bd745e1ff75a9bfc679John McCall class saved_type { 2838804b807ea918184d6de63bd745e1ff75a9bfc679John McCall enum Kind { ScalarLiteral, ScalarAddress, AggregateLiteral, 2839804b807ea918184d6de63bd745e1ff75a9bfc679John McCall AggregateAddress, ComplexAddress }; 2840804b807ea918184d6de63bd745e1ff75a9bfc679John McCall 2841804b807ea918184d6de63bd745e1ff75a9bfc679John McCall llvm::Value *Value; 2842804b807ea918184d6de63bd745e1ff75a9bfc679John McCall Kind K; 2843804b807ea918184d6de63bd745e1ff75a9bfc679John McCall saved_type(llvm::Value *v, Kind k) : Value(v), K(k) {} 2844804b807ea918184d6de63bd745e1ff75a9bfc679John McCall 2845804b807ea918184d6de63bd745e1ff75a9bfc679John McCall public: 2846804b807ea918184d6de63bd745e1ff75a9bfc679John McCall static bool needsSaving(RValue value); 2847804b807ea918184d6de63bd745e1ff75a9bfc679John McCall static saved_type save(CodeGenFunction &CGF, RValue value); 2848804b807ea918184d6de63bd745e1ff75a9bfc679John McCall RValue restore(CodeGenFunction &CGF); 2849804b807ea918184d6de63bd745e1ff75a9bfc679John McCall 2850804b807ea918184d6de63bd745e1ff75a9bfc679John McCall // implementations in CGExprCXX.cpp 2851804b807ea918184d6de63bd745e1ff75a9bfc679John McCall }; 2852804b807ea918184d6de63bd745e1ff75a9bfc679John McCall 2853804b807ea918184d6de63bd745e1ff75a9bfc679John McCall static bool needsSaving(type value) { 2854804b807ea918184d6de63bd745e1ff75a9bfc679John McCall return saved_type::needsSaving(value); 2855804b807ea918184d6de63bd745e1ff75a9bfc679John McCall } 2856804b807ea918184d6de63bd745e1ff75a9bfc679John McCall static saved_type save(CodeGenFunction &CGF, type value) { 2857804b807ea918184d6de63bd745e1ff75a9bfc679John McCall return saved_type::save(CGF, value); 2858804b807ea918184d6de63bd745e1ff75a9bfc679John McCall } 2859150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall static type restore(CodeGenFunction &CGF, saved_type value) { 2860804b807ea918184d6de63bd745e1ff75a9bfc679John McCall return value.restore(CGF); 2861150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall } 2862150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall}; 2863150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall 28645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} // end namespace CodeGen 28655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} // end namespace clang 28664e1524babb095e70de1da882573eb6fbee98a857Fariborz Jahanian 28675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif 2868