Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1 | //===--- CodeGenModule.h - Per-Module state for LLVM CodeGen --------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 0bc735f | 2007-12-29 19:59:25 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This is the internal per-translation-unit state used for llvm translation. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #ifndef CODEGEN_CODEGENMODULE_H |
| 15 | #define CODEGEN_CODEGENMODULE_H |
| 16 | |
| 17 | #include "CodeGenTypes.h" |
| 18 | #include "llvm/ADT/DenseMap.h" |
Anders Carlsson | c9e2091 | 2007-08-21 00:21:21 +0000 | [diff] [blame] | 19 | #include "llvm/ADT/StringMap.h" |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 20 | |
| 21 | namespace llvm { |
| 22 | class Module; |
| 23 | class Constant; |
| 24 | class Function; |
Devang Patel | 9e32d4b | 2007-10-30 21:27:20 +0000 | [diff] [blame] | 25 | class GlobalVariable; |
Devang Patel | 7a4718e | 2007-10-31 20:01:01 +0000 | [diff] [blame] | 26 | class TargetData; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 27 | } |
| 28 | |
| 29 | namespace clang { |
| 30 | class ASTContext; |
| 31 | class FunctionDecl; |
| 32 | class Decl; |
Oliver Hunt | 2824723 | 2007-12-02 00:11:25 +0000 | [diff] [blame] | 33 | class Expr; |
Chris Lattner | 2c8569d | 2007-12-02 07:19:18 +0000 | [diff] [blame] | 34 | class Stmt; |
Steve Naroff | 8e74c93 | 2007-09-13 21:41:19 +0000 | [diff] [blame] | 35 | class ValueDecl; |
Chris Lattner | 2b9d2ca | 2007-12-18 08:16:44 +0000 | [diff] [blame] | 36 | class VarDecl; |
Chris Lattner | d86e6bc | 2008-02-05 08:06:13 +0000 | [diff] [blame] | 37 | class TypeDecl; |
Chris Lattner | 88a69ad | 2007-07-13 05:13:43 +0000 | [diff] [blame] | 38 | class FileVarDecl; |
Chris Lattner | 45e8cbd | 2007-11-28 05:34:05 +0000 | [diff] [blame] | 39 | struct LangOptions; |
Chris Lattner | fb97b03 | 2007-12-02 01:40:18 +0000 | [diff] [blame] | 40 | class Diagnostic; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 41 | |
| 42 | namespace CodeGen { |
| 43 | |
| 44 | /// CodeGenModule - This class organizes the cross-module state that is used |
| 45 | /// while generating LLVM code. |
| 46 | class CodeGenModule { |
| 47 | ASTContext &Context; |
Chris Lattner | 45e8cbd | 2007-11-28 05:34:05 +0000 | [diff] [blame] | 48 | const LangOptions &Features; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 49 | llvm::Module &TheModule; |
Devang Patel | 7a4718e | 2007-10-31 20:01:01 +0000 | [diff] [blame] | 50 | const llvm::TargetData &TheTargetData; |
Chris Lattner | fb97b03 | 2007-12-02 01:40:18 +0000 | [diff] [blame] | 51 | Diagnostic &Diags; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 52 | CodeGenTypes Types; |
| 53 | |
| 54 | llvm::Function *MemCpyFn; |
| 55 | llvm::DenseMap<const Decl*, llvm::Constant*> GlobalDeclMap; |
Chris Lattner | 45e8cbd | 2007-11-28 05:34:05 +0000 | [diff] [blame] | 56 | |
Anders Carlsson | c9e2091 | 2007-08-21 00:21:21 +0000 | [diff] [blame] | 57 | llvm::StringMap<llvm::Constant*> CFConstantStringMap; |
Chris Lattner | 45e8cbd | 2007-11-28 05:34:05 +0000 | [diff] [blame] | 58 | llvm::StringMap<llvm::Constant*> ConstantStringMap; |
Anders Carlsson | c9e2091 | 2007-08-21 00:21:21 +0000 | [diff] [blame] | 59 | llvm::Constant *CFConstantStringClassRef; |
Chris Lattner | bef20ac | 2007-08-31 04:31:45 +0000 | [diff] [blame] | 60 | |
| 61 | std::vector<llvm::Function *> BuiltinFunctions; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 62 | public: |
Chris Lattner | 45e8cbd | 2007-11-28 05:34:05 +0000 | [diff] [blame] | 63 | CodeGenModule(ASTContext &C, const LangOptions &Features, llvm::Module &M, |
Chris Lattner | fb97b03 | 2007-12-02 01:40:18 +0000 | [diff] [blame] | 64 | const llvm::TargetData &TD, Diagnostic &Diags); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 65 | |
| 66 | ASTContext &getContext() const { return Context; } |
Chris Lattner | 45e8cbd | 2007-11-28 05:34:05 +0000 | [diff] [blame] | 67 | const LangOptions &getLangOptions() const { return Features; } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 68 | llvm::Module &getModule() const { return TheModule; } |
| 69 | CodeGenTypes &getTypes() { return Types; } |
Chris Lattner | fb97b03 | 2007-12-02 01:40:18 +0000 | [diff] [blame] | 70 | Diagnostic &getDiags() const { return Diags; } |
Chris Lattner | 8f92528 | 2008-01-03 06:36:51 +0000 | [diff] [blame] | 71 | const llvm::TargetData &getTargetData() const { return TheTargetData; } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 72 | |
Chris Lattner | 9cd4fe4 | 2007-12-02 07:09:19 +0000 | [diff] [blame] | 73 | llvm::Constant *GetAddrOfFunctionDecl(const FunctionDecl *D, |
| 74 | bool isDefinition); |
Chris Lattner | 2b9d2ca | 2007-12-18 08:16:44 +0000 | [diff] [blame] | 75 | llvm::Constant *GetAddrOfGlobalVar(const VarDecl *D, bool isDefinition); |
Chris Lattner | bef20ac | 2007-08-31 04:31:45 +0000 | [diff] [blame] | 76 | |
Chris Lattner | 58c3f9e | 2007-12-02 06:27:33 +0000 | [diff] [blame] | 77 | |
Chris Lattner | bef20ac | 2007-08-31 04:31:45 +0000 | [diff] [blame] | 78 | /// getBuiltinLibFunction - Given a builtin id for a function like |
| 79 | /// "__builtin_fabsf", return a Function* for "fabsf". |
| 80 | /// |
| 81 | llvm::Function *getBuiltinLibFunction(unsigned BuiltinID); |
Anders Carlsson | c9e2091 | 2007-08-21 00:21:21 +0000 | [diff] [blame] | 82 | llvm::Constant *GetAddrOfConstantCFString(const std::string& str); |
Chris Lattner | 45e8cbd | 2007-11-28 05:34:05 +0000 | [diff] [blame] | 83 | llvm::Constant *GetAddrOfConstantString(const std::string& str); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 84 | llvm::Function *getMemCpyFn(); |
Chris Lattner | 7acda7c | 2007-12-18 00:25:38 +0000 | [diff] [blame] | 85 | llvm::Function *getIntrinsic(unsigned IID, const llvm::Type **Tys = 0, |
| 86 | unsigned NumTys = 0); |
Chris Lattner | bef20ac | 2007-08-31 04:31:45 +0000 | [diff] [blame] | 87 | |
Chris Lattner | 88a69ad | 2007-07-13 05:13:43 +0000 | [diff] [blame] | 88 | void EmitFunction(const FunctionDecl *FD); |
| 89 | void EmitGlobalVar(const FileVarDecl *D); |
Chris Lattner | 32b266c | 2007-07-14 00:16:50 +0000 | [diff] [blame] | 90 | void EmitGlobalVarDeclarator(const FileVarDecl *D); |
Chris Lattner | d86e6bc | 2008-02-05 08:06:13 +0000 | [diff] [blame] | 91 | void EmitType(const TypeDecl *D); |
Anders Carlsson | 3b1d57b | 2008-01-26 01:36:00 +0000 | [diff] [blame] | 92 | llvm::Constant *EmitGlobalInit(const Expr *E); |
| 93 | llvm::Constant *EmitConstantExpr(const Expr *E); |
| 94 | |
Chris Lattner | 2c8569d | 2007-12-02 07:19:18 +0000 | [diff] [blame] | 95 | /// WarnUnsupported - Print out a warning that codegen doesn't support the |
| 96 | /// specified stmt yet. |
Anders Carlsson | 3b1d57b | 2008-01-26 01:36:00 +0000 | [diff] [blame] | 97 | |
Chris Lattner | 2c8569d | 2007-12-02 07:19:18 +0000 | [diff] [blame] | 98 | void WarnUnsupported(const Stmt *S, const char *Type); |
| 99 | |
Chris Lattner | c6fdc34 | 2008-01-12 07:05:38 +0000 | [diff] [blame] | 100 | /// WarnUnsupported - Print out a warning that codegen doesn't support the |
| 101 | /// specified decl yet. |
| 102 | void WarnUnsupported(const Decl *D, const char *Type); |
| 103 | |
Chris Lattner | 9cd4fe4 | 2007-12-02 07:09:19 +0000 | [diff] [blame] | 104 | private: |
| 105 | /// ReplaceMapValuesWith - This is a really slow and bad function that |
| 106 | /// searches for any entries in GlobalDeclMap that point to OldVal, changing |
| 107 | /// them to point to NewVal. This is badbadbad, FIXME! |
| 108 | void ReplaceMapValuesWith(llvm::Constant *OldVal, llvm::Constant *NewVal); |
| 109 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 110 | }; |
| 111 | } // end namespace CodeGen |
| 112 | } // end namespace clang |
| 113 | |
| 114 | #endif |