Hey.
I’m trying to add vargs support to my backend.
I’m trying to figure out how to do it, and would like to get help.
I’m still learning about the implementation of VARS, if anyone can help with that too if would be great.
For what I’ve learned so far, there is a pointer on the stack, pointing at the first VARG, and va_arg is fetching the value from the pointer and advances it.
Either way.
My current calling convention is:
The first arguments are stored in registers, there are two 32-bit registers reserved for this purpose.
The rest of the arguments go to the stack.
def BF_CCallingConv : CallingConv<[
CCIfType<[i8], CCAssignToReg<[R_33_b, R_35_b, R_37_b, R_39_b, R_41_b, R_43_b, R_45_b, R_47_b]>>,
CCIfType<[i16], CCAssignToReg<[R_33_w, R_37_w, R_41_w, R_45_w]>>,
CCIfType<[i32], CCAssignToReg<[R_33_d, R_41_d]>>,
CCIfType<[i8], CCAssignToStack<1, 1>>,
CCIfType<[i16], CCAssignToStack<2, 2>>,
CCIfType<[i32], CCAssignToStack<4, 4>>
]>;
I’d like to know if that is enough for VARGS, or should I change something.
As for the implementation of VARGS.
The location of the pointer to the current varg doesn’t really matter, it could be on the stack, but if possible, I’d rather use a register when avilable.
For the actuall vargs, I guess it would be best to just throw them on the stack and let the pointer do its work.
Now, It seems that the most basic opcode I need to lower is ISD::VASTART.
I’ve looked in some other implementations, like SPARC and ARC, it seems that I can imeplement my own MachineFunctionInfo, and store the location of the vargs pointer in there when lowering call, and that use it to lower VASTART, letting it know the location of the pointer.
I still need to figure how to find the location of the next avilable frame index when lowering CALL, but I guess it just matter of understanding the call lowering process better than I do now.
Another thing is, it seems that VAARG could be just Expand and it should work on its own? I’d like to know the pros and cons.
Same for VACOPY and VAEND, which I’m not even sure what they do in the first place.
Every help would be appriciated.
Thanks ![]()