https://github.com/dkolsen-pgi created 
https://github.com/llvm/llvm-project/pull/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.

>From 6d5ba7cd0c500ac0387cffc12a7ed750ddf52225 Mon Sep 17 00:00:00 2001
From: David Olsen <dol...@nvidia.com>
Date: Tue, 10 Dec 2024 12:18:55 -0800
Subject: [PATCH] [CIR] Cleanup: mlirContext and astContext

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.
---
 clang/include/clang/CIR/CIRGenerator.h |  6 +++---
 clang/lib/CIR/CodeGen/CIRGenModule.cpp | 13 +++++++------
 clang/lib/CIR/CodeGen/CIRGenModule.h   |  6 +++---
 clang/lib/CIR/CodeGen/CIRGenTypes.cpp  | 14 ++++++++------
 clang/lib/CIR/CodeGen/CIRGenTypes.h    |  2 +-
 clang/lib/CIR/CodeGen/CIRGenerator.cpp | 12 ++++++------
 6 files changed, 28 insertions(+), 25 deletions(-)

diff --git a/clang/include/clang/CIR/CIRGenerator.h 
b/clang/include/clang/CIR/CIRGenerator.h
index c8ca7e4bfa7285..414eba80b88b8f 100644
--- a/clang/include/clang/CIR/CIRGenerator.h
+++ b/clang/include/clang/CIR/CIRGenerator.h
@@ -37,14 +37,14 @@ namespace cir {
 class CIRGenerator : public clang::ASTConsumer {
   virtual void anchor();
   clang::DiagnosticsEngine &diags;
-  clang::ASTContext *astCtx;
+  clang::ASTContext *astContext;
   // Only used for debug info.
   llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> fs;
 
   const clang::CodeGenOptions &codeGenOpts;
 
 protected:
-  std::unique_ptr<mlir::MLIRContext> mlirCtx;
+  std::unique_ptr<mlir::MLIRContext> mlirContext;
   std::unique_ptr<clang::CIRGen::CIRGenModule> cgm;
 
 public:
@@ -52,7 +52,7 @@ class CIRGenerator : public clang::ASTConsumer {
                llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> fs,
                const clang::CodeGenOptions &cgo);
   ~CIRGenerator() override;
-  void Initialize(clang::ASTContext &astCtx) override;
+  void Initialize(clang::ASTContext &astContext) override;
   bool HandleTopLevelDecl(clang::DeclGroupRef group) override;
   mlir::ModuleOp getModule() const;
 };
diff --git a/clang/lib/CIR/CodeGen/CIRGenModule.cpp 
b/clang/lib/CIR/CodeGen/CIRGenModule.cpp
index e7c9512dcd3de8..0db24c3b41d18d 100644
--- a/clang/lib/CIR/CodeGen/CIRGenModule.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenModule.cpp
@@ -25,13 +25,14 @@
 using namespace clang;
 using namespace clang::CIRGen;
 
-CIRGenModule::CIRGenModule(mlir::MLIRContext &context,
-                           clang::ASTContext &astctx,
+CIRGenModule::CIRGenModule(mlir::MLIRContext &mlirContext,
+                           clang::ASTContext &astContext,
                            const clang::CodeGenOptions &cgo,
                            DiagnosticsEngine &diags)
-    : builder(context, *this), astCtx(astctx), langOpts(astctx.getLangOpts()),
-      theModule{mlir::ModuleOp::create(mlir::UnknownLoc::get(&context))},
-      diags(diags), target(astctx.getTargetInfo()), genTypes(*this) {
+    : builder(mlirContext, *this), astContext(astContext),
+      langOpts(astContext.getLangOpts()),
+      theModule{mlir::ModuleOp::create(mlir::UnknownLoc::get(&mlirContext))},
+      diags(diags), target(astContext.getTargetInfo()), genTypes(*this) {
 
   // Initialize cached types
   SInt8Ty = cir::IntType::get(&getMLIRContext(), 8, /*isSigned=*/true);
@@ -48,7 +49,7 @@ CIRGenModule::CIRGenModule(mlir::MLIRContext &context,
 
 mlir::Location CIRGenModule::getLoc(SourceLocation cLoc) {
   assert(cLoc.isValid() && "expected valid source location");
-  const SourceManager &sm = astCtx.getSourceManager();
+  const SourceManager &sm = astContext.getSourceManager();
   PresumedLoc pLoc = sm.getPresumedLoc(cLoc);
   StringRef filename = pLoc.getFilename();
   return mlir::FileLineColLoc::get(builder.getStringAttr(filename),
diff --git a/clang/lib/CIR/CodeGen/CIRGenModule.h 
b/clang/lib/CIR/CodeGen/CIRGenModule.h
index 397e501fd4e873..1c7ed63773900a 100644
--- a/clang/lib/CIR/CodeGen/CIRGenModule.h
+++ b/clang/lib/CIR/CodeGen/CIRGenModule.h
@@ -41,7 +41,7 @@ class CIRGenModule : public CIRGenTypeCache {
   CIRGenModule &operator=(CIRGenModule &) = delete;
 
 public:
-  CIRGenModule(mlir::MLIRContext &context, clang::ASTContext &astctx,
+  CIRGenModule(mlir::MLIRContext &mlirContext, clang::ASTContext &astContext,
                const clang::CodeGenOptions &cgo,
                clang::DiagnosticsEngine &diags);
 
@@ -51,7 +51,7 @@ class CIRGenModule : public CIRGenTypeCache {
   CIRGenBuilderTy builder;
 
   /// Hold Clang AST information.
-  clang::ASTContext &astCtx;
+  clang::ASTContext &astContext;
 
   const clang::LangOptions &langOpts;
 
@@ -67,7 +67,7 @@ class CIRGenModule : public CIRGenTypeCache {
 public:
   mlir::ModuleOp getModule() const { return theModule; }
   CIRGenBuilderTy &getBuilder() { return builder; }
-  clang::ASTContext &getASTContext() const { return astCtx; }
+  clang::ASTContext &getASTContext() const { return astContext; }
   CIRGenTypes &getTypes() { return genTypes; }
   mlir::MLIRContext &getMLIRContext() { return *builder.getContext(); }
 
diff --git a/clang/lib/CIR/CodeGen/CIRGenTypes.cpp 
b/clang/lib/CIR/CodeGen/CIRGenTypes.cpp
index e93bf93b1cb7d3..181af1898baff2 100644
--- a/clang/lib/CIR/CodeGen/CIRGenTypes.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenTypes.cpp
@@ -9,7 +9,7 @@ using namespace clang;
 using namespace clang::CIRGen;
 
 CIRGenTypes::CIRGenTypes(CIRGenModule &genModule)
-    : cgm(genModule), context(genModule.getASTContext()),
+    : cgm(genModule), astContext(genModule.getASTContext()),
       builder(cgm.getBuilder()) {}
 
 CIRGenTypes::~CIRGenTypes() {}
@@ -19,7 +19,7 @@ mlir::MLIRContext &CIRGenTypes::getMLIRContext() const {
 }
 
 mlir::Type CIRGenTypes::convertType(QualType type) {
-  type = context.getCanonicalType(type);
+  type = astContext.getCanonicalType(type);
   const Type *ty = type.getTypePtr();
 
   // Has the type already been processed?
@@ -43,8 +43,9 @@ mlir::Type CIRGenTypes::convertType(QualType type) {
     case BuiltinType::SChar:
     case BuiltinType::Short:
     case BuiltinType::WChar_S:
-      resultType = cir::IntType::get(&getMLIRContext(), 
context.getTypeSize(ty),
-                                     /*isSigned=*/true);
+      resultType =
+          cir::IntType::get(&getMLIRContext(), astContext.getTypeSize(ty),
+                            /*isSigned=*/true);
       break;
     // Unsigned integral types.
     case BuiltinType::Char8:
@@ -58,8 +59,9 @@ mlir::Type CIRGenTypes::convertType(QualType type) {
     case BuiltinType::ULongLong:
     case BuiltinType::UShort:
     case BuiltinType::WChar_U:
-      resultType = cir::IntType::get(&getMLIRContext(), 
context.getTypeSize(ty),
-                                     /*isSigned=*/false);
+      resultType =
+          cir::IntType::get(&getMLIRContext(), astContext.getTypeSize(ty),
+                            /*isSigned=*/false);
       break;
     default:
       cgm.errorNYI(SourceLocation(), "processing of built-in type", type);
diff --git a/clang/lib/CIR/CodeGen/CIRGenTypes.h 
b/clang/lib/CIR/CodeGen/CIRGenTypes.h
index b5039b6d4a81db..563d7759831fa5 100644
--- a/clang/lib/CIR/CodeGen/CIRGenTypes.h
+++ b/clang/lib/CIR/CodeGen/CIRGenTypes.h
@@ -36,7 +36,7 @@ class CIRGenModule;
 /// AST types to CIR types.
 class CIRGenTypes {
   CIRGenModule &cgm;
-  clang::ASTContext &context;
+  clang::ASTContext &astContext;
   CIRGenBuilderTy &builder;
 
 public:
diff --git a/clang/lib/CIR/CodeGen/CIRGenerator.cpp 
b/clang/lib/CIR/CodeGen/CIRGenerator.cpp
index 8f3370c0041afe..91070eda7d45ad 100644
--- a/clang/lib/CIR/CodeGen/CIRGenerator.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenerator.cpp
@@ -29,15 +29,15 @@ CIRGenerator::CIRGenerator(clang::DiagnosticsEngine &diags,
     : diags(diags), fs(std::move(vfs)), codeGenOpts{cgo} {}
 CIRGenerator::~CIRGenerator() = default;
 
-void CIRGenerator::Initialize(ASTContext &astCtx) {
+void CIRGenerator::Initialize(ASTContext &astContext) {
   using namespace llvm;
 
-  this->astCtx = &astCtx;
+  this->astContext = &astContext;
 
-  mlirCtx = std::make_unique<mlir::MLIRContext>();
-  mlirCtx->loadDialect<cir::CIRDialect>();
-  cgm = std::make_unique<clang::CIRGen::CIRGenModule>(*mlirCtx.get(), astCtx,
-                                                      codeGenOpts, diags);
+  mlirContext = std::make_unique<mlir::MLIRContext>();
+  mlirContext->loadDialect<cir::CIRDialect>();
+  cgm = std::make_unique<clang::CIRGen::CIRGenModule>(
+      *mlirContext.get(), astContext, codeGenOpts, diags);
 }
 
 mlir::ModuleOp CIRGenerator::getModule() const { return cgm->getModule(); }

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to