Skip to content

Commit 7776b19

Browse files
[MLIR] Move TestDialect to ::test namespace
While the changes are extensive, they basically fall into a few categories: 1) Moving the TestDialect itself. 2) Updating C++ code in tablegen to explicitly use ::mlir, since it will be put in a headers that shouldn't expect a 'using'. 3) Updating some generic MLIR Interface definitions to do the same thing. 4) Updating the Tablegen generator in a few places to be explicit about namespaces 5) Doing the same thing for llvm references, since we no longer pick up the definitions from mlir/Support/LLVM.h Differential Revision: https://reviews.llvm.org/D88251
1 parent e11354c commit 7776b19

22 files changed

+170
-175
lines changed

mlir/include/mlir/IR/BuiltinOps.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def FuncOp : Builtin_Op<"func", [
115115
/// Returns the region on the current operation that is callable. This may
116116
/// return null in the case of an external callable object, e.g. an external
117117
/// function.
118-
Region *getCallableRegion() { return isExternal() ? nullptr : &getBody(); }
118+
::mlir::Region *getCallableRegion() { return isExternal() ? nullptr : &getBody(); }
119119

120120
/// Returns the results types that the callable region produces when
121121
/// executed.

mlir/include/mlir/IR/OpBase.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1618,7 +1618,7 @@ class DerivedAttr<code ret, code b, code convert = ""> :
16181618
}
16191619

16201620
// Derived attribute that returns a mlir::Type.
1621-
class DerivedTypeAttr<code body> : DerivedAttr<"Type", body> {
1621+
class DerivedTypeAttr<code body> : DerivedAttr<"::mlir::Type", body> {
16221622
let convertFromStorage = "::mlir::TypeAttr::get($_self)";
16231623
}
16241624

mlir/include/mlir/IR/RegionKindInterface.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def RegionKindInterface : OpInterface<"RegionKindInterface"> {
3333
/*desc=*/[{
3434
Return the kind of the region with the given index inside this operation.
3535
}],
36-
/*retTy=*/"RegionKind",
36+
/*retTy=*/"::mlir::RegionKind",
3737
/*methodName=*/"getRegionKind",
3838
/*args=*/(ins "unsigned":$index)
3939
>,
@@ -44,7 +44,7 @@ def RegionKindInterface : OpInterface<"RegionKindInterface"> {
4444
/*methodName=*/"hasSSADominance",
4545
/*args=*/(ins "unsigned":$index),
4646
/*methodBody=*/[{
47-
return getRegionKind(index) == RegionKind::SSACFG;
47+
return getRegionKind(index) == ::mlir::RegionKind::SSACFG;
4848
}]
4949
>,
5050
];

mlir/include/mlir/Interfaces/InferTypeOpInterface.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,10 @@ def ReifyRankedShapedTypeOpInterface :
168168
rank of the corresponding result. If the shape of a particular
169169
result cannot be computed it must be empty.
170170
}],
171-
/*retTy=*/"LogicalResult",
171+
/*retTy=*/"::mlir::LogicalResult",
172172
/*methodName=*/"reifyResultShapes",
173173
/*args=*/(ins "::mlir::OpBuilder &":$builder,
174-
"ReifiedRankedShapedTypeDims &":$reifiedReturnShapes)
174+
"::mlir::ReifiedRankedShapedTypeDims &":$reifiedReturnShapes)
175175
>
176176
];
177177
}

mlir/test/lib/Dialect/Test/TestAttributes.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#include "llvm/ADT/TypeSwitch.h"
2222

2323
using namespace mlir;
24-
using namespace mlir::test;
24+
using namespace test;
2525

2626
//===----------------------------------------------------------------------===//
2727
// AttrWithSelfTypeParamAttr

mlir/test/lib/Dialect/Test/TestDialect.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,14 @@
2222
#include "mlir/Transforms/InliningUtils.h"
2323
#include "llvm/ADT/StringSwitch.h"
2424

