PIPS
transformation_test.c
Go to the documentation of this file.
1 /*
2 
3  $Id: transformation_test.c 23065 2016-03-02 09:05:50Z coelho $
4 
5  Copyright 1989-2016 MINES ParisTech
6 
7  This file is part of PIPS.
8 
9  PIPS is free software: you can redistribute it and/or modify it
10  under the terms of the GNU General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  any later version.
13 
14  PIPS is distributed in the hope that it will be useful, but WITHOUT ANY
15  WARRANTY; without even the implied warranty of MERCHANTABILITY or
16  FITNESS FOR A PARTICULAR PURPOSE.
17 
18  See the GNU General Public License for more details.
19 
20  You should have received a copy of the GNU General Public License
21  along with PIPS. If not, see <http://www.gnu.org/licenses/>.
22 
23 */
24 
25 // do not compile unless required
26 #include "phases.h"
27 #ifdef BUILDER_TRANSFORMATION_TEST
28 
29 #ifdef HAVE_CONFIG_H
30  #include "pips_config.h"
31 #endif
32 
33 #include <stdio.h>
34 
35 #include "genC.h"
36 #include "linear.h"
37 
38 #include "misc.h"
39 #include "pipsdbm.h"
40 
41 #include "ri.h"
42 #include "ri-util.h"
43 
44 #include "control.h" // module_reorder
45 
46 /* blindly distribute intruction l if it is a loop.
47  */
48 static void blind_loop_distribute(instruction l)
49 {
50  if(instruction_loop_p(l))
51  {
53  flatten_block_if_necessary(b); /* avoid sequences of sequences. */
54 
56  {
57  list /* of statements */ lls = NIL, ls = instruction_block(b);
58 
59  loop_body(instruction_loop(l)) = statement_undefined; /* unlink body */
60 
61  MAP(STATEMENT, s, {
63  loop_body(instruction_loop(nli)) = s;
64  lls = gen_nconc(lls,
66  }, ls);
67 
68  free_loop(instruction_loop(l)); /* drop old loop. */
69  instruction_tag(l) = is_instruction_sequence; /* new sequence */
71  }
72  }
73 }
74 
75 /* distribute any loop in module mod_name.
76  implemented top-down. could be done bottom-up.
77  */
78 static bool blind_loop_distribution(const string mod_name)
79 {
80  // get code from dbm.
81  statement mod_stmt = (statement)
82  db_get_memory_resource(DBR_CODE, mod_name, true);
83 
84  debug_on("BLIND_LOOP_DISTRIBUTION_LEVEL");
85 
86  pips_debug(1, "begin for %s\n", mod_name);
87  pips_assert("statement is consistent", statement_consistent_p(mod_stmt));
88 
89  /* BOTTOM-UP. could be implemented TOP-DOWN. */
90  gen_recurse(mod_stmt,
91  instruction_domain, gen_true, blind_loop_distribute);
92 
93  /* Reorder the module because new statements have been generated. */
94  module_reorder(mod_stmt);
95 
96  pips_assert("statement is consistent", statement_consistent_p(mod_stmt));
97  pips_debug(1, "end for %s\n", mod_name);
98 
99  debug_off();
100 
101  /* return code to DBM. */
102  DB_PUT_MEMORY_RESOURCE(DBR_CODE, mod_name, mod_stmt);
103  return true; /* everything was fine. */
104 }
105 
106 /* apply a transformation on mod_name.
107  called automatically by pipsmake.
108  */
109 bool transformation_test(const string mod_name)
110 {
111  return blind_loop_distribution(mod_name);
112 }
113 
114 #endif // BUILDER_TRANSFORMATION_TEST
instruction copy_instruction(instruction p)
INSTRUCTION.
Definition: ri.c:1115
bool statement_consistent_p(statement p)
Definition: ri.c:2195
sequence make_sequence(list a)
Definition: ri.c:2125
void free_loop(loop p)
Definition: ri.c:1268
struct _newgen_struct_statement_ * statement
Definition: cloning.h:21
#define gen_recurse(start, domain_number, flt, rwt)
Definition: genC.h:283
statement instruction_to_statement(instruction)
Build a statement from a give instruction.
Definition: statement.c:597
bool gen_true(__attribute__((unused)) gen_chunk *unused)
Return true and ignore the argument.
Definition: genClib.c:2780
#define NIL
The empty list (nil in Lisp)
Definition: newgen_list.h:47
size_t gen_length(const list l)
Definition: list.c:150
#define CONS(_t_, _i_, _l_)
List element cell constructor (insert an element at the beginning of a list)
Definition: newgen_list.h:150
list gen_nconc(list cp1, list cp2)
physically concatenates CP1 and CP2 but do not duplicates the elements
Definition: list.c:344
#define MAP(_map_CASTER, _map_item, _map_code, _map_list)
Apply/map an instruction block on all the elements of a list (old fashioned)
Definition: newgen_list.h:226
string db_get_memory_resource(const char *rname, const char *oname, bool pure)
Return the pointer to the resource, whatever it is.
Definition: database.c:755
#define DB_PUT_MEMORY_RESOURCE(res_name, own_name, res_val)
conform to old interface.
Definition: pipsdbm-local.h:66
void flatten_block_if_necessary(instruction i)
Flatten an instruction block if necessary.
Definition: instruction.c:259
#define debug_on(env)
Definition: misc-local.h:157
#define pips_debug
these macros use the GNU extensions that allow variadic macros, including with an empty list.
Definition: misc-local.h:145
#define pips_assert(what, predicate)
common macros, two flavors depending on NDEBUG
Definition: misc-local.h:172
#define debug_off()
Definition: misc-local.h:160
bool module_reorder(statement body)
Reorder a module and recompute order to statement if any.
Definition: reorder.c:244
#define instruction_block_p(i)
#define instruction_block(i)
#define loop_body(x)
Definition: ri.h:1644
#define instruction_loop_p(x)
Definition: ri.h:1518
#define instruction_loop(x)
Definition: ri.h:1520
#define instruction_domain
newgen_functional_domain_defined
Definition: ri.h:202
@ is_instruction_sequence
Definition: ri.h:1469
#define instruction_tag(x)
Definition: ri.h:1511
#define instruction_sequence(x)
Definition: ri.h:1514
#define statement_instruction(x)
Definition: ri.h:2458
#define statement_undefined
Definition: ri.h:2419
#define STATEMENT(x)
STATEMENT.
Definition: ri.h:2413
The structure used to build lists in NewGen.
Definition: newgen_list.h:41
bool transformation_test(const string)
transformation_test.c