Skip to content

Commit 0c77b27

Browse files
authored
[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 0634b25 commit 0c77b27

File tree

147 files changed

+5193
-5619
lines changed

Some content is hidden

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

147 files changed

+5193
-5619
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.

clang/include/clang/CIR/Dialect/IR/CIRAttrs.h

-2
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,11 @@ class VarDecl;
3535
class RecordDecl;
3636
} // namespace clang
3737

38-
namespace mlir {
3938
namespace cir {
4039
class ArrayType;
4140
class StructType;
4241
class BoolType;
4342
} // namespace cir
44-
} // namespace mlir
4543

4644
#define GET_ATTRDEF_CLASSES
4745
#include "clang/CIR/Dialect/IR/CIROpsAttributes.h.inc"

clang/include/clang/CIR/Dialect/IR/CIRAttrs.td

+67-67
Large diffs are not rendered by default.

clang/include/clang/CIR/Dialect/IR/CIRDataLayout.h

+6-6
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class CIRDataLayout {
5353
/// struct, its size, and the offsets of its fields.
5454
///
5555
/// Note that this information is lazily cached.
56-
const StructLayout *getStructLayout(mlir::cir::StructType Ty) const;
56+
const StructLayout *getStructLayout(cir::StructType Ty) const;
5757

5858
/// Internal helper method that returns requested alignment for type.
5959
llvm::Align getAlignment(mlir::Type Ty, bool abiOrPref) const;
@@ -93,17 +93,17 @@ class CIRDataLayout {
9393
}
9494

9595
llvm::TypeSize getPointerTypeSizeInBits(mlir::Type Ty) const {
96-
assert(mlir::isa<mlir::cir::PointerType>(Ty) &&
96+
assert(mlir::isa<cir::PointerType>(Ty) &&
9797
"This should only be called with a pointer type");
9898
return layout.getTypeSizeInBits(Ty);
9999
}
100100

101101
llvm::TypeSize getTypeSizeInBits(mlir::Type Ty) const;
102102

103103
mlir::Type getIntPtrType(mlir::Type Ty) const {
104-
assert(mlir::isa<mlir::cir::PointerType>(Ty) && "Expected pointer type");
105-
auto IntTy = mlir::cir::IntType::get(Ty.getContext(),
106-
getPointerTypeSizeInBits(Ty), false);
104+
assert(mlir::isa<cir::PointerType>(Ty) && "Expected pointer type");
105+
auto IntTy =
106+
cir::IntType::get(Ty.getContext(), getPointerTypeSizeInBits(Ty), false);
107107
return IntTy;
108108
}
109109
};
@@ -153,7 +153,7 @@ class StructLayout final
153153
private:
154154
friend class CIRDataLayout; // Only DataLayout can create this class
155155

156-
StructLayout(mlir::cir::StructType ST, const CIRDataLayout &DL);
156+
StructLayout(cir::StructType ST, const CIRDataLayout &DL);
157157

158158
size_t numTrailingObjects(OverloadToken<llvm::TypeSize>) const {
159159
return NumElements;

clang/include/clang/CIR/Dialect/IR/CIRDialect.h

+6-6
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ template <typename ConcreteType>
5555
class SameFirstOperandAndResultType
5656
: public TraitBase<ConcreteType, SameFirstOperandAndResultType> {
5757
public:
58-
static LogicalResult verifyTrait(Operation *op) {
58+
static llvm::LogicalResult verifyTrait(Operation *op) {
5959
return impl::verifySameFirstOperandAndResultType(op);
6060
}
6161
};
@@ -67,7 +67,7 @@ template <typename ConcreteType>
6767
class SameSecondOperandAndResultType
6868
: public TraitBase<ConcreteType, SameSecondOperandAndResultType> {
6969
public:
70-
static LogicalResult verifyTrait(Operation *op) {
70+
static llvm::LogicalResult verifyTrait(Operation *op) {
7171
return impl::verifySameSecondOperandAndResultType(op);
7272
}
7373
};
@@ -79,19 +79,19 @@ template <typename ConcreteType>
7979
class SameFirstSecondOperandAndResultType
8080
: public TraitBase<ConcreteType, SameFirstSecondOperandAndResultType> {
8181
public:
82-
static LogicalResult verifyTrait(Operation *op) {
82+
static llvm::LogicalResult verifyTrait(Operation *op) {
8383
return impl::verifySameFirstSecondOperandAndResultType(op);
8484
}
8585
};
8686

8787
} // namespace OpTrait
8888

89+
} // namespace mlir
90+
8991
namespace cir {
90-
void buildTerminatedBody(OpBuilder &builder, Location loc);
92+
void buildTerminatedBody(mlir::OpBuilder &builder, mlir::Location loc);
9193
} // namespace cir
9294

93-
} // namespace mlir
94-
9595
#define GET_OP_CLASSES
9696
#include "clang/CIR/Dialect/IR/CIROps.h.inc"
9797

clang/include/clang/CIR/Dialect/IR/CIRDialect.td

+8-8
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def CIR_Dialect : Dialect {
2222
let summary = "A high-level dialect for analyzing and optimizing Clang "
2323
"supported languages";
2424

25-
let cppNamespace = "::mlir::cir";
25+
let cppNamespace = "::cir";
2626

2727
let useDefaultAttributePrinterParser = 0;
2828
let useDefaultTypePrinterParser = 0;
@@ -32,19 +32,19 @@ def CIR_Dialect : Dialect {
3232
let extraClassDeclaration = [{
3333

3434
// Names of CIR parameter attributes.
35-
static StringRef getSExtAttrName() { return "cir.signext"; }
36-
static StringRef getZExtAttrName() { return "cir.zeroext"; }
35+
static llvm::StringRef getSExtAttrName() { return "cir.signext"; }
36+
static llvm::StringRef getZExtAttrName() { return "cir.zeroext"; }
3737

3838
void registerAttributes();
3939
void registerTypes();
4040

41-
Type parseType(DialectAsmParser &parser) const override;
42-
void printType(Type type, DialectAsmPrinter &printer) const override;
41+
mlir::Type parseType(mlir::DialectAsmParser &parser) const override;
42+
void printType(mlir::Type type, mlir::DialectAsmPrinter &printer) const override;
4343

44-
Attribute parseAttribute(DialectAsmParser &parser,
45-
Type type) const override;
44+
mlir::Attribute parseAttribute(mlir::DialectAsmParser &parser,
45+
mlir::Type type) const override;
4646

47-
void printAttribute(Attribute attr, DialectAsmPrinter &os) const override;
47+
void printAttribute(mlir::Attribute attr, mlir::DialectAsmPrinter &os) const override;
4848
}];
4949
}
5050

clang/include/clang/CIR/Dialect/IR/CIROpenCLAttrs.td

+14-14
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@ def OpenCLKernelMetadataAttr
5757
}];
5858

5959
let parameters = (ins
60-
OptionalParameter<"ArrayAttr">:$work_group_size_hint,
61-
OptionalParameter<"ArrayAttr">:$reqd_work_group_size,
62-
OptionalParameter<"TypeAttr">:$vec_type_hint,
60+
OptionalParameter<"mlir::ArrayAttr">:$work_group_size_hint,
61+
OptionalParameter<"mlir::ArrayAttr">:$reqd_work_group_size,
62+
OptionalParameter<"mlir::TypeAttr">:$vec_type_hint,
6363
OptionalParameter<"std::optional<bool>">:$vec_type_hint_signedness,
64-
OptionalParameter<"IntegerAttr">:$intel_reqd_sub_group_size
64+
OptionalParameter<"mlir::IntegerAttr">:$intel_reqd_sub_group_size
6565
);
6666

6767
let assemblyFormat = "`<` struct(params) `>`";
@@ -76,14 +76,14 @@ def OpenCLKernelMetadataAttr
7676
let extraClassDefinition = [{
7777
std::optional<bool> $cppClass::isSignedHint(mlir::Type hintQTy) {
7878
// Only types in CIR carry signedness
79-
if (!mlir::isa<mlir::cir::CIRDialect>(hintQTy.getDialect()))
79+
if (!mlir::isa<cir::CIRDialect>(hintQTy.getDialect()))
8080
return std::nullopt;
8181

8282
// See also clang::CodeGen::CodeGenFunction::EmitKernelMetadata
83-
auto hintEltQTy = mlir::dyn_cast<mlir::cir::VectorType>(hintQTy);
83+
auto hintEltQTy = mlir::dyn_cast<cir::VectorType>(hintQTy);
8484
auto isCIRSignedIntType = [](mlir::Type t) {
85-
return mlir::isa<mlir::cir::IntType>(t) &&
86-
mlir::cast<mlir::cir::IntType>(t).isSigned();
85+
return mlir::isa<cir::IntType>(t) &&
86+
mlir::cast<cir::IntType>(t).isSigned();
8787
};
8888
return isCIRSignedIntType(hintQTy) ||
8989
(hintEltQTy && isCIRSignedIntType(hintEltQTy.getEltType()));
@@ -134,12 +134,12 @@ def OpenCLKernelArgMetadataAttr
134134
}];
135135

136136
let parameters = (ins
137-
"ArrayAttr":$addr_space,
138-
"ArrayAttr":$access_qual,
139-
"ArrayAttr":$type,
140-
"ArrayAttr":$base_type,
141-
"ArrayAttr":$type_qual,
142-
OptionalParameter<"ArrayAttr">:$name
137+
"mlir::ArrayAttr":$addr_space,
138+
"mlir::ArrayAttr":$access_qual,
139+
"mlir::ArrayAttr":$type,
140+
"mlir::ArrayAttr":$base_type,
141+
"mlir::ArrayAttr":$type_qual,
142+
OptionalParameter<"mlir::ArrayAttr">:$name
143143
);
144144

145145
let assemblyFormat = "`<` struct(params) `>`";

0 commit comments

Comments
 (0)