CodeGenModule.h revision 3dc05418538c719fea48b906bfa4febe5296e126
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 1714110477887e3dc168ffc6c191e72d705051f99ePeter Collingbourne#include "clang/Basic/ABI.h" 1804d4078425614bf9fd58d606335c1f5f74ee7fa4Daniel Dunbar#include "clang/Basic/LangOptions.h" 194f8d123e3e2c260de3377208106ddba87cee28b4Dan Gohman#include "clang/AST/Attr.h" 202a131fbca2a51085dc083b8c56a2d4ced3cf1413Anders Carlsson#include "clang/AST/DeclCXX.h" 210ff8bafde95f6fa51ccea70738c1b99db870bddcAnders Carlsson#include "clang/AST/DeclObjC.h" 2214110477887e3dc168ffc6c191e72d705051f99ePeter Collingbourne#include "clang/AST/Mangle.h" 23461e326e74fa840945330a04df33b1180b08ddc0Anders Carlsson#include "CGVTables.h" 24bd3606426d389370616126af969904ec493cb105Chris Lattner#include "CodeGenTypes.h" 25764d0c23724b3671dcbe20af152fa1ad45f45e15Anders Carlsson#include "GlobalDecl.h" 2669243825cb5c91ec7207256aa57ae327cfaf8cb2Owen Anderson#include "llvm/Module.h" 275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "llvm/ADT/DenseMap.h" 28c9e2091efcb535110474434dd12015afdc3b1637Anders Carlsson#include "llvm/ADT/StringMap.h" 296ec3668a2608b63473207319f5ceff9bbd22ea51Douglas Gregor#include "llvm/ADT/StringSet.h" 306a836706c40a31c716952b74785102c90fd6afa7Rafael Espindola#include "llvm/ADT/SmallPtrSet.h" 3135f38a2c22d68c22e2dbe8e9ee84c120c8f327bbChris Lattner#include "llvm/Support/ValueHandle.h" 32b723f7520bcce5f13ccaae557c16a1e7133b6908Anders Carlsson 335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace llvm { 345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class Module; 355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class Constant; 365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class Function; 378bd4afeb876fd0015bb808eb2f3de1fe709658a7Nate Begeman class GlobalValue; 387a4718e813e5e99d478567a482217c7eef8572c5Devang Patel class TargetData; 39ff4a2d9e2c1ddbf87e00e2a36ae341faf03eafb3Eli Friedman class FunctionType; 40f21efe9088a0b3eda1209d1706529f6cb2073092Benjamin Kramer class LLVMContext; 415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang { 4482d0a418c8699fc6f4a9417457ffe93d43bba1c1Anton Korobeynikov class TargetCodeGenInfo; 455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class ASTContext; 465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class FunctionDecl; 4790db88249ac92e6ed515065048a4ead4467e6639Daniel Dunbar class IdentifierInfo; 48391d77a26382dddf25da73e29fc1fa5aaaea4c6fChris Lattner class ObjCMethodDecl; 4920ff3108fcd2c3bd734dc79efc22ebaa090abd41Anton Korobeynikov class ObjCImplementationDecl; 5020ff3108fcd2c3bd734dc79efc22ebaa090abd41Anton Korobeynikov class ObjCCategoryImplDecl; 5120ff3108fcd2c3bd734dc79efc22ebaa090abd41Anton Korobeynikov class ObjCProtocolDecl; 52eaf2bb89eb2aad3b80673de30febe52df43c10ecChris Lattner class ObjCEncodeExpr; 53d5cab5435371b8cc74a9e05ebd40b5995ebad149Anders Carlsson class BlockExpr; 54687cc4a850b59116efee061018f0d8df50728b82Ken Dyck class CharUnits; 555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class Decl; 562824723d6d181d2dfa56e62caabd68b0b18f0b9dOliver Hunt class Expr; 572c8569d5f43f7de1fb993e84c95ea571dd9ac55eChris Lattner class Stmt; 581e04976fc2611d8cc06986a81deed4c42183b870Daniel Dunbar class StringLiteral; 591a1d92ac5e1354634af08c62a1d72e263d13be0cNate Begeman class NamedDecl; 60bd012ff1fa088181646a784f385b28867372d434Daniel Dunbar class ValueDecl; 612b9d2ca4ce53fffbe8a77c7db2fe4df5ccfb9fd4Chris Lattner class VarDecl; 6243af76e845c95be160c088ec11ba3c43e2527fa8Sebastian Redl class LangOptions; 632811ccf48d6d898c42cc4cfad37abedb36236d20Chandler Carruth class CodeGenOptions; 64fb97b03e42d397405f617be0252be83e77a66f6eChris Lattner class Diagnostic; 658bd4afeb876fd0015bb808eb2f3de1fe709658a7Nate Begeman class AnnotateAttr; 6627ae53665f8b00fe4ba21da0fa79a4ce6e0b6cd5Anders Carlsson class CXXDestructorDecl; 6714110477887e3dc168ffc6c191e72d705051f99ePeter Collingbourne class MangleBuffer; 68ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump 695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace CodeGen { 705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 71d26bc76c98006609002d9930f8840490e88ac5b5John McCall class CallArgList; 72813733577d33ec56479667b49e1bff42dc6bba90Lauro Ramos Venancio class CodeGenFunction; 733d5aff5d3036b0ff09d114857cd2276134b3d8c9Dan Gohman class CodeGenTBAA; 744c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall class CGCXXABI; 75e8b9f5b8ea60983c4a74cb8b63879616b914b65aSanjiv Gupta class CGDebugInfo; 76af2f62ce32e462f256855cd24b06dec4755d2827Daniel Dunbar class CGObjCRuntime; 77d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall class BlockFieldFlags; 78d26bc76c98006609002d9930f8840490e88ac5b5John McCall class FunctionArgList; 794a6835e650ff24e19ce08a3bd347c0ad186777fdAnders Carlsson 80ec2830d930e306124c2ba6bf1060a3c71dced6eaChris Lattner struct OrderGlobalInits { 81e0b691a25f801d8be552c9387863637b9526e639Fariborz Jahanian unsigned int priority; 82e0b691a25f801d8be552c9387863637b9526e639Fariborz Jahanian unsigned int lex_order; 83e0b691a25f801d8be552c9387863637b9526e639Fariborz Jahanian OrderGlobalInits(unsigned int p, unsigned int l) 84ec2830d930e306124c2ba6bf1060a3c71dced6eaChris Lattner : priority(p), lex_order(l) {} 85ec2830d930e306124c2ba6bf1060a3c71dced6eaChris Lattner 86ec2830d930e306124c2ba6bf1060a3c71dced6eaChris Lattner bool operator==(const OrderGlobalInits &RHS) const { 87ec2830d930e306124c2ba6bf1060a3c71dced6eaChris Lattner return priority == RHS.priority && 88ec2830d930e306124c2ba6bf1060a3c71dced6eaChris Lattner lex_order == RHS.lex_order; 89f489688114275c821b1e647e26f71eeb94d8ab24Fariborz Jahanian } 90f489688114275c821b1e647e26f71eeb94d8ab24Fariborz Jahanian 91ec2830d930e306124c2ba6bf1060a3c71dced6eaChris Lattner bool operator<(const OrderGlobalInits &RHS) const { 92ec2830d930e306124c2ba6bf1060a3c71dced6eaChris Lattner if (priority < RHS.priority) 93f489688114275c821b1e647e26f71eeb94d8ab24Fariborz Jahanian return true; 94f489688114275c821b1e647e26f71eeb94d8ab24Fariborz Jahanian 95ec2830d930e306124c2ba6bf1060a3c71dced6eaChris Lattner return priority == RHS.priority && lex_order < RHS.lex_order; 96f489688114275c821b1e647e26f71eeb94d8ab24Fariborz Jahanian } 97ec2830d930e306124c2ba6bf1060a3c71dced6eaChris Lattner }; 985936e33bf74dd6bf126ceee0f6169a2593d03a69John McCall 995936e33bf74dd6bf126ceee0f6169a2593d03a69John McCall struct CodeGenTypeCache { 1005936e33bf74dd6bf126ceee0f6169a2593d03a69John McCall /// i8, i32, and i64 1015936e33bf74dd6bf126ceee0f6169a2593d03a69John McCall const llvm::IntegerType *Int8Ty, *Int32Ty, *Int64Ty; 1025936e33bf74dd6bf126ceee0f6169a2593d03a69John McCall 1035936e33bf74dd6bf126ceee0f6169a2593d03a69John McCall /// int 1045936e33bf74dd6bf126ceee0f6169a2593d03a69John McCall const llvm::IntegerType *IntTy; 1055936e33bf74dd6bf126ceee0f6169a2593d03a69John McCall 1065936e33bf74dd6bf126ceee0f6169a2593d03a69John McCall /// intptr_t and size_t, which we assume are the same 1075936e33bf74dd6bf126ceee0f6169a2593d03a69John McCall union { 1085936e33bf74dd6bf126ceee0f6169a2593d03a69John McCall const llvm::IntegerType *IntPtrTy; 1095936e33bf74dd6bf126ceee0f6169a2593d03a69John McCall const llvm::IntegerType *SizeTy; 1105936e33bf74dd6bf126ceee0f6169a2593d03a69John McCall }; 1115936e33bf74dd6bf126ceee0f6169a2593d03a69John McCall 1125936e33bf74dd6bf126ceee0f6169a2593d03a69John McCall /// void* in address space 0 1135936e33bf74dd6bf126ceee0f6169a2593d03a69John McCall union { 1145936e33bf74dd6bf126ceee0f6169a2593d03a69John McCall const llvm::PointerType *VoidPtrTy; 1155936e33bf74dd6bf126ceee0f6169a2593d03a69John McCall const llvm::PointerType *Int8PtrTy; 1165936e33bf74dd6bf126ceee0f6169a2593d03a69John McCall }; 1175936e33bf74dd6bf126ceee0f6169a2593d03a69John McCall 1185936e33bf74dd6bf126ceee0f6169a2593d03a69John McCall /// void** in address space 0 1195936e33bf74dd6bf126ceee0f6169a2593d03a69John McCall union { 1205936e33bf74dd6bf126ceee0f6169a2593d03a69John McCall const llvm::PointerType *VoidPtrPtrTy; 1215936e33bf74dd6bf126ceee0f6169a2593d03a69John McCall const llvm::PointerType *Int8PtrPtrTy; 1225936e33bf74dd6bf126ceee0f6169a2593d03a69John McCall }; 1235936e33bf74dd6bf126ceee0f6169a2593d03a69John McCall 12434695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall /// The width of a pointer into the generic address space. 1255936e33bf74dd6bf126ceee0f6169a2593d03a69John McCall unsigned char PointerWidthInBits; 12634695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall 12734695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall /// The alignment of a pointer into the generic address space. 12834695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall unsigned char PointerAlignInBytes; 1295936e33bf74dd6bf126ceee0f6169a2593d03a69John McCall }; 130e0b691a25f801d8be552c9387863637b9526e639Fariborz Jahanian 131ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump/// CodeGenModule - This class organizes the cross-function state that is used 132ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump/// while generating LLVM code. 1335936e33bf74dd6bf126ceee0f6169a2593d03a69John McCallclass CodeGenModule : public CodeGenTypeCache { 1348a219ceda2b5afd447e7199b9c53079bead31b89Anders Carlsson CodeGenModule(const CodeGenModule&); // DO NOT IMPLEMENT 1358a219ceda2b5afd447e7199b9c53079bead31b89Anders Carlsson void operator=(const CodeGenModule&); // DO NOT IMPLEMENT 1368a219ceda2b5afd447e7199b9c53079bead31b89Anders Carlsson 137ca0017a394e0a93a2412c3fe5c47a63b4b2b2ab0Chris Lattner typedef std::vector<std::pair<llvm::Constant*, int> > CtorList; 1386bfed7e411adc46eaf616371f85f68305c6e6257Daniel Dunbar 1395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ASTContext &Context; 14045e8cbdce25c2e16c7aac2036a591f6190097ae6Chris Lattner const LangOptions &Features; 1412811ccf48d6d898c42cc4cfad37abedb36236d20Chandler Carruth const CodeGenOptions &CodeGenOpts; 1425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer llvm::Module &TheModule; 1437a4718e813e5e99d478567a482217c7eef8572c5Devang Patel const llvm::TargetData &TheTargetData; 14482d0a418c8699fc6f4a9417457ffe93d43bba1c1Anton Korobeynikov mutable const TargetCodeGenInfo *TheTargetCodeGenInfo; 145fb97b03e42d397405f617be0252be83e77a66f6eChris Lattner Diagnostic &Diags; 146f16aa103d3afd42fbca2ab346f191bf745cec092John McCall CGCXXABI &ABI; 1475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer CodeGenTypes Types; 1483d5aff5d3036b0ff09d114857cd2276134b3d8c9Dan Gohman CodeGenTBAA *TBAA; 149b540491851910c2efa68196a8bdc2eed1071c17dAnders Carlsson 150af4403545a50a60d208e6fcae057308d576a92e0Anders Carlsson /// VTables - Holds information about C++ vtables. 151af4403545a50a60d208e6fcae057308d576a92e0Anders Carlsson CodeGenVTables VTables; 152e17ad2fd5c4b66c712bdffd2789eaafc54a9b001Douglas Gregor friend class CodeGenVTables; 153e17ad2fd5c4b66c712bdffd2789eaafc54a9b001Douglas Gregor 154815c78fd9ab8bd5dfe8e8a91b8c6a413e2b8c889Ted Kremenek CGObjCRuntime* Runtime; 155815c78fd9ab8bd5dfe8e8a91b8c6a413e2b8c889Ted Kremenek CGDebugInfo* DebugInfo; 1569986eabd4423d867262c358ca62f94a60ac58412Daniel Dunbar 1576a836706c40a31c716952b74785102c90fd6afa7Rafael Espindola // WeakRefReferences - A set of references that have only been seen via 1586a836706c40a31c716952b74785102c90fd6afa7Rafael Espindola // a weakref so far. This is used to remove the weak of the reference if we ever 1596a836706c40a31c716952b74785102c90fd6afa7Rafael Espindola // see a direct reference or a definition. 1606a836706c40a31c716952b74785102c90fd6afa7Rafael Espindola llvm::SmallPtrSet<llvm::GlobalValue*, 10> WeakRefReferences; 1616a836706c40a31c716952b74785102c90fd6afa7Rafael Espindola 16267b00520c8f5b48fad722b790d87fea6be764efeChris Lattner /// DeferredDecls - This contains all the decls which have definitions but 16367b00520c8f5b48fad722b790d87fea6be764efeChris Lattner /// which are deferred for emission and therefore should only be output if 16467b00520c8f5b48fad722b790d87fea6be764efeChris Lattner /// they are actually used. If a decl is in this, then it is known to have 165f746aa6a8f538be914173a4aef2d9a2fd9f99d17John McCall /// not been referenced yet. 166f746aa6a8f538be914173a4aef2d9a2fd9f99d17John McCall llvm::StringMap<GlobalDecl> DeferredDecls; 16767b00520c8f5b48fad722b790d87fea6be764efeChris Lattner 16867b00520c8f5b48fad722b790d87fea6be764efeChris Lattner /// DeferredDeclsToEmit - This is a list of deferred decls which we have seen 16967b00520c8f5b48fad722b790d87fea6be764efeChris Lattner /// that *are* actually referenced. These get code generated when the module 17067b00520c8f5b48fad722b790d87fea6be764efeChris Lattner /// is done. 1712a131fbca2a51085dc083b8c56a2d4ced3cf1413Anders Carlsson std::vector<GlobalDecl> DeferredDeclsToEmit; 17203f5ad9a7707e098f601921fcec17ed65eb355a7Daniel Dunbar 1730269871c9cba493f76237175ab60313406f3bafaDaniel Dunbar /// LLVMUsed - List of global values which are required to be 1740269871c9cba493f76237175ab60313406f3bafaDaniel Dunbar /// present in the object file; bitcast to i8*. This is used for 1750269871c9cba493f76237175ab60313406f3bafaDaniel Dunbar /// forcing visibility of symbols which may otherwise be optimized 1760269871c9cba493f76237175ab60313406f3bafaDaniel Dunbar /// out. 17735f38a2c22d68c22e2dbe8e9ee84c120c8f327bbChris Lattner std::vector<llvm::WeakVH> LLVMUsed; 178ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump 179ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump /// GlobalCtors - Store the list of global constructors and their respective 180ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump /// priorities to be emitted when the translation unit is complete. 1816bfed7e411adc46eaf616371f85f68305c6e6257Daniel Dunbar CtorList GlobalCtors; 1826bfed7e411adc46eaf616371f85f68305c6e6257Daniel Dunbar 183ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump /// GlobalDtors - Store the list of global destructors and their respective 184ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump /// priorities to be emitted when the translation unit is complete. 1856bfed7e411adc46eaf616371f85f68305c6e6257Daniel Dunbar CtorList GlobalDtors; 1866bfed7e411adc46eaf616371f85f68305c6e6257Daniel Dunbar 187793a990774826a0c20b0da66cec0991badfb8b63Anders Carlsson /// MangledDeclNames - A map of canonical GlobalDecls to their mangled names. 188793a990774826a0c20b0da66cec0991badfb8b63Anders Carlsson llvm::DenseMap<GlobalDecl, llvm::StringRef> MangledDeclNames; 189793a990774826a0c20b0da66cec0991badfb8b63Anders Carlsson llvm::BumpPtrAllocator MangledNamesAllocator; 190793a990774826a0c20b0da66cec0991badfb8b63Anders Carlsson 191532485cc6c078d9e51b517c6bbd8984deb17f0feNate Begeman std::vector<llvm::Constant*> Annotations; 192ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump 193c9e2091efcb535110474434dd12015afdc3b1637Anders Carlsson llvm::StringMap<llvm::Constant*> CFConstantStringMap; 19445e8cbdce25c2e16c7aac2036a591f6190097ae6Chris Lattner llvm::StringMap<llvm::Constant*> ConstantStringMap; 19565ad5a42cca954e070428dcc499b62393aa7a6d3Fariborz Jahanian llvm::DenseMap<const Decl*, llvm::Value*> StaticLocalDeclMap; 1963e9df9920db8de8ec93a424b0c1784f9bff301eaDaniel Dunbar 197efb0fa9e11f75af51744a6159530ef7cc8efa24aDaniel Dunbar /// CXXGlobalInits - Global variables with initializers that need to run 19889ed31d3f9eeb8ec77c284a5cf404a74bf5e7acfAnders Carlsson /// before main. 1996c6bda3b0b1d8adaac2ba3f4da7056e9f1eef52eEli Friedman std::vector<llvm::Constant*> CXXGlobalInits; 200bf40cb518312dde1c07e44fcae59bc4eec65589cJohn McCall 201bf40cb518312dde1c07e44fcae59bc4eec65589cJohn McCall /// When a C++ decl with an initializer is deferred, null is 202bf40cb518312dde1c07e44fcae59bc4eec65589cJohn McCall /// appended to CXXGlobalInits, and the index of that null is placed 203bf40cb518312dde1c07e44fcae59bc4eec65589cJohn McCall /// here so that the initializer will be performed in the correct 204bf40cb518312dde1c07e44fcae59bc4eec65589cJohn McCall /// order. 205bf40cb518312dde1c07e44fcae59bc4eec65589cJohn McCall llvm::DenseMap<const Decl*, unsigned> DelayedCXXInitPosition; 2069f967c5e4bbeb48caf6d0e62056b3d3fee20bf7cFariborz Jahanian 2079f967c5e4bbeb48caf6d0e62056b3d3fee20bf7cFariborz Jahanian /// - Global variables with initializers whose order of initialization 2089f967c5e4bbeb48caf6d0e62056b3d3fee20bf7cFariborz Jahanian /// is set by init_priority attribute. 209e0b691a25f801d8be552c9387863637b9526e639Fariborz Jahanian 210ec2830d930e306124c2ba6bf1060a3c71dced6eaChris Lattner llvm::SmallVector<std::pair<OrderGlobalInits, llvm::Function*>, 8> 2119f967c5e4bbeb48caf6d0e62056b3d3fee20bf7cFariborz Jahanian PrioritizedCXXGlobalInits; 2121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 213efb0fa9e11f75af51744a6159530ef7cc8efa24aDaniel Dunbar /// CXXGlobalDtors - Global destructor functions and arguments that need to 214efb0fa9e11f75af51744a6159530ef7cc8efa24aDaniel Dunbar /// run on termination. 215810112e28dc839715d17b0a786f23aaa19600ac0Chris Lattner std::vector<std::pair<llvm::WeakVH,llvm::Constant*> > CXXGlobalDtors; 216efb0fa9e11f75af51744a6159530ef7cc8efa24aDaniel Dunbar 217ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump /// CFConstantStringClassRef - Cached reference to the class for constant 218ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump /// strings. This value has type int * but is actually an Obj-C class pointer. 219c9e2091efcb535110474434dd12015afdc3b1637Anders Carlsson llvm::Constant *CFConstantStringClassRef; 2201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2214c73307c74764ba99e1379677fe92af72f676531Fariborz Jahanian /// ConstantStringClassRef - Cached reference to the class for constant 2222bb5ddaff86ee73d2cea7ec1835978afc88a83f0Fariborz Jahanian /// strings. This value has type int * but is actually an Obj-C class pointer. 2234c73307c74764ba99e1379677fe92af72f676531Fariborz Jahanian llvm::Constant *ConstantStringClassRef; 2242bb5ddaff86ee73d2cea7ec1835978afc88a83f0Fariborz Jahanian 2250d13f6fdbdd6f06e2449b8834dda53334abd399aDavid Chisnall /// Lazily create the Objective-C runtime 2260d13f6fdbdd6f06e2449b8834dda53334abd399aDavid Chisnall void createObjCRuntime(); 2270d13f6fdbdd6f06e2449b8834dda53334abd399aDavid Chisnall 228a1cf15f4680e5cf39e72e28c5ea854fcba792e84Owen Anderson llvm::LLVMContext &VMContext; 229673431a2986f750b4d8fadb57abf3f00db27bbbdDaniel Dunbar 230673431a2986f750b4d8fadb57abf3f00db27bbbdDaniel Dunbar /// @name Cache for Blocks Runtime Globals 231673431a2986f750b4d8fadb57abf3f00db27bbbdDaniel Dunbar /// @{ 232673431a2986f750b4d8fadb57abf3f00db27bbbdDaniel Dunbar 233754b9fbaa13749c61393cc613eec7c79efe60ddfDaniel Dunbar const VarDecl *NSConcreteGlobalBlockDecl; 234754b9fbaa13749c61393cc613eec7c79efe60ddfDaniel Dunbar const VarDecl *NSConcreteStackBlockDecl; 235673431a2986f750b4d8fadb57abf3f00db27bbbdDaniel Dunbar llvm::Constant *NSConcreteGlobalBlock; 236673431a2986f750b4d8fadb57abf3f00db27bbbdDaniel Dunbar llvm::Constant *NSConcreteStackBlock; 237754b9fbaa13749c61393cc613eec7c79efe60ddfDaniel Dunbar 238754b9fbaa13749c61393cc613eec7c79efe60ddfDaniel Dunbar const FunctionDecl *BlockObjectAssignDecl; 239754b9fbaa13749c61393cc613eec7c79efe60ddfDaniel Dunbar const FunctionDecl *BlockObjectDisposeDecl; 240673431a2986f750b4d8fadb57abf3f00db27bbbdDaniel Dunbar llvm::Constant *BlockObjectAssign; 241673431a2986f750b4d8fadb57abf3f00db27bbbdDaniel Dunbar llvm::Constant *BlockObjectDispose; 242673431a2986f750b4d8fadb57abf3f00db27bbbdDaniel Dunbar 243d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall const llvm::Type *BlockDescriptorType; 244d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall const llvm::Type *GenericBlockLiteralType; 245d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall 246d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall struct { 247d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall int GlobalUniqueCount; 248d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall } Block; 249d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall 250673431a2986f750b4d8fadb57abf3f00db27bbbdDaniel Dunbar /// @} 2515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 2522811ccf48d6d898c42cc4cfad37abedb36236d20Chandler Carruth CodeGenModule(ASTContext &C, const CodeGenOptions &CodeGenOpts, 253468ec6c0266e48fccb26ce50d5b915c645bb3c7bJohn McCall llvm::Module &M, const llvm::TargetData &TD, Diagnostic &Diags); 254815c78fd9ab8bd5dfe8e8a91b8c6a413e2b8c889Ted Kremenek 2552b94fe35edf951a14ecd32b21f7ebcc2e3754c67Chris Lattner ~CodeGenModule(); 256ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump 257815c78fd9ab8bd5dfe8e8a91b8c6a413e2b8c889Ted Kremenek /// Release - Finalize LLVM code generation. 258815c78fd9ab8bd5dfe8e8a91b8c6a413e2b8c889Ted Kremenek void Release(); 259208ff5e8a073de2a5d15cbe03cab8a4c0d935e28Daniel Dunbar 260208ff5e8a073de2a5d15cbe03cab8a4c0d935e28Daniel Dunbar /// getObjCRuntime() - Return a reference to the configured 261208ff5e8a073de2a5d15cbe03cab8a4c0d935e28Daniel Dunbar /// Objective-C runtime. 262ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump CGObjCRuntime &getObjCRuntime() { 2630d13f6fdbdd6f06e2449b8834dda53334abd399aDavid Chisnall if (!Runtime) createObjCRuntime(); 264ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump return *Runtime; 265208ff5e8a073de2a5d15cbe03cab8a4c0d935e28Daniel Dunbar } 266ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump 267208ff5e8a073de2a5d15cbe03cab8a4c0d935e28Daniel Dunbar /// hasObjCRuntime() - Return true iff an Objective-C runtime has 268208ff5e8a073de2a5d15cbe03cab8a4c0d935e28Daniel Dunbar /// been configured. 269208ff5e8a073de2a5d15cbe03cab8a4c0d935e28Daniel Dunbar bool hasObjCRuntime() { return !!Runtime; } 270208ff5e8a073de2a5d15cbe03cab8a4c0d935e28Daniel Dunbar 271f16aa103d3afd42fbca2ab346f191bf745cec092John McCall /// getCXXABI() - Return a reference to the configured C++ ABI. 272f16aa103d3afd42fbca2ab346f191bf745cec092John McCall CGCXXABI &getCXXABI() { return ABI; } 2733a811f1f4286ee3fd0c563c1cfe623956f3caa24Charles Davis 27463326a53418b4853a83b360ce1dbdb10c5739fc7Fariborz Jahanian llvm::Value *getStaticLocalDeclAddress(const VarDecl *VD) { 27565ad5a42cca954e070428dcc499b62393aa7a6d3Fariborz Jahanian return StaticLocalDeclMap[VD]; 27665ad5a42cca954e070428dcc499b62393aa7a6d3Fariborz Jahanian } 27763326a53418b4853a83b360ce1dbdb10c5739fc7Fariborz Jahanian void setStaticLocalDeclAddress(const VarDecl *D, 27865ad5a42cca954e070428dcc499b62393aa7a6d3Fariborz Jahanian llvm::GlobalVariable *GV) { 27965ad5a42cca954e070428dcc499b62393aa7a6d3Fariborz Jahanian StaticLocalDeclMap[D] = GV; 28065ad5a42cca954e070428dcc499b62393aa7a6d3Fariborz Jahanian } 28165ad5a42cca954e070428dcc499b62393aa7a6d3Fariborz Jahanian 282aa11289f754d220c9c155b68a4f84cdcfcefef6aDevang Patel CGDebugInfo *getModuleDebugInfo() { return DebugInfo; } 2835de7a0e8800b89780e565c1013e566414f11546aDevang Patel 2845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ASTContext &getContext() const { return Context; } 2852811ccf48d6d898c42cc4cfad37abedb36236d20Chandler Carruth const CodeGenOptions &getCodeGenOpts() const { return CodeGenOpts; } 28645e8cbdce25c2e16c7aac2036a591f6190097ae6Chris Lattner const LangOptions &getLangOptions() const { return Features; } 2875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer llvm::Module &getModule() const { return TheModule; } 2885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer CodeGenTypes &getTypes() { return Types; } 289af4403545a50a60d208e6fcae057308d576a92e0Anders Carlsson CodeGenVTables &getVTables() { return VTables; } 290fb97b03e42d397405f617be0252be83e77a66f6eChris Lattner Diagnostic &getDiags() const { return Diags; } 2918f925280abe3795ae0fb47f2ba90faea62e26af4Chris Lattner const llvm::TargetData &getTargetData() const { return TheTargetData; } 292d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall const TargetInfo &getTarget() const { return Context.Target; } 293a1cf15f4680e5cf39e72e28c5ea854fcba792e84Owen Anderson llvm::LLVMContext &getLLVMContext() { return VMContext; } 294ea0443212e7ec6ff82e2f174e8e948a6eb0e0876Chris Lattner const TargetCodeGenInfo &getTargetCodeGenInfo(); 2956374c3307e2d73348f7b8cc73eeeb0998ad0ac94John McCall bool isTargetDarwin() const; 296bd012ff1fa088181646a784f385b28867372d434Daniel Dunbar 297bc7fbf0d37b286b37d96b033dfaaabf9c729bca8John McCall bool shouldUseTBAA() const { return TBAA != 0; } 298bc7fbf0d37b286b37d96b033dfaaabf9c729bca8John McCall 2993d5aff5d3036b0ff09d114857cd2276134b3d8c9Dan Gohman llvm::MDNode *getTBAAInfo(QualType QTy); 3003d5aff5d3036b0ff09d114857cd2276134b3d8c9Dan Gohman 3013d5aff5d3036b0ff09d114857cd2276134b3d8c9Dan Gohman static void DecorateInstruction(llvm::Instruction *Inst, 3023d5aff5d3036b0ff09d114857cd2276134b3d8c9Dan Gohman llvm::MDNode *TBAAInfo); 3033d5aff5d3036b0ff09d114857cd2276134b3d8c9Dan Gohman 30404d4078425614bf9fd58d606335c1f5f74ee7fa4Daniel Dunbar /// setGlobalVisibility - Set the visibility for the given LLVM 30504d4078425614bf9fd58d606335c1f5f74ee7fa4Daniel Dunbar /// GlobalValue. 3060ffeaad72cb335b926b064379be4c9886bbff004Anders Carlsson void setGlobalVisibility(llvm::GlobalValue *GV, const NamedDecl *D) const; 30704d4078425614bf9fd58d606335c1f5f74ee7fa4Daniel Dunbar 308fa2e99f72f9bfe2270ea8caf76d0eef11c45259fAnders Carlsson /// TypeVisibilityKind - The kind of global variable that is passed to 309fa2e99f72f9bfe2270ea8caf76d0eef11c45259fAnders Carlsson /// setTypeVisibility 310fa2e99f72f9bfe2270ea8caf76d0eef11c45259fAnders Carlsson enum TypeVisibilityKind { 311fa2e99f72f9bfe2270ea8caf76d0eef11c45259fAnders Carlsson TVK_ForVTT, 312fa2e99f72f9bfe2270ea8caf76d0eef11c45259fAnders Carlsson TVK_ForVTable, 313bda0d6bda0f1a08a9fdf3ee4cf550b6b10d454ecJohn McCall TVK_ForConstructionVTable, 314fa2e99f72f9bfe2270ea8caf76d0eef11c45259fAnders Carlsson TVK_ForRTTI, 315fa2e99f72f9bfe2270ea8caf76d0eef11c45259fAnders Carlsson TVK_ForRTTIName 316fa2e99f72f9bfe2270ea8caf76d0eef11c45259fAnders Carlsson }; 317fa2e99f72f9bfe2270ea8caf76d0eef11c45259fAnders Carlsson 318cbfe50224b19119e759802bd0c1463269dffd09eJohn McCall /// setTypeVisibility - Set the visibility for the given global 319cbfe50224b19119e759802bd0c1463269dffd09eJohn McCall /// value which holds information about a type. 320cbfe50224b19119e759802bd0c1463269dffd09eJohn McCall void setTypeVisibility(llvm::GlobalValue *GV, const CXXRecordDecl *D, 321fa2e99f72f9bfe2270ea8caf76d0eef11c45259fAnders Carlsson TypeVisibilityKind TVK) const; 322cbfe50224b19119e759802bd0c1463269dffd09eJohn McCall 323c7e98fabd852e9dfa7409b7fc664b87322522c43Anders Carlsson static llvm::GlobalValue::VisibilityTypes GetLLVMVisibility(Visibility V) { 324c7e98fabd852e9dfa7409b7fc664b87322522c43Anders Carlsson switch (V) { 325c7e98fabd852e9dfa7409b7fc664b87322522c43Anders Carlsson case DefaultVisibility: return llvm::GlobalValue::DefaultVisibility; 326c7e98fabd852e9dfa7409b7fc664b87322522c43Anders Carlsson case HiddenVisibility: return llvm::GlobalValue::HiddenVisibility; 327c7e98fabd852e9dfa7409b7fc664b87322522c43Anders Carlsson case ProtectedVisibility: return llvm::GlobalValue::ProtectedVisibility; 328c7e98fabd852e9dfa7409b7fc664b87322522c43Anders Carlsson } 329c7e98fabd852e9dfa7409b7fc664b87322522c43Anders Carlsson llvm_unreachable("unknown visibility!"); 330c7e98fabd852e9dfa7409b7fc664b87322522c43Anders Carlsson return llvm::GlobalValue::DefaultVisibility; 331c7e98fabd852e9dfa7409b7fc664b87322522c43Anders Carlsson } 332c7e98fabd852e9dfa7409b7fc664b87322522c43Anders Carlsson 333d46f98573ba104eda102dd3224b2dca69f1c6336John McCall llvm::Constant *GetAddrOfGlobal(GlobalDecl GD) { 334d46f98573ba104eda102dd3224b2dca69f1c6336John McCall if (isa<CXXConstructorDecl>(GD.getDecl())) 335d46f98573ba104eda102dd3224b2dca69f1c6336John McCall return GetAddrOfCXXConstructor(cast<CXXConstructorDecl>(GD.getDecl()), 336d46f98573ba104eda102dd3224b2dca69f1c6336John McCall GD.getCtorType()); 337d46f98573ba104eda102dd3224b2dca69f1c6336John McCall else if (isa<CXXDestructorDecl>(GD.getDecl())) 338d46f98573ba104eda102dd3224b2dca69f1c6336John McCall return GetAddrOfCXXDestructor(cast<CXXDestructorDecl>(GD.getDecl()), 339d46f98573ba104eda102dd3224b2dca69f1c6336John McCall GD.getDtorType()); 340d46f98573ba104eda102dd3224b2dca69f1c6336John McCall else if (isa<FunctionDecl>(GD.getDecl())) 341d46f98573ba104eda102dd3224b2dca69f1c6336John McCall return GetAddrOfFunction(GD); 342d46f98573ba104eda102dd3224b2dca69f1c6336John McCall else 343d46f98573ba104eda102dd3224b2dca69f1c6336John McCall return GetAddrOfGlobalVar(cast<VarDecl>(GD.getDecl())); 344d46f98573ba104eda102dd3224b2dca69f1c6336John McCall } 345d46f98573ba104eda102dd3224b2dca69f1c6336John McCall 3463bd6202ea2d5b5f7c8229cd280a846ae3dcf2355Anders Carlsson /// CreateOrReplaceCXXRuntimeVariable - Will return a global variable of the given 3473bd6202ea2d5b5f7c8229cd280a846ae3dcf2355Anders Carlsson /// type. If a variable with a different type already exists then a new 3483bd6202ea2d5b5f7c8229cd280a846ae3dcf2355Anders Carlsson /// variable with the right type will be created and all uses of the old 3493bd6202ea2d5b5f7c8229cd280a846ae3dcf2355Anders Carlsson /// variable will be replaced with a bitcast to the new variable. 3503bd6202ea2d5b5f7c8229cd280a846ae3dcf2355Anders Carlsson llvm::GlobalVariable * 3513bd6202ea2d5b5f7c8229cd280a846ae3dcf2355Anders Carlsson CreateOrReplaceCXXRuntimeVariable(llvm::StringRef Name, const llvm::Type *Ty, 3523bd6202ea2d5b5f7c8229cd280a846ae3dcf2355Anders Carlsson llvm::GlobalValue::LinkageTypes Linkage); 3533bd6202ea2d5b5f7c8229cd280a846ae3dcf2355Anders Carlsson 354ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump /// GetAddrOfGlobalVar - Return the llvm::Constant for the address of the 355570585c91dee98d7ba8ccf1198c03208ba17966bChris Lattner /// given global variable. If Ty is non-null and if the global doesn't exist, 356570585c91dee98d7ba8ccf1198c03208ba17966bChris Lattner /// then it will be greated with the specified type instead of whatever the 357570585c91dee98d7ba8ccf1198c03208ba17966bChris Lattner /// normal requested type would be. 358570585c91dee98d7ba8ccf1198c03208ba17966bChris Lattner llvm::Constant *GetAddrOfGlobalVar(const VarDecl *D, 359570585c91dee98d7ba8ccf1198c03208ba17966bChris Lattner const llvm::Type *Ty = 0); 360bd012ff1fa088181646a784f385b28867372d434Daniel Dunbar 3611de4d4e8cb2e9c88809fea8092bc6e835a5473d2John McCall 36234809507232bc4c3c4840c7d092c7440219fddafChris Lattner /// GetAddrOfFunction - Return the address of the given function. If Ty is 36334809507232bc4c3c4840c7d092c7440219fddafChris Lattner /// non-null, then this function will use the specified type if it has to 36434809507232bc4c3c4840c7d092c7440219fddafChris Lattner /// create it. 365b4880bab7fc1b61267cfd9a0ad52188e7a828cb3Chris Lattner llvm::Constant *GetAddrOfFunction(GlobalDecl GD, 3661faa89f9c619e4b2411fab4af7e22ee7a2bd9009Anders Carlsson const llvm::Type *Ty = 0, 3671faa89f9c619e4b2411fab4af7e22ee7a2bd9009Anders Carlsson bool ForVTable = false); 3686143293fa4366ee95d7e47e61bd030a34bf68b55Daniel Dunbar 3691d7088d1d9dc99e5478c0184a3e21cafef2a0b53Anders Carlsson /// GetAddrOfRTTIDescriptor - Get the address of the RTTI descriptor 3701d7088d1d9dc99e5478c0184a3e21cafef2a0b53Anders Carlsson /// for the given type. 3719dffe6f51c676c1e423c382c62d1648746e36cd4John McCall llvm::Constant *GetAddrOfRTTIDescriptor(QualType Ty, bool ForEH = false); 37231b7f52d8c8d459e80d2a72176cc7fcc4b7d8d38Anders Carlsson 37319879c98d964bc67442618510af04e3457219780Anders Carlsson /// GetAddrOfThunk - Get the address of the thunk for the given global decl. 37484c49e4e4baeb4c30251fd72220efb344b033cf0Anders Carlsson llvm::Constant *GetAddrOfThunk(GlobalDecl GD, const ThunkInfo &Thunk); 37519879c98d964bc67442618510af04e3457219780Anders Carlsson 3766a836706c40a31c716952b74785102c90fd6afa7Rafael Espindola /// GetWeakRefReference - Get a reference to the target of VD. 3776a836706c40a31c716952b74785102c90fd6afa7Rafael Espindola llvm::Constant *GetWeakRefReference(const ValueDecl *VD); 3786a836706c40a31c716952b74785102c90fd6afa7Rafael Espindola 379bb7e17b52ffaa4097b4c4d7935746d23539ffe2aAnders Carlsson /// GetNonVirtualBaseClassOffset - Returns the offset from a derived class to 380e04d45e05277ee04997fe59b1d194503f484c846Anders Carlsson /// a class. Returns null if the offset is 0. 381a04efdf635d35d88e65041fad007225d8c8d64a5Anders Carlsson llvm::Constant * 382a04efdf635d35d88e65041fad007225d8c8d64a5Anders Carlsson GetNonVirtualBaseClassOffset(const CXXRecordDecl *ClassDecl, 383f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall CastExpr::path_const_iterator PathBegin, 384f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall CastExpr::path_const_iterator PathEnd); 385d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall 386f0c11f7e6848f023ced6a5b51399ba787c7d4d0bJohn McCall /// A pair of helper functions for a __block variable. 387f0c11f7e6848f023ced6a5b51399ba787c7d4d0bJohn McCall class ByrefHelpers : public llvm::FoldingSetNode { 388f0c11f7e6848f023ced6a5b51399ba787c7d4d0bJohn McCall public: 389f0c11f7e6848f023ced6a5b51399ba787c7d4d0bJohn McCall llvm::Constant *CopyHelper; 390f0c11f7e6848f023ced6a5b51399ba787c7d4d0bJohn McCall llvm::Constant *DisposeHelper; 391f0c11f7e6848f023ced6a5b51399ba787c7d4d0bJohn McCall 392f0c11f7e6848f023ced6a5b51399ba787c7d4d0bJohn McCall /// The alignment of the field. This is important because 393f0c11f7e6848f023ced6a5b51399ba787c7d4d0bJohn McCall /// different offsets to the field within the byref struct need to 394f0c11f7e6848f023ced6a5b51399ba787c7d4d0bJohn McCall /// have different helper functions. 395f0c11f7e6848f023ced6a5b51399ba787c7d4d0bJohn McCall CharUnits Alignment; 396f0c11f7e6848f023ced6a5b51399ba787c7d4d0bJohn McCall 397f0c11f7e6848f023ced6a5b51399ba787c7d4d0bJohn McCall ByrefHelpers(CharUnits alignment) : Alignment(alignment) {} 398f0c11f7e6848f023ced6a5b51399ba787c7d4d0bJohn McCall virtual ~ByrefHelpers(); 399f0c11f7e6848f023ced6a5b51399ba787c7d4d0bJohn McCall 400f0c11f7e6848f023ced6a5b51399ba787c7d4d0bJohn McCall void Profile(llvm::FoldingSetNodeID &id) const { 401f0c11f7e6848f023ced6a5b51399ba787c7d4d0bJohn McCall id.AddInteger(Alignment.getQuantity()); 402f0c11f7e6848f023ced6a5b51399ba787c7d4d0bJohn McCall profileImpl(id); 403f0c11f7e6848f023ced6a5b51399ba787c7d4d0bJohn McCall } 404f0c11f7e6848f023ced6a5b51399ba787c7d4d0bJohn McCall virtual void profileImpl(llvm::FoldingSetNodeID &id) const = 0; 405f0c11f7e6848f023ced6a5b51399ba787c7d4d0bJohn McCall 406f0c11f7e6848f023ced6a5b51399ba787c7d4d0bJohn McCall virtual bool needsCopy() const { return true; } 407f0c11f7e6848f023ced6a5b51399ba787c7d4d0bJohn McCall virtual void emitCopy(CodeGenFunction &CGF, 408f0c11f7e6848f023ced6a5b51399ba787c7d4d0bJohn McCall llvm::Value *dest, llvm::Value *src) = 0; 409f0c11f7e6848f023ced6a5b51399ba787c7d4d0bJohn McCall 410f0c11f7e6848f023ced6a5b51399ba787c7d4d0bJohn McCall virtual bool needsDispose() const { return true; } 411f0c11f7e6848f023ced6a5b51399ba787c7d4d0bJohn McCall virtual void emitDispose(CodeGenFunction &CGF, llvm::Value *field) = 0; 412f0c11f7e6848f023ced6a5b51399ba787c7d4d0bJohn McCall }; 413f0c11f7e6848f023ced6a5b51399ba787c7d4d0bJohn McCall 414f0c11f7e6848f023ced6a5b51399ba787c7d4d0bJohn McCall llvm::FoldingSet<ByrefHelpers> ByrefHelpersCache; 415d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall 4168178df3b39ab923ff5d24538812628abee33df79John McCall /// getUniqueBlockCount - Fetches the global unique block count. 4178178df3b39ab923ff5d24538812628abee33df79John McCall int getUniqueBlockCount() { return ++Block.GlobalUniqueCount; } 418d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall 419d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall /// getBlockDescriptorType - Fetches the type of a generic block 420d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall /// descriptor. 421d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall const llvm::Type *getBlockDescriptorType(); 422d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall 423d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall /// getGenericBlockLiteralType - The type of a generic block literal. 424d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall const llvm::Type *getGenericBlockLiteralType(); 425d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall 426d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall /// GetAddrOfGlobalBlock - Gets the address of a block which 427d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall /// requires no captures. 428d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall llvm::Constant *GetAddrOfGlobalBlock(const BlockExpr *BE, const char *); 429a04efdf635d35d88e65041fad007225d8c8d64a5Anders Carlsson 430ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump /// GetStringForStringLiteral - Return the appropriate bytes for a string 431ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump /// literal, properly padded to match the literal type. If only the address of 432ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump /// a constant is needed consider using GetAddrOfConstantStringLiteral. 4336143293fa4366ee95d7e47e61bd030a34bf68b55Daniel Dunbar std::string GetStringForStringLiteral(const StringLiteral *E); 4346143293fa4366ee95d7e47e61bd030a34bf68b55Daniel Dunbar 435ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump /// GetAddrOfConstantCFString - Return a pointer to a constant CFString object 436ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump /// for the given string. 4378d4141f83d9de379547cf05bd75d4c6cf894b189Steve Naroff llvm::Constant *GetAddrOfConstantCFString(const StringLiteral *Literal); 43833e982bf782d851bfe5767acb1336fcf3419ac6bFariborz Jahanian 4394c73307c74764ba99e1379677fe92af72f676531Fariborz Jahanian /// GetAddrOfConstantString - Return a pointer to a constant NSString object 4404c73307c74764ba99e1379677fe92af72f676531Fariborz Jahanian /// for the given string. Or a user defined String object as defined via 4414c73307c74764ba99e1379677fe92af72f676531Fariborz Jahanian /// -fconstant-string-class=class_name option. 4424c73307c74764ba99e1379677fe92af72f676531Fariborz Jahanian llvm::Constant *GetAddrOfConstantString(const StringLiteral *Literal); 443a7ad98ff0919d6a24ea7c46634ea29bea551c1a0Chris Lattner 444ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump /// GetAddrOfConstantStringFromLiteral - Return a pointer to a constant array 445ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump /// for the given string literal. 4466143293fa4366ee95d7e47e61bd030a34bf68b55Daniel Dunbar llvm::Constant *GetAddrOfConstantStringFromLiteral(const StringLiteral *S); 4471e04976fc2611d8cc06986a81deed4c42183b870Daniel Dunbar 448eaf2bb89eb2aad3b80673de30febe52df43c10ecChris Lattner /// GetAddrOfConstantStringFromObjCEncode - Return a pointer to a constant 449eaf2bb89eb2aad3b80673de30febe52df43c10ecChris Lattner /// array for the given ObjCEncodeExpr node. 450eaf2bb89eb2aad3b80673de30febe52df43c10ecChris Lattner llvm::Constant *GetAddrOfConstantStringFromObjCEncode(const ObjCEncodeExpr *); 4511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4526143293fa4366ee95d7e47e61bd030a34bf68b55Daniel Dunbar /// GetAddrOfConstantString - Returns a pointer to a character array 453ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump /// containing the literal. This contents are exactly that of the given 454ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump /// string, i.e. it will not be null terminated automatically; see 455ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump /// GetAddrOfConstantCString. Note that whether the result is actually a 456ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump /// pointer to an LLVM constant depends on Feature.WriteableStrings. 4576143293fa4366ee95d7e47e61bd030a34bf68b55Daniel Dunbar /// 4586143293fa4366ee95d7e47e61bd030a34bf68b55Daniel Dunbar /// The result has pointer to array type. 4595fabf9dbee29464bcd06cd09f8e569d1b850f948Daniel Dunbar /// 4605fabf9dbee29464bcd06cd09f8e569d1b850f948Daniel Dunbar /// \param GlobalName If provided, the name to use for the global 4615fabf9dbee29464bcd06cd09f8e569d1b850f948Daniel Dunbar /// (if one is created). 4629de4342ef79a18c706e46bc23f8f579f5add2375Benjamin Kramer llvm::Constant *GetAddrOfConstantString(llvm::StringRef Str, 4635fabf9dbee29464bcd06cd09f8e569d1b850f948Daniel Dunbar const char *GlobalName=0); 4646143293fa4366ee95d7e47e61bd030a34bf68b55Daniel Dunbar 465ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump /// GetAddrOfConstantCString - Returns a pointer to a character array 466ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump /// containing the literal and a terminating '\0' character. The result has 467ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump /// pointer to array type. 4685fabf9dbee29464bcd06cd09f8e569d1b850f948Daniel Dunbar /// 469ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump /// \param GlobalName If provided, the name to use for the global (if one is 470ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump /// created). 4715fabf9dbee29464bcd06cd09f8e569d1b850f948Daniel Dunbar llvm::Constant *GetAddrOfConstantCString(const std::string &str, 4725fabf9dbee29464bcd06cd09f8e569d1b850f948Daniel Dunbar const char *GlobalName=0); 473ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump 474363c184139e26ea38223b477ad64ee67b22bb9a7Anders Carlsson /// GetAddrOfCXXConstructor - Return the address of the constructor of the 475363c184139e26ea38223b477ad64ee67b22bb9a7Anders Carlsson /// given type. 4761f6f961293da9c2b1c23da2411c1b439a9502ed0John McCall llvm::GlobalValue *GetAddrOfCXXConstructor(const CXXConstructorDecl *ctor, 4771f6f961293da9c2b1c23da2411c1b439a9502ed0John McCall CXXCtorType ctorType, 4781f6f961293da9c2b1c23da2411c1b439a9502ed0John McCall const CGFunctionInfo *fnInfo = 0); 47927ae53665f8b00fe4ba21da0fa79a4ce6e0b6cd5Anders Carlsson 48027ae53665f8b00fe4ba21da0fa79a4ce6e0b6cd5Anders Carlsson /// GetAddrOfCXXDestructor - Return the address of the constructor of the 48127ae53665f8b00fe4ba21da0fa79a4ce6e0b6cd5Anders Carlsson /// given type. 4821f6f961293da9c2b1c23da2411c1b439a9502ed0John McCall llvm::GlobalValue *GetAddrOfCXXDestructor(const CXXDestructorDecl *dtor, 4831f6f961293da9c2b1c23da2411c1b439a9502ed0John McCall CXXDtorType dtorType, 4841f6f961293da9c2b1c23da2411c1b439a9502ed0John McCall const CGFunctionInfo *fnInfo = 0); 4851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 48641071debe9b8887449c3f2ee0dd7124ed47bdda8Daniel Dunbar /// getBuiltinLibFunction - Given a builtin id for a function like 48741071debe9b8887449c3f2ee0dd7124ed47bdda8Daniel Dunbar /// "__builtin_fabsf", return a Function* for "fabsf". 48834771b594ca8cdf8cd2e40b27170efa4ed2833c5Daniel Dunbar llvm::Value *getBuiltinLibFunction(const FunctionDecl *FD, 48934771b594ca8cdf8cd2e40b27170efa4ed2833c5Daniel Dunbar unsigned BuiltinID); 4906143293fa4366ee95d7e47e61bd030a34bf68b55Daniel Dunbar 491ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump llvm::Function *getIntrinsic(unsigned IID, const llvm::Type **Tys = 0, 4927acda7c4a0e4aec6c003b3169ca45a5f3bc7e033Chris Lattner unsigned NumTys = 0); 493bd012ff1fa088181646a784f385b28867372d434Daniel Dunbar 49441071debe9b8887449c3f2ee0dd7124ed47bdda8Daniel Dunbar /// EmitTopLevelDecl - Emit code for a single top level declaration. 49541071debe9b8887449c3f2ee0dd7124ed47bdda8Daniel Dunbar void EmitTopLevelDecl(Decl *D); 496bd012ff1fa088181646a784f385b28867372d434Daniel Dunbar 4970269871c9cba493f76237175ab60313406f3bafaDaniel Dunbar /// AddUsedGlobal - Add a global which should be forced to be 4980269871c9cba493f76237175ab60313406f3bafaDaniel Dunbar /// present in the object file; these are emitted to the llvm.used 4990269871c9cba493f76237175ab60313406f3bafaDaniel Dunbar /// metadata global. 5000269871c9cba493f76237175ab60313406f3bafaDaniel Dunbar void AddUsedGlobal(llvm::GlobalValue *GV); 5010269871c9cba493f76237175ab60313406f3bafaDaniel Dunbar 502bd012ff1fa088181646a784f385b28867372d434Daniel Dunbar void AddAnnotation(llvm::Constant *C) { Annotations.push_back(C); } 503bd012ff1fa088181646a784f385b28867372d434Daniel Dunbar 504efb0fa9e11f75af51744a6159530ef7cc8efa24aDaniel Dunbar /// AddCXXDtorEntry - Add a destructor and object to add to the C++ global 505efb0fa9e11f75af51744a6159530ef7cc8efa24aDaniel Dunbar /// destructor function. 506810112e28dc839715d17b0a786f23aaa19600ac0Chris Lattner void AddCXXDtorEntry(llvm::Constant *DtorFn, llvm::Constant *Object) { 507810112e28dc839715d17b0a786f23aaa19600ac0Chris Lattner CXXGlobalDtors.push_back(std::make_pair(DtorFn, Object)); 508810112e28dc839715d17b0a786f23aaa19600ac0Chris Lattner } 509efb0fa9e11f75af51744a6159530ef7cc8efa24aDaniel Dunbar 51074391b48b4791cded373683a3baf67314f358d50Chris Lattner /// CreateRuntimeFunction - Create a new runtime function with the specified 51174391b48b4791cded373683a3baf67314f358d50Chris Lattner /// type and name. 51274391b48b4791cded373683a3baf67314f358d50Chris Lattner llvm::Constant *CreateRuntimeFunction(const llvm::FunctionType *Ty, 513f746aa6a8f538be914173a4aef2d9a2fd9f99d17John McCall llvm::StringRef Name); 51474391b48b4791cded373683a3baf67314f358d50Chris Lattner /// CreateRuntimeVariable - Create a new runtime global variable with the 51574391b48b4791cded373683a3baf67314f358d50Chris Lattner /// specified type and name. 51674391b48b4791cded373683a3baf67314f358d50Chris Lattner llvm::Constant *CreateRuntimeVariable(const llvm::Type *Ty, 517f746aa6a8f538be914173a4aef2d9a2fd9f99d17John McCall llvm::StringRef Name); 518f1968f28869f4e0675450ae39c478a37c5b9abd6Daniel Dunbar 519673431a2986f750b4d8fadb57abf3f00db27bbbdDaniel Dunbar ///@name Custom Blocks Runtime Interfaces 520673431a2986f750b4d8fadb57abf3f00db27bbbdDaniel Dunbar ///@{ 521673431a2986f750b4d8fadb57abf3f00db27bbbdDaniel Dunbar 522673431a2986f750b4d8fadb57abf3f00db27bbbdDaniel Dunbar llvm::Constant *getNSConcreteGlobalBlock(); 523673431a2986f750b4d8fadb57abf3f00db27bbbdDaniel Dunbar llvm::Constant *getNSConcreteStackBlock(); 524673431a2986f750b4d8fadb57abf3f00db27bbbdDaniel Dunbar llvm::Constant *getBlockObjectAssign(); 525673431a2986f750b4d8fadb57abf3f00db27bbbdDaniel Dunbar llvm::Constant *getBlockObjectDispose(); 526673431a2986f750b4d8fadb57abf3f00db27bbbdDaniel Dunbar 527673431a2986f750b4d8fadb57abf3f00db27bbbdDaniel Dunbar ///@} 528673431a2986f750b4d8fadb57abf3f00db27bbbdDaniel Dunbar 529e80d56771736c85fd8365c394a6731923b17e91dDevang Patel // UpdateCompleteType - Make sure that this type is translated. 530e80d56771736c85fd8365c394a6731923b17e91dDevang Patel void UpdateCompletedType(const TagDecl *TD); 531d60f2fbf69df08e952377b498c036f269395024dDaniel Dunbar 5325808ce43f8d7e71f5acacc9ca320268c4f37565aJohn McCall llvm::Constant *getMemberPointerConstant(const UnaryOperator *e); 5335808ce43f8d7e71f5acacc9ca320268c4f37565aJohn McCall 534d60f2fbf69df08e952377b498c036f269395024dDaniel Dunbar /// EmitConstantExpr - Try to emit the given expression as a 535d60f2fbf69df08e952377b498c036f269395024dDaniel Dunbar /// constant; returns 0 if the expression cannot be emitted as a 536d60f2fbf69df08e952377b498c036f269395024dDaniel Dunbar /// constant. 537e9352cc9818ba59e7cf88500ef048991c90f3821Anders Carlsson llvm::Constant *EmitConstantExpr(const Expr *E, QualType DestType, 538e9352cc9818ba59e7cf88500ef048991c90f3821Anders Carlsson CodeGenFunction *CGF = 0); 539d60f2fbf69df08e952377b498c036f269395024dDaniel Dunbar 5400f59312e7b625fa5821a63db65377d4b3b667e99Eli Friedman /// EmitNullConstant - Return the result of value-initializing the given 5410f59312e7b625fa5821a63db65377d4b3b667e99Eli Friedman /// type, i.e. a null expression of the given type. This is usually, 5420f59312e7b625fa5821a63db65377d4b3b667e99Eli Friedman /// but not always, an LLVM null constant. 5430f59312e7b625fa5821a63db65377d4b3b667e99Eli Friedman llvm::Constant *EmitNullConstant(QualType T); 5440f59312e7b625fa5821a63db65377d4b3b667e99Eli Friedman 5458bd4afeb876fd0015bb808eb2f3de1fe709658a7Nate Begeman llvm::Constant *EmitAnnotateAttr(llvm::GlobalValue *GV, 5468bd4afeb876fd0015bb808eb2f3de1fe709658a7Nate Begeman const AnnotateAttr *AA, unsigned LineNo); 547ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump 54832096695c76033a6b0b1747c439f7378a11e8312John McCall /// Error - Emit a general error that something can't be done. 54932096695c76033a6b0b1747c439f7378a11e8312John McCall void Error(SourceLocation loc, llvm::StringRef error); 55032096695c76033a6b0b1747c439f7378a11e8312John McCall 551488e993a135ce700b982bf099c3d6b856301d642Daniel Dunbar /// ErrorUnsupported - Print out an error that codegen doesn't support the 55290df4b6661968a84bf64baee489bb2f6d948fcc1Daniel Dunbar /// specified stmt yet. 553ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump /// \param OmitOnError - If true, then this error should only be emitted if no 554ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump /// other errors have been reported. 555ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump void ErrorUnsupported(const Stmt *S, const char *Type, 55690df4b6661968a84bf64baee489bb2f6d948fcc1Daniel Dunbar bool OmitOnError=false); 557ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump 558488e993a135ce700b982bf099c3d6b856301d642Daniel Dunbar /// ErrorUnsupported - Print out an error that codegen doesn't support the 559c6fdc34ac0183bfa03d65f317c78b7bdac52897eChris Lattner /// specified decl yet. 560ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump /// \param OmitOnError - If true, then this error should only be emitted if no 561ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump /// other errors have been reported. 56290df4b6661968a84bf64baee489bb2f6d948fcc1Daniel Dunbar void ErrorUnsupported(const Decl *D, const char *Type, 56390df4b6661968a84bf64baee489bb2f6d948fcc1Daniel Dunbar bool OmitOnError=false); 5644f8d123e3e2c260de3377208106ddba87cee28b4Dan Gohman 5650e4f40e1bbc4dce16bbb9870300a435419f1b3d5Daniel Dunbar /// SetInternalFunctionAttributes - Set the attributes on the LLVM 5660e4f40e1bbc4dce16bbb9870300a435419f1b3d5Daniel Dunbar /// function for the given decl and function info. This applies 5670e4f40e1bbc4dce16bbb9870300a435419f1b3d5Daniel Dunbar /// attributes necessary for handling the ABI as well as user 5680e4f40e1bbc4dce16bbb9870300a435419f1b3d5Daniel Dunbar /// specified attributes like section. 5690e4f40e1bbc4dce16bbb9870300a435419f1b3d5Daniel Dunbar void SetInternalFunctionAttributes(const Decl *D, llvm::Function *F, 5700e4f40e1bbc4dce16bbb9870300a435419f1b3d5Daniel Dunbar const CGFunctionInfo &FI); 571f80519b919a348db004fba18530706314d1ebfb5Daniel Dunbar 5727dbd8197040313d796282d4af06eccdf8a17319cDaniel Dunbar /// SetLLVMFunctionAttributes - Set the LLVM function attributes 5737dbd8197040313d796282d4af06eccdf8a17319cDaniel Dunbar /// (sext, zext, etc). 5747dbd8197040313d796282d4af06eccdf8a17319cDaniel Dunbar void SetLLVMFunctionAttributes(const Decl *D, 5757dbd8197040313d796282d4af06eccdf8a17319cDaniel Dunbar const CGFunctionInfo &Info, 5767dbd8197040313d796282d4af06eccdf8a17319cDaniel Dunbar llvm::Function *F); 577b768807c49a1c7085def099b848631856af766faDaniel Dunbar 5787c65e990e9f0dafaf9adbc59b766dcc23eaee845Daniel Dunbar /// SetLLVMFunctionAttributesForDefinition - Set the LLVM function attributes 5797c65e990e9f0dafaf9adbc59b766dcc23eaee845Daniel Dunbar /// which only apply to a function definintion. 5807c65e990e9f0dafaf9adbc59b766dcc23eaee845Daniel Dunbar void SetLLVMFunctionAttributesForDefinition(const Decl *D, llvm::Function *F); 5817c65e990e9f0dafaf9adbc59b766dcc23eaee845Daniel Dunbar 582dacf9dda17346c628fdd8c5df53c681738db0dc5Daniel Dunbar /// ReturnTypeUsesSRet - Return true iff the given type uses 'sret' when used 583ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump /// as a return type. 584dacf9dda17346c628fdd8c5df53c681738db0dc5Daniel Dunbar bool ReturnTypeUsesSRet(const CGFunctionInfo &FI); 585dacf9dda17346c628fdd8c5df53c681738db0dc5Daniel Dunbar 586dacf9dda17346c628fdd8c5df53c681738db0dc5Daniel Dunbar /// ReturnTypeUsesSret - Return true iff the given type uses 'fpret' when used 587dacf9dda17346c628fdd8c5df53c681738db0dc5Daniel Dunbar /// as a return type. 588dacf9dda17346c628fdd8c5df53c681738db0dc5Daniel Dunbar bool ReturnTypeUsesFPRet(QualType ResultType); 589b768807c49a1c7085def099b848631856af766faDaniel Dunbar 590ca6408c3176783f0b29da4679a08512aa05f0c73Daniel Dunbar /// ConstructAttributeList - Get the LLVM attributes and calling convention to 591ca6408c3176783f0b29da4679a08512aa05f0c73Daniel Dunbar /// use for a particular function type. 592ca6408c3176783f0b29da4679a08512aa05f0c73Daniel Dunbar /// 593ca6408c3176783f0b29da4679a08512aa05f0c73Daniel Dunbar /// \param Info - The function type information. 594ca6408c3176783f0b29da4679a08512aa05f0c73Daniel Dunbar /// \param TargetDecl - The decl these attributes are being constructed 595ca6408c3176783f0b29da4679a08512aa05f0c73Daniel Dunbar /// for. If supplied the attributes applied to this decl may contribute to the 596ca6408c3176783f0b29da4679a08512aa05f0c73Daniel Dunbar /// function attributes and calling convention. 597ca6408c3176783f0b29da4679a08512aa05f0c73Daniel Dunbar /// \param PAL [out] - On return, the attribute list to use. 598ca6408c3176783f0b29da4679a08512aa05f0c73Daniel Dunbar /// \param CallingConv [out] - On return, the LLVM calling convention to use. 59988b5396b0897f28d22ae3debf4a0d97b33b6c362Daniel Dunbar void ConstructAttributeList(const CGFunctionInfo &Info, 60088b5396b0897f28d22ae3debf4a0d97b33b6c362Daniel Dunbar const Decl *TargetDecl, 601ca6408c3176783f0b29da4679a08512aa05f0c73Daniel Dunbar AttributeListType &PAL, 602ca6408c3176783f0b29da4679a08512aa05f0c73Daniel Dunbar unsigned &CallingConv); 603b768807c49a1c7085def099b848631856af766faDaniel Dunbar 604793a990774826a0c20b0da66cec0991badfb8b63Anders Carlsson llvm::StringRef getMangledName(GlobalDecl GD); 60514110477887e3dc168ffc6c191e72d705051f99ePeter Collingbourne void getBlockMangledName(GlobalDecl GD, MangleBuffer &Buffer, 60614110477887e3dc168ffc6c191e72d705051f99ePeter Collingbourne const BlockDecl *BD); 607b6c8c8bd8d362c8a6cdb767415b0d21e62b77eb2Douglas Gregor 608b6c8c8bd8d362c8a6cdb767415b0d21e62b77eb2Douglas Gregor void EmitTentativeDefinition(const VarDecl *D); 609f121677b6bbbf4e4a51ee7a1120b77adf187bad4Mike Stump 6106fb745bdf1ff1e32caf07e42093a7920726892c1Douglas Gregor void EmitVTable(CXXRecordDecl *Class, bool DefinitionRequired); 6116fb745bdf1ff1e32caf07e42093a7920726892c1Douglas Gregor 612d46f98573ba104eda102dd3224b2dca69f1c6336John McCall llvm::GlobalVariable::LinkageTypes 613d46f98573ba104eda102dd3224b2dca69f1c6336John McCall getFunctionLinkage(const FunctionDecl *FD); 614d46f98573ba104eda102dd3224b2dca69f1c6336John McCall 6158b2423361648c39a7d8a3c5e8129e12006deac32John McCall void setFunctionLinkage(const FunctionDecl *FD, llvm::GlobalValue *V) { 6168b2423361648c39a7d8a3c5e8129e12006deac32John McCall V->setLinkage(getFunctionLinkage(FD)); 6178b2423361648c39a7d8a3c5e8129e12006deac32John McCall } 6188b2423361648c39a7d8a3c5e8129e12006deac32John McCall 619046c294a43024874ff35656c6e785b64e72f1f36Anders Carlsson /// getVTableLinkage - Return the appropriate linkage for the vtable, VTT, 6204b0f21c0f8bed0e2a7dc62d73be64e7e277d6c9aDouglas Gregor /// and type information of the given class. 6213a717f7fbb94ec31b826b48c15fdc965b5910df3Anders Carlsson llvm::GlobalVariable::LinkageTypes getVTableLinkage(const CXXRecordDecl *RD); 622687cc4a850b59116efee061018f0d8df50728b82Ken Dyck 623687cc4a850b59116efee061018f0d8df50728b82Ken Dyck /// GetTargetTypeStoreSize - Return the store size, in character units, of 624687cc4a850b59116efee061018f0d8df50728b82Ken Dyck /// the given LLVM type. 625687cc4a850b59116efee061018f0d8df50728b82Ken Dyck CharUnits GetTargetTypeStoreSize(const llvm::Type *Ty) const; 626354e712c81fbb07c0ce5f06180788b25fffa1b56Fariborz Jahanian 627354e712c81fbb07c0ce5f06180788b25fffa1b56Fariborz Jahanian /// GetLLVMLinkageVarDefinition - Returns LLVM linkage for a global 628354e712c81fbb07c0ce5f06180788b25fffa1b56Fariborz Jahanian /// variable. 629354e712c81fbb07c0ce5f06180788b25fffa1b56Fariborz Jahanian llvm::GlobalValue::LinkageTypes 630354e712c81fbb07c0ce5f06180788b25fffa1b56Fariborz Jahanian GetLLVMLinkageVarDefinition(const VarDecl *D, 631354e712c81fbb07c0ce5f06180788b25fffa1b56Fariborz Jahanian llvm::GlobalVariable *GV); 632354e712c81fbb07c0ce5f06180788b25fffa1b56Fariborz Jahanian 633046c294a43024874ff35656c6e785b64e72f1f36Anders Carlsson std::vector<const CXXRecordDecl*> DeferredVTables; 634bbf58bb1b8dd8c5e0f07547a6c20ffd55385fcf6Rafael Espindola 6359cd4fe4af6d3e8b6dcfce9c2cdefcaafca7eed7cChris Lattnerprivate: 636f746aa6a8f538be914173a4aef2d9a2fd9f99d17John McCall llvm::GlobalValue *GetGlobalValue(llvm::StringRef Ref); 6371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 638f746aa6a8f538be914173a4aef2d9a2fd9f99d17John McCall llvm::Constant *GetOrCreateLLVMFunction(llvm::StringRef MangledName, 63974391b48b4791cded373683a3baf67314f358d50Chris Lattner const llvm::Type *Ty, 6401faa89f9c619e4b2411fab4af7e22ee7a2bd9009Anders Carlsson GlobalDecl D, 6411faa89f9c619e4b2411fab4af7e22ee7a2bd9009Anders Carlsson bool ForVTable); 642f746aa6a8f538be914173a4aef2d9a2fd9f99d17John McCall llvm::Constant *GetOrCreateLLVMGlobal(llvm::StringRef MangledName, 64374391b48b4791cded373683a3baf67314f358d50Chris Lattner const llvm::PointerType *PTy, 644c532b502858032f377056dc8cba2fe43cba8702bRafael Espindola const VarDecl *D, 645c532b502858032f377056dc8cba2fe43cba8702bRafael Espindola bool UnnamedAddr = false); 6461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6477c65e990e9f0dafaf9adbc59b766dcc23eaee845Daniel Dunbar /// SetCommonAttributes - Set attributes which are common to any 6487c65e990e9f0dafaf9adbc59b766dcc23eaee845Daniel Dunbar /// form of a global definition (alias, Objective-C method, 6497c65e990e9f0dafaf9adbc59b766dcc23eaee845Daniel Dunbar /// function, global variable). 6507dbd8197040313d796282d4af06eccdf8a17319cDaniel Dunbar /// 6517c65e990e9f0dafaf9adbc59b766dcc23eaee845Daniel Dunbar /// NOTE: This should only be called for definitions. 6527c65e990e9f0dafaf9adbc59b766dcc23eaee845Daniel Dunbar void SetCommonAttributes(const Decl *D, llvm::GlobalValue *GV); 653f80519b919a348db004fba18530706314d1ebfb5Daniel Dunbar 6547c65e990e9f0dafaf9adbc59b766dcc23eaee845Daniel Dunbar /// SetFunctionDefinitionAttributes - Set attributes for a global definition. 6551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void SetFunctionDefinitionAttributes(const FunctionDecl *D, 656c6c14d1cd68afcd90d097715296377f15be45210Eli Friedman llvm::GlobalValue *GV); 6571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6587dbd8197040313d796282d4af06eccdf8a17319cDaniel Dunbar /// SetFunctionAttributes - Set function attributes for a function 6597dbd8197040313d796282d4af06eccdf8a17319cDaniel Dunbar /// declaration. 660b2bcf1c176b200b36f371e189ce22f93c86cdf45Anders Carlsson void SetFunctionAttributes(GlobalDecl GD, 661c6c14d1cd68afcd90d097715296377f15be45210Eli Friedman llvm::Function *F, 662c6c14d1cd68afcd90d097715296377f15be45210Eli Friedman bool IsIncompleteFunction); 663d4cbda6292b321c2e7dce7f039d92918fee99b3aNuno Lopes 664ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump /// EmitGlobal - Emit code for a singal global function or var decl. Forward 665ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump /// declarations are emitted lazily. 666b4880bab7fc1b61267cfd9a0ad52188e7a828cb3Chris Lattner void EmitGlobal(GlobalDecl D); 66741071debe9b8887449c3f2ee0dd7124ed47bdda8Daniel Dunbar 668b4880bab7fc1b61267cfd9a0ad52188e7a828cb3Chris Lattner void EmitGlobalDefinition(GlobalDecl D); 669d5d31801fc87239436fa349c89dce7797cf13537Daniel Dunbar 670b4880bab7fc1b61267cfd9a0ad52188e7a828cb3Chris Lattner void EmitGlobalFunctionDefinition(GlobalDecl GD); 671bd012ff1fa088181646a784f385b28867372d434Daniel Dunbar void EmitGlobalVarDefinition(const VarDecl *D); 672f746aa6a8f538be914173a4aef2d9a2fd9f99d17John McCall void EmitAliasDefinition(GlobalDecl GD); 673af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar void EmitObjCPropertyImplementations(const ObjCImplementationDecl *D); 674109dfc6ca6652f60c55ed0f2631aebf323d0200dFariborz Jahanian void EmitObjCIvarInitializations(ObjCImplementationDecl *D); 675354e712c81fbb07c0ce5f06180788b25fffa1b56Fariborz Jahanian 67695d4e5d2f87a0f07fb143ccb824dfc4c5c595c78Anders Carlsson // C++ related functions. 6771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 678d46f98573ba104eda102dd3224b2dca69f1c6336John McCall bool TryEmitDefinitionAsAlias(GlobalDecl Alias, GlobalDecl Target); 679c0bf462cf35fe050bddbd8bff967298e4a67e79dJohn McCall bool TryEmitBaseDestructorAsAlias(const CXXDestructorDecl *D); 680d46f98573ba104eda102dd3224b2dca69f1c6336John McCall 681984e06874685396ca2cb51f0008cfff7c9b3d9c6Anders Carlsson void EmitNamespace(const NamespaceDecl *D); 68291e20dd8bf1bc8980ee93839383d2bd170bce050Anders Carlsson void EmitLinkageSpec(const LinkageSpecDecl *D); 68395d4e5d2f87a0f07fb143ccb824dfc4c5c595c78Anders Carlsson 68495d4e5d2f87a0f07fb143ccb824dfc4c5c595c78Anders Carlsson /// EmitCXXConstructors - Emit constructors (base, complete) from a 68595d4e5d2f87a0f07fb143ccb824dfc4c5c595c78Anders Carlsson /// C++ constructor Decl. 68695d4e5d2f87a0f07fb143ccb824dfc4c5c595c78Anders Carlsson void EmitCXXConstructors(const CXXConstructorDecl *D); 6871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 68895d4e5d2f87a0f07fb143ccb824dfc4c5c595c78Anders Carlsson /// EmitCXXConstructor - Emit a single constructor with the given type from 68995d4e5d2f87a0f07fb143ccb824dfc4c5c595c78Anders Carlsson /// a C++ constructor Decl. 69095d4e5d2f87a0f07fb143ccb824dfc4c5c595c78Anders Carlsson void EmitCXXConstructor(const CXXConstructorDecl *D, CXXCtorType Type); 6911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// EmitCXXDestructors - Emit destructors (base, complete) from a 69327ae53665f8b00fe4ba21da0fa79a4ce6e0b6cd5Anders Carlsson /// C++ destructor Decl. 69427ae53665f8b00fe4ba21da0fa79a4ce6e0b6cd5Anders Carlsson void EmitCXXDestructors(const CXXDestructorDecl *D); 6951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 69627ae53665f8b00fe4ba21da0fa79a4ce6e0b6cd5Anders Carlsson /// EmitCXXDestructor - Emit a single destructor with the given type from 69727ae53665f8b00fe4ba21da0fa79a4ce6e0b6cd5Anders Carlsson /// a C++ destructor Decl. 69827ae53665f8b00fe4ba21da0fa79a4ce6e0b6cd5Anders Carlsson void EmitCXXDestructor(const CXXDestructorDecl *D, CXXDtorType Type); 6991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 700efb0fa9e11f75af51744a6159530ef7cc8efa24aDaniel Dunbar /// EmitCXXGlobalInitFunc - Emit the function that initializes C++ globals. 70189ed31d3f9eeb8ec77c284a5cf404a74bf5e7acfAnders Carlsson void EmitCXXGlobalInitFunc(); 7026c6bda3b0b1d8adaac2ba3f4da7056e9f1eef52eEli Friedman 703efb0fa9e11f75af51744a6159530ef7cc8efa24aDaniel Dunbar /// EmitCXXGlobalDtorFunc - Emit the function that destroys C++ globals. 704efb0fa9e11f75af51744a6159530ef7cc8efa24aDaniel Dunbar void EmitCXXGlobalDtorFunc(); 705efb0fa9e11f75af51744a6159530ef7cc8efa24aDaniel Dunbar 7063030eb82593097502469a8b3fc26112c79c75605John McCall void EmitCXXGlobalVarDeclInitFunc(const VarDecl *D, 7073030eb82593097502469a8b3fc26112c79c75605John McCall llvm::GlobalVariable *Addr); 7086c6bda3b0b1d8adaac2ba3f4da7056e9f1eef52eEli Friedman 7096bfed7e411adc46eaf616371f85f68305c6e6257Daniel Dunbar // FIXME: Hardcoding priority here is gross. 710b4880bab7fc1b61267cfd9a0ad52188e7a828cb3Chris Lattner void AddGlobalCtor(llvm::Function *Ctor, int Priority=65535); 711b4880bab7fc1b61267cfd9a0ad52188e7a828cb3Chris Lattner void AddGlobalDtor(llvm::Function *Dtor, int Priority=65535); 7126bfed7e411adc46eaf616371f85f68305c6e6257Daniel Dunbar 713ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump /// EmitCtorList - Generates a global array of functions and priorities using 714ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump /// the given list and name. This array will have appending linkage and is 715ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump /// suitable for use as a LLVM constructor or destructor array. 7166bfed7e411adc46eaf616371f85f68305c6e6257Daniel Dunbar void EmitCtorList(const CtorList &Fns, const char *GlobalName); 717bd012ff1fa088181646a784f385b28867372d434Daniel Dunbar 718bd012ff1fa088181646a784f385b28867372d434Daniel Dunbar void EmitAnnotations(void); 7190269871c9cba493f76237175ab60313406f3bafaDaniel Dunbar 720d1a5c31b78997befe75d10a4731cee4ab211cc31Rafael Espindola /// EmitFundamentalRTTIDescriptor - Emit the RTTI descriptors for the 721d1a5c31b78997befe75d10a4731cee4ab211cc31Rafael Espindola /// given type. 722d1a5c31b78997befe75d10a4731cee4ab211cc31Rafael Espindola void EmitFundamentalRTTIDescriptor(QualType Type); 723d1a5c31b78997befe75d10a4731cee4ab211cc31Rafael Espindola 724d1a5c31b78997befe75d10a4731cee4ab211cc31Rafael Espindola /// EmitFundamentalRTTIDescriptors - Emit the RTTI descriptors for the 725d1a5c31b78997befe75d10a4731cee4ab211cc31Rafael Espindola /// builtin types. 726d1a5c31b78997befe75d10a4731cee4ab211cc31Rafael Espindola void EmitFundamentalRTTIDescriptors(); 727d1a5c31b78997befe75d10a4731cee4ab211cc31Rafael Espindola 72842745815fa4e90bfb07e581d2e5152b2c2db08ffDaniel Dunbar /// EmitDeferred - Emit any needed decls for which code generation 72942745815fa4e90bfb07e581d2e5152b2c2db08ffDaniel Dunbar /// was deferred. 7300269871c9cba493f76237175ab60313406f3bafaDaniel Dunbar void EmitDeferred(void); 7310269871c9cba493f76237175ab60313406f3bafaDaniel Dunbar 73242745815fa4e90bfb07e581d2e5152b2c2db08ffDaniel Dunbar /// EmitLLVMUsed - Emit the llvm.used metadata used to force 73342745815fa4e90bfb07e581d2e5152b2c2db08ffDaniel Dunbar /// references to global which may otherwise be optimized out. 7340269871c9cba493f76237175ab60313406f3bafaDaniel Dunbar void EmitLLVMUsed(void); 735f1968f28869f4e0675450ae39c478a37c5b9abd6Daniel Dunbar 736744016dde06fcffd50931e94a98c850f8b12cd87John McCall void EmitDeclMetadata(); 737744016dde06fcffd50931e94a98c850f8b12cd87John McCall 7383dc05418538c719fea48b906bfa4febe5296e126Nick Lewycky /// EmitCoverageFile - Emit the llvm.gcov metadata used to tell LLVM where 7395ea4f44e34449a78d6b38aa47c14b527839d7aacNick Lewycky /// to emit the .gcno and .gcda files in a way that persists in .bc files. 7403dc05418538c719fea48b906bfa4febe5296e126Nick Lewycky void EmitCoverageFile(); 7415ea4f44e34449a78d6b38aa47c14b527839d7aacNick Lewycky 74242745815fa4e90bfb07e581d2e5152b2c2db08ffDaniel Dunbar /// MayDeferGeneration - Determine if the given decl can be emitted 74342745815fa4e90bfb07e581d2e5152b2c2db08ffDaniel Dunbar /// lazily; this is only relevant for definitions. The given decl 74442745815fa4e90bfb07e581d2e5152b2c2db08ffDaniel Dunbar /// must be either a function or var decl. 74573241dfeb5c498255b662984cca369fd28ec3147Daniel Dunbar bool MayDeferGeneration(const ValueDecl *D); 746b25938303de0976b9f189363d43033e5788e3d36John McCall 747b25938303de0976b9f189363d43033e5788e3d36John McCall /// SimplifyPersonality - Check whether we can use a "simpler", more 748b25938303de0976b9f189363d43033e5788e3d36John McCall /// core exceptions personality function. 749b25938303de0976b9f189363d43033e5788e3d36John McCall void SimplifyPersonality(); 7505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 7515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} // end namespace CodeGen 7525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} // end namespace clang 7535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 7545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif 755