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"
34a967935303e6b36dcc0490073e47fdd5a5eff93ePeter Collingbourne#include "llvm/Transforms/Utils/SpecialCaseList.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;
310211c8ddb5b500ed84833751363d0cfe1115f4dd3Richard Smith  llvm::DenseMap<const Expr*, llvm::Constant *> MaterializedGlobalTemporaryMap;
311211c8ddb5b500ed84833751363d0cfe1115f4dd3Richard Smith
312b08cfb3c5909752c0e501a4e5c31a507a4cc1f72Fariborz Jahanian  llvm::DenseMap<QualType, llvm::Constant *> AtomicSetterHelperFnMap;
313b08cfb3c5909752c0e501a4e5c31a507a4cc1f72Fariborz Jahanian  llvm::DenseMap<QualType, llvm::Constant *> AtomicGetterHelperFnMap;
3143e9df9920db8de8ec93a424b0c1784f9bff301eaDaniel Dunbar
3150024937dbb23752f606846f4a12aafc712bcde33Richard Smith  /// Map used to track internal linkage functions declared within
3160024937dbb23752f606846f4a12aafc712bcde33Richard Smith  /// extern "C" regions.
31784083b74abc4a2d1a9013ce4c75d63ee7d6d1da3Richard Smith  typedef llvm::MapVector<IdentifierInfo *,
31884083b74abc4a2d1a9013ce4c75d63ee7d6d1da3Richard Smith                          llvm::GlobalValue *> StaticExternCMap;
3190024937dbb23752f606846f4a12aafc712bcde33Richard Smith  StaticExternCMap StaticExternCValues;
3200024937dbb23752f606846f4a12aafc712bcde33Richard Smith
321b80a16eadd0dacabfc1c32412e243ccb99dd664dRichard Smith  /// \brief thread_local variables defined or used in this TU.
322b80a16eadd0dacabfc1c32412e243ccb99dd664dRichard Smith  std::vector<std::pair<const VarDecl *, llvm::GlobalVariable *> >
323b80a16eadd0dacabfc1c32412e243ccb99dd664dRichard Smith    CXXThreadLocals;
324b80a16eadd0dacabfc1c32412e243ccb99dd664dRichard Smith
325b80a16eadd0dacabfc1c32412e243ccb99dd664dRichard Smith  /// \brief thread_local variables with initializers that need to run
326b80a16eadd0dacabfc1c32412e243ccb99dd664dRichard Smith  /// before any thread_local variable in this TU is odr-used.
327b80a16eadd0dacabfc1c32412e243ccb99dd664dRichard Smith  std::vector<llvm::Constant*> CXXThreadLocalInits;
328b80a16eadd0dacabfc1c32412e243ccb99dd664dRichard Smith
329efb0fa9e11f75af51744a6159530ef7cc8efa24aDaniel Dunbar  /// CXXGlobalInits - Global variables with initializers that need to run
33089ed31d3f9eeb8ec77c284a5cf404a74bf5e7acfAnders Carlsson  /// before main.
3316c6bda3b0b1d8adaac2ba3f4da7056e9f1eef52eEli Friedman  std::vector<llvm::Constant*> CXXGlobalInits;
332bf40cb518312dde1c07e44fcae59bc4eec65589cJohn McCall
333bf40cb518312dde1c07e44fcae59bc4eec65589cJohn McCall  /// When a C++ decl with an initializer is deferred, null is
334bf40cb518312dde1c07e44fcae59bc4eec65589cJohn McCall  /// appended to CXXGlobalInits, and the index of that null is placed
335bf40cb518312dde1c07e44fcae59bc4eec65589cJohn McCall  /// here so that the initializer will be performed in the correct
336bf40cb518312dde1c07e44fcae59bc4eec65589cJohn McCall  /// order.
337bf40cb518312dde1c07e44fcae59bc4eec65589cJohn McCall  llvm::DenseMap<const Decl*, unsigned> DelayedCXXInitPosition;
3389f967c5e4bbeb48caf6d0e62056b3d3fee20bf7cFariborz Jahanian
3394179ddd5752ec5a252ca1e1eb77a5c34b5835d3bAnton Korobeynikov  typedef std::pair<OrderGlobalInits, llvm::Function*> GlobalInitData;
3404179ddd5752ec5a252ca1e1eb77a5c34b5835d3bAnton Korobeynikov
3414179ddd5752ec5a252ca1e1eb77a5c34b5835d3bAnton Korobeynikov  struct GlobalInitPriorityCmp {
3424179ddd5752ec5a252ca1e1eb77a5c34b5835d3bAnton Korobeynikov    bool operator()(const GlobalInitData &LHS,
3434179ddd5752ec5a252ca1e1eb77a5c34b5835d3bAnton Korobeynikov                    const GlobalInitData &RHS) const {
3444179ddd5752ec5a252ca1e1eb77a5c34b5835d3bAnton Korobeynikov      return LHS.first.priority < RHS.first.priority;
3454179ddd5752ec5a252ca1e1eb77a5c34b5835d3bAnton Korobeynikov    }
3464179ddd5752ec5a252ca1e1eb77a5c34b5835d3bAnton Korobeynikov  };
3474179ddd5752ec5a252ca1e1eb77a5c34b5835d3bAnton Korobeynikov
3489f967c5e4bbeb48caf6d0e62056b3d3fee20bf7cFariborz Jahanian  /// - Global variables with initializers whose order of initialization
3499f967c5e4bbeb48caf6d0e62056b3d3fee20bf7cFariborz Jahanian  /// is set by init_priority attribute.
3504179ddd5752ec5a252ca1e1eb77a5c34b5835d3bAnton Korobeynikov  SmallVector<GlobalInitData, 8> PrioritizedCXXGlobalInits;
3511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
352efb0fa9e11f75af51744a6159530ef7cc8efa24aDaniel Dunbar  /// CXXGlobalDtors - Global destructor functions and arguments that need to
353efb0fa9e11f75af51744a6159530ef7cc8efa24aDaniel Dunbar  /// run on termination.
354810112e28dc839715d17b0a786f23aaa19600ac0Chris Lattner  std::vector<std::pair<llvm::WeakVH,llvm::Constant*> > CXXGlobalDtors;
355efb0fa9e11f75af51744a6159530ef7cc8efa24aDaniel Dunbar
356b6cbe517237c3c223beb064d60d5b49e56d65c06Douglas Gregor  /// \brief The complete set of modules that has been imported.
357b6cbe517237c3c223beb064d60d5b49e56d65c06Douglas Gregor  llvm::SetVector<clang::Module *> ImportedModules;
358b6cbe517237c3c223beb064d60d5b49e56d65c06Douglas Gregor
3593190ca922d3743137e15fe0c525c04b177b9983bReid Kleckner  /// \brief A vector of metadata strings.
3603190ca922d3743137e15fe0c525c04b177b9983bReid Kleckner  SmallVector<llvm::Value *, 16> LinkerOptionsMetadata;
3613190ca922d3743137e15fe0c525c04b177b9983bReid Kleckner
36245c4ea75b235de94f44bf96843624e6a559e4c00Douglas Gregor  /// @name Cache for Objective-C runtime types
36345c4ea75b235de94f44bf96843624e6a559e4c00Douglas Gregor  /// @{
36445c4ea75b235de94f44bf96843624e6a559e4c00Douglas Gregor
365ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump  /// CFConstantStringClassRef - Cached reference to the class for constant
366ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump  /// strings. This value has type int * but is actually an Obj-C class pointer.
367428edb7f7599b4ee44eaad00bb3c330495fc1ad6Fariborz Jahanian  llvm::WeakVH CFConstantStringClassRef;
3681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3694c73307c74764ba99e1379677fe92af72f676531Fariborz Jahanian  /// ConstantStringClassRef - Cached reference to the class for constant
3702bb5ddaff86ee73d2cea7ec1835978afc88a83f0Fariborz Jahanian  /// strings. This value has type int * but is actually an Obj-C class pointer.
371428edb7f7599b4ee44eaad00bb3c330495fc1ad6Fariborz Jahanian  llvm::WeakVH ConstantStringClassRef;
3722bb5ddaff86ee73d2cea7ec1835978afc88a83f0Fariborz Jahanian
37345c4ea75b235de94f44bf96843624e6a559e4c00Douglas Gregor  /// \brief The LLVM type corresponding to NSConstantString.
37445c4ea75b235de94f44bf96843624e6a559e4c00Douglas Gregor  llvm::StructType *NSConstantStringType;
37545c4ea75b235de94f44bf96843624e6a559e4c00Douglas Gregor
3760815b579b31cb3129f732bb7ea36fd6ba6949e98Douglas Gregor  /// \brief The type used to describe the state of a fast enumeration in
3770815b579b31cb3129f732bb7ea36fd6ba6949e98Douglas Gregor  /// Objective-C's for..in loop.
3780815b579b31cb3129f732bb7ea36fd6ba6949e98Douglas Gregor  QualType ObjCFastEnumerationStateType;
3790815b579b31cb3129f732bb7ea36fd6ba6949e98Douglas Gregor
38045c4ea75b235de94f44bf96843624e6a559e4c00Douglas Gregor  /// @}
38145c4ea75b235de94f44bf96843624e6a559e4c00Douglas Gregor
3820d13f6fdbdd6f06e2449b8834dda53334abd399aDavid Chisnall  /// Lazily create the Objective-C runtime
3830d13f6fdbdd6f06e2449b8834dda53334abd399aDavid Chisnall  void createObjCRuntime();
3840d13f6fdbdd6f06e2449b8834dda53334abd399aDavid Chisnall
3858c25fc584ce27d59df9923f153e8a132dde58d04Peter Collingbourne  void createOpenCLRuntime();
3866c0aa5ff6e6253db0f993053599e2a52b5b93b2dPeter Collingbourne  void createCUDARuntime();
3878c25fc584ce27d59df9923f153e8a132dde58d04Peter Collingbourne
388bcf6b98247bd3ac76c5edf706b1087a8d32c0320Rafael Espindola  bool isTriviallyRecursive(const FunctionDecl *F);
389144a31f53b0a97a2c46bfcb1e2a40fa8327b8e89Peter Collingbourne  bool shouldEmitFunction(GlobalDecl GD);
390673431a2986f750b4d8fadb57abf3f00db27bbbdDaniel Dunbar
391673431a2986f750b4d8fadb57abf3f00db27bbbdDaniel Dunbar  /// @name Cache for Blocks Runtime Globals
392673431a2986f750b4d8fadb57abf3f00db27bbbdDaniel Dunbar  /// @{
393673431a2986f750b4d8fadb57abf3f00db27bbbdDaniel Dunbar
394673431a2986f750b4d8fadb57abf3f00db27bbbdDaniel Dunbar  llvm::Constant *NSConcreteGlobalBlock;
395673431a2986f750b4d8fadb57abf3f00db27bbbdDaniel Dunbar  llvm::Constant *NSConcreteStackBlock;
396754b9fbaa13749c61393cc613eec7c79efe60ddfDaniel Dunbar
397673431a2986f750b4d8fadb57abf3f00db27bbbdDaniel Dunbar  llvm::Constant *BlockObjectAssign;
398673431a2986f750b4d8fadb57abf3f00db27bbbdDaniel Dunbar  llvm::Constant *BlockObjectDispose;
399673431a2986f750b4d8fadb57abf3f00db27bbbdDaniel Dunbar
4009cbe4f0ba01ec304e1e3d071c071f7bca33631c0Chris Lattner  llvm::Type *BlockDescriptorType;
4019cbe4f0ba01ec304e1e3d071c071f7bca33631c0Chris Lattner  llvm::Type *GenericBlockLiteralType;
402d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall
403d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall  struct {
404d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall    int GlobalUniqueCount;
405d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall  } Block;
4064f45bc099f2665bc6e4bcbb169aa452390dbf3feWill Dietz
407495cfa46300979642acde8d93a1f21c9291dac98Nadav Rotem  /// void @llvm.lifetime.start(i64 %size, i8* nocapture <ptr>)
408495cfa46300979642acde8d93a1f21c9291dac98Nadav Rotem  llvm::Constant *LifetimeStartFn;
409495cfa46300979642acde8d93a1f21c9291dac98Nadav Rotem
410495cfa46300979642acde8d93a1f21c9291dac98Nadav Rotem  /// void @llvm.lifetime.end(i64 %size, i8* nocapture <ptr>)
411495cfa46300979642acde8d93a1f21c9291dac98Nadav Rotem  llvm::Constant *LifetimeEndFn;
412495cfa46300979642acde8d93a1f21c9291dac98Nadav Rotem
4134904bf4e84cfb48080270ebaa9005327f18ab0e5Fariborz Jahanian  GlobalDecl initializedGlobalDecl;
414d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall
415a967935303e6b36dcc0490073e47fdd5a5eff93ePeter Collingbourne  llvm::SpecialCaseList SanitizerBlacklist;
4164f45bc099f2665bc6e4bcbb169aa452390dbf3feWill Dietz
4174f45bc099f2665bc6e4bcbb169aa452390dbf3feWill Dietz  const SanitizerOptions &SanOpts;
4184f45bc099f2665bc6e4bcbb169aa452390dbf3feWill Dietz
419673431a2986f750b4d8fadb57abf3f00db27bbbdDaniel Dunbar  /// @}
4205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
4212811ccf48d6d898c42cc4cfad37abedb36236d20Chandler Carruth  CodeGenModule(ASTContext &C, const CodeGenOptions &CodeGenOpts,
4223abae0995b5d4faa3d8cfb1f06118d71a60c7dabJohn McCall                llvm::Module &M, const llvm::DataLayout &TD,
4233abae0995b5d4faa3d8cfb1f06118d71a60c7dabJohn McCall                DiagnosticsEngine &Diags);
424815c78fd9ab8bd5dfe8e8a91b8c6a413e2b8c889Ted Kremenek
4252b94fe35edf951a14ecd32b21f7ebcc2e3754c67Chris Lattner  ~CodeGenModule();
426ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump
427815c78fd9ab8bd5dfe8e8a91b8c6a413e2b8c889Ted Kremenek  /// Release - Finalize LLVM code generation.
428815c78fd9ab8bd5dfe8e8a91b8c6a413e2b8c889Ted Kremenek  void Release();
429208ff5e8a073de2a5d15cbe03cab8a4c0d935e28Daniel Dunbar
430208ff5e8a073de2a5d15cbe03cab8a4c0d935e28Daniel Dunbar  /// getObjCRuntime() - Return a reference to the configured
431208ff5e8a073de2a5d15cbe03cab8a4c0d935e28Daniel Dunbar  /// Objective-C runtime.
432ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump  CGObjCRuntime &getObjCRuntime() {
433e926523105dd2604ccd5c101605dea43c5269965Peter Collingbourne    if (!ObjCRuntime) createObjCRuntime();
434e926523105dd2604ccd5c101605dea43c5269965Peter Collingbourne    return *ObjCRuntime;
435208ff5e8a073de2a5d15cbe03cab8a4c0d935e28Daniel Dunbar  }
436ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump
437f3477c13eeaf11b32a41f181398fb5deffd0dd73Sylvestre Ledru  /// hasObjCRuntime() - Return true iff an Objective-C runtime has
438208ff5e8a073de2a5d15cbe03cab8a4c0d935e28Daniel Dunbar  /// been configured.
439e926523105dd2604ccd5c101605dea43c5269965Peter Collingbourne  bool hasObjCRuntime() { return !!ObjCRuntime; }
440208ff5e8a073de2a5d15cbe03cab8a4c0d935e28Daniel Dunbar
4416c0aa5ff6e6253db0f993053599e2a52b5b93b2dPeter Collingbourne  /// getOpenCLRuntime() - Return a reference to the configured OpenCL runtime.
4428c25fc584ce27d59df9923f153e8a132dde58d04Peter Collingbourne  CGOpenCLRuntime &getOpenCLRuntime() {
4438c25fc584ce27d59df9923f153e8a132dde58d04Peter Collingbourne    assert(OpenCLRuntime != 0);
4448c25fc584ce27d59df9923f153e8a132dde58d04Peter Collingbourne    return *OpenCLRuntime;
4458c25fc584ce27d59df9923f153e8a132dde58d04Peter Collingbourne  }
4468c25fc584ce27d59df9923f153e8a132dde58d04Peter Collingbourne
4476c0aa5ff6e6253db0f993053599e2a52b5b93b2dPeter Collingbourne  /// getCUDARuntime() - Return a reference to the configured CUDA runtime.
4486c0aa5ff6e6253db0f993053599e2a52b5b93b2dPeter Collingbourne  CGCUDARuntime &getCUDARuntime() {
4496c0aa5ff6e6253db0f993053599e2a52b5b93b2dPeter Collingbourne    assert(CUDARuntime != 0);
4506c0aa5ff6e6253db0f993053599e2a52b5b93b2dPeter Collingbourne    return *CUDARuntime;
4516c0aa5ff6e6253db0f993053599e2a52b5b93b2dPeter Collingbourne  }
4526c0aa5ff6e6253db0f993053599e2a52b5b93b2dPeter Collingbourne
453f85e193739c953358c865005855253af4f68a497John McCall  ARCEntrypoints &getARCEntrypoints() const {
4544e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie    assert(getLangOpts().ObjCAutoRefCount && ARCData != 0);
455f85e193739c953358c865005855253af4f68a497John McCall    return *ARCData;
456f85e193739c953358c865005855253af4f68a497John McCall  }
457f85e193739c953358c865005855253af4f68a497John McCall
458f85e193739c953358c865005855253af4f68a497John McCall  RREntrypoints &getRREntrypoints() const {
459f85e193739c953358c865005855253af4f68a497John McCall    assert(RRData != 0);
460f85e193739c953358c865005855253af4f68a497John McCall    return *RRData;
461f85e193739c953358c865005855253af4f68a497John McCall  }
462f85e193739c953358c865005855253af4f68a497John McCall
46371cba34b6e2d3fb81860bd2176ab7003eaf2e918Eli Friedman  llvm::Constant *getStaticLocalDeclAddress(const VarDecl *D) {
46471cba34b6e2d3fb81860bd2176ab7003eaf2e918Eli Friedman    return StaticLocalDeclMap[D];
46565ad5a42cca954e070428dcc499b62393aa7a6d3Fariborz Jahanian  }
46663326a53418b4853a83b360ce1dbdb10c5739fc7Fariborz Jahanian  void setStaticLocalDeclAddress(const VarDecl *D,
46771cba34b6e2d3fb81860bd2176ab7003eaf2e918Eli Friedman                                 llvm::Constant *C) {
46871cba34b6e2d3fb81860bd2176ab7003eaf2e918Eli Friedman    StaticLocalDeclMap[D] = C;
46965ad5a42cca954e070428dcc499b62393aa7a6d3Fariborz Jahanian  }
47065ad5a42cca954e070428dcc499b62393aa7a6d3Fariborz Jahanian
471355bba72ca52c4a70ca3c3802412c03a6ec31f24John McCall  llvm::GlobalVariable *getStaticLocalDeclGuardAddress(const VarDecl *D) {
472355bba72ca52c4a70ca3c3802412c03a6ec31f24John McCall    return StaticLocalDeclGuardMap[D];
473355bba72ca52c4a70ca3c3802412c03a6ec31f24John McCall  }
474355bba72ca52c4a70ca3c3802412c03a6ec31f24John McCall  void setStaticLocalDeclGuardAddress(const VarDecl *D,
475355bba72ca52c4a70ca3c3802412c03a6ec31f24John McCall                                      llvm::GlobalVariable *C) {
476355bba72ca52c4a70ca3c3802412c03a6ec31f24John McCall    StaticLocalDeclGuardMap[D] = C;
477355bba72ca52c4a70ca3c3802412c03a6ec31f24John McCall  }
478355bba72ca52c4a70ca3c3802412c03a6ec31f24John McCall
479b08cfb3c5909752c0e501a4e5c31a507a4cc1f72Fariborz Jahanian  llvm::Constant *getAtomicSetterHelperFnMap(QualType Ty) {
480b08cfb3c5909752c0e501a4e5c31a507a4cc1f72Fariborz Jahanian    return AtomicSetterHelperFnMap[Ty];
481cd93b96bc51c255d104095bc6a6d8eac74a84b1eFariborz Jahanian  }
482b08cfb3c5909752c0e501a4e5c31a507a4cc1f72Fariborz Jahanian  void setAtomicSetterHelperFnMap(QualType Ty,
483cd93b96bc51c255d104095bc6a6d8eac74a84b1eFariborz Jahanian                            llvm::Constant *Fn) {
484b08cfb3c5909752c0e501a4e5c31a507a4cc1f72Fariborz Jahanian    AtomicSetterHelperFnMap[Ty] = Fn;
485b08cfb3c5909752c0e501a4e5c31a507a4cc1f72Fariborz Jahanian  }
486b08cfb3c5909752c0e501a4e5c31a507a4cc1f72Fariborz Jahanian
487b08cfb3c5909752c0e501a4e5c31a507a4cc1f72Fariborz Jahanian  llvm::Constant *getAtomicGetterHelperFnMap(QualType Ty) {
488b08cfb3c5909752c0e501a4e5c31a507a4cc1f72Fariborz Jahanian    return AtomicGetterHelperFnMap[Ty];
489b08cfb3c5909752c0e501a4e5c31a507a4cc1f72Fariborz Jahanian  }
490b08cfb3c5909752c0e501a4e5c31a507a4cc1f72Fariborz Jahanian  void setAtomicGetterHelperFnMap(QualType Ty,
491b08cfb3c5909752c0e501a4e5c31a507a4cc1f72Fariborz Jahanian                            llvm::Constant *Fn) {
492b08cfb3c5909752c0e501a4e5c31a507a4cc1f72Fariborz Jahanian    AtomicGetterHelperFnMap[Ty] = Fn;
493cd93b96bc51c255d104095bc6a6d8eac74a84b1eFariborz Jahanian  }
494cd93b96bc51c255d104095bc6a6d8eac74a84b1eFariborz Jahanian
495aa11289f754d220c9c155b68a4f84cdcfcefef6aDevang Patel  CGDebugInfo *getModuleDebugInfo() { return DebugInfo; }
4965de7a0e8800b89780e565c1013e566414f11546aDevang Patel
497b49bd27b334a6c4e3bf9d810a7d5b022578f1194Dan Gohman  llvm::MDNode *getNoObjCARCExceptionsMetadata() {
498b49bd27b334a6c4e3bf9d810a7d5b022578f1194Dan Gohman    if (!NoObjCARCExceptionsMetadata)
499b49bd27b334a6c4e3bf9d810a7d5b022578f1194Dan Gohman      NoObjCARCExceptionsMetadata =
500b49bd27b334a6c4e3bf9d810a7d5b022578f1194Dan Gohman        llvm::MDNode::get(getLLVMContext(),
501b49bd27b334a6c4e3bf9d810a7d5b022578f1194Dan Gohman                          SmallVector<llvm::Value*,1>());
502b49bd27b334a6c4e3bf9d810a7d5b022578f1194Dan Gohman    return NoObjCARCExceptionsMetadata;
503b49bd27b334a6c4e3bf9d810a7d5b022578f1194Dan Gohman  }
504b49bd27b334a6c4e3bf9d810a7d5b022578f1194Dan Gohman
5055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ASTContext &getContext() const { return Context; }
5064e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie  const LangOptions &getLangOpts() const { return LangOpts; }
50764aa4b3ec7e62288e2e66c1935487ece995ca94bJohn McCall  const CodeGenOptions &getCodeGenOpts() const { return CodeGenOpts; }
5085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  llvm::Module &getModule() const { return TheModule; }
509d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie  DiagnosticsEngine &getDiags() const { return Diags; }
51025a6a84cf5067b32c271e3ba078676dee838798dMicah Villmow  const llvm::DataLayout &getDataLayout() const { return TheDataLayout; }
51164aa4b3ec7e62288e2e66c1935487ece995ca94bJohn McCall  const TargetInfo &getTarget() const { return Target; }
51264aa4b3ec7e62288e2e66c1935487ece995ca94bJohn McCall  CGCXXABI &getCXXABI() { return ABI; }
513a1cf15f4680e5cf39e72e28c5ea854fcba792e84Owen Anderson  llvm::LLVMContext &getLLVMContext() { return VMContext; }
51464aa4b3ec7e62288e2e66c1935487ece995ca94bJohn McCall
515bc7fbf0d37b286b37d96b033dfaaabf9c729bca8John McCall  bool shouldUseTBAA() const { return TBAA != 0; }
516bc7fbf0d37b286b37d96b033dfaaabf9c729bca8John McCall
51764aa4b3ec7e62288e2e66c1935487ece995ca94bJohn McCall  const TargetCodeGenInfo &getTargetCodeGenInfo();
51864aa4b3ec7e62288e2e66c1935487ece995ca94bJohn McCall
51964aa4b3ec7e62288e2e66c1935487ece995ca94bJohn McCall  CodeGenTypes &getTypes() { return Types; }
52064aa4b3ec7e62288e2e66c1935487ece995ca94bJohn McCall
52164aa4b3ec7e62288e2e66c1935487ece995ca94bJohn McCall  CodeGenVTables &getVTables() { return VTables; }
52264aa4b3ec7e62288e2e66c1935487ece995ca94bJohn McCall  VTableContext &getVTableContext() { return VTables.getVTableContext(); }
52364aa4b3ec7e62288e2e66c1935487ece995ca94bJohn McCall
5243d5aff5d3036b0ff09d114857cd2276134b3d8c9Dan Gohman  llvm::MDNode *getTBAAInfo(QualType QTy);
5258cb4a070d491ddd671b049110cc8d0accb08b905Kostya Serebryany  llvm::MDNode *getTBAAInfoForVTablePtr();
526b22c7dc707cf3770ff3b5e5f11f11fd0aaa06d9bDan Gohman  llvm::MDNode *getTBAAStructInfo(QualType QTy);
527b37a73d5c6a0c8bb1f6e363d3b53980e4fa0ceadManman Ren  /// Return the MDNode in the type DAG for the given struct type.
528b37a73d5c6a0c8bb1f6e363d3b53980e4fa0ceadManman Ren  llvm::MDNode *getTBAAStructTypeInfo(QualType QTy);
529b37a73d5c6a0c8bb1f6e363d3b53980e4fa0ceadManman Ren  /// Return the path-aware tag for given base type, access node and offset.
530b37a73d5c6a0c8bb1f6e363d3b53980e4fa0ceadManman Ren  llvm::MDNode *getTBAAStructTagInfo(QualType BaseTy, llvm::MDNode *AccessN,
531b37a73d5c6a0c8bb1f6e363d3b53980e4fa0ceadManman Ren                                     uint64_t O);
5323d5aff5d3036b0ff09d114857cd2276134b3d8c9Dan Gohman
533a9b21d22bb9337649723a8477b5cb15f83451e7dRichard Smith  bool isTypeConstant(QualType QTy, bool ExcludeCtorDtor);
534a9b21d22bb9337649723a8477b5cb15f83451e7dRichard Smith
5359eda3abe7e183b05834947391c0cdc291f4ee0d8John McCall  bool isPaddedAtomicType(QualType type);
5369eda3abe7e183b05834947391c0cdc291f4ee0d8John McCall  bool isPaddedAtomicType(const AtomicType *type);
5379eda3abe7e183b05834947391c0cdc291f4ee0d8John McCall
538ca835180412eb4382fe4cc97e9374489b9ad3946Manman Ren  /// Decorate the instruction with a TBAA tag. For scalar TBAA, the tag
539ca835180412eb4382fe4cc97e9374489b9ad3946Manman Ren  /// is the same as the type. For struct-path aware TBAA, the tag
540ca835180412eb4382fe4cc97e9374489b9ad3946Manman Ren  /// is different from the type: base type, access type and offset.
541ca835180412eb4382fe4cc97e9374489b9ad3946Manman Ren  /// When ConvertTypeToTag is true, we create a tag based on the scalar type.
542ca835180412eb4382fe4cc97e9374489b9ad3946Manman Ren  void DecorateInstruction(llvm::Instruction *Inst,
543ca835180412eb4382fe4cc97e9374489b9ad3946Manman Ren                           llvm::MDNode *TBAAInfo,
544ca835180412eb4382fe4cc97e9374489b9ad3946Manman Ren                           bool ConvertTypeToTag = true);
5453d5aff5d3036b0ff09d114857cd2276134b3d8c9Dan Gohman
546bc8d40d85f3fa1e34569834916f18fecaa635152John McCall  /// getSize - Emit the given number of characters as a value of type size_t.
547bc8d40d85f3fa1e34569834916f18fecaa635152John McCall  llvm::ConstantInt *getSize(CharUnits numChars);
548bc8d40d85f3fa1e34569834916f18fecaa635152John McCall
54904d4078425614bf9fd58d606335c1f5f74ee7fa4Daniel Dunbar  /// setGlobalVisibility - Set the visibility for the given LLVM
55004d4078425614bf9fd58d606335c1f5f74ee7fa4Daniel Dunbar  /// GlobalValue.
5510ffeaad72cb335b926b064379be4c9886bbff004Anders Carlsson  void setGlobalVisibility(llvm::GlobalValue *GV, const NamedDecl *D) const;
55204d4078425614bf9fd58d606335c1f5f74ee7fa4Daniel Dunbar
553de981f3ff163bc9ec69e4c5e7316e94276412993Hans Wennborg  /// setTLSMode - Set the TLS mode for the given LLVM GlobalVariable
554de981f3ff163bc9ec69e4c5e7316e94276412993Hans Wennborg  /// for the thread-local variable declaration D.
555de981f3ff163bc9ec69e4c5e7316e94276412993Hans Wennborg  void setTLSMode(llvm::GlobalVariable *GV, const VarDecl &D) const;
556de981f3ff163bc9ec69e4c5e7316e94276412993Hans Wennborg
557fa2e99f72f9bfe2270ea8caf76d0eef11c45259fAnders Carlsson  /// TypeVisibilityKind - The kind of global variable that is passed to
558fa2e99f72f9bfe2270ea8caf76d0eef11c45259fAnders Carlsson  /// setTypeVisibility
559fa2e99f72f9bfe2270ea8caf76d0eef11c45259fAnders Carlsson  enum TypeVisibilityKind {
560fa2e99f72f9bfe2270ea8caf76d0eef11c45259fAnders Carlsson    TVK_ForVTT,
561fa2e99f72f9bfe2270ea8caf76d0eef11c45259fAnders Carlsson    TVK_ForVTable,
562bda0d6bda0f1a08a9fdf3ee4cf550b6b10d454ecJohn McCall    TVK_ForConstructionVTable,
563fa2e99f72f9bfe2270ea8caf76d0eef11c45259fAnders Carlsson    TVK_ForRTTI,
564fa2e99f72f9bfe2270ea8caf76d0eef11c45259fAnders Carlsson    TVK_ForRTTIName
565fa2e99f72f9bfe2270ea8caf76d0eef11c45259fAnders Carlsson  };
566fa2e99f72f9bfe2270ea8caf76d0eef11c45259fAnders Carlsson
567cbfe50224b19119e759802bd0c1463269dffd09eJohn McCall  /// setTypeVisibility - Set the visibility for the given global
568cbfe50224b19119e759802bd0c1463269dffd09eJohn McCall  /// value which holds information about a type.
569cbfe50224b19119e759802bd0c1463269dffd09eJohn McCall  void setTypeVisibility(llvm::GlobalValue *GV, const CXXRecordDecl *D,
570fa2e99f72f9bfe2270ea8caf76d0eef11c45259fAnders Carlsson                         TypeVisibilityKind TVK) const;
571cbfe50224b19119e759802bd0c1463269dffd09eJohn McCall
572c7e98fabd852e9dfa7409b7fc664b87322522c43Anders Carlsson  static llvm::GlobalValue::VisibilityTypes GetLLVMVisibility(Visibility V) {
573c7e98fabd852e9dfa7409b7fc664b87322522c43Anders Carlsson    switch (V) {
574c7e98fabd852e9dfa7409b7fc664b87322522c43Anders Carlsson    case DefaultVisibility:   return llvm::GlobalValue::DefaultVisibility;
575c7e98fabd852e9dfa7409b7fc664b87322522c43Anders Carlsson    case HiddenVisibility:    return llvm::GlobalValue::HiddenVisibility;
576c7e98fabd852e9dfa7409b7fc664b87322522c43Anders Carlsson    case ProtectedVisibility: return llvm::GlobalValue::ProtectedVisibility;
577c7e98fabd852e9dfa7409b7fc664b87322522c43Anders Carlsson    }
578c7e98fabd852e9dfa7409b7fc664b87322522c43Anders Carlsson    llvm_unreachable("unknown visibility!");
579c7e98fabd852e9dfa7409b7fc664b87322522c43Anders Carlsson  }
580c7e98fabd852e9dfa7409b7fc664b87322522c43Anders Carlsson
581d46f98573ba104eda102dd3224b2dca69f1c6336John McCall  llvm::Constant *GetAddrOfGlobal(GlobalDecl GD) {
582d46f98573ba104eda102dd3224b2dca69f1c6336John McCall    if (isa<CXXConstructorDecl>(GD.getDecl()))
583d46f98573ba104eda102dd3224b2dca69f1c6336John McCall      return GetAddrOfCXXConstructor(cast<CXXConstructorDecl>(GD.getDecl()),
584d46f98573ba104eda102dd3224b2dca69f1c6336John McCall                                     GD.getCtorType());
585d46f98573ba104eda102dd3224b2dca69f1c6336John McCall    else if (isa<CXXDestructorDecl>(GD.getDecl()))
586d46f98573ba104eda102dd3224b2dca69f1c6336John McCall      return GetAddrOfCXXDestructor(cast<CXXDestructorDecl>(GD.getDecl()),
587d46f98573ba104eda102dd3224b2dca69f1c6336John McCall                                     GD.getDtorType());
588d46f98573ba104eda102dd3224b2dca69f1c6336John McCall    else if (isa<FunctionDecl>(GD.getDecl()))
589d46f98573ba104eda102dd3224b2dca69f1c6336John McCall      return GetAddrOfFunction(GD);
590d46f98573ba104eda102dd3224b2dca69f1c6336John McCall    else
591d46f98573ba104eda102dd3224b2dca69f1c6336John McCall      return GetAddrOfGlobalVar(cast<VarDecl>(GD.getDecl()));
592d46f98573ba104eda102dd3224b2dca69f1c6336John McCall  }
593d46f98573ba104eda102dd3224b2dca69f1c6336John McCall
59464aa4b3ec7e62288e2e66c1935487ece995ca94bJohn McCall  /// CreateOrReplaceCXXRuntimeVariable - Will return a global variable of the
59564aa4b3ec7e62288e2e66c1935487ece995ca94bJohn McCall  /// given type. If a variable with a different type already exists then a new
5963bd6202ea2d5b5f7c8229cd280a846ae3dcf2355Anders Carlsson  /// variable with the right type will be created and all uses of the old
5973bd6202ea2d5b5f7c8229cd280a846ae3dcf2355Anders Carlsson  /// variable will be replaced with a bitcast to the new variable.
5983bd6202ea2d5b5f7c8229cd280a846ae3dcf2355Anders Carlsson  llvm::GlobalVariable *
599686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  CreateOrReplaceCXXRuntimeVariable(StringRef Name, llvm::Type *Ty,
6003bd6202ea2d5b5f7c8229cd280a846ae3dcf2355Anders Carlsson                                    llvm::GlobalValue::LinkageTypes Linkage);
6013bd6202ea2d5b5f7c8229cd280a846ae3dcf2355Anders Carlsson
6024dc34ebf2a0716bf77ba110dab6777a3fc4397ddPeter Collingbourne  /// GetGlobalVarAddressSpace - Return the address space of the underlying
6034dc34ebf2a0716bf77ba110dab6777a3fc4397ddPeter Collingbourne  /// global variable for D, as determined by its declaration.  Normally this
6044dc34ebf2a0716bf77ba110dab6777a3fc4397ddPeter Collingbourne  /// is the same as the address space of D's type, but in CUDA, address spaces
6054dc34ebf2a0716bf77ba110dab6777a3fc4397ddPeter Collingbourne  /// are associated with declarations, not types.
6064dc34ebf2a0716bf77ba110dab6777a3fc4397ddPeter Collingbourne  unsigned GetGlobalVarAddressSpace(const VarDecl *D, unsigned AddrSpace);
6074dc34ebf2a0716bf77ba110dab6777a3fc4397ddPeter Collingbourne
608ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump  /// GetAddrOfGlobalVar - Return the llvm::Constant for the address of the
609570585c91dee98d7ba8ccf1198c03208ba17966bChris Lattner  /// given global variable.  If Ty is non-null and if the global doesn't exist,
610570585c91dee98d7ba8ccf1198c03208ba17966bChris Lattner  /// then it will be greated with the specified type instead of whatever the
611570585c91dee98d7ba8ccf1198c03208ba17966bChris Lattner  /// normal requested type would be.
612570585c91dee98d7ba8ccf1198c03208ba17966bChris Lattner  llvm::Constant *GetAddrOfGlobalVar(const VarDecl *D,
6132acc6e3feda5e4f7d9009bdcf8b1cd777fecfe2dChris Lattner                                     llvm::Type *Ty = 0);
614bd012ff1fa088181646a784f385b28867372d434Daniel Dunbar
6151de4d4e8cb2e9c88809fea8092bc6e835a5473d2John McCall
61634809507232bc4c3c4840c7d092c7440219fddafChris Lattner  /// GetAddrOfFunction - Return the address of the given function.  If Ty is
61734809507232bc4c3c4840c7d092c7440219fddafChris Lattner  /// non-null, then this function will use the specified type if it has to
61834809507232bc4c3c4840c7d092c7440219fddafChris Lattner  /// create it.
619b4880bab7fc1b61267cfd9a0ad52188e7a828cb3Chris Lattner  llvm::Constant *GetAddrOfFunction(GlobalDecl GD,
6202acc6e3feda5e4f7d9009bdcf8b1cd777fecfe2dChris Lattner                                    llvm::Type *Ty = 0,
6211faa89f9c619e4b2411fab4af7e22ee7a2bd9009Anders Carlsson                                    bool ForVTable = false);
6226143293fa4366ee95d7e47e61bd030a34bf68b55Daniel Dunbar
6231d7088d1d9dc99e5478c0184a3e21cafef2a0b53Anders Carlsson  /// GetAddrOfRTTIDescriptor - Get the address of the RTTI descriptor
6241d7088d1d9dc99e5478c0184a3e21cafef2a0b53Anders Carlsson  /// for the given type.
6259dffe6f51c676c1e423c382c62d1648746e36cd4John McCall  llvm::Constant *GetAddrOfRTTIDescriptor(QualType Ty, bool ForEH = false);
62631b7f52d8c8d459e80d2a72176cc7fcc4b7d8d38Anders Carlsson
627c5f804636e367ef744fd24cf88f7c956a5af0434Nico Weber  /// GetAddrOfUuidDescriptor - Get the address of a uuid descriptor .
628c5f804636e367ef744fd24cf88f7c956a5af0434Nico Weber  llvm::Constant *GetAddrOfUuidDescriptor(const CXXUuidofExpr* E);
629c5f804636e367ef744fd24cf88f7c956a5af0434Nico Weber
63019879c98d964bc67442618510af04e3457219780Anders Carlsson  /// GetAddrOfThunk - Get the address of the thunk for the given global decl.
63184c49e4e4baeb4c30251fd72220efb344b033cf0Anders Carlsson  llvm::Constant *GetAddrOfThunk(GlobalDecl GD, const ThunkInfo &Thunk);
63219879c98d964bc67442618510af04e3457219780Anders Carlsson
6336a836706c40a31c716952b74785102c90fd6afa7Rafael Espindola  /// GetWeakRefReference - Get a reference to the target of VD.
6346a836706c40a31c716952b74785102c90fd6afa7Rafael Espindola  llvm::Constant *GetWeakRefReference(const ValueDecl *VD);
6356a836706c40a31c716952b74785102c90fd6afa7Rafael Espindola
636bb7e17b52ffaa4097b4c4d7935746d23539ffe2aAnders Carlsson  /// GetNonVirtualBaseClassOffset - Returns the offset from a derived class to
637e04d45e05277ee04997fe59b1d194503f484c846Anders Carlsson  /// a class. Returns null if the offset is 0.
638a04efdf635d35d88e65041fad007225d8c8d64a5Anders Carlsson  llvm::Constant *
639a04efdf635d35d88e65041fad007225d8c8d64a5Anders Carlsson  GetNonVirtualBaseClassOffset(const CXXRecordDecl *ClassDecl,
640f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                               CastExpr::path_const_iterator PathBegin,
641f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                               CastExpr::path_const_iterator PathEnd);
642d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall
643f0c11f7e6848f023ced6a5b51399ba787c7d4d0bJohn McCall  /// A pair of helper functions for a __block variable.
644f0c11f7e6848f023ced6a5b51399ba787c7d4d0bJohn McCall  class ByrefHelpers : public llvm::FoldingSetNode {
645f0c11f7e6848f023ced6a5b51399ba787c7d4d0bJohn McCall  public:
646f0c11f7e6848f023ced6a5b51399ba787c7d4d0bJohn McCall    llvm::Constant *CopyHelper;
647f0c11f7e6848f023ced6a5b51399ba787c7d4d0bJohn McCall    llvm::Constant *DisposeHelper;
648f0c11f7e6848f023ced6a5b51399ba787c7d4d0bJohn McCall
649f0c11f7e6848f023ced6a5b51399ba787c7d4d0bJohn McCall    /// The alignment of the field.  This is important because
650f0c11f7e6848f023ced6a5b51399ba787c7d4d0bJohn McCall    /// different offsets to the field within the byref struct need to
651f0c11f7e6848f023ced6a5b51399ba787c7d4d0bJohn McCall    /// have different helper functions.
652f0c11f7e6848f023ced6a5b51399ba787c7d4d0bJohn McCall    CharUnits Alignment;
653f0c11f7e6848f023ced6a5b51399ba787c7d4d0bJohn McCall
654f0c11f7e6848f023ced6a5b51399ba787c7d4d0bJohn McCall    ByrefHelpers(CharUnits alignment) : Alignment(alignment) {}
655f0c11f7e6848f023ced6a5b51399ba787c7d4d0bJohn McCall    virtual ~ByrefHelpers();
656f0c11f7e6848f023ced6a5b51399ba787c7d4d0bJohn McCall
657f0c11f7e6848f023ced6a5b51399ba787c7d4d0bJohn McCall    void Profile(llvm::FoldingSetNodeID &id) const {
658f0c11f7e6848f023ced6a5b51399ba787c7d4d0bJohn McCall      id.AddInteger(Alignment.getQuantity());
659f0c11f7e6848f023ced6a5b51399ba787c7d4d0bJohn McCall      profileImpl(id);
660f0c11f7e6848f023ced6a5b51399ba787c7d4d0bJohn McCall    }
661f0c11f7e6848f023ced6a5b51399ba787c7d4d0bJohn McCall    virtual void profileImpl(llvm::FoldingSetNodeID &id) const = 0;
662f0c11f7e6848f023ced6a5b51399ba787c7d4d0bJohn McCall
663f0c11f7e6848f023ced6a5b51399ba787c7d4d0bJohn McCall    virtual bool needsCopy() const { return true; }
664f0c11f7e6848f023ced6a5b51399ba787c7d4d0bJohn McCall    virtual void emitCopy(CodeGenFunction &CGF,
665f0c11f7e6848f023ced6a5b51399ba787c7d4d0bJohn McCall                          llvm::Value *dest, llvm::Value *src) = 0;
666f0c11f7e6848f023ced6a5b51399ba787c7d4d0bJohn McCall
667f0c11f7e6848f023ced6a5b51399ba787c7d4d0bJohn McCall    virtual bool needsDispose() const { return true; }
668f0c11f7e6848f023ced6a5b51399ba787c7d4d0bJohn McCall    virtual void emitDispose(CodeGenFunction &CGF, llvm::Value *field) = 0;
669f0c11f7e6848f023ced6a5b51399ba787c7d4d0bJohn McCall  };
670f0c11f7e6848f023ced6a5b51399ba787c7d4d0bJohn McCall
671f0c11f7e6848f023ced6a5b51399ba787c7d4d0bJohn McCall  llvm::FoldingSet<ByrefHelpers> ByrefHelpersCache;
672d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall
6738178df3b39ab923ff5d24538812628abee33df79John McCall  /// getUniqueBlockCount - Fetches the global unique block count.
6748178df3b39ab923ff5d24538812628abee33df79John McCall  int getUniqueBlockCount() { return ++Block.GlobalUniqueCount; }
6754904bf4e84cfb48080270ebaa9005327f18ab0e5Fariborz Jahanian
676d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall  /// getBlockDescriptorType - Fetches the type of a generic block
677d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall  /// descriptor.
6789cbe4f0ba01ec304e1e3d071c071f7bca33631c0Chris Lattner  llvm::Type *getBlockDescriptorType();
679d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall
680d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall  /// getGenericBlockLiteralType - The type of a generic block literal.
6819cbe4f0ba01ec304e1e3d071c071f7bca33631c0Chris Lattner  llvm::Type *getGenericBlockLiteralType();
682d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall
683d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall  /// GetAddrOfGlobalBlock - Gets the address of a block which
684d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall  /// requires no captures.
685d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall  llvm::Constant *GetAddrOfGlobalBlock(const BlockExpr *BE, const char *);
686a04efdf635d35d88e65041fad007225d8c8d64a5Anders Carlsson
687ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump  /// GetAddrOfConstantCFString - Return a pointer to a constant CFString object
688ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump  /// for the given string.
6898d4141f83d9de379547cf05bd75d4c6cf894b189Steve Naroff  llvm::Constant *GetAddrOfConstantCFString(const StringLiteral *Literal);
69033e982bf782d851bfe5767acb1336fcf3419ac6bFariborz Jahanian
6914c73307c74764ba99e1379677fe92af72f676531Fariborz Jahanian  /// GetAddrOfConstantString - Return a pointer to a constant NSString object
6924c73307c74764ba99e1379677fe92af72f676531Fariborz Jahanian  /// for the given string. Or a user defined String object as defined via
6934c73307c74764ba99e1379677fe92af72f676531Fariborz Jahanian  /// -fconstant-string-class=class_name option.
6944c73307c74764ba99e1379677fe92af72f676531Fariborz Jahanian  llvm::Constant *GetAddrOfConstantString(const StringLiteral *Literal);
695a7ad98ff0919d6a24ea7c46634ea29bea551c1a0Chris Lattner
69664f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman  /// GetConstantArrayFromStringLiteral - Return a constant array for the given
69764f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman  /// string.
69864f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman  llvm::Constant *GetConstantArrayFromStringLiteral(const StringLiteral *E);
69964f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman
700ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump  /// GetAddrOfConstantStringFromLiteral - Return a pointer to a constant array
701ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump  /// for the given string literal.
7026143293fa4366ee95d7e47e61bd030a34bf68b55Daniel Dunbar  llvm::Constant *GetAddrOfConstantStringFromLiteral(const StringLiteral *S);
7031e04976fc2611d8cc06986a81deed4c42183b870Daniel Dunbar
704eaf2bb89eb2aad3b80673de30febe52df43c10ecChris Lattner  /// GetAddrOfConstantStringFromObjCEncode - Return a pointer to a constant
705eaf2bb89eb2aad3b80673de30febe52df43c10ecChris Lattner  /// array for the given ObjCEncodeExpr node.
706eaf2bb89eb2aad3b80673de30febe52df43c10ecChris Lattner  llvm::Constant *GetAddrOfConstantStringFromObjCEncode(const ObjCEncodeExpr *);
7071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7086143293fa4366ee95d7e47e61bd030a34bf68b55Daniel Dunbar  /// GetAddrOfConstantString - Returns a pointer to a character array
709ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump  /// containing the literal. This contents are exactly that of the given
710ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump  /// string, i.e. it will not be null terminated automatically; see
711ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump  /// GetAddrOfConstantCString. Note that whether the result is actually a
712ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump  /// pointer to an LLVM constant depends on Feature.WriteableStrings.
7136143293fa4366ee95d7e47e61bd030a34bf68b55Daniel Dunbar  ///
7146143293fa4366ee95d7e47e61bd030a34bf68b55Daniel Dunbar  /// The result has pointer to array type.
7155fabf9dbee29464bcd06cd09f8e569d1b850f948Daniel Dunbar  ///
7165fabf9dbee29464bcd06cd09f8e569d1b850f948Daniel Dunbar  /// \param GlobalName If provided, the name to use for the global
7175fabf9dbee29464bcd06cd09f8e569d1b850f948Daniel Dunbar  /// (if one is created).
718686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  llvm::Constant *GetAddrOfConstantString(StringRef Str,
719a5e19c6b2554f6d9c4b9850d4dbbbfa3643282e5John McCall                                          const char *GlobalName=0,
7206b20351a1d6178addfaa86716aaba36f2e9ea188Ulrich Weigand                                          unsigned Alignment=0);
7216143293fa4366ee95d7e47e61bd030a34bf68b55Daniel Dunbar
722ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump  /// GetAddrOfConstantCString - Returns a pointer to a character array
723ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump  /// containing the literal and a terminating '\0' character. The result has
724ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump  /// pointer to array type.
7255fabf9dbee29464bcd06cd09f8e569d1b850f948Daniel Dunbar  ///
726ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump  /// \param GlobalName If provided, the name to use for the global (if one is
727ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump  /// created).
7285fabf9dbee29464bcd06cd09f8e569d1b850f948Daniel Dunbar  llvm::Constant *GetAddrOfConstantCString(const std::string &str,
729a5e19c6b2554f6d9c4b9850d4dbbbfa3643282e5John McCall                                           const char *GlobalName=0,
7306b20351a1d6178addfaa86716aaba36f2e9ea188Ulrich Weigand                                           unsigned Alignment=0);
7317401cf524cdb7aad4951d8727d280f8b271af5a2Richard Smith
7327401cf524cdb7aad4951d8727d280f8b271af5a2Richard Smith  /// GetAddrOfConstantCompoundLiteral - Returns a pointer to a constant global
7337401cf524cdb7aad4951d8727d280f8b271af5a2Richard Smith  /// variable for the given file-scope compound literal expression.
7347401cf524cdb7aad4951d8727d280f8b271af5a2Richard Smith  llvm::Constant *GetAddrOfConstantCompoundLiteral(const CompoundLiteralExpr*E);
735211c8ddb5b500ed84833751363d0cfe1115f4dd3Richard Smith
736211c8ddb5b500ed84833751363d0cfe1115f4dd3Richard Smith  /// \brief Returns a pointer to a global variable representing a temporary
737211c8ddb5b500ed84833751363d0cfe1115f4dd3Richard Smith  /// with static or thread storage duration.
738211c8ddb5b500ed84833751363d0cfe1115f4dd3Richard Smith  llvm::Constant *GetAddrOfGlobalTemporary(const MaterializeTemporaryExpr *E,
739211c8ddb5b500ed84833751363d0cfe1115f4dd3Richard Smith                                           const Expr *Inner);
740211c8ddb5b500ed84833751363d0cfe1115f4dd3Richard Smith
7410815b579b31cb3129f732bb7ea36fd6ba6949e98Douglas Gregor  /// \brief Retrieve the record type that describes the state of an
7420815b579b31cb3129f732bb7ea36fd6ba6949e98Douglas Gregor  /// Objective-C fast enumeration loop (for..in).
7430815b579b31cb3129f732bb7ea36fd6ba6949e98Douglas Gregor  QualType getObjCFastEnumerationStateType();
7440815b579b31cb3129f732bb7ea36fd6ba6949e98Douglas Gregor
745363c184139e26ea38223b477ad64ee67b22bb9a7Anders Carlsson  /// GetAddrOfCXXConstructor - Return the address of the constructor of the
746363c184139e26ea38223b477ad64ee67b22bb9a7Anders Carlsson  /// given type.
7471f6f961293da9c2b1c23da2411c1b439a9502ed0John McCall  llvm::GlobalValue *GetAddrOfCXXConstructor(const CXXConstructorDecl *ctor,
7481f6f961293da9c2b1c23da2411c1b439a9502ed0John McCall                                             CXXCtorType ctorType,
7491f6f961293da9c2b1c23da2411c1b439a9502ed0John McCall                                             const CGFunctionInfo *fnInfo = 0);
75027ae53665f8b00fe4ba21da0fa79a4ce6e0b6cd5Anders Carlsson
75127ae53665f8b00fe4ba21da0fa79a4ce6e0b6cd5Anders Carlsson  /// GetAddrOfCXXDestructor - Return the address of the constructor of the
75227ae53665f8b00fe4ba21da0fa79a4ce6e0b6cd5Anders Carlsson  /// given type.
7531f6f961293da9c2b1c23da2411c1b439a9502ed0John McCall  llvm::GlobalValue *GetAddrOfCXXDestructor(const CXXDestructorDecl *dtor,
7541f6f961293da9c2b1c23da2411c1b439a9502ed0John McCall                                            CXXDtorType dtorType,
755a4130baad9d10b7feabb7e003da53424e986d269Reid Kleckner                                            const CGFunctionInfo *fnInfo = 0,
756a4130baad9d10b7feabb7e003da53424e986d269Reid Kleckner                                            llvm::FunctionType *fnType = 0);
7571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
75841071debe9b8887449c3f2ee0dd7124ed47bdda8Daniel Dunbar  /// getBuiltinLibFunction - Given a builtin id for a function like
75941071debe9b8887449c3f2ee0dd7124ed47bdda8Daniel Dunbar  /// "__builtin_fabsf", return a Function* for "fabsf".
76034771b594ca8cdf8cd2e40b27170efa4ed2833c5Daniel Dunbar  llvm::Value *getBuiltinLibFunction(const FunctionDecl *FD,
76134771b594ca8cdf8cd2e40b27170efa4ed2833c5Daniel Dunbar                                     unsigned BuiltinID);
7626143293fa4366ee95d7e47e61bd030a34bf68b55Daniel Dunbar
7635543169296beeb183b9c9392debc774fcf493eebDmitri Gribenko  llvm::Function *getIntrinsic(unsigned IID, ArrayRef<llvm::Type*> Tys = None);
764bd012ff1fa088181646a784f385b28867372d434Daniel Dunbar
76541071debe9b8887449c3f2ee0dd7124ed47bdda8Daniel Dunbar  /// EmitTopLevelDecl - Emit code for a single top level declaration.
76641071debe9b8887449c3f2ee0dd7124ed47bdda8Daniel Dunbar  void EmitTopLevelDecl(Decl *D);
767bd012ff1fa088181646a784f385b28867372d434Daniel Dunbar
768025039377d7247620750205dbd61ca1ba336f7e0Rafael Espindola  /// HandleCXXStaticMemberVarInstantiation - Tell the consumer that this
769025039377d7247620750205dbd61ca1ba336f7e0Rafael Espindola  // variable has been instantiated.
770025039377d7247620750205dbd61ca1ba336f7e0Rafael Espindola  void HandleCXXStaticMemberVarInstantiation(VarDecl *VD);
771234fe654a3dd2888be42ae5db34db96c5c2c4ba3Rafael Espindola
7720024937dbb23752f606846f4a12aafc712bcde33Richard Smith  /// \brief If the declaration has internal linkage but is inside an
7730024937dbb23752f606846f4a12aafc712bcde33Richard Smith  /// extern "C" linkage specification, prepare to emit an alias for it
7740024937dbb23752f606846f4a12aafc712bcde33Richard Smith  /// to the expected name.
7750024937dbb23752f606846f4a12aafc712bcde33Richard Smith  template<typename SomeDecl>
7760024937dbb23752f606846f4a12aafc712bcde33Richard Smith  void MaybeHandleStaticInExternC(const SomeDecl *D, llvm::GlobalValue *GV);
7770024937dbb23752f606846f4a12aafc712bcde33Richard Smith
7780269871c9cba493f76237175ab60313406f3bafaDaniel Dunbar  /// AddUsedGlobal - Add a global which should be forced to be
7790269871c9cba493f76237175ab60313406f3bafaDaniel Dunbar  /// present in the object file; these are emitted to the llvm.used
7800269871c9cba493f76237175ab60313406f3bafaDaniel Dunbar  /// metadata global.
7810269871c9cba493f76237175ab60313406f3bafaDaniel Dunbar  void AddUsedGlobal(llvm::GlobalValue *GV);
7820269871c9cba493f76237175ab60313406f3bafaDaniel Dunbar
783efb0fa9e11f75af51744a6159530ef7cc8efa24aDaniel Dunbar  /// AddCXXDtorEntry - Add a destructor and object to add to the C++ global
784efb0fa9e11f75af51744a6159530ef7cc8efa24aDaniel Dunbar  /// destructor function.
785810112e28dc839715d17b0a786f23aaa19600ac0Chris Lattner  void AddCXXDtorEntry(llvm::Constant *DtorFn, llvm::Constant *Object) {
786810112e28dc839715d17b0a786f23aaa19600ac0Chris Lattner    CXXGlobalDtors.push_back(std::make_pair(DtorFn, Object));
787810112e28dc839715d17b0a786f23aaa19600ac0Chris Lattner  }
788efb0fa9e11f75af51744a6159530ef7cc8efa24aDaniel Dunbar
78974391b48b4791cded373683a3baf67314f358d50Chris Lattner  /// CreateRuntimeFunction - Create a new runtime function with the specified
79074391b48b4791cded373683a3baf67314f358d50Chris Lattner  /// type and name.
7912acc6e3feda5e4f7d9009bdcf8b1cd777fecfe2dChris Lattner  llvm::Constant *CreateRuntimeFunction(llvm::FunctionType *Ty,
792686775deca8b8685eb90801495880e3abdd844c2Chris Lattner                                        StringRef Name,
793c4c62fd78a4728c9e4d4df14911a2ced9bdd2031Bill Wendling                                        llvm::AttributeSet ExtraAttrs =
794c4c62fd78a4728c9e4d4df14911a2ced9bdd2031Bill Wendling                                          llvm::AttributeSet());
79574391b48b4791cded373683a3baf67314f358d50Chris Lattner  /// CreateRuntimeVariable - Create a new runtime global variable with the
79674391b48b4791cded373683a3baf67314f358d50Chris Lattner  /// specified type and name.
7972acc6e3feda5e4f7d9009bdcf8b1cd777fecfe2dChris Lattner  llvm::Constant *CreateRuntimeVariable(llvm::Type *Ty,
798686775deca8b8685eb90801495880e3abdd844c2Chris Lattner                                        StringRef Name);
799f1968f28869f4e0675450ae39c478a37c5b9abd6Daniel Dunbar
800673431a2986f750b4d8fadb57abf3f00db27bbbdDaniel Dunbar  ///@name Custom Blocks Runtime Interfaces
801673431a2986f750b4d8fadb57abf3f00db27bbbdDaniel Dunbar  ///@{
802673431a2986f750b4d8fadb57abf3f00db27bbbdDaniel Dunbar
803673431a2986f750b4d8fadb57abf3f00db27bbbdDaniel Dunbar  llvm::Constant *getNSConcreteGlobalBlock();
804673431a2986f750b4d8fadb57abf3f00db27bbbdDaniel Dunbar  llvm::Constant *getNSConcreteStackBlock();
805673431a2986f750b4d8fadb57abf3f00db27bbbdDaniel Dunbar  llvm::Constant *getBlockObjectAssign();
806673431a2986f750b4d8fadb57abf3f00db27bbbdDaniel Dunbar  llvm::Constant *getBlockObjectDispose();
807673431a2986f750b4d8fadb57abf3f00db27bbbdDaniel Dunbar
808673431a2986f750b4d8fadb57abf3f00db27bbbdDaniel Dunbar  ///@}
809673431a2986f750b4d8fadb57abf3f00db27bbbdDaniel Dunbar
810495cfa46300979642acde8d93a1f21c9291dac98Nadav Rotem  llvm::Constant *getLLVMLifetimeStartFn();
811495cfa46300979642acde8d93a1f21c9291dac98Nadav Rotem  llvm::Constant *getLLVMLifetimeEndFn();
812495cfa46300979642acde8d93a1f21c9291dac98Nadav Rotem
813e80d56771736c85fd8365c394a6731923b17e91dDevang Patel  // UpdateCompleteType - Make sure that this type is translated.
814e80d56771736c85fd8365c394a6731923b17e91dDevang Patel  void UpdateCompletedType(const TagDecl *TD);
815d60f2fbf69df08e952377b498c036f269395024dDaniel Dunbar
8165808ce43f8d7e71f5acacc9ca320268c4f37565aJohn McCall  llvm::Constant *getMemberPointerConstant(const UnaryOperator *e);
8175808ce43f8d7e71f5acacc9ca320268c4f37565aJohn McCall
8182d6a5670465cb3f1d811695a9f23e372508240d2Richard Smith  /// EmitConstantInit - Try to emit the initializer for the given declaration
8192d6a5670465cb3f1d811695a9f23e372508240d2Richard Smith  /// as a constant; returns 0 if the expression cannot be emitted as a
8202d6a5670465cb3f1d811695a9f23e372508240d2Richard Smith  /// constant.
8212d6a5670465cb3f1d811695a9f23e372508240d2Richard Smith  llvm::Constant *EmitConstantInit(const VarDecl &D, CodeGenFunction *CGF = 0);
8222d6a5670465cb3f1d811695a9f23e372508240d2Richard Smith
823d60f2fbf69df08e952377b498c036f269395024dDaniel Dunbar  /// EmitConstantExpr - Try to emit the given expression as a
824d60f2fbf69df08e952377b498c036f269395024dDaniel Dunbar  /// constant; returns 0 if the expression cannot be emitted as a
825d60f2fbf69df08e952377b498c036f269395024dDaniel Dunbar  /// constant.
826e9352cc9818ba59e7cf88500ef048991c90f3821Anders Carlsson  llvm::Constant *EmitConstantExpr(const Expr *E, QualType DestType,
827e9352cc9818ba59e7cf88500ef048991c90f3821Anders Carlsson                                   CodeGenFunction *CGF = 0);
828d60f2fbf69df08e952377b498c036f269395024dDaniel Dunbar
829a3ca41f0c2bd1c4a752df88b283332f3b757d21eRichard Smith  /// EmitConstantValue - Emit the given constant value as a constant, in the
830a3ca41f0c2bd1c4a752df88b283332f3b757d21eRichard Smith  /// type's scalar representation.
8312d6a5670465cb3f1d811695a9f23e372508240d2Richard Smith  llvm::Constant *EmitConstantValue(const APValue &Value, QualType DestType,
8322d6a5670465cb3f1d811695a9f23e372508240d2Richard Smith                                    CodeGenFunction *CGF = 0);
8332d6a5670465cb3f1d811695a9f23e372508240d2Richard Smith
834a3ca41f0c2bd1c4a752df88b283332f3b757d21eRichard Smith  /// EmitConstantValueForMemory - Emit the given constant value as a constant,
835a3ca41f0c2bd1c4a752df88b283332f3b757d21eRichard Smith  /// in the type's memory representation.
836a3ca41f0c2bd1c4a752df88b283332f3b757d21eRichard Smith  llvm::Constant *EmitConstantValueForMemory(const APValue &Value,
837a3ca41f0c2bd1c4a752df88b283332f3b757d21eRichard Smith                                             QualType DestType,
838a3ca41f0c2bd1c4a752df88b283332f3b757d21eRichard Smith                                             CodeGenFunction *CGF = 0);
839a3ca41f0c2bd1c4a752df88b283332f3b757d21eRichard Smith
8400f59312e7b625fa5821a63db65377d4b3b667e99Eli Friedman  /// EmitNullConstant - Return the result of value-initializing the given
8410f59312e7b625fa5821a63db65377d4b3b667e99Eli Friedman  /// type, i.e. a null expression of the given type.  This is usually,
8420f59312e7b625fa5821a63db65377d4b3b667e99Eli Friedman  /// but not always, an LLVM null constant.
8430f59312e7b625fa5821a63db65377d4b3b667e99Eli Friedman  llvm::Constant *EmitNullConstant(QualType T);
8440f59312e7b625fa5821a63db65377d4b3b667e99Eli Friedman
8452ed7cb649aa709b875c519f4a980a1e2b5712370Eli Friedman  /// EmitNullConstantForBase - Return a null constant appropriate for
8462ed7cb649aa709b875c519f4a980a1e2b5712370Eli Friedman  /// zero-initializing a base class with the given type.  This is usually,
8472ed7cb649aa709b875c519f4a980a1e2b5712370Eli Friedman  /// but not always, an LLVM null constant.
8482ed7cb649aa709b875c519f4a980a1e2b5712370Eli Friedman  llvm::Constant *EmitNullConstantForBase(const CXXRecordDecl *Record);
8492ed7cb649aa709b875c519f4a980a1e2b5712370Eli Friedman
85032096695c76033a6b0b1747c439f7378a11e8312John McCall  /// Error - Emit a general error that something can't be done.
8510f30a12ce7b3d4d86c9ca9072f587da77c8eef34Chandler Carruth  void Error(SourceLocation loc, StringRef error);
85232096695c76033a6b0b1747c439f7378a11e8312John McCall
853488e993a135ce700b982bf099c3d6b856301d642Daniel Dunbar  /// ErrorUnsupported - Print out an error that codegen doesn't support the
85490df4b6661968a84bf64baee489bb2f6d948fcc1Daniel Dunbar  /// specified stmt yet.
855ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump  /// \param OmitOnError - If true, then this error should only be emitted if no
856ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump  /// other errors have been reported.
857ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump  void ErrorUnsupported(const Stmt *S, const char *Type,
85890df4b6661968a84bf64baee489bb2f6d948fcc1Daniel Dunbar                        bool OmitOnError=false);
859ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump
860488e993a135ce700b982bf099c3d6b856301d642Daniel Dunbar  /// ErrorUnsupported - Print out an error that codegen doesn't support the
861c6fdc34ac0183bfa03d65f317c78b7bdac52897eChris Lattner  /// specified decl yet.
862ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump  /// \param OmitOnError - If true, then this error should only be emitted if no
863ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump  /// other errors have been reported.
86490df4b6661968a84bf64baee489bb2f6d948fcc1Daniel Dunbar  void ErrorUnsupported(const Decl *D, const char *Type,
86590df4b6661968a84bf64baee489bb2f6d948fcc1Daniel Dunbar                        bool OmitOnError=false);
8664f8d123e3e2c260de3377208106ddba87cee28b4Dan Gohman
8670e4f40e1bbc4dce16bbb9870300a435419f1b3d5Daniel Dunbar  /// SetInternalFunctionAttributes - Set the attributes on the LLVM
8680e4f40e1bbc4dce16bbb9870300a435419f1b3d5Daniel Dunbar  /// function for the given decl and function info. This applies
8690e4f40e1bbc4dce16bbb9870300a435419f1b3d5Daniel Dunbar  /// attributes necessary for handling the ABI as well as user
8700e4f40e1bbc4dce16bbb9870300a435419f1b3d5Daniel Dunbar  /// specified attributes like section.
8710e4f40e1bbc4dce16bbb9870300a435419f1b3d5Daniel Dunbar  void SetInternalFunctionAttributes(const Decl *D, llvm::Function *F,
8720e4f40e1bbc4dce16bbb9870300a435419f1b3d5Daniel Dunbar                                     const CGFunctionInfo &FI);
873f80519b919a348db004fba18530706314d1ebfb5Daniel Dunbar
8747dbd8197040313d796282d4af06eccdf8a17319cDaniel Dunbar  /// SetLLVMFunctionAttributes - Set the LLVM function attributes
8757dbd8197040313d796282d4af06eccdf8a17319cDaniel Dunbar  /// (sext, zext, etc).
8767dbd8197040313d796282d4af06eccdf8a17319cDaniel Dunbar  void SetLLVMFunctionAttributes(const Decl *D,
8777dbd8197040313d796282d4af06eccdf8a17319cDaniel Dunbar                                 const CGFunctionInfo &Info,
8787dbd8197040313d796282d4af06eccdf8a17319cDaniel Dunbar                                 llvm::Function *F);
879b768807c49a1c7085def099b848631856af766faDaniel Dunbar
8807c65e990e9f0dafaf9adbc59b766dcc23eaee845Daniel Dunbar  /// SetLLVMFunctionAttributesForDefinition - Set the LLVM function attributes
8817c65e990e9f0dafaf9adbc59b766dcc23eaee845Daniel Dunbar  /// which only apply to a function definintion.
8827c65e990e9f0dafaf9adbc59b766dcc23eaee845Daniel Dunbar  void SetLLVMFunctionAttributesForDefinition(const Decl *D, llvm::Function *F);
8837c65e990e9f0dafaf9adbc59b766dcc23eaee845Daniel Dunbar
884f3477c13eeaf11b32a41f181398fb5deffd0dd73Sylvestre Ledru  /// ReturnTypeUsesSRet - Return true iff the given type uses 'sret' when used
885ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump  /// as a return type.
886dacf9dda17346c628fdd8c5df53c681738db0dc5Daniel Dunbar  bool ReturnTypeUsesSRet(const CGFunctionInfo &FI);
887dacf9dda17346c628fdd8c5df53c681738db0dc5Daniel Dunbar
888f3477c13eeaf11b32a41f181398fb5deffd0dd73Sylvestre Ledru  /// ReturnTypeUsesFPRet - Return true iff the given type uses 'fpret' when
889eea64802558cc398571938b1f28cda1d4fa79ec3Anders Carlsson  /// used as a return type.
890dacf9dda17346c628fdd8c5df53c681738db0dc5Daniel Dunbar  bool ReturnTypeUsesFPRet(QualType ResultType);
891b768807c49a1c7085def099b848631856af766faDaniel Dunbar
892f3477c13eeaf11b32a41f181398fb5deffd0dd73Sylvestre Ledru  /// ReturnTypeUsesFP2Ret - Return true iff the given type uses 'fp2ret' when
893eea64802558cc398571938b1f28cda1d4fa79ec3Anders Carlsson  /// used as a return type.
894eea64802558cc398571938b1f28cda1d4fa79ec3Anders Carlsson  bool ReturnTypeUsesFP2Ret(QualType ResultType);
895eea64802558cc398571938b1f28cda1d4fa79ec3Anders Carlsson
896ca6408c3176783f0b29da4679a08512aa05f0c73Daniel Dunbar  /// ConstructAttributeList - Get the LLVM attributes and calling convention to
897ca6408c3176783f0b29da4679a08512aa05f0c73Daniel Dunbar  /// use for a particular function type.
898ca6408c3176783f0b29da4679a08512aa05f0c73Daniel Dunbar  ///
899ca6408c3176783f0b29da4679a08512aa05f0c73Daniel Dunbar  /// \param Info - The function type information.
900ca6408c3176783f0b29da4679a08512aa05f0c73Daniel Dunbar  /// \param TargetDecl - The decl these attributes are being constructed
901ca6408c3176783f0b29da4679a08512aa05f0c73Daniel Dunbar  /// for. If supplied the attributes applied to this decl may contribute to the
902ca6408c3176783f0b29da4679a08512aa05f0c73Daniel Dunbar  /// function attributes and calling convention.
903ca6408c3176783f0b29da4679a08512aa05f0c73Daniel Dunbar  /// \param PAL [out] - On return, the attribute list to use.
904ca6408c3176783f0b29da4679a08512aa05f0c73Daniel Dunbar  /// \param CallingConv [out] - On return, the LLVM calling convention to use.
90588b5396b0897f28d22ae3debf4a0d97b33b6c362Daniel Dunbar  void ConstructAttributeList(const CGFunctionInfo &Info,
90688b5396b0897f28d22ae3debf4a0d97b33b6c362Daniel Dunbar                              const Decl *TargetDecl,
907ca6408c3176783f0b29da4679a08512aa05f0c73Daniel Dunbar                              AttributeListType &PAL,
90894236e7393d5cd4acbc5f0b503d23bbe78d9aeecBill Wendling                              unsigned &CallingConv,
90994236e7393d5cd4acbc5f0b503d23bbe78d9aeecBill Wendling                              bool AttrOnCallSite);
910b768807c49a1c7085def099b848631856af766faDaniel Dunbar
911686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  StringRef getMangledName(GlobalDecl GD);
91214110477887e3dc168ffc6c191e72d705051f99ePeter Collingbourne  void getBlockMangledName(GlobalDecl GD, MangleBuffer &Buffer,
91314110477887e3dc168ffc6c191e72d705051f99ePeter Collingbourne                           const BlockDecl *BD);
914b6c8c8bd8d362c8a6cdb767415b0d21e62b77eb2Douglas Gregor
915b6c8c8bd8d362c8a6cdb767415b0d21e62b77eb2Douglas Gregor  void EmitTentativeDefinition(const VarDecl *D);
916f121677b6bbbf4e4a51ee7a1120b77adf187bad4Mike Stump
9176fb745bdf1ff1e32caf07e42093a7920726892c1Douglas Gregor  void EmitVTable(CXXRecordDecl *Class, bool DefinitionRequired);
9186fb745bdf1ff1e32caf07e42093a7920726892c1Douglas Gregor
9193190ca922d3743137e15fe0c525c04b177b9983bReid Kleckner  /// \brief Appends Opts to the "Linker Options" metadata value.
9203190ca922d3743137e15fe0c525c04b177b9983bReid Kleckner  void AppendLinkerOptions(StringRef Opts);
9213190ca922d3743137e15fe0c525c04b177b9983bReid Kleckner
922785f1e7e0631f34d5bbbed9d10e90d56d838f722Benjamin Kramer  /// \brief Appends a detect mismatch command to the linker options.
923a7ff62f9443efa3b13a28a1e566d4625b15b8553Aaron Ballman  void AddDetectMismatch(StringRef Name, StringRef Value);
924a7ff62f9443efa3b13a28a1e566d4625b15b8553Aaron Ballman
9253190ca922d3743137e15fe0c525c04b177b9983bReid Kleckner  /// \brief Appends a dependent lib to the "Linker Options" metadata value.
9263190ca922d3743137e15fe0c525c04b177b9983bReid Kleckner  void AddDependentLib(StringRef Lib);
9273190ca922d3743137e15fe0c525c04b177b9983bReid Kleckner
928144a31f53b0a97a2c46bfcb1e2a40fa8327b8e89Peter Collingbourne  llvm::GlobalVariable::LinkageTypes getFunctionLinkage(GlobalDecl GD);
929d46f98573ba104eda102dd3224b2dca69f1c6336John McCall
930144a31f53b0a97a2c46bfcb1e2a40fa8327b8e89Peter Collingbourne  void setFunctionLinkage(GlobalDecl GD, llvm::GlobalValue *V) {
931144a31f53b0a97a2c46bfcb1e2a40fa8327b8e89Peter Collingbourne    V->setLinkage(getFunctionLinkage(GD));
9328b2423361648c39a7d8a3c5e8129e12006deac32John McCall  }
9338b2423361648c39a7d8a3c5e8129e12006deac32John McCall
934046c294a43024874ff35656c6e785b64e72f1f36Anders Carlsson  /// getVTableLinkage - Return the appropriate linkage for the vtable, VTT,
9354b0f21c0f8bed0e2a7dc62d73be64e7e277d6c9aDouglas Gregor  /// and type information of the given class.
9363a717f7fbb94ec31b826b48c15fdc965b5910df3Anders Carlsson  llvm::GlobalVariable::LinkageTypes getVTableLinkage(const CXXRecordDecl *RD);
937687cc4a850b59116efee061018f0d8df50728b82Ken Dyck
938687cc4a850b59116efee061018f0d8df50728b82Ken Dyck  /// GetTargetTypeStoreSize - Return the store size, in character units, of
939687cc4a850b59116efee061018f0d8df50728b82Ken Dyck  /// the given LLVM type.
9402acc6e3feda5e4f7d9009bdcf8b1cd777fecfe2dChris Lattner  CharUnits GetTargetTypeStoreSize(llvm::Type *Ty) const;
941354e712c81fbb07c0ce5f06180788b25fffa1b56Fariborz Jahanian
942354e712c81fbb07c0ce5f06180788b25fffa1b56Fariborz Jahanian  /// GetLLVMLinkageVarDefinition - Returns LLVM linkage for a global
943354e712c81fbb07c0ce5f06180788b25fffa1b56Fariborz Jahanian  /// variable.
944354e712c81fbb07c0ce5f06180788b25fffa1b56Fariborz Jahanian  llvm::GlobalValue::LinkageTypes
94507369dde9d72213bf8a48288cd8b29999af9a40cEli Friedman  GetLLVMLinkageVarDefinition(const VarDecl *D, bool isConstant);
946354e712c81fbb07c0ce5f06180788b25fffa1b56Fariborz Jahanian
94777f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge  /// Emit all the global annotations.
94877f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge  void EmitGlobalAnnotations();
94977f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge
95077f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge  /// Emit an annotation string.
951cfa88f893915ceb8ae4ce2f17c46c24a4d67502fDmitri Gribenko  llvm::Constant *EmitAnnotationString(StringRef Str);
95277f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge
95377f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge  /// Emit the annotation's translation unit.
95477f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge  llvm::Constant *EmitAnnotationUnit(SourceLocation Loc);
95577f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge
95677f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge  /// Emit the annotation line number.
95777f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge  llvm::Constant *EmitAnnotationLineNo(SourceLocation L);
95877f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge
95977f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge  /// EmitAnnotateAttr - Generate the llvm::ConstantStruct which contains the
96077f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge  /// annotation information for a given GlobalValue. The annotation struct is
96177f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge  /// {i8 *, i8 *, i8 *, i32}. The first field is a constant expression, the
96277f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge  /// GlobalValue being annotated. The second field is the constant string
96377f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge  /// created from the AnnotateAttr's annotation. The third field is a constant
96477f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge  /// string containing the name of the translation unit. The fourth field is
96577f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge  /// the line number in the file of the annotated value declaration.
96677f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge  llvm::Constant *EmitAnnotateAttr(llvm::GlobalValue *GV,
96777f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge                                   const AnnotateAttr *AA,
96877f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge                                   SourceLocation L);
96977f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge
97077f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge  /// Add global annotations that are set on D, for the global GV. Those
97177f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge  /// annotations are emitted during finalization of the LLVM code.
97277f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge  void AddGlobalAnnotations(const ValueDecl *D, llvm::GlobalValue *GV);
97377f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge
974a967935303e6b36dcc0490073e47fdd5a5eff93ePeter Collingbourne  const llvm::SpecialCaseList &getSanitizerBlacklist() const {
9754f45bc099f2665bc6e4bcbb169aa452390dbf3feWill Dietz    return SanitizerBlacklist;
9764f45bc099f2665bc6e4bcbb169aa452390dbf3feWill Dietz  }
9774f45bc099f2665bc6e4bcbb169aa452390dbf3feWill Dietz
9784f45bc099f2665bc6e4bcbb169aa452390dbf3feWill Dietz  const SanitizerOptions &getSanOpts() const { return SanOpts; }
9794f45bc099f2665bc6e4bcbb169aa452390dbf3feWill Dietz
980d5617eeafc93209a26b9f88276c88cf997c3a0a7John McCall  void addDeferredVTable(const CXXRecordDecl *RD) {
981d5617eeafc93209a26b9f88276c88cf997c3a0a7John McCall    DeferredVTables.push_back(RD);
982d5617eeafc93209a26b9f88276c88cf997c3a0a7John McCall  }
983d5617eeafc93209a26b9f88276c88cf997c3a0a7John McCall
984a4130baad9d10b7feabb7e003da53424e986d269Reid Kleckner  /// EmitGlobal - Emit code for a singal global function or var decl. Forward
985a4130baad9d10b7feabb7e003da53424e986d269Reid Kleckner  /// declarations are emitted lazily.
986a4130baad9d10b7feabb7e003da53424e986d269Reid Kleckner  void EmitGlobal(GlobalDecl D);
987a4130baad9d10b7feabb7e003da53424e986d269Reid Kleckner
9889cd4fe4af6d3e8b6dcfce9c2cdefcaafca7eed7cChris Lattnerprivate:
989686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  llvm::GlobalValue *GetGlobalValue(StringRef Ref);
9901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
991686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  llvm::Constant *GetOrCreateLLVMFunction(StringRef MangledName,
9922acc6e3feda5e4f7d9009bdcf8b1cd777fecfe2dChris Lattner                                          llvm::Type *Ty,
9931faa89f9c619e4b2411fab4af7e22ee7a2bd9009Anders Carlsson                                          GlobalDecl D,
994f85e193739c953358c865005855253af4f68a497John McCall                                          bool ForVTable,
995c4c62fd78a4728c9e4d4df14911a2ced9bdd2031Bill Wendling                                          llvm::AttributeSet ExtraAttrs =
996c4c62fd78a4728c9e4d4df14911a2ced9bdd2031Bill Wendling                                            llvm::AttributeSet());
997686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  llvm::Constant *GetOrCreateLLVMGlobal(StringRef MangledName,
9982acc6e3feda5e4f7d9009bdcf8b1cd777fecfe2dChris Lattner                                        llvm::PointerType *PTy,
999c532b502858032f377056dc8cba2fe43cba8702bRafael Espindola                                        const VarDecl *D,
1000c532b502858032f377056dc8cba2fe43cba8702bRafael Espindola                                        bool UnnamedAddr = false);
10011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
10027c65e990e9f0dafaf9adbc59b766dcc23eaee845Daniel Dunbar  /// SetCommonAttributes - Set attributes which are common to any
10037c65e990e9f0dafaf9adbc59b766dcc23eaee845Daniel Dunbar  /// form of a global definition (alias, Objective-C method,
10047c65e990e9f0dafaf9adbc59b766dcc23eaee845Daniel Dunbar  /// function, global variable).
10057dbd8197040313d796282d4af06eccdf8a17319cDaniel Dunbar  ///
10067c65e990e9f0dafaf9adbc59b766dcc23eaee845Daniel Dunbar  /// NOTE: This should only be called for definitions.
10077c65e990e9f0dafaf9adbc59b766dcc23eaee845Daniel Dunbar  void SetCommonAttributes(const Decl *D, llvm::GlobalValue *GV);
1008f80519b919a348db004fba18530706314d1ebfb5Daniel Dunbar
10097c65e990e9f0dafaf9adbc59b766dcc23eaee845Daniel Dunbar  /// SetFunctionDefinitionAttributes - Set attributes for a global definition.
10101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void SetFunctionDefinitionAttributes(const FunctionDecl *D,
1011c6c14d1cd68afcd90d097715296377f15be45210Eli Friedman                                       llvm::GlobalValue *GV);
10121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
10137dbd8197040313d796282d4af06eccdf8a17319cDaniel Dunbar  /// SetFunctionAttributes - Set function attributes for a function
10147dbd8197040313d796282d4af06eccdf8a17319cDaniel Dunbar  /// declaration.
1015b2bcf1c176b200b36f371e189ce22f93c86cdf45Anders Carlsson  void SetFunctionAttributes(GlobalDecl GD,
1016c6c14d1cd68afcd90d097715296377f15be45210Eli Friedman                             llvm::Function *F,
1017c6c14d1cd68afcd90d097715296377f15be45210Eli Friedman                             bool IsIncompleteFunction);
1018d4cbda6292b321c2e7dce7f039d92918fee99b3aNuno Lopes
1019b4880bab7fc1b61267cfd9a0ad52188e7a828cb3Chris Lattner  void EmitGlobalDefinition(GlobalDecl D);
1020d5d31801fc87239436fa349c89dce7797cf13537Daniel Dunbar
1021b4880bab7fc1b61267cfd9a0ad52188e7a828cb3Chris Lattner  void EmitGlobalFunctionDefinition(GlobalDecl GD);
1022bd012ff1fa088181646a784f385b28867372d434Daniel Dunbar  void EmitGlobalVarDefinition(const VarDecl *D);
1023f746aa6a8f538be914173a4aef2d9a2fd9f99d17John McCall  void EmitAliasDefinition(GlobalDecl GD);
1024af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar  void EmitObjCPropertyImplementations(const ObjCImplementationDecl *D);
1025109dfc6ca6652f60c55ed0f2631aebf323d0200dFariborz Jahanian  void EmitObjCIvarInitializations(ObjCImplementationDecl *D);
1026354e712c81fbb07c0ce5f06180788b25fffa1b56Fariborz Jahanian
102795d4e5d2f87a0f07fb143ccb824dfc4c5c595c78Anders Carlsson  // C++ related functions.
10281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1029d46f98573ba104eda102dd3224b2dca69f1c6336John McCall  bool TryEmitDefinitionAsAlias(GlobalDecl Alias, GlobalDecl Target);
1030c0bf462cf35fe050bddbd8bff967298e4a67e79dJohn McCall  bool TryEmitBaseDestructorAsAlias(const CXXDestructorDecl *D);
1031d46f98573ba104eda102dd3224b2dca69f1c6336John McCall
1032984e06874685396ca2cb51f0008cfff7c9b3d9c6Anders Carlsson  void EmitNamespace(const NamespaceDecl *D);
103391e20dd8bf1bc8980ee93839383d2bd170bce050Anders Carlsson  void EmitLinkageSpec(const LinkageSpecDecl *D);
10340a050f7d56039bab7556e08b359e06d329977b6bAdrian Prantl  void CompleteDIClassType(const CXXMethodDecl* D);
103595d4e5d2f87a0f07fb143ccb824dfc4c5c595c78Anders Carlsson
103695d4e5d2f87a0f07fb143ccb824dfc4c5c595c78Anders Carlsson  /// EmitCXXConstructor - Emit a single constructor with the given type from
103795d4e5d2f87a0f07fb143ccb824dfc4c5c595c78Anders Carlsson  /// a C++ constructor Decl.
103895d4e5d2f87a0f07fb143ccb824dfc4c5c595c78Anders Carlsson  void EmitCXXConstructor(const CXXConstructorDecl *D, CXXCtorType Type);
10391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
104027ae53665f8b00fe4ba21da0fa79a4ce6e0b6cd5Anders Carlsson  /// EmitCXXDestructor - Emit a single destructor with the given type from
104127ae53665f8b00fe4ba21da0fa79a4ce6e0b6cd5Anders Carlsson  /// a C++ destructor Decl.
104227ae53665f8b00fe4ba21da0fa79a4ce6e0b6cd5Anders Carlsson  void EmitCXXDestructor(const CXXDestructorDecl *D, CXXDtorType Type);
10431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1044b80a16eadd0dacabfc1c32412e243ccb99dd664dRichard Smith  /// \brief Emit the function that initializes C++ thread_local variables.
1045b80a16eadd0dacabfc1c32412e243ccb99dd664dRichard Smith  void EmitCXXThreadLocalInitFunc();
1046b80a16eadd0dacabfc1c32412e243ccb99dd664dRichard Smith
1047efb0fa9e11f75af51744a6159530ef7cc8efa24aDaniel Dunbar  /// EmitCXXGlobalInitFunc - Emit the function that initializes C++ globals.
104889ed31d3f9eeb8ec77c284a5cf404a74bf5e7acfAnders Carlsson  void EmitCXXGlobalInitFunc();
10496c6bda3b0b1d8adaac2ba3f4da7056e9f1eef52eEli Friedman
1050efb0fa9e11f75af51744a6159530ef7cc8efa24aDaniel Dunbar  /// EmitCXXGlobalDtorFunc - Emit the function that destroys C++ globals.
1051efb0fa9e11f75af51744a6159530ef7cc8efa24aDaniel Dunbar  void EmitCXXGlobalDtorFunc();
1052efb0fa9e11f75af51744a6159530ef7cc8efa24aDaniel Dunbar
10537ca4850a3e3530fa6c93b64b740446e32c97f992Richard Smith  /// EmitCXXGlobalVarDeclInitFunc - Emit the function that initializes the
10547ca4850a3e3530fa6c93b64b740446e32c97f992Richard Smith  /// specified global (if PerformInit is true) and registers its destructor.
10553030eb82593097502469a8b3fc26112c79c75605John McCall  void EmitCXXGlobalVarDeclInitFunc(const VarDecl *D,
10567ca4850a3e3530fa6c93b64b740446e32c97f992Richard Smith                                    llvm::GlobalVariable *Addr,
10577ca4850a3e3530fa6c93b64b740446e32c97f992Richard Smith                                    bool PerformInit);
10586c6bda3b0b1d8adaac2ba3f4da7056e9f1eef52eEli Friedman
10596bfed7e411adc46eaf616371f85f68305c6e6257Daniel Dunbar  // FIXME: Hardcoding priority here is gross.
1060b4880bab7fc1b61267cfd9a0ad52188e7a828cb3Chris Lattner  void AddGlobalCtor(llvm::Function *Ctor, int Priority=65535);
1061b4880bab7fc1b61267cfd9a0ad52188e7a828cb3Chris Lattner  void AddGlobalDtor(llvm::Function *Dtor, int Priority=65535);
10626bfed7e411adc46eaf616371f85f68305c6e6257Daniel Dunbar
1063ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump  /// EmitCtorList - Generates a global array of functions and priorities using
1064ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump  /// the given list and name. This array will have appending linkage and is
1065ecc90e9512b2ddaced6cb02a08f933fc7afa8e3fMike Stump  /// suitable for use as a LLVM constructor or destructor array.
10666bfed7e411adc46eaf616371f85f68305c6e6257Daniel Dunbar  void EmitCtorList(const CtorList &Fns, const char *GlobalName);
1067bd012ff1fa088181646a784f385b28867372d434Daniel Dunbar
1068d1a5c31b78997befe75d10a4731cee4ab211cc31Rafael Espindola  /// EmitFundamentalRTTIDescriptor - Emit the RTTI descriptors for the
1069d1a5c31b78997befe75d10a4731cee4ab211cc31Rafael Espindola  /// given type.
1070d1a5c31b78997befe75d10a4731cee4ab211cc31Rafael Espindola  void EmitFundamentalRTTIDescriptor(QualType Type);
1071d1a5c31b78997befe75d10a4731cee4ab211cc31Rafael Espindola
1072d1a5c31b78997befe75d10a4731cee4ab211cc31Rafael Espindola  /// EmitFundamentalRTTIDescriptors - Emit the RTTI descriptors for the
1073d1a5c31b78997befe75d10a4731cee4ab211cc31Rafael Espindola  /// builtin types.
1074d1a5c31b78997befe75d10a4731cee4ab211cc31Rafael Espindola  void EmitFundamentalRTTIDescriptors();
1075d1a5c31b78997befe75d10a4731cee4ab211cc31Rafael Espindola
107642745815fa4e90bfb07e581d2e5152b2c2db08ffDaniel Dunbar  /// EmitDeferred - Emit any needed decls for which code generation
107742745815fa4e90bfb07e581d2e5152b2c2db08ffDaniel Dunbar  /// was deferred.
1078c4a77906c259cba58c147d8468c406a430ecdcbbDmitri Gribenko  void EmitDeferred();
10790269871c9cba493f76237175ab60313406f3bafaDaniel Dunbar
1080d5617eeafc93209a26b9f88276c88cf997c3a0a7John McCall  /// EmitDeferredVTables - Emit any vtables which we deferred and
1081d5617eeafc93209a26b9f88276c88cf997c3a0a7John McCall  /// still have a use for.
1082d5617eeafc93209a26b9f88276c88cf997c3a0a7John McCall  void EmitDeferredVTables();
1083d5617eeafc93209a26b9f88276c88cf997c3a0a7John McCall
108442745815fa4e90bfb07e581d2e5152b2c2db08ffDaniel Dunbar  /// EmitLLVMUsed - Emit the llvm.used metadata used to force
108542745815fa4e90bfb07e581d2e5152b2c2db08ffDaniel Dunbar  /// references to global which may otherwise be optimized out.
1086c4a77906c259cba58c147d8468c406a430ecdcbbDmitri Gribenko  void EmitLLVMUsed();
1087f1968f28869f4e0675450ae39c478a37c5b9abd6Daniel Dunbar
1088858afb3c22144027bcd8ba75e27262eede093a60Douglas Gregor  /// \brief Emit the link options introduced by imported modules.
1089858afb3c22144027bcd8ba75e27262eede093a60Douglas Gregor  void EmitModuleLinkOptions();
1090858afb3c22144027bcd8ba75e27262eede093a60Douglas Gregor
10910024937dbb23752f606846f4a12aafc712bcde33Richard Smith  /// \brief Emit aliases for internal-linkage declarations inside "C" language
10920024937dbb23752f606846f4a12aafc712bcde33Richard Smith  /// linkage specifications, giving them the "expected" name where possible.
10930024937dbb23752f606846f4a12aafc712bcde33Richard Smith  void EmitStaticExternCAliases();
10940024937dbb23752f606846f4a12aafc712bcde33Richard Smith
1095744016dde06fcffd50931e94a98c850f8b12cd87John McCall  void EmitDeclMetadata();
1096744016dde06fcffd50931e94a98c850f8b12cd87John McCall
10973dc05418538c719fea48b906bfa4febe5296e126Nick Lewycky  /// EmitCoverageFile - Emit the llvm.gcov metadata used to tell LLVM where
10985ea4f44e34449a78d6b38aa47c14b527839d7aacNick Lewycky  /// to emit the .gcno and .gcda files in a way that persists in .bc files.
10993dc05418538c719fea48b906bfa4febe5296e126Nick Lewycky  void EmitCoverageFile();
11005ea4f44e34449a78d6b38aa47c14b527839d7aacNick Lewycky
1101c5f804636e367ef744fd24cf88f7c956a5af0434Nico Weber  /// Emits the initializer for a uuidof string.
1102c5f804636e367ef744fd24cf88f7c956a5af0434Nico Weber  llvm::Constant *EmitUuidofInitializer(StringRef uuidstr, QualType IIDType);
1103c5f804636e367ef744fd24cf88f7c956a5af0434Nico Weber
110442745815fa4e90bfb07e581d2e5152b2c2db08ffDaniel Dunbar  /// MayDeferGeneration - Determine if the given decl can be emitted
110542745815fa4e90bfb07e581d2e5152b2c2db08ffDaniel Dunbar  /// lazily; this is only relevant for definitions. The given decl
110642745815fa4e90bfb07e581d2e5152b2c2db08ffDaniel Dunbar  /// must be either a function or var decl.
110773241dfeb5c498255b662984cca369fd28ec3147Daniel Dunbar  bool MayDeferGeneration(const ValueDecl *D);
1108b25938303de0976b9f189363d43033e5788e3d36John McCall
1109b25938303de0976b9f189363d43033e5788e3d36John McCall  /// SimplifyPersonality - Check whether we can use a "simpler", more
1110b25938303de0976b9f189363d43033e5788e3d36John McCall  /// core exceptions personality function.
1111b25938303de0976b9f189363d43033e5788e3d36John McCall  void SimplifyPersonality();
11125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
11135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}  // end namespace CodeGen
11145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}  // end namespace clang
11155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
11165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif
1117