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 14176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines#ifndef LLVM_CLANG_LIB_CODEGEN_CODEGENFUNCTION_H 15176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines#define LLVM_CLANG_LIB_CODEGEN_CODEGENFUNCTION_H 165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1755fc873017f10f6f566b182b70f6fc22aefa3464Chandler Carruth#include "CGBuilder.h" 1855fc873017f10f6f566b182b70f6fc22aefa3464Chandler Carruth#include "CGDebugInfo.h" 196bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines#include "CGLoopInfo.h" 2055fc873017f10f6f566b182b70f6fc22aefa3464Chandler Carruth#include "CGValue.h" 2155fc873017f10f6f566b182b70f6fc22aefa3464Chandler Carruth#include "CodeGenModule.h" 22651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines#include "CodeGenPGO.h" 23651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines#include "EHScopeStack.h" 2455fc873017f10f6f566b182b70f6fc22aefa3464Chandler Carruth#include "clang/AST/CharUnits.h" 25e3a09e6ad09f8d1387ecaa008aaf85527909da0aArgyrios Kyrtzidis#include "clang/AST/ExprCXX.h" 265549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek#include "clang/AST/ExprObjC.h" 2787d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar#include "clang/AST/ExprOpenMP.h" 2855fc873017f10f6f566b182b70f6fc22aefa3464Chandler Carruth#include "clang/AST/Type.h" 2914110477887e3dc168ffc6c191e72d705051f99ePeter Collingbourne#include "clang/Basic/ABI.h" 30524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir#include "clang/Basic/CapturedStmt.h" 310e2c34f92f00628d48968dfea096d36381f494cbStephen Hines#include "clang/Basic/OpenMPKinds.h" 32481769b5dc102b0256b35581e787909ad5edfab5Chris Lattner#include "clang/Basic/TargetInfo.h" 3355fc873017f10f6f566b182b70f6fc22aefa3464Chandler Carruth#include "clang/Frontend/CodeGenOptions.h" 344c7d9f1507d0f102bd4133bba63348636facd469Jay Foad#include "llvm/ADT/ArrayRef.h" 35481769b5dc102b0256b35581e787909ad5edfab5Chris Lattner#include "llvm/ADT/DenseMap.h" 36481769b5dc102b0256b35581e787909ad5edfab5Chris Lattner#include "llvm/ADT/SmallVector.h" 37651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines#include "llvm/IR/ValueHandle.h" 38c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher#include "llvm/Support/Debug.h" 394967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar#include "llvm/Transforms/Utils/SanitizerStats.h" 408f2926b73ed635afecd020da787af6a837601a2bDaniel Dunbar 415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace llvm { 426bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesclass BasicBlock; 436bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesclass LLVMContext; 446bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesclass MDNode; 456bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesclass Module; 466bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesclass SwitchInst; 476bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesclass Twine; 486bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesclass Value; 496bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesclass CallSite; 505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang { 536bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesclass ASTContext; 546bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesclass BlockDecl; 556bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesclass CXXDestructorDecl; 566bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesclass CXXForRangeStmt; 576bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesclass CXXTryStmt; 586bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesclass Decl; 596bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesclass LabelDecl; 606bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesclass EnumConstantDecl; 616bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesclass FunctionDecl; 626bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesclass FunctionProtoType; 636bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesclass LabelStmt; 646bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesclass ObjCContainerDecl; 656bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesclass ObjCInterfaceDecl; 666bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesclass ObjCIvarDecl; 676bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesclass ObjCMethodDecl; 686bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesclass ObjCImplementationDecl; 696bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesclass ObjCPropertyImplDecl; 706bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesclass TargetInfo; 716bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesclass VarDecl; 726bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesclass ObjCForCollectionStmt; 736bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesclass ObjCAtTryStmt; 746bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesclass ObjCAtThrowStmt; 756bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesclass ObjCAtSynchronizedStmt; 766bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesclass ObjCAutoreleasePoolStmt; 775549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek 785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace CodeGen { 796bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesclass CodeGenTypes; 806bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesclass CGFunctionInfo; 816bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesclass CGRecordLayout; 826bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesclass CGBlockInfo; 836bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesclass CGCXXABI; 8487d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainarclass BlockByrefHelpers; 8587d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainarclass BlockByrefInfo; 866bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesclass BlockFlags; 876bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesclass BlockFieldFlags; 884967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainarclass RegionCodeGenTy; 894967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainarclass TargetCodeGenInfo; 904967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainarstruct OMPTaskDataTy; 910dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 929d232c884ea9872d6555df0fd7359699819bc1f1John McCall/// The kind of evaluation to perform on values of a particular 939d232c884ea9872d6555df0fd7359699819bc1f1John McCall/// type. Basically, is the code in CGExprScalar, CGExprComplex, or 949d232c884ea9872d6555df0fd7359699819bc1f1John McCall/// CGExprAgg? 959d232c884ea9872d6555df0fd7359699819bc1f1John McCall/// 969d232c884ea9872d6555df0fd7359699819bc1f1John McCall/// TODO: should vectors maybe be split out into their own thing? 979d232c884ea9872d6555df0fd7359699819bc1f1John McCallenum TypeEvaluationKind { 989d232c884ea9872d6555df0fd7359699819bc1f1John McCall TEK_Scalar, 999d232c884ea9872d6555df0fd7359699819bc1f1John McCall TEK_Complex, 1009d232c884ea9872d6555df0fd7359699819bc1f1John McCall TEK_Aggregate 1019d232c884ea9872d6555df0fd7359699819bc1f1John McCall}; 1029d232c884ea9872d6555df0fd7359699819bc1f1John McCall 1035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// CodeGenFunction - This class organizes the per-function state that is used 1045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// while generating LLVM code. 1055936e33bf74dd6bf126ceee0f6169a2593d03a69John McCallclass CodeGenFunction : public CodeGenTypeCache { 1060e2c34f92f00628d48968dfea096d36381f494cbStephen Hines CodeGenFunction(const CodeGenFunction &) = delete; 1070e2c34f92f00628d48968dfea096d36381f494cbStephen Hines void operator=(const CodeGenFunction &) = delete; 1084c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall 1094c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall friend class CGCXXABI; 110bfc0c1ae4b505b52b36f572a9641f99e76879cabChris Lattnerpublic: 111ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall /// A jump destination is an abstract label, branching to which may 112ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall /// require a jump out through normal cleanups. 113f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall struct JumpDest { 1146bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines JumpDest() : Block(nullptr), ScopeDepth(), Index(0) {} 115ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall JumpDest(llvm::BasicBlock *Block, 116ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall EHScopeStack::stable_iterator Depth, 117ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall unsigned Index) 118ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall : Block(Block), ScopeDepth(Depth), Index(Index) {} 119ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall 1206bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines bool isValid() const { return Block != nullptr; } 121ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall llvm::BasicBlock *getBlock() const { return Block; } 122ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall EHScopeStack::stable_iterator getScopeDepth() const { return ScopeDepth; } 123ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall unsigned getDestIndex() const { return Index; } 1249cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer 125495cfa46300979642acde8d93a1f21c9291dac98Nadav Rotem // This should be used cautiously. 126495cfa46300979642acde8d93a1f21c9291dac98Nadav Rotem void setScopeDepth(EHScopeStack::stable_iterator depth) { 127495cfa46300979642acde8d93a1f21c9291dac98Nadav Rotem ScopeDepth = depth; 128495cfa46300979642acde8d93a1f21c9291dac98Nadav Rotem } 129495cfa46300979642acde8d93a1f21c9291dac98Nadav Rotem 130ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall private: 131f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall llvm::BasicBlock *Block; 132f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall EHScopeStack::stable_iterator ScopeDepth; 133ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall unsigned Index; 134ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall }; 135ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall 1365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer CodeGenModule &CGM; // Per-module state. 137444be7366d0a1e172c0290a1ea54c1cb16b5947cDaniel Dunbar const TargetInfo &Target; 1380dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 13958dee10ed2eee34035f62d1c2d32b3639e9182f8Chris Lattner typedef std::pair<llvm::Value *, llvm::Value *> ComplexPairTy; 1406bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines LoopInfoStack LoopStack; 14145d196b8387dcefc4df26cda114fa34c6528e928Daniel Dunbar CGBuilderTy Builder; 1420dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 1436bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines /// \brief CGBuilder insert helper. This function is called after an 1446bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines /// instruction is created using Builder. 1456bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines void InsertHelper(llvm::Instruction *I, const llvm::Twine &Name, 1466bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines llvm::BasicBlock *BB, 1476bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines llvm::BasicBlock::iterator InsertPt) const; 1486bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 149f5ebf9bf1df10ac15ba32a4b24dfe171b7848c58John McCall /// CurFuncDecl - Holds the Decl for the current outermost 150f5ebf9bf1df10ac15ba32a4b24dfe171b7848c58John McCall /// non-closure context. 1514111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner const Decl *CurFuncDecl; 152b5437d238752dc297e42410e98d38d5250fe0463Chris Lattner /// CurCodeDecl - This is the inner-most code context, which includes blocks. 153b5437d238752dc297e42410e98d38d5250fe0463Chris Lattner const Decl *CurCodeDecl; 15488b5396b0897f28d22ae3debf4a0d97b33b6c362Daniel Dunbar const CGFunctionInfo *CurFnInfo; 155391d77a26382dddf25da73e29fc1fa5aaaea4c6fChris Lattner QualType FnRetTy; 1565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer llvm::Function *CurFn; 1575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1586a1e0eb557d47e85185e09bdf8721f53f4bf9c9cMike Stump /// CurGD - The GlobalDecl for the current function being compiled. 1596a1e0eb557d47e85185e09bdf8721f53f4bf9c9cMike Stump GlobalDecl CurGD; 1606a1e0eb557d47e85185e09bdf8721f53f4bf9c9cMike Stump 161f85e193739c953358c865005855253af4f68a497John McCall /// PrologueCleanupDepth - The cleanup depth enclosing all the 162f85e193739c953358c865005855253af4f68a497John McCall /// cleanups associated with the parameters. 163f85e193739c953358c865005855253af4f68a497John McCall EHScopeStack::stable_iterator PrologueCleanupDepth; 164f85e193739c953358c865005855253af4f68a497John McCall 1655ca2084cf9b529563209429857f01fdae9dcdfa5Daniel Dunbar /// ReturnBlock - Unified return block. 166f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall JumpDest ReturnBlock; 167f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 16887d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// ReturnValue - The temporary alloca to hold the return 16987d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// value. This is invalid iff the function has no return value. 17087d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar Address ReturnValue; 1710dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 1725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// AllocaInsertPoint - This is an instruction in the entry block before which 1735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// we prefer to insert allocas. 174481769b5dc102b0256b35581e787909ad5edfab5Chris Lattner llvm::AssertingVH<llvm::Instruction> AllocaInsertPt; 1750ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar 176524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir /// \brief API for captured statement code generation. 177524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir class CGCapturedStmtInfo { 178524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir public: 1790e2c34f92f00628d48968dfea096d36381f494cbStephen Hines explicit CGCapturedStmtInfo(CapturedRegionKind K = CR_Default) 1800e2c34f92f00628d48968dfea096d36381f494cbStephen Hines : Kind(K), ThisValue(nullptr), CXXThisFieldDecl(nullptr) {} 181524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir explicit CGCapturedStmtInfo(const CapturedStmt &S, 182524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir CapturedRegionKind K = CR_Default) 1836bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines : Kind(K), ThisValue(nullptr), CXXThisFieldDecl(nullptr) { 184524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir 185524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir RecordDecl::field_iterator Field = 186524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir S.getCapturedRecordDecl()->field_begin(); 187524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir for (CapturedStmt::const_capture_iterator I = S.capture_begin(), 188524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir E = S.capture_end(); 189524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir I != E; ++I, ++Field) { 190524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir if (I->capturesThis()) 191524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir CXXThisFieldDecl = *Field; 192176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines else if (I->capturesVariable()) 193524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir CaptureFields[I->getCapturedVar()] = *Field; 1944967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar else if (I->capturesVariableByCopy()) 1954967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar CaptureFields[I->getCapturedVar()] = *Field; 196524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir } 197524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir } 198524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir 199524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir virtual ~CGCapturedStmtInfo(); 200524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir 201524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir CapturedRegionKind getKind() const { return Kind; } 202524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir 20358878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar virtual void setContextValue(llvm::Value *V) { ThisValue = V; } 204524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir // \brief Retrieve the value of the context parameter. 2050e2c34f92f00628d48968dfea096d36381f494cbStephen Hines virtual llvm::Value *getContextValue() const { return ThisValue; } 206524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir 207524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir /// \brief Lookup the captured field decl for a variable. 2080e2c34f92f00628d48968dfea096d36381f494cbStephen Hines virtual const FieldDecl *lookup(const VarDecl *VD) const { 209524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir return CaptureFields.lookup(VD); 210524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir } 211524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir 2120e2c34f92f00628d48968dfea096d36381f494cbStephen Hines bool isCXXThisExprCaptured() const { return getThisFieldDecl() != nullptr; } 2130e2c34f92f00628d48968dfea096d36381f494cbStephen Hines virtual FieldDecl *getThisFieldDecl() const { return CXXThisFieldDecl; } 214524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir 215176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines static bool classof(const CGCapturedStmtInfo *) { 216176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines return true; 217176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines } 218176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines 219524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir /// \brief Emit the captured statement body. 2200e2c34f92f00628d48968dfea096d36381f494cbStephen Hines virtual void EmitBody(CodeGenFunction &CGF, const Stmt *S) { 221b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar CGF.incrementProfileCounter(S); 222524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir CGF.EmitStmt(S); 223524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir } 224524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir 225524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir /// \brief Get the name of the capture helper. 226524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir virtual StringRef getHelperName() const { return "__captured_stmt"; } 227524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir 228524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir private: 229524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir /// \brief The kind of captured statement being generated. 230524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir CapturedRegionKind Kind; 231524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir 232524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir /// \brief Keep the map between VarDecl and FieldDecl. 233524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir llvm::SmallDenseMap<const VarDecl *, FieldDecl *> CaptureFields; 234524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir 235524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir /// \brief The base address of the captured record, passed in as the first 236524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir /// argument of the parallel region function. 237524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir llvm::Value *ThisValue; 238524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir 239524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir /// \brief Captured 'this' type. 240524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir FieldDecl *CXXThisFieldDecl; 241524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir }; 242524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir CGCapturedStmtInfo *CapturedStmtInfo; 243524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir 24487d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// \brief RAII for correct setting/restoring of CapturedStmtInfo. 24587d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar class CGCapturedStmtRAII { 24687d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar private: 24787d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar CodeGenFunction &CGF; 24887d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar CGCapturedStmtInfo *PrevCapturedStmtInfo; 24987d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar public: 25087d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar CGCapturedStmtRAII(CodeGenFunction &CGF, 25187d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar CGCapturedStmtInfo *NewCapturedStmtInfo) 25287d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar : CGF(CGF), PrevCapturedStmtInfo(CGF.CapturedStmtInfo) { 25387d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar CGF.CapturedStmtInfo = NewCapturedStmtInfo; 25487d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar } 25587d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar ~CGCapturedStmtRAII() { CGF.CapturedStmtInfo = PrevCapturedStmtInfo; } 25687d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar }; 257b3198a841e7f356f171f1e11faff014b2deb1eb8Nuno Lopes 258176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines /// \brief Sanitizers enabled for this function. 259176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines SanitizerSet SanOpts; 260176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines 261176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines /// \brief True if CodeGen currently emits code implementing sanitizer checks. 262176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines bool IsSanitizerScope; 263176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines 264176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines /// \brief RAII object to set/unset CodeGenFunction::IsSanitizerScope. 265176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines class SanitizerScope { 266176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines CodeGenFunction *CGF; 267176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines public: 268176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines SanitizerScope(CodeGenFunction *CGF); 269176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines ~SanitizerScope(); 270176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines }; 271176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines 272176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines /// In C++, whether we are code generating a thunk. This controls whether we 273176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines /// should emit cleanups. 274176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines bool CurFuncIsThunk; 2754f45bc099f2665bc6e4bcbb169aa452390dbf3feWill Dietz 276f85e193739c953358c865005855253af4f68a497John McCall /// In ARC, whether we should autorelease the return value. 277f85e193739c953358c865005855253af4f68a497John McCall bool AutoreleaseResult; 278f85e193739c953358c865005855253af4f68a497John McCall 279176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines /// Whether we processed a Microsoft-style asm block during CodeGen. These can 280176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines /// potentially set the return value. 281176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines bool SawAsmBlock; 282176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines 2834967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar const FunctionDecl *CurSEHParent = nullptr; 2844967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar 28558878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar /// True if the current function is an outlined SEH helper. This can be a 28658878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar /// finally block or filter expression. 28758878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar bool IsOutlinedSEHHelper; 28858878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar 289d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall const CodeGen::CGBlockInfo *BlockInfo; 290d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall llvm::Value *BlockPointer; 291d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall 292cec5ebd4a6a89a7023d04cec728fd340b541ed61Eli Friedman llvm::DenseMap<const VarDecl *, FieldDecl *> LambdaCaptureFields; 293cec5ebd4a6a89a7023d04cec728fd340b541ed61Eli Friedman FieldDecl *LambdaThisCaptureField; 294cec5ebd4a6a89a7023d04cec728fd340b541ed61Eli Friedman 2953d91bbcdab155181556969cad6ec97014405acedDouglas Gregor /// \brief A mapping from NRVO variables to the flags used to indicate 2963d91bbcdab155181556969cad6ec97014405acedDouglas Gregor /// when the NRVO has been applied to this variable. 2973d91bbcdab155181556969cad6ec97014405acedDouglas Gregor llvm::DenseMap<const VarDecl *, llvm::Value *> NRVOFlags; 2989cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer 299f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall EHScopeStack EHStack; 3008a07cd3f59a0ede54906bdc8ed21724815db27adRichard Smith llvm::SmallVector<char, 256> LifetimeExtendedCleanupStack; 3010e2c34f92f00628d48968dfea096d36381f494cbStephen Hines llvm::SmallVector<const JumpDest *, 2> SEHTryEpilogueStack; 3028a07cd3f59a0ede54906bdc8ed21724815db27adRichard Smith 30387d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar llvm::Instruction *CurrentFuncletPad = nullptr; 30487d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar 3054967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar class CallLifetimeEnd final : public EHScopeStack::Cleanup { 3064967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar llvm::Value *Addr; 3074967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar llvm::Value *Size; 3084967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar 3094967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar public: 3104967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar CallLifetimeEnd(Address addr, llvm::Value *size) 3114967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar : Addr(addr.getPointer()), Size(size) {} 3124967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar 3134967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar void Emit(CodeGenFunction &CGF, Flags flags) override { 3144967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar CGF.EmitLifetimeEnd(Size, Addr); 3154967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar } 3164967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar }; 3174967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar 3188a07cd3f59a0ede54906bdc8ed21724815db27adRichard Smith /// Header for data within LifetimeExtendedCleanupStack. 3198a07cd3f59a0ede54906bdc8ed21724815db27adRichard Smith struct LifetimeExtendedCleanupHeader { 3208a07cd3f59a0ede54906bdc8ed21724815db27adRichard Smith /// The size of the following cleanup object. 32187d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar unsigned Size; 3228a07cd3f59a0ede54906bdc8ed21724815db27adRichard Smith /// The kind of cleanup to push: a value from the CleanupKind enumeration. 32387d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar CleanupKind Kind; 3248a07cd3f59a0ede54906bdc8ed21724815db27adRichard Smith 32587d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar size_t getSize() const { return Size; } 32687d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar CleanupKind getKind() const { return Kind; } 3278a07cd3f59a0ede54906bdc8ed21724815db27adRichard Smith }; 3280dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 329ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall /// i32s containing the indexes of the cleanup destinations. 330ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall llvm::AllocaInst *NormalCleanupDest; 331ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall 332ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall unsigned NextCleanupDestIndex; 333ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall 3341a343ebbf413e8eae6b2737b2b2d79cbf5765571John McCall /// FirstBlockInfo - The head of a singly-linked-list of block layouts. 3351a343ebbf413e8eae6b2737b2b2d79cbf5765571John McCall CGBlockInfo *FirstBlockInfo; 3361a343ebbf413e8eae6b2737b2b2d79cbf5765571John McCall 337777d6e56ad9b1fed9866daf3ee6486d85c5b7d32John McCall /// EHResumeBlock - Unified block containing a call to llvm.eh.resume. 338777d6e56ad9b1fed9866daf3ee6486d85c5b7d32John McCall llvm::BasicBlock *EHResumeBlock; 339777d6e56ad9b1fed9866daf3ee6486d85c5b7d32John McCall 340285cfd8953d4ca4da613a47a0d691f7234068f8cBill Wendling /// The exception slot. All landing pads write the current exception pointer 341285cfd8953d4ca4da613a47a0d691f7234068f8cBill Wendling /// into this alloca. 342f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall llvm::Value *ExceptionSlot; 3430dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 344285cfd8953d4ca4da613a47a0d691f7234068f8cBill Wendling /// The selector slot. Under the MandatoryCleanup model, all landing pads 345285cfd8953d4ca4da613a47a0d691f7234068f8cBill Wendling /// write the current selector value into this alloca. 34693c332a8ba2c193c435b293966d343dab15f555bJohn McCall llvm::AllocaInst *EHSelectorSlot; 34793c332a8ba2c193c435b293966d343dab15f555bJohn McCall 34887d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// A stack of exception code slots. Entering an __except block pushes a slot 34987d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// on the stack and leaving pops one. The __exception_code() intrinsic loads 35087d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// a value from the top of the stack. 35187d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar SmallVector<Address, 1> SEHCodeSlotStack; 3520e2c34f92f00628d48968dfea096d36381f494cbStephen Hines 35387d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// Value returned by __exception_info intrinsic. 35487d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar llvm::Value *SEHInfo = nullptr; 3550e2c34f92f00628d48968dfea096d36381f494cbStephen Hines 356f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// Emits a landing pad for the current EH stack. 357f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall llvm::BasicBlock *EmitLandingPad(); 3580dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 359f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall llvm::BasicBlock *getInvokeDestImpl(); 36099533834ba8f3658559f334e68a518ebb6388ceaMike Stump 361150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall template <class T> 362804b807ea918184d6de63bd745e1ff75a9bfc679John McCall typename DominatingValue<T>::saved_type saveValueInCond(T value) { 363804b807ea918184d6de63bd745e1ff75a9bfc679John McCall return DominatingValue<T>::save(*this, value); 364150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall } 365150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall 366f1549f66a8216a78112286e3978cea2c29d6334cJohn McCallpublic: 367f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// ObjCEHValueStack - Stack of Objective-C exception values, used for 368f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// rethrows. 369686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVector<llvm::Value*, 8> ObjCEHValueStack; 370bb66f9f2e454135b86462d121629275b6ac38e96Anders Carlsson 371d768e9d29abe1ac1ccc3ed63f2dce835d9bab342John McCall /// A class controlling the emission of a finally block. 372d768e9d29abe1ac1ccc3ed63f2dce835d9bab342John McCall class FinallyInfo { 373d768e9d29abe1ac1ccc3ed63f2dce835d9bab342John McCall /// Where the catchall's edge through the cleanup should go. 374d768e9d29abe1ac1ccc3ed63f2dce835d9bab342John McCall JumpDest RethrowDest; 375d768e9d29abe1ac1ccc3ed63f2dce835d9bab342John McCall 376d768e9d29abe1ac1ccc3ed63f2dce835d9bab342John McCall /// A function to call to enter the catch. 377d768e9d29abe1ac1ccc3ed63f2dce835d9bab342John McCall llvm::Constant *BeginCatchFn; 378d768e9d29abe1ac1ccc3ed63f2dce835d9bab342John McCall 379d768e9d29abe1ac1ccc3ed63f2dce835d9bab342John McCall /// An i1 variable indicating whether or not the @finally is 380d768e9d29abe1ac1ccc3ed63f2dce835d9bab342John McCall /// running for an exception. 381d768e9d29abe1ac1ccc3ed63f2dce835d9bab342John McCall llvm::AllocaInst *ForEHVar; 382d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump 383d768e9d29abe1ac1ccc3ed63f2dce835d9bab342John McCall /// An i8* variable into which the exception pointer to rethrow 384d768e9d29abe1ac1ccc3ed63f2dce835d9bab342John McCall /// has been saved. 385d768e9d29abe1ac1ccc3ed63f2dce835d9bab342John McCall llvm::AllocaInst *SavedExnVar; 386d768e9d29abe1ac1ccc3ed63f2dce835d9bab342John McCall 387d768e9d29abe1ac1ccc3ed63f2dce835d9bab342John McCall public: 388d768e9d29abe1ac1ccc3ed63f2dce835d9bab342John McCall void enter(CodeGenFunction &CGF, const Stmt *Finally, 389d768e9d29abe1ac1ccc3ed63f2dce835d9bab342John McCall llvm::Constant *beginCatchFn, llvm::Constant *endCatchFn, 390d768e9d29abe1ac1ccc3ed63f2dce835d9bab342John McCall llvm::Constant *rethrowFn); 391d768e9d29abe1ac1ccc3ed63f2dce835d9bab342John McCall void exit(CodeGenFunction &CGF); 392d768e9d29abe1ac1ccc3ed63f2dce835d9bab342John McCall }; 393f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 3940e2c34f92f00628d48968dfea096d36381f494cbStephen Hines /// Returns true inside SEH __try blocks. 3950e2c34f92f00628d48968dfea096d36381f494cbStephen Hines bool isSEHTryScope() const { return !SEHTryEpilogueStack.empty(); } 3960e2c34f92f00628d48968dfea096d36381f494cbStephen Hines 39787d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// Returns true while emitting a cleanuppad. 39887d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar bool isCleanupPadScope() const { 39987d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar return CurrentFuncletPad && isa<llvm::CleanupPadInst>(CurrentFuncletPad); 40087d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar } 40187d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar 402150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall /// pushFullExprCleanup - Push a cleanup to be run at the end of the 403150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall /// current full-expression. Safe against the possibility that 404150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall /// we're currently inside a conditionally-evaluated expression. 4053ea9e33ea25e0c2b12db56418ba3f994eb662c04Pirama Arumuga Nainar template <class T, class... As> 4063ea9e33ea25e0c2b12db56418ba3f994eb662c04Pirama Arumuga Nainar void pushFullExprCleanup(CleanupKind kind, As... A) { 4073ad32c8d93eb65d1d4943d7df567fc9b4f55d137John McCall // If we're not in a conditional branch, or if none of the 4083ad32c8d93eb65d1d4943d7df567fc9b4f55d137John McCall // arguments requires saving, then use the unconditional cleanup. 409c4a1a8450a3613ef256a71b9d8305b41f79eef50John McCall if (!isInConditionalBranch()) 4103ea9e33ea25e0c2b12db56418ba3f994eb662c04Pirama Arumuga Nainar return EHStack.pushCleanup<T>(kind, A...); 4113ad32c8d93eb65d1d4943d7df567fc9b4f55d137John McCall 4123ea9e33ea25e0c2b12db56418ba3f994eb662c04Pirama Arumuga Nainar // Stash values in a tuple so we can guarantee the order of saves. 4133ea9e33ea25e0c2b12db56418ba3f994eb662c04Pirama Arumuga Nainar typedef std::tuple<typename DominatingValue<As>::saved_type...> SavedTuple; 4143ea9e33ea25e0c2b12db56418ba3f994eb662c04Pirama Arumuga Nainar SavedTuple Saved{saveValueInCond(A)...}; 4153ad32c8d93eb65d1d4943d7df567fc9b4f55d137John McCall 4163ea9e33ea25e0c2b12db56418ba3f994eb662c04Pirama Arumuga Nainar typedef EHScopeStack::ConditionalCleanup<T, As...> CleanupType; 4173ea9e33ea25e0c2b12db56418ba3f994eb662c04Pirama Arumuga Nainar EHStack.pushCleanupTuple<CleanupType>(kind, Saved); 4189928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall initFullExprCleanup(); 4199928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall } 4209928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall 4218a07cd3f59a0ede54906bdc8ed21724815db27adRichard Smith /// \brief Queue a cleanup to be pushed after finishing the current 4228a07cd3f59a0ede54906bdc8ed21724815db27adRichard Smith /// full-expression. 4233ea9e33ea25e0c2b12db56418ba3f994eb662c04Pirama Arumuga Nainar template <class T, class... As> 4243ea9e33ea25e0c2b12db56418ba3f994eb662c04Pirama Arumuga Nainar void pushCleanupAfterFullExpr(CleanupKind Kind, As... A) { 4258a07cd3f59a0ede54906bdc8ed21724815db27adRichard Smith assert(!isInConditionalBranch() && "can't defer conditional cleanup"); 4268a07cd3f59a0ede54906bdc8ed21724815db27adRichard Smith 4278a07cd3f59a0ede54906bdc8ed21724815db27adRichard Smith LifetimeExtendedCleanupHeader Header = { sizeof(T), Kind }; 4288a07cd3f59a0ede54906bdc8ed21724815db27adRichard Smith 4298a07cd3f59a0ede54906bdc8ed21724815db27adRichard Smith size_t OldSize = LifetimeExtendedCleanupStack.size(); 4308a07cd3f59a0ede54906bdc8ed21724815db27adRichard Smith LifetimeExtendedCleanupStack.resize( 4318a07cd3f59a0ede54906bdc8ed21724815db27adRichard Smith LifetimeExtendedCleanupStack.size() + sizeof(Header) + Header.Size); 4328a07cd3f59a0ede54906bdc8ed21724815db27adRichard Smith 43387d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar static_assert(sizeof(Header) % llvm::AlignOf<T>::Alignment == 0, 43487d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar "Cleanup will be allocated on misaligned address"); 4358a07cd3f59a0ede54906bdc8ed21724815db27adRichard Smith char *Buffer = &LifetimeExtendedCleanupStack[OldSize]; 4368a07cd3f59a0ede54906bdc8ed21724815db27adRichard Smith new (Buffer) LifetimeExtendedCleanupHeader(Header); 4373ea9e33ea25e0c2b12db56418ba3f994eb662c04Pirama Arumuga Nainar new (Buffer + sizeof(Header)) T(A...); 4388a07cd3f59a0ede54906bdc8ed21724815db27adRichard Smith } 4398a07cd3f59a0ede54906bdc8ed21724815db27adRichard Smith 4406f103ba42cb69d50005a977c5ea583984ab63fc4John McCall /// Set up the last cleaup that was pushed as a conditional 4416f103ba42cb69d50005a977c5ea583984ab63fc4John McCall /// full-expression cleanup. 4426f103ba42cb69d50005a977c5ea583984ab63fc4John McCall void initFullExprCleanup(); 4436f103ba42cb69d50005a977c5ea583984ab63fc4John McCall 444f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// PushDestructorCleanup - Push a cleanup to call the 445f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// complete-object destructor of an object of the given type at the 446f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// given address. Does nothing if T is not a C++ class type with a 447f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// non-trivial destructor. 44887d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar void PushDestructorCleanup(QualType T, Address Addr); 449f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 45081407d404a3fc8d24d0e2a052d85cae183033e2bJohn McCall /// PushDestructorCleanup - Push a cleanup to call the 45181407d404a3fc8d24d0e2a052d85cae183033e2bJohn McCall /// complete-object variant of the given destructor on the object at 45281407d404a3fc8d24d0e2a052d85cae183033e2bJohn McCall /// the given address. 45387d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar void PushDestructorCleanup(const CXXDestructorDecl *Dtor, Address Addr); 45481407d404a3fc8d24d0e2a052d85cae183033e2bJohn McCall 455f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// PopCleanupBlock - Will pop the cleanup entry on the stack and 456f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// process all branch fixups. 4571c3db769249a633108dc320da87c48a432e2bcc1Adrian Prantl void PopCleanupBlock(bool FallThroughIsBranchThrough = false); 458f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 4597d8647f194ae4f2499e5bcd40dcfea34cd21ebc6John McCall /// DeactivateCleanupBlock - Deactivates the given cleanup block. 4607d8647f194ae4f2499e5bcd40dcfea34cd21ebc6John McCall /// The block cannot be reactivated. Pops it if it's the top of the 4617d8647f194ae4f2499e5bcd40dcfea34cd21ebc6John McCall /// stack. 4626f103ba42cb69d50005a977c5ea583984ab63fc4John McCall /// 4636f103ba42cb69d50005a977c5ea583984ab63fc4John McCall /// \param DominatingIP - An instruction which is known to 4646f103ba42cb69d50005a977c5ea583984ab63fc4John McCall /// dominate the current IP (if set) and which lies along 4656f103ba42cb69d50005a977c5ea583984ab63fc4John McCall /// all paths of execution between the current IP and the 4666f103ba42cb69d50005a977c5ea583984ab63fc4John McCall /// the point at which the cleanup comes into scope. 4676f103ba42cb69d50005a977c5ea583984ab63fc4John McCall void DeactivateCleanupBlock(EHScopeStack::stable_iterator Cleanup, 4686f103ba42cb69d50005a977c5ea583984ab63fc4John McCall llvm::Instruction *DominatingIP); 4697d8647f194ae4f2499e5bcd40dcfea34cd21ebc6John McCall 4707d8647f194ae4f2499e5bcd40dcfea34cd21ebc6John McCall /// ActivateCleanupBlock - Activates an initially-inactive cleanup. 4717d8647f194ae4f2499e5bcd40dcfea34cd21ebc6John McCall /// Cannot be used to resurrect a deactivated cleanup. 4726f103ba42cb69d50005a977c5ea583984ab63fc4John McCall /// 4736f103ba42cb69d50005a977c5ea583984ab63fc4John McCall /// \param DominatingIP - An instruction which is known to 4746f103ba42cb69d50005a977c5ea583984ab63fc4John McCall /// dominate the current IP (if set) and which lies along 4756f103ba42cb69d50005a977c5ea583984ab63fc4John McCall /// all paths of execution between the current IP and the 4766f103ba42cb69d50005a977c5ea583984ab63fc4John McCall /// the point at which the cleanup comes into scope. 4776f103ba42cb69d50005a977c5ea583984ab63fc4John McCall void ActivateCleanupBlock(EHScopeStack::stable_iterator Cleanup, 4786f103ba42cb69d50005a977c5ea583984ab63fc4John McCall llvm::Instruction *DominatingIP); 479cd2d2b7814e0104ed41a8da159a06a8ca77b70d8John McCall 480f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// \brief Enters a new scope for capturing cleanups, all of which 481f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// will be executed once the scope is exited. 482f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall class RunCleanupsScope { 483f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall EHScopeStack::stable_iterator CleanupStackDepth; 4848a07cd3f59a0ede54906bdc8ed21724815db27adRichard Smith size_t LifetimeExtendedCleanupStackSize; 48501234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor bool OldDidCallStackSave; 486ed383135bcffdb8849418896b742fbca7fa2b787John McCall protected: 4875656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor bool PerformCleanup; 488ed383135bcffdb8849418896b742fbca7fa2b787John McCall private: 48901234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor 4900e2c34f92f00628d48968dfea096d36381f494cbStephen Hines RunCleanupsScope(const RunCleanupsScope &) = delete; 4910e2c34f92f00628d48968dfea096d36381f494cbStephen Hines void operator=(const RunCleanupsScope &) = delete; 49201234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor 493c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher protected: 494c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher CodeGenFunction& CGF; 4954f45bc099f2665bc6e4bcbb169aa452390dbf3feWill Dietz 49601234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor public: 49701234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor /// \brief Enter a new cleanup scope. 4989cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer explicit RunCleanupsScope(CodeGenFunction &CGF) 499c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher : PerformCleanup(true), CGF(CGF) 5005656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor { 501f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall CleanupStackDepth = CGF.EHStack.stable_begin(); 5028a07cd3f59a0ede54906bdc8ed21724815db27adRichard Smith LifetimeExtendedCleanupStackSize = 5038a07cd3f59a0ede54906bdc8ed21724815db27adRichard Smith CGF.LifetimeExtendedCleanupStack.size(); 50401234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor OldDidCallStackSave = CGF.DidCallStackSave; 5054ada2ca7d82dab68d3646f3eb6dcdfee072e8ea4Argyrios Kyrtzidis CGF.DidCallStackSave = false; 50601234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor } 50701234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor 50801234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor /// \brief Exit this cleanup scope, emitting any accumulated 50901234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor /// cleanups. 510f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall ~RunCleanupsScope() { 5115656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor if (PerformCleanup) { 5125656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor CGF.DidCallStackSave = OldDidCallStackSave; 5138a07cd3f59a0ede54906bdc8ed21724815db27adRichard Smith CGF.PopCleanupBlocks(CleanupStackDepth, 5148a07cd3f59a0ede54906bdc8ed21724815db27adRichard Smith LifetimeExtendedCleanupStackSize); 5155656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor } 5165656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor } 5175656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor 5185656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor /// \brief Determine whether this scope requires any cleanups. 5195656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor bool requiresCleanups() const { 520f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall return CGF.EHStack.stable_begin() != CleanupStackDepth; 5215656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor } 5225656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor 5235656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor /// \brief Force the emission of cleanups now, instead of waiting 5245656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor /// until this object is destroyed. 5255656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor void ForceCleanup() { 5265656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor assert(PerformCleanup && "Already forced cleanup"); 52701234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor CGF.DidCallStackSave = OldDidCallStackSave; 5288a07cd3f59a0ede54906bdc8ed21724815db27adRichard Smith CGF.PopCleanupBlocks(CleanupStackDepth, 5298a07cd3f59a0ede54906bdc8ed21724815db27adRichard Smith LifetimeExtendedCleanupStackSize); 5305656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor PerformCleanup = false; 53101234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor } 53201234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor }; 53301234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor 534176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines class LexicalScope : public RunCleanupsScope { 535c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher SourceRange Range; 536495cfa46300979642acde8d93a1f21c9291dac98Nadav Rotem SmallVector<const LabelDecl*, 4> Labels; 537495cfa46300979642acde8d93a1f21c9291dac98Nadav Rotem LexicalScope *ParentScope; 538c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher 5390e2c34f92f00628d48968dfea096d36381f494cbStephen Hines LexicalScope(const LexicalScope &) = delete; 5400e2c34f92f00628d48968dfea096d36381f494cbStephen Hines void operator=(const LexicalScope &) = delete; 541c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher 542c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher public: 543c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher /// \brief Enter a new cleanup scope. 544c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher explicit LexicalScope(CodeGenFunction &CGF, SourceRange Range) 545495cfa46300979642acde8d93a1f21c9291dac98Nadav Rotem : RunCleanupsScope(CGF), Range(Range), ParentScope(CGF.CurLexicalScope) { 546495cfa46300979642acde8d93a1f21c9291dac98Nadav Rotem CGF.CurLexicalScope = this; 547c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher if (CGDebugInfo *DI = CGF.getDebugInfo()) 548c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher DI->EmitLexicalBlockStart(CGF.Builder, Range.getBegin()); 549c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher } 550c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher 551495cfa46300979642acde8d93a1f21c9291dac98Nadav Rotem void addLabel(const LabelDecl *label) { 552495cfa46300979642acde8d93a1f21c9291dac98Nadav Rotem assert(PerformCleanup && "adding label to dead scope?"); 553495cfa46300979642acde8d93a1f21c9291dac98Nadav Rotem Labels.push_back(label); 554495cfa46300979642acde8d93a1f21c9291dac98Nadav Rotem } 555495cfa46300979642acde8d93a1f21c9291dac98Nadav Rotem 556c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher /// \brief Exit this cleanup scope, emitting any accumulated 557c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher /// cleanups. 558c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher ~LexicalScope() { 559efb72adbae0c253fc2fd9127fb3e1c36cb1b8d93Adrian Prantl if (CGDebugInfo *DI = CGF.getDebugInfo()) 560efb72adbae0c253fc2fd9127fb3e1c36cb1b8d93Adrian Prantl DI->EmitLexicalBlockEnd(CGF.Builder, Range.getEnd()); 561efb72adbae0c253fc2fd9127fb3e1c36cb1b8d93Adrian Prantl 562495cfa46300979642acde8d93a1f21c9291dac98Nadav Rotem // If we should perform a cleanup, force them now. Note that 563495cfa46300979642acde8d93a1f21c9291dac98Nadav Rotem // this ends the cleanup scope before rescoping any labels. 5640e2c34f92f00628d48968dfea096d36381f494cbStephen Hines if (PerformCleanup) { 5650e2c34f92f00628d48968dfea096d36381f494cbStephen Hines ApplyDebugLocation DL(CGF, Range.getEnd()); 5660e2c34f92f00628d48968dfea096d36381f494cbStephen Hines ForceCleanup(); 5670e2c34f92f00628d48968dfea096d36381f494cbStephen Hines } 568c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher } 569c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher 570c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher /// \brief Force the emission of cleanups now, instead of waiting 571c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher /// until this object is destroyed. 572c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher void ForceCleanup() { 573efb72adbae0c253fc2fd9127fb3e1c36cb1b8d93Adrian Prantl CGF.CurLexicalScope = ParentScope; 574c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher RunCleanupsScope::ForceCleanup(); 575ed383135bcffdb8849418896b742fbca7fa2b787John McCall 576495cfa46300979642acde8d93a1f21c9291dac98Nadav Rotem if (!Labels.empty()) 577495cfa46300979642acde8d93a1f21c9291dac98Nadav Rotem rescopeLabels(); 578c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher } 579495cfa46300979642acde8d93a1f21c9291dac98Nadav Rotem 580495cfa46300979642acde8d93a1f21c9291dac98Nadav Rotem void rescopeLabels(); 581c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher }; 582c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher 58387d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar typedef llvm::DenseMap<const Decl *, Address> DeclMapTy; 58487d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar 585176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines /// \brief The scope used to remap some variables as private in the OpenMP 586176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines /// loop body (or other captured region emitted without outlining), and to 587176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines /// restore old vars back on exit. 588176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines class OMPPrivateScope : public RunCleanupsScope { 58987d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar DeclMapTy SavedLocals; 59087d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar DeclMapTy SavedPrivates; 591176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines 592176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines private: 5930e2c34f92f00628d48968dfea096d36381f494cbStephen Hines OMPPrivateScope(const OMPPrivateScope &) = delete; 5940e2c34f92f00628d48968dfea096d36381f494cbStephen Hines void operator=(const OMPPrivateScope &) = delete; 595176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines 596176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines public: 597176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines /// \brief Enter a new OpenMP private scope. 598176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines explicit OMPPrivateScope(CodeGenFunction &CGF) : RunCleanupsScope(CGF) {} 599176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines 600176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines /// \brief Registers \a LocalVD variable as a private and apply \a 601176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines /// PrivateGen function for it to generate corresponding private variable. 602176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines /// \a PrivateGen returns an address of the generated private variable. 603176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines /// \return true if the variable is registered as private, false if it has 604176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines /// been privatized already. 605176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines bool 606176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines addPrivate(const VarDecl *LocalVD, 60787d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar llvm::function_ref<Address()> PrivateGen) { 608176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines assert(PerformCleanup && "adding private to dead scope"); 60987d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar 61087d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar // Only save it once. 61187d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar if (SavedLocals.count(LocalVD)) return false; 61287d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar 61387d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar // Copy the existing local entry to SavedLocals. 61487d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar auto it = CGF.LocalDeclMap.find(LocalVD); 61587d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar if (it != CGF.LocalDeclMap.end()) { 61687d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar SavedLocals.insert({LocalVD, it->second}); 61787d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar } else { 61887d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar SavedLocals.insert({LocalVD, Address::invalid()}); 61987d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar } 62087d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar 62187d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar // Generate the private entry. 62287d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar Address Addr = PrivateGen(); 62387d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar QualType VarTy = LocalVD->getType(); 62487d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar if (VarTy->isReferenceType()) { 62587d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar Address Temp = CGF.CreateMemTemp(VarTy); 62687d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar CGF.Builder.CreateStore(Addr.getPointer(), Temp); 62787d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar Addr = Temp; 62887d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar } 62987d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar SavedPrivates.insert({LocalVD, Addr}); 63087d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar 631176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines return true; 632176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines } 633176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines 634176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines /// \brief Privatizes local variables previously registered as private. 635176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines /// Registration is separate from the actual privatization to allow 636176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines /// initializers use values of the original variables, not the private one. 637176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines /// This is important, for example, if the private variable is a class 638176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines /// variable initialized by a constructor that references other private 639176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines /// variables. But at initialization original variables must be used, not 640176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines /// private copies. 641176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines /// \return true if at least one variable was privatized, false otherwise. 642176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines bool Privatize() { 64387d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar copyInto(SavedPrivates, CGF.LocalDeclMap); 644176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines SavedPrivates.clear(); 645176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines return !SavedLocals.empty(); 646176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines } 647176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines 648176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines void ForceCleanup() { 649176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines RunCleanupsScope::ForceCleanup(); 65087d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar copyInto(SavedLocals, CGF.LocalDeclMap); 651176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines SavedLocals.clear(); 652176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines } 653176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines 654176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines /// \brief Exit scope - all the mapped variables are restored. 6553ea9e33ea25e0c2b12db56418ba3f994eb662c04Pirama Arumuga Nainar ~OMPPrivateScope() { 6563ea9e33ea25e0c2b12db56418ba3f994eb662c04Pirama Arumuga Nainar if (PerformCleanup) 6573ea9e33ea25e0c2b12db56418ba3f994eb662c04Pirama Arumuga Nainar ForceCleanup(); 6583ea9e33ea25e0c2b12db56418ba3f994eb662c04Pirama Arumuga Nainar } 65987d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar 6604967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar /// Checks if the global variable is captured in current function. 6614967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar bool isGlobalVarCaptured(const VarDecl *VD) const { 6624967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar return !VD->isLocalVarDeclOrParm() && CGF.LocalDeclMap.count(VD) > 0; 6634967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar } 6644967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar 66587d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar private: 66687d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// Copy all the entries in the source map over the corresponding 66787d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// entries in the destination, which must exist. 66887d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar static void copyInto(const DeclMapTy &src, DeclMapTy &dest) { 66987d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar for (auto &pair : src) { 67087d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar if (!pair.second.isValid()) { 67187d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar dest.erase(pair.first); 67287d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar continue; 67387d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar } 67487d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar 67587d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar auto it = dest.find(pair.first); 67687d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar if (it != dest.end()) { 67787d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar it->second = pair.second; 67887d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar } else { 67987d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar dest.insert(pair); 68087d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar } 68187d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar } 68287d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar } 683176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines }; 68444ec82b4a1597802f5bf17721481b8c265bc8dc5Anders Carlsson 6858a07cd3f59a0ede54906bdc8ed21724815db27adRichard Smith /// \brief Takes the old cleanup stack size and emits the cleanup blocks 6868a07cd3f59a0ede54906bdc8ed21724815db27adRichard Smith /// that have been added. 6871c3db769249a633108dc320da87c48a432e2bcc1Adrian Prantl void PopCleanupBlocks(EHScopeStack::stable_iterator OldCleanupStackSize); 68844ec82b4a1597802f5bf17721481b8c265bc8dc5Anders Carlsson 6898a07cd3f59a0ede54906bdc8ed21724815db27adRichard Smith /// \brief Takes the old cleanup stack size and emits the cleanup blocks 6908a07cd3f59a0ede54906bdc8ed21724815db27adRichard Smith /// that have been added, then adds all lifetime-extended cleanups from 6918a07cd3f59a0ede54906bdc8ed21724815db27adRichard Smith /// the given position to the stack. 6928a07cd3f59a0ede54906bdc8ed21724815db27adRichard Smith void PopCleanupBlocks(EHScopeStack::stable_iterator OldCleanupStackSize, 6938a07cd3f59a0ede54906bdc8ed21724815db27adRichard Smith size_t OldLifetimeExtendedStackSize); 6948a07cd3f59a0ede54906bdc8ed21724815db27adRichard Smith 695ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall void ResolveBranchFixups(llvm::BasicBlock *Target); 696ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall 697f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// The given basic block lies in the current EH scope, but may be a 698f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// target of a potentially scope-crossing jump; get a stable handle 699f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// to which we can perform this jump later. 700ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall JumpDest getJumpDestInCurrentScope(llvm::BasicBlock *Target) { 701413e67778d593215d2f2161a4e712c8568f1ddd0John McCall return JumpDest(Target, 702413e67778d593215d2f2161a4e712c8568f1ddd0John McCall EHStack.getInnermostNormalCleanup(), 703413e67778d593215d2f2161a4e712c8568f1ddd0John McCall NextCleanupDestIndex++); 704f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall } 705c71c845fe77ee1f891d60232ec320912d88557eeAnders Carlsson 706f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// The given basic block lies in the current EH scope, but may be a 707f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// target of a potentially scope-crossing jump; get a stable handle 708f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// to which we can perform this jump later. 709686775deca8b8685eb90801495880e3abdd844c2Chris Lattner JumpDest getJumpDestInCurrentScope(StringRef Name = StringRef()) { 710ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall return getJumpDestInCurrentScope(createBasicBlock(Name)); 711f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall } 712f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 713f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// EmitBranchThroughCleanup - Emit a branch from the current insert 714f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// block through the normal cleanup handling code (if any) and then 715f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// on to \arg Dest. 716f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall void EmitBranchThroughCleanup(JumpDest Dest); 717b11f9198111796ada02b57f62cdea92134fde9f7Chris Lattner 718b11f9198111796ada02b57f62cdea92134fde9f7Chris Lattner /// isObviouslyBranchWithoutCleanups - Return true if a branch to the 719b11f9198111796ada02b57f62cdea92134fde9f7Chris Lattner /// specified destination obviously has no cleanups to run. 'false' is always 720b11f9198111796ada02b57f62cdea92134fde9f7Chris Lattner /// a conservatively correct answer for this method. 721b11f9198111796ada02b57f62cdea92134fde9f7Chris Lattner bool isObviouslyBranchWithoutCleanups(JumpDest Dest) const; 722f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 723777d6e56ad9b1fed9866daf3ee6486d85c5b7d32John McCall /// popCatchScope - Pops the catch scope at the top of the EHScope 724777d6e56ad9b1fed9866daf3ee6486d85c5b7d32John McCall /// stack, emitting any required code (other than the catch handlers 725777d6e56ad9b1fed9866daf3ee6486d85c5b7d32John McCall /// themselves). 726777d6e56ad9b1fed9866daf3ee6486d85c5b7d32John McCall void popCatchScope(); 727ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall 728c686004145b1f4dbeb38173a0886ba7040ae0089David Chisnall llvm::BasicBlock *getEHResumeBlock(bool isCleanup); 729777d6e56ad9b1fed9866daf3ee6486d85c5b7d32John McCall llvm::BasicBlock *getEHDispatchBlock(EHScopeStack::stable_iterator scope); 73087d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar llvm::BasicBlock *getMSVCDispatchBlock(EHScopeStack::stable_iterator scope); 7310dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 732150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall /// An object to manage conditionally-evaluated expressions. 733150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall class ConditionalEvaluation { 734150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall llvm::BasicBlock *StartBB; 7351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 736150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall public: 737150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall ConditionalEvaluation(CodeGenFunction &CGF) 738150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall : StartBB(CGF.Builder.GetInsertBlock()) {} 7399cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer 740150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall void begin(CodeGenFunction &CGF) { 741150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall assert(CGF.OutermostConditional != this); 742150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall if (!CGF.OutermostConditional) 743150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall CGF.OutermostConditional = this; 744150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall } 745150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall 746150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall void end(CodeGenFunction &CGF) { 7476bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines assert(CGF.OutermostConditional != nullptr); 748150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall if (CGF.OutermostConditional == this) 7496bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines CGF.OutermostConditional = nullptr; 750150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall } 751150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall 752150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall /// Returns a block which will be executed prior to each 753150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall /// evaluation of the conditional code. 754150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall llvm::BasicBlock *getStartingBlock() const { 755150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall return StartBB; 756150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall } 757150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall }; 7581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7593019c444c672938c57f5573840071ecd73425ee7John McCall /// isInConditionalBranch - Return true if we're currently emitting 7603019c444c672938c57f5573840071ecd73425ee7John McCall /// one branch or the other of a conditional expression. 7616bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines bool isInConditionalBranch() const { return OutermostConditional != nullptr; } 762150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall 76387d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar void setBeforeOutermostConditional(llvm::Value *value, Address addr) { 7646f103ba42cb69d50005a977c5ea583984ab63fc4John McCall assert(isInConditionalBranch()); 7656f103ba42cb69d50005a977c5ea583984ab63fc4John McCall llvm::BasicBlock *block = OutermostConditional->getStartingBlock(); 76687d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar auto store = new llvm::StoreInst(value, addr.getPointer(), &block->back()); 76787d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar store->setAlignment(addr.getAlignment().getQuantity()); 7686f103ba42cb69d50005a977c5ea583984ab63fc4John McCall } 7696f103ba42cb69d50005a977c5ea583984ab63fc4John McCall 770150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall /// An RAII object to record that we're evaluating a statement 771150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall /// expression. 772150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall class StmtExprEvaluation { 773150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall CodeGenFunction &CGF; 774150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall 775150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall /// We have to save the outermost conditional: cleanups in a 776150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall /// statement expression aren't conditional just because the 777150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall /// StmtExpr is. 778150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall ConditionalEvaluation *SavedOutermostConditional; 779150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall 780150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall public: 781150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall StmtExprEvaluation(CodeGenFunction &CGF) 782150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall : CGF(CGF), SavedOutermostConditional(CGF.OutermostConditional) { 7836bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines CGF.OutermostConditional = nullptr; 784150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall } 785150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall 786150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall ~StmtExprEvaluation() { 787150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall CGF.OutermostConditional = SavedOutermostConditional; 788150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall CGF.EnsureInsertPoint(); 789150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall } 790150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall }; 791e996ffd240f20a1048179d7727a6ee3227261921John McCall 79256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// An object which temporarily prevents a value from being 79356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// destroyed by aggressive peephole optimizations that assume that 79456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// all uses of a value have been realized in the IR. 79556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall class PeepholeProtection { 79656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall llvm::Instruction *Inst; 79756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall friend class CodeGenFunction; 79856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 79956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall public: 8006bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines PeepholeProtection() : Inst(nullptr) {} 8014b9c2d235fb9449e249d74f48ecfec601650de93John McCall }; 80256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 8034b9c2d235fb9449e249d74f48ecfec601650de93John McCall /// A non-RAII class containing all the information about a bound 8044b9c2d235fb9449e249d74f48ecfec601650de93John McCall /// opaque value. OpaqueValueMapping, below, is a RAII wrapper for 8054b9c2d235fb9449e249d74f48ecfec601650de93John McCall /// this which makes individual mappings very simple; using this 8064b9c2d235fb9449e249d74f48ecfec601650de93John McCall /// class directly is useful when you have a variable number of 8074b9c2d235fb9449e249d74f48ecfec601650de93John McCall /// opaque values or don't want the RAII functionality for some 8084b9c2d235fb9449e249d74f48ecfec601650de93John McCall /// reason. 8094b9c2d235fb9449e249d74f48ecfec601650de93John McCall class OpaqueValueMappingData { 810e996ffd240f20a1048179d7727a6ee3227261921John McCall const OpaqueValueExpr *OpaqueValue; 81156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall bool BoundLValue; 81256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall CodeGenFunction::PeepholeProtection Protection; 813e996ffd240f20a1048179d7727a6ee3227261921John McCall 8144b9c2d235fb9449e249d74f48ecfec601650de93John McCall OpaqueValueMappingData(const OpaqueValueExpr *ov, 8154b9c2d235fb9449e249d74f48ecfec601650de93John McCall bool boundLValue) 8164b9c2d235fb9449e249d74f48ecfec601650de93John McCall : OpaqueValue(ov), BoundLValue(boundLValue) {} 817e996ffd240f20a1048179d7727a6ee3227261921John McCall public: 8186bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines OpaqueValueMappingData() : OpaqueValue(nullptr) {} 8194b9c2d235fb9449e249d74f48ecfec601650de93John McCall 82056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall static bool shouldBindAsLValue(const Expr *expr) { 821a5493f885095bd63d525a7035ad1c224de3ae5f2John McCall // gl-values should be bound as l-values for obvious reasons. 822a5493f885095bd63d525a7035ad1c224de3ae5f2John McCall // Records should be bound as l-values because IR generation 823a5493f885095bd63d525a7035ad1c224de3ae5f2John McCall // always keeps them in memory. Expressions of function type 824a5493f885095bd63d525a7035ad1c224de3ae5f2John McCall // act exactly like l-values but are formally required to be 825a5493f885095bd63d525a7035ad1c224de3ae5f2John McCall // r-values in C. 826a5493f885095bd63d525a7035ad1c224de3ae5f2John McCall return expr->isGLValue() || 827651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines expr->getType()->isFunctionType() || 828651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines hasAggregateEvaluationKind(expr->getType()); 82956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 83056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 8314b9c2d235fb9449e249d74f48ecfec601650de93John McCall static OpaqueValueMappingData bind(CodeGenFunction &CGF, 8324b9c2d235fb9449e249d74f48ecfec601650de93John McCall const OpaqueValueExpr *ov, 8334b9c2d235fb9449e249d74f48ecfec601650de93John McCall const Expr *e) { 8344b9c2d235fb9449e249d74f48ecfec601650de93John McCall if (shouldBindAsLValue(ov)) 8354b9c2d235fb9449e249d74f48ecfec601650de93John McCall return bind(CGF, ov, CGF.EmitLValue(e)); 8364b9c2d235fb9449e249d74f48ecfec601650de93John McCall return bind(CGF, ov, CGF.EmitAnyExpr(e)); 8374b9c2d235fb9449e249d74f48ecfec601650de93John McCall } 8384b9c2d235fb9449e249d74f48ecfec601650de93John McCall 8394b9c2d235fb9449e249d74f48ecfec601650de93John McCall static OpaqueValueMappingData bind(CodeGenFunction &CGF, 8404b9c2d235fb9449e249d74f48ecfec601650de93John McCall const OpaqueValueExpr *ov, 8414b9c2d235fb9449e249d74f48ecfec601650de93John McCall const LValue &lv) { 8424b9c2d235fb9449e249d74f48ecfec601650de93John McCall assert(shouldBindAsLValue(ov)); 8434b9c2d235fb9449e249d74f48ecfec601650de93John McCall CGF.OpaqueLValues.insert(std::make_pair(ov, lv)); 8444b9c2d235fb9449e249d74f48ecfec601650de93John McCall return OpaqueValueMappingData(ov, true); 8454b9c2d235fb9449e249d74f48ecfec601650de93John McCall } 8464b9c2d235fb9449e249d74f48ecfec601650de93John McCall 8474b9c2d235fb9449e249d74f48ecfec601650de93John McCall static OpaqueValueMappingData bind(CodeGenFunction &CGF, 8484b9c2d235fb9449e249d74f48ecfec601650de93John McCall const OpaqueValueExpr *ov, 8494b9c2d235fb9449e249d74f48ecfec601650de93John McCall const RValue &rv) { 8504b9c2d235fb9449e249d74f48ecfec601650de93John McCall assert(!shouldBindAsLValue(ov)); 8514b9c2d235fb9449e249d74f48ecfec601650de93John McCall CGF.OpaqueRValues.insert(std::make_pair(ov, rv)); 8524b9c2d235fb9449e249d74f48ecfec601650de93John McCall 8534b9c2d235fb9449e249d74f48ecfec601650de93John McCall OpaqueValueMappingData data(ov, false); 8544b9c2d235fb9449e249d74f48ecfec601650de93John McCall 8554b9c2d235fb9449e249d74f48ecfec601650de93John McCall // Work around an extremely aggressive peephole optimization in 8564b9c2d235fb9449e249d74f48ecfec601650de93John McCall // EmitScalarConversion which assumes that all other uses of a 8574b9c2d235fb9449e249d74f48ecfec601650de93John McCall // value are extant. 8584b9c2d235fb9449e249d74f48ecfec601650de93John McCall data.Protection = CGF.protectFromPeepholes(rv); 8594b9c2d235fb9449e249d74f48ecfec601650de93John McCall 8604b9c2d235fb9449e249d74f48ecfec601650de93John McCall return data; 8614b9c2d235fb9449e249d74f48ecfec601650de93John McCall } 8624b9c2d235fb9449e249d74f48ecfec601650de93John McCall 8636bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines bool isValid() const { return OpaqueValue != nullptr; } 8646bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines void clear() { OpaqueValue = nullptr; } 8654b9c2d235fb9449e249d74f48ecfec601650de93John McCall 8664b9c2d235fb9449e249d74f48ecfec601650de93John McCall void unbind(CodeGenFunction &CGF) { 8674b9c2d235fb9449e249d74f48ecfec601650de93John McCall assert(OpaqueValue && "no data to unbind!"); 8684b9c2d235fb9449e249d74f48ecfec601650de93John McCall 8694b9c2d235fb9449e249d74f48ecfec601650de93John McCall if (BoundLValue) { 8704b9c2d235fb9449e249d74f48ecfec601650de93John McCall CGF.OpaqueLValues.erase(OpaqueValue); 8714b9c2d235fb9449e249d74f48ecfec601650de93John McCall } else { 8724b9c2d235fb9449e249d74f48ecfec601650de93John McCall CGF.OpaqueRValues.erase(OpaqueValue); 8734b9c2d235fb9449e249d74f48ecfec601650de93John McCall CGF.unprotectFromPeepholes(Protection); 8744b9c2d235fb9449e249d74f48ecfec601650de93John McCall } 8754b9c2d235fb9449e249d74f48ecfec601650de93John McCall } 8764b9c2d235fb9449e249d74f48ecfec601650de93John McCall }; 8774b9c2d235fb9449e249d74f48ecfec601650de93John McCall 8784b9c2d235fb9449e249d74f48ecfec601650de93John McCall /// An RAII object to set (and then clear) a mapping for an OpaqueValueExpr. 8794b9c2d235fb9449e249d74f48ecfec601650de93John McCall class OpaqueValueMapping { 8804b9c2d235fb9449e249d74f48ecfec601650de93John McCall CodeGenFunction &CGF; 8814b9c2d235fb9449e249d74f48ecfec601650de93John McCall OpaqueValueMappingData Data; 8824b9c2d235fb9449e249d74f48ecfec601650de93John McCall 8834b9c2d235fb9449e249d74f48ecfec601650de93John McCall public: 8844b9c2d235fb9449e249d74f48ecfec601650de93John McCall static bool shouldBindAsLValue(const Expr *expr) { 8854b9c2d235fb9449e249d74f48ecfec601650de93John McCall return OpaqueValueMappingData::shouldBindAsLValue(expr); 8864b9c2d235fb9449e249d74f48ecfec601650de93John McCall } 8874b9c2d235fb9449e249d74f48ecfec601650de93John McCall 88856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// Build the opaque value mapping for the given conditional 88956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// operator if it's the GNU ?: extension. This is a common 89056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// enough pattern that the convenience operator is really 89156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// helpful. 89256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// 89356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall OpaqueValueMapping(CodeGenFunction &CGF, 89456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall const AbstractConditionalOperator *op) : CGF(CGF) { 8954b9c2d235fb9449e249d74f48ecfec601650de93John McCall if (isa<ConditionalOperator>(op)) 8964b9c2d235fb9449e249d74f48ecfec601650de93John McCall // Leave Data empty. 89756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return; 89856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 89956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall const BinaryConditionalOperator *e = cast<BinaryConditionalOperator>(op); 9004b9c2d235fb9449e249d74f48ecfec601650de93John McCall Data = OpaqueValueMappingData::bind(CGF, e->getOpaqueValue(), 9014b9c2d235fb9449e249d74f48ecfec601650de93John McCall e->getCommon()); 90256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 90356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 904e996ffd240f20a1048179d7727a6ee3227261921John McCall OpaqueValueMapping(CodeGenFunction &CGF, 905e996ffd240f20a1048179d7727a6ee3227261921John McCall const OpaqueValueExpr *opaqueValue, 90656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall LValue lvalue) 9074b9c2d235fb9449e249d74f48ecfec601650de93John McCall : CGF(CGF), Data(OpaqueValueMappingData::bind(CGF, opaqueValue, lvalue)) { 90856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 90956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 91056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall OpaqueValueMapping(CodeGenFunction &CGF, 91156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall const OpaqueValueExpr *opaqueValue, 91256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall RValue rvalue) 9134b9c2d235fb9449e249d74f48ecfec601650de93John McCall : CGF(CGF), Data(OpaqueValueMappingData::bind(CGF, opaqueValue, rvalue)) { 914e996ffd240f20a1048179d7727a6ee3227261921John McCall } 915e996ffd240f20a1048179d7727a6ee3227261921John McCall 916e996ffd240f20a1048179d7727a6ee3227261921John McCall void pop() { 9174b9c2d235fb9449e249d74f48ecfec601650de93John McCall Data.unbind(CGF); 9184b9c2d235fb9449e249d74f48ecfec601650de93John McCall Data.clear(); 919e996ffd240f20a1048179d7727a6ee3227261921John McCall } 920e996ffd240f20a1048179d7727a6ee3227261921John McCall 921e996ffd240f20a1048179d7727a6ee3227261921John McCall ~OpaqueValueMapping() { 9224b9c2d235fb9449e249d74f48ecfec601650de93John McCall if (Data.isValid()) Data.unbind(CGF); 923e996ffd240f20a1048179d7727a6ee3227261921John McCall } 924e996ffd240f20a1048179d7727a6ee3227261921John McCall }; 925e220455a059d926953befe72857b9525273717efFariborz Jahanian 9267f02f721d48772e4eee4fccd8af4f800be1bbc1eChris Lattnerprivate: 927d9becd1846e2c72bf6ad283faa1b048f33dd3afeChris Lattner CGDebugInfo *DebugInfo; 928aa11289f754d220c9c155b68a4f84cdcfcefef6aDevang Patel bool DisableDebugInfo; 92909429b962811f2c0a7a81a1b0a89f96f5878b20cMike Stump 93093c332a8ba2c193c435b293966d343dab15f555bJohn McCall /// DidCallStackSave - Whether llvm.stacksave has been called. Used to avoid 93193c332a8ba2c193c435b293966d343dab15f555bJohn McCall /// calling llvm.stacksave for multiple VLAs in the same scope. 93293c332a8ba2c193c435b293966d343dab15f555bJohn McCall bool DidCallStackSave; 93393c332a8ba2c193c435b293966d343dab15f555bJohn McCall 934f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump /// IndirectBranch - The first time an indirect goto is seen we create a block 935f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump /// with an indirect branch. Every time we see the address of a label taken, 936f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump /// we add the label to the indirect goto. Every subsequent indirect goto is 937f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump /// codegen'd as a jump to the IndirectBranch's basic block. 938d9becd1846e2c72bf6ad283faa1b048f33dd3afeChris Lattner llvm::IndirectBrInst *IndirectBranch; 9390ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar 9400dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// LocalDeclMap - This keeps track of the LLVM allocas or globals for local C 9410dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// decls. 9426b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall DeclMapTy LocalDeclMap; 9435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 94487d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// SizeArguments - If a ParmVarDecl had the pass_object_size attribute, this 94587d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// will contain a mapping from said ParmVarDecl to its implicit "object_size" 94687d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// parameter. 94787d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar llvm::SmallDenseMap<const ParmVarDecl *, const ImplicitParamDecl *, 2> 94887d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar SizeArguments; 94987d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar 95058878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar /// Track escaped local variables with auto storage. Used during SEH 95187d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// outlining to produce a call to llvm.localescape. 95258878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar llvm::DenseMap<llvm::AllocaInst *, int> EscapedLocals; 95358878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar 9545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// LabelMap - This keeps track of the LLVM basic block for each C label. 955ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner llvm::DenseMap<const LabelDecl*, JumpDest> LabelMap; 9560dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 9570dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump // BreakContinueStack - This keeps track of where break and continue 958e4b6d342c29d5cb9d311756100df1603810fa892Anders Carlsson // statements should jump to. 959da13870e99fe33934b2122f06528a5063f78ae4cChris Lattner struct BreakContinue { 960f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall BreakContinue(JumpDest Break, JumpDest Continue) 961f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall : BreakBlock(Break), ContinueBlock(Continue) {} 9620dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 963f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall JumpDest BreakBlock; 964f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall JumpDest ContinueBlock; 9650dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump }; 966686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVector<BreakContinue, 8> BreakContinueStack; 96718ccc7776ad6288c5f630dc7967fb99d099c9cd9Daniel Dunbar 968651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines CodeGenPGO PGO; 969651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 970b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar /// Calculate branch weights appropriate for PGO data 971b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar llvm::MDNode *createProfileWeights(uint64_t TrueCount, uint64_t FalseCount); 972b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar llvm::MDNode *createProfileWeights(ArrayRef<uint64_t> Weights); 973b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar llvm::MDNode *createProfileWeightsForLoop(const Stmt *Cond, 974b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar uint64_t LoopCount); 975b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar 976651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinespublic: 977b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar /// Increment the profiler's counter for the given statement. 978b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar void incrementProfileCounter(const Stmt *S) { 9794967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar if (CGM.getCodeGenOpts().hasProfileClangInstr()) 980b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar PGO.emitCounterIncrement(Builder, S); 981b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar PGO.setCurrentStmt(S); 982b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar } 983b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar 984b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar /// Get the profiler's count for the given statement. 985b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar uint64_t getProfileCount(const Stmt *S) { 986b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar Optional<uint64_t> Count = PGO.getStmtCount(S); 987b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar if (!Count.hasValue()) 988b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar return 0; 989b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar return *Count; 990b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar } 991b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar 992b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar /// Set the profiler's current count. 993b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar void setCurrentProfileCount(uint64_t Count) { 994b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar PGO.setCurrentRegionCount(Count); 995b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar } 996b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar 997b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar /// Get the profiler's current count. This is generally the count for the most 998b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar /// recently incremented counter. 999b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar uint64_t getCurrentProfileCount() { 1000b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar return PGO.getCurrentRegionCount(); 1001651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines } 1002b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar 1003651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinesprivate: 1004651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 1005170fd49294b85ab10f820721d99ff9d109c7230dZhongxing Xu /// SwitchInsn - This is nearest current switch instruction. It is null if 10060dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// current context is not in a switch. 100751b09f2c528c8460b5465c676173324e44176d62Devang Patel llvm::SwitchInst *SwitchInsn; 1008651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines /// The branch weights of SwitchInsn when doing instrumentation based PGO. 1009651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines SmallVector<uint64_t, 16> *SwitchWeights; 101051b09f2c528c8460b5465c676173324e44176d62Devang Patel 10110dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// CaseRangeBlock - This block holds if condition check for last case 101280fd5f96e6805ac43aab99faabd5b4c8b19551b7Devang Patel /// statement range in current switch instruction. 1013c049e4f406a7f7179eba98659044a32508e53289Devang Patel llvm::BasicBlock *CaseRangeBlock; 1014c049e4f406a7f7179eba98659044a32508e53289Devang Patel 101556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// OpaqueLValues - Keeps track of the current set of opaque value 1016e996ffd240f20a1048179d7727a6ee3227261921John McCall /// expressions. 101756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall llvm::DenseMap<const OpaqueValueExpr *, LValue> OpaqueLValues; 101856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall llvm::DenseMap<const OpaqueValueExpr *, RValue> OpaqueRValues; 1019e996ffd240f20a1048179d7727a6ee3227261921John McCall 10200dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump // VLASizeMap - This keeps track of the associated size for each VLA type. 1021bbed6b964414145b29e7b60b3e538093734ea3f8Eli Friedman // We track this by the size expression rather than the type itself because 1022bbed6b964414145b29e7b60b3e538093734ea3f8Eli Friedman // in certain situations, like a const qualifier applied to an VLA typedef, 1023bbed6b964414145b29e7b60b3e538093734ea3f8Eli Friedman // multiple VLA types can share the same size expression. 10240dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump // FIXME: Maybe this could be a stack of maps that is pushed/popped as we 10250dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump // enter/leave scopes. 1026bbed6b964414145b29e7b60b3e538093734ea3f8Eli Friedman llvm::DenseMap<const Expr*, llvm::Value*> VLASizeMap; 10270dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 1028f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// A block containing a single 'unreachable' instruction. Created 1029f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// lazily by getUnreachableBlock(). 1030f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall llvm::BasicBlock *UnreachableBlock; 10310dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 1032d072e59eb6b5e32f93be25f08f212b0ec21d6c5dAdrian Prantl /// Counts of the number return expressions in the function. 1033d072e59eb6b5e32f93be25f08f212b0ec21d6c5dAdrian Prantl unsigned NumReturnExprs; 1034fa6b079b1231366696f6a497c6a084c73a35c85dAdrian Prantl 1035fa6b079b1231366696f6a497c6a084c73a35c85dAdrian Prantl /// Count the number of simple (constant) return expressions in the function. 1036fa6b079b1231366696f6a497c6a084c73a35c85dAdrian Prantl unsigned NumSimpleReturnExprs; 1037fa6b079b1231366696f6a497c6a084c73a35c85dAdrian Prantl 1038d072e59eb6b5e32f93be25f08f212b0ec21d6c5dAdrian Prantl /// The last regular (non-return) debug location (breakpoint) in the function. 1039d072e59eb6b5e32f93be25f08f212b0ec21d6c5dAdrian Prantl SourceLocation LastStopPoint; 1040fa6b079b1231366696f6a497c6a084c73a35c85dAdrian Prantl 1041c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smithpublic: 1042c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith /// A scope within which we are constructing the fields of an object which 1043c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith /// might use a CXXDefaultInitExpr. This stashes away a 'this' value to use 1044c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith /// if we need to evaluate a CXXDefaultInitExpr within the evaluation. 1045c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith class FieldConstructionScope { 1046c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith public: 104787d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar FieldConstructionScope(CodeGenFunction &CGF, Address This) 1048c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith : CGF(CGF), OldCXXDefaultInitExprThis(CGF.CXXDefaultInitExprThis) { 1049c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith CGF.CXXDefaultInitExprThis = This; 1050c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith } 1051c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith ~FieldConstructionScope() { 1052c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith CGF.CXXDefaultInitExprThis = OldCXXDefaultInitExprThis; 1053c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith } 1054c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith 1055c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith private: 1056c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith CodeGenFunction &CGF; 105787d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar Address OldCXXDefaultInitExprThis; 1058c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith }; 1059c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith 1060c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith /// The scope of a CXXDefaultInitExpr. Within this scope, the value of 'this' 1061c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith /// is overridden to be the object under construction. 1062c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith class CXXDefaultInitExprScope { 1063c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith public: 1064c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith CXXDefaultInitExprScope(CodeGenFunction &CGF) 106587d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar : CGF(CGF), OldCXXThisValue(CGF.CXXThisValue), 106687d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar OldCXXThisAlignment(CGF.CXXThisAlignment) { 106787d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar CGF.CXXThisValue = CGF.CXXDefaultInitExprThis.getPointer(); 106887d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar CGF.CXXThisAlignment = CGF.CXXDefaultInitExprThis.getAlignment(); 1069c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith } 1070c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith ~CXXDefaultInitExprScope() { 1071c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith CGF.CXXThisValue = OldCXXThisValue; 107287d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar CGF.CXXThisAlignment = OldCXXThisAlignment; 1073c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith } 1074c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith 1075c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith public: 1076c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith CodeGenFunction &CGF; 1077c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith llvm::Value *OldCXXThisValue; 107887d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar CharUnits OldCXXThisAlignment; 1079c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith }; 1080c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith 10814967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar class InlinedInheritingConstructorScope { 10824967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar public: 10834967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar InlinedInheritingConstructorScope(CodeGenFunction &CGF, GlobalDecl GD) 10844967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar : CGF(CGF), OldCurGD(CGF.CurGD), OldCurFuncDecl(CGF.CurFuncDecl), 10854967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar OldCurCodeDecl(CGF.CurCodeDecl), 10864967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar OldCXXABIThisDecl(CGF.CXXABIThisDecl), 10874967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar OldCXXABIThisValue(CGF.CXXABIThisValue), 10884967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar OldCXXThisValue(CGF.CXXThisValue), 10894967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar OldCXXABIThisAlignment(CGF.CXXABIThisAlignment), 10904967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar OldCXXThisAlignment(CGF.CXXThisAlignment), 10914967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar OldReturnValue(CGF.ReturnValue), OldFnRetTy(CGF.FnRetTy), 10924967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar OldCXXInheritedCtorInitExprArgs( 10934967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar std::move(CGF.CXXInheritedCtorInitExprArgs)) { 10944967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar CGF.CurGD = GD; 10954967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar CGF.CurFuncDecl = CGF.CurCodeDecl = 10964967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar cast<CXXConstructorDecl>(GD.getDecl()); 10974967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar CGF.CXXABIThisDecl = nullptr; 10984967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar CGF.CXXABIThisValue = nullptr; 10994967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar CGF.CXXThisValue = nullptr; 11004967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar CGF.CXXABIThisAlignment = CharUnits(); 11014967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar CGF.CXXThisAlignment = CharUnits(); 11024967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar CGF.ReturnValue = Address::invalid(); 11034967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar CGF.FnRetTy = QualType(); 11044967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar CGF.CXXInheritedCtorInitExprArgs.clear(); 11054967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar } 11064967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar ~InlinedInheritingConstructorScope() { 11074967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar CGF.CurGD = OldCurGD; 11084967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar CGF.CurFuncDecl = OldCurFuncDecl; 11094967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar CGF.CurCodeDecl = OldCurCodeDecl; 11104967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar CGF.CXXABIThisDecl = OldCXXABIThisDecl; 11114967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar CGF.CXXABIThisValue = OldCXXABIThisValue; 11124967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar CGF.CXXThisValue = OldCXXThisValue; 11134967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar CGF.CXXABIThisAlignment = OldCXXABIThisAlignment; 11144967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar CGF.CXXThisAlignment = OldCXXThisAlignment; 11154967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar CGF.ReturnValue = OldReturnValue; 11164967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar CGF.FnRetTy = OldFnRetTy; 11174967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar CGF.CXXInheritedCtorInitExprArgs = 11184967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar std::move(OldCXXInheritedCtorInitExprArgs); 11194967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar } 11204967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar 11214967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar private: 11224967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar CodeGenFunction &CGF; 11234967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar GlobalDecl OldCurGD; 11244967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar const Decl *OldCurFuncDecl; 11254967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar const Decl *OldCurCodeDecl; 11264967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar ImplicitParamDecl *OldCXXABIThisDecl; 11274967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar llvm::Value *OldCXXABIThisValue; 11284967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar llvm::Value *OldCXXThisValue; 11294967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar CharUnits OldCXXABIThisAlignment; 11304967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar CharUnits OldCXXThisAlignment; 11314967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar Address OldReturnValue; 11324967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar QualType OldFnRetTy; 11334967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar CallArgList OldCXXInheritedCtorInitExprArgs; 11344967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar }; 11354967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar 1136c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smithprivate: 1137f6c56e2323c3f973253805a2f35629f3253ebed4Anders Carlsson /// CXXThisDecl - When generating code for a C++ member function, 1138f6c56e2323c3f973253805a2f35629f3253ebed4Anders Carlsson /// this will hold the implicit 'this' declaration. 1139cec5ebd4a6a89a7023d04cec728fd340b541ed61Eli Friedman ImplicitParamDecl *CXXABIThisDecl; 1140cec5ebd4a6a89a7023d04cec728fd340b541ed61Eli Friedman llvm::Value *CXXABIThisValue; 11412504941793b549323f9d29c62507cf21d865fadeJohn McCall llvm::Value *CXXThisValue; 114287d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar CharUnits CXXABIThisAlignment; 114387d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar CharUnits CXXThisAlignment; 11441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1145c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith /// The value of 'this' to use when evaluating CXXDefaultInitExprs within 1146c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith /// this expression. 114787d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar Address CXXDefaultInitExprThis = Address::invalid(); 1148c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith 11494967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar /// The values of function arguments to use when evaluating 11504967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar /// CXXInheritedCtorInitExprs within this context. 11514967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar CallArgList CXXInheritedCtorInitExprArgs; 11524967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar 115359660c21178b6af518bd4b564e032d5c9cc218cbTimur Iskhodzhanov /// CXXStructorImplicitParamDecl - When generating code for a constructor or 115459660c21178b6af518bd4b564e032d5c9cc218cbTimur Iskhodzhanov /// destructor, this will hold the implicit argument (e.g. VTT). 115559660c21178b6af518bd4b564e032d5c9cc218cbTimur Iskhodzhanov ImplicitParamDecl *CXXStructorImplicitParamDecl; 115659660c21178b6af518bd4b564e032d5c9cc218cbTimur Iskhodzhanov llvm::Value *CXXStructorImplicitParamValue; 11579cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer 1158150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall /// OutermostConditional - Points to the outermost active 1159150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall /// conditional control. This is used so that we know if a 1160150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall /// temporary should be destroyed conditionally. 1161150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall ConditionalEvaluation *OutermostConditional; 11621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1163495cfa46300979642acde8d93a1f21c9291dac98Nadav Rotem /// The current lexical scope. 1164495cfa46300979642acde8d93a1f21c9291dac98Nadav Rotem LexicalScope *CurLexicalScope; 11657dfa4079f4b37507048b19bfc693d3b015d9dd11Anders Carlsson 11661c3db769249a633108dc320da87c48a432e2bcc1Adrian Prantl /// The current source location that should be used for exception 11671c3db769249a633108dc320da87c48a432e2bcc1Adrian Prantl /// handling code. 11681c3db769249a633108dc320da87c48a432e2bcc1Adrian Prantl SourceLocation CurEHLocation; 11691c3db769249a633108dc320da87c48a432e2bcc1Adrian Prantl 117087d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// BlockByrefInfos - For each __block variable, contains 117187d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// information about the layout of the variable. 117287d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar llvm::DenseMap<const ValueDecl *, BlockByrefInfo> BlockByrefInfos; 11739cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer 1174f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall llvm::BasicBlock *TerminateLandingPad; 1175182f383db1782af752ecaf607fdff72a8542088bMike Stump llvm::BasicBlock *TerminateHandler; 117683252dcfe61aaebcb6bc117e71dc12968729513fChris Lattner llvm::BasicBlock *TrapBB; 1177940670512d7c3d93389bb38a426abcb7ef44271eEli Friedman 11780df579ec000ffe52e0cddf1e7ee5e50a55256835Tanya Lattner /// Add a kernel metadata node to the named metadata node 'opencl.kernels'. 11790df579ec000ffe52e0cddf1e7ee5e50a55256835Tanya Lattner /// In the kernel metadata node, reference the kernel function and metadata 11800df579ec000ffe52e0cddf1e7ee5e50a55256835Tanya Lattner /// nodes for its optional attribute qualifiers (OpenCL 1.1 6.7.2): 118137453b9580e293eef3bd60bd36047a93ac4515b1Joey Gouly /// - A node for the vec_type_hint(<type>) qualifier contains string 118237453b9580e293eef3bd60bd36047a93ac4515b1Joey Gouly /// "vec_type_hint", an undefined value of the <type> data type, 118337453b9580e293eef3bd60bd36047a93ac4515b1Joey Gouly /// and a Boolean that is true if the <type> is integer and signed. 11840df579ec000ffe52e0cddf1e7ee5e50a55256835Tanya Lattner /// - A node for the work_group_size_hint(X,Y,Z) qualifier contains string 11850df579ec000ffe52e0cddf1e7ee5e50a55256835Tanya Lattner /// "work_group_size_hint", and three 32-bit integers X, Y and Z. 11860df579ec000ffe52e0cddf1e7ee5e50a55256835Tanya Lattner /// - A node for the reqd_work_group_size(X,Y,Z) qualifier contains string 11870df579ec000ffe52e0cddf1e7ee5e50a55256835Tanya Lattner /// "reqd_work_group_size", and three 32-bit integers X, Y and Z. 11880df579ec000ffe52e0cddf1e7ee5e50a55256835Tanya Lattner void EmitOpenCLKernelMetadata(const FunctionDecl *FD, 11890df579ec000ffe52e0cddf1e7ee5e50a55256835Tanya Lattner llvm::Function *Fn); 11900df579ec000ffe52e0cddf1e7ee5e50a55256835Tanya Lattner 11915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 11924904bf4e84cfb48080270ebaa9005327f18ab0e5Fariborz Jahanian CodeGenFunction(CodeGenModule &cgm, bool suppressNewContext=false); 11931a343ebbf413e8eae6b2737b2b2d79cbf5765571John McCall ~CodeGenFunction(); 11940dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 11951e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall CodeGenTypes &getTypes() const { return CGM.getTypes(); } 1196f2aac84709c418189e476ad591848dad50291885John McCall ASTContext &getContext() const { return CGM.getContext(); } 1197aa11289f754d220c9c155b68a4f84cdcfcefef6aDevang Patel CGDebugInfo *getDebugInfo() { 1198aa11289f754d220c9c155b68a4f84cdcfcefef6aDevang Patel if (DisableDebugInfo) 11996bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines return nullptr; 1200aa11289f754d220c9c155b68a4f84cdcfcefef6aDevang Patel return DebugInfo; 1201aa11289f754d220c9c155b68a4f84cdcfcefef6aDevang Patel } 1202aa11289f754d220c9c155b68a4f84cdcfcefef6aDevang Patel void disableDebugInfo() { DisableDebugInfo = true; } 1203aa11289f754d220c9c155b68a4f84cdcfcefef6aDevang Patel void enableDebugInfo() { DisableDebugInfo = false; } 1204aa11289f754d220c9c155b68a4f84cdcfcefef6aDevang Patel 1205f85e193739c953358c865005855253af4f68a497John McCall bool shouldUseFusedARCCalls() { 1206f85e193739c953358c865005855253af4f68a497John McCall return CGM.getCodeGenOpts().OptimizationLevel == 0; 1207f85e193739c953358c865005855253af4f68a497John McCall } 12085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 12094e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie const LangOptions &getLangOpts() const { return CGM.getLangOpts(); } 1210d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall 1211285cfd8953d4ca4da613a47a0d691f7234068f8cBill Wendling /// Returns a pointer to the function's exception object and selector slot, 1212285cfd8953d4ca4da613a47a0d691f7234068f8cBill Wendling /// which is assigned in every landing pad. 121387d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar Address getExceptionSlot(); 121487d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar Address getEHSelectorSlot(); 1215f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 1216ae270598d5c7a9a283d4b3ddce53b151c6e2b182Bill Wendling /// Returns the contents of the function's exception object and selector 1217ae270598d5c7a9a283d4b3ddce53b151c6e2b182Bill Wendling /// slots. 1218ae270598d5c7a9a283d4b3ddce53b151c6e2b182Bill Wendling llvm::Value *getExceptionFromSlot(); 1219ae270598d5c7a9a283d4b3ddce53b151c6e2b182Bill Wendling llvm::Value *getSelectorFromSlot(); 1220ae270598d5c7a9a283d4b3ddce53b151c6e2b182Bill Wendling 122187d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar Address getNormalCleanupDestSlot(); 1222ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall 1223f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall llvm::BasicBlock *getUnreachableBlock() { 1224f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall if (!UnreachableBlock) { 1225f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall UnreachableBlock = createBasicBlock("unreachable"); 1226f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall new llvm::UnreachableInst(getLLVMContext(), UnreachableBlock); 1227f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall } 1228f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall return UnreachableBlock; 1229f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall } 1230f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 1231f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall llvm::BasicBlock *getInvokeDest() { 12326bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines if (!EHStack.requiresLandingPad()) return nullptr; 1233f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall return getInvokeDestImpl(); 1234f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall } 12359834ffbe54788239c8361d3cfe5826fd277ddfb2Daniel Dunbar 12364967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar bool currentFunctionUsesSEHTry() const { return CurSEHParent != nullptr; } 12370e2c34f92f00628d48968dfea096d36381f494cbStephen Hines 123864aa4b3ec7e62288e2e66c1935487ece995ca94bJohn McCall const TargetInfo &getTarget() const { return Target; } 1239d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall llvm::LLVMContext &getLLVMContext() { return CGM.getLLVMContext(); } 124069243825cb5c91ec7207256aa57ae327cfaf8cb2Owen Anderson 12419834ffbe54788239c8361d3cfe5826fd277ddfb2Daniel Dunbar //===--------------------------------------------------------------------===// 1242bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall // Cleanups 1243bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall //===--------------------------------------------------------------------===// 1244bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall 124587d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar typedef void Destroyer(CodeGenFunction &CGF, Address addr, QualType ty); 1246bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall 12472673c68aa58e277ebc755b71d81aca618cdedbf9John McCall void pushIrregularPartialArrayCleanup(llvm::Value *arrayBegin, 124887d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar Address arrayEndPointer, 12492673c68aa58e277ebc755b71d81aca618cdedbf9John McCall QualType elementType, 125087d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar CharUnits elementAlignment, 1251516bbd42e62d709013824d6fb8445a0cfda3129aPeter Collingbourne Destroyer *destroyer); 12522673c68aa58e277ebc755b71d81aca618cdedbf9John McCall void pushRegularPartialArrayCleanup(llvm::Value *arrayBegin, 12532673c68aa58e277ebc755b71d81aca618cdedbf9John McCall llvm::Value *arrayEnd, 12542673c68aa58e277ebc755b71d81aca618cdedbf9John McCall QualType elementType, 125587d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar CharUnits elementAlignment, 1256516bbd42e62d709013824d6fb8445a0cfda3129aPeter Collingbourne Destroyer *destroyer); 1257bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall 12589928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall void pushDestroy(QualType::DestructionKind dtorKind, 125987d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar Address addr, QualType type); 1260074cae0861a87bf96d8ea56d02e34839d9ccbd0aJohn McCall void pushEHDestroy(QualType::DestructionKind dtorKind, 126187d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar Address addr, QualType type); 126287d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar void pushDestroy(CleanupKind kind, Address addr, QualType type, 1263516bbd42e62d709013824d6fb8445a0cfda3129aPeter Collingbourne Destroyer *destroyer, bool useEHCleanupForArray); 126487d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar void pushLifetimeExtendedDestroy(CleanupKind kind, Address addr, 12658a07cd3f59a0ede54906bdc8ed21724815db27adRichard Smith QualType type, Destroyer *destroyer, 12668a07cd3f59a0ede54906bdc8ed21724815db27adRichard Smith bool useEHCleanupForArray); 1267176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines void pushCallObjectDeleteCleanup(const FunctionDecl *OperatorDelete, 1268176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines llvm::Value *CompletePtr, 1269176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines QualType ElementType); 127087d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar void pushStackRestore(CleanupKind kind, Address SPMem); 127187d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar void emitDestroy(Address addr, QualType type, Destroyer *destroyer, 12722673c68aa58e277ebc755b71d81aca618cdedbf9John McCall bool useEHCleanupForArray); 127387d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar llvm::Function *generateDestroyHelper(Address addr, QualType type, 1274516bbd42e62d709013824d6fb8445a0cfda3129aPeter Collingbourne Destroyer *destroyer, 1275c7971a9efdf9880448a69aabb5182c3c27eecf6dDavid Blaikie bool useEHCleanupForArray, 1276c7971a9efdf9880448a69aabb5182c3c27eecf6dDavid Blaikie const VarDecl *VD); 1277bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall void emitArrayDestroy(llvm::Value *begin, llvm::Value *end, 127887d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar QualType elementType, CharUnits elementAlign, 127987d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar Destroyer *destroyer, 1280fbf780a9d1dbb191fc40c8af967c590e08724b74John McCall bool checkZeroLength, bool useEHCleanup); 1281bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall 1282516bbd42e62d709013824d6fb8445a0cfda3129aPeter Collingbourne Destroyer *getDestroyer(QualType::DestructionKind destructionKind); 12839928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall 1284bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall /// Determines whether an EH cleanup is required to destroy a type 1285bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall /// with the given destruction kind. 1286bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall bool needsEHCleanup(QualType::DestructionKind kind) { 1287bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall switch (kind) { 1288bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall case QualType::DK_none: 1289bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall return false; 1290bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall case QualType::DK_cxx_destructor: 1291bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall case QualType::DK_objc_weak_lifetime: 12924e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie return getLangOpts().Exceptions; 1293bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall case QualType::DK_objc_strong_lifetime: 12944e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie return getLangOpts().Exceptions && 1295bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall CGM.getCodeGenOpts().ObjCAutoRefCountExceptions; 1296bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall } 1297bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall llvm_unreachable("bad destruction kind"); 1298bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall } 1299bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall 13009928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall CleanupKind getCleanupKind(QualType::DestructionKind kind) { 13019928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall return (needsEHCleanup(kind) ? NormalAndEHCleanup : NormalCleanup); 13029928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall } 13039928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall 1304bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall //===--------------------------------------------------------------------===// 13059834ffbe54788239c8361d3cfe5826fd277ddfb2Daniel Dunbar // Objective-C 13069834ffbe54788239c8361d3cfe5826fd277ddfb2Daniel Dunbar //===--------------------------------------------------------------------===// 13079834ffbe54788239c8361d3cfe5826fd277ddfb2Daniel Dunbar 1308391d77a26382dddf25da73e29fc1fa5aaaea4c6fChris Lattner void GenerateObjCMethod(const ObjCMethodDecl *OMD); 1309af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar 13100e2c34f92f00628d48968dfea096d36381f494cbStephen Hines void StartObjCMethod(const ObjCMethodDecl *MD, const ObjCContainerDecl *CD); 1311af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar 13120dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// GenerateObjCGetter - Synthesize an Objective-C property getter function. 1313fef30b55230064d334a669a065a1c9acdb87cdfeFariborz Jahanian void GenerateObjCGetter(ObjCImplementationDecl *IMP, 1314fef30b55230064d334a669a065a1c9acdb87cdfeFariborz Jahanian const ObjCPropertyImplDecl *PID); 13151e1f4871535f2cadcbf8c9af8cc48a2213192320John McCall void generateObjCGetterBody(const ObjCImplementationDecl *classImpl, 1316b6e5fe3cae9bf456f084c555c3ecc256f4181cc5Fariborz Jahanian const ObjCPropertyImplDecl *propImpl, 1317490a52b4947381879a47b4251db5fb81cdf5d02bFariborz Jahanian const ObjCMethodDecl *GetterMothodDecl, 1318b6e5fe3cae9bf456f084c555c3ecc256f4181cc5Fariborz Jahanian llvm::Constant *AtomicHelperFn); 13192846b97965e980ad2e7c8d444b82cc21d733a699Fariborz Jahanian 1320109dfc6ca6652f60c55ed0f2631aebf323d0200dFariborz Jahanian void GenerateObjCCtorDtorMethod(ObjCImplementationDecl *IMP, 1321109dfc6ca6652f60c55ed0f2631aebf323d0200dFariborz Jahanian ObjCMethodDecl *MD, bool ctor); 1322af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar 13230dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// GenerateObjCSetter - Synthesize an Objective-C property setter function 13240dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// for the given property. 1325fef30b55230064d334a669a065a1c9acdb87cdfeFariborz Jahanian void GenerateObjCSetter(ObjCImplementationDecl *IMP, 1326fef30b55230064d334a669a065a1c9acdb87cdfeFariborz Jahanian const ObjCPropertyImplDecl *PID); 132771c758d3f4ecc8b511e6ae4a7210486aa994c182John McCall void generateObjCSetterBody(const ObjCImplementationDecl *classImpl, 1328cd93b96bc51c255d104095bc6a6d8eac74a84b1eFariborz Jahanian const ObjCPropertyImplDecl *propImpl, 1329cd93b96bc51c255d104095bc6a6d8eac74a84b1eFariborz Jahanian llvm::Constant *AtomicHelperFn); 1330af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar 13314e7a1f7682d94811bd41fca8aefccc38f686db23Mike Stump //===--------------------------------------------------------------------===// 13324e7a1f7682d94811bd41fca8aefccc38f686db23Mike Stump // Block Bits 13334e7a1f7682d94811bd41fca8aefccc38f686db23Mike Stump //===--------------------------------------------------------------------===// 13344e7a1f7682d94811bd41fca8aefccc38f686db23Mike Stump 13356b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall llvm::Value *EmitBlockLiteral(const BlockExpr *); 13361a343ebbf413e8eae6b2737b2b2d79cbf5765571John McCall llvm::Value *EmitBlockLiteral(const CGBlockInfo &Info); 13371a343ebbf413e8eae6b2737b2b2d79cbf5765571John McCall static void destroyBlockInfos(CGBlockInfo *info); 13384e7a1f7682d94811bd41fca8aefccc38f686db23Mike Stump 1339564360be450b319aeafc26698be9811837bfb826Fariborz Jahanian llvm::Function *GenerateBlockFunction(GlobalDecl GD, 13406b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall const CGBlockInfo &Info, 134164bee65a3436e3f0c352fcfe2130676f3502cffeEli Friedman const DeclMapTy &ldm, 134264bee65a3436e3f0c352fcfe2130676f3502cffeEli Friedman bool IsLambdaConversionToBlock); 13434e7a1f7682d94811bd41fca8aefccc38f686db23Mike Stump 1344d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall llvm::Constant *GenerateCopyHelperFunction(const CGBlockInfo &blockInfo); 1345d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall llvm::Constant *GenerateDestroyHelperFunction(const CGBlockInfo &blockInfo); 134620abee6b95c4f5a61e471b4b616439280ca4a81bFariborz Jahanian llvm::Constant *GenerateObjCAtomicSetterCopyHelperFunction( 134720abee6b95c4f5a61e471b4b616439280ca4a81bFariborz Jahanian const ObjCPropertyImplDecl *PID); 134820abee6b95c4f5a61e471b4b616439280ca4a81bFariborz Jahanian llvm::Constant *GenerateObjCAtomicGetterCopyHelperFunction( 134920abee6b95c4f5a61e471b4b616439280ca4a81bFariborz Jahanian const ObjCPropertyImplDecl *PID); 1350cae40c4d448529fe65de3d87bdbe97d3b54b4d98Eli Friedman llvm::Value *EmitBlockCopyAndAutorelease(llvm::Value *Block, QualType Ty); 1351d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall 1352d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall void BuildBlockRelease(llvm::Value *DeclPtr, BlockFieldFlags flags); 1353d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall 13545af02db5a48476e0748f135369663080eae87c64John McCall class AutoVarEmission; 13555af02db5a48476e0748f135369663080eae87c64John McCall 13565af02db5a48476e0748f135369663080eae87c64John McCall void emitByrefStructureInit(const AutoVarEmission &emission); 13575af02db5a48476e0748f135369663080eae87c64John McCall void enterByrefCleanup(const AutoVarEmission &emission); 13585af02db5a48476e0748f135369663080eae87c64John McCall 135987d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar void setBlockContextParameter(const ImplicitParamDecl *D, unsigned argNum, 136087d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar llvm::Value *ptr); 136187d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar 136287d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar Address LoadBlockStruct(); 136387d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar Address GetAddrOfBlockDecl(const VarDecl *var, bool ByRef); 136487d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar 136587d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// BuildBlockByrefAddress - Computes the location of the 136687d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// data in a variable which is declared as __block. 136787d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar Address emitBlockByrefAddress(Address baseAddr, const VarDecl *V, 136887d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar bool followForward = true); 136987d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar Address emitBlockByrefAddress(Address baseAddr, 137087d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar const BlockByrefInfo &info, 137187d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar bool followForward, 137287d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar const llvm::Twine &name); 13734e7a1f7682d94811bd41fca8aefccc38f686db23Mike Stump 137487d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar const BlockByrefInfo &getBlockByrefInfo(const VarDecl *var); 1375dab514fc30242c7afd6c03956e46136c400fb0d3Mike Stump 13764967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar QualType BuildFunctionArgList(GlobalDecl GD, FunctionArgList &Args); 13774967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar 1378d26bc76c98006609002d9930f8840490e88ac5b5John McCall void GenerateCode(GlobalDecl GD, llvm::Function *Fn, 1379d26bc76c98006609002d9930f8840490e88ac5b5John McCall const CGFunctionInfo &FnInfo); 13806bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines /// \brief Emit code for the start of a function. 13816bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines /// \param Loc The location to be associated with the function. 13826bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines /// \param StartLoc The location of the function body. 1383f5ebf9bf1df10ac15ba32a4b24dfe171b7848c58John McCall void StartFunction(GlobalDecl GD, 1384f5ebf9bf1df10ac15ba32a4b24dfe171b7848c58John McCall QualType RetTy, 13857c086516f3cc9fba2733b1919973206c6ba4b171Daniel Dunbar llvm::Function *Fn, 1386d26bc76c98006609002d9930f8840490e88ac5b5John McCall const CGFunctionInfo &FnInfo, 13872284ac9ec80299fcdefae9a2787cf85105a0f203Daniel Dunbar const FunctionArgList &Args, 13886bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines SourceLocation Loc = SourceLocation(), 13896bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines SourceLocation StartLoc = SourceLocation()); 1390a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar 13919fc6a7774643a810c8501dae2323e863fefb623eJohn McCall void EmitConstructorBody(FunctionArgList &Args); 13929fc6a7774643a810c8501dae2323e863fefb623eJohn McCall void EmitDestructorBody(FunctionArgList &Args); 139356c00c4868831c9a137ca7b0e16d063cf986d110Lang Hames void emitImplicitAssignmentOperatorBody(FunctionArgList &Args); 13943cebc73895daccea85984d8881b5b45c8f8df9c6Richard Smith void EmitFunctionBody(FunctionArgList &Args, const Stmt *Body); 1395b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar void EmitBlockWithFallThrough(llvm::BasicBlock *BB, const Stmt *S); 1396a355e07454463b19829ac92ffd115a097faff0e0John McCall 1397d6992ab33b7113e1bd7af51c0c52d17c23706c01Faisal Vali void EmitForwardingCallToLambda(const CXXMethodDecl *LambdaCallOperator, 139864bee65a3436e3f0c352fcfe2130676f3502cffeEli Friedman CallArgList &CallArgs); 1399bd89f8c2caa9550e41daa1aa9bf30f0f1e0dfaf7Eli Friedman void EmitLambdaToBlockPointerBody(FunctionArgList &Args); 140064bee65a3436e3f0c352fcfe2130676f3502cffeEli Friedman void EmitLambdaBlockInvokeBody(); 140127dd7d962bbf774988bc5e59d04a7743ed503514Douglas Gregor void EmitLambdaDelegatingInvokeBody(const CXXMethodDecl *MD); 140227dd7d962bbf774988bc5e59d04a7743ed503514Douglas Gregor void EmitLambdaStaticInvokeFunction(const CXXMethodDecl *MD); 1403176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines void EmitAsanPrologueOrEpilogue(bool Prologue); 1404bd89f8c2caa9550e41daa1aa9bf30f0f1e0dfaf7Eli Friedman 14050e2c34f92f00628d48968dfea096d36381f494cbStephen Hines /// \brief Emit the unified return block, trying to avoid its emission when 14060e2c34f92f00628d48968dfea096d36381f494cbStephen Hines /// possible. 14070e2c34f92f00628d48968dfea096d36381f494cbStephen Hines /// \return The debug location of the user written return statement if the 14080e2c34f92f00628d48968dfea096d36381f494cbStephen Hines /// return block is is avoided. 14090e2c34f92f00628d48968dfea096d36381f494cbStephen Hines llvm::DebugLoc EmitReturnBlock(); 14101c1d6074f5a0296dd273362655b1b8f9057289e3Daniel Dunbar 14110dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// FinishFunction - Complete IR generation of the current function. It is 14120dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// legal to call this function even if there is no current insertion point. 1413af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar void FinishFunction(SourceLocation EndLoc=SourceLocation()); 141417b708d61827cd86278e9580b041dd6cbadf07d3Daniel Dunbar 14150e2c34f92f00628d48968dfea096d36381f494cbStephen Hines void StartThunk(llvm::Function *Fn, GlobalDecl GD, 14160e2c34f92f00628d48968dfea096d36381f494cbStephen Hines const CGFunctionInfo &FnInfo); 141793b717ac956f5c82f7895ed8874cbd514c6d0a4eHans Wennborg 1418176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines void EmitCallAndReturnForThunk(llvm::Value *Callee, const ThunkInfo *Thunk); 1419176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines 142087d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar void FinishThunk(); 142187d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar 1422176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines /// Emit a musttail call for a thunk with a potentially adjusted this pointer. 1423176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines void EmitMustTailThunk(const CXXMethodDecl *MD, llvm::Value *AdjustedThisPtr, 1424176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines llvm::Value *Callee); 142593b717ac956f5c82f7895ed8874cbd514c6d0a4eHans Wennborg 142687d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// Generate a thunk for the given method. 142787d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar void generateThunk(llvm::Function *Fn, const CGFunctionInfo &FnInfo, 1428d26bc76c98006609002d9930f8840490e88ac5b5John McCall GlobalDecl GD, const ThunkInfo &Thunk); 14299cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer 143087d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar llvm::Function *GenerateVarArgsThunk(llvm::Function *Fn, 143187d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar const CGFunctionInfo &FnInfo, 143287d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar GlobalDecl GD, const ThunkInfo &Thunk); 14337dcdf5ba9324a9577461eae302e88fdd52e310c5Eli Friedman 1434fb8cc253420e93cee33d29df5a2bdae6aaf16e39Douglas Gregor void EmitCtorPrologue(const CXXConstructorDecl *CD, CXXCtorType Type, 1435fb8cc253420e93cee33d29df5a2bdae6aaf16e39Douglas Gregor FunctionArgList &Args); 14361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1437b74ed087469db042325bad76fdf3ff6ed67dec09Eli Friedman void EmitInitializerForField(FieldDecl *Field, LValue LHS, Expr *Init, 1438b74ed087469db042325bad76fdf3ff6ed67dec09Eli Friedman ArrayRef<VarDecl *> ArrayIndexes); 1439b74ed087469db042325bad76fdf3ff6ed67dec09Eli Friedman 144087d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// Struct with all informations about dynamic [sub]class needed to set vptr. 144187d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar struct VPtr { 144287d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar BaseSubobject Base; 144387d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar const CXXRecordDecl *NearestVBase; 144487d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar CharUnits OffsetFromNearestVBase; 144587d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar const CXXRecordDecl *VTableClass; 144687d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar }; 144787d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar 144887d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// Initialize the vtable pointer of the given subobject. 144987d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar void InitializeVTablePointer(const VPtr &vptr); 145087d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar 145187d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar typedef llvm::SmallVector<VPtr, 4> VPtrsVector; 1452d103f9f9b401b419e756f8c1849683cd77586067Anders Carlsson 1453d103f9f9b401b419e756f8c1849683cd77586067Anders Carlsson typedef llvm::SmallPtrSet<const CXXRecordDecl *, 4> VisitedVirtualBasesSetTy; 145487d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar VPtrsVector getVTablePointers(const CXXRecordDecl *VTableClass); 145587d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar 145687d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar void getVTablePointers(BaseSubobject Base, const CXXRecordDecl *NearestVBase, 145787d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar CharUnits OffsetFromNearestVBase, 145887d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar bool BaseIsNonVirtualPrimaryBase, 145987d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar const CXXRecordDecl *VTableClass, 146087d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar VisitedVirtualBasesSetTy &VBases, VPtrsVector &vptrs); 146177a259c6dbf582949af8a243b472c0c7faa373a6Eli Friedman 1462603d6d12cc4cba1ef219a3d55c698c7c87f87adfAnders Carlsson void InitializeVTablePointers(const CXXRecordDecl *ClassDecl); 1463d103f9f9b401b419e756f8c1849683cd77586067Anders Carlsson 1464043fb9a1fc0609285f60f0f87e5a18195408f34cDan Gohman /// GetVTablePtr - Return the Value of the vtable pointer member pointed 1465043fb9a1fc0609285f60f0f87e5a18195408f34cDan Gohman /// to by This. 146687d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar llvm::Value *GetVTablePtr(Address This, llvm::Type *VTableTy, 146787d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar const CXXRecordDecl *VTableClass); 146887d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar 146987d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar enum CFITypeCheckKind { 147087d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar CFITCK_VCall, 147187d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar CFITCK_NVCall, 147287d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar CFITCK_DerivedCast, 147387d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar CFITCK_UnrelatedCast, 14744967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar CFITCK_ICall, 147587d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar }; 1476d103f9f9b401b419e756f8c1849683cd77586067Anders Carlsson 14773ea9e33ea25e0c2b12db56418ba3f994eb662c04Pirama Arumuga Nainar /// \brief Derived is the presumed address of an object of type T after a 14783ea9e33ea25e0c2b12db56418ba3f994eb662c04Pirama Arumuga Nainar /// cast. If T is a polymorphic class type, emit a check that the virtual 14793ea9e33ea25e0c2b12db56418ba3f994eb662c04Pirama Arumuga Nainar /// table for Derived belongs to a class derived from T. 14803ea9e33ea25e0c2b12db56418ba3f994eb662c04Pirama Arumuga Nainar void EmitVTablePtrCheckForCast(QualType T, llvm::Value *Derived, 148187d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar bool MayBeNull, CFITypeCheckKind TCK, 148287d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar SourceLocation Loc); 14833ea9e33ea25e0c2b12db56418ba3f994eb662c04Pirama Arumuga Nainar 14840e2c34f92f00628d48968dfea096d36381f494cbStephen Hines /// EmitVTablePtrCheckForCall - Virtual method MD is being called via VTable. 14850e2c34f92f00628d48968dfea096d36381f494cbStephen Hines /// If vptr CFI is enabled, emit a check that VTable is valid. 14864967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar void EmitVTablePtrCheckForCall(const CXXRecordDecl *RD, llvm::Value *VTable, 148787d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar CFITypeCheckKind TCK, SourceLocation Loc); 14889581ed07dee5376002620a0cfb363c6b9e5bdd3eBenjamin Kramer 14893ea9e33ea25e0c2b12db56418ba3f994eb662c04Pirama Arumuga Nainar /// EmitVTablePtrCheck - Emit a check that VTable is a valid virtual table for 14904967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar /// RD using llvm.type.test. 149187d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar void EmitVTablePtrCheck(const CXXRecordDecl *RD, llvm::Value *VTable, 149287d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar CFITypeCheckKind TCK, SourceLocation Loc); 14933ea9e33ea25e0c2b12db56418ba3f994eb662c04Pirama Arumuga Nainar 14944967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar /// If whole-program virtual table optimization is enabled, emit an assumption 14954967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar /// that VTable is a member of RD's type identifier. Or, if vptr CFI is 14964967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar /// enabled, emit a check that VTable is a member of RD's type identifier. 14974967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar void EmitTypeMetadataCodeForVCall(const CXXRecordDecl *RD, 14984967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar llvm::Value *VTable, SourceLocation Loc); 14994967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar 15004967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar /// Returns whether we should perform a type checked load when loading a 15014967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar /// virtual function for virtual calls to members of RD. This is generally 15024967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar /// true when both vcall CFI and whole-program-vtables are enabled. 15034967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar bool ShouldEmitVTableTypeCheckedLoad(const CXXRecordDecl *RD); 15044967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar 15054967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar /// Emit a type checked load from the given vtable. 15064967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar llvm::Value *EmitVTableTypeCheckedLoad(const CXXRecordDecl *RD, llvm::Value *VTable, 15074967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar uint64_t VTableByteOffset); 15084967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar 15099581ed07dee5376002620a0cfb363c6b9e5bdd3eBenjamin Kramer /// CanDevirtualizeMemberFunctionCalls - Checks whether virtual calls on given 15109581ed07dee5376002620a0cfb363c6b9e5bdd3eBenjamin Kramer /// expr can be devirtualized. 15119581ed07dee5376002620a0cfb363c6b9e5bdd3eBenjamin Kramer bool CanDevirtualizeMemberFunctionCall(const Expr *Base, 15129581ed07dee5376002620a0cfb363c6b9e5bdd3eBenjamin Kramer const CXXMethodDecl *MD); 15139581ed07dee5376002620a0cfb363c6b9e5bdd3eBenjamin Kramer 151450da2cadcc6da86abff6772de65280ace2cabc94John McCall /// EnterDtorCleanups - Enter the cleanups necessary to complete the 151550da2cadcc6da86abff6772de65280ace2cabc94John McCall /// given phase of destruction for a destructor. The end result 151650da2cadcc6da86abff6772de65280ace2cabc94John McCall /// should call destructors on members and base classes in reverse 151750da2cadcc6da86abff6772de65280ace2cabc94John McCall /// order of their construction. 151850da2cadcc6da86abff6772de65280ace2cabc94John McCall void EnterDtorCleanups(const CXXDestructorDecl *Dtor, CXXDtorType Type); 15191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 15207255a2d997b15beae82e627052fdb1b2474495c2Chris Lattner /// ShouldInstrumentFunction - Return true if the current function should be 15217255a2d997b15beae82e627052fdb1b2474495c2Chris Lattner /// instrumented with __cyg_profile_func_* calls 15227255a2d997b15beae82e627052fdb1b2474495c2Chris Lattner bool ShouldInstrumentFunction(); 15237255a2d997b15beae82e627052fdb1b2474495c2Chris Lattner 15244967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar /// ShouldXRayInstrument - Return true if the current function should be 15254967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar /// instrumented with XRay nop sleds. 15264967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar bool ShouldXRayInstrumentFunction() const; 15274967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar 15287255a2d997b15beae82e627052fdb1b2474495c2Chris Lattner /// EmitFunctionInstrumentation - Emit LLVM code to call the specified 15297255a2d997b15beae82e627052fdb1b2474495c2Chris Lattner /// instrumentation function with the current function and the call site, if 15307255a2d997b15beae82e627052fdb1b2474495c2Chris Lattner /// function instrumentation is enabled. 15317255a2d997b15beae82e627052fdb1b2474495c2Chris Lattner void EmitFunctionInstrumentation(const char *Fn); 15327255a2d997b15beae82e627052fdb1b2474495c2Chris Lattner 1533be4c8705e499b55548467eb7adaa23cbc6edfef9Roman Divacky /// EmitMCountInstrumentation - Emit call to .mcount. 1534be4c8705e499b55548467eb7adaa23cbc6edfef9Roman Divacky void EmitMCountInstrumentation(); 1535be4c8705e499b55548467eb7adaa23cbc6edfef9Roman Divacky 15360dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// EmitFunctionProlog - Emit the target specific LLVM code to load the 15370dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// arguments for the given function. This is also responsible for naming the 15380dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// LLVM function arguments. 153988b5396b0897f28d22ae3debf4a0d97b33b6c362Daniel Dunbar void EmitFunctionProlog(const CGFunctionInfo &FI, 154088b5396b0897f28d22ae3debf4a0d97b33b6c362Daniel Dunbar llvm::Function *Fn, 154117b708d61827cd86278e9580b041dd6cbadf07d3Daniel Dunbar const FunctionArgList &Args); 154217b708d61827cd86278e9580b041dd6cbadf07d3Daniel Dunbar 15430dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// EmitFunctionEpilog - Emit the target specific LLVM code to return the 15440dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// given temporary. 15454ee7dc2369c1f0257a73b2e83a7d38fdebdd9176Nick Lewycky void EmitFunctionEpilog(const CGFunctionInfo &FI, bool EmitRetDbgLoc, 15464ee7dc2369c1f0257a73b2e83a7d38fdebdd9176Nick Lewycky SourceLocation EndLoc); 154717b708d61827cd86278e9580b041dd6cbadf07d3Daniel Dunbar 1548cce3d4f9812182ed4e551b7cf0fc86576be8d9c5Mike Stump /// EmitStartEHSpec - Emit the start of the exception spec. 1549cce3d4f9812182ed4e551b7cf0fc86576be8d9c5Mike Stump void EmitStartEHSpec(const Decl *D); 1550cce3d4f9812182ed4e551b7cf0fc86576be8d9c5Mike Stump 1551cce3d4f9812182ed4e551b7cf0fc86576be8d9c5Mike Stump /// EmitEndEHSpec - Emit the end of the exception spec. 1552cce3d4f9812182ed4e551b7cf0fc86576be8d9c5Mike Stump void EmitEndEHSpec(const Decl *D); 1553cce3d4f9812182ed4e551b7cf0fc86576be8d9c5Mike Stump 1554f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// getTerminateLandingPad - Return a landing pad that just calls terminate. 1555f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall llvm::BasicBlock *getTerminateLandingPad(); 1556f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 1557f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// getTerminateHandler - Return a handler (not a landing pad, just 1558f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// a catch handler) that just calls terminate. This is used when 1559f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall /// a terminate scope encloses a try. 15609b39c51ae3c547568ac42325f94b4197618f6b18Mike Stump llvm::BasicBlock *getTerminateHandler(); 15619b39c51ae3c547568ac42325f94b4197618f6b18Mike Stump 15629cbe4f0ba01ec304e1e3d071c071f7bca33631c0Chris Lattner llvm::Type *ConvertTypeForMem(QualType T); 15639cbe4f0ba01ec304e1e3d071c071f7bca33631c0Chris Lattner llvm::Type *ConvertType(QualType T); 15649cbe4f0ba01ec304e1e3d071c071f7bca33631c0Chris Lattner llvm::Type *ConvertType(const TypeDecl *T) { 1565bff225ecf77fb891596ecb1b27196310d268365eJohn McCall return ConvertType(getContext().getTypeDeclType(T)); 1566bff225ecf77fb891596ecb1b27196310d268365eJohn McCall } 1567c8aa5f1f264fb230c38182adab944232bb160c2bChris Lattner 15680dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// LoadObjCSelf - Load the value of self. This function is only valid while 15690dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// generating code for an Objective-C method. 1570c8aa5f1f264fb230c38182adab944232bb160c2bChris Lattner llvm::Value *LoadObjCSelf(); 15710dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 15720dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// TypeOfSelfObject - Return type of object that this self represents. 157345012a7ef5abf1042c893f3f2fa5c23cb5485ea9Fariborz Jahanian QualType TypeOfSelfObject(); 15744111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner 15755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// hasAggregateLLVMType - Return true if the specified AST type will map into 15765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// an aggregate LLVM type or is void. 15779d232c884ea9872d6555df0fd7359699819bc1f1John McCall static TypeEvaluationKind getEvaluationKind(QualType T); 15789d232c884ea9872d6555df0fd7359699819bc1f1John McCall 15799d232c884ea9872d6555df0fd7359699819bc1f1John McCall static bool hasScalarEvaluationKind(QualType T) { 15809d232c884ea9872d6555df0fd7359699819bc1f1John McCall return getEvaluationKind(T) == TEK_Scalar; 15819d232c884ea9872d6555df0fd7359699819bc1f1John McCall } 15829d232c884ea9872d6555df0fd7359699819bc1f1John McCall 15839d232c884ea9872d6555df0fd7359699819bc1f1John McCall static bool hasAggregateEvaluationKind(QualType T) { 15849d232c884ea9872d6555df0fd7359699819bc1f1John McCall return getEvaluationKind(T) == TEK_Aggregate; 15859d232c884ea9872d6555df0fd7359699819bc1f1John McCall } 158655e874299f2ad827646a4ca9ea38c402aaeb38c9Daniel Dunbar 158755e874299f2ad827646a4ca9ea38c402aaeb38c9Daniel Dunbar /// createBasicBlock - Create an LLVM basic block. 15884def70d3040e73707c738f7c366737a986135edfRichard Smith llvm::BasicBlock *createBasicBlock(const Twine &name = "", 15896bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines llvm::Function *parent = nullptr, 15906bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines llvm::BasicBlock *before = nullptr) { 159129ea6729155c759836be4b5453bee9ef8e1e97eeDaniel Dunbar#ifdef NDEBUG 1592d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall return llvm::BasicBlock::Create(getLLVMContext(), "", parent, before); 159329ea6729155c759836be4b5453bee9ef8e1e97eeDaniel Dunbar#else 1594d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall return llvm::BasicBlock::Create(getLLVMContext(), name, parent, before); 159529ea6729155c759836be4b5453bee9ef8e1e97eeDaniel Dunbar#endif 159655e874299f2ad827646a4ca9ea38c402aaeb38c9Daniel Dunbar } 15970dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 15985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getBasicBlockForLabel - Return the LLVM basicblock that the specified 15995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// label maps to. 1600ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner JumpDest getJumpDestForLabel(const LabelDecl *S); 16010dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 1602f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump /// SimplifyForwardingBlocks - If the given basic block is only a branch to 1603f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump /// another basic block, simplify it. This assumes that no other code could 1604f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump /// potentially reference the basic block. 1605aa5bd87f1fd5f9ca47924248817c89325759b30eDaniel Dunbar void SimplifyForwardingBlocks(llvm::BasicBlock *BB); 1606aa5bd87f1fd5f9ca47924248817c89325759b30eDaniel Dunbar 16070dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// EmitBlock - Emit the given block \arg BB and set it as the insert point, 16080dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// adding a fall-through branch from the current insert block if 16090dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// necessary. It is legal to call this function even if there is no current 16100dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// insertion point. 1611a0c21a8faa79e88ac432d116eca58f7a7217195dDaniel Dunbar /// 16120dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// IsFinished - If true, indicates that the caller has finished emitting 16130dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// branches to the given block and does not expect to emit code into it. This 16140dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// means the block can be ignored if it is unreachable. 1615a0c21a8faa79e88ac432d116eca58f7a7217195dDaniel Dunbar void EmitBlock(llvm::BasicBlock *BB, bool IsFinished=false); 1616824e3bd76b2e32db2ec6e4d2d113413e518d1c63Daniel Dunbar 1617777d6e56ad9b1fed9866daf3ee6486d85c5b7d32John McCall /// EmitBlockAfterUses - Emit the given block somewhere hopefully 1618777d6e56ad9b1fed9866daf3ee6486d85c5b7d32John McCall /// near its uses, and leave the insertion point in it. 1619777d6e56ad9b1fed9866daf3ee6486d85c5b7d32John McCall void EmitBlockAfterUses(llvm::BasicBlock *BB); 1620777d6e56ad9b1fed9866daf3ee6486d85c5b7d32John McCall 16210dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// EmitBranch - Emit a branch to the specified basic block from the current 16220dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// insert block, taking care to avoid creation of branches from dummy 16230dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// blocks. It is legal to call this function even if there is no current 16240dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// insertion point. 16255e08ad3cc62ab94649959ae227a9a411a729bf49Daniel Dunbar /// 16260dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// This function clears the current insertion point. The caller should follow 16270dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// calls to this function with calls to Emit*Block prior to generation new 16280dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// code. 1629d57a871339c7c98d58d93108b806f59bdf4e13e2Daniel Dunbar void EmitBranch(llvm::BasicBlock *Block); 1630d57a871339c7c98d58d93108b806f59bdf4e13e2Daniel Dunbar 16310dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// HaveInsertPoint - True if an insertion point is defined. If not, this 16320dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// indicates that the current code being emitted is unreachable. 16330dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump bool HaveInsertPoint() const { 16346bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines return Builder.GetInsertBlock() != nullptr; 1635a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar } 1636a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar 16370dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// EnsureInsertPoint - Ensure that an insertion point is defined so that 16380dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// emitted IR has a place to go. Note that by definition, if this function 16390dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// creates a block then that block is unreachable; callers may do better to 16400dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// detect when no insertion point is defined and simply skip IR generation. 1641a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar void EnsureInsertPoint() { 1642a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar if (!HaveInsertPoint()) 1643a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar EmitBlock(createBasicBlock()); 1644a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar } 16450dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 1646488e993a135ce700b982bf099c3d6b856301d642Daniel Dunbar /// ErrorUnsupported - Print out an error that codegen doesn't support the 1647dc5e8268292046114ffe02e48773572a91a310f1Chris Lattner /// specified stmt yet. 16480a1c862914664029e3b6693e134cf3ccbf423844David Blaikie void ErrorUnsupported(const Stmt *S, const char *Type); 16495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 16505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 16515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Helpers 16525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 16530dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 165487d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar LValue MakeAddrLValue(Address Addr, QualType T, 165587d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar AlignmentSource AlignSource = AlignmentSource::Type) { 165687d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar return LValue::MakeAddr(Addr, T, getContext(), AlignSource, 16573d5aff5d3036b0ff09d114857cd2276134b3d8c9Dan Gohman CGM.getTBAAInfo(T)); 16582f77b3d57031ded0de2b7b977fb63b4660f82624Eli Friedman } 1659e0c1168ec7910a1a7ed08df4d4f0c58c2fa2ecd1John McCall 166087d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar LValue MakeAddrLValue(llvm::Value *V, QualType T, CharUnits Alignment, 166187d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar AlignmentSource AlignSource = AlignmentSource::Type) { 166287d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar return LValue::MakeAddr(Address(V, Alignment), T, getContext(), 166387d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar AlignSource, CGM.getTBAAInfo(T)); 166487d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar } 166587d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar 166687d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar LValue MakeNaturalAlignPointeeAddrLValue(llvm::Value *V, QualType T); 1667176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines LValue MakeNaturalAlignAddrLValue(llvm::Value *V, QualType T); 166887d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar CharUnits getNaturalTypeAlignment(QualType T, 166987d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar AlignmentSource *Source = nullptr, 167087d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar bool forPointeeType = false); 167187d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar CharUnits getNaturalPointeeTypeAlignment(QualType T, 167287d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar AlignmentSource *Source = nullptr); 167387d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar 167487d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar Address EmitLoadOfReference(Address Ref, const ReferenceType *RefTy, 167587d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar AlignmentSource *Source = nullptr); 167687d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar LValue EmitLoadOfReferenceLValue(Address Ref, const ReferenceType *RefTy); 16775cf8bfec711116b3c4acc70a00717b2e119e7550Daniel Dunbar 16784967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar Address EmitLoadOfPointer(Address Ptr, const PointerType *PtrTy, 16794967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar AlignmentSource *Source = nullptr); 16804967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar LValue EmitLoadOfPointerLValue(Address Ptr, const PointerType *PtrTy); 16814967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar 16825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// CreateTempAlloca - This creates a alloca and inserts it into the entry 1683195337d2e5d4625ae9dc1328c7cdbc7115b0261bDaniel Dunbar /// block. The caller is responsible for setting an appropriate alignment on 1684195337d2e5d4625ae9dc1328c7cdbc7115b0261bDaniel Dunbar /// the alloca. 16852acc6e3feda5e4f7d9009bdcf8b1cd777fecfe2dChris Lattner llvm::AllocaInst *CreateTempAlloca(llvm::Type *Ty, 16868cc488fefb2fb04bc8d5398da29f0182f97934cfChris Lattner const Twine &Name = "tmp"); 168787d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar Address CreateTempAlloca(llvm::Type *Ty, CharUnits align, 168887d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar const Twine &Name = "tmp"); 16890dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 169087d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// CreateDefaultAlignedTempAlloca - This creates an alloca with the 169187d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// default ABI alignment of the given LLVM type. 169287d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// 169387d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// IMPORTANT NOTE: This is *not* generally the right alignment for 169487d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// any given AST type that happens to have been lowered to the 169587d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// given IR type. This should only ever be used for function-local, 169687d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// IR-driven manipulations like saving and restoring a value. Do 169787d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// not hand this address off to arbitrary IRGen routines, and especially 169887d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// do not pass it as an argument to a function that might expect a 169987d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// properly ABI-aligned value. 170087d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar Address CreateDefaultAlignTempAlloca(llvm::Type *Ty, 170187d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar const Twine &Name = "tmp"); 170287d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar 170387d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// InitTempAlloca - Provide an initial value for the given alloca which 170487d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// will be observable at all locations in the function. 170587d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// 170687d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// The address should be something that was returned from one of 170787d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// the CreateTempAlloca or CreateMemTemp routines, and the 170887d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// initializer must be valid in the entry block (i.e. it must 170987d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// either be a constant or an argument value). 171087d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar void InitTempAlloca(Address Alloca, llvm::Value *Value); 1711ac418162692a951ca3796d6830496a85a2d12493John McCall 17129bd4da2cfa8b956b851200db8f9a37e175edbb15Daniel Dunbar /// CreateIRTemp - Create a temporary IR object of the given type, with 17139bd4da2cfa8b956b851200db8f9a37e175edbb15Daniel Dunbar /// appropriate alignment. This routine should only be used when an temporary 17149bd4da2cfa8b956b851200db8f9a37e175edbb15Daniel Dunbar /// value needs to be stored into an alloca (for example, to avoid explicit 17159bd4da2cfa8b956b851200db8f9a37e175edbb15Daniel Dunbar /// PHI construction), but the type is the IR type, not the type appropriate 17169bd4da2cfa8b956b851200db8f9a37e175edbb15Daniel Dunbar /// for storing in memory. 171787d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// 171887d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// That is, this is exactly equivalent to CreateMemTemp, but calling 171987d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// ConvertType instead of ConvertTypeForMem. 172087d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar Address CreateIRTemp(QualType T, const Twine &Name = "tmp"); 17219bd4da2cfa8b956b851200db8f9a37e175edbb15Daniel Dunbar 1722195337d2e5d4625ae9dc1328c7cdbc7115b0261bDaniel Dunbar /// CreateMemTemp - Create a temporary memory object of the given type, with 1723195337d2e5d4625ae9dc1328c7cdbc7115b0261bDaniel Dunbar /// appropriate alignment. 172487d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar Address CreateMemTemp(QualType T, const Twine &Name = "tmp"); 172587d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar Address CreateMemTemp(QualType T, CharUnits Align, const Twine &Name = "tmp"); 1726195337d2e5d4625ae9dc1328c7cdbc7115b0261bDaniel Dunbar 1727558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall /// CreateAggTemp - Create a temporary memory object for the given 1728558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall /// aggregate type. 17298cc488fefb2fb04bc8d5398da29f0182f97934cfChris Lattner AggValueSlot CreateAggTemp(QualType T, const Twine &Name = "tmp") { 173087d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar return AggValueSlot::forAddr(CreateMemTemp(T, Name), 1731f394078fde147dcf27e9b6a7965517388d64dcb6Eli Friedman T.getQualifiers(), 17327c2349be2d11143a2e59a167fd43362a3bf4585eJohn McCall AggValueSlot::IsNotDestructed, 1733410ffb2bc5f072d58a73c14560345bcf77dec1ccJohn McCall AggValueSlot::DoesNotNeedGCBarriers, 1734649b4a1a9b5e6f768ca0cb84bd97b00f51083e15Chad Rosier AggValueSlot::IsNotAliased); 1735558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall } 1736558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall 1737d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall /// Emit a cast to void* in the appropriate address space. 1738d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall llvm::Value *EmitCastToVoidPtr(llvm::Value *value); 1739d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall 17405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// EvaluateExprAsBool - Perform the usual unary conversions on the specified 17415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// expression and compare the result against zero, returning an Int1Ty value. 17425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer llvm::Value *EvaluateExprAsBool(const Expr *E); 17435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 17442a41637a995affa1563f4d82a8b026e326a2faa0John McCall /// EmitIgnoredExpr - Emit an expression in a context which ignores the result. 17452a41637a995affa1563f4d82a8b026e326a2faa0John McCall void EmitIgnoredExpr(const Expr *E); 17462a41637a995affa1563f4d82a8b026e326a2faa0John McCall 17479b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner /// EmitAnyExpr - Emit code to compute the specified expression which can have 17489b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner /// any type. The result is returned as an RValue struct. If this is an 17499b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner /// aggregate expression, the aggloc/agglocvolatile arguments indicate where 17509b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner /// the result should be returned. 175149d1cd5a09ed3df353371fd7f206674a85e0fb45Mike Stump /// 175270517ca5c07c4b41ff8662b94ee22047b0299f8cDmitri Gribenko /// \param ignoreResult True if the resulting value isn't used. 1753558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall RValue EmitAnyExpr(const Expr *E, 1754e0c1168ec7910a1a7ed08df4d4f0c58c2fa2ecd1John McCall AggValueSlot aggSlot = AggValueSlot::ignored(), 1755e0c1168ec7910a1a7ed08df4d4f0c58c2fa2ecd1John McCall bool ignoreResult = false); 1756d9363c3a80168283b3da518b4e17f545a6246857Devang Patel 17570dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump // EmitVAListRef - Emit a "reference" to a va_list; this is either the address 17580dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump // or the value of the expression, depending on how va_list is defined. 175987d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar Address EmitVAListRef(const Expr *E); 176087d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar 176187d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// Emit a "reference" to a __builtin_ms_va_list; this is 176287d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// always the value of the expression, because a __builtin_ms_va_list is a 176387d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// pointer to a char. 176487d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar Address EmitMSVAListRef(const Expr *E); 17654fd0aa5803357d8c72eeac2cae15e12649ea08feEli Friedman 17660dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// EmitAnyExprToTemp - Similary to EmitAnyExpr(), however, the result will 17670dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// always be accessible even if no aggregate location is provided. 1768558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall RValue EmitAnyExprToTemp(const Expr *E); 176946f45b9bec4a265ad8400a538e5ec3a5683617f1Daniel Dunbar 177060d3365b46eb826fba44483583c0051ac5c41fe3John McCall /// EmitAnyExprToMem - Emits the code necessary to evaluate an 1771649b4a1a9b5e6f768ca0cb84bd97b00f51083e15Chad Rosier /// arbitrary expression into the given memory location. 177287d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar void EmitAnyExprToMem(const Expr *E, Address Location, 1773649b4a1a9b5e6f768ca0cb84bd97b00f51083e15Chad Rosier Qualifiers Quals, bool IsInitializer); 17743d3ec1c099ec8bfac3aa1fb0126fe515b7c7fa05John McCall 177587d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar void EmitAnyExprToExn(const Expr *E, Address Addr); 17763ea9e33ea25e0c2b12db56418ba3f994eb662c04Pirama Arumuga Nainar 177760d3365b46eb826fba44483583c0051ac5c41fe3John McCall /// EmitExprAsInit - Emits the code necessary to initialize a 177860d3365b46eb826fba44483583c0051ac5c41fe3John McCall /// location in memory with the given initializer. 17790e2c34f92f00628d48968dfea096d36381f494cbStephen Hines void EmitExprAsInit(const Expr *init, const ValueDecl *D, LValue lvalue, 17800e2c34f92f00628d48968dfea096d36381f494cbStephen Hines bool capturedByInit); 178160d3365b46eb826fba44483583c0051ac5c41fe3John McCall 17823ac83d69c61238cd0d38e90fcdd03390530ab2fbFariborz Jahanian /// hasVolatileMember - returns true if aggregate type has a volatile 17833ac83d69c61238cd0d38e90fcdd03390530ab2fbFariborz Jahanian /// member. 17843ac83d69c61238cd0d38e90fcdd03390530ab2fbFariborz Jahanian bool hasVolatileMember(QualType T) { 17853ac83d69c61238cd0d38e90fcdd03390530ab2fbFariborz Jahanian if (const RecordType *RT = T->getAs<RecordType>()) { 17863ac83d69c61238cd0d38e90fcdd03390530ab2fbFariborz Jahanian const RecordDecl *RD = cast<RecordDecl>(RT->getDecl()); 17873ac83d69c61238cd0d38e90fcdd03390530ab2fbFariborz Jahanian return RD->hasVolatileMember(); 17883ac83d69c61238cd0d38e90fcdd03390530ab2fbFariborz Jahanian } 17893ac83d69c61238cd0d38e90fcdd03390530ab2fbFariborz Jahanian return false; 17903ac83d69c61238cd0d38e90fcdd03390530ab2fbFariborz Jahanian } 17918fcbb8dfbc28b6279d22144e10ade401a6c03e9eArnaud A. de Grandmaison /// EmitAggregateCopy - Emit an aggregate assignment. 17926cacae8bf9597b8124cd40aedc189c04484e1990Benjamin Kramer /// 17936cacae8bf9597b8124cd40aedc189c04484e1990Benjamin Kramer /// The difference to EmitAggregateCopy is that tail padding is not copied. 17946cacae8bf9597b8124cd40aedc189c04484e1990Benjamin Kramer /// This is required for correctness when assigning non-POD structures in C++. 179587d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar void EmitAggregateAssign(Address DestPtr, Address SrcPtr, 17963ac83d69c61238cd0d38e90fcdd03390530ab2fbFariborz Jahanian QualType EltTy) { 17973ac83d69c61238cd0d38e90fcdd03390530ab2fbFariborz Jahanian bool IsVolatile = hasVolatileMember(EltTy); 179887d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar EmitAggregateCopy(DestPtr, SrcPtr, EltTy, IsVolatile, true); 17996cacae8bf9597b8124cd40aedc189c04484e1990Benjamin Kramer } 18006cacae8bf9597b8124cd40aedc189c04484e1990Benjamin Kramer 180187d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar void EmitAggregateCopyCtor(Address DestPtr, Address SrcPtr, 180287d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar QualType DestTy, QualType SrcTy) { 18030e2c34f92f00628d48968dfea096d36381f494cbStephen Hines EmitAggregateCopy(DestPtr, SrcPtr, SrcTy, /*IsVolatile=*/false, 18040e2c34f92f00628d48968dfea096d36381f494cbStephen Hines /*IsAssignment=*/false); 18050e2c34f92f00628d48968dfea096d36381f494cbStephen Hines } 18060e2c34f92f00628d48968dfea096d36381f494cbStephen Hines 18078fcbb8dfbc28b6279d22144e10ade401a6c03e9eArnaud A. de Grandmaison /// EmitAggregateCopy - Emit an aggregate copy. 180827fe2e6c97a3782a0639d87b460741e8ba5d076dMike Stump /// 1809f3477c13eeaf11b32a41f181398fb5deffd0dd73Sylvestre Ledru /// \param isVolatile - True iff either the source or the destination is 181027fe2e6c97a3782a0639d87b460741e8ba5d076dMike Stump /// volatile. 18116cacae8bf9597b8124cd40aedc189c04484e1990Benjamin Kramer /// \param isAssignment - If false, allow padding to be copied. This often 18126cacae8bf9597b8124cd40aedc189c04484e1990Benjamin Kramer /// yields more efficient. 181387d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar void EmitAggregateCopy(Address DestPtr, Address SrcPtr, 1814bd7d82878c1588afccbee6c68fa6e17bbbab7f2cEli Friedman QualType EltTy, bool isVolatile=false, 18156cacae8bf9597b8124cd40aedc189c04484e1990Benjamin Kramer bool isAssignment = false); 18167482d12c345c6391f8956850545e2d4aa7701ce6Daniel Dunbar 1817dde0a94120915fa925d1ffcdb997c7b44dc9fa21Anders Carlsson /// GetAddrOfLocalVar - Return the address of a local variable. 181887d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar Address GetAddrOfLocalVar(const VarDecl *VD) { 181987d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar auto it = LocalDeclMap.find(VD); 182087d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar assert(it != LocalDeclMap.end() && 182187d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar "Invalid argument to GetAddrOfLocalVar(), no decl!"); 182287d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar return it->second; 18234c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall } 18240dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 182556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// getOpaqueLValueMapping - Given an opaque value expression (which 182656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// must be mapped to an l-value), return its mapping. 182756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall const LValue &getOpaqueLValueMapping(const OpaqueValueExpr *e) { 182856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall assert(OpaqueValueMapping::shouldBindAsLValue(e)); 182956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 183056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall llvm::DenseMap<const OpaqueValueExpr*,LValue>::iterator 183156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall it = OpaqueLValues.find(e); 183256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall assert(it != OpaqueLValues.end() && "no mapping for opaque value!"); 183356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return it->second; 183456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 183556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 183656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// getOpaqueRValueMapping - Given an opaque value expression (which 183756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// must be mapped to an r-value), return its mapping. 183856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall const RValue &getOpaqueRValueMapping(const OpaqueValueExpr *e) { 183956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall assert(!OpaqueValueMapping::shouldBindAsLValue(e)); 184056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 184156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall llvm::DenseMap<const OpaqueValueExpr*,RValue>::iterator 184256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall it = OpaqueRValues.find(e); 184356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall assert(it != OpaqueRValues.end() && "no mapping for opaque value!"); 1844e996ffd240f20a1048179d7727a6ee3227261921John McCall return it->second; 1845e996ffd240f20a1048179d7727a6ee3227261921John McCall } 1846e996ffd240f20a1048179d7727a6ee3227261921John McCall 18474f8d123e3e2c260de3377208106ddba87cee28b4Dan Gohman /// getAccessedFieldNo - Given an encoded value and a result number, return 18484f8d123e3e2c260de3377208106ddba87cee28b4Dan Gohman /// the input field number being accessed. 18494f8d123e3e2c260de3377208106ddba87cee28b4Dan Gohman static unsigned getAccessedFieldNo(unsigned Idx, const llvm::Constant *Elts); 18504f8d123e3e2c260de3377208106ddba87cee28b4Dan Gohman 1851ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner llvm::BlockAddress *GetAddrOfLabel(const LabelDecl *L); 18523d00fdc82fd550ae4bfbb2e700a1fc85bbd6d6fdChris Lattner llvm::BasicBlock *GetIndirectGotoBlock(); 18530ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar 18541884eb0b5c55edda4893ddec45e7dbad79758782Anders Carlsson /// EmitNullInitialization - Generate code to set a value of the given type to 18551884eb0b5c55edda4893ddec45e7dbad79758782Anders Carlsson /// null, If the type contains data member pointers, they will be initialized 18561884eb0b5c55edda4893ddec45e7dbad79758782Anders Carlsson /// to -1 in accordance with the Itanium C++ ABI. 185787d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar void EmitNullInitialization(Address DestPtr, QualType Ty); 185887d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar 185987d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// Emits a call to an LLVM variable-argument intrinsic, either 186087d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// \c llvm.va_start or \c llvm.va_end. 186187d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// \param ArgValue A reference to the \c va_list as emitted by either 186287d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// \c EmitVAListRef or \c EmitMSVAListRef. 186387d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// \param IsStart If \c true, emits a call to \c llvm.va_start; otherwise, 186487d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// calls \c llvm.va_end. 186587d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar llvm::Value *EmitVAStartEnd(llvm::Value *ArgValue, bool IsStart); 186687d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar 186787d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// Generate code to get an argument from the passed in pointer 186887d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// and update it accordingly. 186987d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// \param VE The \c VAArgExpr for which to generate code. 187087d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// \param VAListAddr Receives a reference to the \c va_list as emitted by 187187d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// either \c EmitVAListRef or \c EmitMSVAListRef. 187287d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// \returns A pointer to the argument. 1873ddf7cac45d85b73127adbbd91a2b28fc7291c57eAnders Carlsson // FIXME: We should be able to get rid of this method and use the va_arg 18740dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump // instruction in LLVM instead once it works well enough. 187587d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar Address EmitVAArg(VAArgExpr *VE, Address &VAListAddr); 1876f666b7780d04186521adcaedb0e15dfa4d5e6933Anders Carlsson 1877bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall /// emitArrayLength - Compute the length of an array, even if it's a 1878bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall /// VLA, and drill down to the base element type. 1879bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall llvm::Value *emitArrayLength(const ArrayType *arrayType, 1880bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall QualType &baseType, 188187d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar Address &addr); 1882bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall 1883bc8d40d85f3fa1e34569834916f18fecaa635152John McCall /// EmitVLASize - Capture all the sizes for the VLA expressions in 1884bc8d40d85f3fa1e34569834916f18fecaa635152John McCall /// the given variably-modified type and store them in the VLASizeMap. 1885d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar /// 1886d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar /// This function can be called with a null (unreachable) insert point. 1887bc8d40d85f3fa1e34569834916f18fecaa635152John McCall void EmitVariablyModifiedType(QualType Ty); 1888bc8d40d85f3fa1e34569834916f18fecaa635152John McCall 1889bc8d40d85f3fa1e34569834916f18fecaa635152John McCall /// getVLASize - Returns an LLVM value that corresponds to the size, 1890bc8d40d85f3fa1e34569834916f18fecaa635152John McCall /// in non-variably-sized elements, of a variable length array type, 1891bc8d40d85f3fa1e34569834916f18fecaa635152John McCall /// plus that largest non-variably-sized element type. Assumes that 1892bc8d40d85f3fa1e34569834916f18fecaa635152John McCall /// the type has already been emitted with EmitVariablyModifiedType. 1893bc8d40d85f3fa1e34569834916f18fecaa635152John McCall std::pair<llvm::Value*,QualType> getVLASize(const VariableArrayType *vla); 1894bc8d40d85f3fa1e34569834916f18fecaa635152John McCall std::pair<llvm::Value*,QualType> getVLASize(QualType vla); 1895dcc90d87e6430c643b4311ae5b0089535bca41f7Anders Carlsson 18965f4307b7ba164b03c853c8d3eb4674d33f8967a6Anders Carlsson /// LoadCXXThis - Load the value of 'this'. This function is only valid while 18975f4307b7ba164b03c853c8d3eb4674d33f8967a6Anders Carlsson /// generating code for an C++ member function. 18982504941793b549323f9d29c62507cf21d865fadeJohn McCall llvm::Value *LoadCXXThis() { 18992504941793b549323f9d29c62507cf21d865fadeJohn McCall assert(CXXThisValue && "no 'this' value for this function"); 19002504941793b549323f9d29c62507cf21d865fadeJohn McCall return CXXThisValue; 19012504941793b549323f9d29c62507cf21d865fadeJohn McCall } 190287d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar Address LoadCXXThisAddress(); 19031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1904c997d4278d329e18891aac9698fb991b2d4622ebAnders Carlsson /// LoadCXXVTT - Load the VTT parameter to base constructors/destructors have 1905c997d4278d329e18891aac9698fb991b2d4622ebAnders Carlsson /// virtual bases. 190659660c21178b6af518bd4b564e032d5c9cc218cbTimur Iskhodzhanov // FIXME: Every place that calls LoadCXXVTT is something 190759660c21178b6af518bd4b564e032d5c9cc218cbTimur Iskhodzhanov // that needs to be abstracted properly. 19082504941793b549323f9d29c62507cf21d865fadeJohn McCall llvm::Value *LoadCXXVTT() { 190959660c21178b6af518bd4b564e032d5c9cc218cbTimur Iskhodzhanov assert(CXXStructorImplicitParamValue && "no VTT value for this function"); 191059660c21178b6af518bd4b564e032d5c9cc218cbTimur Iskhodzhanov return CXXStructorImplicitParamValue; 191159660c21178b6af518bd4b564e032d5c9cc218cbTimur Iskhodzhanov } 191259660c21178b6af518bd4b564e032d5c9cc218cbTimur Iskhodzhanov 1913bff225ecf77fb891596ecb1b27196310d268365eJohn McCall /// GetAddressOfBaseOfCompleteClass - Convert the given pointer to a 19148561a8666c70f924c8f0209c41b9b77bbbf90607Anders Carlsson /// complete class to the given direct base. 191587d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar Address 191687d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar GetAddressOfDirectBaseInCompleteClass(Address Value, 19178561a8666c70f924c8f0209c41b9b77bbbf90607Anders Carlsson const CXXRecordDecl *Derived, 19188561a8666c70f924c8f0209c41b9b77bbbf90607Anders Carlsson const CXXRecordDecl *Base, 19198561a8666c70f924c8f0209c41b9b77bbbf90607Anders Carlsson bool BaseIsVirtual); 1920a88ad5618fcb07c5374c79d6781a33234984b039Anders Carlsson 192187d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar static bool ShouldNullCheckClassCastValue(const CastExpr *Cast); 192287d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar 1923f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump /// GetAddressOfBaseClass - This function will add the necessary delta to the 1924f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump /// load of 'this' and returns address of the base class. 192587d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar Address GetAddressOfBaseClass(Address Value, 192687d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar const CXXRecordDecl *Derived, 192787d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar CastExpr::path_const_iterator PathBegin, 192887d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar CastExpr::path_const_iterator PathEnd, 192987d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar bool NullCheckValue, SourceLocation Loc); 193087d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar 193187d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar Address GetAddressOfDerivedClass(Address Value, 193287d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar const CXXRecordDecl *Derived, 193387d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar CastExpr::path_const_iterator PathBegin, 193487d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar CastExpr::path_const_iterator PathEnd, 193587d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar bool NullCheckValue); 1936a3697c9c155bda93fd2802f37084b620f4738822Anders Carlsson 19371d4fff5551c2347010b955b4337a2aa7d65a050eTimur Iskhodzhanov /// GetVTTParameter - Return the VTT parameter that should be passed to a 19381d4fff5551c2347010b955b4337a2aa7d65a050eTimur Iskhodzhanov /// base constructor/destructor with virtual bases. 19391d4fff5551c2347010b955b4337a2aa7d65a050eTimur Iskhodzhanov /// FIXME: VTTs are Itanium ABI-specific, so the definition should move 19401d4fff5551c2347010b955b4337a2aa7d65a050eTimur Iskhodzhanov /// to ItaniumCXXABI.cpp together with all the references to VTT. 19411d4fff5551c2347010b955b4337a2aa7d65a050eTimur Iskhodzhanov llvm::Value *GetVTTParameter(GlobalDecl GD, bool ForVirtualBase, 19421d4fff5551c2347010b955b4337a2aa7d65a050eTimur Iskhodzhanov bool Delegating); 19431d4fff5551c2347010b955b4337a2aa7d65a050eTimur Iskhodzhanov 1944c0bf462cf35fe050bddbd8bff967298e4a67e79dJohn McCall void EmitDelegateCXXConstructorCall(const CXXConstructorDecl *Ctor, 1945c0bf462cf35fe050bddbd8bff967298e4a67e79dJohn McCall CXXCtorType CtorType, 19464ee7dc2369c1f0257a73b2e83a7d38fdebdd9176Nick Lewycky const FunctionArgList &Args, 19474ee7dc2369c1f0257a73b2e83a7d38fdebdd9176Nick Lewycky SourceLocation Loc); 1948059ce0d92eb5a7da900ae735dc0a2ea3d64f4b0bSean Hunt // It's important not to confuse this and the previous function. Delegating 1949059ce0d92eb5a7da900ae735dc0a2ea3d64f4b0bSean Hunt // constructors are the C++0x feature. The constructor delegate optimization 1950059ce0d92eb5a7da900ae735dc0a2ea3d64f4b0bSean Hunt // is used to reduce duplication in the base and complete consturctors where 1951059ce0d92eb5a7da900ae735dc0a2ea3d64f4b0bSean Hunt // they are substantially the same. 1952059ce0d92eb5a7da900ae735dc0a2ea3d64f4b0bSean Hunt void EmitDelegatingCXXConstructorCall(const CXXConstructorDecl *Ctor, 1953059ce0d92eb5a7da900ae735dc0a2ea3d64f4b0bSean Hunt const FunctionArgList &Args); 195487d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar 19554967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar /// Emit a call to an inheriting constructor (that is, one that invokes a 19564967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar /// constructor inherited from a base class) by inlining its definition. This 19574967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar /// is necessary if the ABI does not support forwarding the arguments to the 19584967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar /// base class constructor (because they're variadic or similar). 19594967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar void EmitInlinedInheritingCXXConstructorCall(const CXXConstructorDecl *Ctor, 19604967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar CXXCtorType CtorType, 19614967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar bool ForVirtualBase, 19624967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar bool Delegating, 19634967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar CallArgList &Args); 19644967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar 19654967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar /// Emit a call to a constructor inherited from a base class, passing the 19664967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar /// current constructor's arguments along unmodified (without even making 19674967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar /// a copy). 19684967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar void EmitInheritedCXXConstructorCall(const CXXConstructorDecl *D, 19694967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar bool ForVirtualBase, Address This, 19704967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar bool InheritedFromVBase, 19714967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar const CXXInheritedCtorInitExpr *E); 19724967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar 1973155ed4a23366f4514befb1c9f5f89d16f8b8b6dbAnders Carlsson void EmitCXXConstructorCall(const CXXConstructorDecl *D, CXXCtorType Type, 1974378e1e739aed97e9b278beeb20e9f5bbe34c0232Douglas Gregor bool ForVirtualBase, bool Delegating, 197587d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar Address This, const CXXConstructExpr *E); 197687d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar 19774967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar void EmitCXXConstructorCall(const CXXConstructorDecl *D, CXXCtorType Type, 19784967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar bool ForVirtualBase, bool Delegating, 19794967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar Address This, CallArgList &Args); 19804967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar 198187d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// Emit assumption load for all bases. Requires to be be called only on 198287d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// most-derived class and not under construction of the object. 198387d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar void EmitVTableAssumptionLoads(const CXXRecordDecl *ClassDecl, Address This); 198487d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar 198587d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// Emit assumption that vptr load == global vtable. 198687d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar void EmitVTableAssumptionLoad(const VPtr &vptr, Address This); 1987176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines 198834999876e215b22febc240b1a6dc054215d12f9cFariborz Jahanian void EmitSynthesizedCXXCopyCtorCall(const CXXConstructorDecl *D, 198987d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar Address This, Address Src, 199087d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar const CXXConstructExpr *E); 19911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1992288dcaf329c49b01dacd5c1dd9f35609555feecdFariborz Jahanian void EmitCXXAggrConstructorCall(const CXXConstructorDecl *D, 19934967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar const ArrayType *ArrayTy, 199487d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar Address ArrayPtr, 1995176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines const CXXConstructExpr *E, 199659174c0633fb5cde41735cfbff5744bdf837e8d9Douglas Gregor bool ZeroInitialization = false); 19979cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer 1998569c1f4a6c703eaa8b963bed7d5c2fd5d4569e93Anders Carlsson void EmitCXXAggrConstructorCall(const CXXConstructorDecl *D, 1999569c1f4a6c703eaa8b963bed7d5c2fd5d4569e93Anders Carlsson llvm::Value *NumElements, 200087d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar Address ArrayPtr, 2001176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines const CXXConstructExpr *E, 200259174c0633fb5cde41735cfbff5744bdf837e8d9Douglas Gregor bool ZeroInitialization = false); 2003b14095aa98c6fedd3625920c4ce834bcaf24d9f7Anders Carlsson 2004bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall static Destroyer destroyCXXObject; 2005bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall 20067267c1693abe7875b0c57268be05005ae013c6c9Anders Carlsson void EmitCXXDestructorCall(const CXXDestructorDecl *D, CXXDtorType Type, 2007378e1e739aed97e9b278beeb20e9f5bbe34c0232Douglas Gregor bool ForVirtualBase, bool Delegating, 200887d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar Address This); 20099cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer 2010197056726ed6412501130c2ef2ff69009772aa65John McCall void EmitNewArrayInitializer(const CXXNewExpr *E, QualType elementType, 201187d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar llvm::Type *ElementTy, Address NewPtr, 201258878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar llvm::Value *NumElements, 2013c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines llvm::Value *AllocSizeWithoutCookie); 20141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 201586811609d9353e3aed198045d56e790eb3b6118cPeter Collingbourne void EmitCXXTemporary(const CXXTemporary *Temporary, QualType TempType, 201687d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar Address Ptr); 20171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2018b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar llvm::Value *EmitLifetimeStart(uint64_t Size, llvm::Value *Addr); 2019b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar void EmitLifetimeEnd(llvm::Value *Size, llvm::Value *Addr); 2020b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar 2021a00703dccbdc6cc4a293db38477dea7db5538c7eAnders Carlsson llvm::Value *EmitCXXNewExpr(const CXXNewExpr *E); 202260e282cc1e508be327b0481cecedc206873cb86aAnders Carlsson void EmitCXXDeleteExpr(const CXXDeleteExpr *E); 20231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 20244bf8152799ec41796f989ea1b94f6f1bac349117Eli Friedman void EmitDeleteCall(const FunctionDecl *DeleteFD, llvm::Value *Ptr, 20254bf8152799ec41796f989ea1b94f6f1bac349117Eli Friedman QualType DeleteTy); 20264bf8152799ec41796f989ea1b94f6f1bac349117Eli Friedman 2027c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines RValue EmitBuiltinNewDeleteCall(const FunctionProtoType *Type, 2028c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines const Expr *Arg, bool IsDelete); 2029c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines 203087d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar llvm::Value *EmitCXXTypeidExpr(const CXXTypeidExpr *E); 203187d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar llvm::Value *EmitDynamicCast(Address V, const CXXDynamicCastExpr *DCE); 203287d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar Address EmitCXXUuidofExpr(const CXXUuidofExpr *E); 2033c2e84ae9a6d25cea3e583c768e576b4c981ec028Mike Stump 20342c9f87ca5cccbfdaad82762368af5b2323320653Richard Smith /// \brief Situations in which we might emit a check for the suitability of a 20352c9f87ca5cccbfdaad82762368af5b2323320653Richard Smith /// pointer or glvalue. 20367ac9ef1c82c779a5348ed11b3d10e01c58803b35Richard Smith enum TypeCheckKind { 20372c9f87ca5cccbfdaad82762368af5b2323320653Richard Smith /// Checking the operand of a load. Must be suitably sized and aligned. 20387ac9ef1c82c779a5348ed11b3d10e01c58803b35Richard Smith TCK_Load, 20392c9f87ca5cccbfdaad82762368af5b2323320653Richard Smith /// Checking the destination of a store. Must be suitably sized and aligned. 20407ac9ef1c82c779a5348ed11b3d10e01c58803b35Richard Smith TCK_Store, 20412c9f87ca5cccbfdaad82762368af5b2323320653Richard Smith /// Checking the bound value in a reference binding. Must be suitably sized 20422c9f87ca5cccbfdaad82762368af5b2323320653Richard Smith /// and aligned, but is not required to refer to an object (until the 20432c9f87ca5cccbfdaad82762368af5b2323320653Richard Smith /// reference is used), per core issue 453. 20447ac9ef1c82c779a5348ed11b3d10e01c58803b35Richard Smith TCK_ReferenceBinding, 20452c9f87ca5cccbfdaad82762368af5b2323320653Richard Smith /// Checking the object expression in a non-static data member access. Must 20462c9f87ca5cccbfdaad82762368af5b2323320653Richard Smith /// be an object within its lifetime. 20477ac9ef1c82c779a5348ed11b3d10e01c58803b35Richard Smith TCK_MemberAccess, 20482c9f87ca5cccbfdaad82762368af5b2323320653Richard Smith /// Checking the 'this' pointer for a call to a non-static member function. 20492c9f87ca5cccbfdaad82762368af5b2323320653Richard Smith /// Must be an object within its lifetime. 20508e1cee6f23e2552b96b81e5ef419ab3f69c5b5c2Richard Smith TCK_MemberCall, 20518e1cee6f23e2552b96b81e5ef419ab3f69c5b5c2Richard Smith /// Checking the 'this' pointer for a constructor call. 2052c764830bdb6de82baed068889096bd3e52d4cbdaRichard Smith TCK_ConstructorCall, 2053c764830bdb6de82baed068889096bd3e52d4cbdaRichard Smith /// Checking the operand of a static_cast to a derived pointer type. Must be 2054c764830bdb6de82baed068889096bd3e52d4cbdaRichard Smith /// null or an object within its lifetime. 2055c764830bdb6de82baed068889096bd3e52d4cbdaRichard Smith TCK_DowncastPointer, 2056c764830bdb6de82baed068889096bd3e52d4cbdaRichard Smith /// Checking the operand of a static_cast to a derived reference type. Must 2057c764830bdb6de82baed068889096bd3e52d4cbdaRichard Smith /// be an object within its lifetime. 2058176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines TCK_DowncastReference, 2059176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines /// Checking the operand of a cast to a base object. Must be suitably sized 2060176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines /// and aligned. 2061176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines TCK_Upcast, 2062176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines /// Checking the operand of a cast to a virtual base object. Must be an 2063176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines /// object within its lifetime. 2064176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines TCK_UpcastToVirtualBase 20652c9f87ca5cccbfdaad82762368af5b2323320653Richard Smith }; 20662c9f87ca5cccbfdaad82762368af5b2323320653Richard Smith 2067c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines /// \brief Whether any type-checking sanitizers are enabled. If \c false, 2068c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines /// calls to EmitTypeCheck can be skipped. 2069c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines bool sanitizePerformTypeCheck() const; 2070c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines 20717ac9ef1c82c779a5348ed11b3d10e01c58803b35Richard Smith /// \brief Emit a check that \p V is the address of storage of the 20722c9f87ca5cccbfdaad82762368af5b2323320653Richard Smith /// appropriate size and alignment for an object of type \p Type. 20734def70d3040e73707c738f7c366737a986135edfRichard Smith void EmitTypeCheck(TypeCheckKind TCK, SourceLocation Loc, llvm::Value *V, 2074176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines QualType Type, CharUnits Alignment = CharUnits::Zero(), 2075176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines bool SkipNullCheck = false); 2076b14e62d5aee7522b98c410ee65bd750c2cfe6f01Mike Stump 2077a0a628f839cf50844cc0f226bd9cb72485f98f91Richard Smith /// \brief Emit a check that \p Base points into an array object, which 2078a0a628f839cf50844cc0f226bd9cb72485f98f91Richard Smith /// we can access at index \p Index. \p Accessed should be \c false if we 2079a0a628f839cf50844cc0f226bd9cb72485f98f91Richard Smith /// this expression is used as an lvalue, for instance in "&Arr[Idx]". 2080a0a628f839cf50844cc0f226bd9cb72485f98f91Richard Smith void EmitBoundsCheck(const Expr *E, const Expr *Base, llvm::Value *Index, 2081a0a628f839cf50844cc0f226bd9cb72485f98f91Richard Smith QualType IndexType, bool Accessed); 2082a0a628f839cf50844cc0f226bd9cb72485f98f91Richard Smith 2083dd36d328730d8c02915d0884541b45ec6ca0049dChris Lattner llvm::Value *EmitScalarPrePostIncDec(const UnaryOperator *E, LValue LV, 2084dd36d328730d8c02915d0884541b45ec6ca0049dChris Lattner bool isInc, bool isPre); 2085dd36d328730d8c02915d0884541b45ec6ca0049dChris Lattner ComplexPairTy EmitComplexPrePostIncDec(const UnaryOperator *E, LValue LV, 2086dd36d328730d8c02915d0884541b45ec6ca0049dChris Lattner bool isInc, bool isPre); 2087176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines 2088176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines void EmitAlignmentAssumption(llvm::Value *PtrValue, unsigned Alignment, 2089176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines llvm::Value *OffsetValue = nullptr) { 2090176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines Builder.CreateAlignmentAssumption(CGM.getDataLayout(), PtrValue, Alignment, 2091176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines OffsetValue); 2092176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines } 2093176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines 20945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 20955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Declaration Emission 20965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 20970dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 2098d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar /// EmitDecl - Emit a declaration. 2099d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar /// 2100d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar /// This function can be called with a null (unreachable) insert point. 21015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void EmitDecl(const Decl &D); 2102d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar 2103b6bbcc9995186799a60ce17d0c1acff31601653aJohn McCall /// EmitVarDecl - Emit a local variable declaration. 2104d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar /// 2105d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar /// This function can be called with a null (unreachable) insert point. 2106b6bbcc9995186799a60ce17d0c1acff31601653aJohn McCall void EmitVarDecl(const VarDecl &D); 2107d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar 21080e2c34f92f00628d48968dfea096d36381f494cbStephen Hines void EmitScalarInit(const Expr *init, const ValueDecl *D, LValue lvalue, 21090e2c34f92f00628d48968dfea096d36381f494cbStephen Hines bool capturedByInit); 21107acddacc921cd0b3f813443a8641eeddb82dfbd4John McCall void EmitScalarInit(llvm::Value *init, LValue lvalue); 2111f85e193739c953358c865005855253af4f68a497John McCall 2112f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall typedef void SpecialInitFn(CodeGenFunction &Init, const VarDecl &D, 2113f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall llvm::Value *Address); 2114f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 2115176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines /// \brief Determine whether the given initializer is trivial in the sense 2116176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines /// that it requires no code to be generated. 2117176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines bool isTrivialInitializer(const Expr *Init); 2118176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines 2119b6bbcc9995186799a60ce17d0c1acff31601653aJohn McCall /// EmitAutoVarDecl - Emit an auto variable declaration. 2120d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar /// 2121d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar /// This function can be called with a null (unreachable) insert point. 212234695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall void EmitAutoVarDecl(const VarDecl &D); 212334695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall 212434695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall class AutoVarEmission { 212534695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall friend class CodeGenFunction; 212634695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall 212757b3b6a60856eaec30fd876a8a3face8f7e3ad7bJohn McCall const VarDecl *Variable; 212834695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall 212987d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// The address of the alloca. Invalid if the variable was emitted 213034695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall /// as a global constant. 213187d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar Address Addr; 213234695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall 213334695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall llvm::Value *NRVOFlag; 213434695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall 213534695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall /// True if the variable is a __block variable. 213634695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall bool IsByRef; 213734695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall 213834695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall /// True if the variable is of aggregate type and has a constant 213934695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall /// initializer. 214034695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall bool IsConstantAggregate; 214134695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall 2142495cfa46300979642acde8d93a1f21c9291dac98Nadav Rotem /// Non-null if we should use lifetime annotations. 2143495cfa46300979642acde8d93a1f21c9291dac98Nadav Rotem llvm::Value *SizeForLifetimeMarkers; 2144495cfa46300979642acde8d93a1f21c9291dac98Nadav Rotem 214557b3b6a60856eaec30fd876a8a3face8f7e3ad7bJohn McCall struct Invalid {}; 214687d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar AutoVarEmission(Invalid) : Variable(nullptr), Addr(Address::invalid()) {} 214757b3b6a60856eaec30fd876a8a3face8f7e3ad7bJohn McCall 214834695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall AutoVarEmission(const VarDecl &variable) 214987d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar : Variable(&variable), Addr(Address::invalid()), NRVOFlag(nullptr), 2150495cfa46300979642acde8d93a1f21c9291dac98Nadav Rotem IsByRef(false), IsConstantAggregate(false), 21516bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines SizeForLifetimeMarkers(nullptr) {} 215234695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall 215387d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar bool wasEmittedAsGlobal() const { return !Addr.isValid(); } 215434695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall 215534695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall public: 215657b3b6a60856eaec30fd876a8a3face8f7e3ad7bJohn McCall static AutoVarEmission invalid() { return AutoVarEmission(Invalid()); } 2157495cfa46300979642acde8d93a1f21c9291dac98Nadav Rotem 21586bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines bool useLifetimeMarkers() const { 21596bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines return SizeForLifetimeMarkers != nullptr; 21606bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines } 2161495cfa46300979642acde8d93a1f21c9291dac98Nadav Rotem llvm::Value *getSizeForLifetimeMarkers() const { 2162495cfa46300979642acde8d93a1f21c9291dac98Nadav Rotem assert(useLifetimeMarkers()); 2163495cfa46300979642acde8d93a1f21c9291dac98Nadav Rotem return SizeForLifetimeMarkers; 2164495cfa46300979642acde8d93a1f21c9291dac98Nadav Rotem } 2165495cfa46300979642acde8d93a1f21c9291dac98Nadav Rotem 2166495cfa46300979642acde8d93a1f21c9291dac98Nadav Rotem /// Returns the raw, allocated address, which is not necessarily 2167495cfa46300979642acde8d93a1f21c9291dac98Nadav Rotem /// the address of the object itself. 216887d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar Address getAllocatedAddress() const { 216987d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar return Addr; 2170495cfa46300979642acde8d93a1f21c9291dac98Nadav Rotem } 217157b3b6a60856eaec30fd876a8a3face8f7e3ad7bJohn McCall 217234695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall /// Returns the address of the object within this declaration. 217334695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall /// Note that this does not chase the forwarding pointer for 217434695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall /// __block decls. 217587d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar Address getObjectAddress(CodeGenFunction &CGF) const { 217687d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar if (!IsByRef) return Addr; 217734695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall 217887d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar return CGF.emitBlockByrefAddress(Addr, Variable, /*forward*/ false); 217934695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall } 218034695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall }; 218134695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall AutoVarEmission EmitAutoVarAlloca(const VarDecl &var); 218234695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall void EmitAutoVarInit(const AutoVarEmission &emission); 218334695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall void EmitAutoVarCleanups(const AutoVarEmission &emission); 2184bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall void emitAutoVarTypeCleanup(const AutoVarEmission &emission, 2185bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall QualType::DestructionKind dtorKind); 2186d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar 2187b6bbcc9995186799a60ce17d0c1acff31601653aJohn McCall void EmitStaticVarDecl(const VarDecl &D, 2188b6bbcc9995186799a60ce17d0c1acff31601653aJohn McCall llvm::GlobalValue::LinkageTypes Linkage); 2189b7ec246872b412f0e7bb9e93eacfd78cfa6adfb3Daniel Dunbar 219087d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar class ParamValue { 219187d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar llvm::Value *Value; 219287d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar unsigned Alignment; 219387d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar ParamValue(llvm::Value *V, unsigned A) : Value(V), Alignment(A) {} 219487d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar public: 219587d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar static ParamValue forDirect(llvm::Value *value) { 219687d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar return ParamValue(value, 0); 219787d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar } 219887d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar static ParamValue forIndirect(Address addr) { 219987d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar assert(!addr.getAlignment().isZero()); 220087d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar return ParamValue(addr.getPointer(), addr.getAlignment().getQuantity()); 220187d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar } 220287d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar 220387d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar bool isIndirect() const { return Alignment != 0; } 220487d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar llvm::Value *getAnyValue() const { return Value; } 220587d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar 220687d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar llvm::Value *getDirectValue() const { 220787d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar assert(!isIndirect()); 220887d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar return Value; 220987d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar } 221087d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar 221187d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar Address getIndirectAddress() const { 221287d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar assert(isIndirect()); 221387d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar return Address(Value, CharUnits::fromQuantity(Alignment)); 221487d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar } 221587d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar }; 221687d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar 2217b7ec246872b412f0e7bb9e93eacfd78cfa6adfb3Daniel Dunbar /// EmitParmDecl - Emit a ParmVarDecl or an ImplicitParamDecl. 221887d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar void EmitParmDecl(const VarDecl &D, ParamValue Arg, unsigned ArgNo); 22190dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 222056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// protectFromPeepholes - Protect a value that we're intending to 222156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// store to the side, but which will probably be used later, from 222256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// aggressive peepholing optimizations that might delete it. 222356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// 222456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// Pass the result to unprotectFromPeepholes to declare that 222556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// protection is no longer required. 222656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// 222756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// There's no particular reason why this shouldn't apply to 222856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// l-values, it's just that no existing peepholes work on pointers. 222956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall PeepholeProtection protectFromPeepholes(RValue rvalue); 223056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall void unprotectFromPeepholes(PeepholeProtection protection); 223156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 22325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 22335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Statement Emission 22345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 22355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 22360dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// EmitStopPoint - Emit a debug stoppoint if we are emitting debug info. 22370912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar void EmitStopPoint(const Stmt *S); 22380912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar 22390dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// EmitStmt - Emit the code for the statement \arg S. It is legal to call 22400dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// this function even if there is no current insertion point. 22410dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// 22420dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// This function may clear the current insertion point; callers should use 22430dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// EnsureInsertPoint if they wish to subsequently generate code without first 22440dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// calling EmitBlock, EmitBranch, or EmitStmt. 22455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void EmitStmt(const Stmt *S); 2246a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar 22470912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar /// EmitSimpleStmt - Try to emit a "simple" statement which does not 22480dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// necessarily require an insertion point or debug information; typically 22490dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// because the statement amounts to a jump or a container of other 22500dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// statements. 22510912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar /// 22520912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar /// \return True if the statement was handled. 22530912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar bool EmitSimpleStmt(const Stmt *S); 22540912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar 225587d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar Address EmitCompoundStmt(const CompoundStmt &S, bool GetLast = false, 225687d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar AggValueSlot AVS = AggValueSlot::ignored()); 225787d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar Address EmitCompoundStmtWithoutScope(const CompoundStmt &S, 225887d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar bool GetLast = false, 225987d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar AggValueSlot AVS = 22602ac2fa7726eb2f6fe445e098489e92931c31f7caEli Friedman AggValueSlot::ignored()); 2261a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar 22620dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// EmitLabel - Emit the block for the given label. It is legal to call this 22630dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// function even if there is no current insertion point. 2264ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner void EmitLabel(const LabelDecl *D); // helper for EmitLabelStmt. 2265a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar 22665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void EmitLabelStmt(const LabelStmt &S); 2267534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith void EmitAttributedStmt(const AttributedStmt &S); 22685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void EmitGotoStmt(const GotoStmt &S); 22690ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar void EmitIndirectGotoStmt(const IndirectGotoStmt &S); 22705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void EmitIfStmt(const IfStmt &S); 2271c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines 2272c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines void EmitWhileStmt(const WhileStmt &S, 2273176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines ArrayRef<const Attr *> Attrs = None); 2274176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines void EmitDoStmt(const DoStmt &S, ArrayRef<const Attr *> Attrs = None); 2275c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines void EmitForStmt(const ForStmt &S, 2276176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines ArrayRef<const Attr *> Attrs = None); 22775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void EmitReturnStmt(const ReturnStmt &S); 22785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void EmitDeclStmt(const DeclStmt &S); 22790912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar void EmitBreakStmt(const BreakStmt &S); 22800912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar void EmitContinueStmt(const ContinueStmt &S); 228151b09f2c528c8460b5465c676173324e44176d62Devang Patel void EmitSwitchStmt(const SwitchStmt &S); 228251b09f2c528c8460b5465c676173324e44176d62Devang Patel void EmitDefaultStmt(const DefaultStmt &S); 228351b09f2c528c8460b5465c676173324e44176d62Devang Patel void EmitCaseStmt(const CaseStmt &S); 2284c049e4f406a7f7179eba98659044a32508e53289Devang Patel void EmitCaseStmtRange(const CaseStmt &S); 2285a23b91d542e336be5051ac54f394e860fb756911Chad Rosier void EmitAsmStmt(const AsmStmt &S); 22860dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 22873d8400d9a61aa4b63ff35e5cede405b32a41425eAnders Carlsson void EmitObjCForCollectionStmt(const ObjCForCollectionStmt &S); 228864d5d6c5903157c521af496479d06dc26032d718Anders Carlsson void EmitObjCAtTryStmt(const ObjCAtTryStmt &S); 228964d5d6c5903157c521af496479d06dc26032d718Anders Carlsson void EmitObjCAtThrowStmt(const ObjCAtThrowStmt &S); 229010cac6f7115b59a466bb8d2d51cdddeb38aadc37Chris Lattner void EmitObjCAtSynchronizedStmt(const ObjCAtSynchronizedStmt &S); 2291f85e193739c953358c865005855253af4f68a497John McCall void EmitObjCAutoreleasePoolStmt(const ObjCAutoreleasePoolStmt &S); 22920dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 229359a7000a79118e4c140885ccbb2ac6a686a73092John McCall void EnterCXXTryStmt(const CXXTryStmt &S, bool IsFnTryBlock = false); 229459a7000a79118e4c140885ccbb2ac6a686a73092John McCall void ExitCXXTryStmt(const CXXTryStmt &S, bool IsFnTryBlock = false); 22959fc6a7774643a810c8501dae2323e863fefb623eJohn McCall 22966815e941998659a55c20c147861b0f437928c3d8Anders Carlsson void EmitCXXTryStmt(const CXXTryStmt &S); 229798592d9c4dff79480fdc25b83988de03f912b647Reid Kleckner void EmitSEHTryStmt(const SEHTryStmt &S); 2298c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines void EmitSEHLeaveStmt(const SEHLeaveStmt &S); 229958878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar void EnterSEHTryStmt(const SEHTryStmt &S); 230058878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar void ExitSEHTryStmt(const SEHTryStmt &S); 230158878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar 230287d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar void startOutlinedSEHHelper(CodeGenFunction &ParentCGF, bool IsFilter, 230358878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar const Stmt *OutlinedStmt); 23040e2c34f92f00628d48968dfea096d36381f494cbStephen Hines 23050e2c34f92f00628d48968dfea096d36381f494cbStephen Hines llvm::Function *GenerateSEHFilterFunction(CodeGenFunction &ParentCGF, 23060e2c34f92f00628d48968dfea096d36381f494cbStephen Hines const SEHExceptStmt &Except); 23070e2c34f92f00628d48968dfea096d36381f494cbStephen Hines 230858878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar llvm::Function *GenerateSEHFinallyFunction(CodeGenFunction &ParentCGF, 230958878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar const SEHFinallyStmt &Finally); 231058878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar 231187d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar void EmitSEHExceptionCodeSave(CodeGenFunction &ParentCGF, 231287d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar llvm::Value *ParentFP, 231387d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar llvm::Value *EntryEBP); 23140e2c34f92f00628d48968dfea096d36381f494cbStephen Hines llvm::Value *EmitSEHExceptionCode(); 23150e2c34f92f00628d48968dfea096d36381f494cbStephen Hines llvm::Value *EmitSEHExceptionInfo(); 23160e2c34f92f00628d48968dfea096d36381f494cbStephen Hines llvm::Value *EmitSEHAbnormalTermination(); 23170e2c34f92f00628d48968dfea096d36381f494cbStephen Hines 231858878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar /// Scan the outlined statement for captures from the parent function. For 231958878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar /// each capture, mark the capture as escaped and emit a call to 232087d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// llvm.localrecover. Insert the localrecover result into the LocalDeclMap. 232158878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar void EmitCapturedLocals(CodeGenFunction &ParentCGF, const Stmt *OutlinedStmt, 232287d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar bool IsFilter); 232387d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar 232487d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// Recovers the address of a local in a parent function. ParentVar is the 232587d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// address of the variable used in the immediate parent function. It can 232687d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// either be an alloca or a call to llvm.localrecover if there are nested 232787d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// outlined functions. ParentFP is the frame pointer of the outermost parent 232887d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// frame. 232987d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar Address recoverAddrOfEscapedLocal(CodeGenFunction &ParentCGF, 233087d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar Address ParentVar, 233187d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar llvm::Value *ParentFP); 233258878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar 2333c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines void EmitCXXForRangeStmt(const CXXForRangeStmt &S, 2334176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines ArrayRef<const Attr *> Attrs = None); 23359cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer 23364967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar /// Returns calculated size of the specified type. 23374967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar llvm::Value *getTypeSize(QualType Ty); 2338176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines LValue InitCapturedStruct(const CapturedStmt &S); 2339524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir llvm::Function *EmitCapturedStmt(const CapturedStmt &S, CapturedRegionKind K); 2340c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines llvm::Function *GenerateCapturedStmtFunction(const CapturedStmt &S); 234187d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar Address GenerateCapturedStmtArgument(const CapturedStmt &S); 234287d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar llvm::Function *GenerateOpenMPCapturedStmtFunction(const CapturedStmt &S); 234387d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar void GenerateOpenMPCapturedVars(const CapturedStmt &S, 234487d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar SmallVectorImpl<llvm::Value *> &CapturedVars); 23454967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar void emitOMPSimpleStore(LValue LVal, RValue RVal, QualType RValTy, 23464967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar SourceLocation Loc); 234758878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar /// \brief Perform element by element copying of arrays with type \a 234858878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar /// OriginalType from \a SrcAddr to \a DestAddr using copying procedure 234958878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar /// generated by \a CopyGen. 235058878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar /// 235158878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar /// \param DestAddr Address of the destination array. 235258878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar /// \param SrcAddr Address of the source array. 235358878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar /// \param OriginalType Type of destination and source arrays. 235458878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar /// \param CopyGen Copying procedure that copies value of single array element 235558878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar /// to another single array element. 235658878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar void EmitOMPAggregateAssign( 235787d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar Address DestAddr, Address SrcAddr, QualType OriginalType, 235887d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar const llvm::function_ref<void(Address, Address)> &CopyGen); 235958878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar /// \brief Emit proper copying of data from one variable to another. 236058878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar /// 236158878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar /// \param OriginalType Original type of the copied variables. 236258878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar /// \param DestAddr Destination address. 236358878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar /// \param SrcAddr Source address. 236458878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar /// \param DestVD Destination variable used in \a CopyExpr (for arrays, has 236558878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar /// type of the base array element). 236658878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar /// \param SrcVD Source variable used in \a CopyExpr (for arrays, has type of 236758878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar /// the base array element). 236858878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar /// \param Copy Actual copygin expression for copying data from \a SrcVD to \a 236958878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar /// DestVD. 237087d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar void EmitOMPCopy(QualType OriginalType, 237187d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar Address DestAddr, Address SrcAddr, 237258878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar const VarDecl *DestVD, const VarDecl *SrcVD, 237358878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar const Expr *Copy); 237458878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar /// \brief Emit atomic update code for constructs: \a X = \a X \a BO \a E or 237558878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar /// \a X = \a E \a BO \a E. 237658878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar /// 237758878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar /// \param X Value to be updated. 237858878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar /// \param E Update value. 237958878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar /// \param BO Binary operation for update operation. 238058878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar /// \param IsXLHSInRHSPart true if \a X is LHS in RHS part of the update 238158878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar /// expression, false otherwise. 238258878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar /// \param AO Atomic ordering of the generated atomic instructions. 238358878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar /// \param CommonGen Code generator for complex expressions that cannot be 238458878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar /// expressed through atomicrmw instruction. 2385b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar /// \returns <true, OldAtomicValue> if simple 'atomicrmw' instruction was 2386b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar /// generated, <false, RValue::get(nullptr)> otherwise. 2387b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar std::pair<bool, RValue> EmitOMPAtomicSimpleUpdateExpr( 238858878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar LValue X, RValue E, BinaryOperatorKind BO, bool IsXLHSInRHSPart, 238958878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar llvm::AtomicOrdering AO, SourceLocation Loc, 239058878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar const llvm::function_ref<RValue(RValue)> &CommonGen); 239158878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar bool EmitOMPFirstprivateClause(const OMPExecutableDirective &D, 2392176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines OMPPrivateScope &PrivateScope); 2393176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines void EmitOMPPrivateClause(const OMPExecutableDirective &D, 2394176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines OMPPrivateScope &PrivateScope); 239558878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar /// \brief Emit code for copyin clause in \a D directive. The next code is 239658878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar /// generated at the start of outlined functions for directives: 239758878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar /// \code 239858878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar /// threadprivate_var1 = master_threadprivate_var1; 239958878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar /// operator=(threadprivate_var2, master_threadprivate_var2); 240058878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar /// ... 240158878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar /// __kmpc_barrier(&loc, global_tid); 240258878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar /// \endcode 240358878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar /// 240458878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar /// \param D OpenMP directive possibly with 'copyin' clause(s). 240558878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar /// \returns true if at least one copyin variable is found, false otherwise. 240658878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar bool EmitOMPCopyinClause(const OMPExecutableDirective &D); 240758878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar /// \brief Emit initial code for lastprivate variables. If some variable is 240858878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar /// not also firstprivate, then the default initialization is used. Otherwise 240958878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar /// initialization of this variable is performed by EmitOMPFirstprivateClause 241058878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar /// method. 241158878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar /// 241258878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar /// \param D Directive that may have 'lastprivate' directives. 241358878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar /// \param PrivateScope Private scope for capturing lastprivate variables for 241458878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar /// proper codegen in internal captured statement. 241558878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar /// 241658878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar /// \returns true if there is at least one lastprivate variable, false 241758878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar /// otherwise. 241858878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar bool EmitOMPLastprivateClauseInit(const OMPExecutableDirective &D, 241958878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar OMPPrivateScope &PrivateScope); 242058878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar /// \brief Emit final copying of lastprivate values to original variables at 242158878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar /// the end of the worksharing or simd directive. 242258878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar /// 242358878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar /// \param D Directive that has at least one 'lastprivate' directives. 242458878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar /// \param IsLastIterCond Boolean condition that must be set to 'i1 true' if 242558878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar /// it is the last iteration of the loop code in associated directive, or to 242687d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// 'i1 false' otherwise. If this item is nullptr, no final check is required. 242758878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar void EmitOMPLastprivateClauseFinal(const OMPExecutableDirective &D, 24284967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar bool NoFinals, 242987d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar llvm::Value *IsLastIterCond = nullptr); 24304967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar /// Emit initial code for linear clauses. 24314967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar void EmitOMPLinearClause(const OMPLoopDirective &D, 24324967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar CodeGenFunction::OMPPrivateScope &PrivateScope); 24334967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar /// Emit final code for linear clauses. 24344967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar /// \param CondGen Optional conditional code for final part of codegen for 24354967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar /// linear clause. 24364967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar void EmitOMPLinearClauseFinal( 24374967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar const OMPLoopDirective &D, 24384967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar const llvm::function_ref<llvm::Value *(CodeGenFunction &)> &CondGen); 243958878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar /// \brief Emit initial code for reduction variables. Creates reduction copies 244058878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar /// and initializes them with the values according to OpenMP standard. 244158878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar /// 244258878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar /// \param D Directive (possibly) with the 'reduction' clause. 244358878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar /// \param PrivateScope Private scope for capturing reduction variables for 244458878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar /// proper codegen in internal captured statement. 244558878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar /// 244658878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar void EmitOMPReductionClauseInit(const OMPExecutableDirective &D, 244758878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar OMPPrivateScope &PrivateScope); 244858878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar /// \brief Emit final update of reduction values to original variables at 244958878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar /// the end of the directive. 245058878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar /// 245158878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar /// \param D Directive that has at least one 'reduction' directives. 245258878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar void EmitOMPReductionClauseFinal(const OMPExecutableDirective &D); 245387d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// \brief Emit initial code for linear variables. Creates private copies 245487d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// and initializes them with the values according to OpenMP standard. 245587d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// 245687d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// \param D Directive (possibly) with the 'linear' clause. 245787d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar void EmitOMPLinearClauseInit(const OMPLoopDirective &D); 24586bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 24594967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar typedef const llvm::function_ref<void(CodeGenFunction & /*CGF*/, 24604967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar llvm::Value * /*OutlinedFn*/, 24614967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar const OMPTaskDataTy & /*Data*/)> 24624967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar TaskGenTy; 24634967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar void EmitOMPTaskBasedDirective(const OMPExecutableDirective &S, 24644967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar const RegionCodeGenTy &BodyGen, 24654967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar const TaskGenTy &TaskGen, OMPTaskDataTy &Data); 24664967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar 24676bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines void EmitOMPParallelDirective(const OMPParallelDirective &S); 24686bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines void EmitOMPSimdDirective(const OMPSimdDirective &S); 2469c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines void EmitOMPForDirective(const OMPForDirective &S); 2470176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines void EmitOMPForSimdDirective(const OMPForSimdDirective &S); 2471c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines void EmitOMPSectionsDirective(const OMPSectionsDirective &S); 2472c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines void EmitOMPSectionDirective(const OMPSectionDirective &S); 2473c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines void EmitOMPSingleDirective(const OMPSingleDirective &S); 2474176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines void EmitOMPMasterDirective(const OMPMasterDirective &S); 2475176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines void EmitOMPCriticalDirective(const OMPCriticalDirective &S); 2476c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines void EmitOMPParallelForDirective(const OMPParallelForDirective &S); 2477176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines void EmitOMPParallelForSimdDirective(const OMPParallelForSimdDirective &S); 2478c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines void EmitOMPParallelSectionsDirective(const OMPParallelSectionsDirective &S); 2479176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines void EmitOMPTaskDirective(const OMPTaskDirective &S); 2480176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines void EmitOMPTaskyieldDirective(const OMPTaskyieldDirective &S); 2481176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines void EmitOMPBarrierDirective(const OMPBarrierDirective &S); 2482176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines void EmitOMPTaskwaitDirective(const OMPTaskwaitDirective &S); 248387d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar void EmitOMPTaskgroupDirective(const OMPTaskgroupDirective &S); 2484176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines void EmitOMPFlushDirective(const OMPFlushDirective &S); 2485176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines void EmitOMPOrderedDirective(const OMPOrderedDirective &S); 2486176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines void EmitOMPAtomicDirective(const OMPAtomicDirective &S); 2487176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines void EmitOMPTargetDirective(const OMPTargetDirective &S); 248887d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar void EmitOMPTargetDataDirective(const OMPTargetDataDirective &S); 24894967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar void EmitOMPTargetEnterDataDirective(const OMPTargetEnterDataDirective &S); 24904967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar void EmitOMPTargetExitDataDirective(const OMPTargetExitDataDirective &S); 24914967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar void EmitOMPTargetUpdateDirective(const OMPTargetUpdateDirective &S); 24924967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar void EmitOMPTargetParallelDirective(const OMPTargetParallelDirective &S); 24934967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar void 24944967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar EmitOMPTargetParallelForDirective(const OMPTargetParallelForDirective &S); 2495176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines void EmitOMPTeamsDirective(const OMPTeamsDirective &S); 249687d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar void 249787d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar EmitOMPCancellationPointDirective(const OMPCancellationPointDirective &S); 249887d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar void EmitOMPCancelDirective(const OMPCancelDirective &S); 24994967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar void EmitOMPTaskLoopBasedDirective(const OMPLoopDirective &S); 250087d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar void EmitOMPTaskLoopDirective(const OMPTaskLoopDirective &S); 250187d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar void EmitOMPTaskLoopSimdDirective(const OMPTaskLoopSimdDirective &S); 250287d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar void EmitOMPDistributeDirective(const OMPDistributeDirective &S); 25034967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar void EmitOMPDistributeLoop(const OMPDistributeDirective &S); 25044967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar void EmitOMPDistributeParallelForDirective( 25054967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar const OMPDistributeParallelForDirective &S); 25064967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar void EmitOMPDistributeParallelForSimdDirective( 25074967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar const OMPDistributeParallelForSimdDirective &S); 25084967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar void EmitOMPDistributeSimdDirective(const OMPDistributeSimdDirective &S); 25094967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar void EmitOMPTargetParallelForSimdDirective( 25104967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar const OMPTargetParallelForSimdDirective &S); 25114967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar 25124967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar /// Emit outlined function for the target directive. 25134967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar static std::pair<llvm::Function * /*OutlinedFn*/, 25144967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar llvm::Constant * /*OutlinedFnID*/> 25154967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar EmitOMPTargetDirectiveOutlinedFunction(CodeGenModule &CGM, 25164967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar const OMPTargetDirective &S, 25174967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar StringRef ParentName, 25184967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar bool IsOffloadEntry); 2519b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar /// \brief Emit inner loop of the worksharing/simd construct. 2520b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar /// 2521b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar /// \param S Directive, for which the inner loop must be emitted. 2522b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar /// \param RequiresCleanup true, if directive has some associated private 2523b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar /// variables. 2524b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar /// \param LoopCond Bollean condition for loop continuation. 2525b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar /// \param IncExpr Increment expression for loop control variable. 2526b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar /// \param BodyGen Generator for the inner body of the inner loop. 2527b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar /// \param PostIncGen Genrator for post-increment code (required for ordered 2528b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar /// loop directvies). 2529b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar void EmitOMPInnerLoop( 2530b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar const Stmt &S, bool RequiresCleanup, const Expr *LoopCond, 2531b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar const Expr *IncExpr, 2532b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar const llvm::function_ref<void(CodeGenFunction &)> &BodyGen, 2533b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar const llvm::function_ref<void(CodeGenFunction &)> &PostIncGen); 253458878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar 253587d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar JumpDest getOMPCancelDestination(OpenMPDirectiveKind Kind); 25364967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar /// Emit initial code for loop counters of loop-based directives. 25374967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar void EmitOMPPrivateLoopCounters(const OMPLoopDirective &S, 25384967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar OMPPrivateScope &LoopScope); 253987d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar 25400e2c34f92f00628d48968dfea096d36381f494cbStephen Hinesprivate: 25410e2c34f92f00628d48968dfea096d36381f494cbStephen Hines /// Helpers for the OpenMP loop directives. 254287d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar void EmitOMPLoopBody(const OMPLoopDirective &D, JumpDest LoopExit); 25434967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar void EmitOMPSimdInit(const OMPLoopDirective &D, bool IsMonotonic = false); 25444967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar void EmitOMPSimdFinal( 25454967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar const OMPLoopDirective &D, 25464967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar const llvm::function_ref<llvm::Value *(CodeGenFunction &)> &CondGen); 254758878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar /// \brief Emit code for the worksharing loop-based directive. 254858878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar /// \return true, if this construct has any lastprivate clause, false - 254958878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar /// otherwise. 255058878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar bool EmitOMPWorksharingLoop(const OMPLoopDirective &S); 25514967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar void EmitOMPOuterLoop(bool IsMonotonic, bool DynamicOrOrdered, 25524967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar const OMPLoopDirective &S, OMPPrivateScope &LoopScope, bool Ordered, 25534967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar Address LB, Address UB, Address ST, Address IL, llvm::Value *Chunk); 25544967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar void EmitOMPForOuterLoop(const OpenMPScheduleTy &ScheduleKind, 25554967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar bool IsMonotonic, const OMPLoopDirective &S, 25564967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar OMPPrivateScope &LoopScope, bool Ordered, Address LB, 25574967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar Address UB, Address ST, Address IL, 25584967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar llvm::Value *Chunk); 25594967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar void EmitOMPDistributeOuterLoop( 25604967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar OpenMPDistScheduleClauseKind ScheduleKind, 25614967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar const OMPDistributeDirective &S, OMPPrivateScope &LoopScope, 25624967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar Address LB, Address UB, Address ST, Address IL, llvm::Value *Chunk); 256387d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// \brief Emit code for sections directive. 25644967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar void EmitSections(const OMPExecutableDirective &S); 25650e2c34f92f00628d48968dfea096d36381f494cbStephen Hines 25660e2c34f92f00628d48968dfea096d36381f494cbStephen Hinespublic: 2567524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir 25685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 25695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // LValue Expression Emission 25705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 25715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 257213e81737a433b23f8c662d10d1d57356122a8caaDaniel Dunbar /// GetUndefRValue - Get an appropriate 'undef' rvalue for the given type. 257313e81737a433b23f8c662d10d1d57356122a8caaDaniel Dunbar RValue GetUndefRValue(QualType Ty); 257413e81737a433b23f8c662d10d1d57356122a8caaDaniel Dunbar 2575ce1d38b8163650e473d7084e0686ed5a7956057bDaniel Dunbar /// EmitUnsupportedRValue - Emit a dummy r-value using the type of E 2576ce1d38b8163650e473d7084e0686ed5a7956057bDaniel Dunbar /// and issue an ErrorUnsupported style diagnostic (using the 2577ce1d38b8163650e473d7084e0686ed5a7956057bDaniel Dunbar /// provided Name). 2578ce1d38b8163650e473d7084e0686ed5a7956057bDaniel Dunbar RValue EmitUnsupportedRValue(const Expr *E, 2579ce1d38b8163650e473d7084e0686ed5a7956057bDaniel Dunbar const char *Name); 2580ce1d38b8163650e473d7084e0686ed5a7956057bDaniel Dunbar 25810dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// EmitUnsupportedLValue - Emit a dummy l-value using the type of E and issue 25820dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// an ErrorUnsupported style diagnostic (using the provided Name). 25836ba82a4a4b295e54cf192c3e98b28f39990c6194Daniel Dunbar LValue EmitUnsupportedLValue(const Expr *E, 25846ba82a4a4b295e54cf192c3e98b28f39990c6194Daniel Dunbar const char *Name); 25856ba82a4a4b295e54cf192c3e98b28f39990c6194Daniel Dunbar 25865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// EmitLValue - Emit code to compute a designator that specifies the location 25875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// of the expression. 25885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 25895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// This can return one of two things: a simple address or a bitfield 25905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// reference. In either case, the LLVM Value* in the LValue structure is 25915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// guaranteed to be an LLVM pointer type. 25925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 25935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// If this returns a bitfield reference, nothing about the pointee type of 25945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// the LLVM value is known: For example, it may not be a pointer to an 25955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// integer. 25965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 25975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// If this returns a normal address, and if the lvalue's C type is fixed 25985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// size, this method guarantees that the returned pointer type will point to 25995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// an LLVM type of the same size of the lvalue's type. If the lvalue has a 26005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// variable length type, this is not possible. 26015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 26025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LValue EmitLValue(const Expr *E); 26030dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 26047ac9ef1c82c779a5348ed11b3d10e01c58803b35Richard Smith /// \brief Same as EmitLValue but additionally we generate checking code to 26057ac9ef1c82c779a5348ed11b3d10e01c58803b35Richard Smith /// guard against undefined behavior. This is only suitable when we know 26067ac9ef1c82c779a5348ed11b3d10e01c58803b35Richard Smith /// that the address will be used to access the object. 26077ac9ef1c82c779a5348ed11b3d10e01c58803b35Richard Smith LValue EmitCheckedLValue(const Expr *E, TypeCheckKind TCK); 2608b14e62d5aee7522b98c410ee65bd750c2cfe6f01Mike Stump 260987d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar RValue convertTempToRValue(Address addr, QualType type, 26104ee7dc2369c1f0257a73b2e83a7d38fdebdd9176Nick Lewycky SourceLocation Loc); 26119d232c884ea9872d6555df0fd7359699819bc1f1John McCall 26129eda3abe7e183b05834947391c0cdc291f4ee0d8John McCall void EmitAtomicInit(Expr *E, LValue lvalue); 26139eda3abe7e183b05834947391c0cdc291f4ee0d8John McCall 26140e2c34f92f00628d48968dfea096d36381f494cbStephen Hines bool LValueIsSuitableForInlineAtomic(LValue Src); 26150e2c34f92f00628d48968dfea096d36381f494cbStephen Hines 26160e2c34f92f00628d48968dfea096d36381f494cbStephen Hines RValue EmitAtomicLoad(LValue LV, SourceLocation SL, 26170e2c34f92f00628d48968dfea096d36381f494cbStephen Hines AggValueSlot Slot = AggValueSlot::ignored()); 26180e2c34f92f00628d48968dfea096d36381f494cbStephen Hines 26194ee7dc2369c1f0257a73b2e83a7d38fdebdd9176Nick Lewycky RValue EmitAtomicLoad(LValue lvalue, SourceLocation loc, 26200e2c34f92f00628d48968dfea096d36381f494cbStephen Hines llvm::AtomicOrdering AO, bool IsVolatile = false, 26219eda3abe7e183b05834947391c0cdc291f4ee0d8John McCall AggValueSlot slot = AggValueSlot::ignored()); 26229eda3abe7e183b05834947391c0cdc291f4ee0d8John McCall 26239eda3abe7e183b05834947391c0cdc291f4ee0d8John McCall void EmitAtomicStore(RValue rvalue, LValue lvalue, bool isInit); 26249eda3abe7e183b05834947391c0cdc291f4ee0d8John McCall 26250e2c34f92f00628d48968dfea096d36381f494cbStephen Hines void EmitAtomicStore(RValue rvalue, LValue lvalue, llvm::AtomicOrdering AO, 26260e2c34f92f00628d48968dfea096d36381f494cbStephen Hines bool IsVolatile, bool isInit); 26270e2c34f92f00628d48968dfea096d36381f494cbStephen Hines 262858878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar std::pair<RValue, llvm::Value *> EmitAtomicCompareExchange( 26290e2c34f92f00628d48968dfea096d36381f494cbStephen Hines LValue Obj, RValue Expected, RValue Desired, SourceLocation Loc, 26304967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar llvm::AtomicOrdering Success = 26314967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar llvm::AtomicOrdering::SequentiallyConsistent, 26324967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar llvm::AtomicOrdering Failure = 26334967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar llvm::AtomicOrdering::SequentiallyConsistent, 26340e2c34f92f00628d48968dfea096d36381f494cbStephen Hines bool IsWeak = false, AggValueSlot Slot = AggValueSlot::ignored()); 26350e2c34f92f00628d48968dfea096d36381f494cbStephen Hines 263658878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar void EmitAtomicUpdate(LValue LVal, llvm::AtomicOrdering AO, 2637b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar const llvm::function_ref<RValue(RValue)> &UpdateOp, 263858878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar bool IsVolatile); 263958878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar 264026815d97c5743481e317f17a8d53a6819d061862John McCall /// EmitToMemory - Change a scalar value from its value 264126815d97c5743481e317f17a8d53a6819d061862John McCall /// representation to its in-memory representation. 264226815d97c5743481e317f17a8d53a6819d061862John McCall llvm::Value *EmitToMemory(llvm::Value *Value, QualType Ty); 264326815d97c5743481e317f17a8d53a6819d061862John McCall 264426815d97c5743481e317f17a8d53a6819d061862John McCall /// EmitFromMemory - Change a scalar value from its memory 264526815d97c5743481e317f17a8d53a6819d061862John McCall /// representation to its value representation. 264626815d97c5743481e317f17a8d53a6819d061862John McCall llvm::Value *EmitFromMemory(llvm::Value *Value, QualType Ty); 264726815d97c5743481e317f17a8d53a6819d061862John McCall 26489d9cc874bcc168474757a8f90476684b4a93ed76Daniel Dunbar /// EmitLoadOfScalar - Load a scalar value from an address, taking 26499d9cc874bcc168474757a8f90476684b4a93ed76Daniel Dunbar /// care to appropriately convert from the memory representation to 26509d9cc874bcc168474757a8f90476684b4a93ed76Daniel Dunbar /// the LLVM value representation. 265187d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar llvm::Value *EmitLoadOfScalar(Address Addr, bool Volatile, QualType Ty, 26524ee7dc2369c1f0257a73b2e83a7d38fdebdd9176Nick Lewycky SourceLocation Loc, 265387d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar AlignmentSource AlignSource = 265487d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar AlignmentSource::Type, 26556bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines llvm::MDNode *TBAAInfo = nullptr, 2656b37a73d5c6a0c8bb1f6e363d3b53980e4fa0ceadManman Ren QualType TBAABaseTy = QualType(), 265787d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar uint64_t TBAAOffset = 0, 265887d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar bool isNontemporal = false); 2659545d996ec5a3113f046944f11b27cc2d6cb055b4John McCall 2660545d996ec5a3113f046944f11b27cc2d6cb055b4John McCall /// EmitLoadOfScalar - Load a scalar value from an address, taking 2661545d996ec5a3113f046944f11b27cc2d6cb055b4John McCall /// care to appropriately convert from the memory representation to 2662545d996ec5a3113f046944f11b27cc2d6cb055b4John McCall /// the LLVM value representation. The l-value must be a simple 2663545d996ec5a3113f046944f11b27cc2d6cb055b4John McCall /// l-value. 26644ee7dc2369c1f0257a73b2e83a7d38fdebdd9176Nick Lewycky llvm::Value *EmitLoadOfScalar(LValue lvalue, SourceLocation Loc); 26659d9cc874bcc168474757a8f90476684b4a93ed76Daniel Dunbar 26669d9cc874bcc168474757a8f90476684b4a93ed76Daniel Dunbar /// EmitStoreOfScalar - Store a scalar value to an address, taking 26679d9cc874bcc168474757a8f90476684b4a93ed76Daniel Dunbar /// care to appropriately convert from the memory representation to 26689d9cc874bcc168474757a8f90476684b4a93ed76Daniel Dunbar /// the LLVM value representation. 266987d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar void EmitStoreOfScalar(llvm::Value *Value, Address Addr, 267087d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar bool Volatile, QualType Ty, 267187d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar AlignmentSource AlignSource = AlignmentSource::Type, 26726bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines llvm::MDNode *TBAAInfo = nullptr, bool isInit = false, 2673b37a73d5c6a0c8bb1f6e363d3b53980e4fa0ceadManman Ren QualType TBAABaseTy = QualType(), 267487d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar uint64_t TBAAOffset = 0, bool isNontemporal = false); 2675545d996ec5a3113f046944f11b27cc2d6cb055b4John McCall 2676545d996ec5a3113f046944f11b27cc2d6cb055b4John McCall /// EmitStoreOfScalar - Store a scalar value to an address, taking 2677545d996ec5a3113f046944f11b27cc2d6cb055b4John McCall /// care to appropriately convert from the memory representation to 2678545d996ec5a3113f046944f11b27cc2d6cb055b4John McCall /// the LLVM value representation. The l-value must be a simple 26797a7ee3033e44b45630981355460ef89efa0bdcc4David Chisnall /// l-value. The isInit flag indicates whether this is an initialization. 26807a7ee3033e44b45630981355460ef89efa0bdcc4David Chisnall /// If so, atomic qualifiers are ignored and the store is always non-atomic. 26817a7ee3033e44b45630981355460ef89efa0bdcc4David Chisnall void EmitStoreOfScalar(llvm::Value *value, LValue lvalue, bool isInit=false); 26829d9cc874bcc168474757a8f90476684b4a93ed76Daniel Dunbar 26835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// EmitLoadOfLValue - Given an expression that represents a value lvalue, 26845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// this method emits the address of the lvalue, then loads the result as an 26855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// rvalue, returning the rvalue. 26864ee7dc2369c1f0257a73b2e83a7d38fdebdd9176Nick Lewycky RValue EmitLoadOfLValue(LValue V, SourceLocation Loc); 2687545d996ec5a3113f046944f11b27cc2d6cb055b4John McCall RValue EmitLoadOfExtVectorElementLValue(LValue V); 2688545d996ec5a3113f046944f11b27cc2d6cb055b4John McCall RValue EmitLoadOfBitfieldLValue(LValue LV); 26896bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines RValue EmitLoadOfGlobalRegLValue(LValue LV); 26900dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 26915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// EmitStoreThroughLValue - Store the specified rvalue into the specified 26925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// lvalue, where both are guaranteed to the have the same type, and that type 26935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// is 'Ty'. 26940e2c34f92f00628d48968dfea096d36381f494cbStephen Hines void EmitStoreThroughLValue(RValue Src, LValue Dst, bool isInit = false); 2695545d996ec5a3113f046944f11b27cc2d6cb055b4John McCall void EmitStoreThroughExtVectorComponentLValue(RValue Src, LValue Dst); 26966bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines void EmitStoreThroughGlobalRegLValue(RValue Src, LValue Dst); 2697ed3849b456d64d124bddc7ac044f3ce590bd9d69Daniel Dunbar 26984ee7dc2369c1f0257a73b2e83a7d38fdebdd9176Nick Lewycky /// EmitStoreThroughBitfieldLValue - Store Src into Dst with same constraints 26994ee7dc2369c1f0257a73b2e83a7d38fdebdd9176Nick Lewycky /// as EmitStoreThroughLValue. 2700ed3849b456d64d124bddc7ac044f3ce590bd9d69Daniel Dunbar /// 27010dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// \param Result [out] - If non-null, this will be set to a Value* for the 27020dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// bit-field contents after the store, appropriate for use as the result of 27030dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// an assignment to the bit-field. 2704545d996ec5a3113f046944f11b27cc2d6cb055b4John McCall void EmitStoreThroughBitfieldLValue(RValue Src, LValue Dst, 27056bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines llvm::Value **Result=nullptr); 27060dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 270783ce9d4a552987d34cbd500e983db8d770232379John McCall /// Emit an l-value for an assignment (simple or compound) of complex type. 270883ce9d4a552987d34cbd500e983db8d770232379John McCall LValue EmitComplexAssignmentLValue(const BinaryOperator *E); 27092a41637a995affa1563f4d82a8b026e326a2faa0John McCall LValue EmitComplexCompoundAssignmentLValue(const CompoundAssignOperator *E); 27100e2c34f92f00628d48968dfea096d36381f494cbStephen Hines LValue EmitScalarCompoundAssignWithComplex(const CompoundAssignOperator *E, 27110e2c34f92f00628d48968dfea096d36381f494cbStephen Hines llvm::Value *&Result); 271283ce9d4a552987d34cbd500e983db8d770232379John McCall 2713fc8f0e14ad142ed811e90fbd9a30e419e301c717Chris Lattner // Note: only available for agg return types 271480e62c29fe21cd06c93eba6e72b7e32dca06fcf9Daniel Dunbar LValue EmitBinaryOperatorLValue(const BinaryOperator *E); 27152a41637a995affa1563f4d82a8b026e326a2faa0John McCall LValue EmitCompoundAssignmentLValue(const CompoundAssignOperator *E); 27165b5c9ef865607e179413462dcd71bcebb5b7daaeDaniel Dunbar // Note: only available for agg return types 271722c940ee588a420cd2e6c8f68be2ac3cc80061ffChristopher Lamb LValue EmitCallExprLValue(const CallExpr *E); 27185b5c9ef865607e179413462dcd71bcebb5b7daaeDaniel Dunbar // Note: only available for agg return types 27195b5c9ef865607e179413462dcd71bcebb5b7daaeDaniel Dunbar LValue EmitVAArgExprLValue(const VAArgExpr *E); 27205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LValue EmitDeclRefLValue(const DeclRefExpr *E); 27215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LValue EmitStringLiteralLValue(const StringLiteral *E); 2722eaf2bb89eb2aad3b80673de30febe52df43c10ecChris Lattner LValue EmitObjCEncodeExprLValue(const ObjCEncodeExpr *E); 2723d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner LValue EmitPredefinedLValue(const PredefinedExpr *E); 27245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LValue EmitUnaryOpLValue(const UnaryOperator *E); 2725a0a628f839cf50844cc0f226bd9cb72485f98f91Richard Smith LValue EmitArraySubscriptExpr(const ArraySubscriptExpr *E, 2726a0a628f839cf50844cc0f226bd9cb72485f98f91Richard Smith bool Accessed = false); 272787d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar LValue EmitOMPArraySectionExpr(const OMPArraySectionExpr *E, 272887d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar bool IsLowerBound = true); 2729213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman LValue EmitExtVectorElementExpr(const ExtVectorElementExpr *E); 2730b84a06e68ffd71da22e3c75b6e4bbdba37816413Devang Patel LValue EmitMemberExpr(const MemberExpr *E); 2731820bca41c3899374775d2a1dfc2ef2e22aaf1c7bFariborz Jahanian LValue EmitObjCIsaExpr(const ObjCIsaExpr *E); 273206e863f2902b8ba55b056308875c19f7ba3dab25Eli Friedman LValue EmitCompoundLiteralLValue(const CompoundLiteralExpr *E); 273313ec9100ca6bc03b5ce8832e4a0fcb724d47bcb1Richard Smith LValue EmitInitListLValue(const InitListExpr *E); 273456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall LValue EmitConditionalOperatorLValue(const AbstractConditionalOperator *E); 273575dfedaf702822c9e51a4f3c5d3ecf2d2ad99272Chris Lattner LValue EmitCastLValue(const CastExpr *E); 273603e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor LValue EmitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *E); 2737e996ffd240f20a1048179d7727a6ee3227261921John McCall LValue EmitOpaqueValueLValue(const OpaqueValueExpr *e); 2738176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines 273987d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar Address EmitExtVectorElementLValue(LValue V); 27409cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer 27414ee7dc2369c1f0257a73b2e83a7d38fdebdd9176Nick Lewycky RValue EmitRValueForField(LValue LV, const FieldDecl *FD, SourceLocation Loc); 2742eaf856db5d1a272dc7188937206ef4572836f82aAnton Korobeynikov 274387d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar Address EmitArrayToPointerDecay(const Expr *Array, 274487d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar AlignmentSource *AlignSource = nullptr); 274587d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar 2746dd2ecee313b558a9b621ec003b45e0fbc83508d7John McCall class ConstantEmission { 2747dd2ecee313b558a9b621ec003b45e0fbc83508d7John McCall llvm::PointerIntPair<llvm::Constant*, 1, bool> ValueAndIsReference; 2748dd2ecee313b558a9b621ec003b45e0fbc83508d7John McCall ConstantEmission(llvm::Constant *C, bool isReference) 2749dd2ecee313b558a9b621ec003b45e0fbc83508d7John McCall : ValueAndIsReference(C, isReference) {} 2750dd2ecee313b558a9b621ec003b45e0fbc83508d7John McCall public: 2751dd2ecee313b558a9b621ec003b45e0fbc83508d7John McCall ConstantEmission() {} 2752dd2ecee313b558a9b621ec003b45e0fbc83508d7John McCall static ConstantEmission forReference(llvm::Constant *C) { 2753dd2ecee313b558a9b621ec003b45e0fbc83508d7John McCall return ConstantEmission(C, true); 2754dd2ecee313b558a9b621ec003b45e0fbc83508d7John McCall } 2755dd2ecee313b558a9b621ec003b45e0fbc83508d7John McCall static ConstantEmission forValue(llvm::Constant *C) { 2756dd2ecee313b558a9b621ec003b45e0fbc83508d7John McCall return ConstantEmission(C, false); 2757dd2ecee313b558a9b621ec003b45e0fbc83508d7John McCall } 2758dd2ecee313b558a9b621ec003b45e0fbc83508d7John McCall 27590e2c34f92f00628d48968dfea096d36381f494cbStephen Hines explicit operator bool() const { 27606bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines return ValueAndIsReference.getOpaqueValue() != nullptr; 27616bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines } 2762dd2ecee313b558a9b621ec003b45e0fbc83508d7John McCall 2763dd2ecee313b558a9b621ec003b45e0fbc83508d7John McCall bool isReference() const { return ValueAndIsReference.getInt(); } 2764dd2ecee313b558a9b621ec003b45e0fbc83508d7John McCall LValue getReferenceLValue(CodeGenFunction &CGF, Expr *refExpr) const { 2765dd2ecee313b558a9b621ec003b45e0fbc83508d7John McCall assert(isReference()); 2766dd2ecee313b558a9b621ec003b45e0fbc83508d7John McCall return CGF.MakeNaturalAlignAddrLValue(ValueAndIsReference.getPointer(), 2767dd2ecee313b558a9b621ec003b45e0fbc83508d7John McCall refExpr->getType()); 2768dd2ecee313b558a9b621ec003b45e0fbc83508d7John McCall } 2769dd2ecee313b558a9b621ec003b45e0fbc83508d7John McCall 2770dd2ecee313b558a9b621ec003b45e0fbc83508d7John McCall llvm::Constant *getValue() const { 2771dd2ecee313b558a9b621ec003b45e0fbc83508d7John McCall assert(!isReference()); 2772dd2ecee313b558a9b621ec003b45e0fbc83508d7John McCall return ValueAndIsReference.getPointer(); 2773dd2ecee313b558a9b621ec003b45e0fbc83508d7John McCall } 2774dd2ecee313b558a9b621ec003b45e0fbc83508d7John McCall }; 2775dd2ecee313b558a9b621ec003b45e0fbc83508d7John McCall 2776f4b88a45902af1802a1cb42ba48b1c474474f228John McCall ConstantEmission tryEmitAsConstant(DeclRefExpr *refExpr); 2777dd2ecee313b558a9b621ec003b45e0fbc83508d7John McCall 27784b9c2d235fb9449e249d74f48ecfec601650de93John McCall RValue EmitPseudoObjectRValue(const PseudoObjectExpr *e, 27794b9c2d235fb9449e249d74f48ecfec601650de93John McCall AggValueSlot slot = AggValueSlot::ignored()); 27804b9c2d235fb9449e249d74f48ecfec601650de93John McCall LValue EmitPseudoObjectLValue(const PseudoObjectExpr *e); 27814b9c2d235fb9449e249d74f48ecfec601650de93John McCall 27822a03192a02dbf4fdff438d1e658356bde871aba4Daniel Dunbar llvm::Value *EmitIvarOffset(const ObjCInterfaceDecl *Interface, 278329e0bccf2bcce22b877f8b2ed173f564c116b97eDaniel Dunbar const ObjCIvarDecl *Ivar); 2784377ecc7996dce6803f7b7b6208cab5e197c9c5b8Eli Friedman LValue EmitLValueForField(LValue Base, const FieldDecl* Field); 2785f5ebf9bf1df10ac15ba32a4b24dfe171b7848c58John McCall LValue EmitLValueForLambdaField(const FieldDecl *Field); 27869cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer 278706a2970e9480c6d02b367b2f970baff29b9f9721Anders Carlsson /// EmitLValueForFieldInitialization - Like EmitLValueForField, except that 278806a2970e9480c6d02b367b2f970baff29b9f9721Anders Carlsson /// if the Field is a reference, this will return the address of the reference 278906a2970e9480c6d02b367b2f970baff29b9f9721Anders Carlsson /// and not the address of the value stored in the reference. 2790377ecc7996dce6803f7b7b6208cab5e197c9c5b8Eli Friedman LValue EmitLValueForFieldInitialization(LValue Base, 2791377ecc7996dce6803f7b7b6208cab5e197c9c5b8Eli Friedman const FieldDecl* Field); 27929cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer 279345012a7ef5abf1042c893f3f2fa5c23cb5485ea9Fariborz Jahanian LValue EmitLValueForIvar(QualType ObjectTy, 279445012a7ef5abf1042c893f3f2fa5c23cb5485ea9Fariborz Jahanian llvm::Value* Base, const ObjCIvarDecl *Ivar, 279529e0bccf2bcce22b877f8b2ed173f564c116b97eDaniel Dunbar unsigned CVRQualifiers); 2796fd64bb635dc221baa19f81d5d2a084f7eb269f7fFariborz Jahanian 2797b58d017f2b9eeed33f2ab3ede968b89cf5296bf2Anders Carlsson LValue EmitCXXConstructLValue(const CXXConstructExpr *E); 2798e61c9e80a108b5db7e5f0e702f0e455d737c6390Anders Carlsson LValue EmitCXXBindTemporaryLValue(const CXXBindTemporaryExpr *E); 279931a3702618ab49578542cffee20ba0c8859b9d1eEli Friedman LValue EmitLambdaLValue(const LambdaExpr *E); 2800c2e84ae9a6d25cea3e583c768e576b4c981ec028Mike Stump LValue EmitCXXTypeidLValue(const CXXTypeidExpr *E); 2801c5f804636e367ef744fd24cf88f7c956a5af0434Nico Weber LValue EmitCXXUuidofLValue(const CXXUuidofExpr *E); 28029cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer 28030a04d77bde7e3a661c2b41b60630d125d09ed6efDaniel Dunbar LValue EmitObjCMessageExprLValue(const ObjCMessageExpr *E); 2804391d77a26382dddf25da73e29fc1fa5aaaea4c6fChris Lattner LValue EmitObjCIvarRefLValue(const ObjCIvarRefExpr *E); 2805654599454c8e6cc83b1b9b3af43c49c2f66a26cbChris Lattner LValue EmitStmtExprLValue(const StmtExpr *E); 28068bfd31f9dad09cd52225d868bbd92a9bebe87775Fariborz Jahanian LValue EmitPointerToDataMemberBinaryExpr(const BinaryOperator *E); 280703b2960c14aede6ac82bdef32247094ebb72fa69Fariborz Jahanian LValue EmitObjCSelectorLValue(const ObjCSelectorExpr *E); 28083b8e0b7f96164e8c49d2a833da26edd960f5da1fYunzhong Gao void EmitDeclRefExprDbgValue(const DeclRefExpr *E, llvm::Constant *Init); 280956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 28105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 2811883f6a7cc7dccb1d675e27121a82614d63492a8dChris Lattner // Scalar Expression Emission 28125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 28135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 28140dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// EmitCall - Generate a call of the given function, expecting the given 28150dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// result type, and using the given argument list which specifies both the 28160dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// LLVM arguments and the types they were derived from. 281787d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar RValue EmitCall(const CGFunctionInfo &FnInfo, llvm::Value *Callee, 281887d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar ReturnValueSlot ReturnValue, const CallArgList &Args, 281987d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar CGCalleeInfo CalleeInfo = CGCalleeInfo(), 28206bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines llvm::Instruction **callOrInvoke = nullptr); 28211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2822176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines RValue EmitCall(QualType FnType, llvm::Value *Callee, const CallExpr *E, 2823d2490a91341b57df7a7e54f8a707e7ecde2eeb4eAnders Carlsson ReturnValueSlot ReturnValue, 282487d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar CGCalleeInfo CalleeInfo = CGCalleeInfo(), 28250e2c34f92f00628d48968dfea096d36381f494cbStephen Hines llvm::Value *Chain = nullptr); 28269cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer RValue EmitCallExpr(const CallExpr *E, 2827d2490a91341b57df7a7e54f8a707e7ecde2eeb4eAnders Carlsson ReturnValueSlot ReturnValue = ReturnValueSlot()); 28281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 282987d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar void checkTargetFeatures(const CallExpr *E, const FunctionDecl *TargetDecl); 283087d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar 2831bd7370a78604e9a20d698bfe328c1e43f12a0613John McCall llvm::CallInst *EmitRuntimeCall(llvm::Value *callee, 2832bd7370a78604e9a20d698bfe328c1e43f12a0613John McCall const Twine &name = ""); 2833bd7370a78604e9a20d698bfe328c1e43f12a0613John McCall llvm::CallInst *EmitRuntimeCall(llvm::Value *callee, 2834bd7370a78604e9a20d698bfe328c1e43f12a0613John McCall ArrayRef<llvm::Value*> args, 2835bd7370a78604e9a20d698bfe328c1e43f12a0613John McCall const Twine &name = ""); 2836bd7370a78604e9a20d698bfe328c1e43f12a0613John McCall llvm::CallInst *EmitNounwindRuntimeCall(llvm::Value *callee, 2837bd7370a78604e9a20d698bfe328c1e43f12a0613John McCall const Twine &name = ""); 2838bd7370a78604e9a20d698bfe328c1e43f12a0613John McCall llvm::CallInst *EmitNounwindRuntimeCall(llvm::Value *callee, 2839bd7370a78604e9a20d698bfe328c1e43f12a0613John McCall ArrayRef<llvm::Value*> args, 2840bd7370a78604e9a20d698bfe328c1e43f12a0613John McCall const Twine &name = ""); 2841bd7370a78604e9a20d698bfe328c1e43f12a0613John McCall 2842f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall llvm::CallSite EmitCallOrInvoke(llvm::Value *Callee, 28432d3ba4f5a923a90c3fc290ddfba5e36c2d0a9b46Chris Lattner ArrayRef<llvm::Value *> Args, 28448cc488fefb2fb04bc8d5398da29f0182f97934cfChris Lattner const Twine &Name = ""); 2845bd7370a78604e9a20d698bfe328c1e43f12a0613John McCall llvm::CallSite EmitRuntimeCallOrInvoke(llvm::Value *callee, 2846bd7370a78604e9a20d698bfe328c1e43f12a0613John McCall ArrayRef<llvm::Value*> args, 2847bd7370a78604e9a20d698bfe328c1e43f12a0613John McCall const Twine &name = ""); 2848bd7370a78604e9a20d698bfe328c1e43f12a0613John McCall llvm::CallSite EmitRuntimeCallOrInvoke(llvm::Value *callee, 2849bd7370a78604e9a20d698bfe328c1e43f12a0613John McCall const Twine &name = ""); 2850bd7370a78604e9a20d698bfe328c1e43f12a0613John McCall void EmitNoreturnRuntimeCallOrInvoke(llvm::Value *callee, 2851bd7370a78604e9a20d698bfe328c1e43f12a0613John McCall ArrayRef<llvm::Value*> args); 2852f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall 28532726267f094a0c1f5ac5b501ec5a9898c58876bfFariborz Jahanian llvm::Value *BuildAppleKextVirtualCall(const CXXMethodDecl *MD, 28542726267f094a0c1f5ac5b501ec5a9898c58876bfFariborz Jahanian NestedNameSpecifier *Qual, 28552acc6e3feda5e4f7d9009bdcf8b1cd777fecfe2dChris Lattner llvm::Type *Ty); 2856ccd5259d33cbbdd6f5fbf7ccab4cb4a2702309eaFariborz Jahanian 2857ccd5259d33cbbdd6f5fbf7ccab4cb4a2702309eaFariborz Jahanian llvm::Value *BuildAppleKextVirtualDestructorCall(const CXXDestructorDecl *DD, 2858ccd5259d33cbbdd6f5fbf7ccab4cb4a2702309eaFariborz Jahanian CXXDtorType Type, 2859771c678c04f5f685b4f188ec6c2fd88ad0f7457fFariborz Jahanian const CXXRecordDecl *RD); 2860566abee1e9828a7700b51e4d17ea08234fde3bb4Anders Carlsson 2861176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines RValue 2862176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines EmitCXXMemberOrOperatorCall(const CXXMethodDecl *MD, llvm::Value *Callee, 2863176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines ReturnValueSlot ReturnValue, llvm::Value *This, 2864176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines llvm::Value *ImplicitParam, 2865176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines QualType ImplicitParamTy, const CallExpr *E); 28664967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar RValue EmitCXXDestructorCall(const CXXDestructorDecl *DD, llvm::Value *Callee, 28674967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar llvm::Value *This, llvm::Value *ImplicitParam, 28684967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar QualType ImplicitParamTy, const CallExpr *E, 28694967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar StructorType Type); 2870a1736c0c750d4514a5d8fda36670addf1e4de54aAnders Carlsson RValue EmitCXXMemberCallExpr(const CXXMemberCallExpr *E, 2871a1736c0c750d4514a5d8fda36670addf1e4de54aAnders Carlsson ReturnValueSlot ReturnValue); 28720e2c34f92f00628d48968dfea096d36381f494cbStephen Hines RValue EmitCXXMemberOrOperatorMemberCallExpr(const CallExpr *CE, 28730e2c34f92f00628d48968dfea096d36381f494cbStephen Hines const CXXMethodDecl *MD, 28740e2c34f92f00628d48968dfea096d36381f494cbStephen Hines ReturnValueSlot ReturnValue, 28750e2c34f92f00628d48968dfea096d36381f494cbStephen Hines bool HasQualifier, 28760e2c34f92f00628d48968dfea096d36381f494cbStephen Hines NestedNameSpecifier *Qualifier, 28770e2c34f92f00628d48968dfea096d36381f494cbStephen Hines bool IsArrow, const Expr *Base); 28780e2c34f92f00628d48968dfea096d36381f494cbStephen Hines // Compute the object pointer. 287987d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar Address EmitCXXMemberDataPointerAddress(const Expr *E, Address base, 288087d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar llvm::Value *memberPtr, 288187d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar const MemberPointerType *memberPtrType, 288287d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar AlignmentSource *AlignSource = nullptr); 2883a1736c0c750d4514a5d8fda36670addf1e4de54aAnders Carlsson RValue EmitCXXMemberPointerCallExpr(const CXXMemberCallExpr *E, 2884a1736c0c750d4514a5d8fda36670addf1e4de54aAnders Carlsson ReturnValueSlot ReturnValue); 28855549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek 28860f294632f36459174199b77699e339715244b5abAnders Carlsson RValue EmitCXXOperatorMemberCallExpr(const CXXOperatorCallExpr *E, 2887a1736c0c750d4514a5d8fda36670addf1e4de54aAnders Carlsson const CXXMethodDecl *MD, 2888a1736c0c750d4514a5d8fda36670addf1e4de54aAnders Carlsson ReturnValueSlot ReturnValue); 28891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 28906c0aa5ff6e6253db0f993053599e2a52b5b93b2dPeter Collingbourne RValue EmitCUDAKernelCallExpr(const CUDAKernelCallExpr *E, 28916c0aa5ff6e6253db0f993053599e2a52b5b93b2dPeter Collingbourne ReturnValueSlot ReturnValue); 28926c0aa5ff6e6253db0f993053599e2a52b5b93b2dPeter Collingbourne 28934967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar RValue EmitCUDADevicePrintfCallExpr(const CallExpr *E, 28944967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar ReturnValueSlot ReturnValue); 28959cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer 28961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump RValue EmitBuiltinExpr(const FunctionDecl *FD, 28970e2c34f92f00628d48968dfea096d36381f494cbStephen Hines unsigned BuiltinID, const CallExpr *E, 28980e2c34f92f00628d48968dfea096d36381f494cbStephen Hines ReturnValueSlot ReturnValue); 28995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2900a1736c0c750d4514a5d8fda36670addf1e4de54aAnders Carlsson RValue EmitBlockCallExpr(const CallExpr *E, ReturnValueSlot ReturnValue); 290109429b962811f2c0a7a81a1b0a89f96f5878b20cMike Stump 29020dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// EmitTargetBuiltinExpr - Emit the given builtin call. Returns 0 if the call 29030dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// is unhandled by the current target. 2904f02e9ddf5efc75917af712b3c7f909581205f0a5Daniel Dunbar llvm::Value *EmitTargetBuiltinExpr(unsigned BuiltinID, const CallExpr *E); 2905f02e9ddf5efc75917af712b3c7f909581205f0a5Daniel Dunbar 29068137a607eebe799d95fd05226fb91119a5b054b0Kevin Qin llvm::Value *EmitAArch64CompareBuiltinExpr(llvm::Value *Op, llvm::Type *Ty, 29078137a607eebe799d95fd05226fb91119a5b054b0Kevin Qin const llvm::CmpInst::Predicate Fp, 29088137a607eebe799d95fd05226fb91119a5b054b0Kevin Qin const llvm::CmpInst::Predicate Ip, 29098137a607eebe799d95fd05226fb91119a5b054b0Kevin Qin const llvm::Twine &Name = ""); 29102752c0137d95aa2f4ee1cdff4b564bac842e041bChris Lattner llvm::Value *EmitARMBuiltinExpr(unsigned BuiltinID, const CallExpr *E); 2911651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 2912651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines llvm::Value *EmitCommonNeonBuiltinExpr(unsigned BuiltinID, 2913651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines unsigned LLVMIntrinsic, 2914651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines unsigned AltLLVMIntrinsic, 2915651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines const char *NameHint, 2916651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines unsigned Modifier, 2917651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines const CallExpr *E, 2918651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines SmallVectorImpl<llvm::Value *> &Ops, 291987d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar Address PtrOp0, Address PtrOp1); 2920651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines llvm::Function *LookupNeonLLVMIntrinsic(unsigned IntrinsicID, 2921651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines unsigned Modifier, llvm::Type *ArgTy, 2922651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines const CallExpr *E); 29239cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer llvm::Value *EmitNeonCall(llvm::Function *F, 2924686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVectorImpl<llvm::Value*> &O, 2925db3d4d036037f379f12643e067b229862d61e932Bob Wilson const char *name, 292661eecf5aea018ea65c9ab0bccacd2996b15c632dNate Begeman unsigned shift = 0, bool rightshift = false); 2927cf55652cf668c1402eee0b12edd2e5a1bc34d7a1Bob Wilson llvm::Value *EmitNeonSplat(llvm::Value *V, llvm::Constant *Idx); 29282acc6e3feda5e4f7d9009bdcf8b1cd777fecfe2dChris Lattner llvm::Value *EmitNeonShiftVector(llvm::Value *V, llvm::Type *Ty, 292961eecf5aea018ea65c9ab0bccacd2996b15c632dNate Begeman bool negateForRightShift); 29307f0ff70c391afeb7811b7ddcb06bfbbd5c6cf8f9Amaury de la Vieuville llvm::Value *EmitNeonRShiftImm(llvm::Value *Vec, llvm::Value *Amt, 29317f0ff70c391afeb7811b7ddcb06bfbbd5c6cf8f9Amaury de la Vieuville llvm::Type *Ty, bool usgn, const char *name); 2932651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines llvm::Value *vectorWrapScalar16(llvm::Value *Op); 29336bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines llvm::Value *EmitAArch64BuiltinExpr(unsigned BuiltinID, const CallExpr *E); 29349cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer 2935795b10062c2eaffae9e04241fb1a73cdbcb24a37Bill Wendling llvm::Value *BuildVector(ArrayRef<llvm::Value*> Ops); 2936564f1de67d7ba43646b8740db86d6269e3dfbe0bAnders Carlsson llvm::Value *EmitX86BuiltinExpr(unsigned BuiltinID, const CallExpr *E); 2937564f1de67d7ba43646b8740db86d6269e3dfbe0bAnders Carlsson llvm::Value *EmitPPCBuiltinExpr(unsigned BuiltinID, const CallExpr *E); 293887d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar llvm::Value *EmitAMDGPUBuiltinExpr(unsigned BuiltinID, const CallExpr *E); 293958878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar llvm::Value *EmitSystemZBuiltinExpr(unsigned BuiltinID, const CallExpr *E); 294087d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar llvm::Value *EmitNVPTXBuiltinExpr(unsigned BuiltinID, const CallExpr *E); 294187d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar llvm::Value *EmitWebAssemblyBuiltinExpr(unsigned BuiltinID, 294287d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar const CallExpr *E); 29430dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 2944ed7c618f849e2541b1d0288c43154937652c5b15Daniel Dunbar llvm::Value *EmitObjCProtocolExpr(const ObjCProtocolExpr *E); 29457f02f721d48772e4eee4fccd8af4f800be1bbc1eChris Lattner llvm::Value *EmitObjCStringLiteral(const ObjCStringLiteral *E); 2946eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard llvm::Value *EmitObjCBoxedExpr(const ObjCBoxedExpr *E); 2947ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek llvm::Value *EmitObjCArrayLiteral(const ObjCArrayLiteral *E); 2948ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek llvm::Value *EmitObjCDictionaryLiteral(const ObjCDictionaryLiteral *E); 2949ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek llvm::Value *EmitObjCCollectionLiteral(const Expr *E, 2950ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek const ObjCMethodDecl *MethodWithObjects); 29518fdf32822be2238aa7db62d40e75b168b637ab7dChris Lattner llvm::Value *EmitObjCSelectorExpr(const ObjCSelectorExpr *E); 2952ef072fd2f3347cfd857d6eb787b245b950771430John McCall RValue EmitObjCMessageExpr(const ObjCMessageExpr *E, 2953ef072fd2f3347cfd857d6eb787b245b950771430John McCall ReturnValueSlot Return = ReturnValueSlot()); 29548fdf32822be2238aa7db62d40e75b168b637ab7dChris Lattner 2955f85e193739c953358c865005855253af4f68a497John McCall /// Retrieves the default cleanup kind for an ARC cleanup. 2956f85e193739c953358c865005855253af4f68a497John McCall /// Except under -fobjc-arc-eh, ARC cleanups are normal-only. 2957f85e193739c953358c865005855253af4f68a497John McCall CleanupKind getARCCleanupKind() { 2958f85e193739c953358c865005855253af4f68a497John McCall return CGM.getCodeGenOpts().ObjCAutoRefCountExceptions 2959f85e193739c953358c865005855253af4f68a497John McCall ? NormalAndEHCleanup : NormalCleanup; 2960f85e193739c953358c865005855253af4f68a497John McCall } 2961f85e193739c953358c865005855253af4f68a497John McCall 2962f85e193739c953358c865005855253af4f68a497John McCall // ARC primitives. 296387d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar void EmitARCInitWeak(Address addr, llvm::Value *value); 296487d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar void EmitARCDestroyWeak(Address addr); 296587d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar llvm::Value *EmitARCLoadWeak(Address addr); 296687d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar llvm::Value *EmitARCLoadWeakRetained(Address addr); 296787d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar llvm::Value *EmitARCStoreWeak(Address addr, llvm::Value *value, bool ignored); 296887d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar void EmitARCCopyWeak(Address dst, Address src); 296987d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar void EmitARCMoveWeak(Address dst, Address src); 2970f85e193739c953358c865005855253af4f68a497John McCall llvm::Value *EmitARCRetainAutorelease(QualType type, llvm::Value *value); 2971f85e193739c953358c865005855253af4f68a497John McCall llvm::Value *EmitARCRetainAutoreleaseNonBlock(llvm::Value *value); 2972545d996ec5a3113f046944f11b27cc2d6cb055b4John McCall llvm::Value *EmitARCStoreStrong(LValue lvalue, llvm::Value *value, 29735b07e8077a20b80fee90bd76c43c6150c676e4a8John McCall bool resultIgnored); 297487d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar llvm::Value *EmitARCStoreStrongCall(Address addr, llvm::Value *value, 29755b07e8077a20b80fee90bd76c43c6150c676e4a8John McCall bool resultIgnored); 2976f85e193739c953358c865005855253af4f68a497John McCall llvm::Value *EmitARCRetain(QualType type, llvm::Value *value); 2977f85e193739c953358c865005855253af4f68a497John McCall llvm::Value *EmitARCRetainNonBlock(llvm::Value *value); 2978348f16fc7c71f0d9b651cb79fd1012843073493fJohn McCall llvm::Value *EmitARCRetainBlock(llvm::Value *value, bool mandatory); 297987d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar void EmitARCDestroyStrong(Address addr, ARCPreciseLifetime_t precise); 29805b07e8077a20b80fee90bd76c43c6150c676e4a8John McCall void EmitARCRelease(llvm::Value *value, ARCPreciseLifetime_t precise); 2981f85e193739c953358c865005855253af4f68a497John McCall llvm::Value *EmitARCAutorelease(llvm::Value *value); 2982f85e193739c953358c865005855253af4f68a497John McCall llvm::Value *EmitARCAutoreleaseReturnValue(llvm::Value *value); 2983f85e193739c953358c865005855253af4f68a497John McCall llvm::Value *EmitARCRetainAutoreleaseReturnValue(llvm::Value *value); 2984f85e193739c953358c865005855253af4f68a497John McCall llvm::Value *EmitARCRetainAutoreleasedReturnValue(llvm::Value *value); 29854967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar llvm::Value *EmitARCUnsafeClaimAutoreleasedReturnValue(llvm::Value *value); 2986f85e193739c953358c865005855253af4f68a497John McCall 2987f85e193739c953358c865005855253af4f68a497John McCall std::pair<LValue,llvm::Value*> 2988f85e193739c953358c865005855253af4f68a497John McCall EmitARCStoreAutoreleasing(const BinaryOperator *e); 2989f85e193739c953358c865005855253af4f68a497John McCall std::pair<LValue,llvm::Value*> 2990f85e193739c953358c865005855253af4f68a497John McCall EmitARCStoreStrong(const BinaryOperator *e, bool ignored); 29914967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar std::pair<LValue,llvm::Value*> 29924967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar EmitARCStoreUnsafeUnretained(const BinaryOperator *e, bool ignored); 2993f85e193739c953358c865005855253af4f68a497John McCall 29942b014d6c0c6b8ac94b416ac37dfc7931f20777a7John McCall llvm::Value *EmitObjCThrowOperand(const Expr *expr); 2995f85e193739c953358c865005855253af4f68a497John McCall llvm::Value *EmitObjCConsumeObject(QualType T, llvm::Value *Ptr); 2996f85e193739c953358c865005855253af4f68a497John McCall llvm::Value *EmitObjCExtendObjectLifetime(QualType T, llvm::Value *Ptr); 2997f85e193739c953358c865005855253af4f68a497John McCall 2998348f16fc7c71f0d9b651cb79fd1012843073493fJohn McCall llvm::Value *EmitARCExtendBlockObject(const Expr *expr); 29994967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar llvm::Value *EmitARCReclaimReturnedObject(const Expr *e, 30004967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar bool allowUnsafeClaim); 3001f85e193739c953358c865005855253af4f68a497John McCall llvm::Value *EmitARCRetainScalarExpr(const Expr *expr); 3002f85e193739c953358c865005855253af4f68a497John McCall llvm::Value *EmitARCRetainAutoreleaseScalarExpr(const Expr *expr); 30034967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar llvm::Value *EmitARCUnsafeUnretainedScalarExpr(const Expr *expr); 3004f85e193739c953358c865005855253af4f68a497John McCall 3005c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines void EmitARCIntrinsicUse(ArrayRef<llvm::Value*> values); 3006b6a6079449a5275c283982e19b0c38e165833bb2John McCall 3007bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall static Destroyer destroyARCStrongImprecise; 3008bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall static Destroyer destroyARCStrongPrecise; 3009bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall static Destroyer destroyARCWeak; 3010bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall 3011f85e193739c953358c865005855253af4f68a497John McCall void EmitObjCAutoreleasePoolPop(llvm::Value *Ptr); 3012f85e193739c953358c865005855253af4f68a497John McCall llvm::Value *EmitObjCAutoreleasePoolPush(); 3013f85e193739c953358c865005855253af4f68a497John McCall llvm::Value *EmitObjCMRRAutoreleasePoolPush(); 3014f85e193739c953358c865005855253af4f68a497John McCall void EmitObjCAutoreleasePoolCleanup(llvm::Value *Ptr); 3015f85e193739c953358c865005855253af4f68a497John McCall void EmitObjCMRRAutoreleasePoolPop(llvm::Value *Ptr); 3016f85e193739c953358c865005855253af4f68a497John McCall 3017d4ec562b3aaf50ea9015f82c96ebfd05a35fc7efRichard Smith /// \brief Emits a reference binding to the passed in expression. 3018d4ec562b3aaf50ea9015f82c96ebfd05a35fc7efRichard Smith RValue EmitReferenceBindingToExpr(const Expr *E); 30193aba09376c5f49c4c8d176109ea4835bc2c528eeAnders Carlsson 3020883f6a7cc7dccb1d675e27121a82614d63492a8dChris Lattner //===--------------------------------------------------------------------===// 3021bfc0c1ae4b505b52b36f572a9641f99e76879cabChris Lattner // Expression Emission 3022883f6a7cc7dccb1d675e27121a82614d63492a8dChris Lattner //===--------------------------------------------------------------------===// 3023bfc0c1ae4b505b52b36f572a9641f99e76879cabChris Lattner 3024bfc0c1ae4b505b52b36f572a9641f99e76879cabChris Lattner // Expressions are broken into three classes: scalar, complex, aggregate. 30250dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 30260dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// EmitScalarExpr - Emit the computation of the specified expression of LLVM 30270dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// scalar type, returning the result. 302814c5cbf59cffee52275230922283a247de407712Anders Carlsson llvm::Value *EmitScalarExpr(const Expr *E , bool IgnoreResultAssign = false); 30290dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 303087d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// Emit a conversion from the specified type to the specified destination 303187d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// type, both of which are LLVM scalar types. 30323707b255f8993fb362904c9cff87b0e9bc6ca317Chris Lattner llvm::Value *EmitScalarConversion(llvm::Value *Src, QualType SrcTy, 303387d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar QualType DstTy, SourceLocation Loc); 30340dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 303587d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// Emit a conversion from the specified complex type to the specified 303687d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// destination type, where the destination type is an LLVM scalar type. 30374f1a7b380809b4ca19ad2daff61bc11cd1e979d8Chris Lattner llvm::Value *EmitComplexToScalarConversion(ComplexPairTy Src, QualType SrcTy, 303887d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar QualType DstTy, 303987d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar SourceLocation Loc); 30400dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 3041558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall /// EmitAggExpr - Emit the computation of the specified expression 3042558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall /// of aggregate type. The result is computed into the given slot, 3043558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall /// which may be null to indicate that the value is not needed. 3044e0c1168ec7910a1a7ed08df4d4f0c58c2fa2ecd1John McCall void EmitAggExpr(const Expr *E, AggValueSlot AS); 30450dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 304618aba0dd518e486d8b50523e7dafb4b5657135d2Daniel Dunbar /// EmitAggExprToLValue - Emit the computation of the specified expression of 304718aba0dd518e486d8b50523e7dafb4b5657135d2Daniel Dunbar /// aggregate type into a temporary LValue. 304818aba0dd518e486d8b50523e7dafb4b5657135d2Daniel Dunbar LValue EmitAggExprToLValue(const Expr *E); 304918aba0dd518e486d8b50523e7dafb4b5657135d2Daniel Dunbar 30500c24c808e4dce43e88abf2d5f98546b901bd4315John McCall /// EmitExtendGCLifetime - Given a pointer to an Objective-C object, 30510c24c808e4dce43e88abf2d5f98546b901bd4315John McCall /// make sure it survives garbage collection until this point. 30520c24c808e4dce43e88abf2d5f98546b901bd4315John McCall void EmitExtendGCLifetime(llvm::Value *object); 30530c24c808e4dce43e88abf2d5f98546b901bd4315John McCall 3054b6ef18a2b06d6760459e1756a61f79ff496cee19Chris Lattner /// EmitComplexExpr - Emit the computation of the specified expression of 305523b1cdb0b5e089468bb8475b8ec9287af67b4b59Chris Lattner /// complex type, returning the result. 3056b418d74c11498b7e1044103131e2e3be4d63512eJohn McCall ComplexPairTy EmitComplexExpr(const Expr *E, 3057b418d74c11498b7e1044103131e2e3be4d63512eJohn McCall bool IgnoreReal = false, 3058b418d74c11498b7e1044103131e2e3be4d63512eJohn McCall bool IgnoreImag = false); 30590dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 30609d232c884ea9872d6555df0fd7359699819bc1f1John McCall /// EmitComplexExprIntoLValue - Emit the given expression of complex 30619d232c884ea9872d6555df0fd7359699819bc1f1John McCall /// type and place its result into the specified l-value. 30629d232c884ea9872d6555df0fd7359699819bc1f1John McCall void EmitComplexExprIntoLValue(const Expr *E, LValue dest, bool isInit); 30639d232c884ea9872d6555df0fd7359699819bc1f1John McCall 30649d232c884ea9872d6555df0fd7359699819bc1f1John McCall /// EmitStoreOfComplex - Store a complex number into the specified l-value. 30659d232c884ea9872d6555df0fd7359699819bc1f1John McCall void EmitStoreOfComplex(ComplexPairTy V, LValue dest, bool isInit); 30667f8ea5c5b3a6a4332a841eefdd86b0726722ea7bDaniel Dunbar 30679d232c884ea9872d6555df0fd7359699819bc1f1John McCall /// EmitLoadOfComplex - Load a complex number from the specified l-value. 30684ee7dc2369c1f0257a73b2e83a7d38fdebdd9176Nick Lewycky ComplexPairTy EmitLoadOfComplex(LValue src, SourceLocation loc); 30692621fd1d6d3c5eadcae246859f62738645df7540Chris Lattner 307087d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar Address emitAddrOfRealComponent(Address complex, QualType complexType); 307187d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar Address emitAddrOfImagComponent(Address complex, QualType complexType); 307287d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar 30730f30a12ce7b3d4d86c9ca9072f587da77c8eef34Chandler Carruth /// AddInitializerToStaticVarDecl - Add the initializer for 'D' to the 30740f30a12ce7b3d4d86c9ca9072f587da77c8eef34Chandler Carruth /// global variable that has already been created for it. If the initializer 30750f30a12ce7b3d4d86c9ca9072f587da77c8eef34Chandler Carruth /// has a different type than GV does, this may free GV and return a different 30760f30a12ce7b3d4d86c9ca9072f587da77c8eef34Chandler Carruth /// one. Otherwise it just returns GV. 30770f30a12ce7b3d4d86c9ca9072f587da77c8eef34Chandler Carruth llvm::GlobalVariable * 30780f30a12ce7b3d4d86c9ca9072f587da77c8eef34Chandler Carruth AddInitializerToStaticVarDecl(const VarDecl &D, 30790f30a12ce7b3d4d86c9ca9072f587da77c8eef34Chandler Carruth llvm::GlobalVariable *GV); 30809cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer 30810096acf421c4609ce7f43e8b05f8c5ca866d4611Daniel Dunbar 30823b2e16b3d25f6b311dba2871e2a566c96238c3d2Anders Carlsson /// EmitCXXGlobalVarDeclInit - Create the initializer for a C++ 30833b2e16b3d25f6b311dba2871e2a566c96238c3d2Anders Carlsson /// variable with global storage. 30847ca4850a3e3530fa6c93b64b740446e32c97f992Richard Smith void EmitCXXGlobalVarDeclInit(const VarDecl &D, llvm::Constant *DeclPtr, 30857ca4850a3e3530fa6c93b64b740446e32c97f992Richard Smith bool PerformInit); 30863b2e16b3d25f6b311dba2871e2a566c96238c3d2Anders Carlsson 3087176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines llvm::Constant *createAtExitStub(const VarDecl &VD, llvm::Constant *Dtor, 3088176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines llvm::Constant *Addr); 3089176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines 309020bb175cb8ae5844034828db094fb948c0e3454aJohn McCall /// Call atexit() with a function that passes the given argument to 309120bb175cb8ae5844034828db094fb948c0e3454aJohn McCall /// the given function. 3092c7971a9efdf9880448a69aabb5182c3c27eecf6dDavid Blaikie void registerGlobalDtorWithAtExit(const VarDecl &D, llvm::Constant *fn, 3093c7971a9efdf9880448a69aabb5182c3c27eecf6dDavid Blaikie llvm::Constant *addr); 30941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 30953030eb82593097502469a8b3fc26112c79c75605John McCall /// Emit code in this function to perform a guarded variable 30963030eb82593097502469a8b3fc26112c79c75605John McCall /// initialization. Guarded initializations are used when it's not 30973030eb82593097502469a8b3fc26112c79c75605John McCall /// possible to prove that an initialization will be done exactly 30983030eb82593097502469a8b3fc26112c79c75605John McCall /// once, e.g. with a static local variable or a static data member 30993030eb82593097502469a8b3fc26112c79c75605John McCall /// of a class template. 31000f30a12ce7b3d4d86c9ca9072f587da77c8eef34Chandler Carruth void EmitCXXGuardedInit(const VarDecl &D, llvm::GlobalVariable *DeclPtr, 31017ca4850a3e3530fa6c93b64b740446e32c97f992Richard Smith bool PerformInit); 31025cd91b513455fd7753e8815b54f0a49bbca6602dJohn McCall 3103efb0fa9e11f75af51744a6159530ef7cc8efa24aDaniel Dunbar /// GenerateCXXGlobalInitFunc - Generates code for initializing global 3104efb0fa9e11f75af51744a6159530ef7cc8efa24aDaniel Dunbar /// variables. 3105efb0fa9e11f75af51744a6159530ef7cc8efa24aDaniel Dunbar void GenerateCXXGlobalInitFunc(llvm::Function *Fn, 3106176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines ArrayRef<llvm::Function *> CXXThreadLocals, 310787d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar Address Guard = Address::invalid()); 3108efb0fa9e11f75af51744a6159530ef7cc8efa24aDaniel Dunbar 31093f88f686e32949ffe02ccb551f482f9cf810358bJohn McCall /// GenerateCXXGlobalDtorsFunc - Generates code for destroying global 3110efb0fa9e11f75af51744a6159530ef7cc8efa24aDaniel Dunbar /// variables. 31113f88f686e32949ffe02ccb551f482f9cf810358bJohn McCall void GenerateCXXGlobalDtorsFunc(llvm::Function *Fn, 31123f88f686e32949ffe02ccb551f482f9cf810358bJohn McCall const std::vector<std::pair<llvm::WeakVH, 31133f88f686e32949ffe02ccb551f482f9cf810358bJohn McCall llvm::Constant*> > &DtorsAndObjects); 3114efb0fa9e11f75af51744a6159530ef7cc8efa24aDaniel Dunbar 3115d26bc76c98006609002d9930f8840490e88ac5b5John McCall void GenerateCXXGlobalVarDeclInitFunc(llvm::Function *Fn, 3116d26bc76c98006609002d9930f8840490e88ac5b5John McCall const VarDecl *D, 31177ca4850a3e3530fa6c93b64b740446e32c97f992Richard Smith llvm::GlobalVariable *Addr, 31187ca4850a3e3530fa6c93b64b740446e32c97f992Richard Smith bool PerformInit); 3119efb0fa9e11f75af51744a6159530ef7cc8efa24aDaniel Dunbar 3120558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall void EmitCXXConstructExpr(const CXXConstructExpr *E, AggValueSlot Dest); 312134999876e215b22febc240b1a6dc054215d12f9cFariborz Jahanian 312287d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar void EmitSynthesizedCXXCopyCtor(Address Dest, Address Src, const Expr *Exp); 31231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 31241a343ebbf413e8eae6b2737b2b2d79cbf5765571John McCall void enterFullExpression(const ExprWithCleanups *E) { 31251a343ebbf413e8eae6b2737b2b2d79cbf5765571John McCall if (E->getNumObjects() == 0) return; 31261a343ebbf413e8eae6b2737b2b2d79cbf5765571John McCall enterNonTrivialFullExpression(E); 31271a343ebbf413e8eae6b2737b2b2d79cbf5765571John McCall } 31281a343ebbf413e8eae6b2737b2b2d79cbf5765571John McCall void enterNonTrivialFullExpression(const ExprWithCleanups *E); 31291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 31304c71b8cded575b0cfc133c5da4502ca613982094Richard Smith void EmitCXXThrowExpr(const CXXThrowExpr *E, bool KeepInsertionPoint = true); 31311eb2e59338c4b9c0429fc39ca98662adc9e7a3f2Douglas Gregor 31324c5d8afd100189b6cce4fd89bfb8aec5700acb50Eli Friedman void EmitLambdaExpr(const LambdaExpr *E, AggValueSlot Dest); 31334c5d8afd100189b6cce4fd89bfb8aec5700acb50Eli Friedman 313487d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar RValue EmitAtomicExpr(AtomicExpr *E); 3135276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman 31360ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar //===--------------------------------------------------------------------===// 313777f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge // Annotations Emission 313877f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge //===--------------------------------------------------------------------===// 313977f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge 314077f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge /// Emit an annotation call (intrinsic or builtin). 314177f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge llvm::Value *EmitAnnotationCall(llvm::Value *AnnotationFn, 314277f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge llvm::Value *AnnotatedVal, 3143cfa88f893915ceb8ae4ce2f17c46c24a4d67502fDmitri Gribenko StringRef AnnotationStr, 314477f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge SourceLocation Location); 314577f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge 314677f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge /// Emit local annotations for the local variable V, declared by D. 314777f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge void EmitVarAnnotations(const VarDecl *D, llvm::Value *V); 314877f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge 314977f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge /// Emit field annotations for the given field & value. Returns the 315077f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge /// annotation result. 315187d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar Address EmitFieldAnnotations(const FieldDecl *D, Address V); 315277f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge 315377f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge //===--------------------------------------------------------------------===// 31540ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar // Internal Helpers 31550ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar //===--------------------------------------------------------------------===// 31560dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 31570946ccd1e58c1f1da31ddbca67c5b6301ac8b255Chris Lattner /// ContainsLabel - Return true if the statement contains a label in it. If 31580946ccd1e58c1f1da31ddbca67c5b6301ac8b255Chris Lattner /// this statement is not executed normally, it not containing a label means 31590946ccd1e58c1f1da31ddbca67c5b6301ac8b255Chris Lattner /// that we can just remove the code. 31600946ccd1e58c1f1da31ddbca67c5b6301ac8b255Chris Lattner static bool ContainsLabel(const Stmt *S, bool IgnoreCaseStmts = false); 31610dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 3162ef425a69006afaa87751ee41ccf8ff405d9ede70Chris Lattner /// containsBreak - Return true if the statement contains a break out of it. 3163ef425a69006afaa87751ee41ccf8ff405d9ede70Chris Lattner /// If the statement (recursively) contains a switch or loop with a break 3164ef425a69006afaa87751ee41ccf8ff405d9ede70Chris Lattner /// inside of it, this is fine. 3165ef425a69006afaa87751ee41ccf8ff405d9ede70Chris Lattner static bool containsBreak(const Stmt *S); 3166ef425a69006afaa87751ee41ccf8ff405d9ede70Chris Lattner 31674bc0455d826e9634b7a68c0d06146edd633c9453Daniel Dunbar /// ConstantFoldsToSimpleInteger - If the specified expression does not fold 3168c2c90011a688c04a4e980282f08c267e081c4b00Chris Lattner /// to a constant, or if it does but contains a label, return false. If it 3169c2c90011a688c04a4e980282f08c267e081c4b00Chris Lattner /// constant folds return true and set the boolean result in Result. 31704967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar bool ConstantFoldsToSimpleInteger(const Expr *Cond, bool &Result, 31714967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar bool AllowLabels = false); 31720dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 3173ef425a69006afaa87751ee41ccf8ff405d9ede70Chris Lattner /// ConstantFoldsToSimpleInteger - If the specified expression does not fold 3174ef425a69006afaa87751ee41ccf8ff405d9ede70Chris Lattner /// to a constant, or if it does but contains a label, return false. If it 3175ef425a69006afaa87751ee41ccf8ff405d9ede70Chris Lattner /// constant folds return true and set the folded value. 31764967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar bool ConstantFoldsToSimpleInteger(const Expr *Cond, llvm::APSInt &Result, 31774967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar bool AllowLabels = false); 31784967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar 317931a0984b5cb4af99d2407c0f25bf5af68df681c6Chris Lattner /// EmitBranchOnBoolExpr - Emit a branch on a boolean condition (e.g. for an 318031a0984b5cb4af99d2407c0f25bf5af68df681c6Chris Lattner /// if statement) to the specified blocks. Based on the condition, this might 318131a0984b5cb4af99d2407c0f25bf5af68df681c6Chris Lattner /// try to simplify the codegen of the conditional based on the branch. 3182651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines /// TrueCount should be the number of times we expect the condition to 3183651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines /// evaluate to true based on PGO data. 31849bc47e29dce8f095be7a6d07dbb02a5a7a112949Chris Lattner void EmitBranchOnBoolExpr(const Expr *Cond, llvm::BasicBlock *TrueBlock, 3185651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines llvm::BasicBlock *FalseBlock, uint64_t TrueCount); 3186be07f60131bc6f8d6696f4644df1ef667a1730d5Mike Stump 31874def70d3040e73707c738f7c366737a986135edfRichard Smith /// \brief Emit a description of a type in a format suitable for passing to 31884def70d3040e73707c738f7c366737a986135edfRichard Smith /// a runtime sanitizer handler. 31894def70d3040e73707c738f7c366737a986135edfRichard Smith llvm::Constant *EmitCheckTypeDescriptor(QualType T); 31904def70d3040e73707c738f7c366737a986135edfRichard Smith 31914def70d3040e73707c738f7c366737a986135edfRichard Smith /// \brief Convert a value into a format suitable for passing to a runtime 31924def70d3040e73707c738f7c366737a986135edfRichard Smith /// sanitizer handler. 31934def70d3040e73707c738f7c366737a986135edfRichard Smith llvm::Value *EmitCheckValue(llvm::Value *V); 31944def70d3040e73707c738f7c366737a986135edfRichard Smith 31954def70d3040e73707c738f7c366737a986135edfRichard Smith /// \brief Emit a description of a source location in a format suitable for 31964def70d3040e73707c738f7c366737a986135edfRichard Smith /// passing to a runtime sanitizer handler. 31974def70d3040e73707c738f7c366737a986135edfRichard Smith llvm::Constant *EmitCheckSourceLocation(SourceLocation Loc); 31984def70d3040e73707c738f7c366737a986135edfRichard Smith 3199cc305617e952f8c3a06b63d9225d0dd7769341b7Richard Smith /// \brief Create a basic block that will call a handler function in a 3200cc305617e952f8c3a06b63d9225d0dd7769341b7Richard Smith /// sanitizer runtime with the provided arguments, and create a conditional 3201cc305617e952f8c3a06b63d9225d0dd7769341b7Richard Smith /// branch to it. 3202b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar void EmitCheck(ArrayRef<std::pair<llvm::Value *, SanitizerMask>> Checked, 3203176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines StringRef CheckName, ArrayRef<llvm::Constant *> StaticArgs, 3204176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines ArrayRef<llvm::Value *> DynamicArgs); 32059cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer 320687d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// \brief Emit a slow path cross-DSO CFI check which calls __cfi_slowpath 320787d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// if Cond if false. 32084967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar void EmitCfiSlowPathCheck(SanitizerMask Kind, llvm::Value *Cond, 32094967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar llvm::ConstantInt *TypeId, llvm::Value *Ptr, 32104967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar ArrayRef<llvm::Constant *> StaticArgs); 321187d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar 3212cc305617e952f8c3a06b63d9225d0dd7769341b7Richard Smith /// \brief Create a basic block that will call the trap intrinsic, and emit a 3213cc305617e952f8c3a06b63d9225d0dd7769341b7Richard Smith /// conditional branch to it, for the -ftrapv checks. 321478d85b1c5830a881c0a20a1b3fea99ee73149590Chad Rosier void EmitTrapCheck(llvm::Value *Checked); 3215cc305617e952f8c3a06b63d9225d0dd7769341b7Richard Smith 321687d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// \brief Emit a call to trap or debugtrap and attach function attribute 321787d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// "trap-func-name" if specified. 321887d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar llvm::CallInst *EmitTrapCall(llvm::Intrinsic::ID IntrID); 321987d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar 32204967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar /// \brief Emit a cross-DSO CFI failure handling function. 32214967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar void EmitCfiCheckFail(); 32224967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar 3223b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar /// \brief Create a check for a function parameter that may potentially be 3224b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar /// declared as non-null. 3225b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar void EmitNonNullArgCheck(RValue RV, QualType ArgType, SourceLocation ArgLoc, 3226b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar const FunctionDecl *FD, unsigned ParmNum); 3227b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar 322821c9ad9d29d08a287292c670e7c52bc522c7f8bbAnders Carlsson /// EmitCallArg - Emit a single call argument. 3229413ebdb1af6fb0d81845b61254daf02ba0449afdJohn McCall void EmitCallArg(CallArgList &args, const Expr *E, QualType ArgType); 323021c9ad9d29d08a287292c670e7c52bc522c7f8bbAnders Carlsson 32312736071ea3a46f90e65c93418961611d96c10ab9John McCall /// EmitDelegateCallArg - We are performing a delegate call; that 32322736071ea3a46f90e65c93418961611d96c10ab9John McCall /// is, the current function is delegating to another one. Produce 32332736071ea3a46f90e65c93418961611d96c10ab9John McCall /// a r-value suitable for passing the given parameter. 32344ee7dc2369c1f0257a73b2e83a7d38fdebdd9176Nick Lewycky void EmitDelegateCallArg(CallArgList &args, const VarDecl *param, 32354ee7dc2369c1f0257a73b2e83a7d38fdebdd9176Nick Lewycky SourceLocation loc); 32362736071ea3a46f90e65c93418961611d96c10ab9John McCall 3237c5096cbf7a42e0f9012945b00d9037a5b5a88d72Peter Collingbourne /// SetFPAccuracy - Set the minimum required accuracy of the given floating 3238c5096cbf7a42e0f9012945b00d9037a5b5a88d72Peter Collingbourne /// point operation, expressed as the maximum relative error in ulp. 32398250016fb9491fcfde7fce05230d66e267944484Duncan Sands void SetFPAccuracy(llvm::Value *Val, float Accuracy); 3240c5096cbf7a42e0f9012945b00d9037a5b5a88d72Peter Collingbourne 324131a0984b5cb4af99d2407c0f25bf5af68df681c6Chris Lattnerprivate: 3242c3f8955d7da1019dbe16b0bdf3e49d2e08d988e9Rafael Espindola llvm::MDNode *getRangeForLoadFromType(QualType Ty); 324329e0bccf2bcce22b877f8b2ed173f564c116b97eDaniel Dunbar void EmitReturnOfRValue(RValue RV, QualType Ty); 324429e0bccf2bcce22b877f8b2ed173f564c116b97eDaniel Dunbar 3245651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines void deferPlaceholderReplacement(llvm::Instruction *Old, llvm::Value *New); 3246651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 3247651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines llvm::SmallVector<std::pair<llvm::Instruction *, llvm::Value *>, 4> 3248651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines DeferredReplacements; 3249651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 325087d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// Set the address of a local variable. 325187d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar void setAddrOfLocalVar(const VarDecl *VD, Address Addr) { 325287d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar assert(!LocalDeclMap.count(VD) && "Decl already exists in LocalDeclMap!"); 325387d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar LocalDeclMap.insert({VD, Addr}); 325487d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar } 325587d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar 32565627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar /// ExpandTypeFromArgs - Reconstruct a structure of type \arg Ty 32575627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar /// from function arguments into \arg Dst. See ABIArgInfo::Expand. 32585627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar /// 32595627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar /// \param AI - The first function argument of the expansion. 3260176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines void ExpandTypeFromArgs(QualType Ty, LValue Dst, 32614967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar SmallVectorImpl<llvm::Value *>::iterator &AI); 3262176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines 3263176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines /// ExpandTypeToArgs - Expand an RValue \arg RV, with the LLVM type for \arg 3264176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines /// Ty, into individual arguments on the provided vector \arg IRCallArgs, 3265176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines /// starting at index \arg IRCallArgPos. See ABIArgInfo::Expand. 3266176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines void ExpandTypeToArgs(QualType Ty, RValue RV, llvm::FunctionType *IRFuncTy, 3267176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines SmallVectorImpl<llvm::Value *> &IRCallArgs, 3268176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines unsigned &IRCallArgPos); 3269c8c7b187adcd989e01a9fba1ebead6c2abd770c9Anders Carlsson 327042b60551eff3a424e191b293bfd606559dc96bffChad Rosier llvm::Value* EmitAsmInput(const TargetInfo::ConstraintInfo &Info, 3271c8c7b187adcd989e01a9fba1ebead6c2abd770c9Anders Carlsson const Expr *InputExpr, std::string &ConstraintStr); 32720dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 327342b60551eff3a424e191b293bfd606559dc96bffChad Rosier llvm::Value* EmitAsmInputLValue(const TargetInfo::ConstraintInfo &Info, 32746d7cfd7ef82e42ff30ee1dafd2883fd94e9f8294Eli Friedman LValue InputValue, QualType InputType, 32754ee7dc2369c1f0257a73b2e83a7d38fdebdd9176Nick Lewycky std::string &ConstraintStr, 32764ee7dc2369c1f0257a73b2e83a7d38fdebdd9176Nick Lewycky SourceLocation Loc); 32776d7cfd7ef82e42ff30ee1dafd2883fd94e9f8294Eli Friedman 327887d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// \brief Attempts to statically evaluate the object size of E. If that 327987d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// fails, emits code to figure the size of E out for us. This is 328087d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// pass_object_size aware. 328187d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar llvm::Value *evaluateOrEmitBuiltinObjectSize(const Expr *E, unsigned Type, 328287d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar llvm::IntegerType *ResType); 328387d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar 328487d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// \brief Emits the size of E, as required by __builtin_object_size. This 328587d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// function is aware of pass_object_size parameters, and will act accordingly 328687d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// if E is a parameter with the pass_object_size attribute. 328787d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar llvm::Value *emitBuiltinObjectSize(const Expr *E, unsigned Type, 328887d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar llvm::IntegerType *ResType); 328987d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar 3290651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinespublic: 329187d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar#ifndef NDEBUG 329287d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar // Determine whether the given argument is an Objective-C method 329387d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar // that may have type parameters in its signature. 329487d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar static bool isObjCMethodWithTypeParams(const ObjCMethodDecl *method) { 329587d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar const DeclContext *dc = method->getDeclContext(); 329687d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar if (const ObjCInterfaceDecl *classDecl= dyn_cast<ObjCInterfaceDecl>(dc)) { 329787d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar return classDecl->getTypeParamListAsWritten(); 329887d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar } 329987d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar 330087d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar if (const ObjCCategoryDecl *catDecl = dyn_cast<ObjCCategoryDecl>(dc)) { 330187d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar return catDecl->getTypeParamList(); 330287d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar } 330387d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar 330487d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar return false; 330587d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar } 330687d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar 330787d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar template<typename T> 330887d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar static bool isObjCMethodWithTypeParams(const T *) { return false; } 330987d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar#endif 331087d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar 33110139bb96494b4c4ba0824617d5d2495dc7e44c76Anders Carlsson /// EmitCallArgs - Emit call arguments for a function. 3312651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines template <typename T> 3313651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines void EmitCallArgs(CallArgList &Args, const T *CallArgTypeInfo, 331487d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar llvm::iterator_range<CallExpr::const_arg_iterator> ArgRange, 3315176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines const FunctionDecl *CalleeDecl = nullptr, 33160e2c34f92f00628d48968dfea096d36381f494cbStephen Hines unsigned ParamsToSkip = 0) { 3317651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines SmallVector<QualType, 16> ArgTypes; 331887d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar CallExpr::const_arg_iterator Arg = ArgRange.begin(); 3319af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson 3320176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines assert((ParamsToSkip == 0 || CallArgTypeInfo) && 3321176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines "Can't skip parameters if type info is not provided"); 3322176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines if (CallArgTypeInfo) { 332387d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar#ifndef NDEBUG 332487d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar bool isGenericMethod = isObjCMethodWithTypeParams(CallArgTypeInfo); 332587d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar#endif 332687d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar 3327176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines // First, use the argument types that the type info knows about 3328176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines for (auto I = CallArgTypeInfo->param_type_begin() + ParamsToSkip, 3329176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines E = CallArgTypeInfo->param_type_end(); 3330176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines I != E; ++I, ++Arg) { 333187d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar assert(Arg != ArgRange.end() && "Running over edge of argument list!"); 333287d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar assert((isGenericMethod || 333387d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar ((*I)->isVariablyModifiedType() || 333487d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar (*I).getNonReferenceType()->isObjCRetainableType() || 333587d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar getContext() 333687d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar .getCanonicalType((*I).getNonReferenceType()) 333787d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar .getTypePtr() == 333887d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar getContext() 333987d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar .getCanonicalType((*Arg)->getType()) 334087d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar .getTypePtr())) && 334187d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar "type mismatch in call argument!"); 3342176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines ArgTypes.push_back(*I); 3343176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines } 3344af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson } 33451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3346651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines // Either we've emitted all the call args, or we have a call to variadic 3347176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines // function. 334887d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar assert((Arg == ArgRange.end() || !CallArgTypeInfo || 334987d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar CallArgTypeInfo->isVariadic()) && 335087d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar "Extra arguments in non-variadic function!"); 3351651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 3352af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson // If we still have any arguments, emit them using the type of the argument. 335387d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar for (auto *A : llvm::make_range(Arg, ArgRange.end())) 335487d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar ArgTypes.push_back(getVarArgType(A)); 3355b0e603c63813c8378e35a75408ab4cefe71e93e2Adrian Prantl 335687d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar EmitCallArgs(Args, ArgTypes, ArgRange, CalleeDecl, ParamsToSkip); 3357af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson } 3358492c4f998d848673d3d6c9e6416115df4036a71dJohn McCall 3359651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines void EmitCallArgs(CallArgList &Args, ArrayRef<QualType> ArgTypes, 336087d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar llvm::iterator_range<CallExpr::const_arg_iterator> ArgRange, 3361176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines const FunctionDecl *CalleeDecl = nullptr, 33620e2c34f92f00628d48968dfea096d36381f494cbStephen Hines unsigned ParamsToSkip = 0); 3363651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 336487d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// EmitPointerWithAlignment - Given an expression with a pointer 336587d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// type, emit the value and compute our best estimate of the 336687d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// alignment of the pointee. 336787d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// 336887d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// Note that this function will conservatively fall back on the type 336987d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// when it doesn't 337087d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// 337187d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// \param Source - If non-null, this will be initialized with 337287d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// information about the source of the alignment. Note that this 337387d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// function will conservatively fall back on the type when it 337487d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// doesn't recognize the expression, which means that sometimes 337587d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// 337687d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// a worst-case One 337787d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// reasonable way to use this information is when there's a 337887d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// language guarantee that the pointer must be aligned to some 337987d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// stricter value, and we're simply trying to ensure that 338087d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// sufficiently obvious uses of under-aligned objects don't get 338187d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// miscompiled; for example, a placement new into the address of 338287d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// a local variable. In such a case, it's quite reasonable to 338387d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// just ignore the returned alignment when it isn't from an 338487d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// explicit source. 338587d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar Address EmitPointerWithAlignment(const Expr *Addr, 338687d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar AlignmentSource *Source = nullptr); 338787d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar 33884967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar void EmitSanitizerStatReport(llvm::SanitizerStatKind SSK); 33894967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar 3390651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinesprivate: 3391176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines QualType getVarArgType(const Expr *Arg); 3392176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines 3393492c4f998d848673d3d6c9e6416115df4036a71dJohn McCall const TargetCodeGenInfo &getTargetHooks() const { 3394492c4f998d848673d3d6c9e6416115df4036a71dJohn McCall return CGM.getTargetCodeGenInfo(); 3395492c4f998d848673d3d6c9e6416115df4036a71dJohn McCall } 3396744016dde06fcffd50931e94a98c850f8b12cd87John McCall 3397744016dde06fcffd50931e94a98c850f8b12cd87John McCall void EmitDeclMetadata(); 3398f0c11f7e6848f023ced6a5b51399ba787c7d4d0bJohn McCall 339987d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar BlockByrefHelpers *buildByrefHelpers(llvm::StructType &byrefType, 340087d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar const AutoVarEmission &emission); 3401b49bd27b334a6c4e3bf9d810a7d5b022578f1194Dan Gohman 3402b49bd27b334a6c4e3bf9d810a7d5b022578f1194Dan Gohman void AddObjCARCExceptionMetadata(llvm::Instruction *Inst); 3403f4c3db175101cbf94dad59419c3ed7aed51bf606Jay Foad 34040e2c34f92f00628d48968dfea096d36381f494cbStephen Hines llvm::Value *GetValueForARMHint(unsigned BuiltinID); 34055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 34061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3407150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall/// Helper class with most of the code for saving a value for a 3408150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall/// conditional expression cleanup. 3409804b807ea918184d6de63bd745e1ff75a9bfc679John McCallstruct DominatingLLVMValue { 3410150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall typedef llvm::PointerIntPair<llvm::Value*, 1, bool> saved_type; 3411150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall 3412150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall /// Answer whether the given value needs extra work to be saved. 3413150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall static bool needsSaving(llvm::Value *value) { 3414150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall // If it's not an instruction, we don't need to save. 3415150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall if (!isa<llvm::Instruction>(value)) return false; 3416150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall 3417150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall // If it's an instruction in the entry block, we don't need to save. 3418150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall llvm::BasicBlock *block = cast<llvm::Instruction>(value)->getParent(); 3419150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall return (block != &block->getParent()->getEntryBlock()); 3420150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall } 3421150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall 3422150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall /// Try to save the given value. 3423150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall static saved_type save(CodeGenFunction &CGF, llvm::Value *value) { 3424150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall if (!needsSaving(value)) return saved_type(value, false); 3425150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall 342687d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar // Otherwise, we need an alloca. 342787d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar auto align = CharUnits::fromQuantity( 342887d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar CGF.CGM.getDataLayout().getPrefTypeAlignment(value->getType())); 342987d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar Address alloca = 343087d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar CGF.CreateTempAlloca(value->getType(), align, "cond-cleanup.save"); 3431150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall CGF.Builder.CreateStore(value, alloca); 3432150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall 343387d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar return saved_type(alloca.getPointer(), true); 3434150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall } 3435150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall 3436150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall static llvm::Value *restore(CodeGenFunction &CGF, saved_type value) { 343787d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar // If the value says it wasn't saved, trust that it's still dominating. 3438150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall if (!value.getInt()) return value.getPointer(); 343987d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar 344087d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar // Otherwise, it should be an alloca instruction, as set up in save(). 344187d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar auto alloca = cast<llvm::AllocaInst>(value.getPointer()); 344287d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar return CGF.Builder.CreateAlignedLoad(alloca, alloca->getAlignment()); 3443150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall } 3444150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall}; 3445150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall 3446804b807ea918184d6de63bd745e1ff75a9bfc679John McCall/// A partial specialization of DominatingValue for llvm::Values that 3447804b807ea918184d6de63bd745e1ff75a9bfc679John McCall/// might be llvm::Instructions. 3448804b807ea918184d6de63bd745e1ff75a9bfc679John McCalltemplate <class T> struct DominatingPointer<T,true> : DominatingLLVMValue { 3449804b807ea918184d6de63bd745e1ff75a9bfc679John McCall typedef T *type; 3450804b807ea918184d6de63bd745e1ff75a9bfc679John McCall static type restore(CodeGenFunction &CGF, saved_type value) { 3451804b807ea918184d6de63bd745e1ff75a9bfc679John McCall return static_cast<T*>(DominatingLLVMValue::restore(CGF, value)); 3452804b807ea918184d6de63bd745e1ff75a9bfc679John McCall } 3453804b807ea918184d6de63bd745e1ff75a9bfc679John McCall}; 3454804b807ea918184d6de63bd745e1ff75a9bfc679John McCall 345587d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar/// A specialization of DominatingValue for Address. 345687d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainartemplate <> struct DominatingValue<Address> { 345787d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar typedef Address type; 345887d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar 345987d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar struct saved_type { 346087d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar DominatingLLVMValue::saved_type SavedValue; 346187d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar CharUnits Alignment; 346287d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar }; 346387d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar 346487d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar static bool needsSaving(type value) { 346587d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar return DominatingLLVMValue::needsSaving(value.getPointer()); 346687d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar } 346787d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar static saved_type save(CodeGenFunction &CGF, type value) { 346887d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar return { DominatingLLVMValue::save(CGF, value.getPointer()), 346987d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar value.getAlignment() }; 347087d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar } 347187d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar static type restore(CodeGenFunction &CGF, saved_type value) { 347287d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar return Address(DominatingLLVMValue::restore(CGF, value.SavedValue), 347387d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar value.Alignment); 347487d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar } 347587d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar}; 347687d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar 3477804b807ea918184d6de63bd745e1ff75a9bfc679John McCall/// A specialization of DominatingValue for RValue. 3478804b807ea918184d6de63bd745e1ff75a9bfc679John McCalltemplate <> struct DominatingValue<RValue> { 3479804b807ea918184d6de63bd745e1ff75a9bfc679John McCall typedef RValue type; 3480804b807ea918184d6de63bd745e1ff75a9bfc679John McCall class saved_type { 3481804b807ea918184d6de63bd745e1ff75a9bfc679John McCall enum Kind { ScalarLiteral, ScalarAddress, AggregateLiteral, 3482804b807ea918184d6de63bd745e1ff75a9bfc679John McCall AggregateAddress, ComplexAddress }; 3483804b807ea918184d6de63bd745e1ff75a9bfc679John McCall 3484804b807ea918184d6de63bd745e1ff75a9bfc679John McCall llvm::Value *Value; 348587d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar unsigned K : 3; 348687d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar unsigned Align : 29; 348787d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar saved_type(llvm::Value *v, Kind k, unsigned a = 0) 348887d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar : Value(v), K(k), Align(a) {} 3489804b807ea918184d6de63bd745e1ff75a9bfc679John McCall 3490804b807ea918184d6de63bd745e1ff75a9bfc679John McCall public: 3491804b807ea918184d6de63bd745e1ff75a9bfc679John McCall static bool needsSaving(RValue value); 3492804b807ea918184d6de63bd745e1ff75a9bfc679John McCall static saved_type save(CodeGenFunction &CGF, RValue value); 3493804b807ea918184d6de63bd745e1ff75a9bfc679John McCall RValue restore(CodeGenFunction &CGF); 3494804b807ea918184d6de63bd745e1ff75a9bfc679John McCall 349587d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar // implementations in CGCleanup.cpp 3496804b807ea918184d6de63bd745e1ff75a9bfc679John McCall }; 3497804b807ea918184d6de63bd745e1ff75a9bfc679John McCall 3498804b807ea918184d6de63bd745e1ff75a9bfc679John McCall static bool needsSaving(type value) { 3499804b807ea918184d6de63bd745e1ff75a9bfc679John McCall return saved_type::needsSaving(value); 3500804b807ea918184d6de63bd745e1ff75a9bfc679John McCall } 3501804b807ea918184d6de63bd745e1ff75a9bfc679John McCall static saved_type save(CodeGenFunction &CGF, type value) { 3502804b807ea918184d6de63bd745e1ff75a9bfc679John McCall return saved_type::save(CGF, value); 3503804b807ea918184d6de63bd745e1ff75a9bfc679John McCall } 3504150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall static type restore(CodeGenFunction &CGF, saved_type value) { 3505804b807ea918184d6de63bd745e1ff75a9bfc679John McCall return value.restore(CGF); 3506150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall } 3507150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall}; 3508150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall 35095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} // end namespace CodeGen 35105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} // end namespace clang 35114e1524babb095e70de1da882573eb6fbee98a857Fariborz Jahanian 35125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif 3513