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/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 "CGBlocks.h"
24 #include "CGCall.h"
25 #include "CGVTables.h"
26 #include "CodeGenTypes.h"
27 #include "GlobalDecl.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   class MangleBuffer;
70 
71 namespace CodeGen {
72 
73   class CodeGenFunction;
74   class CodeGenTBAA;
75   class CGCXXABI;
76   class CGDebugInfo;
77   class CGObjCRuntime;
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,
263                            bool IsForDefinition) const;
264 
265   /// setTypeVisibility - Set the visibility for the given global
266   /// value which holds information about a type.
267   void setTypeVisibility(llvm::GlobalValue *GV, const CXXRecordDecl *D,
268                          bool IsForRTTI, bool IsForDefinition) const;
269 
270   llvm::Constant *GetAddrOfGlobal(GlobalDecl GD) {
271     if (isa<CXXConstructorDecl>(GD.getDecl()))
272       return GetAddrOfCXXConstructor(cast<CXXConstructorDecl>(GD.getDecl()),
273                                      GD.getCtorType());
274     else if (isa<CXXDestructorDecl>(GD.getDecl()))
275       return GetAddrOfCXXDestructor(cast<CXXDestructorDecl>(GD.getDecl()),
276                                      GD.getDtorType());
277     else if (isa<FunctionDecl>(GD.getDecl()))
278       return GetAddrOfFunction(GD);
279     else
280       return GetAddrOfGlobalVar(cast<VarDecl>(GD.getDecl()));
281   }
282 
283   /// GetAddrOfGlobalVar - Return the llvm::Constant for the address of the
284   /// given global variable.  If Ty is non-null and if the global doesn't exist,
285   /// then it will be greated with the specified type instead of whatever the
286   /// normal requested type would be.
287   llvm::Constant *GetAddrOfGlobalVar(const VarDecl *D,
288                                      const llvm::Type *Ty = 0);
289 
290   /// GetAddrOfFunction - Return the address of the given function.  If Ty is
291   /// non-null, then this function will use the specified type if it has to
292   /// create it.
293   llvm::Constant *GetAddrOfFunction(GlobalDecl GD,
294                                     const llvm::Type *Ty = 0);
295 
296   /// GetAddrOfRTTIDescriptor - Get the address of the RTTI descriptor
297   /// for the given type.
298   llvm::Constant *GetAddrOfRTTIDescriptor(QualType Ty, bool ForEH = false);
299 
300   /// GetAddrOfThunk - Get the address of the thunk for the given global decl.
301   llvm::Constant *GetAddrOfThunk(GlobalDecl GD, const ThunkInfo &Thunk);
302 
303   /// GetWeakRefReference - Get a reference to the target of VD.
304   llvm::Constant *GetWeakRefReference(const ValueDecl *VD);
305 
306   /// GetNonVirtualBaseClassOffset - Returns the offset from a derived class to
307   /// a class. Returns null if the offset is 0.
308   llvm::Constant *
309   GetNonVirtualBaseClassOffset(const CXXRecordDecl *ClassDecl,
310                                CastExpr::path_const_iterator PathBegin,
311                                CastExpr::path_const_iterator PathEnd);
312 
313   /// GetStringForStringLiteral - Return the appropriate bytes for a string
314   /// literal, properly padded to match the literal type. If only the address of
315   /// a constant is needed consider using GetAddrOfConstantStringLiteral.
316   std::string GetStringForStringLiteral(const StringLiteral *E);
317 
318   /// GetAddrOfConstantCFString - Return a pointer to a constant CFString object
319   /// for the given string.
320   llvm::Constant *GetAddrOfConstantCFString(const StringLiteral *Literal);
321 
322   /// GetAddrOfConstantString - Return a pointer to a constant NSString object
323   /// for the given string. Or a user defined String object as defined via
324   /// -fconstant-string-class=class_name option.
325   llvm::Constant *GetAddrOfConstantString(const StringLiteral *Literal);
326 
327   /// GetAddrOfConstantStringFromLiteral - Return a pointer to a constant array
328   /// for the given string literal.
329   llvm::Constant *GetAddrOfConstantStringFromLiteral(const StringLiteral *S);
330 
331   /// GetAddrOfConstantStringFromObjCEncode - Return a pointer to a constant
332   /// array for the given ObjCEncodeExpr node.
333   llvm::Constant *GetAddrOfConstantStringFromObjCEncode(const ObjCEncodeExpr *);
334 
335   /// GetAddrOfConstantString - Returns a pointer to a character array
336   /// containing the literal. This contents are exactly that of the given
337   /// string, i.e. it will not be null terminated automatically; see
338   /// GetAddrOfConstantCString. Note that whether the result is actually a
339   /// pointer to an LLVM constant depends on Feature.WriteableStrings.
340   ///
341   /// The result has pointer to array type.
342   ///
343   /// \param GlobalName If provided, the name to use for the global
344   /// (if one is created).
345   llvm::Constant *GetAddrOfConstantString(const std::string& str,
346                                           const char *GlobalName=0);
347 
348   /// GetAddrOfConstantCString - Returns a pointer to a character array
349   /// containing the literal and a terminating '\0' character. The result has
350   /// pointer to array type.
351   ///
352   /// \param GlobalName If provided, the name to use for the global (if one is
353   /// created).
354   llvm::Constant *GetAddrOfConstantCString(const std::string &str,
355                                            const char *GlobalName=0);
356 
357   /// GetAddrOfCXXConstructor - Return the address of the constructor of the
358   /// given type.
359   llvm::GlobalValue *GetAddrOfCXXConstructor(const CXXConstructorDecl *D,
360                                              CXXCtorType Type);
361 
362   /// GetAddrOfCXXDestructor - Return the address of the constructor of the
363   /// given type.
364   llvm::GlobalValue *GetAddrOfCXXDestructor(const CXXDestructorDecl *D,
365                                             CXXDtorType Type);
366 
367   /// getBuiltinLibFunction - Given a builtin id for a function like
368   /// "__builtin_fabsf", return a Function* for "fabsf".
369   llvm::Value *getBuiltinLibFunction(const FunctionDecl *FD,
370                                      unsigned BuiltinID);
371 
372   llvm::Function *getIntrinsic(unsigned IID, const llvm::Type **Tys = 0,
373                                unsigned NumTys = 0);
374 
375   /// EmitTopLevelDecl - Emit code for a single top level declaration.
376   void EmitTopLevelDecl(Decl *D);
377 
378   /// AddUsedGlobal - Add a global which should be forced to be
379   /// present in the object file; these are emitted to the llvm.used
380   /// metadata global.
381   void AddUsedGlobal(llvm::GlobalValue *GV);
382 
383   void AddAnnotation(llvm::Constant *C) { Annotations.push_back(C); }
384 
385   /// AddCXXDtorEntry - Add a destructor and object to add to the C++ global
386   /// destructor function.
387   void AddCXXDtorEntry(llvm::Constant *DtorFn, llvm::Constant *Object) {
388     CXXGlobalDtors.push_back(std::make_pair(DtorFn, Object));
389   }
390 
391   /// CreateRuntimeFunction - Create a new runtime function with the specified
392   /// type and name.
393   llvm::Constant *CreateRuntimeFunction(const llvm::FunctionType *Ty,
394                                         llvm::StringRef Name);
395   /// CreateRuntimeVariable - Create a new runtime global variable with the
396   /// specified type and name.
397   llvm::Constant *CreateRuntimeVariable(const llvm::Type *Ty,
398                                         llvm::StringRef Name);
399 
400   ///@name Custom Blocks Runtime Interfaces
401   ///@{
402 
403   llvm::Constant *getNSConcreteGlobalBlock();
404   llvm::Constant *getNSConcreteStackBlock();
405   llvm::Constant *getBlockObjectAssign();
406   llvm::Constant *getBlockObjectDispose();
407 
408   ///@}
409 
410   void UpdateCompletedType(const TagDecl *TD) {
411     // Make sure that this type is translated.
412     Types.UpdateCompletedType(TD);
413   }
414 
415   /// EmitConstantExpr - Try to emit the given expression as a
416   /// constant; returns 0 if the expression cannot be emitted as a
417   /// constant.
418   llvm::Constant *EmitConstantExpr(const Expr *E, QualType DestType,
419                                    CodeGenFunction *CGF = 0);
420 
421   /// EmitNullConstant - Return the result of value-initializing the given
422   /// type, i.e. a null expression of the given type.  This is usually,
423   /// but not always, an LLVM null constant.
424   llvm::Constant *EmitNullConstant(QualType T);
425 
426   llvm::Constant *EmitAnnotateAttr(llvm::GlobalValue *GV,
427                                    const AnnotateAttr *AA, unsigned LineNo);
428 
429   /// ErrorUnsupported - Print out an error that codegen doesn't support the
430   /// specified stmt yet.
431   /// \param OmitOnError - If true, then this error should only be emitted if no
432   /// other errors have been reported.
433   void ErrorUnsupported(const Stmt *S, const char *Type,
434                         bool OmitOnError=false);
435 
436   /// ErrorUnsupported - Print out an error that codegen doesn't support the
437   /// specified decl yet.
438   /// \param OmitOnError - If true, then this error should only be emitted if no
439   /// other errors have been reported.
440   void ErrorUnsupported(const Decl *D, const char *Type,
441                         bool OmitOnError=false);
442 
443   /// SetInternalFunctionAttributes - Set the attributes on the LLVM
444   /// function for the given decl and function info. This applies
445   /// attributes necessary for handling the ABI as well as user
446   /// specified attributes like section.
447   void SetInternalFunctionAttributes(const Decl *D, llvm::Function *F,
448                                      const CGFunctionInfo &FI);
449 
450   /// SetLLVMFunctionAttributes - Set the LLVM function attributes
451   /// (sext, zext, etc).
452   void SetLLVMFunctionAttributes(const Decl *D,
453                                  const CGFunctionInfo &Info,
454                                  llvm::Function *F);
455 
456   /// SetLLVMFunctionAttributesForDefinition - Set the LLVM function attributes
457   /// which only apply to a function definintion.
458   void SetLLVMFunctionAttributesForDefinition(const Decl *D, llvm::Function *F);
459 
460   /// ReturnTypeUsesSRet - Return true iff the given type uses 'sret' when used
461   /// as a return type.
462   bool ReturnTypeUsesSRet(const CGFunctionInfo &FI);
463 
464   /// ReturnTypeUsesSret - Return true iff the given type uses 'fpret' when used
465   /// as a return type.
466   bool ReturnTypeUsesFPRet(QualType ResultType);
467 
468   /// ConstructAttributeList - Get the LLVM attributes and calling convention to
469   /// use for a particular function type.
470   ///
471   /// \param Info - The function type information.
472   /// \param TargetDecl - The decl these attributes are being constructed
473   /// for. If supplied the attributes applied to this decl may contribute to the
474   /// function attributes and calling convention.
475   /// \param PAL [out] - On return, the attribute list to use.
476   /// \param CallingConv [out] - On return, the LLVM calling convention to use.
477   void ConstructAttributeList(const CGFunctionInfo &Info,
478                               const Decl *TargetDecl,
479                               AttributeListType &PAL,
480                               unsigned &CallingConv);
481 
482   llvm::StringRef getMangledName(GlobalDecl GD);
483   void getBlockMangledName(GlobalDecl GD, MangleBuffer &Buffer,
484                            const BlockDecl *BD);
485 
486   void EmitTentativeDefinition(const VarDecl *D);
487 
488   void EmitVTable(CXXRecordDecl *Class, bool DefinitionRequired);
489 
490   llvm::GlobalVariable::LinkageTypes
491   getFunctionLinkage(const FunctionDecl *FD);
492 
493   void setFunctionLinkage(const FunctionDecl *FD, llvm::GlobalValue *V) {
494     V->setLinkage(getFunctionLinkage(FD));
495   }
496 
497   /// getVTableLinkage - Return the appropriate linkage for the vtable, VTT,
498   /// and type information of the given class.
499   llvm::GlobalVariable::LinkageTypes getVTableLinkage(const CXXRecordDecl *RD);
500 
501   /// GetTargetTypeStoreSize - Return the store size, in character units, of
502   /// the given LLVM type.
503   CharUnits GetTargetTypeStoreSize(const llvm::Type *Ty) const;
504 
505   /// GetLLVMLinkageVarDefinition - Returns LLVM linkage for a global
506   /// variable.
507   llvm::GlobalValue::LinkageTypes
508   GetLLVMLinkageVarDefinition(const VarDecl *D,
509                               llvm::GlobalVariable *GV);
510 
511   std::vector<const CXXRecordDecl*> DeferredVTables;
512 
513 private:
514   llvm::GlobalValue *GetGlobalValue(llvm::StringRef Ref);
515 
516   llvm::Constant *GetOrCreateLLVMFunction(llvm::StringRef MangledName,
517                                           const llvm::Type *Ty,
518                                           GlobalDecl D);
519   llvm::Constant *GetOrCreateLLVMGlobal(llvm::StringRef MangledName,
520                                         const llvm::PointerType *PTy,
521                                         const VarDecl *D,
522                                         bool UnnamedAddr = false);
523 
524   /// SetCommonAttributes - Set attributes which are common to any
525   /// form of a global definition (alias, Objective-C method,
526   /// function, global variable).
527   ///
528   /// NOTE: This should only be called for definitions.
529   void SetCommonAttributes(const Decl *D, llvm::GlobalValue *GV);
530 
531   /// SetFunctionDefinitionAttributes - Set attributes for a global definition.
532   void SetFunctionDefinitionAttributes(const FunctionDecl *D,
533                                        llvm::GlobalValue *GV);
534 
535   /// SetFunctionAttributes - Set function attributes for a function
536   /// declaration.
537   void SetFunctionAttributes(GlobalDecl GD,
538                              llvm::Function *F,
539                              bool IsIncompleteFunction);
540 
541   /// EmitGlobal - Emit code for a singal global function or var decl. Forward
542   /// declarations are emitted lazily.
543   void EmitGlobal(GlobalDecl D);
544 
545   void EmitGlobalDefinition(GlobalDecl D);
546 
547   void EmitGlobalFunctionDefinition(GlobalDecl GD);
548   void EmitGlobalVarDefinition(const VarDecl *D);
549   void EmitAliasDefinition(GlobalDecl GD);
550   void EmitObjCPropertyImplementations(const ObjCImplementationDecl *D);
551   void EmitObjCIvarInitializations(ObjCImplementationDecl *D);
552 
553   // C++ related functions.
554 
555   bool TryEmitDefinitionAsAlias(GlobalDecl Alias, GlobalDecl Target);
556   bool TryEmitBaseDestructorAsAlias(const CXXDestructorDecl *D);
557 
558   void EmitNamespace(const NamespaceDecl *D);
559   void EmitLinkageSpec(const LinkageSpecDecl *D);
560 
561   /// EmitCXXConstructors - Emit constructors (base, complete) from a
562   /// C++ constructor Decl.
563   void EmitCXXConstructors(const CXXConstructorDecl *D);
564 
565   /// EmitCXXConstructor - Emit a single constructor with the given type from
566   /// a C++ constructor Decl.
567   void EmitCXXConstructor(const CXXConstructorDecl *D, CXXCtorType Type);
568 
569   /// EmitCXXDestructors - Emit destructors (base, complete) from a
570   /// C++ destructor Decl.
571   void EmitCXXDestructors(const CXXDestructorDecl *D);
572 
573   /// EmitCXXDestructor - Emit a single destructor with the given type from
574   /// a C++ destructor Decl.
575   void EmitCXXDestructor(const CXXDestructorDecl *D, CXXDtorType Type);
576 
577   /// EmitCXXGlobalInitFunc - Emit the function that initializes C++ globals.
578   void EmitCXXGlobalInitFunc();
579 
580   /// EmitCXXGlobalDtorFunc - Emit the function that destroys C++ globals.
581   void EmitCXXGlobalDtorFunc();
582 
583   void EmitCXXGlobalVarDeclInitFunc(const VarDecl *D,
584                                     llvm::GlobalVariable *Addr);
585 
586   // FIXME: Hardcoding priority here is gross.
587   void AddGlobalCtor(llvm::Function *Ctor, int Priority=65535);
588   void AddGlobalDtor(llvm::Function *Dtor, int Priority=65535);
589 
590   /// EmitCtorList - Generates a global array of functions and priorities using
591   /// the given list and name. This array will have appending linkage and is
592   /// suitable for use as a LLVM constructor or destructor array.
593   void EmitCtorList(const CtorList &Fns, const char *GlobalName);
594 
595   void EmitAnnotations(void);
596 
597   /// EmitFundamentalRTTIDescriptor - Emit the RTTI descriptors for the
598   /// given type.
599   void EmitFundamentalRTTIDescriptor(QualType Type);
600 
601   /// EmitFundamentalRTTIDescriptors - Emit the RTTI descriptors for the
602   /// builtin types.
603   void EmitFundamentalRTTIDescriptors();
604 
605   /// EmitDeferred - Emit any needed decls for which code generation
606   /// was deferred.
607   void EmitDeferred(void);
608 
609   /// EmitLLVMUsed - Emit the llvm.used metadata used to force
610   /// references to global which may otherwise be optimized out.
611   void EmitLLVMUsed(void);
612 
613   void EmitDeclMetadata();
614 
615   /// MayDeferGeneration - Determine if the given decl can be emitted
616   /// lazily; this is only relevant for definitions. The given decl
617   /// must be either a function or var decl.
618   bool MayDeferGeneration(const ValueDecl *D);
619 
620   /// SimplifyPersonality - Check whether we can use a "simpler", more
621   /// core exceptions personality function.
622   void SimplifyPersonality();
623 };
624 }  // end namespace CodeGen
625 }  // end namespace clang
626 
627 #endif
628