PIPS
reductions.c File Reference
#include "genC.h"
#include "linear.h"
#include "ri.h"
#include "effects.h"
#include "resources.h"
#include "misc.h"
#include "ri-util.h"
#include "prettyprint.h"
#include "effects-util.h"
#include "pipsdbm.h"
#include "effects-generic.h"
#include "accel-util.h"
#include "reductions.h"
#include "sac.h"
#include "ricedg.h"
#include "effects-convex.h"
#include "effects-simple.h"
#include "control.h"
#include "callgraph.h"
#include "properties.h"
+ Include dependency graph for reductions.c:

Go to the source code of this file.

Data Structures

struct  reduction_in_statement_param
 finds out expression with reduction More...
 

Functions

bool sac_expression_reduction_p (expression e)
 reductions.c More...
 
static entity make_reduction_vector_entity (reduction r)
 
static reductionInfo add_reduction (list *reds, reduction r)
 The first part of the function check that the reduction is allowed. More...
 
static void undo_rename_reference (reference r, reductionInfo ri)
 
static void rename_reduction_ref_walker (expression e, reductionInfo ri)
 
static bool reduction_in_statement_walker (reference r, reduction_in_statement_param *p)
 
static bool reduction_in_statement_p (reduction red, statement stat)
 
static void rename_statement_reductions (statement s, list *reductions_info, list reductions)
 This function gets the possible reduction thanks to load_cumulated_reductions() function. More...
 
static expression make_maxval_expression (basic b)
 
static expression make_minval_expression (basic b)
 
static expression make_0val_expression (basic b)
 
static expression make_1val_expression (basic b)
 
static statement generate_prelude (reductionInfo ri)
 
static statement generate_compact (reductionInfo ri)
 
static bool simd_gather_reduction (statement body, list reductions, list *reductions_info)
 
static void reductions_rewrite (statement s, set skip)
 
static bool reduction_rewrite_filter (statement s, set skip)
 
bool simd_remove_reductions (char *mod_name)
 remove reductions by expanding reduced scalar to an array More...
 
static bool no_write_read_conflicts_p (list succs)
 
static bool potential_out_effects_p (statement s)
 
static void do_redundant_load_store_elimination (graph dg)
 
bool redundant_load_store_elimination (char *module_name)
 

Function Documentation

◆ add_reduction()

static reductionInfo add_reduction ( list reds,
reduction  r 
)
static

The first part of the function check that the reduction is allowed.

If not, the function returns undefined. If the reduction is allowed, the function updates the reductionInfo list reds or add the reduction to the list.

Definition at line 85 of file reductions.c.

86 {
88 
89  pips_debug(1, "reduction reference %s\n", entity_local_name(reference_variable(reduction_reference(r))));
90 
91  //See if the reduction has already been encountered
92  FOREACH(REDUCTIONINFO,ri,*reds)
93  {
95  {
96  //The reduction has already been encountered: update the counter
97  reductionInfo_count(ri)++;
98 
101 
102  return ri;
103  }
104  }
105 
106  //First time we see this reduction: initialize a reductionInfo structure
108 
109  //Add to the list of reductions encountered
110  *reds=CONS(REDUCTIONINFO,ri,*reds);
111 
112  return ri;
113 }
void free_expression(expression p)
Definition: ri.c:853
reductionInfo make_reductionInfo(reduction a1, intptr_t a2, entity a3)
Definition: sac_private.c:376
#define CONS(_t_, _i_, _l_)
List element cell constructor (insert an element at the beginning of a list)
Definition: newgen_list.h:150
#define CAR(pcons)
Get the value of the first element of a list.
Definition: newgen_list.h:92
#define FOREACH(_fe_CASTER, _fe_item, _fe_list)
Apply/map an instruction block on all the elements of a list.
Definition: newgen_list.h:179
#define pips_debug
these macros use the GNU extensions that allow variadic macros, including with an empty list.
Definition: misc-local.h:145
bool same_reduction_p(reduction r1, reduction r2)
Definition: reductions.c:611
static entity make_reduction_vector_entity(reduction r)
Definition: reductions.c:64
#define reduction_reference(x)
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
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
#define reference_variable(x)
Definition: ri.h:2326
#define type_variable(x)
Definition: ri.h:2949
#define dimension_upper(x)
Definition: ri.h:982
#define variable_dimensions(x)
Definition: ri.h:3122
#define entity_type(x)
Definition: ri.h:2792
#define reductionInfo_reduction(x)
Definition: sac_private.h:451
#define reductionInfo_count(x)
Definition: sac_private.h:453
#define reductionInfo_undefined
Definition: sac_private.h:426
#define REDUCTIONINFO(x)
REDUCTIONINFO.
Definition: sac_private.h:420
#define reductionInfo_vector(x)
Definition: sac_private.h:455

References CAR, CONS, DIMENSION, dimension_upper, entity_local_name(), entity_type, FOREACH, free_expression(), int_to_expression(), make_reduction_vector_entity(), make_reductionInfo(), pips_debug, reduction_reference, REDUCTIONINFO, reductionInfo_count, reductionInfo_reduction, reductionInfo_undefined, reductionInfo_vector, reference_variable, same_reduction_p(), type_variable, and variable_dimensions.

Referenced by rename_statement_reductions().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ do_redundant_load_store_elimination()

static void do_redundant_load_store_elimination ( graph  dg)
static

Definition at line 752 of file reductions.c.

