static memerr process_node(rewrite_sampler_accesses_context *ctx, node *n, essl_bool change_type) { if(_essl_ptrset_has(&ctx->visited, n)) { return MEM_OK; } if(_essl_node_is_texture_operation(n)) { node *sampler; node *swz; assert(change_type == ESSL_FALSE); ESSL_CHECK(sampler = GET_CHILD(n, 0)); ESSL_CHECK(swz = _essl_new_unary_expression(ctx->pool, EXPR_OP_SWIZZLE, sampler)); _essl_ensure_compatible_node(swz, sampler); swz->expr.u.swizzle = _essl_create_scalar_swizzle(0); SET_CHILD(n, 0, swz); ESSL_CHECK(process_node(ctx, sampler, ESSL_TRUE)); } if(change_type == ESSL_TRUE) { if(n->hdr.kind == EXPR_KIND_LOAD && _essl_type_is_or_has_sampler(n->hdr.type)) { ESSL_CHECK(n->hdr.type = _essl_get_type_with_given_vec_size(ctx->typestor_ctx, n->hdr.type, 4)); ESSL_CHECK(_essl_ptrset_insert(&ctx->visited, n)); return MEM_OK; } if (n->hdr.kind == EXPR_KIND_PHI) { phi_source *src; for (src = n->expr.u.phi.sources; src != 0; src = src->next) { ESSL_CHECK(process_node(ctx, src->source, change_type)); } }else { unsigned i; for (i = 0; i < GET_N_CHILDREN(n); ++i) { node *child = GET_CHILD(n, i); ESSL_CHECK(process_node(ctx, child, change_type)); } } ESSL_CHECK(n->hdr.type = _essl_get_type_with_given_vec_size(ctx->typestor_ctx, n->hdr.type, 4)); } ESSL_CHECK(_essl_ptrset_insert(&ctx->visited, n)); return MEM_OK; }
/* * drop item from heap * returns heap size */ HEAP_PNT heap_drop(void) { GW_LARGE_INT child, childr, parent; GW_LARGE_INT i; HEAP_PNT child_p, childr_p, last_p, root_p; seg_get(&search_heap, (char *)&last_p, 0, heap_size); seg_get(&search_heap, (char *)&root_p, 0, 1); if (heap_size == 1) { heap_size = 0; return root_p; } parent = 1; while ((child = GET_CHILD(parent)) < heap_size) { seg_get(&search_heap, (char *)&child_p, 0, child); if (child < heap_size) { childr = child + 1; i = child + 8; while (childr < heap_size && childr < i) { seg_get(&search_heap, (char *)&childr_p, 0, childr); if (heap_cmp(&childr_p, &child_p)) { child = childr; child_p = childr_p; } childr++; } } if (heap_cmp(&last_p, &child_p)) { break; } /* move hole down */ seg_put(&search_heap, (char *)&child_p, 0, parent); parent = child; } /* fill hole */ if (parent < heap_size) { seg_put(&search_heap, (char *)&last_p, 0, parent); } /* the actual drop */ heap_size--; return root_p; }
void walk_ast_depthfirst( antlr::tree::Tree *t, std::vector<antlr::tree::Tree *>& out, const Func& is_interesting) { if (t) { if (is_interesting(t)) out.push_back(t); for (unsigned i = 0U; i < GET_CHILD_COUNT(t); ++i) { walk_ast_depthfirst(GET_CHILD(t, i), out, is_interesting); } } }
/* drop point routine for min heap */ HEAP_PNT drop_pt(void) { int child, childr, parent; int i; HEAP_PNT child_p, childr_p, last_p, root_p; seg_get(&search_heap, (char *)&last_p, 0, heap_size); seg_get(&search_heap, (char *)&root_p, 0, 1); /* sift down: move hole back towards bottom of heap */ parent = 1; while ((child = GET_CHILD(parent)) < heap_size) { /* select child with lower ele, if both are equal, older child * older child is older startpoint for flow path, important */ seg_get(&search_heap, (char *)&child_p, 0, child); if (child < heap_size) { childr = child + 1; i = child + 4; while (childr < i && childr < heap_size) { seg_get(&search_heap, (char *)&childr_p, 0, childr); if (cmp_pnt(&childr_p, &child_p)) { child = childr; child_p = childr_p; } childr++; } } if (cmp_pnt(&last_p, &child_p)) { break; } /* move hole down */ seg_put(&search_heap, (char *)&child_p, 0, parent); parent = child; } seg_put(&search_heap, (char *)&last_p, 0, parent); /* the actual drop */ heap_size--; return root_p; }
static void cgen_expression(pSymbol func, pNode expr) { switch (GET_TYPE(expr)) { case EXPRESSION: { // Function call if (!GET_DATA(expr)) { puts("\t# Function call"); pNode iden = GET_CHILD(expr, 0), args = GET_CHILD(expr, 1); for (size_t i = 0; i < GET_SIZE(args); i++) { printf("\t# Arg num %zu\n", i); pNode arg = GET_CHILD(args, i); cgen_expression(func, arg); ASM1(pushq, %rax); } for (size_t i = 1; i <= GET_SIZE(args); i++) FASM1(popq, %s, record[GET_SIZE(args) - i]); FASM1(call, _%s, GET_ENTRY(iden)->name); puts(""); return; } puts("\t# Expression evaluation"); // Unary minus if (GET_SIZE(expr) == 1) { puts("\t# Unary minus"); pNode ch = GET_CHILD(expr, 0); ADDR(movq, cgen_resaddr(func, GET_ENTRY(ch)), %rax); ASM1(negq, %rax); return; } // Normal operator epxression pNode ch0 = GET_CHILD(expr, 0), ch1 = GET_CHILD(expr, 1); // Left hand side cgen_expression(func, ch0); ASM1(pushq, %rax); // Right hand side cgen_expression(func, ch1); ASM1(popq, %r8); switch (*(char *)GET_DATA(expr)) { case '+': puts("\t# Addition"); ASM2(addq, %r8, %rax); break; case '-': puts("\t# Subtraction"); ASM2(subq, %rax, %r8); ASM2(movq, %r8, %rax); break; case '*': puts("\t# Multiplication"); ASM0(cqo); ASM1(imulq, %r8); break; case '/': puts("\t# Divition"); ASM2(xchg, %rax, %r8); ASM0(cqo); ASM1(idivq, %r8); break; } puts(""); break; }