mirror of
https://github.com/AFLplusplus/AFLplusplus.git
synced 2025-06-11 01:31:37 +00:00
port cmplog-switches-pass
This commit is contained in:
parent
f2831419f5
commit
899fa59ab6
@ -119,18 +119,20 @@ llvmGetPassPluginInfo() {
|
|||||||
/* lambda to insert our pass into the pass pipeline. */
|
/* lambda to insert our pass into the pass pipeline. */
|
||||||
[](PassBuilder &PB) {
|
[](PassBuilder &PB) {
|
||||||
|
|
||||||
#if LLVM_VERSION_MAJOR <= 13
|
#if LLVM_VERSION_MAJOR <= 13
|
||||||
using OptimizationLevel = typename PassBuilder::OptimizationLevel;
|
using OptimizationLevel = typename PassBuilder::OptimizationLevel;
|
||||||
#endif
|
#endif
|
||||||
PB.registerOptimizerLastEPCallback(
|
PB.registerOptimizerLastEPCallback(
|
||||||
[](ModulePassManager &MPM, OptimizationLevel OL) {
|
[](ModulePassManager &MPM, OptimizationLevel OL) {
|
||||||
|
|
||||||
MPM.addPass(CmpLogInstructions());
|
MPM.addPass(CmpLogInstructions());
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
}};
|
}};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
char CmpLogInstructions::ID = 0;
|
char CmpLogInstructions::ID = 0;
|
||||||
#endif
|
#endif
|
||||||
|
@ -83,7 +83,6 @@ class CmpLogRoutines : public ModulePass {
|
|||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
|
||||||
#if LLVM_MAJOR >= 11 && 1 == 0
|
#if LLVM_MAJOR >= 11 && 1 == 0
|
||||||
llvmGetPassPluginInfo() {
|
llvmGetPassPluginInfo() {
|
||||||
|
|
||||||
@ -91,24 +90,24 @@ llvmGetPassPluginInfo() {
|
|||||||
/* lambda to insert our pass into the pass pipeline. */
|
/* lambda to insert our pass into the pass pipeline. */
|
||||||
[](PassBuilder &PB) {
|
[](PassBuilder &PB) {
|
||||||
|
|
||||||
#if LLVM_VERSION_MAJOR <= 13
|
#if LLVM_VERSION_MAJOR <= 13
|
||||||
using OptimizationLevel = typename PassBuilder::OptimizationLevel;
|
using OptimizationLevel = typename PassBuilder::OptimizationLevel;
|
||||||
#endif
|
#endif
|
||||||
PB.registerOptimizerLastEPCallback(
|
PB.registerOptimizerLastEPCallback(
|
||||||
[](ModulePassManager &MPM, OptimizationLevel OL) {
|
[](ModulePassManager &MPM, OptimizationLevel OL) {
|
||||||
|
|
||||||
MPM.addPass(SplitComparesTransform());
|
MPM.addPass(SplitComparesTransform());
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
}};
|
}};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
char CmpLogRoutines::ID = 0;
|
char CmpLogRoutines::ID = 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool CmpLogRoutines::hookRtns(Module &M) {
|
bool CmpLogRoutines::hookRtns(Module &M) {
|
||||||
|
|
||||||
std::vector<CallInst *> calls, llvmStdStd, llvmStdC, gccStdStd, gccStdC,
|
std::vector<CallInst *> calls, llvmStdStd, llvmStdC, gccStdStd, gccStdC,
|
||||||
|
@ -28,7 +28,14 @@
|
|||||||
#include "llvm/Config/llvm-config.h"
|
#include "llvm/Config/llvm-config.h"
|
||||||
#include "llvm/ADT/Statistic.h"
|
#include "llvm/ADT/Statistic.h"
|
||||||
#include "llvm/IR/IRBuilder.h"
|
#include "llvm/IR/IRBuilder.h"
|
||||||
#include "llvm/IR/LegacyPassManager.h"
|
#if LLVM_VERSION_MAJOR >= 11 /* 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/IR/Module.h"
|
||||||
#include "llvm/Support/Debug.h"
|
#include "llvm/Support/Debug.h"
|
||||||
#include "llvm/Support/raw_ostream.h"
|
#include "llvm/Support/raw_ostream.h"
|
||||||
@ -37,6 +44,7 @@
|
|||||||
#include "llvm/Pass.h"
|
#include "llvm/Pass.h"
|
||||||
#include "llvm/Analysis/ValueTracking.h"
|
#include "llvm/Analysis/ValueTracking.h"
|
||||||
|
|
||||||
|
#include "llvm/IR/IRBuilder.h"
|
||||||
#if LLVM_VERSION_MAJOR >= 4 || \
|
#if LLVM_VERSION_MAJOR >= 4 || \
|
||||||
(LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR > 4)
|
(LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR > 4)
|
||||||
#include "llvm/IR/Verifier.h"
|
#include "llvm/IR/Verifier.h"
|
||||||
@ -54,29 +62,42 @@ using namespace llvm;
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
class CmpLogInstructions : public ModulePass {
|
#if LLVM_VERSION_MAJOR >= 11 /* use new pass manager */
|
||||||
|
class CmplogSwitches : public PassInfoMixin<CmplogSwitches> {
|
||||||
|
|
||||||
|
public:
|
||||||
|
CmplogSwitches() {
|
||||||
|
|
||||||
|
#else
|
||||||
|
class CmplogSwitches : public ModulePass {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static char ID;
|
static char ID;
|
||||||
CmpLogInstructions() : ModulePass(ID) {
|
CmplogSwitches() : ModulePass(ID) {
|
||||||
|
|
||||||
|
#endif
|
||||||
initInstrumentList();
|
initInstrumentList();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool runOnModule(Module &M) override;
|
#if LLVM_VERSION_MAJOR >= 11 /* use new pass manager */
|
||||||
|
PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM);
|
||||||
|
#else
|
||||||
|
bool runOnModule(Module &M) override;
|
||||||
|
|
||||||
#if LLVM_VERSION_MAJOR < 4
|
#if LLVM_VERSION_MAJOR < 4
|
||||||
const char *getPassName() const override {
|
const char *getPassName() const override {
|
||||||
|
|
||||||
#else
|
#else
|
||||||
StringRef getPassName() const override {
|
StringRef getPassName() const override {
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
return "cmplog instructions";
|
return "cmplog switch split";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool hookInstrs(Module &M);
|
bool hookInstrs(Module &M);
|
||||||
|
|
||||||
@ -84,27 +105,30 @@ class CmpLogInstructions : public ModulePass {
|
|||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
#if LLVM_MAJOR >= 11 && 1 == 0
|
#if LLVM_MAJOR >= 11
|
||||||
|
extern "C" ::llvm::PassPluginLibraryInfo LLVM_ATTRIBUTE_WEAK
|
||||||
llvmGetPassPluginInfo() {
|
llvmGetPassPluginInfo() {
|
||||||
|
|
||||||
return {LLVM_PLUGIN_API_VERSION, "cmplogswitches", "v0.1",
|
return {LLVM_PLUGIN_API_VERSION, "cmplogswitches", "v0.1",
|
||||||
/* lambda to insert our pass into the pass pipeline. */
|
/* lambda to insert our pass into the pass pipeline. */
|
||||||
[](PassBuilder &PB) {
|
[](PassBuilder &PB) {
|
||||||
|
|
||||||
#if LLVM_VERSION_MAJOR <= 13
|
#if LLVM_VERSION_MAJOR <= 13
|
||||||
using OptimizationLevel = typename PassBuilder::OptimizationLevel;
|
using OptimizationLevel = typename PassBuilder::OptimizationLevel;
|
||||||
#endif
|
#endif
|
||||||
PB.registerOptimizerLastEPCallback(
|
PB.registerOptimizerLastEPCallback(
|
||||||
[](ModulePassManager &MPM, OptimizationLevel OL) {
|
[](ModulePassManager &MPM, OptimizationLevel OL) {
|
||||||
|
|
||||||
MPM.addPass(SplitComparesTransform());
|
MPM.addPass(CmplogSwitches());
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
}};
|
}};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
char CmpLogInstructions::ID = 0;
|
char CmplogSwitches::ID = 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
template <class Iterator>
|
template <class Iterator>
|
||||||
@ -122,7 +146,7 @@ Iterator Unique(Iterator first, Iterator last) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CmpLogInstructions::hookInstrs(Module &M) {
|
bool CmplogSwitches::hookInstrs(Module &M) {
|
||||||
|
|
||||||
std::vector<SwitchInst *> switches;
|
std::vector<SwitchInst *> switches;
|
||||||
LLVMContext & C = M.getContext();
|
LLVMContext & C = M.getContext();
|
||||||
@ -404,36 +428,51 @@ bool CmpLogInstructions::hookInstrs(Module &M) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CmpLogInstructions::runOnModule(Module &M) {
|
#if LLVM_VERSION_MAJOR >= 11 /* use new pass manager */
|
||||||
|
PreservedAnalyses CmplogSwitches::run(Module &M, ModuleAnalysisManager &MAM) {
|
||||||
|
|
||||||
|
#else
|
||||||
|
bool CmplogSwitches::runOnModule(Module &M) {
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
if (getenv("AFL_QUIET") == NULL)
|
if (getenv("AFL_QUIET") == NULL)
|
||||||
printf("Running cmplog-switches-pass by andreafioraldi@gmail.com\n");
|
printf("Running cmplog-switches-pass by andreafioraldi@gmail.com\n");
|
||||||
else
|
else
|
||||||
be_quiet = 1;
|
be_quiet = 1;
|
||||||
hookInstrs(M);
|
hookInstrs(M);
|
||||||
|
#if LLVM_VERSION_MAJOR >= 11 /* use new pass manager */
|
||||||
|
auto PA = PreservedAnalyses::all();
|
||||||
|
#endif
|
||||||
verifyModule(M);
|
verifyModule(M);
|
||||||
|
|
||||||
|
#if LLVM_VERSION_MAJOR >= 11 /* use new pass manager */
|
||||||
|
return PA;
|
||||||
|
#else
|
||||||
return true;
|
return true;
|
||||||
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void registerCmpLogInstructionsPass(const PassManagerBuilder &,
|
#if LLVM_VERSION_MAJOR < 11 /* use old pass manager */
|
||||||
legacy::PassManagerBase &PM) {
|
static void registerCmplogSwitchesPass(const PassManagerBuilder &,
|
||||||
|
legacy::PassManagerBase &PM) {
|
||||||
|
|
||||||
auto p = new CmpLogInstructions();
|
auto p = new CmplogSwitches();
|
||||||
PM.add(p);
|
PM.add(p);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static RegisterStandardPasses RegisterCmpLogInstructionsPass(
|
static RegisterStandardPasses RegisterCmplogSwitchesPass(
|
||||||
PassManagerBuilder::EP_OptimizerLast, registerCmpLogInstructionsPass);
|
PassManagerBuilder::EP_OptimizerLast, registerCmplogSwitchesPass);
|
||||||
|
|
||||||
static RegisterStandardPasses RegisterCmpLogInstructionsPass0(
|
static RegisterStandardPasses RegisterCmplogSwitchesPass0(
|
||||||
PassManagerBuilder::EP_EnabledOnOptLevel0, registerCmpLogInstructionsPass);
|
PassManagerBuilder::EP_EnabledOnOptLevel0, registerCmplogSwitchesPass);
|
||||||
|
|
||||||
#if LLVM_VERSION_MAJOR >= 11
|
#if LLVM_VERSION_MAJOR >= 11
|
||||||
static RegisterStandardPasses RegisterCmpLogInstructionsPassLTO(
|
static RegisterStandardPasses RegisterCmplogSwitchesPassLTO(
|
||||||
PassManagerBuilder::EP_FullLinkTimeOptimizationLast,
|
PassManagerBuilder::EP_FullLinkTimeOptimizationLast,
|
||||||
registerCmpLogInstructionsPass);
|
registerCmplogSwitchesPass);
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user