752  {
753  bool did_something ;
754  set deleted_vertex = set_make(set_pointer);
755  do {
756  did_something=false;
757  statement deleted = statement_undefined;
759  if(!set_belong_p(deleted_vertex,v) && no_write_read_conflicts_p(vertex_successors(v))) {
761  if(statement_call_p(s) &&
762  !return_statement_p(s) &&
766  did_something=true;
767  deleted=s;
768  set_add_element(deleted_vertex,deleted_vertex,v);
769  break;
770  }
771  }
772  }
773 
774  if(!statement_undefined_p(deleted)) {
776  if(!set_belong_p(deleted_vertex,v)) {
778  FOREACH(SUCCESSOR,s,tmp) {
779  if(vertex_to_statement(successor_vertex(s)) == deleted )
781  }
782  }
783  }
784  }
785  } while(did_something);
786 }
static graph dg
dg is the dependency graph ; FIXME : should not be static global ?
Definition: chains.c:124
#define successor_vertex(x)
Definition: graph.h:118
#define vertex_successors(x)
Definition: graph.h:154
#define SUCCESSOR(x)
SUCCESSOR.
Definition: graph.h:86
#define graph_vertices(x)
Definition: graph.h:82
#define VERTEX(x)
VERTEX.
Definition: graph.h:122
instruction make_continue_instruction()
Creates a CONTINUE instruction, that is the FORTRAN nop, the ";" in C or the "pass" in Python for exa...
Definition: instruction.c:79
void gen_remove(list *cpp, const void *o)
remove all occurences of item o from list *cpp, which is thus modified.
Definition: list.c:685
list gen_copy_seq(list l)
Copy a list structure.
Definition: list.c:501
bool statement_call_p(statement)
Definition: statement.c:364
statement update_statement_instruction(statement, instruction)
Replace the instruction in statement s by instruction i.
Definition: statement.c:3039
bool return_statement_p(statement)
Test if a statement is a C or Fortran "return".
Definition: statement.c:172
bool declaration_statement_p(statement)
Had to be optimized according to Beatrice Creusillet.
Definition: statement.c:224
statement vertex_to_statement(vertex v)
Vertex_to_statement looks for the statement that is pointed to by vertex v.
Definition: util.c:45
bool set_belong_p(const set, const void *)
Definition: set.c:194
@ set_pointer
Definition: newgen_set.h:44
set set_make(set_type)
Create an empty set of any type but hash_private.
Definition: set.c:102
set set_add_element(set, const set, const void *)
Definition: set.c:152
static bool no_write_read_conflicts_p(list succs)
Definition: reductions.c:716
static bool potential_out_effects_p(statement s)
Definition: reductions.c:727
#define statement_undefined_p(x)
Definition: ri.h:2420
#define statement_undefined
Definition: ri.h:2419
FI: I do not understand why the type is duplicated at the set level.
Definition: set.c:59
The structure used to build lists in NewGen.
Definition: newgen_list.h:41

References declaration_statement_p(), dg, FOREACH, gen_copy_seq(), gen_remove(), graph_vertices, make_continue_instruction(), no_write_read_conflicts_p(), potential_out_effects_p(), return_statement_p(), set_add_element(), set_belong_p(), set_make(), set_pointer, statement_call_p(), statement_undefined, statement_undefined_p, SUCCESSOR, successor_vertex, update_statement_instruction(), VERTEX, vertex_successors, and vertex_to_statement().

Referenced by redundant_load_store_elimination().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ generate_compact()

static statement generate_compact ( reductionInfo  ri)
static

Definition at line 355 of file reductions.c.

