remove WIP code

This commit is contained in:
vanhauser-thc
2022-04-18 13:16:10 +02:00
parent 1d00bde6c5
commit 4f42ecd815
4 changed files with 5 additions and 82 deletions

View File

@ -32,15 +32,9 @@
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
#if LLVM_MAJOR >= 11
#include "llvm/Pass.h"
#include "llvm/InitializePasses.h"
#include "llvm/Passes/PassPlugin.h"
#include "llvm/Passes/PassBuilder.h"
#include "llvm/IR/PassManager.h"
#include "llvm/Analysis/EHPersonalities.h"
#include "llvm/Analysis/PostDominators.h"
#include "llvm/Analysis/LoopInfo.h"
#include "llvm/Analysis/LoopPass.h"
#else
#include "llvm/IR/LegacyPassManager.h"
#include "llvm/Transforms/IPO/PassManagerBuilder.h"
@ -70,10 +64,7 @@ using namespace llvm;
namespace {
using LoopInfoCallback = function_ref<const LoopInfo *(Function &F)>;
#if LLVM_MAJOR >= 11 /* use new pass manager */
class CmpLogInstructions : public PassInfoMixin<CmpLogInstructions> {
public:
@ -97,7 +88,6 @@ class CmpLogInstructions : public ModulePass {
#endif
#if LLVM_MAJOR >= 11 /* use new pass manager */
PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM);
#else
bool runOnModule(Module &M) override;
@ -116,8 +106,7 @@ class CmpLogInstructions : public ModulePass {
#endif
private:
bool hookInstrs(Module &M, LoopInfoCallback LCallback);
unsigned int instrumented = 0;
bool hookInstrs(Module &M);
};
@ -164,7 +153,7 @@ Iterator Unique(Iterator first, Iterator last) {
}
bool CmpLogInstructions::hookInstrs(Module &M, LoopInfoCallback LCallback) {
bool CmpLogInstructions::hookInstrs(Module &M) {
std::vector<Instruction *> icomps;
LLVMContext & C = M.getContext();
@ -301,64 +290,14 @@ bool CmpLogInstructions::hookInstrs(Module &M, LoopInfoCallback LCallback) {
if (!isInInstrumentList(&F, MNAME)) continue;
std::vector<BasicBlock *> lcomps;
const LoopInfo * LI = LCallback(F);
#if 0
for (LoopInfo::iterator I = LI->begin(), E = LI->end(); I != E; ++I) {
Loop * L = *I;
BasicBlock *In, *Out;
bool ok = false ; L->getIncomingAndBackEdge(In, Out);
if (ok) {
BasicBlock *decisionBB = In->getSingleSuccessor();
if (decisionBB) {
/*
std::string errMsg1;
raw_string_ostream os1(errMsg1);
In->print(os1);
fprintf(stderr, "In: %s\n", os1.str().c_str());
std::string errMsg2;
raw_string_ostream os2(errMsg2);
Out->print(os2);
fprintf(stderr, "Out: %s\n", os2.str().c_str());
std::string errMsg3;
raw_string_ostream os3(errMsg3);
decisionBB->print(os3);
fprintf(stderr, "Dec: %s\n", os3.str().c_str());
*/
lcomps.push_back(decisionBB);
}
}
}
#endif
// fprintf(stderr, "Loops in %s: %zu\n", F.getName().str().c_str(),
// lcomps.size());
for (auto &BB : F) {
if (std::find(lcomps.begin(), lcomps.end(), &BB) != lcomps.end()) {
fprintf(stderr, "skipping: %p %s\n", &BB, BB.getName().str().c_str());
continue;
}
for (auto &IN : BB) {
CmpInst *selectcmpInst = nullptr;
if ((selectcmpInst = dyn_cast<CmpInst>(&IN))) {
icomps.push_back(selectcmpInst);
fprintf(stderr, "Found icomp %p in %p\n", selectcmpInst, &BB);
}
@ -706,8 +645,6 @@ bool CmpLogInstructions::hookInstrs(Module &M, LoopInfoCallback LCallback) {
}
++instrumented;
}
/* else fprintf(stderr, "skipped\n"); */
@ -721,8 +658,6 @@ bool CmpLogInstructions::hookInstrs(Module &M, LoopInfoCallback LCallback) {
}
fprintf(stderr, "instrumented: %u (%zu)\n", instrumented, icomps.size());
if (icomps.size())
return true;
else
@ -743,19 +678,9 @@ bool CmpLogInstructions::runOnModule(Module &M) {
printf("Running cmplog-instructions-pass by andreafioraldi@gmail.com\n");
else
be_quiet = 1;
auto &FAM = MAM.getResult<FunctionAnalysisManagerModuleProxy>(M).getManager();
auto LoopCallback = [&FAM](Function &F) -> const LoopInfo * {
return &FAM.getResult<LoopAnalysis>(F);
};
hookInstrs(M, LoopCallback);
hookInstrs(M);
verifyModule(M);
fprintf(stderr, "done cmplog-instructions-pass\n");
#if LLVM_MAJOR >= 11 /* use new pass manager */
return PreservedAnalyses::all();
#else

View File

@ -761,8 +761,6 @@ bool CmpLogRoutines::runOnModule(Module &M) {
#endif
verifyModule(M);
fprintf(stderr, "done cmplog-routines-pass\n");
#if LLVM_VERSION_MAJOR >= 11 /* use new pass manager */
return PA;
#else