Skip to content

Llvm

llvm

GEP_USE_SSA_VAL = -2147483648 module-attribute

This is used in the getelementptr index list to signify that an ssa value should be used for this index.

ALL_ICMP_FLAGS = tuple(ICmpPredicateFlag) module-attribute

ICMP_INDEX_BY_FLAG = {f: i for i, f in (enumerate(ALL_ICMP_FLAGS))} module-attribute

LLVM_CALLING_CONVS: set[str] = {'ccc', 'fastcc', 'coldcc', 'cc 10', 'cc 11', 'webkit_jscc', 'anyregcc', 'preserve_mostcc', 'preserve_allcc', 'cxx_fast_tlscc', 'tailcc', 'swiftcc', 'swifttailcc', 'cfguard_checkcc'} module-attribute

A list of all valid calling conventions understood by LLVM, see external documentation here for more info.

LLVMType = LLVMStructType | LLVMPointerType | LLVMArrayType | LLVMVoidType | LLVMFunctionType module-attribute

LLVMTypeConstr = base(LLVMStructType) | base(LLVMPointerType) | base(LLVMArrayType) | base(LLVMVoidType) | base(LLVMFunctionType) module-attribute

LLVM = Dialect('llvm', [AShrOp, AddOp, AddressOfOp, AllocaOp, AndOp, BitcastOp, CallIntrinsicOp, CallOp, ConstantOp, ExtractValueOp, FAddOp, FDivOp, FMulOp, FPExtOp, FRemOp, FSubOp, FuncOp, GEPOp, GlobalOp, ICmpOp, InlineAsmOp, InsertValueOp, IntToPtrOp, LShrOp, LoadOp, MulOp, NullOp, OrOp, PtrToIntOp, ReturnOp, SDivOp, SExtOp, SIToFPOp, SRemOp, ShlOp, StoreOp, SubOp, TruncOp, UDivOp, URemOp, UndefOp, UnreachableOp, XOrOp, ZExtOp, ZeroOp], [CallingConventionAttr, FastMathAttr, FramePointerKindAttr, LLVMArrayType, LLVMFunctionType, LLVMPointerType, LLVMStructType, LLVMVoidType, LinkageAttr, OverflowAttr, TailCallKindAttr, TargetFeaturesAttr]) module-attribute

LLVMStructType dataclass

Bases: ParametrizedAttribute, TypeAttribute

See external documentation.

Source code in xdsl/dialects/llvm.py
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
@irdl_attr_definition
class LLVMStructType(ParametrizedAttribute, TypeAttribute):
    """
    See external [documentation](https://mlir.llvm.org/docs/Dialects/LLVM/#structure-types).
    """

    name = "llvm.struct"

    # An empty string refers to a struct without a name.
    struct_name: StringAttr
    types: ArrayAttr[Attribute]

    # TODO: Add this parameter once xDSL supports the necessary capabilities.
    #  bitmask: StringAttr

    @staticmethod
    def from_type_list(types: Sequence[Attribute]) -> LLVMStructType:
        return LLVMStructType(StringAttr(""), ArrayAttr(types))

    def print_parameters(self, printer: Printer) -> None:
        with printer.in_angle_brackets():
            if self.struct_name.data:
                printer.print_string_literal(self.struct_name.data)
                printer.print_string(", ")
            with printer.in_parens():
                printer.print_list(self.types.data, printer.print_attribute)

    @classmethod
    def parse_parameters(cls, parser: AttrParser) -> tuple[StringAttr, ArrayAttr]:
        parser.parse_characters("<", " in LLVM struct")
        struct_name = parser.parse_optional_str_literal()
        if struct_name is None:
            struct_name = ""
        else:
            parser.parse_characters(",", " after type")

        params = parser.parse_comma_separated_list(
            parser.Delimiter.PAREN, lambda: parse_llvm_type(parser)
        )
        parser.parse_characters(">", " to close LLVM struct parameters")
        return (StringAttr(struct_name), ArrayAttr(params))

name = 'llvm.struct' class-attribute instance-attribute

struct_name: StringAttr instance-attribute

types: ArrayAttr[Attribute] instance-attribute

from_type_list(types: Sequence[Attribute]) -> LLVMStructType staticmethod

Source code in xdsl/dialects/llvm.py
127
128
129
@staticmethod
def from_type_list(types: Sequence[Attribute]) -> LLVMStructType:
    return LLVMStructType(StringAttr(""), ArrayAttr(types))

print_parameters(printer: Printer) -> None

Source code in xdsl/dialects/llvm.py
131
132
133
134
135
136
137
def print_parameters(self, printer: Printer) -> None:
    with printer.in_angle_brackets():
        if self.struct_name.data:
            printer.print_string_literal(self.struct_name.data)
            printer.print_string(", ")
        with printer.in_parens():
            printer.print_list(self.types.data, printer.print_attribute)

parse_parameters(parser: AttrParser) -> tuple[StringAttr, ArrayAttr] classmethod

Source code in xdsl/dialects/llvm.py
139
140
141
142
143
144
145
146
147
148
149
150
151
152
@classmethod
def parse_parameters(cls, parser: AttrParser) -> tuple[StringAttr, ArrayAttr]:
    parser.parse_characters("<", " in LLVM struct")
    struct_name = parser.parse_optional_str_literal()
    if struct_name is None:
        struct_name = ""
    else:
        parser.parse_characters(",", " after type")

    params = parser.parse_comma_separated_list(
        parser.Delimiter.PAREN, lambda: parse_llvm_type(parser)
    )
    parser.parse_characters(">", " to close LLVM struct parameters")
    return (StringAttr(struct_name), ArrayAttr(params))

LLVMPointerType

Bases: ParametrizedAttribute, TypeAttribute

Source code in xdsl/dialects/llvm.py
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
@irdl_attr_definition
class LLVMPointerType(ParametrizedAttribute, TypeAttribute):
    name = "llvm.ptr"

    addr_space: IntAttr | NoneAttr

    def print_parameters(self, printer: Printer) -> None:
        if isinstance(self.addr_space, IntAttr):
            with printer.in_angle_brackets():
                printer.print_int(self.addr_space.data)

    @classmethod
    def parse_parameters(cls, parser: AttrParser) -> tuple[IntAttr | NoneAttr]:
        if parser.parse_optional_characters("<") is None:
            return (NoneAttr(),)
        addr_space = parser.parse_integer()
        parser.parse_characters(">", " to end llvm.ptr parameters")
        return (IntAttr(addr_space),)

    def __init__(self, addr_space: IntAttr | NoneAttr = NoneAttr()):
        super().__init__(addr_space)

name = 'llvm.ptr' class-attribute instance-attribute

addr_space: IntAttr | NoneAttr instance-attribute

print_parameters(printer: Printer) -> None

Source code in xdsl/dialects/llvm.py
161
162
163
164
def print_parameters(self, printer: Printer) -> None:
    if isinstance(self.addr_space, IntAttr):
        with printer.in_angle_brackets():
            printer.print_int(self.addr_space.data)

parse_parameters(parser: AttrParser) -> tuple[IntAttr | NoneAttr] classmethod

Source code in xdsl/dialects/llvm.py
166
167
168
169
170
171
172
@classmethod
def parse_parameters(cls, parser: AttrParser) -> tuple[IntAttr | NoneAttr]:
    if parser.parse_optional_characters("<") is None:
        return (NoneAttr(),)
    addr_space = parser.parse_integer()
    parser.parse_characters(">", " to end llvm.ptr parameters")
    return (IntAttr(addr_space),)

__init__(addr_space: IntAttr | NoneAttr = NoneAttr())

Source code in xdsl/dialects/llvm.py
174
175
def __init__(self, addr_space: IntAttr | NoneAttr = NoneAttr()):
    super().__init__(addr_space)

LLVMArrayType dataclass

Bases: ParametrizedAttribute, TypeAttribute

Source code in xdsl/dialects/llvm.py
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
@irdl_attr_definition
class LLVMArrayType(ParametrizedAttribute, TypeAttribute):
    name = "llvm.array"

    size: IntAttr = param_def(converter=IntAttr.get)
    type: Attribute

    def print_parameters(self, printer: Printer) -> None:
        with printer.in_angle_brackets():
            printer.print_int(self.size.data)
            printer.print_string(" x ")
            printer.print_attribute(self.type)

    @classmethod
    def parse_parameters(cls, parser: AttrParser) -> tuple[IntAttr, Attribute]:
        with parser.in_angle_brackets():
            size = IntAttr(parser.parse_integer())
            parser.parse_shape_delimiter()
            type = parse_llvm_type(parser)
        return (size, type)

    @deprecated("Please use LLVMArrayType(size, type)")
    @staticmethod
    def from_size_and_type(size: int | IntAttr, type: Attribute):
        return LLVMArrayType(size, type)

name = 'llvm.array' class-attribute instance-attribute

size: IntAttr = param_def(converter=(IntAttr.get)) class-attribute instance-attribute

type: Attribute instance-attribute

print_parameters(printer: Printer) -> None

Source code in xdsl/dialects/llvm.py
185
186
187
188
189
def print_parameters(self, printer: Printer) -> None:
    with printer.in_angle_brackets():
        printer.print_int(self.size.data)
        printer.print_string(" x ")
        printer.print_attribute(self.type)

parse_parameters(parser: AttrParser) -> tuple[IntAttr, Attribute] classmethod

Source code in xdsl/dialects/llvm.py
191
192
193
194
195
196
197
@classmethod
def parse_parameters(cls, parser: AttrParser) -> tuple[IntAttr, Attribute]:
    with parser.in_angle_brackets():
        size = IntAttr(parser.parse_integer())
        parser.parse_shape_delimiter()
        type = parse_llvm_type(parser)
    return (size, type)

from_size_and_type(size: int | IntAttr, type: Attribute) staticmethod

Source code in xdsl/dialects/llvm.py
199
200
201
202
@deprecated("Please use LLVMArrayType(size, type)")
@staticmethod
def from_size_and_type(size: int | IntAttr, type: Attribute):
    return LLVMArrayType(size, type)

LLVMVoidType dataclass

Bases: ParametrizedAttribute, TypeAttribute

Source code in xdsl/dialects/llvm.py
205
206
207
@irdl_attr_definition
class LLVMVoidType(ParametrizedAttribute, TypeAttribute):
    name = "llvm.void"

name = 'llvm.void' class-attribute instance-attribute

LLVMFunctionType

Bases: ParametrizedAttribute, TypeAttribute

Currently does not support variadics.

See external documentation.

Source code in xdsl/dialects/llvm.py
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
@irdl_attr_definition
class LLVMFunctionType(ParametrizedAttribute, TypeAttribute):
    """
    Currently does not support variadics.

    See external [documentation](https://mlir.llvm.org/docs/Dialects/LLVM/#function-types).
    """

    name = "llvm.func"

    inputs: ArrayAttr[Attribute]
    output: Attribute
    variadic: UnitAttr | NoneAttr

    def __init__(
        self,
        inputs: Sequence[Attribute] | ArrayAttr[Attribute],
        output: Attribute | None = None,
        is_variadic: bool = False,
    ) -> None:
        if not isinstance(inputs, ArrayAttr):
            inputs = ArrayAttr(inputs)
        if output is None:
            output = LLVMVoidType()
        variad_attr = UnitAttr() if is_variadic else NoneAttr()
        super().__init__(inputs, output, variad_attr)

    @property
    def is_variadic(self) -> bool:
        return isinstance(self.variadic, UnitAttr)

    def print_parameters(self, printer: Printer) -> None:
        with printer.in_angle_brackets():
            if isinstance(self.output, LLVMVoidType):
                printer.print_string("void")
            else:
                printer.print_attribute(self.output)

            printer.print_string(" ")
            with printer.in_parens():
                printer.print_list(self.inputs, printer.print_attribute)
                if self.is_variadic:
                    if self.inputs:
                        printer.print_string(", ")
                    printer.print_string("...")

    @classmethod
    def parse_parameters(cls, parser: AttrParser) -> list[Attribute]:
        parser.parse_characters("<", " in llvm.func parameters")
        output = parse_llvm_type(parser)

        # save pos before args for error message printing
        pos = parser.pos

        def _parse_attr_or_variadic() -> Attribute | EllipsisType:
            """
            This returns either an attribute, or Ellipsis if a
            varargs specifier (`...`) was parsed.
            """
            if parser.parse_optional_characters("...") is not None:
                return ...
            return parse_llvm_type(parser)

        inputs = parser.parse_comma_separated_list(
            Parser.Delimiter.PAREN, _parse_attr_or_variadic
        )
        is_varargs: NoneAttr | UnitAttr = NoneAttr()
        if inputs and inputs[-1] is Ellipsis:
            is_varargs = UnitAttr()
            inputs = inputs[:-1]

        if not isa(inputs, list[Attribute]):
            parser.raise_error(
                "Varargs specifier `...` must be at the end of the argument definition",
                pos,
                parser.pos,
            )

        parser.parse_characters(">", " in llvm.func parameters")

        return [ArrayAttr(inputs), output, is_varargs]

name = 'llvm.func' class-attribute instance-attribute

inputs: ArrayAttr[Attribute] instance-attribute

output: Attribute instance-attribute

variadic: UnitAttr | NoneAttr instance-attribute

is_variadic: bool property

__init__(inputs: Sequence[Attribute] | ArrayAttr[Attribute], output: Attribute | None = None, is_variadic: bool = False) -> None

Source code in xdsl/dialects/llvm.py
224
225
226
227
228
229
230
231
232
233
234
235
def __init__(
    self,
    inputs: Sequence[Attribute] | ArrayAttr[Attribute],
    output: Attribute | None = None,
    is_variadic: bool = False,
) -> None:
    if not isinstance(inputs, ArrayAttr):
        inputs = ArrayAttr(inputs)
    if output is None:
        output = LLVMVoidType()
    variad_attr = UnitAttr() if is_variadic else NoneAttr()
    super().__init__(inputs, output, variad_attr)

print_parameters(printer: Printer) -> None

Source code in xdsl/dialects/llvm.py
241
242
243
244
245
246
247
248
249
250
251
252
253
254
def print_parameters(self, printer: Printer) -> None:
    with printer.in_angle_brackets():
        if isinstance(self.output, LLVMVoidType):
            printer.print_string("void")
        else:
            printer.print_attribute(self.output)

        printer.print_string(" ")
        with printer.in_parens():
            printer.print_list(self.inputs, printer.print_attribute)
            if self.is_variadic:
                if self.inputs:
                    printer.print_string(", ")
                printer.print_string("...")

parse_parameters(parser: AttrParser) -> list[Attribute] classmethod

Source code in xdsl/dialects/llvm.py
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
@classmethod
def parse_parameters(cls, parser: AttrParser) -> list[Attribute]:
    parser.parse_characters("<", " in llvm.func parameters")
    output = parse_llvm_type(parser)

    # save pos before args for error message printing
    pos = parser.pos

    def _parse_attr_or_variadic() -> Attribute | EllipsisType:
        """
        This returns either an attribute, or Ellipsis if a
        varargs specifier (`...`) was parsed.
        """
        if parser.parse_optional_characters("...") is not None:
            return ...
        return parse_llvm_type(parser)

    inputs = parser.parse_comma_separated_list(
        Parser.Delimiter.PAREN, _parse_attr_or_variadic
    )
    is_varargs: NoneAttr | UnitAttr = NoneAttr()
    if inputs and inputs[-1] is Ellipsis:
        is_varargs = UnitAttr()
        inputs = inputs[:-1]

    if not isa(inputs, list[Attribute]):
        parser.raise_error(
            "Varargs specifier `...` must be at the end of the argument definition",
            pos,
            parser.pos,
        )

    parser.parse_characters(">", " in llvm.func parameters")

    return [ArrayAttr(inputs), output, is_varargs]

LinkageAttr

Bases: ParametrizedAttribute

