Skip to content

Commit 4195345

Browse files
committed
Revert "[CIR] Cleanup: mlirContext and astContext (llvm#119450)"
This reverts commit 7eb73b9.
1 parent 9fb8849 commit 4195345

File tree

6 files changed

+25
-28
lines changed

6 files changed

+25
-28
lines changed

clang/include/clang/CIR/CIRGenerator.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,22 @@ namespace cir {
3737
class CIRGenerator : public clang::ASTConsumer {
3838
virtual void anchor();
3939
clang::DiagnosticsEngine &diags;
40-
clang::ASTContext *astContext;
40+
clang::ASTContext *astCtx;
4141
// Only used for debug info.
4242
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> fs;
4343

4444
const clang::CodeGenOptions &codeGenOpts;
4545

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

5050
public:
5151
CIRGenerator(clang::DiagnosticsEngine &diags,
5252
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> fs,
5353
const clang::CodeGenOptions &cgo);
5454
~CIRGenerator() override;
55-
void Initialize(clang::ASTContext &astContext) override;
55+
void Initialize(clang::ASTContext &astCtx) override;
5656
bool HandleTopLevelDecl(clang::DeclGroupRef group) override;
5757
mlir::ModuleOp getModule() const;
5858
};

clang/lib/CIR/CodeGen/CIRGenModule.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,13 @@
2525
using namespace clang;
2626
using namespace clang::CIRGen;
2727

28-
CIRGenModule::CIRGenModule(mlir::MLIRContext &mlirContext,
29-
clang::ASTContext &astContext,
28+
CIRGenModule::CIRGenModule(mlir::MLIRContext &context,
29+
clang::ASTContext &astctx,
3030
const clang::CodeGenOptions &cgo,
3131
DiagnosticsEngine &diags)
32-
: builder(mlirContext, *this), astContext(astContext),
33-
langOpts(astContext.getLangOpts()),
34-
theModule{mlir::ModuleOp::create(mlir::UnknownLoc::get(&mlirContext))},
35-
diags(diags), target(astContext.getTargetInfo()), genTypes(*this) {
32+
: builder(context, *this), astCtx(astctx), langOpts(astctx.getLangOpts()),
33+
theModule{mlir::ModuleOp::create(mlir::UnknownLoc::get(&context))},
34+
diags(diags), target(astctx.getTargetInfo()), genTypes(*this) {
3635

3736
// Initialize cached types
3837
SInt8Ty = cir::IntType::get(&getMLIRContext(), 8, /*isSigned=*/true);
@@ -49,7 +48,7 @@ CIRGenModule::CIRGenModule(mlir::MLIRContext &mlirContext,
4948

5049
mlir::Location CIRGenModule::getLoc(SourceLocation cLoc) {
5150
assert(cLoc.isValid() && "expected valid source location");
52-
const SourceManager &sm = astContext.getSourceManager();
51+
const SourceManager &sm = astCtx.getSourceManager();
5352
PresumedLoc pLoc = sm.getPresumedLoc(cLoc);
5453
StringRef filename = pLoc.getFilename();
5554
return mlir::FileLineColLoc::get(builder.getStringAttr(filename),

clang/lib/CIR/CodeGen/CIRGenModule.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class CIRGenModule : public CIRGenTypeCache {
4141
CIRGenModule &operator=(CIRGenModule &) = delete;
4242

4343
public:
44-
CIRGenModule(mlir::MLIRContext &mlirContext, clang::ASTContext &astContext,
44+
CIRGenModule(mlir::MLIRContext &context, clang::ASTContext &astctx,
4545
const clang::CodeGenOptions &cgo,
4646
clang::DiagnosticsEngine &diags);
4747

@@ -51,7 +51,7 @@ class CIRGenModule : public CIRGenTypeCache {
5151
CIRGenBuilderTy builder;
5252

5353
/// Hold Clang AST information.
54-
clang::ASTContext &astContext;
54+
clang::ASTContext &astCtx;
5555

5656
const clang::LangOptions &langOpts;
5757

@@ -67,7 +67,7 @@ class CIRGenModule : public CIRGenTypeCache {
6767
public:
6868
mlir::ModuleOp getModule() const { return theModule; }
6969
CIRGenBuilderTy &getBuilder() { return builder; }
70-
clang::ASTContext &getASTContext() const { return astContext; }
70+
clang::ASTContext &getASTContext() const { return astCtx; }
7171
CIRGenTypes &getTypes() { return genTypes; }
7272
mlir::MLIRContext &getMLIRContext() { return *builder.getContext(); }
7373

clang/lib/CIR/CodeGen/CIRGenTypes.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ using namespace clang;
99
using namespace clang::CIRGen;
1010

1111
CIRGenTypes::CIRGenTypes(CIRGenModule &genModule)
12-
: cgm(genModule), astContext(genModule.getASTContext()),
12+
: cgm(genModule), context(genModule.getASTContext()),
1313
builder(cgm.getBuilder()) {}
1414

1515
CIRGenTypes::~CIRGenTypes() {}
@@ -19,7 +19,7 @@ mlir::MLIRContext &CIRGenTypes::getMLIRContext() const {
1919
}
2020

2121
mlir::Type CIRGenTypes::convertType(QualType type) {
22-
type = astContext.getCanonicalType(type);
22+
type = context.getCanonicalType(type);
2323
const Type *ty = type.getTypePtr();
2424

2525
// Has the type already been processed?
@@ -43,9 +43,8 @@ mlir::Type CIRGenTypes::convertType(QualType type) {
4343
case BuiltinType::SChar:
4444
case BuiltinType::Short:
4545
case BuiltinType::WChar_S:
46-
resultType =
47-
cir::IntType::get(&getMLIRContext(), astContext.getTypeSize(ty),
48-
/*isSigned=*/true);
46+
resultType = cir::IntType::get(&getMLIRContext(), context.getTypeSize(ty),
47+
/*isSigned=*/true);
4948
break;
5049
// Unsigned integral types.
5150
case BuiltinType::Char8:
@@ -59,9 +58,8 @@ mlir::Type CIRGenTypes::convertType(QualType type) {
5958
case BuiltinType::ULongLong:
6059
case BuiltinType::UShort:
6160
case BuiltinType::WChar_U:
62-
resultType =
63-
cir::IntType::get(&getMLIRContext(), astContext.getTypeSize(ty),
64-
/*isSigned=*/false);
61+
resultType = cir::IntType::get(&getMLIRContext(), context.getTypeSize(ty),
62+
/*isSigned=*/false);
6563
break;
6664
default:
6765
cgm.errorNYI(SourceLocation(), "processing of built-in type", type);

clang/lib/CIR/CodeGen/CIRGenTypes.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class CIRGenModule;
3636
/// AST types to CIR types.
3737
class CIRGenTypes {
3838
CIRGenModule &cgm;
39-
clang::ASTContext &astContext;
39+
clang::ASTContext &context;
4040
CIRGenBuilderTy &builder;
4141

4242
public:

clang/lib/CIR/CodeGen/CIRGenerator.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@ CIRGenerator::CIRGenerator(clang::DiagnosticsEngine &diags,
2929
: diags(diags), fs(std::move(vfs)), codeGenOpts{cgo} {}
3030
CIRGenerator::~CIRGenerator() = default;
3131

32-
void CIRGenerator::Initialize(ASTContext &astContext) {
32+
void CIRGenerator::Initialize(ASTContext &astCtx) {
3333
using namespace llvm;
3434

35-
this->astContext = &astContext;
35+
this->astCtx = &astCtx;
3636

37-
mlirContext = std::make_unique<mlir::MLIRContext>();
38-
mlirContext->loadDialect<cir::CIRDialect>();
39-
cgm = std::make_unique<clang::CIRGen::CIRGenModule>(
40-
*mlirContext.get(), astContext, codeGenOpts, diags);
37+
mlirCtx = std::make_unique<mlir::MLIRContext>();
38+
mlirCtx->loadDialect<cir::CIRDialect>();
39+
cgm = std::make_unique<clang::CIRGen::CIRGenModule>(*mlirCtx.get(), astCtx,
40+
codeGenOpts, diags);
4141
}
4242

4343
mlir::ModuleOp CIRGenerator::getModule() const { return cgm->getModule(); }

0 commit comments

Comments
 (0)