Skip to content

Commit 1f0af01

Browse files
committed
Flip the order attributes appear, add more tests for that in face of operand attrs
1 parent bbc3b1f commit 1f0af01

File tree

3 files changed

+17
-19
lines changed

3 files changed

+17
-19
lines changed

mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3613,6 +3613,9 @@ ParseResult CallIntrinsicOp::parse(OpAsmParser &parser,
36133613
CallIntrinsicOp::getOpBundleTagsAttrName(result.name).getValue(),
36143614
opBundleTags);
36153615

3616+
if (parser.parseOptionalAttrDict(result.attributes))
3617+
return mlir::failure();
3618+
36163619
SmallVector<DictionaryAttr> argAttrs;
36173620
SmallVector<DictionaryAttr> resultAttrs;
36183621
if (parseCallTypeAndResolveOperands(parser, result, /*isDirect=*/true,
@@ -3622,12 +3625,6 @@ ParseResult CallIntrinsicOp::parse(OpAsmParser &parser,
36223625
parser.getBuilder(), result, argAttrs, resultAttrs,
36233626
getArgAttrsAttrName(result.name), getResAttrsAttrName(result.name));
36243627

3625-
// TODO: In CallOp, the attr dict happens *before* the call type.
3626-
// CallIntrinsicOp should mimic that, allowing most of this function to be
3627-
// shared between the two ops.
3628-
if (parser.parseOptionalAttrDict(result.attributes))
3629-
return mlir::failure();
3630-
36313628
if (resolveOpBundleOperands(parser, opBundlesLoc, result, opBundleOperands,
36323629
opBundleOperandTypes,
36333630
getOpBundleSizesAttrName(result.name)))
@@ -3658,18 +3655,19 @@ void CallIntrinsicOp::print(OpAsmPrinter &p) {
36583655
printOpBundles(p, *this, getOpBundleOperands(),
36593656
getOpBundleOperands().getTypes(), getOpBundleTagsAttr());
36603657
}
3661-
p << " : ";
3662-
3663-
// Reconstruct the MLIR function type from operand and result types.
3664-
call_interface_impl::printFunctionSignature(
3665-
p, args.getTypes(), getArgAttrsAttr(),
3666-
/*isVariadic=*/false, getResultTypes(), getResAttrsAttr());
36673658

36683659
p.printOptionalAttrDict(processFMFAttr((*this)->getAttrs()),
36693660
{getOperandSegmentSizesAttrName(),
36703661
getOpBundleSizesAttrName(), getIntrinAttrName(),
36713662
getOpBundleTagsAttrName(), getArgAttrsAttrName(),
36723663
getResAttrsAttrName()});
3664+
3665+
p << " : ";
3666+
3667+
// Reconstruct the MLIR function type from operand and result types.
3668+
call_interface_impl::printFunctionSignature(
3669+
p, args.getTypes(), getArgAttrsAttr(),
3670+
/*isVariadic=*/false, getResultTypes(), getResAttrsAttr());
36733671
}
36743672

36753673
//===----------------------------------------------------------------------===//

mlir/test/Dialect/LLVMIR/call-intrin.mlir

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
llvm.func @round_sse41() -> vector<4xf32> {
88
%0 = llvm.mlir.constant(1 : i32) : i32
99
%1 = llvm.mlir.constant(dense<0.2> : vector<4xf32>) : vector<4xf32>
10-
%res = llvm.call_intrinsic "llvm.x86.sse41.round.ss"(%1, %1, %0) : (vector<4xf32>, vector<4xf32>, i32) -> vector<4xf32> {fastmathFlags = #llvm.fastmath<reassoc>}
10+
%res = llvm.call_intrinsic "llvm.x86.sse41.round.ss"(%1, %1, %0) {fastmathFlags = #llvm.fastmath<reassoc>} : (vector<4xf32>, vector<4xf32>, i32) -> vector<4xf32>
1111
llvm.return %res: vector<4xf32>
1212
}
1313

@@ -19,7 +19,7 @@ llvm.func @round_sse41() -> vector<4xf32> {
1919
// CHECK: }
2020
llvm.func @round_overloaded() -> f32 {
2121
%0 = llvm.mlir.constant(1.0 : f32) : f32
22-
%res = llvm.call_intrinsic "llvm.round"(%0) : (f32) -> f32 {}
22+
%res = llvm.call_intrinsic "llvm.round"(%0) {} : (f32) -> f32
2323
llvm.return %res: f32
2424
}
2525

@@ -34,7 +34,7 @@ llvm.func @lifetime_start() {
3434
%0 = llvm.mlir.constant(4 : i64) : i64
3535
%1 = llvm.mlir.constant(1 : i8) : i8
3636
%2 = llvm.alloca %1 x f32 : (i8) -> !llvm.ptr
37-
llvm.call_intrinsic "llvm.lifetime.start"(%0, %2) : (i64, !llvm.ptr) -> () {}
37+
llvm.call_intrinsic "llvm.lifetime.start"(%0, %2) {} : (i64, !llvm.ptr) -> ()
3838
llvm.return
3939
}
4040

@@ -64,7 +64,7 @@ llvm.func @bad_types() {
6464
%0 = llvm.mlir.constant(1 : i8) : i8
6565
// expected-error@below {{call intrinsic signature i8 (i8) to overloaded intrinsic "llvm.round" does not match any of the overloads}}
6666
// expected-error@below {{LLVM Translation failed for operation: llvm.call_intrinsic}}
67-
llvm.call_intrinsic "llvm.round"(%0) : (i8) -> i8 {}
67+
llvm.call_intrinsic "llvm.round"(%0) {} : (i8) -> i8
6868
llvm.return
6969
}
7070

@@ -102,7 +102,7 @@ llvm.func @bad_args() {
102102
%1 = llvm.mlir.constant(dense<0.2> : vector<4xf32>) : vector<4xf32>
103103
// expected-error @below {{intrinsic call operand #2 has type i64 but "llvm.x86.sse41.round.ss" expects i32}}
104104
// expected-error@below {{LLVM Translation failed for operation: llvm.call_intrinsic}}
105-
%res = llvm.call_intrinsic "llvm.x86.sse41.round.ss"(%1, %1, %0) : (vector<4xf32>, vector<4xf32>, i64) -> vector<4xf32> {fastmathFlags = #llvm.fastmath<reassoc>}
105+
%res = llvm.call_intrinsic "llvm.x86.sse41.round.ss"(%1, %1, %0) {fastmathFlags = #llvm.fastmath<reassoc>} : (vector<4xf32>, vector<4xf32>, i64) -> vector<4xf32>
106106
llvm.return
107107
}
108108

mlir/test/Dialect/LLVMIR/roundtrip.mlir

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -998,7 +998,7 @@ llvm.func @intrinsic_call_arg_attrs(%arg0: i32) -> i32 {
998998

999999
// CHECK-LABEL: intrinsic_call_arg_attrs_bundles
10001000
llvm.func @intrinsic_call_arg_attrs_bundles(%arg0: i32) -> i32 {
1001-
// CHECK: %{{.*}} = llvm.call_intrinsic "llvm.riscv.sha256sig0"({{.*}}) ["adazdazd"()] : (i32 {llvm.signext}) -> i32
1002-
%0 = llvm.call_intrinsic "llvm.riscv.sha256sig0"(%arg0) ["adazdazd"()] : (i32 {llvm.signext}) -> (i32)
1001+
// CHECK: %{{.*}} = llvm.call_intrinsic "llvm.riscv.sha256sig0"({{.*}}) ["adazdazd"()] {constant} : (i32 {llvm.signext}) -> i32
1002+
%0 = llvm.call_intrinsic "llvm.riscv.sha256sig0"(%arg0) ["adazdazd"()] {constant} : (i32 {llvm.signext}) -> (i32)
10031003
llvm.return %0 : i32
10041004
}

0 commit comments

Comments
 (0)