-
Notifications
You must be signed in to change notification settings - Fork 0
/
PossiblyCheck.cpp
89 lines (78 loc) · 1.83 KB
/
PossiblyCheck.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
* not even prototype front end to finding functions that some static
* analysis thinks should have some assume/assert compile time DbC
* checks.
*
* more lame arr code
*/
#include "llvm/IR/Module.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/CFG.h"
#include "llvm/Pass.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Support/CommandLine.h"
#include <set>
using namespace llvm;
#include "PossiblyCheck.h"
bool
PossiblyCheck::scCheckAll(Function *F)
{
return true;
}
bool
PossiblyCheck::scCheckNone(Function *F)
{
return false;
}
bool
PossiblyCheck::scCheckCyclo(Function *F)
{
/*
* For a function in well-formed IR, there should be only
* 1 connected component.
*
* M = E - N + 2C;
*
*/
unsigned nEdges = 0; // E
unsigned nNodes = 0; // N
unsigned nConnectedComponents = 1; // C
nNodes = std::distance(F->begin(), F->end());
for (BasicBlock &BB : *F) {
BasicBlock *b = &BB;
nEdges += std::distance(succ_begin(b), succ_end(b));
}
unsigned v = (nEdges - nNodes + (2 * nConnectedComponents));
/* Make tunable */
#define ARBITRARY_CCBAR 10
if (v > 10) {
return true;
}
return false;
}
bool
PossiblyCheck::runOnModule(Module &M)
{
for (Function &F : M) {
if (F.isIntrinsic() || F.isDeclaration() || F.hasName() == false) {
continue;
}
std::string Fname = F.getName().str();
errs() << Fname << ":\n";
for (auto ci = shouldCheckMap.begin(); ci != shouldCheckMap.end();
++ci) {
std::string scName = ci->first;
errs() << " Running check test: " << scName << " ";
shouldCheck scFunc = ci->second;
if (scFunc(&F) == true) {
errs() << "(SHOULD CHECK)\n";
} else {
errs() << "(NO COMMENT)\n";
}
}
}
return false;
}
char PossiblyCheck::ID = 0;
static RegisterPass<PossiblyCheck> X("possibly-check", "Possibly add DbC checks");