2008-07-30 03:18:29 +04:00
|
|
|
//===--- CodeGenModule.h - Per-Module state for LLVM CodeGen ----*- C++ -*-===//
|
2007-07-11 21:01:13 +04:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 22:59:25 +03:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2007-07-11 21:01:13 +04:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This is the internal per-translation-unit state used for llvm translation.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2008-02-29 20:10:38 +03:00
|
|
|
#ifndef CLANG_CODEGEN_CODEGENMODULE_H
|
|
|
|
#define CLANG_CODEGEN_CODEGENMODULE_H
|
2007-07-11 21:01:13 +04:00
|
|
|
|
|
|
|
#include "CodeGenTypes.h"
|
2008-03-01 11:45:05 +03:00
|
|
|
#include "CGObjCRuntime.h"
|
2008-05-22 04:50:06 +04:00
|
|
|
#include "clang/AST/Attr.h"
|
2007-07-11 21:01:13 +04:00
|
|
|
#include "llvm/ADT/DenseMap.h"
|
2007-08-21 04:21:21 +04:00
|
|
|
#include "llvm/ADT/StringMap.h"
|
2007-07-11 21:01:13 +04:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
class Module;
|
|
|
|
class Constant;
|
|
|
|
class Function;
|
2008-04-19 08:17:09 +04:00
|
|
|
class GlobalValue;
|
2007-10-31 23:01:01 +03:00
|
|
|
class TargetData;
|
2008-06-01 19:54:49 +04:00
|
|
|
class FunctionType;
|
2007-07-11 21:01:13 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
namespace clang {
|
|
|
|
class ASTContext;
|
|
|
|
class FunctionDecl;
|
2008-03-31 03:03:07 +04:00
|
|
|
class ObjCMethodDecl;
|
2008-06-01 18:13:53 +04:00
|
|
|
class ObjCImplementationDecl;
|
|
|
|
class ObjCCategoryImplDecl;
|
|
|
|
class ObjCProtocolDecl;
|
2007-07-11 21:01:13 +04:00
|
|
|
class Decl;
|
2007-12-02 03:11:25 +03:00
|
|
|
class Expr;
|
2007-12-02 10:19:18 +03:00
|
|
|
class Stmt;
|
2008-04-21 00:38:08 +04:00
|
|
|
class NamedDecl;
|
2008-07-30 03:18:29 +04:00
|
|
|
class ValueDecl;
|
2007-12-18 11:16:44 +03:00
|
|
|
class VarDecl;
|
2007-11-28 08:34:05 +03:00
|
|
|
struct LangOptions;
|
2007-12-02 04:40:18 +03:00
|
|
|
class Diagnostic;
|
2008-04-19 08:17:09 +04:00
|
|
|
class AnnotateAttr;
|
2007-07-11 21:01:13 +04:00
|
|
|
|
|
|
|
namespace CodeGen {
|
|
|
|
|
2008-02-27 00:41:45 +03:00
|
|
|
class CodeGenFunction;
|
2008-05-08 12:54:20 +04:00
|
|
|
class CGDebugInfo;
|
|
|
|
|
2007-07-11 21:01:13 +04:00
|
|
|
/// CodeGenModule - This class organizes the cross-module state that is used
|
|
|
|
/// while generating LLVM code.
|
|
|
|
class CodeGenModule {
|
|
|
|
ASTContext &Context;
|
2007-11-28 08:34:05 +03:00
|
|
|
const LangOptions &Features;
|
2007-07-11 21:01:13 +04:00
|
|
|
llvm::Module &TheModule;
|
2007-10-31 23:01:01 +03:00
|
|
|
const llvm::TargetData &TheTargetData;
|
2007-12-02 04:40:18 +03:00
|
|
|
Diagnostic &Diags;
|
2007-07-11 21:01:13 +04:00
|
|
|
CodeGenTypes Types;
|
2008-03-01 11:45:05 +03:00
|
|
|
CGObjCRuntime *Runtime;
|
2008-05-08 12:54:20 +04:00
|
|
|
CGDebugInfo *DebugInfo;
|
2007-07-11 21:01:13 +04:00
|
|
|
|
|
|
|
llvm::Function *MemCpyFn;
|
2008-05-26 16:59:39 +04:00
|
|
|
llvm::Function *MemMoveFn;
|
2008-02-20 01:01:01 +03:00
|
|
|
llvm::Function *MemSetFn;
|
2007-07-11 21:01:13 +04:00
|
|
|
llvm::DenseMap<const Decl*, llvm::Constant*> GlobalDeclMap;
|
2008-07-30 03:18:29 +04:00
|
|
|
|
|
|
|
/// 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;
|
2008-04-20 10:29:50 +04:00
|
|
|
|
2008-03-14 20:18:18 +03:00
|
|
|
std::vector<llvm::Constant*> GlobalCtors;
|
2008-04-19 03:43:57 +04:00
|
|
|
std::vector<llvm::Constant*> Annotations;
|
2007-11-28 08:34:05 +03:00
|
|
|
|
2007-08-21 04:21:21 +04:00
|
|
|
llvm::StringMap<llvm::Constant*> CFConstantStringMap;
|
2007-11-28 08:34:05 +03:00
|
|
|
llvm::StringMap<llvm::Constant*> ConstantStringMap;
|
2007-08-21 04:21:21 +04:00
|
|
|
llvm::Constant *CFConstantStringClassRef;
|
2007-08-31 08:31:45 +04:00
|
|
|
|
|
|
|
std::vector<llvm::Function *> BuiltinFunctions;
|
2007-07-11 21:01:13 +04:00
|
|
|
public:
|
2007-11-28 08:34:05 +03:00
|
|
|
CodeGenModule(ASTContext &C, const LangOptions &Features, llvm::Module &M,
|
2008-05-08 12:54:20 +04:00
|
|
|
const llvm::TargetData &TD, Diagnostic &Diags,
|
|
|
|
bool GenerateDebugInfo);
|
2008-03-01 11:45:05 +03:00
|
|
|
~CodeGenModule();
|
2007-07-11 21:01:13 +04:00
|
|
|
|
2008-03-01 11:45:05 +03:00
|
|
|
CGObjCRuntime *getObjCRuntime() { return Runtime; }
|
2008-05-08 12:54:20 +04:00
|
|
|
CGDebugInfo *getDebugInfo() { return DebugInfo; }
|
2007-07-11 21:01:13 +04:00
|
|
|
ASTContext &getContext() const { return Context; }
|
2007-11-28 08:34:05 +03:00
|
|
|
const LangOptions &getLangOptions() const { return Features; }
|
2007-07-11 21:01:13 +04:00
|
|
|
llvm::Module &getModule() const { return TheModule; }
|
|
|
|
CodeGenTypes &getTypes() { return Types; }
|
2007-12-02 04:40:18 +03:00
|
|
|
Diagnostic &getDiags() const { return Diags; }
|
2008-01-03 09:36:51 +03:00
|
|
|
const llvm::TargetData &getTargetData() const { return TheTargetData; }
|
2008-07-30 03:18:29 +04:00
|
|
|
|
|
|
|
/// 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);
|
2007-12-02 09:27:33 +03:00
|
|
|
|
2007-08-31 08:31:45 +04:00
|
|
|
/// getBuiltinLibFunction - Given a builtin id for a function like
|
|
|
|
/// "__builtin_fabsf", return a Function* for "fabsf".
|
|
|
|
///
|
|
|
|
llvm::Function *getBuiltinLibFunction(unsigned BuiltinID);
|
2007-08-21 04:21:21 +04:00
|
|
|
llvm::Constant *GetAddrOfConstantCFString(const std::string& str);
|
2008-02-11 03:02:17 +03:00
|
|
|
|
|
|
|
/// GetAddrOfConstantString -- returns a pointer to the character
|
|
|
|
/// array containing the literal. The result is pointer to array type.
|
2007-11-28 08:34:05 +03:00
|
|
|
llvm::Constant *GetAddrOfConstantString(const std::string& str);
|
2007-07-11 21:01:13 +04:00
|
|
|
llvm::Function *getMemCpyFn();
|
2008-05-26 16:59:39 +04:00
|
|
|
llvm::Function *getMemMoveFn();
|
2008-02-20 01:01:01 +03:00
|
|
|
llvm::Function *getMemSetFn();
|
2007-12-18 03:25:38 +03:00
|
|
|
llvm::Function *getIntrinsic(unsigned IID, const llvm::Type **Tys = 0,
|
|
|
|
unsigned NumTys = 0);
|
2007-08-31 08:31:45 +04:00
|
|
|
|
2008-03-31 03:03:07 +04:00
|
|
|
void EmitObjCMethod(const ObjCMethodDecl *OMD);
|
2008-06-01 18:13:53 +04:00
|
|
|
void EmitObjCCategoryImpl(const ObjCCategoryImplDecl *OCD);
|
|
|
|
void EmitObjCClassImplementation(const ObjCImplementationDecl *OID);
|
|
|
|
void EmitObjCProtocolImplementation(const ObjCProtocolDecl *PD);
|
2008-07-30 03:18:29 +04:00
|
|
|
|
|
|
|
/// 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); }
|
|
|
|
|
2008-02-06 08:08:19 +03:00
|
|
|
void UpdateCompletedType(const TagDecl *D);
|
2008-02-27 00:41:45 +03:00
|
|
|
llvm::Constant *EmitConstantExpr(const Expr *E, CodeGenFunction *CGF = 0);
|
2008-04-19 08:17:09 +04:00
|
|
|
llvm::Constant *EmitAnnotateAttr(llvm::GlobalValue *GV,
|
|
|
|
const AnnotateAttr *AA, unsigned LineNo);
|
2008-01-26 04:36:00 +03:00
|
|
|
|
2007-12-02 10:19:18 +03:00
|
|
|
/// WarnUnsupported - Print out a warning that codegen doesn't support the
|
|
|
|
/// specified stmt yet.
|
2008-01-26 04:36:00 +03:00
|
|
|
|
2007-12-02 10:19:18 +03:00
|
|
|
void WarnUnsupported(const Stmt *S, const char *Type);
|
|
|
|
|
2008-01-12 10:05:38 +03:00
|
|
|
/// WarnUnsupported - Print out a warning that codegen doesn't support the
|
|
|
|
/// specified decl yet.
|
|
|
|
void WarnUnsupported(const Decl *D, const char *Type);
|
|
|
|
|
2008-05-22 04:50:06 +04:00
|
|
|
/// setVisibility - Set the visibility for the given LLVM GlobalValue
|
|
|
|
/// according to the given clang AST visibility value.
|
|
|
|
static void setVisibility(llvm::GlobalValue *GV,
|
|
|
|
VisibilityAttr::VisibilityTypes);
|
|
|
|
|
2007-12-02 10:09:19 +03:00
|
|
|
private:
|
|
|
|
/// ReplaceMapValuesWith - This is a really slow and bad function that
|
|
|
|
/// searches for any entries in GlobalDeclMap that point to OldVal, changing
|
|
|
|
/// them to point to NewVal. This is badbadbad, FIXME!
|
|
|
|
void ReplaceMapValuesWith(llvm::Constant *OldVal, llvm::Constant *NewVal);
|
2008-06-01 19:54:49 +04:00
|
|
|
|
|
|
|
void SetFunctionAttributes(const FunctionDecl *FD,
|
|
|
|
llvm::Function *F,
|
|
|
|
const llvm::FunctionType *FTy);
|
2008-06-08 19:45:52 +04:00
|
|
|
|
|
|
|
void SetGlobalValueAttributes(const FunctionDecl *FD,
|
|
|
|
llvm::GlobalValue *GV);
|
2007-12-02 10:09:19 +03:00
|
|
|
|
2008-07-30 03:18:29 +04:00
|
|
|
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);
|
|
|
|
|
2007-07-11 21:01:13 +04:00
|
|
|
};
|
|
|
|
} // end namespace CodeGen
|
|
|
|
} // end namespace clang
|
|
|
|
|
|
|
|
#endif
|