PIPS
utils.c File Reference
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "genC.h"
#include "boolean.h"
#include "arithmetique.h"
#include "vecteur.h"
#include "contrainte.h"
#include "ray_dte.h"
#include "sommet.h"
#include "sg.h"
#include "sc.h"
#include "polyedre.h"
#include "union.h"
#include "matrice.h"
#include "matrix.h"
#include "ri.h"
#include "ri-util.h"
#include "constants.h"
#include "graph.h"
#include "paf_ri.h"
#include "text.h"
#include "text-util.h"
#include "misc.h"
#include "static_controlize.h"
#include "paf-util.h"
#include "prgm_mapping.h"
+ Include dependency graph for utils.c:

Go to the source code of this file.

Typedefs

typedef dfg_vertex_label vertex_label
 Internal variables
More...
 
typedef dfg_arc_label arc_label
 
typedef bool(* argh) (Pvecteur *, Pvecteur *)
 ======================================================================== More...
 

Functions

list insert_sort (list l, bool(*compare_obj)())
 ======================================================================== More...
 
bool is_index_coeff_p (entity e)
 ======================================================================== More...
 
bool compare_coeff (chunk *c1, chunk *c2)
 ======================================================================== More...
 
bool compare_nodes_dim (chunk *n1, chunk *n2)
 ======================================================================== More...
 
bool compare_dfs_weight (chunk *d1, chunk *d2)
 ======================================================================== More...
 
bool compare_unks_frenq (chunk *e1, chunk *e2)
 ======================================================================== More...
 
entity make_coeff (string prefix, int n)
 ======================================================================== More...
 
entity find_or_create_coeff (string prefix, int n)
 ======================================================================== More...
 
list rm_non_x_var (list l)
 ======================================================================== More...
 
list unify_lists (list l1, list l2)
 ======================================================================== More...
 
Psysteme new_elim_var_with_eg (Psysteme ps, list *init_l, list *elim_l)
 ======================================================================== More...
 
Psysteme plc_elim_var_with_eg (Psysteme ps, list *init_l, list *elim_l)
 ======================================================================== More...
 
int count_implicit_equation (Psysteme ps)
 ======================================================================== More...
 
list put_source_ind (list le)
 ======================================================================== More...
 
Ppolynome apply_farkas (Ppolynome F, Psysteme D, list *L, int *count_lambdas)
 
list get_graph_dataflows (graph g)
 ======================================================================== More...
 
list get_stmt_index_coeff (int stmt, hash_table StoL)
 ======================================================================== More...
 
Psysteme completer_base (Psysteme sys, list var_l, list par_l)
 ======================================================================== More...
 
list diff_lists (list l1, list l2)
 ======================================================================== More...
 
bool vecteurs_libres_p (Psysteme sys, Pbase v_base, Pbase c_base)
 ======================================================================== More...
 
Psysteme append_eg (Psysteme M1, Psysteme M2)
 ======================================================================== More...
 
void di_polynome_var_subst_null (Ppolynome *pp, entity var)
 ======================================================================== More...
 
Psysteme nullify_factors (Ppolynome *pp, list var_l, bool with_remnants)
 ======================================================================== More...
 
bool is_broadcast_p (dataflow df)
 ======================================================================== More...
 
int communication_dim (dataflow df)
 ======================================================================== More...
 
bool is_reduction_p (dataflow df)
 ======================================================================== More...
 
bool is_shift_p (dataflow df)
 ======================================================================== More...
 
void my_substitute_var_with_vec (Psysteme ps, entity var, int val, Pvecteur vec)
 =========================================================================== More...
 
Pvecteur old_prototype_factorize (Ppolynome pp, Variable var)
 ======================================================================== More...
 

Variables

char vcid_prgm_mapping_utils [] = "$Id: utils.c 23065 2016-03-02 09:05:50Z coelho $"
 
list prgm_parameter_l
 lint More...
 

Typedef Documentation

◆ arc_label

Definition at line 94 of file utils.c.

◆ argh

typedef bool(* argh) (Pvecteur *, Pvecteur *)

========================================================================

Ppolynome apply_farkas(Ppolynome F, Psysteme D, list *L, int *count_lambdas) returns the affine from of farkas lemma computed from the polynome "F" (the affine form) and the domain of its variables "ps_dom".

Farkas Lemma:

Let D be a non empty polyhedron defined by n affine inequalities: Ik(x) >= 0, k in 1,..,n

Then an affine form F is a non negative everywhere in D iff it is a positive affine combination of the above inequalities: F(x) >= 0 in D <=> F(x) == L0 + L1.I1(x) + .. + Ln.In(x) with Lk >= 0, k in 1,..,n

Here, *L" is the list (L0,..,Ln). If we note P(x) = L0 + L1.I1(x) + .. + Ln.In(x), the polynome returned is the Farkas polynome: FP = F(x) - P(x)

We also have to add the structure parameters that do not appear in D and that are in the global var "prgm_parameter_l". For instance, if "p" (in "prgm_parameter_l") does not appear in D, we'll have: P(x) = L0 + L1.I1(x) + .. + Ln.In(x) + Ln+1.p and "*L" will be (L0,..,Ln,Ln+1)

In the following code, variable "P" is the opposite of our P(x). In doing so, we'll be able to simplified the final calculus (F(x) - P(x)) by an addition.

Definition at line 667 of file utils.c.

◆ vertex_label

Internal variables

Local defines

Definition at line 93 of file utils.c.

Function Documentation

◆ append_eg()

Psysteme append_eg ( Psysteme  M1,
Psysteme  M2 
)

========================================================================

Definition at line 946 of file utils.c.

948 {
949  Pcontrainte pc1, pc2, prec;
950  Pvecteur pv;
951 
952  if(M1 == NULL)
953  return(M2);
954  if(M2 == NULL)
955  return(M1);
956 
957  pc1 = M1->egalites;
958  pc2 = M2->egalites;
959  for(prec = NULL; pc1 != NULL; pc1 = pc1->succ)
960  prec = pc1;
961 
962  if(prec == NULL)
963  return(M2);
964 
965  prec->succ = pc2;
966  M1->nb_eq += M2->nb_eq;
967 
968  pv = M1->base;
969  M1->base = NULL;
970  vect_rm(pv);
971  sc_creer_base(M1);
972 
973  return(M1);
974 }
#define M2
Definition: r1.c:27
#define M1
Definition: r1.c:26
void sc_creer_base(Psysteme ps)
void sc_creer_base(Psysteme ps): initialisation des parametres dimension et base d'un systeme lineair...
Definition: sc_alloc.c:129
struct Scontrainte * succ
le type des coefficients dans les vecteurs: Value est defini dans le package arithmetique
Definition: vecteur-local.h:89
void vect_rm(Pvecteur v)
void vect_rm(Pvecteur v): desallocation des couples de v;
Definition: alloc.c:78

References M1, M2, sc_creer_base(), Scontrainte::succ, and vect_rm().

Referenced by base_complete(), completer_base(), completer_n_base(), cutting_conditions(), and partial_broadcast_coefficients().

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

◆ apply_farkas()

Ppolynome apply_farkas ( Ppolynome  F,
Psysteme  D,
list L,
int count_lambdas 
)

Constant term: L0

We associate to each equation or inequation a different coefficient, so the addition is never simplified, it just put a few monomes to the end of "P", i.e. "last_P". We do not used "polynome_add()" because this function looks for similar monomes.

An equality (v == 0) is also two inequalities (v >= 0, v <= 0)

We add to (-P) the parameters that do not appear in D

pu_is_inferior_var is not implemented and does not match prototype...

FP = F + (-P) We are sure that F-P can not be simplified, i.e. that there are similar monomes; this is because each monome of P has a variable that never appear outside of P.

Definition at line 669 of file utils.c.

