compiler construction - LLVM How to detect when a specific ASM instruction sequence is generated -
i compiling c program using llvm. want know if particular assembly sequence generated , if generated, source code line associated with. example , want log every time push %eax
instruction generated. there way approach problem?
in case others stumble upon similar problem.
the place looked @ llvms backend code. in particular concerned x86 assembly generation.
there 2 main areas modify , add tests.
asmprinter
class @lib/codegen/asmprinter/asmprinter.cpp
has different emit functions deal functions, basic blocks etc. go through them. these functions iterate through each machine instructionsmi
has functionsgetoperand()
,getopcode()
check specific instructions per requirement.
each specific opcode , actual instructions specified in target specific files eg.lib/target/x86/x86geninstrinfo.inc
- the above functions in turn call target specific subclass functions. in case x86asmprinter , similar classes.
to poke around add log statments such
errs()<<"opcode "<<mi.getopcode()<<"\n"; mi.dump();
and can see these error messages when running llc file.bc
hope helps