1 // Copyright (C) 2009 Free Software Foundation, Inc.
2 // Contributed by Jan Sjodin <jan.sjodin@amd.com>.
4 // This file is part of the Polyhedral Compilation Package Library (libpcp).
6 // Libpcp is free software; you can redistribute it and/or modify it
7 // under the terms of the GNU Lesser General Public License as published by
8 // the Free Software Foundation; either version 2.1 of the License, or
9 // (at your option) any later version.
11 // Libpcp is distributed in the hope that it will be useful, but WITHOUT ANY
12 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
16 // You should have received a copy of the GNU Lesser General Public License
17 // along with libpcp; see the file COPYING.LIB. If not, write to the
18 // Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19 // MA 02110-1301, USA.
21 // As a special exception, if you link this library with other files, some
22 // of which are compiled with GCC, to produce an executable, this library
23 // does not by itself cause the resulting executable to be covered by the
24 // GNU General Public License. This exception does not however invalidate
25 // any other reasons why the executable file might be covered by the GNU
26 // General Public License.
28 #include "pcp_cloog_gateway.h"
29 #include "cloog/cloog.h"
35 PcpCloogGateway::buildCloogProgram(PcpPolyScop
* polyScop
)
38 int max_nb_loops
= 0; //scop_max_loop_depth (scop);
40 CloogLoop
*loop_list
= NULL
;
41 CloogBlockList
*block_list
= NULL
;
42 CloogDomainList
*scattering
= NULL
;
43 int nbs
= 2 * max_nb_loops
+ 1;
44 int *scaldims
= (int *) malloc (nbs
* (sizeof (int)));
46 build_scop_context (polyScop
, prog
);
47 nbs
= unify_scattering_dimensions (scop
);
48 cloog_program_set_nb_scattdims (prog
, nbs
);
49 initialize_cloog_names (scop
, prog
);
51 for (i
= 0; VEC_iterate (poly_bb_p
, SCOP_BBS (scop
), i
, pbb
); i
++)
53 /* Build new block. */
54 CloogStatement
*stmt
= cloog_statement_alloc
55 (GBB_BB (PBB_BLACK_BOX (pbb
))->index
);
56 CloogBlock
*block
= cloog_block_alloc (stmt
, 0, NULL
,
59 cloog_statement_set_usr (stmt
, pbb
);
61 /* Build loop list. */
63 CloogLoop
*new_loop_list
= cloog_loop_malloc ();
64 cloog_loop_set_next (new_loop_list
, loop_list
);
67 new_Cloog_Domain_from_ppl_Pointset_Powerset (PBB_DOMAIN (pbb
)));
68 cloog_loop_set_block (new_loop_list
, block
);
69 loop_list
= new_loop_list
;
72 /* Build block list. */
74 CloogBlockList
*new_block_list
= cloog_block_list_malloc ();
76 cloog_block_list_set_next (new_block_list
, block_list
);
77 cloog_block_list_set_block (new_block_list
, block
);
78 block_list
= new_block_list
;
81 /* Build scattering list. */
83 /* XXX: Replace with cloog_domain_list_alloc(), when available. */
84 CloogDomainList
*new_scattering
85 = (CloogDomainList
*) xmalloc (sizeof (CloogDomainList
));
86 ppl_Polyhedron_t scat
;
89 scat
= PBB_TRANSFORMED_SCATTERING (pbb
);
90 dom
= new_Cloog_Domain_from_ppl_Polyhedron (scat
);
92 cloog_set_next_domain (new_scattering
, scattering
);
93 cloog_set_domain (new_scattering
, dom
);
94 scattering
= new_scattering
;
98 cloog_program_set_loop (prog
, loop_list
);
99 cloog_program_set_blocklist (prog
, block_list
);
101 for (i
= 0; i
< nbs
; i
++)
104 cloog_program_set_scaldims (prog
, scaldims
);
106 /* Extract scalar dimensions to simplify the code generation problem. */
107 cloog_program_extract_scalars (prog
, scattering
);
109 /* Apply scattering. */
110 cloog_program_scatter (prog
, scattering
);
111 free_scattering (scattering
);
113 /* Iterators corresponding to scalar dimensions have to be extracted. */
114 cloog_names_scalarize (cloog_program_names (prog
), nbs
,
115 cloog_program_scaldims (prog
));
117 /* Free blocklist. */
119 CloogBlockList
*next
= cloog_program_blocklist (prog
);
123 CloogBlockList
*toDelete
= next
;
124 next
= cloog_block_list_next (next
);
125 cloog_block_list_set_next (toDelete
, NULL
);
126 cloog_block_list_set_block (toDelete
, NULL
);
127 cloog_block_list_free (toDelete
);
129 cloog_program_set_blocklist (prog
, NULL
);