xref: /llvm-project/llvm/unittests/Passes/Plugins/TestPlugin/TestPlugin.cpp (revision e281d102fb73bffae32831b759ed07744e82b751)
1*e281d102Sibricchi //===- unittests/Passes/TestPlugin.cpp --------------------------------===//
2*e281d102Sibricchi //
3*e281d102Sibricchi // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*e281d102Sibricchi // See https://llvm.org/LICENSE.txt for license information.
5*e281d102Sibricchi // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*e281d102Sibricchi //
7*e281d102Sibricchi //===----------------------------------------------------------------------===//
8*e281d102Sibricchi 
9*e281d102Sibricchi #include "llvm/Passes/PassBuilder.h"
10*e281d102Sibricchi #include "llvm/Passes/PassPlugin.h"
11*e281d102Sibricchi 
12*e281d102Sibricchi #include "../TestPlugin.h"
13*e281d102Sibricchi 
14*e281d102Sibricchi using namespace llvm;
15*e281d102Sibricchi 
16*e281d102Sibricchi struct TestModulePass : public PassInfoMixin<TestModulePass> {
runTestModulePass17*e281d102Sibricchi   PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM) {
18*e281d102Sibricchi     return PreservedAnalyses::all();
19*e281d102Sibricchi   }
20*e281d102Sibricchi 
registerCallbacksTestModulePass21*e281d102Sibricchi   static void registerCallbacks(PassBuilder &PB) {
22*e281d102Sibricchi     PB.registerPipelineParsingCallback(
23*e281d102Sibricchi         [](StringRef Name, ModulePassManager &PM,
24*e281d102Sibricchi            ArrayRef<PassBuilder::PipelineElement> InnerPipeline) {
25*e281d102Sibricchi           if (Name == "plugin-pass") {
26*e281d102Sibricchi             PM.addPass(TestModulePass());
27*e281d102Sibricchi             return true;
28*e281d102Sibricchi           }
29*e281d102Sibricchi           return false;
30*e281d102Sibricchi         });
31*e281d102Sibricchi   }
32*e281d102Sibricchi };
33*e281d102Sibricchi 
34*e281d102Sibricchi extern "C" ::llvm::PassPluginLibraryInfo LLVM_ATTRIBUTE_WEAK
llvmGetPassPluginInfo()35*e281d102Sibricchi llvmGetPassPluginInfo() {
36*e281d102Sibricchi   return {LLVM_PLUGIN_API_VERSION, TEST_PLUGIN_NAME, TEST_PLUGIN_VERSION,
37*e281d102Sibricchi           TestModulePass::registerCallbacks};
38*e281d102Sibricchi }
39