356 {
357  expression rightExpr;
358  entity operator;
359  instruction compact;
360  int i;
361 
362  // According to the operator, get the correct entity
364  {
365  default:
367  return statement_undefined; //nothing to generate
368  break;
369 
372  break;
373 
376  break;
377 
380  break;
381 
384  break;
385 
388  break;
389 
392  break;
393 
396  break;
397  }
398 
399  // Get the reduction variable
401 
402  const char* spostlude = get_string_property("SIMD_REMOVE_REDUCTIONS_POSTLUDE");
403  statement postlude = statement_undefined;
405  // For each reductionInfo_vector reference, add it to the compact statement
406  for(i=0; i<reductionInfo_count(ri); i++)
407  {
408  call c;
409  expression e;
410 
413  c = make_call(operator, CONS(EXPRESSION, e,
414  CONS(EXPRESSION, rightExpr, NIL)));
415 
416  rightExpr = call_to_expression(c);
417  }
418 
419  // Make the compact assignment statement
420  compact = make_assign_instruction(
422  rightExpr);
423 
424  postlude= instruction_to_statement(compact);
425  }
426  else {
427  entity epostlude = FindEntity(TOP_LEVEL_MODULE_NAME,spostlude);
428  if(entity_undefined_p(epostlude)) {
429  pips_user_warning("%s not found, using a dummy one",spostlude);
431  }
432  postlude=call_to_statement(
433  make_call(
434  epostlude,
439  ),
446  )
447  )
448  )
449  )
450  )
451  );
452  }
453  return postlude;
454 }
call make_call(entity a1, list a2)
Definition: ri.c:269
reference make_reference(entity a1, list a2)
Definition: ri.c:2083
language copy_language(language p)
LANGUAGE.
Definition: ri.c:1202
reference copy_reference(reference p)
REFERENCE.
Definition: ri.c:2047
bool empty_string_p(const char *s)
Definition: entity_names.c:239
char * get_string_property(const char *)
statement instruction_to_statement(instruction)
Build a statement from a give instruction.
Definition: statement.c:597
entity get_current_module_entity(void)
Get the entity of the current module.
Definition: static.c:85
instruction make_assign_instruction(expression l, expression r)
Definition: instruction.c:87
#define NIL
The empty list (nil in Lisp)
Definition: newgen_list.h:47
#define pips_user_warning
Definition: misc-local.h:146
#define TOP_LEVEL_MODULE_NAME
Module containing the global variables in Fortran and C.
Definition: naming-local.h:101
#define reduction_operator_sum_p(x)
@ is_reduction_operator_none
@ is_reduction_operator_min
@ is_reduction_operator_max
@ is_reduction_operator_csum
@ is_reduction_operator_prod
@ is_reduction_operator_or
@ is_reduction_operator_and
@ is_reduction_operator_sum
#define reduction_operator_tag(x)
#define reduction_op(x)
#define make_expression_list(stats...)
#define MAX_OPERATOR_NAME
#define PLUS_OPERATOR_NAME
#define call_to_statement(c)
#define AND_OPERATOR_NAME
FI: intrinsics are defined at a third place after bootstrap and effects! I guess the name should be d...
#define ADDRESS_OF_OPERATOR_NAME
#define module_language(e)
implemented as a macro to allow lhs
#define MULTIPLY_OPERATOR_NAME
#define OR_OPERATOR_NAME
#define PLUS_C_OPERATOR_NAME
#define MIN_OPERATOR_NAME
entity FindEntity(const char *package, const char *name)
Retrieve an entity from its package/module name and its local name.
Definition: entity.c:1503
entity make_empty_subroutine(const char *name, language l)
Definition: entity.c:268
entity entity_intrinsic(const char *name)
FI: I do not understand this function name (see next one!).
Definition: entity.c:1292
expression reference_to_expression(reference r)
Definition: expression.c:196
expression MakeUnaryCall(entity f, expression a)
Creates a call expression to a function with one argument.
Definition: expression.c:342
expression call_to_expression(call c)
Build an expression that call a function or procedure.
Definition: expression.c:309
#define EXPRESSION(x)
EXPRESSION.
Definition: ri.h:1217
#define entity_undefined_p(x)
Definition: ri.h:2762

References ADDRESS_OF_OPERATOR_NAME, AND_OPERATOR_NAME, call_to_expression(), call_to_statement, CONS, copy_language(), copy_reference(), empty_string_p(), entity_intrinsic(), entity_undefined_p, EXPRESSION, FindEntity(), get_current_module_entity(), get_string_property(), instruction_to_statement(), int_to_expression(), is_reduction_operator_and, is_reduction_operator_csum, is_reduction_operator_max, is_reduction_operator_min, is_reduction_operator_none, is_reduction_operator_or, is_reduction_operator_prod, is_reduction_operator_sum, make_assign_instruction(), make_call(), make_empty_subroutine(), make_expression_list, make_reference(), MakeUnaryCall(), MAX_OPERATOR_NAME, MIN_OPERATOR_NAME, module_language, MULTIPLY_OPERATOR_NAME, NIL, OR_OPERATOR_NAME, pips_user_warning, PLUS_C_OPERATOR_NAME, PLUS_OPERATOR_NAME, reduction_op, reduction_operator_sum_p, reduction_operator_tag, reduction_reference, reductionInfo_count, reductionInfo_reduction, reductionInfo_vector, reference_to_expression(), statement_undefined, and TOP_LEVEL_MODULE_NAME.

Referenced by reductions_rewrite().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ generate_prelude()

static statement generate_prelude ( reductionInfo  ri)
static

Definition at line 287 of file reductions.c.

288 {
289  expression initval;
290  list prelude = NIL;
291  int i;
293 
294  // According to the operator, get the correct initialization value
295  // should use operator_neutral_element
297  {
298  default:
300  return statement_undefined;
301  break;
302 
304  initval = make_maxval_expression(bas);
305  break;
306 
308  initval = make_minval_expression(bas);
309  break;
310 
312  initval = make_0val_expression(bas);
313  break;
314 
316  initval = make_1val_expression(bas);
317  break;
318 
320  initval = bool_to_expression(true);
321  break;
322 
324  initval = bool_to_expression(false);
325  break;
326  }
327 
328  // For each reductionInfo_vector reference, make an initialization
329  // assign statement and add it to the prelude
330  // do nothing if no init val exist
331  for(i=0; i<reductionInfo_count(ri); i++)
332  {
333  instruction is;
334 
339  NIL))),
340  copy_expression(initval));
341 
342  prelude = CONS(STATEMENT,
344  prelude);
345  }
346 
347  free_expression(initval);
348 
350 }
expression copy_expression(expression p)
EXPRESSION.
Definition: ri.c:850
instruction make_instruction_sequence(sequence _field_)
Definition: ri.c:1169
sequence make_sequence(list a)
Definition: ri.c:2125
static expression make_minval_expression(basic b)
Definition: reductions.c:221
static expression make_0val_expression(basic b)
Definition: reductions.c:243
static expression make_1val_expression(basic b)
Definition: reductions.c:266
static expression make_maxval_expression(basic b)
Definition: reductions.c:199
expression bool_to_expression(bool b)
Definition: expression.c:1238
basic basic_of_reference(reference)
Retrieves the basic of a reference in a newly allocated basic object.
Definition: type.c:1459
#define STATEMENT(x)
STATEMENT.
Definition: ri.h:2413

