1 //===- unittests/Passes/Plugins/Plugin.cpp --------------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #include "llvm/Passes/PassBuilder.h" 11 #include "llvm/Passes/PassPlugin.h" 12 13 #include "TestPlugin.h" 14 15 using namespace llvm; 16 17 struct TestModulePass : public PassInfoMixin<TestModulePass> { runTestModulePass18 PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM) { 19 return PreservedAnalyses::all(); 20 } 21 }; 22 registerCallbacks(PassBuilder & PB)23void registerCallbacks(PassBuilder &PB) { 24 PB.registerPipelineParsingCallback( 25 [](StringRef Name, ModulePassManager &PM, 26 ArrayRef<PassBuilder::PipelineElement> InnerPipeline) { 27 if (Name == "plugin-pass") { 28 PM.addPass(TestModulePass()); 29 return true; 30 } 31 return false; 32 }); 33 } 34 35 extern "C" ::llvm::PassPluginLibraryInfo LLVM_ATTRIBUTE_WEAK llvmGetPassPluginInfo()36llvmGetPassPluginInfo() { 37 return {LLVM_PLUGIN_API_VERSION, TEST_PLUGIN_NAME, TEST_PLUGIN_VERSION, 38 registerCallbacks}; 39 } 40