mirror of
https://github.com/AFLplusplus/AFLplusplus.git
synced 2025-06-16 20:08:07 +00:00
converted compare-transform-pass to new pass manager
This commit is contained in:
@ -26,7 +26,10 @@
|
|||||||
|
|
||||||
#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"
|
#include "llvm/Passes/PassPlugin.h"
|
||||||
|
#include "llvm/Passes/PassBuilder.h"
|
||||||
|
#include "llvm/IR/PassManager.h"
|
||||||
|
//#include "llvm/IR/LegacyPassManager.h"
|
||||||
#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"
|
||||||
@ -52,28 +55,16 @@ using namespace llvm;
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
class CompareTransform : public ModulePass {
|
class CompareTransform : public PassInfoMixin<CompareTransform> {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static char ID;
|
CompareTransform() {
|
||||||
CompareTransform() : ModulePass(ID) {
|
|
||||||
|
|
||||||
initInstrumentList();
|
initInstrumentList();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool runOnModule(Module &M) override;
|
PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM);
|
||||||
|
|
||||||
#if LLVM_VERSION_MAJOR < 4
|
|
||||||
const char *getPassName() const override {
|
|
||||||
|
|
||||||
#else
|
|
||||||
StringRef getPassName() const override {
|
|
||||||
|
|
||||||
#endif
|
|
||||||
return "transforms compare functions";
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool transformCmps(Module &M, const bool processStrcmp,
|
bool transformCmps(Module &M, const bool processStrcmp,
|
||||||
@ -85,7 +76,37 @@ class CompareTransform : public ModulePass {
|
|||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
char CompareTransform::ID = 0;
|
extern "C" ::llvm::PassPluginLibraryInfo LLVM_ATTRIBUTE_WEAK
|
||||||
|
llvmGetPassPluginInfo() {
|
||||||
|
return {
|
||||||
|
LLVM_PLUGIN_API_VERSION, "comparetransform", "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(CompareTransform());
|
||||||
|
}
|
||||||
|
);
|
||||||
|
/* TODO LTO registration */
|
||||||
|
#else
|
||||||
|
using PipelineElement = typename PassBuilder::PipelineElement;
|
||||||
|
PB.registerPipelineParsingCallback(
|
||||||
|
[](StringRef Name, ModulePassManager &MPM, ArrayRef<PipelineElement>) {
|
||||||
|
if ( Name == "comparetransform" ) {
|
||||||
|
MPM.addPass(CompareTransform);
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool CompareTransform::transformCmps(Module &M, const bool processStrcmp,
|
bool CompareTransform::transformCmps(Module &M, const bool processStrcmp,
|
||||||
const bool processMemcmp,
|
const bool processMemcmp,
|
||||||
@ -592,7 +613,7 @@ bool CompareTransform::transformCmps(Module &M, const bool processStrcmp,
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CompareTransform::runOnModule(Module &M) {
|
PreservedAnalyses CompareTransform::run(Module &M, ModuleAnalysisManager &MAM) {
|
||||||
|
|
||||||
if ((isatty(2) && getenv("AFL_QUIET") == NULL) || getenv("AFL_DEBUG") != NULL)
|
if ((isatty(2) && getenv("AFL_QUIET") == NULL) || getenv("AFL_DEBUG") != NULL)
|
||||||
printf(
|
printf(
|
||||||
@ -601,13 +622,22 @@ bool CompareTransform::runOnModule(Module &M) {
|
|||||||
else
|
else
|
||||||
be_quiet = 1;
|
be_quiet = 1;
|
||||||
|
|
||||||
|
auto PA = PreservedAnalyses::none();
|
||||||
|
|
||||||
transformCmps(M, true, true, true, true, true);
|
transformCmps(M, true, true, true, true, true);
|
||||||
verifyModule(M);
|
verifyModule(M);
|
||||||
|
|
||||||
return true;
|
/* if (modified) {
|
||||||
|
PA.abandon<XX_Manager>();
|
||||||
|
}*/
|
||||||
|
|
||||||
|
return PA;
|
||||||
|
|
||||||
|
// return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
static void registerCompTransPass(const PassManagerBuilder &,
|
static void registerCompTransPass(const PassManagerBuilder &,
|
||||||
legacy::PassManagerBase &PM) {
|
legacy::PassManagerBase &PM) {
|
||||||
|
|
||||||
@ -626,4 +656,5 @@ static RegisterStandardPasses RegisterCompTransPass0(
|
|||||||
static RegisterStandardPasses RegisterCompTransPassLTO(
|
static RegisterStandardPasses RegisterCompTransPassLTO(
|
||||||
PassManagerBuilder::EP_FullLinkTimeOptimizationLast, registerCompTransPass);
|
PassManagerBuilder::EP_FullLinkTimeOptimizationLast, registerCompTransPass);
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
@ -480,11 +480,9 @@ static void edit_params(u32 argc, char **argv, char **envp) {
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
cc_params[cc_par_cnt++] = "-Xclang";
|
cc_params[cc_par_cnt++] = "-fexperimental-new-pass-manager";
|
||||||
cc_params[cc_par_cnt++] = "-load";
|
|
||||||
cc_params[cc_par_cnt++] = "-Xclang";
|
|
||||||
cc_params[cc_par_cnt++] =
|
cc_params[cc_par_cnt++] =
|
||||||
alloc_printf("%s/compare-transform-pass.so", obj_path);
|
alloc_printf("-fpass-plugin=%s/compare-transform-pass.so", obj_path);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user