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"
11 static cl::opt
<bool> Wave("wave-goodbye", cl::init(false),
12 cl::desc("wave good bye"));
16 bool runBye(Function
&F
) {
19 errs().write_escaped(F
.getName()) << '\n';
24 struct LegacyBye
: public FunctionPass
{
26 LegacyBye() : FunctionPass(ID
) {}
27 bool runOnFunction(Function
&F
) override
{ return runBye(F
); }
30 struct Bye
: PassInfoMixin
<Bye
> {
31 PreservedAnalyses
run(Function
&F
, FunctionAnalysisManager
&) {
33 return PreservedAnalyses::all();
34 return PreservedAnalyses::none();
40 char LegacyBye::ID
= 0;
42 static RegisterPass
<LegacyBye
> X("goodbye", "Good Bye World Pass",
43 false /* Only looks at CFG */,
44 false /* Analysis Pass */);
46 /* New PM Registration */
47 llvm::PassPluginLibraryInfo
getByePluginInfo() {
48 return {LLVM_PLUGIN_API_VERSION
, "Bye", LLVM_VERSION_STRING
,
50 PB
.registerVectorizerStartEPCallback(
51 [](llvm::FunctionPassManager
&PM
, OptimizationLevel Level
) {
54 PB
.registerPipelineParsingCallback(
55 [](StringRef Name
, llvm::FunctionPassManager
&PM
,
56 ArrayRef
<llvm::PassBuilder::PipelineElement
>) {
57 if (Name
== "goodbye") {
66 #ifndef LLVM_BYE_LINK_INTO_TOOLS
67 extern "C" LLVM_ATTRIBUTE_WEAK ::llvm::PassPluginLibraryInfo
68 llvmGetPassPluginInfo() {
69 return getByePluginInfo();