blob: 3dc5cdc84768f00d1512b3bc2294fc78632c834a [file] [log] [blame]
Nico Weber3069e4e2018-05-15 16:30:30 +00001//===- unittests/Passes/Plugins/Plugin.cpp --------------------------------===//
Philip Pfaffe53016772018-04-05 15:04:13 +00002//
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
15using namespace llvm;
16
17struct TestModulePass : public PassInfoMixin<TestModulePass> {
18 PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM) {
19 return PreservedAnalyses::all();
20 }
21};
22
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
Nico Weber3fcac5a2018-05-19 03:05:30 +000035extern "C" ::llvm::PassPluginLibraryInfo LLVM_ATTRIBUTE_WEAK
Philip Pfaffe53016772018-04-05 15:04:13 +000036llvmGetPassPluginInfo() {
37 return {LLVM_PLUGIN_API_VERSION, TEST_PLUGIN_NAME, TEST_PLUGIN_VERSION,
38 registerCallbacks};
39}