Nico Weber | 3069e4e | 2018-05-15 16:30:30 +0000 | [diff] [blame] | 1 | //===- unittests/Passes/Plugins/Plugin.cpp --------------------------------===// |
Philip Pfaffe | 5301677 | 2018-04-05 15:04:13 +0000 | [diff] [blame] | 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> { |
| 18 | PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM) { |
| 19 | return PreservedAnalyses::all(); |
| 20 | } |
| 21 | }; |
| 22 | |
| 23 | void 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 | |
Nico Weber | 3fcac5a | 2018-05-19 03:05:30 +0000 | [diff] [blame] | 35 | extern "C" ::llvm::PassPluginLibraryInfo LLVM_ATTRIBUTE_WEAK |
Philip Pfaffe | 5301677 | 2018-04-05 15:04:13 +0000 | [diff] [blame] | 36 | llvmGetPassPluginInfo() { |
| 37 | return {LLVM_PLUGIN_API_VERSION, TEST_PLUGIN_NAME, TEST_PLUGIN_VERSION, |
| 38 | registerCallbacks}; |
| 39 | } |