llvm new passmanager fixes
MODIFY
instrumentation/afl-llvm-pass.so.cc
instrumentation/afl-llvm-pass.so.cc
@@ -45,7 +45,7 @@ typedef long double max_align_t;
#endif
#include "llvm/IR/IRBuilder.h"
-#if LLVM_VERSION_MAJOR >= 7 /* use new pass manager */
+#if LLVM_VERSION_MAJOR >= 11 /* use new pass manager */
#include "llvm/Passes/PassPlugin.h"
#include "llvm/Passes/PassBuilder.h"
#include "llvm/IR/PassManager.h"
@@ -57,6 +57,9 @@ typedef long double max_align_t;
#include "llvm/IR/Module.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/MathExtras.h"
+#if LLVM_VERSION_MAJOR >= 14 /* how about stable interfaces? */
+ #include "llvm/Passes/OptimizationLevel.h"
+#endif
#if LLVM_VERSION_MAJOR > 3 || \
(LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR > 4)
@@ -74,22 +77,26 @@ using namespace llvm;
namespace {
-#if LLVM_VERSION_MAJOR >= 7 /* use new pass manager */
+#if LLVM_VERSION_MAJOR >= 11 /* use new pass manager */
class AFLCoverage : public PassInfoMixin<AFLCoverage> {
+
public:
AFLCoverage() {
+
#else
class AFLCoverage : public ModulePass {
+
public:
static char ID;
AFLCoverage() : ModulePass(ID) {
+
#endif
initInstrumentList();
}
-#if LLVM_VERSION_MAJOR >= 7 /* use new pass manager */
+#if LLVM_VERSION_MAJOR >= 11 /* use new pass manager */
PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM);
#else
bool runOnModule(Module &M) override;
@@ -107,37 +114,51 @@ class AFLCoverage : public ModulePass {
} // namespace
-#if LLVM_VERSION_MAJOR >= 7 /* use new pass manager */
+#if LLVM_VERSION_MAJOR >= 11 /* use new pass manager */
extern "C" ::llvm::PassPluginLibraryInfo LLVM_ATTRIBUTE_WEAK
llvmGetPassPluginInfo() {
- return {
- LLVM_PLUGIN_API_VERSION, "AFLCoverage", "v0.1",
+
+ return {LLVM_PLUGIN_API_VERSION, "AFLCoverage", "v0.1",
/* lambda to insert our pass into the pass pipeline. */
[](PassBuilder &PB) {
+
#if 1
+ #if LLVM_VERSION_MAJOR <= 13
using OptimizationLevel = typename PassBuilder::OptimizationLevel;
+ #endif
PB.registerOptimizerLastEPCallback(
[](ModulePassManager &MPM, OptimizationLevel OL) {
+
MPM.addPass(AFLCoverage());
- }
- );
+
+ });
+
/* TODO LTO registration */
#else
using PipelineElement = typename PassBuilder::PipelineElement;
- PB.registerPipelineParsingCallback(
- [](StringRef Name, ModulePassManager &MPM, ArrayRef<PipelineElement>) {
+ PB.registerPipelineParsingCallback([](StringRef Name,
+ ModulePassManager &MPM,
+ ArrayRef<PipelineElement>) {
+
if (Name == "AFLCoverage") {
+
MPM.addPass(AFLCoverage());
return true;
+
} else {
+
return false;
+
}
- }
- );
+
+ });
+
#endif
+
+ }};
+
}
- };
-}
+
#else
char AFLCoverage::ID = 0;
@@ -168,11 +189,12 @@ uint64_t PowerOf2Ceil(unsigned in) {
#define AFL_HAVE_VECTOR_INTRINSICS 1
#endif
-
-#if LLVM_VERSION_MAJOR >= 7 /* use new pass manager */
+#if LLVM_VERSION_MAJOR >= 11 /* use new pass manager */
PreservedAnalyses AFLCoverage::run(Module &M, ModuleAnalysisManager &MAM) {
+
#else
bool AFLCoverage::runOnModule(Module &M) {
+
#endif
LLVMContext &C = M.getContext();
@@ -188,7 +210,7 @@ bool AFLCoverage::runOnModule(Module &M) {
u32 rand_seed;
unsigned int cur_loc = 0;
-#if LLVM_VERSION_MAJOR >= 7 /* use new pass manager */
+#if LLVM_VERSION_MAJOR >= 11 /* use new pass manager */
auto PA = PreservedAnalyses::all();
#endif
@@ -1029,7 +1051,7 @@ bool AFLCoverage::runOnModule(Module &M) {
}
-#if LLVM_VERSION_MAJOR >= 7 /* use new pass manager */
+#if LLVM_VERSION_MAJOR >= 11 /* use new pass manager */
return PA;
#else
return true;
@@ -1037,7 +1059,7 @@ bool AFLCoverage::runOnModule(Module &M) {
}
-#if LLVM_VERSION_MAJOR < 7 /* use old pass manager */
+#if LLVM_VERSION_MAJOR < 11 /* use old pass manager */
static void registerAFLPass(const PassManagerBuilder &,
legacy::PassManagerBase &PM) {
@@ -1051,3 +1073,4 @@ static RegisterStandardPasses RegisterAFLPass(
static RegisterStandardPasses RegisterAFLPass0(
PassManagerBuilder::EP_EnabledOnOptLevel0, registerAFLPass);
#endif
+

MODIFY
instrumentation/compare-transform-pass.so.cc
instrumentation/compare-transform-pass.so.cc
#include "llvm/ADT/Statistic.h"
#include "llvm/IR/IRBuilder.h"
-#if LLVM_MAJOR >= 7 /* use new pass manager */
+#if LLVM_MAJOR >= 11 /* use new pass manager */
#include "llvm/Passes/PassPlugin.h"
#include "llvm/Passes/PassBuilder.h"
#include "llvm/IR/PassManager.h"
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
#include "llvm/Pass.h"
#include "llvm/Analysis/ValueTracking.h"
+#if LLVM_VERSION_MAJOR >= 14 /* how about stable interfaces? */
+ #include "llvm/Passes/OptimizationLevel.h"
+#endif
#if LLVM_VERSION_MAJOR > 3 || \
(LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR > 4)
@@ -58,7 +61,7 @@ using namespace llvm;
namespace {
-#if LLVM_MAJOR >= 7 /* use new pass manager */
+#if LLVM_MAJOR >= 11 /* use new pass manager */
class CompareTransform : public PassInfoMixin<CompareTransform> {
public:
@@ -77,7 +80,7 @@ class CompareTransform : public ModulePass {
}
-#if LLVM_MAJOR >= 7 /* use new pass manager */
+#if LLVM_MAJOR >= 11 /* use new pass manager */
PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM);
#else
bool runOnModule(Module &M) override;
@@ -93,7 +96,7 @@ class CompareTransform : public ModulePass {
} // namespace
-#if LLVM_MAJOR >= 7 /* use new pass manager */
+#if LLVM_MAJOR >= 11 /* use new pass manager */
extern "C" ::llvm::PassPluginLibraryInfo LLVM_ATTRIBUTE_WEAK
llvmGetPassPluginInfo() {
@@ -102,7 +105,9 @@ llvmGetPassPluginInfo() {
[](PassBuilder &PB) {
#if 1
+ #if LLVM_VERSION_MAJOR <= 13
using OptimizationLevel = typename PassBuilder::OptimizationLevel;
+ #endif
PB.registerOptimizerLastEPCallback(
[](ModulePassManager &MPM, OptimizationLevel OL) {
@@ -650,7 +655,7 @@ bool CompareTransform::transformCmps(Module &M, const bool processStrcmp,
}
-#if LLVM_MAJOR >= 7 /* use new pass manager */
+#if LLVM_MAJOR >= 11 /* use new pass manager */
PreservedAnalyses CompareTransform::run(Module &M, ModuleAnalysisManager &MAM) {
#else
@@ -665,14 +670,14 @@ bool CompareTransform::runOnModule(Module &M) {
else
be_quiet = 1;
-#if LLVM_MAJOR >= 7 /* use new pass manager */
+#if LLVM_MAJOR >= 11 /* use new pass manager */
auto PA = PreservedAnalyses::all();
#endif
transformCmps(M, true, true, true, true, true);
verifyModule(M);
-#if LLVM_MAJOR >= 7 /* use new pass manager */
+#if LLVM_MAJOR >= 11 /* use new pass manager */
/* if (modified) {
PA.abandon<XX_Manager>();
@@ -686,7 +691,7 @@ bool CompareTransform::runOnModule(Module &M) {
}
-#if LLVM_MAJOR < 7 /* use old pass manager */
+#if LLVM_MAJOR < 11 /* use old pass manager */
static void registerCompTransPass(const PassManagerBuilder &,
legacy::PassManagerBase &PM) {

MODIFY
instrumentation/split-compares-pass.so.cc
instrumentation/split-compares-pass.so.cc
#include "llvm/Pass.h"
#include "llvm/Support/raw_ostream.h"
-#if LLVM_MAJOR >= 7
+#if LLVM_MAJOR >= 11
#include "llvm/Passes/PassPlugin.h"
#include "llvm/Passes/PassBuilder.h"
#include "llvm/IR/PassManager.h"
#endif
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
#include "llvm/IR/Module.h"
+#if LLVM_VERSION_MAJOR >= 14 /* how about stable interfaces? */
+ #include "llvm/Passes/OptimizationLevel.h"
+#endif
#include "llvm/IR/IRBuilder.h"
#if LLVM_VERSION_MAJOR > 3 || \
@@ -61,22 +64,27 @@ using namespace llvm;
namespace {
-#if LLVM_MAJOR >= 7
+#if LLVM_MAJOR >= 11
class SplitComparesTransform : public PassInfoMixin<SplitComparesTransform> {
+
public:
// static char ID;
SplitComparesTransform() : enableFPSplit(0) {
+
#else
class SplitComparesTransform : public ModulePass {
+
public:
static char ID;
SplitComparesTransform() : ModulePass(ID), enableFPSplit(0) {
+
#endif
initInstrumentList();
+
}
-#if LLVM_MAJOR >= 7
+#if LLVM_MAJOR >= 11
PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM);
#else
bool runOnModule(Module &M) override;
@@ -169,37 +177,51 @@ class SplitComparesTransform : public ModulePass {
} // namespace
-#if LLVM_MAJOR >= 7
+#if LLVM_MAJOR >= 11
extern "C" ::llvm::PassPluginLibraryInfo LLVM_ATTRIBUTE_WEAK
llvmGetPassPluginInfo() {
- return {
- LLVM_PLUGIN_API_VERSION, "splitcompares", "v0.1",
+
+ return {LLVM_PLUGIN_API_VERSION, "splitcompares", "v0.1",
/* lambda to insert our pass into the pass pipeline. */
[](PassBuilder &PB) {
+
#if 1
+ #if LLVM_VERSION_MAJOR <= 13
using OptimizationLevel = typename PassBuilder::OptimizationLevel;
+ #endif
PB.registerOptimizerLastEPCallback(
[](ModulePassManager &MPM, OptimizationLevel OL) {
+
MPM.addPass(SplitComparesTransform());
- }
- );
+
+ });
+
/* TODO LTO registration */
#else
using PipelineElement = typename PassBuilder::PipelineElement;
- PB.registerPipelineParsingCallback(
- [](StringRef Name, ModulePassManager &MPM, ArrayRef<PipelineElement>) {
+ PB.registerPipelineParsingCallback([](StringRef Name,
+ ModulePassManager &MPM,
+ ArrayRef<PipelineElement>) {
+
if (Name == "splitcompares") {
+
MPM.addPass(SplitComparesTransform());
return true;
+
} else {
+
return false;
+
}
- }
- );
+
+ });
+
#endif
+
+ }};
+
}
- };
-}
+
#else
char SplitComparesTransform::ID = 0;
#endif
@@ -1356,10 +1378,13 @@ size_t SplitComparesTransform::splitFPCompares(Module &M) {
}
-#if LLVM_MAJOR >= 7
-PreservedAnalyses SplitComparesTransform::run(Module &M, ModuleAnalysisManager &MAM) {
+#if LLVM_MAJOR >= 11
+PreservedAnalyses SplitComparesTransform::run(Module & M,
+ ModuleAnalysisManager &MAM) {
+
#else
bool SplitComparesTransform::runOnModule(Module &M) {
+
#endif
char *bitw_env = getenv("AFL_LLVM_LAF_SPLIT_COMPARES_BITW");
@@ -1383,7 +1408,7 @@ bool SplitComparesTransform::runOnModule(Module &M) {
}
-#if LLVM_MAJOR >= 7
+#if LLVM_MAJOR >= 11
auto PA = PreservedAnalyses::all();
#endif
@@ -1420,12 +1445,15 @@ bool SplitComparesTransform::runOnModule(Module &M) {
auto op0 = CI->getOperand(0);
auto op1 = CI->getOperand(1);
if (!op0 || !op1) {
-#if LLVM_MAJOR >= 7
+
+#if LLVM_MAJOR >= 11
return PA;
#else
return false;
#endif
+
}
+
auto iTy1 = dyn_cast<IntegerType>(op0->getType());
if (iTy1 && isa<IntegerType>(op1->getType())) {
@@ -1476,12 +1504,16 @@ bool SplitComparesTransform::runOnModule(Module &M) {
if ((isatty(2) && getenv("AFL_QUIET") == NULL) ||
getenv("AFL_DEBUG") != NULL) {
+
errs() << count << " comparisons found\n";
+
}
-#if LLVM_MAJOR >= 7
+#if LLVM_MAJOR >= 11
/* if (modified) {
+
PA.abandon<XX_Manager>();
+
}*/
return PA;
@@ -1491,7 +1523,7 @@ bool SplitComparesTransform::runOnModule(Module &M) {
}
-#if LLVM_MAJOR < 7 /* use old pass manager */
+#if LLVM_MAJOR < 11 /* use old pass manager */
static void registerSplitComparesPass(const PassManagerBuilder &,
legacy::PassManagerBase &PM) {
@@ -1517,3 +1549,4 @@ static RegisterPass<SplitComparesTransform> X("splitcompares",
true /* Only looks at CFG */,
true /* Analysis Pass */);
#endif
+

MODIFY
instrumentation/split-switches-pass.so.cc
instrumentation/split-switches-pass.so.cc
#include "llvm/ADT/Statistic.h"
#include "llvm/IR/IRBuilder.h"
-#if LLVM_VERSION_MAJOR >= 7 /* use new pass manager */
+#if LLVM_VERSION_MAJOR >= 11 /* use new pass manager */
#include "llvm/Passes/PassPlugin.h"
#include "llvm/Passes/PassBuilder.h"
#include "llvm/IR/PassManager.h"
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
#include "llvm/Pass.h"
#include "llvm/Analysis/ValueTracking.h"
+#if LLVM_VERSION_MAJOR >= 14 /* how about stable interfaces? */
+ #include "llvm/Passes/OptimizationLevel.h"
+#endif
#include "llvm/IR/IRBuilder.h"
#if LLVM_VERSION_MAJOR > 3 || \
@@ -60,23 +63,25 @@ using namespace llvm;
namespace {
-#if LLVM_VERSION_MAJOR >= 7 /* use new pass manager */
+#if LLVM_VERSION_MAJOR >= 11 /* 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 */
+#if LLVM_VERSION_MAJOR >= 11 /* use new pass manager */
PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM);
#else
bool runOnModule(Module &M) override;
@@ -91,6 +96,7 @@ class SplitSwitchesTransform : public ModulePass {
return "splits switch constructs";
}
+
#endif
struct CaseExpr {
@@ -119,37 +125,51 @@ class SplitSwitchesTransform : public ModulePass {
} // namespace
-#if LLVM_VERSION_MAJOR >= 7 /* use new pass manager */
+#if LLVM_VERSION_MAJOR >= 11 /* use new pass manager */
extern "C" ::llvm::PassPluginLibraryInfo LLVM_ATTRIBUTE_WEAK
llvmGetPassPluginInfo() {
- return {
- LLVM_PLUGIN_API_VERSION, "splitswitches", "v0.1",
+
+ return {LLVM_PLUGIN_API_VERSION, "splitswitches", "v0.1",
/* lambda to insert our pass into the pass pipeline. */
[](PassBuilder &PB) {
+
#if 1
+ #if LLVM_VERSION_MAJOR <= 13
using OptimizationLevel = typename PassBuilder::OptimizationLevel;
+ #endif
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>) {
+ 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
@@ -464,10 +484,13 @@ bool SplitSwitchesTransform::splitSwitches(Module &M) {
}
-#if LLVM_VERSION_MAJOR >= 7 /* use new pass manager */
-PreservedAnalyses SplitSwitchesTransform::run(Module &M, ModuleAnalysisManager &MAM) {
+#if LLVM_VERSION_MAJOR >= 11 /* 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)
@@ -475,16 +498,18 @@ bool SplitSwitchesTransform::runOnModule(Module &M) {
else
be_quiet = 1;
-#if LLVM_VERSION_MAJOR >= 7 /* use new pass manager */
+#if LLVM_VERSION_MAJOR >= 11 /* use new pass manager */
auto PA = PreservedAnalyses::all();
#endif
splitSwitches(M);
verifyModule(M);
-#if LLVM_VERSION_MAJOR >= 7 /* use new pass manager */
+#if LLVM_VERSION_MAJOR >= 11 /* use new pass manager */
/* if (modified) {
+
PA.abandon<XX_Manager>();
+
}*/
return PA;
@@ -494,7 +519,7 @@ bool SplitSwitchesTransform::runOnModule(Module &M) {
}
-#if LLVM_VERSION_MAJOR < 7 /* use old pass manager */
+#if LLVM_VERSION_MAJOR < 11 /* use old pass manager */
static void registerSplitSwitchesTransPass(const PassManagerBuilder &,
legacy::PassManagerBase &PM) {
@@ -515,3 +540,4 @@ static RegisterStandardPasses RegisterSplitSwitchesTransPassLTO(
registerSplitSwitchesTransPass);
#endif
#endif
+

llvm new passmanager fixes