References basic_of_reference(), bool_to_expression(), CONS, copy_expression(), EXPRESSION, free_expression(), instruction_to_statement(), int_to_expression(), is_reduction_operator_and, is_reduction_operator_max, is_reduction_operator_min, is_reduction_operator_none, is_reduction_operator_or, is_reduction_operator_prod, is_reduction_operator_sum, make_0val_expression(), make_1val_expression(), make_assign_instruction(), make_instruction_sequence(), make_maxval_expression(), make_minval_expression(), make_reference(), make_sequence(), NIL, reduction_op, reduction_operator_tag, reduction_reference, reductionInfo_count, reductionInfo_reduction, reductionInfo_vector, reference_to_expression(), STATEMENT, and statement_undefined.

Referenced by reductions_rewrite().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ make_0val_expression()

static expression make_0val_expression ( basic  b)
static

Definition at line 243 of file reductions.c.

244 {
245  switch(basic_tag(b))
246  {
247  case is_basic_float:
248  return float_to_expression(0);
249 
250  case is_basic_int:
251  return int_to_expression(0);
252 
253  case is_basic_complex:
254  return complex_to_expression(0,0);
255 
256  default:
257  pips_internal_error("function not implemented for this basic ");
258  }
259  return expression_undefined;
260 }
#define pips_internal_error
Definition: misc-local.h:149
expression float_to_expression(float c)
Definition: expression.c:1229
expression complex_to_expression(float re, float im)
Definition: expression.c:1234
@ is_basic_float
Definition: ri.h:572
@ is_basic_int
Definition: ri.h:571
@ is_basic_complex
Definition: ri.h:575
#define basic_tag(x)
Definition: ri.h:613
#define expression_undefined
Definition: ri.h:1223

References basic_tag, complex_to_expression(), expression_undefined, float_to_expression(), int_to_expression(), is_basic_complex, is_basic_float, is_basic_int, and pips_internal_error.

Referenced by generate_prelude().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ make_1val_expression()

static expression make_1val_expression ( basic  b)
static

Definition at line 266 of file reductions.c.

267 {
268  switch(basic_tag(b))
269  {
270  case is_basic_float:
271  return float_to_expression(1);
272 
273  case is_basic_int:
274  return int_to_expression(1);
275 
276  case is_basic_complex:
277  return complex_to_expression(0,1);
278 
279  default:
280  return expression_undefined;
281  }
282 }

References basic_tag, complex_to_expression(), expression_undefined, float_to_expression(), int_to_expression(), is_basic_complex, is_basic_float, and is_basic_int.

Referenced by generate_prelude().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ make_maxval_expression()

static expression make_maxval_expression ( basic  b)
static

Definition at line 199 of file reductions.c.

200 {
201  switch(basic_tag(b))
202  {
203  case is_basic_float:
204  return expression_undefined;
205 
206  case is_basic_int:
207  {
208  long long max = (2 << (basic_int(b) - 2)) - 1;
209  return int_to_expression(max);
210  }
211 
212  default:
213  return expression_undefined;
214  }
215 }
#define max(a, b)
#define basic_int(x)
Definition: ri.h:616

References basic_int, basic_tag, expression_undefined, int_to_expression(), is_basic_float, is_basic_int, and max.

Referenced by generate_prelude().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ make_minval_expression()

static expression make_minval_expression ( basic  b)
static

Definition at line 221 of file reductions.c.

222 {
223  switch(basic_tag(b))
224  {
225  case is_basic_float:
226  return expression_undefined;
227 
228  case is_basic_int:
229  {
230  long long min = -(2 << (basic_int(b) - 2));
231  return int_to_expression(min);
232  }
233 
234  default:
235  return expression_undefined;
236  }
237 }
#define min(a, b)

References basic_int, basic_tag, expression_undefined, int_to_expression(), is_basic_float, is_basic_int, and min.

Referenced by generate_prelude().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ make_reduction_vector_entity()

static entity make_reduction_vector_entity ( reduction  r)
static

Definition at line 64 of file reductions.c.

65 {
67  entity new_ent, mod_ent;
68  static int counter = 0;
69  const char *prefix = get_string_property("SIMD_REMOVE_REDUCTIONS_PREFIX") ;
70  char buffer[ 1 + 3 + strlen(prefix) ];
71  pips_assert("buffer does not overflow",counter < 1000);
72  sprintf(buffer,"%s%u",prefix,counter++);
73 
78  return new_ent;
79 }
dimension make_dimension(expression a1, expression a2, list a3)
Definition: ri.c:565
static entity mod_ent
bdt base
Current expression.
Definition: bdt_read_paf.c:100
statement get_current_module_statement(void)
Get the current module statement.
Definition: static.c:208
#define pips_assert(what, predicate)
common macros, two flavors depending on NDEBUG
Definition: misc-local.h:172
static const char * prefix
void AddLocalEntityToDeclarations(entity, entity, statement)
Add the variable entity e to the list of variables of the function module.
Definition: variable.c:233
entity make_new_array_variable_with_prefix(const char *, entity, basic, list)
J'ai ameliore la fonction make_new_scalar_variable_with_prefix
Definition: variable.c:785
static string buffer
Definition: string.c:113

References AddLocalEntityToDeclarations(), base, basic_of_reference(), buffer, CONS, DIMENSION, get_current_module_entity(), get_current_module_statement(), get_string_property(), int_to_expression(), make_dimension(), make_new_array_variable_with_prefix(), mod_ent, NIL, pips_assert, prefix, and reduction_reference.

