diff options
author | hexcoder- <heiko@hexco.de> | 2021-11-22 16:51:06 +0100 |
---|---|---|
committer | hexcoder- <heiko@hexco.de> | 2021-11-22 16:51:06 +0100 |
commit | 0e9b2089498c2acf307bbc90ade420b33aede150 (patch) | |
tree | c1f9ac58f1635e6a3c3af6b7cd072ef92a31be25 /instrumentation/split-switches-pass.so.cc | |
parent | 6f9a98c4a97e8e261fc52891d61f0b0c145b6364 (diff) | |
parent | 7d0e0cde0ad8c5b89eaf72a9751e3fb7513cc0e9 (diff) | |
download | afl++-0e9b2089498c2acf307bbc90ade420b33aede150.tar.gz |
Merge branch 'dev_newpm' into dev
Diffstat (limited to 'instrumentation/split-switches-pass.so.cc')
-rw-r--r-- | instrumentation/split-switches-pass.so.cc | 73 |
1 files changed, 70 insertions, 3 deletions
diff --git a/instrumentation/split-switches-pass.so.cc b/instrumentation/split-switches-pass.so.cc index 1e32a31d..ca8cdc9b 100644 --- a/instrumentation/split-switches-pass.so.cc +++ b/instrumentation/split-switches-pass.so.cc @@ -27,11 +27,17 @@ #include "llvm/ADT/Statistic.h" #include "llvm/IR/IRBuilder.h" +#if LLVM_VERSION_MAJOR >= 7 /* use new pass manager */ +#include "llvm/Passes/PassPlugin.h" +#include "llvm/Passes/PassBuilder.h" +#include "llvm/IR/PassManager.h" +#else #include "llvm/IR/LegacyPassManager.h" +#include "llvm/Transforms/IPO/PassManagerBuilder.h" +#endif #include "llvm/IR/Module.h" #include "llvm/Support/Debug.h" #include "llvm/Support/raw_ostream.h" -#include "llvm/Transforms/IPO/PassManagerBuilder.h" #include "llvm/Transforms/Utils/BasicBlockUtils.h" #include "llvm/Pass.h" #include "llvm/Analysis/ValueTracking.h" @@ -54,16 +60,25 @@ using namespace llvm; namespace { +#if LLVM_VERSION_MAJOR >= 7 /* use new pass manager */ +class SplitSwitchesTransform : public PassInfoMixin<SplitSwitchesTransform> { + + public: + SplitSwitchesTransform() { +#else class SplitSwitchesTransform : public ModulePass { public: static char ID; SplitSwitchesTransform() : ModulePass(ID) { - +#endif initInstrumentList(); } +#if LLVM_VERSION_MAJOR >= 7 /* use new pass manager */ + PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM); +#else bool runOnModule(Module &M) override; #if LLVM_VERSION_MAJOR >= 4 @@ -76,6 +91,7 @@ class SplitSwitchesTransform : public ModulePass { return "splits switch constructs"; } +#endif struct CaseExpr { @@ -103,7 +119,40 @@ class SplitSwitchesTransform : public ModulePass { } // namespace +#if LLVM_VERSION_MAJOR >= 7 /* use new pass manager */ +extern "C" ::llvm::PassPluginLibraryInfo LLVM_ATTRIBUTE_WEAK +llvmGetPassPluginInfo() { + return { + LLVM_PLUGIN_API_VERSION, "splitswitches", "v0.1", + /* lambda to insert our pass into the pass pipeline. */ + [](PassBuilder &PB) { +#if 1 + using OptimizationLevel = typename PassBuilder::OptimizationLevel; + PB.registerOptimizerLastEPCallback( + [](ModulePassManager &MPM, OptimizationLevel OL) { + MPM.addPass(SplitSwitchesTransform()); + } + ); +/* TODO LTO registration */ +#else + using PipelineElement = typename PassBuilder::PipelineElement; + PB.registerPipelineParsingCallback( + [](StringRef Name, ModulePassManager &MPM, ArrayRef<PipelineElement>) { + if ( Name == "splitswitches" ) { + MPM.addPass(SplitSwitchesTransform()); + return true; + } else { + return false; + } + } + ); +#endif + } + }; +} +#else char SplitSwitchesTransform::ID = 0; +#endif /* switchConvert - Transform simple list of Cases into list of CaseRange's */ BasicBlock *SplitSwitchesTransform::switchConvert( @@ -415,19 +464,37 @@ bool SplitSwitchesTransform::splitSwitches(Module &M) { } +#if LLVM_VERSION_MAJOR >= 7 /* use new pass manager */ +PreservedAnalyses SplitSwitchesTransform::run(Module &M, ModuleAnalysisManager &MAM) { +#else bool SplitSwitchesTransform::runOnModule(Module &M) { +#endif if ((isatty(2) && getenv("AFL_QUIET") == NULL) || getenv("AFL_DEBUG") != NULL) printf("Running split-switches-pass by laf.intel@gmail.com\n"); else be_quiet = 1; + +#if LLVM_VERSION_MAJOR >= 7 /* use new pass manager */ + auto PA = PreservedAnalyses::all(); +#endif + splitSwitches(M); verifyModule(M); +#if LLVM_VERSION_MAJOR >= 7 /* use new pass manager */ +/* if (modified) { + PA.abandon<XX_Manager>(); + }*/ + + return PA; +#else return true; +#endif } +#if LLVM_VERSION_MAJOR < 7 /* use old pass manager */ static void registerSplitSwitchesTransPass(const PassManagerBuilder &, legacy::PassManagerBase &PM) { @@ -447,4 +514,4 @@ static RegisterStandardPasses RegisterSplitSwitchesTransPassLTO( PassManagerBuilder::EP_FullLinkTimeOptimizationLast, registerSplitSwitchesTransPass); #endif - +#endif |