Source code in xdsl/dialects/llvm.py
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
@irdl_attr_definition
class LinkageAttr(ParametrizedAttribute):
    name = "llvm.linkage"

    linkage: StringAttr

    def __init__(self, linkage: str | StringAttr) -> None:
        if isinstance(linkage, str):
            linkage = StringAttr(linkage)
        super().__init__(linkage)

    def print_parameters(self, printer: Printer) -> None:
        printer.print_string("<")
        printer.print_attribute(self.linkage)
        printer.print_string(">")

    @classmethod
    def parse_parameters(cls, parser: AttrParser) -> list[Attribute]:
        parser.parse_characters("<", "llvm.linkage parameter expected")
        # The linkage string is output from xDSL as a string (and accepted by MLIR as such)
        # however it is always output from MLIR without quotes. Therefore need to determine
        # whether this is a string or not and slightly change how we parse based upon that
        linkage_str = parser.parse_optional_str_literal()
        if linkage_str is None:
            linkage_str = parser.parse_identifier()
        linkage = StringAttr(linkage_str)
        parser.parse_characters(">", " to end llvm.linkage parameters")
        return [linkage]

    def verify(self):
        allowed_linkage = [
            "private",
            "internal",
            "available_externally",
            "linkonce",
            "weak",
            "common",
            "appending",
            "extern_weak",
            "linkonce_odr",
            "weak_odr",
            "external",
        ]
        if self.linkage.data not in allowed_linkage:
            raise VerifyException(f"Specified linkage '{self.linkage.data}' is unknown")

name = 'llvm.linkage' class-attribute instance-attribute

linkage: StringAttr instance-attribute

__init__(linkage: str | StringAttr) -> None

Source code in xdsl/dialects/llvm.py
299
300
301
302
def __init__(self, linkage: str | StringAttr) -> None:
    if isinstance(linkage, str):
        linkage = StringAttr(linkage)
    super().__init__(linkage)

print_parameters(printer: Printer) -> None

Source code in xdsl/dialects/llvm.py
304
305
306
307
def print_parameters(self, printer: Printer) -> None:
    printer.print_string("<")
    printer.print_attribute(self.linkage)
    printer.print_string(">")

parse_parameters(parser: AttrParser) -> list[Attribute] classmethod

Source code in xdsl/dialects/llvm.py
309
310
311
312
313
314
315
316
317
318
319
320
@classmethod
def parse_parameters(cls, parser: AttrParser) -> list[Attribute]:
    parser.parse_characters("<", "llvm.linkage parameter expected")
    # The linkage string is output from xDSL as a string (and accepted by MLIR as such)
    # however it is always output from MLIR without quotes. Therefore need to determine
    # whether this is a string or not and slightly change how we parse based upon that
    linkage_str = parser.parse_optional_str_literal()
    if linkage_str is None:
        linkage_str = parser.parse_identifier()
    linkage = StringAttr(linkage_str)
    parser.parse_characters(">", " to end llvm.linkage parameters")
    return [linkage]

verify()

Source code in xdsl/dialects/llvm.py
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
def verify(self):
    allowed_linkage = [
        "private",
        "internal",
        "available_externally",
        "linkonce",
        "weak",
        "common",
        "appending",
        "extern_weak",
        "linkonce_odr",
        "weak_odr",
        "external",
    ]
    if self.linkage.data not in allowed_linkage:
        raise VerifyException(f"Specified linkage '{self.linkage.data}' is unknown")

ArithmeticBinOperation

Bases: IRDLOperation, ABC

Class for arithmetic binary operations.

Source code in xdsl/dialects/llvm.py
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
class ArithmeticBinOperation(IRDLOperation, ABC):
    """Class for arithmetic binary operations."""

    T: ClassVar = VarConstraint(
        "T", SignlessIntegerConstraint | VectorType.constr(SignlessIntegerConstraint)
    )

    lhs = operand_def(T)
    rhs = operand_def(T)
    res = result_def(T)

    traits = traits_def(NoMemoryEffect())

    def __init__(
        self,
        lhs: SSAValue,
        rhs: SSAValue,
        attributes: dict[str, Attribute] = {},
    ):
        super().__init__(
            operands=[lhs, rhs],
            attributes=attributes,
            result_types=[lhs.type],
        )

    @classmethod
    def parse(cls, parser: Parser):
        lhs = parser.parse_unresolved_operand()
        parser.parse_characters(",")
        rhs = parser.parse_unresolved_operand()
        attributes = parser.parse_optional_attr_dict()
        parser.parse_characters(":")
        type = parser.parse_type()
        operands = parser.resolve_operands([lhs, rhs], [type, type], parser.pos)
        return cls(operands[0], operands[1], attributes)

    def print(self, printer: Printer) -> None:
        printer.print_string(" ")
        printer.print_ssa_value(self.lhs)
        printer.print_string(", ")
        printer.print_ssa_value(self.rhs)
        printer.print_op_attributes(self.attributes)
        printer.print_string(" : ")
        printer.print_attribute(self.lhs.type)

T: ClassVar = VarConstraint('T', SignlessIntegerConstraint | VectorType.constr(SignlessIntegerConstraint)) class-attribute instance-attribute

lhs = operand_def(T) class-attribute instance-attribute

rhs = operand_def(T) class-attribute instance-attribute

res = result_def(T) class-attribute instance-attribute

traits = traits_def(NoMemoryEffect()) class-attribute instance-attribute

__init__(lhs: SSAValue, rhs: SSAValue, attributes: dict[str, Attribute] = {})

Source code in xdsl/dialects/llvm.py
353
354
355
356
357
358
359
360
361
362
363
def __init__(
    self,
    lhs: SSAValue,
    rhs: SSAValue,
    attributes: dict[str, Attribute] = {},
):
    super().__init__(
        operands=[lhs, rhs],
        attributes=attributes,
        result_types=[lhs.type],
    )

parse(parser: Parser) classmethod

Source code in xdsl/dialects/llvm.py
365
366
367
368
369
370
371
372
373
374
@classmethod
def parse(cls, parser: Parser):
    lhs = parser.parse_unresolved_operand()
    parser.parse_characters(",")
    rhs = parser.parse_unresolved_operand()
    attributes = parser.parse_optional_attr_dict()
    parser.parse_characters(":")
    type = parser.parse_type()
    operands = parser.resolve_operands([lhs, rhs], [type, type], parser.pos)
    return cls(operands[0], operands[1], attributes)

print(printer: Printer) -> None

Source code in xdsl/dialects/llvm.py
376
377
378
379
380
381
382
383
def print(self, printer: Printer) -> None:
    printer.print_string(" ")
    printer.print_ssa_value(self.lhs)
    printer.print_string(", ")
    printer.print_ssa_value(self.rhs)
    printer.print_op_attributes(self.attributes)
    printer.print_string(" : ")
    printer.print_attribute(self.lhs.type)

OverflowFlag

Bases: StrEnum

Source code in xdsl/dialects/llvm.py
386
387
388
class OverflowFlag(StrEnum):
    NO_SIGNED_WRAP = "nsw"
    NO_UNSIGNED_WRAP = "nuw"

NO_SIGNED_WRAP = 'nsw' class-attribute instance-attribute

NO_UNSIGNED_WRAP = 'nuw' class-attribute instance-attribute

OverflowAttrBase dataclass

Bases: BitEnumAttribute[OverflowFlag]

Source code in xdsl/dialects/llvm.py
391
392
393
@dataclass(frozen=True, init=False)
class OverflowAttrBase(BitEnumAttribute[OverflowFlag]):
    none_value = "none"

none_value = 'none' class-attribute instance-attribute

__init__(data: DataElement) -> None

OverflowAttr dataclass

Bases: OverflowAttrBase

Source code in xdsl/dialects/llvm.py
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
@irdl_attr_definition(init=False)
class OverflowAttr(OverflowAttrBase):
    name = "llvm.overflow"

    @classmethod
    def parse(cls, parser: Parser) -> OverflowAttr:
        if parser.parse_optional_keyword("overflow") is not None:
            return OverflowAttr(OverflowAttr.parse_parameter(parser))
        return OverflowAttr("none")

    def print(self, printer: Printer):
        if self.flags:
            printer.print_string(" overflow")
            self.print_parameter(printer)

    def to_int(self) -> int:
        if len(self.data) == 0:
            return 0
        if len(self.data) == 2:
            return 3
        if self.data[0] == OverflowFlag.NO_SIGNED_WRAP:
            return 1
        return 2

    @staticmethod
    def from_int(i: int) -> OverflowAttr:
        match i:
            case 0:
                return OverflowAttr("none")
            case 1:
                return OverflowAttr((OverflowFlag.NO_SIGNED_WRAP,))
            case 2:
                return OverflowAttr((OverflowFlag.NO_UNSIGNED_WRAP,))
            case 3:
                return OverflowAttr(
                    (OverflowFlag.NO_SIGNED_WRAP, OverflowFlag.NO_UNSIGNED_WRAP)
                )
            case _:
                raise ValueError("OverflowAttr given out of bounds integer.")

name = 'llvm.overflow' class-attribute instance-attribute

parse(parser: Parser) -> OverflowAttr classmethod

Source code in xdsl/dialects/llvm.py
400
401
402
403
404
@classmethod
def parse(cls, parser: Parser) -> OverflowAttr:
    if parser.parse_optional_keyword("overflow") is not None:
        return OverflowAttr(OverflowAttr.parse_parameter(parser))
    return OverflowAttr("none")

print(printer: Printer)

Source code in xdsl/dialects/llvm.py
406
407
408
409
def print(self, printer: Printer):
    if self.flags:
        printer.print_string(" overflow")
        self.print_parameter(printer)

to_int() -> int

Source code in xdsl/dialects/llvm.py
411
412
413
414
415
416
417
418
def to_int(self) -> int:
    if len(self.data) == 0:
        return 0
    if len(self.data) == 2:
        return 3
    if self.data[0] == OverflowFlag.NO_SIGNED_WRAP:
        return 1
    return 2

from_int(i: int) -> OverflowAttr staticmethod

Source code in xdsl/dialects/llvm.py
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
@staticmethod
def from_int(i: int) -> OverflowAttr:
    match i:
        case 0:
            return OverflowAttr("none")
        case 1:
            return OverflowAttr((OverflowFlag.NO_SIGNED_WRAP,))
        case 2:
            return OverflowAttr((OverflowFlag.NO_UNSIGNED_WRAP,))
        case 3:
            return OverflowAttr(
                (OverflowFlag.NO_SIGNED_WRAP, OverflowFlag.NO_UNSIGNED_WRAP)
            )
        case _:
            raise ValueError("OverflowAttr given out of bounds integer.")

ArithmeticBinOpOverflow

Bases: IRDLOperation, ABC

Class for arithmetic binary operations that use overflow flags.

Source code in xdsl/dialects/llvm.py
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
class ArithmeticBinOpOverflow(IRDLOperation, ABC):
    """Class for arithmetic binary operations that use overflow flags."""

    T: ClassVar = VarConstraint(
        "T", SignlessIntegerConstraint | VectorType.constr(SignlessIntegerConstraint)
    )

    lhs = operand_def(T)
    rhs = operand_def(T)
    res = result_def(T)
    overflowFlags = opt_prop_def(IntegerAttr[I32])

    traits = traits_def(NoMemoryEffect())

    def __init__(
        self,
        lhs: SSAValue,
        rhs: SSAValue,
        attributes: dict[str, Attribute] = {},
        overflow: OverflowAttr | IntegerAttr = IntegerAttr(0, 32),
    ):
        if isinstance(overflow, OverflowAttr):
            overflow = IntegerAttr(overflow.to_int(), 32)
        super().__init__(
            operands=[lhs, rhs],
            attributes=attributes,
            result_types=[lhs.type],
            properties={
                "overflowFlags": overflow,
            },
        )

    @classmethod
    def parse(cls, parser: Parser):
        lhs = parser.parse_unresolved_operand()
        parser.parse_characters(",")
        rhs = parser.parse_unresolved_operand()
        overflowFlags = OverflowAttr.parse(parser)
        attributes = parser.parse_optional_attr_dict()
        parser.parse_characters(":")
        type = parser.parse_type()
        operands = parser.resolve_operands([lhs, rhs], [type, type], parser.pos)
        return cls(operands[0], operands[1], attributes, overflowFlags)

    def print(self, printer: Printer) -> None:
        printer.print_string(" ")
        printer.print_ssa_value(self.lhs)
        printer.print_string(", ")
        printer.print_ssa_value(self.rhs)
        if self.overflowFlags:
            OverflowAttr.from_int(self.overflowFlags.value.data).print(printer)
        printer.print_op_attributes(self.attributes)
        printer.print_string(" : ")
        printer.print_attribute(self.lhs.type)

T: ClassVar = VarConstraint('T', SignlessIntegerConstraint | VectorType.constr(SignlessIntegerConstraint)) class-attribute instance-attribute

lhs = operand_def(T) class-attribute instance-attribute

rhs = operand_def(T) class-attribute instance-attribute

res = result_def(T) class-attribute instance-attribute

overflowFlags = opt_prop_def(IntegerAttr[I32]) class-attribute instance-attribute

traits = traits_def(NoMemoryEffect()) class-attribute instance-attribute

__init__(lhs: SSAValue, rhs: SSAValue, attributes: dict[str, Attribute] = {}, overflow: OverflowAttr | IntegerAttr = IntegerAttr(0, 32))

Source code in xdsl/dialects/llvm.py
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
def __init__(
    self,
    lhs: SSAValue,
    rhs: SSAValue,
    attributes: dict[str, Attribute] = {},
    overflow: OverflowAttr | IntegerAttr = IntegerAttr(0, 32),
):
    if isinstance(overflow, OverflowAttr):
        overflow = IntegerAttr(overflow.to_int(), 32)
    super().__init__(
        operands=[lhs, rhs],
        attributes=attributes,
        result_types=[lhs.type],
        properties={
            "overflowFlags": overflow,
        },
    )

parse(parser: Parser) classmethod

Source code in xdsl/dialects/llvm.py
469
470
471
472
473
474
475
476
477
478
479
@classmethod
def parse(cls, parser: Parser):
    lhs = parser.parse_unresolved_operand()
    parser.parse_characters(",")
    rhs = parser.parse_unresolved_operand()
    overflowFlags = OverflowAttr.parse(parser)
    attributes = parser.parse_optional_attr_dict()
    parser.parse_characters(":")
    type = parser.parse_type()
    operands = parser.resolve_operands([lhs, rhs], [type, type], parser.pos)
    return cls(operands[0], operands[1], attributes, overflowFlags)

print(printer: Printer) -> None

Source code in xdsl/dialects/llvm.py
481
482
483
484
485
486
487
488
489
490
def print(self, printer: Printer) -> None:
    printer.print_string(" ")
    printer.print_ssa_value(self.lhs)
    printer.print_string(", ")
    printer.print_ssa_value(self.rhs)
    if self.overflowFlags:
        OverflowAttr.from_int(self.overflowFlags.value.data).print(printer)
    printer.print_op_attributes(self.attributes)
    printer.print_string(" : ")
    printer.print_attribute(self.lhs.type)

ArithmeticBinOpExact

Bases: IRDLOperation, ABC

Class for arithmetic binary operations that use an exact flag.

Source code in xdsl/dialects/llvm.py
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
class ArithmeticBinOpExact(IRDLOperation, ABC):
    """Class for arithmetic binary operations that use an exact flag."""

    T: ClassVar = VarConstraint(
        "T", SignlessIntegerConstraint | VectorType.constr(SignlessIntegerConstraint)
    )

    lhs = operand_def(T)
    rhs = operand_def(T)
    res = result_def(T)
    is_exact = opt_prop_def(UnitAttr, prop_name="isExact")

    traits = traits_def(NoMemoryEffect())

    def __init__(
        self,
        lhs: SSAValue,
        rhs: SSAValue,
        attributes: dict[str, Attribute] = {},
        is_exact: UnitAttr | None = None,
    ):
        super().__init__(
            operands=[lhs, rhs],
            attributes=attributes,
            result_types=[lhs.type],
            properties={
                "isExact": is_exact,
            },
        )

    @classmethod
    def parse_exact(cls, parser: Parser):
        if parser.parse_optional_keyword("exact") is not None:
            return UnitAttr()

    def print_exact(self, printer: Printer) -> None:
        if self.is_exact:
            printer.print_string(" exact")

    @classmethod
    def parse(cls, parser: Parser):
        exact = cls.parse_exact(parser)
        lhs = parser.parse_unresolved_operand()
        parser.parse_characters(",")
        rhs = parser.parse_unresolved_operand()
        attributes = parser.parse_optional_attr_dict()
        parser.parse_characters(":")
        type = parser.parse_type()
        operands = parser.resolve_operands([lhs, rhs], [type, type], parser.pos)
        return cls(operands[0], operands[1], attributes, exact)

    def print(self, printer: Printer) -> None:
        self.print_exact(printer)
        printer.print_string(" ")
        printer.print_ssa_value(self.lhs)
        printer.print_string(", ")
        printer.print_ssa_value(self.rhs)
        printer.print_op_attributes(self.attributes)
        printer.print_string(" : ")
        printer.print_attribute(self.lhs.type)

T: ClassVar = VarConstraint('T', SignlessIntegerConstraint | VectorType.constr(SignlessIntegerConstraint)) class-attribute instance-attribute

lhs = operand_def(T) class-attribute instance-attribute

rhs = operand_def(T) class-attribute instance-attribute

res = result_def(T) class-attribute instance-attribute

is_exact = opt_prop_def(UnitAttr, prop_name='isExact') class-attribute instance-attribute

traits = traits_def(NoMemoryEffect()) class-attribute instance-attribute

__init__(lhs: SSAValue, rhs: SSAValue, attributes: dict[str, Attribute] = {}, is_exact: UnitAttr | None = None)

Source code in xdsl/dialects/llvm.py
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
def __init__(
    self,
    lhs: SSAValue,
    rhs: SSAValue,
    attributes: dict[str, Attribute] = {},
    is_exact: UnitAttr | None = None,
):
    super().__init__(
        operands=[lhs, rhs],
        attributes=attributes,
        result_types=[lhs.type],
        properties={
            "isExact": is_exact,
        },
    )

parse_exact(parser: Parser) classmethod

Source code in xdsl/dialects/llvm.py
523
524
525
526
@classmethod
def parse_exact(cls, parser: Parser):
    if parser.parse_optional_keyword("exact") is not None:
        return UnitAttr()

print_exact(printer: Printer) -> None

Source code in xdsl/dialects/llvm.py
528
529
530
def print_exact(self, printer: Printer) -> None:
    if self.is_exact:
        printer.print_string(" exact")

parse(parser: Parser) classmethod

Source code in xdsl/dialects/llvm.py
532
533
534
535
536
537
538
539
540
541
542
@classmethod
def parse(cls, parser: Parser):
    exact = cls.parse_exact(parser)
    lhs = parser.parse_unresolved_operand()
    parser.parse_characters(",")
    rhs = parser.parse_unresolved_operand()
    attributes = parser.parse_optional_attr_dict()
    parser.parse_characters(":")
    type = parser.parse_type()
    operands = parser.resolve_operands([lhs, rhs], [type, type], parser.pos)
    return cls(operands[0], operands[1], attributes, exact)

print(printer: Printer) -> None

Source code in xdsl/dialects/llvm.py
544
545
546
547
548
549
550
551
552
def print(self, printer: Printer) -> None:
    self.print_exact(printer)
    printer.print_string(" ")
    printer.print_ssa_value(self.lhs)
    printer.print_string(", ")
    printer.print_ssa_value(self.rhs)
    printer.print_op_attributes(self.attributes)
    printer.print_string(" : ")
    printer.print_attribute(self.lhs.type)

ArithmeticBinOpDisjoint

Bases: IRDLOperation, ABC

Class for arithmetic binary operations that use a disjoint flag.

Source code in xdsl/dialects/llvm.py
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
class ArithmeticBinOpDisjoint(IRDLOperation, ABC):
    """Class for arithmetic binary operations that use a disjoint flag."""

    T: ClassVar = VarConstraint(
        "T", SignlessIntegerConstraint | VectorType.constr(SignlessIntegerConstraint)
    )

    lhs = operand_def(T)
    rhs = operand_def(T)
    res = result_def(T)
    is_disjoint = opt_prop_def(UnitAttr, prop_name="isDisjoint")

    traits = traits_def(NoMemoryEffect())

    assembly_format = (
        "(`disjoint` $isDisjoint^)? $lhs `,` $rhs attr-dict `:` type($res)"
    )

    def __init__(
        self,
        lhs: SSAValue,
        rhs: SSAValue,
        attributes: dict[str, Attribute] = {},
        is_disjoint: UnitAttr | None = None,
    ):
        super().__init__(
            operands=[lhs, rhs],
            attributes=attributes,
            result_types=[lhs.type],
            properties={
                "isDisjoint": is_disjoint,
            },
        )

T: ClassVar = VarConstraint('T', SignlessIntegerConstraint | VectorType.constr(SignlessIntegerConstraint)) class-attribute instance-attribute

lhs = operand_def(T) class-attribute instance-attribute

rhs = operand_def(T) class-attribute instance-attribute

res = result_def(T) class-attribute instance-attribute

is_disjoint = opt_prop_def(UnitAttr, prop_name='isDisjoint') class-attribute instance-attribute

traits = traits_def(NoMemoryEffect()) class-attribute instance-attribute

assembly_format = '(`disjoint` $isDisjoint^)? $lhs `,` $rhs attr-dict `:` type($res)' class-attribute instance-attribute

__init__(lhs: SSAValue, rhs: SSAValue, attributes: dict[str, Attribute] = {}, is_disjoint: UnitAttr | None = None)

Source code in xdsl/dialects/llvm.py
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
def __init__(
    self,
    lhs: SSAValue,
    rhs: SSAValue,
    attributes: dict[str, Attribute] = {},
    is_disjoint: UnitAttr | None = None,
):
    super().__init__(
        operands=[lhs, rhs],
        attributes=attributes,
        result_types=[lhs.type],
        properties={
            "isDisjoint": is_disjoint,
        },
    )

IntegerConversionOp

Bases: IRDLOperation, ABC

Source code in xdsl/dialects/llvm.py
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
class IntegerConversionOp(IRDLOperation, ABC):
    arg = operand_def(
        SignlessIntegerConstraint | VectorType.constr(SignlessIntegerConstraint)
    )

    res = result_def(
        SignlessIntegerConstraint | VectorType.constr(SignlessIntegerConstraint)
    )

    traits = traits_def(NoMemoryEffect())

    def __init__(
        self,
        arg: SSAValue,
        res_type: Attribute,
        attributes: dict[str, Attribute] = {},
    ):
        super().__init__(operands=[arg], attributes=attributes, result_types=[res_type])

    @classmethod
    def parse(cls, parser: Parser):
        arg = parser.parse_unresolved_operand()
        attributes = parser.parse_optional_attr_dict()
        parser.parse_characters(":")
        arg_type = parser.parse_type()
        parser.parse_characters("to")
        res_type = parser.parse_type()
        operands = parser.resolve_operands([arg], [arg_type], parser.pos)
        return cls(operands[0], res_type, attributes)

    def print(self, printer: Printer):
        printer.print_string(" ")
        printer.print_ssa_value(self.arg)
        printer.print_op_attributes(self.attributes)
        printer.print_string(" : ")
        printer.print_attribute(self.arg.type)
        printer.print_string(" to ")
        printer.print_attribute(self.res.type)

arg = operand_def(SignlessIntegerConstraint | VectorType.constr(SignlessIntegerConstraint)) class-attribute instance-attribute

res = result_def(SignlessIntegerConstraint | VectorType.constr(SignlessIntegerConstraint)) class-attribute instance-attribute

traits = traits_def(NoMemoryEffect()) class-attribute instance-attribute

__init__(arg: SSAValue, res_type: Attribute, attributes: dict[str, Attribute] = {})

Source code in xdsl/dialects/llvm.py
601
602
603
604
605
606
607
def __init__(
    self,
    arg: SSAValue,
    res_type: Attribute,
    attributes: dict[str, Attribute] = {},
):
    super().__init__(operands=[arg], attributes=attributes, result_types=[res_type])

parse(parser: Parser) classmethod

Source code in xdsl/dialects/llvm.py
609
610
611
612
613
614
615
616
617
618
@classmethod
def parse(cls, parser: Parser):
    arg = parser.parse_unresolved_operand()
    attributes = parser.parse_optional_attr_dict()
    parser.parse_characters(":")
    arg_type = parser.parse_type()
    parser.parse_characters("to")
    res_type = parser.parse_type()
    operands = parser.resolve_operands([arg], [arg_type], parser.pos)
    return cls(operands[0], res_type, attributes)

print(printer: Printer)

Source code in xdsl/dialects/llvm.py
620
621
622
623
624
625
626
627
def print(self, printer: Printer):
    printer.print_string(" ")
    printer.print_ssa_value(self.arg)
    printer.print_op_attributes(self.attributes)
    printer.print_string(" : ")
    printer.print_attribute(self.arg.type)
    printer.print_string(" to ")
    printer.print_attribute(self.res.type)

IntegerConversionOpNNeg

Bases: IRDLOperation, ABC

Source code in xdsl/dialects/llvm.py
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
class IntegerConversionOpNNeg(IRDLOperation, ABC):
    arg = operand_def(
        SignlessIntegerConstraint | VectorType.constr(SignlessIntegerConstraint)
    )
    res = result_def(
        SignlessIntegerConstraint | VectorType.constr(SignlessIntegerConstraint)
    )
    traits = traits_def(NoMemoryEffect())
    non_neg = opt_prop_def(UnitAttr, prop_name="nonNeg")

    assembly_format = "(`nneg` $nonNeg^)? $arg attr-dict `:` type($arg) `to` type($res)"

    def __init__(
        self,
        arg: SSAValue,
        res_type: Attribute,
        attributes: dict[str, Attribute] = {},
        non_neg: UnitAttr | None = None,
    ):
        super().__init__(
            operands=(arg,),
            attributes=attributes,
            result_types=(res_type,),
            properties={
                "nonNeg": non_neg,
            },
        )

arg = operand_def(SignlessIntegerConstraint | VectorType.constr(SignlessIntegerConstraint)) class-attribute instance-attribute

res = result_def(SignlessIntegerConstraint | VectorType.constr(SignlessIntegerConstraint)) class-attribute instance-attribute

traits = traits_def(NoMemoryEffect()) class-attribute instance-attribute

non_neg = opt_prop_def(UnitAttr, prop_name='nonNeg') class-attribute instance-attribute

assembly_format = '(`nneg` $nonNeg^)? $arg attr-dict `:` type($arg) `to` type($res)' class-attribute instance-attribute

__init__(arg: SSAValue, res_type: Attribute, attributes: dict[str, Attribute] = {}, non_neg: UnitAttr | None = None)

Source code in xdsl/dialects/llvm.py
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
def __init__(
    self,
    arg: SSAValue,
    res_type: Attribute,
    attributes: dict[str, Attribute] = {},
    non_neg: UnitAttr | None = None,
):
    super().__init__(
        operands=(arg,),
        attributes=attributes,
        result_types=(res_type,),
        properties={
            "nonNeg": non_neg,
        },
    )

IntegerConversionOpOverflow

Bases: IRDLOperation, ABC

Source code in xdsl/dialects/llvm.py
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
class IntegerConversionOpOverflow(IRDLOperation, ABC):
    arg = operand_def(
        SignlessIntegerConstraint | VectorType.constr(SignlessIntegerConstraint)
    )
    res = result_def(
        SignlessIntegerConstraint | VectorType.constr(SignlessIntegerConstraint)
    )
    overflowFlags = opt_prop_def(OverflowAttr)
    traits = traits_def(NoMemoryEffect())

    def __init__(
        self,
        arg: SSAValue,
        res_type: Attribute,
        attributes: dict[str, Attribute] = {},
        overflow: OverflowAttr = OverflowAttr(None),
    ):
        super().__init__(
            operands=(arg,),
            attributes=attributes,
            result_types=(res_type,),
            properties={
                "overflowFlags": overflow,
            },
        )

    @classmethod
    def parse(cls, parser: Parser):
        arg = parser.parse_unresolved_operand()
        overflowFlags = OverflowAttr.parse(parser)
        attributes = parser.parse_optional_attr_dict()
        parser.parse_characters(":")
        arg_type = parser.parse_type()
        parser.parse_characters("to")
        res_type = parser.parse_type()
        operands = parser.resolve_operands([arg], [arg_type], parser.pos)
        return cls(operands[0], res_type, attributes, overflowFlags)

    def print(self, printer: Printer):
        printer.print_string(" ")
        printer.print_ssa_value(self.arg)
        if self.overflowFlags:
            self.overflowFlags.print(printer)
        printer.print_op_attributes(self.attributes)
        printer.print_string(" : ")
        printer.print_attribute(self.arg.type)
        printer.print_string(" to ")
        printer.print_attribute(self.res.type)

arg = operand_def(SignlessIntegerConstraint | VectorType.constr(SignlessIntegerConstraint)) class-attribute instance-attribute

res = result_def(SignlessIntegerConstraint | VectorType.constr(SignlessIntegerConstraint)) class-attribute instance-attribute

overflowFlags = opt_prop_def(OverflowAttr) class-attribute instance-attribute

traits = traits_def(NoMemoryEffect()) class-attribute instance-attribute

__init__(arg: SSAValue, res_type: Attribute, attributes: dict[str, Attribute] = {}, overflow: OverflowAttr = OverflowAttr(None))

Source code in xdsl/dialects/llvm.py
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
def __init__(
    self,
    arg: SSAValue,
    res_type: Attribute,
    attributes: dict[str, Attribute] = {},
    overflow: OverflowAttr = OverflowAttr(None),
):
    super().__init__(
        operands=(arg,),
        attributes=attributes,
        result_types=(res_type,),
        properties={
            "overflowFlags": overflow,
        },
    )

parse(parser: Parser) classmethod

Source code in xdsl/dialects/llvm.py
685
686
687
688
689
690
691
692
693
694
695
@classmethod
def parse(cls, parser: Parser):
    arg = parser.parse_unresolved_operand()
    overflowFlags = OverflowAttr.parse(parser)
    attributes = parser.parse_optional_attr_dict()
    parser.parse_characters(":")
    arg_type = parser.parse_type()
    parser.parse_characters("to")
    res_type = parser.parse_type()
    operands = parser.resolve_operands([arg], [arg_type], parser.pos)
    return cls(operands[0], res_type, attributes, overflowFlags)

print(printer: Printer)

Source code in xdsl/dialects/llvm.py
697
698
699
700
701
702
703
704
705
706
def print(self, printer: Printer):
    printer.print_string(" ")
    printer.print_ssa_value(self.arg)
    if self.overflowFlags:
        self.overflowFlags.print(printer)
    printer.print_op_attributes(self.attributes)
    printer.print_string(" : ")
    printer.print_attribute(self.arg.type)
    printer.print_string(" to ")
    printer.print_attribute(self.res.type)

AddOp dataclass

Bases: ArithmeticBinOpOverflow

Source code in xdsl/dialects/llvm.py
709
710
711
@irdl_op_definition
class AddOp(ArithmeticBinOpOverflow):
    name = "llvm.add"

name = 'llvm.add' class-attribute instance-attribute

SubOp dataclass

Bases: ArithmeticBinOpOverflow

Source code in xdsl/dialects/llvm.py
714
715
716
@irdl_op_definition
class SubOp(ArithmeticBinOpOverflow):
    name = "llvm.sub"

name = 'llvm.sub' class-attribute instance-attribute

MulOp dataclass

Bases: ArithmeticBinOpOverflow

Source code in xdsl/dialects/llvm.py
719
720
721
@irdl_op_definition
class MulOp(ArithmeticBinOpOverflow):
    name = "llvm.mul"

name = 'llvm.mul' class-attribute instance-attribute

UDivOp dataclass

Bases: ArithmeticBinOpExact

Source code in xdsl/dialects/llvm.py
724
725
726
@irdl_op_definition
class UDivOp(ArithmeticBinOpExact):
    name = "llvm.udiv"

name = 'llvm.udiv' class-attribute instance-attribute

SDivOp dataclass

Bases: ArithmeticBinOpExact

Source code in xdsl/dialects/llvm.py
729
730
731
@irdl_op_definition
class SDivOp(ArithmeticBinOpExact):
    name = "llvm.sdiv"

name = 'llvm.sdiv' class-attribute instance-attribute

URemOp dataclass

Bases: ArithmeticBinOperation

Source code in xdsl/dialects/llvm.py
734
735
736
@irdl_op_definition
class URemOp(ArithmeticBinOperation):
    name = "llvm.urem"

name = 'llvm.urem' class-attribute instance-attribute

SRemOp dataclass

Bases: ArithmeticBinOperation

Source code in xdsl/dialects/llvm.py
739
740
741
@irdl_op_definition
class SRemOp(ArithmeticBinOperation):
    name = "llvm.srem"

name = 'llvm.srem' class-attribute instance-attribute

AndOp dataclass

Bases: ArithmeticBinOperation

Source code in xdsl/dialects/llvm.py
744
745
746
@irdl_op_definition
class AndOp(ArithmeticBinOperation):
    name = "llvm.and"

name = 'llvm.and' class-attribute instance-attribute

OrOp dataclass

Bases: ArithmeticBinOpDisjoint

Source code in xdsl/dialects/llvm.py
749
750
751
@irdl_op_definition
class OrOp(ArithmeticBinOpDisjoint):
    name = "llvm.or"

name = 'llvm.or' class-attribute instance-attribute

XOrOp dataclass

Bases: ArithmeticBinOperation

Source code in xdsl/dialects/llvm.py
754
755
756
@irdl_op_definition
class XOrOp(ArithmeticBinOperation):
    name = "llvm.xor"

name = 'llvm.xor' class-attribute instance-attribute

ShlOp dataclass

Bases: ArithmeticBinOpOverflow

Source code in xdsl/dialects/llvm.py
759
760
761
@irdl_op_definition
class ShlOp(ArithmeticBinOpOverflow):
    name = "llvm.shl"

name = 'llvm.shl' class-attribute instance-attribute

LShrOp dataclass

Bases: ArithmeticBinOpExact

Source code in xdsl/dialects/llvm.py
764
765
766
@irdl_op_definition
class LShrOp(ArithmeticBinOpExact):
    name = "llvm.lshr"

name = 'llvm.lshr' class-attribute instance-attribute

AShrOp dataclass

Bases: ArithmeticBinOpExact

Source code in xdsl/dialects/llvm.py
769
770
771
@irdl_op_definition
class AShrOp(ArithmeticBinOpExact):
    name = "llvm.ashr"

name = 'llvm.ashr' class-attribute instance-attribute

TruncOp dataclass

Bases: IntegerConversionOpOverflow

Source code in xdsl/dialects/llvm.py
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
@irdl_op_definition
class TruncOp(IntegerConversionOpOverflow):
    name = "llvm.trunc"

    def verify(self, verify_nested_ops: bool = True):
        arg_type = (
            arg_t.element_type if isa(arg_t := self.arg.type, VectorType) else arg_t
        )
        res_type = (
            res_t.element_type if isa(res_t := self.res.type, VectorType) else res_t
        )

        assert isa(arg_type, IntegerType)
        assert isa(res_type, IntegerType)

        if arg_type.bitwidth <= res_type.bitwidth:
            raise VerifyException(
                f"invalid cast opcode for cast from {arg_type} to {res_type}"
            )
        super().verify(verify_nested_ops)

name = 'llvm.trunc' class-attribute instance-attribute

verify(verify_nested_ops: bool = True)

Source code in xdsl/dialects/llvm.py
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
def verify(self, verify_nested_ops: bool = True):
    arg_type = (
        arg_t.element_type if isa(arg_t := self.arg.type, VectorType) else arg_t
    )
    res_type = (
        res_t.element_type if isa(res_t := self.res.type, VectorType) else res_t
    )

    assert isa(arg_type, IntegerType)
    assert isa(res_type, IntegerType)

    if arg_type.bitwidth <= res_type.bitwidth:
        raise VerifyException(
            f"invalid cast opcode for cast from {arg_type} to {res_type}"
        )
    super().verify(verify_nested_ops)

ZExtOp dataclass

Bases: IntegerConversionOpNNeg

Source code in xdsl/dialects/llvm.py
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
@irdl_op_definition
class ZExtOp(IntegerConversionOpNNeg):
    name = "llvm.zext"

    def verify(self, verify_nested_ops: bool = True):
        arg_type = (
            arg_t.element_type if isa(arg_t := self.arg.type, VectorType) else arg_t
        )
        res_type = (
            res_t.element_type if isa(res_t := self.res.type, VectorType) else res_t
        )

        assert isa(arg_type, IntegerType)
        assert isa(res_type, IntegerType)
        if arg_type.bitwidth >= res_type.bitwidth:
            raise VerifyException(
                f"invalid cast opcode for cast from {arg_type} to {res_type}"
            )
        super().verify(verify_nested_ops)

name = 'llvm.zext' class-attribute instance-attribute

verify(verify_nested_ops: bool = True)

Source code in xdsl/dialects/llvm.py
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
def verify(self, verify_nested_ops: bool = True):
    arg_type = (
        arg_t.element_type if isa(arg_t := self.arg.type, VectorType) else arg_t
    )
    res_type = (
        res_t.element_type if isa(res_t := self.res.type, VectorType) else res_t
    )

    assert isa(arg_type, IntegerType)
    assert isa(res_type, IntegerType)
    if arg_type.bitwidth >= res_type.bitwidth:
        raise VerifyException(
            f"invalid cast opcode for cast from {arg_type} to {res_type}"
        )
    super().verify(verify_nested_ops)

SExtOp dataclass

Bases: IntegerConversionOp

Source code in xdsl/dialects/llvm.py
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
@irdl_op_definition
class SExtOp(IntegerConversionOp):
    name = "llvm.sext"

    def verify(self, verify_nested_ops: bool = True):
        arg_type = (
            arg_t.element_type if isa(arg_t := self.arg.type, VectorType) else arg_t
        )
        res_type = (
            res_t.element_type if isa(res_t := self.res.type, VectorType) else res_t
        )

        assert isa(arg_type, IntegerType)
        assert isa(res_type, IntegerType)
        if arg_type.bitwidth >= res_type.bitwidth:
            raise VerifyException(
                f"invalid cast opcode for cast from {arg_type} to {res_type}"
            )
        super().verify(verify_nested_ops)

name = 'llvm.sext' class-attribute instance-attribute

verify(verify_nested_ops: bool = True)

Source code in xdsl/dialects/llvm.py
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
def verify(self, verify_nested_ops: bool = True):
    arg_type = (
        arg_t.element_type if isa(arg_t := self.arg.type, VectorType) else arg_t
    )
    res_type = (
        res_t.element_type if isa(res_t := self.res.type, VectorType) else res_t
    )

    assert isa(arg_type, IntegerType)
    assert isa(res_type, IntegerType)
    if arg_type.bitwidth >= res_type.bitwidth:
        raise VerifyException(
            f"invalid cast opcode for cast from {arg_type} to {res_type}"
        )
    super().verify(verify_nested_ops)

ICmpPredicateFlag

Bases: StrEnum

Source code in xdsl/dialects/llvm.py
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
class ICmpPredicateFlag(StrEnum):
    EQ = "eq"
    NE = "ne"
    SLT = "slt"
    SLE = "sle"
    SGT = "sgt"
    SGE = "sge"
    ULT = "ult"
    ULE = "ule"
    UGT = "ugt"
    UGE = "uge"

    @staticmethod
    def from_int(index: int) -> ICmpPredicateFlag:
        return ALL_ICMP_FLAGS[index]

    def to_int(self) -> int:
        return ICMP_INDEX_BY_FLAG[self]

EQ = 'eq' class-attribute instance-attribute

NE = 'ne' class-attribute instance-attribute

SLT = 'slt' class-attribute instance-attribute

SLE = 'sle' class-attribute instance-attribute

SGT = 'sgt' class-attribute instance-attribute

SGE = 'sge' class-attribute instance-attribute

ULT = 'ult' class-attribute instance-attribute

ULE = 'ule' class-attribute instance-attribute

UGT = 'ugt' class-attribute instance-attribute

UGE = 'uge' class-attribute instance-attribute

from_int(index: int) -> ICmpPredicateFlag staticmethod

Source code in xdsl/dialects/llvm.py
850
851
852
@staticmethod
def from_int(index: int) -> ICmpPredicateFlag:
    return ALL_ICMP_FLAGS[index]

to_int() -> int

Source code in xdsl/dialects/llvm.py
854
855
def to_int(self) -> int:
    return ICMP_INDEX_BY_FLAG[self]

ICmpOp

Bases: IRDLOperation

Source code in xdsl/dialects/llvm.py
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
@irdl_op_definition
class ICmpOp(IRDLOperation):
    name = "llvm.icmp"
    T: ClassVar = VarConstraint(
        "T", SignlessIntegerConstraint | VectorType.constr(SignlessIntegerConstraint)
    )

    lhs = operand_def(T)
    rhs = operand_def(T)
    res = result_def(I1 | VectorType[I1])
    predicate = prop_def(IntegerAttr[i64])

    traits = traits_def(NoMemoryEffect())

    def __init__(
        self,
        lhs: SSAValue,
        rhs: SSAValue,
        predicate: IntegerAttr[IntegerType],
        attributes: dict[str, Attribute] = {},
    ):
        result_type = (
            VectorType(i1, lhs_type.shape)
            if isa(lhs_type := lhs.type, VectorType)
            else i1
        )

        super().__init__(
            operands=[lhs, rhs],
            attributes=attributes,
            result_types=[result_type],
            properties={
                "predicate": predicate,
            },
        )

    @classmethod
    def parse(cls, parser: Parser):
        predicate_literal = parser.parse_str_literal()
        predicate_value = ICmpPredicateFlag[predicate_literal.upper()]
        predicate_int = predicate_value.to_int()
        predicate = IntegerAttr(predicate_int, i64)
        lhs = parser.parse_unresolved_operand()
        parser.parse_characters(",")
        rhs = parser.parse_unresolved_operand()
        attributes = parser.parse_optional_attr_dict()
        parser.parse_characters(":")
        type = parser.parse_type()
        operands = parser.resolve_operands([lhs, rhs], [type, type], parser.pos)
        return cls(operands[0], operands[1], predicate, attributes)

    def print_predicate(self, printer: Printer):
        flag = ICmpPredicateFlag.from_int(self.predicate.value.data)
        printer.print_string(f"{flag}")

    def print(self, printer: Printer):
        printer.print_string(' "')
        self.print_predicate(printer)
        printer.print_string('" ')
        printer.print_ssa_value(self.lhs)
        printer.print_string(", ")
        printer.print_ssa_value(self.rhs)
        printer.print_op_attributes(self.attributes)
        printer.print_string(" : ")
        printer.print_attribute(self.lhs.type)

    def verify_(self, verify_nested_ops: bool = True) -> None:
        if isa(self.lhs.type, VectorType):
            if not isa(res_type := self.res.type, VectorType):
                raise VerifyException(
                    f"Result must be a vector if operands are vectors, got {res_type}"
                )
        else:
            if isa(res_type := self.res.type, VectorType):
                raise VerifyException(
                    f"Result must be scalar if operands are scalar, got {res_type}"
                )

name = 'llvm.icmp' class-attribute instance-attribute

T: ClassVar = VarConstraint('T', SignlessIntegerConstraint | VectorType.constr(SignlessIntegerConstraint)) class-attribute instance-attribute

lhs = operand_def(T) class-attribute instance-attribute

rhs = operand_def(T) class-attribute instance-attribute

res = result_def(I1 | VectorType[I1]) class-attribute instance-attribute

predicate = prop_def(IntegerAttr[i64]) class-attribute instance-attribute

traits = traits_def(NoMemoryEffect()) class-attribute instance-attribute

__init__(lhs: SSAValue, rhs: SSAValue, predicate: IntegerAttr[IntegerType], attributes: dict[str, Attribute] = {})

Source code in xdsl/dialects/llvm.py
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
def __init__(
    self,
    lhs: SSAValue,
    rhs: SSAValue,
    predicate: IntegerAttr[IntegerType],
    attributes: dict[str, Attribute] = {},
):
    result_type = (
        VectorType(i1, lhs_type.shape)
        if isa(lhs_type := lhs.type, VectorType)
        else i1
    )

    super().__init__(
        operands=[lhs, rhs],
        attributes=attributes,
        result_types=[result_type],
        properties={
            "predicate": predicate,
        },
    )

parse(parser: Parser) classmethod

Source code in xdsl/dialects/llvm.py
898
899
900
901
902
903
904
905
906
907
908
909
910
911
@classmethod
def parse(cls, parser: Parser):
    predicate_literal = parser.parse_str_literal()
    predicate_value = ICmpPredicateFlag[predicate_literal.upper()]
    predicate_int = predicate_value.to_int()
    predicate = IntegerAttr(predicate_int, i64)
    lhs = parser.parse_unresolved_operand()
    parser.parse_characters(",")
    rhs = parser.parse_unresolved_operand()
    attributes = parser.parse_optional_attr_dict()
    parser.parse_characters(":")
    type = parser.parse_type()
    operands = parser.resolve_operands([lhs, rhs], [type, type], parser.pos)
    return cls(operands[0], operands[1], predicate, attributes)

print_predicate(printer: Printer)

Source code in xdsl/dialects/llvm.py
913
914
915
def print_predicate(self, printer: Printer):
    flag = ICmpPredicateFlag.from_int(self.predicate.value.data)
    printer.print_string(f"{flag}")

print(printer: Printer)

Source code in xdsl/dialects/llvm.py
917
918
919
920
921
922
923
924
925
926
def print(self, printer: Printer):
    printer.print_string(' "')
    self.print_predicate(printer)
    printer.print_string('" ')
    printer.print_ssa_value(self.lhs)
    printer.print_string(", ")
    printer.print_ssa_value(self.rhs)
    printer.print_op_attributes(self.attributes)
    printer.print_string(" : ")
    printer.print_attribute(self.lhs.type)

verify_(verify_nested_ops: bool = True) -> None

Source code in xdsl/dialects/llvm.py
928
929
930
931
932
933
934
935
936
937
938
def verify_(self, verify_nested_ops: bool = True) -> None:
    if isa(self.lhs.type, VectorType):
        if not isa(res_type := self.res.type, VectorType):
            raise VerifyException(
                f"Result must be a vector if operands are vectors, got {res_type}"
            )
    else:
        if isa(res_type := self.res.type, VectorType):
            raise VerifyException(
                f"Result must be scalar if operands are scalar, got {res_type}"
            )

GEPOp

Bases: IRDLOperation

llvm.getelementptr is an instruction to do pointer arithmetic by adding/subtracting offsets from a pointer.

See external documentation.

GetElementPtr is documented in various places online:

See the LLVM documentation. A good blogpost.

Note that the first two discuss LLVM IRs GEP operation, not the MLIR one. The semantics are the same, but the structure used by MLIR is not well documented (yet) and the syntax is a bit different.

Here we focus on MLIRs GEP operation:

%res = llvm.getelementptr %ptr [1, 2, %val] ^^^^ ^^^^^^^^^^ input indices

The central point to understanding GEP is that:

GEP never dereferences, it only does math on the given pointer

It always returns a pointer to the element "selected" that is some number of bytes offset from the input pointer:

result = ptr + x for some x parametrized by the arguments

Examples:

Given the following pointer:

%ptr : llvm.ptr<llvm.struct<(i32, i32, llvm.array<2xi32>)>>

The following indices point to the following things:

[0] -> The first element of the pointer, so a pointer to the struct: llvm.ptr<llvm.struct<(i32, i32, llvm.array<2xi32>)>>

[1] -> The next element of the pointer, useful if the pointer points to a list of structs. Equivalent to (ptr + 1), so points to llvm.ptr<llvm.struct<(i32, i32, llvm.array<2xi32>)>>

[0,0] -> The first member of the first struct: llvm.ptr

[1,0] -> The first member of the second struct pointed to by ptr (can result in out-of-bounds access if the ptr only points to a single struct) llvm.ptr

[0,2] -> The third member of the first struct. llvm.ptr<llvm.array<2,i32>>

[0,2,0] -> The first entry of the array that is the third member of the first struct pointed to by our ptr. llvm.ptr

[0,0,1] -> Invalid! The first element of the first struct has no "sub-elements"!

Here is an example of invalid GEP operation parameters:

Given a different pointer to the example above:

%ptr : llvm.ptr<llvm.struct<(llvm.ptr, i32)>>

Note the two pointers, one to the struct, one in the struct.

We can do math on the first pointer:

[0] -> First struct llvm.ptr<llvm.struct<(llvm.ptr, i32)>>

[0,1] -> Second member of first struct llvm.ptr

[0,0] -> First member of the first struct llvm.ptr>

[0,0,3] -> Invalid! In order to find the fourth element in the pointer it would need to be dereferenced! GEP can't do that!

Expressed in "C", this would equate to:

address of first struct

(ptr + 0)

address of first field of first struct

&((ptr + 0)->elm0) ^^^^^^ Even though it looks like it, we are not actually dereferencing ptr here.

address of fourth element:

&(((ptr + 0)->elm0 + 3)) ^^^^^^^^^^ This actually dereferences (ptr + 0) to access elm0!

Which translates to roughly this MLIR code:

%elm0_addr = llvm.gep %ptr[0,0] : (!llvm.ptr<...>) -> !llvm.ptr<!llvm.ptr> %elm0 = llvm.load %elm0_addr : (!llvm.ptr>) -> !llvm.ptr %elm0_3_addr = llvm.gep %elm0[3] : !llvm.ptr -> !llvm.ptr

Here the necessary dereferencing is very visible, as %elm0_3_addr is only accessible through an llvm.load on %elm0_addr.

Source code in xdsl/dialects/llvm.py
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
@irdl_op_definition
class GEPOp(IRDLOperation):
    """
    llvm.getelementptr is an instruction to do pointer arithmetic by
    adding/subtracting offsets from a pointer.

    See external [documentation](https://mlir.llvm.org/docs/Dialects/LLVM/#llvmgetelementptr-mlirllvmgepop).

    GetElementPtr is documented in various places online:

    See the LLVM [documentation](https://www.llvm.org/docs/GetElementPtr.html).
    A good [blogpost](https://blog.yossarian.net/2020/09/19/LLVMs-getelementptr-by-example).

    Note that the first two discuss *LLVM IRs* GEP operation, not the MLIR one.
    The semantics are the same, but the structure used by MLIR is not well
    documented (yet) and the syntax is a bit different.

    Here we focus on MLIRs GEP operation:

    %res = llvm.getelementptr %ptr  [1, 2, %val]
                              ^^^^   ^^^^^^^^^^
                              input   indices

    The central point to understanding GEP is that:
    > GEP never dereferences, it only does math on the given pointer

    It *always* returns a pointer to the element "selected" that is some
    number of bytes offset from the input pointer:

    `result = ptr + x` for some x parametrized by the arguments

    ## Examples:

    Given the following pointer:

    %ptr : llvm.ptr<llvm.struct<(i32, i32, llvm.array<2xi32>)>>

    The following indices point to the following things:

    [0]      -> The first element of the pointer, so a pointer to the struct:
                llvm.ptr<llvm.struct<(i32, i32, llvm.array<2xi32>)>>

    [1]      -> The *next* element of the pointer, useful if the
                pointer points to a list of structs.
                Equivalent to (ptr + 1), so points to
                llvm.ptr<llvm.struct<(i32, i32, llvm.array<2xi32>)>>

    [0,0]    -> The first member of the first struct:
                llvm.ptr<i32>

    [1,0]    -> The first member of the *second* struct pointed to by ptr
                (can result in out-of-bounds access if the ptr only points to a single struct)
                llvm.ptr<i32>

    [0,2]    -> The third member of the first struct.
                llvm.ptr<llvm.array<2,i32>>

    [0,2,0]  -> The first entry of the array that is the third member of
                the first struct pointed to by our ptr.
                llvm.ptr<i32>

    [0,0,1]  -> Invalid! The first element of the first struct has no "sub-elements"!


    Here is an example of invalid GEP operation parameters:

    Given a different pointer to the example above:

    %ptr : llvm.ptr<llvm.struct<(llvm.ptr<i32>, i32)>>

    Note the two pointers, one to the struct, one in the struct.

    We can do math on the first pointer:

    [0]      -> First struct
                llvm.ptr<llvm.struct<(llvm.ptr<i32>, i32)>>

    [0,1]    -> Second member of first struct
                llvm.ptr<i32>

    [0,0]    -> First member of the first struct
                llvm.ptr<llvm.ptr<i32>>

    [0,0,3]  -> Invalid! In order to find the fourth element in the pointer
                it would need to be dereferenced! GEP can't do that!

    Expressed in "C", this would equate to:

    # address of first struct
    (ptr + 0)

    # address of first field of first struct
    &((ptr + 0)->elm0)
               ^^^^^^
               Even though it looks like it, we are not actually
               dereferencing ptr here.

    # address of fourth element:
    &(((ptr + 0)->elm0 + 3))
                ^^^^^^^^^^
                This actually dereferences (ptr + 0) to access elm0!

    Which translates to roughly this MLIR code:

    %elm0_addr   = llvm.gep %ptr[0,0]   : (!llvm.ptr<...>) -> !llvm.ptr<!llvm.ptr<i32>>
    %elm0        = llvm.load %elm0_addr : (!llvm.ptr<llvm.ptr<i32>>) -> !llvm.ptr<i32>
    %elm0_3_addr = llvm.gep %elm0[3]    : !llvm.ptr<i32> -> !llvm.ptr<i32>

    Here the necessary dereferencing is very visible, as %elm0_3_addr is only
    accessible through an `llvm.load` on %elm0_addr.
    """

    name = "llvm.getelementptr"

    ptr = operand_def(LLVMPointerType)
    ssa_indices = var_operand_def(IntegerType)
    elem_type = prop_def()
    noWrapFlags = prop_def(IntegerAttr[I32])

    result = result_def(LLVMPointerType)

    rawConstantIndices = prop_def(DenseArrayBase.constr(i32))
    inbounds = opt_prop_def(UnitAttr)

    traits = traits_def(NoMemoryEffect())

    def __init__(
        self,
        ptr: SSAValue | Operation,
        indices: Sequence[int],
        pointee_type: Attribute,
        ssa_indices: Sequence[SSAValue | Operation] | None = None,
        result_type: LLVMPointerType = LLVMPointerType(),
        inbounds: bool = False,
    ):
        """
        A basic constructor for the GEPOp.

        Pass the GEP_USE_SSA_VAL magic value in place of each constant
        index that you want to be read from an SSA value.

        Take a look at `from_mixed_indices` for something without
        magic values.
        """
        if ssa_indices is None:
            ssa_indices = []

        props: dict[str, Attribute] = {
            "rawConstantIndices": DenseArrayBase.from_list(i32, indices),
            "elem_type": pointee_type,
            "noWrapFlags": IntegerAttr(0, 32),
        }

        props["elem_type"] = pointee_type

        if inbounds:
            props["inbounds"] = UnitAttr()

        super().__init__(
            operands=[ptr, ssa_indices], result_types=[result_type], properties=props
        )

    @staticmethod
    def from_mixed_indices(
        ptr: SSAValue | Operation,
        indices: Sequence[int | SSAValue | Operation],
        pointee_type: Attribute,
        result_type: LLVMPointerType = LLVMPointerType(),
        inbounds: bool = False,
    ):
        """
        This is a helper function that accepts a mixed list of SSA values and const
        indices. It will automatically construct the correct indices and ssa_indices
        lists from that.

        You can call this using [1, 2, some_ssa_val, 3] as the indices array.

        Other than that, this behaves exactly the same as `.get`
        """
        ssa_indices: list[SSAValue] = []
        const_indices: list[int] = []
        for idx in indices:
            if isinstance(idx, int):
                const_indices.append(idx)
            else:
                const_indices.append(GEP_USE_SSA_VAL)
                ssa_indices.append(SSAValue.get(idx))
        return GEPOp(
            ptr,
            const_indices,
            pointee_type,
            ssa_indices,
            result_type=result_type,
            inbounds=inbounds,
        )

name = 'llvm.getelementptr' class-attribute instance-attribute

ptr = operand_def(LLVMPointerType) class-attribute instance-attribute

ssa_indices = var_operand_def(IntegerType) class-attribute instance-attribute

elem_type = prop_def() class-attribute instance-attribute

noWrapFlags = prop_def(IntegerAttr[I32]) class-attribute instance-attribute

result = result_def(LLVMPointerType) class-attribute instance-attribute

rawConstantIndices = prop_def(DenseArrayBase.constr(i32)) class-attribute instance-attribute

inbounds = opt_prop_def(UnitAttr) class-attribute instance-attribute

traits = traits_def(NoMemoryEffect()) class-attribute instance-attribute

__init__(ptr: SSAValue | Operation, indices: Sequence[int], pointee_type: Attribute, ssa_indices: Sequence[SSAValue | Operation] | None = None, result_type: LLVMPointerType = LLVMPointerType(), inbounds: bool = False)

A basic constructor for the GEPOp.

Pass the GEP_USE_SSA_VAL magic value in place of each constant index that you want to be read from an SSA value.

Take a look at from_mixed_indices for something without magic values.

Source code in xdsl/dialects/llvm.py
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
def __init__(
    self,
    ptr: SSAValue | Operation,
    indices: Sequence[int],
    pointee_type: Attribute,
    ssa_indices: Sequence[SSAValue | Operation] | None = None,
    result_type: LLVMPointerType = LLVMPointerType(),
    inbounds: bool = False,
):
    """
    A basic constructor for the GEPOp.

    Pass the GEP_USE_SSA_VAL magic value in place of each constant
    index that you want to be read from an SSA value.

    Take a look at `from_mixed_indices` for something without
    magic values.
    """
    if ssa_indices is None:
        ssa_indices = []

    props: dict[str, Attribute] = {
        "rawConstantIndices": DenseArrayBase.from_list(i32, indices),
        "elem_type": pointee_type,
        "noWrapFlags": IntegerAttr(0, 32),
    }

    props["elem_type"] = pointee_type

    if inbounds:
        props["inbounds"] = UnitAttr()

    super().__init__(
        operands=[ptr, ssa_indices], result_types=[result_type], properties=props
    )

from_mixed_indices(ptr: SSAValue | Operation, indices: Sequence[int | SSAValue | Operation], pointee_type: Attribute, result_type: LLVMPointerType = LLVMPointerType(), inbounds: bool = False) staticmethod

This is a helper function that accepts a mixed list of SSA values and const indices. It will automatically construct the correct indices and ssa_indices lists from that.

You can call this using [1, 2, some_ssa_val, 3] as the indices array.

Other than that, this behaves exactly the same as .get

Source code in xdsl/dialects/llvm.py
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
@staticmethod
def from_mixed_indices(
    ptr: SSAValue | Operation,
    indices: Sequence[int | SSAValue | Operation],
    pointee_type: Attribute,
    result_type: LLVMPointerType = LLVMPointerType(),
    inbounds: bool = False,
):
    """
    This is a helper function that accepts a mixed list of SSA values and const
    indices. It will automatically construct the correct indices and ssa_indices
    lists from that.

    You can call this using [1, 2, some_ssa_val, 3] as the indices array.

    Other than that, this behaves exactly the same as `.get`
    """
    ssa_indices: list[SSAValue] = []
    const_indices: list[int] = []
    for idx in indices:
        if isinstance(idx, int):
            const_indices.append(idx)
        else:
            const_indices.append(GEP_USE_SSA_VAL)
            ssa_indices.append(SSAValue.get(idx))
    return GEPOp(
        ptr,
        const_indices,
        pointee_type,
        ssa_indices,
        result_type=result_type,
        inbounds=inbounds,
    )

AllocaOp

Bases: IRDLOperation

Source code in xdsl/dialects/llvm.py
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
@irdl_op_definition
class AllocaOp(IRDLOperation):
    name = "llvm.alloca"

    size = operand_def(IntegerType)

    alignment = opt_prop_def(IntegerAttr)
    elem_type = opt_prop_def()

    res = result_def()

    def __init__(
        self,
        size: SSAValue | Operation,
        elem_type: Attribute,
        alignment: int = 32,
    ):
        props: dict[str, Attribute] = {
            "alignment": IntegerAttr.from_int_and_width(alignment, 64)
        }
        ptr_type = LLVMPointerType()
        props["elem_type"] = elem_type

        super().__init__(operands=[size], properties=props, result_types=[ptr_type])

name = 'llvm.alloca' class-attribute instance-attribute

size = operand_def(IntegerType) class-attribute instance-attribute

alignment = opt_prop_def(IntegerAttr) class-attribute instance-attribute

elem_type = opt_prop_def() class-attribute instance-attribute

res = result_def() class-attribute instance-attribute

__init__(size: SSAValue | Operation, elem_type: Attribute, alignment: int = 32)

Source code in xdsl/dialects/llvm.py
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
def __init__(
    self,
    size: SSAValue | Operation,
    elem_type: Attribute,
    alignment: int = 32,
):
    props: dict[str, Attribute] = {
        "alignment": IntegerAttr.from_int_and_width(alignment, 64)
    }
    ptr_type = LLVMPointerType()
    props["elem_type"] = elem_type

    super().__init__(operands=[size], properties=props, result_types=[ptr_type])

IntToPtrOp

Bases: IRDLOperation

Source code in xdsl/dialects/llvm.py
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
@irdl_op_definition
class IntToPtrOp(IRDLOperation):
    name = "llvm.inttoptr"

    input = operand_def(IntegerType)

    output = result_def(LLVMPointerType)

    traits = traits_def(NoMemoryEffect())

    def __init__(self, input: SSAValue | Operation):
        ptr_type = LLVMPointerType()
        super().__init__(operands=[input], result_types=[ptr_type])

name = 'llvm.inttoptr' class-attribute instance-attribute

input = operand_def(IntegerType) class-attribute instance-attribute

output = result_def(LLVMPointerType) class-attribute instance-attribute

traits = traits_def(NoMemoryEffect()) class-attribute instance-attribute

__init__(input: SSAValue | Operation)

Source code in xdsl/dialects/llvm.py
1174
1175
1176
def __init__(self, input: SSAValue | Operation):
    ptr_type = LLVMPointerType()
    super().__init__(operands=[input], result_types=[ptr_type])

TailCallKind

Bases: StrEnum

Source code in xdsl/dialects/llvm.py
1179
1180
1181
1182
1183
class TailCallKind(StrEnum):
    NONE = "none"
    TAIL = "tail"
    MUST_TAIL = "musttail"
    NOTAIL = "notail"

NONE = 'none' class-attribute instance-attribute

TAIL = 'tail' class-attribute instance-attribute

MUST_TAIL = 'musttail' class-attribute instance-attribute

NOTAIL = 'notail' class-attribute instance-attribute

TailCallKindAttr dataclass

Bases: EnumAttribute[TailCallKind]

Source code in xdsl/dialects/llvm.py
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
@irdl_attr_definition
class TailCallKindAttr(EnumAttribute[TailCallKind]):
    name = "llvm.tailcallkind"

    @classmethod
    def parse_parameter(cls, parser: AttrParser) -> TailCallKind:
        with parser.in_angle_brackets():
            return super().parse_parameter(parser)

    def print_parameter(self, printer: Printer) -> None:
        with printer.in_angle_brackets():
            super().print_parameter(printer)

name = 'llvm.tailcallkind' class-attribute instance-attribute

parse_parameter(parser: AttrParser) -> TailCallKind classmethod

Source code in xdsl/dialects/llvm.py
1190
1191
1192
1193
@classmethod
def parse_parameter(cls, parser: AttrParser) -> TailCallKind:
    with parser.in_angle_brackets():
        return super().parse_parameter(parser)

print_parameter(printer: Printer) -> None

Source code in xdsl/dialects/llvm.py
1195
1196
1197
def print_parameter(self, printer: Printer) -> None:
    with printer.in_angle_brackets():
        super().print_parameter(printer)

InlineAsmOp

Bases: IRDLOperation

See external documentation.

To see what each field means, have a look here.

Source code in xdsl/dialects/llvm.py
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
@irdl_op_definition
class InlineAsmOp(IRDLOperation):
    """
    See external [documentation](https://mlir.llvm.org/docs/Dialects/LLVM/#llvminline_asm-llvminlineasmop).

    To see what each field means, have a look [here](https://llvm.org/docs/LangRef.html#inline-assembler-expressions).
    """

    name = "llvm.inline_asm"

    operands_ = var_operand_def()

    res = opt_result_def()

    # note: in MLIR upstream this is implemented as AsmDialectAttr;
    # which is an instantiation of an LLVM_EnumAttr
    # 0 for AT&T inline assembly dialect
    # 1 for Intel inline assembly dialect
    # In this context dialect does not refer to an MLIR dialect
    asm_dialect = opt_prop_def(IntegerAttr[I64])

    asm_string = prop_def(StringAttr)
    constraints = prop_def(StringAttr)

    has_side_effects = opt_prop_def(UnitAttr)
    is_align_stack = opt_prop_def(UnitAttr)

    tail_call_kind = prop_def(
        TailCallKindAttr, default_value=TailCallKindAttr(TailCallKind.NONE)
    )

    def __init__(
        self,
        asm_string: str,
        constraints: str,
        operands: Sequence[SSAValue | Operation],
        res_types: Sequence[Attribute] | None = None,
        asm_dialect: int = 0,
        has_side_effects: bool = False,
        is_align_stack: bool = False,
        tail_call_kind: TailCallKindAttr | None = None,
    ):
        props: dict[str, Attribute | None] = {
            "asm_string": StringAttr(asm_string),
            "constraints": StringAttr(constraints),
            "asm_dialect": IntegerAttr.from_int_and_width(asm_dialect, 64),
            "has_side_effects": UnitAttr() if has_side_effects else None,
            "is_align_stack": UnitAttr() if is_align_stack else None,
            "tail_call_kind": tail_call_kind,
        }

        if res_types is None:
            res_types = []

        super().__init__(
            operands=[operands],
            properties=props,
            result_types=[res_types],
        )

