forked from illumos/gcc
/
graphite.c
6193 lines (4962 loc) · 161 KB
/
graphite.c
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
/* Gimple Represented as Polyhedra.
Copyright (C) 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
Contributed by Sebastian Pop <sebastian.pop@inria.fr>.
This file is part of GCC.
GCC is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
GCC is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GCC; see the file COPYING3. If not see
<http://www.gnu.org/licenses/>. */
/* This pass converts GIMPLE to GRAPHITE, performs some loop
transformations and then converts the resulting representation back
to GIMPLE.
An early description of this pass can be found in the GCC Summit'06
paper "GRAPHITE: Polyhedral Analyses and Optimizations for GCC".
The wiki page http://gcc.gnu.org/wiki/Graphite contains pointers to
the related work.
One important document to read is CLooG's internal manual:
http://repo.or.cz/w/cloog-ppl.git?a=blob_plain;f=doc/cloog.texi;hb=HEAD
that describes the data structure of loops used in this file, and
the functions that are used for transforming the code. */
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "tm.h"
#include "ggc.h"
#include "tree.h"
#include "rtl.h"
#include "basic-block.h"
#include "diagnostic.h"
#include "tree-flow.h"
#include "toplev.h"
#include "tree-dump.h"
#include "timevar.h"
#include "cfgloop.h"
#include "tree-chrec.h"
#include "tree-data-ref.h"
#include "tree-scalar-evolution.h"
#include "tree-pass.h"
#include "domwalk.h"
#include "value-prof.h"
#include "pointer-set.h"
#include "gimple.h"
#ifdef HAVE_cloog
#include "cloog/cloog.h"
#include "graphite.h"
static VEC (scop_p, heap) *current_scops;
/* Converts a GMP constant V to a tree and returns it. */
static tree
gmp_cst_to_tree (tree type, Value v)
{
return build_int_cst (type, value_get_si (v));
}
/* Returns true when BB is in REGION. */
static bool
bb_in_sese_p (basic_block bb, sese region)
{
return pointer_set_contains (SESE_REGION_BBS (region), bb);
}
/* Returns true when LOOP is in the SESE region R. */
static inline bool
loop_in_sese_p (struct loop *loop, sese r)
{
return (bb_in_sese_p (loop->header, r)
&& bb_in_sese_p (loop->latch, r));
}
/* For a USE in BB, if BB is outside REGION, mark the USE in the
SESE_LIVEIN and SESE_LIVEOUT sets. */
static void
sese_build_livein_liveouts_use (sese region, basic_block bb, tree use)
{
unsigned ver;
basic_block def_bb;
if (TREE_CODE (use) != SSA_NAME)
return;
ver = SSA_NAME_VERSION (use);
def_bb = gimple_bb (SSA_NAME_DEF_STMT (use));
if (!def_bb
|| !bb_in_sese_p (def_bb, region)
|| bb_in_sese_p (bb, region))
return;
if (!SESE_LIVEIN_VER (region, ver))
SESE_LIVEIN_VER (region, ver) = BITMAP_ALLOC (NULL);
bitmap_set_bit (SESE_LIVEIN_VER (region, ver), bb->index);
bitmap_set_bit (SESE_LIVEOUT (region), ver);
}
/* Marks for rewrite all the SSA_NAMES defined in REGION and that are
used in BB that is outside of the REGION. */
static void
sese_build_livein_liveouts_bb (sese region, basic_block bb)
{
gimple_stmt_iterator bsi;
edge e;
edge_iterator ei;
ssa_op_iter iter;
tree var;
FOR_EACH_EDGE (e, ei, bb->succs)
for (bsi = gsi_start_phis (e->dest); !gsi_end_p (bsi); gsi_next (&bsi))
sese_build_livein_liveouts_use (region, bb,
PHI_ARG_DEF_FROM_EDGE (gsi_stmt (bsi), e));
for (bsi = gsi_start_bb (bb); !gsi_end_p (bsi); gsi_next (&bsi))
FOR_EACH_SSA_TREE_OPERAND (var, gsi_stmt (bsi), iter, SSA_OP_ALL_USES)
sese_build_livein_liveouts_use (region, bb, var);
}
/* Build the SESE_LIVEIN and SESE_LIVEOUT for REGION. */
void
sese_build_livein_liveouts (sese region)
{
basic_block bb;
SESE_LIVEOUT (region) = BITMAP_ALLOC (NULL);
SESE_NUM_VER (region) = num_ssa_names;
SESE_LIVEIN (region) = XCNEWVEC (bitmap, SESE_NUM_VER (region));
FOR_EACH_BB (bb)
sese_build_livein_liveouts_bb (region, bb);
}
/* Register basic blocks belonging to a region in a pointer set. */
static void
register_bb_in_sese (basic_block entry_bb, basic_block exit_bb, sese region)
{
edge_iterator ei;
edge e;
basic_block bb = entry_bb;
FOR_EACH_EDGE (e, ei, bb->succs)
{
if (!pointer_set_contains (SESE_REGION_BBS (region), e->dest) &&
e->dest->index != exit_bb->index)
{
pointer_set_insert (SESE_REGION_BBS (region), e->dest);
register_bb_in_sese (e->dest, exit_bb, region);
}
}
}
/* Builds a new SESE region from edges ENTRY and EXIT. */
sese
new_sese (edge entry, edge exit)
{
sese res = XNEW (struct sese);
SESE_ENTRY (res) = entry;
SESE_EXIT (res) = exit;
SESE_REGION_BBS (res) = pointer_set_create ();
register_bb_in_sese (entry->dest, exit->dest, res);
SESE_LIVEOUT (res) = NULL;
SESE_NUM_VER (res) = 0;
SESE_LIVEIN (res) = NULL;
return res;
}
/* Deletes REGION. */
void
free_sese (sese region)
{
int i;
for (i = 0; i < SESE_NUM_VER (region); i++)
BITMAP_FREE (SESE_LIVEIN_VER (region, i));
if (SESE_LIVEIN (region))
free (SESE_LIVEIN (region));
if (SESE_LIVEOUT (region))
BITMAP_FREE (SESE_LIVEOUT (region));
pointer_set_destroy (SESE_REGION_BBS (region));
XDELETE (region);
}
/* Debug the list of old induction variables for this SCOP. */
void
debug_oldivs (scop_p scop)
{
int i;
name_tree oldiv;
fprintf (stderr, "Old IVs:");
for (i = 0; VEC_iterate (name_tree, SCOP_OLDIVS (scop), i, oldiv); i++)
{
fprintf (stderr, "(");
print_generic_expr (stderr, oldiv->t, 0);
fprintf (stderr, ", %s, %d)\n", oldiv->name, oldiv->loop->num);
}
fprintf (stderr, "\n");
}
/* Debug the loops around basic block GB. */
void
debug_loop_vec (graphite_bb_p gb)
{
int i;
loop_p loop;
fprintf (stderr, "Loop Vec:");
for (i = 0; VEC_iterate (loop_p, GBB_LOOPS (gb), i, loop); i++)
fprintf (stderr, "%d: %d, ", i, loop ? loop->num : -1);
fprintf (stderr, "\n");
}
/* Returns true if stack ENTRY is a constant. */
static bool
iv_stack_entry_is_constant (iv_stack_entry *entry)
{
return entry->kind == iv_stack_entry_const;
}
/* Returns true if stack ENTRY is an induction variable. */
static bool
iv_stack_entry_is_iv (iv_stack_entry *entry)
{
return entry->kind == iv_stack_entry_iv;
}
/* Push (IV, NAME) on STACK. */
static void
loop_iv_stack_push_iv (loop_iv_stack stack, tree iv, const char *name)
{
iv_stack_entry *entry = XNEW (iv_stack_entry);
name_tree named_iv = XNEW (struct name_tree);
named_iv->t = iv;
named_iv->name = name;
entry->kind = iv_stack_entry_iv;
entry->data.iv = named_iv;
VEC_safe_push (iv_stack_entry_p, heap, *stack, entry);
}
/* Inserts a CONSTANT in STACK at INDEX. */
static void
loop_iv_stack_insert_constant (loop_iv_stack stack, int index,
tree constant)
{
iv_stack_entry *entry = XNEW (iv_stack_entry);
entry->kind = iv_stack_entry_const;
entry->data.constant = constant;
VEC_safe_insert (iv_stack_entry_p, heap, *stack, index, entry);
}
/* Pops and frees an element out of STACK. */
static void
loop_iv_stack_pop (loop_iv_stack stack)
{
iv_stack_entry_p entry = VEC_pop (iv_stack_entry_p, *stack);
free (entry->data.iv);
free (entry);
}
/* Get the IV at INDEX in STACK. */
static tree
loop_iv_stack_get_iv (loop_iv_stack stack, int index)
{
iv_stack_entry_p entry = VEC_index (iv_stack_entry_p, *stack, index);
iv_stack_entry_data data = entry->data;
return iv_stack_entry_is_iv (entry) ? data.iv->t : data.constant;
}
/* Get the IV from its NAME in STACK. */
static tree
loop_iv_stack_get_iv_from_name (loop_iv_stack stack, const char* name)
{
int i;
iv_stack_entry_p entry;
for (i = 0; VEC_iterate (iv_stack_entry_p, *stack, i, entry); i++)
{
name_tree iv = entry->data.iv;
if (!strcmp (name, iv->name))
return iv->t;
}
return NULL;
}
/* Prints on stderr the contents of STACK. */
void
debug_loop_iv_stack (loop_iv_stack stack)
{
int i;
iv_stack_entry_p entry;
bool first = true;
fprintf (stderr, "(");
for (i = 0; VEC_iterate (iv_stack_entry_p, *stack, i, entry); i++)
{
if (first)
first = false;
else
fprintf (stderr, " ");
if (iv_stack_entry_is_iv (entry))
{
name_tree iv = entry->data.iv;
fprintf (stderr, "%s:", iv->name);
print_generic_expr (stderr, iv->t, 0);
}
else
{
tree constant = entry->data.constant;
print_generic_expr (stderr, constant, 0);
fprintf (stderr, ":");
print_generic_expr (stderr, constant, 0);
}
}
fprintf (stderr, ")\n");
}
/* Frees STACK. */
static void
free_loop_iv_stack (loop_iv_stack stack)
{
int i;
iv_stack_entry_p entry;
for (i = 0; VEC_iterate (iv_stack_entry_p, *stack, i, entry); i++)
{
free (entry->data.iv);
free (entry);
}
VEC_free (iv_stack_entry_p, heap, *stack);
}
/* Structure containing the mapping between the CLooG's induction
variable and the type of the old induction variable. */
typedef struct ivtype_map_elt
{
tree type;
const char *cloog_iv;
} *ivtype_map_elt;
/* Print to stderr the element ELT. */
static void
debug_ivtype_elt (ivtype_map_elt elt)
{
fprintf (stderr, "(%s, ", elt->cloog_iv);
print_generic_expr (stderr, elt->type, 0);
fprintf (stderr, ")\n");
}
/* Helper function for debug_ivtype_map. */
static int
debug_ivtype_map_1 (void **slot, void *s ATTRIBUTE_UNUSED)
{
struct ivtype_map_elt *entry = (struct ivtype_map_elt *) *slot;
debug_ivtype_elt (entry);
return 1;
}
/* Print to stderr all the elements of MAP. */
void
debug_ivtype_map (htab_t map)
{
htab_traverse (map, debug_ivtype_map_1, NULL);
}
/* Constructs a new SCEV_INFO_STR structure for VAR and INSTANTIATED_BELOW. */
static inline ivtype_map_elt
new_ivtype_map_elt (const char *cloog_iv, tree type)
{
ivtype_map_elt res;
res = XNEW (struct ivtype_map_elt);
res->cloog_iv = cloog_iv;
res->type = type;
return res;
}
/* Computes a hash function for database element ELT. */
static hashval_t
ivtype_map_elt_info (const void *elt)
{
return htab_hash_pointer (((const struct ivtype_map_elt *) elt)->cloog_iv);
}
/* Compares database elements E1 and E2. */
static int
eq_ivtype_map_elts (const void *e1, const void *e2)
{
const struct ivtype_map_elt *elt1 = (const struct ivtype_map_elt *) e1;
const struct ivtype_map_elt *elt2 = (const struct ivtype_map_elt *) e2;
return (elt1->cloog_iv == elt2->cloog_iv);
}
/* Given a CLOOG_IV, returns the type that it should have in GCC land.
If the information is not available, i.e. in the case one of the
transforms created the loop, just return integer_type_node. */
static tree
gcc_type_for_cloog_iv (const char *cloog_iv, graphite_bb_p gbb)
{
struct ivtype_map_elt tmp;
PTR *slot;
tmp.cloog_iv = cloog_iv;
slot = htab_find_slot (GBB_CLOOG_IV_TYPES (gbb), &tmp, NO_INSERT);
if (slot && *slot)
return ((ivtype_map_elt) *slot)->type;
return integer_type_node;
}
/* Inserts constants derived from the USER_STMT argument list into the
STACK. This is needed to map old ivs to constants when loops have
been eliminated. */
static void
loop_iv_stack_patch_for_consts (loop_iv_stack stack,
struct clast_user_stmt *user_stmt)
{
struct clast_stmt *t;
int index = 0;
CloogStatement *cs = user_stmt->statement;
graphite_bb_p gbb = (graphite_bb_p) cloog_statement_usr (cs);
for (t = user_stmt->substitutions; t; t = t->next)
{
struct clast_expr *expr = (struct clast_expr *)
((struct clast_assignment *)t)->RHS;
struct clast_term *term = (struct clast_term *) expr;
/* FIXME: What should be done with expr_bin, expr_red? */
if (expr->type == expr_term
&& !term->var)
{
loop_p loop = gbb_loop_at_index (gbb, index);
tree oldiv = oldiv_for_loop (GBB_SCOP (gbb), loop);
tree type = oldiv ? TREE_TYPE (oldiv) : integer_type_node;
tree value = gmp_cst_to_tree (type, term->val);
loop_iv_stack_insert_constant (stack, index, value);
}
index = index + 1;
}
}
/* Removes all constants in the iv STACK. */
static void
loop_iv_stack_remove_constants (loop_iv_stack stack)
{
int i;
iv_stack_entry *entry;
for (i = 0; VEC_iterate (iv_stack_entry_p, *stack, i, entry);)
{
if (iv_stack_entry_is_constant (entry))
{
free (VEC_index (iv_stack_entry_p, *stack, i));
VEC_ordered_remove (iv_stack_entry_p, *stack, i);
}
else
i++;
}
}
/* Returns a new loop_to_cloog_loop_str structure. */
static inline struct loop_to_cloog_loop_str *
new_loop_to_cloog_loop_str (int loop_num,
int loop_position,
CloogLoop *cloog_loop)
{
struct loop_to_cloog_loop_str *result;
result = XNEW (struct loop_to_cloog_loop_str);
result->loop_num = loop_num;
result->cloog_loop = cloog_loop;
result->loop_position = loop_position;
return result;
}
/* Hash function for SCOP_LOOP2CLOOG_LOOP hash table. */
static hashval_t
hash_loop_to_cloog_loop (const void *elt)
{
return ((const struct loop_to_cloog_loop_str *) elt)->loop_num;
}
/* Equality function for SCOP_LOOP2CLOOG_LOOP hash table. */
static int
eq_loop_to_cloog_loop (const void *el1, const void *el2)
{
const struct loop_to_cloog_loop_str *elt1, *elt2;
elt1 = (const struct loop_to_cloog_loop_str *) el1;
elt2 = (const struct loop_to_cloog_loop_str *) el2;
return elt1->loop_num == elt2->loop_num;
}
/* Compares two graphite bbs and returns an integer less than, equal to, or
greater than zero if the first argument is considered to be respectively
less than, equal to, or greater than the second.
We compare using the lexicographic order of the static schedules. */
static int
gbb_compare (const void *p_1, const void *p_2)
{
const struct graphite_bb *const gbb_1
= *(const struct graphite_bb *const*) p_1;
const struct graphite_bb *const gbb_2
= *(const struct graphite_bb *const*) p_2;
return lambda_vector_compare (GBB_STATIC_SCHEDULE (gbb_1),
gbb_nb_loops (gbb_1) + 1,
GBB_STATIC_SCHEDULE (gbb_2),
gbb_nb_loops (gbb_2) + 1);
}
/* Sort graphite bbs in SCOP. */
static void
graphite_sort_gbbs (scop_p scop)
{
VEC (graphite_bb_p, heap) *bbs = SCOP_BBS (scop);
qsort (VEC_address (graphite_bb_p, bbs),
VEC_length (graphite_bb_p, bbs),
sizeof (graphite_bb_p), gbb_compare);
}
/* Dump conditions of a graphite basic block GBB on FILE. */
static void
dump_gbb_conditions (FILE *file, graphite_bb_p gbb)
{
int i;
gimple stmt;
VEC (gimple, heap) *conditions = GBB_CONDITIONS (gbb);
if (VEC_empty (gimple, conditions))
return;
fprintf (file, "\tbb %d\t: cond = {", GBB_BB (gbb)->index);
for (i = 0; VEC_iterate (gimple, conditions, i, stmt); i++)
print_gimple_stmt (file, stmt, 0, 0);
fprintf (file, "}\n");
}
/* Converts the graphite scheduling function into a cloog scattering
matrix. This scattering matrix is used to limit the possible cloog
output to valid programs in respect to the scheduling function.
SCATTERING_DIMENSIONS specifies the dimensionality of the scattering
matrix. CLooG 0.14.0 and previous versions require, that all scattering
functions of one CloogProgram have the same dimensionality, therefore we
allow to specify it. (Should be removed in future versions) */
static CloogMatrix *
schedule_to_scattering (graphite_bb_p gb, int scattering_dimensions)
{
int i;
scop_p scop = GBB_SCOP (gb);
int nb_iterators = gbb_nb_loops (gb);
/* The cloog scattering matrix consists of these colums:
1 col = Eq/Inq,
scattering_dimensions cols = Scattering dimensions,
nb_iterators cols = bb's iterators,
scop_nb_params cols = Parameters,
1 col = Constant 1.
Example:
scattering_dimensions = 5
max_nb_iterators = 2
nb_iterators = 1
scop_nb_params = 2
Schedule:
? i
4 5
Scattering Matrix:
s1 s2 s3 s4 s5 i p1 p2 1
1 0 0 0 0 0 0 0 -4 = 0
0 1 0 0 0 -1 0 0 0 = 0
0 0 1 0 0 0 0 0 -5 = 0 */
int nb_params = scop_nb_params (scop);
int nb_cols = 1 + scattering_dimensions + nb_iterators + nb_params + 1;
int col_const = nb_cols - 1;
int col_iter_offset = 1 + scattering_dimensions;
CloogMatrix *scat = cloog_matrix_alloc (scattering_dimensions, nb_cols);
gcc_assert (scattering_dimensions >= nb_iterators * 2 + 1);
/* Initialize the identity matrix. */
for (i = 0; i < scattering_dimensions; i++)
value_set_si (scat->p[i][i + 1], 1);
/* Textual order outside the first loop */
value_set_si (scat->p[0][col_const], -GBB_STATIC_SCHEDULE (gb)[0]);
/* For all surrounding loops. */
for (i = 0; i < nb_iterators; i++)
{
int schedule = GBB_STATIC_SCHEDULE (gb)[i + 1];
/* Iterations of this loop. */
value_set_si (scat->p[2 * i + 1][col_iter_offset + i], -1);
/* Textual order inside this loop. */
value_set_si (scat->p[2 * i + 2][col_const], -schedule);
}
return scat;
}
/* Print the schedules of GB to FILE with INDENT white spaces before.
VERBOSITY determines how verbose the code pretty printers are. */
void
print_graphite_bb (FILE *file, graphite_bb_p gb, int indent, int verbosity)
{
CloogMatrix *scattering;
int i;
loop_p loop;
fprintf (file, "\nGBB (\n");
print_loops_bb (file, GBB_BB (gb), indent+2, verbosity);
if (GBB_DOMAIN (gb))
{
fprintf (file, " (domain: \n");
cloog_matrix_print (file, GBB_DOMAIN (gb));
fprintf (file, " )\n");
}
if (GBB_STATIC_SCHEDULE (gb))
{
fprintf (file, " (static schedule: ");
print_lambda_vector (file, GBB_STATIC_SCHEDULE (gb),
gbb_nb_loops (gb) + 1);
fprintf (file, " )\n");
}
if (GBB_LOOPS (gb))
{
fprintf (file, " (contained loops: \n");
for (i = 0; VEC_iterate (loop_p, GBB_LOOPS (gb), i, loop); i++)
if (loop == NULL)
fprintf (file, " iterator %d => NULL \n", i);
else
fprintf (file, " iterator %d => loop %d \n", i,
loop->num);
fprintf (file, " )\n");
}
if (GBB_DATA_REFS (gb))
dump_data_references (file, GBB_DATA_REFS (gb));
if (GBB_CONDITIONS (gb))
{
fprintf (file, " (conditions: \n");
dump_gbb_conditions (file, gb);
fprintf (file, " )\n");
}
if (GBB_SCOP (gb)
&& GBB_STATIC_SCHEDULE (gb))
{
fprintf (file, " (scattering: \n");
scattering = schedule_to_scattering (gb, 2 * gbb_nb_loops (gb) + 1);
cloog_matrix_print (file, scattering);
cloog_matrix_free (scattering);
fprintf (file, " )\n");
}
fprintf (file, ")\n");
}
/* Print to STDERR the schedules of GB with VERBOSITY level. */
void
debug_gbb (graphite_bb_p gb, int verbosity)
{
print_graphite_bb (stderr, gb, 0, verbosity);
}
/* Print SCOP to FILE. VERBOSITY determines how verbose the pretty
printers are. */
static void
print_scop (FILE *file, scop_p scop, int verbosity)
{
if (scop == NULL)
return;
fprintf (file, "\nSCoP_%d_%d (\n",
SCOP_ENTRY (scop)->index, SCOP_EXIT (scop)->index);
fprintf (file, " (cloog: \n");
cloog_program_print (file, SCOP_PROG (scop));
fprintf (file, " )\n");
if (SCOP_BBS (scop))
{
graphite_bb_p gb;
int i;
for (i = 0; VEC_iterate (graphite_bb_p, SCOP_BBS (scop), i, gb); i++)
print_graphite_bb (file, gb, 0, verbosity);
}
fprintf (file, ")\n");
}
/* Print all the SCOPs to FILE. VERBOSITY determines how verbose the
code pretty printers are. */
static void
print_scops (FILE *file, int verbosity)
{
int i;
scop_p scop;
for (i = 0; VEC_iterate (scop_p, current_scops, i, scop); i++)
print_scop (file, scop, verbosity);
}
/* Debug SCOP. VERBOSITY determines how verbose the code pretty
printers are. */
void
debug_scop (scop_p scop, int verbosity)
{
print_scop (stderr, scop, verbosity);
}
/* Debug all SCOPs from CURRENT_SCOPS. VERBOSITY determines how
verbose the code pretty printers are. */
void
debug_scops (int verbosity)
{
print_scops (stderr, verbosity);
}
/* Pretty print to FILE the SCOP in DOT format. */
static void
dot_scop_1 (FILE *file, scop_p scop)
{
edge e;
edge_iterator ei;
basic_block bb;
basic_block entry = SCOP_ENTRY (scop);
basic_block exit = SCOP_EXIT (scop);
fprintf (file, "digraph SCoP_%d_%d {\n", entry->index,
exit->index);
FOR_ALL_BB (bb)
{
if (bb == entry)
fprintf (file, "%d [shape=triangle];\n", bb->index);
if (bb == exit)
fprintf (file, "%d [shape=box];\n", bb->index);
if (bb_in_sese_p (bb, SCOP_REGION (scop)))
fprintf (file, "%d [color=red];\n", bb->index);
FOR_EACH_EDGE (e, ei, bb->succs)
fprintf (file, "%d -> %d;\n", bb->index, e->dest->index);
}
fputs ("}\n\n", file);
}
/* Display SCOP using dotty. */
void
dot_scop (scop_p scop)
{
dot_scop_1 (stderr, scop);
}
/* Pretty print all SCoPs in DOT format and mark them with different colors.
If there are not enough colors, paint later SCoPs gray.
Special nodes:
- "*" after the node number: entry of a SCoP,
- "#" after the node number: exit of a SCoP,
- "()" entry or exit not part of SCoP. */
static void
dot_all_scops_1 (FILE *file)
{
basic_block bb;
edge e;
edge_iterator ei;
scop_p scop;
const char* color;
int i;
/* Disable debugging while printing graph. */
int tmp_dump_flags = dump_flags;
dump_flags = 0;
fprintf (file, "digraph all {\n");
FOR_ALL_BB (bb)
{
int part_of_scop = false;
/* Use HTML for every bb label. So we are able to print bbs
which are part of two different SCoPs, with two different
background colors. */
fprintf (file, "%d [label=<\n <TABLE BORDER=\"0\" CELLBORDER=\"1\" ",
bb->index);
fprintf (file, "CELLSPACING=\"0\">\n");
/* Select color for SCoP. */
for (i = 0; VEC_iterate (scop_p, current_scops, i, scop); i++)
if (bb_in_sese_p (bb, SCOP_REGION (scop))
|| (SCOP_EXIT (scop) == bb)
|| (SCOP_ENTRY (scop) == bb))
{
switch (i % 17)
{
case 0: /* red */
color = "#e41a1c";
break;
case 1: /* blue */
color = "#377eb8";
break;
case 2: /* green */
color = "#4daf4a";
break;
case 3: /* purple */
color = "#984ea3";
break;
case 4: /* orange */
color = "#ff7f00";
break;
case 5: /* yellow */
color = "#ffff33";
break;
case 6: /* brown */
color = "#a65628";
break;
case 7: /* rose */
color = "#f781bf";
break;
case 8:
color = "#8dd3c7";
break;
case 9:
color = "#ffffb3";
break;
case 10:
color = "#bebada";
break;
case 11:
color = "#fb8072";
break;
case 12:
color = "#80b1d3";
break;
case 13:
color = "#fdb462";
break;
case 14:
color = "#b3de69";
break;
case 15:
color = "#fccde5";
break;
case 16:
color = "#bc80bd";
break;
default: /* gray */
color = "#999999";
}
fprintf (file, " <TR><TD WIDTH=\"50\" BGCOLOR=\"%s\">", color);
if (!bb_in_sese_p (bb, SCOP_REGION (scop)))
fprintf (file, " (");
if (bb == SCOP_ENTRY (scop)
&& bb == SCOP_EXIT (scop))
fprintf (file, " %d*# ", bb->index);
else if (bb == SCOP_ENTRY (scop))
fprintf (file, " %d* ", bb->index);
else if (bb == SCOP_EXIT (scop))
fprintf (file, " %d# ", bb->index);
else
fprintf (file, " %d ", bb->index);
if (!bb_in_sese_p (bb, SCOP_REGION (scop)))
fprintf (file, ")");
fprintf (file, "</TD></TR>\n");
part_of_scop = true;
}
if (!part_of_scop)
{
fprintf (file, " <TR><TD WIDTH=\"50\" BGCOLOR=\"#ffffff\">");
fprintf (file, " %d </TD></TR>\n", bb->index);
}
fprintf (file, " </TABLE>>, shape=box, style=\"setlinewidth(0)\"]\n");
}
FOR_ALL_BB (bb)
{
FOR_EACH_EDGE (e, ei, bb->succs)
fprintf (file, "%d -> %d;\n", bb->index, e->dest->index);
}
fputs ("}\n\n", file);
/* Enable debugging again. */
dump_flags = tmp_dump_flags;