PIPS
treematch.c File Reference
#include "genC.h"
#include "linear.h"
#include "ri.h"
#include "effects.h"
#include "resources.h"
#include "properties.h"
#include "misc.h"
#include "ri-util.h"
#include "effects-util.h"
#include "pipsdbm.h"
#include "sac.h"
#include "patterns.h"
#include <errno.h>
+ Include dependency graph for treematch.c:

Go to the source code of this file.

Functions

void set_simd_treematch (matchTree t)
 treematch.c More...
 
void reset_simd_treematch ()
 
void simd_reset_finalArgType ()
 
static list simd_fill_curArgType_call (call ca)
 
void simd_fill_finalArgType (statement stat)
 
void simd_fill_curArgType (statement stat)
 
bool simd_check_argType ()
 
static matchTree make_tree ()
 
static void insert_tree_branch (matchTree t, int token, matchTree n)
 
static matchTree select_tree_branch (matchTree t, int token)
 
static matchTree match_call (call c, matchTree t, list *args)
 Warning: list of arguments is built in reversed order (the head is in fact the last argument) More...
 
static matchTree match_expression (expression arg, matchTree t, list *args)
 
static list merge_lists (list l, list format)
 merge the 2 lists. More...
 
list match_statement (statement s)
 return a list of matching statements More...
 
void insert_opcodeClass (char *s, int nbArgs, list opcodes)
 
static opcodeClass get_opcodeClass (char *s)
 
void insert_pattern (char *s, list tokens, list args)
 
bool simd_treematcher (const string module_name)
 

Variables

static matchTree patterns_tree = NULL
 
static list finalArgType = NIL
 
static list curArgType = NIL
 

Function Documentation

◆ get_opcodeClass()

static opcodeClass get_opcodeClass ( char *  s)
static

Definition at line 273 of file treematch.c.

274 {
275  return gen_find_opcodeClass(s);
276 }
opcodeClass gen_find_opcodeClass(char *s)
Definition: sac_private.c:454

References gen_find_opcodeClass().

Referenced by insert_pattern().

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

◆ insert_opcodeClass()

void insert_opcodeClass ( char *  s,
int  nbArgs,
list  opcodes 
)
Parameters
nbArgsbArgs
opcodespcodes

Definition at line 267 of file treematch.c.

268 {
269  //Add the class and name in the map
270  make_opcodeClass(s, nbArgs, opcodes);
271 }
opcodeClass make_opcodeClass(string a1, intptr_t a2, list a3)
Definition: sac_private.c:468

References make_opcodeClass().

+ Here is the call graph for this function:

◆ insert_pattern()

void insert_pattern ( char *  s,
list  tokens,
list  args 
)

no such branch -> create a new branch

Parameters
tokensokens
argsrgs

Definition at line 278 of file treematch.c.

279 {
281  patternx p;
283 
284  if (c == opcodeClass_undefined)
285  {
286  pips_user_warning("defining pattern for an undefined opcodeClass (%s).",s);
287  return;
288  }
289 
290  p = make_patternx(c, args);
291 
292  for( ; tokens != NIL; tokens = CDR(tokens) )
293  {
294  int token = INT(CAR(tokens));
295  matchTree next = select_tree_branch(m, token);
296 
297  if (next == matchTree_undefined)
298  {
299  /* no such branch -> create a new branch */
300  next = make_tree();
301  insert_tree_branch(m, token, next);
302  }
303 
304  m = next;
305  }
306 
308 }
patternx make_patternx(opcodeClass a1, list a2)
Definition: sac_private.c:334
@ INT
Definition: atomic.c:48
#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
#define CDR(pcons)
Get the list less its first element.
Definition: newgen_list.h:111
#define pips_user_warning
Definition: misc-local.h:146
#define matchTree_undefined
Definition: sac_private.h:150
#define opcodeClass_undefined
Definition: sac_private.h:507
#define PATTERNX(x)
PATTERNX.
Definition: sac_private.h:384
#define matchTree_patterns(x)
Definition: sac_private.h:174
static matchTree select_tree_branch(matchTree t, int token)
Definition: treematch.c:120
static matchTree patterns_tree
Definition: treematch.c:45
static void insert_tree_branch(matchTree t, int token, matchTree n)
Definition: treematch.c:115
static opcodeClass get_opcodeClass(char *s)
Definition: treematch.c:273
static matchTree make_tree()
Definition: treematch.c:108

