Skip to content

Commit 1b0e5c6

Browse files
committed
Address review feedback
1 parent dc69628 commit 1b0e5c6

File tree

4 files changed

+13
-15
lines changed

4 files changed

+13
-15
lines changed

clang/include/clang/CIR/CIRGenerator.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class CIRGenerator : public clang::ASTConsumer {
4444
const clang::CodeGenOptions &codeGenOpts;
4545

4646
protected:
47-
std::shared_ptr<mlir::MLIRContext> mlirContext;
47+
std::unique_ptr<mlir::MLIRContext> mlirContext;
4848
std::unique_ptr<clang::CIRGen::CIRGenModule> cgm;
4949

5050
public:
@@ -55,9 +55,6 @@ class CIRGenerator : public clang::ASTConsumer {
5555
void Initialize(clang::ASTContext &astContext) override;
5656
bool HandleTopLevelDecl(clang::DeclGroupRef group) override;
5757
mlir::ModuleOp getModule() const;
58-
std::shared_ptr<mlir::MLIRContext> getContext() {
59-
return mlirContext;
60-
};
6158
};
6259

6360
} // namespace cir

clang/lib/CIR/CodeGen/CIRGenerator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ void CIRGenerator::Initialize(ASTContext &astContext) {
3434

3535
this->astContext = &astContext;
3636

37-
mlirContext = std::make_shared<mlir::MLIRContext>();
37+
mlirContext = std::make_unique<mlir::MLIRContext>();
3838
mlirContext->loadDialect<cir::CIRDialect>();
3939
cgm = std::make_unique<clang::CIRGen::CIRGenModule>(
4040
*mlirContext.get(), astContext, codeGenOpts, diags);

clang/lib/CIR/FrontendAction/CIRGenAction.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,20 @@ namespace cir {
2323
static BackendAction
2424
getBackendActionFromOutputType(CIRGenAction::OutputType Action) {
2525
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
2630
case CIRGenAction::OutputType::EmitLLVM:
2731
return BackendAction::Backend_EmitLL;
28-
default:
29-
llvm_unreachable("Unsupported action");
3032
}
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!");
3136
}
3237

33-
static std::unique_ptr<llvm::Module> lowerFromCIRToLLVMIR(
34-
const clang::FrontendOptions &FEOpts, mlir::ModuleOp MLIRModule,
35-
std::shared_ptr<mlir::MLIRContext> MLIRCtx, llvm::LLVMContext &LLVMCtx) {
38+
static std::unique_ptr<llvm::Module>
39+
lowerFromCIRToLLVMIR(mlir::ModuleOp MLIRModule, llvm::LLVMContext &LLVMCtx) {
3640
return direct::lowerDirectlyFromCIRToLLVMIR(MLIRModule, LLVMCtx);
3741
}
3842

@@ -72,7 +76,6 @@ class CIRGenConsumer : public clang::ASTConsumer {
7276
void HandleTranslationUnit(ASTContext &C) override {
7377
Gen->HandleTranslationUnit(C);
7478
mlir::ModuleOp MlirModule = Gen->getModule();
75-
std::shared_ptr<mlir::MLIRContext> MLIRCtx = Gen->getContext();
7679
switch (Action) {
7780
case CIRGenAction::OutputType::EmitCIR:
7881
if (OutputStream && MlirModule) {
@@ -83,8 +86,8 @@ class CIRGenConsumer : public clang::ASTConsumer {
8386
break;
8487
case CIRGenAction::OutputType::EmitLLVM: {
8588
llvm::LLVMContext LLVMCtx;
86-
auto LLVMModule = lowerFromCIRToLLVMIR(CI.getFrontendOpts(), MlirModule,
87-
MLIRCtx, LLVMCtx);
89+
std::unique_ptr<llvm::Module> LLVMModule =
90+
lowerFromCIRToLLVMIR(MlirModule, LLVMCtx);
8891

8992
BackendAction BEAction = getBackendActionFromOutputType(Action);
9093
emitBackendOutput(

clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
#include "clang/CIR/LowerToLLVM.h"
1414

1515
#include "mlir/IR/BuiltinOps.h"
16-
#include "mlir/Pass/Pass.h"
17-
#include "mlir/Pass/PassManager.h"
1816
#include "llvm/IR/Module.h"
1917
#include "llvm/Support/TimeProfiler.h"
2018

0 commit comments

Comments
 (0)