Skip to content

[clang][CIR] Move CIRGen types into clang::CIRGen #115385

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 8, 2024
Merged

Conversation

smeenai
Copy link
Collaborator

@smeenai smeenai commented Nov 7, 2024

llvm/clangir#1025 explains why we want to move
the CIR dialect from the mlir::cir to the cir namespace. To avoid
overloading the cir namespace too much afterwards, move all symbols
whose equivalents live inside the clang::CodeGen namespace to a new
clang::CIRGen namespace, so that we match the original CodeGen's
structure more closely.

[ghstack-poisoned]
@smeenai
Copy link
Collaborator Author

smeenai commented Nov 7, 2024

@llvmbot llvmbot added clang Clang issues not falling into any other category ClangIR Anything related to the ClangIR project labels Nov 7, 2024
@llvmbot
Copy link
Member

llvmbot commented Nov 7, 2024

@llvm/pr-subscribers-clangir

@llvm/pr-subscribers-clang

Author: Shoaib Meenai (smeenai)

Changes

llvm/clangir#1025 explains why we want to move
the CIR dialect from the mlir::cir to the cir namespace. To avoid
overloading the cir namespace too much afterwards, move all symbols
whose equivalents live inside the clang::CodeGen namespace to a new
clang::CIRGen namespace, so that we match the original CodeGen's
structure more closely.


Full diff: https://github.com/llvm/llvm-project/pull/115385.diff

5 Files Affected:

  • (modified) clang/include/clang/CIR/CIRGenerator.h (+4-3)
  • (modified) clang/lib/CIR/CodeGen/CIRGenModule.cpp (+3-1)
  • (modified) clang/lib/CIR/CodeGen/CIRGenModule.h (+4-4)
  • (modified) clang/lib/CIR/CodeGen/CIRGenTypeCache.h (+2-2)
  • (modified) clang/lib/CIR/CodeGen/CIRGenerator.cpp (+2-2)
