3 #include "pips_config.h"
4 extern char *step_lexertext;
5 extern int step_lexerlex();
6 extern int step_lexer_scan_string(char*);
7 extern int step_parse();
9 #include "step_lexer.h"
12 #include "defines-local.h"
15 extern void set_current_transform(int transform);
17 extern entity entity_from_user_name(string name);
18 extern void remove_old_pragma(void);
19 extern step_directive begin_omp_construct(int type, string s);
20 extern step_directive end_omp_construct(int type);
22 static step_directive concat_drt_clauses(step_directive drt, cons *liste_clauses);
23 static step_clause step_handle_reduction_clause(cons *ident_liste, int op);
24 static cons * step_add_to_ident_list(string name, cons * list);
26 static string pragma_str_original=NULL;
28 void step_lexererror(const char *s)
30 pips_user_error("\nParsing :\n%s\n%s at '%s'\n", pragma_str_original, s, step_lexertext);
35 /* Bison declarations */
40 step_directive step_directive;
41 step_clause step_clause;
45 %token TK_EOL TK_ERROR
46 %token TK_LPAREN TK_RPAREN
47 %token TK_COLON TK_COMMA
49 %token <string> TK_IDENT TK_COMMENT
50 %type <liste> ident_list string_list
52 %token <integer> TK_OPERATOR
54 %token <string> TK_RAW
58 %token <integer> TK_OMP_PARALLEL TK_OMP_LOOP TK_OMP_END TK_OMP_BARRIER TK_OMP_MASTER TK_OMP_SINGLE TK_OMP_THREADPRIVATE
59 %token TK_OMP_SHARED TK_OMP_PRIVATE TK_OMP_NOWAIT TK_OMP_REDUCTION TK_OMP_DEFAULT TK_OMP_COPYIN TK_OMP_FIRSTPRIVATE TK_OMP_SCHEDULE
61 %type <step_directive> omp_directive
62 %type <liste> omp_parallel_clauses omp_loop_clauses omp_end_loop_clauses omp_parallel_loop_clauses
63 %type <step_clause> omp_shared omp_private omp_reduction omp_copyin omp_firstprivate omp_schedule
64 %type <liste> omp_threadprivate_listvar
67 %token <integer> TK_STEP_TRANSFORMATION
72 TK_RAW { pips_user_warning("unknown pragma : %s\n", $1);}
75 { pips_debug(1,"OMP pragma begin\n"); remove_old_pragma(); }
76 omp_directive omp_comment TK_EOL
77 { pips_debug(1,"OMP pragma end\n"); step_directive_print($3); }
80 { pips_debug(1,"STEP pragma begin\n"); remove_old_pragma(); }
81 step_transformation TK_EOL
82 { pips_debug(1,"STEP pragma end\n"); }
86 TK_STEP_TRANSFORMATION { pips_debug(1, "STEP transform : %d\n", $1); set_current_transform($1);}
90 | TK_COMMENT { pips_debug(1,"COMMENT : %s\n", $1);}
95 { $<step_directive>$ = begin_omp_construct($1, "PARALLEL"); }
97 { $$ = concat_drt_clauses($<step_directive>2, $3); }
99 { $<step_directive>$ = begin_omp_construct($1, "LOOP"); }
101 { $$ = concat_drt_clauses($<step_directive>2, $3); }
102 | TK_OMP_PARALLEL TK_OMP_LOOP
103 { $<step_directive>$=begin_omp_construct(STEP_PARALLEL_DO, "PARALLEL LOOP");}
104 omp_parallel_loop_clauses
105 { $$ = concat_drt_clauses($<step_directive>3, $4); }
107 { $$ = begin_omp_construct($1, "MASTER");}
109 { $$ = begin_omp_construct($1, "SINGLE");}
111 { step_directive drt = begin_omp_construct($1, "BARRIER");
112 end_omp_construct($1);
114 | TK_OMP_THREADPRIVATE
115 { $<step_directive>$ = begin_omp_construct($1, "THREADPRIVATE");}
116 omp_threadprivate_listvar
117 { $$ = concat_drt_clauses($<step_directive>2, $3);
118 end_omp_construct($1);}
119 | TK_OMP_END TK_OMP_PARALLEL
120 { $$ = end_omp_construct($2);}
121 | TK_OMP_END TK_OMP_LOOP omp_end_loop_clauses
122 { $$ = concat_drt_clauses(end_omp_construct($2), $3); }
123 | TK_OMP_END TK_OMP_PARALLEL TK_OMP_LOOP
124 { $$ = end_omp_construct(STEP_PARALLEL_DO);}
125 | TK_OMP_END TK_OMP_MASTER
126 { $$ = end_omp_construct($2);}
127 | TK_OMP_END TK_OMP_SINGLE
128 { $$ = end_omp_construct($2);}
131 omp_parallel_clauses: {$$=NIL;}
132 | omp_parallel_clauses omp_shared
133 { pips_debug(1, "clause SHARED\n");
134 $$ = CONS(STEP_CLAUSE, $2, $1); }
135 | omp_parallel_clauses omp_private
136 { pips_debug(1, "clause PRIVATE\n");
137 $$ = CONS(STEP_CLAUSE, $2, $1); }
138 | omp_parallel_clauses omp_copyin
139 { pips_debug(1, "clause COPYIN\n");
140 $$ = CONS(STEP_CLAUSE, $2, $1); }
141 | omp_parallel_clauses omp_firstprivate
142 { pips_debug(1, "clause FIRSTPRIVATE\n");
143 $$ = CONS(STEP_CLAUSE, $2, $1); }
144 | omp_parallel_clauses omp_reduction
145 { pips_debug(1, "clause REDUCTION\n");
146 $$ = CONS(STEP_CLAUSE, $2, $1); }
147 | omp_parallel_clauses omp_default
148 { pips_debug(1, "clause DEFAULT SKIPPED\n");
153 omp_loop_clauses: {$$=NIL;}
154 | omp_loop_clauses omp_private
155 { pips_debug(1, "clause PRIVATE\n");
156 $$ = CONS(STEP_CLAUSE, $2, $1);}
157 | omp_loop_clauses omp_firstprivate
158 { pips_debug(1, "clause FIRSTPRIVATE\n");
159 $$ = CONS(STEP_CLAUSE, $2, $1);}
160 | omp_loop_clauses omp_reduction
161 { pips_debug(1, "clause REDUCTION\n");
162 $$ = CONS(STEP_CLAUSE, $2, $1);}
163 | omp_loop_clauses omp_schedule
164 { pips_debug(1, "clause SCHEDULE\n");
165 $$ = CONS(STEP_CLAUSE, $2, $1);}
166 | omp_loop_clauses TK_OMP_NOWAIT
167 { pips_debug(1, "clause NOWAIT\n");
168 $$ = CONS(STEP_CLAUSE, make_step_clause_nowait(), $1);}
171 omp_end_loop_clauses:{$$=NIL;}
172 | omp_loop_clauses TK_OMP_NOWAIT {pips_debug(1, "clause NOWAIT\n");
173 $$ = CONS(STEP_CLAUSE, make_step_clause_nowait(), $1);}
176 omp_parallel_loop_clauses: { $$=NIL; }
177 | omp_parallel_loop_clauses omp_shared
178 { pips_debug(1, "clause SHARED\n");
179 $$ = CONS(STEP_CLAUSE, $2, $1); }
180 | omp_parallel_loop_clauses omp_private
181 { pips_debug(1, "clause PRIVATE\n");
182 $$ = CONS(STEP_CLAUSE, $2, $1); }
183 | omp_parallel_loop_clauses omp_copyin
184 { pips_debug(1, "clause COPYIN\n");
185 $$ = CONS(STEP_CLAUSE, $2, $1); }
186 | omp_parallel_loop_clauses omp_firstprivate
187 { pips_debug(1, "clause FIRSTPRIVATE\n");
188 $$ = CONS(STEP_CLAUSE, $2, $1); }
189 | omp_parallel_loop_clauses omp_reduction
190 { pips_debug(1, "clause REDUCTION\n");
191 $$ = CONS(STEP_CLAUSE, $2, $1); }
192 | omp_parallel_loop_clauses omp_schedule
193 { pips_debug(1, "clause SCHEDULE\n");
194 $$ = CONS(STEP_CLAUSE, $2, $1); }
195 | omp_parallel_loop_clauses omp_default
196 { pips_debug(1, "clause DEFAULT SKIPPED\n");
200 omp_shared: TK_OMP_SHARED {pips_debug(2, "SHARED begin \n");}
201 TK_LPAREN ident_list TK_RPAREN {pips_debug(2, "SHARED end\n");
202 $$ = make_step_clause_shared($4);}
207 { pips_debug(2, "PRIVATE begin \n");}
208 TK_LPAREN ident_list TK_RPAREN
209 { pips_debug(2, "PRIVATE end\n");
210 $$ = make_step_clause_private($4);}
215 { pips_debug(2, "COPYIN begin \n");}
216 TK_LPAREN ident_list TK_RPAREN
217 { pips_debug(2, "COPYIN end\n");
218 $$ = make_step_clause_copyin($4);}
221 omp_threadprivate_listvar :
222 { pips_debug(2, "THREADPRIVATE begin \n");}
223 TK_LPAREN ident_list TK_RPAREN
224 { pips_debug(2, "THREADPRIVATE end\n");
225 $$ = CONS(STEP_CLAUSE, make_step_clause_threadprivate($3),NIL);}
230 { pips_debug(2, "FIRSTPRIVATE begin \n");}
231 TK_LPAREN ident_list TK_RPAREN
232 { pips_debug(2, "FIRSTPRIVATE end\n");
233 $$ = make_step_clause_firstprivate($4);}
238 { pips_debug(2, "SCHEDULE begin \n");}
239 TK_LPAREN string_list TK_RPAREN
240 { pips_debug(2, "SCHEDULE end\n");
241 $$ = make_step_clause_schedule(gen_nreverse($4)); }
246 { pips_debug(2, "REDUCTION begin\n"); }
247 TK_LPAREN TK_OPERATOR
248 { pips_debug(2, "OPERATOR %d\n", $4); }
249 TK_COLON ident_list TK_RPAREN
250 { pips_debug(2, "REDUCTION end\n");
251 $$ = step_handle_reduction_clause($7, $4); }
256 { pips_debug(2, "DEFAULT begin\n"); }
257 TK_LPAREN TK_IDENT TK_RPAREN
258 { pips_debug(2, "DEFAULT %s end\n", $4); }
263 { pips_debug(2, "first string %s\n", $1);
264 $$ = CONS(STRING, $1, NIL);
266 | string_list TK_COMMA TK_IDENT
267 { pips_debug(2, "next IDENT %s\n", $3);
268 $$ = CONS(STRING, $3, $1);
274 { pips_debug(2, "first IDENT %s\n", $1);
275 $$ = step_add_to_ident_list($1, NIL);
277 | ident_list TK_COMMA TK_IDENT
278 { pips_debug(2, "next IDENT %s\n", $3);
279 $$ = step_add_to_ident_list($3, $1);
285 static cons * step_add_to_ident_list(string name, cons * list)
287 pips_debug(2, "begin\n");
288 entity e = entity_from_user_name(name);
289 pips_assert("entity", !entity_undefined_p(e));
290 pips_debug(2, "end\n");
291 return CONS(ENTITY, e, list);
294 static step_clause step_handle_reduction_clause(cons *ident_liste, int op)
296 pips_debug(2, "begin\n");
297 map_entity_int reductions = make_map_entity_int();
298 FOREACH(ENTITY, e, ident_liste)
300 pips_assert("first reduction", !bound_map_entity_int_p(reductions, e));
301 pips_debug(2,"add reduction %d variable : %s)\n", op, entity_name(e));
302 extend_map_entity_int(reductions, e, op);
304 gen_free_list(ident_liste);
305 pips_debug(2, "end\n");
306 return make_step_clause_reduction(reductions);
309 static step_directive concat_drt_clauses(step_directive drt, cons *liste_clauses)
311 pips_debug(2, "begin\n");
312 step_directive_clauses(drt)= gen_nconc(liste_clauses, step_directive_clauses(drt));
313 pips_debug(2, "end\n");
317 void step_bison_parse(pragma pgm, statement stmt)
319 string pragma_str = pragma_string(pgm);
321 if(pragma_str[strlen(pragma_str)-1]!= '\n')
322 pragma_str = strdup(concatenate(pragma_string(pgm),"\n",NULL));
324 pragma_str = strdup(pragma_string(pgm));
326 pips_debug(1, "############### PARSER BEGIN ################\nwith :\n%s\non stmt : %p\n", pragma_str, stmt);
329 pragma_str_original = strdup(pragma_str);
330 step_lexer_scan_string(pragma_str);
332 free(pragma_str_original);
333 pips_debug(1, "############### PARSER END ################\n");