LLVM Register allocation

Hello,

I'm relatively a newcomer to this forum and LLVM. I wish to do the following:

1) play with LLVM's register allocation without any other optimizations performed, such as inlining. This is because I'm trying to observe the effects of our path-sensitive tool on register allocation but other optimizations could influence the results. In other words, I would like to perform register allocation with -O0, if that's possible.

2) view the results of register allocation. That is, the mapping of variables to physical registers. I'm comfortable with reading dwarf information. For eg, using gcc I would do: gcc -c -g hello.c ; dwarfdump hello.o

Kindly guide me in performing the above steps. If they are not possible, is there any workaround?

Thank you!

I'm not sure the best way to do what you're asking, but I haven't seen
any other responses...

For regalloc experiments, you probably want to suppress individual
optimizations rather than using -O0. I always refer to the gcc docs
and assume clang supports the option, because I haven't found any
equivalent doc for clang. You can get some undocumented help text
using the secret command "clang -cc1 -help", which is kind of like
"gcc -v -help t.c".

e.g. clang -fno-inline ...

If you want more control, you can split up the compilation path into
these steps:

I'm not sure if -O0 is needed here but it should ensure clang won't inline
before generating bitcode.
$ clang -O0 -emit-llvm -c t.c -o t.bc

-emit-llvm is the equivalent of -flto that shows up in --help.

Normally, you would optimize bitcode using this.
$ opt -std-compile-opts t.bc -o t.bc

But for true -O0, you can skip "opt" altogether.

For regalloc, I suggest at least running "opt -mem2reg". See opt -help
for more passes.

You may then want to run optimal codegen:
llc -O3 t.bc -o t.s

If not, you can override regalloc:
llc -O0 -regalloc=linearscan t.bc -o t.s

See llc -help for more options.

You can trace regalloc using:
$ llc -debug-only=regalloc

Other traceable modules are: liveintervals, virtregmap, spiller, virtregrewriter

-Andy