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
119
|
#ifndef _CG_H
#define _CG_H
#include <omega/Relation.h>
#include <basic/BoolSet.h>
#include <code_gen/CG_outputBuilder.h>
#include <vector>
namespace omega {
class CodeGen;
struct CG_result {
CodeGen *codegen_;
BoolSet<> active_;
CG_result() { codegen_ = NULL; }
virtual ~CG_result() { /* not responsible for codegen_ */ }
virtual CG_result *recompute(const BoolSet<> &parent_active, const Relation &known, const Relation &restriction) = 0;
virtual int populateDepth() = 0;
virtual std::pair<CG_result *, Relation> liftOverhead(int depth, bool propagate_up) = 0;
virtual Relation hoistGuard() = 0;
virtual void removeGuard(const Relation &guard) = 0;
virtual CG_outputRepr *printRepr(int indent, CG_outputBuilder *ocg, const std::vector<CG_outputRepr *> &stmts, const std::vector<std::pair<CG_outputRepr *, int> > &assigned_on_the_fly,std::vector<std::map<std::string, std::vector<CG_outputRepr *> > > unin, bool printString = false) const = 0;
CG_outputRepr *printRepr(CG_outputBuilder *ocg, const std::vector<CG_outputRepr *> &stmts, std::vector<std::map<std::string,std::vector<CG_outputRepr *> > >uninterpreted_symbols, bool printString = false) const;
std::string printString(std::vector<std::map<std::string, std::vector<CG_outputRepr *> > >uninterpreted_symbols = std::vector<std::map<std::string, std::vector<CG_outputRepr *> > >()) const;
int num_level() const;
virtual CG_result *clone() const = 0;
virtual void dump(int indent) const {}
void dump() { dump(0); }
};
struct CG_split: public CG_result {
std::vector<Relation> restrictions_;
std::vector<CG_result *> clauses_;
CG_split(CodeGen *codegen, const BoolSet<> &active, const std::vector<Relation> &restrictions, const std::vector<CG_result *> &clauses) {
codegen_ = codegen;
active_ = active;
restrictions_ = restrictions;
clauses_ = clauses;
}
~CG_split() {
for (int i = 0; i < clauses_.size(); i++)
delete clauses_[i];
}
CG_result *recompute(const BoolSet<> &parent_active, const Relation &known, const Relation &restriction);
int populateDepth();
std::pair<CG_result *, Relation> liftOverhead(int depth, bool propagate_up);
Relation hoistGuard();
void removeGuard(const Relation &guard);
CG_outputRepr *printRepr(int indent, CG_outputBuilder *ocg, const std::vector<CG_outputRepr *> &stmts, const std::vector<std::pair<CG_outputRepr *, int> > &assigned_on_the_fly, std::vector<std::map<std::string, std::vector<CG_outputRepr *> > > unin, bool printString=false) const;
CG_result *clone() const;
void dump(int indent) const;
private:
std::vector<CG_result *> findNextLevel() const;
};
struct CG_loop: public CG_result {
int level_;
CG_result *body_;
Relation known_;
Relation restriction_;
Relation bounds_;
Relation guard_;
bool needLoop_;
int depth_;
CG_loop(CodeGen *codegen, const BoolSet<> &active, int level, CG_result *body) {
codegen_ = codegen;
active_ = active;
level_ = level;
body_ = body;
}
~CG_loop() { delete body_; }
CG_result *recompute(const BoolSet<> &parent_active, const Relation &known, const Relation &restriction);
int populateDepth();
std::pair<CG_result *, Relation> liftOverhead(int depth, bool propagate_up);
Relation hoistGuard();
void removeGuard(const Relation &guard);
CG_outputRepr *printRepr(int indent, CG_outputBuilder *ocg, const std::vector<CG_outputRepr *> &stmts, const std::vector<std::pair<CG_outputRepr *, int> > &assigned_on_the_fly,std::vector<std::map<std::string, std::vector<CG_outputRepr *> > >unin, bool printString = false) const;
CG_outputRepr *printRepr(bool do_print_guard, int indent, CG_outputBuilder *ocg, const std::vector<CG_outputRepr *> &stmts, const std::vector<std::pair<CG_outputRepr *, int> > &assigned_on_the_fly, std::vector<std::map<std::string, std::vector<CG_outputRepr *> > > unin, bool printString = false) const;
CG_result *clone() const;
void dump(int indent) const;
};
struct CG_leaf: public CG_result {
Relation known_;
std::map<int, Relation> guards_;
CG_leaf(CodeGen *codegen, const BoolSet<> &active) {
codegen_ = codegen;
active_ = active;
}
~CG_leaf() {}
CG_result *recompute(const BoolSet<> &parent_active, const Relation &known, const Relation &restriction);
int populateDepth() { return 0; }
std::pair<CG_result *, Relation> liftOverhead(int depth, bool propagate_up);
Relation hoistGuard();
void removeGuard(const Relation &guard);
CG_outputRepr *printRepr(int indent, CG_outputBuilder *ocg, const std::vector<CG_outputRepr *> &stmts, const std::vector<std::pair<CG_outputRepr *, int> > &assigned_on_the_fly, std::vector<std::map<std::string, std::vector<CG_outputRepr *> > > unin, bool printString = false) const;
CG_result *clone() const;
void dump(int indent) const;
};
}
#endif
|