77// ===----------------------------------------------------------------------===//
88
99#include " clang/CIR/FrontendAction/CIRGenAction.h"
10- #include " mlir/IR/MLIRContext.h"
11- #include " mlir/IR/OwningOpRef.h"
1210#include " clang/CIR/CIRGenerator.h"
13- #include " clang/CIR/LowerToLLVM.h"
14- #include " clang/CodeGen/BackendUtil.h"
1511#include " clang/Frontend/CompilerInstance.h"
16- #include " llvm/IR/Module.h"
12+
13+ #include " mlir/IR/MLIRContext.h"
14+ #include " mlir/IR/OwningOpRef.h"
1715
1816using namespace cir ;
1917using namespace clang ;
2018
2119namespace cir {
2220
23- static BackendAction
24- getBackendActionFromOutputType (CIRGenAction::OutputType Action) {
25- switch (Action) {
26- case CIRGenAction::OutputType::EmitCIR:
27- assert (false &&
28- " Unsupported output type for getBackendActionFromOutputType!" );
29- break ; // Unreachable, but fall through to report that
30- case CIRGenAction::OutputType::EmitLLVM:
31- return BackendAction::Backend_EmitLL;
32- }
33- // We should only get here if a non-enum value is passed in or we went through
34- // the assert(false) case above
35- llvm_unreachable (" Unsupported output type!" );
36- }
37-
38- static std::unique_ptr<llvm::Module>
39- lowerFromCIRToLLVMIR (mlir::ModuleOp MLIRModule, llvm::LLVMContext &LLVMCtx) {
40- return direct::lowerDirectlyFromCIRToLLVMIR (MLIRModule, LLVMCtx);
41- }
42-
4321class CIRGenConsumer : public clang ::ASTConsumer {
4422
4523 virtual void anchor ();
4624
4725 CIRGenAction::OutputType Action;
4826
49- CompilerInstance &CI;
50-
5127 std::unique_ptr<raw_pwrite_stream> OutputStream;
5228
5329 ASTContext *Context{nullptr };
5430 IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS;
5531 std::unique_ptr<CIRGenerator> Gen;
5632
5733public:
58- CIRGenConsumer (CIRGenAction::OutputType Action, CompilerInstance &CI,
34+ CIRGenConsumer (CIRGenAction::OutputType Action,
35+ DiagnosticsEngine &DiagnosticsEngine,
36+ IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS,
37+ const HeaderSearchOptions &HeaderSearchOptions,
38+ const CodeGenOptions &CodeGenOptions,
39+ const TargetOptions &TargetOptions,
40+ const LangOptions &LangOptions,
41+ const FrontendOptions &FEOptions,
5942 std::unique_ptr<raw_pwrite_stream> OS)
60- : Action(Action), CI(CI), OutputStream(std::move(OS)),
61- FS (&CI.getVirtualFileSystem()),
62- Gen(std::make_unique<CIRGenerator>(CI.getDiagnostics(), std::move(FS),
63- CI.getCodeGenOpts())) {}
43+ : Action(Action), OutputStream(std::move(OS)), FS(VFS),
44+ Gen (std::make_unique<CIRGenerator>(DiagnosticsEngine, std::move(VFS),
45+ CodeGenOptions)) {}
6446
6547 void Initialize (ASTContext &Ctx) override {
6648 assert (!Context && " initialized multiple times" );
@@ -84,17 +66,6 @@ class CIRGenConsumer : public clang::ASTConsumer {
8466 MlirModule->print (*OutputStream, Flags);
8567 }
8668 break ;
87- case CIRGenAction::OutputType::EmitLLVM: {
88- llvm::LLVMContext LLVMCtx;
89- std::unique_ptr<llvm::Module> LLVMModule =
90- lowerFromCIRToLLVMIR (MlirModule, LLVMCtx);
91-
92- BackendAction BEAction = getBackendActionFromOutputType (Action);
93- emitBackendOutput (
94- CI, CI.getCodeGenOpts (), C.getTargetInfo ().getDataLayoutString (),
95- LLVMModule.get (), BEAction, FS, std::move (OutputStream));
96- break ;
97- }
9869 }
9970 }
10071};
@@ -113,8 +84,6 @@ getOutputStream(CompilerInstance &CI, StringRef InFile,
11384 switch (Action) {
11485 case CIRGenAction::OutputType::EmitCIR:
11586 return CI.createDefaultOutputFile (false , InFile, " cir" );
116- case CIRGenAction::OutputType::EmitLLVM:
117- return CI.createDefaultOutputFile (false , InFile, " ll" );
11887 }
11988 llvm_unreachable (" Invalid CIRGenAction::OutputType" );
12089}
@@ -126,16 +95,14 @@ CIRGenAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) {
12695 if (!Out)
12796 Out = getOutputStream (CI, InFile, Action);
12897
129- auto Result =
130- std::make_unique<cir::CIRGenConsumer>(Action, CI, std::move (Out));
98+ auto Result = std::make_unique<cir::CIRGenConsumer>(
99+ Action, CI.getDiagnostics (), &CI.getVirtualFileSystem (),
100+ CI.getHeaderSearchOpts (), CI.getCodeGenOpts (), CI.getTargetOpts (),
101+ CI.getLangOpts (), CI.getFrontendOpts (), std::move (Out));
131102
132103 return Result;
133104}
134105
135106void EmitCIRAction::anchor () {}
136107EmitCIRAction::EmitCIRAction (mlir::MLIRContext *MLIRCtx)
137108 : CIRGenAction(OutputType::EmitCIR, MLIRCtx) {}
138-
139- void EmitLLVMAction::anchor () {}
140- EmitLLVMAction::EmitLLVMAction (mlir::MLIRContext *MLIRCtx)
141- : CIRGenAction(OutputType::EmitLLVM, MLIRCtx) {}
0 commit comments