Skip to content

Commit

Permalink
add llvm bitcast op
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonLydike committed Jan 21, 2025
1 parent 5c96c6e commit 53ad570
Show file tree
Hide file tree
Showing 2 changed files with 26 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
}
20 changes: 20 additions & 0 deletions xdsl/dialects/llvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -1710,10 +1710,30 @@ 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

res = operand_def(Attribute) # LLVM-compatible non-aggregate type

traits = traits_def(NoMemoryEffect())

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

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 53ad570

Please sign in to comment.