about summary refs log tree commit diff
path: root/instrumentation/split-switches-pass.so.cc
diff options
context:
space:
mode:
Diffstat (limited to 'instrumentation/split-switches-pass.so.cc')
-rw-r--r--instrumentation/split-switches-pass.so.cc46
1 files changed, 43 insertions, 3 deletions
diff --git a/instrumentation/split-switches-pass.so.cc b/instrumentation/split-switches-pass.so.cc
index b8cd61c3..42441de1 100644
--- a/instrumentation/split-switches-pass.so.cc
+++ b/instrumentation/split-switches-pass.so.cc
@@ -27,14 +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"
-//#include "llvm/IR/LegacyPassManager.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"
@@ -57,16 +60,38 @@ 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
+  StringRef getPassName() const override {
+
+#else
+  const char *getPassName() const override {
+
+#endif
+    return "splits switch constructs";
+
+  }
+#endif
 
   struct CaseExpr {
 
@@ -94,6 +119,7 @@ class SplitSwitchesTransform : public PassInfoMixin<SplitSwitchesTransform> {
 
 }  // namespace
 
+#if LLVM_VERSION_MAJOR >= 7 /* use new pass manager */
 extern "C" ::llvm::PassPluginLibraryInfo LLVM_ATTRIBUTE_WEAK
 llvmGetPassPluginInfo() {
   return {
@@ -124,6 +150,9 @@ llvmGetPassPluginInfo() {
     }
   };
 }
+#else
+char SplitSwitchesTransform::ID = 0;
+#endif
 
 /* switchConvert - Transform simple list of Cases into list of CaseRange's */
 BasicBlock *SplitSwitchesTransform::switchConvert(
@@ -435,26 +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 0
+
+#if LLVM_VERSION_MAJOR < 7 /* use old pass manager */
 static void registerSplitSwitchesTransPass(const PassManagerBuilder &,
                                            legacy::PassManagerBase &PM) {