forked from pranavk/spatial-computing
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdataflow.hpp
More file actions
84 lines (67 loc) · 1.91 KB
/
dataflow.hpp
File metadata and controls
84 lines (67 loc) · 1.91 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
/*
* 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.
*/
#ifndef SPATIAL_DATAFLOW_HPP
#define SPATIAL_DATAFLOW_HPP
#include "llvm/Pass.h"
#include "llvm/PassManager.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/Instruction.h"
#include "llvm/IR/Instructions.h"
#include "llvm/Support/InstIterator.h"
#include "llvm/Support/raw_ostream.h"
#include <vector>
using namespace llvm;
template<typename T>
class DFG{
T p;
public:
DFG(T t) : p(t) { }
std::string getFunctionName(){
return p->getName();
}
T operator*() {return p;}
};
namespace llvm {
template<>
struct DOTGraphTraits<DFG<Function*> > : public DefaultDOTGraphTraits{
explicit DOTGraphTraits(bool isSimple=false) : DefaultDOTGraphTraits(isSimple){}
static std::string getGraphName(DFG<Function*> F){
return "DFG for function \'" + F.getFunctionName() + "\'";
}
static std::string getNodeLabel(Value *v, const DFG<Function*> &F){
Instruction *instr = dyn_cast<Instruction>(v);
std::string str;
raw_string_ostream rso(str);
instr->print(rso);
return str;
}
};
template<>
struct GraphTraits<DFG<Function*> > {
typedef Value NodeType;
typedef Value::use_iterator ChildIteratorType;
static NodeType *getEntryNode(Value *G){
return G;
}
static inline ChildIteratorType child_begin(NodeType *N){
return N->use_begin();
}
static inline ChildIteratorType child_end(NodeType *N){
return N->use_end();
}
typedef inst_iterator nodes_iterator;
static nodes_iterator nodes_begin(DFG<Function*> F){
return inst_begin(*F);
}
static nodes_iterator nodes_end(DFG<Function*> F){
return inst_end(*F);
}
};
}
#endif