40 using next_map_t = std::map<UniqueId, std::unordered_map<cstring, std::set<UniqueId>>>;
43 std::map<UniqueId, std::unordered_map<int, std::set<UniqueId>>> lbs;
44 size_t get_num_lbs() {
return size_t(max_tag + 1); }
45 size_t get_num_dts() {
return num_dts; }
53 friend std::ostream &operator<<(std::ostream &out,
const JbayNextTable &nt) {
54 out <<
"Long Branches:" << std::endl;
55 for (
auto id_tag : nt.lbs) {
56 out <<
" " << id_tag.first <<
" has long branch mapping:" << std::endl;
57 for (
auto tag_tbls : id_tag.second) {
58 out <<
" " << tag_tbls.first <<
":" << std::endl;
59 for (
auto t : tag_tbls.second) {
60 out <<
" " << t << std::endl;
64 if (nt.lbs.size() == 0) out <<
" unused" << std::endl;
65 out <<
"Liveness:" << std::endl;
66 for (
auto luse : nt.lbus) {
67 out <<
" " << luse << std::endl;
71 void dbprint(std::ostream &out)
const { out << *
this; }
73 const std::unordered_map<int, std::set<UniqueId>> &long_branches(
UniqueId tbl)
const {
74 if (!lbs.count(tbl))
return NextTable::long_branches(tbl);
83 const IR::MAU::Table *dest;
84 explicit LBUse(
const IR::MAU::Table *d)
85 : fst(-1), lst(-1), dest(d) {}
86 LBUse(
const IR::MAU::Table *d,
size_t f,
size_t l)
87 : fst(f), lst(l), dest(d) {}
89 bool operator<(
const LBUse &r)
const {
return dest->unique_id() < r.dest->unique_id(); }
90 bool operator&(
const LBUse &a)
const;
91 void extend(
const IR::MAU::Table *);
93 inline bool same_gress(
const LBUse &r)
const {
return dest->thread() == r.dest->thread(); }
95 inline gress_t thread()
const {
return dest->thread(); }
96 friend std::ostream &operator<<(std::ostream &out,
const LBUse &u) {
97 out <<
"dest: " << u.dest->name <<
", rng: " << u.fst <<
"->" << u.lst;
103 using TableToSeqSet =
105 using TableToTableSet =
107 using SeqToThreads =
ordered_map<
const IR::MAU::TableSeq *,
110 TableToSeqSet table_to_seqs;
111 TableToTableSet can_localize_prop_to;
112 SeqToThreads seq_to_threads;
115 auto rv = PassManager::init_apply(node);
116 table_to_seqs.clear();
117 can_localize_prop_to.clear();
118 seq_to_threads.clear();
125 auto rv = MauInspector::init_apply(node);
126 self.table_to_seqs.clear();
129 bool preorder(
const IR::MAU::Table *)
override;
132 explicit BuildTableToSeqs(LocalizeSeqs &s) : self(s) { visitDagOnce =
false; }
138 auto rv = MauInspector::init_apply(node);
139 self.can_localize_prop_to.clear();
142 bool preorder(
const IR::MAU::Table *)
override;
145 explicit BuildCanLocalizeMaps(LocalizeSeqs &s) : self(s) {}
150 addPasses({
new BuildTableToSeqs(*
this),
new BuildCanLocalizeMaps(*
this)});
153 bool can_propagate_to(
const IR::MAU::Table *src,
const IR::MAU::Table *dst)
const {
154 auto src_pos = can_localize_prop_to.find(src);
155 if (src_pos == can_localize_prop_to.end())
return false;
156 return src_pos->second.count(dst) > 0;
160 LocalizeSeqs localize_seqs;
164 std::vector<LBUse> uses;
167 bool add_use(
const LBUse &);
168 std::vector<LBUse>::iterator begin() {
return uses.begin(); }
169 std::vector<LBUse>::iterator end() {
return uses.end(); }
170 size_t size()
const {
return uses.size(); }
174 static inline UniqueId get_uid(
const IR::MAU::Table *t) {
175 return t->is_placed() ? t->unique_id() : t->pp_unique_id();
183 bool uses_next_table(
const IR::MAU::Table *tbl)
const {
return use_next_table.count(tbl) > 0; }
186 std::map<int, std::unique_ptr<Memories>> mems;
187 std::map<int, int> stage_id;
191 std::map<UniqueId, ordered_set<const IR::MAU::TableSeq *>> dest_ts;
192 std::set<UniqueId> al_runs;
203 void add_table_seq(
const IR::MAU::Table *, std::pair<cstring, const IR::MAU::TableSeq *>);
204 void local_prop(
const NTInfo &nti, std::map<int, bitvec> &executed_paths);
205 void cross_prop(
const NTInfo &nti, std::map<int, bitvec> &executed_paths);
206 void next_table_prop(
const NTInfo &nti, std::map<int, bitvec> &executed_paths);
207 bool preorder(
const IR::MAU::Table *)
override;
210 void end_apply()
override;
219 std::map<LBUse, int> use_tags;
224 bool preorder(
const IR::BFN::Pipe *)
override;
225 int alloc_lb(
const LBUse &);
227 std::stringstream log;
230 void end_apply()
override;
244 sym_matrix<merge_t> find_merges()
const;
245 merge_t merge(Tag l, Tag r)
const;
247 std::map<int, std::vector<IR::MAU::Table *>> stage_dts;
248 void alloc_dt_mems();
251 std::map<const IR::MAU::TableSeq *, std::vector<IR::MAU::Table *>> dumb_tbls;
255 IR::Node *preorder(IR::BFN::Pipe *)
override;
256 IR::Node *preorder(IR::MAU::Table *)
override;
258 IR::MAU::TableSeq *)
override;
260 explicit TagReduce(
JbayNextTable &ntp) : self(ntp) { visitDagOnce =
false; }