-
Notifications
You must be signed in to change notification settings - Fork 4
/
funcdefn.cpp
3940 lines (3817 loc) · 168 KB
/
funcdefn.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 "funcdefn.hpp"
void stmtnode::set_nonlive_count (void) {
nonlive_count = (int)lhs_labels.size() + (int)rhs_labels.size();
}
void stmtnode::set_nonlive_count (int val) {
nonlive_count = val;
}
void stmtnode::print_statement (stringstream &output, int vsize) {
lhs_node->print_node (output);
output << print_stmt_op (op_type);
rhs_node->print_node (output);
output << ";\n";
}
void stmtnode::set_expr_data_types (void) {
DATA_TYPE d_type = infer_data_type (lhs_node->get_type (), rhs_node->get_type ());
lhs_node->set_type (d_type);
rhs_node->set_type (d_type);
}
string stmtnode::print_statement (stringstream &output, vector<string> &initialized_labels, vector<string> iters, int vsize) {
stringstream header_output;
if (!print_intrinsics) {
rhs_node->print_initializations (header_output, initialized_labels, iters, EXPLICIT_LOADS, false);
stringstream rhs_output;
rhs_node->print_node (rhs_output, initialized_labels, iters, EXPLICIT_LOADS, false);
if (get_op_type() == ST_EQ)
lhs_node->print_initializations (header_output, initialized_labels, iters, false, true);
else
lhs_node->print_initializations (header_output, initialized_labels, iters, true, true);
lhs_node->print_node (output, initialized_labels, iters, false, true);
output << print_stmt_op (op_type);
output << rhs_output.str();
output << ";\n";
}
else {
rhs_node->print_initializations (header_output, initialized_labels, iters, EXPLICIT_LOADS, false);
if (get_op_type() == ST_EQ)
lhs_node->print_initializations (header_output, initialized_labels, iters, false, true);
else
lhs_node->print_initializations (header_output, initialized_labels, iters, true, true);
// Convert the statement back to assignment
bool is_binary = (rhs_node->get_expr_type () == T_BINARY);
OP_TYPE rhs_op = is_binary ? dynamic_cast<binary_node*>(rhs_node)->get_operator () : T_EQ;
OP_TYPE fma_op = T_EQ;
if (op_type != ST_EQ) {
fma_op = convert_stmt_op_to_op (op_type);
rhs_node = new binary_node (fma_op, lhs_node, rhs_node, vsize, gen_fma, print_intrinsics);
set_expr_data_types ();
op_type = ST_EQ;
}
// Now check if we can emit an FMA
if (gen_fma && is_binary && rhs_op == T_MULT && (fma_op == T_PLUS || fma_op == T_MINUS)) {
lhs_node->print_node (output, initialized_labels, iters, false, true);
output << print_stmt_op (op_type);
expr_node *t_lhs = dynamic_cast<binary_node*>(rhs_node)->get_lhs ();
expr_node *t_rhs = dynamic_cast<binary_node*>(rhs_node)->get_rhs ();
expr_node *rhs_m1 = dynamic_cast<binary_node*>(t_rhs)->get_lhs();
expr_node *rhs_m2 = dynamic_cast<binary_node*>(t_rhs)->get_rhs();
string tail = (lhs_node->get_type () == DOUBLE) ? "pd" : "ps";
if (fma_op == T_PLUS) output << "_mm" << to_string(vsize) << "_fmadd_" << tail << " (";
else output << "_mm" << to_string(vsize) << "_fnmadd_" << tail << " (";
rhs_m1->print_node (output, initialized_labels, iters, EXPLICIT_LOADS, false);
output << ", ";
rhs_m2->print_node (output, initialized_labels, iters, EXPLICIT_LOADS, false);
output << ", ";
t_lhs->print_node (output, initialized_labels, iters, EXPLICIT_LOADS, false);
output << ")";
}
else {
lhs_node->print_node (output, initialized_labels, iters, false, true);
output << print_stmt_op (op_type);
rhs_node->print_node (output, initialized_labels, iters, EXPLICIT_LOADS, false);
}
output << ";\n";
}
return header_output.str ();
}
void stmtnode::print_statement (map<string, string> ®_map, map<string, expr_node*> &label_to_node_map, map<string,int> &first_load, map<string,int> &last_write, vector<string> &printed_regs, stringstream &output, int vsize) {
vector<string> l_labels = get_lhs_labels ();
vector<string> r_labels = get_rhs_labels ();
// For each r_label, print out the first load.
for (vector<string>::iterator i=r_labels.begin(); i!=r_labels.end(); i++) {
if (first_load.find (*i) == first_load.end ()) continue;
if (first_load[*i] == stmt_num) {
if (DEBUG) assert (label_to_node_map.find (*i) != label_to_node_map.end ());
if (DEBUG) assert (reg_map.find (*i) != reg_map.end ());
expr_node *node = label_to_node_map[*i];
if (find (printed_regs.begin(), printed_regs.end(), reg_map[*i]) == printed_regs.end ()) {
output << print_data_type (node->get_type ());
printed_regs.push_back (reg_map[*i]);
}
output << reg_map[*i] << " = ";
node->print_node (output);
output << ";\n";
}
}
// Print type of lhs if register is appearing for the first time
for (vector<string>::iterator i=l_labels.begin(); i!=l_labels.end(); i++) {
if (find (printed_regs.begin(), printed_regs.end(), reg_map[*i]) == printed_regs.end ()) {
output << print_data_type (lhs_node->get_type ());
printed_regs.push_back (reg_map[*i]);
}
}
// Print the statement
lhs_node->print_node (reg_map, output);
output << print_stmt_op (op_type);
rhs_node->print_node (reg_map, output);
output << ";\n";
// For each l_label, print out the last write.
for (vector<string>::iterator i=l_labels.begin(); i!=l_labels.end(); i++) {
if (DEBUG) assert (last_write.find (*i) != last_write.end ());
if (last_write[*i] == stmt_num) {
if (DEBUG) assert (label_to_node_map.find (*i) != label_to_node_map.end ());
expr_node *node = label_to_node_map[*i];
if (DEBUG) assert (reg_map.find (*i) != reg_map.end ());
node->print_node (output);
output << " = " << reg_map[*i] << ";\n";
}
}
}
// Check if the label is present in the statement
bool stmtnode::is_label_present (string s) {
vector<string> l_labels = get_lhs_labels ();
vector<string> r_labels = get_rhs_labels ();
for (vector<string>::iterator i=l_labels.begin(); i!=l_labels.end(); i++)
if (s.compare (*i) == 0) return true;
for (vector<string>::iterator i=r_labels.begin(); i!=r_labels.end(); i++)
if (s.compare (*i) == 0) return true;
return false;
}
bool stmtnode::is_label_present (string s, int &frequency) {
vector<string> l_labels = get_lhs_labels ();
vector<string> r_labels = get_rhs_labels ();
bool ret = false;
frequency = 0;
for (vector<string>::iterator i=l_labels.begin(); i!=l_labels.end(); i++) {
if (s.compare (*i) == 0) {
ret = true;
frequency++;
}
}
for (vector<string>::iterator i=r_labels.begin(); i!=r_labels.end(); i++) {
if (s.compare (*i) == 0) {
ret = true;
frequency++;
}
}
return ret;
}
void funcdefn::print_decomposed_statements (stringstream & out) {
vector<stmtnode*> stmts = stmt_list->get_stmt_list ();
vector<stmtnode*> init = initial_assignments;
vector<string> initialized;
for (vector<stmtnode*>::const_iterator k=stmts.begin(); k!=stmts.end(); k++) {
expr_node *lhs = (*k)->get_lhs_expr ();
string op = print_stmt_op ((*k)->get_op_type());
expr_node *rhs = (*k)->get_rhs_expr ();
string decl = "";
// If it is an assignment statement, and the lhs is ID, declare
if ((*k)->get_op_type() == ST_EQ && lhs->get_expr_type () == T_ID && find (initialized.begin(), initialized.end(), lhs->get_name())==initialized.end()) {
initialized.push_back (lhs->get_name());
out << print_data_type (gdata_type);
}
// Iterate over initial assignments, and add the initialization if lhs match
for (vector<stmtnode*>::iterator i=init.begin(); i!=init.end();) {
if ((*i)->get_lhs_expr () == lhs) {
if ((*i)->get_op_type() == ST_EQ && ((*i)->get_lhs_expr())->get_expr_type () == T_ID && find (initialized.begin(), initialized.end(), ((*i)->get_lhs_expr())->get_name())==initialized.end()) {
initialized.push_back (((*i)->get_lhs_expr())->get_name());
out << print_data_type (gdata_type);
}
(*i)->print_statement (out, vsize);
i = init.erase (i);
break;
}
else ++i;
}
// Print lhs and rhs
stringstream lhs_out;
lhs->print_node (lhs_out);
stringstream rhs_out;
rhs->print_node (rhs_out);
out << lhs_out.str() << op << rhs_out.str() << ";\n";
}
}
void funcdefn::print_func_defn (string name) {
cout << "func definition : " << name << "{\n";
vector<stmtnode*> stmts = stmt_list->get_stmt_list ();
for (vector<stmtnode*>::const_iterator k=stmts.begin(); k!=stmts.end(); k++) {
expr_node *lhs = (*k)->get_lhs_expr ();
string op = print_stmt_op ((*k)->get_op_type());
expr_node *rhs = (*k)->get_rhs_expr ();
stringstream lhs_out;
lhs->print_node (lhs_out);
stringstream rhs_out;
rhs->print_node (rhs_out);
cout << " <" << lhs->get_type () << "> " << lhs_out.str() << op << "<" << rhs->get_type() << "> " << rhs_out.str() << ";";
cout << "\t{STMT_NO : " << (*k)->get_stmt_num() << ", ORIG_STMT_NO : " << (*k)->get_orig_stmt_num() << " | OUT_LABELS : ";
vector<string> lhs_label = (*k)->get_lhs_labels ();
for (vector<string>::const_iterator l=lhs_label.begin(); l!=lhs_label.end(); l++) {
cout << *l << " ";
}
cout << "| IN_LABELS : ";
vector<string> rhs_label = (*k)->get_rhs_labels ();
for (vector<string>::const_iterator l=rhs_label.begin(); l!=rhs_label.end(); l++) {
cout << *l << " ";
}
cout << "} (live: " << (*k)->get_live_count () << ", nonlive: " <<(*k)->get_nonlive_count() << ")" << endl;
}
cout << "}\n";
}
void funcdefn::print_transitive_dependence_graph (map<int, vector<int>> transitive_dependence_graph) {
cout << "\nTransitive dependence graph : " << endl;
for (map<int, vector<int>>::iterator j=transitive_dependence_graph.begin(); j!=transitive_dependence_graph.end(); j++) {
int lhs = j->first;
printf ("%d - ", lhs);
vector<int> rhs = j->second;
for (vector<int>::iterator k=rhs.begin(); k!=rhs.end(); k++) {
printf ("%d ", *k);
}
printf ("\n");
}
}
// Return true if source has to be executed before destination
bool funcdefn::dependence_exists_in_dependence_graph (map<int, vector<int>> &dependence_graph, int source, int dest) {
if (dependence_graph.find (dest) != dependence_graph.end ()) {
if (find (dependence_graph[dest].begin(), dependence_graph[dest].end (), source) != dependence_graph[dest].end ())
return true;
}
return false;;
}
// Return false if there is an edge from dest to source, i.e. source has dest in its rhs
bool funcdefn::verify_dependence (map<int, vector<int>> &dependence_graph, int source, int dest) {
if (dependence_graph.find (source) != dependence_graph.end ()) {
if (find (dependence_graph[source].begin(), dependence_graph[source].end (), dest) != dependence_graph[source].end ())
return false;
}
return true;
}
void funcdefn::merge_nodes_in_topological_clustering (map<int, vector<int>> &clustering, int source, int dest) {
// First add just the dest to source cluster
if (clustering.find (source) != clustering.end ()) {
// First check if there is a dependence between the source cluster rhs and dest
bool dependence_exists = false ;
for (vector<int>::iterator it=clustering[source].begin(); it!=clustering[source].end(); it++) {
dependence_exists |= dependence_exists_in_dependence_graph (cluster_dependence_graph, dest, *it);
}
if (dependence_exists) {
bool inserted = false;
for (vector<int>::iterator it=clustering[source].begin(); it!=clustering[source].end(); it++) {
if (dependence_exists_in_dependence_graph (cluster_dependence_graph, dest, *it)) {
clustering[source].insert (it, dest);
inserted = true;
break;
}
}
if (!inserted) clustering[source].push_back (dest);
}
else clustering[source].push_back (dest);
}
else {
vector<int> dest_vec;
dest_vec.push_back (dest);
clustering[source] = dest_vec;
}
if (clustering.find (dest) != clustering.end ()) {
for (vector<int>::iterator it=clustering[dest].begin(); it!=clustering[dest].end(); it++) {
int val = *it;
bool dependence_exists = false ;
for (vector<int>::iterator jt=clustering[source].begin(); jt!=clustering[source].end(); jt++) {
dependence_exists |= dependence_exists_in_dependence_graph (cluster_dependence_graph, val, *jt);
}
if (dependence_exists) {
bool inserted = false;
for (vector<int>::iterator jt=clustering[source].begin(); jt!=clustering[source].end(); jt++) {
if (dependence_exists_in_dependence_graph (cluster_dependence_graph, dest, *jt)) {
clustering[source].insert (jt, val);
inserted = true;
break;
}
}
if (!inserted) clustering[source].push_back (val);
}
else clustering[source].push_back (val);
}
clustering.erase (dest);
}
}
void funcdefn::merge_nodes_in_dependence_graph (map<int, vector<int>> &dependence_graph, int source, int dest) {
// Merge dest dependences into source
if (dependence_graph.find (source) != dependence_graph.end ()) {
if (dependence_graph.find (dest) != dependence_graph.end ()) {
vector<int> dest_vec = dependence_graph[dest];
for (vector<int>::iterator it=dest_vec.begin(); it!=dest_vec.end (); it++) {
if (*it != source && find (dependence_graph[source].begin(), dependence_graph[source].end(), *it) == dependence_graph[source].end ())
dependence_graph[source].push_back (*it);
}
dependence_graph.erase (dest);
}
}
else if (dependence_graph.find (dest) != dependence_graph.end ()) {
dependence_graph[source] = dependence_graph[dest];
dependence_graph.erase (dest);
}
// Remove self-dependence in source
if (dependence_graph.find (source) != dependence_graph.end ()) {
vector<int>::iterator jt = find (dependence_graph[source].begin(), dependence_graph[source].end(), source);
if (jt != dependence_graph[source].end ())
dependence_graph[source].erase (jt);
}
// Iterate over the entire map, and replace dest with source in rhs of each entry
for (map<int, vector<int>>::iterator it=dependence_graph.begin(); it!=dependence_graph.end(); it++) {
vector<int>::iterator jt = find (it->second.begin(), it->second.end(), dest);
if (jt != it->second.end ()) {
it->second.erase (jt);
if (it->first != source && find (it->second.begin(), it->second.end(), source) == it->second.end ())
it->second.push_back (source);
}
}
// Iterate over the map, and remove entries with empty rhs
for (map<int, vector<int>>::iterator it=dependence_graph.begin(); it!=dependence_graph.end();) {
if (it->second.empty ())
it = dependence_graph.erase (it);
else ++it;
}
}
void funcdefn::print_cluster_dependence_graph (string name) {
cout << "\nCluster dependence graph for function " << name << " : " << endl;
for (map<int, vector<int>>::iterator j=cluster_dependence_graph.begin(); j!=cluster_dependence_graph.end(); j++) {
int lhs = j->first;
printf ("%d - ", lhs);
vector<int> rhs = j->second;
for (vector<int>::iterator k=rhs.begin(); k!=rhs.end(); k++) {
printf ("%d ", *k);
}
printf ("\n");
}
}
void funcdefn::print_dependence_graph (map<int, vector<int>> dep_graph) {
if (DEBUG) cout << "\nCluster dependence graph : " << endl;
for (map<int, vector<int>>::iterator j=dep_graph.begin(); j!=dep_graph.end(); j++) {
int lhs = j->first;
printf ("%d - ", lhs);
vector<int> rhs = j->second;
for (vector<int>::iterator k=rhs.begin(); k!=rhs.end(); k++) {
printf ("%d ", *k);
}
printf ("\n");
}
}
void funcdefn::print_dependence_graph (string name) {
// First print the statement dependence graph
print_cluster_dependence_graph (name);
// Then print the sub-statement dependence graph
if (DEBUG) cout << "\nSub-statement dependence graph for function " << name << " : " << endl;
for (map<stmtnode*, vector<stmtnode*>>::iterator j=substmt_dependence_graph.begin(); j!=substmt_dependence_graph.end(); j++) {
stmtnode *lhs = (*j).first;
printf ("%d - ", lhs->get_stmt_num ());
vector<stmtnode*> rhs = (*j).second;
for (vector<stmtnode*>::iterator k=rhs.begin(); k!=rhs.end(); k++) {
printf ("%d ", (*k)->get_stmt_num());
}
printf ("\n");
}
}
void funcdefn::print_schedulable_stmts (string name) {
vector<stmtnode*> schedulable_stmts = get_schedulable_stmts ();
cout << "\nFor function " << name << ", schedulable stmts are: ( ";
for (vector<stmtnode*>::iterator j=schedulable_stmts.begin(); j!=schedulable_stmts.end(); j++) {
cout << (*j)->get_stmt_num() << " ";
}
cout << ")" << endl;
}
void funcdefn::print_scatter_gather_contributions (string name) {
map<string, vector<string>> gather_contrib = get_gather_contributions ();
// Print gather values for output
cout << "\nFor function " << name << ", output's gather contributions are: { ";
for (map<string, vector<string>>::iterator j=gather_contrib.begin(); j!=gather_contrib.end(); j++) {
cout << j->first << " <- ( ";
for (vector<string>::iterator k=(j->second).begin(); k!=(j->second).end(); k++)
cout << *k << " ";
cout << ") ";
}
cout << "}" << endl;
// Print scatter values for input
map<string, vector<string>> scatter_contrib = get_scatter_contributions ();
cout << "\nFor function " << name << ", input's scatter contributions are: { ";
for (map<string, vector<string>>::iterator j=scatter_contrib.begin(); j!=scatter_contrib.end(); j++) {
cout << j->first << " -> ( ";
for (vector<string>::iterator k=(j->second).begin(); k!=(j->second).end(); k++)
cout << *k << " ";
cout << ") ";
}
cout << "}" << endl;
// Print the label reuse
map<string, int> label_reuse = get_label_reuse ();
cout << "\nFor function " << name << ", label reuse: { ";
for (map<string, int>::iterator j=label_reuse.begin(); j!=label_reuse.end(); j++) {
cout << "[" << j->first << " , " << j->second << "] ";
}
cout << "}" << endl;
}
void funcdefn::print_affinities (string name) {
// Print primary affinity
int p_count = 0;
map<string,map<string,int>> primary_affinity = get_primary_affinity ();
cout << "\nFor function " << name << ", primary affinity : ";
for (map<string,map<string,int>>::iterator j=primary_affinity.begin(); j!=primary_affinity.end(); j++) {
string lhs = j->first;
map<string,int> &rhs = j->second;
cout << endl << lhs << " -> ";
for (map<string,int>::iterator k=rhs.begin(); k!=rhs.end(); k++) {
cout << "[" << k->first << " , " << k->second << "] ";
p_count++;
}
}
cout << "\nTotal primary affinity count: " << p_count << endl;
// Print secondary affinity
int s_count = 0;
map<string,map<string,int>> secondary_affinity = get_secondary_affinity ();
cout << "\nFor function " << name << ", secondary affinity: ";
for (map<string,map<string,int>>::iterator j=secondary_affinity.begin(); j!=secondary_affinity.end(); j++) {
string lhs = j->first;
map<string,int> &rhs = j->second;
cout << endl << lhs << " -> ";
for (map<string,int>::iterator k=rhs.begin(); k!=rhs.end(); k++) {
cout << "[" << k->first << " , " << k->second << "] ";
s_count++;
}
}
cout << "\nTotal secondary affinity count: " << s_count << endl;
}
void funcdefn::create_labels (void) {
vector<stmtnode*> stmts = stmt_list->get_stmt_list ();
for (vector<stmtnode*>::const_iterator i=stmts.begin(); i!=stmts.end(); i++) {
expr_node *lhs = (*i)->get_lhs_expr ();
expr_node *rhs = (*i)->get_rhs_expr ();
lhs->create_labels (label_to_node_map);
rhs->create_labels (label_to_node_map);
}
}
//// TODO: Erroneous right now. Remove WAR dependences by creating new entry in lassign_map
//void funcdefn::create_labels (void) {
// vector<stmtnode*> stmts = stmt_list->get_stmt_list ();
// map<string, int> lassign_map;
// vector<stmtnode*> init = initial_assignments;
// for (vector<stmtnode*>::const_iterator i=stmts.begin(); i!=stmts.end(); i++) {
// expr_node *lhs = (*i)->get_lhs_expr ();
// expr_node *rhs = (*i)->get_rhs_expr ();
// // If the operator is an assignment, we need to make sure that the
// // lhs is properly SSA'ed.
// bool is_asgn = (*i)->get_op_type () == ST_EQ;
// if (!is_asgn) {
// for (vector<stmtnode*>::iterator it=init.begin(); it!=init.end();) {
// if ((*it)->get_lhs_expr () == lhs) {
// is_asgn = true;
// it = init.erase (it);
// break;
// }
// else ++it;
// }
// }
// lhs->create_labels (lassign_map, label_to_node_map, is_asgn);
// rhs->create_labels (lassign_map, label_to_node_map, false);
// }
//}
void funcdefn::compute_participating_labels (void) {
vector<stmtnode*> stmts = stmt_list->get_stmt_list ();
for (vector<stmtnode*>::const_iterator i=stmts.begin(); i!=stmts.end(); i++) {
expr_node *lhs = (*i)->get_lhs_expr ();
expr_node *rhs = (*i)->get_rhs_expr ();
lhs->gather_participating_labels ((*i)->get_lhs_labels (), (*i)->get_lhs_names (), coefficients);
rhs->gather_participating_labels ((*i)->get_rhs_labels (), (*i)->get_rhs_names (), coefficients);
(*i)->set_nonlive_count ();
}
}
void funcdefn::distribute_rhs (void) {
vector<stmtnode*> stmts = stmt_list->get_stmt_list ();
for (vector<stmtnode*>::reverse_iterator i=stmts.rbegin(); i!=stmts.rend();) {
expr_node *lhs = (*i)->get_lhs_expr ();
expr_node *rhs = (*i)->get_rhs_expr ();
bool is_asgn = (*i)->get_op_type () == ST_EQ;
// rhs must be a binary expression with mult op
if (rhs->get_expr_type () != T_BINARY) {
i++;
continue;
}
OP_TYPE binop = dynamic_cast<binary_node*>(rhs)->get_operator ();
if (binop != T_MULT) {
i++;
continue;
}
expr_node *bin_lhs = dynamic_cast<binary_node*>(rhs)->get_lhs ();
expr_node *bin_rhs = dynamic_cast<binary_node*>(rhs)->get_rhs ();
if (bin_lhs->is_data_type () && bin_rhs->is_data_type ()) {
i++;
continue;
}
vector<string> bin_lhs_labels, bin_rhs_labels;
bin_lhs->stringify_accesses (bin_lhs_labels);
bin_rhs->stringify_accesses (bin_rhs_labels);
if (bin_rhs_labels.size()>1 || bin_lhs_labels.size()>1) {
i++;
continue;
}
// Identify the temp and coef from the binary node
vector<string> temp_val;
expr_node *temp_node=NULL, *coef_node=NULL;
// Trivial case: coef is datatype value
if (bin_lhs->is_data_type ())
coef_node = bin_lhs;
else if (bin_rhs->is_data_type ())
coef_node = bin_rhs;
for (vector<string>::iterator it=bin_lhs_labels.begin(); it!=bin_lhs_labels.end(); it++) {
if ((*it).find ("_t_") != string::npos) {
temp_val.push_back (*it);
temp_node = bin_lhs;
}
else {
coef_node = bin_lhs;
}
}
for (vector<string>::iterator it=bin_rhs_labels.begin(); it!=bin_rhs_labels.end(); it++) {
if ((*it).find ("_t_") != string::npos) {
temp_val.push_back (*it);
temp_node = bin_rhs;
}
else {
coef_node = bin_rhs;
}
}
if (temp_node == NULL) {
i++;
continue;
}
if (!(temp_node->get_expr_type () == T_ID || temp_node->get_expr_type () != T_UMINUS) | temp_val.size() != 1) {
i++;
continue;
}
string replace_temp = temp_val[0];
bool replaced = false;
for (vector<stmtnode*>::reverse_iterator j=next(i); j!=stmts.rend(); j++) {
expr_node *j_lhs = (*j)->get_lhs_expr ();
// Check that the stmt type is assignment
vector<string> t_lhs;
j_lhs->stringify_accesses (t_lhs);
bool lhs_found = false;
for (vector<string>::iterator lt=t_lhs.begin(); lt!=t_lhs.end(); lt++) {
if (replace_temp.compare (*lt) == 0)
lhs_found = true;
}
if (lhs_found) {
stmtnode *new_stmt = new stmtnode (distributive_stmt_op ((*i)->get_op_type(), (*j)->get_op_type()), lhs, new binary_node (binop, coef_node, (*j)->get_rhs_expr(), vsize, gen_fma, print_intrinsics), (*j)->get_stmt_num(), (*j)->get_orig_stmt_num(), vsize, gen_fma, print_intrinsics);
if (DEBUG) {
stringstream rhs_out;
rhs_out << "Distribution: Replacing ";
(*j)->print_statement (rhs_out, vsize);
rhs_out << " with ";
new_stmt->print_statement(rhs_out, vsize);
cout << rhs_out.str() << "\n";
}
*j = new_stmt;
replaced = true;
}
}
if (replaced) {
// Replace the initialization
if (is_asgn) {
for (vector<stmtnode*>::iterator kt=initial_assignments.begin(); kt!=initial_assignments.end(); kt++) {
if ((*kt)->get_lhs_expr () == temp_node) {
(*kt)->set_lhs_expr (lhs);
}
}
}
i = vector<stmtnode*>::reverse_iterator (stmts.erase (i.base() - 1));
}
else i++;
}
stmt_list->set_stmt_list (stmts);
total_stmts = (stmt_list->get_stmt_list()).size ();
}
void funcdefn::optimize_available_expressions (void) {
vector<stmtnode*> stmts = stmt_list->get_stmt_list ();
vector<stmtnode*> init = initial_assignments;
// The first field in tuple is the label for lhs, the second is the labels for rhs, and the third is the rhs expression
map<stmtnode*, tuple<vector<string>, vector<string>, string>> stmt_labels;
for (vector<stmtnode*>::const_iterator i=stmts.begin(); i!=stmts.end(); i++) {
// Compute the labels for this one
expr_node *lhs = (*i)->get_lhs_expr ();
expr_node *rhs = (*i)->get_rhs_expr ();
bool is_asgn = (*i)->get_op_type () == ST_EQ;
if (!is_asgn) {
for (vector<stmtnode*>::iterator it=init.begin(); it!=init.end();) {
if ((*it)->get_lhs_expr () == lhs) {
is_asgn = true;
it = init.erase (it);
break;
}
else ++it;
}
}
vector<string> lhs_labels;
vector<string> rhs_labels;
string rhs_expr;
lhs->stringify_accesses (lhs_labels);
rhs->stringify_accesses (rhs_labels, rhs_expr);
stmt_labels[*i] = make_tuple (lhs_labels, rhs_labels, rhs_expr);
}
// Now find available expression starting from top going down
map<string, string> replacement_map;
map<int, string> av_optimized;
int av_count = 0;
for (vector<stmtnode*>::const_iterator i=stmts.begin(); i!=stmts.end(); i++) {
tuple<vector<string>, vector<string>, string> src_tuple = stmt_labels[*i];
string src_expr_label = get<2>(src_tuple);
if (src_expr_label.compare ("") == 0) continue;
vector<string> src_lhs_labels = get<0>(src_tuple);
vector<string> src_rhs_labels = get<1>(src_tuple);
if (src_rhs_labels.size () <= 1) continue;
bool expression_killed = false;
// Make sure that lhs does not write any rhs label
for (vector<string>::iterator it=src_lhs_labels.begin(); it!=src_lhs_labels.end(); it++) {
for (vector<string>::iterator jt=src_rhs_labels.begin(); jt!=src_rhs_labels.end(); jt++) {
if ((*it).compare (*jt) == 0) {
expression_killed = true;
break;
}
}
}
if (expression_killed) continue;
for (vector<stmtnode*>::const_iterator j=i+1; j!=stmts.end(); j++) {
tuple<vector<string>, vector<string>, string> dest_tuple = stmt_labels[*j];
string dest_expr_label = get<2>(dest_tuple);
vector<string> dest_lhs_labels = get<0>(dest_tuple);
vector<string> dest_rhs_labels = get<1>(dest_tuple);
// First check if the destinations's rhs is same as source's rhs. If so, perform available expression analysis
if (dest_expr_label.compare (src_expr_label) == 0) {
if (replacement_map.find (src_expr_label) == replacement_map.end ()) {
string temp = "_v_" + to_string (av_count++) + "_";
replacement_map[src_expr_label] = temp;
av_optimized[(*i)->get_stmt_num()] = temp;
}
string replacement = replacement_map[src_expr_label];
expr_node *temp = new id_node (replacement, gdata_type, vsize, gen_fma, print_intrinsics);
(*j)->set_rhs_expr (temp);
// Remove the expr_label of dest
get<2>(dest_tuple) = "";
}
bool expression_killed = false;
for (vector<string>::iterator it=dest_lhs_labels.begin(); it!=dest_lhs_labels.end(); it++) {
for (vector<string>::iterator jt=src_rhs_labels.begin(); jt!=src_rhs_labels.end(); jt++) {
if ((*it).compare (*jt) == 0) {
expression_killed = true;
break;
}
}
}
if (expression_killed) {
// Remove expression to label mapping for source stmt
if (replacement_map.find (src_expr_label) != replacement_map.end ())
replacement_map.erase (src_expr_label);
break;
}
}
}
// Insert placeholders for optimization
if (av_optimized.size () > 0) {
stmtlist *new_stmts = new stmtlist ();
int id = 0, stmt_num = 0;
for (vector<stmtnode*>::const_iterator it=stmts.begin(); it!=stmts.end(); it++,stmt_num++) {
// Find if we need to push in an optimization condition
int st_no = (*it)->get_stmt_num ();
if (av_optimized.find (st_no) != av_optimized.end ()) {
string replacement = av_optimized[st_no];
expr_node *temp = new id_node (replacement, gdata_type, vsize, gen_fma, print_intrinsics);
expr_node *lhs_expr = (*it)->get_lhs_expr ();
expr_node *rhs_expr = (*it)->get_rhs_expr ();
temp->set_type (lhs_expr->get_type ());
(*it)->set_rhs_expr (temp);
temp_vars.push_back (temp);
new_stmts->push_stmt (new stmtnode (ST_EQ, temp, rhs_expr, stmt_num++, (*it)->get_orig_stmt_num (), vsize, gen_fma, print_intrinsics));
}
(*it)->set_stmt_num (stmt_num);
new_stmts->push_stmt (*it);
}
stmt_list = new_stmts;
total_stmts = (stmt_list->get_stmt_list()).size ();
}
}
/* A simple copy propagation pass for reducing temporaries
1. Convert a = b; c += a to c += b;
2. Convert a = 1; a*=b; c+=a to c+=b;
a and b, both have to be a label at present */
void funcdefn::copy_propagation (vector<tuple<expr_node*,expr_node*,STMT_OP>> &tstmt) {
vector<stmtnode*> init = initial_assignments;
for (vector<tuple<expr_node*,expr_node*,STMT_OP>>::iterator i=tstmt.begin(); i!=tstmt.end();) {
if (get<0>(*i)->get_expr_type () == T_ID && get<1>(*i)->get_expr_type () == T_ID) {
bool init_found = false;
vector<stmtnode*>::iterator it = initial_assignments.begin();
for (vector<stmtnode*>::iterator j=init.begin(); j!=init.end(); j++,it++) {
if ((*j)->get_lhs_expr () == get<0>(*i)) {
init_found = true;
j = init.erase (j);
break;
}
}
if (get<2>(*i) == ST_EQ || init_found) {
bool replaced_uses = false;
for (vector<tuple<expr_node*,expr_node*,STMT_OP>>::iterator j=i+1; j!=tstmt.end(); j++) {
// Change the RHS
if (get<1>(*j) == get<0>(*i)) {
get<1>(*j) = get<1>(*i);
replaced_uses = true;
}
// If the node is rewritten, then exit
if (get<0>(*j) == get<0>(*i)) {
if (init_found && get<2>(*j) != ST_EQ) {
get<0>(*j) = get<1>(*i);
replaced_uses = true;
}
else break;
}
}
if (replaced_uses) {
if (init_found) initial_assignments.erase (it);
i = tstmt.erase (i);
}
else ++i;
}
else ++i;
}
else ++i;
}
}
void funcdefn::decompose_statements (DATA_TYPE gdata_type) {
stmtlist *new_stmts = new stmtlist ();
vector<stmtnode*> stmts = stmt_list->get_stmt_list ();
int id = 0, stmt_num = 0, orig_stmt_num = 0;
int s_count = 0;
for (vector<stmtnode*>::const_iterator i=stmts.begin(); i!=stmts.end(); i++, orig_stmt_num++) {
vector<tuple<expr_node*, expr_node*, STMT_OP>> tstmt;
vector<tuple<expr_node*, expr_node*, STMT_OP>> init;
expr_node *lhs = (*i)->get_lhs_expr ();
expr_node *rhs = (*i)->get_rhs_expr ();
STMT_OP stmt_type = (*i)->get_op_type ();
bool local_assigned = false;
bool global_assigned = false;
bool flip = false;
if (stmt_type == ST_EQ)
rhs->decompose_node (tstmt, init, temp_vars, lhs, ST_EQ, id, gdata_type, local_assigned, global_assigned, flip);
else {
if (rhs->simple_nondecomposable_expr ())
tstmt.push_back (make_tuple (lhs, rhs, stmt_type));
else {
string name_t = "_t_" + to_string (id++) + "_";
expr_node *temp = new id_node (name_t, gdata_type, vsize, gen_fma, print_intrinsics);
rhs->decompose_node (tstmt, init, temp_vars, temp, ST_EQ, id, gdata_type, local_assigned, global_assigned, flip);
// Now infer types
lhs->set_type (gdata_type);
tstmt.push_back (make_tuple (lhs, temp, stmt_type));
temp_vars.push_back (temp);
}
}
for (vector<tuple<expr_node*,expr_node*,STMT_OP>>::const_iterator j=init.begin(); j!=init.end(); j++) {
stmtnode *node = new stmtnode (get<2>(*j), get<0>(*j), get<1>(*j), vsize, gen_fma, print_intrinsics);
initial_assignments.push_back (node);
}
// Run a pass of copy propagation
if (ASSOC_MULT) copy_propagation (tstmt);
int local_stmt_cnt = 0;
for (vector<tuple<expr_node*,expr_node*,STMT_OP>>::const_iterator j=tstmt.begin(); j!=tstmt.end(); j++,stmt_num++,local_stmt_cnt++) {
stmtnode *node = new stmtnode (get<2>(*j), get<0>(*j), get<1>(*j), stmt_num, orig_stmt_num, vsize, gen_fma, print_intrinsics);
new_stmts->push_stmt (node);
}
clusterwise_stmt_count[orig_stmt_num] = local_stmt_cnt;
clusterwise_stmts_executed[orig_stmt_num] = 0;
}
stmt_list = new_stmts;
total_stmts = (stmt_list->get_stmt_list()).size ();
total_orig_stmts = orig_stmt_num;
// Set the initial priority
for (int i=0; i<total_orig_stmts; i++) {
initial_priority[i] = total_orig_stmts-1-i;
}
}
//// Only preserves the last writes
//void funcdefn::remove_redundant_stmts (void) {
// map<string, stmtnode*> write_labels;
// vector<stmtnode*> redundant_stmts;
// vector<stmtnode*> stmts = stmt_list->get_stmt_list ();
// for (vector<stmtnode*>::const_iterator i=stmts.begin(); i!=stmts.end(); i++) {
// // Compute the labels for this one
// expr_node *lhs = (*i)->get_lhs_expr ();
// if (lhs->get_expr_type () == T_SHIFTVEC && (*i)->get_op_type () == ST_EQ) {
// vector<string> lhs_labels;
// lassign_map[lhs->get_name()] = 0;
// lhs->stringify_accesses (lhs_labels);
// for (vector<string>::iterator j=lhs_labels.begin(); j!=lhs_labels.end(); j++) {
// if (write_labels.find (*j) == write_labels.end ())
// write_labels[*j] = *i;
// else {
// redundant_stmts.push_back (write_labels[*j]);
// write_labels[*j] = *i;
// }
// }
// }
// }
// if (redundant_stmts.size () != 0) {
// stmtlist *new_stmts = new stmtlist ();
// for (vector<stmtnode*>::const_iterator i=stmts.begin(); i!=stmts.end(); i++) {
// if (find (redundant_stmts.begin(), redundant_stmts.end (), *i) == redundant_stmts.end())
// new_stmts->push_stmt (*i);
// }
// stmt_list = new_stmts;
// redundant_stmts.clear ();
// }
// write_labels.clear ();
//}
void funcdefn::unroll_stmts (map<string, int> unroll_decls) {
for (map<string, int>::const_iterator u=unroll_decls.begin(); u!=unroll_decls.end(); ++u) {
string id = u->first;
map<string, int> scalar_count;
stmtlist *new_stmts = new stmtlist ();
vector<stmtnode*> stmts = stmt_list->get_stmt_list ();
for (int val=1; val<u->second; val++) {
for (vector<stmtnode*>::const_iterator i=stmts.begin(); i!=stmts.end(); i++) {
vector<tuple<expr_node*, expr_node*, STMT_OP>> tstmt;
vector<tuple<expr_node*, expr_node*, STMT_OP>> init;
expr_node *lhs = (*i)->get_lhs_expr ();
expr_node *rhs = (*i)->get_rhs_expr ();
STMT_OP stmt_type = (*i)->get_op_type ();
expr_node *unroll_lhs = lhs->unroll_expr (id, val, coefficients, scalar_count, true);
expr_node *unroll_rhs = rhs->unroll_expr (id, val, coefficients, scalar_count, false);
new_stmts->push_stmt (new stmtnode (stmt_type, unroll_lhs, unroll_rhs, vsize, gen_fma, print_intrinsics));
}
}
stmt_list->push_stmt (new_stmts->get_stmt_list ());
}
}
void funcdefn::print_stmt_label_map (string name) {
// First print the stmt -> labels map
cout << "\nFor function " << name << ", stmt -> label map:\n";
for (map<int, boost::dynamic_bitset<>>::iterator it=labels_per_stmt.begin(); it!=labels_per_stmt.end(); it++) {
cout << "stmt " << it->first << " -> ";
print_bitset (label_bitset_index, it->second, label_count);
}
// Now print the labels -> stmt map
cout << "\nFor function " << name << ", labels -> stmt map: ";
for (map<string, vector<int>>::iterator it=stmts_per_label.begin(); it!=stmts_per_label.end (); it++) {
cout << endl << it->first << " -> ( ";
for (vector<int>::iterator jt=it->second.begin(); jt!=it->second.end(); jt++)
cout << *jt << " ";
cout << " ) ";
}
cout << endl;
}
// Compute the initial schedulable stmts list
void funcdefn::compute_schedulable_stmts (void) {
vector<stmtnode*> stmts = stmt_list->get_stmt_list ();
for (vector<stmtnode*>::const_iterator i=stmts.begin(); i!=stmts.end(); i++) {
if (substmt_dependence_graph.find (*i) == substmt_dependence_graph.end ())
schedulable_stmts.push_back (*i);
}
}
stmtnode *funcdefn::split_accumulations (stmtnode *stmt) {
if (stmt->get_op_type () == ST_EQ)
return stmt;
// In case of an accumulation node, find the current counter
stmtnode *new_stmt = new stmtnode (stmt->get_op_type (), (stmt->get_lhs_expr())->deep_copy(), (stmt->get_rhs_expr())->deep_copy(), vsize, gen_fma, print_intrinsics);
new_stmt->set_lhs_labels (stmt->get_lhs_labels ());
new_stmt->set_rhs_labels (stmt->get_rhs_labels ());
vector<string> &l_labels = new_stmt->get_lhs_labels ();
bool split = false;
for (vector<string>::iterator it=l_labels.begin(); it!=l_labels.end(); it++) {
if (acc_vars.find (*it) == acc_vars.end ())
acc_vars[*it] = make_tuple (0, 0);
bool conflicts = true;
int free_idx = 0;
for (int i=0; i<=get<0>(acc_vars[*it]); i++) {
tuple<string,int> index_tuple = make_tuple (*it, i);
if (find (interlock_lhs.begin (), interlock_lhs.end (), index_tuple) == interlock_lhs.end ()) {
conflicts = false;
free_idx = i;
break;
}
}
tuple<int,int> &index_tuple = acc_vars[*it];
if (conflicts) {
free_idx = (get<1>(index_tuple) + 1) % acc_size;
if (free_idx > get<0>(index_tuple) && new_stmt->get_op_type () != ST_EQ)
initial_assignments.push_back (new stmtnode (ST_EQ, new_stmt->get_lhs_expr(), new datatype_node<int> (get_init_val (new_stmt->get_op_type()), INT), vsize, gen_fma, print_intrinsics));
}
get<0>(index_tuple) = max (get<0>(index_tuple), free_idx);
get<1>(index_tuple) = free_idx;
// Change the lhs label if free_idx is greater than 0
if (free_idx > 0) {
string new_label = *it, new_name = (new_stmt->get_lhs_expr())->get_name ();
if (new_label.substr(new_label.length()-1).compare ("_") == 0)
new_label += to_string (free_idx) + "_";
else new_label += "_" + to_string (free_idx) + "_";
if (new_name.substr(new_name.length()-1).compare ("_") == 0)
new_name += to_string (free_idx) + "_";
else new_name += "_" + to_string (free_idx) + "_";
if (new_stmt->get_lhs_expr()->get_expr_type () == T_SHIFTVEC) {
dynamic_cast<shiftvec_node*>(new_stmt->get_lhs_expr())->set_label (new_label);
}
if (new_stmt->get_lhs_expr()->get_expr_type () == T_ID) {
dynamic_cast<id_node*>(new_stmt->get_lhs_expr())->set_name (new_name);
dynamic_cast<id_node*>(new_stmt->get_lhs_expr())->set_label (new_label);
}
replace (l_labels.begin (), l_labels.end (), *it, new_label);
// Create a new_label -> register mapping
if (register_mapping.find (new_label) == register_mapping.end ()) {
if (register_pool.size () == 0) {
string s = "_r_" + to_string (reg_count++) + "_";
register_mapping[new_label] = s;
}
else {
register_mapping[new_label] = register_pool.front ();
register_pool.pop_front ();
}
}
split = true;
}
}
return split ? new_stmt : stmt;
}
void funcdefn::split_output_summation (stmtnode *stmt) {
vector<string> l_labels = stmt->get_lhs_labels ();
for (vector<string>::iterator it=l_labels.begin(); it!=l_labels.end(); it++) {
if (acc_vars.find (*it) != acc_vars.end ()) {
// Generate the summation
tuple<int,int> index_value = acc_vars[*it];
if (get<0>(index_value) > 0) {
for (int j=1; j<=get<0>(index_value); j++) {
string new_label = *it;
if (new_label.substr(new_label.length()-1).compare ("_") == 0)
new_label += to_string (j) + "_";
else new_label += "_" + to_string (j) + "_";
stmtnode *new_stmt = new stmtnode (ST_PLUSEQ, stmt->get_lhs_expr()->deep_copy(), new id_node (new_label, gdata_type, vsize, gen_fma, print_intrinsics), vsize, gen_fma, print_intrinsics);
new_stmt->set_lhs_labels (stmt->get_lhs_labels ());
vector<string> rhs_label;
rhs_label.push_back (new_label);
new_stmt->set_rhs_labels (rhs_label);
fireable_ilp_stmts.push_back (new_stmt);
register_pool.push_back (register_mapping[new_label]);
}
}
// Clear up the values
acc_vars[*it] = make_tuple (0,0);
}
}
}
/* For all the rhs nodes, generate the summation of all copies till now */
void funcdefn::split_input_summation (stmtnode *stmt) {
vector<string> r_labels = stmt->get_rhs_labels ();
for (vector<string>::iterator it=r_labels.begin(); it!=r_labels.end(); it++) {
if (acc_vars.find (*it) != acc_vars.end ()) {
// Generate the summation
tuple<int,int> index_value = acc_vars[*it];
if (get<0>(index_value) > 0) {
expr_node *lhs = new id_node (*it, gdata_type, vsize, gen_fma, print_intrinsics);
for (int j=1; j<=get<0>(index_value); j++) {
string new_label = *it;