10#include "mlir/IR/MLIRContext.h"
11#include "mlir/IR/OwningOpRef.h"
18#include "llvm/IR/Module.h"
30 "Unsupported output type for getBackendActionFromOutputType!");
33 return BackendAction::Backend_EmitAssembly;
35 return BackendAction::Backend_EmitBC;
37 return BackendAction::Backend_EmitLL;
39 return BackendAction::Backend_EmitObj;
43 llvm_unreachable(
"Unsupported output type!");
46static std::unique_ptr<llvm::Module>
53 virtual void anchor();
59 std::unique_ptr<raw_pwrite_stream> OutputStream;
63 std::unique_ptr<CIRGenerator> Gen;
70 : Action(Action), CI(CI), OutputStream(
std::move(OS)),
71 FS(&CI.getVirtualFileSystem()),
73 CI.getCodeGenOpts())),
74 FEOptions(CI.getFrontendOpts()), CGO(CGO) {}
77 assert(!Context &&
"initialized multiple times");
83 Gen->HandleTopLevelDecl(
D);
88 Gen->HandleCXXStaticMemberVarInstantiation(VD);
92 Gen->HandleInlineFunctionDefinition(
D);
96 Gen->HandleTranslationUnit(
C);
99 if (!Gen->verifyModule()) {
101 diag::err_cir_verification_failed_pre_passes);
102 llvm::report_fatal_error(
103 "CIR codegen: module verification error before running CIR passes");
108 mlir::ModuleOp MlirModule = Gen->getModule();
109 mlir::MLIRContext &MlirCtx = Gen->getMLIRContext();
115 CGO.OptimizationLevel > 0)
124 if (OutputStream && MlirModule) {
125 mlir::OpPrintingFlags Flags;
126 Flags.enableDebugInfo(
true,
false);
127 MlirModule->print(*OutputStream, Flags);
134 llvm::LLVMContext LLVMCtx;
135 std::unique_ptr<llvm::Module> LLVMModule =
141 LLVMModule.get(), BEAction, FS, std::move(OutputStream));
150 "CIR generation of declaration");
151 Gen->HandleTagDeclDefinition(
D);
155 Gen->HandleTagDeclRequiredDefinition(
D);
159 Gen->CompleteTentativeDefinition(
D);
166void CIRGenConsumer::anchor() {}
169 : MLIRCtx(MLIRCtx ? MLIRCtx : new
mlir::MLIRContext), Action(Act) {}
173static std::unique_ptr<raw_pwrite_stream>
188 llvm_unreachable(
"Invalid CIRGenAction::OutputType");
191std::unique_ptr<ASTConsumer>
198 auto Result = std::make_unique<cir::CIRGenConsumer>(
204void EmitAssemblyAction::anchor() {}
208void EmitCIRAction::anchor() {}
212void EmitLLVMAction::anchor() {}
216void EmitBCAction::anchor() {}
220void EmitObjAction::anchor() {}
static std::unique_ptr< raw_pwrite_stream > getOutputStream(CompilerInstance &CI, StringRef InFile, CIRGenAction::OutputType Action)
CIRGenAction(OutputType Action, mlir::MLIRContext *MLIRCtx=nullptr)
std::unique_ptr< clang::ASTConsumer > CreateASTConsumer(clang::CompilerInstance &CI, llvm::StringRef InFile) override
void Initialize(ASTContext &Ctx) override
Initialize - This is called to initialize the consumer, providing the ASTContext.
bool HandleTopLevelDecl(DeclGroupRef D) override
HandleTopLevelDecl - Handle the specified top-level declaration.
void HandleTranslationUnit(ASTContext &C) override
HandleTranslationUnit - This method is called when the ASTs for entire translation unit have been par...
CIRGenConsumer(CIRGenAction::OutputType Action, CompilerInstance &CI, CodeGenOptions &CGO, std::unique_ptr< raw_pwrite_stream > OS)
void HandleInlineFunctionDefinition(FunctionDecl *D) override
This callback is invoked each time an inline (method or friend) function definition in a class is com...
void CompleteTentativeDefinition(VarDecl *D) override
CompleteTentativeDefinition - Callback invoked at the end of a translation unit to notify the consume...
void HandleTagDeclRequiredDefinition(const TagDecl *D) override
This callback is invoked the first time each TagDecl is required to be complete.
void HandleVTable(CXXRecordDecl *RD) override
Callback involved at the end of a translation unit to notify the consumer that a vtable for the given...
void HandleCXXStaticMemberVarInstantiation(clang::VarDecl *VD) override
HandleCXXStaticMemberVarInstantiation - Tell the consumer that this.
void HandleTagDeclDefinition(TagDecl *D) override
HandleTagDeclDefinition - This callback is invoked each time a TagDecl (e.g.
EmitAssemblyAction(mlir::MLIRContext *MLIRCtx=nullptr)
EmitBCAction(mlir::MLIRContext *MLIRCtx=nullptr)
EmitCIRAction(mlir::MLIRContext *MLIRCtx=nullptr)
EmitLLVMAction(mlir::MLIRContext *MLIRCtx=nullptr)
EmitObjAction(mlir::MLIRContext *MLIRCtx=nullptr)
ASTConsumer - This is an abstract interface that should be implemented by clients that read ASTs.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
SourceManager & getSourceManager()
Represents a C++ struct/union/class.
CodeGenOptions - Track various options which control how the code is optimized and passed to the back...
CompilerInstance - Helper class for managing a single instance of the Clang compiler.
DiagnosticsEngine & getDiagnostics() const
Get the current diagnostics engine.
std::unique_ptr< raw_pwrite_stream > createDefaultOutputFile(bool Binary=true, StringRef BaseInput="", StringRef Extension="", bool RemoveFileOnSignal=true, bool CreateMissingDirectories=false, bool ForceUseTemporary=false)
Create the default output file (from the invocation's options) and add it to the list of tracked outp...
std::unique_ptr< llvm::raw_pwrite_stream > takeOutputStream()
CodeGenOptions & getCodeGenOpts()
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
FrontendOptions - Options for controlling the behavior of the frontend.
unsigned ClangIRDisablePasses
Disable Clang IR specific (CIR) passes.
unsigned ClangIRDisableCIRVerifier
Disable Clang IR (CIR) verifier.
Represents a function declaration or definition.
PrettyStackTraceDecl - If a crash occurs, indicate that it happened when doing something to a specifi...
Encodes a location in the source.
Represents the declaration of a struct/union/class/enum.
Represents a variable declaration or definition.
std::unique_ptr< llvm::Module > lowerDirectlyFromCIRToLLVMIR(mlir::ModuleOp mlirModule, llvm::LLVMContext &llvmCtx)
mlir::LogicalResult runCIRToCIRPasses(mlir::ModuleOp theModule, mlir::MLIRContext &mlirCtx, clang::ASTContext &astCtx, bool enableVerifier, bool enableCIRSimplify)
static BackendAction getBackendActionFromOutputType(CIRGenAction::OutputType Action)
static std::unique_ptr< llvm::Module > lowerFromCIRToLLVMIR(mlir::ModuleOp MLIRModule, llvm::LLVMContext &LLVMCtx)
The JSON file list parser is used to communicate input to InstallAPI.
void emitBackendOutput(CompilerInstance &CI, CodeGenOptions &CGOpts, StringRef TDesc, llvm::Module *M, BackendAction Action, llvm::IntrusiveRefCntPtr< llvm::vfs::FileSystem > VFS, std::unique_ptr< raw_pwrite_stream > OS, BackendConsumer *BC=nullptr)