Skip to content

Commit 3655069

Browse files
committed
[mlir] Move the Builtin FuncOp to the Func dialect
This commit moves FuncOp out of the builtin dialect, and into the Func dialect. This move has been planned in some capacity from the moment we made FuncOp an operation (years ago). This commit handles the functional aspects of the move, but various aspects are left untouched to ease migration: func::FuncOp is re-exported into mlir to reduce the actual API churn, the assembly format still accepts the unqualified `func`. These temporary measures will remain for a little while to simplify migration before being removed. Differential Revision: https://reviews.llvm.org/D121266
1 parent f4548ed commit 3655069

File tree

246 files changed

+1137
-1019
lines changed

Some content is hidden

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

246 files changed

+1137
-1019
lines changed

flang/include/flang/Lower/CallInterface.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
#include "flang/Common/reference.h"
3131
#include "flang/Evaluate/characteristics.h"
32+
#include "mlir/Dialect/Func/IR/FuncOps.h"
3233
#include "mlir/IR/BuiltinOps.h"
3334
#include <memory>
3435
#include <optional>

flang/include/flang/Optimizer/Builder/FIRBuilder.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "flang/Optimizer/Dialect/FIROps.h"
2020
#include "flang/Optimizer/Dialect/FIRType.h"
2121
#include "flang/Optimizer/Support/KindMapping.h"
22+
#include "mlir/Dialect/Func/IR/FuncOps.h"
2223
#include "mlir/IR/Builders.h"
2324
#include "mlir/IR/BuiltinOps.h"
2425

flang/include/flang/Optimizer/Builder/LowLevelIntrinsics.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,21 @@
1414
#define FLANG_OPTIMIZER_BUILDER_LOWLEVELINTRINSICS_H
1515

1616
namespace mlir {
17+
namespace func {
1718
class FuncOp;
18-
}
19+
} // namespace func
20+
} // namespace mlir
1921
namespace fir {
2022
class FirOpBuilder;
2123
}
2224

2325
namespace fir::factory {
2426

2527
/// Get the `llvm.stacksave` intrinsic.
26-
mlir::FuncOp getLlvmStackSave(FirOpBuilder &builder);
28+
mlir::func::FuncOp getLlvmStackSave(FirOpBuilder &builder);
2729

2830
/// Get the `llvm.stackrestore` intrinsic.
29-
mlir::FuncOp getLlvmStackRestore(FirOpBuilder &builder);
31+
mlir::func::FuncOp getLlvmStackRestore(FirOpBuilder &builder);
3032

3133
} // namespace fir::factory
3234

flang/test/Fir/Todo/boxproc_host.fir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// Test that `fir.boxproc_host` fails conversion to llvm.
44
// At the moment this test fails since `fir.boxproc` type does not have a conversion.
55