674 {
675  Ppolynome FP, pp_v, P, last_P;
676  int cl = *count_lambdas;
677  entity nl;
678  list local_l = NIL, params_in_D, l, ll;
679  Pcontrainte pc;
680 
681  nl = find_or_create_coeff(LAMBD_COEFF, cl++);
682  local_l = CONS(ENTITY, nl, local_l);
683 
684  /* Constant term: L0 */
685  P = make_polynome(-1.0, (Variable) nl, 1);
686  last_P = P;
687 
688  /* We associate to each equation or inequation a different coefficient, so
689  * the addition is never simplified, it just put a few monomes to the end
690  * of "P", i.e. "last_P". We do not used "polynome_add()" because this
691  * function looks for similar monomes.
692  */
693  if(D != NULL) {
694  for(pc = D->inegalites; pc != NULL; pc = pc->succ) {
695  Pvecteur pv = pc->vecteur;
696 
697  nl = find_or_create_coeff(LAMBD_COEFF, cl++);
698  local_l = CONS(ENTITY, nl, local_l);
699 
700  pp_v = vecteur_mult(pv, vect_new((Variable) nl, 1));
701 
702  for(last_P->succ = pp_v; last_P->succ != NULL; last_P = last_P->succ) {}
703  }
704 
705  /* An equality (v == 0) is also two inequalities (v >= 0, v <= 0) */
706  for(pc = D->egalites; pc != NULL; pc = pc->succ) {
707  Pvecteur pv = pc->vecteur;
708 
709  nl = find_or_create_coeff(LAMBD_COEFF, cl++);
710  local_l = CONS(ENTITY, nl, local_l);
711 
712  pp_v = vecteur_mult(pv, vect_new((Variable) nl, 1));
713 
714  for(last_P->succ = pp_v; last_P->succ != NULL; last_P = last_P->succ) {}
715 
716  nl = find_or_create_coeff(LAMBD_COEFF, cl++);
717  local_l = CONS(ENTITY, nl, local_l);
718 
719  pp_v = vecteur_mult(pv, vect_new((Variable) nl, -1));
720 
721  for(last_P->succ = pp_v; last_P->succ != NULL; last_P = last_P->succ) {}
722  }
723  }
724 
725  /* We add to (-P) the parameters that do not appear in D */
726  /* pu_is_inferior_var is not implemented and does not match prototype... */
728  for(l = gen_append(prgm_parameter_l, NIL); !ENDP(l); POP(l)) {
729  bool not_found = true;
730  entity p = ENTITY(CAR(l));
731  for(ll = params_in_D; !ENDP(ll) && (not_found); POP(ll)) {
732  if( same_entity_p(p, ENTITY(CAR(ll))) )
733  not_found = false;
734  }
735  if(not_found) {
736  nl = find_or_create_coeff(LAMBD_COEFF, cl++);
737  local_l = CONS(ENTITY, nl, local_l);
738 
739  pp_v = vecteur_mult(vect_new((Variable) nl, -1),
740  vect_new((Variable) p, 1));
741 
742  for(last_P->succ = pp_v; last_P->succ != NULL; last_P = last_P->succ) {}
743  }
744  }
745 
746  /* FP = F + (-P)
747  * We are sure that F-P can not be simplified, i.e. that there are similar
748  * monomes; this is because each monome of P has a variable that never
749  * appear outside of P.
750  */
751  FP = P;
752  last_P->succ = F;
753 
754  *L = local_l;
755  *count_lambdas = cl;
756  return(FP);
757 }
#define F
Definition: freia-utils.c:51
#define ENDP(l)
Test if a list is empty.
Definition: newgen_list.h:66
#define POP(l)
Modify a list pointer to point on the next element of the list.
Definition: newgen_list.h:59
#define NIL
The empty list (nil in Lisp)
Definition: newgen_list.h:47
#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
list gen_append(list l1, const list l2)
Definition: list.c:471
list base_to_list(Pbase base)
Most includes are centralized here.
#define D(A)
Definition: iabrev.h:56
Ppolynome vecteur_mult(Pvecteur v1, Pvecteur v2)
========================================================================
Definition: utils.c:2024
bool pu_is_inferior_var(Variable, Variable)
Ppolynome make_polynome(float coeff, Variable var, Value expo)
Ppolynome make_polynome(float coeff, Variable var, Value expo) PRIVATE allocates space for,...
Definition: pnome-alloc.c:100
Pbase polynome_used_var(Ppolynome pp, int *is_inferior_var)
Pbase polynome_used_var(Ppolynome pp, bool *is_inferior_var()) PRIVATE Returns, in a Pbase,...
Definition: pnome-reduc.c:204
#define LAMBD_COEFF
entity find_or_create_coeff(string prefix, int n)
========================================================================
Definition: utils.c:238
list prgm_parameter_l
lint
Definition: prgm_mapping.c:115
bool(* argh)(Pvecteur *, Pvecteur *)
========================================================================
Definition: utils.c:667
bool same_entity_p(entity e1, entity e2)
predicates on entities
Definition: entity.c:1321
#define ENTITY(x)
ENTITY.
Definition: ri.h:2755
Definition: pip__tab.h:30
Pvecteur vecteur
struct Spolynome * succ
The structure used to build lists in NewGen.
Definition: newgen_list.h:41
void * Variable
arithmetique is a requirement for vecteur, but I do not want to inforce it in all pips files....
Definition: vecteur-local.h:60
Pvecteur vect_new(Variable var, Value coeff)
Pvecteur vect_new(Variable var,Value coeff): allocation d'un vecteur colineaire au vecteur de base va...
Definition: alloc.c:110

References base_to_list(), CAR, CONS, D, ENDP, ENTITY, F, find_or_create_coeff(), gen_append(), LAMBD_COEFF, make_polynome(), NIL, polynome_used_var(), POP, prgm_parameter_l, pu_is_inferior_var(), same_entity_p(), Scontrainte::succ, Spolynome::succ, vect_new(), Scontrainte::vecteur, and vecteur_mult().

Referenced by valuer().

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

◆ communication_dim()

int communication_dim ( dataflow  df)

========================================================================

int communication_dim(dataflow df): returns the number of directions vectors of the dataflow if it a broadcast or a reduction. Oterwise, returns 0.

Definition at line 1116 of file utils.c.

1118 {
1119  communication com;
1120  predicate bp, rp;
1121  Psysteme ps;
1122  Pcontrainte pc;
1123  int dim = 0;
1124 
1125  com = dataflow_communication(df);
1126  if(com == communication_undefined)
1127  return(0);
1128 
1129  bp = communication_broadcast(com);
1130  rp = communication_reduction(com);
1131  if((bp == predicate_undefined) && (rp == predicate_undefined))
1132  return(0);
1133 
1134  if(bp == predicate_undefined)
1135  ps = (Psysteme) predicate_system(rp);
1136  else
1137  ps = (Psysteme) predicate_system(bp);
1138 
1139  for(pc = ps->egalites; pc != NULL; pc = pc->succ)
1140  dim++;
1141 
1142  return(dim);
1143 }
#define dataflow_communication(x)
Definition: paf_ri.h:346
#define communication_undefined
Definition: paf_ri.h:236
#define communication_reduction(x)
Definition: paf_ri.h:263
#define communication_broadcast(x)
Definition: paf_ri.h:261
#define predicate_undefined
Definition: ri.h:2046
#define predicate_system(x)
Definition: ri.h:2069
struct Ssysteme * Psysteme
Pcontrainte egalites
Definition: sc-local.h:70

References communication_broadcast, communication_reduction, communication_undefined, dataflow_communication, Ssysteme::egalites, predicate_system, predicate_undefined, and Scontrainte::succ.

Referenced by edge_weight().

+ Here is the caller graph for this function:

◆ compare_coeff()

bool compare_coeff ( chunk *  c1,
chunk *  c2 
)

========================================================================

bool compare_coeff(c1, c2):

returns a bool saying true if "c1" is before "c2" in the lexicographic order, else FALSE. "c1" and "c2" are entities, we compare their name.

Definition at line 161 of file utils.c.

163 {
164  return strcmp(entity_local_name((entity) c1),
165  entity_local_name((entity) c2))<0;
166 }
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

References entity_local_name().

Referenced by plc_make_vvs_with_vector(), and valuer().

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

◆ compare_dfs_weight()

bool compare_dfs_weight ( chunk *  d1,
chunk *  d2 
)

========================================================================

Definition at line 181 of file utils.c.

183 {
184  extern hash_table DtfToWgh;
185 
186  return( (int) hash_get(DtfToWgh, (char *) d1) >
187  (int) hash_get(DtfToWgh, (char *) d2) );
188 }
void * hash_get(const hash_table htp, const void *key)
this function retrieves in the hash table pointed to by htp the couple whose key is equal to key.
Definition: hash.c:449
hash_table DtfToWgh
Mapping from a dataflow to its distance.
Definition: prgm_mapping.c:105

References DtfToWgh, and hash_get().

Referenced by prgm_mapping().

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

◆ compare_nodes_dim()

bool compare_nodes_dim ( chunk *  n1,
chunk *  n2 
)

========================================================================

Definition at line 170 of file utils.c.

172 {
173  extern hash_table StmtToDim;
174 
175  return((int) hash_get(StmtToDim, (char *) vertex_int_stmt((vertex) n1)) >
176  (int) hash_get(StmtToDim, (char *) vertex_int_stmt((vertex) n2)) );
177 }
int vertex_int_stmt(vertex v)
===========================================================================
Definition: utils.c:866
hash_table StmtToDim
Mapping from a statement to the dim of its bdt.
Definition: prgm_mapping.c:109

References hash_get(), StmtToDim, and vertex_int_stmt().

Referenced by sort_dfg_node().

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

◆ compare_unks_frenq()

bool compare_unks_frenq ( chunk *  e1,
chunk *  e2 
)