diff --git a/clang/include/clang/CIR/CIRGenerator.h b/clang/include/clang/CIR/CIRGenerator.h
index aa1a7e64459b356..c8ca7e4bfa7285f 100644
--- a/clang/include/clang/CIR/CIRGenerator.h
+++ b/clang/include/clang/CIR/CIRGenerator.h
@@ -25,14 +25,15 @@
 namespace clang {
 class DeclGroupRef;
 class DiagnosticsEngine;
+namespace CIRGen {
+class CIRGenModule;
+} // namespace CIRGen
 } // namespace clang
 
 namespace mlir {
 class MLIRContext;
 } // namespace mlir
 namespace cir {
-class CIRGenModule;
-
 class CIRGenerator : public clang::ASTConsumer {
   virtual void anchor();
   clang::DiagnosticsEngine &diags;
@@ -44,7 +45,7 @@ class CIRGenerator : public clang::ASTConsumer {
 
 protected:
   std::unique_ptr<mlir::MLIRContext> mlirCtx;
-  std::unique_ptr<CIRGenModule> cgm;
+  std::unique_ptr<clang::CIRGen::CIRGenModule> cgm;
 
 public:
   CIRGenerator(clang::DiagnosticsEngine &diags,
diff --git a/clang/lib/CIR/CodeGen/CIRGenModule.cpp b/clang/lib/CIR/CodeGen/CIRGenModule.cpp
index c1adc7ecbf74dd5..5a6fc27a130c8f1 100644
--- a/clang/lib/CIR/CodeGen/CIRGenModule.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenModule.cpp
@@ -22,7 +22,9 @@
 #include "mlir/IR/Location.h"
 #include "mlir/IR/MLIRContext.h"
 
-using namespace cir;
+using namespace clang;
+using namespace clang::CIRGen;
+
 CIRGenModule::CIRGenModule(mlir::MLIRContext &context,
                            clang::ASTContext &astctx,
                            const clang::CodeGenOptions &cgo,
diff --git a/clang/lib/CIR/CodeGen/CIRGenModule.h b/clang/lib/CIR/CodeGen/CIRGenModule.h
index 2bf6a5d9c8f5975..9e5950ff71c528c 100644
--- a/clang/lib/CIR/CodeGen/CIRGenModule.h
+++ b/clang/lib/CIR/CodeGen/CIRGenModule.h
@@ -31,10 +31,8 @@ class LangOptions;
 class SourceLocation;
 class SourceRange;
 class TargetInfo;
-} // namespace clang
 
-using namespace clang;
-namespace cir {
+namespace CIRGen {
 
 /// This class organizes the cross-function state that is used while generating
 /// CIR code.
@@ -91,6 +89,8 @@ class CIRGenModule : public CIRGenTypeCache {
   DiagnosticBuilder errorNYI(SourceRange, llvm::StringRef);
   DiagnosticBuilder errorNYI(SourceRange, llvm::StringRef, llvm::StringRef);
 };
-} // namespace cir
+} // namespace CIRGen
+
+} // namespace clang
 
 #endif // LLVM_CLANG_LIB_CIR_CODEGEN_CIRGENMODULE_H
diff --git a/clang/lib/CIR/CodeGen/CIRGenTypeCache.h b/clang/lib/CIR/CodeGen/CIRGenTypeCache.h
index 6478e0a0780994a..fde9a355f524165 100644
--- a/clang/lib/CIR/CodeGen/CIRGenTypeCache.h
+++ b/clang/lib/CIR/CodeGen/CIRGenTypeCache.h
@@ -13,7 +13,7 @@
 #ifndef LLVM_CLANG_LIB_CIR_CIRGENTYPECACHE_H
 #define LLVM_CLANG_LIB_CIR_CIRGENTYPECACHE_H
 
-namespace cir {
+namespace clang::CIRGen {
 
 /// This structure provides a set of types that are commonly used
 /// during IR emission. It's initialized once in CodeGenModule's
@@ -22,6 +22,6 @@ struct CIRGenTypeCache {
   CIRGenTypeCache() = default;
 };
 
-} // namespace cir
+} // namespace clang::CIRGen
 
 #endif // LLVM_CLANG_LIB_CIR_CODEGEN_CIRGENTYPECACHE_H
diff --git a/clang/lib/CIR/CodeGen/CIRGenerator.cpp b/clang/lib/CIR/CodeGen/CIRGenerator.cpp
index 152124a00b2bbdc..825f78d32e76f04 100644
--- a/clang/lib/CIR/CodeGen/CIRGenerator.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenerator.cpp
@@ -36,8 +36,8 @@ void CIRGenerator::Initialize(ASTContext &astCtx) {
 
   mlirCtx = std::make_unique<mlir::MLIRContext>();
   mlirCtx->loadDialect<mlir::cir::CIRDialect>();
-  cgm = std::make_unique<CIRGenModule>(*mlirCtx.get(), astCtx, codeGenOpts,
-                                       diags);
+  cgm = std::make_unique<clang::CIRGen::CIRGenModule>(*mlirCtx.get(), astCtx,
+                                                      codeGenOpts, diags);
 }
 
 mlir::ModuleOp CIRGenerator::getModule() const { return cgm->getModule(); }

Copy link
Member

@bcardosolopes bcardosolopes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, pending Aaron's and others feedback.

jollaitbot pushed a commit to sailfishos-mirror/llvm-project that referenced this pull request Nov 8, 2024
llvm/clangir#1025 explains why we want to move
the CIR dialect from the `mlir::cir` to the `cir` namespace. To avoid
overloading the `cir` namespace too much afterwards, move all symbols
whose equivalents live inside the `clang::CodeGen` namespace to a new
`clang::CIRGen` namespace, so that we match the original CodeGen's
structure more closely.

ghstack-source-id: 62666dc
ghstack-comment-id: 2463364244
Pull Request resolved: llvm/llvm-project#115385
Copy link
Collaborator

@AaronBallman AaronBallman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@smeenai smeenai merged commit 40e5450 into main Nov 8, 2024
11 checks passed
@smeenai smeenai deleted the users/smeenai/1/head branch November 8, 2024 18:41
Groverkss pushed a commit to iree-org/llvm-project that referenced this pull request Nov 15, 2024
llvm/clangir#1025 explains why we want to move
the CIR dialect from the `mlir::cir` to the `cir` namespace. To avoid
overloading the `cir` namespace too much afterwards, move all symbols
whose equivalents live inside the `clang::CodeGen` namespace to a new
`clang::CIRGen` namespace, so that we match the original CodeGen's
structure more closely.
bcardosolopes pushed a commit to bcardosolopes/llvm-project that referenced this pull request Mar 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang Clang issues not falling into any other category ClangIR Anything related to the ClangIR project
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants