I'm developing a very basic new LLVM backend for a RISC machine (named Risco), based on the existing Sparc backend and this tutorial. To register the backend, I've used the following.
At RiscoTargetMachine.cpp:
extern "C" void LLVMInitializeRiscoTarget()
{
// Register the target.
RegisterTargetMachine<RiscoSimulatorTargetMachine> X(TheRiscoTarget);
RegisterAsmInfo<RiscoMCAsmInfo> Y(TheRiscoTarget);
}
At Risco.td:
def : Processor<"simulator", NoItineraries, [FeatureA]>;
def Risco : Target {
// Pull in Instruction Info:
let InstructionSet = RiscoInstrInfo;
}
At TargetInfo/RiscoTargetInfo.cpp:
Target llvm::TheRiscoTarget;
extern "C" void LLVMInitializeRiscoTargetInfo() {
RegisterTarget<> X(TheRiscoTarget, "risco", "Risco");
}
At the top level LLVM configure script:
# Added Risco to the TARGETS_TO_BUILD variable at line 4965 (from svn trunk):
all) TARGETS_TO_BUILD="X86 Sparc PowerPC Alpha ARM Mips CellSPU PIC16 XCore MSP430 SystemZ Blackfin CBackend CppBackend MBlaze PTX Risco" ;;
After build, llc -version
doesn't show the new target. Even llc -march=risco test.ll
says it's an invalid target. What am I missing?
PS: Currently, I'm including the new target as a folder inside llvm/lib/Target. How can I change that so I can build the target separately, and load it dynamic with llc -load
?
The default first template parameter for RegisterTarget
is Triple::InvalidArch
. Try this:
extern "C" void LLVMInitializeRiscoTargetInfo() {
RegisterTarget<Triple::UnknownArch> X(TheRiscoTarget, "risco", "Risco");
}
You might also need to register an assembly printer for your backend in RiscoAsmPrinter.cpp:
extern "C" void LLVMInitializeRiscoAsmPrinter() {
RegisterAsmPrinter<RiscoAsmPrinter> X(TheRiscoTarget);
}
I'm not quite sure what you mean by the last bit. My Makefile has LOADABLE_MODULE=1
and builds the target as a shared object in the lib folder. In order to see the Risco target in the list of registered targets, I would run something like ./bin/llc -load ./lib/libLLVMRisco.so -version
assuming you are on Linux.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With