References CAR, CDR, CONS, get_opcodeClass(), insert_tree_branch(), INT, make_patternx(), make_tree(), matchTree_patterns, matchTree_undefined, NIL, opcodeClass_undefined, patterns_tree, PATTERNX, pips_user_warning, and select_tree_branch().

+ Here is the call graph for this function:

◆ insert_tree_branch()

static void insert_tree_branch ( matchTree  t,
int  token,
matchTree  n 
)
static

Definition at line 115 of file treematch.c.

116 {
117  extend_matchTreeSons(matchTree_sons(t), token, n);
118 }
void extend_matchTreeSons(matchTreeSons f, intptr_t k, matchTree v)
Definition: sac_private.c:105
#define matchTree_sons(x)
Definition: sac_private.h:176

References extend_matchTreeSons(), and matchTree_sons.

Referenced by insert_pattern().

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

◆ make_tree()

static matchTree make_tree ( )
static

Definition at line 108 of file treematch.c.

109 {
111  matchTree n = make_matchTree(NIL, sons);
112  return n;
113 }
matchTree make_matchTree(list a1, matchTreeSons a2)
Definition: sac_private.c:54
matchTreeSons make_matchTreeSons(void)
Definition: sac_private.c:96

References make_matchTree(), make_matchTreeSons(), and NIL.

Referenced by insert_pattern(), and simd_treematcher().

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

◆ match_call()

static matchTree match_call ( call  c,
matchTree  t,
list args 
)
static

Warning: list of arguments is built in reversed order (the head is in fact the last argument)

no match

no match

Definition at line 183 of file treematch.c.

184 {
186  return matchTree_undefined; /* no match */
187 
189  if (matchTree_undefined_p(t))
190  return matchTree_undefined; /* no match */
191 
193  {
194  t=match_expression(arg,t,args);
195  if (matchTree_undefined_p(t) )
196  return matchTree_undefined;
197  }
198 
199 
200  return t;
201 }
#define call_constant_p(C)
Definition: flint_check.c:51
#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
int get_operator_id(entity e)
Definition: operatorid.c:161
bool top_level_entity_p(entity e)
Check if the scope of entity e is global.
Definition: entity.c:1130
#define call_function(x)
Definition: ri.h:709
#define EXPRESSION(x)
EXPRESSION.
Definition: ri.h:1217
#define call_arguments(x)
Definition: ri.h:711
#define matchTree_undefined_p(x)
Definition: sac_private.h:151
static matchTree match_expression(expression arg, matchTree t, list *args)
Definition: treematch.c:129

References call_arguments, call_constant_p, call_function, EXPRESSION, FOREACH, get_operator_id(), match_expression(), matchTree_undefined, matchTree_undefined_p, select_tree_branch(), and top_level_entity_p().

Referenced by match_expression(), and match_statement().

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

◆ match_expression()

static matchTree match_expression ( expression  arg,
matchTree  t,
list args 
)
static

field call should be taken care of as references

right now we have matched the rhs of the field, now bring back the lhs !

unexpected token !! -> no match

Definition at line 129 of file treematch.c.

