[Mlir-commits] [mlir] [MLIR][LLVM] Use oilist for llvm.load and llvm.store flags (PR #228977)
Arseniy Obolenskiy
llvmlistbot at llvm.org
Sun Oct 4 22:29:12 PDT 2026
https://github.com/aobolensk created https://github.com/llvm/llvm-project/pull/228977
Parse attributes in oilist clauses as required after the keyword
>From ddd963ee64c7fe6e2bfeca5aeaeb4f6412b9edd2 Mon Sep 17 00:00:00 2001
From: Arseniy Obolenskiy <arseniy.obolenskiy at amd.com>
Date: Mon, 5 Oct 2026 07:28:30 +0200
Subject: [PATCH] [MLIR][LLVM] Use oilist for llvm.load and llvm.store flags
Parse attributes in oilist clauses as required after the keyword
---
mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td | 10 ++++++----
mlir/test/Dialect/LLVMIR/roundtrip.mlir | 7 +++++++
mlir/test/Dialect/OpenMP/invalid.mlir | 2 +-
mlir/test/IR/traits.mlir | 18 ++++++++++++++++++
mlir/test/lib/Dialect/Test/TestOpsSyntax.td | 9 +++++++++
mlir/tools/mlir-tblgen/OpFormatGen.cpp | 2 +-
6 files changed, 42 insertions(+), 6 deletions(-)
diff --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td b/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
index a50a29bfc38ba..39d2952912c51 100644
--- a/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
+++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
@@ -425,9 +425,11 @@ def LLVM_LoadOp : LLVM_MemAccessOpBase<"load",
let assemblyFormat = [{
(`volatile` $volatile_^)? $addr
(`atomic` (`syncscope` `(` $syncscope^ `)`)? $ordering^)?
- (`invariant` $invariant^)?
- (`invariant_group` $invariantGroup^)?
- (`dereferenceable` `` $dereferenceable^)?
+ oilist(
+ `invariant` $invariant |
+ `invariant_group` $invariantGroup |
+ `dereferenceable` `` $dereferenceable
+ )
prop-dict
attr-dict `:` qualified(type($addr)) `->` type($res)
}];
@@ -513,7 +515,7 @@ def LLVM_StoreOp : LLVM_MemAccessOpBase<"store",
let assemblyFormat = [{
(`volatile` $volatile_^)? $value `,` $addr
(`atomic` (`syncscope` `(` $syncscope^ `)`)? $ordering^)?
- (`invariant_group` $invariantGroup^)?
+ oilist(`invariant_group` $invariantGroup)
prop-dict
attr-dict `:` type($value) `,` qualified(type($addr))
}];
diff --git a/mlir/test/Dialect/LLVMIR/roundtrip.mlir b/mlir/test/Dialect/LLVMIR/roundtrip.mlir
index 6ef571efe5c51..8485807e5c9c2 100644
--- a/mlir/test/Dialect/LLVMIR/roundtrip.mlir
+++ b/mlir/test/Dialect/LLVMIR/roundtrip.mlir
@@ -605,6 +605,13 @@ func.func @invariant_group_load(%ptr : !llvm.ptr) -> i32 {
func.return %0 : i32
}
+// CHECK-LABEL: @load_flags_any_order
+func.func @load_flags_any_order(%ptr : !llvm.ptr) -> !llvm.ptr {
+ // CHECK: llvm.load %{{.+}} invariant invariant_group dereferenceable<bytes = 4> : !llvm.ptr -> !llvm.ptr
+ %0 = llvm.load %ptr dereferenceable<bytes = 4> invariant_group invariant : !llvm.ptr -> !llvm.ptr
+ func.return %0 : !llvm.ptr
+}
+
// CHECK-LABEL: @invariant_group_store
func.func @invariant_group_store(%val: i32, %ptr : !llvm.ptr) {
// CHECK: llvm.store %{{.+}}, %{{.+}} invariant_group : i32, !llvm.ptr
diff --git a/mlir/test/Dialect/OpenMP/invalid.mlir b/mlir/test/Dialect/OpenMP/invalid.mlir
index c3fe4f60e4166..ad17f8167da68 100644
--- a/mlir/test/Dialect/OpenMP/invalid.mlir
+++ b/mlir/test/Dialect/OpenMP/invalid.mlir
@@ -3003,7 +3003,7 @@ func.func @omp_target_update_invalid_motion_type(%map1 : memref<?xi32>) {
// -----
func.func @omp_target_map_must_specify_both_var_ptr_ptr_args(%arg : memref<?xi32>) {
- %map1 = omp.map.info var_ptr(%arg : memref<?xi32>, tensor<?xi32>) map_clauses(to) capture(ByRef) var_ptr_ptr(%arg : memref<?xi32>, ) name("") -> memref<?xi32>
+ %map1 = "omp.map.info"(%arg, %arg) <{map_capture_type = #omp.variable_capture_kind<ByRef>, map_type = #omp.clause_map_flags<to>, name = "", operandSegmentSizes = array<i32: 1, 1, 0, 0>, partial_map = false, var_ptr_type = tensor<?xi32>}> : (memref<?xi32>, memref<?xi32>) -> memref<?xi32>
// expected-error @below {{if varPtrPtr or varPtrPtrType is specified, then both must be present}}
omp.target_update map_entries(%map1 : memref<?xi32>)
diff --git a/mlir/test/IR/traits.mlir b/mlir/test/IR/traits.mlir
index 5e5c2afe88cbd..648dce42ea597 100644
--- a/mlir/test/IR/traits.mlir
+++ b/mlir/test/IR/traits.mlir
@@ -600,6 +600,17 @@ func.func @succeededOilistTrivialProperties() {
// -----
+// CHECK-LABEL: @succeededOilistOptionalAttr
+func.func @succeededOilistOptionalAttr() {
+ // CHECK: test.oilist_optional_attr keyword nested <nested = <1, !test.smpla, [5, 6]>>
+ test.oilist_optional_attr nested <nested = <1, !test.smpla, [5, 6]>> keyword
+ // CHECK: test.oilist_optional_attr nested <nested = <1, !test.smpla, [5, 6]>>
+ test.oilist_optional_attr nested #test.cmpnd_nested<nested = <1, !test.smpla, [5, 6]>>
+ return
+}
+
+// -----
+
// CHECK-LABEL: @succeededOilistSimple
func.func @succeededOilistSimple(%arg0 : i32, %arg1 : i32, %arg2 : i32) {
// CHECK: test.oilist_with_simple_args keyword %{{.*}} : i32
@@ -690,6 +701,13 @@ func.func @failedOilistWithTrailingSeparator() {
// -----
+func.func @failedOilistOptionalAttrMissingValue() {
+ // expected-error at +1 {{expected '<'}}
+ test.oilist_optional_attr nested
+}
+
+// -----
+
func.func @failedHasDominanceScopeOutsideDominanceFreeScope() -> () {
"test.ssacfg_region"() ({
test.graph_region {
diff --git a/mlir/test/lib/Dialect/Test/TestOpsSyntax.td b/mlir/test/lib/Dialect/Test/TestOpsSyntax.td
index 8b0ded9ad27d9..f2d6ba3c5855e 100644
--- a/mlir/test/lib/Dialect/Test/TestOpsSyntax.td
+++ b/mlir/test/lib/Dialect/Test/TestOpsSyntax.td
@@ -147,6 +147,15 @@ def OIListWithSeparator : TEST_Op<"oilist_with_separator"> {
}];
}
+def OIListOptionalAttr : TEST_Op<"oilist_optional_attr"> {
+ let arguments = (ins UnitAttr:$keyword,
+ OptionalAttr<CompoundAttrNested>:$nested);
+ let assemblyFormat = [{
+ oilist( `keyword` $keyword
+ | `nested` $nested) attr-dict
+ }];
+}
+
def OIListAllowedLiteral : TEST_Op<"oilist_allowed_literal"> {
let assemblyFormat = [{
oilist( `foo` | `bar` ) `buzz` attr-dict
diff --git a/mlir/tools/mlir-tblgen/OpFormatGen.cpp b/mlir/tools/mlir-tblgen/OpFormatGen.cpp
index 33a7ac7c42244..a4798440cf28d 100644
--- a/mlir/tools/mlir-tblgen/OpFormatGen.cpp
+++ b/mlir/tools/mlir-tblgen/OpFormatGen.cpp
@@ -2032,7 +2032,7 @@ void OperationFormat::genElementParser(FormatElement *element, MethodBody &body,
}
} else {
for (FormatElement *el : pelement)
- genElementParser(el, body, attrTypeCtx);
+ genElementParser(el, body, attrTypeCtx, GenContext::Optional);
}
body << " } else ";
}
More information about the Mlir-commits
mailing list