How to debug LLVM

Hi,every one.
I want to add an intrinsics which mapping a new instruction.
What I added in LLVM can compile and link.But when I lli test.bc ,it breaks down. I want to know where is wrong, but bugpoint tool and XRay don’t find the wrong.(Maybe I use these tools incorrectly. ) I want to know how to debug intrinsics and instruction.
Thank you,
Tianhao Shen.

Hi Tianhao,

From: llvm-dev <llvm-dev-bounces@lists.llvm.org> On Behalf Of ??? via llvm-dev
Subject: [llvm-dev] How to debug LLVM

Hi,every one.
I want to add an intrinsics which mapping a new instruction.
What I added in LLVM can compile and link. But when I lli test.bc, it breaks down.
I want to know where is wrong, but bugpoint tool and XRay don't find the wrong.
(Maybe I use these tools incorrectly. ) I want to know how to debug intrinsics and instruction.
Thank you,
Tianhao Shen.

When you say "it breaks down," I assume you mean there is some internal compiler crash?
I'd suggest building a debug version of the compiler, if you do not already have one.
Assertions are very helpful in debugging, and if you are trying to resolve a crash, analyzing
crashes from a debugger is much simpler than using a release build.

Before you run lli, have you examined the machine instruction representation? One trick
you might find handy is the following: emit your test code as llvm IR and ensure your
intrinsic is represented correctly in IR. You can feed that IR file into 'llc' and dump the
machine code representation. To take a peek at the machine form of your code, run llc:
'llc test.ll -stop-after machine-cp' where test.ll is your IR file that uses your newly added
intrinsic. The resulting .s file should have the lowered MachineInstr representation
which should present your newly added instruction.

Hope that helps,

-Matt

Hi,Matt
Thank you for your suggestion.
I’m sorry that I reply to you so late.

About building a debug version, I don’t know whether adding “-DCMAKE_BUILD_TYPE=DEBUG” when I cmake LLVM is right way.

The result .s file after using ‘llc test.ll -stop-after machine-cp’ has my intrinsic and the binary file also have.But it can’t run.

Thank you again,
Tianhao Shen.

Just as a side note: lli uses various JIT engines currently available, but they may lack some features that you need.
I'd say the best way to check your intrinsic is to use llc to compile it down to the binary and then run binary as a normal program.