Debugging code generation

From llvm-mos
Jump to navigation Jump to search

The llvm-mos code generator runs mostly on test cases written in MIR. These can be found in llvm/test/CodeGen/MOS .

To test a particular section of codegen, you typically compile the code with clang, and then use llc to watch as the GlobalISel architecture lowers the code from generic MIR to MOS code.

One way of doing this is by debugging program:

llc -O2 -debug --debug-pass=Details -verify-machineinstrs -o %t %s

Where %t is the assembly output file, and %s is the name of a LLVM bitcode file with an .ll extension.

This command line runs all the GlobalISel passes, emitting copious debug information on every pass.

A formula for creating C code to test codegen passes is as follows:

clang --target=mos -emit-llvm -S %s -o %t.ll
llc -debug --debug-pass=Details -mtriple=mos -verify-machineinstrs %t.ll -o %t.s