Skip to content

Commit

Permalink
dialects: (LLVM) Add bitcast op (#3776)
Browse files Browse the repository at this point in the history
Add the `llvm.bitcast` op
  • Loading branch information
AntonLydike authored Jan 22, 2025
1 parent d8543d1 commit 9cdc462
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
6 changes: 6 additions & 0 deletions tests/filecheck/dialects/llvm/example.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,10 @@ builtin.module {
// CHECK-NEXT: func.return
// CHECK-NEXT: }

%val = "test.op"() : () -> i32

%fval = llvm.bitcast %val : i32 to f32

// CHECK: %val = "test.op"() : () -> i32
// CHECK-NEXT: %fval = llvm.bitcast %val : i32 to f32
}
26 changes: 26 additions & 0 deletions xdsl/dialects/llvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -1710,10 +1710,36 @@ class ZeroOp(IRDLOperation):
res = result_def(LLVMTypeConstr)


@irdl_op_definition
class BitcastOp(IRDLOperation):
name = "llvm.bitcast"

arg = operand_def(Attribute)
"""
LLVM-compatible non-aggregate type
"""

result = result_def(Attribute)
"""
LLVM-compatible non-aggregate type
"""

traits = traits_def(NoMemoryEffect())

assembly_format = "$arg attr-dict `:` type($arg) `to` type($result)"

def __init__(self, val: Operation | SSAValue, res_type: Attribute):
super().__init__(
operands=[SSAValue.get(val)],
result_types=[res_type],
)


LLVM = Dialect(
"llvm",
[
AddOp,
BitcastOp,
SubOp,
MulOp,
UDivOp,
Expand Down

0 comments on commit 9cdc462

Please sign in to comment.