-
Notifications
You must be signed in to change notification settings - Fork 1
/
brchAnalysis.hpp
86 lines (62 loc) · 2.59 KB
/
brchAnalysis.hpp
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
//
// brchAnalysis.hpp
// LLVM
//
// Created by Fangzhou Liu on 2017/7/11.
//
//
#ifndef brchAnalysis_hpp
#define brchAnalysis_hpp
#include <stdio.h>
#include <regex>
#include <algorithm>
#include "llvm/Pass.h"
#include "llvm/IR/Function.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Analysis/CFG.h"
#include "Utils.hpp"
#include "idxAnalysis.hpp"
#include "argAnalysis.hpp"
#include "gVarAnalysis.hpp"
#include "loopAnalysis.hpp"
using namespace llvm;
namespace brchAnalysis {
struct BranchAnalysis : public FunctionPass {
static char ID;
BranchAnalysis();
struct ConditionInfoStruct {
loopAnalysis::LoopIndvBoundAnalysis::LoopRefTNode* node; /* The LoopRefTNode that the condition in */
Loop* L; /* The Loop this condition in */
BasicBlock *BB; /* The BasicBlock this condition in */
ICmpInst* COND; /* The condition */
// Value* LHS; /* The left-hand side of this condition */
// Value* RHS; /* The rightf-hand side of this condition */
// CmpInst::Predicate PREDICATE; /* The condition symbol, like >, >=, <, <= ... */
};
// Extract the Conditions From the Block Within the Loop
void BranchConditionAnalysis(Function &F);
// Analysis pass main function
bool runOnFunction(Function &F) override;
// Find the If Body in the Loop
vector<BasicBlock *> FindIfBody(Loop *L);
// Tranverse the LoopRefTree
void tranverseLoopRefTree(TreeNodeBase* node);
// Find the Branch Conditions
void FindBranch(loopAnalysis::LoopIndvBoundAnalysis::LoopRefTNode* nodeL);
// Check whether the branch is valid
bool CheckBranchValid(Loop *L, Value *v);
// Check Whether the Condition Var belongs to the self/parent Loop Indv
bool CheckIndvVar(Loop *L, string var);
// Print the Conditions
void dumpBranchInfoStruct();
void dumpCondInfoStruch(ConditionInfoStruct cis);
// Return the String Representation of a Branch Condition
string dumpBranchCondition(Value *cond);
// Return the String Representation of a Value
string dumpValue(Value *v);
// Return the String Representation of a Array
string dumpArray(Value *arr);
void getAnalysisUsage(AnalysisUsage &AU) const override;
};
}
#endif