Skip to content

Commit f8479d9

Browse files
committed
[mlir] Set the namespace of the BuiltinDialect to 'builtin'
Historically the builtin dialect has had an empty namespace. This has unfortunately created a very awkward situation, where many utilities either have to special case the empty namespace, or just don't work at all right now. This revision adds a namespace to the builtin dialect, and starts to cleanup some of the utilities to no longer handle empty namespaces. For now, the assembly form of builtin operations does not require the `builtin.` prefix. (This should likely be re-evaluated though) Differential Revision: https://reviews.llvm.org/D105149
1 parent d52ba48 commit f8479d9

File tree

84 files changed

+471
-485
lines changed

Some content is hidden

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

84 files changed

+471
-485
lines changed

flang/lib/Optimizer/Dialect/FIRType.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "flang/Optimizer/Dialect/FIRType.h"
1414
#include "flang/Optimizer/Dialect/FIRDialect.h"
1515
#include "mlir/IR/Builders.h"
16+
#include "mlir/IR/BuiltinDialect.h"
1617
#include "mlir/IR/Diagnostics.h"
1718
#include "mlir/IR/DialectImplementation.h"
1819
#include "llvm/ADT/SmallPtrSet.h"
@@ -188,7 +189,7 @@ bool isa_fir_type(mlir::Type t) {
188189
}
189190

190191
bool isa_std_type(mlir::Type t) {
191-
return t.getDialect().getNamespace().empty();
192+
return llvm::isa<mlir::BuiltinDialect>(t.getDialect());
192193
}
193194