name = 'llvm.inline_asm' class-attribute instance-attribute

operands_ = var_operand_def() class-attribute instance-attribute

res = opt_result_def() class-attribute instance-attribute

asm_dialect = opt_prop_def(IntegerAttr[I64]) class-attribute instance-attribute

asm_string = prop_def(StringAttr) class-attribute instance-attribute

constraints = prop_def(StringAttr) class-attribute instance-attribute

has_side_effects = opt_prop_def(UnitAttr) class-attribute instance-attribute

is_align_stack = opt_prop_def(UnitAttr) class-attribute instance-attribute

tail_call_kind = prop_def(TailCallKindAttr, default_value=(TailCallKindAttr(TailCallKind.NONE))) class-attribute instance-attribute

__init__(asm_string: str, constraints: str, operands: Sequence[SSAValue | Operation], res_types: Sequence[Attribute] | None = None, asm_dialect: int = 0, has_side_effects: bool = False, is_align_stack: bool = False, tail_call_kind: TailCallKindAttr | None = None)

Source code in xdsl/dialects/llvm.py
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
def __init__(
    self,
    asm_string: str,
    constraints: str,
    operands: Sequence[SSAValue | Operation],
    res_types: Sequence[Attribute] | None = None,
    asm_dialect: int = 0,
    has_side_effects: bool = False,
    is_align_stack: bool = False,
    tail_call_kind: TailCallKindAttr | None = None,
):
    props: dict[str, Attribute | None] = {
        "asm_string": StringAttr(asm_string),
        "constraints": StringAttr(constraints),
        "asm_dialect": IntegerAttr.from_int_and_width(asm_dialect, 64),
        "has_side_effects": UnitAttr() if has_side_effects else None,
        "is_align_stack": UnitAttr() if is_align_stack else None,
        "tail_call_kind": tail_call_kind,
    }

    if res_types is None:
        res_types = []

    super().__init__(
        operands=[operands],
        properties=props,
        result_types=[res_types],
    )

PtrToIntOp

Bases: IRDLOperation

Source code in xdsl/dialects/llvm.py
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
@irdl_op_definition
class PtrToIntOp(IRDLOperation):
    name = "llvm.ptrtoint"

    input = operand_def(LLVMPointerType)

    output = result_def(IntegerType)

    traits = traits_def(NoMemoryEffect())

    def __init__(self, arg: SSAValue | Operation, int_type: Attribute = i64):
        super().__init__(operands=[arg], result_types=[int_type])

name = 'llvm.ptrtoint' class-attribute instance-attribute

input = operand_def(LLVMPointerType) class-attribute instance-attribute

output = result_def(IntegerType) class-attribute instance-attribute

traits = traits_def(NoMemoryEffect()) class-attribute instance-attribute

__init__(arg: SSAValue | Operation, int_type: Attribute = i64)

Source code in xdsl/dialects/llvm.py
1271
1272
def __init__(self, arg: SSAValue | Operation, int_type: Attribute = i64):
    super().__init__(operands=[arg], result_types=[int_type])

LoadOp

Bases: IRDLOperation

Source code in xdsl/dialects/llvm.py
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
@irdl_op_definition
class LoadOp(IRDLOperation):
    name = "llvm.load"

    ptr = operand_def(LLVMPointerType)

    alignment = opt_prop_def(IntegerAttr[IntegerType])
    ordering = prop_def(IntegerAttr[IntegerType], default_value=IntegerAttr(0, i64))

    dereferenced_value = result_def()

    def __init__(
        self,
        ptr: SSAValue | Operation,
        result_type: Attribute,
        alignment: int | None = None,
        ordering: int = 0,
    ):
        props: dict[str, Attribute] = {
            "ordering": IntegerAttr(ordering, i64),
        }

        if alignment is not None:
            props["alignment"] = IntegerAttr(alignment, i64)

        super().__init__(operands=[ptr], result_types=[result_type], properties=props)

name = 'llvm.load' class-attribute instance-attribute

ptr = operand_def(LLVMPointerType) class-attribute instance-attribute

alignment = opt_prop_def(IntegerAttr[IntegerType]) class-attribute instance-attribute

ordering = prop_def(IntegerAttr[IntegerType], default_value=(IntegerAttr(0, i64))) class-attribute instance-attribute

dereferenced_value = result_def() class-attribute instance-attribute

__init__(ptr: SSAValue | Operation, result_type: Attribute, alignment: int | None = None, ordering: int = 0)

Source code in xdsl/dialects/llvm.py
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
def __init__(
    self,
    ptr: SSAValue | Operation,
    result_type: Attribute,
    alignment: int | None = None,
    ordering: int = 0,
):
    props: dict[str, Attribute] = {
        "ordering": IntegerAttr(ordering, i64),
    }

    if alignment is not None:
        props["alignment"] = IntegerAttr(alignment, i64)

    super().__init__(operands=[ptr], result_types=[result_type], properties=props)

StoreOp

Bases: IRDLOperation

Source code in xdsl/dialects/llvm.py
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
@irdl_op_definition
class StoreOp(IRDLOperation):
    name = "llvm.store"

    value = operand_def()
    ptr = operand_def(LLVMPointerType)

    alignment = opt_prop_def(IntegerAttr[IntegerType])
    ordering = opt_prop_def(IntegerAttr[IntegerType])
    volatile_ = opt_prop_def(UnitAttr)
    nontemporal = opt_prop_def(UnitAttr)

    def __init__(
        self,
        value: SSAValue | Operation,
        ptr: SSAValue | Operation,
        alignment: int | None = None,
        ordering: int = 0,
        volatile: bool = False,
        nontemporal: bool = False,
    ):
        props: dict[str, Attribute] = {
            "ordering": IntegerAttr(ordering, i64),
        }

        if alignment is not None:
            props["alignment"] = IntegerAttr[IntegerType](alignment, i64)
        if volatile:
            props["volatile_"] = UnitAttr()
        if nontemporal:
            props["nontemporal"] = UnitAttr()

        super().__init__(
            operands=[value, ptr],
            properties=props,
            result_types=[],
        )

name = 'llvm.store' class-attribute instance-attribute

value = operand_def() class-attribute instance-attribute

ptr = operand_def(LLVMPointerType) class-attribute instance-attribute

alignment = opt_prop_def(IntegerAttr[IntegerType]) class-attribute instance-attribute

ordering = opt_prop_def(IntegerAttr[IntegerType]) class-attribute instance-attribute

volatile_ = opt_prop_def(UnitAttr) class-attribute instance-attribute

nontemporal = opt_prop_def(UnitAttr) class-attribute instance-attribute

__init__(value: SSAValue | Operation, ptr: SSAValue | Operation, alignment: int | None = None, ordering: int = 0, volatile: bool = False, nontemporal: bool = False)

Source code in xdsl/dialects/llvm.py
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
def __init__(
    self,
    value: SSAValue | Operation,
    ptr: SSAValue | Operation,
    alignment: int | None = None,
    ordering: int = 0,
    volatile: bool = False,
    nontemporal: bool = False,
):
    props: dict[str, Attribute] = {
        "ordering": IntegerAttr(ordering, i64),
    }

    if alignment is not None:
        props["alignment"] = IntegerAttr[IntegerType](alignment, i64)
    if volatile:
        props["volatile_"] = UnitAttr()
    if nontemporal:
        props["nontemporal"] = UnitAttr()

    super().__init__(
        operands=[value, ptr],
        properties=props,
        result_types=[],
    )

NullOp

Bases: IRDLOperation

Source code in xdsl/dialects/llvm.py
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
@irdl_op_definition
class NullOp(IRDLOperation):
    name = "llvm.mlir.null"

    nullptr = result_def(LLVMPointerType)

    traits = traits_def(NoMemoryEffect())

    def __init__(self, ptr_type: LLVMPointerType | None = None):
        if ptr_type is None:
            ptr_type = LLVMPointerType()

        super().__init__(result_types=[ptr_type])

name = 'llvm.mlir.null' class-attribute instance-attribute

nullptr = result_def(LLVMPointerType) class-attribute instance-attribute

traits = traits_def(NoMemoryEffect()) class-attribute instance-attribute

__init__(ptr_type: LLVMPointerType | None = None)

Source code in xdsl/dialects/llvm.py
1350
1351
1352
1353
1354
def __init__(self, ptr_type: LLVMPointerType | None = None):
    if ptr_type is None:
        ptr_type = LLVMPointerType()

    super().__init__(result_types=[ptr_type])

ExtractValueOp

Bases: IRDLOperation

See external documentation.

Source code in xdsl/dialects/llvm.py
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
@irdl_op_definition
class ExtractValueOp(IRDLOperation):
    """
    See external [documentation](https://mlir.llvm.org/docs/Dialects/LLVM/#llvmextractvalue-mlirllvmextractvalueop).
    """

    name = "llvm.extractvalue"

    position = prop_def(DenseArrayBase.constr(i64))
    container = operand_def(Attribute)

    res = result_def(Attribute)

    traits = traits_def(NoMemoryEffect())

    def __init__(
        self,
        position: DenseArrayBase,
        container: SSAValue | Operation,
        result_type: Attribute,
    ):
        super().__init__(
            operands=[container],
            properties={
                "position": position,
            },
            result_types=[result_type],
        )

name = 'llvm.extractvalue' class-attribute instance-attribute

position = prop_def(DenseArrayBase.constr(i64)) class-attribute instance-attribute

container = operand_def(Attribute) class-attribute instance-attribute

res = result_def(Attribute) class-attribute instance-attribute

traits = traits_def(NoMemoryEffect()) class-attribute instance-attribute

__init__(position: DenseArrayBase, container: SSAValue | Operation, result_type: Attribute)

Source code in xdsl/dialects/llvm.py
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
def __init__(
    self,
    position: DenseArrayBase,
    container: SSAValue | Operation,
    result_type: Attribute,
):
    super().__init__(
        operands=[container],
        properties={
            "position": position,
        },
        result_types=[result_type],
    )

InsertValueOp

Bases: IRDLOperation

See external documentation.

Source code in xdsl/dialects/llvm.py
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
@irdl_op_definition
class InsertValueOp(IRDLOperation):
    """
    See external [documentation](https://mlir.llvm.org/docs/Dialects/LLVM/#llvminsertvalue-mlirllvminsertvalueop).
    """

    name = "llvm.insertvalue"

    position = prop_def(DenseArrayBase.constr(i64))
    container = operand_def(Attribute)
    value = operand_def(Attribute)

    res = result_def(Attribute)

    traits = traits_def(NoMemoryEffect())

    def __init__(
        self,
        position: DenseArrayBase,
        container: SSAValue,
        value: SSAValue,
    ):
        super().__init__(
            operands=[container, value],
            properties={
                "position": position,
            },
            result_types=[container.type],
        )

name = 'llvm.insertvalue' class-attribute instance-attribute

position = prop_def(DenseArrayBase.constr(i64)) class-attribute instance-attribute

container = operand_def(Attribute) class-attribute instance-attribute

value = operand_def(Attribute) class-attribute instance-attribute

res = result_def(Attribute) class-attribute instance-attribute

traits = traits_def(NoMemoryEffect()) class-attribute instance-attribute

__init__(position: DenseArrayBase, container: SSAValue, value: SSAValue)

Source code in xdsl/dialects/llvm.py
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
def __init__(
    self,
    position: DenseArrayBase,
    container: SSAValue,
    value: SSAValue,
):
    super().__init__(
        operands=[container, value],
        properties={
            "position": position,
        },
        result_types=[container.type],
    )

UndefOp

Bases: IRDLOperation

See external documentation.

Source code in xdsl/dialects/llvm.py
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
@irdl_op_definition
class UndefOp(IRDLOperation):
    """
    See external [documentation](https://mlir.llvm.org/docs/Dialects/LLVM/#llvmmlirundef-mlirllvmundefop).
    """

    name = "llvm.mlir.undef"

    res = result_def(Attribute)

    traits = traits_def(NoMemoryEffect())

    def __init__(self, result_type: Attribute):
        super().__init__(result_types=[result_type])

name = 'llvm.mlir.undef' class-attribute instance-attribute

res = result_def(Attribute) class-attribute instance-attribute

traits = traits_def(NoMemoryEffect()) class-attribute instance-attribute

__init__(result_type: Attribute)

Source code in xdsl/dialects/llvm.py
1430
1431
def __init__(self, result_type: Attribute):
    super().__init__(result_types=[result_type])

GlobalOp

Bases: IRDLOperation

Source code in xdsl/dialects/llvm.py
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
@irdl_op_definition
class GlobalOp(IRDLOperation):
    name = "llvm.mlir.global"

    global_type = prop_def()
    constant = opt_prop_def(UnitAttr)
    sym_name = prop_def(SymbolNameConstraint())
    linkage = prop_def(LinkageAttr)
    dso_local = opt_prop_def(UnitAttr)
    thread_local_ = opt_prop_def(UnitAttr)
    visibility_ = opt_prop_def(IntegerAttr[IntegerType])
    value = opt_prop_def()
    alignment = opt_prop_def(IntegerAttr)
    addr_space = prop_def(IntegerAttr)
    unnamed_addr = opt_prop_def(IntegerAttr)
    section = opt_prop_def(StringAttr)

    # This always needs an empty region as it is in the top level module definition
    body = region_def()

    traits = traits_def(SymbolOpInterface())

    def __init__(
        self,
        global_type: Attribute,
        sym_name: str | StringAttr,
        linkage: str | LinkageAttr,
        addr_space: int = 0,
        constant: bool | None = None,
        dso_local: bool | None = None,
        thread_local_: bool | None = None,
        value: Attribute | None = None,
        alignment: int | None = None,
        unnamed_addr: int | None = None,
        section: str | StringAttr | None = None,
        body: Region | None = None,
    ):
        if isinstance(sym_name, str):
            sym_name = StringAttr(sym_name)

        if isinstance(linkage, str):
            linkage = LinkageAttr(linkage)

        props: dict[str, Attribute] = {
            "global_type": global_type,
            "sym_name": sym_name,
            "linkage": linkage,
            "addr_space": IntegerAttr(addr_space, 32),
        }

        if constant is not None and constant:
            props["constant"] = UnitAttr()

        if dso_local is not None and dso_local:
            props["dso_local"] = UnitAttr()

        if thread_local_ is not None and thread_local_:
            props["thread_local_"] = UnitAttr()

        if value is not None:
            props["value"] = value

        if alignment is not None:
            props["alignment"] = IntegerAttr(alignment, 64)

        if unnamed_addr is not None:
            props["unnamed_addr"] = IntegerAttr(unnamed_addr, 64)

        if section is not None:
            if isinstance(section, str):
                section = StringAttr(section)
            props["section"] = section

        if body is None:
            body = Region()

        super().__init__(properties=props, regions=(body,))

name = 'llvm.mlir.global' class-attribute instance-attribute

global_type = prop_def() class-attribute instance-attribute

constant = opt_prop_def(UnitAttr) class-attribute instance-attribute

sym_name = prop_def(SymbolNameConstraint()) class-attribute instance-attribute

linkage = prop_def(LinkageAttr) class-attribute instance-attribute

dso_local = opt_prop_def(UnitAttr) class-attribute instance-attribute

thread_local_ = opt_prop_def(UnitAttr) class-attribute instance-attribute

visibility_ = opt_prop_def(IntegerAttr[IntegerType]) class-attribute instance-attribute

value = opt_prop_def() class-attribute instance-attribute

alignment = opt_prop_def(IntegerAttr) class-attribute instance-attribute

addr_space = prop_def(IntegerAttr) class-attribute instance-attribute

unnamed_addr = opt_prop_def(IntegerAttr) class-attribute instance-attribute

section = opt_prop_def(StringAttr) class-attribute instance-attribute

body = region_def() class-attribute instance-attribute

traits = traits_def(SymbolOpInterface()) class-attribute instance-attribute

__init__(global_type: Attribute, sym_name: str | StringAttr, linkage: str | LinkageAttr, addr_space: int = 0, constant: bool | None = None, dso_local: bool | None = None, thread_local_: bool | None = None, value: Attribute | None = None, alignment: int | None = None, unnamed_addr: int | None = None, section: str | StringAttr | None = None, body: Region | None = None)