130 {
131  syntax s = expression_syntax(arg);
132  switch(syntax_tag(s))
133  {
134  case is_syntax_call:
135  {
136  call c = syntax_call(s);
137  if (call_constant_p(c))
138  {
140  *args = CONS(EXPRESSION, arg, *args);
141  }
142  /* field call should be taken care of as references */
143  else if ( ENTITY_FIELD_P(call_function(c)) )
144  {
145  t=match_expression(binary_call_rhs(c),t,args);
146  /* right now we have matched the rhs of the field,
147  * now bring back the lhs !
148  */
149  if( !matchTree_undefined_p(t))
150  *REFCAR(*args) = (gen_chunkp)arg;
151  }
152  else
153  t = match_call(c, t, args);
154  break;
155  }
156 
157  case is_syntax_reference:
158  {
160  if(bas == basic_undefined || basic_type_size(bas)*8 >= get_int_property("SAC_SIMD_REGISTER_WIDTH"))
161  {
162  free_basic(bas);
163  return matchTree_undefined;
164  }
165  else
166  {
168  *args = CONS(EXPRESSION, arg, *args);
169  free_basic(bas);
170  }
171  break;
172  }
173 
174  case is_syntax_range:
175  default:
176  return matchTree_undefined; /* unexpected token !! -> no match */
177  }
178  return t;
179 }
int get_int_property(const string)
void free_basic(basic p)
Definition: ri.c:107
@ REFERENCE_TOK
UNKNOWN_TOK
Definition: patterns.h:58
@ CONSTANT_TOK
LOG_REF_TOK
Definition: patterns.h:68
union gen_chunk * gen_chunkp
#define REFCAR(pc)
Get the adress of the first element of a list.
Definition: newgen_list.h:119
#define binary_call_rhs(c)
#define ENTITY_FIELD_P(e)
C data structure and pointer management.
int basic_type_size(basic)
See also SizeOfElements()
Definition: type.c:1074
basic basic_of_reference(reference)
Retrieves the basic of a reference in a newly allocated basic object.
Definition: type.c:1459
#define syntax_reference(x)
Definition: ri.h:2730
#define syntax_tag(x)
Definition: ri.h:2727
@ is_syntax_range
Definition: ri.h:2692
@ is_syntax_call
Definition: ri.h:2693
@ is_syntax_reference
Definition: ri.h:2691
#define basic_undefined
Definition: ri.h:556
#define syntax_call(x)
Definition: ri.h:2736
#define expression_syntax(x)
Definition: ri.h:1247
static matchTree match_call(call, matchTree, list *)
Warning: list of arguments is built in reversed order (the head is in fact the last argument)
Definition: treematch.c:183

References basic_of_reference(), basic_type_size(), basic_undefined, binary_call_rhs, call_constant_p, call_function, CONS, CONSTANT_TOK, ENTITY_FIELD_P, EXPRESSION, expression_syntax, free_basic(), get_int_property(), is_syntax_call, is_syntax_range, is_syntax_reference, match_call(), matchTree_undefined, matchTree_undefined_p, REFCAR, REFERENCE_TOK, select_tree_branch(), syntax_call, syntax_reference, and syntax_tag.

Referenced by match_call().

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

◆ match_statement()

list match_statement ( statement  s)

return a list of matching statements

find the matching patterns

build the matches

Definition at line 237 of file treematch.c.

238 {
239  list matches = NIL;
240 
241  if (statement_call_p(s))
242  {
243 
244  /* find the matching patterns */
245  list args = NIL;
247  if (matchTree_undefined_p(t))
248  {
249  gen_free_list(args);
250  return NIL;
251  }
252 
253  /* build the matches */
255  {
256  match m = make_match(
257  patternx_class(p),
258  merge_lists(args, patternx_args(p))
259  );
260  matches = CONS(MATCH, m, matches);
261  }
262  }
263 
264  return matches;
265 }
match make_match(opcodeClass a1, list a2)
Definition: sac_private.c:153
void gen_free_list(list l)
free the spine of the list
Definition: list.c:327
call statement_call(statement)
Get the call of a statement.
Definition: statement.c:1406
bool statement_call_p(statement)
Definition: statement.c:364
#define MATCH(x)
MATCH.
Definition: sac_private.h:221
#define patternx_class(x)
Definition: sac_private.h:414
#define patternx_args(x)
Definition: sac_private.h:416
static hash_table matches
Definition: simdizer.c:60
The structure used to build lists in NewGen.
Definition: newgen_list.h:41
static list merge_lists(list l, list format)
merge the 2 lists.
Definition: treematch.c:204

References CONS, FOREACH, gen_free_list(), make_match(), MATCH, match_call(), matches, matchTree_patterns, matchTree_undefined_p, merge_lists(), NIL, patterns_tree, PATTERNX, patternx_args, patternx_class, statement_call(), and statement_call_p().

