-
Notifications
You must be signed in to change notification settings - Fork 4
/
TestPass.cpp
64 lines (55 loc) · 2.03 KB
/
TestPass.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "llvm/IR/LegacyPassManager.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/Module.h"
#include "llvm/Pass.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Transforms/IPO/PassManagerBuilder.h"
#include "include/CallString.h"
#include "include/LivenessPointsTo.h"
#include "include/PointsToData.h"
using namespace llvm;
namespace {
struct TestPass : public ModulePass {
static char ID;
LivenessPointsTo analysis;
TestPass() : ModulePass(ID) {}
bool runOnModule(Module &M) override {
analysis.runOnModule(M);
errs() << "\n";
errs() << "Worklist iterations: " << analysis.worklistIterations << "\n";
errs() << "Times ran on function: " << analysis.timesRanOnFunction << "\n";
for (Function &F : M) {
if (F.isDeclaration())
continue;
ProcedurePointsTo data = *analysis.getPointsTo(F);
errs() << "Number of call strings for " << F.getName() << ": " << data.size() << "\n";
for (auto &P : data) {
errs() << "\n";
errs() << "Function: " << F.getName() << "\n";
errs() << "Call string: ";
std::get<0>(P).dump();
IntraproceduralPointsTo *pt = std::get<1>(P);
for (BasicBlock &BB : F) {
errs() << BB.getName() << ":\n";
for (Instruction &I : BB) {
auto sv = pt->find(&I)->second;
auto l = sv.first;
auto p = sv.second;
errs() << "Lin: \033[1;31m";
l->dump();
errs() << "\033[0m";
I.dump();
errs() << "Aout: \033[1;32m";
p->dump();
errs() << "\033[0m";
}
}
}
}
errs().flush();
return false;
}
};
char TestPass::ID;
static RegisterPass<TestPass> X("test-pass", "Test pass for LFCPA.");
}