Referenced by add_reduction().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ no_write_read_conflicts_p()

static bool no_write_read_conflicts_p ( list  succs)
static

Definition at line 716 of file reductions.c.

716  {
717  FOREACH(SUCCESSOR, succ, succs) {
721  return false;
722  }
723  }
724  return true;
725 }
#define conflict_sink(x)
Definition: dg.h:167
#define CONFLICT(x)
CONFLICT.
Definition: dg.h:134
#define dg_arc_label_conflicts(x)
Definition: dg.h:201
#define conflict_source(x)
Definition: dg.h:165
#define effect_write_p(eff)
#define effect_read_p(eff)
#define effect_scalar_p(eff) entity_scalar_p(effect_entity(eff))
#define successor_arc_label(x)
Definition: graph.h:116

References CONFLICT, conflict_sink, conflict_source, dg_arc_label_conflicts, effect_read_p, effect_write_p, FOREACH, SUCCESSOR, and successor_arc_label.

Referenced by do_redundant_load_store_elimination().

+ Here is the caller graph for this function:

◆ potential_out_effects_p()

static bool potential_out_effects_p ( statement  s)
static

get_current_module_statement()

Definition at line 727 of file reductions.c.

727  {
728  FOREACH(EFFECT,eff,load_proper_rw_effects_list(s)) if(io_effect_p(eff)) return true;
729  if(get_bool_property("REDUNDANT_LOAD_STORE_ELIMINATION_CONSERVATIVE")) {
731  bool out_effect = false;
734  if( anywhere_effect_p(eff) ||
737  ) {
738  out_effect=true;break;
739  }
740  }
742  return out_effect;
743  }
744  else {
745 
746  list out_effects = load_cumulated_rw_effects_list(s /* get_current_module_statement() */);
747  return !ENDP(out_effects);
748  }
749 
750 }
void write_effects(FILE *f, effects p)
Definition: effects.c:562
list load_proper_rw_effects_list(statement)
list load_cumulated_rw_effects_list(statement)
list effects_write_effects(list)
bool out_effects(const string)
#define effect_any_reference(e)
FI: cannot be used as a left hand side.
bool anywhere_effect_p(effect)
Is it an anywhere effect? ANYMMODULE:ANYWHERE
Definition: effects.c:346
bool io_effect_p(effect)
Definition: effects.c:501
#define EFFECT(x)
EFFECT.
Definition: effects.h:608
bool get_bool_property(const string)
FC 2015-07-20: yuk, moved out to prevent an include cycle dependency include "properties....
#define ENDP(l)
Test if a list is empty.
Definition: newgen_list.h:66
void gen_free_list(list l)
free the spine of the list
Definition: list.c:327
bool top_level_entity_p(entity e)
Check if the scope of entity e is global.
Definition: entity.c:1130
bool formal_parameter_p(entity)
Definition: variable.c:1489
#define reference_indices(x)
Definition: ri.h:2328

References anywhere_effect_p(), EFFECT, effect_any_reference, effects_write_effects(), ENDP, FOREACH, formal_parameter_p(), gen_free_list(), get_bool_property(), io_effect_p(), load_cumulated_rw_effects_list(), load_proper_rw_effects_list(), out_effects(), reference_indices, reference_variable, top_level_entity_p(), and write_effects().

Referenced by do_redundant_load_store_elimination().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ reduction_in_statement_p()

static bool reduction_in_statement_p ( reduction  red,
statement  stat 
)
static

Definition at line 151 of file reductions.c.

152 {
153  reduction_in_statement_param p ={ red, false };
155  return p.has_reduction_p;
156 }
#define gen_context_recurse(start, ctxt, domain_number, flt, rwt)
Definition: genC.h:285
void gen_null2(__attribute__((unused)) void *u1, __attribute__((unused)) void *u2)
idem with 2 args, to please overpeaky compiler checks
Definition: genClib.c:2758
static bool reduction_in_statement_walker(reference r, reduction_in_statement_param *p)
Definition: reductions.c:145
#define reference_domain
newgen_range_domain_defined
Definition: ri.h:338
finds out expression with reduction
Definition: reductions.c:140

References gen_context_recurse, gen_null2(), reduction_in_statement_param::has_reduction_p, reduction_in_statement_walker(), and reference_domain.

Referenced by rename_statement_reductions().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ reduction_in_statement_walker()

static bool reduction_in_statement_walker ( reference  r,
reduction_in_statement_param p 
)
static

Definition at line 145 of file reductions.c.

146 {
148  return ! p->has_reduction_p;
149 }
bool reference_equal_p(reference r1, reference r2)
Definition: expression.c:1500

References reduction_in_statement_param::has_reduction_p, reduction_in_statement_param::red, reduction_reference, and reference_equal_p().

Referenced by reduction_in_statement_p().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ reduction_rewrite_filter()

static bool reduction_rewrite_filter ( statement  s,
set  skip 
)
static

Definition at line 557 of file reductions.c.

558 {
559  if (statement_loop_p(s))
561  return true;
562 }
loop statement_loop(statement)
Get the loop of a statement.
Definition: statement.c:1374
bool statement_loop_p(statement)
Definition: statement.c:349
#define loop_body(x)
Definition: ri.h:1644

References loop_body, set_add_element(), statement_loop(), and statement_loop_p().

Referenced by simd_remove_reductions().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ reductions_rewrite()

