ported cmplog-routines-pass
MODIFY
instrumentation/cmplog-routines-pass.cc
instrumentation/cmplog-routines-pass.cc
#include "llvm/ADT/Statistic.h"
#include "llvm/IR/IRBuilder.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/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Pass.h"
#include "llvm/Analysis/ValueTracking.h"
+#include "llvm/IR/IRBuilder.h"
#if LLVM_VERSION_MAJOR >= 4 || \
(LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR > 4)
#include "llvm/IR/Verifier.h"
@@ -53,16 +61,28 @@ using namespace llvm;
namespace {
+#if LLVM_VERSION_MAJOR >= 11 /* use new pass manager */
+class CmpLogRoutines : public PassInfoMixin<CmpLogRoutines> {
+
+ public:
+ CmpLogRoutines() {
+
+#else
class CmpLogRoutines : public ModulePass {
public:
static char ID;
CmpLogRoutines() : ModulePass(ID) {
+#endif
+
initInstrumentList();
}
+#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
@@ -76,6 +96,8 @@ class CmpLogRoutines : public ModulePass {
}
+#endif
+
private:
bool hookRtns(Module &M);
@@ -83,7 +105,8 @@ class CmpLogRoutines : public ModulePass {
} // namespace
-#if LLVM_MAJOR >= 11 && 1 == 0
+#if LLVM_MAJOR >= 11
+extern "C" ::llvm::PassPluginLibraryInfo LLVM_ATTRIBUTE_WEAK
llvmGetPassPluginInfo() {
return {LLVM_PLUGIN_API_VERSION, "cmplogroutines", "v0.1",
@@ -96,7 +119,7 @@ llvmGetPassPluginInfo() {
PB.registerOptimizerLastEPCallback(
[](ModulePassManager &MPM, OptimizationLevel OL) {
- MPM.addPass(SplitComparesTransform());
+ MPM.addPass(CmpLogRoutines());
});
@@ -720,19 +743,33 @@ bool CmpLogRoutines::hookRtns(Module &M) {
}
+#if LLVM_VERSION_MAJOR >= 11 /* use new pass manager */
+PreservedAnalyses CmpLogRoutines::run(Module &M, ModuleAnalysisManager &MAM) {
+
+#else
bool CmpLogRoutines::runOnModule(Module &M) {
+#endif
+
if (getenv("AFL_QUIET") == NULL)
printf("Running cmplog-routines-pass by andreafioraldi@gmail.com\n");
else
be_quiet = 1;
hookRtns(M);
+#if LLVM_VERSION_MAJOR >= 11 /* use new pass manager */
+ auto PA = PreservedAnalyses::all();
+#endif
verifyModule(M);
+#if LLVM_VERSION_MAJOR >= 11 /* use new pass manager */
+ return PA;
+#else
return true;
+#endif
}
+#if LLVM_VERSION_MAJOR < 11 /* use old pass manager */
static void registerCmpLogRoutinesPass(const PassManagerBuilder &,
legacy::PassManagerBase &PM) {
@@ -752,4 +789,5 @@ static RegisterStandardPasses RegisterCmpLogRoutinesPassLTO(
PassManagerBuilder::EP_FullLinkTimeOptimizationLast,
registerCmpLogRoutinesPass);
#endif
+#endif

ported cmplog-routines-pass