brintos

brintos / llvm-project-archived public Read only

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