static void reductions_rewrite ( statement  s,
set  skip 
)
static

we may have failed to find any reduction info, in that case try again with the inner reductions

not enough elements: undo the change

Definition at line 475 of file reductions.c.

476 {
477  if(set_belong_p(skip,s)) return;
479  statement body;
480  bool is_loop=true;
481 
482  //We are only interested in loops
483  switch(instruction_tag(i))
484  {
485  case is_instruction_loop:
486  body = loop_body(instruction_loop(i));
487  break;
488 
491  break;
492 
495  break;
496 
498  body = s;
499  is_loop=false;
500  break;
501 
502  default:
503  return;
504  }
505  {
506 
507  list reductions_info = NIL;
508  list preludes = NIL;
509  list compacts = NIL;
510 
511  //Compute the reductions list for the loop
513  ifdebug(2) {
514  if(!ENDP(reductions))
515  pips_debug(2,"found reductions for loop:\n");
516  else
517  pips_debug(2,"no reduction for loop:\n");
518  print_statement(s);
519  }
520  //Lookup the reductions in the loop's body, and change the loop body accordingly
521  if(!simd_gather_reduction(body,reductions,&reductions_info)) {
522  /* we may have failed to find any reduction info, in that case try again with the inner reductions */
524  simd_gather_reduction(body,reductions,&reductions_info);
525  s=body;
526  }
527 
528 
529  //Generate prelude and compact code for each of the reductions
530  FOREACH(REDUCTIONINFO, ri,reductions_info)
531  {
532  if(entity_memory_size(reductionInfo_vector(ri))*8 >= get_int_property("SAC_SIMD_REGISTER_WIDTH")) {
533  statement curStat = generate_prelude(ri);
534  if (curStat != statement_undefined)
535  preludes = CONS(STATEMENT, curStat, preludes);
536 
537  curStat = generate_compact(ri);
538  if (curStat != statement_undefined)
539  compacts = CONS(STATEMENT, curStat, compacts);
540  }
541  /* not enough elements: undo the change */
542  else {
544  }
545  };
546  gen_full_free_list(reductions_info);
547 
548  // Replace the old statement instruction by the new one
549  gen_recurse_stop(compacts);
550  insert_statement(s,make_block_statement(compacts),false);
551  insert_statement(s,make_block_statement(preludes),true);
552 
553  }
554  if(is_loop) gen_recurse_stop(statement_instruction(s));
555 }
int get_int_property(const string)
void gen_full_free_list(list l)
Definition: genClib.c:1023
statement make_block_statement(list)
Make a block statement from a list of statement.
Definition: statement.c:616
void gen_recurse_stop(void *obj)
Tells the recursion not to go in this object.
Definition: genClib.c:3251
bool gen_true2(__attribute__((unused)) gen_chunk *u1, __attribute__((unused)) void *u2)
Definition: genClib.c:2785
void insert_statement(statement, statement, bool)
This is the normal entry point.
Definition: statement.c:2570
static void undo_rename_reference(reference r, reductionInfo ri)
Definition: reductions.c:115
static bool simd_gather_reduction(statement body, list reductions, list *reductions_info)
Definition: reductions.c:456
static statement generate_compact(reductionInfo ri)
Definition: reductions.c:355
static statement generate_prelude(reductionInfo ri)
Definition: reductions.c:287
void print_statement(statement)
Print a statement on stderr.
Definition: statement.c:98
reductions load_cumulated_reductions(statement)
#define reductions_list(x)
int entity_memory_size(entity)
Definition: size.c:239
#define instruction_loop(x)
Definition: ri.h:1520
@ is_instruction_whileloop
Definition: ri.h:1472
@ is_instruction_sequence
Definition: ri.h:1469
@ is_instruction_forloop
Definition: ri.h:1477
@ is_instruction_loop
Definition: ri.h:1471
#define instruction_tag(x)
Definition: ri.h:1511
#define instruction_forloop(x)
Definition: ri.h:1538
#define instruction_whileloop(x)
Definition: ri.h:1523
#define whileloop_body(x)
Definition: ri.h:3162
#define statement_instruction(x)
Definition: ri.h:2458
#define forloop_body(x)
Definition: ri.h:1372
#define ifdebug(n)
Definition: sg.c:47

References CONS, ENDP, entity_memory_size(), FOREACH, forloop_body, gen_context_recurse, gen_full_free_list(), gen_recurse_stop(), gen_true2(), generate_compact(), generate_prelude(), get_int_property(), ifdebug, insert_statement(), instruction_forloop, instruction_loop, instruction_tag, instruction_whileloop, is_instruction_forloop, is_instruction_loop, is_instruction_sequence, is_instruction_whileloop, load_cumulated_reductions(), loop_body, make_block_statement(), NIL, pips_debug, print_statement(), REDUCTIONINFO, reductionInfo_vector, reductions_list, reference_domain, set_belong_p(), simd_gather_reduction(), STATEMENT, statement_instruction, statement_undefined, undo_rename_reference(), and whileloop_body.

Referenced by simd_remove_reductions().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ redundant_load_store_elimination()

bool redundant_load_store_elimination ( char *  module_name)

Get the code of the module.

Parameters
module_nameodule_name

Definition at line 788 of file reductions.c.

