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