Referenced by compute_parallelism_factor(), and init_statement_matches_map().

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

◆ merge_lists()

static list merge_lists ( list  l,
list  format 
)
static

merge the 2 lists.

Warning: list gets reversed.

merge according to the format specifier list

append remaining arguments, if any

Definition at line 204 of file treematch.c.

205 {
206  list res = NIL;
207 
208  /* merge according to the format specifier list */
209  FOREACH(PATTERNARG,param,format)
210  {
212  {
213  if (l != NIL)
214  {
215  res = CONS(EXPRESSION, EXPRESSION(CAR(l)), res);
216  l = CDR(l);
217  }
218  else
219  pips_user_warning("Trying to use a malformed rule. Ignoring missing parameter...\n");
220  }
221  else
222  {
224 
225  res = CONS(EXPRESSION, e, res);
226  }
227  }
228 
229  /* append remaining arguments, if any */
230  for( ; l != NIL; l = CDR(l) )
231  res = CONS(EXPRESSION, EXPRESSION(CAR(l)), res);
232 
233  return res;
234 }
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 patternArg_dynamic_p(x)
Definition: sac_private.h:378
#define patternArg_static(x)
Definition: sac_private.h:377
#define PATTERNARG(x)
PATTERNARG.
Definition: sac_private.h:335
Definition: replace.c:135

References CAR, CDR, CONS, EXPRESSION, FOREACH, int_to_expression(), NIL, PATTERNARG, patternArg_dynamic_p, patternArg_static, and pips_user_warning.

Referenced by match_statement().

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

◆ reset_simd_treematch()

void reset_simd_treematch ( void  )

Definition at line 52 of file treematch.c.

53 {
54  pips_assert("tree match already set",patterns_tree!=NULL);
55  patterns_tree=NULL;
56 }
#define pips_assert(what, predicate)
common macros, two flavors depending on NDEBUG
Definition: misc-local.h:172

References patterns_tree, and pips_assert.

Referenced by simd_treematcher(), simd_unroll_as_needed(), and simdizer().

+ Here is the caller graph for this function:

◆ select_tree_branch()

static matchTree select_tree_branch ( matchTree  t,
int  token 
)
static

Definition at line 120 of file treematch.c.

121 {
122  if (bound_matchTreeSons_p(matchTree_sons(t), token))
123  return apply_matchTreeSons(matchTree_sons(t), token);
124  else
125  return matchTree_undefined;
126 }
matchTree apply_matchTreeSons(matchTreeSons f, intptr_t k)
Definition: sac_private.c:99
bool bound_matchTreeSons_p(matchTreeSons f, intptr_t k)
Definition: sac_private.c:111

References apply_matchTreeSons(), bound_matchTreeSons_p(), matchTree_sons, and matchTree_undefined.

Referenced by insert_pattern(), match_call(), and match_expression().

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

◆ set_simd_treematch()

void set_simd_treematch ( matchTree  t)

treematch.c

Definition at line 46 of file treematch.c.

47 {
48  pips_assert("tree match not already set",patterns_tree==NULL);
49  patterns_tree=t;
50 }

References patterns_tree, and pips_assert.

Referenced by simd_treematcher(), simd_unroll_as_needed(), and simdizer().

+ Here is the caller graph for this function:

◆ simd_check_argType()

bool simd_check_argType ( void  )

Definition at line 87 of file treematch.c.

88 {
89  list pCurBas = curArgType;
90 
91  FOREACH(BASIC, finBas, finalArgType)
92  {
93  if(ENDP(pCurBas) )
94  return false;
95  basic curBas = BASIC(CAR(pCurBas));
96  if(!basic_equal_p(curBas, finBas))
97  return false;
98  pCurBas = CDR(pCurBas);
99  }
100 
102  curArgType = NIL;
103 
104  return true;
105 }
void gen_full_free_list(list l)
Definition: genClib.c:1023
#define ENDP(l)
Test if a list is empty.
Definition: newgen_list.h:66
bool basic_equal_p(basic, basic)
Definition: type.c:927
#define BASIC(x)
BASIC.
Definition: ri.h:550
static list curArgType
Definition: treematch.c:59
static list finalArgType
Definition: treematch.c:58