========================================================================

Definition at line 192 of file utils.c.

194 {
195  extern hash_table UnkToFrenq;
196 
197  return( (int) hash_get(UnkToFrenq, (char *) e1) >
198  (int) hash_get(UnkToFrenq, (char *) e2) );
199 }
hash_table UnkToFrenq
Mapping from a stmt to its mu coeff.
Definition: prgm_mapping.c:112

References hash_get(), and UnkToFrenq.

Referenced by sort_unknowns().

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

◆ completer_base()

Psysteme completer_base ( Psysteme  sys,
list  var_l,
list  par_l 
)

========================================================================

Definition at line 832 of file utils.c.

835 {
836  Psysteme ps = sc_dup(sys), new_ps = sc_new();
837  int dim = gen_length(var_l) - sys->nb_eq;
838  list l;
839 
840  for(l = var_l; (!ENDP(l)) && (new_ps->nb_eq < dim); POP(l)) {
841  entity var = ENTITY(CAR(l));
842  Pvecteur pv = vect_new((Variable) var, 1);
843  Psysteme aux_ps = sc_dup(ps);
844  Psysteme aux_new_ps = sc_dup(new_ps);
845 
846  sc_add_egalite(aux_new_ps, contrainte_make(pv));
847  aux_ps = append_eg(aux_ps, aux_new_ps);
848 
849  if(vecteurs_libres_p(aux_ps, list_to_base(var_l), list_to_base(par_l))) {
850  new_ps = aux_new_ps;
851  }
852  else
853  sc_rm(aux_new_ps);
854  }
855  ps = append_eg(ps, new_ps);
856  ps->base = NULL;
857  sc_creer_base(ps);
858  return(ps);
859 }
Pcontrainte contrainte_make(Pvecteur pv)
Pcontrainte contrainte_make(Pvecteur pv): allocation et initialisation d'une contrainte avec un vecte...
Definition: alloc.c:73
size_t gen_length(const list l)
Definition: list.c:150
Pbase list_to_base(list l)
Pbase list_to_base(list l): returns the Pbase that contains the variables of list "l",...
bool vecteurs_libres_p(Psysteme sys, Pbase v_base, Pbase c_base)
========================================================================
Definition: utils.c:903
Psysteme append_eg(Psysteme M1, Psysteme M2)
========================================================================
Definition: utils.c:946
void sc_rm(Psysteme ps)
void sc_rm(Psysteme ps): liberation de l'espace memoire occupe par le systeme de contraintes ps;
Definition: sc_alloc.c:277
void sc_add_egalite(Psysteme p, Pcontrainte e)
void sc_add_egalite(Psysteme p, Pcontrainte e): macro ajoutant une egalite e a un systeme p; la base ...
Definition: sc_alloc.c:389
Psysteme sc_new(void)
Psysteme sc_new(): alloue un systeme vide, initialise tous les champs avec des valeurs nulles,...
Definition: sc_alloc.c:55
Psysteme sc_dup(Psysteme ps)
Psysteme sc_dup(Psysteme ps): should becomes a link.
Definition: sc_alloc.c:176
Pbase base
Definition: sc-local.h:75
int nb_eq
Definition: sc-local.h:72

References append_eg(), Ssysteme::base, CAR, contrainte_make(), ENDP, ENTITY, gen_length(), list_to_base(), POP, sc_add_egalite(), sc_creer_base(), sc_dup(), sc_new(), sc_rm(), vect_new(), and vecteurs_libres_p().

Referenced by broadcast_conditions(), and system_inversion_restrict().

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

◆ count_implicit_equation()

int count_implicit_equation ( Psysteme  ps)

========================================================================

int new_count_implicit_equation(Psysteme ps): returns the number of implicit equations there are in the system "ps".

Practically, we construct a system containing all the implicit equations, then we count the number of equations (there should be no redondant equation since find_implicit_equation() normalizes its result).

See the description of find_implicit_equation().

If impl_ps is empty, then no data are communicated

Definition at line 562 of file utils.c.

564 {
565  Psysteme impl_ps;
566 
567  if(ps == NULL)
568  return(0);
569 
570  impl_ps = find_implicit_equation(ps);
571 
572  /* If impl_ps is empty, then no data are communicated */
573  if(impl_ps == NULL)
574  return(ps->nb_ineq + ps->nb_eq);
575 
576  if(get_debug_level() > 6) {
577  fprintf(stderr, "Number of equations in Implicit system : %d\n", impl_ps->nb_eq);
578  }
579  return(impl_ps->nb_eq);
580 }
int get_debug_level(void)
GET_DEBUG_LEVEL returns the current debugging level.
Definition: debug.c:67
Psysteme find_implicit_equation(Psysteme ps)
========================================================================
Definition: utils.c:2350
int fprintf()
test sc_min : ce test s'appelle par : programme fichier1.data fichier2.data ...
int nb_ineq
Definition: sc-local.h:73

References find_implicit_equation(), fprintf(), get_debug_level(), and Ssysteme::nb_eq.

Referenced by edge_weight().

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

◆ di_polynome_var_subst_null()

void di_polynome_var_subst_null ( Ppolynome pp,
entity  var 
)

========================================================================

Definition at line 980 of file utils.c.

983 {
984  Ppolynome ppp, p = POLYNOME_UNDEFINED;
985  Pvecteur pv;
986 
987  for(ppp = *pp; ppp != NULL; ppp = ppp->succ) {
988  entity first = entity_undefined,
989  second = entity_undefined;
990  pv = (ppp->monome)->term;
991  for(; (pv != NULL) && (second == entity_undefined); pv = pv->succ) {
992  second = first;
993  first = (entity) pv->var;
994  }
995  if(pv != NULL)
996  pips_internal_error("Vecteur should contains 2 var");
997  else if(same_entity_p(first, var) || same_entity_p(second, var)) {
998  if(POLYNOME_UNDEFINED_P(p)) {
999  *pp = ppp->succ;
1000  }
1001  else
1002  p->succ = ppp->succ;
1003  }
1004  else
1005  p = ppp;
1006  }
1007 }
struct _newgen_struct_entity_ * entity
Definition: abc_private.h:14
static void term(Pproblem XX, int s, Value k, int x)
Definition: isolve.c:315
#define pips_internal_error
Definition: misc-local.h:149
#define POLYNOME_UNDEFINED
#define POLYNOME_UNDEFINED_P(pp)
#define entity_undefined
Definition: ri.h:2761
Pmonome monome
Variable var
Definition: vecteur-local.h:90
struct Svecteur * succ
Definition: vecteur-local.h:92

References entity_undefined, Spolynome::monome, pips_internal_error, POLYNOME_UNDEFINED, POLYNOME_UNDEFINED_P, same_entity_p(), Spolynome::succ, Svecteur::succ, term(), and Svecteur::var.

+ Here is the call graph for this function:

◆ diff_lists()

list diff_lists ( list  l1,
list  l2 
)

========================================================================

Definition at line 868 of file utils.c.

870 {
871  list l = NIL;
872 
873  if(l2 == NULL)
874  return(l1);
875 
876  for( ; !ENDP(l1); POP(l1)) {
877  chunk *c1 = CHUNK(CAR(l1));
878  bool found = false;
879  for(; (!ENDP(l2)) && (!found); POP(l2)) {
880  chunk *c2 = CHUNK(CAR(l2));
881  if(c1 == c2)
882  found = true;
883  }
884  if(!found)
885  l = gen_nconc(l, CONS(CHUNK, c1, NIL));
886  }
887  return(l);
888 }
#define CHUNK(x)
Definition: genC.h:90
list gen_nconc(list cp1, list cp2)
physically concatenates CP1 and CP2 but do not duplicates the elements
Definition: list.c:344

References CAR, CHUNK, CONS, ENDP, gen_nconc(), NIL, and POP.

+ Here is the call graph for this function:

◆ find_or_create_coeff()

entity find_or_create_coeff ( string  prefix,
int  n 
)

========================================================================

entity find_or_create_coeff(string prefix, int n): returns the entity that represent the coefficient numbered "n" and prefixed by "prefix". If it does not exist yet, we create it.

We create it, if it does not exist yet

Definition at line 238 of file utils.c.

241 {
242  string num, name;
243  entity new_coeff;
244 
245  num=int2a(n);
247  prefix, num, (char *) NULL));
248  new_coeff = gen_find_tabulated(name, entity_domain);
249 
250  /* We create it, if it does not exist yet */
251  if(new_coeff == entity_undefined)
252  new_coeff = make_coeff(prefix, n);
253 
254  free(num);
255  return(new_coeff);
256 }
static int num
Definition: bourdoncle.c:137
void free(void *)
#define MODULE_SEP_STRING
Definition: naming-local.h:30
string concatenate(const char *,...)
Return the concatenation of the given strings.
Definition: string.c:183
void * gen_find_tabulated(const char *, int)
Definition: tabulated.c:218
#define MAPPING_MODULE_NAME
entity make_coeff(string prefix, int n)
========================================================================
Definition: utils.c:209
static const char * prefix
#define entity_domain
newgen_syntax_domain_defined
Definition: ri.h:410
char * strdup()
char * int2a(int)
util.c
Definition: util.c:42

