adapt compiler driver to laod new pass manager passes

This commit is contained in:
hexcoder-
2021-10-12 19:04:35 +02:00
parent d0fc985e22
commit 8e66289809
2 changed files with 19 additions and 12 deletions

View File

@ -1,6 +1,7 @@
/* /*
* Copyright 2016 laf-intel * Copyright 2016 laf-intel
* extended for floating point by Heiko Eißfeldt * extended for floating point by Heiko Eißfeldt
* adapted to new pass manager by Heiko Eißfeldt
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -33,7 +34,7 @@
#include "llvm/Passes/PassBuilder.h" #include "llvm/Passes/PassBuilder.h"
#include "llvm/IR/PassManager.h" #include "llvm/IR/PassManager.h"
//#include "llvm/IR/LegacyPassManager.h" //#include "llvm/IR/LegacyPassManager.h"
#include "llvm/Transforms/IPO/PassManagerBuilder.h" //#include "llvm/Transforms/IPO/PassManagerBuilder.h"
#include "llvm/Transforms/Utils/BasicBlockUtils.h" #include "llvm/Transforms/Utils/BasicBlockUtils.h"
#include "llvm/IR/Module.h" #include "llvm/IR/Module.h"
@ -61,7 +62,7 @@ namespace {
class SplitComparesTransform : public PassInfoMixin<SplitComparesTransform> { class SplitComparesTransform : public PassInfoMixin<SplitComparesTransform> {
public: public:
static char ID; // static char ID;
SplitComparesTransform() : enableFPSplit(0) { SplitComparesTransform() : enableFPSplit(0) {
initInstrumentList(); initInstrumentList();
@ -159,7 +160,7 @@ class SplitComparesTransform : public PassInfoMixin<SplitComparesTransform> {
extern "C" ::llvm::PassPluginLibraryInfo LLVM_ATTRIBUTE_WEAK extern "C" ::llvm::PassPluginLibraryInfo LLVM_ATTRIBUTE_WEAK
llvmGetPassPluginInfo() { llvmGetPassPluginInfo() {
return { return {
LLVM_PLUGIN_API_VERSION, "SplitCompares", "v0.1", LLVM_PLUGIN_API_VERSION, "splitcompares", "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 1 #if 1
@ -187,7 +188,7 @@ llvmGetPassPluginInfo() {
}; };
} }
char SplitComparesTransform::ID = 0; //char SplitComparesTransform::ID = 0;
/// This function splits FCMP instructions with xGE or xLE predicates into two /// This function splits FCMP instructions with xGE or xLE predicates into two
/// FCMP instructions with predicate xGT or xLT and EQ /// FCMP instructions with predicate xGT or xLT and EQ
@ -700,7 +701,7 @@ bool SplitComparesTransform::splitCompare(CmpInst *cmp_inst, Module &M,
ReplaceInstWithInst(cmp_inst->getParent()->getInstList(), ii, PN); ReplaceInstWithInst(cmp_inst->getParent()->getInstList(), ii, PN);
// We split the comparison into low and high. If this isn't our target // We split the comparison into low and high. If this isn't our target
// bitwidth we recursivly split the low and high parts again until we have // bitwidth we recursively split the low and high parts again until we have
// target bitwidth. // target bitwidth.
if ((bitw / 2) > target_bitwidth) { if ((bitw / 2) > target_bitwidth) {
@ -1352,7 +1353,7 @@ PreservedAnalyses SplitComparesTransform::run(Module &M, ModuleAnalysisManager &
if ((isatty(2) && getenv("AFL_QUIET") == NULL) || if ((isatty(2) && getenv("AFL_QUIET") == NULL) ||
getenv("AFL_DEBUG") != NULL) { getenv("AFL_DEBUG") != NULL) {
errs() << "Split-compare-pass by laf.intel@gmail.com, extended by " errs() << "Split-compare-newpass by laf.intel@gmail.com, extended by "
"heiko@hexco.de (splitting icmp to " "heiko@hexco.de (splitting icmp to "
<< target_bitwidth << " bit)\n"; << target_bitwidth << " bit)\n";
@ -1364,7 +1365,7 @@ PreservedAnalyses SplitComparesTransform::run(Module &M, ModuleAnalysisManager &
} }
auto PA = PreservedAnalyses::all(); auto PA = PreservedAnalyses::none();
if (enableFPSplit) { if (enableFPSplit) {
@ -1447,6 +1448,11 @@ PreservedAnalyses SplitComparesTransform::run(Module &M, ModuleAnalysisManager &
} }
if ((isatty(2) && getenv("AFL_QUIET") == NULL) ||
getenv("AFL_DEBUG") != NULL) {
errs() << count << " comparisons found\n";
}
/* if (modified) { /* if (modified) {
PA.abandon<XX_Manager>(); PA.abandon<XX_Manager>();
}*/ }*/

View File

@ -500,11 +500,12 @@ static void edit_params(u32 argc, char **argv, char **envp) {
} else { } else {
cc_params[cc_par_cnt++] = "-Xclang"; // cc_params[cc_par_cnt++] = "-Xclang";
cc_params[cc_par_cnt++] = "-load"; // cc_params[cc_par_cnt++] = "-load";
cc_params[cc_par_cnt++] = "-Xclang"; // cc_params[cc_par_cnt++] = "-Xclang";
cc_params[cc_par_cnt++] = "-fexperimental-new-pass-manager";
cc_params[cc_par_cnt++] = cc_params[cc_par_cnt++] =
alloc_printf("%s/split-compares-pass.so", obj_path); alloc_printf("-fpass-plugin=%s/split-compares-pass.so", obj_path);
} }
@ -548,7 +549,7 @@ static void edit_params(u32 argc, char **argv, char **envp) {
#if LLVM_MAJOR >= 13 #if LLVM_MAJOR >= 13
// fuck you llvm 13 // fuck you llvm 13
cc_params[cc_par_cnt++] = "-fno-experimental-new-pass-manager"; // cc_params[cc_par_cnt++] = "-fno-experimental-new-pass-manager";
#endif #endif
if (lto_mode && !have_c) { if (lto_mode && !have_c) {