CodeGenModule.h revision 204643
1193326Sed//===--- CodeGenModule.h - Per-Module state for LLVM CodeGen ----*- C++ -*-===// 2193326Sed// 3193326Sed// The LLVM Compiler Infrastructure 4193326Sed// 5193326Sed// This file is distributed under the University of Illinois Open Source 6193326Sed// License. See LICENSE.TXT for details. 7193326Sed// 8193326Sed//===----------------------------------------------------------------------===// 9193326Sed// 10193326Sed// This is the internal per-translation-unit state used for llvm translation. 11193326Sed// 12193326Sed//===----------------------------------------------------------------------===// 13193326Sed 14193326Sed#ifndef CLANG_CODEGEN_CODEGENMODULE_H 15193326Sed#define CLANG_CODEGEN_CODEGENMODULE_H 16193326Sed 17193326Sed#include "clang/Basic/LangOptions.h" 18193326Sed#include "clang/AST/Attr.h" 19193326Sed#include "clang/AST/DeclCXX.h" 20198092Srdivacky#include "clang/AST/DeclObjC.h" 21193326Sed#include "CGBlocks.h" 22193326Sed#include "CGCall.h" 23193326Sed#include "CGCXX.h" 24198092Srdivacky#include "CGVtable.h" 25193326Sed#include "CodeGenTypes.h" 26199482Srdivacky#include "GlobalDecl.h" 27198092Srdivacky#include "Mangle.h" 28198092Srdivacky#include "llvm/Module.h" 29193326Sed#include "llvm/ADT/DenseMap.h" 30193326Sed#include "llvm/ADT/StringMap.h" 31193326Sed#include "llvm/ADT/StringSet.h" 32193326Sed#include "llvm/Support/ValueHandle.h" 33193326Sed#include <list> 34193326Sed 35193326Sednamespace llvm { 36193326Sed class Module; 37193326Sed class Constant; 38193326Sed class Function; 39193326Sed class GlobalValue; 40193326Sed class TargetData; 41193326Sed class FunctionType; 42198092Srdivacky class LLVMContext; 43193326Sed} 44193326Sed 45193326Sednamespace clang { 46202379Srdivacky class TargetCodeGenInfo; 47193326Sed class ASTContext; 48193326Sed class FunctionDecl; 49193326Sed class IdentifierInfo; 50193326Sed class ObjCMethodDecl; 51193326Sed class ObjCImplementationDecl; 52193326Sed class ObjCCategoryImplDecl; 53193326Sed class ObjCProtocolDecl; 54193326Sed class ObjCEncodeExpr; 55193326Sed class BlockExpr; 56203955Srdivacky class CharUnits; 57193326Sed class Decl; 58193326Sed class Expr; 59193326Sed class Stmt; 60193326Sed class StringLiteral; 61193326Sed class NamedDecl; 62193326Sed class ValueDecl; 63193326Sed class VarDecl; 64193326Sed class LangOptions; 65199482Srdivacky class CodeGenOptions; 66193326Sed class Diagnostic; 67193326Sed class AnnotateAttr; 68193326Sed class CXXDestructorDecl; 69193326Sed 70193326Sednamespace CodeGen { 71193326Sed 72193326Sed class CodeGenFunction; 73193326Sed class CGDebugInfo; 74193326Sed class CGObjCRuntime; 75193326Sed 76193326Sed 77193326Sed/// CodeGenModule - This class organizes the cross-function state that is used 78193326Sed/// while generating LLVM code. 79193326Sedclass CodeGenModule : public BlockModule { 80193326Sed CodeGenModule(const CodeGenModule&); // DO NOT IMPLEMENT 81193326Sed void operator=(const CodeGenModule&); // DO NOT IMPLEMENT 82193326Sed 83198092Srdivacky typedef std::vector<std::pair<llvm::Constant*, int> > CtorList; 84193326Sed 85193326Sed ASTContext &Context; 86193326Sed const LangOptions &Features; 87199482Srdivacky const CodeGenOptions &CodeGenOpts; 88193326Sed llvm::Module &TheModule; 89193326Sed const llvm::TargetData &TheTargetData; 90202379Srdivacky mutable const TargetCodeGenInfo *TheTargetCodeGenInfo; 91193326Sed Diagnostic &Diags; 92193326Sed CodeGenTypes Types; 93198092Srdivacky MangleContext MangleCtx; 94198092Srdivacky 95198092Srdivacky /// VtableInfo - Holds information about C++ vtables. 96198092Srdivacky CGVtableInfo VtableInfo; 97198092Srdivacky 98193326Sed CGObjCRuntime* Runtime; 99193326Sed CGDebugInfo* DebugInfo; 100198092Srdivacky 101193326Sed llvm::Function *MemCpyFn; 102193326Sed llvm::Function *MemMoveFn; 103193326Sed llvm::Function *MemSetFn; 104193326Sed 105193326Sed /// GlobalDeclMap - Mapping of decl names (represented as unique 106193326Sed /// character pointers from either the identifier table or the set 107193326Sed /// of mangled names) to global variables we have already 108193326Sed /// emitted. Note that the entries in this map are the actual 109193326Sed /// globals and therefore may not be of the same type as the decl, 110193326Sed /// they should be bitcasted on retrieval. Also note that the 111193326Sed /// globals are keyed on their source mangled name, not the global name 112193326Sed /// (which may change with attributes such as asm-labels). The key 113193326Sed /// to this map should be generated using getMangledName(). 114193326Sed /// 115193326Sed /// Note that this map always lines up exactly with the contents of the LLVM 116193326Sed /// IR symbol table, but this is quicker to query since it is doing uniqued 117193326Sed /// pointer lookups instead of full string lookups. 118193326Sed llvm::DenseMap<const char*, llvm::GlobalValue*> GlobalDeclMap; 119193326Sed 120193326Sed /// \brief Contains the strings used for mangled names. 121193326Sed /// 122193326Sed /// FIXME: Eventually, this should map from the semantic/canonical 123193326Sed /// declaration for each global entity to its mangled name (if it 124193326Sed /// has one). 125193326Sed llvm::StringSet<> MangledNames; 126193326Sed 127193326Sed /// DeferredDecls - This contains all the decls which have definitions but 128193326Sed /// which are deferred for emission and therefore should only be output if 129193326Sed /// they are actually used. If a decl is in this, then it is known to have 130193326Sed /// not been referenced yet. The key to this map is a uniqued mangled name. 131193326Sed llvm::DenseMap<const char*, GlobalDecl> DeferredDecls; 132193326Sed 133193326Sed /// DeferredDeclsToEmit - This is a list of deferred decls which we have seen 134193326Sed /// that *are* actually referenced. These get code generated when the module 135193326Sed /// is done. 136193326Sed std::vector<GlobalDecl> DeferredDeclsToEmit; 137193326Sed 138193326Sed /// LLVMUsed - List of global values which are required to be 139193326Sed /// present in the object file; bitcast to i8*. This is used for 140193326Sed /// forcing visibility of symbols which may otherwise be optimized 141193326Sed /// out. 142193326Sed std::vector<llvm::WeakVH> LLVMUsed; 143193326Sed 144193326Sed /// GlobalCtors - Store the list of global constructors and their respective 145193326Sed /// priorities to be emitted when the translation unit is complete. 146193326Sed CtorList GlobalCtors; 147193326Sed 148193326Sed /// GlobalDtors - Store the list of global destructors and their respective 149193326Sed /// priorities to be emitted when the translation unit is complete. 150193326Sed CtorList GlobalDtors; 151193326Sed 152193326Sed std::vector<llvm::Constant*> Annotations; 153193326Sed 154193326Sed llvm::StringMap<llvm::Constant*> CFConstantStringMap; 155193326Sed llvm::StringMap<llvm::Constant*> ConstantStringMap; 156193326Sed 157198092Srdivacky /// CXXGlobalInits - Variables with global initializers that need to run 158198092Srdivacky /// before main. 159202379Srdivacky std::vector<llvm::Constant*> CXXGlobalInits; 160198092Srdivacky 161193326Sed /// CFConstantStringClassRef - Cached reference to the class for constant 162193326Sed /// strings. This value has type int * but is actually an Obj-C class pointer. 163193326Sed llvm::Constant *CFConstantStringClassRef; 164198092Srdivacky 165202879Srdivacky /// Lazily create the Objective-C runtime 166202879Srdivacky void createObjCRuntime(); 167202879Srdivacky 168198092Srdivacky llvm::LLVMContext &VMContext; 169193326Sedpublic: 170199482Srdivacky CodeGenModule(ASTContext &C, const CodeGenOptions &CodeGenOpts, 171193326Sed llvm::Module &M, const llvm::TargetData &TD, Diagnostic &Diags); 172193326Sed 173193326Sed ~CodeGenModule(); 174193326Sed 175193326Sed /// Release - Finalize LLVM code generation. 176193326Sed void Release(); 177193326Sed 178193326Sed /// getObjCRuntime() - Return a reference to the configured 179193326Sed /// Objective-C runtime. 180193326Sed CGObjCRuntime &getObjCRuntime() { 181202879Srdivacky if (!Runtime) createObjCRuntime(); 182193326Sed return *Runtime; 183193326Sed } 184193326Sed 185193326Sed /// hasObjCRuntime() - Return true iff an Objective-C runtime has 186193326Sed /// been configured. 187193326Sed bool hasObjCRuntime() { return !!Runtime; } 188193326Sed 189193326Sed CGDebugInfo *getDebugInfo() { return DebugInfo; } 190193326Sed ASTContext &getContext() const { return Context; } 191199482Srdivacky const CodeGenOptions &getCodeGenOpts() const { return CodeGenOpts; } 192193326Sed const LangOptions &getLangOptions() const { return Features; } 193193326Sed llvm::Module &getModule() const { return TheModule; } 194193326Sed CodeGenTypes &getTypes() { return Types; } 195198092Srdivacky MangleContext &getMangleContext() { return MangleCtx; } 196198092Srdivacky CGVtableInfo &getVtableInfo() { return VtableInfo; } 197193326Sed Diagnostic &getDiags() const { return Diags; } 198193326Sed const llvm::TargetData &getTargetData() const { return TheTargetData; } 199198092Srdivacky llvm::LLVMContext &getLLVMContext() { return VMContext; } 200202379Srdivacky const TargetCodeGenInfo &getTargetCodeGenInfo() const; 201193326Sed 202193326Sed /// getDeclVisibilityMode - Compute the visibility of the decl \arg D. 203193326Sed LangOptions::VisibilityMode getDeclVisibilityMode(const Decl *D) const; 204193326Sed 205193326Sed /// setGlobalVisibility - Set the visibility for the given LLVM 206193326Sed /// GlobalValue. 207193326Sed void setGlobalVisibility(llvm::GlobalValue *GV, const Decl *D) const; 208193326Sed 209204643Srdivacky llvm::Constant *GetAddrOfGlobal(GlobalDecl GD) { 210204643Srdivacky if (isa<CXXConstructorDecl>(GD.getDecl())) 211204643Srdivacky return GetAddrOfCXXConstructor(cast<CXXConstructorDecl>(GD.getDecl()), 212204643Srdivacky GD.getCtorType()); 213204643Srdivacky else if (isa<CXXDestructorDecl>(GD.getDecl())) 214204643Srdivacky return GetAddrOfCXXDestructor(cast<CXXDestructorDecl>(GD.getDecl()), 215204643Srdivacky GD.getDtorType()); 216204643Srdivacky else if (isa<FunctionDecl>(GD.getDecl())) 217204643Srdivacky return GetAddrOfFunction(GD); 218204643Srdivacky else 219204643Srdivacky return GetAddrOfGlobalVar(cast<VarDecl>(GD.getDecl())); 220204643Srdivacky } 221204643Srdivacky 222193326Sed /// GetAddrOfGlobalVar - Return the llvm::Constant for the address of the 223193326Sed /// given global variable. If Ty is non-null and if the global doesn't exist, 224193326Sed /// then it will be greated with the specified type instead of whatever the 225193326Sed /// normal requested type would be. 226193326Sed llvm::Constant *GetAddrOfGlobalVar(const VarDecl *D, 227193326Sed const llvm::Type *Ty = 0); 228193326Sed 229193326Sed /// GetAddrOfFunction - Return the address of the given function. If Ty is 230193326Sed /// non-null, then this function will use the specified type if it has to 231193326Sed /// create it. 232193326Sed llvm::Constant *GetAddrOfFunction(GlobalDecl GD, 233193326Sed const llvm::Type *Ty = 0); 234193326Sed 235201361Srdivacky /// GetAddrOfRTTIDescriptor - Get the address of the RTTI descriptor 236201361Srdivacky /// for the given type. 237201361Srdivacky llvm::Constant *GetAddrOfRTTIDescriptor(QualType Ty); 238199482Srdivacky 239200583Srdivacky llvm::Constant *GetAddrOfThunk(GlobalDecl GD, 240200583Srdivacky const ThunkAdjustment &ThisAdjustment); 241200583Srdivacky llvm::Constant *GetAddrOfCovariantThunk(GlobalDecl GD, 242200583Srdivacky const CovariantThunkAdjustment &ThisAdjustment); 243200583Srdivacky void BuildThunksForVirtual(GlobalDecl GD); 244200583Srdivacky void BuildThunksForVirtualRecursive(GlobalDecl GD, GlobalDecl BaseOGD); 245198092Srdivacky 246199990Srdivacky /// BuildThunk - Build a thunk for the given method. 247200583Srdivacky llvm::Constant *BuildThunk(GlobalDecl GD, bool Extern, 248199990Srdivacky const ThunkAdjustment &ThisAdjustment); 249199990Srdivacky 250198092Srdivacky /// BuildCoVariantThunk - Build a thunk for the given method 251199990Srdivacky llvm::Constant * 252200583Srdivacky BuildCovariantThunk(const GlobalDecl &GD, bool Extern, 253199990Srdivacky const CovariantThunkAdjustment &Adjustment); 254198092Srdivacky 255203955Srdivacky /// GetNonVirtualBaseClassOffset - Returns the offset from a derived class to 256203955Srdivacky /// its base class. Returns null if the offset is 0. 257203955Srdivacky llvm::Constant * 258203955Srdivacky GetNonVirtualBaseClassOffset(const CXXRecordDecl *ClassDecl, 259203955Srdivacky const CXXRecordDecl *BaseClassDecl); 260198092Srdivacky 261200583Srdivacky /// ComputeThunkAdjustment - Returns the two parts required to compute the 262200583Srdivacky /// offset for an object. 263200583Srdivacky ThunkAdjustment ComputeThunkAdjustment(const CXXRecordDecl *ClassDecl, 264200583Srdivacky const CXXRecordDecl *BaseClassDecl); 265200583Srdivacky 266193326Sed /// GetStringForStringLiteral - Return the appropriate bytes for a string 267193326Sed /// literal, properly padded to match the literal type. If only the address of 268193326Sed /// a constant is needed consider using GetAddrOfConstantStringLiteral. 269193326Sed std::string GetStringForStringLiteral(const StringLiteral *E); 270193326Sed 271193326Sed /// GetAddrOfConstantCFString - Return a pointer to a constant CFString object 272193326Sed /// for the given string. 273193326Sed llvm::Constant *GetAddrOfConstantCFString(const StringLiteral *Literal); 274193326Sed 275193326Sed /// GetAddrOfConstantStringFromLiteral - Return a pointer to a constant array 276193326Sed /// for the given string literal. 277193326Sed llvm::Constant *GetAddrOfConstantStringFromLiteral(const StringLiteral *S); 278193326Sed 279193326Sed /// GetAddrOfConstantStringFromObjCEncode - Return a pointer to a constant 280193326Sed /// array for the given ObjCEncodeExpr node. 281193326Sed llvm::Constant *GetAddrOfConstantStringFromObjCEncode(const ObjCEncodeExpr *); 282198092Srdivacky 283193326Sed /// GetAddrOfConstantString - Returns a pointer to a character array 284193326Sed /// containing the literal. This contents are exactly that of the given 285193326Sed /// string, i.e. it will not be null terminated automatically; see 286193326Sed /// GetAddrOfConstantCString. Note that whether the result is actually a 287193326Sed /// pointer to an LLVM constant depends on Feature.WriteableStrings. 288193326Sed /// 289193326Sed /// The result has pointer to array type. 290193326Sed /// 291193326Sed /// \param GlobalName If provided, the name to use for the global 292193326Sed /// (if one is created). 293193326Sed llvm::Constant *GetAddrOfConstantString(const std::string& str, 294193326Sed const char *GlobalName=0); 295193326Sed 296193326Sed /// GetAddrOfConstantCString - Returns a pointer to a character array 297193326Sed /// containing the literal and a terminating '\0' character. The result has 298193326Sed /// pointer to array type. 299193326Sed /// 300193326Sed /// \param GlobalName If provided, the name to use for the global (if one is 301193326Sed /// created). 302193326Sed llvm::Constant *GetAddrOfConstantCString(const std::string &str, 303193326Sed const char *GlobalName=0); 304193326Sed 305193326Sed /// GetAddrOfCXXConstructor - Return the address of the constructor of the 306193326Sed /// given type. 307204643Srdivacky llvm::GlobalValue *GetAddrOfCXXConstructor(const CXXConstructorDecl *D, 308204643Srdivacky CXXCtorType Type); 309193326Sed 310193326Sed /// GetAddrOfCXXDestructor - Return the address of the constructor of the 311193326Sed /// given type. 312204643Srdivacky llvm::GlobalValue *GetAddrOfCXXDestructor(const CXXDestructorDecl *D, 313204643Srdivacky CXXDtorType Type); 314198092Srdivacky 315193326Sed /// getBuiltinLibFunction - Given a builtin id for a function like 316193326Sed /// "__builtin_fabsf", return a Function* for "fabsf". 317198092Srdivacky llvm::Value *getBuiltinLibFunction(const FunctionDecl *FD, 318198092Srdivacky unsigned BuiltinID); 319193326Sed 320193326Sed llvm::Function *getMemCpyFn(); 321193326Sed llvm::Function *getMemMoveFn(); 322193326Sed llvm::Function *getMemSetFn(); 323193326Sed llvm::Function *getIntrinsic(unsigned IID, const llvm::Type **Tys = 0, 324193326Sed unsigned NumTys = 0); 325193326Sed 326193326Sed /// EmitTopLevelDecl - Emit code for a single top level declaration. 327193326Sed void EmitTopLevelDecl(Decl *D); 328193326Sed 329193326Sed /// AddUsedGlobal - Add a global which should be forced to be 330193326Sed /// present in the object file; these are emitted to the llvm.used 331193326Sed /// metadata global. 332193326Sed void AddUsedGlobal(llvm::GlobalValue *GV); 333193326Sed 334193326Sed void AddAnnotation(llvm::Constant *C) { Annotations.push_back(C); } 335193326Sed 336193326Sed /// CreateRuntimeFunction - Create a new runtime function with the specified 337193326Sed /// type and name. 338193326Sed llvm::Constant *CreateRuntimeFunction(const llvm::FunctionType *Ty, 339193326Sed const char *Name); 340193326Sed /// CreateRuntimeVariable - Create a new runtime global variable with the 341193326Sed /// specified type and name. 342193326Sed llvm::Constant *CreateRuntimeVariable(const llvm::Type *Ty, 343193326Sed const char *Name); 344193326Sed 345193326Sed void UpdateCompletedType(const TagDecl *TD) { 346193326Sed // Make sure that this type is translated. 347193326Sed Types.UpdateCompletedType(TD); 348193326Sed } 349193326Sed 350193326Sed /// EmitConstantExpr - Try to emit the given expression as a 351193326Sed /// constant; returns 0 if the expression cannot be emitted as a 352193326Sed /// constant. 353193326Sed llvm::Constant *EmitConstantExpr(const Expr *E, QualType DestType, 354193326Sed CodeGenFunction *CGF = 0); 355193326Sed 356193326Sed /// EmitNullConstant - Return the result of value-initializing the given 357193326Sed /// type, i.e. a null expression of the given type. This is usually, 358193326Sed /// but not always, an LLVM null constant. 359193326Sed llvm::Constant *EmitNullConstant(QualType T); 360193326Sed 361193326Sed llvm::Constant *EmitAnnotateAttr(llvm::GlobalValue *GV, 362193326Sed const AnnotateAttr *AA, unsigned LineNo); 363193326Sed 364203955Srdivacky llvm::Constant *EmitPointerToDataMember(const FieldDecl *FD); 365203955Srdivacky 366193326Sed /// ErrorUnsupported - Print out an error that codegen doesn't support the 367193326Sed /// specified stmt yet. 368193326Sed /// \param OmitOnError - If true, then this error should only be emitted if no 369193326Sed /// other errors have been reported. 370193326Sed void ErrorUnsupported(const Stmt *S, const char *Type, 371193326Sed bool OmitOnError=false); 372193326Sed 373193326Sed /// ErrorUnsupported - Print out an error that codegen doesn't support the 374193326Sed /// specified decl yet. 375193326Sed /// \param OmitOnError - If true, then this error should only be emitted if no 376193326Sed /// other errors have been reported. 377193326Sed void ErrorUnsupported(const Decl *D, const char *Type, 378193326Sed bool OmitOnError=false); 379193326Sed 380193326Sed /// SetInternalFunctionAttributes - Set the attributes on the LLVM 381193326Sed /// function for the given decl and function info. This applies 382193326Sed /// attributes necessary for handling the ABI as well as user 383193326Sed /// specified attributes like section. 384193326Sed void SetInternalFunctionAttributes(const Decl *D, llvm::Function *F, 385193326Sed const CGFunctionInfo &FI); 386193326Sed 387193326Sed /// SetLLVMFunctionAttributes - Set the LLVM function attributes 388193326Sed /// (sext, zext, etc). 389193326Sed void SetLLVMFunctionAttributes(const Decl *D, 390193326Sed const CGFunctionInfo &Info, 391193326Sed llvm::Function *F); 392193326Sed 393193326Sed /// SetLLVMFunctionAttributesForDefinition - Set the LLVM function attributes 394193326Sed /// which only apply to a function definintion. 395193326Sed void SetLLVMFunctionAttributesForDefinition(const Decl *D, llvm::Function *F); 396193326Sed 397193326Sed /// ReturnTypeUsesSret - Return true iff the given type uses 'sret' when used 398193326Sed /// as a return type. 399193326Sed bool ReturnTypeUsesSret(const CGFunctionInfo &FI); 400193326Sed 401198092Srdivacky /// ConstructAttributeList - Get the LLVM attributes and calling convention to 402198092Srdivacky /// use for a particular function type. 403198092Srdivacky /// 404198092Srdivacky /// \param Info - The function type information. 405198092Srdivacky /// \param TargetDecl - The decl these attributes are being constructed 406198092Srdivacky /// for. If supplied the attributes applied to this decl may contribute to the 407198092Srdivacky /// function attributes and calling convention. 408198092Srdivacky /// \param PAL [out] - On return, the attribute list to use. 409198092Srdivacky /// \param CallingConv [out] - On return, the LLVM calling convention to use. 410193326Sed void ConstructAttributeList(const CGFunctionInfo &Info, 411193326Sed const Decl *TargetDecl, 412198092Srdivacky AttributeListType &PAL, 413198092Srdivacky unsigned &CallingConv); 414193326Sed 415193326Sed const char *getMangledName(const GlobalDecl &D); 416193326Sed 417193326Sed const char *getMangledName(const NamedDecl *ND); 418198092Srdivacky const char *getMangledCXXCtorName(const CXXConstructorDecl *D, 419193326Sed CXXCtorType Type); 420198092Srdivacky const char *getMangledCXXDtorName(const CXXDestructorDecl *D, 421193326Sed CXXDtorType Type); 422193326Sed 423193326Sed void EmitTentativeDefinition(const VarDecl *D); 424198092Srdivacky 425193326Sed enum GVALinkage { 426193326Sed GVA_Internal, 427193326Sed GVA_C99Inline, 428193326Sed GVA_CXXInline, 429195341Sed GVA_StrongExternal, 430195341Sed GVA_TemplateInstantiation 431193326Sed }; 432198092Srdivacky 433204643Srdivacky llvm::GlobalVariable::LinkageTypes 434204643Srdivacky getFunctionLinkage(const FunctionDecl *FD); 435204643Srdivacky 436202379Srdivacky /// getVtableLinkage - Return the appropriate linkage for the vtable, VTT, 437202379Srdivacky /// and type information of the given class. 438202379Srdivacky static llvm::GlobalVariable::LinkageTypes 439202379Srdivacky getVtableLinkage(const CXXRecordDecl *RD); 440203955Srdivacky 441203955Srdivacky /// GetTargetTypeStoreSize - Return the store size, in character units, of 442203955Srdivacky /// the given LLVM type. 443203955Srdivacky CharUnits GetTargetTypeStoreSize(const llvm::Type *Ty) const; 444202379Srdivacky 445193326Sedprivate: 446193326Sed /// UniqueMangledName - Unique a name by (if necessary) inserting it into the 447193326Sed /// MangledNames string map. 448193326Sed const char *UniqueMangledName(const char *NameStart, const char *NameEnd); 449198092Srdivacky 450193326Sed llvm::Constant *GetOrCreateLLVMFunction(const char *MangledName, 451193326Sed const llvm::Type *Ty, 452193326Sed GlobalDecl D); 453193326Sed llvm::Constant *GetOrCreateLLVMGlobal(const char *MangledName, 454193326Sed const llvm::PointerType *PTy, 455193326Sed const VarDecl *D); 456198092Srdivacky 457193326Sed /// SetCommonAttributes - Set attributes which are common to any 458193326Sed /// form of a global definition (alias, Objective-C method, 459193326Sed /// function, global variable). 460193326Sed /// 461193326Sed /// NOTE: This should only be called for definitions. 462193326Sed void SetCommonAttributes(const Decl *D, llvm::GlobalValue *GV); 463193326Sed 464193326Sed /// SetFunctionDefinitionAttributes - Set attributes for a global definition. 465198092Srdivacky void SetFunctionDefinitionAttributes(const FunctionDecl *D, 466193326Sed llvm::GlobalValue *GV); 467198092Srdivacky 468193326Sed /// SetFunctionAttributes - Set function attributes for a function 469193326Sed /// declaration. 470203955Srdivacky void SetFunctionAttributes(GlobalDecl GD, 471193326Sed llvm::Function *F, 472193326Sed bool IsIncompleteFunction); 473193326Sed 474193326Sed /// EmitGlobal - Emit code for a singal global function or var decl. Forward 475193326Sed /// declarations are emitted lazily. 476193326Sed void EmitGlobal(GlobalDecl D); 477193326Sed 478193326Sed void EmitGlobalDefinition(GlobalDecl D); 479193326Sed 480193326Sed void EmitGlobalFunctionDefinition(GlobalDecl GD); 481193326Sed void EmitGlobalVarDefinition(const VarDecl *D); 482193326Sed void EmitAliasDefinition(const ValueDecl *D); 483193326Sed void EmitObjCPropertyImplementations(const ObjCImplementationDecl *D); 484193326Sed 485193326Sed // C++ related functions. 486198092Srdivacky 487204643Srdivacky bool TryEmitDefinitionAsAlias(GlobalDecl Alias, GlobalDecl Target); 488204643Srdivacky bool TryEmitBaseDestructorAsAlias(const CXXDestructorDecl *D); 489204643Srdivacky 490193326Sed void EmitNamespace(const NamespaceDecl *D); 491193326Sed void EmitLinkageSpec(const LinkageSpecDecl *D); 492193326Sed 493193326Sed /// EmitCXXConstructors - Emit constructors (base, complete) from a 494193326Sed /// C++ constructor Decl. 495193326Sed void EmitCXXConstructors(const CXXConstructorDecl *D); 496198092Srdivacky 497193326Sed /// EmitCXXConstructor - Emit a single constructor with the given type from 498193326Sed /// a C++ constructor Decl. 499193326Sed void EmitCXXConstructor(const CXXConstructorDecl *D, CXXCtorType Type); 500198092Srdivacky 501198092Srdivacky /// EmitCXXDestructors - Emit destructors (base, complete) from a 502193326Sed /// C++ destructor Decl. 503193326Sed void EmitCXXDestructors(const CXXDestructorDecl *D); 504198092Srdivacky 505193326Sed /// EmitCXXDestructor - Emit a single destructor with the given type from 506193326Sed /// a C++ destructor Decl. 507193326Sed void EmitCXXDestructor(const CXXDestructorDecl *D, CXXDtorType Type); 508198092Srdivacky 509198092Srdivacky /// EmitCXXGlobalInitFunc - Emit a function that initializes C++ globals. 510198092Srdivacky void EmitCXXGlobalInitFunc(); 511202379Srdivacky 512202379Srdivacky void EmitCXXGlobalVarDeclInitFunc(const VarDecl *D); 513202379Srdivacky 514193326Sed // FIXME: Hardcoding priority here is gross. 515193326Sed void AddGlobalCtor(llvm::Function *Ctor, int Priority=65535); 516193326Sed void AddGlobalDtor(llvm::Function *Dtor, int Priority=65535); 517193326Sed 518193326Sed /// EmitCtorList - Generates a global array of functions and priorities using 519193326Sed /// the given list and name. This array will have appending linkage and is 520193326Sed /// suitable for use as a LLVM constructor or destructor array. 521193326Sed void EmitCtorList(const CtorList &Fns, const char *GlobalName); 522193326Sed 523193326Sed void EmitAnnotations(void); 524193326Sed 525193326Sed /// EmitDeferred - Emit any needed decls for which code generation 526193326Sed /// was deferred. 527193326Sed void EmitDeferred(void); 528193326Sed 529193326Sed /// EmitLLVMUsed - Emit the llvm.used metadata used to force 530193326Sed /// references to global which may otherwise be optimized out. 531193326Sed void EmitLLVMUsed(void); 532193326Sed 533193326Sed /// MayDeferGeneration - Determine if the given decl can be emitted 534193326Sed /// lazily; this is only relevant for definitions. The given decl 535193326Sed /// must be either a function or var decl. 536193326Sed bool MayDeferGeneration(const ValueDecl *D); 537193326Sed}; 538193326Sed} // end namespace CodeGen 539193326Sed} // end namespace clang 540193326Sed 541193326Sed#endif 542