1 #include "llvm/IR/Function.h"
2 #include "llvm/IR/LegacyPassManager.h"
4 #include "llvm/Passes/PassBuilder.h"
5 #include "llvm/Passes/PassPlugin.h"
6 #include "llvm/Support/CommandLine.h"
7 #include "llvm/Support/raw_ostream.h"
8 #include "llvm/Transforms/IPO/PassManagerBuilder.h"
12 static cl::opt
<bool> Wave("wave-goodbye", cl::init(false),
13 cl::desc("wave good bye"));
17 bool runBye(Function
&F
) {
20 errs().write_escaped(F
.getName()) << '\n';
25 struct LegacyBye
: public FunctionPass
{
27 LegacyBye() : FunctionPass(ID
) {}
28 bool runOnFunction(Function
&F
) override
{ return runBye(F
); }
31 struct Bye
: PassInfoMixin
<Bye
> {
32 PreservedAnalyses
run(Function
&F
, FunctionAnalysisManager
&) {
34 return PreservedAnalyses::all();
35 return PreservedAnalyses::none();
41 char LegacyBye::ID
= 0;
43 static RegisterPass
<LegacyBye
> X("goodbye", "Good Bye World Pass",
44 false /* Only looks at CFG */,
45 false /* Analysis Pass */);
47 /* Legacy PM Registration */
48 static llvm::RegisterStandardPasses
RegisterBye(
49 llvm::PassManagerBuilder::EP_VectorizerStart
,
50 [](const llvm::PassManagerBuilder
&Builder
,
51 llvm::legacy::PassManagerBase
&PM
) { PM
.add(new LegacyBye()); });
53 /* New PM Registration */
54 llvm::PassPluginLibraryInfo
getByePluginInfo() {
55 return {LLVM_PLUGIN_API_VERSION
, "Bye", LLVM_VERSION_STRING
,
57 PB
.registerVectorizerStartEPCallback(
58 [](llvm::FunctionPassManager
&PM
, OptimizationLevel Level
) {
61 PB
.registerPipelineParsingCallback(
62 [](StringRef Name
, llvm::FunctionPassManager
&PM
,
63 ArrayRef
<llvm::PassBuilder::PipelineElement
>) {
64 if (Name
== "goodbye") {
73 #ifndef LLVM_BYE_LINK_INTO_TOOLS
74 extern "C" LLVM_ATTRIBUTE_WEAK ::llvm::PassPluginLibraryInfo
75 llvmGetPassPluginInfo() {
76 return getByePluginInfo();