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