25-
using namespace mlir;
26-
using namespace mlir::test;
27-
25+
// Include this before the using namespace lines below to
26+
// test that we don't have namespace dependencies.
2827
#include "TestOpsDialect.cpp.inc"
2928

30-
void mlir::test::registerTestDialect(DialectRegistry &registry) {
29+
using namespace mlir;
30+
using namespace test;
31+
32+
void test::registerTestDialect(DialectRegistry &registry) {
3133
registry.insert<TestDialect>();
3234
}
3335

mlir/test/lib/Dialect/Test/TestDialect.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,9 @@ class RewritePatternSet;
4545
#define GET_OP_CLASSES
4646
#include "TestOps.h.inc"
4747

48-
namespace mlir {
4948
namespace test {
50-
void registerTestDialect(DialectRegistry &registry);
51-
void populateTestReductionPatterns(RewritePatternSet &patterns);
52-
} // namespace test
53-
} // namespace mlir
49+
void registerTestDialect(::mlir::DialectRegistry &registry);
50+
void populateTestReductionPatterns(::mlir::RewritePatternSet &patterns);
51+
} // end namespace test
5452

5553
#endif // MLIR_TESTDIALECT_H

mlir/test/lib/Dialect/Test/TestInterfaces.td

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,26 @@ include "mlir/Interfaces/SideEffectInterfaceBase.td"
1414

