1 //===--- CodeGenModule.h - Per-Module state for LLVM CodeGen ----*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This is the internal per-translation-unit state used for llvm translation.
12 //===----------------------------------------------------------------------===//
14 #ifndef CLANG_CODEGEN_CODEGENMODULE_H
15 #define CLANG_CODEGEN_CODEGENMODULE_H
17 #include "clang/Basic/ABI.h"
18 #include "clang/Basic/LangOptions.h"
19 #include "clang/AST/Attr.h"
20 #include "clang/AST/DeclCXX.h"
21 #include "clang/AST/DeclObjC.h"
22 #include "clang/AST/Mangle.h"
23 #include "CGVTables.h"
24 #include "CodeGenTypes.h"
25 #include "GlobalDecl.h"
26 #include "llvm/Module.h"
27 #include "llvm/ADT/DenseMap.h"
28 #include "llvm/ADT/StringMap.h"
29 #include "llvm/ADT/StringSet.h"
30 #include "llvm/ADT/SmallPtrSet.h"
31 #include "llvm/Support/ValueHandle.h"
44 class TargetCodeGenInfo;
49 class ObjCImplementationDecl;
50 class ObjCCategoryImplDecl;
51 class ObjCProtocolDecl;
66 class CXXDestructorDecl;
72 class CodeGenFunction;
77 class BlockFieldFlags;
78 class FunctionArgList;
80 struct OrderGlobalInits {
81 unsigned int priority;
82 unsigned int lex_order;
83 OrderGlobalInits(unsigned int p, unsigned int l)
84 : priority(p), lex_order(l) {}
86 bool operator==(const OrderGlobalInits &RHS) const {
87 return priority == RHS.priority &&
88 lex_order == RHS.lex_order;
91 bool operator<(const OrderGlobalInits &RHS) const {
92 if (priority < RHS.priority)
95 return priority == RHS.priority && lex_order < RHS.lex_order;
99 struct CodeGenTypeCache {
101 const llvm::IntegerType *Int8Ty, *Int32Ty, *Int64Ty;
104 const llvm::IntegerType *IntTy;
106 /// intptr_t and size_t, which we assume are the same
108 const llvm::IntegerType *IntPtrTy;
109 const llvm::IntegerType *SizeTy;
112 /// void* in address space 0
114 const llvm::PointerType *VoidPtrTy;
115 const llvm::PointerType *Int8PtrTy;
118 /// void** in address space 0
120 const llvm::PointerType *VoidPtrPtrTy;
121 const llvm::PointerType *Int8PtrPtrTy;
124 /// The width of a pointer into the generic address space.
125 unsigned char PointerWidthInBits;
127 /// The alignment of a pointer into the generic address space.
128 unsigned char PointerAlignInBytes;
131 /// CodeGenModule - This class organizes the cross-function state that is used
132 /// while generating LLVM code.
133 class CodeGenModule : public CodeGenTypeCache {
134 CodeGenModule(const CodeGenModule&); // DO NOT IMPLEMENT
135 void operator=(const CodeGenModule&); // DO NOT IMPLEMENT
137 typedef std::vector<std::pair<llvm::Constant*, int> > CtorList;
140 const LangOptions &Features;
141 const CodeGenOptions &CodeGenOpts;
142 llvm::Module &TheModule;
143 const llvm::TargetData &TheTargetData;
144 mutable const TargetCodeGenInfo *TheTargetCodeGenInfo;
150 /// VTables - Holds information about C++ vtables.
151 CodeGenVTables VTables;
152 friend class CodeGenVTables;
154 CGObjCRuntime* Runtime;
155 CGDebugInfo* DebugInfo;
157 // WeakRefReferences - A set of references that have only been seen via
158 // a weakref so far. This is used to remove the weak of the reference if we ever
159 // see a direct reference or a definition.
160 llvm::SmallPtrSet<llvm::GlobalValue*, 10> WeakRefReferences;
162 /// DeferredDecls - This contains all the decls which have definitions but
163 /// which are deferred for emission and therefore should only be output if
164 /// they are actually used. If a decl is in this, then it is known to have
165 /// not been referenced yet.
166 llvm::StringMap<GlobalDecl> DeferredDecls;
168 /// DeferredDeclsToEmit - This is a list of deferred decls which we have seen
169 /// that *are* actually referenced. These get code generated when the module
171 std::vector<GlobalDecl> DeferredDeclsToEmit;
173 /// LLVMUsed - List of global values which are required to be
174 /// present in the object file; bitcast to i8*. This is used for
175 /// forcing visibility of symbols which may otherwise be optimized
177 std::vector<llvm::WeakVH> LLVMUsed;
179 /// GlobalCtors - Store the list of global constructors and their respective
180 /// priorities to be emitted when the translation unit is complete.
181 CtorList GlobalCtors;
183 /// GlobalDtors - Store the list of global destructors and their respective
184 /// priorities to be emitted when the translation unit is complete.
185 CtorList GlobalDtors;
187 /// MangledDeclNames - A map of canonical GlobalDecls to their mangled names.
188 llvm::DenseMap<GlobalDecl, llvm::StringRef> MangledDeclNames;
189 llvm::BumpPtrAllocator MangledNamesAllocator;
191 std::vector<llvm::Constant*> Annotations;
193 llvm::StringMap<llvm::Constant*> CFConstantStringMap;
194 llvm::StringMap<llvm::Constant*> ConstantStringMap;
195 llvm::DenseMap<const Decl*, llvm::Value*> StaticLocalDeclMap;
197 /// CXXGlobalInits - Global variables with initializers that need to run
199 std::vector<llvm::Constant*> CXXGlobalInits;
201 /// When a C++ decl with an initializer is deferred, null is
202 /// appended to CXXGlobalInits, and the index of that null is placed
203 /// here so that the initializer will be performed in the correct
205 llvm::DenseMap<const Decl*, unsigned> DelayedCXXInitPosition;
207 /// - Global variables with initializers whose order of initialization
208 /// is set by init_priority attribute.
210 llvm::SmallVector<std::pair<OrderGlobalInits, llvm::Function*>, 8>
211 PrioritizedCXXGlobalInits;
213 /// CXXGlobalDtors - Global destructor functions and arguments that need to
214 /// run on termination.
215 std::vector<std::pair<llvm::WeakVH,llvm::Constant*> > CXXGlobalDtors;
217 /// CFConstantStringClassRef - Cached reference to the class for constant
218 /// strings. This value has type int * but is actually an Obj-C class pointer.
219 llvm::Constant *CFConstantStringClassRef;
221 /// ConstantStringClassRef - Cached reference to the class for constant
222 /// strings. This value has type int * but is actually an Obj-C class pointer.
223 llvm::Constant *ConstantStringClassRef;
225 /// Lazily create the Objective-C runtime
226 void createObjCRuntime();
228 llvm::LLVMContext &VMContext;
230 /// @name Cache for Blocks Runtime Globals
233 const VarDecl *NSConcreteGlobalBlockDecl;
234 const VarDecl *NSConcreteStackBlockDecl;
235 llvm::Constant *NSConcreteGlobalBlock;
236 llvm::Constant *NSConcreteStackBlock;
238 const FunctionDecl *BlockObjectAssignDecl;
239 const FunctionDecl *BlockObjectDisposeDecl;
240 llvm::Constant *BlockObjectAssign;
241 llvm::Constant *BlockObjectDispose;
243 const llvm::Type *BlockDescriptorType;
244 const llvm::Type *GenericBlockLiteralType;
247 int GlobalUniqueCount;
252 CodeGenModule(ASTContext &C, const CodeGenOptions &CodeGenOpts,
253 llvm::Module &M, const llvm::TargetData &TD, Diagnostic &Diags);
257 /// Release - Finalize LLVM code generation.
260 /// getObjCRuntime() - Return a reference to the configured
261 /// Objective-C runtime.
262 CGObjCRuntime &getObjCRuntime() {
263 if (!Runtime) createObjCRuntime();
267 /// hasObjCRuntime() - Return true iff an Objective-C runtime has
269 bool hasObjCRuntime() { return !!Runtime; }
271 /// getCXXABI() - Return a reference to the configured C++ ABI.
272 CGCXXABI &getCXXABI() { return ABI; }
274 llvm::Value *getStaticLocalDeclAddress(const VarDecl *VD) {
275 return StaticLocalDeclMap[VD];
277 void setStaticLocalDeclAddress(const VarDecl *D,
278 llvm::GlobalVariable *GV) {
279 StaticLocalDeclMap[D] = GV;
282 CGDebugInfo *getModuleDebugInfo() { return DebugInfo; }
284 ASTContext &getContext() const { return Context; }
285 const CodeGenOptions &getCodeGenOpts() const { return CodeGenOpts; }
286 const LangOptions &getLangOptions() const { return Features; }
287 llvm::Module &getModule() const { return TheModule; }
288 CodeGenTypes &getTypes() { return Types; }
289 CodeGenVTables &getVTables() { return VTables; }
290 Diagnostic &getDiags() const { return Diags; }
291 const llvm::TargetData &getTargetData() const { return TheTargetData; }
292 const TargetInfo &getTarget() const { return Context.Target; }
293 llvm::LLVMContext &getLLVMContext() { return VMContext; }
294 const TargetCodeGenInfo &getTargetCodeGenInfo();
295 bool isTargetDarwin() const;
297 bool shouldUseTBAA() const { return TBAA != 0; }
299 llvm::MDNode *getTBAAInfo(QualType QTy);
301 static void DecorateInstruction(llvm::Instruction *Inst,
302 llvm::MDNode *TBAAInfo);
304 /// setGlobalVisibility - Set the visibility for the given LLVM
306 void setGlobalVisibility(llvm::GlobalValue *GV, const NamedDecl *D) const;
308 /// TypeVisibilityKind - The kind of global variable that is passed to
309 /// setTypeVisibility
310 enum TypeVisibilityKind {
313 TVK_ForConstructionVTable,
318 /// setTypeVisibility - Set the visibility for the given global
319 /// value which holds information about a type.
320 void setTypeVisibility(llvm::GlobalValue *GV, const CXXRecordDecl *D,
321 TypeVisibilityKind TVK) const;
323 static llvm::GlobalValue::VisibilityTypes GetLLVMVisibility(Visibility V) {
325 case DefaultVisibility: return llvm::GlobalValue::DefaultVisibility;
326 case HiddenVisibility: return llvm::GlobalValue::HiddenVisibility;
327 case ProtectedVisibility: return llvm::GlobalValue::ProtectedVisibility;
329 llvm_unreachable("unknown visibility!");
330 return llvm::GlobalValue::DefaultVisibility;
333 llvm::Constant *GetAddrOfGlobal(GlobalDecl GD) {
334 if (isa<CXXConstructorDecl>(GD.getDecl()))
335 return GetAddrOfCXXConstructor(cast<CXXConstructorDecl>(GD.getDecl()),
337 else if (isa<CXXDestructorDecl>(GD.getDecl()))
338 return GetAddrOfCXXDestructor(cast<CXXDestructorDecl>(GD.getDecl()),
340 else if (isa<FunctionDecl>(GD.getDecl()))
341 return GetAddrOfFunction(GD);
343 return GetAddrOfGlobalVar(cast<VarDecl>(GD.getDecl()));
346 /// CreateOrReplaceCXXRuntimeVariable - Will return a global variable of the given
347 /// type. If a variable with a different type already exists then a new
348 /// variable with the right type will be created and all uses of the old
349 /// variable will be replaced with a bitcast to the new variable.
350 llvm::GlobalVariable *
351 CreateOrReplaceCXXRuntimeVariable(llvm::StringRef Name, const llvm::Type *Ty,
352 llvm::GlobalValue::LinkageTypes Linkage);
354 /// GetAddrOfGlobalVar - Return the llvm::Constant for the address of the
355 /// given global variable. If Ty is non-null and if the global doesn't exist,
356 /// then it will be greated with the specified type instead of whatever the
357 /// normal requested type would be.
358 llvm::Constant *GetAddrOfGlobalVar(const VarDecl *D,
359 const llvm::Type *Ty = 0);
362 /// GetAddrOfFunction - Return the address of the given function. If Ty is
363 /// non-null, then this function will use the specified type if it has to
365 llvm::Constant *GetAddrOfFunction(GlobalDecl GD,
366 const llvm::Type *Ty = 0,
367 bool ForVTable = false);
369 /// GetAddrOfRTTIDescriptor - Get the address of the RTTI descriptor
370 /// for the given type.
371 llvm::Constant *GetAddrOfRTTIDescriptor(QualType Ty, bool ForEH = false);
373 /// GetAddrOfThunk - Get the address of the thunk for the given global decl.
374 llvm::Constant *GetAddrOfThunk(GlobalDecl GD, const ThunkInfo &Thunk);
376 /// GetWeakRefReference - Get a reference to the target of VD.
377 llvm::Constant *GetWeakRefReference(const ValueDecl *VD);
379 /// GetNonVirtualBaseClassOffset - Returns the offset from a derived class to
380 /// a class. Returns null if the offset is 0.
382 GetNonVirtualBaseClassOffset(const CXXRecordDecl *ClassDecl,
383 CastExpr::path_const_iterator PathBegin,
384 CastExpr::path_const_iterator PathEnd);
386 /// A pair of helper functions for a __block variable.
387 class ByrefHelpers : public llvm::FoldingSetNode {
389 llvm::Constant *CopyHelper;
390 llvm::Constant *DisposeHelper;
392 /// The alignment of the field. This is important because
393 /// different offsets to the field within the byref struct need to
394 /// have different helper functions.
397 ByrefHelpers(CharUnits alignment) : Alignment(alignment) {}
398 virtual ~ByrefHelpers();
400 void Profile(llvm::FoldingSetNodeID &id) const {
401 id.AddInteger(Alignment.getQuantity());
404 virtual void profileImpl(llvm::FoldingSetNodeID &id) const = 0;
406 virtual bool needsCopy() const { return true; }
407 virtual void emitCopy(CodeGenFunction &CGF,
408 llvm::Value *dest, llvm::Value *src) = 0;
410 virtual bool needsDispose() const { return true; }
411 virtual void emitDispose(CodeGenFunction &CGF, llvm::Value *field) = 0;
414 llvm::FoldingSet<ByrefHelpers> ByrefHelpersCache;
416 /// getUniqueBlockCount - Fetches the global unique block count.
417 int getUniqueBlockCount() { return ++Block.GlobalUniqueCount; }
419 /// getBlockDescriptorType - Fetches the type of a generic block
421 const llvm::Type *getBlockDescriptorType();
423 /// getGenericBlockLiteralType - The type of a generic block literal.
424 const llvm::Type *getGenericBlockLiteralType();
426 /// GetAddrOfGlobalBlock - Gets the address of a block which
427 /// requires no captures.
428 llvm::Constant *GetAddrOfGlobalBlock(const BlockExpr *BE, const char *);
430 /// GetStringForStringLiteral - Return the appropriate bytes for a string
431 /// literal, properly padded to match the literal type. If only the address of
432 /// a constant is needed consider using GetAddrOfConstantStringLiteral.
433 std::string GetStringForStringLiteral(const StringLiteral *E);
435 /// GetAddrOfConstantCFString - Return a pointer to a constant CFString object
436 /// for the given string.
437 llvm::Constant *GetAddrOfConstantCFString(const StringLiteral *Literal);
439 /// GetAddrOfConstantString - Return a pointer to a constant NSString object
440 /// for the given string. Or a user defined String object as defined via
441 /// -fconstant-string-class=class_name option.
442 llvm::Constant *GetAddrOfConstantString(const StringLiteral *Literal);
444 /// GetAddrOfConstantStringFromLiteral - Return a pointer to a constant array
445 /// for the given string literal.
446 llvm::Constant *GetAddrOfConstantStringFromLiteral(const StringLiteral *S);
448 /// GetAddrOfConstantStringFromObjCEncode - Return a pointer to a constant
449 /// array for the given ObjCEncodeExpr node.
450 llvm::Constant *GetAddrOfConstantStringFromObjCEncode(const ObjCEncodeExpr *);
452 /// GetAddrOfConstantString - Returns a pointer to a character array
453 /// containing the literal. This contents are exactly that of the given
454 /// string, i.e. it will not be null terminated automatically; see
455 /// GetAddrOfConstantCString. Note that whether the result is actually a
456 /// pointer to an LLVM constant depends on Feature.WriteableStrings.
458 /// The result has pointer to array type.
460 /// \param GlobalName If provided, the name to use for the global
461 /// (if one is created).
462 llvm::Constant *GetAddrOfConstantString(llvm::StringRef Str,
463 const char *GlobalName=0);
465 /// GetAddrOfConstantCString - Returns a pointer to a character array
466 /// containing the literal and a terminating '\0' character. The result has
467 /// pointer to array type.
469 /// \param GlobalName If provided, the name to use for the global (if one is
471 llvm::Constant *GetAddrOfConstantCString(const std::string &str,
472 const char *GlobalName=0);
474 /// GetAddrOfCXXConstructor - Return the address of the constructor of the
476 llvm::GlobalValue *GetAddrOfCXXConstructor(const CXXConstructorDecl *ctor,
477 CXXCtorType ctorType,
478 const CGFunctionInfo *fnInfo = 0);
480 /// GetAddrOfCXXDestructor - Return the address of the constructor of the
482 llvm::GlobalValue *GetAddrOfCXXDestructor(const CXXDestructorDecl *dtor,
483 CXXDtorType dtorType,
484 const CGFunctionInfo *fnInfo = 0);
486 /// getBuiltinLibFunction - Given a builtin id for a function like
487 /// "__builtin_fabsf", return a Function* for "fabsf".
488 llvm::Value *getBuiltinLibFunction(const FunctionDecl *FD,
491 llvm::Function *getIntrinsic(unsigned IID, const llvm::Type **Tys = 0,
492 unsigned NumTys = 0);
494 /// EmitTopLevelDecl - Emit code for a single top level declaration.
495 void EmitTopLevelDecl(Decl *D);
497 /// AddUsedGlobal - Add a global which should be forced to be
498 /// present in the object file; these are emitted to the llvm.used
500 void AddUsedGlobal(llvm::GlobalValue *GV);
502 void AddAnnotation(llvm::Constant *C) { Annotations.push_back(C); }
504 /// AddCXXDtorEntry - Add a destructor and object to add to the C++ global
505 /// destructor function.
506 void AddCXXDtorEntry(llvm::Constant *DtorFn, llvm::Constant *Object) {
507 CXXGlobalDtors.push_back(std::make_pair(DtorFn, Object));
510 /// CreateRuntimeFunction - Create a new runtime function with the specified
512 llvm::Constant *CreateRuntimeFunction(const llvm::FunctionType *Ty,
513 llvm::StringRef Name);
514 /// CreateRuntimeVariable - Create a new runtime global variable with the
515 /// specified type and name.
516 llvm::Constant *CreateRuntimeVariable(const llvm::Type *Ty,
517 llvm::StringRef Name);
519 ///@name Custom Blocks Runtime Interfaces
522 llvm::Constant *getNSConcreteGlobalBlock();
523 llvm::Constant *getNSConcreteStackBlock();
524 llvm::Constant *getBlockObjectAssign();
525 llvm::Constant *getBlockObjectDispose();
529 // UpdateCompleteType - Make sure that this type is translated.
530 void UpdateCompletedType(const TagDecl *TD);
532 llvm::Constant *getMemberPointerConstant(const UnaryOperator *e);
534 /// EmitConstantExpr - Try to emit the given expression as a
535 /// constant; returns 0 if the expression cannot be emitted as a
537 llvm::Constant *EmitConstantExpr(const Expr *E, QualType DestType,
538 CodeGenFunction *CGF = 0);
540 /// EmitNullConstant - Return the result of value-initializing the given
541 /// type, i.e. a null expression of the given type. This is usually,
542 /// but not always, an LLVM null constant.
543 llvm::Constant *EmitNullConstant(QualType T);
545 llvm::Constant *EmitAnnotateAttr(llvm::GlobalValue *GV,
546 const AnnotateAttr *AA, unsigned LineNo);
548 /// Error - Emit a general error that something can't be done.
549 void Error(SourceLocation loc, llvm::StringRef error);
551 /// ErrorUnsupported - Print out an error that codegen doesn't support the
552 /// specified stmt yet.
553 /// \param OmitOnError - If true, then this error should only be emitted if no
554 /// other errors have been reported.
555 void ErrorUnsupported(const Stmt *S, const char *Type,
556 bool OmitOnError=false);
558 /// ErrorUnsupported - Print out an error that codegen doesn't support the
559 /// specified decl yet.
560 /// \param OmitOnError - If true, then this error should only be emitted if no
561 /// other errors have been reported.
562 void ErrorUnsupported(const Decl *D, const char *Type,
563 bool OmitOnError=false);
565 /// SetInternalFunctionAttributes - Set the attributes on the LLVM
566 /// function for the given decl and function info. This applies
567 /// attributes necessary for handling the ABI as well as user
568 /// specified attributes like section.
569 void SetInternalFunctionAttributes(const Decl *D, llvm::Function *F,
570 const CGFunctionInfo &FI);
572 /// SetLLVMFunctionAttributes - Set the LLVM function attributes
573 /// (sext, zext, etc).
574 void SetLLVMFunctionAttributes(const Decl *D,
575 const CGFunctionInfo &Info,
578 /// SetLLVMFunctionAttributesForDefinition - Set the LLVM function attributes
579 /// which only apply to a function definintion.
580 void SetLLVMFunctionAttributesForDefinition(const Decl *D, llvm::Function *F);
582 /// ReturnTypeUsesSRet - Return true iff the given type uses 'sret' when used
583 /// as a return type.
584 bool ReturnTypeUsesSRet(const CGFunctionInfo &FI);
586 /// ReturnTypeUsesSret - Return true iff the given type uses 'fpret' when used
587 /// as a return type.
588 bool ReturnTypeUsesFPRet(QualType ResultType);
590 /// ConstructAttributeList - Get the LLVM attributes and calling convention to
591 /// use for a particular function type.
593 /// \param Info - The function type information.
594 /// \param TargetDecl - The decl these attributes are being constructed
595 /// for. If supplied the attributes applied to this decl may contribute to the
596 /// function attributes and calling convention.
597 /// \param PAL [out] - On return, the attribute list to use.
598 /// \param CallingConv [out] - On return, the LLVM calling convention to use.
599 void ConstructAttributeList(const CGFunctionInfo &Info,
600 const Decl *TargetDecl,
601 AttributeListType &PAL,
602 unsigned &CallingConv);
604 llvm::StringRef getMangledName(GlobalDecl GD);
605 void getBlockMangledName(GlobalDecl GD, MangleBuffer &Buffer,
606 const BlockDecl *BD);
608 void EmitTentativeDefinition(const VarDecl *D);
610 void EmitVTable(CXXRecordDecl *Class, bool DefinitionRequired);
612 llvm::GlobalVariable::LinkageTypes
613 getFunctionLinkage(const FunctionDecl *FD);
615 void setFunctionLinkage(const FunctionDecl *FD, llvm::GlobalValue *V) {
616 V->setLinkage(getFunctionLinkage(FD));
619 /// getVTableLinkage - Return the appropriate linkage for the vtable, VTT,
620 /// and type information of the given class.
621 llvm::GlobalVariable::LinkageTypes getVTableLinkage(const CXXRecordDecl *RD);
623 /// GetTargetTypeStoreSize - Return the store size, in character units, of
624 /// the given LLVM type.
625 CharUnits GetTargetTypeStoreSize(const llvm::Type *Ty) const;
627 /// GetLLVMLinkageVarDefinition - Returns LLVM linkage for a global
629 llvm::GlobalValue::LinkageTypes
630 GetLLVMLinkageVarDefinition(const VarDecl *D,
631 llvm::GlobalVariable *GV);
633 std::vector<const CXXRecordDecl*> DeferredVTables;
636 llvm::GlobalValue *GetGlobalValue(llvm::StringRef Ref);
638 llvm::Constant *GetOrCreateLLVMFunction(llvm::StringRef MangledName,
639 const llvm::Type *Ty,
642 llvm::Constant *GetOrCreateLLVMGlobal(llvm::StringRef MangledName,
643 const llvm::PointerType *PTy,
645 bool UnnamedAddr = false);
647 /// SetCommonAttributes - Set attributes which are common to any
648 /// form of a global definition (alias, Objective-C method,
649 /// function, global variable).
651 /// NOTE: This should only be called for definitions.
652 void SetCommonAttributes(const Decl *D, llvm::GlobalValue *GV);
654 /// SetFunctionDefinitionAttributes - Set attributes for a global definition.
655 void SetFunctionDefinitionAttributes(const FunctionDecl *D,
656 llvm::GlobalValue *GV);
658 /// SetFunctionAttributes - Set function attributes for a function
660 void SetFunctionAttributes(GlobalDecl GD,
662 bool IsIncompleteFunction);
664 /// EmitGlobal - Emit code for a singal global function or var decl. Forward
665 /// declarations are emitted lazily.
666 void EmitGlobal(GlobalDecl D);
668 void EmitGlobalDefinition(GlobalDecl D);
670 void EmitGlobalFunctionDefinition(GlobalDecl GD);
671 void EmitGlobalVarDefinition(const VarDecl *D);
672 void EmitAliasDefinition(GlobalDecl GD);
673 void EmitObjCPropertyImplementations(const ObjCImplementationDecl *D);
674 void EmitObjCIvarInitializations(ObjCImplementationDecl *D);
676 // C++ related functions.
678 bool TryEmitDefinitionAsAlias(GlobalDecl Alias, GlobalDecl Target);
679 bool TryEmitBaseDestructorAsAlias(const CXXDestructorDecl *D);
681 void EmitNamespace(const NamespaceDecl *D);
682 void EmitLinkageSpec(const LinkageSpecDecl *D);
684 /// EmitCXXConstructors - Emit constructors (base, complete) from a
685 /// C++ constructor Decl.
686 void EmitCXXConstructors(const CXXConstructorDecl *D);
688 /// EmitCXXConstructor - Emit a single constructor with the given type from
689 /// a C++ constructor Decl.
690 void EmitCXXConstructor(const CXXConstructorDecl *D, CXXCtorType Type);
692 /// EmitCXXDestructors - Emit destructors (base, complete) from a
693 /// C++ destructor Decl.
694 void EmitCXXDestructors(const CXXDestructorDecl *D);
696 /// EmitCXXDestructor - Emit a single destructor with the given type from
697 /// a C++ destructor Decl.
698 void EmitCXXDestructor(const CXXDestructorDecl *D, CXXDtorType Type);
700 /// EmitCXXGlobalInitFunc - Emit the function that initializes C++ globals.
701 void EmitCXXGlobalInitFunc();
703 /// EmitCXXGlobalDtorFunc - Emit the function that destroys C++ globals.
704 void EmitCXXGlobalDtorFunc();
706 void EmitCXXGlobalVarDeclInitFunc(const VarDecl *D,
707 llvm::GlobalVariable *Addr);
709 // FIXME: Hardcoding priority here is gross.
710 void AddGlobalCtor(llvm::Function *Ctor, int Priority=65535);
711 void AddGlobalDtor(llvm::Function *Dtor, int Priority=65535);
713 /// EmitCtorList - Generates a global array of functions and priorities using
714 /// the given list and name. This array will have appending linkage and is
715 /// suitable for use as a LLVM constructor or destructor array.
716 void EmitCtorList(const CtorList &Fns, const char *GlobalName);
718 void EmitAnnotations(void);
720 /// EmitFundamentalRTTIDescriptor - Emit the RTTI descriptors for the
722 void EmitFundamentalRTTIDescriptor(QualType Type);
724 /// EmitFundamentalRTTIDescriptors - Emit the RTTI descriptors for the
726 void EmitFundamentalRTTIDescriptors();
728 /// EmitDeferred - Emit any needed decls for which code generation
730 void EmitDeferred(void);
732 /// EmitLLVMUsed - Emit the llvm.used metadata used to force
733 /// references to global which may otherwise be optimized out.
734 void EmitLLVMUsed(void);
736 void EmitDeclMetadata();
738 /// MayDeferGeneration - Determine if the given decl can be emitted
739 /// lazily; this is only relevant for definitions. The given decl
740 /// must be either a function or var decl.
741 bool MayDeferGeneration(const ValueDecl *D);
743 /// SimplifyPersonality - Check whether we can use a "simpler", more
744 /// core exceptions personality function.
745 void SimplifyPersonality();
747 } // end namespace CodeGen
748 } // end namespace clang