Runtime alignment

For the size of a type to be calculated at runtime, there is a known trick with gep. Is there any similar trick for determining the alignment of a type at runtime for target-independent IR?

There's ConstantExpr::getAlignOf to go with getSizeOf and getOffsetOf. The
implementation has this comment:

  // alignof is implemented as: (i64) gep ({i1,Ty}*)null, 0, 1
  // Note that a non-inbounds gep is used, as null isn't within any object.

Nick

Thanks, that’s sweet. I’ve been thinking about using this in various contexts and I’ve come to the conclusion that it’s not that useful because the alloca alignment cannot be a ConstantExpr, so there’s no way to defer alignment for trying to create IR that’s more target-independent. I’ve been thinking about suggesting that some IR-level constructs that currently require literal constants, like array sizes and alloca alignment, should be changed to be ConstantExprs.

Thanks, that's sweet. I've been thinking about using this in various
contexts and I've come to the conclusion that it's not that useful because
the alloca alignment cannot be a ConstantExpr, so there's no way to defer
alignment for trying to create IR that's more target-independent. I've been
thinking about suggesting that some IR-level constructs that currently
require literal constants, like array sizes and alloca alignment, should be
changed to be ConstantExprs.

I don't think that can work either. How do we generate code for an alloca
whose alignment is equal to "&f - &g" when we don't yet know the addresses
of 'f' or of 'g'? They may not be known until after the loader runs.