Skip to content

Convert op

convert_op

convert_op(op: Operation, builder: ir.IRBuilder, val_map: dict[SSAValue, ir.Value])

Convert an xDSL operation to an llvmlite LLVM IR.

Side effects

Mutates val_map by adding entries for the operation's results.

Parameters:

Name Type Description Default
op Operation

The xDSL operation to convert

required
builder IRBuilder

The LLVM IR builder for constructing instructions

required
val_map dict[SSAValue, Value]

The Mapping from xDSL SSA values to LLVM IR values. This dictionary is mutated to store the LLVM IR value produced by this operation for use by subsequent operations.

required

Raises:

Type Description
NotImplementedError

If the operation is not supported.

Source code in xdsl/backend/llvm/convert_op.py
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
def convert_op(
    op: Operation,
    builder: ir.IRBuilder,
    val_map: dict[SSAValue, ir.Value],
):
    """
    Convert an xDSL operation to an llvmlite LLVM IR.

    Side effects:
        Mutates val_map by adding entries for the operation's results.

    Args:
        op: The xDSL operation to convert
        builder: The LLVM IR builder for constructing instructions
        val_map: The Mapping from xDSL SSA values to LLVM IR values.
                 This dictionary is mutated to store the LLVM IR value produced by this operation for
                 use by subsequent operations.

    Raises:
        NotImplementedError: If the operation is not supported.
    """
    if (op_builder := _BINARY_OP_MAP.get(type(op))) is not None:
        val_map[op.results[0]] = op_builder(builder)(
            val_map[op.operands[0]], val_map[op.operands[1]]
        )
        return

    match op:
        case llvm.InlineAsmOp():
            _convert_inline_asm(op, builder, val_map)
        case llvm.ReturnOp():
            _convert_return(op, builder, val_map)
        case _:
            raise NotImplementedError(f"Conversion not implemented for op: {op.name}")