LLVM Newbie

Hi,

I am trying to write my own backend using LLVM and I downloaded the support files from the book titled “LLVM Cookbook” for the “Toy” architecture described in the book.

I made the changes described in the book to register the TOY architecture but am seeing compile errors. I am not sure if I set this up correctly. The code that I am compiling for the backend was downloaded from the publisher and should be tested? (I think they used 3.5 whereas I am using 3.8.0)

Any help would be much appreciated!

Wolf

[ 59%] Built target LLVMXCoreInfo
[ 59%] Built target LLVMXCoreDesc
[ 59%] Updating TOYGenRegisterInfo.inc…
[ 59%] Updating TOYGenInstrInfo.inc…
[ 60%] Updating TOYGenAsmWriter.inc…
[ 60%] Updating TOYGenDAGISel.inc…
[ 60%] Updating TOYGenCallingConv.inc…
[ 60%] Updating TOYGenSubtargetInfo.inc…
[ 60%] Updating TOYGenMCCodeEmitter.inc…
[ 60%] Built target TOYCommonTableGen
Scanning dependencies of target LLVMTOYCodeGen
[ 60%] Building CXX object lib/Target/TOY/CMakeFiles/LLVMTOYCodeGen.dir/TOYSubtarget.cpp.o
In file included from /home/wolf/gang/llvm/llvm_build/llvm-3.8.0.src/lib/Target/TOY/TOYInstrInfo.h:17:0,
from /home/wolf/gang/llvm/llvm_build/llvm-3.8.0.src/lib/Target/TOY/TOYSubtarget.h:20,
from /home/wolf/gang/llvm/llvm_build/llvm-3.8.0.src/lib/Target/TOY/TOYSubtarget.cpp:14:
/home/wolf/gang/llvm/llvm_build/llvm-3.8.0.src/lib/Target/TOY/TOYRegisterInfo.h:34:19: error: ‘const uint32_t* llvm::TOYRegisterInfo::getCallPreservedMask(llvm::CallingConv::ID) const’ marked override, but does not override
const uint32_t getCallPreservedMask(CallingConv::ID) const override;
^
In file included from /home/wolf/gang/llvm/llvm_build/llvm-3.8.0.src/lib/Target/TOY/TOYSubtarget.cpp:14:0:
/home/wolf/gang/llvm/llvm_build/llvm-3.8.0.src/lib/Target/TOY/TOYSubtarget.h:69:21: error: ‘const llvm::DataLayout
llvm::TOYSubtarget::getDataLayout() const’ marked override, but does not override
const DataLayout *getDataLayout() const override { return &DL; }
^
/home/wolf/gang/llvm/llvm_build/llvm-3.8.0.src/lib/Target/TOY/TOYSubtarget.h:41:20: error: cannot declare field ‘llvm::TOYSubtarget::FrameLowering’ to be of abstract type ‘llvm::TOYFrameLowering’
TOYFrameLowering FrameLowering;
^
In file included from /home/wolf/gang/llvm/llvm_build/llvm-3.8.0.src/lib/Target/TOY/TOYSubtarget.h:18:0,
from /home/wolf/gang/llvm/llvm_build/llvm-3.8.0.src/lib/Target/TOY/TOYSubtarget.cpp:14:
/home/wolf/gang/llvm/llvm_build/llvm-3.8.0.src/lib/Target/TOY/TOYFrameLowering.h:24:7: note: because the following virtual functions are pure within ‘llvm::TOYFrameLowering’:
class TOYFrameLowering : public TargetFrameLowering {
^
In file included from /home/wolf/gang/llvm/llvm_build/llvm-3.8.0.src/lib/Target/TOY/TOYFrameLowering.h:18:0,
from /home/wolf/gang/llvm/llvm_build/llvm-3.8.0.src/lib/Target/TOY/TOYSubtarget.h:18,
from /home/wolf/gang/llvm/llvm_build/llvm-3.8.0.src/lib/Target/TOY/TOYSubtarget.cpp:14:
/home/wolf/gang/llvm/llvm_build/llvm-3.8.0.src/include/llvm/Target/TargetFrameLowering.h:156:16: note: virtual void llvm::TargetFrameLowering::emitPrologue(llvm::MachineFunction&, llvm::MachineBasicBlock&) const
virtual void emitPrologue(MachineFunction &MF,
^
/home/wolf/gang/llvm/llvm_build/llvm-3.8.0.src/lib/Target/TOY/TOYSubtarget.cpp: In constructor ‘llvm::TOYSubtarget::TOYSubtarget(const string&, const string&, const string&, llvm::TOYTargetMachine&)’:
/home/wolf/gang/llvm/llvm_build/llvm-3.8.0.src/lib/Target/TOY/TOYSubtarget.cpp:32:58: error: no matching function for call to ‘llvm::TOYGenSubtargetInfo::TOYGenSubtargetInfo(const string&, const string&, const string&)’
InstrInfo(), TLInfo™, TSInfo(DL), FrameLowering() {}
^
/home/wolf/gang/llvm/llvm_build/llvm-3.8.0.src/lib/Target/TOY/TOYSubtarget.cpp:32:58: note: candidate is:
In file included from /home/wolf/gang/llvm/llvm_build/llvm-3.8.0.src/lib/Target/TOY/TOYSubtarget.cpp:22:0:
/home/wolf/gang/llvm/llvm_build/llvm-3.8.0.src/build/lib/Target/TOY/TOYGenSubtargetInfo.inc:117:1: note: llvm::TOYGenSubtargetInfo::TOYGenSubtargetInfo(const llvm::Triple&, llvm::StringRef, llvm::StringRef)
TOYGenSubtargetInfo::TOYGenSubtargetInfo(const Triple &TT, StringRef CPU, StringRef FS)
^
/home/wolf/gang/llvm/llvm_build/llvm-3.8.0.src/build/lib/Target/TOY/TOYGenSubtargetInfo.inc:117:1: note: no known conversion for argument 1 from ‘const string {aka const std::basic_string}’ to ‘const llvm::Triple&’
make[2]: *** [lib/Target/TOY/CMakeFiles/LLVMTOYCodeGen.dir/TOYSubtarget.cpp.o] Error 1
make[1]: *** [lib/Target/TOY/CMakeFiles/LLVMTOYCodeGen.dir/all] Error 2
make: *** [all] Error 2

There are always pretty big, and incompatible, changes between major LLVM versions. Ideally, the publisher of your book would provide a site with updates to their code.

The easiest thing for you to do is to get LLVM 3.5 and use that.

Or, you could do a diff between the 3.5 and 3.8 versions of the headers for the classes you’re inheriting from and see if there’s been something like an obvious simple renaming of methods.

Yeah, that book is old enough and the content, mainly based on current
code, doesn't age well. :slight_smile:

However, it should still contain the general ideas, but you'll have to
dig the code more deeper than you would a few years ago.

You could try the official document:

http://llvm.org/docs/WritingAnLLVMBackend.html

or an old but very thorough experiment (probably same age as the book):

http://jonathan2251.github.io/lbd/

Or this tutorial:

http://llvm.org/devmtg/2014-04/PDFs/Talks/Building%20an%20LLVM%20backend.pdf

Or, as Bruce said, you could use 3.5.

A good rule of thumb is, if you're serious about LLVM, grab ToT and
suffer the initial impact. It's not that big. If, OTOH, this is just
for fun, or a side project, use and old but sure version, and spend
more time on the core of your project.

cheers,
--renato