CodeGenModule.h revision a7ff62f9443efa3b13a28a1e566d4625b15b8553
1bd012ff1fa088181646a784f385b28867372d434Daniel Dunbar//===--- CodeGenModule.h - Per-Module 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// 10ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump// This is the internal per-translation-unit state used for llvm translation. 115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 14ef52a2fb2ace36c92f88c6e125bd7defa17dafa5Chris Lattner#ifndef CLANG_CODEGEN_CODEGENMODULE_H 15ef52a2fb2ace36c92f88c6e125bd7defa17dafa5Chris Lattner#define CLANG_CODEGEN_CODEGENMODULE_H 165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1755fc873017f10f6f566b182b70f6fc22aefa3464Chandler Carruth#include "CGVTables.h" 1855fc873017f10f6f566b182b70f6fc22aefa3464Chandler Carruth#include "CodeGenTypes.h" 194f8d123e3e2c260de3377208106ddba87cee28b4Dan Gohman#include "clang/AST/Attr.h" 202a131fbca2a51085dc083b8c56a2d4ced3cf1413Anders Carlsson#include "clang/AST/DeclCXX.h" 210ff8bafde95f6fa51ccea70738c1b99db870bddcAnders Carlsson#include "clang/AST/DeclObjC.h" 22fd05ca03abdfb38f78b9535d996ecc9c39d3b0dbPeter Collingbourne#include "clang/AST/GlobalDecl.h" 2314110477887e3dc168ffc6c191e72d705051f99ePeter Collingbourne#include "clang/AST/Mangle.h" 2455fc873017f10f6f566b182b70f6fc22aefa3464Chandler Carruth#include "clang/Basic/ABI.h" 2555fc873017f10f6f566b182b70f6fc22aefa3464Chandler Carruth#include "clang/Basic/LangOptions.h" 26b6cbe517237c3c223beb064d60d5b49e56d65c06Douglas Gregor#include "clang/Basic/Module.h" 275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "llvm/ADT/DenseMap.h" 28b6cbe517237c3c223beb064d60d5b49e56d65c06Douglas Gregor#include "llvm/ADT/SetVector.h" 296a836706c40a31c716952b74785102c90fd6afa7Rafael Espindola#include "llvm/ADT/SmallPtrSet.h" 3055fc873017f10f6f566b182b70f6fc22aefa3464Chandler Carruth#include "llvm/ADT/StringMap.h" 31bd7370a78604e9a20d698bfe328c1e43f12a0613John McCall#include "llvm/IR/CallingConv.h" 323b844ba7d5be205a9b4f5f0b0d1b7978977f4b8cChandler Carruth#include "llvm/IR/Module.h" 3335f38a2c22d68c22e2dbe8e9ee84c120c8f327bbChris Lattner#include "llvm/Support/ValueHandle.h" 344f45bc099f2665bc6e4bcbb169aa452390dbf3feWill Dietz#include "llvm/Transforms/Utils/BlackList.h" 35b723f7520bcce5f13ccaae557c16a1e7133b6908Anders Carlsson 365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace llvm { 375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class Module; 385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class Constant; 39bc8d40d85f3fa1e34569834916f18fecaa635152John McCall class ConstantInt; 405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class Function; 418bd4afeb876fd0015bb808eb2f3de1fe709658a7Nate Begeman class GlobalValue; 4225a6a84cf5067b32c271e3ba078676dee838798dMicah Villmow class DataLayout; 43ff4a2d9e2c1ddbf87e00e2a36ae341faf03eafb3Eli Friedman class FunctionType; 44f21efe9088a0b3eda1209d1706529f6cb2073092Benjamin Kramer class LLVMContext; 455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang { 4882d0a418c8699fc6f4a9417457ffe93d43bba1c1Anton Korobeynikov class TargetCodeGenInfo; 495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class ASTContext; 509eda3abe7e183b05834947391c0cdc291f4ee0d8John McCall class AtomicType; 515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class FunctionDecl; 5290db88249ac92e6ed515065048a4ead4467e6639Daniel Dunbar class IdentifierInfo; 53391d77a26382dddf25da73e29fc1fa5aaaea4c6fChris Lattner class ObjCMethodDecl; 5420ff3108fcd2c3bd734dc79efc22ebaa090abd41Anton Korobeynikov class ObjCImplementationDecl; 5520ff3108fcd2c3bd734dc79efc22ebaa090abd41Anton Korobeynikov class ObjCCategoryImplDecl; 5620ff3108fcd2c3bd734dc79efc22ebaa090abd41Anton Korobeynikov class ObjCProtocolDecl; 57eaf2bb89eb2aad3b80673de30febe52df43c10ecChris Lattner class ObjCEncodeExpr; 58d5cab5435371b8cc74a9e05ebd40b5995ebad149Anders Carlsson class BlockExpr; 59687cc4a850b59116efee061018f0d8df50728b82Ken Dyck class CharUnits; 605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class Decl; 612824723d6d181d2dfa56e62caabd68b0b18f0b9dOliver Hunt class Expr; 622c8569d5f43f7de1fb993e84c95ea571dd9ac55eChris Lattner class Stmt; 6319b1a6eb2c90fab7cefe74bea5b6de490b65ac9dSebastian Redl class InitListExpr; 641e04976fc2611d8cc06986a81deed4c42183b870Daniel Dunbar class StringLiteral; 651a1d92ac5e1354634af08c62a1d72e263d13be0cNate Begeman class NamedDecl; 66bd012ff1fa088181646a784f385b28867372d434Daniel Dunbar class ValueDecl; 672b9d2ca4ce53fffbe8a77c7db2fe4df5ccfb9fd4Chris Lattner class VarDecl; 6843af76e845c95be160c088ec11ba3c43e2527fa8Sebastian Redl class LangOptions; 692811ccf48d6d898c42cc4cfad37abedb36236d20Chandler Carruth class CodeGenOptions; 70d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie class DiagnosticsEngine; 718bd4afeb876fd0015bb808eb2f3de1fe709658a7Nate Begeman class AnnotateAttr; 7227ae53665f8b00fe4ba21da0fa79a4ce6e0b6cd5Anders Carlsson class CXXDestructorDecl; 7314110477887e3dc168ffc6c191e72d705051f99ePeter Collingbourne class MangleBuffer; 74b6cbe517237c3c223beb064d60d5b49e56d65c06Douglas Gregor class Module; 75ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump 765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace CodeGen { 775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 78d26bc76c98006609002d9930f8840490e88ac5b5John McCall class CallArgList; 79813733577d33ec56479667b49e1bff42dc6bba90Lauro Ramos Venancio class CodeGenFunction; 803d5aff5d3036b0ff09d114857cd2276134b3d8c9Dan Gohman class CodeGenTBAA; 814c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall class CGCXXABI; 82e8b9f5b8ea60983c4a74cb8b63879616b914b65aSanjiv Gupta class CGDebugInfo; 83af2f62ce32e462f256855cd24b06dec4755d2827Daniel Dunbar class CGObjCRuntime; 848c25fc584ce27d59df9923f153e8a132dde58d04Peter Collingbourne class CGOpenCLRuntime; 856c0aa5ff6e6253db0f993053599e2a52b5b93b2dPeter Collingbourne class CGCUDARuntime; 86d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall class BlockFieldFlags; 87d26bc76c98006609002d9930f8840490e88ac5b5John McCall class FunctionArgList; 884a6835e650ff24e19ce08a3bd347c0ad186777fdAnders Carlsson 89ec2830d930e306124c2ba6bf1060a3c71dced6eaChris Lattner struct OrderGlobalInits { 90e0b691a25f801d8be552c9387863637b9526e639Fariborz Jahanian unsigned int priority; 91e0b691a25f801d8be552c9387863637b9526e639Fariborz Jahanian unsigned int lex_order; 92e0b691a25f801d8be552c9387863637b9526e639Fariborz Jahanian OrderGlobalInits(unsigned int p, unsigned int l) 93ec2830d930e306124c2ba6bf1060a3c71dced6eaChris Lattner : priority(p), lex_order(l) {} 94ec2830d930e306124c2ba6bf1060a3c71dced6eaChris Lattner 95ec2830d930e306124c2ba6bf1060a3c71dced6eaChris Lattner bool operator==(const OrderGlobalInits &RHS) const { 96ec2830d930e306124c2ba6bf1060a3c71dced6eaChris Lattner return priority == RHS.priority && 97ec2830d930e306124c2ba6bf1060a3c71dced6eaChris Lattner lex_order == RHS.lex_order; 98f489688114275c821b1e647e26f71eeb94d8ab24Fariborz Jahanian } 99f489688114275c821b1e647e26f71eeb94d8ab24Fariborz Jahanian 100ec2830d930e306124c2ba6bf1060a3c71dced6eaChris Lattner bool operator<(const OrderGlobalInits &RHS) const { 101ec2830d930e306124c2ba6bf1060a3c71dced6eaChris Lattner if (priority < RHS.priority) 102f489688114275c821b1e647e26f71eeb94d8ab24Fariborz Jahanian return true; 103f489688114275c821b1e647e26f71eeb94d8ab24Fariborz Jahanian 104ec2830d930e306124c2ba6bf1060a3c71dced6eaChris Lattner return priority == RHS.priority && lex_order < RHS.lex_order; 105f489688114275c821b1e647e26f71eeb94d8ab24Fariborz Jahanian } 106ec2830d930e306124c2ba6bf1060a3c71dced6eaChris Lattner }; 1075936e33bf74dd6bf126ceee0f6169a2593d03a69John McCall 1085936e33bf74dd6bf126ceee0f6169a2593d03a69John McCall struct CodeGenTypeCache { 1090774cb84719f2aea3016493a2bbd9a02aa3e0541John McCall /// void 1109cbe4f0ba01ec304e1e3d071c071f7bca33631c0Chris Lattner llvm::Type *VoidTy; 1110774cb84719f2aea3016493a2bbd9a02aa3e0541John McCall 1128b418685e9e4f02f4eb2a76e1ec063e07552b68dChris Lattner /// i8, i16, i32, and i64 1138b418685e9e4f02f4eb2a76e1ec063e07552b68dChris Lattner llvm::IntegerType *Int8Ty, *Int16Ty, *Int32Ty, *Int64Ty; 1148b418685e9e4f02f4eb2a76e1ec063e07552b68dChris Lattner /// float, double 1158b418685e9e4f02f4eb2a76e1ec063e07552b68dChris Lattner llvm::Type *FloatTy, *DoubleTy; 1165936e33bf74dd6bf126ceee0f6169a2593d03a69John McCall 1175936e33bf74dd6bf126ceee0f6169a2593d03a69John McCall /// int 1189cbe4f0ba01ec304e1e3d071c071f7bca33631c0Chris Lattner llvm::IntegerType *IntTy; 1195936e33bf74dd6bf126ceee0f6169a2593d03a69John McCall 1200774cb84719f2aea3016493a2bbd9a02aa3e0541John McCall /// intptr_t, size_t, and ptrdiff_t, which we assume are the same size. 1215936e33bf74dd6bf126ceee0f6169a2593d03a69John McCall union { 1229cbe4f0ba01ec304e1e3d071c071f7bca33631c0Chris Lattner llvm::IntegerType *IntPtrTy; 1239cbe4f0ba01ec304e1e3d071c071f7bca33631c0Chris Lattner llvm::IntegerType *SizeTy; 1249cbe4f0ba01ec304e1e3d071c071f7bca33631c0Chris Lattner llvm::IntegerType *PtrDiffTy; 1255936e33bf74dd6bf126ceee0f6169a2593d03a69John McCall }; 1265936e33bf74dd6bf126ceee0f6169a2593d03a69John McCall 1275936e33bf74dd6bf126ceee0f6169a2593d03a69John McCall /// void* in address space 0 1285936e33bf74dd6bf126ceee0f6169a2593d03a69John McCall union { 1299cbe4f0ba01ec304e1e3d071c071f7bca33631c0Chris Lattner llvm::PointerType *VoidPtrTy; 1309cbe4f0ba01ec304e1e3d071c071f7bca33631c0Chris Lattner llvm::PointerType *Int8PtrTy; 1315936e33bf74dd6bf126ceee0f6169a2593d03a69John McCall }; 1325936e33bf74dd6bf126ceee0f6169a2593d03a69John McCall 1335936e33bf74dd6bf126ceee0f6169a2593d03a69John McCall /// void** in address space 0 1345936e33bf74dd6bf126ceee0f6169a2593d03a69John McCall union { 1359cbe4f0ba01ec304e1e3d071c071f7bca33631c0Chris Lattner llvm::PointerType *VoidPtrPtrTy; 1369cbe4f0ba01ec304e1e3d071c071f7bca33631c0Chris Lattner llvm::PointerType *Int8PtrPtrTy; 1375936e33bf74dd6bf126ceee0f6169a2593d03a69John McCall }; 1385936e33bf74dd6bf126ceee0f6169a2593d03a69John McCall 13934695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall /// The width of a pointer into the generic address space. 1405936e33bf74dd6bf126ceee0f6169a2593d03a69John McCall unsigned char PointerWidthInBits; 14134695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall 14271c758d3f4ecc8b511e6ae4a7210486aa994c182John McCall /// The size and alignment of a pointer into the generic address 14371c758d3f4ecc8b511e6ae4a7210486aa994c182John McCall /// space. 14471c758d3f4ecc8b511e6ae4a7210486aa994c182John McCall union { 14571c758d3f4ecc8b511e6ae4a7210486aa994c182John McCall unsigned char PointerAlignInBytes; 14671c758d3f4ecc8b511e6ae4a7210486aa994c182John McCall unsigned char PointerSizeInBytes; 147e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall unsigned char SizeSizeInBytes; // sizeof(size_t) 14871c758d3f4ecc8b511e6ae4a7210486aa994c182John McCall }; 149bd7370a78604e9a20d698bfe328c1e43f12a0613John McCall 150bd7370a78604e9a20d698bfe328c1e43f12a0613John McCall llvm::CallingConv::ID RuntimeCC; 151bd7370a78604e9a20d698bfe328c1e43f12a0613John McCall llvm::CallingConv::ID getRuntimeCC() const { 152bd7370a78604e9a20d698bfe328c1e43f12a0613John McCall return RuntimeCC; 153bd7370a78604e9a20d698bfe328c1e43f12a0613John McCall } 1545936e33bf74dd6bf126ceee0f6169a2593d03a69John McCall }; 155f85e193739c953358c865005855253af4f68a497John McCall 156f85e193739c953358c865005855253af4f68a497John McCallstruct RREntrypoints { 157f85e193739c953358c865005855253af4f68a497John McCall RREntrypoints() { memset(this, 0, sizeof(*this)); } 158f85e193739c953358c865005855253af4f68a497John McCall /// void objc_autoreleasePoolPop(void*); 159f85e193739c953358c865005855253af4f68a497John McCall llvm::Constant *objc_autoreleasePoolPop; 160f85e193739c953358c865005855253af4f68a497John McCall 161f85e193739c953358c865005855253af4f68a497John McCall /// void *objc_autoreleasePoolPush(void); 162f85e193739c953358c865005855253af4f68a497John McCall llvm::Constant *objc_autoreleasePoolPush; 163f85e193739c953358c865005855253af4f68a497John McCall}; 164f85e193739c953358c865005855253af4f68a497John McCall 165f85e193739c953358c865005855253af4f68a497John McCallstruct ARCEntrypoints { 166f85e193739c953358c865005855253af4f68a497John McCall ARCEntrypoints() { memset(this, 0, sizeof(*this)); } 167f85e193739c953358c865005855253af4f68a497John McCall 168f85e193739c953358c865005855253af4f68a497John McCall /// id objc_autorelease(id); 169f85e193739c953358c865005855253af4f68a497John McCall llvm::Constant *objc_autorelease; 170f85e193739c953358c865005855253af4f68a497John McCall 171f85e193739c953358c865005855253af4f68a497John McCall /// id objc_autoreleaseReturnValue(id); 172f85e193739c953358c865005855253af4f68a497John McCall llvm::Constant *objc_autoreleaseReturnValue; 173f85e193739c953358c865005855253af4f68a497John McCall 174f85e193739c953358c865005855253af4f68a497John McCall /// void objc_copyWeak(id *dest, id *src); 175f85e193739c953358c865005855253af4f68a497John McCall llvm::Constant *objc_copyWeak; 176f85e193739c953358c865005855253af4f68a497John McCall 177f85e193739c953358c865005855253af4f68a497John McCall /// void objc_destroyWeak(id*); 178f85e193739c953358c865005855253af4f68a497John McCall llvm::Constant *objc_destroyWeak; 179f85e193739c953358c865005855253af4f68a497John McCall 180f85e193739c953358c865005855253af4f68a497John McCall /// id objc_initWeak(id*, id); 181f85e193739c953358c865005855253af4f68a497John McCall llvm::Constant *objc_initWeak; 182f85e193739c953358c865005855253af4f68a497John McCall 183f85e193739c953358c865005855253af4f68a497John McCall /// id objc_loadWeak(id*); 184f85e193739c953358c865005855253af4f68a497John McCall llvm::Constant *objc_loadWeak; 185f85e193739c953358c865005855253af4f68a497John McCall 186f85e193739c953358c865005855253af4f68a497John McCall /// id objc_loadWeakRetained(id*); 187f85e193739c953358c865005855253af4f68a497John McCall llvm::Constant *objc_loadWeakRetained; 188f85e193739c953358c865005855253af4f68a497John McCall 189f85e193739c953358c865005855253af4f68a497John McCall /// void objc_moveWeak(id *dest, id *src); 190f85e193739c953358c865005855253af4f68a497John McCall llvm::Constant *objc_moveWeak; 191f85e193739c953358c865005855253af4f68a497John McCall 192f85e193739c953358c865005855253af4f68a497John McCall /// id objc_retain(id); 193f85e193739c953358c865005855253af4f68a497John McCall llvm::Constant *objc_retain; 194f85e193739c953358c865005855253af4f68a497John McCall 195f85e193739c953358c865005855253af4f68a497John McCall /// id objc_retainAutorelease(id); 196f85e193739c953358c865005855253af4f68a497John McCall llvm::Constant *objc_retainAutorelease; 197f85e193739c953358c865005855253af4f68a497John McCall 198f85e193739c953358c865005855253af4f68a497John McCall /// id objc_retainAutoreleaseReturnValue(id); 199f85e193739c953358c865005855253af4f68a497John McCall llvm::Constant *objc_retainAutoreleaseReturnValue; 200f85e193739c953358c865005855253af4f68a497John McCall 201f85e193739c953358c865005855253af4f68a497John McCall /// id objc_retainAutoreleasedReturnValue(id); 202f85e193739c953358c865005855253af4f68a497John McCall llvm::Constant *objc_retainAutoreleasedReturnValue; 203f85e193739c953358c865005855253af4f68a497John McCall 204f85e193739c953358c865005855253af4f68a497John McCall /// id objc_retainBlock(id); 205f85e193739c953358c865005855253af4f68a497John McCall llvm::Constant *objc_retainBlock; 206f85e193739c953358c865005855253af4f68a497John McCall 207f85e193739c953358c865005855253af4f68a497John McCall /// void objc_release(id); 208f85e193739c953358c865005855253af4f68a497John McCall llvm::Constant *objc_release; 209f85e193739c953358c865005855253af4f68a497John McCall 210f85e193739c953358c865005855253af4f68a497John McCall /// id objc_storeStrong(id*, id); 211f85e193739c953358c865005855253af4f68a497John McCall llvm::Constant *objc_storeStrong; 212f85e193739c953358c865005855253af4f68a497John McCall 213f85e193739c953358c865005855253af4f68a497John McCall /// id objc_storeWeak(id*, id); 214f85e193739c953358c865005855253af4f68a497John McCall llvm::Constant *objc_storeWeak; 215f85e193739c953358c865005855253af4f68a497John McCall 216f85e193739c953358c865005855253af4f68a497John McCall /// A void(void) inline asm to use to mark that the return value of 217f85e193739c953358c865005855253af4f68a497John McCall /// a call will be immediately retain. 218f85e193739c953358c865005855253af4f68a497John McCall llvm::InlineAsm *retainAutoreleasedReturnValueMarker; 219b6a6079449a5275c283982e19b0c38e165833bb2John McCall 220b6a6079449a5275c283982e19b0c38e165833bb2John McCall /// void clang.arc.use(...); 221b6a6079449a5275c283982e19b0c38e165833bb2John McCall llvm::Constant *clang_arc_use; 222f85e193739c953358c865005855253af4f68a497John McCall}; 2234f45bc099f2665bc6e4bcbb169aa452390dbf3feWill Dietz 224ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump/// CodeGenModule - This class organizes the cross-function state that is used 225ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump/// while generating LLVM code. 2265936e33bf74dd6bf126ceee0f6169a2593d03a69John McCallclass CodeGenModule : public CodeGenTypeCache { 227f56faa01936b9cf909623d7f06e3c2569ca4a78eDmitri Gribenko CodeGenModule(const CodeGenModule &) LLVM_DELETED_FUNCTION; 228f56faa01936b9cf909623d7f06e3c2569ca4a78eDmitri Gribenko void operator=(const CodeGenModule &) LLVM_DELETED_FUNCTION; 2298a219ceda2b5afd447e7199b9c53079bead31b89Anders Carlsson 230ca0017a394e0a93a2412c3fe5c47a63b4b2b2ab0Chris Lattner typedef std::vector<std::pair<llvm::Constant*, int> > CtorList; 2316bfed7e411adc46eaf616371f85f68305c6e6257Daniel Dunbar 2325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ASTContext &Context; 2334e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie const LangOptions &LangOpts; 2342811ccf48d6d898c42cc4cfad37abedb36236d20Chandler Carruth const CodeGenOptions &CodeGenOpts; 2355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer llvm::Module &TheModule; 236d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie DiagnosticsEngine &Diags; 23764aa4b3ec7e62288e2e66c1935487ece995ca94bJohn McCall const llvm::DataLayout &TheDataLayout; 23864aa4b3ec7e62288e2e66c1935487ece995ca94bJohn McCall const TargetInfo &Target; 239f16aa103d3afd42fbca2ab346f191bf745cec092John McCall CGCXXABI &ABI; 24064aa4b3ec7e62288e2e66c1935487ece995ca94bJohn McCall llvm::LLVMContext &VMContext; 241b540491851910c2efa68196a8bdc2eed1071c17dAnders Carlsson 24264aa4b3ec7e62288e2e66c1935487ece995ca94bJohn McCall CodeGenTBAA *TBAA; 24364aa4b3ec7e62288e2e66c1935487ece995ca94bJohn McCall 24464aa4b3ec7e62288e2e66c1935487ece995ca94bJohn McCall mutable const TargetCodeGenInfo *TheTargetCodeGenInfo; 24564aa4b3ec7e62288e2e66c1935487ece995ca94bJohn McCall 24664aa4b3ec7e62288e2e66c1935487ece995ca94bJohn McCall // This should not be moved earlier, since its initialization depends on some 24764aa4b3ec7e62288e2e66c1935487ece995ca94bJohn McCall // of the previous reference members being already initialized and also checks 24864aa4b3ec7e62288e2e66c1935487ece995ca94bJohn McCall // if TheTargetCodeGenInfo is NULL 24964aa4b3ec7e62288e2e66c1935487ece995ca94bJohn McCall CodeGenTypes Types; 25064aa4b3ec7e62288e2e66c1935487ece995ca94bJohn McCall 251af4403545a50a60d208e6fcae057308d576a92e0Anders Carlsson /// VTables - Holds information about C++ vtables. 252af4403545a50a60d208e6fcae057308d576a92e0Anders Carlsson CodeGenVTables VTables; 253e17ad2fd5c4b66c712bdffd2789eaafc54a9b001Douglas Gregor friend class CodeGenVTables; 254e17ad2fd5c4b66c712bdffd2789eaafc54a9b001Douglas Gregor 255e926523105dd2604ccd5c101605dea43c5269965Peter Collingbourne CGObjCRuntime* ObjCRuntime; 2568c25fc584ce27d59df9923f153e8a132dde58d04Peter Collingbourne CGOpenCLRuntime* OpenCLRuntime; 2576c0aa5ff6e6253db0f993053599e2a52b5b93b2dPeter Collingbourne CGCUDARuntime* CUDARuntime; 258815c78fd9ab8bd5dfe8e8a91b8c6a413e2b8c889Ted Kremenek CGDebugInfo* DebugInfo; 259f85e193739c953358c865005855253af4f68a497John McCall ARCEntrypoints *ARCData; 260b49bd27b334a6c4e3bf9d810a7d5b022578f1194Dan Gohman llvm::MDNode *NoObjCARCExceptionsMetadata; 261f85e193739c953358c865005855253af4f68a497John McCall RREntrypoints *RRData; 2629986eabd4423d867262c358ca62f94a60ac58412Daniel Dunbar 2636a836706c40a31c716952b74785102c90fd6afa7Rafael Espindola // WeakRefReferences - A set of references that have only been seen via 26464aa4b3ec7e62288e2e66c1935487ece995ca94bJohn McCall // a weakref so far. This is used to remove the weak of the reference if we 26564aa4b3ec7e62288e2e66c1935487ece995ca94bJohn McCall // ever see a direct reference or a definition. 2666a836706c40a31c716952b74785102c90fd6afa7Rafael Espindola llvm::SmallPtrSet<llvm::GlobalValue*, 10> WeakRefReferences; 2676a836706c40a31c716952b74785102c90fd6afa7Rafael Espindola 26867b00520c8f5b48fad722b790d87fea6be764efeChris Lattner /// DeferredDecls - This contains all the decls which have definitions but 26967b00520c8f5b48fad722b790d87fea6be764efeChris Lattner /// which are deferred for emission and therefore should only be output if 27067b00520c8f5b48fad722b790d87fea6be764efeChris Lattner /// they are actually used. If a decl is in this, then it is known to have 271f746aa6a8f538be914173a4aef2d9a2fd9f99d17John McCall /// not been referenced yet. 272f746aa6a8f538be914173a4aef2d9a2fd9f99d17John McCall llvm::StringMap<GlobalDecl> DeferredDecls; 27367b00520c8f5b48fad722b790d87fea6be764efeChris Lattner 27467b00520c8f5b48fad722b790d87fea6be764efeChris Lattner /// DeferredDeclsToEmit - This is a list of deferred decls which we have seen 27567b00520c8f5b48fad722b790d87fea6be764efeChris Lattner /// that *are* actually referenced. These get code generated when the module 27667b00520c8f5b48fad722b790d87fea6be764efeChris Lattner /// is done. 2772a131fbca2a51085dc083b8c56a2d4ced3cf1413Anders Carlsson std::vector<GlobalDecl> DeferredDeclsToEmit; 27803f5ad9a7707e098f601921fcec17ed65eb355a7Daniel Dunbar 279d5617eeafc93209a26b9f88276c88cf997c3a0a7John McCall /// DeferredVTables - A queue of (optional) vtables to consider emitting. 280d5617eeafc93209a26b9f88276c88cf997c3a0a7John McCall std::vector<const CXXRecordDecl*> DeferredVTables; 281d5617eeafc93209a26b9f88276c88cf997c3a0a7John McCall 2820269871c9cba493f76237175ab60313406f3bafaDaniel Dunbar /// LLVMUsed - List of global values which are required to be 2830269871c9cba493f76237175ab60313406f3bafaDaniel Dunbar /// present in the object file; bitcast to i8*. This is used for 2840269871c9cba493f76237175ab60313406f3bafaDaniel Dunbar /// forcing visibility of symbols which may otherwise be optimized 2850269871c9cba493f76237175ab60313406f3bafaDaniel Dunbar /// out. 28635f38a2c22d68c22e2dbe8e9ee84c120c8f327bbChris Lattner std::vector<llvm::WeakVH> LLVMUsed; 287ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump 288ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump /// GlobalCtors - Store the list of global constructors and their respective 289ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump /// priorities to be emitted when the translation unit is complete. 2906bfed7e411adc46eaf616371f85f68305c6e6257Daniel Dunbar CtorList GlobalCtors; 2916bfed7e411adc46eaf616371f85f68305c6e6257Daniel Dunbar 292ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump /// GlobalDtors - Store the list of global destructors and their respective 293ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump /// priorities to be emitted when the translation unit is complete. 2946bfed7e411adc46eaf616371f85f68305c6e6257Daniel Dunbar CtorList GlobalDtors; 2956bfed7e411adc46eaf616371f85f68305c6e6257Daniel Dunbar 296793a990774826a0c20b0da66cec0991badfb8b63Anders Carlsson /// MangledDeclNames - A map of canonical GlobalDecls to their mangled names. 297686775deca8b8685eb90801495880e3abdd844c2Chris Lattner llvm::DenseMap<GlobalDecl, StringRef> MangledDeclNames; 298793a990774826a0c20b0da66cec0991badfb8b63Anders Carlsson llvm::BumpPtrAllocator MangledNamesAllocator; 299793a990774826a0c20b0da66cec0991badfb8b63Anders Carlsson 30077f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge /// Global annotations. 301532485cc6c078d9e51b517c6bbd8984deb17f0feNate Begeman std::vector<llvm::Constant*> Annotations; 302ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump 30377f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge /// Map used to get unique annotation strings. 30477f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge llvm::StringMap<llvm::Constant*> AnnotationStrings; 30577f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge 306c9e2091efcb535110474434dd12015afdc3b1637Anders Carlsson llvm::StringMap<llvm::Constant*> CFConstantStringMap; 307a5e19c6b2554f6d9c4b9850d4dbbbfa3643282e5John McCall llvm::StringMap<llvm::GlobalVariable*> ConstantStringMap; 30871cba34b6e2d3fb81860bd2176ab7003eaf2e918Eli Friedman llvm::DenseMap<const Decl*, llvm::Constant *> StaticLocalDeclMap; 309355bba72ca52c4a70ca3c3802412c03a6ec31f24John McCall llvm::DenseMap<const Decl*, llvm::GlobalVariable*> StaticLocalDeclGuardMap; 310cd93b96bc51c255d104095bc6a6d8eac74a84b1eFariborz Jahanian 311b08cfb3c5909752c0e501a4e5c31a507a4cc1f72Fariborz Jahanian llvm::DenseMap<QualType, llvm::Constant *> AtomicSetterHelperFnMap; 312b08cfb3c5909752c0e501a4e5c31a507a4cc1f72Fariborz Jahanian llvm::DenseMap<QualType, llvm::Constant *> AtomicGetterHelperFnMap; 3133e9df9920db8de8ec93a424b0c1784f9bff301eaDaniel Dunbar 3140024937dbb23752f606846f4a12aafc712bcde33Richard Smith /// Map used to track internal linkage functions declared within 3150024937dbb23752f606846f4a12aafc712bcde33Richard Smith /// extern "C" regions. 31684083b74abc4a2d1a9013ce4c75d63ee7d6d1da3Richard Smith typedef llvm::MapVector<IdentifierInfo *, 31784083b74abc4a2d1a9013ce4c75d63ee7d6d1da3Richard Smith llvm::GlobalValue *> StaticExternCMap; 3180024937dbb23752f606846f4a12aafc712bcde33Richard Smith StaticExternCMap StaticExternCValues; 3190024937dbb23752f606846f4a12aafc712bcde33Richard Smith 320b80a16eadd0dacabfc1c32412e243ccb99dd664dRichard Smith /// \brief thread_local variables defined or used in this TU. 321b80a16eadd0dacabfc1c32412e243ccb99dd664dRichard Smith std::vector<std::pair<const VarDecl *, llvm::GlobalVariable *> > 322b80a16eadd0dacabfc1c32412e243ccb99dd664dRichard Smith CXXThreadLocals; 323b80a16eadd0dacabfc1c32412e243ccb99dd664dRichard Smith 324b80a16eadd0dacabfc1c32412e243ccb99dd664dRichard Smith /// \brief thread_local variables with initializers that need to run 325b80a16eadd0dacabfc1c32412e243ccb99dd664dRichard Smith /// before any thread_local variable in this TU is odr-used. 326b80a16eadd0dacabfc1c32412e243ccb99dd664dRichard Smith std::vector<llvm::Constant*> CXXThreadLocalInits; 327b80a16eadd0dacabfc1c32412e243ccb99dd664dRichard Smith 328efb0fa9e11f75af51744a6159530ef7cc8efa24aDaniel Dunbar /// CXXGlobalInits - Global variables with initializers that need to run 32989ed31d3f9eeb8ec77c284a5cf404a74bf5e7acfAnders Carlsson /// before main. 3306c6bda3b0b1d8adaac2ba3f4da7056e9f1eef52eEli Friedman std::vector<llvm::Constant*> CXXGlobalInits; 331bf40cb518312dde1c07e44fcae59bc4eec65589cJohn McCall 332bf40cb518312dde1c07e44fcae59bc4eec65589cJohn McCall /// When a C++ decl with an initializer is deferred, null is 333bf40cb518312dde1c07e44fcae59bc4eec65589cJohn McCall /// appended to CXXGlobalInits, and the index of that null is placed 334bf40cb518312dde1c07e44fcae59bc4eec65589cJohn McCall /// here so that the initializer will be performed in the correct 335bf40cb518312dde1c07e44fcae59bc4eec65589cJohn McCall /// order. 336bf40cb518312dde1c07e44fcae59bc4eec65589cJohn McCall llvm::DenseMap<const Decl*, unsigned> DelayedCXXInitPosition; 3379f967c5e4bbeb48caf6d0e62056b3d3fee20bf7cFariborz Jahanian 3384179ddd5752ec5a252ca1e1eb77a5c34b5835d3bAnton Korobeynikov typedef std::pair<OrderGlobalInits, llvm::Function*> GlobalInitData; 3394179ddd5752ec5a252ca1e1eb77a5c34b5835d3bAnton Korobeynikov 3404179ddd5752ec5a252ca1e1eb77a5c34b5835d3bAnton Korobeynikov struct GlobalInitPriorityCmp { 3414179ddd5752ec5a252ca1e1eb77a5c34b5835d3bAnton Korobeynikov bool operator()(const GlobalInitData &LHS, 3424179ddd5752ec5a252ca1e1eb77a5c34b5835d3bAnton Korobeynikov const GlobalInitData &RHS) const { 3434179ddd5752ec5a252ca1e1eb77a5c34b5835d3bAnton Korobeynikov return LHS.first.priority < RHS.first.priority; 3444179ddd5752ec5a252ca1e1eb77a5c34b5835d3bAnton Korobeynikov } 3454179ddd5752ec5a252ca1e1eb77a5c34b5835d3bAnton Korobeynikov }; 3464179ddd5752ec5a252ca1e1eb77a5c34b5835d3bAnton Korobeynikov 3479f967c5e4bbeb48caf6d0e62056b3d3fee20bf7cFariborz Jahanian /// - Global variables with initializers whose order of initialization 3489f967c5e4bbeb48caf6d0e62056b3d3fee20bf7cFariborz Jahanian /// is set by init_priority attribute. 3494179ddd5752ec5a252ca1e1eb77a5c34b5835d3bAnton Korobeynikov SmallVector<GlobalInitData, 8> PrioritizedCXXGlobalInits; 3501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 351efb0fa9e11f75af51744a6159530ef7cc8efa24aDaniel Dunbar /// CXXGlobalDtors - Global destructor functions and arguments that need to 352efb0fa9e11f75af51744a6159530ef7cc8efa24aDaniel Dunbar /// run on termination. 353810112e28dc839715d17b0a786f23aaa19600ac0Chris Lattner std::vector<std::pair<llvm::WeakVH,llvm::Constant*> > CXXGlobalDtors; 354efb0fa9e11f75af51744a6159530ef7cc8efa24aDaniel Dunbar 355b6cbe517237c3c223beb064d60d5b49e56d65c06Douglas Gregor /// \brief The complete set of modules that has been imported. 356b6cbe517237c3c223beb064d60d5b49e56d65c06Douglas Gregor llvm::SetVector<clang::Module *> ImportedModules; 357b6cbe517237c3c223beb064d60d5b49e56d65c06Douglas Gregor 3583190ca922d3743137e15fe0c525c04b177b9983bReid Kleckner /// \brief A vector of metadata strings. 3593190ca922d3743137e15fe0c525c04b177b9983bReid Kleckner SmallVector<llvm::Value *, 16> LinkerOptionsMetadata; 3603190ca922d3743137e15fe0c525c04b177b9983bReid Kleckner 36145c4ea75b235de94f44bf96843624e6a559e4c00Douglas Gregor /// @name Cache for Objective-C runtime types 36245c4ea75b235de94f44bf96843624e6a559e4c00Douglas Gregor /// @{ 36345c4ea75b235de94f44bf96843624e6a559e4c00Douglas Gregor 364ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump /// CFConstantStringClassRef - Cached reference to the class for constant 365ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump /// strings. This value has type int * but is actually an Obj-C class pointer. 366428edb7f7599b4ee44eaad00bb3c330495fc1ad6Fariborz Jahanian llvm::WeakVH CFConstantStringClassRef; 3671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3684c73307c74764ba99e1379677fe92af72f676531Fariborz Jahanian /// ConstantStringClassRef - Cached reference to the class for constant 3692bb5ddaff86ee73d2cea7ec1835978afc88a83f0Fariborz Jahanian /// strings. This value has type int * but is actually an Obj-C class pointer. 370428edb7f7599b4ee44eaad00bb3c330495fc1ad6Fariborz Jahanian llvm::WeakVH ConstantStringClassRef; 3712bb5ddaff86ee73d2cea7ec1835978afc88a83f0Fariborz Jahanian 37245c4ea75b235de94f44bf96843624e6a559e4c00Douglas Gregor /// \brief The LLVM type corresponding to NSConstantString. 37345c4ea75b235de94f44bf96843624e6a559e4c00Douglas Gregor llvm::StructType *NSConstantStringType; 37445c4ea75b235de94f44bf96843624e6a559e4c00Douglas Gregor 3750815b579b31cb3129f732bb7ea36fd6ba6949e98Douglas Gregor /// \brief The type used to describe the state of a fast enumeration in 3760815b579b31cb3129f732bb7ea36fd6ba6949e98Douglas Gregor /// Objective-C's for..in loop. 3770815b579b31cb3129f732bb7ea36fd6ba6949e98Douglas Gregor QualType ObjCFastEnumerationStateType; 3780815b579b31cb3129f732bb7ea36fd6ba6949e98Douglas Gregor 37945c4ea75b235de94f44bf96843624e6a559e4c00Douglas Gregor /// @} 38045c4ea75b235de94f44bf96843624e6a559e4c00Douglas Gregor 3810d13f6fdbdd6f06e2449b8834dda53334abd399aDavid Chisnall /// Lazily create the Objective-C runtime 3820d13f6fdbdd6f06e2449b8834dda53334abd399aDavid Chisnall void createObjCRuntime(); 3830d13f6fdbdd6f06e2449b8834dda53334abd399aDavid Chisnall 3848c25fc584ce27d59df9923f153e8a132dde58d04Peter Collingbourne void createOpenCLRuntime(); 3856c0aa5ff6e6253db0f993053599e2a52b5b93b2dPeter Collingbourne void createCUDARuntime(); 3868c25fc584ce27d59df9923f153e8a132dde58d04Peter Collingbourne 387bcf6b98247bd3ac76c5edf706b1087a8d32c0320Rafael Espindola bool isTriviallyRecursive(const FunctionDecl *F); 388a411d2f1ed4598a7a96a7befe07a9d9ee1a6efdeRafael Espindola bool shouldEmitFunction(const FunctionDecl *F); 389673431a2986f750b4d8fadb57abf3f00db27bbbdDaniel Dunbar 390673431a2986f750b4d8fadb57abf3f00db27bbbdDaniel Dunbar /// @name Cache for Blocks Runtime Globals 391673431a2986f750b4d8fadb57abf3f00db27bbbdDaniel Dunbar /// @{ 392673431a2986f750b4d8fadb57abf3f00db27bbbdDaniel Dunbar 393673431a2986f750b4d8fadb57abf3f00db27bbbdDaniel Dunbar llvm::Constant *NSConcreteGlobalBlock; 394673431a2986f750b4d8fadb57abf3f00db27bbbdDaniel Dunbar llvm::Constant *NSConcreteStackBlock; 395754b9fbaa13749c61393cc613eec7c79efe60ddfDaniel Dunbar 396673431a2986f750b4d8fadb57abf3f00db27bbbdDaniel Dunbar llvm::Constant *BlockObjectAssign; 397673431a2986f750b4d8fadb57abf3f00db27bbbdDaniel Dunbar llvm::Constant *BlockObjectDispose; 398673431a2986f750b4d8fadb57abf3f00db27bbbdDaniel Dunbar 3999cbe4f0ba01ec304e1e3d071c071f7bca33631c0Chris Lattner llvm::Type *BlockDescriptorType; 4009cbe4f0ba01ec304e1e3d071c071f7bca33631c0Chris Lattner llvm::Type *GenericBlockLiteralType; 401d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall 402d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall struct { 403d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall int GlobalUniqueCount; 404d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall } Block; 4054f45bc099f2665bc6e4bcbb169aa452390dbf3feWill Dietz 406495cfa46300979642acde8d93a1f21c9291dac98Nadav Rotem /// void @llvm.lifetime.start(i64 %size, i8* nocapture <ptr>) 407495cfa46300979642acde8d93a1f21c9291dac98Nadav Rotem llvm::Constant *LifetimeStartFn; 408495cfa46300979642acde8d93a1f21c9291dac98Nadav Rotem 409495cfa46300979642acde8d93a1f21c9291dac98Nadav Rotem /// void @llvm.lifetime.end(i64 %size, i8* nocapture <ptr>) 410495cfa46300979642acde8d93a1f21c9291dac98Nadav Rotem llvm::Constant *LifetimeEndFn; 411495cfa46300979642acde8d93a1f21c9291dac98Nadav Rotem 4124904bf4e84cfb48080270ebaa9005327f18ab0e5Fariborz Jahanian GlobalDecl initializedGlobalDecl; 413d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall 4144f45bc099f2665bc6e4bcbb169aa452390dbf3feWill Dietz llvm::BlackList SanitizerBlacklist; 4154f45bc099f2665bc6e4bcbb169aa452390dbf3feWill Dietz 4164f45bc099f2665bc6e4bcbb169aa452390dbf3feWill Dietz const SanitizerOptions &SanOpts; 4174f45bc099f2665bc6e4bcbb169aa452390dbf3feWill Dietz 418673431a2986f750b4d8fadb57abf3f00db27bbbdDaniel Dunbar /// @} 4195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 4202811ccf48d6d898c42cc4cfad37abedb36236d20Chandler Carruth CodeGenModule(ASTContext &C, const CodeGenOptions &CodeGenOpts, 4213abae0995b5d4faa3d8cfb1f06118d71a60c7dabJohn McCall llvm::Module &M, const llvm::DataLayout &TD, 4223abae0995b5d4faa3d8cfb1f06118d71a60c7dabJohn McCall DiagnosticsEngine &Diags); 423815c78fd9ab8bd5dfe8e8a91b8c6a413e2b8c889Ted Kremenek 4242b94fe35edf951a14ecd32b21f7ebcc2e3754c67Chris Lattner ~CodeGenModule(); 425ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump 426815c78fd9ab8bd5dfe8e8a91b8c6a413e2b8c889Ted Kremenek /// Release - Finalize LLVM code generation. 427815c78fd9ab8bd5dfe8e8a91b8c6a413e2b8c889Ted Kremenek void Release(); 428208ff5e8a073de2a5d15cbe03cab8a4c0d935e28Daniel Dunbar 429208ff5e8a073de2a5d15cbe03cab8a4c0d935e28Daniel Dunbar /// getObjCRuntime() - Return a reference to the configured 430208ff5e8a073de2a5d15cbe03cab8a4c0d935e28Daniel Dunbar /// Objective-C runtime. 431ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump CGObjCRuntime &getObjCRuntime() { 432e926523105dd2604ccd5c101605dea43c5269965Peter Collingbourne if (!ObjCRuntime) createObjCRuntime(); 433e926523105dd2604ccd5c101605dea43c5269965Peter Collingbourne return *ObjCRuntime; 434208ff5e8a073de2a5d15cbe03cab8a4c0d935e28Daniel Dunbar } 435ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump 436f3477c13eeaf11b32a41f181398fb5deffd0dd73Sylvestre Ledru /// hasObjCRuntime() - Return true iff an Objective-C runtime has 437208ff5e8a073de2a5d15cbe03cab8a4c0d935e28Daniel Dunbar /// been configured. 438e926523105dd2604ccd5c101605dea43c5269965Peter Collingbourne bool hasObjCRuntime() { return !!ObjCRuntime; } 439208ff5e8a073de2a5d15cbe03cab8a4c0d935e28Daniel Dunbar 4406c0aa5ff6e6253db0f993053599e2a52b5b93b2dPeter Collingbourne /// getOpenCLRuntime() - Return a reference to the configured OpenCL runtime. 4418c25fc584ce27d59df9923f153e8a132dde58d04Peter Collingbourne CGOpenCLRuntime &getOpenCLRuntime() { 4428c25fc584ce27d59df9923f153e8a132dde58d04Peter Collingbourne assert(OpenCLRuntime != 0); 4438c25fc584ce27d59df9923f153e8a132dde58d04Peter Collingbourne return *OpenCLRuntime; 4448c25fc584ce27d59df9923f153e8a132dde58d04Peter Collingbourne } 4458c25fc584ce27d59df9923f153e8a132dde58d04Peter Collingbourne 4466c0aa5ff6e6253db0f993053599e2a52b5b93b2dPeter Collingbourne /// getCUDARuntime() - Return a reference to the configured CUDA runtime. 4476c0aa5ff6e6253db0f993053599e2a52b5b93b2dPeter Collingbourne CGCUDARuntime &getCUDARuntime() { 4486c0aa5ff6e6253db0f993053599e2a52b5b93b2dPeter Collingbourne assert(CUDARuntime != 0); 4496c0aa5ff6e6253db0f993053599e2a52b5b93b2dPeter Collingbourne return *CUDARuntime; 4506c0aa5ff6e6253db0f993053599e2a52b5b93b2dPeter Collingbourne } 4516c0aa5ff6e6253db0f993053599e2a52b5b93b2dPeter Collingbourne 452f85e193739c953358c865005855253af4f68a497John McCall ARCEntrypoints &getARCEntrypoints() const { 4534e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie assert(getLangOpts().ObjCAutoRefCount && ARCData != 0); 454f85e193739c953358c865005855253af4f68a497John McCall return *ARCData; 455f85e193739c953358c865005855253af4f68a497John McCall } 456f85e193739c953358c865005855253af4f68a497John McCall 457f85e193739c953358c865005855253af4f68a497John McCall RREntrypoints &getRREntrypoints() const { 458f85e193739c953358c865005855253af4f68a497John McCall assert(RRData != 0); 459f85e193739c953358c865005855253af4f68a497John McCall return *RRData; 460f85e193739c953358c865005855253af4f68a497John McCall } 461f85e193739c953358c865005855253af4f68a497John McCall 46271cba34b6e2d3fb81860bd2176ab7003eaf2e918Eli Friedman llvm::Constant *getStaticLocalDeclAddress(const VarDecl *D) { 46371cba34b6e2d3fb81860bd2176ab7003eaf2e918Eli Friedman return StaticLocalDeclMap[D]; 46465ad5a42cca954e070428dcc499b62393aa7a6d3Fariborz Jahanian } 46563326a53418b4853a83b360ce1dbdb10c5739fc7Fariborz Jahanian void setStaticLocalDeclAddress(const VarDecl *D, 46671cba34b6e2d3fb81860bd2176ab7003eaf2e918Eli Friedman llvm::Constant *C) { 46771cba34b6e2d3fb81860bd2176ab7003eaf2e918Eli Friedman StaticLocalDeclMap[D] = C; 46865ad5a42cca954e070428dcc499b62393aa7a6d3Fariborz Jahanian } 46965ad5a42cca954e070428dcc499b62393aa7a6d3Fariborz Jahanian 470355bba72ca52c4a70ca3c3802412c03a6ec31f24John McCall llvm::GlobalVariable *getStaticLocalDeclGuardAddress(const VarDecl *D) { 471355bba72ca52c4a70ca3c3802412c03a6ec31f24John McCall return StaticLocalDeclGuardMap[D]; 472355bba72ca52c4a70ca3c3802412c03a6ec31f24John McCall } 473355bba72ca52c4a70ca3c3802412c03a6ec31f24John McCall void setStaticLocalDeclGuardAddress(const VarDecl *D, 474355bba72ca52c4a70ca3c3802412c03a6ec31f24John McCall llvm::GlobalVariable *C) { 475355bba72ca52c4a70ca3c3802412c03a6ec31f24John McCall StaticLocalDeclGuardMap[D] = C; 476355bba72ca52c4a70ca3c3802412c03a6ec31f24John McCall } 477355bba72ca52c4a70ca3c3802412c03a6ec31f24John McCall 478b08cfb3c5909752c0e501a4e5c31a507a4cc1f72Fariborz Jahanian llvm::Constant *getAtomicSetterHelperFnMap(QualType Ty) { 479b08cfb3c5909752c0e501a4e5c31a507a4cc1f72Fariborz Jahanian return AtomicSetterHelperFnMap[Ty]; 480cd93b96bc51c255d104095bc6a6d8eac74a84b1eFariborz Jahanian } 481b08cfb3c5909752c0e501a4e5c31a507a4cc1f72Fariborz Jahanian void setAtomicSetterHelperFnMap(QualType Ty, 482cd93b96bc51c255d104095bc6a6d8eac74a84b1eFariborz Jahanian llvm::Constant *Fn) { 483b08cfb3c5909752c0e501a4e5c31a507a4cc1f72Fariborz Jahanian AtomicSetterHelperFnMap[Ty] = Fn; 484b08cfb3c5909752c0e501a4e5c31a507a4cc1f72Fariborz Jahanian } 485b08cfb3c5909752c0e501a4e5c31a507a4cc1f72Fariborz Jahanian 486b08cfb3c5909752c0e501a4e5c31a507a4cc1f72Fariborz Jahanian llvm::Constant *getAtomicGetterHelperFnMap(QualType Ty) { 487b08cfb3c5909752c0e501a4e5c31a507a4cc1f72Fariborz Jahanian return AtomicGetterHelperFnMap[Ty]; 488b08cfb3c5909752c0e501a4e5c31a507a4cc1f72Fariborz Jahanian } 489b08cfb3c5909752c0e501a4e5c31a507a4cc1f72Fariborz Jahanian void setAtomicGetterHelperFnMap(QualType Ty, 490b08cfb3c5909752c0e501a4e5c31a507a4cc1f72Fariborz Jahanian llvm::Constant *Fn) { 491b08cfb3c5909752c0e501a4e5c31a507a4cc1f72Fariborz Jahanian AtomicGetterHelperFnMap[Ty] = Fn; 492cd93b96bc51c255d104095bc6a6d8eac74a84b1eFariborz Jahanian } 493cd93b96bc51c255d104095bc6a6d8eac74a84b1eFariborz Jahanian 494aa11289f754d220c9c155b68a4f84cdcfcefef6aDevang Patel CGDebugInfo *getModuleDebugInfo() { return DebugInfo; } 4955de7a0e8800b89780e565c1013e566414f11546aDevang Patel 496b49bd27b334a6c4e3bf9d810a7d5b022578f1194Dan Gohman llvm::MDNode *getNoObjCARCExceptionsMetadata() { 497b49bd27b334a6c4e3bf9d810a7d5b022578f1194Dan Gohman if (!NoObjCARCExceptionsMetadata) 498b49bd27b334a6c4e3bf9d810a7d5b022578f1194Dan Gohman NoObjCARCExceptionsMetadata = 499b49bd27b334a6c4e3bf9d810a7d5b022578f1194Dan Gohman llvm::MDNode::get(getLLVMContext(), 500b49bd27b334a6c4e3bf9d810a7d5b022578f1194Dan Gohman SmallVector<llvm::Value*,1>()); 501b49bd27b334a6c4e3bf9d810a7d5b022578f1194Dan Gohman return NoObjCARCExceptionsMetadata; 502b49bd27b334a6c4e3bf9d810a7d5b022578f1194Dan Gohman } 503b49bd27b334a6c4e3bf9d810a7d5b022578f1194Dan Gohman 5045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ASTContext &getContext() const { return Context; } 5054e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie const LangOptions &getLangOpts() const { return LangOpts; } 50664aa4b3ec7e62288e2e66c1935487ece995ca94bJohn McCall const CodeGenOptions &getCodeGenOpts() const { return CodeGenOpts; } 5075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer llvm::Module &getModule() const { return TheModule; } 508d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie DiagnosticsEngine &getDiags() const { return Diags; } 50925a6a84cf5067b32c271e3ba078676dee838798dMicah Villmow const llvm::DataLayout &getDataLayout() const { return TheDataLayout; } 51064aa4b3ec7e62288e2e66c1935487ece995ca94bJohn McCall const TargetInfo &getTarget() const { return Target; } 51164aa4b3ec7e62288e2e66c1935487ece995ca94bJohn McCall CGCXXABI &getCXXABI() { return ABI; } 512a1cf15f4680e5cf39e72e28c5ea854fcba792e84Owen Anderson llvm::LLVMContext &getLLVMContext() { return VMContext; } 51364aa4b3ec7e62288e2e66c1935487ece995ca94bJohn McCall 514bc7fbf0d37b286b37d96b033dfaaabf9c729bca8John McCall bool shouldUseTBAA() const { return TBAA != 0; } 515bc7fbf0d37b286b37d96b033dfaaabf9c729bca8John McCall 51664aa4b3ec7e62288e2e66c1935487ece995ca94bJohn McCall const TargetCodeGenInfo &getTargetCodeGenInfo(); 51764aa4b3ec7e62288e2e66c1935487ece995ca94bJohn McCall 51864aa4b3ec7e62288e2e66c1935487ece995ca94bJohn McCall CodeGenTypes &getTypes() { return Types; } 51964aa4b3ec7e62288e2e66c1935487ece995ca94bJohn McCall 52064aa4b3ec7e62288e2e66c1935487ece995ca94bJohn McCall CodeGenVTables &getVTables() { return VTables; } 52164aa4b3ec7e62288e2e66c1935487ece995ca94bJohn McCall VTableContext &getVTableContext() { return VTables.getVTableContext(); } 52264aa4b3ec7e62288e2e66c1935487ece995ca94bJohn McCall 5233d5aff5d3036b0ff09d114857cd2276134b3d8c9Dan Gohman llvm::MDNode *getTBAAInfo(QualType QTy); 5248cb4a070d491ddd671b049110cc8d0accb08b905Kostya Serebryany llvm::MDNode *getTBAAInfoForVTablePtr(); 525b22c7dc707cf3770ff3b5e5f11f11fd0aaa06d9bDan Gohman llvm::MDNode *getTBAAStructInfo(QualType QTy); 526b37a73d5c6a0c8bb1f6e363d3b53980e4fa0ceadManman Ren /// Return the MDNode in the type DAG for the given struct type. 527b37a73d5c6a0c8bb1f6e363d3b53980e4fa0ceadManman Ren llvm::MDNode *getTBAAStructTypeInfo(QualType QTy); 528b37a73d5c6a0c8bb1f6e363d3b53980e4fa0ceadManman Ren /// Return the path-aware tag for given base type, access node and offset. 529b37a73d5c6a0c8bb1f6e363d3b53980e4fa0ceadManman Ren llvm::MDNode *getTBAAStructTagInfo(QualType BaseTy, llvm::MDNode *AccessN, 530b37a73d5c6a0c8bb1f6e363d3b53980e4fa0ceadManman Ren uint64_t O); 5313d5aff5d3036b0ff09d114857cd2276134b3d8c9Dan Gohman 532a9b21d22bb9337649723a8477b5cb15f83451e7dRichard Smith bool isTypeConstant(QualType QTy, bool ExcludeCtorDtor); 533a9b21d22bb9337649723a8477b5cb15f83451e7dRichard Smith 5349eda3abe7e183b05834947391c0cdc291f4ee0d8John McCall bool isPaddedAtomicType(QualType type); 5359eda3abe7e183b05834947391c0cdc291f4ee0d8John McCall bool isPaddedAtomicType(const AtomicType *type); 5369eda3abe7e183b05834947391c0cdc291f4ee0d8John McCall 537ca835180412eb4382fe4cc97e9374489b9ad3946Manman Ren /// Decorate the instruction with a TBAA tag. For scalar TBAA, the tag 538ca835180412eb4382fe4cc97e9374489b9ad3946Manman Ren /// is the same as the type. For struct-path aware TBAA, the tag 539ca835180412eb4382fe4cc97e9374489b9ad3946Manman Ren /// is different from the type: base type, access type and offset. 540ca835180412eb4382fe4cc97e9374489b9ad3946Manman Ren /// When ConvertTypeToTag is true, we create a tag based on the scalar type. 541ca835180412eb4382fe4cc97e9374489b9ad3946Manman Ren void DecorateInstruction(llvm::Instruction *Inst, 542ca835180412eb4382fe4cc97e9374489b9ad3946Manman Ren llvm::MDNode *TBAAInfo, 543ca835180412eb4382fe4cc97e9374489b9ad3946Manman Ren bool ConvertTypeToTag = true); 5443d5aff5d3036b0ff09d114857cd2276134b3d8c9Dan Gohman 545bc8d40d85f3fa1e34569834916f18fecaa635152John McCall /// getSize - Emit the given number of characters as a value of type size_t. 546bc8d40d85f3fa1e34569834916f18fecaa635152John McCall llvm::ConstantInt *getSize(CharUnits numChars); 547bc8d40d85f3fa1e34569834916f18fecaa635152John McCall 54804d4078425614bf9fd58d606335c1f5f74ee7fa4Daniel Dunbar /// setGlobalVisibility - Set the visibility for the given LLVM 54904d4078425614bf9fd58d606335c1f5f74ee7fa4Daniel Dunbar /// GlobalValue. 5500ffeaad72cb335b926b064379be4c9886bbff004Anders Carlsson void setGlobalVisibility(llvm::GlobalValue *GV, const NamedDecl *D) const; 55104d4078425614bf9fd58d606335c1f5f74ee7fa4Daniel Dunbar 552de981f3ff163bc9ec69e4c5e7316e94276412993Hans Wennborg /// setTLSMode - Set the TLS mode for the given LLVM GlobalVariable 553de981f3ff163bc9ec69e4c5e7316e94276412993Hans Wennborg /// for the thread-local variable declaration D. 554de981f3ff163bc9ec69e4c5e7316e94276412993Hans Wennborg void setTLSMode(llvm::GlobalVariable *GV, const VarDecl &D) const; 555de981f3ff163bc9ec69e4c5e7316e94276412993Hans Wennborg 556fa2e99f72f9bfe2270ea8caf76d0eef11c45259fAnders Carlsson /// TypeVisibilityKind - The kind of global variable that is passed to 557fa2e99f72f9bfe2270ea8caf76d0eef11c45259fAnders Carlsson /// setTypeVisibility 558fa2e99f72f9bfe2270ea8caf76d0eef11c45259fAnders Carlsson enum TypeVisibilityKind { 559fa2e99f72f9bfe2270ea8caf76d0eef11c45259fAnders Carlsson TVK_ForVTT, 560fa2e99f72f9bfe2270ea8caf76d0eef11c45259fAnders Carlsson TVK_ForVTable, 561bda0d6bda0f1a08a9fdf3ee4cf550b6b10d454ecJohn McCall TVK_ForConstructionVTable, 562fa2e99f72f9bfe2270ea8caf76d0eef11c45259fAnders Carlsson TVK_ForRTTI, 563fa2e99f72f9bfe2270ea8caf76d0eef11c45259fAnders Carlsson TVK_ForRTTIName 564fa2e99f72f9bfe2270ea8caf76d0eef11c45259fAnders Carlsson }; 565fa2e99f72f9bfe2270ea8caf76d0eef11c45259fAnders Carlsson 566cbfe50224b19119e759802bd0c1463269dffd09eJohn McCall /// setTypeVisibility - Set the visibility for the given global 567cbfe50224b19119e759802bd0c1463269dffd09eJohn McCall /// value which holds information about a type. 568cbfe50224b19119e759802bd0c1463269dffd09eJohn McCall void setTypeVisibility(llvm::GlobalValue *GV, const CXXRecordDecl *D, 569fa2e99f72f9bfe2270ea8caf76d0eef11c45259fAnders Carlsson TypeVisibilityKind TVK) const; 570cbfe50224b19119e759802bd0c1463269dffd09eJohn McCall 571c7e98fabd852e9dfa7409b7fc664b87322522c43Anders Carlsson static llvm::GlobalValue::VisibilityTypes GetLLVMVisibility(Visibility V) { 572c7e98fabd852e9dfa7409b7fc664b87322522c43Anders Carlsson switch (V) { 573c7e98fabd852e9dfa7409b7fc664b87322522c43Anders Carlsson case DefaultVisibility: return llvm::GlobalValue::DefaultVisibility; 574c7e98fabd852e9dfa7409b7fc664b87322522c43Anders Carlsson case HiddenVisibility: return llvm::GlobalValue::HiddenVisibility; 575c7e98fabd852e9dfa7409b7fc664b87322522c43Anders Carlsson case ProtectedVisibility: return llvm::GlobalValue::ProtectedVisibility; 576c7e98fabd852e9dfa7409b7fc664b87322522c43Anders Carlsson } 577c7e98fabd852e9dfa7409b7fc664b87322522c43Anders Carlsson llvm_unreachable("unknown visibility!"); 578c7e98fabd852e9dfa7409b7fc664b87322522c43Anders Carlsson } 579c7e98fabd852e9dfa7409b7fc664b87322522c43Anders Carlsson 580d46f98573ba104eda102dd3224b2dca69f1c6336John McCall llvm::Constant *GetAddrOfGlobal(GlobalDecl GD) { 581d46f98573ba104eda102dd3224b2dca69f1c6336John McCall if (isa<CXXConstructorDecl>(GD.getDecl())) 582d46f98573ba104eda102dd3224b2dca69f1c6336John McCall return GetAddrOfCXXConstructor(cast<CXXConstructorDecl>(GD.getDecl()), 583d46f98573ba104eda102dd3224b2dca69f1c6336John McCall GD.getCtorType()); 584d46f98573ba104eda102dd3224b2dca69f1c6336John McCall else if (isa<CXXDestructorDecl>(GD.getDecl())) 585d46f98573ba104eda102dd3224b2dca69f1c6336John McCall return GetAddrOfCXXDestructor(cast<CXXDestructorDecl>(GD.getDecl()), 586d46f98573ba104eda102dd3224b2dca69f1c6336John McCall GD.getDtorType()); 587d46f98573ba104eda102dd3224b2dca69f1c6336John McCall else if (isa<FunctionDecl>(GD.getDecl())) 588d46f98573ba104eda102dd3224b2dca69f1c6336John McCall return GetAddrOfFunction(GD); 589d46f98573ba104eda102dd3224b2dca69f1c6336John McCall else 590d46f98573ba104eda102dd3224b2dca69f1c6336John McCall return GetAddrOfGlobalVar(cast<VarDecl>(GD.getDecl())); 591d46f98573ba104eda102dd3224b2dca69f1c6336John McCall } 592d46f98573ba104eda102dd3224b2dca69f1c6336John McCall 59364aa4b3ec7e62288e2e66c1935487ece995ca94bJohn McCall /// CreateOrReplaceCXXRuntimeVariable - Will return a global variable of the 59464aa4b3ec7e62288e2e66c1935487ece995ca94bJohn McCall /// given type. If a variable with a different type already exists then a new 5953bd6202ea2d5b5f7c8229cd280a846ae3dcf2355Anders Carlsson /// variable with the right type will be created and all uses of the old 5963bd6202ea2d5b5f7c8229cd280a846ae3dcf2355Anders Carlsson /// variable will be replaced with a bitcast to the new variable. 5973bd6202ea2d5b5f7c8229cd280a846ae3dcf2355Anders Carlsson llvm::GlobalVariable * 598686775deca8b8685eb90801495880e3abdd844c2Chris Lattner CreateOrReplaceCXXRuntimeVariable(StringRef Name, llvm::Type *Ty, 5993bd6202ea2d5b5f7c8229cd280a846ae3dcf2355Anders Carlsson llvm::GlobalValue::LinkageTypes Linkage); 6003bd6202ea2d5b5f7c8229cd280a846ae3dcf2355Anders Carlsson 6014dc34ebf2a0716bf77ba110dab6777a3fc4397ddPeter Collingbourne /// GetGlobalVarAddressSpace - Return the address space of the underlying 6024dc34ebf2a0716bf77ba110dab6777a3fc4397ddPeter Collingbourne /// global variable for D, as determined by its declaration. Normally this 6034dc34ebf2a0716bf77ba110dab6777a3fc4397ddPeter Collingbourne /// is the same as the address space of D's type, but in CUDA, address spaces 6044dc34ebf2a0716bf77ba110dab6777a3fc4397ddPeter Collingbourne /// are associated with declarations, not types. 6054dc34ebf2a0716bf77ba110dab6777a3fc4397ddPeter Collingbourne unsigned GetGlobalVarAddressSpace(const VarDecl *D, unsigned AddrSpace); 6064dc34ebf2a0716bf77ba110dab6777a3fc4397ddPeter Collingbourne 607ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump /// GetAddrOfGlobalVar - Return the llvm::Constant for the address of the 608570585c91dee98d7ba8ccf1198c03208ba17966bChris Lattner /// given global variable. If Ty is non-null and if the global doesn't exist, 609570585c91dee98d7ba8ccf1198c03208ba17966bChris Lattner /// then it will be greated with the specified type instead of whatever the 610570585c91dee98d7ba8ccf1198c03208ba17966bChris Lattner /// normal requested type would be. 611570585c91dee98d7ba8ccf1198c03208ba17966bChris Lattner llvm::Constant *GetAddrOfGlobalVar(const VarDecl *D, 6122acc6e3feda5e4f7d9009bdcf8b1cd777fecfe2dChris Lattner llvm::Type *Ty = 0); 613bd012ff1fa088181646a784f385b28867372d434Daniel Dunbar 6141de4d4e8cb2e9c88809fea8092bc6e835a5473d2John McCall 61534809507232bc4c3c4840c7d092c7440219fddafChris Lattner /// GetAddrOfFunction - Return the address of the given function. If Ty is 61634809507232bc4c3c4840c7d092c7440219fddafChris Lattner /// non-null, then this function will use the specified type if it has to 61734809507232bc4c3c4840c7d092c7440219fddafChris Lattner /// create it. 618b4880bab7fc1b61267cfd9a0ad52188e7a828cb3Chris Lattner llvm::Constant *GetAddrOfFunction(GlobalDecl GD, 6192acc6e3feda5e4f7d9009bdcf8b1cd777fecfe2dChris Lattner llvm::Type *Ty = 0, 6201faa89f9c619e4b2411fab4af7e22ee7a2bd9009Anders Carlsson bool ForVTable = false); 6216143293fa4366ee95d7e47e61bd030a34bf68b55Daniel Dunbar 6221d7088d1d9dc99e5478c0184a3e21cafef2a0b53Anders Carlsson /// GetAddrOfRTTIDescriptor - Get the address of the RTTI descriptor 6231d7088d1d9dc99e5478c0184a3e21cafef2a0b53Anders Carlsson /// for the given type. 6249dffe6f51c676c1e423c382c62d1648746e36cd4John McCall llvm::Constant *GetAddrOfRTTIDescriptor(QualType Ty, bool ForEH = false); 62531b7f52d8c8d459e80d2a72176cc7fcc4b7d8d38Anders Carlsson 626c5f804636e367ef744fd24cf88f7c956a5af0434Nico Weber /// GetAddrOfUuidDescriptor - Get the address of a uuid descriptor . 627c5f804636e367ef744fd24cf88f7c956a5af0434Nico Weber llvm::Constant *GetAddrOfUuidDescriptor(const CXXUuidofExpr* E); 628c5f804636e367ef744fd24cf88f7c956a5af0434Nico Weber 62919879c98d964bc67442618510af04e3457219780Anders Carlsson /// GetAddrOfThunk - Get the address of the thunk for the given global decl. 63084c49e4e4baeb4c30251fd72220efb344b033cf0Anders Carlsson llvm::Constant *GetAddrOfThunk(GlobalDecl GD, const ThunkInfo &Thunk); 63119879c98d964bc67442618510af04e3457219780Anders Carlsson 6326a836706c40a31c716952b74785102c90fd6afa7Rafael Espindola /// GetWeakRefReference - Get a reference to the target of VD. 6336a836706c40a31c716952b74785102c90fd6afa7Rafael Espindola llvm::Constant *GetWeakRefReference(const ValueDecl *VD); 6346a836706c40a31c716952b74785102c90fd6afa7Rafael Espindola 635bb7e17b52ffaa4097b4c4d7935746d23539ffe2aAnders Carlsson /// GetNonVirtualBaseClassOffset - Returns the offset from a derived class to 636e04d45e05277ee04997fe59b1d194503f484c846Anders Carlsson /// a class. Returns null if the offset is 0. 637a04efdf635d35d88e65041fad007225d8c8d64a5Anders Carlsson llvm::Constant * 638a04efdf635d35d88e65041fad007225d8c8d64a5Anders Carlsson GetNonVirtualBaseClassOffset(const CXXRecordDecl *ClassDecl, 639f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall CastExpr::path_const_iterator PathBegin, 640f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall CastExpr::path_const_iterator PathEnd); 641d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall 642f0c11f7e6848f023ced6a5b51399ba787c7d4d0bJohn McCall /// A pair of helper functions for a __block variable. 643f0c11f7e6848f023ced6a5b51399ba787c7d4d0bJohn McCall class ByrefHelpers : public llvm::FoldingSetNode { 644f0c11f7e6848f023ced6a5b51399ba787c7d4d0bJohn McCall public: 645f0c11f7e6848f023ced6a5b51399ba787c7d4d0bJohn McCall llvm::Constant *CopyHelper; 646f0c11f7e6848f023ced6a5b51399ba787c7d4d0bJohn McCall llvm::Constant *DisposeHelper; 647f0c11f7e6848f023ced6a5b51399ba787c7d4d0bJohn McCall 648f0c11f7e6848f023ced6a5b51399ba787c7d4d0bJohn McCall /// The alignment of the field. This is important because 649f0c11f7e6848f023ced6a5b51399ba787c7d4d0bJohn McCall /// different offsets to the field within the byref struct need to 650f0c11f7e6848f023ced6a5b51399ba787c7d4d0bJohn McCall /// have different helper functions. 651f0c11f7e6848f023ced6a5b51399ba787c7d4d0bJohn McCall CharUnits Alignment; 652f0c11f7e6848f023ced6a5b51399ba787c7d4d0bJohn McCall 653f0c11f7e6848f023ced6a5b51399ba787c7d4d0bJohn McCall ByrefHelpers(CharUnits alignment) : Alignment(alignment) {} 654f0c11f7e6848f023ced6a5b51399ba787c7d4d0bJohn McCall virtual ~ByrefHelpers(); 655f0c11f7e6848f023ced6a5b51399ba787c7d4d0bJohn McCall 656f0c11f7e6848f023ced6a5b51399ba787c7d4d0bJohn McCall void Profile(llvm::FoldingSetNodeID &id) const { 657f0c11f7e6848f023ced6a5b51399ba787c7d4d0bJohn McCall id.AddInteger(Alignment.getQuantity()); 658f0c11f7e6848f023ced6a5b51399ba787c7d4d0bJohn McCall profileImpl(id); 659f0c11f7e6848f023ced6a5b51399ba787c7d4d0bJohn McCall } 660f0c11f7e6848f023ced6a5b51399ba787c7d4d0bJohn McCall virtual void profileImpl(llvm::FoldingSetNodeID &id) const = 0; 661f0c11f7e6848f023ced6a5b51399ba787c7d4d0bJohn McCall 662f0c11f7e6848f023ced6a5b51399ba787c7d4d0bJohn McCall virtual bool needsCopy() const { return true; } 663f0c11f7e6848f023ced6a5b51399ba787c7d4d0bJohn McCall virtual void emitCopy(CodeGenFunction &CGF, 664f0c11f7e6848f023ced6a5b51399ba787c7d4d0bJohn McCall llvm::Value *dest, llvm::Value *src) = 0; 665f0c11f7e6848f023ced6a5b51399ba787c7d4d0bJohn McCall 666f0c11f7e6848f023ced6a5b51399ba787c7d4d0bJohn McCall virtual bool needsDispose() const { return true; } 667f0c11f7e6848f023ced6a5b51399ba787c7d4d0bJohn McCall virtual void emitDispose(CodeGenFunction &CGF, llvm::Value *field) = 0; 668f0c11f7e6848f023ced6a5b51399ba787c7d4d0bJohn McCall }; 669f0c11f7e6848f023ced6a5b51399ba787c7d4d0bJohn McCall 670f0c11f7e6848f023ced6a5b51399ba787c7d4d0bJohn McCall llvm::FoldingSet<ByrefHelpers> ByrefHelpersCache; 671d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall 6728178df3b39ab923ff5d24538812628abee33df79John McCall /// getUniqueBlockCount - Fetches the global unique block count. 6738178df3b39ab923ff5d24538812628abee33df79John McCall int getUniqueBlockCount() { return ++Block.GlobalUniqueCount; } 6744904bf4e84cfb48080270ebaa9005327f18ab0e5Fariborz Jahanian 675d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall /// getBlockDescriptorType - Fetches the type of a generic block 676d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall /// descriptor. 6779cbe4f0ba01ec304e1e3d071c071f7bca33631c0Chris Lattner llvm::Type *getBlockDescriptorType(); 678d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall 679d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall /// getGenericBlockLiteralType - The type of a generic block literal. 6809cbe4f0ba01ec304e1e3d071c071f7bca33631c0Chris Lattner llvm::Type *getGenericBlockLiteralType(); 681d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall 682d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall /// GetAddrOfGlobalBlock - Gets the address of a block which 683d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall /// requires no captures. 684d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall llvm::Constant *GetAddrOfGlobalBlock(const BlockExpr *BE, const char *); 685a04efdf635d35d88e65041fad007225d8c8d64a5Anders Carlsson 686ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump /// GetAddrOfConstantCFString - Return a pointer to a constant CFString object 687ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump /// for the given string. 6888d4141f83d9de379547cf05bd75d4c6cf894b189Steve Naroff llvm::Constant *GetAddrOfConstantCFString(const StringLiteral *Literal); 68933e982bf782d851bfe5767acb1336fcf3419ac6bFariborz Jahanian 6904c73307c74764ba99e1379677fe92af72f676531Fariborz Jahanian /// GetAddrOfConstantString - Return a pointer to a constant NSString object 6914c73307c74764ba99e1379677fe92af72f676531Fariborz Jahanian /// for the given string. Or a user defined String object as defined via 6924c73307c74764ba99e1379677fe92af72f676531Fariborz Jahanian /// -fconstant-string-class=class_name option. 6934c73307c74764ba99e1379677fe92af72f676531Fariborz Jahanian llvm::Constant *GetAddrOfConstantString(const StringLiteral *Literal); 694a7ad98ff0919d6a24ea7c46634ea29bea551c1a0Chris Lattner 69564f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman /// GetConstantArrayFromStringLiteral - Return a constant array for the given 69664f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman /// string. 69764f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman llvm::Constant *GetConstantArrayFromStringLiteral(const StringLiteral *E); 69864f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman 699ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump /// GetAddrOfConstantStringFromLiteral - Return a pointer to a constant array 700ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump /// for the given string literal. 7016143293fa4366ee95d7e47e61bd030a34bf68b55Daniel Dunbar llvm::Constant *GetAddrOfConstantStringFromLiteral(const StringLiteral *S); 7021e04976fc2611d8cc06986a81deed4c42183b870Daniel Dunbar 703eaf2bb89eb2aad3b80673de30febe52df43c10ecChris Lattner /// GetAddrOfConstantStringFromObjCEncode - Return a pointer to a constant 704eaf2bb89eb2aad3b80673de30febe52df43c10ecChris Lattner /// array for the given ObjCEncodeExpr node. 705eaf2bb89eb2aad3b80673de30febe52df43c10ecChris Lattner llvm::Constant *GetAddrOfConstantStringFromObjCEncode(const ObjCEncodeExpr *); 7061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7076143293fa4366ee95d7e47e61bd030a34bf68b55Daniel Dunbar /// GetAddrOfConstantString - Returns a pointer to a character array 708ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump /// containing the literal. This contents are exactly that of the given 709ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump /// string, i.e. it will not be null terminated automatically; see 710ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump /// GetAddrOfConstantCString. Note that whether the result is actually a 711ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump /// pointer to an LLVM constant depends on Feature.WriteableStrings. 7126143293fa4366ee95d7e47e61bd030a34bf68b55Daniel Dunbar /// 7136143293fa4366ee95d7e47e61bd030a34bf68b55Daniel Dunbar /// The result has pointer to array type. 7145fabf9dbee29464bcd06cd09f8e569d1b850f948Daniel Dunbar /// 7155fabf9dbee29464bcd06cd09f8e569d1b850f948Daniel Dunbar /// \param GlobalName If provided, the name to use for the global 7165fabf9dbee29464bcd06cd09f8e569d1b850f948Daniel Dunbar /// (if one is created). 717686775deca8b8685eb90801495880e3abdd844c2Chris Lattner llvm::Constant *GetAddrOfConstantString(StringRef Str, 718a5e19c6b2554f6d9c4b9850d4dbbbfa3643282e5John McCall const char *GlobalName=0, 7196b20351a1d6178addfaa86716aaba36f2e9ea188Ulrich Weigand unsigned Alignment=0); 7206143293fa4366ee95d7e47e61bd030a34bf68b55Daniel Dunbar 721ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump /// GetAddrOfConstantCString - Returns a pointer to a character array 722ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump /// containing the literal and a terminating '\0' character. The result has 723ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump /// pointer to array type. 7245fabf9dbee29464bcd06cd09f8e569d1b850f948Daniel Dunbar /// 725ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump /// \param GlobalName If provided, the name to use for the global (if one is 726ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump /// created). 7275fabf9dbee29464bcd06cd09f8e569d1b850f948Daniel Dunbar llvm::Constant *GetAddrOfConstantCString(const std::string &str, 728a5e19c6b2554f6d9c4b9850d4dbbbfa3643282e5John McCall const char *GlobalName=0, 7296b20351a1d6178addfaa86716aaba36f2e9ea188Ulrich Weigand unsigned Alignment=0); 7307401cf524cdb7aad4951d8727d280f8b271af5a2Richard Smith 7317401cf524cdb7aad4951d8727d280f8b271af5a2Richard Smith /// GetAddrOfConstantCompoundLiteral - Returns a pointer to a constant global 7327401cf524cdb7aad4951d8727d280f8b271af5a2Richard Smith /// variable for the given file-scope compound literal expression. 7337401cf524cdb7aad4951d8727d280f8b271af5a2Richard Smith llvm::Constant *GetAddrOfConstantCompoundLiteral(const CompoundLiteralExpr*E); 734f85e193739c953358c865005855253af4f68a497John McCall 7350815b579b31cb3129f732bb7ea36fd6ba6949e98Douglas Gregor /// \brief Retrieve the record type that describes the state of an 7360815b579b31cb3129f732bb7ea36fd6ba6949e98Douglas Gregor /// Objective-C fast enumeration loop (for..in). 7370815b579b31cb3129f732bb7ea36fd6ba6949e98Douglas Gregor QualType getObjCFastEnumerationStateType(); 7380815b579b31cb3129f732bb7ea36fd6ba6949e98Douglas Gregor 739363c184139e26ea38223b477ad64ee67b22bb9a7Anders Carlsson /// GetAddrOfCXXConstructor - Return the address of the constructor of the 740363c184139e26ea38223b477ad64ee67b22bb9a7Anders Carlsson /// given type. 7411f6f961293da9c2b1c23da2411c1b439a9502ed0John McCall llvm::GlobalValue *GetAddrOfCXXConstructor(const CXXConstructorDecl *ctor, 7421f6f961293da9c2b1c23da2411c1b439a9502ed0John McCall CXXCtorType ctorType, 7431f6f961293da9c2b1c23da2411c1b439a9502ed0John McCall const CGFunctionInfo *fnInfo = 0); 74427ae53665f8b00fe4ba21da0fa79a4ce6e0b6cd5Anders Carlsson 74527ae53665f8b00fe4ba21da0fa79a4ce6e0b6cd5Anders Carlsson /// GetAddrOfCXXDestructor - Return the address of the constructor of the 74627ae53665f8b00fe4ba21da0fa79a4ce6e0b6cd5Anders Carlsson /// given type. 7471f6f961293da9c2b1c23da2411c1b439a9502ed0John McCall llvm::GlobalValue *GetAddrOfCXXDestructor(const CXXDestructorDecl *dtor, 7481f6f961293da9c2b1c23da2411c1b439a9502ed0John McCall CXXDtorType dtorType, 7491f6f961293da9c2b1c23da2411c1b439a9502ed0John McCall const CGFunctionInfo *fnInfo = 0); 7501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 75141071debe9b8887449c3f2ee0dd7124ed47bdda8Daniel Dunbar /// getBuiltinLibFunction - Given a builtin id for a function like 75241071debe9b8887449c3f2ee0dd7124ed47bdda8Daniel Dunbar /// "__builtin_fabsf", return a Function* for "fabsf". 75334771b594ca8cdf8cd2e40b27170efa4ed2833c5Daniel Dunbar llvm::Value *getBuiltinLibFunction(const FunctionDecl *FD, 75434771b594ca8cdf8cd2e40b27170efa4ed2833c5Daniel Dunbar unsigned BuiltinID); 7556143293fa4366ee95d7e47e61bd030a34bf68b55Daniel Dunbar 7565543169296beeb183b9c9392debc774fcf493eebDmitri Gribenko llvm::Function *getIntrinsic(unsigned IID, ArrayRef<llvm::Type*> Tys = None); 757bd012ff1fa088181646a784f385b28867372d434Daniel Dunbar 75841071debe9b8887449c3f2ee0dd7124ed47bdda8Daniel Dunbar /// EmitTopLevelDecl - Emit code for a single top level declaration. 75941071debe9b8887449c3f2ee0dd7124ed47bdda8Daniel Dunbar void EmitTopLevelDecl(Decl *D); 760bd012ff1fa088181646a784f385b28867372d434Daniel Dunbar 761025039377d7247620750205dbd61ca1ba336f7e0Rafael Espindola /// HandleCXXStaticMemberVarInstantiation - Tell the consumer that this 762025039377d7247620750205dbd61ca1ba336f7e0Rafael Espindola // variable has been instantiated. 763025039377d7247620750205dbd61ca1ba336f7e0Rafael Espindola void HandleCXXStaticMemberVarInstantiation(VarDecl *VD); 764234fe654a3dd2888be42ae5db34db96c5c2c4ba3Rafael Espindola 7650024937dbb23752f606846f4a12aafc712bcde33Richard Smith /// \brief If the declaration has internal linkage but is inside an 7660024937dbb23752f606846f4a12aafc712bcde33Richard Smith /// extern "C" linkage specification, prepare to emit an alias for it 7670024937dbb23752f606846f4a12aafc712bcde33Richard Smith /// to the expected name. 7680024937dbb23752f606846f4a12aafc712bcde33Richard Smith template<typename SomeDecl> 7690024937dbb23752f606846f4a12aafc712bcde33Richard Smith void MaybeHandleStaticInExternC(const SomeDecl *D, llvm::GlobalValue *GV); 7700024937dbb23752f606846f4a12aafc712bcde33Richard Smith 7710269871c9cba493f76237175ab60313406f3bafaDaniel Dunbar /// AddUsedGlobal - Add a global which should be forced to be 7720269871c9cba493f76237175ab60313406f3bafaDaniel Dunbar /// present in the object file; these are emitted to the llvm.used 7730269871c9cba493f76237175ab60313406f3bafaDaniel Dunbar /// metadata global. 7740269871c9cba493f76237175ab60313406f3bafaDaniel Dunbar void AddUsedGlobal(llvm::GlobalValue *GV); 7750269871c9cba493f76237175ab60313406f3bafaDaniel Dunbar 776efb0fa9e11f75af51744a6159530ef7cc8efa24aDaniel Dunbar /// AddCXXDtorEntry - Add a destructor and object to add to the C++ global 777efb0fa9e11f75af51744a6159530ef7cc8efa24aDaniel Dunbar /// destructor function. 778810112e28dc839715d17b0a786f23aaa19600ac0Chris Lattner void AddCXXDtorEntry(llvm::Constant *DtorFn, llvm::Constant *Object) { 779810112e28dc839715d17b0a786f23aaa19600ac0Chris Lattner CXXGlobalDtors.push_back(std::make_pair(DtorFn, Object)); 780810112e28dc839715d17b0a786f23aaa19600ac0Chris Lattner } 781efb0fa9e11f75af51744a6159530ef7cc8efa24aDaniel Dunbar 78274391b48b4791cded373683a3baf67314f358d50Chris Lattner /// CreateRuntimeFunction - Create a new runtime function with the specified 78374391b48b4791cded373683a3baf67314f358d50Chris Lattner /// type and name. 7842acc6e3feda5e4f7d9009bdcf8b1cd777fecfe2dChris Lattner llvm::Constant *CreateRuntimeFunction(llvm::FunctionType *Ty, 785686775deca8b8685eb90801495880e3abdd844c2Chris Lattner StringRef Name, 786c4c62fd78a4728c9e4d4df14911a2ced9bdd2031Bill Wendling llvm::AttributeSet ExtraAttrs = 787c4c62fd78a4728c9e4d4df14911a2ced9bdd2031Bill Wendling llvm::AttributeSet()); 78874391b48b4791cded373683a3baf67314f358d50Chris Lattner /// CreateRuntimeVariable - Create a new runtime global variable with the 78974391b48b4791cded373683a3baf67314f358d50Chris Lattner /// specified type and name. 7902acc6e3feda5e4f7d9009bdcf8b1cd777fecfe2dChris Lattner llvm::Constant *CreateRuntimeVariable(llvm::Type *Ty, 791686775deca8b8685eb90801495880e3abdd844c2Chris Lattner StringRef Name); 792f1968f28869f4e0675450ae39c478a37c5b9abd6Daniel Dunbar 793673431a2986f750b4d8fadb57abf3f00db27bbbdDaniel Dunbar ///@name Custom Blocks Runtime Interfaces 794673431a2986f750b4d8fadb57abf3f00db27bbbdDaniel Dunbar ///@{ 795673431a2986f750b4d8fadb57abf3f00db27bbbdDaniel Dunbar 796673431a2986f750b4d8fadb57abf3f00db27bbbdDaniel Dunbar llvm::Constant *getNSConcreteGlobalBlock(); 797673431a2986f750b4d8fadb57abf3f00db27bbbdDaniel Dunbar llvm::Constant *getNSConcreteStackBlock(); 798673431a2986f750b4d8fadb57abf3f00db27bbbdDaniel Dunbar llvm::Constant *getBlockObjectAssign(); 799673431a2986f750b4d8fadb57abf3f00db27bbbdDaniel Dunbar llvm::Constant *getBlockObjectDispose(); 800673431a2986f750b4d8fadb57abf3f00db27bbbdDaniel Dunbar 801673431a2986f750b4d8fadb57abf3f00db27bbbdDaniel Dunbar ///@} 802673431a2986f750b4d8fadb57abf3f00db27bbbdDaniel Dunbar 803495cfa46300979642acde8d93a1f21c9291dac98Nadav Rotem llvm::Constant *getLLVMLifetimeStartFn(); 804495cfa46300979642acde8d93a1f21c9291dac98Nadav Rotem llvm::Constant *getLLVMLifetimeEndFn(); 805495cfa46300979642acde8d93a1f21c9291dac98Nadav Rotem 806e80d56771736c85fd8365c394a6731923b17e91dDevang Patel // UpdateCompleteType - Make sure that this type is translated. 807e80d56771736c85fd8365c394a6731923b17e91dDevang Patel void UpdateCompletedType(const TagDecl *TD); 808d60f2fbf69df08e952377b498c036f269395024dDaniel Dunbar 8095808ce43f8d7e71f5acacc9ca320268c4f37565aJohn McCall llvm::Constant *getMemberPointerConstant(const UnaryOperator *e); 8105808ce43f8d7e71f5acacc9ca320268c4f37565aJohn McCall 8112d6a5670465cb3f1d811695a9f23e372508240d2Richard Smith /// EmitConstantInit - Try to emit the initializer for the given declaration 8122d6a5670465cb3f1d811695a9f23e372508240d2Richard Smith /// as a constant; returns 0 if the expression cannot be emitted as a 8132d6a5670465cb3f1d811695a9f23e372508240d2Richard Smith /// constant. 8142d6a5670465cb3f1d811695a9f23e372508240d2Richard Smith llvm::Constant *EmitConstantInit(const VarDecl &D, CodeGenFunction *CGF = 0); 8152d6a5670465cb3f1d811695a9f23e372508240d2Richard Smith 816d60f2fbf69df08e952377b498c036f269395024dDaniel Dunbar /// EmitConstantExpr - Try to emit the given expression as a 817d60f2fbf69df08e952377b498c036f269395024dDaniel Dunbar /// constant; returns 0 if the expression cannot be emitted as a 818d60f2fbf69df08e952377b498c036f269395024dDaniel Dunbar /// constant. 819e9352cc9818ba59e7cf88500ef048991c90f3821Anders Carlsson llvm::Constant *EmitConstantExpr(const Expr *E, QualType DestType, 820e9352cc9818ba59e7cf88500ef048991c90f3821Anders Carlsson CodeGenFunction *CGF = 0); 821d60f2fbf69df08e952377b498c036f269395024dDaniel Dunbar 822a3ca41f0c2bd1c4a752df88b283332f3b757d21eRichard Smith /// EmitConstantValue - Emit the given constant value as a constant, in the 823a3ca41f0c2bd1c4a752df88b283332f3b757d21eRichard Smith /// type's scalar representation. 8242d6a5670465cb3f1d811695a9f23e372508240d2Richard Smith llvm::Constant *EmitConstantValue(const APValue &Value, QualType DestType, 8252d6a5670465cb3f1d811695a9f23e372508240d2Richard Smith CodeGenFunction *CGF = 0); 8262d6a5670465cb3f1d811695a9f23e372508240d2Richard Smith 827a3ca41f0c2bd1c4a752df88b283332f3b757d21eRichard Smith /// EmitConstantValueForMemory - Emit the given constant value as a constant, 828a3ca41f0c2bd1c4a752df88b283332f3b757d21eRichard Smith /// in the type's memory representation. 829a3ca41f0c2bd1c4a752df88b283332f3b757d21eRichard Smith llvm::Constant *EmitConstantValueForMemory(const APValue &Value, 830a3ca41f0c2bd1c4a752df88b283332f3b757d21eRichard Smith QualType DestType, 831a3ca41f0c2bd1c4a752df88b283332f3b757d21eRichard Smith CodeGenFunction *CGF = 0); 832a3ca41f0c2bd1c4a752df88b283332f3b757d21eRichard Smith 8330f59312e7b625fa5821a63db65377d4b3b667e99Eli Friedman /// EmitNullConstant - Return the result of value-initializing the given 8340f59312e7b625fa5821a63db65377d4b3b667e99Eli Friedman /// type, i.e. a null expression of the given type. This is usually, 8350f59312e7b625fa5821a63db65377d4b3b667e99Eli Friedman /// but not always, an LLVM null constant. 8360f59312e7b625fa5821a63db65377d4b3b667e99Eli Friedman llvm::Constant *EmitNullConstant(QualType T); 8370f59312e7b625fa5821a63db65377d4b3b667e99Eli Friedman 8382ed7cb649aa709b875c519f4a980a1e2b5712370Eli Friedman /// EmitNullConstantForBase - Return a null constant appropriate for 8392ed7cb649aa709b875c519f4a980a1e2b5712370Eli Friedman /// zero-initializing a base class with the given type. This is usually, 8402ed7cb649aa709b875c519f4a980a1e2b5712370Eli Friedman /// but not always, an LLVM null constant. 8412ed7cb649aa709b875c519f4a980a1e2b5712370Eli Friedman llvm::Constant *EmitNullConstantForBase(const CXXRecordDecl *Record); 8422ed7cb649aa709b875c519f4a980a1e2b5712370Eli Friedman 84332096695c76033a6b0b1747c439f7378a11e8312John McCall /// Error - Emit a general error that something can't be done. 8440f30a12ce7b3d4d86c9ca9072f587da77c8eef34Chandler Carruth void Error(SourceLocation loc, StringRef error); 84532096695c76033a6b0b1747c439f7378a11e8312John McCall 846488e993a135ce700b982bf099c3d6b856301d642Daniel Dunbar /// ErrorUnsupported - Print out an error that codegen doesn't support the 84790df4b6661968a84bf64baee489bb2f6d948fcc1Daniel Dunbar /// specified stmt yet. 848ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump /// \param OmitOnError - If true, then this error should only be emitted if no 849ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump /// other errors have been reported. 850ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump void ErrorUnsupported(const Stmt *S, const char *Type, 85190df4b6661968a84bf64baee489bb2f6d948fcc1Daniel Dunbar bool OmitOnError=false); 852ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump 853488e993a135ce700b982bf099c3d6b856301d642Daniel Dunbar /// ErrorUnsupported - Print out an error that codegen doesn't support the 854c6fdc34ac0183bfa03d65f317c78b7bdac52897eChris Lattner /// specified decl yet. 855ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump /// \param OmitOnError - If true, then this error should only be emitted if no 856ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump /// other errors have been reported. 85790df4b6661968a84bf64baee489bb2f6d948fcc1Daniel Dunbar void ErrorUnsupported(const Decl *D, const char *Type, 85890df4b6661968a84bf64baee489bb2f6d948fcc1Daniel Dunbar bool OmitOnError=false); 8594f8d123e3e2c260de3377208106ddba87cee28b4Dan Gohman 8600e4f40e1bbc4dce16bbb9870300a435419f1b3d5Daniel Dunbar /// SetInternalFunctionAttributes - Set the attributes on the LLVM 8610e4f40e1bbc4dce16bbb9870300a435419f1b3d5Daniel Dunbar /// function for the given decl and function info. This applies 8620e4f40e1bbc4dce16bbb9870300a435419f1b3d5Daniel Dunbar /// attributes necessary for handling the ABI as well as user 8630e4f40e1bbc4dce16bbb9870300a435419f1b3d5Daniel Dunbar /// specified attributes like section. 8640e4f40e1bbc4dce16bbb9870300a435419f1b3d5Daniel Dunbar void SetInternalFunctionAttributes(const Decl *D, llvm::Function *F, 8650e4f40e1bbc4dce16bbb9870300a435419f1b3d5Daniel Dunbar const CGFunctionInfo &FI); 866f80519b919a348db004fba18530706314d1ebfb5Daniel Dunbar 8677dbd8197040313d796282d4af06eccdf8a17319cDaniel Dunbar /// SetLLVMFunctionAttributes - Set the LLVM function attributes 8687dbd8197040313d796282d4af06eccdf8a17319cDaniel Dunbar /// (sext, zext, etc). 8697dbd8197040313d796282d4af06eccdf8a17319cDaniel Dunbar void SetLLVMFunctionAttributes(const Decl *D, 8707dbd8197040313d796282d4af06eccdf8a17319cDaniel Dunbar const CGFunctionInfo &Info, 8717dbd8197040313d796282d4af06eccdf8a17319cDaniel Dunbar llvm::Function *F); 872b768807c49a1c7085def099b848631856af766faDaniel Dunbar 8737c65e990e9f0dafaf9adbc59b766dcc23eaee845Daniel Dunbar /// SetLLVMFunctionAttributesForDefinition - Set the LLVM function attributes 8747c65e990e9f0dafaf9adbc59b766dcc23eaee845Daniel Dunbar /// which only apply to a function definintion. 8757c65e990e9f0dafaf9adbc59b766dcc23eaee845Daniel Dunbar void SetLLVMFunctionAttributesForDefinition(const Decl *D, llvm::Function *F); 8767c65e990e9f0dafaf9adbc59b766dcc23eaee845Daniel Dunbar 877f3477c13eeaf11b32a41f181398fb5deffd0dd73Sylvestre Ledru /// ReturnTypeUsesSRet - Return true iff the given type uses 'sret' when used 878ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump /// as a return type. 879dacf9dda17346c628fdd8c5df53c681738db0dc5Daniel Dunbar bool ReturnTypeUsesSRet(const CGFunctionInfo &FI); 880dacf9dda17346c628fdd8c5df53c681738db0dc5Daniel Dunbar 881f3477c13eeaf11b32a41f181398fb5deffd0dd73Sylvestre Ledru /// ReturnTypeUsesFPRet - Return true iff the given type uses 'fpret' when 882eea64802558cc398571938b1f28cda1d4fa79ec3Anders Carlsson /// used as a return type. 883dacf9dda17346c628fdd8c5df53c681738db0dc5Daniel Dunbar bool ReturnTypeUsesFPRet(QualType ResultType); 884b768807c49a1c7085def099b848631856af766faDaniel Dunbar 885f3477c13eeaf11b32a41f181398fb5deffd0dd73Sylvestre Ledru /// ReturnTypeUsesFP2Ret - Return true iff the given type uses 'fp2ret' when 886eea64802558cc398571938b1f28cda1d4fa79ec3Anders Carlsson /// used as a return type. 887eea64802558cc398571938b1f28cda1d4fa79ec3Anders Carlsson bool ReturnTypeUsesFP2Ret(QualType ResultType); 888eea64802558cc398571938b1f28cda1d4fa79ec3Anders Carlsson 889ca6408c3176783f0b29da4679a08512aa05f0c73Daniel Dunbar /// ConstructAttributeList - Get the LLVM attributes and calling convention to 890ca6408c3176783f0b29da4679a08512aa05f0c73Daniel Dunbar /// use for a particular function type. 891ca6408c3176783f0b29da4679a08512aa05f0c73Daniel Dunbar /// 892ca6408c3176783f0b29da4679a08512aa05f0c73Daniel Dunbar /// \param Info - The function type information. 893ca6408c3176783f0b29da4679a08512aa05f0c73Daniel Dunbar /// \param TargetDecl - The decl these attributes are being constructed 894ca6408c3176783f0b29da4679a08512aa05f0c73Daniel Dunbar /// for. If supplied the attributes applied to this decl may contribute to the 895ca6408c3176783f0b29da4679a08512aa05f0c73Daniel Dunbar /// function attributes and calling convention. 896ca6408c3176783f0b29da4679a08512aa05f0c73Daniel Dunbar /// \param PAL [out] - On return, the attribute list to use. 897ca6408c3176783f0b29da4679a08512aa05f0c73Daniel Dunbar /// \param CallingConv [out] - On return, the LLVM calling convention to use. 89888b5396b0897f28d22ae3debf4a0d97b33b6c362Daniel Dunbar void ConstructAttributeList(const CGFunctionInfo &Info, 89988b5396b0897f28d22ae3debf4a0d97b33b6c362Daniel Dunbar const Decl *TargetDecl, 900ca6408c3176783f0b29da4679a08512aa05f0c73Daniel Dunbar AttributeListType &PAL, 90194236e7393d5cd4acbc5f0b503d23bbe78d9aeecBill Wendling unsigned &CallingConv, 90294236e7393d5cd4acbc5f0b503d23bbe78d9aeecBill Wendling bool AttrOnCallSite); 903b768807c49a1c7085def099b848631856af766faDaniel Dunbar 904686775deca8b8685eb90801495880e3abdd844c2Chris Lattner StringRef getMangledName(GlobalDecl GD); 90514110477887e3dc168ffc6c191e72d705051f99ePeter Collingbourne void getBlockMangledName(GlobalDecl GD, MangleBuffer &Buffer, 90614110477887e3dc168ffc6c191e72d705051f99ePeter Collingbourne const BlockDecl *BD); 907b6c8c8bd8d362c8a6cdb767415b0d21e62b77eb2Douglas Gregor 908b6c8c8bd8d362c8a6cdb767415b0d21e62b77eb2Douglas Gregor void EmitTentativeDefinition(const VarDecl *D); 909f121677b6bbbf4e4a51ee7a1120b77adf187bad4Mike Stump 9106fb745bdf1ff1e32caf07e42093a7920726892c1Douglas Gregor void EmitVTable(CXXRecordDecl *Class, bool DefinitionRequired); 9116fb745bdf1ff1e32caf07e42093a7920726892c1Douglas Gregor 9123190ca922d3743137e15fe0c525c04b177b9983bReid Kleckner /// \brief Appends Opts to the "Linker Options" metadata value. 9133190ca922d3743137e15fe0c525c04b177b9983bReid Kleckner void AppendLinkerOptions(StringRef Opts); 9143190ca922d3743137e15fe0c525c04b177b9983bReid Kleckner 915a7ff62f9443efa3b13a28a1e566d4625b15b8553Aaron Ballman /// \bried Appends a detect mismatch command to the linker options. 916a7ff62f9443efa3b13a28a1e566d4625b15b8553Aaron Ballman void AddDetectMismatch(StringRef Name, StringRef Value); 917a7ff62f9443efa3b13a28a1e566d4625b15b8553Aaron Ballman 9183190ca922d3743137e15fe0c525c04b177b9983bReid Kleckner /// \brief Appends a dependent lib to the "Linker Options" metadata value. 9193190ca922d3743137e15fe0c525c04b177b9983bReid Kleckner void AddDependentLib(StringRef Lib); 9203190ca922d3743137e15fe0c525c04b177b9983bReid Kleckner 921d46f98573ba104eda102dd3224b2dca69f1c6336John McCall llvm::GlobalVariable::LinkageTypes 922d46f98573ba104eda102dd3224b2dca69f1c6336John McCall getFunctionLinkage(const FunctionDecl *FD); 923d46f98573ba104eda102dd3224b2dca69f1c6336John McCall 9248b2423361648c39a7d8a3c5e8129e12006deac32John McCall void setFunctionLinkage(const FunctionDecl *FD, llvm::GlobalValue *V) { 9258b2423361648c39a7d8a3c5e8129e12006deac32John McCall V->setLinkage(getFunctionLinkage(FD)); 9268b2423361648c39a7d8a3c5e8129e12006deac32John McCall } 9278b2423361648c39a7d8a3c5e8129e12006deac32John McCall 928046c294a43024874ff35656c6e785b64e72f1f36Anders Carlsson /// getVTableLinkage - Return the appropriate linkage for the vtable, VTT, 9294b0f21c0f8bed0e2a7dc62d73be64e7e277d6c9aDouglas Gregor /// and type information of the given class. 9303a717f7fbb94ec31b826b48c15fdc965b5910df3Anders Carlsson llvm::GlobalVariable::LinkageTypes getVTableLinkage(const CXXRecordDecl *RD); 931687cc4a850b59116efee061018f0d8df50728b82Ken Dyck 932687cc4a850b59116efee061018f0d8df50728b82Ken Dyck /// GetTargetTypeStoreSize - Return the store size, in character units, of 933687cc4a850b59116efee061018f0d8df50728b82Ken Dyck /// the given LLVM type. 9342acc6e3feda5e4f7d9009bdcf8b1cd777fecfe2dChris Lattner CharUnits GetTargetTypeStoreSize(llvm::Type *Ty) const; 935354e712c81fbb07c0ce5f06180788b25fffa1b56Fariborz Jahanian 936354e712c81fbb07c0ce5f06180788b25fffa1b56Fariborz Jahanian /// GetLLVMLinkageVarDefinition - Returns LLVM linkage for a global 937354e712c81fbb07c0ce5f06180788b25fffa1b56Fariborz Jahanian /// variable. 938354e712c81fbb07c0ce5f06180788b25fffa1b56Fariborz Jahanian llvm::GlobalValue::LinkageTypes 939354e712c81fbb07c0ce5f06180788b25fffa1b56Fariborz Jahanian GetLLVMLinkageVarDefinition(const VarDecl *D, 940354e712c81fbb07c0ce5f06180788b25fffa1b56Fariborz Jahanian llvm::GlobalVariable *GV); 941354e712c81fbb07c0ce5f06180788b25fffa1b56Fariborz Jahanian 94277f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge /// Emit all the global annotations. 94377f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge void EmitGlobalAnnotations(); 94477f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge 94577f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge /// Emit an annotation string. 946cfa88f893915ceb8ae4ce2f17c46c24a4d67502fDmitri Gribenko llvm::Constant *EmitAnnotationString(StringRef Str); 94777f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge 94877f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge /// Emit the annotation's translation unit. 94977f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge llvm::Constant *EmitAnnotationUnit(SourceLocation Loc); 95077f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge 95177f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge /// Emit the annotation line number. 95277f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge llvm::Constant *EmitAnnotationLineNo(SourceLocation L); 95377f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge 95477f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge /// EmitAnnotateAttr - Generate the llvm::ConstantStruct which contains the 95577f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge /// annotation information for a given GlobalValue. The annotation struct is 95677f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge /// {i8 *, i8 *, i8 *, i32}. The first field is a constant expression, the 95777f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge /// GlobalValue being annotated. The second field is the constant string 95877f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge /// created from the AnnotateAttr's annotation. The third field is a constant 95977f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge /// string containing the name of the translation unit. The fourth field is 96077f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge /// the line number in the file of the annotated value declaration. 96177f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge llvm::Constant *EmitAnnotateAttr(llvm::GlobalValue *GV, 96277f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge const AnnotateAttr *AA, 96377f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge SourceLocation L); 96477f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge 96577f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge /// Add global annotations that are set on D, for the global GV. Those 96677f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge /// annotations are emitted during finalization of the LLVM code. 96777f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge void AddGlobalAnnotations(const ValueDecl *D, llvm::GlobalValue *GV); 96877f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge 9694f45bc099f2665bc6e4bcbb169aa452390dbf3feWill Dietz const llvm::BlackList &getSanitizerBlacklist() const { 9704f45bc099f2665bc6e4bcbb169aa452390dbf3feWill Dietz return SanitizerBlacklist; 9714f45bc099f2665bc6e4bcbb169aa452390dbf3feWill Dietz } 9724f45bc099f2665bc6e4bcbb169aa452390dbf3feWill Dietz 9734f45bc099f2665bc6e4bcbb169aa452390dbf3feWill Dietz const SanitizerOptions &getSanOpts() const { return SanOpts; } 9744f45bc099f2665bc6e4bcbb169aa452390dbf3feWill Dietz 975d5617eeafc93209a26b9f88276c88cf997c3a0a7John McCall void addDeferredVTable(const CXXRecordDecl *RD) { 976d5617eeafc93209a26b9f88276c88cf997c3a0a7John McCall DeferredVTables.push_back(RD); 977d5617eeafc93209a26b9f88276c88cf997c3a0a7John McCall } 978d5617eeafc93209a26b9f88276c88cf997c3a0a7John McCall 9799cd4fe4af6d3e8b6dcfce9c2cdefcaafca7eed7cChris Lattnerprivate: 980686775deca8b8685eb90801495880e3abdd844c2Chris Lattner llvm::GlobalValue *GetGlobalValue(StringRef Ref); 9811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 982686775deca8b8685eb90801495880e3abdd844c2Chris Lattner llvm::Constant *GetOrCreateLLVMFunction(StringRef MangledName, 9832acc6e3feda5e4f7d9009bdcf8b1cd777fecfe2dChris Lattner llvm::Type *Ty, 9841faa89f9c619e4b2411fab4af7e22ee7a2bd9009Anders Carlsson GlobalDecl D, 985f85e193739c953358c865005855253af4f68a497John McCall bool ForVTable, 986c4c62fd78a4728c9e4d4df14911a2ced9bdd2031Bill Wendling llvm::AttributeSet ExtraAttrs = 987c4c62fd78a4728c9e4d4df14911a2ced9bdd2031Bill Wendling llvm::AttributeSet()); 988686775deca8b8685eb90801495880e3abdd844c2Chris Lattner llvm::Constant *GetOrCreateLLVMGlobal(StringRef MangledName, 9892acc6e3feda5e4f7d9009bdcf8b1cd777fecfe2dChris Lattner llvm::PointerType *PTy, 990c532b502858032f377056dc8cba2fe43cba8702bRafael Espindola const VarDecl *D, 991c532b502858032f377056dc8cba2fe43cba8702bRafael Espindola bool UnnamedAddr = false); 9921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 9937c65e990e9f0dafaf9adbc59b766dcc23eaee845Daniel Dunbar /// SetCommonAttributes - Set attributes which are common to any 9947c65e990e9f0dafaf9adbc59b766dcc23eaee845Daniel Dunbar /// form of a global definition (alias, Objective-C method, 9957c65e990e9f0dafaf9adbc59b766dcc23eaee845Daniel Dunbar /// function, global variable). 9967dbd8197040313d796282d4af06eccdf8a17319cDaniel Dunbar /// 9977c65e990e9f0dafaf9adbc59b766dcc23eaee845Daniel Dunbar /// NOTE: This should only be called for definitions. 9987c65e990e9f0dafaf9adbc59b766dcc23eaee845Daniel Dunbar void SetCommonAttributes(const Decl *D, llvm::GlobalValue *GV); 999f80519b919a348db004fba18530706314d1ebfb5Daniel Dunbar 10007c65e990e9f0dafaf9adbc59b766dcc23eaee845Daniel Dunbar /// SetFunctionDefinitionAttributes - Set attributes for a global definition. 10011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void SetFunctionDefinitionAttributes(const FunctionDecl *D, 1002c6c14d1cd68afcd90d097715296377f15be45210Eli Friedman llvm::GlobalValue *GV); 10031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 10047dbd8197040313d796282d4af06eccdf8a17319cDaniel Dunbar /// SetFunctionAttributes - Set function attributes for a function 10057dbd8197040313d796282d4af06eccdf8a17319cDaniel Dunbar /// declaration. 1006b2bcf1c176b200b36f371e189ce22f93c86cdf45Anders Carlsson void SetFunctionAttributes(GlobalDecl GD, 1007c6c14d1cd68afcd90d097715296377f15be45210Eli Friedman llvm::Function *F, 1008c6c14d1cd68afcd90d097715296377f15be45210Eli Friedman bool IsIncompleteFunction); 1009d4cbda6292b321c2e7dce7f039d92918fee99b3aNuno Lopes 1010ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump /// EmitGlobal - Emit code for a singal global function or var decl. Forward 1011ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump /// declarations are emitted lazily. 1012b4880bab7fc1b61267cfd9a0ad52188e7a828cb3Chris Lattner void EmitGlobal(GlobalDecl D); 101341071debe9b8887449c3f2ee0dd7124ed47bdda8Daniel Dunbar 1014b4880bab7fc1b61267cfd9a0ad52188e7a828cb3Chris Lattner void EmitGlobalDefinition(GlobalDecl D); 1015d5d31801fc87239436fa349c89dce7797cf13537Daniel Dunbar 1016b4880bab7fc1b61267cfd9a0ad52188e7a828cb3Chris Lattner void EmitGlobalFunctionDefinition(GlobalDecl GD); 1017bd012ff1fa088181646a784f385b28867372d434Daniel Dunbar void EmitGlobalVarDefinition(const VarDecl *D); 101819b1a6eb2c90fab7cefe74bea5b6de490b65ac9dSebastian Redl llvm::Constant *MaybeEmitGlobalStdInitializerListInitializer(const VarDecl *D, 101919b1a6eb2c90fab7cefe74bea5b6de490b65ac9dSebastian Redl const Expr *init); 1020f746aa6a8f538be914173a4aef2d9a2fd9f99d17John McCall void EmitAliasDefinition(GlobalDecl GD); 1021af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar void EmitObjCPropertyImplementations(const ObjCImplementationDecl *D); 1022109dfc6ca6652f60c55ed0f2631aebf323d0200dFariborz Jahanian void EmitObjCIvarInitializations(ObjCImplementationDecl *D); 1023354e712c81fbb07c0ce5f06180788b25fffa1b56Fariborz Jahanian 102495d4e5d2f87a0f07fb143ccb824dfc4c5c595c78Anders Carlsson // C++ related functions. 10251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1026d46f98573ba104eda102dd3224b2dca69f1c6336John McCall bool TryEmitDefinitionAsAlias(GlobalDecl Alias, GlobalDecl Target); 1027c0bf462cf35fe050bddbd8bff967298e4a67e79dJohn McCall bool TryEmitBaseDestructorAsAlias(const CXXDestructorDecl *D); 1028d46f98573ba104eda102dd3224b2dca69f1c6336John McCall 1029984e06874685396ca2cb51f0008cfff7c9b3d9c6Anders Carlsson void EmitNamespace(const NamespaceDecl *D); 103091e20dd8bf1bc8980ee93839383d2bd170bce050Anders Carlsson void EmitLinkageSpec(const LinkageSpecDecl *D); 10310a050f7d56039bab7556e08b359e06d329977b6bAdrian Prantl void CompleteDIClassType(const CXXMethodDecl* D); 103295d4e5d2f87a0f07fb143ccb824dfc4c5c595c78Anders Carlsson 103395d4e5d2f87a0f07fb143ccb824dfc4c5c595c78Anders Carlsson /// EmitCXXConstructors - Emit constructors (base, complete) from a 103495d4e5d2f87a0f07fb143ccb824dfc4c5c595c78Anders Carlsson /// C++ constructor Decl. 103595d4e5d2f87a0f07fb143ccb824dfc4c5c595c78Anders Carlsson void EmitCXXConstructors(const CXXConstructorDecl *D); 10361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 103795d4e5d2f87a0f07fb143ccb824dfc4c5c595c78Anders Carlsson /// EmitCXXConstructor - Emit a single constructor with the given type from 103895d4e5d2f87a0f07fb143ccb824dfc4c5c595c78Anders Carlsson /// a C++ constructor Decl. 103995d4e5d2f87a0f07fb143ccb824dfc4c5c595c78Anders Carlsson void EmitCXXConstructor(const CXXConstructorDecl *D, CXXCtorType Type); 10401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 10411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// EmitCXXDestructors - Emit destructors (base, complete) from a 104227ae53665f8b00fe4ba21da0fa79a4ce6e0b6cd5Anders Carlsson /// C++ destructor Decl. 104327ae53665f8b00fe4ba21da0fa79a4ce6e0b6cd5Anders Carlsson void EmitCXXDestructors(const CXXDestructorDecl *D); 10441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 104527ae53665f8b00fe4ba21da0fa79a4ce6e0b6cd5Anders Carlsson /// EmitCXXDestructor - Emit a single destructor with the given type from 104627ae53665f8b00fe4ba21da0fa79a4ce6e0b6cd5Anders Carlsson /// a C++ destructor Decl. 104727ae53665f8b00fe4ba21da0fa79a4ce6e0b6cd5Anders Carlsson void EmitCXXDestructor(const CXXDestructorDecl *D, CXXDtorType Type); 10481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1049b80a16eadd0dacabfc1c32412e243ccb99dd664dRichard Smith /// \brief Emit the function that initializes C++ thread_local variables. 1050b80a16eadd0dacabfc1c32412e243ccb99dd664dRichard Smith void EmitCXXThreadLocalInitFunc(); 1051b80a16eadd0dacabfc1c32412e243ccb99dd664dRichard Smith 1052efb0fa9e11f75af51744a6159530ef7cc8efa24aDaniel Dunbar /// EmitCXXGlobalInitFunc - Emit the function that initializes C++ globals. 105389ed31d3f9eeb8ec77c284a5cf404a74bf5e7acfAnders Carlsson void EmitCXXGlobalInitFunc(); 10546c6bda3b0b1d8adaac2ba3f4da7056e9f1eef52eEli Friedman 1055efb0fa9e11f75af51744a6159530ef7cc8efa24aDaniel Dunbar /// EmitCXXGlobalDtorFunc - Emit the function that destroys C++ globals. 1056efb0fa9e11f75af51744a6159530ef7cc8efa24aDaniel Dunbar void EmitCXXGlobalDtorFunc(); 1057efb0fa9e11f75af51744a6159530ef7cc8efa24aDaniel Dunbar 10587ca4850a3e3530fa6c93b64b740446e32c97f992Richard Smith /// EmitCXXGlobalVarDeclInitFunc - Emit the function that initializes the 10597ca4850a3e3530fa6c93b64b740446e32c97f992Richard Smith /// specified global (if PerformInit is true) and registers its destructor. 10603030eb82593097502469a8b3fc26112c79c75605John McCall void EmitCXXGlobalVarDeclInitFunc(const VarDecl *D, 10617ca4850a3e3530fa6c93b64b740446e32c97f992Richard Smith llvm::GlobalVariable *Addr, 10627ca4850a3e3530fa6c93b64b740446e32c97f992Richard Smith bool PerformInit); 10636c6bda3b0b1d8adaac2ba3f4da7056e9f1eef52eEli Friedman 10646bfed7e411adc46eaf616371f85f68305c6e6257Daniel Dunbar // FIXME: Hardcoding priority here is gross. 1065b4880bab7fc1b61267cfd9a0ad52188e7a828cb3Chris Lattner void AddGlobalCtor(llvm::Function *Ctor, int Priority=65535); 1066b4880bab7fc1b61267cfd9a0ad52188e7a828cb3Chris Lattner void AddGlobalDtor(llvm::Function *Dtor, int Priority=65535); 10676bfed7e411adc46eaf616371f85f68305c6e6257Daniel Dunbar 1068ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump /// EmitCtorList - Generates a global array of functions and priorities using 1069ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump /// the given list and name. This array will have appending linkage and is 1070ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump /// suitable for use as a LLVM constructor or destructor array. 10716bfed7e411adc46eaf616371f85f68305c6e6257Daniel Dunbar void EmitCtorList(const CtorList &Fns, const char *GlobalName); 1072bd012ff1fa088181646a784f385b28867372d434Daniel Dunbar 1073d1a5c31b78997befe75d10a4731cee4ab211cc31Rafael Espindola /// EmitFundamentalRTTIDescriptor - Emit the RTTI descriptors for the 1074d1a5c31b78997befe75d10a4731cee4ab211cc31Rafael Espindola /// given type. 1075d1a5c31b78997befe75d10a4731cee4ab211cc31Rafael Espindola void EmitFundamentalRTTIDescriptor(QualType Type); 1076d1a5c31b78997befe75d10a4731cee4ab211cc31Rafael Espindola 1077d1a5c31b78997befe75d10a4731cee4ab211cc31Rafael Espindola /// EmitFundamentalRTTIDescriptors - Emit the RTTI descriptors for the 1078d1a5c31b78997befe75d10a4731cee4ab211cc31Rafael Espindola /// builtin types. 1079d1a5c31b78997befe75d10a4731cee4ab211cc31Rafael Espindola void EmitFundamentalRTTIDescriptors(); 1080d1a5c31b78997befe75d10a4731cee4ab211cc31Rafael Espindola 108142745815fa4e90bfb07e581d2e5152b2c2db08ffDaniel Dunbar /// EmitDeferred - Emit any needed decls for which code generation 108242745815fa4e90bfb07e581d2e5152b2c2db08ffDaniel Dunbar /// was deferred. 1083c4a77906c259cba58c147d8468c406a430ecdcbbDmitri Gribenko void EmitDeferred(); 10840269871c9cba493f76237175ab60313406f3bafaDaniel Dunbar 1085d5617eeafc93209a26b9f88276c88cf997c3a0a7John McCall /// EmitDeferredVTables - Emit any vtables which we deferred and 1086d5617eeafc93209a26b9f88276c88cf997c3a0a7John McCall /// still have a use for. 1087d5617eeafc93209a26b9f88276c88cf997c3a0a7John McCall void EmitDeferredVTables(); 1088d5617eeafc93209a26b9f88276c88cf997c3a0a7John McCall 108942745815fa4e90bfb07e581d2e5152b2c2db08ffDaniel Dunbar /// EmitLLVMUsed - Emit the llvm.used metadata used to force 109042745815fa4e90bfb07e581d2e5152b2c2db08ffDaniel Dunbar /// references to global which may otherwise be optimized out. 1091c4a77906c259cba58c147d8468c406a430ecdcbbDmitri Gribenko void EmitLLVMUsed(); 1092f1968f28869f4e0675450ae39c478a37c5b9abd6Daniel Dunbar 1093858afb3c22144027bcd8ba75e27262eede093a60Douglas Gregor /// \brief Emit the link options introduced by imported modules. 1094858afb3c22144027bcd8ba75e27262eede093a60Douglas Gregor void EmitModuleLinkOptions(); 1095858afb3c22144027bcd8ba75e27262eede093a60Douglas Gregor 10960024937dbb23752f606846f4a12aafc712bcde33Richard Smith /// \brief Emit aliases for internal-linkage declarations inside "C" language 10970024937dbb23752f606846f4a12aafc712bcde33Richard Smith /// linkage specifications, giving them the "expected" name where possible. 10980024937dbb23752f606846f4a12aafc712bcde33Richard Smith void EmitStaticExternCAliases(); 10990024937dbb23752f606846f4a12aafc712bcde33Richard Smith 1100744016dde06fcffd50931e94a98c850f8b12cd87John McCall void EmitDeclMetadata(); 1101744016dde06fcffd50931e94a98c850f8b12cd87John McCall 11023dc05418538c719fea48b906bfa4febe5296e126Nick Lewycky /// EmitCoverageFile - Emit the llvm.gcov metadata used to tell LLVM where 11035ea4f44e34449a78d6b38aa47c14b527839d7aacNick Lewycky /// to emit the .gcno and .gcda files in a way that persists in .bc files. 11043dc05418538c719fea48b906bfa4febe5296e126Nick Lewycky void EmitCoverageFile(); 11055ea4f44e34449a78d6b38aa47c14b527839d7aacNick Lewycky 1106c5f804636e367ef744fd24cf88f7c956a5af0434Nico Weber /// Emits the initializer for a uuidof string. 1107c5f804636e367ef744fd24cf88f7c956a5af0434Nico Weber llvm::Constant *EmitUuidofInitializer(StringRef uuidstr, QualType IIDType); 1108c5f804636e367ef744fd24cf88f7c956a5af0434Nico Weber 110942745815fa4e90bfb07e581d2e5152b2c2db08ffDaniel Dunbar /// MayDeferGeneration - Determine if the given decl can be emitted 111042745815fa4e90bfb07e581d2e5152b2c2db08ffDaniel Dunbar /// lazily; this is only relevant for definitions. The given decl 111142745815fa4e90bfb07e581d2e5152b2c2db08ffDaniel Dunbar /// must be either a function or var decl. 111273241dfeb5c498255b662984cca369fd28ec3147Daniel Dunbar bool MayDeferGeneration(const ValueDecl *D); 1113b25938303de0976b9f189363d43033e5788e3d36John McCall 1114b25938303de0976b9f189363d43033e5788e3d36John McCall /// SimplifyPersonality - Check whether we can use a "simpler", more 1115b25938303de0976b9f189363d43033e5788e3d36John McCall /// core exceptions personality function. 1116b25938303de0976b9f189363d43033e5788e3d36John McCall void SimplifyPersonality(); 11175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 11185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} // end namespace CodeGen 11195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} // end namespace clang 11205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif 1122