Skip to content

Commit dc69628

Browse files
committed
Make CIRGenerator::mlirContext a shared pointer
1 parent a9ea2d8 commit dc69628

File tree

5 files changed

+10
-10
lines changed

5 files changed

+10
-10
lines changed

clang/include/clang/CIR/CIRGenerator.h

Lines changed: 3 additions & 3 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::unique_ptr<mlir::MLIRContext> mlirContext;
47+
std::shared_ptr<mlir::MLIRContext> mlirContext;
4848
std::unique_ptr<clang::CIRGen::CIRGenModule> cgm;
4949

5050
public:
@@ -55,8 +55,8 @@ 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::unique_ptr<mlir::MLIRContext> takeContext() {
59-
return std::move(mlirContext);
58+
std::shared_ptr<mlir::MLIRContext> getContext() {
59+
return mlirContext;
6060
};
6161
};
6262

clang/include/clang/CIR/LowerToLLVM.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@ lowerDirectlyFromCIRToLLVMIR(mlir::ModuleOp M, llvm::LLVMContext &Ctx);
3333
} // namespace direct
3434
} // namespace cir
3535

36-
#endif // CLANG_CIR_LOWERTOLLVM_H
36+
#endif // CLANG_CIR_LOWERTOLLVM_H

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_unique<mlir::MLIRContext>();
37+
mlirContext = std::make_shared<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: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ getBackendActionFromOutputType(CIRGenAction::OutputType Action) {
3232

3333
static std::unique_ptr<llvm::Module> lowerFromCIRToLLVMIR(
3434
const clang::FrontendOptions &FEOpts, mlir::ModuleOp MLIRModule,
35-
std::unique_ptr<mlir::MLIRContext> MLIRCtx, llvm::LLVMContext &LLVMCtx) {
35+
std::shared_ptr<mlir::MLIRContext> MLIRCtx, llvm::LLVMContext &LLVMCtx) {
3636
return direct::lowerDirectlyFromCIRToLLVMIR(MLIRModule, LLVMCtx);
3737
}
3838

@@ -72,7 +72,7 @@ class CIRGenConsumer : public clang::ASTConsumer {
7272
void HandleTranslationUnit(ASTContext &C) override {
7373
Gen->HandleTranslationUnit(C);
7474
mlir::ModuleOp MlirModule = Gen->getModule();
75-
auto MLIRCtx = Gen->takeContext();
75+
std::shared_ptr<mlir::MLIRContext> MLIRCtx = Gen->getContext();
7676
switch (Action) {
7777
case CIRGenAction::OutputType::EmitCIR:
7878
if (OutputStream && MlirModule) {
@@ -84,7 +84,7 @@ class CIRGenConsumer : public clang::ASTConsumer {
8484
case CIRGenAction::OutputType::EmitLLVM: {
8585
llvm::LLVMContext LLVMCtx;
8686
auto LLVMModule = lowerFromCIRToLLVMIR(CI.getFrontendOpts(), MlirModule,
87-
std::move(MLIRCtx), LLVMCtx);
87+
MLIRCtx, LLVMCtx);
8888

8989
BackendAction BEAction = getBackendActionFromOutputType(Action);
9090
emitBackendOutput(
@@ -135,4 +135,4 @@ EmitCIRAction::EmitCIRAction(mlir::MLIRContext *MLIRCtx)
135135

136136
void EmitLLVMAction::anchor() {}
137137
EmitLLVMAction::EmitLLVMAction(mlir::MLIRContext *MLIRCtx)
138-
: CIRGenAction(OutputType::EmitLLVM, MLIRCtx) {}
138+
: CIRGenAction(OutputType::EmitLLVM, MLIRCtx) {}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
add_subdirectory(DirectToLLVM)
1+
add_subdirectory(DirectToLLVM)

0 commit comments

Comments
 (0)