I am wondering how I can prevent the LLVM from re-ordering the added local variables during instrumentation?
Because, during the instrumentation, I add some metadata to some local variables, exactly next to it, and the generated bitcode looks good. However, when it is executed, basically the stack is formed as all original local variables are located next to each other, and then all the metadata is inserted. In other words, I was expecting to have “data, metadata, data, metadata”, however, I was seeing “data, data, metadata, metadata” in the actual stack.
Investigating into this problem, I realized that when printing the instruction instance (errs() << AI << “\n”), there is a numbering for each AllocaInst. However, the newly-added AllocaInsts, during instrumentation, are having a way higher number than the original AllocaInsts’, and I guess that is why all the original local variables are first located in the stack, and then the metadata that I added are inserted into the stack.
I am wondering how I can prevent LLVM from doing re-ordering them, or even reset the AllocaInst numbers, so the newly added AllocaInst can be inserted between the existing and original local variables?
Look forward to hearing from you.