Hi, I’m trying to implement a custom target for LLVM (version 6.0.1) based on the X86 target as a loadable module to use it with llc’s -load option. I have defined the module in the CMakeLists.txt file in the target folder as: add_llvm_loadable_module(MyTarget ${sources} AsmParser/X86AsmInstrumentation.cpp AsmParser/X86AsmParser.cpp Disassembler/X86Disassembler.cpp Disassembler/X86DisassemblerDecoder.cpp InstPrinter/X86ATTInstPrinter.cpp InstPrinter/X86IntelInstPrinter.cpp InstPrinter/X86InstComments.cpp MCTargetDesc/X86AsmBackend.cpp MCTargetDesc/X86MCTargetDesc.cpp MCTargetDesc/X86MCAsmInfo.cpp MCTargetDesc/X86MCCodeEmitter.cpp MCTargetDesc/X86MachObjectWriter.cpp MCTargetDesc/X86ELFObjectWriter.cpp MCTargetDesc/X86WinCOFFObjectWriter.cpp MCTargetDesc/X86WinCOFFStreamer.cpp MCTargetDesc/X86WinCOFFTargetStreamer.cpp TargetInfo/X86TargetInfo.cpp Utils/X86ShuffleDecode.cpp ) I also defined new versions of the LLVMInitializeMyTarget(AsmPrinter|Target|AsmParser|Disassembler|TargetMC|TargetInfo) functions. The shared module gets created, but when I load it into llc the target is not present in the list of loaded targets (from llc -version) and I cannot use it with -march=mytarget. However, when I use the llc binary that was compiled with my custom target, and load the module with it, I get errors because of duplicated options, meaning that the custom target is, in fact, loaded from the module in this case. What am I missing here? The documentation I’ve been able to find on loadable modules seems to be targeted at previous versions of LLVM which use the LOADABLE_MODULE makefile value instead of the current cmake compilation pipeline. Cheers, Loïc
Anton Korobeynikov via llvm-dev
2019-Mar-20 06:46 UTC
[llvm-dev] LLVM target as loadable module
Hello You're not missed anything – targets can only be built-in due to way how they are registered, etc. On Wed, Mar 20, 2019 at 7:55 AM Ottet Loïc via llvm-dev <llvm-dev at lists.llvm.org> wrote:> > Hi, > > I’m trying to implement a custom target for LLVM (version 6.0.1) based on the X86 target as a loadable module to use it with llc’s -load option. I have defined the module in the CMakeLists.txt file in the target folder as: > > add_llvm_loadable_module(MyTarget ${sources} > AsmParser/X86AsmInstrumentation.cpp > AsmParser/X86AsmParser.cpp > Disassembler/X86Disassembler.cpp > Disassembler/X86DisassemblerDecoder.cpp > InstPrinter/X86ATTInstPrinter.cpp > InstPrinter/X86IntelInstPrinter.cpp > InstPrinter/X86InstComments.cpp > MCTargetDesc/X86AsmBackend.cpp > MCTargetDesc/X86MCTargetDesc.cpp > MCTargetDesc/X86MCAsmInfo.cpp > MCTargetDesc/X86MCCodeEmitter.cpp > MCTargetDesc/X86MachObjectWriter.cpp > MCTargetDesc/X86ELFObjectWriter.cpp > MCTargetDesc/X86WinCOFFObjectWriter.cpp > MCTargetDesc/X86WinCOFFStreamer.cpp > MCTargetDesc/X86WinCOFFTargetStreamer.cpp > TargetInfo/X86TargetInfo.cpp > Utils/X86ShuffleDecode.cpp > ) > > I also defined new versions of the LLVMInitializeMyTarget(AsmPrinter|Target|AsmParser|Disassembler|TargetMC|TargetInfo) functions. The shared module gets created, but when I load it into llc the target is not present in the list of loaded targets (from llc -version) and I cannot use it with -march=mytarget. However, when I use the llc binary that was compiled with my custom target, and load the module with it, I get errors because of duplicated options, meaning that the custom target is, in fact, loaded from the module in this case. > > What am I missing here? The documentation I’ve been able to find on loadable modules seems to be targeted at previous versions of LLVM which use the LOADABLE_MODULE makefile value instead of the current cmake compilation pipeline. > > Cheers, > > Loïc > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev-- With best regards, Anton Korobeynikov Department of Statistical Modelling, Saint Petersburg State University