1515
// A type interface used to test the ODS generation of type interfaces.
1616
def TestTypeInterface : TypeInterface<"TestTypeInterface"> {
17-
let cppNamespace = "::mlir::test";
17+
let cppNamespace = "::test";
1818
let methods = [
1919
InterfaceMethod<"Prints the type name.",
20-
"void", "printTypeA", (ins "Location":$loc), [{
20+
"void", "printTypeA", (ins "::mlir::Location":$loc), [{
2121
emitRemark(loc) << $_type << " - TestA";
2222
}]
2323
>,
2424
InterfaceMethod<"Prints the type name.",
25-
"void", "printTypeB", (ins "Location":$loc),
25+
"void", "printTypeB", (ins "::mlir::Location":$loc),
2626
[{}], /*defaultImplementation=*/[{
2727
emitRemark(loc) << $_type << " - TestB";
2828
}]
2929
>,
3030
InterfaceMethod<"Prints the type name.",
31-
"void", "printTypeC", (ins "Location":$loc)
31+
"void", "printTypeC", (ins "::mlir::Location":$loc)
3232
>,
3333
// It should be possible to use the interface type name as result type
3434
// as well as in the implementation.
3535
InterfaceMethod<"Prints the type name and returns the type as interface.",
36-
"TestTypeInterface", "printTypeRet", (ins "Location":$loc),
36+
"TestTypeInterface", "printTypeRet", (ins "::mlir::Location":$loc),
3737
[{}], /*defaultImplementation=*/[{
3838
emitRemark(loc) << $_type << " - TestRet";
3939
return $_type;
@@ -42,13 +42,13 @@ def TestTypeInterface : TypeInterface<"TestTypeInterface"> {
4242
];
4343
let extraClassDeclaration = [{
4444
/// Prints the type name.
45-
void printTypeD(Location loc) const {
45+
void printTypeD(::mlir::Location loc) const {
4646
emitRemark(loc) << *this << " - TestD";
4747
}
4848
}];
4949
let extraTraitClassDeclaration = [{
5050
/// Prints the type name.
51-
void printTypeE(Location loc) const {
51+
void printTypeE(::mlir::Location loc) const {
5252
emitRemark(loc) << $_type << " - TestE";
5353
}
5454
}];

mlir/test/lib/Dialect/Test/TestOps.td

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ include "TestInterfaces.td"
2424

2525
def Test_Dialect : Dialect {
2626
let name = "test";
27-
let cppNamespace = "::mlir::test";
27+
let cppNamespace = "::test";
2828
let hasCanonicalizer = 1;
2929
let hasConstantMaterializer = 1;
3030
let hasOperationAttrVerify = 1;
@@ -38,16 +38,16 @@ def Test_Dialect : Dialect {
3838
void registerAttributes();
3939
void registerTypes();
4040

41-
Attribute parseAttribute(DialectAsmParser &parser,
42-
Type type) const override;
43-
void printAttribute(Attribute attr,
44-
DialectAsmPrinter &printer) const override;
41+
::mlir::Attribute parseAttribute(::mlir::DialectAsmParser &parser,
42+
::mlir::Type type) const override;
43+
void printAttribute(::mlir::Attribute attr,
44+
::mlir::DialectAsmPrinter &printer) const override;
4545

4646
// Provides a custom printing/parsing for some operations.
47-
Optional<ParseOpHook>
48-
getParseOperationHook(StringRef opName) const override;
49-
LogicalResult printOperation(Operation *op,
50-
OpAsmPrinter &printer) const override;
47+
::llvm::Optional<ParseOpHook>
48+
getParseOperationHook(::llvm::StringRef opName) const override;
49+
::mlir::LogicalResult printOperation(::mlir::Operation *op,
50+
::mlir::OpAsmPrinter &printer) const override;
5151
private:
5252
// Storage for a custom fallback interface.
5353
void *fallbackEffectOpInterfaces;
@@ -117,8 +117,8 @@ def MultiTensorRankOf : TEST_Op<"multi_tensor_rank_of"> {
117117
}
118118

119119
def TEST_TestType : DialectType<Test_Dialect,
120-
CPred<"$_self.isa<::mlir::test::TestType>()">, "test">,
121-
BuildableType<"$_builder.getType<::mlir::test::TestType>()">;
120+
CPred<"$_self.isa<::test::TestType>()">, "test">,
121+
BuildableType<"$_builder.getType<::test::TestType>()">;
122122

123123
//===----------------------------------------------------------------------===//
124124
// Test Symbols
@@ -372,8 +372,8 @@ def ConversionCallOp : TEST_Op<"conversion_call_op",
372372
operand_range getArgOperands() { return inputs(); }
373373

374374
/// Return the callee of this operation.
375-
CallInterfaceCallable getCallableForCallee() {
376-
return (*this)->getAttrOfType<SymbolRefAttr>("callee");
375+
::mlir::CallInterfaceCallable getCallableForCallee() {
376+
return (*this)->getAttrOfType<::mlir::SymbolRefAttr>("callee");
377377
}
378378
}];
379379
}
@@ -384,9 +384,9 @@ def FunctionalRegionOp : TEST_Op<"functional_region_op",
384384
let results = (outs FunctionType);
385385

386386
let extraClassDeclaration = [{
387-
Region *getCallableRegion() { return &body(); }
388-
ArrayRef<Type> getCallableResults() {
389-
return getType().cast<FunctionType>().getResults();
387+
::mlir::Region *getCallableRegion() { return &body(); }
388+
::llvm::ArrayRef<::mlir::Type> getCallableResults() {
389+
return getType().cast<::mlir::FunctionType>().getResults();
390390
}
391391
}];
392392
}
@@ -748,7 +748,7 @@ def OpFuncRef : TEST_Op<"op_funcref"> {
748748
let description = [{
749749
The "test.op_funcref" is a test op with a reference to a function symbol.
750750
}];
751-
let builders = [OpBuilder<(ins "FuncOp":$function)>];
751+
let builders = [OpBuilder<(ins "::mlir::FuncOp":$function)>];
752752
}
753753

754754
// Pattern add the argument plus a increasing static number hidden in
@@ -898,10 +898,10 @@ def OpAllAttrConstraint2 : TEST_Op<"all_attr_constraint_of2"> {
898898
}
899899
def Constraint0 : AttrConstraint<
900900
CPred<"$_self.cast<ArrayAttr>()[0]."
901-
"cast<IntegerAttr>().getInt() == 0">,
901+
"cast<::mlir::IntegerAttr>().getInt() == 0">,
902902
"[0] == 0">;
903903
def Constraint1 : AttrConstraint<
904-
CPred<"$_self.cast<ArrayAttr>()[1].cast<IntegerAttr>().getInt() == 1">,
904+
CPred<"$_self.cast<ArrayAttr>()[1].cast<::mlir::IntegerAttr>().getInt() == 1">,
905905
"[1] == 1">;
906906
def : Pat<(OpAllAttrConstraint1
907907
AllAttrConstraintsOf<[Constraint0, Constraint1]>:$attr),
@@ -917,7 +917,7 @@ def TestOpConstant : TEST_Op<"constant", [ConstantLike, NoSideEffect]> {
917917
let arguments = (ins AnyAttr:$value);
918918
let results = (outs AnyType);
919919
let extraClassDeclaration = [{
920-
Attribute getValue() { return (*this)->getAttr("value"); }
920+
::mlir::Attribute getValue() { return (*this)->getAttr("value"); }
921921
}];
922922

923923
let hasFolder = 1;
@@ -1268,7 +1268,7 @@ def MixedVResultOp3 : TEST_Op<"mixed_variadic_out3",
12681268
// We will use this op in a nested result pattern, where we cannot deduce the
12691269
// result type. So need to provide a builder not requiring result types.
12701270
let builders = [
1271-
OpBuilder<(ins "IntegerAttr":$count),
1271+
OpBuilder<(ins "::mlir::IntegerAttr":$count),
12721272
[{
12731273
auto i32Type = $_builder.getIntegerType(32);
12741274
$_state.addTypes(i32Type); // $output1
@@ -1936,8 +1936,8 @@ def CopyOp : TEST_Op<"copy", [CopyOpInterface]> {
19361936
attr-dict
19371937
}];
19381938
let extraClassDeclaration = [{
1939-
Value getSource() { return source(); }
1940-
Value getTarget() { return target(); }
1939+
::mlir::Value getSource() { return source(); }
1940+
::mlir::Value getTarget() { return target(); }
19411941
}];
19421942
}
19431943

@@ -2027,16 +2027,16 @@ def RegionIfOp : TEST_Op<"region_if",
20272027
AnyRegion:$elseRegion,
20282028
AnyRegion:$joinRegion);
20292029
let extraClassDeclaration = [{
2030-
Block::BlockArgListType getThenArgs() {
2030+
::mlir::Block::BlockArgListType getThenArgs() {
20312031
return getBody(0)->getArguments();
20322032
}
2033-
Block::BlockArgListType getElseArgs() {
2033+
::mlir::Block::BlockArgListType getElseArgs() {
20342034
return getBody(1)->getArguments();
20352035
}
2036-
Block::BlockArgListType getJoinArgs() {
2036+
::mlir::Block::BlockArgListType getJoinArgs() {
20372037
return getBody(2)->getArguments();
20382038
}
2039-
OperandRange getSuccessorEntryOperands(unsigned index);
2039+
::mlir::OperandRange getSuccessorEntryOperands(unsigned index);
20402040
}];
20412041
}
20422042

@@ -2089,12 +2089,12 @@ def TableGenBuildOp5 : TEST_Op<"tblgen_build_5",
20892089
let results = (outs AnyType:$result);
20902090

20912091
let extraClassDeclaration = [{
2092-
static LogicalResult inferReturnTypes(MLIRContext *,
2093-
Optional<Location> location, ValueRange operands,
2094-
DictionaryAttr attributes, RegionRange regions,
2095-
SmallVectorImpl<Type> &inferredReturnTypes) {
2092+
static ::mlir::LogicalResult inferReturnTypes(::mlir::MLIRContext *,
2093+
::llvm::Optional<::mlir::Location> location, ::mlir::ValueRange operands,
2094+
::mlir::DictionaryAttr attributes, ::mlir::RegionRange regions,
2095+
::llvm::SmallVectorImpl<::mlir::Type> &inferredReturnTypes) {
20962096
inferredReturnTypes.assign({operands[0].getType()});
2097-
return success();
2097+
return ::mlir::success();
20982098
}
20992099
}];
21002100
}

mlir/test/lib/Dialect/Test/TestPatterns.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#include "mlir/Transforms/GreedyPatternRewriteDriver.h"
1818

1919
using namespace mlir;
20-
using namespace mlir::test;
20+
using namespace test;
2121

2222
// Native function for testing NativeCodeCall
2323
static Value chooseOperand(Value input1, Value input2, BoolAttr choice) {
@@ -67,7 +67,7 @@ namespace {
6767
// Test Reduce Pattern Interface
6868
//===----------------------------------------------------------------------===//
6969

70-
void mlir::test::populateTestReductionPatterns(RewritePatternSet &patterns) {
70+
void test::populateTestReductionPatterns(RewritePatternSet &patterns) {
7171
populateWithGenerated(patterns);
7272
}
7373

mlir/test/lib/Dialect/Test/TestTraits.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include "mlir/Transforms/GreedyPatternRewriteDriver.h"
1212

1313
using namespace mlir;
14-
using namespace mlir::test;
14+
using namespace test;
1515

1616
//===----------------------------------------------------------------------===//
1717
// Trait Folder.

mlir/test/lib/Dialect/Test/TestTypeDefs.td

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def IntegerType : Test_Type<"TestInteger"> {
5656
ins
5757
"unsigned":$width,
5858
// SignednessSemantics is defined below.
59-
"::mlir::test::TestIntegerType::SignednessSemantics":$signedness
59+
"::test::TestIntegerType::SignednessSemantics":$signedness
6060
);
6161

6262
// We define the printer inline.
@@ -84,7 +84,7 @@ def IntegerType : Test_Type<"TestInteger"> {
8484
int width;
8585
if ($_parser.parseInteger(width)) return Type();
8686
if ($_parser.parseGreater()) return Type();
87-
Location loc = $_parser.getEncodedSourceLoc($_parser.getNameLoc());
87+
::mlir::Location loc = $_parser.getEncodedSourceLoc($_parser.getNameLoc());
8888
return getChecked(loc, loc.getContext(), width, signedness);
8989
}];
9090

@@ -114,7 +114,7 @@ class FieldInfo_Type<string name> : Test_Type<name> {
114114
// An ArrayRef of something which requires allocation in the storage
115115
// constructor.
116116
ArrayRefOfSelfAllocationParameter<
117-
"::mlir::test::FieldInfo", // FieldInfo is defined/declared in TestTypes.h.
117+
"::test::FieldInfo", // FieldInfo is defined/declared in TestTypes.h.
118118
"Models struct fields">: $fields
119119
);
120120

@@ -136,7 +136,7 @@ class FieldInfo_Type<string name> : Test_Type<name> {
136136
llvm::SmallVector<FieldInfo, 4> parameters;
137137
if ($_parser.parseLess()) return Type();
138138
while (mlir::succeeded($_parser.parseOptionalLBrace())) {
139-
StringRef name;
139+
llvm::StringRef name;
140140
if ($_parser.parseKeyword(&name)) return Type();
141141
if ($_parser.parseComma()) return Type();
142142
Type type;
@@ -166,12 +166,12 @@ def TestTypeWithLayoutType : Test_Type<"TestTypeWithLayout", [
166166
let mnemonic = "test_type_with_layout";
167167
let parameters = (ins "unsigned":$key);
168168
let extraClassDeclaration = [{
169-
LogicalResult verifyEntries(DataLayoutEntryListRef params,
170-
Location loc) const;
169+
::mlir::LogicalResult verifyEntries(::mlir::DataLayoutEntryListRef params,
170+
::mlir::Location loc) const;
171171

172172
private:
173-
unsigned extractKind(DataLayoutEntryListRef params,
174-
StringRef expectedKind) const;
173+
unsigned extractKind(::mlir::DataLayoutEntryListRef params,
174+
::llvm::StringRef expectedKind) const;
175175

176176
public:
177177
}];

0 commit comments

Comments
 (0)