6-
// CHECK: failed to legalize operation 'builtin.func'
6+
// CHECK: failed to legalize operation 'func.func'
77
func @test(%bproc: !fir.boxproc<(i32) -> ()>) {
88
%tuple = fir.boxproc_host %bproc : (!fir.boxproc<(i32) -> ()>) -> (!fir.ref<tuple<i32,f64>>)
99
return

flang/test/Fir/Todo/unboxproc.fir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// Not implemented yet.
55
// Currently fails since coversion for boxproc type is not implemented.
66

7-
// CHECK: failed to legalize operation 'builtin.func'
7+
// CHECK: failed to legalize operation 'func.func'
88
func @boxing_match(%bproc: !fir.boxproc<(i32) -> ()>) {
99
%ubproc:2 = fir.unboxproc %bproc : (!fir.boxproc<(i32) -> ()>) -> ((i32) -> (), !fir.ref<tuple<i32,f64>>)
1010
return

flang/unittests/Optimizer/Builder/CharacterTest.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
struct CharacterTest : public testing::Test {
1717
public:
1818
void SetUp() override {
19+
fir::support::loadDialects(context);
20+
1921
kindMap = std::make_unique<fir::KindMapping>(&context,
2022
"i10:80,l3:24,a1:8,r54:Double,c20:X86_FP80,r11:PPC_FP128,"
2123
"r12:FP128,r13:X86_FP80,r14:Double,r15:Float,r16:Half,r23:BFloat");
@@ -31,7 +33,6 @@ struct CharacterTest : public testing::Test {
3133
mod.push_back(mod);
3234
builder.setInsertionPointToStart(entryBlock);
3335

34-
fir::support::loadDialects(context);
3536
firBuilder = std::make_unique<fir::FirOpBuilder>(mod, *kindMap);
3637
}
3738

flang/unittests/Optimizer/Builder/ComplexTest.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
struct ComplexTest : public testing::Test {
1616
public:
1717
void SetUp() override {
18+
fir::support::loadDialects(context);
19+
1820
mlir::OpBuilder builder(&context);
1921
auto loc = builder.getUnknownLoc();
2022

@@ -27,7 +29,6 @@ struct ComplexTest : public testing::Test {
2729
mod.push_back(mod);
2830
builder.setInsertionPointToStart(entryBlock);
2931

30-
fir::support::loadDialects(context);
3132
kindMap = std::make_unique<fir::KindMapping>(&context);
3233
firBuilder = std::make_unique<fir::FirOpBuilder>(mod, *kindMap);
3334
helper = std::make_unique<fir::factory::Complex>(*firBuilder, loc);

flang/unittests/Optimizer/Builder/FIRBuilderTest.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ using namespace mlir;
1717
struct FIRBuilderTest : public testing::Test {
1818
public:
1919
void SetUp() override {
20+
fir::support::loadDialects(context);
21+
2022
llvm::ArrayRef<fir::KindTy> defs;
2123
fir::KindMapping kindMap(&context, defs);
2224
mlir::OpBuilder builder(&context);
@@ -31,7 +33,6 @@ struct FIRBuilderTest : public testing::Test {
3133
mod.push_back(mod);
3234
builder.setInsertionPointToStart(entryBlock);
3335

34-
fir::support::loadDialects(context);
3536
firBuilder = std::make_unique<fir::FirOpBuilder>(mod, kindMap);
3637
}
3738

flang/unittests/Optimizer/Builder/Runtime/RuntimeCallTestBase.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
struct RuntimeCallTest : public testing::Test {
1818
public:
1919
void SetUp() override {
20+
fir::support::loadDialects(context);
21+
2022
mlir::OpBuilder builder(&context);
2123
auto loc = builder.getUnknownLoc();
2224

@@ -29,7 +31,6 @@ struct RuntimeCallTest : public testing::Test {
2931
mod.push_back(mod);
3032
builder.setInsertionPointToStart(entryBlock);
3133

32-
fir::support::loadDialects(context);
3334
kindMap = std::make_unique<fir::KindMapping>(&context);
3435
firBuilder = std::make_unique<fir::FirOpBuilder>(mod, *kindMap);
3536

mlir/benchmark/python/benchmark_sparse.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def benchmark_sparse_mlir_multiplication():
4343
param2_type = ir.RankedTensorType.get([1500, 2000], f64)
4444
result_type = ir.RankedTensorType.get([1000, 2000], f64)
4545
with ir.InsertionPoint(module.body):
46-
@builtin.FuncOp.from_py_func(param1_type, param2_type, result_type)
46+
@func.FuncOp.from_py_func(param1_type, param2_type, result_type)
4747
def sparse_kernel(x, y, z):
4848
return matmul_dsl(x, y, outs=[z])
4949

mlir/benchmark/python/common.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def create_sparse_np_tensor(dimensions, number_of_elements):
4141
return tensor
4242

4343

44-
def get_kernel_func_from_module(module: ir.Module) -> builtin.FuncOp:
44+
def get_kernel_func_from_module(module: ir.Module) -> func.FuncOp:
4545
"""Takes an mlir module object and extracts the function object out of it.
4646
This function only works for a module with one region, one block, and one
4747
operation.
@@ -55,12 +55,12 @@ def get_kernel_func_from_module(module: ir.Module) -> builtin.FuncOp:
5555
return module.operation.regions[0].blocks[0].operations[0]
5656

5757

58-
def emit_timer_func() -> builtin.FuncOp:
58+
def emit_timer_func() -> func.FuncOp:
5959
"""Returns the declaration of nano_time function. If nano_time function is
6060
used, the `MLIR_RUNNER_UTILS` and `MLIR_C_RUNNER_UTILS` must be included.
6161
"""
6262
i64_type = ir.IntegerType.get_signless(64)
63-
nano_time = builtin.FuncOp(
63+
nano_time = func.FuncOp(
6464
"nano_time", ([], [i64_type]), visibility="private")
6565
nano_time.attributes["llvm.emit_c_interface"] = ir.UnitAttr.get()
6666
return nano_time
@@ -76,7 +76,7 @@ def emit_benchmark_wrapped_main_func(func, timer_func):
7676
"""
7777
i64_type = ir.IntegerType.get_signless(64)
7878
memref_of_i64_type = ir.MemRefType.get([-1], i64_type)
79-
wrapped_func = builtin.FuncOp(
79+
wrapped_func = func.FuncOp(
8080
# Same signature and an extra buffer of indices to save timings.
8181
"main",
8282
(func.arguments.types + [memref_of_i64_type], func.type.results),

mlir/docs/Bindings/Python.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ from mlir.dialects import builtin
639639
with Context():
640640
module = Module.create()
641641
with InsertionPoint(module.body), Location.unknown():
642-
func = builtin.FuncOp("main", ([], []))
642+
func = func.FuncOp("main", ([], []))
643643
```
644644

645645
Also see below for constructors generated from ODS.
@@ -660,12 +660,12 @@ with Context():
660660
with InsertionPoint(module.body), Location.unknown():
661661
# Operations can be created in a generic way.
662662
func = Operation.create(
663-
"builtin.func", results=[], operands=[],
663+
"func.func", results=[], operands=[],
664664
attributes={"type":TypeAttr.get(FunctionType.get([], []))},
665665
successors=None, regions=1)
666666
# The result will be downcasted to the concrete `OpView` subclass if
667667
# available.
668-
assert isinstance(func, builtin.FuncOp)
668+
assert isinstance(func, func.FuncOp)
669669
```
670670

671671
Regions are created for an operation when constructing it on the C++ side. They

mlir/docs/Dialects/ShapeDialect.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ below[^wip_form1]:
3434
```mlir
3535
shape.function_library @shplib {
3636
37-
builtin.func @matmul(%lhs: !shape.value_shape, %rhs: !shape.value_shape) -> !shape.shape {
37+
func.func @matmul(%lhs: !shape.value_shape, %rhs: !shape.value_shape) -> !shape.shape {
3838
%c1 = shape.const_size 1
3939
%c2 = shape.const_size 2
4040
// We could also allow rank etc operations directly on value_shape too, that

mlir/docs/PassManagement.md

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -532,12 +532,12 @@ A pipeline view that models the structure of the pass manager, this is the
532532
default view:
533533
534534
```shell
535-
$ mlir-opt -pass-pipeline='builtin.func(my-pass,my-pass)' foo.mlir -pass-statistics
535+
$ mlir-opt -pass-pipeline='func.func(my-pass,my-pass)' foo.mlir -pass-statistics
536536
537537
===-------------------------------------------------------------------------===
538538
... Pass statistics report ...
539539
===-------------------------------------------------------------------------===
540-
'builtin.func' Pipeline
540+
'func.func' Pipeline
541541
MyPass
542542
(S) 15 exampleStat - An example statistic
543543
VerifierPass
@@ -551,7 +551,7 @@ A list view that aggregates the statistics of all instances of a specific pass
551551
together:
552552

553553
```shell
554-
$ mlir-opt -pass-pipeline='builtin.func(my-pass, my-pass)' foo.mlir -pass-statistics -pass-statistics-display=list
554+
$ mlir-opt -pass-pipeline='func.func(my-pass, my-pass)' foo.mlir -pass-statistics -pass-statistics-display=list
555555

556556
===-------------------------------------------------------------------------===
557557
... Pass statistics report ...
@@ -657,7 +657,7 @@ options ::= '{' (key ('=' value)?)+ '}'
657657

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

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

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

10241024
```shell
1025-
$ mlir-opt foo.mlir -mlir-disable-threading -pass-pipeline='builtin.func(cse,canonicalize)' -convert-func-to-llvm -mlir-timing
1025+
$ mlir-opt foo.mlir -mlir-disable-threading -pass-pipeline='func.func(cse,canonicalize)' -convert-func-to-llvm -mlir-timing
10261026

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

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

10551055
```shell
1056-
$ mlir-opt foo.mlir -pass-pipeline='builtin.func(cse,canonicalize)' -convert-func-to-llvm -mlir-timing
1056+
$ mlir-opt foo.mlir -pass-pipeline='func.func(cse,canonicalize)' -convert-func-to-llvm -mlir-timing
10571057

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

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

10911091
```shell
1092-
$ mlir-opt foo.mlir -pass-pipeline='builtin.func(cse)' -print-ir-before=cse
1092+
$ mlir-opt foo.mlir -pass-pipeline='func.func(cse)' -print-ir-before=cse
10931093

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

11071107
```shell
1108-
$ mlir-opt foo.mlir -pass-pipeline='builtin.func(cse)' -print-ir-after=cse
1108+
$ mlir-opt foo.mlir -pass-pipeline='func.func(cse)' -print-ir-after=cse
11091109

11101110
*** IR Dump After CSE ***
11111111
func @simple_constant() -> (i32, i32) {
@@ -1126,7 +1126,7 @@ func @simple_constant() -> (i32, i32) {
11261126
printing.
11271127

11281128
```shell
1129-
$ mlir-opt foo.mlir -pass-pipeline='builtin.func(cse,cse)' -print-ir-after=cse -print-ir-after-change
1129+
$ mlir-opt foo.mlir -pass-pipeline='func.func(cse,cse)' -print-ir-after=cse -print-ir-after-change
11301130

11311131
*** IR Dump After CSE ***
11321132
func @simple_constant() -> (i32, i32) {
@@ -1141,7 +1141,7 @@ func @simple_constant() -> (i32, i32) {
11411141
above.
11421142

11431143
```shell
1144-
$ mlir-opt foo.mlir -pass-pipeline='builtin.func(cse,bad-pass)' -print-ir-failure
1144+
$ mlir-opt foo.mlir -pass-pipeline='func.func(cse,bad-pass)' -print-ir-failure
11451145

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

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

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

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

11961196
```mlir
1197-
// configuration: -pass-pipeline='builtin.func(cse,canonicalize),inline' -verify-each
1197+
// configuration: -pass-pipeline='func.func(cse,canonicalize),inline' -verify-each
11981198

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

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

mlir/docs/SymbolsAndSymbolTables.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ 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-
[`builtin.func`](Dialects/Builtin.md/#func-mlirfuncop). `builtin.func` defines a
34+
[`func.func`](Dialects/Builtin.md/#func-mlirfuncop). `func.func` defines a
3535
symbol name, which is [referred to](#referencing-a-symbol) by operations like
3636
[`func.call`](Dialects/Func.md/#funccall-callop).
3737

@@ -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 `builtin.func` operation defines a symbol named `symbol`.
80+
// This `func.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 `builtin.func` operation defines a symbol named `nested_symbol`.
109+
// This `func.func` operation defines a symbol named `nested_symbol`.
110110
func @nested_symbol()
111111
}
112112

mlir/docs/TargetLLVMIR.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ individual scalar arguments.
348348

349349
Examples:
350350

351-
This convention is implemented in the conversion of `builtin.func` and `func.call` to
351+
This convention is implemented in the conversion of `func.func` and `func.call` to
352352
the LLVM dialect, with the former unpacking the descriptor into a set of
353353
individual values and the latter packing those values back into a descriptor so
354354
as to make it transparently usable by other operations. Conversions from other

0 commit comments

Comments
 (0)