Skip to content

Commit 88f0e4c

Browse files
authored
[mlir][async] Avoid crash when not using func.func (#72801)
The `createParallelComputeFunction` crashed when calling `getFunctionTypeAttrName` during the creation of a new `FuncOp` inside the pass. The problem is that `getFunctionTypeAttrName` looks up the attribute name for the function type which in this case is `func.func`. However, `name.getAttributeNames()` was empty when clients used `llvm.func` instead of `func.func`. To fix this, the `func` dialect is now registered as a dependent dialect. Also, I've added an assertion which could save other people some time. Fixes #71281, fixes #64326.
1 parent c8c81f4 commit 88f0e4c

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

mlir/include/mlir/Dialect/Async/Passes.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ def AsyncParallelFor : Pass<"async-parallel-for", "ModuleOp"> {
3636
let dependentDialects = [
3737
"arith::ArithDialect",
3838
"async::AsyncDialect",
39+
"func::FuncDialect",
3940
"scf::SCFDialect"
4041
];
4142
}

mlir/test/Dialect/Async/async-parallel-for-compute-fn.mlir

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,25 @@ func.func @sink_constant_step(%arg0: memref<?xf32>, %lb: index, %ub: index) {
6969

7070
// -----
7171

72+
// Smoke test that parallel for doesn't crash when func dialect is not used.
73+
74+
// CHECK-LABEL: llvm.func @without_func_dialect()
75+
llvm.func @without_func_dialect() {
76+
%cst = arith.constant 0.0 : f32
77+
78+
%c0 = arith.constant 0 : index
79+
%c22 = arith.constant 22 : index
80+
%c1 = arith.constant 1 : index
81+
%54 = memref.alloc() : memref<22xf32>
82+
%alloc_4 = memref.alloc() : memref<22xf32>
83+
scf.parallel (%arg0) = (%c0) to (%c22) step (%c1) {
84+
memref.store %cst, %alloc_4[%arg0] : memref<22xf32>
85+
}
86+
llvm.return
87+
}
88+
89+
// -----
90+
7291
// Check that for statically known inner loop bound block size is aligned and
7392
// inner loop uses statically known loop trip counts.
7493

mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,6 +1143,8 @@ void OpEmitter::genAttrNameGetters() {
11431143
const char *const getAttrName = R"(
11441144
assert(index < {0} && "invalid attribute index");
11451145
assert(name.getStringRef() == getOperationName() && "invalid operation name");
1146+
assert(name.isRegistered() && "Operation isn't registered, missing a "
1147+
"dependent dialect loading?");
11461148
return name.getAttributeNames()[index];
11471149
)";
11481150
method->body() << formatv(getAttrName, attributes.size());

0 commit comments

Comments
 (0)