1 //===--- CodeGenModule.h - Per-Module state for LLVM CodeGen ----*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 // 10 // This is the internal per-translation-unit state used for llvm translation. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #ifndef CLANG_CODEGEN_CODEGENMODULE_H 15 #define CLANG_CODEGEN_CODEGENMODULE_H 16 17 #include "clang/Basic/LangOptions.h" 18 #include "clang/AST/Attr.h" 19 #include "clang/AST/DeclCXX.h" 20 #include "clang/AST/DeclObjC.h" 21 #include "CGBlocks.h" 22 #include "CGCall.h" 23 #include "CGCXX.h" 24 #include "CGVTables.h" 25 #include "CodeGenTypes.h" 26 #include "GlobalDecl.h" 27 #include "Mangle.h" 28 #include "llvm/Module.h" 29 #include "llvm/ADT/DenseMap.h" 30 #include "llvm/ADT/StringMap.h" 31 #include "llvm/ADT/StringSet.h" 32 #include "llvm/ADT/SmallPtrSet.h" 33 #include "llvm/Support/ValueHandle.h" 34 35 namespace llvm { 36 class Module; 37 class Constant; 38 class Function; 39 class GlobalValue; 40 class TargetData; 41 class FunctionType; 42 class LLVMContext; 43 } 44 45 namespace clang { 46 class TargetCodeGenInfo; 47 class ASTContext; 48 class FunctionDecl; 49 class IdentifierInfo; 50 class ObjCMethodDecl; 51 class ObjCImplementationDecl; 52 class ObjCCategoryImplDecl; 53 class ObjCProtocolDecl; 54 class ObjCEncodeExpr; 55 class BlockExpr; 56 class CharUnits; 57 class Decl; 58 class Expr; 59 class Stmt; 60 class StringLiteral; 61 class NamedDecl; 62 class ValueDecl; 63 class VarDecl; 64 class LangOptions; 65 class CodeGenOptions; 66 class Diagnostic; 67 class AnnotateAttr; 68 class CXXDestructorDecl; 69 70 namespace CodeGen { 71 72 class CodeGenFunction; 73 class CodeGenTBAA; 74 class CGCXXABI; 75 class CGDebugInfo; 76 class CGObjCRuntime; 77 class MangleBuffer; 78 79 struct OrderGlobalInits { 80 unsigned int priority; 81 unsigned int lex_order; 82 OrderGlobalInits(unsigned int p, unsigned int l) 83 : priority(p), lex_order(l) {} 84 85 bool operator==(const OrderGlobalInits &RHS) const { 86 return priority == RHS.priority && 87 lex_order == RHS.lex_order; 88 } 89 90 bool operator<(const OrderGlobalInits &RHS) const { 91 if (priority < RHS.priority) 92 return true; 93 94 return priority == RHS.priority && lex_order < RHS.lex_order; 95 } 96 }; 97 98 /// CodeGenModule - This class organizes the cross-function state that is used 99 /// while generating LLVM code. 100 class CodeGenModule : public BlockModule { 101 CodeGenModule(const CodeGenModule&); // DO NOT IMPLEMENT 102 void operator=(const CodeGenModule&); // DO NOT IMPLEMENT 103 104 typedef std::vector<std::pair<llvm::Constant*, int> > CtorList; 105 106 ASTContext &Context; 107 const LangOptions &Features; 108 const CodeGenOptions &CodeGenOpts; 109 llvm::Module &TheModule; 110 const llvm::TargetData &TheTargetData; 111 mutable const TargetCodeGenInfo *TheTargetCodeGenInfo; 112 Diagnostic &Diags; 113 CGCXXABI &ABI; 114 CodeGenTypes Types; 115 CodeGenTBAA *TBAA; 116 117 /// VTables - Holds information about C++ vtables. 118 CodeGenVTables VTables; 119 friend class CodeGenVTables; 120 121 CGObjCRuntime* Runtime; 122 CGDebugInfo* DebugInfo; 123 124 // WeakRefReferences - A set of references that have only been seen via 125 // a weakref so far. This is used to remove the weak of the reference if we ever 126 // see a direct reference or a definition. 127 llvm::SmallPtrSet<llvm::GlobalValue*, 10> WeakRefReferences; 128 129 /// DeferredDecls - This contains all the decls which have definitions but 130 /// which are deferred for emission and therefore should only be output if 131 /// they are actually used. If a decl is in this, then it is known to have 132 /// not been referenced yet. 133 llvm::StringMap<GlobalDecl> DeferredDecls; 134 135 /// DeferredDeclsToEmit - This is a list of deferred decls which we have seen 136 /// that *are* actually referenced. These get code generated when the module 137 /// is done. 138 std::vector<GlobalDecl> DeferredDeclsToEmit; 139 140 /// LLVMUsed - List of global values which are required to be 141 /// present in the object file; bitcast to i8*. This is used for 142 /// forcing visibility of symbols which may otherwise be optimized 143 /// out. 144 std::vector<llvm::WeakVH> LLVMUsed; 145 146 /// GlobalCtors - Store the list of global constructors and their respective 147 /// priorities to be emitted when the translation unit is complete. 148 CtorList GlobalCtors; 149 150 /// GlobalDtors - Store the list of global destructors and their respective 151 /// priorities to be emitted when the translation unit is complete. 152 CtorList GlobalDtors; 153 154 /// MangledDeclNames - A map of canonical GlobalDecls to their mangled names. 155 llvm::DenseMap<GlobalDecl, llvm::StringRef> MangledDeclNames; 156 llvm::BumpPtrAllocator MangledNamesAllocator; 157 158 std::vector<llvm::Constant*> Annotations; 159 160 llvm::StringMap<llvm::Constant*> CFConstantStringMap; 161 llvm::StringMap<llvm::Constant*> ConstantStringMap; 162 llvm::DenseMap<const Decl*, llvm::Value*> StaticLocalDeclMap; 163 164 /// CXXGlobalInits - Global variables with initializers that need to run 165 /// before main. 166 std::vector<llvm::Constant*> CXXGlobalInits; 167 168 /// When a C++ decl with an initializer is deferred, null is 169 /// appended to CXXGlobalInits, and the index of that null is placed 170 /// here so that the initializer will be performed in the correct 171 /// order. 172 llvm::DenseMap<const Decl*, unsigned> DelayedCXXInitPosition; 173 174 /// - Global variables with initializers whose order of initialization 175 /// is set by init_priority attribute. 176 177 llvm::SmallVector<std::pair<OrderGlobalInits, llvm::Function*>, 8> 178 PrioritizedCXXGlobalInits; 179 180 /// CXXGlobalDtors - Global destructor functions and arguments that need to 181 /// run on termination. 182 std::vector<std::pair<llvm::WeakVH,llvm::Constant*> > CXXGlobalDtors; 183 184 /// CFConstantStringClassRef - Cached reference to the class for constant 185 /// strings. This value has type int * but is actually an Obj-C class pointer. 186 llvm::Constant *CFConstantStringClassRef; 187 188 /// ConstantStringClassRef - Cached reference to the class for constant 189 /// strings. This value has type int * but is actually an Obj-C class pointer. 190 llvm::Constant *ConstantStringClassRef; 191 192 /// Lazily create the Objective-C runtime 193 void createObjCRuntime(); 194 195 llvm::LLVMContext &VMContext; 196 197 /// @name Cache for Blocks Runtime Globals 198 /// @{ 199 200 const VarDecl *NSConcreteGlobalBlockDecl; 201 const VarDecl *NSConcreteStackBlockDecl; 202 llvm::Constant *NSConcreteGlobalBlock; 203 llvm::Constant *NSConcreteStackBlock; 204 205 const FunctionDecl *BlockObjectAssignDecl; 206 const FunctionDecl *BlockObjectDisposeDecl; 207 llvm::Constant *BlockObjectAssign; 208 llvm::Constant *BlockObjectDispose; 209 210 /// @} 211 public: 212 CodeGenModule(ASTContext &C, const CodeGenOptions &CodeGenOpts, 213 llvm::Module &M, const llvm::TargetData &TD, Diagnostic &Diags); 214 215 ~CodeGenModule(); 216 217 /// Release - Finalize LLVM code generation. 218 void Release(); 219 220 /// getObjCRuntime() - Return a reference to the configured 221 /// Objective-C runtime. 222 CGObjCRuntime &getObjCRuntime() { 223 if (!Runtime) createObjCRuntime(); 224 return *Runtime; 225 } 226 227 /// hasObjCRuntime() - Return true iff an Objective-C runtime has 228 /// been configured. 229 bool hasObjCRuntime() { return !!Runtime; } 230 231 /// getCXXABI() - Return a reference to the configured C++ ABI. 232 CGCXXABI &getCXXABI() { return ABI; } 233 234 llvm::Value *getStaticLocalDeclAddress(const VarDecl *VD) { 235 return StaticLocalDeclMap[VD]; 236 } 237 void setStaticLocalDeclAddress(const VarDecl *D, 238 llvm::GlobalVariable *GV) { 239 StaticLocalDeclMap[D] = GV; 240 } 241 242 CGDebugInfo *getDebugInfo() { return DebugInfo; } 243 ASTContext &getContext() const { return Context; } 244 const CodeGenOptions &getCodeGenOpts() const { return CodeGenOpts; } 245 const LangOptions &getLangOptions() const { return Features; } 246 llvm::Module &getModule() const { return TheModule; } 247 CodeGenTypes &getTypes() { return Types; } 248 CodeGenVTables &getVTables() { return VTables; } 249 Diagnostic &getDiags() const { return Diags; } 250 const llvm::TargetData &getTargetData() const { return TheTargetData; } 251 llvm::LLVMContext &getLLVMContext() { return VMContext; } 252 const TargetCodeGenInfo &getTargetCodeGenInfo(); 253 bool isTargetDarwin() const; 254 255 llvm::MDNode *getTBAAInfo(QualType QTy); 256 257 static void DecorateInstruction(llvm::Instruction *Inst, 258 llvm::MDNode *TBAAInfo); 259 260 /// setGlobalVisibility - Set the visibility for the given LLVM 261 /// GlobalValue. 262 void setGlobalVisibility(llvm::GlobalValue *GV, const NamedDecl *D) const; 263 264 /// setTypeVisibility - Set the visibility for the given global 265 /// value which holds information about a type. 266 void setTypeVisibility(llvm::GlobalValue *GV, const CXXRecordDecl *D, 267 bool IsForRTTI) const; 268 269 llvm::Constant *GetAddrOfGlobal(GlobalDecl GD) { 270 if (isa<CXXConstructorDecl>(GD.getDecl())) 271 return GetAddrOfCXXConstructor(cast<CXXConstructorDecl>(GD.getDecl()), 272 GD.getCtorType()); 273 else if (isa<CXXDestructorDecl>(GD.getDecl())) 274 return GetAddrOfCXXDestructor(cast<CXXDestructorDecl>(GD.getDecl()), 275 GD.getDtorType()); 276 else if (isa<FunctionDecl>(GD.getDecl())) 277 return GetAddrOfFunction(GD); 278 else 279 return GetAddrOfGlobalVar(cast<VarDecl>(GD.getDecl())); 280 } 281 282 /// GetAddrOfGlobalVar - Return the llvm::Constant for the address of the 283 /// given global variable. If Ty is non-null and if the global doesn't exist, 284 /// then it will be greated with the specified type instead of whatever the 285 /// normal requested type would be. 286 llvm::Constant *GetAddrOfGlobalVar(const VarDecl *D, 287 const llvm::Type *Ty = 0); 288 289 /// GetAddrOfFunction - Return the address of the given function. If Ty is 290 /// non-null, then this function will use the specified type if it has to 291 /// create it. 292 llvm::Constant *GetAddrOfFunction(GlobalDecl GD, 293 const llvm::Type *Ty = 0); 294 295 /// GetAddrOfRTTIDescriptor - Get the address of the RTTI descriptor 296 /// for the given type. 297 llvm::Constant *GetAddrOfRTTIDescriptor(QualType Ty, bool ForEH = false); 298 299 /// GetAddrOfThunk - Get the address of the thunk for the given global decl. 300 llvm::Constant *GetAddrOfThunk(GlobalDecl GD, const ThunkInfo &Thunk); 301 302 /// GetWeakRefReference - Get a reference to the target of VD. 303 llvm::Constant *GetWeakRefReference(const ValueDecl *VD); 304 305 /// GetNonVirtualBaseClassOffset - Returns the offset from a derived class to 306 /// a class. Returns null if the offset is 0. 307 llvm::Constant * 308 GetNonVirtualBaseClassOffset(const CXXRecordDecl *ClassDecl, 309 CastExpr::path_const_iterator PathBegin, 310 CastExpr::path_const_iterator PathEnd); 311 312 /// GetStringForStringLiteral - Return the appropriate bytes for a string 313 /// literal, properly padded to match the literal type. If only the address of 314 /// a constant is needed consider using GetAddrOfConstantStringLiteral. 315 std::string GetStringForStringLiteral(const StringLiteral *E); 316 317 /// GetAddrOfConstantCFString - Return a pointer to a constant CFString object 318 /// for the given string. 319 llvm::Constant *GetAddrOfConstantCFString(const StringLiteral *Literal); 320 321 /// GetAddrOfConstantString - Return a pointer to a constant NSString object 322 /// for the given string. Or a user defined String object as defined via 323 /// -fconstant-string-class=class_name option. 324 llvm::Constant *GetAddrOfConstantString(const StringLiteral *Literal); 325 326 /// GetAddrOfConstantStringFromLiteral - Return a pointer to a constant array 327 /// for the given string literal. 328 llvm::Constant *GetAddrOfConstantStringFromLiteral(const StringLiteral *S); 329 330 /// GetAddrOfConstantStringFromObjCEncode - Return a pointer to a constant 331 /// array for the given ObjCEncodeExpr node. 332 llvm::Constant *GetAddrOfConstantStringFromObjCEncode(const ObjCEncodeExpr *); 333 334 /// GetAddrOfConstantString - Returns a pointer to a character array 335 /// containing the literal. This contents are exactly that of the given 336 /// string, i.e. it will not be null terminated automatically; see 337 /// GetAddrOfConstantCString. Note that whether the result is actually a 338 /// pointer to an LLVM constant depends on Feature.WriteableStrings. 339 /// 340 /// The result has pointer to array type. 341 /// 342 /// \param GlobalName If provided, the name to use for the global 343 /// (if one is created). 344 llvm::Constant *GetAddrOfConstantString(const std::string& str, 345 const char *GlobalName=0); 346 347 /// GetAddrOfConstantCString - Returns a pointer to a character array 348 /// containing the literal and a terminating '\0' character. The result has 349 /// pointer to array type. 350 /// 351 /// \param GlobalName If provided, the name to use for the global (if one is 352 /// created). 353 llvm::Constant *GetAddrOfConstantCString(const std::string &str, 354 const char *GlobalName=0); 355 356 /// GetAddrOfCXXConstructor - Return the address of the constructor of the 357 /// given type. 358 llvm::GlobalValue *GetAddrOfCXXConstructor(const CXXConstructorDecl *D, 359 CXXCtorType Type); 360 361 /// GetAddrOfCXXDestructor - Return the address of the constructor of the 362 /// given type. 363 llvm::GlobalValue *GetAddrOfCXXDestructor(const CXXDestructorDecl *D, 364 CXXDtorType Type); 365 366 /// getBuiltinLibFunction - Given a builtin id for a function like 367 /// "__builtin_fabsf", return a Function* for "fabsf". 368 llvm::Value *getBuiltinLibFunction(const FunctionDecl *FD, 369 unsigned BuiltinID); 370 371 llvm::Function *getMemCpyFn(const llvm::Type *DestType, 372 const llvm::Type *SrcType, 373 const llvm::Type *SizeType); 374 375 llvm::Function *getMemMoveFn(const llvm::Type *DestType, 376 const llvm::Type *SrcType, 377 const llvm::Type *SizeType); 378 379 llvm::Function *getMemSetFn(const llvm::Type *DestType, 380 const llvm::Type *SizeType); 381 382 llvm::Function *getIntrinsic(unsigned IID, const llvm::Type **Tys = 0, 383 unsigned NumTys = 0); 384 385 /// EmitTopLevelDecl - Emit code for a single top level declaration. 386 void EmitTopLevelDecl(Decl *D); 387 388 /// AddUsedGlobal - Add a global which should be forced to be 389 /// present in the object file; these are emitted to the llvm.used 390 /// metadata global. 391 void AddUsedGlobal(llvm::GlobalValue *GV); 392 393 void AddAnnotation(llvm::Constant *C) { Annotations.push_back(C); } 394 395 /// AddCXXDtorEntry - Add a destructor and object to add to the C++ global 396 /// destructor function. 397 void AddCXXDtorEntry(llvm::Constant *DtorFn, llvm::Constant *Object) { 398 CXXGlobalDtors.push_back(std::make_pair(DtorFn, Object)); 399 } 400 401 /// CreateRuntimeFunction - Create a new runtime function with the specified 402 /// type and name. 403 llvm::Constant *CreateRuntimeFunction(const llvm::FunctionType *Ty, 404 llvm::StringRef Name); 405 /// CreateRuntimeVariable - Create a new runtime global variable with the 406 /// specified type and name. 407 llvm::Constant *CreateRuntimeVariable(const llvm::Type *Ty, 408 llvm::StringRef Name); 409 410 ///@name Custom Blocks Runtime Interfaces 411 ///@{ 412 413 llvm::Constant *getNSConcreteGlobalBlock(); 414 llvm::Constant *getNSConcreteStackBlock(); 415 llvm::Constant *getBlockObjectAssign(); 416 llvm::Constant *getBlockObjectDispose(); 417 418 ///@} 419 420 void UpdateCompletedType(const TagDecl *TD) { 421 // Make sure that this type is translated. 422 Types.UpdateCompletedType(TD); 423 } 424 425 /// EmitConstantExpr - Try to emit the given expression as a 426 /// constant; returns 0 if the expression cannot be emitted as a 427 /// constant. 428 llvm::Constant *EmitConstantExpr(const Expr *E, QualType DestType, 429 CodeGenFunction *CGF = 0); 430 431 /// EmitNullConstant - Return the result of value-initializing the given 432 /// type, i.e. a null expression of the given type. This is usually, 433 /// but not always, an LLVM null constant. 434 llvm::Constant *EmitNullConstant(QualType T); 435 436 llvm::Constant *EmitAnnotateAttr(llvm::GlobalValue *GV, 437 const AnnotateAttr *AA, unsigned LineNo); 438 439 /// ErrorUnsupported - Print out an error that codegen doesn't support the 440 /// specified stmt yet. 441 /// \param OmitOnError - If true, then this error should only be emitted if no 442 /// other errors have been reported. 443 void ErrorUnsupported(const Stmt *S, const char *Type, 444 bool OmitOnError=false); 445 446 /// ErrorUnsupported - Print out an error that codegen doesn't support the 447 /// specified decl yet. 448 /// \param OmitOnError - If true, then this error should only be emitted if no 449 /// other errors have been reported. 450 void ErrorUnsupported(const Decl *D, const char *Type, 451 bool OmitOnError=false); 452 453 /// SetInternalFunctionAttributes - Set the attributes on the LLVM 454 /// function for the given decl and function info. This applies 455 /// attributes necessary for handling the ABI as well as user 456 /// specified attributes like section. 457 void SetInternalFunctionAttributes(const Decl *D, llvm::Function *F, 458 const CGFunctionInfo &FI); 459 460 /// SetLLVMFunctionAttributes - Set the LLVM function attributes 461 /// (sext, zext, etc). 462 void SetLLVMFunctionAttributes(const Decl *D, 463 const CGFunctionInfo &Info, 464 llvm::Function *F); 465 466 /// SetLLVMFunctionAttributesForDefinition - Set the LLVM function attributes 467 /// which only apply to a function definintion. 468 void SetLLVMFunctionAttributesForDefinition(const Decl *D, llvm::Function *F); 469 470 /// ReturnTypeUsesSRet - Return true iff the given type uses 'sret' when used 471 /// as a return type. 472 bool ReturnTypeUsesSRet(const CGFunctionInfo &FI); 473 474 /// ReturnTypeUsesSret - Return true iff the given type uses 'fpret' when used 475 /// as a return type. 476 bool ReturnTypeUsesFPRet(QualType ResultType); 477 478 /// ConstructAttributeList - Get the LLVM attributes and calling convention to 479 /// use for a particular function type. 480 /// 481 /// \param Info - The function type information. 482 /// \param TargetDecl - The decl these attributes are being constructed 483 /// for. If supplied the attributes applied to this decl may contribute to the 484 /// function attributes and calling convention. 485 /// \param PAL [out] - On return, the attribute list to use. 486 /// \param CallingConv [out] - On return, the LLVM calling convention to use. 487 void ConstructAttributeList(const CGFunctionInfo &Info, 488 const Decl *TargetDecl, 489 AttributeListType &PAL, 490 unsigned &CallingConv); 491 492 llvm::StringRef getMangledName(GlobalDecl GD); 493 void getMangledName(GlobalDecl GD, MangleBuffer &Buffer, const BlockDecl *BD); 494 495 void EmitTentativeDefinition(const VarDecl *D); 496 497 void EmitVTable(CXXRecordDecl *Class, bool DefinitionRequired); 498 499 llvm::GlobalVariable::LinkageTypes 500 getFunctionLinkage(const FunctionDecl *FD); 501 502 void setFunctionLinkage(const FunctionDecl *FD, llvm::GlobalValue *V) { 503 V->setLinkage(getFunctionLinkage(FD)); 504 } 505 506 /// getVTableLinkage - Return the appropriate linkage for the vtable, VTT, 507 /// and type information of the given class. 508 static llvm::GlobalVariable::LinkageTypes 509 getVTableLinkage(const CXXRecordDecl *RD); 510 511 /// GetTargetTypeStoreSize - Return the store size, in character units, of 512 /// the given LLVM type. 513 CharUnits GetTargetTypeStoreSize(const llvm::Type *Ty) const; 514 515 std::vector<const CXXRecordDecl*> DeferredVTables; 516 517 private: 518 llvm::GlobalValue *GetGlobalValue(llvm::StringRef Ref); 519 520 llvm::Constant *GetOrCreateLLVMFunction(llvm::StringRef MangledName, 521 const llvm::Type *Ty, 522 GlobalDecl D); 523 llvm::Constant *GetOrCreateLLVMGlobal(llvm::StringRef MangledName, 524 const llvm::PointerType *PTy, 525 const VarDecl *D); 526 527 /// SetCommonAttributes - Set attributes which are common to any 528 /// form of a global definition (alias, Objective-C method, 529 /// function, global variable). 530 /// 531 /// NOTE: This should only be called for definitions. 532 void SetCommonAttributes(const Decl *D, llvm::GlobalValue *GV); 533 534 /// SetFunctionDefinitionAttributes - Set attributes for a global definition. 535 void SetFunctionDefinitionAttributes(const FunctionDecl *D, 536 llvm::GlobalValue *GV); 537 538 /// SetFunctionAttributes - Set function attributes for a function 539 /// declaration. 540 void SetFunctionAttributes(GlobalDecl GD, 541 llvm::Function *F, 542 bool IsIncompleteFunction); 543 544 /// EmitGlobal - Emit code for a singal global function or var decl. Forward 545 /// declarations are emitted lazily. 546 void EmitGlobal(GlobalDecl D); 547 548 void EmitGlobalDefinition(GlobalDecl D); 549 550 void EmitGlobalFunctionDefinition(GlobalDecl GD); 551 void EmitGlobalVarDefinition(const VarDecl *D); 552 void EmitAliasDefinition(GlobalDecl GD); 553 void EmitObjCPropertyImplementations(const ObjCImplementationDecl *D); 554 void EmitObjCIvarInitializations(ObjCImplementationDecl *D); 555 556 // C++ related functions. 557 558 bool TryEmitDefinitionAsAlias(GlobalDecl Alias, GlobalDecl Target); 559 bool TryEmitBaseDestructorAsAlias(const CXXDestructorDecl *D); 560 561 void EmitNamespace(const NamespaceDecl *D); 562 void EmitLinkageSpec(const LinkageSpecDecl *D); 563 564 /// EmitCXXConstructors - Emit constructors (base, complete) from a 565 /// C++ constructor Decl. 566 void EmitCXXConstructors(const CXXConstructorDecl *D); 567 568 /// EmitCXXConstructor - Emit a single constructor with the given type from 569 /// a C++ constructor Decl. 570 void EmitCXXConstructor(const CXXConstructorDecl *D, CXXCtorType Type); 571 572 /// EmitCXXDestructors - Emit destructors (base, complete) from a 573 /// C++ destructor Decl. 574 void EmitCXXDestructors(const CXXDestructorDecl *D); 575 576 /// EmitCXXDestructor - Emit a single destructor with the given type from 577 /// a C++ destructor Decl. 578 void EmitCXXDestructor(const CXXDestructorDecl *D, CXXDtorType Type); 579 580 /// EmitCXXGlobalInitFunc - Emit the function that initializes C++ globals. 581 void EmitCXXGlobalInitFunc(); 582 583 /// EmitCXXGlobalDtorFunc - Emit the function that destroys C++ globals. 584 void EmitCXXGlobalDtorFunc(); 585 586 void EmitCXXGlobalVarDeclInitFunc(const VarDecl *D); 587 588 // FIXME: Hardcoding priority here is gross. 589 void AddGlobalCtor(llvm::Function *Ctor, int Priority=65535); 590 void AddGlobalDtor(llvm::Function *Dtor, int Priority=65535); 591 592 /// EmitCtorList - Generates a global array of functions and priorities using 593 /// the given list and name. This array will have appending linkage and is 594 /// suitable for use as a LLVM constructor or destructor array. 595 void EmitCtorList(const CtorList &Fns, const char *GlobalName); 596 597 void EmitAnnotations(void); 598 599 /// EmitFundamentalRTTIDescriptor - Emit the RTTI descriptors for the 600 /// given type. 601 void EmitFundamentalRTTIDescriptor(QualType Type); 602 603 /// EmitFundamentalRTTIDescriptors - Emit the RTTI descriptors for the 604 /// builtin types. 605 void EmitFundamentalRTTIDescriptors(); 606 607 /// EmitDeferred - Emit any needed decls for which code generation 608 /// was deferred. 609 void EmitDeferred(void); 610 611 /// EmitLLVMUsed - Emit the llvm.used metadata used to force 612 /// references to global which may otherwise be optimized out. 613 void EmitLLVMUsed(void); 614 615 void EmitDeclMetadata(); 616 617 /// MayDeferGeneration - Determine if the given decl can be emitted 618 /// lazily; this is only relevant for definitions. The given decl 619 /// must be either a function or var decl. 620 bool MayDeferGeneration(const ValueDecl *D); 621 622 /// SimplifyPersonality - Check whether we can use a "simpler", more 623 /// core exceptions personality function. 624 void SimplifyPersonality(); 625 }; 626 } // end namespace CodeGen 627 } // end namespace clang 628 629 #endif 630