-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdataflowPass.cpp
More file actions
118 lines (98 loc) · 3.43 KB
/
dataflowPass.cpp
File metadata and controls
118 lines (98 loc) · 3.43 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*
* Spatial Computation - Manifestation of Spatial computing.
* Copyright © 2014 Pranav Kant
*
* This code is available to you under Apache License Version 2.0, January
* 2014. You can grab a copy of license from the same repository from where you
* fetched this code.
*/
#include "llvm/ADT/DenseMap.h"
#include "llvm/Analysis/CFGPrinter.h"
#include "llvm/ADT/PostOrderIterator.h"
#include "llvm/ADT/SCCIterator.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/Analysis/CFG.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/Instruction.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Module.h"
#include "llvm/IRReader/IRReader.h"
#include "llvm/Pass.h"
#include "llvm/PassManager.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Support/SourceMgr.h"
#include "llvm/Support/InstIterator.h"
#include "llvm/Support/DataFlow.h"
#include "llvm/Analysis/Dominators.h"
//#include "llvm/Support/GraphWriter.h"
#include "DFGWriter.h"
#include "waves.hpp"
#include "dataflow.hpp"
using namespace llvm;
void printInstructionsWithWaveNo(Function &F, WaveScalar &obj){
for (inst_iterator I = inst_begin(F), E = inst_end(F); I!=E; ++I){
Instruction *instr = &*I;
std::string str;
raw_string_ostream rso(str);
instr->print(rso);
outs() << *instr << " -> " << obj.getWaveNo(str) << "\n";
}
}
void printDefs(Instruction *instr){
outs() << "Use :" << *instr << "\n";
for (User::op_iterator it = instr->op_begin(), e = instr->op_end(); it!=e; it++){
Instruction *vi = dyn_cast<Instruction>(*it);
outs() << "\t\t" << *vi << "\n";
}
}
void printUses(Instruction *instr){
outs() << "Def :" << *instr << "\n";
for (Value::use_iterator i = instr->use_begin(), ie = instr->use_end(); i != ie; i++){
Instruction *vi = dyn_cast<Instruction>(*i);
outs() << "\t\t" <<*vi << "\n";
}
}
/*
DataFlowGraph is a pass that would output the Data flow graph for
corresponding function in DOT format.
*/
struct DataFlowGraph : public FunctionPass,
public SmallVectorImpl <std::pair<const BasicBlock*, const BasicBlock*> > {
static char ID;
DataFlowGraph() : FunctionPass(ID), SmallVectorImpl(10){}
virtual void getAnalysisUsage (AnalysisUsage &AU) const {
AU.setPreservesAll();
AU.addRequired<DominatorTree>();
}
bool runOnFunction(Function &F) {
if (F.getName() == "main")
return false;
DominatorTree& DT = getAnalysis<DominatorTree>();
SmallVectorImpl<std::pair<const BasicBlock*, const BasicBlock*> > *res = this;
WaveScalar obj;
obj.annotateWaves(F, res);
// printInstructionsWithWaveNo(F, obj);
std::vector<Instruction*> worklist;
for (inst_iterator I = inst_begin(F), E = inst_end(F); I!=E; ++I){
Instruction *instr = &*I;
worklist.push_back(instr);
}
for (std::vector<Instruction*>::iterator iter = worklist.begin();
iter != worklist.end();
iter++){
Instruction *instr = *iter;
printUses(instr);
}
std::string ErrorInfo;
raw_fd_ostream File("dfg.dot", ErrorInfo);
WriteDFG (File, (DFG<Function*>)&F, obj, DT);
raw_fd_ostream File1("cfg.dot", ErrorInfo);
WriteGraph (File1, (const Function*)&F);
return false;
}
};
char DataFlowGraph::ID = 0;
static RegisterPass<DataFlowGraph> X("dot-dfg",
"Output Dataflow Graph in DOT format for WaveScalar Architecture",
false, false);