Skip to content

Commit 7eb73b9

Browse files
authoredDec 10, 2024
[CIR] Cleanup: mlirContext and astContext (#119450)
ClangIR CodeGen code uses both `mlir::MLIRContext` and `clang::ASTContext` objects extensively. Refering to either of those as just "context" can be confusing. Change the names of all variables, parameters, and fields in `clang/lib/CIR/CodeGen` that refer to `MLIRContext` or an `ASTContext` to be either `mlirContext` or `astContext`. This change is only the renaming of variables/parameters/fields. There are no behavior changes. So there are no new tests or changes to existing tests. This change mimics a recent change in the ClangIR incubator repository.
1 parent 4dac0df commit 7eb73b9

File tree

6 files changed

+28
-25
lines changed

6 files changed

+28
-25
lines changed
 

‎clang/include/clang/CIR/CIRGenerator.h

+3-3
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 *astCtx;
40+
clang::ASTContext *astContext;
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> mlirCtx;
47+
std::unique_ptr<mlir::MLIRContext> mlirContext;
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 &astCtx) override;
55+
void Initialize(clang::ASTContext &astContext) override;
5656
bool HandleTopLevelDecl(clang::DeclGroupRef group) override;
5757
mlir::ModuleOp getModule() const;
5858
};

‎clang/lib/CIR/CodeGen/CIRGenModule.cpp

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

28-
CIRGenModule::CIRGenModule(mlir::MLIRContext &context,
29-
clang::ASTContext &astctx,
28+
CIRGenModule::CIRGenModule(mlir::MLIRContext &mlirContext,
29+
clang::ASTContext &astContext,
3030
const clang::CodeGenOptions &cgo,
3131
DiagnosticsEngine &diags)
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) {
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) {
3536

3637
// Initialize cached types
3738
SInt8Ty = cir::IntType::get(&getMLIRContext(), 8, /*isSigned=*/true);
@@ -48,7 +49,7 @@ CIRGenModule::CIRGenModule(mlir::MLIRContext &context,
4849

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

‎clang/lib/CIR/CodeGen/CIRGenModule.h

+3-3
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 &context, clang::ASTContext &astctx,
44+
CIRGenModule(mlir::MLIRContext &mlirContext, clang::ASTContext &astContext,
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 &astCtx;
54+
clang::ASTContext &astContext;
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 astCtx; }
70+
clang::ASTContext &getASTContext() const { return astContext; }
7171
CIRGenTypes &getTypes() { return genTypes; }
7272
mlir::MLIRContext &getMLIRContext() { return *builder.getContext(); }
7373

‎clang/lib/CIR/CodeGen/CIRGenTypes.cpp

+8-6
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), context(genModule.getASTContext()),
12+
: cgm(genModule), astContext(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 = context.getCanonicalType(type);
22+
type = astContext.getCanonicalType(type);
2323
const Type *ty = type.getTypePtr();
2424

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

‎clang/lib/CIR/CodeGen/CIRGenTypes.h

+1-1
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 &context;
39+
clang::ASTContext &astContext;
4040
CIRGenBuilderTy &builder;
4141

4242
public:

‎clang/lib/CIR/CodeGen/CIRGenerator.cpp

+6-6
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 &astCtx) {
32+
void CIRGenerator::Initialize(ASTContext &astContext) {
3333
using namespace llvm;
3434

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

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);
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);
4141
}
4242

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

0 commit comments

Comments
 (0)
Please sign in to comment.