diff options
author | Daniel Dunbar <daniel@zuster.org> | 2008-07-29 23:18:29 +0000 |
---|---|---|
committer | Daniel Dunbar <daniel@zuster.org> | 2008-07-29 23:18:29 +0000 |
commit | bd012ff1fa088181646a784f385b28867372d434 (patch) | |
tree | 1ebb8c8ea9f37c4b01ecc872d7030c0d0504e106 /lib/CodeGen/CodeGenModule.h | |
parent | 4f95b750534f2111f28434b282bcbd5656002816 (diff) |
Rework codegen emission of globals
- No (intended) functionality change.
- Primary purpose is to clearly separate (lazy) construction of
globals that are a forward declaration or tentative definition from
those that are the final definition.
- Lazy construction is now encapsulated in
GetAddrOf{Function,GlobalVar} while final definitions are
constructed in EmitGlobal{Function,Var}Definition.
- External interface for dealing with globals is now limited to
EmitGlobal and GetAddrOf{Function,GlobalVar}.
- Also updated helper functions dealing with statics, annotations,
and ctors to be private.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@54179 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CodeGenModule.h')
-rw-r--r-- | lib/CodeGen/CodeGenModule.h | 51 |
1 files changed, 34 insertions, 17 deletions
diff --git a/lib/CodeGen/CodeGenModule.h b/lib/CodeGen/CodeGenModule.h index 8609497242..57363cddee 100644 --- a/lib/CodeGen/CodeGenModule.h +++ b/lib/CodeGen/CodeGenModule.h @@ -1,4 +1,4 @@ -//===--- CodeGenModule.h - Per-Module state for LLVM CodeGen --------------===// +//===--- CodeGenModule.h - Per-Module state for LLVM CodeGen ----*- C++ -*-===// // // The LLVM Compiler Infrastructure // @@ -40,6 +40,7 @@ namespace clang { class Expr; class Stmt; class NamedDecl; + class ValueDecl; class VarDecl; struct LangOptions; class Diagnostic; @@ -66,7 +67,13 @@ class CodeGenModule { llvm::Function *MemMoveFn; llvm::Function *MemSetFn; llvm::DenseMap<const Decl*, llvm::Constant*> GlobalDeclMap; - std::vector<const NamedDecl*> StaticDecls; + + /// List of static global for which code generation is delayed. When + /// the translation unit has been fully processed we will lazily + /// emit definitions for only the decls that were actually used. + /// This should contain only Function and Var decls, and only those + /// which actually define something. + std::vector<const ValueDecl*> StaticDecls; std::vector<llvm::Constant*> GlobalCtors; std::vector<llvm::Constant*> Annotations; @@ -90,11 +97,14 @@ public: CodeGenTypes &getTypes() { return Types; } Diagnostic &getDiags() const { return Diags; } const llvm::TargetData &getTargetData() const { return TheTargetData; } - - llvm::Constant *GetAddrOfFunctionDecl(const FunctionDecl *D, - bool isDefinition); - llvm::Constant *GetAddrOfGlobalVar(const VarDecl *D, bool isDefinition); - + + /// GetAddrOfGlobalVar - Return the llvm::Constant for the address + /// of the given global variable. + llvm::Constant *GetAddrOfGlobalVar(const VarDecl *D); + + /// GetAddrOfFunction - Return the llvm::Constant for the address + /// of the given function. + llvm::Constant *GetAddrOfFunction(const FunctionDecl *D); /// getBuiltinLibFunction - Given a builtin id for a function like /// "__builtin_fabsf", return a Function* for "fabsf". @@ -111,21 +121,18 @@ public: llvm::Function *getIntrinsic(unsigned IID, const llvm::Type **Tys = 0, unsigned NumTys = 0); - void AddGlobalCtor(llvm::Function * Ctor); - void EmitGlobalCtors(void); - void AddAnnotation(llvm::Constant *C) { Annotations.push_back(C); } - void EmitAnnotations(void); - void EmitStatics(void); - void EmitObjCMethod(const ObjCMethodDecl *OMD); void EmitObjCCategoryImpl(const ObjCCategoryImplDecl *OCD); void EmitObjCClassImplementation(const ObjCImplementationDecl *OID); void EmitObjCProtocolImplementation(const ObjCProtocolDecl *PD); - void EmitFunction(const FunctionDecl *FD); - void EmitGlobalVar(const VarDecl *D); - void EmitGlobalVarInit(const VarDecl *D); + + /// EmitGlobal - Emit code for a singal global function or var + /// decl. Forward declarations are emitted lazily. + void EmitGlobal(const ValueDecl *D); + + void AddAnnotation(llvm::Constant *C) { Annotations.push_back(C); } + void UpdateCompletedType(const TagDecl *D); - llvm::Constant *EmitGlobalInit(const Expr *E); llvm::Constant *EmitConstantExpr(const Expr *E, CodeGenFunction *CGF = 0); llvm::Constant *EmitAnnotateAttr(llvm::GlobalValue *GV, const AnnotateAttr *AA, unsigned LineNo); @@ -157,6 +164,16 @@ private: void SetGlobalValueAttributes(const FunctionDecl *FD, llvm::GlobalValue *GV); + void EmitGlobalDefinition(const ValueDecl *D); + llvm::GlobalValue *EmitForwardFunctionDefinition(const FunctionDecl *D); + void EmitGlobalFunctionDefinition(const FunctionDecl *D); + void EmitGlobalVarDefinition(const VarDecl *D); + + void AddGlobalCtor(llvm::Function * Ctor); + void EmitGlobalCtors(void); + void EmitAnnotations(void); + void EmitStatics(void); + }; } // end namespace CodeGen } // end namespace clang |