[Mlir-commits] [mlir] [mlir][emitc] Support 'emitc::LValueType' in 'emitc::VerbatimOp' (PR #144151)
Andrey Timonin
llvmlistbot at llvm.org
Mon Jun 16 02:39:41 PDT 2025
https://github.com/EtoAndruwa updated https://github.com/llvm/llvm-project/pull/144151
>From 60ee9b94d51f62a91b3b83ba4d984dde2e9c44ad Mon Sep 17 00:00:00 2001
From: EtoAndruwa <timonina1909 at gmail.com>
Date: Fri, 13 Jun 2025 22:10:05 +0300
Subject: [PATCH 1/2] [mlir][emitc] Support 'emitc::LValueType' in
'emitc::verbatimOp'
This PR introduces support for `emitc::LvalueType` in `emitc::VerbatimOp`,
providing a mechanism to reduce the number of operations required when
working with verbatim operations whose arguments are of type `emitc::LvalueType`.
An example of this would be:
```mlir
emitc.func @foo() {
%a = "emitc.variable"() <{value = #emitc.opaque<"1">}> : () -> !emitc.lvalue<i32>
emitc.verbatim "++{};" args %a : !emitc.lvalue<i32>
return
}
```
---
mlir/include/mlir/Dialect/EmitC/IR/EmitC.td | 2 +-
mlir/test/Dialect/EmitC/ops.mlir | 16 ++++++++++++----
2 files changed, 13 insertions(+), 5 deletions(-)
diff --git a/mlir/include/mlir/Dialect/EmitC/IR/EmitC.td b/mlir/include/mlir/Dialect/EmitC/IR/EmitC.td
index d4aea52a0d485..e53d3e45875d5 100644
--- a/mlir/include/mlir/Dialect/EmitC/IR/EmitC.td
+++ b/mlir/include/mlir/Dialect/EmitC/IR/EmitC.td
@@ -1304,7 +1304,7 @@ def EmitC_VerbatimOp : EmitC_Op<"verbatim"> {
FailureOr<SmallVector<::mlir::emitc::ReplacementItem>> parseFormatString();
}];
- let arguments = (ins StrAttr:$value, Variadic<EmitCType>:$fmtArgs);
+ let arguments = (ins StrAttr:$value, Variadic<AnyTypeOf<[EmitCType, EmitC_LValueType]>>:$fmtArgs);
let builders = [OpBuilder<(ins "::mlir::StringAttr":$value),
[{ build($_builder, $_state, value, {}); }]>];
diff --git a/mlir/test/Dialect/EmitC/ops.mlir b/mlir/test/Dialect/EmitC/ops.mlir
index 36d12e763afc7..2ca7c4bc3bbb5 100644
--- a/mlir/test/Dialect/EmitC/ops.mlir
+++ b/mlir/test/Dialect/EmitC/ops.mlir
@@ -246,12 +246,20 @@ emitc.verbatim "typedef float f32;"
// The value is not interpreted as format string if there are no operands.
emitc.verbatim "{} { }"
-func.func @test_verbatim(%arg0 : !emitc.ptr<i32>, %arg1 : i32) {
+func.func @test_verbatim(%arg0 : !emitc.ptr<i32>, %arg1 : i32, %arg3: !emitc.array<3x!emitc.ptr<i32>>) {
+ %a = "emitc.variable"() <{value = #emitc.opaque<"1">}> : () -> !emitc.lvalue<i32>
+
+ // Check that the lvalue type can be used by verbatim.
+ emitc.verbatim "++{};" args %a : !emitc.lvalue<i32>
+
+ // Check that the array type can be used by verbatim.
+ emitc.verbatim "*{}[0] = 1;" args %arg3 : !emitc.array<3x!emitc.ptr<i32>>
+
emitc.verbatim "{} + {};" args %arg0, %arg1 : !emitc.ptr<i32>, i32
- // Check there is no ambiguity whether %a is the argument to the emitc.verbatim op.
- emitc.verbatim "a"
- %a = "emitc.constant"(){value = 42 : i32} : () -> i32
+ // Check there is no ambiguity whether %b is the argument to the emitc.verbatim op.
+ emitc.verbatim "b"
+ %b = "emitc.constant"(){value = 42 : i32} : () -> i32
return
}
>From 65df1f8d18a1c5a1967c2c6f25ba75f5ef342c17 Mon Sep 17 00:00:00 2001
From: EtoAndruwa <timonina1909 at gmail.com>
Date: Mon, 16 Jun 2025 12:39:23 +0300
Subject: [PATCH 2/2] [mlir][emitc] Change arg name
---
mlir/test/Dialect/EmitC/ops.mlir | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/mlir/test/Dialect/EmitC/ops.mlir b/mlir/test/Dialect/EmitC/ops.mlir
index 2ca7c4bc3bbb5..ad40313f95df9 100644
--- a/mlir/test/Dialect/EmitC/ops.mlir
+++ b/mlir/test/Dialect/EmitC/ops.mlir
@@ -246,14 +246,14 @@ emitc.verbatim "typedef float f32;"
// The value is not interpreted as format string if there are no operands.
emitc.verbatim "{} { }"
-func.func @test_verbatim(%arg0 : !emitc.ptr<i32>, %arg1 : i32, %arg3: !emitc.array<3x!emitc.ptr<i32>>) {
+func.func @test_verbatim(%arg0 : !emitc.ptr<i32>, %arg1 : i32, %arg2: !emitc.array<3x!emitc.ptr<i32>>) {
%a = "emitc.variable"() <{value = #emitc.opaque<"1">}> : () -> !emitc.lvalue<i32>
// Check that the lvalue type can be used by verbatim.
emitc.verbatim "++{};" args %a : !emitc.lvalue<i32>
// Check that the array type can be used by verbatim.
- emitc.verbatim "*{}[0] = 1;" args %arg3 : !emitc.array<3x!emitc.ptr<i32>>
+ emitc.verbatim "*{}[0] = 1;" args %arg2 : !emitc.array<3x!emitc.ptr<i32>>
emitc.verbatim "{} + {};" args %arg0, %arg1 : !emitc.ptr<i32>, i32
More information about the Mlir-commits
mailing list