References BASIC, basic_equal_p(), CAR, CDR, curArgType, ENDP, finalArgType, FOREACH, gen_full_free_list(), and NIL.

Referenced by extract_matching_statements().

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

◆ simd_fill_curArgType()

void simd_fill_curArgType ( statement  stat)
Parameters
stattat

Definition at line 82 of file treematch.c.

83 {
85 }
static list simd_fill_curArgType_call(call ca)
Definition: treematch.c:69

References curArgType, simd_fill_curArgType_call(), and statement_call().

Referenced by extract_matching_statements().

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

◆ simd_fill_curArgType_call()

static list simd_fill_curArgType_call ( call  ca)
static

Definition at line 69 of file treematch.c.

70 {
71  list c=NIL;
73  c= CONS(BASIC,basic_of_expression(arg),c);
74  return c;
75 }
basic basic_of_expression(expression)
basic basic_of_expression(expression exp): Makes a basic of the same basic as the expression "exp".
Definition: type.c:1383

References BASIC, basic_of_expression(), call_arguments, CONS, EXPRESSION, FOREACH, and NIL.

Referenced by simd_fill_curArgType(), and simd_fill_finalArgType().

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

◆ simd_fill_finalArgType()

void simd_fill_finalArgType ( statement  stat)
Parameters
stattat

Definition at line 77 of file treematch.c.

References finalArgType, simd_fill_curArgType_call(), and statement_call().

Referenced by simdize_simple_statements_pass2().

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

◆ simd_reset_finalArgType()

void simd_reset_finalArgType ( void  )

Definition at line 61 of file treematch.c.

62 {
64  finalArgType = NIL;
65 
67  curArgType = NIL;
68 }

References curArgType, finalArgType, gen_free_list(), and NIL.

Referenced by simdize_simple_statements_pass2().

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

◆ simd_treematcher()

bool simd_treematcher ( const string  module_name)

create a new tree match

fill it

put it in pipsdbm

clean up

Parameters
module_nameodule_name

Definition at line 310 of file treematch.c.

311 {
313  /* create a new tree match */
314  matchTree treematch = make_tree();
315  set_simd_treematch(treematch);
316 
317  /* fill it */
318  sac_lineno=0;
319  patterns_yyin=fopen_config("patterns.def","SIMD_PATTERN_FILE",NULL);
321  fclose(patterns_yyin);
322 
323  /* put it in pipsdbm */
324  DB_PUT_MEMORY_RESOURCE(DBR_SIMD_TREEMATCH,"",treematch);
325 
326  /* clean up */
328  return true;
329 }
size_t sac_lineno
patterns.c
Definition: patterns.c:97
int patterns_yyparse(void)
const char * module_name(const char *s)
Return the module part of an entity name.
Definition: entity_names.c:296
FILE * fopen_config(const char *canonical_name, const char *cproperty, const char *cenv)
Definition: file.c:952
#define DB_PUT_MEMORY_RESOURCE(res_name, own_name, res_val)
conform to old interface.
Definition: pipsdbm-local.h:66
FILE * patterns_yyin
symbols exported by the parser
Definition: sac.h:157
void reset_simd_treematch()
Definition: treematch.c:52
void set_simd_treematch(matchTree t)
treematch.c
Definition: treematch.c:46

References DB_PUT_MEMORY_RESOURCE, fopen_config(), make_tree(), module_name(), patterns_yyin, patterns_yyparse(), pips_assert, reset_simd_treematch(), sac_lineno, and set_simd_treematch().

+ Here is the call graph for this function:

Variable Documentation

◆ curArgType

list curArgType = NIL
static

Definition at line 59 of file treematch.c.

Referenced by simd_check_argType(), simd_fill_curArgType(), and simd_reset_finalArgType().

◆ finalArgType

list finalArgType = NIL
static

Definition at line 58 of file treematch.c.

Referenced by simd_check_argType(), simd_fill_finalArgType(), and simd_reset_finalArgType().

◆ patterns_tree

matchTree patterns_tree = NULL
static