Source code in xdsl/dialects/llvm.py
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
def __init__(
    self,
    global_type: Attribute,
    sym_name: str | StringAttr,
    linkage: str | LinkageAttr,
    addr_space: int = 0,
    constant: bool | None = None,
    dso_local: bool | None = None,
    thread_local_: bool | None = None,
    value: Attribute | None = None,
    alignment: int | None = None,
    unnamed_addr: int | None = None,
    section: str | StringAttr | None = None,
    body: Region | None = None,
):
    if isinstance(sym_name, str):
        sym_name = StringAttr(sym_name)

    if isinstance(linkage, str):
        linkage = LinkageAttr(linkage)

    props: dict[str, Attribute] = {
        "global_type": global_type,
        "sym_name": sym_name,
        "linkage": linkage,
        "addr_space": IntegerAttr(addr_space, 32),
    }

    if constant is not None and constant:
        props["constant"] = UnitAttr()

    if dso_local is not None and dso_local:
        props["dso_local"] = UnitAttr()

    if thread_local_ is not None and thread_local_:
        props["thread_local_"] = UnitAttr()

    if value is not None:
        props["value"] = value

    if alignment is not None:
        props["alignment"] = IntegerAttr(alignment, 64)

    if unnamed_addr is not None:
        props["unnamed_addr"] = IntegerAttr(unnamed_addr, 64)

    if section is not None:
        if isinstance(section, str):
            section = StringAttr(section)
        props["section"] = section

    if body is None:
        body = Region()

    super().__init__(properties=props, regions=(body,))

AddressOfOp

Bases: IRDLOperation

Source code in xdsl/dialects/llvm.py
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
@irdl_op_definition
class AddressOfOp(IRDLOperation):
    name = "llvm.mlir.addressof"

    global_name = prop_def(SymbolRefAttr)
    result = result_def(LLVMPointerType)

    traits = traits_def(NoMemoryEffect())

    def __init__(
        self,
        global_name: str | StringAttr | SymbolRefAttr,
        result_type: LLVMPointerType,
    ):
        if isinstance(global_name, StringAttr | str):
            global_name = SymbolRefAttr(global_name)

        super().__init__(
            properties={"global_name": global_name}, result_types=[result_type]
        )

name = 'llvm.mlir.addressof' class-attribute instance-attribute

global_name = prop_def(SymbolRefAttr) class-attribute instance-attribute

result = result_def(LLVMPointerType) class-attribute instance-attribute

traits = traits_def(NoMemoryEffect()) class-attribute instance-attribute

__init__(global_name: str | StringAttr | SymbolRefAttr, result_type: LLVMPointerType)

Source code in xdsl/dialects/llvm.py
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
def __init__(
    self,
    global_name: str | StringAttr | SymbolRefAttr,
    result_type: LLVMPointerType,
):
    if isinstance(global_name, StringAttr | str):
        global_name = SymbolRefAttr(global_name)

    super().__init__(
        properties={"global_name": global_name}, result_types=[result_type]
    )

CallingConventionAttr

Bases: ParametrizedAttribute

LLVM Calling convention, default is ccc.

Source code in xdsl/dialects/llvm.py
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
@irdl_attr_definition
class CallingConventionAttr(ParametrizedAttribute):
    """
    LLVM Calling convention, default is ccc.
    """

    name = "llvm.cconv"

    convention: StringAttr

    @property
    def cconv_name(self) -> str:
        return self.convention.data

    def __init__(self, conv: str):
        super().__init__(StringAttr(conv))

    def _verify(self):
        if self.cconv_name not in LLVM_CALLING_CONVS:
            raise VerifyException(f'Invalid calling convention "{self.cconv_name}"')

    def print_parameters(self, printer: Printer) -> None:
        printer.print_string("<" + self.convention.data + ">")

    @classmethod
    def parse_parameters(cls, parser: AttrParser) -> list[Attribute]:
        parser.parse_characters("<")
        for conv in LLVM_CALLING_CONVS:
            if parser.parse_optional_characters(conv) is not None:
                parser.parse_characters(">")
                return [StringAttr(conv)]
        parser.raise_error("Unknown calling convention")

name = 'llvm.cconv' class-attribute instance-attribute

convention: StringAttr instance-attribute

cconv_name: str property

__init__(conv: str)

Source code in xdsl/dialects/llvm.py
1571
1572
def __init__(self, conv: str):
    super().__init__(StringAttr(conv))

print_parameters(printer: Printer) -> None

Source code in xdsl/dialects/llvm.py
1578
1579
def print_parameters(self, printer: Printer) -> None:
    printer.print_string("<" + self.convention.data + ">")

parse_parameters(parser: AttrParser) -> list[Attribute] classmethod

Source code in xdsl/dialects/llvm.py
1581
1582
1583
1584
1585
1586
1587
1588
@classmethod
def parse_parameters(cls, parser: AttrParser) -> list[Attribute]:
    parser.parse_characters("<")
    for conv in LLVM_CALLING_CONVS:
        if parser.parse_optional_characters(conv) is not None:
            parser.parse_characters(">")
            return [StringAttr(conv)]
    parser.raise_error("Unknown calling convention")

FramePointerKind

Bases: StrEnum

Source code in xdsl/dialects/llvm.py
1591
1592
1593
1594
1595
class FramePointerKind(StrEnum):
    NONE = "none"
    NONLEAF = "non-leaf"
    ALL = "all"
    RESERVED = "reserved"

NONE = 'none' class-attribute instance-attribute

NONLEAF = 'non-leaf' class-attribute instance-attribute

ALL = 'all' class-attribute instance-attribute

RESERVED = 'reserved' class-attribute instance-attribute

FramePointerKindAttr dataclass

Bases: EnumAttribute[FramePointerKind]

LLVM Frame Pointer Kind.

Source code in xdsl/dialects/llvm.py
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
@irdl_attr_definition
class FramePointerKindAttr(EnumAttribute[FramePointerKind]):
    """LLVM Frame Pointer Kind."""

    name = "llvm.framePointerKind"

    def print_parameter(self, printer: Printer) -> None:
        with printer.in_angle_brackets():
            super().print_parameter(printer)

    @classmethod
    def parse_parameter(cls, parser: AttrParser) -> FramePointerKind:
        with parser.in_angle_brackets():
            return super().parse_parameter(parser)

name = 'llvm.framePointerKind' class-attribute instance-attribute

print_parameter(printer: Printer) -> None

Source code in xdsl/dialects/llvm.py
1604
1605
1606
def print_parameter(self, printer: Printer) -> None:
    with printer.in_angle_brackets():
        super().print_parameter(printer)

parse_parameter(parser: AttrParser) -> FramePointerKind classmethod

Source code in xdsl/dialects/llvm.py
1608
1609
1610
1611
@classmethod
def parse_parameter(cls, parser: AttrParser) -> FramePointerKind:
    with parser.in_angle_brackets():
        return super().parse_parameter(parser)

TargetFeaturesAttr dataclass

Bases: ParametrizedAttribute

Represents the LLVM target features as a list that can be checked within passes/rewrites.

Source code in xdsl/dialects/llvm.py
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
@irdl_attr_definition
class TargetFeaturesAttr(ParametrizedAttribute):
    """
    Represents the LLVM target features as a list that can be checked within
    passes/rewrites.
    """

    name = "llvm.target_features"

    features: ArrayAttr[StringAttr]

    def verify(self):
        for feature in self.features:
            if not feature.data.startswith(("-", "+")):
                raise VerifyException("target features must start with '+' or '-'")

name = 'llvm.target_features' class-attribute instance-attribute

features: ArrayAttr[StringAttr] instance-attribute

verify()

Source code in xdsl/dialects/llvm.py
1625
1626
1627
1628
def verify(self):
    for feature in self.features:
        if not feature.data.startswith(("-", "+")):
            raise VerifyException("target features must start with '+' or '-'")

FuncOp

Bases: IRDLOperation

Source code in xdsl/dialects/llvm.py
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
@irdl_op_definition
class FuncOp(IRDLOperation):
    name = "llvm.func"

    body = region_def()
    sym_name = prop_def(SymbolNameConstraint())
    function_type = prop_def(LLVMFunctionType)
    CConv = prop_def(CallingConventionAttr)
    linkage = prop_def(LinkageAttr)
    sym_visibility = opt_prop_def(StringAttr)
    visibility_ = prop_def(IntegerAttr[IntegerType])

    # The following properties are not yet verified by the xDSL verifier, but
    # are verified to at least allow the IR to be parsed and printed correctly.
    arg_attrs = opt_prop_def(ArrayAttr[DictionaryAttr])
    frame_pointer = opt_prop_def(FramePointerKindAttr)
    no_inline = opt_prop_def(UnitAttr)
    no_unwind = opt_prop_def(UnitAttr)
    optimize_none = opt_prop_def(UnitAttr)
    passthrough = opt_prop_def(ArrayAttr[Attribute])
    target_cpu = opt_prop_def(StringAttr)
    target_features = opt_prop_def(TargetFeaturesAttr)
    tune_cpu = opt_prop_def(StringAttr)
    unnamed_addr = opt_prop_def(IntegerAttr)

    def __init__(
        self,
        sym_name: str | StringAttr,
        function_type: LLVMFunctionType,
        linkage: LinkageAttr = LinkageAttr("internal"),
        cconv: CallingConventionAttr = CallingConventionAttr("ccc"),
        visibility: int | IntegerAttr[IntegerType] = 0,
        sym_visibility: str | StringAttr | None = None,
        body: Region | None = None,
        other_props: dict[str, Attribute | None] | None = None,
    ):
        if isinstance(sym_name, str):
            sym_name = StringAttr(sym_name)
        if isinstance(visibility, int):
            visibility = IntegerAttr.from_int_and_width(visibility, 64)
        if body is None:
            body = Region([])
        if isinstance(sym_visibility, str):
            sym_visibility = StringAttr(sym_visibility)
        properties = other_props if other_props is not None else {}
        properties.update(
            {
                "sym_name": sym_name,
                "function_type": function_type,
                "CConv": cconv,
                "linkage": linkage,
                "visibility_": visibility,
                "sym_visibility": sym_visibility,
            }
        )
        super().__init__(
            operands=[],
            regions=[body],
            properties=properties,
        )

name = 'llvm.func' class-attribute instance-attribute

body = region_def() class-attribute instance-attribute

sym_name = prop_def(SymbolNameConstraint()) class-attribute instance-attribute

function_type = prop_def(LLVMFunctionType) class-attribute instance-attribute

CConv = prop_def(CallingConventionAttr) class-attribute instance-attribute

linkage = prop_def(LinkageAttr) class-attribute instance-attribute

sym_visibility = opt_prop_def(StringAttr) class-attribute instance-attribute

visibility_ = prop_def(IntegerAttr[IntegerType]) class-attribute instance-attribute

arg_attrs = opt_prop_def(ArrayAttr[DictionaryAttr]) class-attribute instance-attribute

frame_pointer = opt_prop_def(FramePointerKindAttr) class-attribute instance-attribute

no_inline = opt_prop_def(UnitAttr) class-attribute instance-attribute

no_unwind = opt_prop_def(UnitAttr) class-attribute instance-attribute

optimize_none = opt_prop_def(UnitAttr) class-attribute instance-attribute

passthrough = opt_prop_def(ArrayAttr[Attribute]) class-attribute instance-attribute

target_cpu = opt_prop_def(StringAttr) class-attribute instance-attribute

target_features = opt_prop_def(TargetFeaturesAttr) class-attribute instance-attribute

tune_cpu = opt_prop_def(StringAttr) class-attribute instance-attribute

unnamed_addr = opt_prop_def(IntegerAttr) class-attribute instance-attribute

__init__(sym_name: str | StringAttr, function_type: LLVMFunctionType, linkage: LinkageAttr = LinkageAttr('internal'), cconv: CallingConventionAttr = CallingConventionAttr('ccc'), visibility: int | IntegerAttr[IntegerType] = 0, sym_visibility: str | StringAttr | None = None, body: Region | None = None, other_props: dict[str, Attribute | None] | None = None)

Source code in xdsl/dialects/llvm.py
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
def __init__(
    self,
    sym_name: str | StringAttr,
    function_type: LLVMFunctionType,
    linkage: LinkageAttr = LinkageAttr("internal"),
    cconv: CallingConventionAttr = CallingConventionAttr("ccc"),
    visibility: int | IntegerAttr[IntegerType] = 0,
    sym_visibility: str | StringAttr | None = None,
    body: Region | None = None,
    other_props: dict[str, Attribute | None] | None = None,
):
    if isinstance(sym_name, str):
        sym_name = StringAttr(sym_name)
    if isinstance(visibility, int):
        visibility = IntegerAttr.from_int_and_width(visibility, 64)
    if body is None:
        body = Region([])
    if isinstance(sym_visibility, str):
        sym_visibility = StringAttr(sym_visibility)
    properties = other_props if other_props is not None else {}
    properties.update(
        {
            "sym_name": sym_name,
            "function_type": function_type,
            "CConv": cconv,
            "linkage": linkage,
            "visibility_": visibility,
            "sym_visibility": sym_visibility,
        }
    )
    super().__init__(
        operands=[],
        regions=[body],
        properties=properties,
    )

ReturnOp

Bases: IRDLOperation

See external documentation.

Source code in xdsl/dialects/llvm.py
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
@irdl_op_definition
class ReturnOp(IRDLOperation):
    """
    See external [documentation](https://mlir.llvm.org/docs/Dialects/LLVM/#llvmreturn-mlirllvmreturnop).
    """

    name = "llvm.return"

    assembly_format = "($arg^ `:` type($arg))? attr-dict"

    arg = opt_operand_def(Attribute)

    traits = traits_def(IsTerminator(), NoMemoryEffect())

    def __init__(self, value: SSAValue | None = None):
        super().__init__(operands=[value])

name = 'llvm.return' class-attribute instance-attribute

assembly_format = '($arg^ `:` type($arg))? attr-dict' class-attribute instance-attribute

arg = opt_operand_def(Attribute) class-attribute instance-attribute

traits = traits_def(IsTerminator(), NoMemoryEffect()) class-attribute instance-attribute

__init__(value: SSAValue | None = None)

Source code in xdsl/dialects/llvm.py
1707
1708
def __init__(self, value: SSAValue | None = None):
    super().__init__(operands=[value])

ConstantOp

Bases: IRDLOperation

Source code in xdsl/dialects/llvm.py
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
@irdl_op_definition
class ConstantOp(IRDLOperation):
    name = "llvm.mlir.constant"
    result = result_def(Attribute)
    value = prop_def()

    traits = traits_def(NoMemoryEffect())

    def __init__(self, value: Attribute, value_type: Attribute):
        super().__init__(properties={"value": value}, result_types=[value_type])

    @classmethod
    def parse_value(cls, parser: Parser) -> Attribute:
        b = parser.parse_optional_boolean()
        if b is not None:
            return IntegerAttr.from_bool(b)
        attr = parser.parse_optional_attribute()
        if attr:
            return attr
        return IntegerAttr(parser.parse_integer(), 64)

    @classmethod
    def parse(cls, parser: Parser):
        parser.parse_characters("(")
        value = cls.parse_value(parser)
        parser.parse_characters(")")
        parser.parse_characters(":")
        value_type = parser.parse_type()
        return cls(value, value_type)

    def print(self, printer: Printer) -> None:
        with printer.in_parens():
            if isa(self.value, IntegerAttr) and self.result.type == IntegerType(64):
                self.value.print_without_type(printer)
            else:
                printer.print_attribute(self.value)
        printer.print_string(" : ")
        printer.print_attribute(self.result.type)

name = 'llvm.mlir.constant' class-attribute instance-attribute

result = result_def(Attribute) class-attribute instance-attribute

value = prop_def() class-attribute instance-attribute

traits = traits_def(NoMemoryEffect()) class-attribute instance-attribute

__init__(value: Attribute, value_type: Attribute)

Source code in xdsl/dialects/llvm.py
1719
1720
def __init__(self, value: Attribute, value_type: Attribute):
    super().__init__(properties={"value": value}, result_types=[value_type])

parse_value(parser: Parser) -> Attribute classmethod

Source code in xdsl/dialects/llvm.py
1722
1723
1724
1725
1726
1727
1728
1729
1730
@classmethod
def parse_value(cls, parser: Parser) -> Attribute:
    b = parser.parse_optional_boolean()
    if b is not None:
        return IntegerAttr.from_bool(b)
    attr = parser.parse_optional_attribute()
    if attr:
        return attr
    return IntegerAttr(parser.parse_integer(), 64)

parse(parser: Parser) classmethod

