-
Notifications
You must be signed in to change notification settings - Fork 0
/
enumerate.cpp.old
98 lines (76 loc) · 2.78 KB
/
enumerate.cpp.old
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
90
91
92
93
94
95
96
97
#include <iostream>
#include <list>
#include <string>
#include "llvm/Pass.h"
#include "llvm/Function.h"
#include "llvm/Support/InstIterator.h"
#include "llvm/Analysis/LoopPass.h"
using namespace llvm;
struct SILParameter
{
SILParameter(Loop* beta, Value* v, Instruction* s)
: m_beta(beta), m_v(v), m_s(s)
{
}
Loop* m_beta;
Value* m_v;
Instruction* m_s;
};
class SIL : public FunctionPass
{
typedef std::list<SILParameter*> SILParameterList;
std::map<Loop*, SILParameterList > m_loopToSILParameterListMap;
std::string m_currentFunction;
public:
static char ID;
SIL() : FunctionPass(&ID)
{
}
virtual bool runOnFunction(Function &f)
{
m_currentFunction = f.getName();
m_loopToSILParameterListMap.clear();
LoopInfo& loopInfo = getAnalysis<LoopInfo>();
for (inst_iterator i = inst_begin(f); i != inst_end(f); ++i)
{
Instruction& current_instruction = *i;
const BasicBlock* parentBlock = current_instruction.getParent();
Loop* loop = loopInfo.getLoopFor(parentBlock);
while (loop != NULL)
{
SILParameterList& currentList = m_loopToSILParameterListMap[loop];
for (User::op_iterator j = current_instruction.op_begin(); j != current_instruction.op_end(); ++j)
{
Value* v = j->get();
currentList.push_back(new SILParameter(loop, v, ¤t_instruction));
}
loop = loop->getParentLoop();
}
}
dump();
return false;
}
void dump(void)
{
std::cout << "===" << m_currentFunction << "===" << std::endl;
for (std::map<Loop*, SILParameterList>::iterator i = m_loopToSILParameterListMap.begin();
i != m_loopToSILParameterListMap.end(); ++i)
{
Loop* loop = i->first;
std::cout << "Loop header: " << loop->getHeader()->getName() << "\n\n";
for (SILParameterList::iterator j = i->second.begin(); j != i->second.end(); ++j)
{
SILParameter* par = *j;
std::cout << "\t" << "Value: " << *(par->m_v) << "\tInstruction: " << *(par->m_s) << std::endl;
std::cout << "\t------------\n";
}
}
}
virtual void getAnalysisUsage(AnalysisUsage& AU) const
{
AU.setPreservesAll();
AU.addRequired<LoopInfo>();
}
};
char SIL::ID = 0;
RegisterPass<SIL> sil("silpars", "enumerate all the variable uses in all loop bodies");