Hi, I'm developing a very basic new LLVM backend for a RISC machine (named Risco), based on the existing Sparc and Mips backends and the main tutorial [1]. I'm having trouble registering the backend so the main tools can see it. My project code is outside the source tree, and I've altered the Makefile to generate a shared library for the backend (libLLVMRiscoCodeGen.so). I've tried running: llc -load ./libLLVMRiscoCodeGen.so -march=risco, but the target isn't recognized (it doesn't even appear in the llc -version output). The main steps I did for registering the backend were: - At RiscoTargetMachine.cpp: extern "C" void LLVMInitializeRiscoTarget() { // Register the target. RegisterTargetMachine<RiscoTargetMachine> X(TheRiscoTarget); RegisterAsmInfo<RiscoMCAsmInfo> A(TheRiscoTarget); } - At Risco.td: def Risco : Target { let InstructionSet = RiscoInstrInfo; } - At RiscoTargetInfo.cpp: Target llvm::TheRiscoTarget; extern "C" void LLVMInitializeRiscoTargetInfo() { RegisterTarget<> X(TheRiscoTarget, "risco", "Risco"); } What I found suspicious was that in the last file (RiscoTargetInfo.cpp), the original RegisterTarget template parameter was Triple::mips. I found it odd because, if I understood it right, this attaches backend information to a LLVM core file. What am I supposed to put there for a new backend? Do I leave the default parameter? Is this the problem or am I missing something else? [1] http://llvm.org/docs/WritingAnLLVMBackend.html -- []'s Giuliano Vilela. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20101013/7e81f8c1/attachment.html>
Hi Giuliano, Have you modified the configure script to know to enable the target? Look for the bit that handles "--enable-targets" and you'll see a list of the default targets (all of them) that are enabled in a build and a case statement that parses the options to "--enable-targets". Make sure your new target is added in both places. include/llvm/ADT/Triple.h contains a enumeration for the targets. Make sure you've added "risco" there, too. -Jim On Oct 13, 2010, at 12:57 PM, Giuliano Vilela wrote:> Hi, > > I'm developing a very basic new LLVM backend for a RISC machine (named Risco), based on the existing Sparc and Mips backends and the main tutorial [1]. I'm having trouble registering the backend so the main tools can see it. > > My project code is outside the source tree, and I've altered the Makefile to generate a shared library for the backend (libLLVMRiscoCodeGen.so). I've tried running: llc -load ./libLLVMRiscoCodeGen.so -march=risco, but the target isn't recognized (it doesn't even appear in the llc -version output). > > The main steps I did for registering the backend were: > > - At RiscoTargetMachine.cpp: > > extern "C" void LLVMInitializeRiscoTarget() { > // Register the target. > RegisterTargetMachine<RiscoTargetMachine> X(TheRiscoTarget); > RegisterAsmInfo<RiscoMCAsmInfo> A(TheRiscoTarget); > } > > - At Risco.td: > > def Risco : Target { > let InstructionSet = RiscoInstrInfo; > } > > - At RiscoTargetInfo.cpp: > > Target llvm::TheRiscoTarget; > > extern "C" void LLVMInitializeRiscoTargetInfo() { > RegisterTarget<> X(TheRiscoTarget, "risco", "Risco"); > } > > > > What I found suspicious was that in the last file (RiscoTargetInfo.cpp), the original RegisterTarget template parameter was Triple::mips. I found it odd because, if I understood it right, this attaches backend information to a LLVM core file. What am I supposed to put there for a new backend? Do I leave the default parameter? > > Is this the problem or am I missing something else? > > > [1] http://llvm.org/docs/WritingAnLLVMBackend.html > > -- > []'s > > Giuliano Vilela. > > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20101013/6f012c8b/attachment.html>
> My project code is outside the source tree, and I've altered the Makefile to > generate a shared library for the backend (libLLVMRiscoCodeGen.so).You cannot do this anymore. You need to alter the build system (add stuff to configure, etc.) -- With best regards, Anton Korobeynikov Faculty of Mathematics and Mechanics, Saint Petersburg State University
Hi, I think you need to modify these files, at a minimum, for it to build and register the target. * /configure /lib/Support/Triple.cpp /include/llvm/ADT/Triple.h* --John On Wed, Oct 13, 2010 at 12:57 PM, Giuliano Vilela <giulianoxt at gmail.com>wrote:> Hi, > > I'm developing a very basic new LLVM backend for a RISC machine (named > Risco), based on the existing Sparc and Mips backends and the main tutorial > [1]. I'm having trouble registering the backend so the main tools can see > it. > > My project code is outside the source tree, and I've altered the Makefile > to generate a shared library for the backend (libLLVMRiscoCodeGen.so). I've > tried running: llc -load ./libLLVMRiscoCodeGen.so -march=risco, but the > target isn't recognized (it doesn't even appear in the llc -version output). > > The main steps I did for registering the backend were: > > - At RiscoTargetMachine.cpp: > > extern "C" void LLVMInitializeRiscoTarget() { > // Register the target. > RegisterTargetMachine<RiscoTargetMachine> X(TheRiscoTarget); > RegisterAsmInfo<RiscoMCAsmInfo> A(TheRiscoTarget); > } > > - At Risco.td: > > def Risco : Target { > let InstructionSet = RiscoInstrInfo; > } > > - At RiscoTargetInfo.cpp: > > Target llvm::TheRiscoTarget; > > extern "C" void LLVMInitializeRiscoTargetInfo() { > RegisterTarget<> X(TheRiscoTarget, "risco", "Risco"); > } > > > > What I found suspicious was that in the last file (RiscoTargetInfo.cpp), > the original RegisterTarget template parameter was Triple::mips. I found it > odd because, if I understood it right, this attaches backend information to > a LLVM core file. What am I supposed to put there for a new backend? Do I > leave the default parameter? > > Is this the problem or am I missing something else? > > > [1] http://llvm.org/docs/WritingAnLLVMBackend.html > > -- > []'s > > Giuliano Vilela. > > > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20101013/85eeaebb/attachment.html>
Thanks for the info. On Wed, Oct 13, 2010 at 5:27 PM, Anton Korobeynikov <anton at korobeynikov.info> wrote:> > > My project code is outside the source tree, and I've altered the Makefile to > > generate a shared library for the backend (libLLVMRiscoCodeGen.so). > You cannot do this anymore. You need to alter the build system (add > stuff to configure, etc.)That's unfortunate. In order to test the backend, currently, I have to build it and then link llc again: the linking process in freezing my machine pretty bad for a while. Is there a easier way to debug changes to a backend? Maybe speed up llc linking?> > -- > With best regards, Anton Korobeynikov > Faculty of Mathematics and Mechanics, Saint Petersburg State University-- []'s Giuliano Vilela.