I need to modify llvm bytecode / native code just before it is emitted i.e. after all the regular operations and optimizations are done. I was told that this can be achieved by implementing a MachineFunctionPass.
I searched the internet for some tutorials or some example MachineFunctionPass but found nothing. Kindly point some links, or anything that may help. Thank you.
You could check the code in lib/Target/ARM/ARMOptimizeBarriersPass.cpp for an example of a MachineFunctionPass that runs very late. Look in lib/Target/ARM/ARMTargetMachine.cpp to see where it is added to the pass pipeline.
– Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
You will want to read up on the LLVM Code Generator infrastructure: http://llvm.org/docs/CodeGenerator.html#machine-code-description-classes
Also, a MachineFunctionPass is nearly the same as an LLVM FunctionPass except that it operations on MachineFunction objects instead of Function objects. If you read the "Writing an LLVM Pass" document (http://llvm.org/docs/WritingAnLLVMPass.html) and understand how to use MachineInstr's, MachineBasicBlocks, and MachineInstr's, you should be able to figure it out.
Finally, take a look at the doxygen documentation anytime you need details on how to use a specific LLVM class, and as David suggested, take a look at existing code.
Thank you Mr. John and Mr. David !