I am trying to encode the labeled union (also known as the sum type) in LLVM, and this is not possible, while preserving the agnostic of the front-end compiler platform. Imagine I had this tagged union (expressed in Rust):
enum T {
C1(i32, i64),
C2(i64)
}
To encode this in LLVM, I need to know the size of the largest option. This, in turn, requires me to know the alignment and size of all fields. In other words, my interface should
- track the size and alignment of all things
- create a dummy structure (correctly complemented) to represent the largest type that can match any option (for example
{[2 x i64]}, assuming the tag can match the same word as the field i32), - and finally, either use packed structures or tell LLVM which “data layout” I assumed, so my calculations correspond to LLVM
What is the best way to encode labeled joins in LLVM?
source
share