PIPS
vectransform.c
Go to the documentation of this file.
1 /*
2 
3  $Id: vectransform.c 23065 2016-03-02 09:05:50Z coelho $
4 
5  Copyright 1989-2016 MINES ParisTech
6 
7  This file is part of PIPS.
8 
9  PIPS is free software: you can redistribute it and/or modify it
10  under the terms of the GNU General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  any later version.
13 
14  PIPS is distributed in the hope that it will be useful, but WITHOUT ANY
15  WARRANTY; without even the implied warranty of MERCHANTABILITY or
16  FITNESS FOR A PARTICULAR PURPOSE.
17 
18  See the GNU General Public License for more details.
19 
20  You should have received a copy of the GNU General Public License
21  along with PIPS. If not, see <http://www.gnu.org/licenses/>.
22 
23 */
24 #ifdef HAVE_CONFIG_H
25  #include "pips_config.h"
26 #endif
27 #include <stdlib.h>
28 
29 #include "genC.h"
30 #include "linear.h"
31 #include "ri.h"
32 #include "effects.h"
33 
34 #include "resources.h"
35 
36 #include "ri-util.h"
37 #include "effects-util.h"
38 
39 #include "sac.h"
40 
41 static list transformations = NIL; /* <transformation> */
42 
43 void insert_transformation(char * name, int vectorLengthOut, int subwordSizeOut, int vectorLengthIn, int subwordSizeIn, int nbArgs, list mapping)
44 {
45  int i;
46  list l;
48  vectorLengthOut,
49  subwordSizeOut,
50  vectorLengthIn,
51  subwordSizeIn,
52  nbArgs,
53  (int*)malloc(sizeof(int)*vectorLengthOut));
54 
55  for(i = vectorLengthOut-1, l=mapping; (i>=0) && (l!=NIL); i--, l=CDR(l))
56  transformation_mapping(t)[i] = INT(CAR(l));
57 
59 }
60 
61 #if 0
62 static statement make_transformation_statement(transformation t, entity vdest, entity vsrc1, entity vsrc2)
63 {
64  list l=NIL;
65 
66  if (transformation_nbArgs(t) == 3)
67  l = CONS(EXPRESSION, entity_to_expression(vsrc2), l);
68  l = CONS(EXPRESSION, entity_to_expression(vsrc1), l);
69  l = CONS(EXPRESSION, entity_to_expression(vdest), l);
70 
72 }
73 
74 static bool best_transformation_p(transformation t1, transformation t2)
75 {
76  return ((t2 == transformation_undefined) ||
78 }
79 static statement generate_transformation_statement(simdStatementInfo si, int line)
80 {
81  int vectorLength = opcode_vectorSize(simdStatementInfo_opcode(si));
82  //MOIint subwordSize = opcode_subwordSize(simdStatementInfo_opcode(si));
83  int offset = line * vectorLength;
84 
85  list t;
87  entity bestFirstArg = entity_undefined;
88  entity bestSecArg = entity_undefined;
89 
90  //Look up all the registered transformations to find the
91  //best one
92  for(t = transformations; t != NIL; t = CDR(t))
93  {
94  int i;
95  list firstArg;
96  list secArg;
97  list l;
99 
100  //Dismiss transformation that do not have the right kind of
101  //arguments
102  if ((transformation_vectorLengthOut(tr) != vectorLength) /*MOI||
103  (transformation_subwordSizeOut(tr) != subwordSize)*/)
104  continue;
105 
106  //Find out if some vectors may be used, based on the first element
107  firstArg = secArg = NIL;
108  for(l = statementArgument_dependances(simdStatementInfo_arguments(si)[offset]);
109  l != NIL;
110  l = CDR(l))
111  {
112  vectorElement ve = VECTORELEMENT(CAR(l));
113 
114  if ( (vectorElement_vectorLength(ve) != transformation_vectorLengthIn(tr)) //||
115  //MOI (vectorElement_subwordSize(ve) != transformation_subwordSizeIn(tr))
116  )
117  continue;
118 
119  if (vectorElement_element(ve) == transformation_mapping(tr)[0])
120  firstArg = CONS(ENTITY, vectorElement_vector(ve), firstArg);
121  if ((vectorElement_element(ve) | 0x100) == transformation_mapping(tr)[0])
122  secArg = CONS(ENTITY, vectorElement_vector(ve), secArg);
123  }
124 
125  //Now verify these vector can actually be used, by looking at all
126  //the other elements
127  for( i = 1;
128  (i < vectorLength) && (firstArg != NIL) &&
129  ((transformation_nbArgs(tr) == 2) || (secArg != NIL));
130  i ++ )
131  {
132  statementArgument ssa = simdStatementInfo_arguments(si)[i + offset];
133  list first = NIL;
134  list sec = NIL;
135 
136  //Build the list of the vectors that match for the current element
137  for(l = statementArgument_dependances(ssa); l != NIL; l = CDR(l))
138  {
139  vectorElement ve = VECTORELEMENT(CAR(l));
140 
141  if (vectorElement_element(ve) == transformation_mapping(tr)[i])
142  first = CONS(ENTITY, vectorElement_vector(ve), first);
143  if ((vectorElement_element(ve) | 0x100) == transformation_mapping(tr)[i])
144  sec = CONS(ENTITY, vectorElement_vector(ve), sec);
145  }
146 
147  //Merge the lists to get vectors that match on all elements tested
148  //up to now
149  gen_list_and(&firstArg, first);
150  gen_free_list(first);
151 
152  gen_list_and(&secArg, sec);
153  gen_free_list(sec);
154  }
155 
156  //If the transformation can be used, test if it is better than some
157  //other we may have found
158  if ( (firstArg != NIL) &&
159  ((transformation_nbArgs(tr) == 2) || (secArg != NIL)) &&
160  (best_transformation_p(tr, bestTr)) )
161  {
162  bestTr = tr;
163  bestFirstArg = ENTITY(CAR(firstArg));
164  if (secArg != NIL)
165  bestSecArg = ENTITY(CAR(secArg));
166  }
167 
168  gen_free_list(firstArg);
169  gen_free_list(secArg);
170  }
171 
172  //No appliable transformation found, so exit now: can't do anything!
173  if (bestTr == transformation_undefined)
174  return statement_undefined;
175 
176  //We found out if there is some appliable transformation, and we even
177  //have chosen the best one. Now is time to generate the actual
178  //statement.
179  return make_transformation_statement(bestTr,
180  simdStatementInfo_vectors(si)[line],
181  bestFirstArg,
182  bestSecArg);
183 }
184 #endif
transformation make_transformation(string a1, intptr_t a2, intptr_t a3, intptr_t a4, intptr_t a5, intptr_t a6, int *a7)
Definition: sac_private.c:510
@ INT
Definition: atomic.c:48
static Value offset
Definition: translation.c:283
void * malloc(YYSIZE_T)
void gen_list_and(list *a, const list b)
Compute A = A inter B: complexity in O(n2)
Definition: list.c:941
#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
void gen_free_list(list l)
free the spine of the list
Definition: list.c:327
#define CDR(pcons)
Get the list less its first element.
Definition: newgen_list.h:111
expression entity_to_expression(entity e)
if v is a constant, returns a constant call.
Definition: expression.c:165
#define ENTITY(x)
ENTITY.
Definition: ri.h:2755
#define EXPRESSION(x)
EXPRESSION.
Definition: ri.h:1217
#define entity_undefined
Definition: ri.h:2761
#define statement_undefined
Definition: ri.h:2419
static statement make_exec_statement_from_name(string ename, list args)
Definition: codegen.c:602
#define transformation_name(x)
Definition: sac_private.h:577
#define opcode_vectorSize(x)
Definition: sac_private.h:291
#define transformation_mapping(x)
Definition: sac_private.h:589
#define transformation_vectorLengthIn(x)
Definition: sac_private.h:583
#define transformation_vectorLengthOut(x)
Definition: sac_private.h:579
#define TRANSFORMATION(x)
TRANSFORMATION.
Definition: sac_private.h:542
#define transformation_nbArgs(x)
Definition: sac_private.h:587
#define transformation_undefined
Definition: sac_private.h:548
char * strdup()
static int line
FLEX_SCANNER.
Definition: scanner.c:852
The structure used to build lists in NewGen.
Definition: newgen_list.h:41
static list transformations
transformation>
Definition: vectransform.c:41
void insert_transformation(char *name, int vectorLengthOut, int subwordSizeOut, int vectorLengthIn, int subwordSizeIn, int nbArgs, list mapping)
vectransform.c
Definition: vectransform.c:43