Astaroth  3.1
Scalable Multi-GPU Stencil Computations
Loading...
Searching...
No Matches
loop_hoisting.h
Go to the documentation of this file.
1#pragma once
2//TP: handling of constant loops at the start of generate (unroll_constant_loops), included in codegen.c after the AST helpers it uses
3// (is_for_iteration_statement, replace_variable_with_constant_int, create_func_call, push_to_statement_list, get_nodes, eval_int, ...).
4// Short loops are unrolled as before, long loops are kept rolled with their iteration-specific stencil calls hoisted (see below).
5
6#ifndef MAX_UNROLL_ITERATIONS
7#define MAX_UNROLL_ITERATIONS (4)
8#endif
9//TP: long constant loops (more than MAX_UNROLL_ITERATIONS iterations), e.g. loops over 32 dust species.
10// Unrolling them makes every iteration-specific stencil call a call on a compile-time known field, so all of them are preloaded
11// at the start of the kernel and the kernels spill heavily to scratch.
12// Instead the loop is kept rolled and the stencil calls that depend only on the loop variable are hoisted to locals at the start of each
13// iteration between ac_dynamic_stencils_begin() and ac_dynamic_stencils_end(). The analysis marks the stencil calls in between
14// with AC_STENCIL_DYNAMIC_CALL and stencilgen computes the stencils that are called only like this on demand instead of preloading them.
15// So the loads of one iteration are still issued together while the working set is that of one iteration.
16// If the arrays indexed in the hoisted calls are used also outside long loops the stencils are preloaded anyways so the loop is unrolled as before.
17typedef struct
18{
21 node_vec func_callees; //TP: data[i] is actually a string_vec* of the callees of funcs[i]
22 node_vec func_stencils; //TP: data[i] is actually a string_vec* of the stencils funcs[i] calls directly or through other functions
24 struct hashmap_s used_outside_long_loops; //TP: keys "array:stencil" of the stencils called on the elements of the array outside long loops
27
28static bool
29is_side_effect_call_name(const char* name)
30{
31 return !strncmp(name,"write",5) || !strncmp(name,"reduce",6) || !strncmp(name,"print",5) || !strncmp(name,"fprintf",7)
32 || !strncmp(name,"atomic",6) || !strncmp(name,"AC_INTERNAL_write",17) || !strncmp(name,"ac_dummy_write",14);
33}
34static const char*
35get_func_call_name(const ASTNode* node)
36{
37 if(!(node->type & NODE_FUNCTION_CALL) || !node->lhs) return NULL;
38 const ASTNode* id = get_node_by_token(IDENTIFIER,node->lhs);
39 return id ? id->buffer : NULL;
40}
41static void
42collect_callee_names(const ASTNode* node, string_vec* dst)
43{
44 if(node->lhs) collect_callee_names(node->lhs,dst);
45 if(node->rhs) collect_callee_names(node->rhs,dst);
46 const char* name = get_func_call_name(node);
47 if(name && str_vec_get_index(*dst,name) < 0) push(dst,name);
48}
49static bool
50eval_loop_bound(const ASTNode* bound, int* res)
51{
52 const char* str = intern(combine_buffers_new(bound));
53 if(is_number(str))
54 {
55 *res = atoi(str);
56 return true;
57 }
58 int err = 0;
59 ASTNode* copy = astnode_dup(bound,NULL);
60 *res = eval_int(copy,const_int_values,const_ints,run_const_int_values,run_const_ints,false,&err);
61 return err == 0;
62}
63//TP: -1 if not a for loop over a range with bounds known at compile time.
64// *literal_bounds tells whether the bounds are int literals: only those loops are unrolled, the others are rolled as before
65// but they can be long loops of which the iteration-specific calls are hoisted, e.g. for k in 1:ndustspec+1
66static int
67get_const_loop_trip_count_base(const ASTNode* node, bool* literal_bounds, int* start_value)
68{
69 if(!is_for_iteration_statement(node)) return -1;
70 const ASTNode* for_expr = node->lhs->rhs;
71 if(!for_expr || !for_expr->rhs || for_expr->rhs->token != RANGE) return -1;
72 const ASTNode* start_node = for_expr->rhs->lhs->lhs;
73 const ASTNode* end_node = for_expr->rhs->rhs->lhs;
74 if(!start_node || !end_node) return -1;
75 *literal_bounds = is_number(intern(combine_buffers_new(start_node))) && is_number(intern(combine_buffers_new(end_node)));
76 int start = 0, end = 0;
77 if(!eval_loop_bound(start_node,&start) || !eval_loop_bound(end_node,&end)) return -1;
78 *start_value = start;
79 return end > start ? end-start : 0;
80}
81static bool
82is_long_const_loop(const ASTNode* node)
83{
84 bool literal_bounds;
85 int start;
86 return get_const_loop_trip_count_base(node,&literal_bounds,&start) > MAX_UNROLL_ITERATIONS;
87}
88static const string_vec*
89get_callee_stencils(const loop_hoist_info* info, const char* name, string_vec* tmp)
90{
91 if(str_vec_get_index(info->stencils,name) >= 0)
92 {
93 push(tmp,name);
94 return tmp;
95 }
96 const int index = str_vec_get_index(info->funcs,name);
97 if(index < 0) return tmp;
98 return (const string_vec*)info->func_stencils.data[index];
99}
100static void
101mark_used_outside_long_loops(loop_hoist_info* info, const char* array, const char* stencil)
102{
103 const char* key = sprintf_intern("%s:%s",array,stencil);
104 if(!hashmap_get(&info->used_outside_long_loops,key,strlen(key)))
105 hashmap_put(&info->used_outside_long_loops,key,strlen(key),(void*)key);
106}
107static bool
108used_outside_long_loops(const loop_hoist_info* info, const char* array, const char* stencil)
109{
110 const char* key = sprintf_intern("%s:%s",array,stencil);
111 return hashmap_get((struct hashmap_s*)&info->used_outside_long_loops,key,strlen(key)) != NULL;
112}
113static void
114collect_identifiers(const ASTNode* node, string_vec* dst)
115{
116 if(node->token == IDENTIFIER && node->buffer && str_vec_get_index(*dst,node->buffer) < 0) push(dst,node->buffer);
117 if(node->lhs) collect_identifiers(node->lhs,dst);
118 if(node->rhs) collect_identifiers(node->rhs,dst);
119}
120//TP: an identifier in the arguments of a call is marked as used with the stencils of the callee,
121// an identifier outside calls, e.g. F_DUST_DENSITY in nd = F_DUST_DENSITY, with the value stencil.
122// Conservative: all identifiers are marked, not only fields
123static void
124collect_stencil_uses_outside_long_loops(const ASTNode* node, const bool in_function, const bool in_call_args, loop_hoist_info* info)
125{
126 if(is_long_const_loop(node)) return;
127 const bool in_func = in_function || (node->type & NODE_FUNCTION);
128 if(in_func && !in_call_args && node->token == IDENTIFIER && node->buffer)
129 mark_used_outside_long_loops(info,node->buffer,intern("value_stencil"));
130 const char* name = in_func ? get_func_call_name(node) : NULL;
131 if(name && node->rhs)
132 {
134 const string_vec* stencils = get_callee_stencils(info,name,&tmp);
135 if(stencils->size)
136 {
138 collect_identifiers(node->rhs,&ids);
139 for(size_t i = 0; i < ids.size; ++i)
140 for(size_t j = 0; j < stencils->size; ++j)
141 mark_used_outside_long_loops(info,ids.data[i],stencils->data[j]);
142 free_str_vec(&ids);
143 }
144 free_str_vec(&tmp);
145 }
146 if(node->lhs) collect_stencil_uses_outside_long_loops(node->lhs,in_func,in_call_args,info);
147 if(node->rhs) collect_stencil_uses_outside_long_loops(node->rhs,in_func,in_call_args || name != NULL,info);
148}
149static loop_hoist_info
150get_loop_hoist_info(const ASTNode* root)
151{
152 loop_hoist_info info;
153 memset(&info,0,sizeof(info));
154 {
156 get_nodes(root,&nodes,&info.stencils,NODE_STENCIL);
157 free_node_vec(&nodes);
158 }
160 string_vec func_names = VEC_INITIALIZER;
161 get_nodes(root,&funcs,&func_names,NODE_DFUNCTION);
162 //TP: overloads share the name so the info of a name is the union over them
163 for(size_t i = 0; i < funcs.size; ++i)
164 {
165 int index = str_vec_get_index(info.funcs,func_names.data[i]);
166 if(index < 0)
167 {
168 push(&info.funcs,func_names.data[i]);
169 string_vec* callees = calloc(1,sizeof(string_vec));
170 push_node(&info.func_callees,(const ASTNode*)callees);
171 index = info.funcs.size-1;
172 }
173 collect_callee_names(funcs.data[i]->rhs ? funcs.data[i]->rhs : funcs.data[i],(string_vec*)info.func_callees.data[index]);
174 }
175 free_node_vec(&funcs);
176 free_str_vec(&func_names);
177 const size_t n = info.funcs.size;
178 for(size_t i = 0; i < n; ++i) push_node(&info.func_stencils,(const ASTNode*)calloc(1,sizeof(string_vec)));
179 info.has_side_effects = calloc(n+1,sizeof(bool));
180 bool changed = true;
181 while(changed)
182 {
183 changed = false;
184 for(size_t i = 0; i < n; ++i)
185 {
186 const string_vec* callees = (const string_vec*)info.func_callees.data[i];
187 for(size_t j = 0; j < callees->size; ++j)
188 {
189 const char* callee = callees->data[j];
190 const int index = str_vec_get_index(info.funcs,callee);
191 string_vec* own_stencils = (string_vec*)info.func_stencils.data[i];
192 if(str_vec_get_index(info.stencils,callee) >= 0 && str_vec_get_index(*own_stencils,callee) < 0) { push(own_stencils,callee); changed = true; }
193 if(index >= 0 && index != (int)i)
194 {
195 const string_vec* callee_stencils = (const string_vec*)info.func_stencils.data[index];
196 for(size_t k = 0; k < callee_stencils->size; ++k)
197 if(str_vec_get_index(*own_stencils,callee_stencils->data[k]) < 0) { push(own_stencils,callee_stencils->data[k]); changed = true; }
198 }
199 const bool side_effects = is_side_effect_call_name(callee) || (index >= 0 && info.has_side_effects[index]);
200 if(side_effects && !info.has_side_effects[i]) { info.has_side_effects[i] = true; changed = true; }
201 }
202 }
203 }
205 collect_stencil_uses_outside_long_loops(root,false,false,&info);
206 return info;
207}
208static void
209free_loop_hoist_info(loop_hoist_info* info)
210{
211 for(size_t i = 0; i < info->func_callees.size; ++i)
212 {
213 string_vec* callees = (string_vec*)info->func_callees.data[i];
214 free_str_vec(callees);
215 free(callees);
216 }
217 free_node_vec(&info->func_callees);
218 for(size_t i = 0; i < info->func_stencils.size; ++i)
219 {
221 free_str_vec(stencils);
222 free(stencils);
223 }
224 free_node_vec(&info->func_stencils);
225 free_str_vec(&info->stencils);
226 free_str_vec(&info->funcs);
228 free(info->has_side_effects);
229}
230static bool
231subtree_has_identifier(const ASTNode* node, const char* id)
232{
233 if(node->token == IDENTIFIER && node->buffer == id) return true;
234 return (node->lhs && subtree_has_identifier(node->lhs,id)) || (node->rhs && subtree_has_identifier(node->rhs,id));
235}
236static bool
237subtree_has_any_identifier(const ASTNode* node, const string_vec ids)
238{
239 if(node->token == IDENTIFIER && node->buffer && str_vec_get_index(ids,node->buffer) >= 0) return true;
240 return (node->lhs && subtree_has_any_identifier(node->lhs,ids)) || (node->rhs && subtree_has_any_identifier(node->rhs,ids));
241}
242static void
243collect_identifiers_outside_indexes(const ASTNode* node, string_vec* dst)
244{
245 if(node->token == IDENTIFIER && node->buffer && str_vec_get_index(*dst,node->buffer) < 0) push(dst,node->buffer);
246 if(node->lhs) collect_identifiers_outside_indexes(node->lhs,dst);
247 if(node->rhs && !(node->type & NODE_ARRAY_ACCESS)) collect_identifiers_outside_indexes(node->rhs,dst);
248}
249//TP: the variables declared or assigned inside the loop body, a call depending on them can not be moved to the start of the iteration
250static void
251collect_assigned_identifiers(const ASTNode* node, string_vec* dst)
252{
253 //TP: the indexes of an assigned array element, e.g. the loop variable in arr[k-1] = ..., are only read
254 if((node->type & NODE_ASSIGNMENT) && node->lhs) collect_identifiers_outside_indexes(node->lhs,dst);
255 if((node->type & NODE_DECLARATION) && node->rhs) collect_identifiers_outside_indexes(node->rhs,dst);
256 if(node->lhs) collect_assigned_identifiers(node->lhs,dst);
257 if(node->rhs) collect_assigned_identifiers(node->rhs,dst);
258}
259//TP: the bases of the array accesses indexed with the loop variable, e.g. F_DUST_VELOCITY in F_DUST_VELOCITY[k-1]
260static void
261collect_loop_indexed_arrays(const ASTNode* node, const char* loop_variable, string_vec* dst)
262{
263 if((node->type & NODE_ARRAY_ACCESS) && node->lhs && node->rhs && subtree_has_identifier(node->rhs,loop_variable))
264 {
265 const ASTNode* base = get_node_by_token(IDENTIFIER,node->lhs);
266 if(base && str_vec_get_index(*dst,base->buffer) < 0) push(dst,base->buffer);
267 }
268 if(node->lhs) collect_loop_indexed_arrays(node->lhs,loop_variable,dst);
269 if(node->rhs) collect_loop_indexed_arrays(node->rhs,loop_variable,dst);
270}
271static bool
272is_loop_statement(const ASTNode* node)
273{
274 if(is_for_iteration_statement(node)) return true;
275 return node->lhs && node->lhs->lhs && node->lhs->lhs->token == WHILE;
276}
277static bool
278is_logical_binary_expression(const ASTNode* node)
279{
280 if(!node_is_binary_expr(node)) return false;
281 const ASTNode* op = get_node_by_token(BINARY_OP,node->rhs->lhs);
282 return op && op->buffer && (!strcmp(op->buffer,"&&") || !strcmp(op->buffer,"||"));
283}
284static bool
285is_hoistable_call(const ASTNode* node, const char* loop_variable, const string_vec assigned, const loop_hoist_info* info)
286{
287 const char* name = get_func_call_name(node);
288 if(!name || !node->rhs) return false;
289 if(node->parent && node->parent->token == NON_RETURNING_FUNC_CALL) return false;
290 const int index = str_vec_get_index(info->funcs,name);
291 const bool is_stencil = str_vec_get_index(info->stencils,name) >= 0;
292 if(!is_stencil && (index < 0 || ((const string_vec*)info->func_stencils.data[index])->size == 0 || info->has_side_effects[index])) return false;
293 if(!subtree_has_identifier(node->rhs,loop_variable)) return false;
294 if(subtree_has_any_identifier(node->rhs,assigned)) return false;
295 return true;
296}
297static bool
298subtree_has_func_call(const ASTNode* node)
299{
300 if(node->type & NODE_FUNCTION_CALL) return true;
301 return (node->lhs && subtree_has_func_call(node->lhs)) || (node->rhs && subtree_has_func_call(node->rhs));
302}
303//TP: a condition that is the same for all iterations and does not read fields, e.g. AC_lpencil__mod__cdata[i_uud-1] in the transpiled PC code.
304// Typically these are eliminated as known at compile time.
305static bool
306is_uniform_condition(const ASTNode* node, const char* loop_variable, const string_vec assigned)
307{
308 return !subtree_has_func_call(node) && !subtree_has_identifier(node,loop_variable) && !subtree_has_any_identifier(node,assigned);
309}
310//TP: goes through the loop body in program order and stops hoisting at the first write since the calls could read the written values.
311// Calls in conditionally executed code are not hoisted since they could be invalid if executed unconditionally,
312// except under uniform conditions (see is_uniform_condition): if such a condition is false the hoisted call is only unneeded work
313// that the compiler removes since the result is not used. The field the call is on could be invalid if the condition is false
314// but on the device the stencil functions return NAN for an unknown field and the analysis skips invalid fields.
315static void
316find_hoistable_calls(const ASTNode* node, const char* loop_variable, const string_vec assigned, const loop_hoist_info* info, const bool conditional, bool* write_seen, node_vec* dst)
317{
318 if(*write_seen) return;
319 if((node->type & NODE_FUNCTION_CALL) && !conditional && is_hoistable_call(node,loop_variable,assigned,info))
320 {
321 push_node(dst,node);
322 return;
323 }
324 if(node->type & NODE_IF)
325 {
326 const bool uniform = node->lhs && is_uniform_condition(node->lhs,loop_variable,assigned);
327 if(node->lhs) find_hoistable_calls(node->lhs,loop_variable,assigned,info,conditional,write_seen,dst);
328 if(node->rhs) find_hoistable_calls(node->rhs,loop_variable,assigned,info,conditional || !uniform,write_seen,dst);
329 return;
330 }
331 const bool cond = conditional || (node->type & NODE_TERNARY) || is_loop_statement(node);
332 if(node->lhs) find_hoistable_calls(node->lhs,loop_variable,assigned,info,cond,write_seen,dst);
333 if(node->rhs) find_hoistable_calls(node->rhs,loop_variable,assigned,info,cond || is_logical_binary_expression(node),write_seen,dst);
334 const char* name = get_func_call_name(node);
335 if(name)
336 {
337 const int index = str_vec_get_index(info->funcs,name);
338 if(is_side_effect_call_name(name) || (index >= 0 && info->has_side_effects[index])) *write_seen = true;
339 }
340}
341static ASTNode*
342create_non_returning_call_statement(const char* func_name)
343{
344 node_vec params = VEC_INITIALIZER;
345 ASTNode* call = create_func_call(func_name,params);
346 ASTNode* basic_statement = astnode_create(NODE_UNKNOWN,call,NULL);
347 astnode_set_postfix(";",basic_statement);
348 basic_statement->token = NON_RETURNING_FUNC_CALL;
349 return create_basic_statement(basic_statement);
350}
352static long_loop_action
353hoist_iteration_specific_calls(ASTNode* node, loop_hoist_info* info)
354{
355 ASTNode* body = node->rhs;
356 if(!body || !(body->type & NODE_BEGIN_SCOPE) || !body->lhs || !(body->lhs->type & NODE_STATEMENT_LIST_HEAD)) return LOOP_KEEP_ROLLED;
357 const char* loop_variable = node->lhs->rhs->lhs->buffer;
358 string_vec assigned = VEC_INITIALIZER;
359 collect_assigned_identifiers(body,&assigned);
361 bool write_seen = false;
362 find_hoistable_calls(body,loop_variable,assigned,info,false,&write_seen,&calls);
363 free_str_vec(&assigned);
364 if(calls.size == 0)
365 {
366 free_node_vec(&calls);
367 return LOOP_KEEP_ROLLED;
368 }
369 //TP: unrolled as before if all the stencils of the hoisted calls are called on the same arrays also outside long loops
370 bool used_elsewhere = true;
371 for(size_t i = 0; i < calls.size && used_elsewhere; ++i)
372 {
374 collect_loop_indexed_arrays(calls.data[i]->rhs,loop_variable,&arrays);
376 const string_vec* stencils = get_callee_stencils(info,get_func_call_name(calls.data[i]),&tmp);
377 if(arrays.size == 0) used_elsewhere = false;
378 for(size_t a = 0; a < arrays.size && used_elsewhere; ++a)
379 for(size_t st = 0; st < stencils->size && used_elsewhere; ++st)
380 if(!used_outside_long_loops(info,arrays.data[a],stencils->data[st])) used_elsewhere = false;
381 free_str_vec(&tmp);
382 free_str_vec(&arrays);
383 }
384 if(used_elsewhere)
385 {
386 free_node_vec(&calls);
387 return LOOP_UNROLL;
388 }
389 ASTNode* head = body->lhs;
390 while(head->lhs && (head->lhs->type & NODE_STATEMENT_LIST_HEAD)) head = head->lhs;
391 push_to_statement_list(head,create_non_returning_call_statement("ac_dynamic_stencils_begin"));
392 //TP: the same call is hoisted only once
393 string_vec hoisted_calls = VEC_INITIALIZER;
394 string_vec hoisted_vars = VEC_INITIALIZER;
395 for(size_t i = 0; i < calls.size; ++i)
396 {
397 ASTNode* call = (ASTNode*)calls.data[i];
398 const char* call_str = intern(combine_all_new(call));
399 const int index = str_vec_get_index(hoisted_calls,call_str);
400 if(index >= 0)
401 {
402 replace_node(call,create_primary_expression(hoisted_vars.data[index]));
403 continue;
404 }
405 //TP: numbered per function such that the otherwise identical copies of a kernel stay identical (see dedup_optimized_kernels)
406 const char* var_name = sprintf_intern("ac_loop_hoisted_%d",info->hoist_counter++);
407 //TP: typed such that remove_dead_writes can remove the hoisted calls that are not needed
408 const char* type = get_expr_type(call);
409 ASTNode* call_copy = astnode_dup(call,NULL);
410 replace_node(call,create_primary_expression(var_name));
411 push_to_statement_list(head,create_assignment(create_declaration(var_name,type,CONST_STR),call_copy,EQ_STR));
412 push(&hoisted_calls,call_str);
413 push(&hoisted_vars,var_name);
414 }
415 free_str_vec(&hoisted_calls);
416 free_str_vec(&hoisted_vars);
417 push_to_statement_list(head,create_non_returning_call_statement("ac_dynamic_stencils_end"));
418 free_node_vec(&calls);
419 return LOOP_HOISTED;
420}
421static void
422unroll_constant_loops_recursive(ASTNode* node, loop_hoist_info* info)
423{
424 if(node->type & NODE_FUNCTION)
425 {
426 const int counter = info->hoist_counter;
427 info->hoist_counter = 0;
428 if(node->lhs) unroll_constant_loops_recursive(node->lhs,info);
429 if(node->rhs) unroll_constant_loops_recursive(node->rhs,info);
430 info->hoist_counter = counter;
431 return;
432 }
433 TRAVERSE_PREAMBLE_PARAMS(unroll_constant_loops_recursive,info);
434 bool literal_bounds = false;
435 int start_value = 0;
436 const int trip_count = get_const_loop_trip_count_base(node,&literal_bounds,&start_value);
437 if(trip_count < 0) return;
438 if(trip_count > MAX_UNROLL_ITERATIONS && hoist_iteration_specific_calls(node,info) != LOOP_UNROLL) return;
439 if(!literal_bounds) return;
440 const ASTNode* for_expr = node->lhs->rhs;
441 const char* loop_variable = for_expr->lhs->buffer;
442 const ASTNode* iterated_body = node->rhs;
443 //TP: a compound body has to stay a scope also for the DSL: with only the {} emitted for the C++ compiler
444 //the declarations of the later iterations are generated as assignments to variables
445 //that the C++ compiler sees declared only inside the {} of the first iteration
446 //if(iterated_body->type & NODE_BEGIN_SCOPE && iterated_body->lhs) iterated_body = iterated_body->lhs;
447
448 const int end_value = start_value + trip_count;
450 for(int i = start_value; i < end_value; ++i)
451 {
452 const char* replacement = intern(itoa(i));
453 ASTNode* res = astnode_dup(iterated_body,NULL);
454 replace_variable_with_constant_int(res,loop_variable,replacement);
455 push_node(&nodes,res);
456
457 }
458 ASTNode* res = build_list_node(nodes,"");
459 //res is null if we have 0:0 loop then no need to replace
460 //or if we have some other error we should skip unrolling since it is optional and thus return
461 if(res == NULL) return;
462 free_node_vec(&nodes);
463 replace_node(node,res);
464 if(node->parent->type == NODE_BEGIN_SCOPE)
465 node->parent->type = NODE_UNKNOWN;
466}
467void
469{
470 loop_hoist_info info = get_loop_hoist_info(root);
471 unroll_constant_loops_recursive(root,&info);
472 free_loop_hoist_info(&info);
473}
@ NODE_STENCIL
Definition ast.h:75
@ NODE_ASSIGNMENT
Definition ast.h:84
@ NODE_FUNCTION_CALL
Definition ast.h:92
@ NODE_TERNARY
Definition ast.h:81
@ NODE_ARRAY_ACCESS
Definition ast.h:89
@ NODE_FUNCTION
Definition ast.h:98
@ NODE_DECLARATION
Definition ast.h:72
@ NODE_DFUNCTION
Definition ast.h:66
@ NODE_STATEMENT_LIST_HEAD
Definition ast.h:90
@ NODE_IF
Definition ast.h:91
@ NODE_BEGIN_SCOPE
Definition ast.h:71
@ NODE_UNKNOWN
Definition ast.h:64
HASHMAP_WEAK int hashmap_create(const hashmap_uint32_t initial_capacity, struct hashmap_s *const out_hashmap)
Create a hashmap.
Definition hashtable.h:295
HASHMAP_WEAK void hashmap_destroy(struct hashmap_s *const hashmap)
Destroy the hashmap.
Definition hashtable.h:494
HASHMAP_WEAK void * hashmap_get(const struct hashmap_s *const hashmap, const void *const key, const hashmap_uint32_t len)
Get an element from the hashmap.
Definition hashtable.h:364
HASHMAP_WEAK int hashmap_put(struct hashmap_s *const hashmap, const void *const key, const hashmap_uint32_t len, void *const value)
Put an element into the hashmap.
Definition hashtable.h:334
#define MAX_UNROLL_ITERATIONS
Definition loop_hoisting.h:7
long_loop_action
Definition loop_hoisting.h:351
@ LOOP_KEEP_ROLLED
Definition loop_hoisting.h:351
@ LOOP_UNROLL
Definition loop_hoisting.h:351
@ LOOP_HOISTED
Definition loop_hoisting.h:351
void unroll_constant_loops(ASTNode *root)
Definition loop_hoisting.h:468
int counter
Definition string_vec.h:123
#define VEC_INITIALIZER
Definition string_vec.h:7
Definition ast.h:146
struct astnode_s * lhs
Definition ast.h:148
struct astnode_s * rhs
Definition ast.h:149
NodeType type
Definition ast.h:157
struct astnode_s * parent
Definition ast.h:147
int token
Definition ast.h:156
const char * buffer
Definition ast.h:150
Definition loop_hoisting.h:18
bool * has_side_effects
Definition loop_hoisting.h:23
int hoist_counter
Definition loop_hoisting.h:25
struct hashmap_s used_outside_long_loops
Definition loop_hoisting.h:24
node_vec func_callees
Definition loop_hoisting.h:21
string_vec funcs
Definition loop_hoisting.h:20
node_vec func_stencils
Definition loop_hoisting.h:22
string_vec stencils
Definition loop_hoisting.h:19
Definition ast.h:874
size_t size
Definition ast.h:876
const ASTNode ** data
Definition ast.h:875
Definition string_vec.h:9
size_t size
Definition string_vec.h:11
const char ** data
Definition string_vec.h:10
__device__ AcReal stencils[NUM_STENCILS][STENCIL_DEPTH][STENCIL_HEIGHT][STENCIL_WIDTH]
static __device__ const int const int index
Definition user_kernel.h:128