194195
bool isa_fir_or_std_type(mlir::Type t) {

flang/test/Fir/cg-ops.fir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: fir-opt --pass-pipeline="func(cg-rewrite),fir.global(cg-rewrite),cse" %s | FileCheck %s
1+
// RUN: fir-opt --pass-pipeline="builtin.func(cg-rewrite),fir.global(cg-rewrite),cse" %s | FileCheck %s
22

33
// CHECK-LABEL: func @codegen(
44
// CHECK-SAME: %[[arg:.*]]: !fir

mlir/docs/Diagnostics.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ operation that may be invalid, especially when debugging verifier failures. An
155155
example output is shown below:
156156

157157
```shell
158-
test.mlir:3:3: error: 'module_terminator' op expects parent op 'module'
158+
test.mlir:3:3: error: 'module_terminator' op expects parent op 'builtin.module'
159159
"module_terminator"() : () -> ()
160160
^
161161
test.mlir:3:3: note: see current operation: "module_terminator"() : () -> ()
@@ -172,7 +172,7 @@ diagnostic. This option is useful for understanding which part of the compiler
172172
generated certain diagnostics. An example output is shown below:
173173

174174
```shell
175-
test.mlir:3:3: error: 'module_terminator' op expects parent op 'module'
175+
test.mlir:3:3: error: 'module_terminator' op expects parent op 'builtin.module'
176176
"module_terminator"() : () -> ()
177177
^
178178
test.mlir:3:3: note: diagnostic emitted with trace:

mlir/docs/PassManagement.md

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ structure:
343343
// explicitly specific, the default is the builtin `module` operation.
344344
PassManager pm(ctx);
345345
// Note: We could also create the above `PassManager` this way.
346-
PassManager pm(ctx, /*operationName=*/"module");
346+
PassManager pm(ctx, /*operationName=*/"builtin.module");
347347
348348
// Add a pass on the top-level module operation.
349349
pm.addPass(std::make_unique<MyModulePass>());
@@ -405,7 +405,7 @@ top-level `PassManager::run` method. A simple example is shown below:
405405
void MyModulePass::runOnOperation() {
406406
ModuleOp module = getOperation();
407407
if (hasSomeSpecificProperty(module)) {
408-
OpPassManager dynamicPM("module");
408+
OpPassManager dynamicPM("builtin.module");
409409
...; // Build the dynamic pipeline.
410410
if (failed(runPipeline(dynamicPM, module)))
411411
return signalPassFailure();
@@ -531,12 +531,12 @@ A pipeline view that models the structure of the pass manager, this is the
531531
default view:
532532
533533
```shell
534-
$ mlir-opt -pass-pipeline='func(my-pass,my-pass)' foo.mlir -pass-statistics
534+
$ mlir-opt -pass-pipeline='builtin.func(my-pass,my-pass)' foo.mlir -pass-statistics
535535
536536
===-------------------------------------------------------------------------===
537537
... Pass statistics report ...
538538
===-------------------------------------------------------------------------===
539-
'func' Pipeline
539+
'builtin.func' Pipeline
540540
MyPass
541541
(S) 15 exampleStat - An example statistic
542542
VerifierPass
@@ -550,7 +550,7 @@ A list view that aggregates the statistics of all instances of a specific pass
550550
together:
551551

552552
```shell
553-
$ mlir-opt -pass-pipeline='func(my-pass, my-pass)' foo.mlir -pass-statistics -pass-statistics-display=list
553+
$ mlir-opt -pass-pipeline='builtin.func(my-pass, my-pass)' foo.mlir -pass-statistics -pass-statistics-display=list
554554

555555
===-------------------------------------------------------------------------===
556556
... Pass statistics report ...
@@ -656,7 +656,7 @@ options ::= '{' (key ('=' value)?)+ '}'
656656

657657
* `op-name`
658658
* This corresponds to the mnemonic name of an operation to run passes on,
659-
e.g. `func` or `module`.
659+
e.g. `builtin.func` or `builtin.module`.
660660
* `pass-name` | `pass-pipeline-name`
661661
* This corresponds to the argument of a registered pass or pass pipeline,
662662
e.g. `cse` or `canonicalize`.
@@ -675,7 +675,7 @@ $ mlir-opt foo.mlir -cse -canonicalize -convert-std-to-llvm='use-bare-ptr-memref
675675
Can also be specified as (via the `-pass-pipeline` flag):
676676

677677
```shell
678-
$ mlir-opt foo.mlir -pass-pipeline='func(cse,canonicalize),convert-std-to-llvm{use-bare-ptr-memref-call-conv=1}'
678+
$ mlir-opt foo.mlir -pass-pipeline='builtin.func(cse,canonicalize),convert-std-to-llvm{use-bare-ptr-memref-call-conv=1}'
679679
```
680680

681681
In order to support round-tripping a pass to the textual representation using
@@ -996,7 +996,7 @@ pipeline. This display mode is available in mlir-opt via
996996
`-mlir-timing-display=list`.
997997
998998
```shell
999-
$ mlir-opt foo.mlir -mlir-disable-threading -pass-pipeline='func(cse,canonicalize)' -convert-std-to-llvm -mlir-timing -mlir-timing-display=list
999+
$ mlir-opt foo.mlir -mlir-disable-threading -pass-pipeline='builtin.func(cse,canonicalize)' -convert-std-to-llvm -mlir-timing -mlir-timing-display=list
10001000
10011001
===-------------------------------------------------------------------------===
10021002
... Pass execution timing report ...
@@ -1021,15 +1021,15 @@ the most time, and can also be used to identify when analyses are being
10211021
invalidated and recomputed. This is the default display mode.
10221022

10231023
```shell
1024-
$ mlir-opt foo.mlir -mlir-disable-threading -pass-pipeline='func(cse,canonicalize)' -convert-std-to-llvm -mlir-timing
1024+
$ mlir-opt foo.mlir -mlir-disable-threading -pass-pipeline='builtin.func(cse,canonicalize)' -convert-std-to-llvm -mlir-timing
10251025

10261026
===-------------------------------------------------------------------------===
10271027
... Pass execution timing report ...
10281028
===-------------------------------------------------------------------------===
10291029
Total Execution Time: 0.0249 seconds
10301030

10311031
---Wall Time--- --- Name ---
1032-
0.0058 ( 70.8%) 'func' Pipeline
1032+
0.0058 ( 70.8%) 'builtin.func' Pipeline
10331033
0.0004 ( 4.3%) CSE
10341034
0.0002 ( 2.6%) (A) DominanceInfo
10351035
0.0004 ( 4.8%) VerifierPass
@@ -1052,15 +1052,15 @@ perceived time, or clock time, whereas the `User Time` will display the total
10521052
cpu time.
10531053

10541054
```shell
1055-
$ mlir-opt foo.mlir -pass-pipeline='func(cse,canonicalize)' -convert-std-to-llvm -mlir-timing
1055+
$ mlir-opt foo.mlir -pass-pipeline='builtin.func(cse,canonicalize)' -convert-std-to-llvm -mlir-timing
10561056

10571057
===-------------------------------------------------------------------------===
10581058
... Pass execution timing report ...
10591059
===-------------------------------------------------------------------------===
10601060
Total Execution Time: 0.0078 seconds
10611061

10621062
---User Time--- ---Wall Time--- --- Name ---
1063-
0.0177 ( 88.5%) 0.0057 ( 71.3%) 'func' Pipeline
1063+
0.0177 ( 88.5%) 0.0057 ( 71.3%) 'builtin.func' Pipeline
10641064
0.0044 ( 22.0%) 0.0015 ( 18.9%) CSE
10651065
0.0029 ( 14.5%) 0.0012 ( 15.2%) (A) DominanceInfo
10661066
0.0038 ( 18.9%) 0.0015 ( 18.7%) VerifierPass
@@ -1088,7 +1088,7 @@ this instrumentation:
10881088
* Print the IR before every pass in the pipeline.
10891089

10901090
```shell
1091-
$ mlir-opt foo.mlir -pass-pipeline='func(cse)' -print-ir-before=cse
1091+
$ mlir-opt foo.mlir -pass-pipeline='builtin.func(cse)' -print-ir-before=cse
10921092

10931093
*** IR Dump Before CSE ***
10941094
func @simple_constant() -> (i32, i32) {
@@ -1104,7 +1104,7 @@ func @simple_constant() -> (i32, i32) {
11041104
* Print the IR after every pass in the pipeline.
11051105

11061106
```shell
1107-
$ mlir-opt foo.mlir -pass-pipeline='func(cse)' -print-ir-after=cse
1107+
$ mlir-opt foo.mlir -pass-pipeline='builtin.func(cse)' -print-ir-after=cse
11081108

11091109
*** IR Dump After CSE ***
11101110
func @simple_constant() -> (i32, i32) {
@@ -1125,7 +1125,7 @@ func @simple_constant() -> (i32, i32) {
11251125
printing.
11261126

11271127
```shell
1128-
$ mlir-opt foo.mlir -pass-pipeline='func(cse,cse)' -print-ir-after=cse -print-ir-after-change
1128+
$ mlir-opt foo.mlir -pass-pipeline='builtin.func(cse,cse)' -print-ir-after=cse -print-ir-after-change
11291129

11301130
*** IR Dump After CSE ***
11311131
func @simple_constant() -> (i32, i32) {
@@ -1140,7 +1140,7 @@ func @simple_constant() -> (i32, i32) {
11401140
above.
11411141

11421142
```shell
1143-
$ mlir-opt foo.mlir -pass-pipeline='func(cse,bad-pass)' -print-ir-failure
1143+
$ mlir-opt foo.mlir -pass-pipeline='builtin.func(cse,bad-pass)' -print-ir-failure
11441144

11451145
*** IR Dump After BadPass Failed ***
11461146
func @simple_constant() -> (i32, i32) {
@@ -1156,9 +1156,9 @@ func @simple_constant() -> (i32, i32) {
11561156
is disabled(`-mlir-disable-threading`)
11571157

11581158
```shell
1159-
$ mlir-opt foo.mlir -mlir-disable-threading -pass-pipeline='func(cse)' -print-ir-after=cse -print-ir-module-scope
1159+
$ mlir-opt foo.mlir -mlir-disable-threading -pass-pipeline='builtin.func(cse)' -print-ir-after=cse -print-ir-module-scope
11601160

1161-
*** IR Dump After CSE *** ('func' operation: @bar)
1161+
*** IR Dump After CSE *** ('builtin.func' operation: @bar)
11621162
func @bar(%arg0: f32, %arg1: f32) -> f32 {
11631163
...
11641164
}
@@ -1169,7 +1169,7 @@ func @simple_constant() -> (i32, i32) {
11691169
return %c1_i32, %c1_i32_0 : i32, i32
11701170
}
11711171

1172-
*** IR Dump After CSE *** ('func' operation: @simple_constant)
1172+
*** IR Dump After CSE *** ('builtin.func' operation: @simple_constant)
11731173
func @bar(%arg0: f32, %arg1: f32) -> f32 {
11741174
...
11751175
}
@@ -1193,7 +1193,7 @@ was executing, as well as the initial IR before any passes were run. A potential
11931193
reproducible may have the form:
11941194

11951195
```mlir
1196-
// configuration: -pass-pipeline='func(cse,canonicalize),inline' -verify-each
1196+
// configuration: -pass-pipeline='builtin.func(cse,canonicalize),inline' -verify-each
11971197

11981198
module {
11991199
func @foo() {
@@ -1228,7 +1228,7 @@ For example, if the failure in the previous example came from `canonicalize`,
12281228
the following reproducer will be generated:
12291229

12301230
```mlir
1231-
// configuration: -pass-pipeline='func(canonicalize)' -verify-each -mlir-disable-threading
1231+
// configuration: -pass-pipeline='builtin.func(canonicalize)' -verify-each -mlir-disable-threading
12321232
12331233
module {
12341234
func @foo() {

mlir/docs/SymbolsAndSymbolTables.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,16 @@ defines a [`SymbolTable`](#symbol-table). The name of a symbol *must* be unique
3131
within the parent `SymbolTable`. This name is semantically similarly to an SSA
3232
result value, and may be referred to by other operations to provide a symbolic
3333
link, or use, to the symbol. An example of a `Symbol` operation is
34-
[`func`](Dialects/Builtin.md/#func-mlirfuncop). `func` defines a symbol name, which is
35-
[referred to](#referencing-a-symbol) by operations like
34+
[`builtin.func`](Dialects/Builtin.md/#func-mlirfuncop). `builtin.func` defines a
35+
symbol name, which is [referred to](#referencing-a-symbol) by operations like
3636
[`std.call`](Dialects/Standard.md/#stdcall-callop).
3737

3838
### Defining or declaring a Symbol
3939

4040
A `Symbol` operation should use the `SymbolOpInterface` interface to provide the
41-
necessary verification and accessors; it also supports
42-
operations, such as `module`, that conditionally define a symbol. `Symbol`s must
43-
have the following properties:
41+
necessary verification and accessors; it also supports operations, such as
42+
`builtin.module`, that conditionally define a symbol. `Symbol`s must have the
43+
following properties:
4444

4545
* A `StringAttr` attribute named
4646
'SymbolTable::getSymbolAttrName()'(`sym_name`).
@@ -77,7 +77,7 @@ operation that is also a [symbol table](#symbol-table).
7777
Below is an example of how an operation can reference a symbol operation:
7878

7979
```mlir
80-
// This `func` operation defines a symbol named `symbol`.
80+
// This `builtin.func` operation defines a symbol named `symbol`.
8181
func @symbol()
8282
8383
// Our `foo.user` operation contains a SymbolRefAttr with the name of the
@@ -106,7 +106,7 @@ module {
106106
// Here we define another nested symbol table, except this time it also defines
107107
// a symbol.
108108
module @module_symbol {
109-
// This `func` operation defines a symbol named `nested_symbol`.
109+
// This `builtin.func` operation defines a symbol named `nested_symbol`.
110110
func @nested_symbol()
111111
}
112112

mlir/docs/Tutorials/UnderstandingTheIRStructure.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ with `mlir-opt -test-print-nesting -allow-unregistered-dialect
9696
llvm-project/mlir/test/IR/print-ir-nesting.mlir`:
9797
9898
```mlir
99-
"module"() ( {
99+
"builtin.module"() ( {
100100
%0:4 = "dialect.op1"() {"attribute name" = 42 : i32} : () -> (i1, i16, i32, i64)
101101
"dialect.op2"() ( {
102102
"dialect.innerop1"(%0#0, %0#1) : (i1, i16) -> ()
@@ -116,7 +116,7 @@ llvm-project/mlir/test/IR/print-ir-nesting.mlir`:
116116
And will yield the following output:
117117

118118
```
119-
visiting op: 'module' with 0 operands and 0 results
119+
visiting op: 'builtin.module' with 0 operands and 0 results
120120
1 nested regions:
121121
Region with 1 blocks:
122122
Block with 0 arguments, 0 successors, and 3 operations

mlir/include/mlir/Dialect/PDL/IR/PDLOps.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ def PDL_OperationOp
342342
```mlir
343343
// Define an instance with single range of types.
344344
%allResultTypes = pdl.types
345-
%op = pdl.operation "unrealized_conversion_cast" -> (%allResultTypes : !pdl.types)
345+
%op = pdl.operation "builtin.unrealized_conversion_cast" -> (%allResultTypes : !pdl.types)
346346
```
347347

348348
2) A variadic number of either !pdl.type or !pdl.range<type>:

mlir/include/mlir/IR/BuiltinDialect.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def Builtin_Dialect : Dialect {
2020
let summary =
2121
"A dialect containing the builtin Attributes, Operations, and Types";
2222

23-
let name = "";
23+
let name = "builtin";
2424
let cppNamespace = "::mlir";
2525
let extraClassDeclaration = [{
2626
private:

mlir/include/mlir/IR/Dialect.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ class DialectRegistry {
294294
using InterfaceMapTy = DenseMap<TypeID, DelayedInterfaces>;
295295

296296
public:
297-
explicit DialectRegistry() {}
297+
explicit DialectRegistry();
298298

299299
template <typename ConcreteDialect>
300300
void insert() {
@@ -367,8 +367,7 @@ class DialectRegistry {
367367
void addOpInterface() {
368368
StringRef opName = OpTy::getOperationName();
369369
StringRef dialectName = opName.split('.').first;
370-
addObjectInterface(dialectName == opName ? "" : dialectName,
371-
ModelTy::Interface::getInterfaceID(),
370+
addObjectInterface(dialectName, ModelTy::Interface::getInterfaceID(),
372371
[](MLIRContext *context) {
373372
OpTy::template attachInterface<ModelTy>(*context);
374373
});

mlir/include/mlir/Pass/PassManager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ class PassManager : public OpPassManager {
172172
/// style. The created pass manager can schedule operations that match
173173
/// `operationName`.
174174
PassManager(MLIRContext *ctx, Nesting nesting = Nesting::Explicit,
175-
StringRef operationName = "module");
175+
StringRef operationName = "builtin.module");
176176
PassManager(MLIRContext *ctx, StringRef operationName)
177177
: PassManager(ctx, Nesting::Explicit, operationName) {}
178178
~PassManager();

mlir/include/mlir/Transforms/LoopUtils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ void collapseParallelLoops(scf::ParallelOp loops,
278278
void mapLoopToProcessorIds(scf::ForOp forOp, ArrayRef<Value> processorId,
279279
ArrayRef<Value> numProcessors);
280280

281-
/// Gathers all AffineForOps in 'func' grouped by loop depth.
281+
/// Gathers all AffineForOps in 'builtin.func' grouped by loop depth.
282282
void gatherLoops(FuncOp func,
283283
std::vector<SmallVector<AffineForOp, 2>> &depthToLoops);
284284

mlir/lib/Bindings/Python/IRCore.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -643,11 +643,8 @@ void PyThreadContextEntry::popLocation(PyLocation &location) {
643643

644644
MlirDialect PyDialects::getDialectForKey(const std::string &key,
645645
bool attrError) {
646-
// If the "std" dialect was asked for, substitute the empty namespace :(
647-
static const std::string emptyKey;
648-
const std::string *canonKey = key == "std" ? &emptyKey : &key;
649-
MlirDialect dialect = mlirContextGetOrLoadDialect(
650-
getContext()->get(), {canonKey->data(), canonKey->size()});
646+
MlirDialect dialect = mlirContextGetOrLoadDialect(getContext()->get(),
647+
{key.data(), key.size()});
651648
if (mlirDialectIsNull(dialect)) {
652649
throw SetPyError(attrError ? PyExc_AttributeError : PyExc_IndexError,
653650
Twine("Dialect '") + key + "' not found");

mlir/lib/Dialect/Linalg/Transforms/ComprehensiveBufferize.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2813,7 +2813,7 @@ void LinalgComprehensiveModuleBufferize::runOnOperation() {
28132813
removeBufferizationFuncArguments(bbArg);
28142814
});
28152815

2816-
OpPassManager cleanupPipeline(OpPassManager("module"));
2816+
OpPassManager cleanupPipeline("builtin.module");
28172817
cleanupPipeline.addPass(createCanonicalizerPass());
28182818
cleanupPipeline.addPass(createCSEPass());
28192819
cleanupPipeline.addPass(createLoopInvariantCodeMotionPass());

mlir/lib/IR/BuiltinDialect.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ void BuiltinDialect::initialize() {
7878

7979
FuncOp FuncOp::create(Location location, StringRef name, FunctionType type,
8080
ArrayRef<NamedAttribute> attrs) {
81-
OperationState state(location, "func");
8281
OpBuilder builder(location->getContext());
82+
OperationState state(location, getOperationName());
8383
FuncOp::build(builder, state, name, type, attrs);
8484
return cast<FuncOp>(Operation::create(state));
8585
}

mlir/lib/IR/BuiltinTypes.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ bool TensorType::isValidElementType(Type type) {
491491
// element type within that dialect.
492492
return type.isa<ComplexType, FloatType, IntegerType, OpaqueType, VectorType,
493493
IndexType>() ||
494-
!type.getDialect().getNamespace().empty();
494+
!llvm::isa<BuiltinDialect>(type.getDialect());
495495
}
496496

497497
//===----------------------------------------------------------------------===//

0 commit comments

Comments
 (0)