References concatenate(), entity_domain, entity_undefined, free(), gen_find_tabulated(), int2a(), make_coeff(), MAPPING_MODULE_NAME, MODULE_SEP_STRING, num, prefix, and strdup().

Referenced by apply_farkas(), put_source_ind(), and valuer().

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

◆ get_graph_dataflows()

list get_graph_dataflows ( graph  g)

========================================================================

list get_graph_dataflows(graph g): returns the list of dataflows of the DFG graph "g". Each edge of "g" contains a list of dataflows, so we concatenate these lists into one.

Definition at line 765 of file utils.c.

767 {
768  list l, su_l, g_dfs;
769 
770  g_dfs = NIL;
771  for(l = graph_vertices(g); !ENDP(l); POP(l)) {
772  for(su_l = vertex_successors(VERTEX(CAR(l))); !ENDP(su_l); POP(su_l)) {
773  list dfs = gen_append(SUCC_DATAFLOWS(SUCCESSOR(CAR(su_l))), NIL);
774  g_dfs = gen_nconc(g_dfs, dfs);
775  }
776  }
777 
778  return(g_dfs);
779 }
#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
#define SUCC_DATAFLOWS(s)

References CAR, ENDP, gen_append(), gen_nconc(), graph_vertices, NIL, POP, SUCC_DATAFLOWS, SUCCESSOR, VERTEX, and vertex_successors.

Referenced by prgm_mapping().

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

◆ get_stmt_index_coeff()

list get_stmt_index_coeff ( int  stmt,
hash_table  StoL 
)

========================================================================

Definition at line 792 of file utils.c.

795 {
796  list proto_lambda, prec, pl;
797 
798  proto_lambda = gen_append((list) hash_get(StoL, (char *) stmt), NIL);
799 
800  prec = NIL;
801  for(pl = proto_lambda; !ENDP(pl); POP(pl)) {
802  entity e = ENTITY(CAR(pl));
803  if(is_index_coeff_p(e))
804  prec = pl;
805  else
806  if(prec == NIL)
807  proto_lambda = CDR(proto_lambda);
808  else
809  CDR(prec) = CDR(pl);
810  }
811 
812  return(proto_lambda);
813 }
#define CDR(pcons)
Get the list less its first element.
Definition: newgen_list.h:111
bool is_index_coeff_p(entity e)
========================================================================
Definition: utils.c:144
static hash_table pl
properties are stored in this hash table (string -> property) for fast accesses.
Definition: properties.c:783
Definition: statement.c:54

References CAR, CDR, ENDP, ENTITY, gen_append(), hash_get(), is_index_coeff_p(), NIL, pl, and POP.

Referenced by broadcast_conditions().

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

◆ insert_sort()

list insert_sort ( list  l,
bool (*)()  compare_obj 
)

========================================================================

list insert_sort(list l, bool (*compare_obj)()): returns the result of sorting the list "l" using the comparison function "compare_obj". This bool function should retuns true if its first argument has to be placed before its second argument in the sorted list, else FALSE.

This is a generic function that accepts any homogene list of newgen objects. The comparison function must be coded by the user, its prototype should be: bool my_compare_obj(chunk * obj1, chunk * obj2);

This function uses the insert sort algorithm which has a mean and worst case complexity of n^2.

Definition at line 110 of file utils.c.

113 {
114  list al, aal, nl = NIL, nnl, nnl_q;
115  chunk * ngo, * aux_ngo;
116  bool not_inserted;
117 
118  for(al = l; al != NIL; al = CDR(al)) {
119  ngo = CHUNK(CAR(al));
120  not_inserted = true;
121  nnl = NIL;
122  nnl_q = nnl;
123 
124  for(aal = nl; (aal != NIL) && not_inserted ; aal = CDR(aal)) {
125  aux_ngo = CHUNK(CAR(aal));
126  if(compare_obj(ngo, aux_ngo)) {
127  nnl = gen_nconc(gen_nconc(nnl, CONS(CHUNK, ngo, NIL)), aal);
128  not_inserted = false;
129  }
130  else
131  nnl = gen_nconc(nnl, CONS(CHUNK, aux_ngo, NIL));
132  }
133  if(not_inserted)
134  nnl = gen_nconc(nnl, CONS(CHUNK, ngo, NIL));
135 
136  nl = nnl;
137  }
138 
139  return(nl);
140 }

References CAR, CDR, CHUNK, CONS, gen_nconc(), and NIL.

+ Here is the call graph for this function:

◆ is_broadcast_p()

bool is_broadcast_p ( dataflow  df)

========================================================================

bool is_broadcast_p(dataflow df): returns true if the dataflow "df" has a defined broadcast communication. Otherwise it returns FALSE.

Definition at line 1088 of file utils.c.

1090 {
1091  communication com;
1092  predicate bp;
1093  Psysteme ps;
1094 
1095  com = dataflow_communication(df);
1096  if(com == communication_undefined)
1097  return(false);
1098 
1099  bp = communication_broadcast(com);
1100  if(bp == predicate_undefined)
1101  return(false);
1102 
1103  ps = (Psysteme) predicate_system(bp);
1104  if(ps == NULL)
1105  return(false);
1106  else
1107  return(true);
1108 }

References communication_broadcast, communication_undefined, dataflow_communication, predicate_system, and predicate_undefined.

Referenced by broadcast_conditions(), and edge_weight().

+ Here is the caller graph for this function:

◆ is_index_coeff_p()

bool is_index_coeff_p ( entity  e)

========================================================================

Definition at line 144 of file utils.c.

146 {
147  if( (strncmp(entity_local_name(e), INDEX_COEFF, 1) == 0) ||
148  (strncmp(entity_local_name(e), MU_COEFF, 1) == 0) )
149  return(true);
150  else
151  return(false);
152 }
#define MU_COEFF
#define INDEX_COEFF

References entity_local_name(), INDEX_COEFF, and MU_COEFF.

Referenced by get_stmt_index_coeff(), partition_unknowns(), rm_non_x_var(), and sort_unknowns().

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

◆ is_reduction_p()

bool is_reduction_p ( dataflow  df)

========================================================================

bool is_reduction_p(dataflow df): returns true if the dataflow "df" has a defined reduction communication. Otherwise it returns FALSE.

Definition at line 1150 of file utils.c.

1152 {
1154  predicate bp;
1155  Psysteme ps;
1156 
1157  if(com == communication_undefined)
1158  return(false);
1159 
1160  bp = communication_reduction(com);
1161  if(bp == predicate_undefined)
1162  return(false);
1163 
1164  ps = (Psysteme) predicate_system(bp);
1165  if(ps == NULL)
1166  return(false);
1167  else
1168  return(true);
1169 }

References communication_reduction, communication_undefined, dataflow_communication, predicate_system, and predicate_undefined.

Referenced by edge_weight().

+ Here is the caller graph for this function:

◆ is_shift_p()

bool is_shift_p ( dataflow  df)

========================================================================

bool is_shift_p(dataflow df): returns true if the dataflow "df" has a defined shift communication. Otherwise it returns FALSE.

Definition at line 1176 of file utils.c.

1178 {
1180  predicate bp;
1181  Psysteme ps;
1182 
1183  if(com == communication_undefined)
1184  return(false);
1185 
1186  bp = communication_shift(com);
1187  if(bp == predicate_undefined)
1188  return(false);
1189 
1190  ps = (Psysteme) predicate_system(bp);
1191  if(ps == NULL)
1192  return(false);
1193  else
1194  return(true);
1195 }
#define communication_shift(x)
Definition: paf_ri.h:265

References communication_shift, communication_undefined, dataflow_communication, predicate_system, and predicate_undefined.

◆ make_coeff()

entity make_coeff ( string  prefix,
int  n 
)

========================================================================

entity make_coeff(string prefix, int n): returns a new entity which will be used as a coefficient in a prototype of a placement function. All coefficients differ in their name which is something like: "MAPPING:prefix#" where # is the integer value of "n".

Definition at line 209 of file utils.c.

212 {
213  string num, name;
214  entity new_coeff;
215 
216  num=int2a(n);
217 
219  prefix, num, (char *) NULL));
220 
221  new_coeff = make_entity(name,
224  NIL)),
227 
228  free(num);
229  return(new_coeff);
230 }
basic make_basic(enum basic_utype tag, void *val)
Definition: ri.c:155
storage make_storage(enum storage_utype tag, void *val)
Definition: ri.c:2273
value make_value(enum value_utype tag, void *val)
Definition: ri.c:2832
variable make_variable(basic a1, list a2, list a3)
Definition: ri.c:2895
type make_type(enum type_utype tag, void *val)
Definition: ri.c:2706
#define UU
Definition: newgen_types.h:98
#define make_entity(n, t, s, i)
@ is_basic_int
Definition: ri.h:571
@ is_value_unknown
Definition: ri.h:3035
@ is_storage_rom
Definition: ri.h:2494
@ is_type_variable
Definition: ri.h:2900

References concatenate(), free(), int2a(), is_basic_int, is_storage_rom, is_type_variable, is_value_unknown, make_basic(), make_entity, make_storage(), make_type(), make_value(), make_variable(), MAPPING_MODULE_NAME, MODULE_SEP_STRING, NIL, num, prefix, strdup(), and UU.

Referenced by find_or_create_coeff(), initialize_mu_list(), and plc_make_proto().

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

◆ my_substitute_var_with_vec()

void my_substitute_var_with_vec ( Psysteme  ps,
entity  var,
int  val,
Pvecteur  vec 
)

===========================================================================

void my_substitute_var_with_vec(Psysteme ps, entity var, int val, Pvecteur vec): Substitutes in a system ("ps") a variable ("var"), factor of a positive value ("val"), by an expression ("vec").

This substitution is done on all assertions of the system (equalities and inequalities). For each assertion (represented by a vector Vold) we have:

 Vold = c*var + Vaux
 val*var = vec

Vnew represents the new assertion. With: p = gcd(c, val) >= 1, we have:

 Vnew = (c/p)*vec + (val/p)*Vaux = (c/p)*vec + (val/p)*(Vold - c*var)

Note: we have: Vold == 0 <=> (val/p)*Vold == 0 Vold > 0 <=> (val/p)*Vold > 0 ...

because "val" is positive.

If we want to substitute a NULL vector, we just erase "Var"

"val" must be positive.

Vnew = (c/p)*vec + (val/p)*Vaux = (c/p)*vec + (val/p)*(Vold - c*var)

Definition at line 1219 of file utils.c.

