How to get stack argument alignment? I noticed this is distinct from DL->getStackAlignment() since that returns the alignment of stack pointer before a call instruction. For example in x64 Sys V ABI stack pointer is required to be 16-byte aligned, while arguments passed on stack are 8-byte aligned. How do I get the latter value programmatically?
In general, the alignment of arguments passed on the stack depends on the types involved. It’s computed inside the target’s call lowering code (in SelectionDAG or GlobalISel).
byval arguments should have an “align” attribute specifying the alignment.
It’s specified in llvm-project/X86CallingConv.td at main · llvm/llvm-project · GitHub
You can get the information from the generated X86GenCallingConv.inc
in you build folder. Something like
static bool CC_X86_64_C(unsigned ValNo, MVT ValVT,
MVT LocVT, CCValAssign::LocInfo LocInfo,
ISD::ArgFlagsTy ArgFlags, CCState &State) {
if (ArgFlags.isByVal()) {
State.HandleByVal(ValNo, ValVT, LocVT, LocInfo, 8, Align(8), ArgFlags);
return false;
}
... ...
if (LocVT == MVT::i32 ||
LocVT == MVT::i64 ||
LocVT == MVT::f16 ||
LocVT == MVT::f32 ||
LocVT == MVT::f64) {
unsigned Offset6 = State.AllocateStack(8, Align(8));
State.addLoc(CCValAssign::getMem(ValNo, ValVT, Offset6, LocVT, LocInfo));
return false;
}
... ...