10b57cec5SDimitry Andric //===--- ModuleBuilder.cpp - Emit LLVM Code from ASTs ---------------------===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric //
90b57cec5SDimitry Andric // This builds an AST and converts it to LLVM Code.
100b57cec5SDimitry Andric //
110b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
120b57cec5SDimitry Andric
130b57cec5SDimitry Andric #include "clang/CodeGen/ModuleBuilder.h"
140b57cec5SDimitry Andric #include "CGDebugInfo.h"
150b57cec5SDimitry Andric #include "CodeGenModule.h"
160b57cec5SDimitry Andric #include "clang/AST/ASTContext.h"
170b57cec5SDimitry Andric #include "clang/AST/DeclObjC.h"
180b57cec5SDimitry Andric #include "clang/AST/Expr.h"
190b57cec5SDimitry Andric #include "clang/Basic/CodeGenOptions.h"
200b57cec5SDimitry Andric #include "clang/Basic/Diagnostic.h"
210b57cec5SDimitry Andric #include "clang/Basic/TargetInfo.h"
220b57cec5SDimitry Andric #include "llvm/ADT/StringRef.h"
230b57cec5SDimitry Andric #include "llvm/IR/DataLayout.h"
240b57cec5SDimitry Andric #include "llvm/IR/LLVMContext.h"
250b57cec5SDimitry Andric #include "llvm/IR/Module.h"
26972a253aSDimitry Andric #include "llvm/Support/VirtualFileSystem.h"
270b57cec5SDimitry Andric #include <memory>
280b57cec5SDimitry Andric
290b57cec5SDimitry Andric using namespace clang;
300b57cec5SDimitry Andric using namespace CodeGen;
310b57cec5SDimitry Andric
320b57cec5SDimitry Andric namespace {
330b57cec5SDimitry Andric class CodeGeneratorImpl : public CodeGenerator {
340b57cec5SDimitry Andric DiagnosticsEngine &Diags;
350b57cec5SDimitry Andric ASTContext *Ctx;
36972a253aSDimitry Andric IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS; // Only used for debug info.
370b57cec5SDimitry Andric const HeaderSearchOptions &HeaderSearchOpts; // Only used for debug info.
380b57cec5SDimitry Andric const PreprocessorOptions &PreprocessorOpts; // Only used for debug info.
3906c3fb27SDimitry Andric const CodeGenOptions &CodeGenOpts;
400b57cec5SDimitry Andric
410b57cec5SDimitry Andric unsigned HandlingTopLevelDecls;
420b57cec5SDimitry Andric
430b57cec5SDimitry Andric /// Use this when emitting decls to block re-entrant decl emission. It will
440b57cec5SDimitry Andric /// emit all deferred decls on scope exit. Set EmitDeferred to false if decl
450b57cec5SDimitry Andric /// emission must be deferred longer, like at the end of a tag definition.
460b57cec5SDimitry Andric struct HandlingTopLevelDeclRAII {
470b57cec5SDimitry Andric CodeGeneratorImpl &Self;
480b57cec5SDimitry Andric bool EmitDeferred;
HandlingTopLevelDeclRAII__anonbec9d48b0111::CodeGeneratorImpl::HandlingTopLevelDeclRAII490b57cec5SDimitry Andric HandlingTopLevelDeclRAII(CodeGeneratorImpl &Self,
500b57cec5SDimitry Andric bool EmitDeferred = true)
510b57cec5SDimitry Andric : Self(Self), EmitDeferred(EmitDeferred) {
520b57cec5SDimitry Andric ++Self.HandlingTopLevelDecls;
530b57cec5SDimitry Andric }
~HandlingTopLevelDeclRAII__anonbec9d48b0111::CodeGeneratorImpl::HandlingTopLevelDeclRAII540b57cec5SDimitry Andric ~HandlingTopLevelDeclRAII() {
550b57cec5SDimitry Andric unsigned Level = --Self.HandlingTopLevelDecls;
560b57cec5SDimitry Andric if (Level == 0 && EmitDeferred)
570b57cec5SDimitry Andric Self.EmitDeferredDecls();
580b57cec5SDimitry Andric }
590b57cec5SDimitry Andric };
600b57cec5SDimitry Andric
610b57cec5SDimitry Andric CoverageSourceInfo *CoverageInfo;
620b57cec5SDimitry Andric
630b57cec5SDimitry Andric protected:
640b57cec5SDimitry Andric std::unique_ptr<llvm::Module> M;
650b57cec5SDimitry Andric std::unique_ptr<CodeGen::CodeGenModule> Builder;
660b57cec5SDimitry Andric
670b57cec5SDimitry Andric private:
680b57cec5SDimitry Andric SmallVector<FunctionDecl *, 8> DeferredInlineMemberFuncDefs;
690b57cec5SDimitry Andric
ExpandModuleName(llvm::StringRef ModuleName,const CodeGenOptions & CGO)70a7dea167SDimitry Andric static llvm::StringRef ExpandModuleName(llvm::StringRef ModuleName,
71a7dea167SDimitry Andric const CodeGenOptions &CGO) {
72a7dea167SDimitry Andric if (ModuleName == "-" && !CGO.MainFileName.empty())
73a7dea167SDimitry Andric return CGO.MainFileName;
74a7dea167SDimitry Andric return ModuleName;
75a7dea167SDimitry Andric }
76a7dea167SDimitry Andric
770b57cec5SDimitry Andric 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)780b57cec5SDimitry Andric CodeGeneratorImpl(DiagnosticsEngine &diags, llvm::StringRef ModuleName,
79972a253aSDimitry Andric IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS,
800b57cec5SDimitry Andric const HeaderSearchOptions &HSO,
810b57cec5SDimitry Andric const PreprocessorOptions &PPO, const CodeGenOptions &CGO,
820b57cec5SDimitry Andric llvm::LLVMContext &C,
830b57cec5SDimitry Andric CoverageSourceInfo *CoverageInfo = nullptr)
84972a253aSDimitry Andric : Diags(diags), Ctx(nullptr), FS(std::move(FS)), HeaderSearchOpts(HSO),
850b57cec5SDimitry Andric PreprocessorOpts(PPO), CodeGenOpts(CGO), HandlingTopLevelDecls(0),
86a7dea167SDimitry Andric CoverageInfo(CoverageInfo),
87a7dea167SDimitry Andric M(new llvm::Module(ExpandModuleName(ModuleName, CGO), C)) {
880b57cec5SDimitry Andric C.setDiscardValueNames(CGO.DiscardValueNames);
890b57cec5SDimitry Andric }
900b57cec5SDimitry Andric
~CodeGeneratorImpl()910b57cec5SDimitry Andric ~CodeGeneratorImpl() override {
920b57cec5SDimitry Andric // There should normally not be any leftover inline method definitions.
930b57cec5SDimitry Andric assert(DeferredInlineMemberFuncDefs.empty() ||
940b57cec5SDimitry Andric Diags.hasErrorOccurred());
950b57cec5SDimitry Andric }
960b57cec5SDimitry Andric
CGM()970b57cec5SDimitry Andric CodeGenModule &CGM() {
980b57cec5SDimitry Andric return *Builder;
990b57cec5SDimitry Andric }
1000b57cec5SDimitry Andric
GetModule()1010b57cec5SDimitry Andric llvm::Module *GetModule() {
1020b57cec5SDimitry Andric return M.get();
1030b57cec5SDimitry Andric }
1040b57cec5SDimitry Andric
getCGDebugInfo()1050b57cec5SDimitry Andric CGDebugInfo *getCGDebugInfo() {
1060b57cec5SDimitry Andric return Builder->getModuleDebugInfo();
1070b57cec5SDimitry Andric }
1080b57cec5SDimitry Andric
ReleaseModule()1090b57cec5SDimitry Andric llvm::Module *ReleaseModule() {
1100b57cec5SDimitry Andric return M.release();
1110b57cec5SDimitry Andric }
1120b57cec5SDimitry Andric
GetDeclForMangledName(StringRef MangledName)1130b57cec5SDimitry Andric const Decl *GetDeclForMangledName(StringRef MangledName) {
1140b57cec5SDimitry Andric GlobalDecl Result;
1150b57cec5SDimitry Andric if (!Builder->lookupRepresentativeDecl(MangledName, Result))
1160b57cec5SDimitry Andric return nullptr;
1170b57cec5SDimitry Andric const Decl *D = Result.getCanonicalDecl().getDecl();
1180b57cec5SDimitry Andric if (auto FD = dyn_cast<FunctionDecl>(D)) {
1190b57cec5SDimitry Andric if (FD->hasBody(FD))
1200b57cec5SDimitry Andric return FD;
1210b57cec5SDimitry Andric } else if (auto TD = dyn_cast<TagDecl>(D)) {
1220b57cec5SDimitry Andric if (auto Def = TD->getDefinition())
1230b57cec5SDimitry Andric return Def;
1240b57cec5SDimitry Andric }
1250b57cec5SDimitry Andric return D;
1260b57cec5SDimitry Andric }
1270b57cec5SDimitry Andric
GetMangledName(GlobalDecl GD)128349cc55cSDimitry Andric llvm::StringRef GetMangledName(GlobalDecl GD) {
129349cc55cSDimitry Andric return Builder->getMangledName(GD);
130349cc55cSDimitry Andric }
131349cc55cSDimitry Andric
GetAddrOfGlobal(GlobalDecl global,bool isForDefinition)1320b57cec5SDimitry Andric llvm::Constant *GetAddrOfGlobal(GlobalDecl global, bool isForDefinition) {
1330b57cec5SDimitry Andric return Builder->GetAddrOfGlobal(global, ForDefinition_t(isForDefinition));
1340b57cec5SDimitry Andric }
1350b57cec5SDimitry Andric
StartModule(llvm::StringRef ModuleName,llvm::LLVMContext & C)1360b57cec5SDimitry Andric llvm::Module *StartModule(llvm::StringRef ModuleName,
1370b57cec5SDimitry Andric llvm::LLVMContext &C) {
1380b57cec5SDimitry Andric assert(!M && "Replacing existing Module?");
139a7dea167SDimitry Andric M.reset(new llvm::Module(ExpandModuleName(ModuleName, CodeGenOpts), C));
14081ad6265SDimitry Andric
14181ad6265SDimitry Andric std::unique_ptr<CodeGenModule> OldBuilder = std::move(Builder);
14281ad6265SDimitry Andric
1430b57cec5SDimitry Andric Initialize(*Ctx);
14481ad6265SDimitry Andric
14581ad6265SDimitry Andric if (OldBuilder)
14681ad6265SDimitry Andric OldBuilder->moveLazyEmissionStates(Builder.get());
14781ad6265SDimitry Andric
1480b57cec5SDimitry Andric return M.get();
1490b57cec5SDimitry Andric }
1500b57cec5SDimitry Andric
Initialize(ASTContext & Context)1510b57cec5SDimitry Andric void Initialize(ASTContext &Context) override {
1520b57cec5SDimitry Andric Ctx = &Context;
1530b57cec5SDimitry Andric
1540b57cec5SDimitry Andric M->setTargetTriple(Ctx->getTargetInfo().getTriple().getTriple());
155fe6060f1SDimitry Andric M->setDataLayout(Ctx->getTargetInfo().getDataLayoutString());
1560b57cec5SDimitry Andric const auto &SDKVersion = Ctx->getTargetInfo().getSDKVersion();
1570b57cec5SDimitry Andric if (!SDKVersion.empty())
1580b57cec5SDimitry Andric M->setSDKVersion(SDKVersion);
15981ad6265SDimitry Andric if (const auto *TVT = Ctx->getTargetInfo().getDarwinTargetVariantTriple())
16081ad6265SDimitry Andric M->setDarwinTargetVariantTriple(TVT->getTriple());
16181ad6265SDimitry Andric if (auto TVSDKVersion =
16281ad6265SDimitry Andric Ctx->getTargetInfo().getDarwinTargetVariantSDKVersion())
16381ad6265SDimitry Andric M->setDarwinTargetVariantSDKVersion(*TVSDKVersion);
164972a253aSDimitry Andric Builder.reset(new CodeGen::CodeGenModule(Context, FS, HeaderSearchOpts,
1650b57cec5SDimitry Andric PreprocessorOpts, CodeGenOpts,
1660b57cec5SDimitry Andric *M, Diags, CoverageInfo));
1670b57cec5SDimitry Andric
1680b57cec5SDimitry Andric for (auto &&Lib : CodeGenOpts.DependentLibraries)
1690b57cec5SDimitry Andric Builder->AddDependentLib(Lib);
1700b57cec5SDimitry Andric for (auto &&Opt : CodeGenOpts.LinkerOptions)
1710b57cec5SDimitry Andric Builder->AppendLinkerOptions(Opt);
1720b57cec5SDimitry Andric }
1730b57cec5SDimitry Andric
HandleCXXStaticMemberVarInstantiation(VarDecl * VD)1740b57cec5SDimitry Andric void HandleCXXStaticMemberVarInstantiation(VarDecl *VD) override {
1750b57cec5SDimitry Andric if (Diags.hasErrorOccurred())
1760b57cec5SDimitry Andric return;
1770b57cec5SDimitry Andric
1780b57cec5SDimitry Andric Builder->HandleCXXStaticMemberVarInstantiation(VD);
1790b57cec5SDimitry Andric }
1800b57cec5SDimitry Andric
HandleTopLevelDecl(DeclGroupRef DG)1810b57cec5SDimitry Andric bool HandleTopLevelDecl(DeclGroupRef DG) override {
182bdd1243dSDimitry Andric // FIXME: Why not return false and abort parsing?
183*0fca6ea1SDimitry Andric if (Diags.hasUnrecoverableErrorOccurred())
1840b57cec5SDimitry Andric return true;
1850b57cec5SDimitry Andric
1860b57cec5SDimitry Andric HandlingTopLevelDeclRAII HandlingDecl(*this);
1870b57cec5SDimitry Andric
1880b57cec5SDimitry Andric // Make sure to emit all elements of a Decl.
1890b57cec5SDimitry Andric for (DeclGroupRef::iterator I = DG.begin(), E = DG.end(); I != E; ++I)
1900b57cec5SDimitry Andric Builder->EmitTopLevelDecl(*I);
1910b57cec5SDimitry Andric
1920b57cec5SDimitry Andric return true;
1930b57cec5SDimitry Andric }
1940b57cec5SDimitry Andric
EmitDeferredDecls()1950b57cec5SDimitry Andric void EmitDeferredDecls() {
1960b57cec5SDimitry Andric if (DeferredInlineMemberFuncDefs.empty())
1970b57cec5SDimitry Andric return;
1980b57cec5SDimitry Andric
1990b57cec5SDimitry Andric // Emit any deferred inline method definitions. Note that more deferred
2000b57cec5SDimitry Andric // methods may be added during this loop, since ASTConsumer callbacks
2010b57cec5SDimitry Andric // can be invoked if AST inspection results in declarations being added.
2020b57cec5SDimitry Andric HandlingTopLevelDeclRAII HandlingDecl(*this);
2030b57cec5SDimitry Andric for (unsigned I = 0; I != DeferredInlineMemberFuncDefs.size(); ++I)
2040b57cec5SDimitry Andric Builder->EmitTopLevelDecl(DeferredInlineMemberFuncDefs[I]);
2050b57cec5SDimitry Andric DeferredInlineMemberFuncDefs.clear();
2060b57cec5SDimitry Andric }
2070b57cec5SDimitry Andric
HandleInlineFunctionDefinition(FunctionDecl * D)2080b57cec5SDimitry Andric void HandleInlineFunctionDefinition(FunctionDecl *D) override {
209*0fca6ea1SDimitry Andric if (Diags.hasUnrecoverableErrorOccurred())
2100b57cec5SDimitry Andric return;
2110b57cec5SDimitry Andric
2120b57cec5SDimitry Andric assert(D->doesThisDeclarationHaveABody());
2130b57cec5SDimitry Andric
2140b57cec5SDimitry Andric // We may want to emit this definition. However, that decision might be
2150b57cec5SDimitry Andric // based on computing the linkage, and we have to defer that in case we
2160b57cec5SDimitry Andric // are inside of something that will change the method's final linkage,
2170b57cec5SDimitry Andric // e.g.
2180b57cec5SDimitry Andric // typedef struct {
2190b57cec5SDimitry Andric // void bar();
2200b57cec5SDimitry Andric // void foo() { bar(); }
2210b57cec5SDimitry Andric // } A;
2220b57cec5SDimitry Andric DeferredInlineMemberFuncDefs.push_back(D);
2230b57cec5SDimitry Andric
2240b57cec5SDimitry Andric // Provide some coverage mapping even for methods that aren't emitted.
2250b57cec5SDimitry Andric // Don't do this for templated classes though, as they may not be
2260b57cec5SDimitry Andric // instantiable.
2270b57cec5SDimitry Andric if (!D->getLexicalDeclContext()->isDependentContext())
2280b57cec5SDimitry Andric Builder->AddDeferredUnusedCoverageMapping(D);
2290b57cec5SDimitry Andric }
2300b57cec5SDimitry Andric
2310b57cec5SDimitry Andric /// HandleTagDeclDefinition - This callback is invoked each time a TagDecl
2320b57cec5SDimitry Andric /// to (e.g. struct, union, enum, class) is completed. This allows the
2330b57cec5SDimitry Andric /// client hack on the type, which can occur at any point in the file
2340b57cec5SDimitry Andric /// (because these can be defined in declspecs).
HandleTagDeclDefinition(TagDecl * D)2350b57cec5SDimitry Andric void HandleTagDeclDefinition(TagDecl *D) override {
236*0fca6ea1SDimitry Andric if (Diags.hasUnrecoverableErrorOccurred())
2370b57cec5SDimitry Andric return;
2380b57cec5SDimitry Andric
2390b57cec5SDimitry Andric // Don't allow re-entrant calls to CodeGen triggered by PCH
2400b57cec5SDimitry Andric // deserialization to emit deferred decls.
2410b57cec5SDimitry Andric HandlingTopLevelDeclRAII HandlingDecl(*this, /*EmitDeferred=*/false);
2420b57cec5SDimitry Andric
2430b57cec5SDimitry Andric Builder->UpdateCompletedType(D);
2440b57cec5SDimitry Andric
2450b57cec5SDimitry Andric // For MSVC compatibility, treat declarations of static data members with
2460b57cec5SDimitry Andric // inline initializers as definitions.
2470b57cec5SDimitry Andric if (Ctx->getTargetInfo().getCXXABI().isMicrosoft()) {
2480b57cec5SDimitry Andric for (Decl *Member : D->decls()) {
2490b57cec5SDimitry Andric if (VarDecl *VD = dyn_cast<VarDecl>(Member)) {
2500b57cec5SDimitry Andric if (Ctx->isMSStaticDataMemberInlineDefinition(VD) &&
2510b57cec5SDimitry Andric Ctx->DeclMustBeEmitted(VD)) {
2520b57cec5SDimitry Andric Builder->EmitGlobal(VD);
2530b57cec5SDimitry Andric }
2540b57cec5SDimitry Andric }
2550b57cec5SDimitry Andric }
2560b57cec5SDimitry Andric }
2570b57cec5SDimitry Andric // For OpenMP emit declare reduction functions, if required.
2580b57cec5SDimitry Andric if (Ctx->getLangOpts().OpenMP) {
2590b57cec5SDimitry Andric for (Decl *Member : D->decls()) {
2600b57cec5SDimitry Andric if (auto *DRD = dyn_cast<OMPDeclareReductionDecl>(Member)) {
2610b57cec5SDimitry Andric if (Ctx->DeclMustBeEmitted(DRD))
2620b57cec5SDimitry Andric Builder->EmitGlobal(DRD);
263a7dea167SDimitry Andric } else if (auto *DMD = dyn_cast<OMPDeclareMapperDecl>(Member)) {
264a7dea167SDimitry Andric if (Ctx->DeclMustBeEmitted(DMD))
265a7dea167SDimitry Andric Builder->EmitGlobal(DMD);
2660b57cec5SDimitry Andric }
2670b57cec5SDimitry Andric }
2680b57cec5SDimitry Andric }
2690b57cec5SDimitry Andric }
2700b57cec5SDimitry Andric
HandleTagDeclRequiredDefinition(const TagDecl * D)2710b57cec5SDimitry Andric void HandleTagDeclRequiredDefinition(const TagDecl *D) override {
272*0fca6ea1SDimitry Andric if (Diags.hasUnrecoverableErrorOccurred())
2730b57cec5SDimitry Andric return;
2740b57cec5SDimitry Andric
2750b57cec5SDimitry Andric // Don't allow re-entrant calls to CodeGen triggered by PCH
2760b57cec5SDimitry Andric // deserialization to emit deferred decls.
2770b57cec5SDimitry Andric HandlingTopLevelDeclRAII HandlingDecl(*this, /*EmitDeferred=*/false);
2780b57cec5SDimitry Andric
2790b57cec5SDimitry Andric if (CodeGen::CGDebugInfo *DI = Builder->getModuleDebugInfo())
2800b57cec5SDimitry Andric if (const RecordDecl *RD = dyn_cast<RecordDecl>(D))
2810b57cec5SDimitry Andric DI->completeRequiredType(RD);
2820b57cec5SDimitry Andric }
2830b57cec5SDimitry Andric
HandleTranslationUnit(ASTContext & Ctx)2840b57cec5SDimitry Andric void HandleTranslationUnit(ASTContext &Ctx) override {
2850b57cec5SDimitry Andric // Release the Builder when there is no error.
286*0fca6ea1SDimitry Andric if (!Diags.hasUnrecoverableErrorOccurred() && Builder)
2870b57cec5SDimitry Andric Builder->Release();
2880b57cec5SDimitry Andric
2890b57cec5SDimitry Andric // If there are errors before or when releasing the Builder, reset
2900b57cec5SDimitry Andric // the module to stop here before invoking the backend.
2910b57cec5SDimitry Andric if (Diags.hasErrorOccurred()) {
2920b57cec5SDimitry Andric if (Builder)
2930b57cec5SDimitry Andric Builder->clear();
2940b57cec5SDimitry Andric M.reset();
2950b57cec5SDimitry Andric return;
2960b57cec5SDimitry Andric }
2970b57cec5SDimitry Andric }
2980b57cec5SDimitry Andric
AssignInheritanceModel(CXXRecordDecl * RD)2990b57cec5SDimitry Andric void AssignInheritanceModel(CXXRecordDecl *RD) override {
300*0fca6ea1SDimitry Andric if (Diags.hasUnrecoverableErrorOccurred())
3010b57cec5SDimitry Andric return;
3020b57cec5SDimitry Andric
3030b57cec5SDimitry Andric Builder->RefreshTypeCacheForClass(RD);
3040b57cec5SDimitry Andric }
3050b57cec5SDimitry Andric
CompleteTentativeDefinition(VarDecl * D)3060b57cec5SDimitry Andric void CompleteTentativeDefinition(VarDecl *D) override {
307*0fca6ea1SDimitry Andric if (Diags.hasUnrecoverableErrorOccurred())
3080b57cec5SDimitry Andric return;
3090b57cec5SDimitry Andric
3100b57cec5SDimitry Andric Builder->EmitTentativeDefinition(D);
3110b57cec5SDimitry Andric }
3120b57cec5SDimitry Andric
CompleteExternalDeclaration(DeclaratorDecl * D)313*0fca6ea1SDimitry Andric void CompleteExternalDeclaration(DeclaratorDecl *D) override {
314480093f4SDimitry Andric Builder->EmitExternalDeclaration(D);
315480093f4SDimitry Andric }
316480093f4SDimitry Andric
HandleVTable(CXXRecordDecl * RD)3170b57cec5SDimitry Andric void HandleVTable(CXXRecordDecl *RD) override {
318*0fca6ea1SDimitry Andric if (Diags.hasUnrecoverableErrorOccurred())
3190b57cec5SDimitry Andric return;
3200b57cec5SDimitry Andric
3210b57cec5SDimitry Andric Builder->EmitVTable(RD);
3220b57cec5SDimitry Andric }
3230b57cec5SDimitry Andric };
3240b57cec5SDimitry Andric }
3250b57cec5SDimitry Andric
anchor()3260b57cec5SDimitry Andric void CodeGenerator::anchor() { }
3270b57cec5SDimitry Andric
CGM()3280b57cec5SDimitry Andric CodeGenModule &CodeGenerator::CGM() {
3290b57cec5SDimitry Andric return static_cast<CodeGeneratorImpl*>(this)->CGM();
3300b57cec5SDimitry Andric }
3310b57cec5SDimitry Andric
GetModule()3320b57cec5SDimitry Andric llvm::Module *CodeGenerator::GetModule() {
3330b57cec5SDimitry Andric return static_cast<CodeGeneratorImpl*>(this)->GetModule();
3340b57cec5SDimitry Andric }
3350b57cec5SDimitry Andric
ReleaseModule()3360b57cec5SDimitry Andric llvm::Module *CodeGenerator::ReleaseModule() {
3370b57cec5SDimitry Andric return static_cast<CodeGeneratorImpl*>(this)->ReleaseModule();
3380b57cec5SDimitry Andric }
3390b57cec5SDimitry Andric
getCGDebugInfo()3400b57cec5SDimitry Andric CGDebugInfo *CodeGenerator::getCGDebugInfo() {
3410b57cec5SDimitry Andric return static_cast<CodeGeneratorImpl*>(this)->getCGDebugInfo();
3420b57cec5SDimitry Andric }
3430b57cec5SDimitry Andric
GetDeclForMangledName(llvm::StringRef name)3440b57cec5SDimitry Andric const Decl *CodeGenerator::GetDeclForMangledName(llvm::StringRef name) {
3450b57cec5SDimitry Andric return static_cast<CodeGeneratorImpl*>(this)->GetDeclForMangledName(name);
3460b57cec5SDimitry Andric }
3470b57cec5SDimitry Andric
GetMangledName(GlobalDecl GD)348349cc55cSDimitry Andric llvm::StringRef CodeGenerator::GetMangledName(GlobalDecl GD) {
349349cc55cSDimitry Andric return static_cast<CodeGeneratorImpl *>(this)->GetMangledName(GD);
350349cc55cSDimitry Andric }
351349cc55cSDimitry Andric
GetAddrOfGlobal(GlobalDecl global,bool isForDefinition)3520b57cec5SDimitry Andric llvm::Constant *CodeGenerator::GetAddrOfGlobal(GlobalDecl global,
3530b57cec5SDimitry Andric bool isForDefinition) {
3540b57cec5SDimitry Andric return static_cast<CodeGeneratorImpl*>(this)
3550b57cec5SDimitry Andric ->GetAddrOfGlobal(global, isForDefinition);
3560b57cec5SDimitry Andric }
3570b57cec5SDimitry Andric
StartModule(llvm::StringRef ModuleName,llvm::LLVMContext & C)3580b57cec5SDimitry Andric llvm::Module *CodeGenerator::StartModule(llvm::StringRef ModuleName,
3590b57cec5SDimitry Andric llvm::LLVMContext &C) {
3600b57cec5SDimitry Andric return static_cast<CodeGeneratorImpl*>(this)->StartModule(ModuleName, C);
3610b57cec5SDimitry Andric }
3620b57cec5SDimitry Andric
363972a253aSDimitry 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)364972a253aSDimitry Andric clang::CreateLLVMCodeGen(DiagnosticsEngine &Diags, llvm::StringRef ModuleName,
365972a253aSDimitry Andric IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS,
3660b57cec5SDimitry Andric const HeaderSearchOptions &HeaderSearchOpts,
367972a253aSDimitry Andric const PreprocessorOptions &PreprocessorOpts,
368972a253aSDimitry Andric const CodeGenOptions &CGO, llvm::LLVMContext &C,
369972a253aSDimitry Andric CoverageSourceInfo *CoverageInfo) {
370972a253aSDimitry Andric return new CodeGeneratorImpl(Diags, ModuleName, std::move(FS),
371972a253aSDimitry Andric HeaderSearchOpts, PreprocessorOpts, CGO, C,
372972a253aSDimitry Andric CoverageInfo);
3730b57cec5SDimitry Andric }
374