| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1 | //===--- ModuleBuilder.cpp - Emit LLVM Code from ASTs ---------------------===// |
| 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 builds an AST and converts it to LLVM Code. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "clang/CodeGen/ModuleBuilder.h" |
| David Blaikie | 658cd2c | 2013-07-13 21:08:14 +0000 | [diff] [blame] | 15 | #include "CGDebugInfo.h" |
| Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 16 | #include "CodeGenModule.h" |
| Chris Lattner | 8ee3c03 | 2008-02-06 02:01:47 +0000 | [diff] [blame] | 17 | #include "clang/AST/ASTContext.h" |
| Daniel Dunbar | e91593e | 2008-08-11 04:54:23 +0000 | [diff] [blame] | 18 | #include "clang/AST/DeclObjC.h" |
| 19 | #include "clang/AST/Expr.h" |
| Chris Lattner | 8ee3c03 | 2008-02-06 02:01:47 +0000 | [diff] [blame] | 20 | #include "clang/Basic/Diagnostic.h" |
| 21 | #include "clang/Basic/TargetInfo.h" |
| Chandler Carruth | 55fc873 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 22 | #include "clang/Frontend/CodeGenOptions.h" |
| Reid Kleckner | 3190ca9 | 2013-05-08 13:44:39 +0000 | [diff] [blame] | 23 | #include "llvm/ADT/StringRef.h" |
| Chandler Carruth | 3b844ba | 2013-01-02 11:45:17 +0000 | [diff] [blame] | 24 | #include "llvm/IR/DataLayout.h" |
| 25 | #include "llvm/IR/LLVMContext.h" |
| 26 | #include "llvm/IR/Module.h" |
| Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 27 | #include <memory> |
| Pirama Arumuga Nainar | 4967a71 | 2016-09-19 22:19:55 -0700 | [diff] [blame] | 28 | |
| Chris Lattner | bd36064 | 2009-03-26 05:00:52 +0000 | [diff] [blame] | 29 | using namespace clang; |
| Pirama Arumuga Nainar | 4967a71 | 2016-09-19 22:19:55 -0700 | [diff] [blame] | 30 | using namespace CodeGen; |
| Ted Kremenek | 815c78f | 2008-08-05 18:50:11 +0000 | [diff] [blame] | 31 | |
| Chris Lattner | 8ee3c03 | 2008-02-06 02:01:47 +0000 | [diff] [blame] | 32 | namespace { |
| Benjamin Kramer | 85b4521 | 2009-11-28 19:45:26 +0000 | [diff] [blame] | 33 | class CodeGeneratorImpl : public CodeGenerator { |
| David Blaikie | d6471f7 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 34 | DiagnosticsEngine &Diags; |
| Chris Lattner | 8ee3c03 | 2008-02-06 02:01:47 +0000 | [diff] [blame] | 35 | ASTContext *Ctx; |
| Pirama Arumuga Nainar | 87d948e | 2016-03-03 15:49:35 -0800 | [diff] [blame] | 36 | const HeaderSearchOptions &HeaderSearchOpts; // Only used for debug info. |
| 37 | const PreprocessorOptions &PreprocessorOpts; // Only used for debug info. |
| Chandler Carruth | 2811ccf | 2009-11-12 17:24:48 +0000 | [diff] [blame] | 38 | const CodeGenOptions CodeGenOpts; // Intentionally copied in. |
| Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 39 | |
| 40 | unsigned HandlingTopLevelDecls; |
| Pirama Arumuga Nainar | 4967a71 | 2016-09-19 22:19:55 -0700 | [diff] [blame] | 41 | |
| 42 | /// Use this when emitting decls to block re-entrant decl emission. It will |
| 43 | /// emit all deferred decls on scope exit. Set EmitDeferred to false if decl |
| 44 | /// emission must be deferred longer, like at the end of a tag definition. |
| Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 45 | struct HandlingTopLevelDeclRAII { |
| 46 | CodeGeneratorImpl &Self; |
| Pirama Arumuga Nainar | 4967a71 | 2016-09-19 22:19:55 -0700 | [diff] [blame] | 47 | bool EmitDeferred; |
| 48 | HandlingTopLevelDeclRAII(CodeGeneratorImpl &Self, |
| 49 | bool EmitDeferred = true) |
| 50 | : Self(Self), EmitDeferred(EmitDeferred) { |
| Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 51 | ++Self.HandlingTopLevelDecls; |
| 52 | } |
| 53 | ~HandlingTopLevelDeclRAII() { |
| Pirama Arumuga Nainar | 4967a71 | 2016-09-19 22:19:55 -0700 | [diff] [blame] | 54 | unsigned Level = --Self.HandlingTopLevelDecls; |
| 55 | if (Level == 0 && EmitDeferred) |
| Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 56 | Self.EmitDeferredDecls(); |
| 57 | } |
| 58 | }; |
| 59 | |
| 60 | CoverageSourceInfo *CoverageInfo; |
| 61 | |
| Chris Lattner | 8ee3c03 | 2008-02-06 02:01:47 +0000 | [diff] [blame] | 62 | protected: |
| Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 63 | std::unique_ptr<llvm::Module> M; |
| 64 | std::unique_ptr<CodeGen::CodeGenModule> Builder; |
| 65 | |
| Stephen Hines | 0e2c34f | 2015-03-23 12:09:02 -0700 | [diff] [blame] | 66 | private: |
| 67 | SmallVector<CXXMethodDecl *, 8> DeferredInlineMethodDefinitions; |
| 68 | |
| Chris Lattner | 8ee3c03 | 2008-02-06 02:01:47 +0000 | [diff] [blame] | 69 | public: |
| Pirama Arumuga Nainar | 4967a71 | 2016-09-19 22:19:55 -0700 | [diff] [blame] | 70 | CodeGeneratorImpl(DiagnosticsEngine &diags, llvm::StringRef ModuleName, |
| Pirama Arumuga Nainar | 87d948e | 2016-03-03 15:49:35 -0800 | [diff] [blame] | 71 | const HeaderSearchOptions &HSO, |
| 72 | const PreprocessorOptions &PPO, const CodeGenOptions &CGO, |
| 73 | llvm::LLVMContext &C, |
| Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 74 | CoverageSourceInfo *CoverageInfo = nullptr) |
| Pirama Arumuga Nainar | 87d948e | 2016-03-03 15:49:35 -0800 | [diff] [blame] | 75 | : Diags(diags), Ctx(nullptr), HeaderSearchOpts(HSO), |
| 76 | PreprocessorOpts(PPO), CodeGenOpts(CGO), HandlingTopLevelDecls(0), |
| Pirama Arumuga Nainar | 4967a71 | 2016-09-19 22:19:55 -0700 | [diff] [blame] | 77 | CoverageInfo(CoverageInfo), M(new llvm::Module(ModuleName, C)) { |
| 78 | C.setDiscardValueNames(CGO.DiscardValueNames); |
| 79 | } |
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 80 | |
| Pirama Arumuga Nainar | 58878f8 | 2015-05-06 11:48:57 -0700 | [diff] [blame] | 81 | ~CodeGeneratorImpl() override { |
| Stephen Hines | 0e2c34f | 2015-03-23 12:09:02 -0700 | [diff] [blame] | 82 | // There should normally not be any leftover inline method definitions. |
| 83 | assert(DeferredInlineMethodDefinitions.empty() || |
| 84 | Diags.hasErrorOccurred()); |
| 85 | } |
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 86 | |
| Pirama Arumuga Nainar | 4967a71 | 2016-09-19 22:19:55 -0700 | [diff] [blame] | 87 | CodeGenModule &CGM() { |
| 88 | return *Builder; |
| 89 | } |
| 90 | |
| 91 | llvm::Module *GetModule() { |
| Daniel Dunbar | d8c0ea1 | 2008-10-21 19:55:09 +0000 | [diff] [blame] | 92 | return M.get(); |
| 93 | } |
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 94 | |
| Pirama Arumuga Nainar | 4967a71 | 2016-09-19 22:19:55 -0700 | [diff] [blame] | 95 | llvm::Module *ReleaseModule() { |
| 96 | return M.release(); |
| 97 | } |
| 98 | |
| 99 | const Decl *GetDeclForMangledName(StringRef MangledName) { |
| Stephen Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame] | 100 | GlobalDecl Result; |
| 101 | if (!Builder->lookupRepresentativeDecl(MangledName, Result)) |
| 102 | return nullptr; |
| 103 | const Decl *D = Result.getCanonicalDecl().getDecl(); |
| 104 | if (auto FD = dyn_cast<FunctionDecl>(D)) { |
| 105 | if (FD->hasBody(FD)) |
| 106 | return FD; |
| 107 | } else if (auto TD = dyn_cast<TagDecl>(D)) { |
| 108 | if (auto Def = TD->getDefinition()) |
| 109 | return Def; |
| 110 | } |
| 111 | return D; |
| 112 | } |
| 113 | |
| Pirama Arumuga Nainar | 4967a71 | 2016-09-19 22:19:55 -0700 | [diff] [blame] | 114 | llvm::Constant *GetAddrOfGlobal(GlobalDecl global, bool isForDefinition) { |
| 115 | return Builder->GetAddrOfGlobal(global, isForDefinition); |
| 116 | } |
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 117 | |
| Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 118 | void Initialize(ASTContext &Context) override { |
| Chris Lattner | 8ee3c03 | 2008-02-06 02:01:47 +0000 | [diff] [blame] | 119 | Ctx = &Context; |
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 120 | |
| Douglas Gregor | bcfd1f5 | 2011-09-02 00:18:52 +0000 | [diff] [blame] | 121 | M->setTargetTriple(Ctx->getTargetInfo().getTriple().getTriple()); |
| Pirama Arumuga Nainar | 4967a71 | 2016-09-19 22:19:55 -0700 | [diff] [blame] | 122 | M->setDataLayout(Ctx->getTargetInfo().getDataLayout()); |
| Pirama Arumuga Nainar | 87d948e | 2016-03-03 15:49:35 -0800 | [diff] [blame] | 123 | Builder.reset(new CodeGen::CodeGenModule(Context, HeaderSearchOpts, |
| 124 | PreprocessorOpts, CodeGenOpts, |
| 125 | *M, Diags, CoverageInfo)); |
| Hans Wennborg | b357479 | 2013-08-08 00:17:41 +0000 | [diff] [blame] | 126 | |
| Pirama Arumuga Nainar | 4967a71 | 2016-09-19 22:19:55 -0700 | [diff] [blame] | 127 | for (auto &&Lib : CodeGenOpts.DependentLibraries) |
| 128 | Builder->AddDependentLib(Lib); |
| 129 | for (auto &&Opt : CodeGenOpts.LinkerOptions) |
| 130 | Builder->AppendLinkerOptions(Opt); |
| Chris Lattner | 8ee3c03 | 2008-02-06 02:01:47 +0000 | [diff] [blame] | 131 | } |
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 132 | |
| Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 133 | void HandleCXXStaticMemberVarInstantiation(VarDecl *VD) override { |
| David Blaikie | 0a1c862 | 2013-08-19 21:02:26 +0000 | [diff] [blame] | 134 | if (Diags.hasErrorOccurred()) |
| 135 | return; |
| 136 | |
| Rafael Espindola | 0250393 | 2012-03-08 15:51:03 +0000 | [diff] [blame] | 137 | Builder->HandleCXXStaticMemberVarInstantiation(VD); |
| Rafael Espindola | 234fe65 | 2012-03-05 10:54:55 +0000 | [diff] [blame] | 138 | } |
| 139 | |
| Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 140 | bool HandleTopLevelDecl(DeclGroupRef DG) override { |
| David Blaikie | 0a1c862 | 2013-08-19 21:02:26 +0000 | [diff] [blame] | 141 | if (Diags.hasErrorOccurred()) |
| 142 | return true; |
| 143 | |
| Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 144 | HandlingTopLevelDeclRAII HandlingDecl(*this); |
| 145 | |
| Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 146 | // Make sure to emit all elements of a Decl. |
| Chris Lattner | 682bf92 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 147 | for (DeclGroupRef::iterator I = DG.begin(), E = DG.end(); I != E; ++I) |
| 148 | Builder->EmitTopLevelDecl(*I); |
| Stephen Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame] | 149 | |
| Argyrios Kyrtzidis | 88c2596 | 2011-11-18 00:26:59 +0000 | [diff] [blame] | 150 | return true; |
| Chris Lattner | 8ee3c03 | 2008-02-06 02:01:47 +0000 | [diff] [blame] | 151 | } |
| Daniel Dunbar | 41071de | 2008-08-15 23:26:23 +0000 | [diff] [blame] | 152 | |
| Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 153 | void EmitDeferredDecls() { |
| 154 | if (DeferredInlineMethodDefinitions.empty()) |
| 155 | return; |
| 156 | |
| 157 | // Emit any deferred inline method definitions. Note that more deferred |
| 158 | // methods may be added during this loop, since ASTConsumer callbacks |
| 159 | // can be invoked if AST inspection results in declarations being added. |
| 160 | HandlingTopLevelDeclRAII HandlingDecl(*this); |
| 161 | for (unsigned I = 0; I != DeferredInlineMethodDefinitions.size(); ++I) |
| 162 | Builder->EmitTopLevelDecl(DeferredInlineMethodDefinitions[I]); |
| 163 | DeferredInlineMethodDefinitions.clear(); |
| 164 | } |
| 165 | |
| Pirama Arumuga Nainar | 4967a71 | 2016-09-19 22:19:55 -0700 | [diff] [blame] | 166 | void HandleInlineFunctionDefinition(FunctionDecl *D) override { |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 167 | if (Diags.hasErrorOccurred()) |
| 168 | return; |
| 169 | |
| 170 | assert(D->doesThisDeclarationHaveABody()); |
| 171 | |
| Pirama Arumuga Nainar | 4967a71 | 2016-09-19 22:19:55 -0700 | [diff] [blame] | 172 | // Handle friend functions. |
| 173 | if (D->isInIdentifierNamespace(Decl::IDNS_OrdinaryFriend)) { |
| 174 | if (Ctx->getTargetInfo().getCXXABI().isMicrosoft() |
| 175 | && !D->getLexicalDeclContext()->isDependentContext()) |
| 176 | Builder->EmitTopLevelDecl(D); |
| 177 | return; |
| 178 | } |
| 179 | |
| 180 | // Otherwise, must be a method. |
| 181 | auto MD = cast<CXXMethodDecl>(D); |
| 182 | |
| Stephen Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame] | 183 | // We may want to emit this definition. However, that decision might be |
| 184 | // based on computing the linkage, and we have to defer that in case we |
| 185 | // are inside of something that will change the method's final linkage, |
| 186 | // e.g. |
| 187 | // typedef struct { |
| 188 | // void bar(); |
| 189 | // void foo() { bar(); } |
| 190 | // } A; |
| Pirama Arumuga Nainar | 4967a71 | 2016-09-19 22:19:55 -0700 | [diff] [blame] | 191 | DeferredInlineMethodDefinitions.push_back(MD); |
| Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 192 | |
| 193 | // Provide some coverage mapping even for methods that aren't emitted. |
| 194 | // Don't do this for templated classes though, as they may not be |
| 195 | // instantiable. |
| Pirama Arumuga Nainar | 4967a71 | 2016-09-19 22:19:55 -0700 | [diff] [blame] | 196 | if (!MD->getParent()->getDescribedClassTemplate()) |
| 197 | Builder->AddDeferredUnusedCoverageMapping(MD); |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 198 | } |
| 199 | |
| Chris Lattner | 9eee0f8 | 2008-02-06 04:51:19 +0000 | [diff] [blame] | 200 | /// HandleTagDeclDefinition - This callback is invoked each time a TagDecl |
| Chris Lattner | 682bf92 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 201 | /// to (e.g. struct, union, enum, class) is completed. This allows the |
| 202 | /// client hack on the type, which can occur at any point in the file |
| 203 | /// (because these can be defined in declspecs). |
| Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 204 | void HandleTagDeclDefinition(TagDecl *D) override { |
| David Blaikie | 0a1c862 | 2013-08-19 21:02:26 +0000 | [diff] [blame] | 205 | if (Diags.hasErrorOccurred()) |
| 206 | return; |
| 207 | |
| Pirama Arumuga Nainar | 4967a71 | 2016-09-19 22:19:55 -0700 | [diff] [blame] | 208 | // Don't allow re-entrant calls to CodeGen triggered by PCH |
| 209 | // deserialization to emit deferred decls. |
| 210 | HandlingTopLevelDeclRAII HandlingDecl(*this, /*EmitDeferred=*/false); |
| 211 | |
| Chris Lattner | c5b8806 | 2008-02-06 05:08:19 +0000 | [diff] [blame] | 212 | Builder->UpdateCompletedType(D); |
| Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 213 | |
| 214 | // For MSVC compatibility, treat declarations of static data members with |
| 215 | // inline initializers as definitions. |
| Pirama Arumuga Nainar | 87d948e | 2016-03-03 15:49:35 -0800 | [diff] [blame] | 216 | if (Ctx->getTargetInfo().getCXXABI().isMicrosoft()) { |
| Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 217 | for (Decl *Member : D->decls()) { |
| 218 | if (VarDecl *VD = dyn_cast<VarDecl>(Member)) { |
| 219 | if (Ctx->isMSStaticDataMemberInlineDefinition(VD) && |
| 220 | Ctx->DeclMustBeEmitted(VD)) { |
| 221 | Builder->EmitGlobal(VD); |
| 222 | } |
| 223 | } |
| 224 | } |
| 225 | } |
| Pirama Arumuga Nainar | 4967a71 | 2016-09-19 22:19:55 -0700 | [diff] [blame] | 226 | // For OpenMP emit declare reduction functions, if required. |
| 227 | if (Ctx->getLangOpts().OpenMP) { |
| 228 | for (Decl *Member : D->decls()) { |
| 229 | if (auto *DRD = dyn_cast<OMPDeclareReductionDecl>(Member)) { |
| 230 | if (Ctx->DeclMustBeEmitted(DRD)) |
| 231 | Builder->EmitGlobal(DRD); |
| 232 | } |
| 233 | } |
| 234 | } |
| Chris Lattner | 9eee0f8 | 2008-02-06 04:51:19 +0000 | [diff] [blame] | 235 | } |
| Ted Kremenek | 159346a | 2008-08-07 19:47:41 +0000 | [diff] [blame] | 236 | |
| Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 237 | void HandleTagDeclRequiredDefinition(const TagDecl *D) override { |
| David Blaikie | 0a1c862 | 2013-08-19 21:02:26 +0000 | [diff] [blame] | 238 | if (Diags.hasErrorOccurred()) |
| 239 | return; |
| 240 | |
| Pirama Arumuga Nainar | 4967a71 | 2016-09-19 22:19:55 -0700 | [diff] [blame] | 241 | // Don't allow re-entrant calls to CodeGen triggered by PCH |
| 242 | // deserialization to emit deferred decls. |
| 243 | HandlingTopLevelDeclRAII HandlingDecl(*this, /*EmitDeferred=*/false); |
| 244 | |
| David Blaikie | 658cd2c | 2013-07-13 21:08:14 +0000 | [diff] [blame] | 245 | if (CodeGen::CGDebugInfo *DI = Builder->getModuleDebugInfo()) |
| 246 | if (const RecordDecl *RD = dyn_cast<RecordDecl>(D)) |
| David Blaikie | 2780489 | 2013-08-15 20:49:17 +0000 | [diff] [blame] | 247 | DI->completeRequiredType(RD); |
| David Blaikie | 658cd2c | 2013-07-13 21:08:14 +0000 | [diff] [blame] | 248 | } |
| 249 | |
| Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 250 | void HandleTranslationUnit(ASTContext &Ctx) override { |
| Pirama Arumuga Nainar | 4967a71 | 2016-09-19 22:19:55 -0700 | [diff] [blame] | 251 | // Release the Builder when there is no error. |
| 252 | if (!Diags.hasErrorOccurred() && Builder) |
| 253 | Builder->Release(); |
| 254 | |
| 255 | // If there are errors before or when releasing the Builder, reset |
| 256 | // the module to stop here before invoking the backend. |
| Ted Kremenek | 159346a | 2008-08-07 19:47:41 +0000 | [diff] [blame] | 257 | if (Diags.hasErrorOccurred()) { |
| Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 258 | if (Builder) |
| 259 | Builder->clear(); |
| Ted Kremenek | 159346a | 2008-08-07 19:47:41 +0000 | [diff] [blame] | 260 | M.reset(); |
| 261 | return; |
| 262 | } |
| Pirama Arumuga Nainar | 4967a71 | 2016-09-19 22:19:55 -0700 | [diff] [blame] | 263 | } |
| Ted Kremenek | 159346a | 2008-08-07 19:47:41 +0000 | [diff] [blame] | 264 | |
| Pirama Arumuga Nainar | 4967a71 | 2016-09-19 22:19:55 -0700 | [diff] [blame] | 265 | void AssignInheritanceModel(CXXRecordDecl *RD) override { |
| 266 | if (Diags.hasErrorOccurred()) |
| 267 | return; |
| 268 | |
| 269 | Builder->RefreshTypeCacheForClass(RD); |
| Daniel Dunbar | 7177dee | 2009-12-19 17:50:07 +0000 | [diff] [blame] | 270 | } |
| Douglas Gregor | b6c8c8b | 2009-04-21 17:11:58 +0000 | [diff] [blame] | 271 | |
| Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 272 | void CompleteTentativeDefinition(VarDecl *D) override { |
| Douglas Gregor | b6c8c8b | 2009-04-21 17:11:58 +0000 | [diff] [blame] | 273 | if (Diags.hasErrorOccurred()) |
| 274 | return; |
| 275 | |
| 276 | Builder->EmitTentativeDefinition(D); |
| 277 | } |
| Douglas Gregor | 6fb745b | 2010-05-13 16:44:06 +0000 | [diff] [blame] | 278 | |
| Stephen Hines | 0e2c34f | 2015-03-23 12:09:02 -0700 | [diff] [blame] | 279 | void HandleVTable(CXXRecordDecl *RD) override { |
| Douglas Gregor | 6fb745b | 2010-05-13 16:44:06 +0000 | [diff] [blame] | 280 | if (Diags.hasErrorOccurred()) |
| 281 | return; |
| 282 | |
| Stephen Hines | 0e2c34f | 2015-03-23 12:09:02 -0700 | [diff] [blame] | 283 | Builder->EmitVTable(RD); |
| Douglas Gregor | 6fb745b | 2010-05-13 16:44:06 +0000 | [diff] [blame] | 284 | } |
| Chris Lattner | 8ee3c03 | 2008-02-06 02:01:47 +0000 | [diff] [blame] | 285 | }; |
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 286 | } |
| 287 | |
| David Blaikie | 99ba9e3 | 2011-12-20 02:48:34 +0000 | [diff] [blame] | 288 | void CodeGenerator::anchor() { } |
| 289 | |
| Pirama Arumuga Nainar | 4967a71 | 2016-09-19 22:19:55 -0700 | [diff] [blame] | 290 | CodeGenModule &CodeGenerator::CGM() { |
| 291 | return static_cast<CodeGeneratorImpl*>(this)->CGM(); |
| 292 | } |
| 293 | |
| 294 | llvm::Module *CodeGenerator::GetModule() { |
| 295 | return static_cast<CodeGeneratorImpl*>(this)->GetModule(); |
| 296 | } |
| 297 | |
| 298 | llvm::Module *CodeGenerator::ReleaseModule() { |
| 299 | return static_cast<CodeGeneratorImpl*>(this)->ReleaseModule(); |
| 300 | } |
| 301 | |
| 302 | const Decl *CodeGenerator::GetDeclForMangledName(llvm::StringRef name) { |
| 303 | return static_cast<CodeGeneratorImpl*>(this)->GetDeclForMangledName(name); |
| 304 | } |
| 305 | |
| 306 | llvm::Constant *CodeGenerator::GetAddrOfGlobal(GlobalDecl global, |
| 307 | bool isForDefinition) { |
| 308 | return static_cast<CodeGeneratorImpl*>(this) |
| 309 | ->GetAddrOfGlobal(global, isForDefinition); |
| 310 | } |
| 311 | |
| Pirama Arumuga Nainar | 87d948e | 2016-03-03 15:49:35 -0800 | [diff] [blame] | 312 | CodeGenerator *clang::CreateLLVMCodeGen( |
| Pirama Arumuga Nainar | 4967a71 | 2016-09-19 22:19:55 -0700 | [diff] [blame] | 313 | DiagnosticsEngine &Diags, llvm::StringRef ModuleName, |
| Pirama Arumuga Nainar | 87d948e | 2016-03-03 15:49:35 -0800 | [diff] [blame] | 314 | const HeaderSearchOptions &HeaderSearchOpts, |
| 315 | const PreprocessorOptions &PreprocessorOpts, const CodeGenOptions &CGO, |
| 316 | llvm::LLVMContext &C, CoverageSourceInfo *CoverageInfo) { |
| 317 | return new CodeGeneratorImpl(Diags, ModuleName, HeaderSearchOpts, |
| 318 | PreprocessorOpts, CGO, C, CoverageInfo); |
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 319 | } |