1224 {
1225  Variable Var = (Variable) var;
1227 
1228  if(get_debug_level() > 8) {
1229 fprintf(stderr, "\t\t\tAvant Sub: \n");
1230 fprint_psysteme(stderr, ps);
1231 fprintf(stderr, "\n");
1232  }
1233 
1234  /* If we want to substitute a NULL vector, we just erase "Var" */
1235  if(VECTEUR_NUL_P(vec)) {
1236  for(assert = ps->egalites; assert != NULL; assert = assert->succ) {
1237  Pvecteur v_old = assert->vecteur;
1238  vect_erase_var(&v_old, Var);
1239  }
1240  for(assert = ps->inegalites; assert != NULL; assert = assert->succ) {
1241  Pvecteur v_old = assert->vecteur;
1242  vect_erase_var(&v_old, Var);
1243  }
1244  }
1245 
1246  /* "val" must be positive. */
1247  if(val < 0) {
1248  val = 0-val;
1249  vect_chg_sgn(vec);
1250  }
1251 
1252  /* Vnew = (c/p)*vec + (val/p)*Vaux = (c/p)*vec + (val/p)*(Vold - c*var) */
1253  for(assert = ps->egalites; assert != NULL; assert = assert->succ) {
1254  Pvecteur v_old = assert->vecteur;
1255  int coeff = vect_coeff(Var, v_old);
1256  if(coeff != 0) {
1257  int p = pgcd(coeff, val);
1258 
1259  assert->vecteur = vect_cl2_ofl_ctrl(coeff/p, vec,
1260  val/p,
1261  vect_cl2_ofl_ctrl(1, v_old, -1,
1262  vect_new(Var,
1263  coeff),
1264  NO_OFL_CTRL),
1265  NO_OFL_CTRL);
1266  }
1267  }
1268  for(assert = ps->inegalites; assert != NULL; assert = assert->succ) {
1269  Pvecteur v_old = assert->vecteur;
1270  int coeff = vect_coeff(Var, v_old);
1271  if(coeff != 0) {
1272  int p = pgcd(coeff, val);
1273 
1274  assert->vecteur = vect_cl2_ofl_ctrl(coeff/p, vec,
1275  val/p,
1276  vect_cl2_ofl_ctrl(1, v_old, -1,
1277  vect_new(Var,
1278  coeff),
1279  NO_OFL_CTRL),
1280  NO_OFL_CTRL);
1281  }
1282  }
1283  vect_rm((Pvecteur) ps->base);
1284  ps->base = (Pbase) NULL;
1285  sc_creer_base(ps);
1286 
1287  if(get_debug_level() > 8) {
1288 fprintf(stderr, "\t\t\tApres Sub: \n");
1289 fprint_psysteme(stderr, ps);
1290 fprintf(stderr, "\n");
1291  }
1292 
1293 }
#define pgcd(a, b)
Pour la recherche de performance, selection d'une implementation particuliere des fonctions.
#define assert(ex)
Definition: newgen_assert.h:41
void fprint_psysteme(FILE *, Psysteme)
===========================================================================
Definition: print.c:302
void vect_chg_sgn(Pvecteur v)
void vect_chg_sgn(Pvecteur v): multiplie v par -1
Definition: scalaires.c:151
Pcontrainte inegalites
Definition: sc-local.h:71
#define NO_OFL_CTRL
struct Svecteur * Pbase
#define VECTEUR_NUL_P(v)
Pvecteur vect_cl2_ofl_ctrl(Value x1, Pvecteur v1, Value x2, Pvecteur v2, int ofl_ctrl)
Pvecteur vect_cl2_ofl(Value x1, Pvecteur v1, Value x2, Pvecteur v2): allocation d'un vecteur v dont l...
Definition: binaires.c:204
void vect_erase_var(Pvecteur *ppv, Variable v)
void vect_erase_var(Pvecteur * ppv, Variable v): projection du vecteur *ppv selon la direction v (i....
Definition: unaires.c:106
Value vect_coeff(Variable var, Pvecteur vect)
Variable vect_coeff(Variable var, Pvecteur vect): coefficient de coordonnee var du vecteur vect —> So...
Definition: unaires.c:228

References assert, fprint_psysteme(), fprintf(), get_debug_level(), NO_OFL_CTRL, pgcd, sc_creer_base(), vect_chg_sgn(), vect_cl2_ofl_ctrl(), vect_coeff(), vect_erase_var(), vect_new(), vect_rm(), and VECTEUR_NUL_P.

Referenced by plc_elim_var_with_eg().

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

◆ new_elim_var_with_eg()

Psysteme new_elim_var_with_eg ( Psysteme  ps,
list init_l,
list elim_l 
)

========================================================================

Psysteme new_elim_var_with_eg(Psysteme ps, list *init_l, list *elim_l): Computes the gaussian elimination of variables in the system "ps". The modifications are directly done on "ps".

However, we keep all the eliminated equations in "sc_elim", and return that system.

Initially, "init_l" gives the list of variables that can be eliminated, at the end, it only contains the variables that were not eliminated. We take the order of this list in our process of eliminating.

Initially, "elim_l" is empty, at the end it contains the variables that were eliminated.

During the computation, we modify *init_l, so we duplicate it. We use "el" not *elim_l, which should be empty at the beginning.

si eq etait en tete il faut l'enlever de la liste, sinon, eq a ete enleve dans la fonction contrainte_var_min_coeff().

Definition at line 338 of file utils.c.

341 {
342  Psysteme sc_elim = sc_new();
343 
344  /* During the computation, we modify *init_l, so we duplicate it.
345  * We use "el" not *elim_l, which should be empty at the beginning.
346  */
347  list vl = gen_append(*init_l, NIL),
348  el = NIL,
349  l;
350  Pcontrainte eq, eg;
351 
352  for(l = vl; !ENDP(l); POP(l)) {
353  Variable v = (Variable) ENTITY(CAR(l));
354  Value coeff;
355 
356  if ((eq = contrainte_var_min_coeff(ps->egalites,v, &coeff, true))
357  != NULL) {
358 
359  if(get_debug_level() > 7) {
360 fprintf(stderr, "System is :");
361 fprint_psysteme(stderr, ps);
362 fprintf(stderr, "\t\tElim var %s in equation:", entity_local_name((entity) v));
363 pu_vect_fprint(stderr, eq->vecteur);
364 fprintf(stderr, "\n");
365  }
366 
367  if(!egalite_normalize(eq))
368  pips_internal_error("Egalite bizarre");
369 
370  sc_nbre_egalites(ps)--;
371  if (eq == (ps->egalites)) ps->egalites = eq->succ;
372  /* si eq etait en tete il faut l'enlever de la liste, sinon, eq a
373  ete enleve dans la fonction contrainte_var_min_coeff(). */
374 
375  for(eg = ps->egalites; eg != NULL; eg = eg->succ)
376  (void) contrainte_subst_ofl_ctrl(v, eq, eg, true, NO_OFL_CTRL);
377  for(eg = ps->inegalites; eg != NULL; eg = eg->succ)
378  (void) contrainte_subst_ofl_ctrl(v, eq, eg, false, NO_OFL_CTRL);
379 
380  for(eg = sc_elim->egalites; eg != NULL; eg = eg->succ)
381  (void) contrainte_subst_ofl_ctrl(v, eq, eg, true, NO_OFL_CTRL);
382  for(eg = sc_elim->inegalites; eg != NULL; eg = eg->succ)
383  (void) contrainte_subst_ofl_ctrl(v, eq, eg, false, NO_OFL_CTRL);
384 
385  sc_add_egalite(sc_elim, eq);
386  gen_remove(init_l, (chunk *) v);
387  el = CONS(ENTITY, (entity) v, el);
388  }
389  }
390 
391  *elim_l = el;
392  sc_elim->base = NULL;
393  sc_creer_base(sc_elim);
394 
395  if(get_debug_level() > 6) {
396 fprintf(stderr, "[new_elim_var_with_eg] Results:\n");
397 fprintf(stderr, "Elim sys:\n");
398 fprint_entity_list(stderr, el);
399 fprint_psysteme(stderr, sc_elim);
400 fprintf(stderr, "Remnants sys:\n");
401 fprint_entity_list(stderr, *init_l);
402 fprint_psysteme(stderr, ps);
403 fprintf(stderr, "\n");
404  }
405 
406  return(sc_elim);
407 }
int Value
int contrainte_subst_ofl_ctrl(Variable v, Pcontrainte def, Pcontrainte c, bool eq_p, int ofl_ctrl)
int contrainte_subst_ofl_ctrl(Variable v, Pcontrainte def, Pcontrainte c Boolean eq_p,...
Definition: binaires.c:107
Pcontrainte contrainte_var_min_coeff(Pcontrainte, Variable, Value *, bool)
Pcontrainte contrainte_var_min_coeff(Pcontrainte contraintes, Variable v, int *coeff) input : a list ...
Definition: unaires.c:345
bool egalite_normalize(Pcontrainte)
bool egalite_normalize(Pcontrainte eg): reduction d'une equation diophantienne par le pgcd de ses coe...
Definition: normalize.c:136
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
void fprint_entity_list(FILE *fp, list l)
void fprint_entity_list(FILE *fp,list l): prints a list of entities on file fp.
Definition: entity.c:3188
void pu_vect_fprint(FILE *, Pvecteur)
===========================================================================
Definition: print.c:446
Pcontrainte eq
element du vecteur colonne du systeme donne par l'analyse
Definition: sc_gram.c:108

References Ssysteme::base, CAR, CONS, contrainte_subst_ofl_ctrl(), contrainte_var_min_coeff(), egalite_normalize(), Ssysteme::egalites, ENDP, ENTITY, entity_local_name(), eq, fprint_entity_list(), fprint_psysteme(), fprintf(), gen_append(), gen_remove(), get_debug_level(), Ssysteme::inegalites, NIL, NO_OFL_CTRL, pips_internal_error, POP, pu_vect_fprint(), sc_add_egalite(), sc_creer_base(), sc_new(), Scontrainte::succ, and Scontrainte::vecteur.

+ Here is the call graph for this function:

◆ nullify_factors()

Psysteme nullify_factors ( Ppolynome pp,
list  var_l,
bool  with_remnants 
)

========================================================================

For each variable, we nullify its factor in the polynome.

We get the current variable.

We get its factor in the polynome.

We add a new equality in the system.

We delete the occurences of this variable in the polynome.

The remnants are zero out and are added as one equation.

Definition at line 1026 of file utils.c.

1030 {
1031  Ppolynome aux_pp = *pp;
1032  Psysteme new_ps = sc_new();
1033  list l;
1034 
1035  if(get_debug_level() > 4) {
1036  fprintf(stderr, "[nullify_factors] polynome is :");
1038  fprintf(stderr, "\n");
1039  }
1040 
1041  if(!POLYNOME_NUL_P(aux_pp)) {
1042 
1043  /* For each variable, we nullify its factor in the polynome. */
1044  for(l = var_l; l != NIL; l = CDR(l)) {
1045  /* We get the current variable. */
1046  entity var = ENTITY(CAR(l));
1047 
1048  /* We get its factor in the polynome. */
1049  Pvecteur pv_fac = prototype_factorize(aux_pp, (Variable) var);
1050 
1051  if(get_debug_level() > 5) {
1052  fprintf(stderr, "[nullify_factors] factor is :");
1053  pu_vect_fprint(stderr, pv_fac);
1054  fprintf(stderr, "\n");
1055  }
1056 
1057  if(!VECTEUR_NUL_P(pv_fac)) {
1058  /* We add a new equality in the system. */
1059  sc_add_egalite(new_ps, contrainte_make(pv_fac));
1060 
1061  /* We delete the occurences of this variable in the polynome. */
1062  aux_pp = prototype_var_subst(aux_pp, (Variable) var, POLYNOME_NUL);
1063  }
1064  }
1065 
1066  if( (with_remnants) && (!POLYNOME_NUL_P(aux_pp)) )
1067  /* The remnants are zero out and are added as one equation. */
1068  sc_add_egalite(new_ps, polynome_to_contrainte(aux_pp));
1069 
1070  if(get_debug_level() > 4) {
1071  fprintf(stderr, "[nullify_factors] final new sys :");
1072  fprint_psysteme(stderr, new_ps);
1073  fprintf(stderr, "\n");
1074  }
1075 
1076  sc_creer_base(new_ps);
1077  sc_normalize(new_ps);
1078  *pp = aux_pp;
1079  }
1080  return(new_ps);
1081 }
Ppolynome prototype_var_subst(Ppolynome pp, Variable var, Ppolynome ppsubst)
=================================================================
Definition: utils.c:1978
Pvecteur prototype_factorize(Ppolynome pp, Variable var)
========================================================================
Definition: utils.c:2070
Pcontrainte polynome_to_contrainte(Ppolynome pp)
========================================================================
Definition: utils.c:1095
const char * pu_variable_name(Variable)
package mapping : Alexis Platonoff, april 1993
Definition: print.c:421
void polynome_fprint(FILE *fd, Ppolynome pp, char *(*variable_name)(Variable), int *is_inferior_var)
void polynome_fprint(FILE* fd, Ppolynome pp, char* (*variable_name)(), bool (*is_inferior_var)()) Out...
Definition: pnome-io.c:173
#define POLYNOME_NUL
#define POLYNOME_NUL_P(pp)
Psysteme sc_normalize(Psysteme ps)
Psysteme sc_normalize(Psysteme ps): normalisation d'un systeme d'equation et d'inequations lineaires ...

References CAR, CDR, contrainte_make(), ENTITY, fprint_psysteme(), fprintf(), get_debug_level(), NIL, polynome_fprint(), POLYNOME_NUL, POLYNOME_NUL_P, polynome_to_contrainte(), prototype_factorize(), prototype_var_subst(), pu_is_inferior_var(), pu_variable_name(), pu_vect_fprint(), sc_add_egalite(), sc_creer_base(), sc_new(), sc_normalize(), and VECTEUR_NUL_P.

Referenced by cutting_conditions(), and valuer().

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

◆ old_prototype_factorize()

Pvecteur old_prototype_factorize ( Ppolynome  pp,
Variable  var 
)

========================================================================

Definition at line 1300 of file utils.c.

1303 {
1304  Pvecteur pv = NULL;
1305 
1306  if(POLYNOME_NUL_P(pp))
1307  pv = VECTEUR_NUL;
1308  else if(var == TCST)
1309  pv = vect_new(TCST, (int) polynome_TCST(pp));
1310  else {
1311  Ppolynome ppp;
1312 
1313  for(ppp = pp; ppp != NULL; ppp = ppp->succ) {
1314  Variable newvar = VARIABLE_UNDEFINED;
1315  int newval;
1316  Pvecteur vec, newpv;
1317  entity first = entity_undefined, second = entity_undefined;
1318  bool factor_found = true;
1319 
1320  vec = (ppp->monome)->term;
1321  for(; (vec != NULL) && (second == entity_undefined); vec = vec->succ) {
1322  second = first;
1323  first = (entity) vec->var;
1324  }
1325  if(vec != NULL)
1326  pips_internal_error("Vecteur should contains 2 var");
1327  else if(same_entity_p(first, (entity) var))
1328  if(second == entity_undefined)
1329  newvar = TCST;
1330  else
1331  newvar = (Variable) second;
1332  else if(same_entity_p(second, (entity) var))
1333  newvar = (Variable) first;
1334  else
1335  factor_found = false;
1336 
1337  if(factor_found) {
1338  newval = (int) (ppp->monome)->coeff;
1339  newpv = vect_new(newvar, newval);
1340  newpv->succ = pv;
1341  pv = newpv;
1342  }
1343  }
1344  }
1345 
1346  return(pv);
1347 }
void const char const char const int
float polynome_TCST(Ppolynome pp)
float polynome_TCST(Ppolynome pp) returns the constant term of polynomial pp.
Definition: pnome-reduc.c:156
#define TCST
VARIABLE REPRESENTANT LE TERME CONSTANT.
#define VECTEUR_NUL
DEFINITION DU VECTEUR NUL.
#define VARIABLE_UNDEFINED
Definition: vecteur-local.h:64

References entity_undefined, int, Spolynome::monome, pips_internal_error, POLYNOME_NUL_P, polynome_TCST(), same_entity_p(), Spolynome::succ, Svecteur::succ, TCST, term(), Svecteur::var, VARIABLE_UNDEFINED, vect_new(), and VECTEUR_NUL.

+ Here is the call graph for this function:

◆ plc_elim_var_with_eg()

Psysteme plc_elim_var_with_eg ( Psysteme  ps,
list init_l,
list elim_l 
)

========================================================================

Psysteme plc_elim_var_with_eg(Psysteme ps, list *init_l, list *elim_l): Computes the gaussian elimination of variables in the system "ps". The modifications are directly done on "ps".

However, we keep all the eliminated equations in "sc_elim", and return that system.

Initially, "init_l" gives the list of variables that can be eliminated, at the end, it only contains the variables that were not eliminated. We take the order of this list in our process of eliminating.

Initially, "elim_l" is empty, at the end it contains the variables that were eliminated.

We use "vl" during the computation, not *init_l

We use "el" during the computation, not *elim_l

This elimination works only on equalities. While there remains equalities, we can eliminate variables.

We look, in vl (i.e. init_l), for a variable that we can eliminate in ve, i.e. with a coefficient equal to 1 or -1.

If we get such a variable, we eliminate it.

First, we remove it from "vl".

Then, we add it to "el".

We keep a copy of the initial vector.

We compute the expression (pv_elim) by which we are going to substitute our variable (var):

We have: var = pv_elim

The equality is: V = 0, with: V = val*var + Vaux, and: val in {-1,1}

So, we have: pv_elim = -val*Vaux, with: Vaux = V - val*var

So: pv_elim = -val(V - val*var) i.e.: pv_elim = -val+V + (val^2)*var but: val in {-1,1}, so: val^2 = 1

so: pv_elim = -val*V + var

We substitute var by its value (pv_elim) in "ps".

We substitute var by its value (pv_elim) in "sc_elim".

The initial equality is added to "sc_elim".

We reinitialize the list of equalities.

Else, we try on the next equality.

Definition at line 426 of file utils.c.

429 {
430  bool var_not_found;
431  Psysteme sc_elim = sc_new();
432  Pcontrainte eqs;
433  Pvecteur ve, pv_elim;
434  entity crt_var = entity_undefined;
435  int crt_val = 0;
436  list vl = *init_l, /* We use "vl" during the computation, not *init_l */
437  el = NIL, /* We use "el" during the computation, not *elim_l */
438  l;
439 
440  /* This elimination works only on equalities. While there remains equalities,
441  * we can eliminate variables.
442  */
443  eqs = ps->egalites;
444  while(eqs != NULL)
445  {
446  ve = eqs->vecteur;
447 
448  if(get_debug_level() > 8) {
449 fprintf(stderr, "System is :");
450 fprint_psysteme(stderr, ps);
451 fprintf(stderr, "\t\tConsidered Vect :");
452 pu_vect_fprint(stderr, ve);
453 fprintf(stderr, "\n");
454  }
455 
456  /* We look, in vl (i.e. init_l), for a variable that we can eliminate in
457  * ve, i.e. with a coefficient equal to 1 or -1.
458  */
459  var_not_found = true;
460  for(l = vl ; (l != NIL) && var_not_found; l = CDR(l)) {
461  crt_var = ENTITY(CAR(l));
462  crt_val = (int) vect_coeff((Variable) crt_var, ve);
463  if((crt_val == 1) || (crt_val == -1))
464  var_not_found = false;
465  }
466 
467  /* If we get such a variable, we eliminate it. */
468  if(! var_not_found)
469  {
470  Pvecteur init_vec;
471 
472  /* First, we remove it from "vl". */
473  gen_remove(&vl, (chunk *) crt_var);
474 
475  /* Then, we add it to "el". */
476  el = CONS(ENTITY, crt_var, el);
477 
478  /* We keep a copy of the initial vector. */
479  init_vec = vect_dup(eqs->vecteur);
480 
481  /* We compute the expression (pv_elim) by which we are going to
482  * substitute our variable (var):
483  *
484  * We have: var = pv_elim
485  *
486  * The equality is: V = 0, with: V = val*var + Vaux, and: val in {-1,1}
487  *
488  * So, we have: pv_elim = -val*Vaux, with: Vaux = V - val*var
489  *
490  * So: pv_elim = -val(V - val*var)
491  * i.e.: pv_elim = -val+V + (val^2)*var
492  * but: val in {-1,1}, so: val^2 = 1
493  *
494  * so: pv_elim = -val*V + var
495  *
496  */
497  pv_elim = vect_cl2_ofl_ctrl((crt_val)*(-1), eqs->vecteur,
498  1, vect_new((Variable) crt_var, 1),
499  NO_OFL_CTRL);
500 
501  if(get_debug_level() > 7) {
502 fprintf(stderr, "\t\tElim with %s = ", entity_local_name(crt_var));
503 pu_vect_fprint(stderr, pv_elim);
504 fprintf(stderr, "\n");
505  }
506 
507  /* We substitute var by its value (pv_elim) in "ps". */
508  my_substitute_var_with_vec(ps, crt_var, 1, vect_dup(pv_elim));
509 
510  /* We substitute var by its value (pv_elim) in "sc_elim". */
511  my_substitute_var_with_vec(sc_elim, crt_var, 1, vect_dup(pv_elim));
512 
513  ps = sc_normalize(ps);
514  vect_rm(pv_elim);
515 
516  if(get_debug_level() > 7) {
517 fprintf(stderr, "New System is :");
518 fprint_psysteme(stderr, ps);
519  }
520 
521  /* The initial equality is added to "sc_elim". */
522  sc_add_egalite(sc_elim, contrainte_make(init_vec));
523 
524 
525  /* We reinitialize the list of equalities. */
526  eqs = ps->egalites;
527  }
528  /* Else, we try on the next equality. */
529  else
530  eqs = eqs->succ;
531  }
532  *init_l = vl;
533  *elim_l = el;
534  sc_elim->base = NULL;
535  sc_creer_base(sc_elim);
536 
537  if(get_debug_level() > 6) {
538 fprintf(stderr, "[plc_elim_var_with_eg] Results:\n");
539 fprintf(stderr, "Elim sys:\n");
540 fprint_entity_list(stderr, el);
541 fprint_psysteme(stderr, sc_elim);
542 fprintf(stderr, "Remnants sys:\n");
543 fprint_entity_list(stderr, vl);
544 fprint_psysteme(stderr, ps);
545 fprintf(stderr, "\n");
546  }
547 
548  return(sc_elim);
549 }
void my_substitute_var_with_vec(Psysteme ps, entity var, int val, Pvecteur vec)
===========================================================================
Definition: utils.c:1219
Pvecteur vect_dup(Pvecteur v_in)
Pvecteur vect_dup(Pvecteur v_in): duplication du vecteur v_in; allocation de et copie dans v_out;.
Definition: alloc.c:51

References Ssysteme::base, CAR, CDR, CONS, contrainte_make(), ENTITY, entity_local_name(), entity_undefined, fprint_entity_list(), fprint_psysteme(), fprintf(), gen_remove(), get_debug_level(), int, my_substitute_var_with_vec(), NIL, NO_OFL_CTRL, pu_vect_fprint(), sc_add_egalite(), sc_creer_base(), sc_new(), sc_normalize(), Scontrainte::succ, vect_cl2_ofl_ctrl(), vect_coeff(), vect_dup(), vect_new(), vect_rm(), and Scontrainte::vecteur.

+ Here is the call graph for this function:

◆ put_source_ind()

list put_source_ind ( list  le)

========================================================================

list put_source_ind(list le): returns a list of expressions computed from the list given in argument ("le").

We want to associate a variable (var) to each expression (exp) in order to have some kind of equality : 0 = exp - var which means in fact : var = exp

The name of the variables are not important, however, we need a different variable for each expression.

Note: the variables are entities.

This counter makes sure that each new variable is different for the preceding one.

The resulting list is initialized to NIL.

For each expression we compute the new expression.

We get a new variable (an entity).

We make the new expression : exp - var.

This expression is added to the new list. The order is kept.

Definition at line 596 of file utils.c.

598 {
599  int count = 1; /* This counter makes sure that each new variable is different
600  * for the preceding one.
601  */
602  expression texp, new_texp;
603  entity en;
604  list l,
605  new_le = NIL; /* The resulting list is initialized to NIL. */
606 
607  /* For each expression we compute the new expression. */
608  for(l = le; l != NIL; l = CDR(l), count++)
609  {
610  normalized nor;
611 
612  /* We get a new variable (an entity). */
614 
615  texp = EXPRESSION(CAR(l));
616  NORMALIZE_EXPRESSION(texp);
617  nor = expression_normalized(texp);
618 
620  Pvecteur pv = normalized_linear(nor);
621  pv = vect_cl_ofl_ctrl(pv, -1, vect_new((Variable) en, 1), NO_OFL_CTRL);
622  new_texp = make_vecteur_expression(pv);
623  }
624  else {
625  /* We make the new expression : exp - var. */
626  new_texp = make_op_exp(MINUS_OPERATOR_NAME,
627  texp, make_entity_expression(en, NIL));
628  }
629 
630  /* This expression is added to the new list. The order is kept. */
631  new_le = gen_nconc(new_le, CONS(EXPRESSION, new_texp, NIL));
632  }
633  return(new_le);
634 }
static int count
Definition: SDG.c:519
#define INDEX_VARIA
#define MINUS_OPERATOR_NAME
#define NORMALIZE_EXPRESSION(e)
expression make_vecteur_expression(Pvecteur pv)
make expression for vector (Pvecteur)
Definition: expression.c:1650
expression make_entity_expression(entity e, cons *inds)
Definition: expression.c:176
expression make_op_exp(char *op_name, expression exp1, expression exp2)
================================================================
Definition: expression.c:2012
#define EXPRESSION(x)
EXPRESSION.
Definition: ri.h:1217
#define normalized_tag(x)
Definition: ri.h:1778
#define expression_normalized(x)
Definition: ri.h:1249
#define normalized_linear(x)
Definition: ri.h:1781
@ is_normalized_linear
Definition: ri.h:1760
Pvecteur vect_cl_ofl_ctrl(Pvecteur v, Value lambda, Pvecteur u, int ofl_ctrl)
Pvecteur vect_cl_ofl_ctrl(Pvecteur v, Value lambda, Pvecteur u, int ofl_ctrl): etape d'acculumulation...
Definition: binaires.c:128

References CAR, CDR, CONS, count, EXPRESSION, expression_normalized, find_or_create_coeff(), gen_nconc(), INDEX_VARIA, is_normalized_linear, make_entity_expression(), make_op_exp(), make_vecteur_expression(), MINUS_OPERATOR_NAME, NIL, NO_OFL_CTRL, NORMALIZE_EXPRESSION, normalized_linear, normalized_tag, vect_cl_ofl_ctrl(), and vect_new().

Referenced by edge_weight().

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

◆ rm_non_x_var()

list rm_non_x_var ( list  l)

========================================================================

Definition at line 260 of file utils.c.

262 {
263  list prec, aux_l;
264 
265 if(get_debug_level() > 6) {
266 fprintf(stderr, "\n[rm_non_x_var] Bases de depart :\n");
267 fprint_entity_list(stderr, l);
268 fprintf(stderr, "\n");
269 }
270 
271  prec = NIL;
272  for(aux_l = l; !ENDP(aux_l); POP(aux_l)) {
273  entity crt_var = ENTITY(CAR(aux_l));
274  if(!is_index_coeff_p(crt_var)) {
275  if(prec == NIL)
276  l = CDR(l);
277  else
278  CDR(prec) = CDR(aux_l);
279  }
280  else
281  prec = aux_l;
282  }
283 
284 if(get_debug_level() > 6) {
285 fprintf(stderr, "\n[rm_non_x_var] Base d'arrivee :\n");
286 fprint_entity_list(stderr, l);
287 fprintf(stderr, "\n");
288 }
289 
290  return(l);
291 }

References CAR, CDR, ENDP, ENTITY, fprint_entity_list(), fprintf(), get_debug_level(), is_index_coeff_p(), NIL, and POP.

+ Here is the call graph for this function:

◆ unify_lists()

list unify_lists ( list  l1,
list  l2 
)

========================================================================

Definition at line 295 of file utils.c.

297 {
298  list l;
299 
300  if(l1 == NULL)
301  l = gen_append(l2, NIL);
302  else {
303  l = gen_append(l1, NIL);
304 
305  for(; !ENDP(l2); POP(l2)) {
306  chunk * c2 = CHUNK(CAR(l2));
307  bool found = false;
308  for(; (!ENDP(l1)) && (!found); POP(l1)) {
309  chunk *c1 = CHUNK(CAR(l1));
310  if(c1 == c2)
311  found = true;
312  }
313  if(! found)
314  gen_nconc(l, CONS(CHUNK, c2, NIL));
315  }
316  }
317 
318  return(l);
319 }

References CAR, CHUNK, CONS, ENDP, gen_append(), gen_nconc(), NIL, and POP.

+ Here is the call graph for this function:

◆ vecteurs_libres_p()

bool vecteurs_libres_p ( Psysteme  sys,
Pbase  v_base,
Pbase  c_base 
)

========================================================================

add 1, because of the TCST

Definition at line 903 of file utils.c.

906 {
907  int n, m1, m2, r;
908  Value det_p, det_q;
909  matrice A, B, P, H, Q;
910 
911  n = sys->nb_eq;
912  m1 = base_dimension(v_base);
913 
914  if(m1 < n)
915  return(false);
916 
917  m2 = base_dimension(c_base) + 1; /* add 1, because of the TCST */
918  A = matrice_new(n,m1);
919  B = matrice_new(n,m2);
920 
922  A,B,n,m1,m2);
923 
924  P = matrice_new(n,n);
925  Q = matrice_new(m1,m1);
926  H = matrice_new(n,m1);
927  matrice_hermite(A, n, m1, P, H, Q, &det_p, &det_q);
928 
929  r = matrice_hermite_rank(H, n, m1);
930 
931  matrice_free(A);
932  matrice_free(B);
933  matrice_free(P);
934  matrice_free(Q);
935  matrice_free(H);
936 
937  return(r == n);
938 }
#define A(i, j)
comp_matrice.c
Definition: comp_matrice.c:63
#define B(A)
Definition: iabrev.h:61
#define matrice_free(m)
Definition: matrice-local.h:78
#define matrice_new(n, m)
Allocation et desallocation d'une matrice.
Definition: matrice-local.h:77
Value * matrice
package matrice
Definition: matrice-local.h:71
int matrice_hermite_rank(matrice a, int n, int m __attribute__((unused)))
int matrice_hermite_rank(matrice a, int n, int m): rang d'une matrice en forme de hermite
Definition: hermite.c:178
void matrice_hermite(Value *MAT, int n, int m, Value *P, Value *H, Value *Q, Value *det_p, Value *det_q)
package matrice
Definition: hermite.c:78
void contraintes_with_sym_cst_to_matrices(Pcontrainte pc, Pbase index_base, Pbase const_base, matrice A, matrice B, int n, int m1, int m2)
Creation de la matrice A correspondant au systeme lineaire et de la matrice correspondant a la partie...
Definition: utils.c:446
#define Q
Definition: pip__type.h:39
Definition: pip__tab.h:25
#define base_dimension(b)

References A, B, base_dimension, contraintes_with_sym_cst_to_matrices(), matrice_free, matrice_hermite(), matrice_hermite_rank(), matrice_new, and Q.

Referenced by base_complete(), broadcast_conditions(), completer_base(), completer_n_base(), mapping_on_broadcast(), prepare_reindexing(), and stmt_bdt_directions().

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

Variable Documentation

◆ prgm_parameter_l

list prgm_parameter_l
extern

lint

Name : utils.c Package : prgm_mapping Author : Alexis Platonoff Date : 23 september 1993

Historic :

Documents:

Comments : This file contains useful functions used for the computation of prgm_mapping. Ansi includes
Newgen includes
C3 includes
Pips includes
Useful constants Macro functions
Global variables

lint

Definition at line 115 of file prgm_mapping.c.

Referenced by apply_farkas(), cutting_conditions(), partial_broadcast_coefficients(), plc_make_proto(), prgm_mapping(), and valuer().

◆ vcid_prgm_mapping_utils

char vcid_prgm_mapping_utils[] = "$Id: utils.c 23065 2016-03-02 09:05:50Z coelho $"

Definition at line 29 of file utils.c.