I wanted to use __attribute__((bitwidth(N))) to define custom-sized integer types when generating LLVM IR code with clang. I found some information that there is no plan to support this attribute. However, supporting such an attribute for IR generation (i.e. assembly representation) would be very helpful.
My use-case: I want to write a compiler for a custom micro-architecture with smallest possible effort*. The architecture only supports a very specific/unusual bitwidth. "Programs" for the micro-architecture are supposed to be written in a limited subset of C. In this context it is promising to use clang in order to generate LLVM IR and use this as basis for further processing. It would be great if the bitwidth attribute could be used to pass additional information about datatypes on to the next step as in the following example:
C-Code:
typedef int __attribute__((bitwidth(22))) int22;
int22 myVar = 0;
LLVM IR Assembly:
@myVar = global i22 0, align 3
; note that the align information is not relevant
; in my case, i.e. "align 4" would also be fine
Maybe there is some trick to "enable" this attribute for IR (wouldn't be too difficult to implement IMHO), or someone has more recent information than I could find (the llvm bugzilla entry is rather old now).
If not, maybe there is some alternative approach how I could "attach" additional information about the datatypes defined in C.
*) Adding a custom micro-architecture to clang (so that the -target option can be used) is regraded as very complex. True?