PIPS
fortran90.c
Go to the documentation of this file.
1 /*
2 
3  $Id: fortran90.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 #ifdef HAVE_CONFIG_H
25  #include "pips_config.h"
26 #endif
27 /* Prettyprint one FORTRAN 90 loop as an array expression.
28 
29  Pierre Jouvelot
30 
31  For one level only loop, with one assignment as body. Replaces
32  occurences of the index variable by ranges in expressions. Ranges are
33  prettyprinted as triplet when they occur as subscript expressions and
34  as vectors with implicit DO otherwise. If the replacement cannot occur,
35  for instance because subscript expressions are coupled, the loop is
36  printed as a loop.
37 
38  There are/were memory leaks here since a new expression is constructed.
39 
40 */
41 
42 #include <stdio.h>
43 
44 #include "linear.h"
45 
46 #include "genC.h"
47 #include "ri.h"
48 #include "misc.h"
49 
50 #include "ri-util.h"
51 
52 /* Entity f is supposed to be a binary operator, not always commutative
53  but meaningful for a range and a scalar or for two ranges. Boolean
54  argument left means that range r appears on the left of f, i.e. as
55  first operator.
56 
57  No sharing is created between the new expression e and arguments r, lw,
58  up or in.
59  */
60 
61 expression update_range(f, r, lw, up, in, left)
62 entity f ;
63 range r ;
64 expression lw, up, in ;
65 bool left;
66 {
67  range new_r = copy_range(r);
68  intptr_t val = 0;
69  expression new_up = copy_expression(up);
70  expression new_lw = copy_expression(lw);
71  expression new_in = copy_expression(in);
73 
74  pips_assert("new_r is consistent before update", range_consistent_p(new_r));
75 
76  if(left) {
77  range_lower( new_r ) = MakeBinaryCall(f, range_lower(new_r), new_lw);
78  range_upper( new_r ) = MakeBinaryCall(f, range_upper(new_r), new_up);
79  }
80  else {
81  range_lower( new_r ) = MakeBinaryCall(f, new_lw, range_lower(new_r));
82  range_upper( new_r ) = MakeBinaryCall(f, new_up, range_upper(new_r));
83  }
84 
85  pips_assert("new_r is consistent", range_consistent_p(new_r));
86 
87  if( strcmp( entity_local_name( f ), MULTIPLY_OPERATOR_NAME ) == 0 ) {
88  /* expression "in" must be integer constant 1 */
89  pips_assert("This is a scalar value", lw==up);
91  range_increment( new_r ) =
92  MakeBinaryCall(f, new_in, copy_expression(range_lower(new_r))) ;
93  }
94 
95  if( !left && (strcmp( entity_local_name( f ), MINUS_OPERATOR_NAME ) == 0) ) {
97 
98  range_increment( new_r ) =
99  MakeUnaryCall(um, range_increment(new_r)) ;
100  }
101 
102  if(expression_integer_value(range_lower(new_r), &val)) {
104  range_lower(new_r) = int_to_expression(val);
105  }
106 
107  if(expression_integer_value(range_upper(new_r), &val)) {
109  range_upper(new_r) = int_to_expression(val);
110  }
111 
112  if(expression_integer_value(range_increment(new_r), &val)) {
114  range_increment(new_r) = int_to_expression(val);
115  }
116 
117  pips_assert("new_r is consistent after simplification", range_consistent_p(new_r));
118 
121 
122  return e;
123 }
range copy_range(range p)
RANGE.
Definition: ri.c:2005
expression make_expression(syntax a1, normalized a2)
Definition: ri.c:886
expression copy_expression(expression p)
EXPRESSION.
Definition: ri.c:850
bool range_consistent_p(range p)
Definition: ri.c:2014
void free_expression(expression p)
Definition: ri.c:853
syntax make_syntax(enum syntax_utype tag, void *val)
Definition: ri.c:2491
#define pips_assert(what, predicate)
common macros, two flavors depending on NDEBUG
Definition: misc-local.h:172
int f(int off1, int off2, int n, float r[n], float a[n], float b[n])
Definition: offsets.c:15
#define MINUS_OPERATOR_NAME
#define UNARY_MINUS_OPERATOR_NAME
#define MULTIPLY_OPERATOR_NAME
const char * entity_local_name(entity e)
entity_local_name modified so that it does not core when used in vect_fprint, since someone thought t...
Definition: entity.c:453
entity entity_intrinsic(const char *name)
FI: I do not understand this function name (see next one!).
Definition: entity.c:1292
bool expression_integer_value(expression e, intptr_t *pval)
Definition: eval.c:792
expression MakeBinaryCall(entity f, expression eg, expression ed)
Creates a call expression to a function with 2 arguments.
Definition: expression.c:354
expression int_to_expression(_int i)
transform an int into an expression and generate the corresponding entity if necessary; it is not cle...
Definition: expression.c:1188
expression MakeUnaryCall(entity f, expression a)
Creates a call expression to a function with one argument.
Definition: expression.c:342
expression update_range(f, r, expression lw, expression up, expression in, bool left)
Prettyprint one FORTRAN 90 loop as an array expression.
Definition: fortran90.c:61
#define normalized_undefined
Definition: ri.h:1745
#define range_upper(x)
Definition: ri.h:2290
@ is_syntax_range
Definition: ri.h:2692
#define range_increment(x)
Definition: ri.h:2292
#define expression_undefined
Definition: ri.h:1223
#define range_lower(x)
Definition: ri.h:2288
#define intptr_t
Definition: stdint.in.h:294