forked from pssrawat/artemis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexprnode.cpp
2497 lines (2332 loc) · 90.9 KB
/
exprnode.cpp
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "exprnode.hpp"
using namespace std;
void idNode::collect_accesses (set<string> &accesses) {
accesses.insert (name);
}
void idNode::print_node (stringstream &out) {
if (nested)
out << "(";
out << name;
if (nested)
out << ")";
}
void idNode::print_node (stringstream &out, map<tuple<string,int,bool>,RESOURCE> rmap, bool is_lhs, bool full_stream, bool stream, string stream_dim, vector<string> temp_arrays, map<string,int> unroll_instance, bool blocked_loads, map<string,int> udecls, vector<string> params, vector<string> iters, bool linearize_accesses, bool code_diff, string &cstream_shift) {
if (unroll_instance.find (name) != unroll_instance.end()) {
if (blocked_loads) {
exprNode *temp = new binaryNode (T_PLUS, this, new datatypeNode<int>(unroll_instance[name], INT), type, false);
temp->print_node (out);
}
else {
vector<string> blockdims = (iters.size() == 3) ? vector<string>({"z", "y", "x"}) : ((iters.size() == 2) ? vector<string>({"y", "x"}) : vector<string> ({"x"}));
print_node (out);
for (vector<string>::iterator it=iters.begin(); it!=iters.end(); it++) {
if (name.compare (*it) == 0) {
out << "+";
if (unroll_instance[name] > 1)
out << unroll_instance[name] << "*";
out << "blockDim." << blockdims[it-iters.begin()];
}
}
}
}
else
print_node (out);
}
void idNode::print_node (stringstream &out, map<tuple<string,int,bool>,RESOURCE> rmap, bool is_lhs, bool full_stream, bool stream, string stream_dim, vector<string> temp_arrays, bool blocked_loads, map<string,int> udecls, vector<string> params, vector<string> iters, bool linearize_accesses, bool code_diff, map<string,tuple<int,int>> halo_dims, int reg_count, string &cstream_shift) {
if (udecls.find (name) != udecls.end()) {
vector<string> blockdims = (iters.size() == 3) ? vector<string>({"z", "y", "x"}) : ((iters.size() == 2) ? vector<string>({"y", "x"}) : vector<string> ({"x"}));
print_node (out);
for (vector<string>::iterator it=iters.begin(); it!=iters.end(); it++) {
if (name.compare (*it) == 0) {
int ufactor = (udecls.find (*it) != udecls.end ()) ? udecls[*it] : 1;
tuple<int,int> halo = (halo_dims.find (*it) != halo_dims.end ()) ? halo_dims[*it] : make_tuple (0, 0);
if (ufactor > 1 || (get<0>(halo) != 0 || get<1>(halo) != 0))
out << ufactor;
}
}
}
else
print_node (out);
}
void idNode::decompose_access_fsm (string &id, int &offset) {
id = id + name;
}
void idNode::set_data_type (map<string, DATA_TYPE> data_types) {
assert (data_types.find (name) != data_types.end ());
type = data_types[name];
}
bool idNode::same_expr (exprNode *node) {
bool same_expr = type == node->get_type ();
same_expr &= expr_type == node->get_expr_type ();
if (same_expr)
same_expr &= name.compare (node->get_name ()) == 0;
return same_expr;
}
bool idNode::consolidate_same_accesses (vector<tuple<OP_TYPE,exprNode*>> &consolidated_exprs, map<exprNode*,vector<exprNode*>> &same_accesses, map<exprNode*,exprNode*> &cmap, exprNode* access, bool flip) {
bool found = false;
if (access != NULL) {
for (auto it : same_accesses) {
if (same_expr (it.first)) {
for (auto jt : it.second) {
if (access->same_expr (jt))
found = true;
}
}
}
if (found) {
bool rhs_exists = false;
for (auto it : cmap) {
if (same_expr (it.first)) {
OP_TYPE op = flip ? T_MINUS : T_PLUS;
cmap[it.first] = new binaryNode (op, it.second, access, infer_data_type(access->get_type(), (it.second)->get_type()), false);
rhs_exists = true;
break;
}
}
if (!rhs_exists) {
cmap[this] = flip ? new uminusNode (access) : access;
}
}
}
return found;
}
bool idNode::identify_same_accesses (map<exprNode*,vector<exprNode*>> &same_accesses, exprNode *access) {
bool found = false;
for (auto it : same_accesses) {
if (same_expr(it.first)) {
(same_accesses[it.first]).push_back (access);
found = true;
}
}
if (!found && access!=NULL)
(same_accesses[this]).push_back (access);
return found;
}
bool idNode::waw_dependence (exprNode *node) {
return same_expr (node);
}
bool idNode::raw_dependence (exprNode *node) {
return same_expr (node);
}
bool idNode::war_dependence (exprNode *node) {
return same_expr (node);
}
bool idNode::pointwise_occurrence (exprNode *node) {
return true;
}
bool idNode::verify_immutable_expr (vector<string> writes, bool start_verification) {
if (start_verification) {
bool result = true;
for (auto w : writes) {
result &= (name.compare (w) != 0);
}
return result;
}
return true;
}
void idNode::compute_hull (map<string, vector<Range*>> &hull_map, vector<Range*> &hull, vector<Range*> &initial_hull, bool stream, string stream_dim, int offset) {
if (hull_map.find(name) != hull_map.end()) {
vector<Range*> new_hull = vector<Range*> (hull_map[name]);
// Take an intersection with the current hull
vector<Range*>::iterator b_dom = hull.begin();
int pos = 0;
for (vector<Range*>::iterator a_dom=new_hull.begin(); a_dom!=new_hull.end(); a_dom++,b_dom++,pos++) {
// Intersection of lo_a and lo_b;
exprNode *lo_a = (*a_dom)->get_lo_range ();
exprNode *lo_b = (*b_dom)->get_lo_range ();
string lo_a_id = "", lo_b_id = "";
int lo_a_val = 0, lo_b_val = 0;
lo_a->decompose_access_fsm (lo_a_id, lo_a_val);
lo_b->decompose_access_fsm (lo_b_id, lo_b_val);
assert (lo_a_id.compare (lo_b_id) == 0);
exprNode *lo = (lo_a_val >= lo_b_val) ? lo_a : lo_b;
// Intersection of hi_a and hi_b;
exprNode *hi_a = (*a_dom)->get_hi_range ();
exprNode *hi_b = (*b_dom)->get_hi_range ();
string hi_a_id = "", hi_b_id = "";
int hi_a_val = 0, hi_b_val = 0;
hi_a->decompose_access_fsm (hi_a_id, hi_a_val);
hi_b->decompose_access_fsm (hi_b_id, hi_b_val);
assert (hi_a_id.compare (hi_b_id) == 0);
exprNode *hi = (hi_a_val <= hi_b_val) ? hi_a : hi_b;
hull[pos] = new Range (lo, hi);
}
}
}
void idNode::compute_hull (map<string, vector<Range*>> &hull_map, vector<Range*> &hull, vector<Range*> &initial_hull, map<tuple<string,int,bool>,RESOURCE> rmap, bool stream, string stream_dim, int offset) {
if (hull_map.find(name) != hull_map.end()) {
vector<Range*> new_hull = vector<Range*> (hull_map[name]);
// Take an intersection with the current hull
vector<Range*>::iterator b_dom = hull.begin();
int pos = 0;
for (vector<Range*>::iterator a_dom=new_hull.begin(); a_dom!=new_hull.end(); a_dom++,b_dom++,pos++) {
// Intersection of lo_a and lo_b;
exprNode *lo_a = (*a_dom)->get_lo_range ();
exprNode *lo_b = (*b_dom)->get_lo_range ();
string lo_a_id = "", lo_b_id = "";
int lo_a_val = 0, lo_b_val = 0;
lo_a->decompose_access_fsm (lo_a_id, lo_a_val);
lo_b->decompose_access_fsm (lo_b_id, lo_b_val);
assert (lo_a_id.compare (lo_b_id) == 0);
exprNode *lo = (lo_a_val >= lo_b_val) ? lo_a : lo_b;
// Intersection of hi_a and hi_b;
exprNode *hi_a = (*a_dom)->get_hi_range ();
exprNode *hi_b = (*b_dom)->get_hi_range ();
string hi_a_id = "", hi_b_id = "";
int hi_a_val = 0, hi_b_val = 0;
hi_a->decompose_access_fsm (hi_a_id, hi_a_val);
hi_b->decompose_access_fsm (hi_b_id, hi_b_val);
assert (hi_a_id.compare (hi_b_id) == 0);
exprNode *hi = (hi_a_val <= hi_b_val) ? hi_a : hi_b;
hull[pos] = new Range (lo, hi);
}
}
}
exprNode *idNode::unroll_expr (string iter, int unroll_instance, map<string,int> &scalar_version_map, bool is_lhs) {
exprNode *result;
if (is_lhs) {
int val = (scalar_version_map.find (name) == scalar_version_map.end ()) ? 0 : scalar_version_map[name];
scalar_version_map[name] = val + 1;
}
if ((scalar_version_map.find (name) == scalar_version_map.end ()) || scalar_version_map[name] == 0)
result = new idNode (name, type, false);
else {
string new_name = name + "_" + to_string (scalar_version_map[name]);
result = new idNode (new_name, type, false);
}
if ((name.compare (iter) == 0) && unroll_instance != 0)
result = new binaryNode (T_PLUS, result, new datatypeNode<int>(unroll_instance, INT), type, true);
return result;
}
exprNode *uminusNode::retime_node (string stream_dim, int offset) {
uminusNode *ret = new uminusNode (*this);
ret->base_expr = base_expr->retime_node (stream_dim, offset);
return ret;
}
exprNode *uminusNode::distribute_node (void) {
uminusNode *ret = new uminusNode (*this);
ret->base_expr = (ret->get_base_expr())->distribute_node ();
return ret;
}
void uminusNode::remove_redundant_nesting (void) {
base_expr->remove_redundant_nesting();
}
bool uminusNode::same_operator (OP_TYPE p) {
return (base_expr->is_nested() || base_expr->same_operator(p));
}
void uminusNode::decompose_node (exprNode* lhs, vector<tuple<exprNode*,STMT_OP,exprNode*>> &substmts, bool flip) {
base_expr->decompose_node (lhs, substmts, !flip);
}
bool uminusNode::identify_same_accesses (map<exprNode*,vector<exprNode*>> &same_accesses, exprNode* access) {
return base_expr->identify_same_accesses (same_accesses, access);
}
bool uminusNode::consolidate_same_accesses (vector<tuple<OP_TYPE,exprNode*>> &consolidated_exprs, map<exprNode*,vector<exprNode*>> &same_accesses, map<exprNode*,exprNode*> &cmap, exprNode* access, bool flip) {
return base_expr->consolidate_same_accesses (consolidated_exprs, same_accesses, cmap, access, !flip);
}
void uminusNode::print_node (stringstream &out) {
if (nested)
out << "(";
out << "-";
base_expr->print_node (out);
if (nested)
out << ")";
}
void uminusNode::decompose_access_fsm (string &id, int &offset) {
string temp_id = "";
int temp_offset = 0;
base_expr->decompose_access_fsm (temp_id, temp_offset);
if (temp_id.length () > 0)
id = id + "-" + temp_id;
offset += -1*temp_offset;
}
bool uminusNode::same_expr (exprNode *node) {
bool result = (node->get_expr_type () == T_UMINUS);
if (result)
result &= base_expr->same_expr (dynamic_cast<uminusNode*>(node)->get_base_expr());
return result;
}
void uminusNode::print_node (stringstream &out, map<tuple<string,int,bool>,RESOURCE> rmap, bool is_lhs, bool full_stream, bool stream, string stream_dim, vector<string> temp_arrays, map<string,int> unroll_instance, bool blocked_loads, map<string,int> udecls, vector<string> params, vector<string> iters, bool linearize_accesses, bool code_diff, string &cstream_shift) {
if (nested)
out << "(";
out << "-";
base_expr->print_node (out, rmap, stream, is_lhs, full_stream, stream_dim, temp_arrays, unroll_instance, blocked_loads, udecls, params, iters, linearize_accesses, code_diff, cstream_shift);
if (nested)
out << ")";
}
void uminusNode::print_node (stringstream &out, map<tuple<string,int,bool>,RESOURCE> rmap, bool is_lhs, bool full_stream, bool stream, string stream_dim, vector<string> temp_arrays, bool blocked_loads, map<string,int> udecls, vector<string> params, vector<string> iters, bool linearize_accesses, bool code_diff, map<string,tuple<int,int>> halo_dims, int reg_count, string &cstream_shift) {
if (nested)
out << "(";
out << "-";
base_expr->print_node (out, rmap, is_lhs, full_stream, stream, stream_dim, temp_arrays, blocked_loads, udecls, params, iters, linearize_accesses, code_diff, halo_dims, reg_count, cstream_shift);
if (nested)
out << ")";
}
void uminusNode::print_last_write (stringstream &out, map<tuple<string,int,bool>,RESOURCE> rmap, map<string,exprNode*> last_writes, bool full_stream, bool stream, string stream_dim, vector<string> temp_arrays, map<string,int> unroll_instance, bool blocked_loads, map<string,int> udecls, vector<string> params, vector<string> iters, bool linearize_accesses, bool code_diff, string &cstream_shift) {
out << "-";
base_expr->print_last_write (out, rmap, last_writes, full_stream, stream, stream_dim, temp_arrays, unroll_instance, blocked_loads, udecls, params, iters, linearize_accesses, code_diff, cstream_shift);
}
void uminusNode::print_last_write (stringstream &out, map<tuple<string,int,bool>,RESOURCE> rmap, map<string,exprNode*> last_writes, bool full_stream, bool stream, string stream_dim, vector<string> temp_arrays, bool blocked_loads, map<string,int> udecls, vector<string> params, vector<string> iters, bool linearize_accesses, bool code_diff, map<string,tuple<int,int>> halo_dims, int reg_count, string &cstream_shift) {
out << "-";
base_expr->print_last_write (out, rmap, last_writes, full_stream, stream, stream_dim, temp_arrays, blocked_loads, udecls, params, iters, linearize_accesses, code_diff, halo_dims, reg_count, cstream_shift);
}
exprNode *uminusNode::unroll_expr (string iter, int unroll_instance, map<string,int> &scalar_version_map, bool is_lhs) {
exprNode *temp = base_expr->unroll_expr (iter, unroll_instance, scalar_version_map, is_lhs);
return new uminusNode (temp, type, nested);
}
bool binaryNode::is_scalar_expr (void) {
bool ret = true;
ret &= lhs->is_scalar_expr ();
ret &= rhs->is_scalar_expr ();
return ret;
}
exprNode *binaryNode::retime_node (string stream_dim, int offset) {
binaryNode *new_node = new binaryNode (*this);
new_node->lhs = lhs->retime_node (stream_dim, offset);
new_node->rhs = rhs->retime_node (stream_dim, offset);
return new_node;
}
int binaryNode::get_retiming_offset (string stream_dim) {
int lhs_offset = INT_MIN, rhs_offset = INT_MIN;
lhs_offset = lhs->get_retiming_offset (stream_dim);
rhs_offset = rhs->get_retiming_offset (stream_dim);
return max (lhs_offset, rhs_offset);
}
bool binaryNode::retiming_feasible (string stream_dim, vector<int> &offset) {
bool ret = lhs->retiming_feasible (stream_dim, offset);
ret &= rhs->retiming_feasible (stream_dim, offset);
return ret;
}
bool binaryNode::same_subscripts_for_array (string arr_name, vector<string> &subscripts, DATA_TYPE &arr_type) {
bool ret = true;
ret &= lhs->same_subscripts_for_array (arr_name, subscripts, arr_type);
ret &= rhs->same_subscripts_for_array (arr_name, subscripts, arr_type);
return ret;
}
void binaryNode::replace_array_name (string old_name, string new_name) {
lhs->replace_array_name (old_name, new_name);
rhs->replace_array_name (old_name, new_name);
}
int binaryNode::get_flop_count (void) {
int lhs_flop_count = lhs->get_flop_count ();
int rhs_flop_count = rhs->get_flop_count ();
return flops_per_op (op) + lhs_flop_count + rhs_flop_count;
}
void binaryNode::accessed_arrays (set<string> &arrays) {
lhs->accessed_arrays (arrays);
rhs->accessed_arrays (arrays);
}
bool binaryNode::identify_same_accesses (map<exprNode*,vector<exprNode*>> &same_accesses, exprNode *access) {
bool inserted= false;
if (op == T_MINUS || op == T_PLUS) {
if (!lhs->is_nested())
inserted |= lhs->identify_same_accesses (same_accesses, NULL);
if (!rhs->is_nested())
inserted |= rhs->identify_same_accesses (same_accesses, NULL);
}
if (op == T_MULT) {
bool lhs_simple = (lhs->is_id_node() || lhs->is_shiftvec_node() || lhs->is_data_node());
bool lhs_nested = lhs->is_nested ();
bool rhs_simple = (rhs->is_id_node() || rhs->is_shiftvec_node() || rhs->is_data_node());
bool rhs_nested = rhs->is_nested ();
// If lhs is simple, and rhs is simple or (), then check for similary of lhs
if (lhs_simple && (rhs_simple || rhs_nested)) {
inserted = lhs->identify_same_accesses (same_accesses, rhs);
}
// If rhs is simple, and lhs is simple or (), then check for similary of rhs
if (!inserted && rhs_simple && (lhs_simple || lhs_nested)) {
inserted = rhs->identify_same_accesses (same_accesses, lhs);
}
}
return inserted;
}
bool binaryNode::consolidate_same_accesses (vector<tuple<OP_TYPE,exprNode*>> &consolidated_exprs, map<exprNode*,vector<exprNode*>> &same_accesses, map<exprNode*,exprNode*> &cmap, exprNode* access, bool flip) {
bool inserted= false;
if (op == T_MINUS || op == T_PLUS) {
if (!lhs->is_nested() && lhs->is_binary_node()) {
inserted |= lhs->consolidate_same_accesses (consolidated_exprs, same_accesses, cmap, NULL, false);
}
else {
OP_TYPE lhs_op = flip ? T_MINUS : T_PLUS;
consolidated_exprs.push_back (make_tuple (lhs_op, lhs));
}
if (!rhs->is_nested() && rhs->is_binary_node()) {
inserted |= rhs->consolidate_same_accesses (consolidated_exprs, same_accesses, cmap, NULL, op==T_MINUS);
}
else {
consolidated_exprs.push_back (make_tuple (op, rhs));
}
}
if (op == T_MULT) {
bool lhs_simple = (lhs->is_id_node() || lhs->is_shiftvec_node() || lhs->is_data_node());
bool lhs_nested = lhs->is_nested ();
bool rhs_simple = (rhs->is_id_node() || rhs->is_shiftvec_node() || rhs->is_data_node());
bool rhs_nested = rhs->is_nested ();
// If lhs is simple, and rhs is simple or (), then check for similary of lhs
if (lhs_simple && (rhs_simple || rhs_nested)) {
inserted = lhs->consolidate_same_accesses (consolidated_exprs, same_accesses, cmap, rhs, flip);
}
// If rhs is simple, and lhs is simple or (), then check for similary of rhs
if (!inserted && rhs_simple && (lhs_simple || lhs_nested)) {
inserted = rhs->consolidate_same_accesses (consolidated_exprs, same_accesses, cmap, lhs, flip);
}
if (!inserted) {
OP_TYPE new_op = flip ? T_MINUS : T_PLUS;
consolidated_exprs.push_back (make_tuple (new_op, this));
}
}
return inserted;
}
void binaryNode::decompose_node (exprNode* stmt_lhs, vector<tuple<exprNode*,STMT_OP,exprNode*>> &substmts, bool flip) {
//if (DEBUG) {
// stringstream npf;
// npf << "Currently, visiting node with lhs ";
// lhs->print_node (npf);
// npf << " and rhs ";
// rhs->print_node (npf);
// npf << "\n";
// cout << npf.str ();
//}
// The LHS gets the sign of flip
if (op == T_MINUS || op == T_PLUS) {
vector<tuple<exprNode*,STMT_OP,exprNode*>> lhs_substmts, rhs_substmts;
bool lhs_flip = flip;
lhs->decompose_node (stmt_lhs, lhs_substmts, lhs_flip);
if (lhs_substmts.empty ()) {
substmts.push_back (make_tuple (stmt_lhs, get_acc_op (T_PLUS, lhs_flip), lhs));
}
else
substmts.insert (substmts.end(), lhs_substmts.begin(), lhs_substmts.end());
bool rhs_flip = (op==T_MINUS && rhs->is_nested()) ? !flip : flip;
rhs->decompose_node (stmt_lhs, rhs_substmts, rhs_flip);
if (rhs_substmts.empty ()) {
substmts.push_back (make_tuple (stmt_lhs, get_acc_op (op, rhs_flip), rhs));
}
else {
substmts.insert (substmts.end(), rhs_substmts.begin(), rhs_substmts.end());
}
}
}
// chain of division/multiplication
void binaryNode::nonassoc_chain (bool &ret) {
if (!(op == T_MULT || op == T_DIV))
ret = false;
if (ret) {
lhs->nonassoc_chain (ret);
rhs->nonassoc_chain (ret);
}
}
// chain of addition/subtraction
void binaryNode::assoc_chain (bool &ret) {
if (!(op == T_PLUS || op == T_MINUS))
ret = false;
}
bool binaryNode::same_operator (OP_TYPE p) {
bool ret = (op == p);
if (ret) {
ret &= (lhs->is_nested() || lhs->same_operator(op));
ret &= (rhs->is_nested() || rhs->same_operator(op));
}
return ret;
}
void binaryNode::remove_redundant_nesting (void) {
//If my operator is +,/,*, and the lhs/rhs have only operators the
//same operators, remove the nesting from lhs/rhs
lhs->remove_redundant_nesting();
rhs->remove_redundant_nesting();
if (op==T_MULT || op==T_PLUS || op==T_DIV) {
stringstream temp_lhs, temp_rhs;
lhs->print_node (temp_lhs);
rhs->print_node (temp_rhs);
if (lhs->is_nested() && lhs->same_operator(op)) {
lhs->set_nested (false);
}
if (rhs->is_nested() && rhs->same_operator(op)) {
rhs->set_nested (false);
}
}
}
exprNode *binaryNode::distribute_node (void) {
// LHS must be a chain of multiplication/division,
bool lhs_nonassoc_chain = true;
lhs->nonassoc_chain (lhs_nonassoc_chain);
stringstream temp_lhs, temp_rhs;
lhs->print_node (temp_lhs);
rhs->print_node (temp_rhs);
// RHS must be nested in (), and a chain of addition/subtraction
bool rhs_assoc_chain = (rhs->is_nested()) && (rhs->get_expr_type()==T_BINARY);
rhs->assoc_chain (rhs_assoc_chain);
if (DEBUG) {
cout << "lhs = " << temp_lhs.str () << "\nrhs = " << temp_rhs.str () << endl;
cout <<" initial rhs assoc = " << rhs_assoc_chain << ", rhs nested = " << rhs->is_nested();
cout << ", lhs nonassoc = " << lhs_nonassoc_chain << ", rhs_assoc = " << rhs_assoc_chain << endl;
}
if (lhs_nonassoc_chain && rhs_assoc_chain && (op==T_MULT)) {
// Distribute lhs over the binary rhs
exprNode *t_lhs = dynamic_cast<binaryNode*>(rhs)->get_lhs ();
exprNode *t_rhs = dynamic_cast<binaryNode*>(rhs)->get_rhs ();
if (t_lhs->get_expr_type()==T_BINARY)
t_lhs->set_nested ();
if (t_rhs->get_expr_type()==T_BINARY)
t_rhs->set_nested ();
OP_TYPE new_op = dynamic_cast<binaryNode*>(rhs)->get_operator ();
exprNode *new_lhs = new binaryNode (op, lhs, t_lhs, type, false);
exprNode *new_rhs = new binaryNode (op, lhs, t_rhs, type, false);
return new binaryNode (new_op, new_lhs->distribute_node(), new_rhs->distribute_node(), type, rhs->is_nested());
}
else if (op == T_PLUS || op == T_MINUS) {
binaryNode *new_node = new binaryNode (*this);
new_node->lhs = (new_node->lhs)->distribute_node ();
new_node->rhs = (new_node->rhs)->distribute_node ();
return new_node;
}
return this;
}
void binaryNode::infer_expr_type (DATA_TYPE &ret) {
lhs->infer_expr_type (ret);
rhs->infer_expr_type (ret);
}
void binaryNode::print_node (stringstream &out) {
if (nested)
out << "(";
lhs->print_node (out);
out << print_operator (op);
rhs->print_node (out);
if (nested)
out << ")";
}
void binaryNode::print_node (stringstream &out, map<tuple<string,int,bool>,RESOURCE> rmap, bool is_lhs, bool full_stream, bool stream, string stream_dim, vector<string> temp_arrays, map<string,int> unroll_instance, bool blocked_loads, map<string,int> udecls, vector<string> params, vector<string> iters, bool linearize_accesses, bool code_diff, string &cstream_shift) {
if (nested)
out << "(";
lhs->print_node (out, rmap, is_lhs, full_stream, stream, stream_dim, temp_arrays, unroll_instance, blocked_loads, udecls, params, iters, linearize_accesses, code_diff, cstream_shift);
out << print_operator (op);
rhs->print_node (out, rmap, is_lhs, full_stream, stream, stream_dim, temp_arrays, unroll_instance, blocked_loads, udecls, params, iters, linearize_accesses, code_diff, cstream_shift);
if (nested)
out << ")";
}
void binaryNode::print_node (stringstream &out, map<tuple<string,int,bool>,RESOURCE> rmap, bool is_lhs, bool full_stream, bool stream, string stream_dim, vector<string> temp_arrays, bool blocked_loads, map<string,int> udecls, vector<string> params, vector<string> iters, bool linearize_accesses, bool code_diff, map<string,tuple<int,int>> halo_dims, int reg_count, string &cstream_shift) {
if (nested)
out << "(";
lhs->print_node (out, rmap, is_lhs, full_stream, stream, stream_dim, temp_arrays, blocked_loads, udecls, params, iters, linearize_accesses, code_diff, halo_dims, reg_count, cstream_shift);
out << print_operator (op);
rhs->print_node (out, rmap, is_lhs, full_stream, stream, stream_dim, temp_arrays, blocked_loads, udecls, params, iters, linearize_accesses, code_diff, halo_dims, reg_count, cstream_shift);
if (nested)
out << ")";
}
void binaryNode::print_last_write (stringstream &out, map<tuple<string,int,bool>,RESOURCE> rmap, map<string,exprNode*> last_writes, bool full_stream, bool stream, string stream_dim, vector<string> temp_arrays, map<string,int> unroll_instance, bool blocked_loads, map<string,int> udecls, vector<string> params, vector<string> iters, bool linearize_accesses, bool code_diff, string &cstream_shift) {
lhs->print_last_write (out, rmap, last_writes, full_stream, stream, stream_dim, temp_arrays, unroll_instance, blocked_loads, udecls, params, iters, linearize_accesses, code_diff, cstream_shift);
rhs->print_last_write (out, rmap, last_writes, full_stream, stream, stream_dim, temp_arrays, unroll_instance, blocked_loads, udecls, params, iters, linearize_accesses, code_diff, cstream_shift);
}
void binaryNode::print_last_write (stringstream &out, map<tuple<string,int,bool>,RESOURCE> rmap, map<string,exprNode*> last_writes, bool full_stream, bool stream, string stream_dim, vector<string> temp_arrays, bool blocked_loads, map<string,int> udecls, vector<string> params, vector<string> iters, bool linearize_accesses, bool code_diff, map<string,tuple<int,int>> halo_dims, int reg_count, string &cstream_shift) {
lhs->print_last_write (out, rmap, last_writes, full_stream, stream, stream_dim, temp_arrays, blocked_loads, udecls, params, iters, linearize_accesses, code_diff, halo_dims, reg_count, cstream_shift);
rhs->print_last_write (out, rmap, last_writes, full_stream, stream, stream_dim, temp_arrays, blocked_loads, udecls, params, iters, linearize_accesses, code_diff, halo_dims, reg_count, cstream_shift);
}
void binaryNode::determine_stmt_resource_mapping (map<tuple<string,int,bool>,RESOURCE> &rmap, vector<string> iters, bool stream, string stream_dim, bool use_shmem) {
lhs->determine_stmt_resource_mapping (rmap, iters, stream, stream_dim, use_shmem);
rhs->determine_stmt_resource_mapping (rmap, iters, stream, stream_dim, use_shmem);
}
int binaryNode::compute_dimensionality (vector<string> iters) {
int lhs_dim = lhs->compute_dimensionality (iters);
int rhs_dim = rhs->compute_dimensionality (iters);
return max (lhs_dim, rhs_dim);
}
void binaryNode::decompose_access_fsm (string &id, int &offset) {
string l_id = "", r_id = "";
int l_val = 0, r_val = 0;
lhs->decompose_access_fsm (l_id, l_val);
rhs->decompose_access_fsm (r_id, r_val);
if (op == T_DIV) {
if (DEBUG) assert ((l_id.length () == 0 || l_val == 0) && "Complicated div unhandled (decompose_access_fsm)");
if (DEBUG) assert ((r_id.length () == 0 || r_val == 0) && "Complicated div unhandled (decompose_access_fsm)");
if (l_id.length () == 0 && r_id.length () == 0) {
if (l_val % r_val == 0)
offset += l_val / r_val;
else
id = id + to_string(l_val) + "/" + to_string (r_val);
}
else if (l_id.length () != 0) {
if (r_id.length () == 0)
id = id + l_id + "/" + to_string (r_val);
else
id = id + l_id + "/" + r_id;
}
else if (r_id.length () != 0)
id = id + to_string (l_val) + "/" + r_id;
}
else if (op == T_MULT) {
// Arrange IDs on left, and val on right.
if (DEBUG) assert ((l_id.length () == 0 || l_val == 0) && "Complicated mult unhandled (decompose_access_fsm)");
if (DEBUG) assert ((r_id.length () == 0 || r_val == 0) && "Complicated mult unhandled (decompose_access_fsm)");
if (l_id.length () == 0 && r_id.length () == 0)
offset += l_val * r_val;
else if (l_id.length () != 0) {
if (r_id.length () == 0)
id = id + l_id + "*" + to_string (r_val);
else {
string first = (l_id.compare (r_id) <= 0) ? l_id : r_id;
string second = (l_id.compare (r_id) > 0) ? l_id : r_id;
id = id + first + "*" + second;
}
}
else if (r_id.length () != 0)
id = id + r_id + "*" + to_string (l_val);
}
else if (op == T_PLUS) {
if (l_id.length () > 0 && r_id.length () > 0) {
string first = (l_id.compare (r_id) <= 0) ? l_id : r_id;
string second = (l_id.compare (r_id) > 0) ? l_id : r_id;
id = id + first + "+" + second;
}
else if (l_id.length () > 0)
id = id + l_id;
else if (r_id.length () > 0)
id = id + r_id;
offset += l_val + r_val;
}
else if (op == T_MINUS) {
if (l_id.length () > 0 && r_id.length () > 0) {
r_id = "-" + r_id;
string first = (l_id.compare (r_id) <= 0) ? l_id : r_id;
string second = (l_id.compare (r_id) > 0) ? l_id : r_id;
id = id + first + "-" + second;
}
else if (l_id.length () > 0)
id = id + l_id;
else if (r_id.length () > 0)
id = id + "-" + r_id;
offset += l_val - r_val;
}
}
void binaryNode::set_data_type (map<string, DATA_TYPE> data_types) {
lhs->set_data_type (data_types);
rhs->set_data_type (data_types);
}
void binaryNode::collect_accesses (set<string> &accesses) {
lhs->collect_accesses (accesses);
rhs->collect_accesses (accesses);
}
bool binaryNode::same_expr (exprNode *node) {
bool same_expr = type == node->get_type ();
same_expr &= expr_type == node->get_expr_type ();
if (same_expr) {
same_expr &= op == dynamic_cast<binaryNode*>(node)->get_operator ();
same_expr &= lhs->same_expr (dynamic_cast<binaryNode*>(node)->get_lhs ());
same_expr &= rhs->same_expr (dynamic_cast<binaryNode*>(node)->get_rhs ());
}
return same_expr;
}
bool binaryNode::waw_dependence (exprNode *node) {
bool waw_dependence = lhs->waw_dependence (node);
waw_dependence |= rhs->waw_dependence (node);
return waw_dependence;
}
bool binaryNode::raw_dependence (exprNode *node) {
bool raw_dependence = lhs->raw_dependence (node);
raw_dependence |= rhs->raw_dependence (node);
return raw_dependence;
}
bool binaryNode::war_dependence (exprNode *node) {
bool war_dependence = lhs->war_dependence (node);
war_dependence |= rhs->war_dependence (node);
return war_dependence;
}
bool binaryNode::pointwise_occurrence (exprNode *node) {
bool pointwise_occurrence = lhs->pointwise_occurrence (node);
pointwise_occurrence &= rhs->pointwise_occurrence (node);
return pointwise_occurrence;
}
void binaryNode::compute_rbw (set<string> &reads, set<string> &writes, bool is_read) {
lhs->compute_rbw (reads, writes, is_read);
rhs->compute_rbw (reads, writes, is_read);
}
void binaryNode::compute_wbr (set<string> &writes, set<string> &reads, bool is_write) {
lhs->compute_wbr (writes, reads, is_write);
rhs->compute_wbr (writes, reads, is_write);
}
bool binaryNode::verify_immutable_expr (vector<string> writes, bool start_verification) {
bool result = true;
result &= lhs->verify_immutable_expr (writes, start_verification);
result &= rhs->verify_immutable_expr (writes, start_verification);
return result;
}
int binaryNode::maximum_streaming_offset (exprNode *src_lhs, string stream_dim) {
int lhs_result = lhs->maximum_streaming_offset (src_lhs, stream_dim);
int rhs_result = rhs->maximum_streaming_offset (src_lhs, stream_dim);
return max (lhs_result, rhs_result);
}
int binaryNode::minimum_streaming_offset (string stream_dim) {
int lhs_result = lhs->minimum_streaming_offset (stream_dim);
int rhs_result = rhs->minimum_streaming_offset (stream_dim);
return min (lhs_result, rhs_result);
}
void binaryNode::offset_expr (int offset, string stream_dim) {
lhs->offset_expr (offset, stream_dim);
rhs->offset_expr (offset, stream_dim);
}
void binaryNode::compute_hull (map<string, vector<Range*>> &hull_map, vector<Range*> &hull, vector<Range*> &initial_hull, bool stream, string stream_dim, int offset) {
lhs->compute_hull (hull_map, hull, initial_hull, stream, stream_dim, offset);
rhs->compute_hull (hull_map, hull, initial_hull, stream, stream_dim, offset);
}
void binaryNode::compute_hull (map<string, vector<Range*>> &hull_map, vector<Range*> &hull, vector<Range*> &initial_hull, map<tuple<string,int,bool>,RESOURCE> rmap, bool stream, string stream_dim, int offset) {
lhs->compute_hull (hull_map, hull, initial_hull, rmap, stream, stream_dim, offset);
rhs->compute_hull (hull_map, hull, initial_hull, rmap, stream, stream_dim, offset);
}
void binaryNode::shift_hull (vector<Range*> &hull) {
lhs->shift_hull (hull);
rhs->shift_hull (hull);
}
void binaryNode::shift_hull (vector<Range*> &hull, bool stream, string stream_dim) {
lhs->shift_hull (hull, stream, stream_dim);
rhs->shift_hull (hull, stream, stream_dim);
}
void binaryNode::collect_access_stats (map<tuple<string,int,bool>,tuple<int,int,int>> &access_map, bool is_read, map<string,int> blockdims, vector<string> iters, bool stream, string stream_dim) {
lhs->collect_access_stats (access_map, is_read, blockdims, iters, stream, stream_dim);
rhs->collect_access_stats (access_map, is_read, blockdims, iters, stream, stream_dim);
}
void binaryNode::collect_access_stats (map<tuple<string,int,bool>, tuple<int,int,map<int,vector<string>>>> &access_map, bool is_read, vector<string> iters, bool stream, string stream_dim) {
lhs->collect_access_stats (access_map, is_read, iters, stream, stream_dim);
rhs->collect_access_stats (access_map, is_read, iters, stream, stream_dim);
}
exprNode *binaryNode::unroll_expr (string iter, int unroll_instance, map<string,int> &scalar_version_map, bool is_lhs) {
exprNode *temp1 = lhs->unroll_expr (iter, unroll_instance, scalar_version_map, is_lhs);
exprNode *temp2 = rhs->unroll_expr (iter, unroll_instance, scalar_version_map, is_lhs);
return new binaryNode (op, temp1, temp2, type, nested);
}
exprNode *shiftvecNode::retime_node (string stream_dim, int offset) {
shiftvecNode *ret = new shiftvecNode (*this);
int pos = 0;
for (vector<exprNode*>::iterator it=indices.begin(); it!=indices.end(); it++,pos++) {
string id = "";
int val = 0;
(*it)->decompose_access_fsm (id, val);
if (!id.empty () & (id.compare (stream_dim) == 0)) {
// Start retiming
OP_TYPE op = (offset > 0) ? T_PLUS : T_MINUS;
exprNode *temp = new binaryNode (op, *it, new datatypeNode<int>(abs(offset), INT));
ret->set_index (temp, pos);
break;
}
}
return ret;
}
int shiftvecNode::get_retiming_offset (string stream_dim) {
int ret = INT_MIN;
for (vector<exprNode*>::iterator it=indices.begin(); it!=indices.end(); it++) {
string id = "";
int val = 0;
(*it)->decompose_access_fsm (id, val);
if (!id.empty () & (id.compare (stream_dim) == 0)) {
ret = val;
break;
}
}
return ret;
}
bool shiftvecNode::retiming_feasible (string stream_dim, vector<int> &offset) {
bool ret = false;
for (vector<exprNode*>::iterator it=indices.begin(); it!=indices.end(); it++) {
string id = "";
int val = 0;
(*it)->decompose_access_fsm (id, val);
if (!id.empty () & (id.compare (stream_dim) == 0)) {
if (offset.empty ()) {
offset.push_back (val);
ret = true;
}
else {
ret = (val == offset.front());
}
break;
}
}
return ret;
}
bool shiftvecNode::identify_same_accesses (map<exprNode*,vector<exprNode*>> &same_accesses, exprNode *access) {
bool found = false;
for (auto it : same_accesses) {
if (same_expr(it.first)) {
(same_accesses[it.first]).push_back (access);
found = true;
}
}
if (!found && access!=NULL)
(same_accesses[this]).push_back (access);
return found;
}
bool shiftvecNode::consolidate_same_accesses (vector<tuple<OP_TYPE,exprNode*>> &consolidated_exprs, map<exprNode*,vector<exprNode*>> &same_accesses, map<exprNode*,exprNode*> &cmap, exprNode* access, bool flip) {
bool found = false;
if (access != NULL) {
for (auto it : same_accesses) {
if (same_expr (it.first)) {
for (auto jt : it.second) {
if (access->same_expr (jt))
found = true;
}
}
}
if (found) {
bool rhs_exists = false;
for (auto it : cmap) {
if (same_expr (it.first)) {
OP_TYPE op = flip ? T_MINUS : T_PLUS;
cmap[it.first] = new binaryNode (op, it.second, access, infer_data_type(access->get_type(), (it.second)->get_type()), false);
rhs_exists = true;
break;
}
}
if (!rhs_exists) {
cmap[this] = flip ? new uminusNode (access) : access;
}
}
}
return found;
}
void shiftvecNode::collect_accesses (set<string> &accesses) {
accesses.insert (name);
}
void shiftvecNode::print_node (stringstream &out) {
if (nested)
out << "(";
out << print_array ();
if (nested)
out << ")";
}
void shiftvecNode::print_node (stringstream &out, map<tuple<string,int,bool>,RESOURCE> rmap, bool is_lhs, bool full_stream, bool stream, string stream_dim, vector<string> temp_arrays, map<string,int> unroll_instance, bool blocked_loads, map<string,int> udecls, vector<string> params, vector<string> iters, bool linearize_accesses, bool code_diff, string &cstream_shift) {
if (nested)
out << "(";
out << print_array (rmap, is_lhs, full_stream, stream, stream_dim, temp_arrays, unroll_instance, blocked_loads, udecls, params, iters, linearize_accesses, code_diff, cstream_shift);
if (nested)
out << ")";
}
void shiftvecNode::print_node (stringstream &out, map<tuple<string,int,bool>,RESOURCE> rmap, bool is_lhs, bool full_stream, bool stream, string stream_dim, vector<string> temp_arrays, bool blocked_loads, map<string,int> udecls, vector<string> params, vector<string> iters, bool linearize_accesses, bool code_diff, map<string,tuple<int,int>> halo_dims, int reg_count, string &cstream_shift) {
if (nested)
out << "(";
out << print_array (rmap, is_lhs, full_stream, stream, stream_dim, temp_arrays, blocked_loads, udecls, params, iters, linearize_accesses, code_diff, halo_dims, reg_count, cstream_shift);
if (nested)
out << ")";
}
void shiftvecNode::print_last_write (stringstream &out, map<tuple<string,int,bool>,RESOURCE> rmap, map<string,exprNode*> last_writes, bool full_stream, bool stream, string stream_dim, vector<string> temp_arrays, map<string,int> unroll_instance, bool blocked_loads, map<string,int> udecls, vector<string> params, vector<string> iters, bool linearize_accesses, bool code_diff, string &cstream_shift) {
RESOURCE res = GLOBAL_MEM;
bool resource_found = false;
bool found_streaming_iterator = false;
int streaming_pos = 0, offset = 0;
tuple<string,int,bool> access;
string access_name = name;
// Change the name according to the resource map
if (stream) {
int pos = 0;
for (vector<exprNode*>::iterator it=indices.begin(); it!=indices.end(); it++,pos++) {
string id = "";
int val = 0;
(*it)->decompose_access_fsm (id, val);
if (!id.empty () & (id.compare (stream_dim) == 0)) {
found_streaming_iterator = true;
streaming_pos = pos;
}
if (id.empty ()) {
access_name = access_name + "@" + to_string(val) + "@";
}
}
}
if (found_streaming_iterator) {
exprNode *it = indices[streaming_pos];
string id = "";
it->decompose_access_fsm (id, offset);
assert (stream_dim.compare (id) == 0 && "streaming dimension not found (print_array)");
access = make_tuple (access_name, offset, stream);
}
else
access = make_tuple (access_name, offset, false);
if (rmap.find (access) != rmap.end ()) {
res = rmap[access];
resource_found = true;
}
// Check if this is the last write
if (resource_found && (res != GLOBAL_MEM) && (last_writes.find (access_name) != last_writes.end ())) {
if (last_writes[access_name] == this) {
out << print_array (temp_arrays, full_stream, stream, stream_dim, unroll_instance, blocked_loads, params, iters, linearize_accesses, code_diff, cstream_shift);
out << " = ";
out << print_array (rmap, false, full_stream, stream, stream_dim, temp_arrays, unroll_instance, blocked_loads, udecls, params, iters, linearize_accesses, code_diff, cstream_shift);
out << ";\n";
}
}
}
void shiftvecNode::print_last_write (stringstream &out, map<tuple<string,int,bool>,RESOURCE> rmap, map<string,exprNode*> last_writes, bool full_stream, bool stream, string stream_dim, vector<string> temp_arrays,bool blocked_loads, map<string,int> udecls, vector<string> params, vector<string> iters, bool linearize_accesses, bool code_diff, map<string,tuple<int,int>> halo_dims, int reg_count, string &cstream_shift) {
RESOURCE res = GLOBAL_MEM;
bool resource_found = false;
bool found_streaming_iterator = false;
int streaming_pos = 0, offset = 0;
tuple<string,int,bool> access;
string access_name = name;
// Change the name according to the resource map
if (stream) {
int pos = 0;
for (vector<exprNode*>::iterator it=indices.begin(); it!=indices.end(); it++,pos++) {
string id = "";
int val = 0;
(*it)->decompose_access_fsm (id, val);
if (!id.empty () & (id.compare (stream_dim) == 0)) {
found_streaming_iterator = true;
streaming_pos = pos;
}
if (id.empty ()) {
access_name = access_name + "@" + to_string(val) + "@";
}
}
}
if (found_streaming_iterator) {
exprNode *it = indices[streaming_pos];
string id = "";
it->decompose_access_fsm (id, offset);
assert (stream_dim.compare (id) == 0 && "streaming dimension not found (print_array)");
access = make_tuple (access_name, offset, stream);
}
else
access = make_tuple (access_name, offset, false);
if (rmap.find (access) != rmap.end ()) {
res = rmap[access];
resource_found = true;
}
// Check if this is the last write
if (resource_found && (res != GLOBAL_MEM) && (last_writes.find (access_name) != last_writes.end ())) {
if (last_writes[access_name] == this) {
out << print_array (temp_arrays, full_stream, stream, stream_dim, udecls, blocked_loads, params, iters, linearize_accesses, code_diff, halo_dims, reg_count, cstream_shift);
out << " = ";
out << print_array (rmap, false, full_stream, stream, stream_dim, temp_arrays, blocked_loads, udecls, params, iters, linearize_accesses, code_diff, halo_dims, reg_count, cstream_shift);
out << ";\n";
}
}
}
string shiftvecNode::print_array (void) {
stringstream out;
out << name;
for (auto ind : indices) {
string id = "";
int offset = 0;
ind->decompose_access_fsm (id, offset);
out << "[";
if (id.empty ())