Skip to content

Commit ab347cb

Browse files
smeenailanza
authored andcommittedMar 17, 2025
[CIR] Merge the mlir::cir namespace into cir (#1084)
#1025 explains why we want to move the CIR dialect from the `mlir::cir` to the `cir` namespace. This is a large PR, and I've split it out into four commits (that'll be squashed when landing). The first commit changes `mlir::cir` to `cir` everywhere. This was originally done mechanically with: ``` find clang \( -name '*.h' -o -name '*.cpp' -o -name '*.td' \) -print0 | xargs -0 perl -pi -e 's/mlir::cir/cir/g' find clang \( -name '*.h' -o -name '*.cpp' \) -print0 | xargs -0 perl -pi -e 's/::cir/cir/g' find clang \( -name '*.h' -o -name '*.cpp' \) -print0 | xargs -0 perl -0777 -pi -e 's/namespace mlir \{\nnamespace cir \{/namespace cir {/g' find clang \( -name '*.h' -o -name '*.cpp' \) -print0 | xargs -0 perl -0777 -pi -e 's!\} // namespace cir\n\} // namespace mlir!} // namespace cir!g' ``` It then required some manual fixups to address edge cases. Code that lived under `mlir::cir` could refer to the `mlir` namespace without qualification, but after the namespace change, we need to explicitly qualify all our usages. This is done in the second commit via https://gist.github.com/smeenai/996200fd45ad123bbf22b412d59479b6, which is an idempotent script to add all qualifications. I added cases to the script one at a time and reviewed each change afterwards to ensure we were only making the intended modifications, so I feel pretty confident in the end result. I also removed `using namespace llvm` from some headers to avoid conflicts, which in turn required adding some `llvm::` qualifiers as well. The third commit fixes a test, since an error message now contains the mlir namespace. Similar tests in flang also have the namespace in their error messages, so this is an expected change. The fourth change runs `git clang-format`. Unfortunately, that doesn't work for TableGen files, so we'll have a few instances of undesirable formatting left there. I'll look into fixing that as a follow-up. I validated the end result by examining the symbols in the built Clang binary. There's nothing in the `mlir::cir` namespace anymore. https://gist.github.com/smeenai/8438fd01588109fcdbde5c8652781dc0 had the symbols which lived in `cir` and should have moved to `clang::CIRGen`, and I validated that all the symbols were moved, with the exceptions noted in #1082 and the duplicated symbols noted in #1025.
1 parent be58977 commit ab347cb

File tree

148 files changed

+5220
-5647
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

148 files changed

+5220
-5647
lines changed
 

‎clang/include/clang/CIR/ABIArgInfo.h

+3-5
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,7 @@ class ABIArgInfo {
167167
}
168168
static ABIArgInfo getZeroExtend(mlir::Type Ty, mlir::Type T = nullptr) {
169169
// NOTE(cir): Enumerations are IntTypes in CIR.
170-
assert(mlir::isa<mlir::cir::IntType>(Ty) ||
171-
mlir::isa<mlir::cir::BoolType>(Ty));
170+
assert(mlir::isa<cir::IntType>(Ty) || mlir::isa<cir::BoolType>(Ty));
172171
auto AI = ABIArgInfo(Extend);
173172
AI.setCoerceToType(T);
174173
AI.setPaddingType(nullptr);
@@ -190,9 +189,8 @@ class ABIArgInfo {
190189
// NOTE(cir): The original can apply this method on both integers and
191190
// enumerations, but in CIR, these two types are one and the same. Booleans
192191
// will also fall into this category, but they have their own type.
193-
if (mlir::isa<mlir::cir::IntType>(Ty) &&
194-
mlir::cast<mlir::cir::IntType>(Ty).isSigned())
195-
return getSignExtend(mlir::cast<mlir::cir::IntType>(Ty), T);
192+
if (mlir::isa<cir::IntType>(Ty) && mlir::cast<cir::IntType>(Ty).isSigned())
193+
return getSignExtend(mlir::cast<cir::IntType>(Ty), T);
196194
return getZeroExtend(Ty, T);
197195
}
198196

‎clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h

+221-251
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)
Please sign in to comment.