Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dialects (llvm): Add dense array constraint for the position attribute of llvm.extractvalue and llvm.insertvalue operations #3643

Merged
merged 3 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion tests/filecheck/dialects/llvm/invalid.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,29 @@ builtin.module {
// CHECK: Varargs specifier `...` must be at the end of the argument definition

// -----
// CHECK: -----

builtin.module {
%cc = "test.op"() {"cconv" = #llvm.cconv<invalid>} : () -> ()
}

// CHECK: Unknown calling convention

// -----

func.func public @main() {
%0 = "test.op"() : () -> (!llvm.struct<(i32)>)
%1 = "llvm.extractvalue"(%0) {"position" = array<i32: 0>} : (!llvm.struct<(i32)>) -> i32
func.return
}

// CHECK: Expected attribute i64 but got i32

// -----

func.func public @main() {
%0, %1 = "test.op"() : () -> (!llvm.struct<(i32)>, i32)
%2 = "llvm.insertvalue"(%0, %1) {"position" = array<i32: 0>} : (!llvm.struct<(i32)>, i32) -> !llvm.struct<(i32)>
func.return
}

// CHECK: Expected attribute i64 but got i32
4 changes: 4 additions & 0 deletions xdsl/dialects/builtin.py
Original file line number Diff line number Diff line change
Expand Up @@ -1248,6 +1248,10 @@ def __len__(self) -> int:
return len(self.data.data) // self.elt_type.size


DenseI64ArrayConstr = ParamAttrConstraint(DenseArrayBase, [i64, BytesAttr])
"""Type constraint for DenseArrays containing integers of i64 integers."""


@irdl_attr_definition
class FunctionType(ParametrizedAttribute, TypeAttribute):
name = "fun"
Expand Down
5 changes: 3 additions & 2 deletions xdsl/dialects/llvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
ArrayAttr,
ContainerType,
DenseArrayBase,
DenseI64ArrayConstr,
IndexType,
IntAttr,
IntegerAttr,
Expand Down Expand Up @@ -1262,7 +1263,7 @@ class ExtractValueOp(IRDLOperation):

name = "llvm.extractvalue"

position = prop_def(DenseArrayBase)
position = prop_def(DenseI64ArrayConstr)
container = operand_def(Attribute)

res = result_def(Attribute)
Expand Down Expand Up @@ -1292,7 +1293,7 @@ class InsertValueOp(IRDLOperation):

name = "llvm.insertvalue"

position = prop_def(DenseArrayBase)
position = prop_def(DenseI64ArrayConstr)
container = operand_def(Attribute)
value = operand_def(Attribute)

Expand Down
Loading