Source code in xdsl/dialects/llvm.py
1732
1733
1734
1735
1736
1737
1738
1739
@classmethod
def parse(cls, parser: Parser):
    parser.parse_characters("(")
    value = cls.parse_value(parser)
    parser.parse_characters(")")
    parser.parse_characters(":")
    value_type = parser.parse_type()
    return cls(value, value_type)

print(printer: Printer) -> None

Source code in xdsl/dialects/llvm.py
1741
1742
1743
1744
1745
1746
1747
1748
def print(self, printer: Printer) -> None:
    with printer.in_parens():
        if isa(self.value, IntegerAttr) and self.result.type == IntegerType(64):
            self.value.print_without_type(printer)
        else:
            printer.print_attribute(self.value)
    printer.print_string(" : ")
    printer.print_attribute(self.result.type)

FastMathAttr dataclass

Bases: FastMathAttrBase

Source code in xdsl/dialects/llvm.py
1751
1752
1753
@irdl_attr_definition(init=False)
class FastMathAttr(FastMathAttrBase):
    name = "llvm.fastmath"

name = 'llvm.fastmath' class-attribute instance-attribute

CallIntrinsicOp

Bases: IRDLOperation

See external documentation.

Source code in xdsl/dialects/llvm.py
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
@irdl_op_definition
class CallIntrinsicOp(IRDLOperation):
    """
    See external [documentation](https://mlir.llvm.org/docs/Dialects/LLVM/#llvmcall_intrinsic-mlirllvmcallintrinsicop).
    """

    name = "llvm.call_intrinsic"

    fastmathFlags = opt_prop_def(FastMathAttr)
    intrin = prop_def(StringAttr)
    op_bundle_sizes = prop_def(DenseArrayBase.constr(i32))
    args = var_operand_def()
    op_bundle_operands = var_operand_def()
    ress = opt_result_def()

    irdl_options = (AttrSizedOperandSegments(as_property=True),)

    def __init__(
        self,
        intrin: StringAttr | str,
        args: Sequence[SSAValue],
        result_types: Sequence[Attribute],
        *,
        op_bundle_sizes: DenseArrayBase,
        op_bundle_operands: Sequence[SSAValue] = (),
    ):
        if isinstance(intrin, str):
            intrin = StringAttr(intrin)
        super().__init__(
            operands=[args, op_bundle_operands],
            result_types=(result_types,),
            properties={
                "intrin": intrin,
                "op_bundle_sizes": op_bundle_sizes,
            },
        )

name = 'llvm.call_intrinsic' class-attribute instance-attribute

fastmathFlags = opt_prop_def(FastMathAttr) class-attribute instance-attribute

intrin = prop_def(StringAttr) class-attribute instance-attribute

op_bundle_sizes = prop_def(DenseArrayBase.constr(i32)) class-attribute instance-attribute

args = var_operand_def() class-attribute instance-attribute

op_bundle_operands = var_operand_def() class-attribute instance-attribute

ress = opt_result_def() class-attribute instance-attribute

irdl_options = (AttrSizedOperandSegments(as_property=True),) class-attribute instance-attribute

__init__(intrin: StringAttr | str, args: Sequence[SSAValue], result_types: Sequence[Attribute], *, op_bundle_sizes: DenseArrayBase, op_bundle_operands: Sequence[SSAValue] = ())

Source code in xdsl/dialects/llvm.py
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
def __init__(
    self,
    intrin: StringAttr | str,
    args: Sequence[SSAValue],
    result_types: Sequence[Attribute],
    *,
    op_bundle_sizes: DenseArrayBase,
    op_bundle_operands: Sequence[SSAValue] = (),
):
    if isinstance(intrin, str):
        intrin = StringAttr(intrin)
    super().__init__(
        operands=[args, op_bundle_operands],
        result_types=(result_types,),
        properties={
            "intrin": intrin,
            "op_bundle_sizes": op_bundle_sizes,
        },
    )

CallOp

Bases: IRDLOperation

Source code in xdsl/dialects/llvm.py
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
@irdl_op_definition
class CallOp(IRDLOperation):
    name = "llvm.call"

    args = var_operand_def()
    op_bundle_operands = var_operand_def()

    callee = opt_prop_def(SymbolRefAttr)
    var_callee_type = opt_prop_def(LLVMFunctionType)
    fastmathFlags = prop_def(FastMathAttr, default_value=FastMathAttr("none"))
    CConv = prop_def(CallingConventionAttr, default_value=CallingConventionAttr("ccc"))
    op_bundle_sizes = prop_def(
        DenseArrayBase.constr(i32),
        default_value=DenseArrayBase.from_list(i32, ()),
    )
    TailCallKind = prop_def(
        TailCallKindAttr, default_value=TailCallKindAttr(TailCallKind.NONE)
    )
    returned = opt_result_def()

    irdl_options = (AttrSizedOperandSegments(as_property=True),)

    def __init__(
        self,
        callee: str | SymbolRefAttr | StringAttr,
        *args: SSAValue | Operation,
        op_bundle_sizes: DenseArrayBase = DenseArrayBase.from_list(i32, ()),
        op_bundle_operands: tuple[SSAValue, ...] = (),
        return_type: Attribute | None = None,
        calling_convention: CallingConventionAttr = CallingConventionAttr("ccc"),
        fastmath: FastMathAttr = FastMathAttr(None),
        variadic_args: int = 0,
    ):
        if isinstance(callee, str):
            callee = SymbolRefAttr(callee)
        op_result_type = [return_type]
        if return_type is None:
            return_type = LLVMVoidType()
        input_types = [
            SSAValue.get(arg).type for arg in args[: len(args) - variadic_args]
        ]
        if variadic_args:
            var_callee_type = LLVMFunctionType(
                input_types, return_type, bool(variadic_args)
            )
        else:
            var_callee_type = None
        super().__init__(
            operands=[args, op_bundle_operands],
            properties={
                "callee": callee,
                "var_callee_type": var_callee_type,
                "fastmathFlags": fastmath,
                "CConv": calling_convention,
                "op_bundle_sizes": op_bundle_sizes,
            },
            result_types=op_result_type,
        )

name = 'llvm.call' class-attribute instance-attribute

args = var_operand_def() class-attribute instance-attribute

op_bundle_operands = var_operand_def() class-attribute instance-attribute

callee = opt_prop_def(SymbolRefAttr) class-attribute instance-attribute

var_callee_type = opt_prop_def(LLVMFunctionType) class-attribute instance-attribute

fastmathFlags = prop_def(FastMathAttr, default_value=(FastMathAttr('none'))) class-attribute instance-attribute

CConv = prop_def(CallingConventionAttr, default_value=(CallingConventionAttr('ccc'))) class-attribute instance-attribute

op_bundle_sizes = prop_def(DenseArrayBase.constr(i32), default_value=(DenseArrayBase.from_list(i32, ()))) class-attribute instance-attribute

TailCallKind = prop_def(TailCallKindAttr, default_value=(TailCallKindAttr(TailCallKind.NONE))) class-attribute instance-attribute

returned = opt_result_def() class-attribute instance-attribute

irdl_options = (AttrSizedOperandSegments(as_property=True),) class-attribute instance-attribute

__init__(callee: str | SymbolRefAttr | StringAttr, *args: SSAValue | Operation, op_bundle_sizes: DenseArrayBase = DenseArrayBase.from_list(i32, ()), op_bundle_operands: tuple[SSAValue, ...] = (), return_type: Attribute | None = None, calling_convention: CallingConventionAttr = CallingConventionAttr('ccc'), fastmath: FastMathAttr = FastMathAttr(None), variadic_args: int = 0)

Source code in xdsl/dialects/llvm.py
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
def __init__(
    self,
    callee: str | SymbolRefAttr | StringAttr,
    *args: SSAValue | Operation,
    op_bundle_sizes: DenseArrayBase = DenseArrayBase.from_list(i32, ()),
    op_bundle_operands: tuple[SSAValue, ...] = (),
    return_type: Attribute | None = None,
    calling_convention: CallingConventionAttr = CallingConventionAttr("ccc"),
    fastmath: FastMathAttr = FastMathAttr(None),
    variadic_args: int = 0,
):
    if isinstance(callee, str):
        callee = SymbolRefAttr(callee)
    op_result_type = [return_type]
    if return_type is None:
        return_type = LLVMVoidType()
    input_types = [
        SSAValue.get(arg).type for arg in args[: len(args) - variadic_args]
    ]
    if variadic_args:
        var_callee_type = LLVMFunctionType(
            input_types, return_type, bool(variadic_args)
        )
    else:
        var_callee_type = None
    super().__init__(
        operands=[args, op_bundle_operands],
        properties={
            "callee": callee,
            "var_callee_type": var_callee_type,
            "fastmathFlags": fastmath,
            "CConv": calling_convention,
            "op_bundle_sizes": op_bundle_sizes,
        },
        result_types=op_result_type,
    )

ZeroOp dataclass

Bases: IRDLOperation

Source code in xdsl/dialects/llvm.py
1866
1867
1868
1869
1870
1871
1872
1873
1874
@irdl_op_definition
class ZeroOp(IRDLOperation):
    name = "llvm.mlir.zero"

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

    traits = traits_def(NoMemoryEffect())

    res = result_def(LLVMTypeConstr)

name = 'llvm.mlir.zero' class-attribute instance-attribute

assembly_format = 'attr-dict `:` type($res)' class-attribute instance-attribute

traits = traits_def(NoMemoryEffect()) class-attribute instance-attribute

res = result_def(LLVMTypeConstr) class-attribute instance-attribute

GenericCastOp

Bases: IRDLOperation, ABC

Source code in xdsl/dialects/llvm.py
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
class GenericCastOp(IRDLOperation, ABC):
    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],
        )

arg = operand_def(Attribute) class-attribute instance-attribute

LLVM-compatible non-aggregate type

result = result_def(Attribute) class-attribute instance-attribute

LLVM-compatible non-aggregate type

traits = traits_def(NoMemoryEffect()) class-attribute instance-attribute

assembly_format = '$arg attr-dict `:` type($arg) `to` type($result)' class-attribute instance-attribute

__init__(val: Operation | SSAValue, res_type: Attribute)

Source code in xdsl/dialects/llvm.py
1892
1893
1894
1895
1896
def __init__(self, val: Operation | SSAValue, res_type: Attribute):
    super().__init__(
        operands=[SSAValue.get(val)],
        result_types=[res_type],
    )

AbstractFloatArithOp

Bases: IRDLOperation, ABC

Source code in xdsl/dialects/llvm.py
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
class AbstractFloatArithOp(IRDLOperation, ABC):
    T: ClassVar = VarConstraint("T", AnyFloatConstr | VectorType.constr(AnyFloatConstr))

    lhs = operand_def(T)
    rhs = operand_def(T)
    res = result_def(T)

    fastmathFlags = prop_def(FastMathAttr, default_value=FastMathAttr(None))

    traits = traits_def(Pure(), SameOperandsAndResultType())

    assembly_format = "$lhs `,` $rhs attr-dict `:` type($lhs)"

    irdl_options = (ParsePropInAttrDict(),)

    def __init__(
        self,
        lhs: SSAValue | Operation,
        rhs: SSAValue | Operation,
        fast_math: FastMathAttr | FastMathFlag | None = None,
        attrs: dict[str, Attribute] | None = None,
    ):
        if isinstance(fast_math, FastMathFlag | str | None):
            fast_math = FastMathAttr(fast_math)

        super().__init__(
            operands=[lhs, rhs],
            result_types=[SSAValue.get(lhs).type],
            properties={"fastmathFlags": fast_math},
            attributes=attrs,
        )

T: ClassVar = VarConstraint('T', AnyFloatConstr | VectorType.constr(AnyFloatConstr)) class-attribute instance-attribute

lhs = operand_def(T) class-attribute instance-attribute

rhs = operand_def(T) class-attribute instance-attribute

res = result_def(T) class-attribute instance-attribute

fastmathFlags = prop_def(FastMathAttr, default_value=(FastMathAttr(None))) class-attribute instance-attribute

traits = traits_def(Pure(), SameOperandsAndResultType()) class-attribute instance-attribute

assembly_format = '$lhs `,` $rhs attr-dict `:` type($lhs)' class-attribute instance-attribute

irdl_options = (ParsePropInAttrDict(),) class-attribute instance-attribute

__init__(lhs: SSAValue | Operation, rhs: SSAValue | Operation, fast_math: FastMathAttr | FastMathFlag | None = None, attrs: dict[str, Attribute] | None = None)

Source code in xdsl/dialects/llvm.py
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
def __init__(
    self,
    lhs: SSAValue | Operation,
    rhs: SSAValue | Operation,
    fast_math: FastMathAttr | FastMathFlag | None = None,
    attrs: dict[str, Attribute] | None = None,
):
    if isinstance(fast_math, FastMathFlag | str | None):
        fast_math = FastMathAttr(fast_math)

    super().__init__(
        operands=[lhs, rhs],
        result_types=[SSAValue.get(lhs).type],
        properties={"fastmathFlags": fast_math},
        attributes=attrs,
    )

FAddOp dataclass

Bases: AbstractFloatArithOp

Source code in xdsl/dialects/llvm.py
1932
1933
1934
@irdl_op_definition
class FAddOp(AbstractFloatArithOp):
    name = "llvm.fadd"

name = 'llvm.fadd' class-attribute instance-attribute

FMulOp dataclass

Bases: AbstractFloatArithOp

Source code in xdsl/dialects/llvm.py
1937
1938
1939
@irdl_op_definition
class FMulOp(AbstractFloatArithOp):
    name = "llvm.fmul"

name = 'llvm.fmul' class-attribute instance-attribute

FDivOp dataclass

Bases: AbstractFloatArithOp

Source code in xdsl/dialects/llvm.py
1942
1943
1944
@irdl_op_definition
class FDivOp(AbstractFloatArithOp):
    name = "llvm.fdiv"

name = 'llvm.fdiv' class-attribute instance-attribute

FSubOp dataclass

Bases: AbstractFloatArithOp

Source code in xdsl/dialects/llvm.py
1947
1948
1949
@irdl_op_definition
class FSubOp(AbstractFloatArithOp):
    name = "llvm.fsub"

name = 'llvm.fsub' class-attribute instance-attribute

FRemOp dataclass

Bases: AbstractFloatArithOp

Source code in xdsl/dialects/llvm.py
1952
1953
1954
@irdl_op_definition
class FRemOp(AbstractFloatArithOp):
    name = "llvm.frem"

name = 'llvm.frem' class-attribute instance-attribute

BitcastOp dataclass

Bases: GenericCastOp

Source code in xdsl/dialects/llvm.py
1957
1958
1959
@irdl_op_definition
class BitcastOp(GenericCastOp):
    name = "llvm.bitcast"

name = 'llvm.bitcast' class-attribute instance-attribute

SIToFPOp dataclass

Bases: GenericCastOp

Source code in xdsl/dialects/llvm.py
1962
1963
1964
@irdl_op_definition
class SIToFPOp(GenericCastOp):
    name = "llvm.sitofp"

name = 'llvm.sitofp' class-attribute instance-attribute

FPExtOp dataclass

Bases: GenericCastOp

Source code in xdsl/dialects/llvm.py
1967
1968
1969
@irdl_op_definition
class FPExtOp(GenericCastOp):
    name = "llvm.fpext"

name = 'llvm.fpext' class-attribute instance-attribute

UnreachableOp dataclass

Bases: IRDLOperation

Source code in xdsl/dialects/llvm.py
1972
1973
1974
1975
1976
1977
@irdl_op_definition
class UnreachableOp(IRDLOperation):
    name = "llvm.unreachable"

    traits = traits_def(IsTerminator())
    assembly_format = "attr-dict"

name = 'llvm.unreachable' class-attribute instance-attribute

traits = traits_def(IsTerminator()) class-attribute instance-attribute

assembly_format = 'attr-dict' class-attribute instance-attribute

parse_llvm_type(parser: AttrParser) -> Attribute

Source code in xdsl/dialects/llvm.py
100
101
102
103
def parse_llvm_type(parser: AttrParser) -> Attribute:
    if (l := _parse_optional_llvm_type(parser)) is not None:
        return l
    return parser.parse_attribute()

parse_optional_llvm_type(parser: AttrParser) -> Attribute | None

Source code in xdsl/dialects/llvm.py
106
107
108
109
def parse_optional_llvm_type(parser: AttrParser) -> Attribute | None:
    if (l := _parse_optional_llvm_type(parser)) is not None:
        return l
    return parser.parse_optional_attribute()