Set the minimum number of allocated bits for a variable


I would like to force the minimum number of bits allocated for a variable in memory to be 16. From what I have seen, i1 is already represented on 8 bits. So, the only change would be to represent i1 and i8 on 16 bits, as all other types already fulfill this condition.

TargetData can help by setting a higher alignment, thus although the type is i1 or i8, the number of allocated bits is 16.

What is the best approach to impose this?

(i) modifying the back-end of LLVM

  • where can I find the defaults for specifying the number of allocated bits for each type?
    (ii) writing a pass that overwrites these defaults?

  • by asking for an alignment higher than the default

  • one approach is to set a higher alignment for each allocated variable of type i1 or i8, but this means digging inside the arrays, vectors and structures to check the type of each element.

Looking forward to receiving your suggestions.

Thank you,

Hi Alexandra,

I’m not sure want you want to do. Is the data layout string (, also usually set by each target specific *TargetMachine constructor), for setting the alignment good enough for you?

Or is it more than the alignment you want to control? Do you have a target with 16-bit bytes? In that case, there is quite a lot of changes that needs to be done (we maintain some patches internally that we can provide upon request).


Patrik Hägglund

Hello Patrik,

Thank you for your reply. Indeed, setting the alignment using the constructor is sufficient.