Daniel Dunbar | bd012ff | 2008-07-29 23:18:29 +0000 | [diff] [blame] | 1 | //===--- CodeGenModule.h - Per-Module state for LLVM CodeGen ----*- C++ -*-===// |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 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 | |
Chris Lattner | ef52a2f | 2008-02-29 17:10:38 +0000 | [diff] [blame] | 14 | #ifndef CLANG_CODEGEN_CODEGENMODULE_H |
| 15 | #define CLANG_CODEGEN_CODEGENMODULE_H |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 16 | |
| 17 | #include "CodeGenTypes.h" |
Dan Gohman | 4f8d123 | 2008-05-22 00:50:06 +0000 | [diff] [blame] | 18 | #include "clang/AST/Attr.h" |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 19 | #include "llvm/ADT/DenseMap.h" |
Anders Carlsson | c9e2091 | 2007-08-21 00:21:21 +0000 | [diff] [blame] | 20 | #include "llvm/ADT/StringMap.h" |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 21 | |
Daniel Dunbar | b768807 | 2008-09-10 00:41:16 +0000 | [diff] [blame] | 22 | #include "CGCall.h" |
| 23 | |
Anders Carlsson | b723f75 | 2009-01-04 02:08:04 +0000 | [diff] [blame] | 24 | #include <list> |
| 25 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 26 | namespace llvm { |
| 27 | class Module; |
| 28 | class Constant; |
| 29 | class Function; |
Nate Begeman | 8bd4afe | 2008-04-19 04:17:09 +0000 | [diff] [blame] | 30 | class GlobalValue; |
Devang Patel | 7a4718e | 2007-10-31 20:01:01 +0000 | [diff] [blame] | 31 | class TargetData; |
Eli Friedman | ff4a2d9 | 2008-06-01 15:54:49 +0000 | [diff] [blame] | 32 | class FunctionType; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | namespace clang { |
| 36 | class ASTContext; |
| 37 | class FunctionDecl; |
Daniel Dunbar | 90db882 | 2008-08-25 06:18:57 +0000 | [diff] [blame] | 38 | class IdentifierInfo; |
Chris Lattner | 391d77a | 2008-03-30 23:03:07 +0000 | [diff] [blame] | 39 | class ObjCMethodDecl; |
Anton Korobeynikov | 20ff310 | 2008-06-01 14:13:53 +0000 | [diff] [blame] | 40 | class ObjCImplementationDecl; |
| 41 | class ObjCCategoryImplDecl; |
| 42 | class ObjCProtocolDecl; |
Anders Carlsson | d5cab54 | 2009-02-12 17:55:02 +0000 | [diff] [blame] | 43 | class BlockExpr; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 44 | class Decl; |
Oliver Hunt | 2824723 | 2007-12-02 00:11:25 +0000 | [diff] [blame] | 45 | class Expr; |
Chris Lattner | 2c8569d | 2007-12-02 07:19:18 +0000 | [diff] [blame] | 46 | class Stmt; |
Daniel Dunbar | 1e04976 | 2008-08-10 20:25:57 +0000 | [diff] [blame] | 47 | class StringLiteral; |
Nate Begeman | 1a1d92a | 2008-04-20 20:38:08 +0000 | [diff] [blame] | 48 | class NamedDecl; |
Daniel Dunbar | bd012ff | 2008-07-29 23:18:29 +0000 | [diff] [blame] | 49 | class ValueDecl; |
Chris Lattner | 2b9d2ca | 2007-12-18 08:16:44 +0000 | [diff] [blame] | 50 | class VarDecl; |
Chris Lattner | 45e8cbd | 2007-11-28 05:34:05 +0000 | [diff] [blame] | 51 | struct LangOptions; |
Chris Lattner | fb97b03 | 2007-12-02 01:40:18 +0000 | [diff] [blame] | 52 | class Diagnostic; |
Nate Begeman | 8bd4afe | 2008-04-19 04:17:09 +0000 | [diff] [blame] | 53 | class AnnotateAttr; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 54 | |
| 55 | namespace CodeGen { |
| 56 | |
Lauro Ramos Venancio | 8137335 | 2008-02-26 21:41:45 +0000 | [diff] [blame] | 57 | class CodeGenFunction; |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 58 | class CGDebugInfo; |
Daniel Dunbar | af2f62c | 2008-08-13 00:59:25 +0000 | [diff] [blame] | 59 | class CGObjCRuntime; |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 60 | |
Daniel Dunbar | 41071de | 2008-08-15 23:26:23 +0000 | [diff] [blame] | 61 | /// CodeGenModule - This class organizes the cross-function state that |
| 62 | /// is used while generating LLVM code. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 63 | class CodeGenModule { |
Daniel Dunbar | 6bfed7e | 2008-08-01 00:01:51 +0000 | [diff] [blame] | 64 | typedef std::vector< std::pair<llvm::Constant*, int> > CtorList; |
| 65 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 66 | ASTContext &Context; |
Chris Lattner | 45e8cbd | 2007-11-28 05:34:05 +0000 | [diff] [blame] | 67 | const LangOptions &Features; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 68 | llvm::Module &TheModule; |
Devang Patel | 7a4718e | 2007-10-31 20:01:01 +0000 | [diff] [blame] | 69 | const llvm::TargetData &TheTargetData; |
Chris Lattner | fb97b03 | 2007-12-02 01:40:18 +0000 | [diff] [blame] | 70 | Diagnostic &Diags; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 71 | CodeGenTypes Types; |
Ted Kremenek | 815c78f | 2008-08-05 18:50:11 +0000 | [diff] [blame] | 72 | CGObjCRuntime* Runtime; |
| 73 | CGDebugInfo* DebugInfo; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 74 | |
| 75 | llvm::Function *MemCpyFn; |
Eli Friedman | 0c99509 | 2008-05-26 12:59:39 +0000 | [diff] [blame] | 76 | llvm::Function *MemMoveFn; |
Lauro Ramos Venancio | 41ef30e | 2008-02-19 22:01:01 +0000 | [diff] [blame] | 77 | llvm::Function *MemSetFn; |
Daniel Dunbar | 9986eab | 2008-07-30 16:32:24 +0000 | [diff] [blame] | 78 | |
Daniel Dunbar | f1968f2 | 2008-10-01 00:49:24 +0000 | [diff] [blame] | 79 | /// RuntimeFunctions - List of runtime functions whose names must be |
| 80 | /// protected from introducing conflicts. These functions should be |
| 81 | /// created unnamed, we will name them and patch up conflicts when |
| 82 | /// we release the module. |
| 83 | std::vector< std::pair<llvm::Function*, std::string> > RuntimeFunctions; |
| 84 | |
Daniel Dunbar | 3c827a7 | 2008-08-05 23:31:02 +0000 | [diff] [blame] | 85 | /// GlobalDeclMap - Mapping of decl names global variables we have |
Daniel Dunbar | 9986eab | 2008-07-30 16:32:24 +0000 | [diff] [blame] | 86 | /// already emitted. Note that the entries in this map are the |
Daniel Dunbar | 3c827a7 | 2008-08-05 23:31:02 +0000 | [diff] [blame] | 87 | /// actual globals and therefore may not be of the same type as the |
| 88 | /// decl, they should be bitcasted on retrieval. Also note that the |
| 89 | /// globals are keyed on their source name, not the global name |
| 90 | /// (which may change with attributes such as asm-labels). |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 91 | /// This key to this map should be generated using getMangledName(). |
Daniel Dunbar | 90db882 | 2008-08-25 06:18:57 +0000 | [diff] [blame] | 92 | llvm::DenseMap<IdentifierInfo*, llvm::GlobalValue*> GlobalDeclMap; |
Daniel Dunbar | bd012ff | 2008-07-29 23:18:29 +0000 | [diff] [blame] | 93 | |
Daniel Dunbar | 219df66 | 2008-09-08 23:44:31 +0000 | [diff] [blame] | 94 | /// Aliases - List of aliases in module. These cannot be emitted |
| 95 | /// until all the code has been seen, as they reference things by |
| 96 | /// name instead of directly and may reference forward. |
| 97 | std::vector<const FunctionDecl*> Aliases; |
| 98 | |
| 99 | /// StaticDecls - List of static global for which code generation is |
| 100 | /// delayed. When the translation unit has been fully processed we |
| 101 | /// will lazily emit definitions for only the decls that were |
| 102 | /// actually used. This should contain only Function and Var decls, |
| 103 | /// and only those which actually define something. |
Anders Carlsson | b723f75 | 2009-01-04 02:08:04 +0000 | [diff] [blame] | 104 | std::list<const ValueDecl*> StaticDecls; |
Nate Begeman | 4c13b7a | 2008-04-20 06:29:50 +0000 | [diff] [blame] | 105 | |
Daniel Dunbar | 6bfed7e | 2008-08-01 00:01:51 +0000 | [diff] [blame] | 106 | /// GlobalCtors - Store the list of global constructors and their |
| 107 | /// respective priorities to be emitted when the translation unit is |
| 108 | /// complete. |
| 109 | CtorList GlobalCtors; |
| 110 | |
| 111 | /// GlobalDtors - Store the list of global destructors and their |
| 112 | /// respective priorities to be emitted when the translation unit is |
| 113 | /// complete. |
| 114 | CtorList GlobalDtors; |
| 115 | |
Nate Begeman | 532485c | 2008-04-18 23:43:57 +0000 | [diff] [blame] | 116 | std::vector<llvm::Constant*> Annotations; |
Chris Lattner | 45e8cbd | 2007-11-28 05:34:05 +0000 | [diff] [blame] | 117 | |
Anders Carlsson | c9e2091 | 2007-08-21 00:21:21 +0000 | [diff] [blame] | 118 | llvm::StringMap<llvm::Constant*> CFConstantStringMap; |
Chris Lattner | 45e8cbd | 2007-11-28 05:34:05 +0000 | [diff] [blame] | 119 | llvm::StringMap<llvm::Constant*> ConstantStringMap; |
Daniel Dunbar | 3e9df99 | 2008-08-23 18:37:06 +0000 | [diff] [blame] | 120 | |
| 121 | /// CFConstantStringClassRef - Cached reference to the class for |
| 122 | /// constant strings. This value has type int * but is actually an |
| 123 | /// Obj-C class pointer. |
Anders Carlsson | c9e2091 | 2007-08-21 00:21:21 +0000 | [diff] [blame] | 124 | llvm::Constant *CFConstantStringClassRef; |
Chris Lattner | bef20ac | 2007-08-31 04:31:45 +0000 | [diff] [blame] | 125 | |
Mike Stump | ab69514 | 2009-02-13 15:16:56 +0000 | [diff] [blame] | 126 | /// NSConcreteGlobalBlock - Cached reference to the class pointer for |
Anders Carlsson | d5cab54 | 2009-02-12 17:55:02 +0000 | [diff] [blame] | 127 | /// global blocks. |
| 128 | llvm::Constant *NSConcreteGlobalBlock; |
| 129 | |
Mike Stump | ab69514 | 2009-02-13 15:16:56 +0000 | [diff] [blame] | 130 | const llvm::Type *BlockDescriptorType; |
Mike Stump | 9b8a797 | 2009-02-13 15:25:34 +0000 | [diff] [blame] | 131 | const llvm::Type * GenericBlockLiteralType; |
Mike Stump | ab69514 | 2009-02-13 15:16:56 +0000 | [diff] [blame] | 132 | |
Chris Lattner | bef20ac | 2007-08-31 04:31:45 +0000 | [diff] [blame] | 133 | std::vector<llvm::Function *> BuiltinFunctions; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 134 | public: |
Chris Lattner | 45e8cbd | 2007-11-28 05:34:05 +0000 | [diff] [blame] | 135 | CodeGenModule(ASTContext &C, const LangOptions &Features, llvm::Module &M, |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 136 | const llvm::TargetData &TD, Diagnostic &Diags, |
Daniel Dunbar | f77ac86 | 2008-08-11 21:35:06 +0000 | [diff] [blame] | 137 | bool GenerateDebugInfo); |
Ted Kremenek | 815c78f | 2008-08-05 18:50:11 +0000 | [diff] [blame] | 138 | |
Chris Lattner | 2b94fe3 | 2008-03-01 08:45:05 +0000 | [diff] [blame] | 139 | ~CodeGenModule(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 140 | |
Ted Kremenek | 815c78f | 2008-08-05 18:50:11 +0000 | [diff] [blame] | 141 | /// Release - Finalize LLVM code generation. |
| 142 | void Release(); |
Daniel Dunbar | 208ff5e | 2008-08-11 18:12:00 +0000 | [diff] [blame] | 143 | |
Mike Stump | f99f1d0 | 2009-02-13 17:23:42 +0000 | [diff] [blame] | 144 | llvm::Constant *getNSConcreteGlobalBlock(); |
| 145 | |
Mike Stump | ab69514 | 2009-02-13 15:16:56 +0000 | [diff] [blame] | 146 | const llvm::Type *getBlockDescriptorType(); |
| 147 | |
Mike Stump | 9b8a797 | 2009-02-13 15:25:34 +0000 | [diff] [blame] | 148 | const llvm::Type *getGenericBlockLiteralType(); |
| 149 | |
Daniel Dunbar | 208ff5e | 2008-08-11 18:12:00 +0000 | [diff] [blame] | 150 | /// getObjCRuntime() - Return a reference to the configured |
| 151 | /// Objective-C runtime. |
| 152 | CGObjCRuntime &getObjCRuntime() { |
| 153 | assert(Runtime && "No Objective-C runtime has been configured."); |
| 154 | return *Runtime; |
| 155 | } |
Ted Kremenek | 815c78f | 2008-08-05 18:50:11 +0000 | [diff] [blame] | 156 | |
Daniel Dunbar | 208ff5e | 2008-08-11 18:12:00 +0000 | [diff] [blame] | 157 | /// hasObjCRuntime() - Return true iff an Objective-C runtime has |
| 158 | /// been configured. |
| 159 | bool hasObjCRuntime() { return !!Runtime; } |
| 160 | |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 161 | CGDebugInfo *getDebugInfo() { return DebugInfo; } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 162 | ASTContext &getContext() const { return Context; } |
Chris Lattner | 45e8cbd | 2007-11-28 05:34:05 +0000 | [diff] [blame] | 163 | const LangOptions &getLangOptions() const { return Features; } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 164 | llvm::Module &getModule() const { return TheModule; } |
| 165 | CodeGenTypes &getTypes() { return Types; } |
Chris Lattner | fb97b03 | 2007-12-02 01:40:18 +0000 | [diff] [blame] | 166 | Diagnostic &getDiags() const { return Diags; } |
Chris Lattner | 8f92528 | 2008-01-03 06:36:51 +0000 | [diff] [blame] | 167 | const llvm::TargetData &getTargetData() const { return TheTargetData; } |
Daniel Dunbar | bd012ff | 2008-07-29 23:18:29 +0000 | [diff] [blame] | 168 | |
| 169 | /// GetAddrOfGlobalVar - Return the llvm::Constant for the address |
| 170 | /// of the given global variable. |
| 171 | llvm::Constant *GetAddrOfGlobalVar(const VarDecl *D); |
| 172 | |
| 173 | /// GetAddrOfFunction - Return the llvm::Constant for the address |
| 174 | /// of the given function. |
| 175 | llvm::Constant *GetAddrOfFunction(const FunctionDecl *D); |
Daniel Dunbar | 6143293 | 2008-08-13 23:20:05 +0000 | [diff] [blame] | 176 | |
| 177 | /// GetStringForStringLiteral - Return the appropriate bytes for a |
| 178 | /// string literal, properly padded to match the literal type. If |
| 179 | /// only the address of a constant is needed consider using |
| 180 | /// GetAddrOfConstantStringLiteral. |
| 181 | std::string GetStringForStringLiteral(const StringLiteral *E); |
| 182 | |
Daniel Dunbar | 41071de | 2008-08-15 23:26:23 +0000 | [diff] [blame] | 183 | /// GetAddrOfConstantCFString - Return a pointer to a |
| 184 | /// constant CFString object for the given string. |
Anders Carlsson | c9e2091 | 2007-08-21 00:21:21 +0000 | [diff] [blame] | 185 | llvm::Constant *GetAddrOfConstantCFString(const std::string& str); |
Chris Lattner | a7ad98f | 2008-02-11 00:02:17 +0000 | [diff] [blame] | 186 | |
Daniel Dunbar | 6143293 | 2008-08-13 23:20:05 +0000 | [diff] [blame] | 187 | /// GetAddrOfConstantStringFromLiteral - Return a pointer to a |
| 188 | /// constant array for the given string literal. |
| 189 | llvm::Constant *GetAddrOfConstantStringFromLiteral(const StringLiteral *S); |
Daniel Dunbar | 1e04976 | 2008-08-10 20:25:57 +0000 | [diff] [blame] | 190 | |
Daniel Dunbar | 6143293 | 2008-08-13 23:20:05 +0000 | [diff] [blame] | 191 | /// GetAddrOfConstantString - Returns a pointer to a character array |
| 192 | /// containing the literal. This contents are exactly that of the |
| 193 | /// given string, i.e. it will not be null terminated automatically; |
| 194 | /// see GetAddrOfConstantCString. Note that whether the result is |
| 195 | /// actually a pointer to an LLVM constant depends on |
| 196 | /// Feature.WriteableStrings. |
| 197 | /// |
| 198 | /// The result has pointer to array type. |
Daniel Dunbar | 5fabf9d | 2008-10-17 21:56:50 +0000 | [diff] [blame] | 199 | /// |
| 200 | /// \param GlobalName If provided, the name to use for the global |
| 201 | /// (if one is created). |
| 202 | llvm::Constant *GetAddrOfConstantString(const std::string& str, |
| 203 | const char *GlobalName=0); |
Daniel Dunbar | 6143293 | 2008-08-13 23:20:05 +0000 | [diff] [blame] | 204 | |
| 205 | /// GetAddrOfConstantCString - Returns a pointer to a character |
Daniel Dunbar | 5fabf9d | 2008-10-17 21:56:50 +0000 | [diff] [blame] | 206 | /// array containing the literal and a terminating '\0' |
Daniel Dunbar | 6143293 | 2008-08-13 23:20:05 +0000 | [diff] [blame] | 207 | /// character. The result has pointer to array type. |
Daniel Dunbar | 5fabf9d | 2008-10-17 21:56:50 +0000 | [diff] [blame] | 208 | /// |
| 209 | /// \param GlobalName If provided, the name to use for the global |
| 210 | /// (if one is created). |
| 211 | llvm::Constant *GetAddrOfConstantCString(const std::string &str, |
| 212 | const char *GlobalName=0); |
Daniel Dunbar | 41071de | 2008-08-15 23:26:23 +0000 | [diff] [blame] | 213 | |
Anders Carlsson | d5cab54 | 2009-02-12 17:55:02 +0000 | [diff] [blame] | 214 | llvm::Constant *GetAddrOfGlobalBlock(const BlockExpr *BE); |
| 215 | |
Daniel Dunbar | 41071de | 2008-08-15 23:26:23 +0000 | [diff] [blame] | 216 | /// getBuiltinLibFunction - Given a builtin id for a function like |
| 217 | /// "__builtin_fabsf", return a Function* for "fabsf". |
| 218 | llvm::Function *getBuiltinLibFunction(unsigned BuiltinID); |
Daniel Dunbar | 6143293 | 2008-08-13 23:20:05 +0000 | [diff] [blame] | 219 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 220 | llvm::Function *getMemCpyFn(); |
Eli Friedman | 0c99509 | 2008-05-26 12:59:39 +0000 | [diff] [blame] | 221 | llvm::Function *getMemMoveFn(); |
Lauro Ramos Venancio | 41ef30e | 2008-02-19 22:01:01 +0000 | [diff] [blame] | 222 | llvm::Function *getMemSetFn(); |
Chris Lattner | 7acda7c | 2007-12-18 00:25:38 +0000 | [diff] [blame] | 223 | llvm::Function *getIntrinsic(unsigned IID, const llvm::Type **Tys = 0, |
| 224 | unsigned NumTys = 0); |
Daniel Dunbar | bd012ff | 2008-07-29 23:18:29 +0000 | [diff] [blame] | 225 | |
Daniel Dunbar | 41071de | 2008-08-15 23:26:23 +0000 | [diff] [blame] | 226 | /// EmitTopLevelDecl - Emit code for a single top level declaration. |
| 227 | void EmitTopLevelDecl(Decl *D); |
Daniel Dunbar | bd012ff | 2008-07-29 23:18:29 +0000 | [diff] [blame] | 228 | |
| 229 | void AddAnnotation(llvm::Constant *C) { Annotations.push_back(C); } |
| 230 | |
Daniel Dunbar | f1968f2 | 2008-10-01 00:49:24 +0000 | [diff] [blame] | 231 | /// CreateRuntimeFunction - Create a new runtime function whose name |
| 232 | /// must be protected from collisions. |
| 233 | llvm::Function *CreateRuntimeFunction(const llvm::FunctionType *Ty, |
| 234 | const std::string &Name); |
| 235 | |
Chris Lattner | c5b8806 | 2008-02-06 05:08:19 +0000 | [diff] [blame] | 236 | void UpdateCompletedType(const TagDecl *D); |
Lauro Ramos Venancio | 8137335 | 2008-02-26 21:41:45 +0000 | [diff] [blame] | 237 | llvm::Constant *EmitConstantExpr(const Expr *E, CodeGenFunction *CGF = 0); |
Nate Begeman | 8bd4afe | 2008-04-19 04:17:09 +0000 | [diff] [blame] | 238 | llvm::Constant *EmitAnnotateAttr(llvm::GlobalValue *GV, |
| 239 | const AnnotateAttr *AA, unsigned LineNo); |
Anders Carlsson | 3b1d57b | 2008-01-26 01:36:00 +0000 | [diff] [blame] | 240 | |
Daniel Dunbar | 488e993 | 2008-08-16 00:56:44 +0000 | [diff] [blame] | 241 | /// ErrorUnsupported - Print out an error that codegen doesn't support the |
Daniel Dunbar | 90df4b6 | 2008-09-04 03:43:08 +0000 | [diff] [blame] | 242 | /// specified stmt yet. |
| 243 | /// \param OmitOnError - If true, then this error should only be |
| 244 | /// emitted if no other errors have been reported. |
| 245 | void ErrorUnsupported(const Stmt *S, const char *Type, |
| 246 | bool OmitOnError=false); |
Chris Lattner | 2c8569d | 2007-12-02 07:19:18 +0000 | [diff] [blame] | 247 | |
Daniel Dunbar | 488e993 | 2008-08-16 00:56:44 +0000 | [diff] [blame] | 248 | /// ErrorUnsupported - Print out an error that codegen doesn't support the |
Chris Lattner | c6fdc34 | 2008-01-12 07:05:38 +0000 | [diff] [blame] | 249 | /// specified decl yet. |
Daniel Dunbar | 90df4b6 | 2008-09-04 03:43:08 +0000 | [diff] [blame] | 250 | /// \param OmitOnError - If true, then this error should only be |
| 251 | /// emitted if no other errors have been reported. |
| 252 | void ErrorUnsupported(const Decl *D, const char *Type, |
| 253 | bool OmitOnError=false); |
Dan Gohman | 4f8d123 | 2008-05-22 00:50:06 +0000 | [diff] [blame] | 254 | |
Daniel Dunbar | f80519b | 2008-09-04 23:41:35 +0000 | [diff] [blame] | 255 | void SetMethodAttributes(const ObjCMethodDecl *MD, |
| 256 | llvm::Function *F); |
| 257 | |
Devang Patel | 761d7f7 | 2008-09-25 21:02:23 +0000 | [diff] [blame] | 258 | void SetFunctionAttributes(const Decl *D, |
Daniel Dunbar | 45c25ba | 2008-09-10 04:01:49 +0000 | [diff] [blame] | 259 | const CGFunctionInfo &Info, |
Daniel Dunbar | b768807 | 2008-09-10 00:41:16 +0000 | [diff] [blame] | 260 | llvm::Function *F); |
| 261 | |
| 262 | /// ReturnTypeUsesSret - Return true iff the given type uses 'sret' |
| 263 | /// when used as a return type. |
Daniel Dunbar | 88b5396 | 2009-02-02 22:03:45 +0000 | [diff] [blame] | 264 | bool ReturnTypeUsesSret(const CGFunctionInfo &FI); |
Daniel Dunbar | b768807 | 2008-09-10 00:41:16 +0000 | [diff] [blame] | 265 | |
Daniel Dunbar | 88b5396 | 2009-02-02 22:03:45 +0000 | [diff] [blame] | 266 | void ConstructAttributeList(const CGFunctionInfo &Info, |
| 267 | const Decl *TargetDecl, |
Devang Patel | 761d7f7 | 2008-09-25 21:02:23 +0000 | [diff] [blame] | 268 | AttributeListType &PAL); |
Daniel Dunbar | b768807 | 2008-09-10 00:41:16 +0000 | [diff] [blame] | 269 | |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 270 | IdentifierInfo *getMangledName(const NamedDecl *ND) const; |
| 271 | |
| 272 | |
Chris Lattner | 9cd4fe4 | 2007-12-02 07:09:19 +0000 | [diff] [blame] | 273 | private: |
Daniel Dunbar | f80519b | 2008-09-04 23:41:35 +0000 | [diff] [blame] | 274 | /// SetFunctionAttributesForDefinition - Set function attributes |
| 275 | /// specific to a function definition. |
Daniel Dunbar | 219df66 | 2008-09-08 23:44:31 +0000 | [diff] [blame] | 276 | /// \param D - The ObjCMethodDecl or FunctionDecl defining \arg F. |
| 277 | void SetFunctionAttributesForDefinition(const Decl *D, |
| 278 | llvm::Function *F); |
Daniel Dunbar | f80519b | 2008-09-04 23:41:35 +0000 | [diff] [blame] | 279 | |
Eli Friedman | ff4a2d9 | 2008-06-01 15:54:49 +0000 | [diff] [blame] | 280 | void SetFunctionAttributes(const FunctionDecl *FD, |
Daniel Dunbar | f80519b | 2008-09-04 23:41:35 +0000 | [diff] [blame] | 281 | llvm::Function *F); |
Nuno Lopes | d4cbda6 | 2008-06-08 15:45:52 +0000 | [diff] [blame] | 282 | |
Daniel Dunbar | 41071de | 2008-08-15 23:26:23 +0000 | [diff] [blame] | 283 | /// EmitGlobal - Emit code for a singal global function or var |
| 284 | /// decl. Forward declarations are emitted lazily. |
| 285 | void EmitGlobal(const ValueDecl *D); |
| 286 | |
Daniel Dunbar | bd012ff | 2008-07-29 23:18:29 +0000 | [diff] [blame] | 287 | void EmitGlobalDefinition(const ValueDecl *D); |
| 288 | llvm::GlobalValue *EmitForwardFunctionDefinition(const FunctionDecl *D); |
| 289 | void EmitGlobalFunctionDefinition(const FunctionDecl *D); |
| 290 | void EmitGlobalVarDefinition(const VarDecl *D); |
Daniel Dunbar | af05bb9 | 2008-08-26 08:29:31 +0000 | [diff] [blame] | 291 | void EmitObjCPropertyImplementations(const ObjCImplementationDecl *D); |
Daniel Dunbar | 6bfed7e | 2008-08-01 00:01:51 +0000 | [diff] [blame] | 292 | |
| 293 | // FIXME: Hardcoding priority here is gross. |
| 294 | void AddGlobalCtor(llvm::Function * Ctor, int Priority=65535); |
| 295 | void AddGlobalDtor(llvm::Function * Dtor, int Priority=65535); |
Daniel Dunbar | bd012ff | 2008-07-29 23:18:29 +0000 | [diff] [blame] | 296 | |
Daniel Dunbar | 6bfed7e | 2008-08-01 00:01:51 +0000 | [diff] [blame] | 297 | /// EmitCtorList - Generates a global array of functions and |
| 298 | /// priorities using the given list and name. This array will have |
| 299 | /// appending linkage and is suitable for use as a LLVM constructor |
| 300 | /// or destructor array. |
| 301 | void EmitCtorList(const CtorList &Fns, const char *GlobalName); |
| 302 | |
Daniel Dunbar | 219df66 | 2008-09-08 23:44:31 +0000 | [diff] [blame] | 303 | void EmitAliases(void); |
Daniel Dunbar | bd012ff | 2008-07-29 23:18:29 +0000 | [diff] [blame] | 304 | void EmitAnnotations(void); |
| 305 | void EmitStatics(void); |
Daniel Dunbar | f1968f2 | 2008-10-01 00:49:24 +0000 | [diff] [blame] | 306 | |
| 307 | void BindRuntimeFunctions(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 308 | }; |
| 309 | } // end namespace CodeGen |
| 310 | } // end namespace clang |
| 311 | |
| 312 | #endif |