Is there a way to associate LLVM IR instructions with the instructions they finally generate in the assembly file emitted by LLC? I need to track the PC’s corresponding to certain IR level instructions for ARM.
One way to do this is to tag an IR instruction with a special flag and pass that flag onto the Machine IR created by LLC and then onto Machine Code. It would be helpful if I could get some pointers on how to do this.
Thanks in advance,
University of Michigan, Ann Arbor
You may want to look at the -debug-ir pass, which creates METADATA to emit debugging information that allows you to associate machine instructions with IR instructions. This may or may not be what you want.
Thanks for the pointer. I am unfortunately running into llc problems with this pass.
opt -debug-ir hello.bc -o hello.deb.bc
llc -march=arm -debug -O0 hello.deb.bc -o hello.deb.s
This is aborting with the error: llc: llvm-3.4/lib/CodeGen/AsmPrinter/DwarfDebug.cpp:1614: void llvm::DwarfDebug::beginFunction(const llvm::MachineFunction*): Assertion `TheCU && “Unable to find compile unit!”’ failed.
I’m assuming this is because llc found some errors in the metadata that debug-ir prints out. How do I find and correct this?
This is indeed surprising. I have no idea where this is coming from. Does this only happen on ARM? Can you attach the debug.bc file? Or even better, open a bug report for that?
I included Daniel who committed the -debug-ir pass as well as Eric who has better knowledge about debug info than me.
Compiling for both x86 and ARM with llc aborts after this pass.
I have a simple helloworld.c program.
I am attaching the .ll file created by:
clang -O3 -g -emit-llvm hello.c -c -o hello.bc
Thanks again for the response!
hello.ll (2.41 KB)
Oops, I didn’t attach the .ll file after the -debug-ir pass. Adding it here.
hello.deb.ll (2.39 KB)
Yes, that one crashes for me for every architecture I tried except the experimental AVR target — which doesn’t support dwarf.
main: ; @main
; BB#0: ; %entry
ldi r24, lo8(.L.str)
ldi r25, hi8(.L.str)
in r30, 61
in r31, 62
adiw r30, 2
in r0, 63
out 62, r31
out 63, r0
out 61, r30
ldi r22, 1
ldi r23, 0
ldi r24, 0
ldi r25, 0
.size main, .Ltmp0-main
.type .L.str,@object ; @.str
.asciz “Hello World”
.size .L.str, 12
Thank you for the reply! Can you point me to a method to go about solving this bug?
Or instead, is there another way I can associate every assembly instruction to a corresponding IR one?
Are you mixing versions of llc and opt? I.e. are they both built from
the same version?
No. They’re both from the 3.4 version of llvm.
Interesting. My guess is that the debug-ir pass wasn't updated when we
changed some version of the debug metadata and so isn't producing good
I'm not sure when I'll get to updating it though and it looks like
Daniel's address is bouncing.
Which was the last version of llc that worked with the pass? I could try working with an older version that is compatible.
Is there something else I can hack up to serve my purpose of mapping assembly → IR instructions?
Thanks for the help!
Which was the last version of llc that worked with the pass? I could try
working with an older version that is compatible.
Couldn't say, it would be a revision in svn, but I'm not sure what it
is. A lot of changes went into the format in 3.4.
Is there something else I can hack up to serve my purpose of mapping
assembly -> IR instructions?
Possibly not. It depends on accuracy. You could probably get the
instruction selector to put instructions as comments in the final IR,
but I don't necessarily think that's a small amount of work nor will
it be that accurate if it falls back to the DAG.