789 {
790  /* Get the code of the module. */
792  statement module_stat = (statement)db_get_memory_resource(DBR_CODE, module_name, true);
793  set_ordering_to_statement(module_stat);
795  set_current_module_statement( module_stat);
798 
800 
801  // buggy and incomplete
802  //do_sac_reduction_optimizations(dependence_graph);
804 
805  unnormalize_expression(module_stat);
806  module_reorder(module_stat);
807  DB_PUT_MEMORY_RESOURCE(DBR_CODE, module_name, module_stat);
809 
810 
816 
817  return true;
818 }
static graph dependence_graph
Definition: delay.c:93
callees compute_callees(const statement stat)
Recompute the callees of a module statement.
Definition: callgraph.c:355
struct _newgen_struct_statement_ * statement
Definition: cloning.h:21
void reset_proper_rw_effects(void)
void set_proper_rw_effects(statement_effects)
void set_cumulated_rw_effects(statement_effects)
void reset_cumulated_rw_effects(void)
const char * module_name(const char *s)
Return the module part of an entity name.
Definition: entity_names.c:296
struct _newgen_struct_graph_ * graph
Definition: graph.h:31
void reset_current_module_entity(void)
Reset the current module entity.
Definition: static.c:97
void reset_current_module_statement(void)
Reset the current module statement.
Definition: static.c:221
statement set_current_module_statement(statement)
Set the current module statement.
Definition: static.c:165
entity set_current_module_entity(entity)
static.c
Definition: static.c:66
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
hash_table set_ordering_to_statement(statement s)
To be used instead of initialize_ordering_to_statement() to make sure that the hash table ots is in s...
Definition: ordering.c:172
void reset_ordering_to_statement(void)
Reset the mapping from ordering to statement.
Definition: ordering.c:185
void unnormalize_expression(void *st)
void unnormalize_expression(expression exp): puts all the normalized field of expressions in "st" to ...
Definition: normalize.c:452
static void do_redundant_load_store_elimination(graph dg)
Definition: reductions.c:752
static char * module
Definition: pips.c:74
bool module_reorder(statement body)
Reorder a module and recompute order to statement if any.
Definition: reorder.c:244
entity module_name_to_entity(const char *mn)
This is an alias for local_name_to_top_level_entity.
Definition: entity.c:1479

References compute_callees(), db_get_memory_resource(), DB_PUT_MEMORY_RESOURCE, dependence_graph, do_redundant_load_store_elimination(), get_current_module_statement(), module, module_name(), module_name_to_entity(), module_reorder(), reset_cumulated_rw_effects(), reset_current_module_entity(), reset_current_module_statement(), reset_ordering_to_statement(), reset_proper_rw_effects(), set_cumulated_rw_effects(), set_current_module_entity(), set_current_module_statement(), set_ordering_to_statement(), set_proper_rw_effects(), and unnormalize_expression().

+ Here is the call graph for this function:

◆ rename_reduction_ref_walker()

static void rename_reduction_ref_walker ( expression  e,
reductionInfo  ri 
)
static

Definition at line 126 of file reductions.c.

