-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSymbolicRangeTest.cc
More file actions
75 lines (55 loc) · 2.17 KB
/
SymbolicRangeTest.cc
File metadata and controls
75 lines (55 loc) · 2.17 KB
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
65
66
67
68
69
70
71
72
73
74
75
#define DEBUG_TYPE "sra-test"
#include "SRA/SymbolicRangeAnalysis.h"
#include <llvm/IR/Function.h>
#include <llvm/IR/Instructions.h>
#include <llvm/IR/Module.h>
using namespace llvm;
using namespace std;
namespace {
class SymbolicRangeTest : public ModulePass {
public:
// standard LLVM pass interface
SymbolicRangeTest();
static char ID;
void getAnalysisUsage(AnalysisUsage &) const final override;
bool runOnModule(Module &) final override;
void print(raw_ostream &, const Module *) const final override;
};
char SymbolicRangeTest::ID;
static const RegisterPass<SymbolicRangeTest> registration("sra-test-easily",
"Playing around with the Symbolic Range Analysis tool.",
true, true);
}
inline SymbolicRangeTest::SymbolicRangeTest()
: ModulePass(ID) {
}
void SymbolicRangeTest::getAnalysisUsage(AnalysisUsage &usage) const {
// read-only pass never changes anything
usage.setPreservesAll();
usage.addRequired<SymbolicRangeAnalysis>();
}
bool SymbolicRangeTest::runOnModule(Module &module) {
for (Function &func : module) {
if (func.isDeclaration()) continue;
errs() << "Processing " << func.getName().str() << "\n";
for (BasicBlock &block : func) {
for (Instruction &inst : block) {
if (inst.getType()->isIntegerTy()) {
const SymbolicRangeAnalysis &sra = getAnalysis<SymbolicRangeAnalysis>(func);
BasicBlock *placeHolder = BasicBlock::Create(module.getContext());
Value *symbolicIndexInst = sra.getRangeValuesFor(&inst, IRBuilder<>(placeHolder)).second;
SAGERange R = sra.getState(&inst);
errs() << "Address is " << &inst;
errs() << inst << " [" << R.getLower() << ", " << R.getUpper()
<< "]\n";
if (symbolicIndexInst != nullptr)
errs() << "\t\tValue is " << *symbolicIndexInst << "\n";
delete placeHolder;
}
}
}
}
return false;
}
void SymbolicRangeTest::print(raw_ostream &, const Module *) const {
}