Debian Codegraph @

llvm-project/llvm/unittests/Passes/DoublerPlugin.cpp

raw
1 //===- unittests/Passes/DoublerPlugin.cpp
2 //--------------------------------===//
3 //
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //
8 //===----------------------------------------------------------------------===//
9
10 #include "llvm/Passes/PassBuilder.h"
11 #include "llvm/Passes/PassPlugin.h"
12
13 using namespace llvm;
14
15 struct DoublerModulePass : public PassInfoMixin<DoublerModulePass> {
16
17 // Double the value of the initializer
18 PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM) {
19 auto *GV = cast<GlobalVariable>(M.getNamedValue("doubleme"));
20 auto *Init = GV->getInitializer();
21 auto *Init2 = ConstantExpr::getAdd(Init, Init);
22 GV->setInitializer(Init2);
23
24 return PreservedAnalyses::none();
25 }
26
27 static void registerCallbacks(PassBuilder &PB) {
28 PB.registerPipelineParsingCallback(
29 [](StringRef Name, ModulePassManager &PM,
30 ArrayRef<PassBuilder::PipelineElement> InnerPipeline) {
31 if (Name == "doubler-pass") {
32 PM.addPass(DoublerModulePass());
33 return true;
34 }
35 return false;
36 });
37 }
38 };
39
40 extern "C" ::llvm::PassPluginLibraryInfo LLVM_ATTRIBUTE_WEAK
41 llvmGetPassPluginInfo() {
42 return {LLVM_PLUGIN_API_VERSION, "DoublerPlugin", "2.2-unit",
43 DoublerModulePass::registerCallbacks};
44 }