2007-05-28 01:07:47 +00:00
|
|
|
//===--- CodeGenModule.h - Per-Module state for LLVM CodeGen --------------===//
|
2007-05-24 06:29:05 +00:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 19:59:25 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2007-05-24 06:29:05 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This is the internal per-translation-unit state used for llvm translation.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2008-02-29 17:10:38 +00:00
|
|
|
#ifndef CLANG_CODEGEN_CODEGENMODULE_H
|
|
|
|
#define CLANG_CODEGEN_CODEGENMODULE_H
|
2007-05-24 06:29:05 +00:00
|
|
|
|
2007-06-16 00:16:26 +00:00
|
|
|
#include "CodeGenTypes.h"
|
2008-03-01 08:45:05 +00:00
|
|
|
#include "CGObjCRuntime.h"
|
2007-06-20 04:44:43 +00:00
|
|
|
#include "llvm/ADT/DenseMap.h"
|
2007-08-21 00:21:21 +00:00
|
|
|
#include "llvm/ADT/StringMap.h"
|
2007-06-16 00:16:26 +00:00
|
|
|
|
2007-05-24 06:29:05 +00:00
|
|
|
namespace llvm {
|
|
|
|
class Module;
|
2007-06-16 00:12:05 +00:00
|
|
|
class Constant;
|
2007-06-22 18:48:09 +00:00
|
|
|
class Function;
|
2007-10-30 21:27:20 +00:00
|
|
|
class GlobalVariable;
|
2007-10-31 20:01:01 +00:00
|
|
|
class TargetData;
|
2007-06-15 23:05:46 +00:00
|
|
|
}
|
|
|
|
|
2007-05-24 06:29:05 +00:00
|
|
|
namespace clang {
|
|
|
|
class ASTContext;
|
|
|
|
class FunctionDecl;
|
2008-03-30 23:03:07 +00:00
|
|
|
class ObjCMethodDecl;
|
2007-06-16 00:12:05 +00:00
|
|
|
class Decl;
|
2007-12-02 00:11:25 +00:00
|
|
|
class Expr;
|
2007-12-02 07:19:18 +00:00
|
|
|
class Stmt;
|
2007-09-13 21:41:19 +00:00
|
|
|
class ValueDecl;
|
2007-12-18 08:16:44 +00:00
|
|
|
class VarDecl;
|
2008-02-05 08:06:13 +00:00
|
|
|
class TypeDecl;
|
2007-07-13 05:13:43 +00:00
|
|
|
class FileVarDecl;
|
2007-11-28 05:34:05 +00:00
|
|
|
struct LangOptions;
|
2007-12-02 01:40:18 +00:00
|
|
|
class Diagnostic;
|
2007-05-24 06:29:05 +00:00
|
|
|
|
|
|
|
namespace CodeGen {
|
|
|
|
|
2008-02-26 21:41:45 +00:00
|
|
|
class CodeGenFunction;
|
|
|
|
|
2007-05-28 01:07:47 +00:00
|
|
|
/// CodeGenModule - This class organizes the cross-module state that is used
|
|
|
|
/// while generating LLVM code.
|
|
|
|
class CodeGenModule {
|
2007-05-24 06:29:05 +00:00
|
|
|
ASTContext &Context;
|
2007-11-28 05:34:05 +00:00
|
|
|
const LangOptions &Features;
|
2007-06-15 23:05:46 +00:00
|
|
|
llvm::Module &TheModule;
|
2007-10-31 20:01:01 +00:00
|
|
|
const llvm::TargetData &TheTargetData;
|
2007-12-02 01:40:18 +00:00
|
|
|
Diagnostic &Diags;
|
2007-06-16 00:16:26 +00:00
|
|
|
CodeGenTypes Types;
|
2008-03-01 08:45:05 +00:00
|
|
|
CGObjCRuntime *Runtime;
|
2007-06-16 00:16:26 +00:00
|
|
|
|
2007-06-22 18:48:09 +00:00
|
|
|
llvm::Function *MemCpyFn;
|
2008-02-19 22:01:01 +00:00
|
|
|
llvm::Function *MemSetFn;
|
2007-06-20 04:44:43 +00:00
|
|
|
llvm::DenseMap<const Decl*, llvm::Constant*> GlobalDeclMap;
|
2008-03-14 17:18:18 +00:00
|
|
|
std::vector<llvm::Constant*> GlobalCtors;
|
2007-11-28 05:34:05 +00:00
|
|
|
|
2007-08-21 00:21:21 +00:00
|
|
|
llvm::StringMap<llvm::Constant*> CFConstantStringMap;
|
2007-11-28 05:34:05 +00:00
|
|
|
llvm::StringMap<llvm::Constant*> ConstantStringMap;
|
2007-08-21 00:21:21 +00:00
|
|
|
llvm::Constant *CFConstantStringClassRef;
|
2007-08-31 04:31:45 +00:00
|
|
|
|
|
|
|
std::vector<llvm::Function *> BuiltinFunctions;
|
2007-05-24 06:29:05 +00:00
|
|
|
public:
|
2007-11-28 05:34:05 +00:00
|
|
|
CodeGenModule(ASTContext &C, const LangOptions &Features, llvm::Module &M,
|
2007-12-02 01:40:18 +00:00
|
|
|
const llvm::TargetData &TD, Diagnostic &Diags);
|
2008-03-01 08:45:05 +00:00
|
|
|
~CodeGenModule();
|
2007-05-24 06:29:05 +00:00
|
|
|
|
2008-03-01 08:45:05 +00:00
|
|
|
CGObjCRuntime *getObjCRuntime() { return Runtime; }
|
2007-05-29 23:17:50 +00:00
|
|
|
ASTContext &getContext() const { return Context; }
|
2007-11-28 05:34:05 +00:00
|
|
|
const LangOptions &getLangOptions() const { return Features; }
|
2007-06-15 23:05:46 +00:00
|
|
|
llvm::Module &getModule() const { return TheModule; }
|
2007-06-16 00:16:26 +00:00
|
|
|
CodeGenTypes &getTypes() { return Types; }
|
2007-12-02 01:40:18 +00:00
|
|
|
Diagnostic &getDiags() const { return Diags; }
|
2008-01-03 06:36:51 +00:00
|
|
|
const llvm::TargetData &getTargetData() const { return TheTargetData; }
|
2007-05-29 23:17:50 +00:00
|
|
|
|
2007-12-02 07:09:19 +00:00
|
|
|
llvm::Constant *GetAddrOfFunctionDecl(const FunctionDecl *D,
|
|
|
|
bool isDefinition);
|
2007-12-18 08:16:44 +00:00
|
|
|
llvm::Constant *GetAddrOfGlobalVar(const VarDecl *D, bool isDefinition);
|
2007-08-31 04:31:45 +00:00
|
|
|
|
2007-12-02 06:27:33 +00:00
|
|
|
|
2007-08-31 04:31:45 +00: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 00:21:21 +00:00
|
|
|
llvm::Constant *GetAddrOfConstantCFString(const std::string& str);
|
2008-02-11 00:02:17 +00:00
|
|
|
|
|
|
|
/// GetAddrOfConstantString -- returns a pointer to the character
|
|
|
|
/// array containing the literal. The result is pointer to array type.
|
2007-11-28 05:34:05 +00:00
|
|
|
llvm::Constant *GetAddrOfConstantString(const std::string& str);
|
2007-06-22 18:48:09 +00:00
|
|
|
llvm::Function *getMemCpyFn();
|
2008-02-19 22:01:01 +00:00
|
|
|
llvm::Function *getMemSetFn();
|
2007-12-18 00:25:38 +00:00
|
|
|
llvm::Function *getIntrinsic(unsigned IID, const llvm::Type **Tys = 0,
|
|
|
|
unsigned NumTys = 0);
|
2007-08-31 04:31:45 +00:00
|
|
|
|
2008-03-14 17:18:18 +00:00
|
|
|
void AddGlobalCtor(llvm::Function * Ctor);
|
|
|
|
void EmitGlobalCtors(void);
|
|
|
|
|
2008-03-30 23:03:07 +00:00
|
|
|
void EmitObjCMethod(const ObjCMethodDecl *OMD);
|
2007-07-13 05:13:43 +00:00
|
|
|
void EmitFunction(const FunctionDecl *FD);
|
|
|
|
void EmitGlobalVar(const FileVarDecl *D);
|
2007-07-14 00:16:50 +00:00
|
|
|
void EmitGlobalVarDeclarator(const FileVarDecl *D);
|
2008-02-06 05:08:19 +00:00
|
|
|
void UpdateCompletedType(const TagDecl *D);
|
2008-01-26 01:36:00 +00:00
|
|
|
llvm::Constant *EmitGlobalInit(const Expr *E);
|
2008-02-26 21:41:45 +00:00
|
|
|
llvm::Constant *EmitConstantExpr(const Expr *E, CodeGenFunction *CGF = 0);
|
2008-01-26 01:36:00 +00:00
|
|
|
|
2007-12-02 07:19:18 +00:00
|
|
|
/// WarnUnsupported - Print out a warning that codegen doesn't support the
|
|
|
|
/// specified stmt yet.
|
2008-01-26 01:36:00 +00:00
|
|
|
|
2007-12-02 07:19:18 +00:00
|
|
|
void WarnUnsupported(const Stmt *S, const char *Type);
|
|
|
|
|
2008-01-12 07:05:38 +00:00
|
|
|
/// WarnUnsupported - Print out a warning that codegen doesn't support the
|
|
|
|
/// specified decl yet.
|
|
|
|
void WarnUnsupported(const Decl *D, const char *Type);
|
|
|
|
|
2007-12-02 07:09:19 +00: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);
|
|
|
|
|
2007-05-24 06:29:05 +00:00
|
|
|
};
|
|
|
|
} // end namespace CodeGen
|
|
|
|
} // end namespace clang
|
|
|
|
|
|
|
|
#endif
|