Skip to content

vector

Functions:

emit_add

emit_add(
    ir_builder: IRBuilder,
    lhs: Value,
    rhs: Value,
    name: str = "addtmp",
) -> Instruction
Source code in src/irx/builders/llvmliteir/vector.py
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
def emit_add(
    ir_builder: ir.IRBuilder,
    lhs: ir.Value,
    rhs: ir.Value,
    name: str = "addtmp",
) -> ir.Instruction:
    """
    title: Emit add.
    parameters:
      ir_builder:
        type: ir.IRBuilder
      lhs:
        type: ir.Value
      rhs:
        type: ir.Value
      name:
        type: str
    returns:
      type: ir.Instruction
    """
    if is_fp_type(lhs.type):
        return ir_builder.fadd(lhs, rhs, name=name)
    return ir_builder.add(lhs, rhs, name=name)

emit_int_div

emit_int_div(
    ir_builder: IRBuilder,
    lhs: Value,
    rhs: Value,
    unsigned: bool,
) -> Instruction
Source code in src/irx/builders/llvmliteir/vector.py
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
def emit_int_div(
    ir_builder: ir.IRBuilder,
    lhs: ir.Value,
    rhs: ir.Value,
    unsigned: bool,
) -> ir.Instruction:
    """
    title: Emit int div.
    parameters:
      ir_builder:
        type: ir.IRBuilder
      lhs:
        type: ir.Value
      rhs:
        type: ir.Value
      unsigned:
        type: bool
    returns:
      type: ir.Instruction
    """
    return (
        ir_builder.udiv(lhs, rhs, name="vdivtmp")
        if unsigned
        else ir_builder.sdiv(lhs, rhs, name="vdivtmp")
    )

is_vector

is_vector(value: Value) -> bool
Source code in src/irx/builders/llvmliteir/vector.py
13
14
15
16
17
18
19
20
21
22
def is_vector(value: ir.Value) -> bool:
    """
    title: Is vector.
    parameters:
      value:
        type: ir.Value
    returns:
      type: bool
    """
    return isinstance(getattr(value, "type", None), VectorType)

splat_scalar

splat_scalar(
    ir_builder: IRBuilder,
    scalar: Value,
    vec_type: VectorType,
) -> Value
Source code in src/irx/builders/llvmliteir/vector.py
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
def splat_scalar(
    ir_builder: ir.IRBuilder,
    scalar: ir.Value,
    vec_type: ir.VectorType,
) -> ir.Value:
    """
    title: Splat scalar.
    parameters:
      ir_builder:
        type: ir.IRBuilder
      scalar:
        type: ir.Value
      vec_type:
        type: ir.VectorType
    returns:
      type: ir.Value
    """
    zero_i32 = ir.Constant(ir.IntType(32), 0)
    undef_vec = ir.Constant(vec_type, ir.Undefined)
    vector_zero = ir_builder.insert_element(undef_vec, scalar, zero_i32)
    mask_ty = ir.VectorType(ir.IntType(32), vec_type.count)
    mask = ir.Constant(mask_ty, [0] * vec_type.count)
    return ir_builder.shuffle_vector(vector_zero, undef_vec, mask)