xref: /src/contrib/llvm-project/clang/lib/CodeGen/ModuleBuilder.cpp (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
1ec2b103cSEd Schouten //===--- ModuleBuilder.cpp - Emit LLVM Code from ASTs ---------------------===//
2ec2b103cSEd Schouten //
322989816SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
422989816SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
522989816SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6ec2b103cSEd Schouten //
7ec2b103cSEd Schouten //===----------------------------------------------------------------------===//
8ec2b103cSEd Schouten //
9ec2b103cSEd Schouten // This builds an AST and converts it to LLVM Code.
10ec2b103cSEd Schouten //
11ec2b103cSEd Schouten //===----------------------------------------------------------------------===//
12ec2b103cSEd Schouten 
13ec2b103cSEd Schouten #include "clang/CodeGen/ModuleBuilder.h"
14bfef3995SDimitry Andric #include "CGDebugInfo.h"
159f4dbff6SDimitry Andric #include "CodeGenModule.h"
16ec2b103cSEd Schouten #include "clang/AST/ASTContext.h"
17ec2b103cSEd Schouten #include "clang/AST/DeclObjC.h"
18ec2b103cSEd Schouten #include "clang/AST/Expr.h"
19676fbe81SDimitry Andric #include "clang/Basic/CodeGenOptions.h"
20ec2b103cSEd Schouten #include "clang/Basic/Diagnostic.h"
21ec2b103cSEd Schouten #include "clang/Basic/TargetInfo.h"
22bfef3995SDimitry Andric #include "llvm/ADT/StringRef.h"
23809500fcSDimitry Andric #include "llvm/IR/DataLayout.h"
24809500fcSDimitry Andric #include "llvm/IR/LLVMContext.h"
25809500fcSDimitry Andric #include "llvm/IR/Module.h"
2608e8dd7bSDimitry Andric #include "llvm/Support/VirtualFileSystem.h"
279f4dbff6SDimitry Andric #include <memory>
282b6b257fSDimitry Andric 
29ec2b103cSEd Schouten using namespace clang;
302b6b257fSDimitry Andric using namespace CodeGen;
31ec2b103cSEd Schouten 
32ec2b103cSEd Schouten namespace {
331569ce68SRoman Divacky   class CodeGeneratorImpl : public CodeGenerator {
3436981b17SDimitry Andric     DiagnosticsEngine &Diags;
35ec2b103cSEd Schouten     ASTContext *Ctx;
3608e8dd7bSDimitry Andric     IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS; // Only used for debug info.
37c192b3dcSDimitry Andric     const HeaderSearchOptions &HeaderSearchOpts; // Only used for debug info.
38c192b3dcSDimitry Andric     const PreprocessorOptions &PreprocessorOpts; // Only used for debug info.
397fa27ce4SDimitry Andric     const CodeGenOptions &CodeGenOpts;
4006d4ba38SDimitry Andric 
4106d4ba38SDimitry Andric     unsigned HandlingTopLevelDecls;
422b6b257fSDimitry Andric 
432b6b257fSDimitry Andric     /// Use this when emitting decls to block re-entrant decl emission. It will
442b6b257fSDimitry Andric     /// emit all deferred decls on scope exit. Set EmitDeferred to false if decl
452b6b257fSDimitry Andric     /// emission must be deferred longer, like at the end of a tag definition.
4606d4ba38SDimitry Andric     struct HandlingTopLevelDeclRAII {
4706d4ba38SDimitry Andric       CodeGeneratorImpl &Self;
482b6b257fSDimitry Andric       bool EmitDeferred;
HandlingTopLevelDeclRAII__anonb496aee00111::CodeGeneratorImpl::HandlingTopLevelDeclRAII492b6b257fSDimitry Andric       HandlingTopLevelDeclRAII(CodeGeneratorImpl &Self,
502b6b257fSDimitry Andric                                bool EmitDeferred = true)
512b6b257fSDimitry Andric           : Self(Self), EmitDeferred(EmitDeferred) {
5206d4ba38SDimitry Andric         ++Self.HandlingTopLevelDecls;
5306d4ba38SDimitry Andric       }
~HandlingTopLevelDeclRAII__anonb496aee00111::CodeGeneratorImpl::HandlingTopLevelDeclRAII5406d4ba38SDimitry Andric       ~HandlingTopLevelDeclRAII() {
552b6b257fSDimitry Andric         unsigned Level = --Self.HandlingTopLevelDecls;
562b6b257fSDimitry Andric         if (Level == 0 && EmitDeferred)
5706d4ba38SDimitry Andric           Self.EmitDeferredDecls();
5806d4ba38SDimitry Andric       }
5906d4ba38SDimitry Andric     };
6006d4ba38SDimitry Andric 
6106d4ba38SDimitry Andric     CoverageSourceInfo *CoverageInfo;
6206d4ba38SDimitry Andric 
63ec2b103cSEd Schouten   protected:
649f4dbff6SDimitry Andric     std::unique_ptr<llvm::Module> M;
659f4dbff6SDimitry Andric     std::unique_ptr<CodeGen::CodeGenModule> Builder;
669f4dbff6SDimitry Andric 
6706d4ba38SDimitry Andric   private:
68676fbe81SDimitry Andric     SmallVector<FunctionDecl *, 8> DeferredInlineMemberFuncDefs;
6906d4ba38SDimitry Andric 
ExpandModuleName(llvm::StringRef ModuleName,const CodeGenOptions & CGO)70519fc96cSDimitry Andric     static llvm::StringRef ExpandModuleName(llvm::StringRef ModuleName,
71519fc96cSDimitry Andric                                             const CodeGenOptions &CGO) {
72519fc96cSDimitry Andric       if (ModuleName == "-" && !CGO.MainFileName.empty())
73519fc96cSDimitry Andric         return CGO.MainFileName;
74519fc96cSDimitry Andric       return ModuleName;
75519fc96cSDimitry Andric     }
76519fc96cSDimitry Andric 
77ec2b103cSEd Schouten   public:
CodeGeneratorImpl(DiagnosticsEngine & diags,llvm::StringRef ModuleName,IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS,const HeaderSearchOptions & HSO,const PreprocessorOptions & PPO,const CodeGenOptions & CGO,llvm::LLVMContext & C,CoverageSourceInfo * CoverageInfo=nullptr)782b6b257fSDimitry Andric     CodeGeneratorImpl(DiagnosticsEngine &diags, llvm::StringRef ModuleName,
7908e8dd7bSDimitry Andric                       IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS,
80c192b3dcSDimitry Andric                       const HeaderSearchOptions &HSO,
81c192b3dcSDimitry Andric                       const PreprocessorOptions &PPO, const CodeGenOptions &CGO,
82c192b3dcSDimitry Andric                       llvm::LLVMContext &C,
8306d4ba38SDimitry Andric                       CoverageSourceInfo *CoverageInfo = nullptr)
8408e8dd7bSDimitry Andric         : Diags(diags), Ctx(nullptr), FS(std::move(FS)), HeaderSearchOpts(HSO),
85c192b3dcSDimitry Andric           PreprocessorOpts(PPO), CodeGenOpts(CGO), HandlingTopLevelDecls(0),
86519fc96cSDimitry Andric           CoverageInfo(CoverageInfo),
87519fc96cSDimitry Andric           M(new llvm::Module(ExpandModuleName(ModuleName, CGO), C)) {
882b6b257fSDimitry Andric       C.setDiscardValueNames(CGO.DiscardValueNames);
892b6b257fSDimitry Andric     }
90ec2b103cSEd Schouten 
~CodeGeneratorImpl()915e20cdd8SDimitry Andric     ~CodeGeneratorImpl() override {
9206d4ba38SDimitry Andric       // There should normally not be any leftover inline method definitions.
93676fbe81SDimitry Andric       assert(DeferredInlineMemberFuncDefs.empty() ||
9406d4ba38SDimitry Andric              Diags.hasErrorOccurred());
9506d4ba38SDimitry Andric     }
96ec2b103cSEd Schouten 
CGM()972b6b257fSDimitry Andric     CodeGenModule &CGM() {
982b6b257fSDimitry Andric       return *Builder;
992b6b257fSDimitry Andric     }
1002b6b257fSDimitry Andric 
GetModule()1012b6b257fSDimitry Andric     llvm::Module *GetModule() {
102ec2b103cSEd Schouten       return M.get();
103ec2b103cSEd Schouten     }
104ec2b103cSEd Schouten 
getCGDebugInfo()1057442d6faSDimitry Andric     CGDebugInfo *getCGDebugInfo() {
1067442d6faSDimitry Andric       return Builder->getModuleDebugInfo();
1077442d6faSDimitry Andric     }
1087442d6faSDimitry Andric 
ReleaseModule()1092b6b257fSDimitry Andric     llvm::Module *ReleaseModule() {
1102b6b257fSDimitry Andric       return M.release();
1112b6b257fSDimitry Andric     }
1122b6b257fSDimitry Andric 
GetDeclForMangledName(StringRef MangledName)1132b6b257fSDimitry Andric     const Decl *GetDeclForMangledName(StringRef MangledName) {
1149f4dbff6SDimitry Andric       GlobalDecl Result;
1159f4dbff6SDimitry Andric       if (!Builder->lookupRepresentativeDecl(MangledName, Result))
1169f4dbff6SDimitry Andric         return nullptr;
1179f4dbff6SDimitry Andric       const Decl *D = Result.getCanonicalDecl().getDecl();
1189f4dbff6SDimitry Andric       if (auto FD = dyn_cast<FunctionDecl>(D)) {
1199f4dbff6SDimitry Andric         if (FD->hasBody(FD))
1209f4dbff6SDimitry Andric           return FD;
1219f4dbff6SDimitry Andric       } else if (auto TD = dyn_cast<TagDecl>(D)) {
1229f4dbff6SDimitry Andric         if (auto Def = TD->getDefinition())
1239f4dbff6SDimitry Andric           return Def;
1249f4dbff6SDimitry Andric       }
1259f4dbff6SDimitry Andric       return D;
126ec2b103cSEd Schouten     }
127ec2b103cSEd Schouten 
GetMangledName(GlobalDecl GD)128c0981da4SDimitry Andric     llvm::StringRef GetMangledName(GlobalDecl GD) {
129c0981da4SDimitry Andric       return Builder->getMangledName(GD);
130c0981da4SDimitry Andric     }
131c0981da4SDimitry Andric 
GetAddrOfGlobal(GlobalDecl global,bool isForDefinition)1322b6b257fSDimitry Andric     llvm::Constant *GetAddrOfGlobal(GlobalDecl global, bool isForDefinition) {
133bab175ecSDimitry Andric       return Builder->GetAddrOfGlobal(global, ForDefinition_t(isForDefinition));
1342b6b257fSDimitry Andric     }
1359f4dbff6SDimitry Andric 
StartModule(llvm::StringRef ModuleName,llvm::LLVMContext & C)136461a67faSDimitry Andric     llvm::Module *StartModule(llvm::StringRef ModuleName,
137461a67faSDimitry Andric                               llvm::LLVMContext &C) {
138461a67faSDimitry Andric       assert(!M && "Replacing existing Module?");
139519fc96cSDimitry Andric       M.reset(new llvm::Module(ExpandModuleName(ModuleName, CodeGenOpts), C));
140145449b1SDimitry Andric 
141145449b1SDimitry Andric       std::unique_ptr<CodeGenModule> OldBuilder = std::move(Builder);
142145449b1SDimitry Andric 
143461a67faSDimitry Andric       Initialize(*Ctx);
144145449b1SDimitry Andric 
145145449b1SDimitry Andric       if (OldBuilder)
146145449b1SDimitry Andric         OldBuilder->moveLazyEmissionStates(Builder.get());
147145449b1SDimitry Andric 
148461a67faSDimitry Andric       return M.get();
149461a67faSDimitry Andric     }
150461a67faSDimitry Andric 
Initialize(ASTContext & Context)1519f4dbff6SDimitry Andric     void Initialize(ASTContext &Context) override {
152ec2b103cSEd Schouten       Ctx = &Context;
153ec2b103cSEd Schouten 
15436981b17SDimitry Andric       M->setTargetTriple(Ctx->getTargetInfo().getTriple().getTriple());
155344a3780SDimitry Andric       M->setDataLayout(Ctx->getTargetInfo().getDataLayoutString());
156676fbe81SDimitry Andric       const auto &SDKVersion = Ctx->getTargetInfo().getSDKVersion();
157676fbe81SDimitry Andric       if (!SDKVersion.empty())
158676fbe81SDimitry Andric         M->setSDKVersion(SDKVersion);
159145449b1SDimitry Andric       if (const auto *TVT = Ctx->getTargetInfo().getDarwinTargetVariantTriple())
160145449b1SDimitry Andric         M->setDarwinTargetVariantTriple(TVT->getTriple());
161145449b1SDimitry Andric       if (auto TVSDKVersion =
162145449b1SDimitry Andric               Ctx->getTargetInfo().getDarwinTargetVariantSDKVersion())
163145449b1SDimitry Andric         M->setDarwinTargetVariantSDKVersion(*TVSDKVersion);
16408e8dd7bSDimitry Andric       Builder.reset(new CodeGen::CodeGenModule(Context, FS, HeaderSearchOpts,
16545b53394SDimitry Andric                                                PreprocessorOpts, CodeGenOpts,
16645b53394SDimitry Andric                                                *M, Diags, CoverageInfo));
167bfef3995SDimitry Andric 
1682b6b257fSDimitry Andric       for (auto &&Lib : CodeGenOpts.DependentLibraries)
1692b6b257fSDimitry Andric         Builder->AddDependentLib(Lib);
1702b6b257fSDimitry Andric       for (auto &&Opt : CodeGenOpts.LinkerOptions)
1712b6b257fSDimitry Andric         Builder->AppendLinkerOptions(Opt);
172ec2b103cSEd Schouten     }
173ec2b103cSEd Schouten 
HandleCXXStaticMemberVarInstantiation(VarDecl * VD)1749f4dbff6SDimitry Andric     void HandleCXXStaticMemberVarInstantiation(VarDecl *VD) override {
175bfef3995SDimitry Andric       if (Diags.hasErrorOccurred())
176bfef3995SDimitry Andric         return;
177bfef3995SDimitry Andric 
178dbe13110SDimitry Andric       Builder->HandleCXXStaticMemberVarInstantiation(VD);
179dbe13110SDimitry Andric     }
180dbe13110SDimitry Andric 
HandleTopLevelDecl(DeclGroupRef DG)1819f4dbff6SDimitry Andric     bool HandleTopLevelDecl(DeclGroupRef DG) override {
182e3b55780SDimitry Andric       // FIXME: Why not return false and abort parsing?
183ac9a064cSDimitry Andric       if (Diags.hasUnrecoverableErrorOccurred())
184bfef3995SDimitry Andric         return true;
185bfef3995SDimitry Andric 
18606d4ba38SDimitry Andric       HandlingTopLevelDeclRAII HandlingDecl(*this);
18706d4ba38SDimitry Andric 
188ec2b103cSEd Schouten       // Make sure to emit all elements of a Decl.
189ec2b103cSEd Schouten       for (DeclGroupRef::iterator I = DG.begin(), E = DG.end(); I != E; ++I)
190ec2b103cSEd Schouten         Builder->EmitTopLevelDecl(*I);
1919f4dbff6SDimitry Andric 
192dbe13110SDimitry Andric       return true;
193ec2b103cSEd Schouten     }
194ec2b103cSEd Schouten 
EmitDeferredDecls()19506d4ba38SDimitry Andric     void EmitDeferredDecls() {
196676fbe81SDimitry Andric       if (DeferredInlineMemberFuncDefs.empty())
19706d4ba38SDimitry Andric         return;
19806d4ba38SDimitry Andric 
19906d4ba38SDimitry Andric       // Emit any deferred inline method definitions. Note that more deferred
20006d4ba38SDimitry Andric       // methods may be added during this loop, since ASTConsumer callbacks
20106d4ba38SDimitry Andric       // can be invoked if AST inspection results in declarations being added.
20206d4ba38SDimitry Andric       HandlingTopLevelDeclRAII HandlingDecl(*this);
203676fbe81SDimitry Andric       for (unsigned I = 0; I != DeferredInlineMemberFuncDefs.size(); ++I)
204676fbe81SDimitry Andric         Builder->EmitTopLevelDecl(DeferredInlineMemberFuncDefs[I]);
205676fbe81SDimitry Andric       DeferredInlineMemberFuncDefs.clear();
20606d4ba38SDimitry Andric     }
20706d4ba38SDimitry Andric 
HandleInlineFunctionDefinition(FunctionDecl * D)2082b6b257fSDimitry Andric     void HandleInlineFunctionDefinition(FunctionDecl *D) override {
209ac9a064cSDimitry Andric       if (Diags.hasUnrecoverableErrorOccurred())
2109f4dbff6SDimitry Andric         return;
2119f4dbff6SDimitry Andric 
2129f4dbff6SDimitry Andric       assert(D->doesThisDeclarationHaveABody());
2139f4dbff6SDimitry Andric 
2149f4dbff6SDimitry Andric       // We may want to emit this definition. However, that decision might be
2159f4dbff6SDimitry Andric       // based on computing the linkage, and we have to defer that in case we
2169f4dbff6SDimitry Andric       // are inside of something that will change the method's final linkage,
2179f4dbff6SDimitry Andric       // e.g.
2189f4dbff6SDimitry Andric       //   typedef struct {
2199f4dbff6SDimitry Andric       //     void bar();
2209f4dbff6SDimitry Andric       //     void foo() { bar(); }
2219f4dbff6SDimitry Andric       //   } A;
222676fbe81SDimitry Andric       DeferredInlineMemberFuncDefs.push_back(D);
22306d4ba38SDimitry Andric 
22406d4ba38SDimitry Andric       // Provide some coverage mapping even for methods that aren't emitted.
22506d4ba38SDimitry Andric       // Don't do this for templated classes though, as they may not be
22606d4ba38SDimitry Andric       // instantiable.
227676fbe81SDimitry Andric       if (!D->getLexicalDeclContext()->isDependentContext())
228676fbe81SDimitry Andric         Builder->AddDeferredUnusedCoverageMapping(D);
2299f4dbff6SDimitry Andric     }
2309f4dbff6SDimitry Andric 
231ec2b103cSEd Schouten     /// HandleTagDeclDefinition - This callback is invoked each time a TagDecl
232ec2b103cSEd Schouten     /// to (e.g. struct, union, enum, class) is completed. This allows the
233ec2b103cSEd Schouten     /// client hack on the type, which can occur at any point in the file
234ec2b103cSEd Schouten     /// (because these can be defined in declspecs).
HandleTagDeclDefinition(TagDecl * D)2359f4dbff6SDimitry Andric     void HandleTagDeclDefinition(TagDecl *D) override {
236ac9a064cSDimitry Andric       if (Diags.hasUnrecoverableErrorOccurred())
237bfef3995SDimitry Andric         return;
238bfef3995SDimitry Andric 
2392b6b257fSDimitry Andric       // Don't allow re-entrant calls to CodeGen triggered by PCH
2402b6b257fSDimitry Andric       // deserialization to emit deferred decls.
2412b6b257fSDimitry Andric       HandlingTopLevelDeclRAII HandlingDecl(*this, /*EmitDeferred=*/false);
2422b6b257fSDimitry Andric 
243ec2b103cSEd Schouten       Builder->UpdateCompletedType(D);
244bca07a45SDimitry Andric 
2459f4dbff6SDimitry Andric       // For MSVC compatibility, treat declarations of static data members with
2469f4dbff6SDimitry Andric       // inline initializers as definitions.
24745b53394SDimitry Andric       if (Ctx->getTargetInfo().getCXXABI().isMicrosoft()) {
2489f4dbff6SDimitry Andric         for (Decl *Member : D->decls()) {
2499f4dbff6SDimitry Andric           if (VarDecl *VD = dyn_cast<VarDecl>(Member)) {
2509f4dbff6SDimitry Andric             if (Ctx->isMSStaticDataMemberInlineDefinition(VD) &&
2519f4dbff6SDimitry Andric                 Ctx->DeclMustBeEmitted(VD)) {
2529f4dbff6SDimitry Andric               Builder->EmitGlobal(VD);
2539f4dbff6SDimitry Andric             }
2549f4dbff6SDimitry Andric           }
2559f4dbff6SDimitry Andric         }
256bca07a45SDimitry Andric       }
2572b6b257fSDimitry Andric       // For OpenMP emit declare reduction functions, if required.
2582b6b257fSDimitry Andric       if (Ctx->getLangOpts().OpenMP) {
2592b6b257fSDimitry Andric         for (Decl *Member : D->decls()) {
2602b6b257fSDimitry Andric           if (auto *DRD = dyn_cast<OMPDeclareReductionDecl>(Member)) {
2612b6b257fSDimitry Andric             if (Ctx->DeclMustBeEmitted(DRD))
2622b6b257fSDimitry Andric               Builder->EmitGlobal(DRD);
263519fc96cSDimitry Andric           } else if (auto *DMD = dyn_cast<OMPDeclareMapperDecl>(Member)) {
264519fc96cSDimitry Andric             if (Ctx->DeclMustBeEmitted(DMD))
265519fc96cSDimitry Andric               Builder->EmitGlobal(DMD);
2662b6b257fSDimitry Andric           }
2672b6b257fSDimitry Andric         }
2682b6b257fSDimitry Andric       }
269ec2b103cSEd Schouten     }
270ec2b103cSEd Schouten 
HandleTagDeclRequiredDefinition(const TagDecl * D)2719f4dbff6SDimitry Andric     void HandleTagDeclRequiredDefinition(const TagDecl *D) override {
272ac9a064cSDimitry Andric       if (Diags.hasUnrecoverableErrorOccurred())
273bfef3995SDimitry Andric         return;
274bfef3995SDimitry Andric 
2752b6b257fSDimitry Andric       // Don't allow re-entrant calls to CodeGen triggered by PCH
2762b6b257fSDimitry Andric       // deserialization to emit deferred decls.
2772b6b257fSDimitry Andric       HandlingTopLevelDeclRAII HandlingDecl(*this, /*EmitDeferred=*/false);
2782b6b257fSDimitry Andric 
279bfef3995SDimitry Andric       if (CodeGen::CGDebugInfo *DI = Builder->getModuleDebugInfo())
280bfef3995SDimitry Andric         if (const RecordDecl *RD = dyn_cast<RecordDecl>(D))
281bfef3995SDimitry Andric           DI->completeRequiredType(RD);
282bfef3995SDimitry Andric     }
283bfef3995SDimitry Andric 
HandleTranslationUnit(ASTContext & Ctx)2849f4dbff6SDimitry Andric     void HandleTranslationUnit(ASTContext &Ctx) override {
2852b6b257fSDimitry Andric       // Release the Builder when there is no error.
286ac9a064cSDimitry Andric       if (!Diags.hasUnrecoverableErrorOccurred() && Builder)
2872b6b257fSDimitry Andric         Builder->Release();
2882b6b257fSDimitry Andric 
2892b6b257fSDimitry Andric       // If there are errors before or when releasing the Builder, reset
2902b6b257fSDimitry Andric       // the module to stop here before invoking the backend.
291ec2b103cSEd Schouten       if (Diags.hasErrorOccurred()) {
2929f4dbff6SDimitry Andric         if (Builder)
2939f4dbff6SDimitry Andric           Builder->clear();
294ec2b103cSEd Schouten         M.reset();
295ec2b103cSEd Schouten         return;
296ec2b103cSEd Schouten       }
2972b6b257fSDimitry Andric     }
298ec2b103cSEd Schouten 
AssignInheritanceModel(CXXRecordDecl * RD)2992b6b257fSDimitry Andric     void AssignInheritanceModel(CXXRecordDecl *RD) override {
300ac9a064cSDimitry Andric       if (Diags.hasUnrecoverableErrorOccurred())
3012b6b257fSDimitry Andric         return;
3022b6b257fSDimitry Andric 
3032b6b257fSDimitry Andric       Builder->RefreshTypeCacheForClass(RD);
304abe15e55SRoman Divacky     }
305ec2b103cSEd Schouten 
CompleteTentativeDefinition(VarDecl * D)3069f4dbff6SDimitry Andric     void CompleteTentativeDefinition(VarDecl *D) override {
307ac9a064cSDimitry Andric       if (Diags.hasUnrecoverableErrorOccurred())
308ec2b103cSEd Schouten         return;
309ec2b103cSEd Schouten 
310ec2b103cSEd Schouten       Builder->EmitTentativeDefinition(D);
311ec2b103cSEd Schouten     }
312d7279c4cSRoman Divacky 
CompleteExternalDeclaration(DeclaratorDecl * D)313ac9a064cSDimitry Andric     void CompleteExternalDeclaration(DeclaratorDecl *D) override {
314706b4fc4SDimitry Andric       Builder->EmitExternalDeclaration(D);
315706b4fc4SDimitry Andric     }
316706b4fc4SDimitry Andric 
HandleVTable(CXXRecordDecl * RD)3175e20cdd8SDimitry Andric     void HandleVTable(CXXRecordDecl *RD) override {
318ac9a064cSDimitry Andric       if (Diags.hasUnrecoverableErrorOccurred())
319d7279c4cSRoman Divacky         return;
320d7279c4cSRoman Divacky 
3215e20cdd8SDimitry Andric       Builder->EmitVTable(RD);
322d7279c4cSRoman Divacky     }
323ec2b103cSEd Schouten   };
324ec2b103cSEd Schouten }
325ec2b103cSEd Schouten 
anchor()326dbe13110SDimitry Andric void CodeGenerator::anchor() { }
327dbe13110SDimitry Andric 
CGM()3282b6b257fSDimitry Andric CodeGenModule &CodeGenerator::CGM() {
3292b6b257fSDimitry Andric   return static_cast<CodeGeneratorImpl*>(this)->CGM();
3302b6b257fSDimitry Andric }
3312b6b257fSDimitry Andric 
GetModule()3322b6b257fSDimitry Andric llvm::Module *CodeGenerator::GetModule() {
3332b6b257fSDimitry Andric   return static_cast<CodeGeneratorImpl*>(this)->GetModule();
3342b6b257fSDimitry Andric }
3352b6b257fSDimitry Andric 
ReleaseModule()3362b6b257fSDimitry Andric llvm::Module *CodeGenerator::ReleaseModule() {
3372b6b257fSDimitry Andric   return static_cast<CodeGeneratorImpl*>(this)->ReleaseModule();
3382b6b257fSDimitry Andric }
3392b6b257fSDimitry Andric 
getCGDebugInfo()3407442d6faSDimitry Andric CGDebugInfo *CodeGenerator::getCGDebugInfo() {
3417442d6faSDimitry Andric   return static_cast<CodeGeneratorImpl*>(this)->getCGDebugInfo();
3427442d6faSDimitry Andric }
3437442d6faSDimitry Andric 
GetDeclForMangledName(llvm::StringRef name)3442b6b257fSDimitry Andric const Decl *CodeGenerator::GetDeclForMangledName(llvm::StringRef name) {
3452b6b257fSDimitry Andric   return static_cast<CodeGeneratorImpl*>(this)->GetDeclForMangledName(name);
3462b6b257fSDimitry Andric }
3472b6b257fSDimitry Andric 
GetMangledName(GlobalDecl GD)348c0981da4SDimitry Andric llvm::StringRef CodeGenerator::GetMangledName(GlobalDecl GD) {
349c0981da4SDimitry Andric   return static_cast<CodeGeneratorImpl *>(this)->GetMangledName(GD);
350c0981da4SDimitry Andric }
351c0981da4SDimitry Andric 
GetAddrOfGlobal(GlobalDecl global,bool isForDefinition)3522b6b257fSDimitry Andric llvm::Constant *CodeGenerator::GetAddrOfGlobal(GlobalDecl global,
3532b6b257fSDimitry Andric                                                bool isForDefinition) {
3542b6b257fSDimitry Andric   return static_cast<CodeGeneratorImpl*>(this)
3552b6b257fSDimitry Andric            ->GetAddrOfGlobal(global, isForDefinition);
3562b6b257fSDimitry Andric }
3572b6b257fSDimitry Andric 
StartModule(llvm::StringRef ModuleName,llvm::LLVMContext & C)358461a67faSDimitry Andric llvm::Module *CodeGenerator::StartModule(llvm::StringRef ModuleName,
359461a67faSDimitry Andric                                          llvm::LLVMContext &C) {
360461a67faSDimitry Andric   return static_cast<CodeGeneratorImpl*>(this)->StartModule(ModuleName, C);
361461a67faSDimitry Andric }
362461a67faSDimitry Andric 
36308e8dd7bSDimitry Andric CodeGenerator *
CreateLLVMCodeGen(DiagnosticsEngine & Diags,llvm::StringRef ModuleName,IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS,const HeaderSearchOptions & HeaderSearchOpts,const PreprocessorOptions & PreprocessorOpts,const CodeGenOptions & CGO,llvm::LLVMContext & C,CoverageSourceInfo * CoverageInfo)36408e8dd7bSDimitry Andric clang::CreateLLVMCodeGen(DiagnosticsEngine &Diags, llvm::StringRef ModuleName,
36508e8dd7bSDimitry Andric                          IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS,
366c192b3dcSDimitry Andric                          const HeaderSearchOptions &HeaderSearchOpts,
36708e8dd7bSDimitry Andric                          const PreprocessorOptions &PreprocessorOpts,
36808e8dd7bSDimitry Andric                          const CodeGenOptions &CGO, llvm::LLVMContext &C,
36908e8dd7bSDimitry Andric                          CoverageSourceInfo *CoverageInfo) {
37008e8dd7bSDimitry Andric   return new CodeGeneratorImpl(Diags, ModuleName, std::move(FS),
37108e8dd7bSDimitry Andric                                HeaderSearchOpts, PreprocessorOpts, CGO, C,
37208e8dd7bSDimitry Andric                                CoverageInfo);
373ec2b103cSEd Schouten }
374