Hi, I’ve written a loop nest pass which I’d like to have run with clang. I’ve followed the documentation (Writing an LLVM Pass — LLVM 17.0.0git documentation) to register it in the places it needs to be but I’m getting an undefined reference error in the linking phase of building LLVM.
Here’s the class for my pass:
class AliasHintsPass : public PassInfoMixin<AliasHintsPass> {
public:
PreservedAnalyses run(LoopNest &LN, LoopAnalysisManager &AM,
LoopStandardAnalysisResults &AR, LPMUpdater &U);
Here’s the code I’ve used to register it as a plugin:
llvm::PassPluginLibraryInfo getAliasHintsPluginInfo() {
return {LLVM_PLUGIN_API_VERSION, "AliasHints", LLVM_VERSION_STRING,
[](PassBuilder &PB) {
PB.registerLateLoopOptimizationsEPCallback(
[](llvm::LoopPassManager &LPM, OptimizationLevel Level) {
LPM.addPass(AliasHintsPass());
});
PB.registerPipelineParsingCallback(
[](StringRef Name, llvm::LoopPassManager &LPM,
ArrayRef<llvm::PassBuilder::PipelineElement>) {
if (Name == "aliashints") {
LPM.addPass(AliasHintsPass());
return true;
}
return false;
});
}};
}
#ifndef LLVM_ALIASHINTS_LINK_INTO_TOOLS
extern "C" LLVM_ATTRIBUTE_WEAK ::llvm::PassPluginLibraryInfo
llvmGetPassPluginInfo() {
return getAliasHintsPluginInfo();
}
#endif
I’ve also added this line to register it as a loop nest pass along the other loop nest passes in PassRegistry.def:
LOOPNEST_PASS("alias-hints", AliasHintsPass());
And then when building, this is the error I receive:
/usr/lib/gcc/x86_64-pc-linux-gnu/11/../../../../x86_64-pc-linux-gnu/bin/ld: ../../lib/libLLVMLTO.a(LTOBackend.cpp.o): in function `runNewPMPasses(llvm::lto::Config const&, llvm::Module&, llvm::TargetMachine*, unsigned int, bool, llvm::ModuleSummaryIndex*, llvm::ModuleSummaryIndex const*)':
/home/muke/Programming/Huawei/llvm-project/build/include/llvm/Support/Extension.def:2: undefined reference to `getAliasHintsPassPluginInfo()'
/usr/lib/gcc/x86_64-pc-linux-gnu/11/../../../../x86_64-pc-linux-gnu/bin/ld: ../../lib/libLLVMPasses.a(PassBuilder.cpp.o): in function `llvm::detail::PassModel<llvm::LoopNest, llvm::AliasHintsPass, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>::run(llvm::LoopNest&, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>&, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&)':
/home/muke/Programming/Huawei/llvm-project/llvm/include/llvm/IR/PassManagerInternal.h:88: undefined reference to `llvm::AliasHintsPass::run(llvm::LoopNest&, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>&, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&)'
collect2: error: ld returned 1 exit status
gmake[2]: *** [tools/llvm-lto/CMakeFiles/llvm-lto.dir/build.make:156: bin/llvm-lto] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:19965: tools/llvm-lto/CMakeFiles/llvm-lto.dir/all] Error 2
gmake: *** [Makefile:156: all] Error 2
I’ve tried building with and without the cmake flag LLVM_ALIASHINTSPASS_LINK_INTO_TOOLS=ON
.