Recently, I am working on some information collection on the machine instruction (MachineInstr) level.
But, sometimes, I need check the corresponding IR level instruction of the a machine instruction.
When visiting a machine instruction which is a call (MachineInstr::isCall()), I need to check the arguments of this call site.
I know that the CallSite class provides good facility for this work, but the CallSite can be constructed only fromInstruction rather than MachineInstr.
Is there any workaround?
If you’re working on MachineInstr’s, then you can probably examine the MachineIntr’s operands to determine which function is being called. This probably won’t be target independent, but if you’re working at the MachineInstr level, you’re not doing target independent work, anyway. Alternatively, you should check to see if the MachineBasicBlock has a method to fetch the BasicBlock from which it was generated. Using that, you could potentially scan the BasicBlock looking for a CallInst or InvokeInst that is likely to match the MachineInstr. Regards, John Criswell
Thanks so much!
I have checked the BasicBlock. However, there may be multiple call sites in one basic block, so it cannot guarantee correctness.
Finally, I chose to add the CallInst into VDNode during DAG construction, and then add the CallInst into MachineInstr during instruction selection.
Thanks all the same!