A question about RISCV's target function frame & stack object


I want to make some changes to RISCV64’s frame, especially when accessing stack objects, due to a hardware issue. But I need help.

For example, the following C code

void foo(int a, int b, int num) {

int arr0[8] = {…}; // This is a fixed size array on RISCV64 stack

int arr1[num]; // This is a variable size array on RISCV64 stack

arr0[a] = b;

arr1[a] = b;



For both arr0[a] = b and arr1[a] = b, two SW instructions are generated. And I would like to insert an ADDI (via BuildMI) before each SW, due to a HW issue !!!

Actually I have found solution for the fixed size array, that is writing a BuildMI() inside RISCVRegisterInfo::eliminateFrameIndex() of RISCVRegisterInfo.cpp,

However I do not know how the insert the ADDI for the variable size array. Where should I insert the BuildMI (ADDI)?

It seems the SW for the variable size array does not run into RISCVRegisterInfo::eliminateFrameIndex()

I really appreciate if anybody help me. Thanks.

Ben Shi