Make bit range operator more versatile
Closed this issue · 3 comments
The bit range operator must have a fixed size. Do achieve this, it is currently limited to compile-time-constant expressions comprised only of literals and parameters. However, this semantic precludes using it e.g. in a loop:
for (i = 0; i < sizeof(x); i += 3)
x[i+2:i] = ... // prohibited
The proposed solution is to relax the restriction and allow arbitrary expressions, under the condition that the frontend is able to evaluate (from)-(to)
at compile-time to a constant value. In the example above, this would mean to determine that i+2 - i
evaluates to 2
and the variable reference expression cancels out.
Decided to keep the [start:end]
syntax (see #52), but we'll relax the compile-time-constness-constraint. Instead, arbitrary expression are allowed as long as the range size is compile-time constant. A limited set of patterns that an frontend must understand will be specified.
Implemented and successfully used in the MLIR code generator.