<div dir="ltr"><div>I'm trying to build an analysis pass over LLVM target-independent<br>machine code. However, I need the machine code to be "as close<br>to its future target-specific code as possible". As far as I understand<br>the LLVM backend infrastructure, the following applies:<br><br>- the LLVM IR abstracts the input code, allowing for many analysis<br>  and optimization passes to take place;<br>- after that, a series of passes converts the IR representation into other<br>  temporary structures, by taking target-specific decisions;<br>- finally, at the very beginning of code emission, there are<br>  MachineFunctions, i.e., CFGs composed of MachineBasicBlocks<br>  (sequences of MachineInstrs);<br>- during code emission, MachineInstrs are converted into MCInsts,<br>  which are later   emitted as either target-specific assembly<br>  or binary object.<br><br>Since my goal is to deal with target-independent code, I must not write<br>a pass to be executed by a single target-specific module. Yet, I have not<br>found how to properly add a pass just before code emission.<br><br>As a workaround, I've added a stub in file:<br><br>    ~/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cppAsmPrinter.cpp<br><br>to call my analysis method over MachineFunctions. Despite the fact<br>that it does work, I'd like to know if is there any elegant/correct way<br>to do such analysis.<br><br>Notice my pass simply analyzes such structures, thus not modifying<br>any of them. Also, it simply works because every target-specific<br>code-emission module inherits from LLMV::AsmPrinter, which means<br>I have my analysis called upon any target-specific compilation<br>(with llc -march=... input.bc).<br><br>Any ideas/suggestions on how to implement such analysis without<br>resorting to adding stubs/function calls on the AsmPrinter?<br><br><br></div>Regards!</div>