127 {
128  syntax s = expression_syntax(e);
129 
130  if (syntax_reference_p(s) &&
132  {
136  }
137 }
void free_reference(reference p)
Definition: ri.c:2050
#define syntax_reference_p(x)
Definition: ri.h:2728
#define syntax_reference(x)
Definition: ri.h:2730
#define expression_syntax(x)
Definition: ri.h:1247

References expression_syntax, free_reference(), int_to_expression(), make_expression_list, make_reference(), reduction_reference, reductionInfo_count, reductionInfo_reduction, reductionInfo_vector, reference_equal_p(), syntax_reference, and syntax_reference_p.

Referenced by rename_statement_reductions().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ rename_statement_reductions()

static void rename_statement_reductions ( statement  s,
list reductions_info,
list  reductions 
)
static

This function gets the possible reduction thanks to load_cumulated_reductions() function.

Then, for each possible reduction, the function call add_reduction() to know if the reduction is allowed and if it is, the function calls rename_reduction_ref() to do the reduction.

Definition at line 163 of file reductions.c.

164 {
165  ifdebug(3) {
166  pips_debug(3,"considering statement:\n");
167  print_statement(s);
168  }
170  {
171  ifdebug(3) {
172  pips_debug(3,"considering reduction:\n");
174  fprintf(stderr,"\n");
175  }
176  if(reduction_star_p(r))
177  pips_debug(3,"can do nothing with star reductions ...\n");
178  else if(reduction_in_statement_p(r,s))
179  {
180  pips_debug(3,"found in the statement ! Rewriting ...\n");
182  if(!basic_undefined_p(b))
183  {
184  free_basic(b);
185  reductionInfo ri = add_reduction(reductions_info, r);
186  if( ! reductionInfo_undefined_p(ri))
188  }
189  }
190  else
191  pips_debug(3,"not found in the statement ! Skipping ...\n");
192  }
193 }
void free_basic(basic p)
Definition: ri.c:107
static void rename_reduction_ref_walker(expression e, reductionInfo ri)
Definition: reductions.c:126
static bool reduction_in_statement_p(reduction red, statement stat)
Definition: reductions.c:151
static reductionInfo add_reduction(list *reds, reduction r)
The first part of the function check that the reduction is allowed.
Definition: reductions.c:85
void print_reference(reference r)
Definition: expression.c:142
bool reduction_star_p(reduction)
utils.c
Definition: utils.c:46
#define REDUCTION(x)
REDUCTION.
#define expression_domain
newgen_execution_domain_defined
Definition: ri.h:154
#define basic_undefined_p(x)
Definition: ri.h:557
#define reductionInfo_undefined_p(x)
Definition: sac_private.h:427
int fprintf()
test sc_min : ce test s'appelle par : programme fichier1.data fichier2.data ...

References add_reduction(), basic_of_reference(), basic_undefined_p, expression_domain, FOREACH, fprintf(), free_basic(), gen_context_recurse, gen_true2(), ifdebug, pips_debug, print_reference(), print_statement(), REDUCTION, reduction_in_statement_p(), reduction_reference, reduction_star_p(), reductionInfo_undefined_p, and rename_reduction_ref_walker().

Referenced by simd_gather_reduction().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sac_expression_reduction_p()

bool sac_expression_reduction_p ( expression  e)

reductions.c

Definition at line 55 of file reductions.c.

55  {
56  if(expression_reference_p(e)) {
57  const char* refname = entity_user_name(reference_variable(expression_reference(e)));
58  if(refname==strstr(refname,get_string_property("SIMD_REMOVE_REDUCTIONS_PREFIX")))
59  return true;
60  }
61  return false;
62 }
const char * entity_user_name(entity e)
Since entity_local_name may contain PIPS special characters such as prefixes (label,...
Definition: entity.c:487
bool expression_reference_p(expression e)
Test if an expression is a reference.
Definition: expression.c:528
reference expression_reference(expression e)
Short cut, meaningful only if expression_reference_p(e) holds.
Definition: expression.c:1832

References entity_user_name(), expression_reference(), expression_reference_p(), get_string_property(), and reference_variable.

+ Here is the call graph for this function:

◆ simd_gather_reduction()

static bool simd_gather_reduction ( statement  body,
list  reductions,
list reductions_info 
)
static

Definition at line 456 of file reductions.c.

456  {
457  instruction ibody = statement_instruction(body);
458  switch(instruction_tag(ibody))
459  {
461  {
463  rename_statement_reductions(curStat, reductions_info, reductions);
464  } break;
465 
466  default:
467  return false;
468  }
469  return !ENDP(*reductions_info);
470 }
static void rename_statement_reductions(statement s, list *reductions_info, list reductions)
This function gets the possible reduction thanks to load_cumulated_reductions() function.
Definition: reductions.c:163
#define sequence_statements(x)
Definition: ri.h:2360
#define instruction_sequence(x)
Definition: ri.h:1514

References ENDP, FOREACH, instruction_sequence, instruction_tag, is_instruction_sequence, rename_statement_reductions(), sequence_statements, STATEMENT, and statement_instruction.

Referenced by reductions_rewrite().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ simd_remove_reductions()

bool simd_remove_reductions ( char *  mod_name)

remove reductions by expanding reduced scalar to an array

Parameters
mod_namemodule to remove reductions from
Returns
true

get the resources

Now do the job

Reorder the module, because new statements have been added

update/release resources

Parameters
mod_nameod_name

Definition at line 571 of file reductions.c.

572 {
573 
574  /* get the resources */
577  set_cumulated_reductions((pstatement_reductions) db_get_memory_resource(DBR_CUMULATED_REDUCTIONS, mod_name, true));
578 
579  debug_on("SIMDREDUCTION_DEBUG_LEVEL");
580 
581  /* Now do the job */
582  set skip = set_make(set_pointer);
584  set_free(skip);
585 
586  pips_assert("Statement is consistent after remove reductions", statement_consistent_p(get_current_module_statement()));
587 
588  /* Reorder the module, because new statements have been added */
593 
594  /* update/release resources */
598 
599  debug_off();
600 
601  return true;
602 }
bool statement_consistent_p(statement p)
Definition: ri.c:2195
bool clean_up_sequences(statement s)
Recursively clean up the statement sequences by fusing them if possible and by removing useless one.
#define debug_on(env)
Definition: misc-local.h:157
#define debug_off()
Definition: misc-local.h:160
void set_free(set)
Definition: set.c:332
static bool reduction_rewrite_filter(statement s, set skip)
Definition: reductions.c:557
static void reductions_rewrite(statement s, set skip)
Definition: reductions.c:475
void reset_cumulated_reductions(void)
void set_cumulated_reductions(pstatement_reductions)
#define statement_domain
newgen_sizeofexpression_domain_defined
Definition: ri.h:362

References clean_up_sequences(), compute_callees(), db_get_memory_resource(), DB_PUT_MEMORY_RESOURCE, debug_off, debug_on, gen_context_recurse, get_current_module_statement(), module_name_to_entity(), module_reorder(), pips_assert, reduction_rewrite_filter(), reductions_rewrite(), reset_cumulated_reductions(), reset_current_module_entity(), reset_current_module_statement(), set_cumulated_reductions(), set_current_module_entity(), set_current_module_statement(), set_free(), set_make(), set_pointer, statement_consistent_p(), and statement_domain.

+ Here is the call graph for this function:

◆ undo_rename_reference()

static void undo_rename_reference ( reference  r,
reductionInfo  ri 
)
static

Definition at line 115 of file reductions.c.

115  {
116  if(same_entity_p(
118  reductionInfo_vector(ri))) {
123  }
124 }
list gen_full_copy_list(list l)
Copy a list structure with element copy.
Definition: list.c:535
bool same_entity_p(entity e1, entity e2)
predicates on entities
Definition: entity.c:1321

References gen_full_copy_list(), gen_full_free_list(), reduction_reference, reductionInfo_reduction, reductionInfo_vector, reference_indices, reference_variable, and same_entity_p().

Referenced by reductions_rewrite().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: