Expand description
index
dialect.
The Index dialect contains operations for manipulating values of the builtin
index
type. The index type models target-specific values of pointer width,
like intptr_t
. Index values are typically used as loop bounds, array
subscripts, tensor dimensions, etc.
The operations in this dialect operate exclusively on scalar index types. The dialect and its operations treat the index type as signless and contains signed and unsigned versions of certain operations where the distinction is meaningful. In particular, the operations and transformations are careful to be aware of the target-independent-ness of the index type, such as when folding.
The folding semantics of the Index dialect operations ensure that folding
produces the same results irrespective of the eventual target pointer width.
All index constants are stored in APInt
s of maximum index bitwidth: 64.
Operations are folded using 64-bit integer arithmetic.
For operations where the values of the upper 32 bits don’t impact the values of the lower 32 bits, no additional handling is required because if the target is 32-bit, the truncated folded result will be the same as if the operation were computed with 32-bit arithmetic, and if the target is 64-bit, the fold result is valid by default.
Consider addition: an overflow in 32-bit is the same as truncating the
result computed in 64-bit. For example, add(0x800000008, 0x800000008)
is
0x1000000010
in 64-bit, which truncates to 0x10
, the same result as
truncating the operands first: add(0x08, 0x08)
. Specifically, an operation
f
can always be folded if it satisfies the following for all 64-bit values
of a
and b
:
trunc(f(a, b)) = f(trunc(a), trunc(b))
When materializing target-specific code, constants just need to be truncated as appropriate.
Operations where the values of the upper 32 bits do impact the values of the
lower 32 bits are not folded if the results would be different in 32-bit.
These are operations that right shift – division, remainder, etc. These
operations are only folded for subsets of a
and b
for which the above
property is satisfied. This is checked per fold attempt.
Consider division: the 32-bit computation will differ from 64-bit if the
latter results in a high bit shifted into the lower 32 bits. For example,
div(0x100000002, 2)
is 0x80000001
in 64-bit but 0x01
in 32-bit; it
cannot be folded. However, div(0x200000002, 2)
can be folded. The 64-bit
result is 0x100000001
, which truncated to 32 bits is 0x01
. The 32-bit
result of the operation with truncated operands div(0x02, 2)
which is
0x01
, the same as truncating the 64-bit result.
Structs§
- An
add
operation. Index addition. - A builder for an
add
operation. - An
and
operation. Index bitwise and. - A builder for an
and
operation. - A
bool.constant
operation. Boolean constant. - A builder for a
bool.constant
operation. - A
casts
operation. Index signed cast. - A builder for a
casts
operation. - A
castu
operation. Index unsigned cast. - A builder for a
castu
operation. - A
ceildivs
operation. Index signed ceil division. - A builder for a
ceildivs
operation. - A
ceildivu
operation. Index unsigned ceil division. - A builder for a
ceildivu
operation. - A
cmp
operation. Index compare. - A builder for a
cmp
operation. - A
constant
operation. Index constant. - A builder for a
constant
operation. - A
divs
operation. Index signed division. - A builder for a
divs
operation. - A
divu
operation. Index unsigned division. - A builder for a
divu
operation. - A
floordivs
operation. Index signed floor division. - A builder for a
floordivs
operation. - A
maxs
operation. Index signed maximum. - A builder for a
maxs
operation. - A
maxu
operation. Index unsigned maximum. - A builder for a
maxu
operation. - A
mins
operation. Index signed minimum. - A builder for a
mins
operation. - A
minu
operation. Index unsigned minimum. - A builder for a
minu
operation. - A
mul
operation. Index multiplication. - A builder for a
mul
operation. - An
or
operation. Index bitwise or. - A builder for an
or
operation. - A
rems
operation. Index signed remainder. - A builder for a
rems
operation. - A
remu
operation. Index unsigned remainder. - A builder for a
remu
operation. - A
shl
operation. Index shift left. - A builder for a
shl
operation. - A
shrs
operation. Signed index shift right. - A builder for a
shrs
operation. - A
shru
operation. Unsigned index shift right. - A builder for a
shru
operation. - A
sizeof
operation. Size in bits of the index type. - A builder for a
sizeof
operation. - A
sub
operation. Index subtraction. - A builder for a
sub
operation. - A
xor
operation. Index bitwise xor. - A builder for a
xor
operation.
Functions§
- Creates an
add
operation. - Creates an
and
operation. - Creates a
bool.constant
operation. - Creates a
casts
operation. - Creates a
castu
operation. - Creates a
ceildivs
operation. - Creates a
ceildivu
operation. - Creates a
cmp
operation. - Creates a
constant
operation. - Creates a
divs
operation. - Creates a
divu
operation. - Creates a
floordivs
operation. - Creates a
maxs
operation. - Creates a
maxu
operation. - Creates a
mins
operation. - Creates a
minu
operation. - Creates a
mul
operation. - Creates an
or
operation. - Creates a
rems
operation. - Creates a
remu
operation. - Creates a
shl
operation. - Creates a
shrs
operation. - Creates a
shru
operation. - Creates a
sizeof
operation. - Creates a
sub
operation. - Creates a
xor
operation.