Hi!
I’m developing a register allocator and need it to be available as an option for llc tool. I used to edit /lib/CodeGen/Passes.cpp for this aim but after yesterday’s update these options are defined somewhere else and I can’t find the place.
Thanks for your help.
Tony.
Hi again!
I’ve found the place I needed looking carefully at regAllocLinearScan.cpp file
Thanks.
Tony.
Welcome to the world of pluggable machine passes. This work was done to lighten the load of some llvm tools, ie., only link in the register allocators and instruction schedulers that are actually needed in a particular circumstance. I guess I will have to write this up, but generally it works like this.
In your register allocator .cpp file add the following include;
#include ""llvm/CodeGen/RegAllocRegistry.h""
In your register allocator .cpp file define a create function in the form;
FunctionPass *createMyRegisterAllocator() {
return new MyRegisterAllocator();
}
and the "installing" static constructor declaration, in the form;
static RegisterRegAlloc myRegAlloc("myregalloc",
" my register allocator help string",
createMyRegisterAllocator);
To force the load/linking of your register allocator into the llc/lli tools, add your create function's global declaration to "Passes.h" and add a "pseudo" call line to "llvm/Codegen/LinkAllCodegenComponents.h" .
And that should do it.
Cheers,
-- Jim
Another note: with this new functionality you should be able to dynamically load register allocators. Build your register allocator into a dynamic library, like this: Writing an LLVM Pass — LLVM 16.0.0git documentation
They you should be able to use:
llc -load yourregalloc.so -regalloc=yours ...
-Chris
Hi!
I’ve did what Jim Laskey wrote but llc didn’t reckognize my regalloc option.
So I moved my allocator implementation into seperate folder within CodeGen and wrote separate makefile for it (like in “Writing an LLVM pass” tutorial). But when I run “make” from LLVMOBJDIR it doesn’t enter the RegAlloc directory and when linking llc an error like “createGraphColoringRegAlloc not defined” occurs.
What am I doing wrong? 
Hi,
So I moved my allocator implementation into seperate folder within CodeGen and wrote separate makefile for it (like in "Writing an LLVM pass" tutorial). But when I run "make" from LLVMOBJDIR it doesn't enter the RegAlloc directory and when linking llc an error like "createGraphColoringRegAlloc not defined" occurs.
Did you add your new folder to the (PARALLEL_)DIRS variable within CodeGen's Makefile?
llc -load yourregalloc.so -regalloc=yours ...
-Chris
BTW, do you know what the extension cygwin uses instead of ".so"?
I managed to load a pass without any extension (using opt or llvm-ld), so maybe the following works: llc -load /path/to/yourregalloc -regalloc=...
Kind regards,
Bram Adams
GH-SEL, INTEC, Ghent University
Dear Anton,
you can add your register allocator strait iin the
"lib/CodeGen/Passes.cpp", and then 're-make' it: "makellvm llc", on the
top of lib/CodeGen. It is faster than running make from LLVMOBJDIR. The
problem is that it only add to llc the changes on the lib/CodeGen
directory. If you change other parts, a make from LLVMOBJDIR will
synchronize it.
Try adding code like this to your Passes.cpp file:
//===---------------------------------------------------------------------===//
///
/// RegAlloc command line options.
///
//===---------------------------------------------------------------------===//
namespace {
cl::opt<RegisterRegAlloc::FunctionPassCtor, false,
RegisterPassParser<RegisterRegAlloc> >
RegAlloc("regalloc",
cl::init(&createChordalRegisterAllocator),
cl::desc("Register allocator to use: (default = chordal)"));
}
All the best,
Fernando
I managed to link my RegAlloc.a library to llc tool but can;t make the same with lli tool.
Should I use USEDLIBS variable in lli makefile (like llc) or there is another way?
Hi all!
I didn’t manage to link my regalloc to lli (I added USEDLIBS to its makefile). Without it I can’t run tests cause they need lli to be built. So how can I link createMyRegisterAllocator function to lli?
Thanks.
I didn't manage to link my regalloc to lli (I added USEDLIBS to its
makefile). Without it I can't run tests cause they need lli to be built. So
how can I link createMyRegisterAllocator function to lli?
Make sure to add it to Codegen/LinkAllCodegenComponents.h.
-Chris
I’m sure I did. I did so from the first time and I also needed to add my library .a file to the USEDLIBS variable within llc makefile to build llc. I wonder how lli links with all the rest LLVM as it seems to include no lib within its makefile. May be I need to include/link my lib somewhere else?
Thanks,
Tony.
Ah, that's probably it. Try adding your lib to the JIT_LIBS variable in llvm/Makefile.rules.
-Chris
Hi!
Everything worked fine, thanks!
Though now I’ve updated LLVM from CVS and both llc and lli can’t link with my library. Checked via “make VERBOSE=1” that all libraries listed in USEDLIBS variable are linked except mine. My library is built successfully and situated in LLVMOBJROOT/Debug/libs directory among the others. It doesn’t have LLVM prefix though.
I noticed that LINK_COMPONENTS variable added to the llc and lli makefiles. I tried to reread the documentation about LLVM makefile system but it didn’t help to solve my problem.
I have the following makefile:
LEVEL = …/…/…
LIBRARYNAME = RegAlloc
BUILD_ARCHIVE = 1
DONT_BUILD_RELINKED = 1
include $(LEVEL)/Makefile.common
I’ve included my library dir within PARALLEL_DIRS of CodeGen makefile.
My createRegisterAllocator function is declared in Passes.h and called in LinkAllCodeGenComponents.cpp
The name of my library is listed in USEDLIBS variable of llc makefile and JIT_LIBS of llvm/Makefile.rules (in order to link with lli). I tried both with “a” extension and without it.
Any help would be appreciated. Thanks.
Tony.