bool dump::visit(region_node& n, bool enter) { if (enter) { indent(); dump_flags(n); sblog << "region #" << n.region_id << " "; dump_common(n); if (!n.vars_defined.empty()) { sblog << "vars_defined: "; dump_set(sh, n.vars_defined); } dump_live_values(n, true); ++level; if (n.loop_phi) run_on(*n.loop_phi); } else { --level; if (n.phi) run_on(*n.phi); indent(); dump_live_values(n, false); } return true; }
void peephole::run_on(container_node* c) { for (node_riterator I = c->rbegin(), E = c->rend(); I != E; ++I) { node *n = *I; if (n->is_container()) run_on(static_cast<container_node*>(n)); else { if (n->is_alu_inst()) { alu_node *a = static_cast<alu_node*>(n); if (a->bc.op_ptr->flags & AF_CC_MASK) { optimize_cc_op(a); } else if (a->bc.op == ALU_OP1_FLT_TO_INT) { alu_node *s = a; if (get_bool_flt_to_int_source(s)) { convert_float_setcc(a, s); } } } } } }
void ra_checker::run_on(container_node* c) { if (c->is_region()) { region_node *r = static_cast<region_node*>(c); if (r->loop_phi) { check_phi_src(r->loop_phi, 0); process_phi_dst(r->loop_phi); } } else if (c->is_depart()) { push_stack(); } else if (c->is_repeat()) { push_stack(); } for (node_iterator I = c->begin(), E = c->end(); I != E; ++I) { node *n = *I; if(n->is_cf_inst() || n->is_fetch_inst()) { check_op_src(n); process_op_dst(n); } if (n->is_container()) { if (n->is_alu_group()) { check_alu_group(static_cast<alu_group_node*>(n)); } else { container_node *nc = static_cast<container_node*>(n); run_on(nc); } } } if (c->is_depart()) { depart_node *r = static_cast<depart_node*>(c); check_phi_src(r->target->phi, r->dep_id); pop_stack(); } else if (c->is_repeat()) { repeat_node *r = static_cast<repeat_node*>(c); assert (r->target->loop_phi); pop_stack(); } else if (c->is_region()) { region_node *r = static_cast<region_node*>(c); if (r->phi) process_phi_dst(r->phi); } }
int ra_checker::run() { rm_stack.clear(); rm_stack.resize(1); rm_stk_level = 0; process_op_dst(sh.root); run_on(sh.root); assert(rm_stk_level == 0); dump_all_errors(); assert(sh.errors.empty()); return 0; }
void bc_finalizer::run_on(container_node* c) { node *prev_node = NULL; for (node_iterator I = c->begin(), E = c->end(); I != E; ++I) { node *n = *I; if (n->is_alu_group()) { finalize_alu_group(static_cast<alu_group_node*>(n), prev_node); } else { if (n->is_alu_clause()) { cf_node *c = static_cast<cf_node*>(n); if (c->bc.op == CF_OP_ALU_PUSH_BEFORE && ctx.is_egcm()) { if (ctx.stack_workaround_8xx) { region_node *r = c->get_parent_region(); if (r) { unsigned ifs, loops; unsigned elems = get_stack_depth(r, loops, ifs); unsigned dmod1 = elems % ctx.stack_entry_size; unsigned dmod2 = (elems + 1) % ctx.stack_entry_size; if (elems && (!dmod1 || !dmod2)) c->flags |= NF_ALU_STACK_WORKAROUND; } } else if (ctx.stack_workaround_9xx) { region_node *r = c->get_parent_region(); if (r) { unsigned ifs, loops; get_stack_depth(r, loops, ifs); if (loops >= 2) c->flags |= NF_ALU_STACK_WORKAROUND; } } } } else if (n->is_fetch_inst()) { finalize_fetch(static_cast<fetch_node*>(n)); } else if (n->is_cf_inst()) { finalize_cf(static_cast<cf_node*>(n)); } if (n->is_container()) run_on(static_cast<container_node*>(n)); } prev_node = n; } }
void *test_xchg_lock(void *arg) { int me = (long)arg; run_on(me); atomic_inc(&nthreadsrunning); while (READ_ONCE(goflag) == GOFLAG_INIT) poll(NULL, 0, 1); while (READ_ONCE(goflag) == GOFLAG_RUN) { xchg_lock(&testlock); if (owner != -1) lockerr++; lockacqs++; owner = me; poll(NULL, 0, 1); owner = -1; xchg_unlock(&testlock); } return NULL; }
void *seqlock_read_test(void *arg) { int i; int j; int me = (long)arg; long long n_errs_local = 0LL; long long n_reads_local = 0LL; long long n_retries_local = 0LL; long long n_retries_local_cur = 0LL; unsigned long old; unsigned long seq; run_on(me); atomic_inc(&nthreadsrunning); while (ACCESS_ONCE(goflag) == GOFLAG_INIT) poll(NULL, 0, 1); while (ACCESS_ONCE(goflag) == GOFLAG_RUN) { for (i = COUNT_READ_RUN; i > 0; i--) { n_retries_local_cur = -1; do { seq = read_seqbegin(&test_seqlock); old = testarray[0]; n_errs_local = 0; n_retries_local_cur++; for (j = 1; j < n_elems; j++) { if (old + 1 != testarray[j]) n_errs_local++; old = testarray[j]; } } while (read_seqretry(&test_seqlock, seq)); n_retries_local += n_retries_local_cur; barrier(); } n_reads_local += COUNT_READ_RUN; } __get_thread_var(n_reads_pt) += n_reads_local; __get_thread_var(n_read_retries_pt) += n_retries_local; __get_thread_var(n_read_errs_pt) += n_errs_local; return (NULL); }
void def_use::run_on(node* n, bool defs) { bool is_region = (n->type == NT_REGION); bool is_op = (n->type == NT_OP || n->type == NT_IF); if (is_op) { if (0) { sblog << "def_use processing op "; dump::dump_op(n); sblog << "\n"; } if (defs) process_defs(n, n->dst, false); else process_uses(n); } else if (is_region & defs) { region_node *r = static_cast<region_node*>(n); if (r->loop_phi) process_phi(r->loop_phi, true, false); } if (n->is_container() && n->subtype != NST_ALU_PACKED_INST) { container_node *c = static_cast<container_node*>(n); for (node_iterator I = c->begin(), E = c->end(); I != E; ++I) { run_on(*I, defs); } } if (is_region) { region_node *r = static_cast<region_node*>(n); if (r->phi) process_phi(r->phi, defs, !defs); if (r->loop_phi && !defs) process_phi(r->loop_phi, false, true); } }
void *seqlock_write_test(void *arg) { int i; int j; int me = (long)arg; long long n_writes_local = 0LL; run_on(me); atomic_inc(&nthreadsrunning); while (ACCESS_ONCE(goflag) == GOFLAG_INIT) poll(NULL, 0, 1); while (ACCESS_ONCE(goflag) == GOFLAG_RUN) { for (i = COUNT_UPDATE_RUN; i > 0; i--) { write_seqlock(&test_seqlock); for (j = 0; j < n_elems; j++) testarray[j]++; write_sequnlock(&test_seqlock); barrier(); } n_writes_local += COUNT_UPDATE_RUN; } __get_thread_var(n_writes_pt) += n_writes_local; return NULL; }
int bc_finalizer::run() { run_on(sh.root); regions_vec &rv = sh.get_regions(); for (regions_vec::reverse_iterator I = rv.rbegin(), E = rv.rend(); I != E; ++I) { region_node *r = *I; assert(r); bool loop = r->is_loop(); if (loop) finalize_loop(r); else finalize_if(r); r->expand(); } cf_peephole(); // workaround for some problems on r6xx/7xx // add ALU NOP to each vertex shader if (!ctx.is_egcm() && (sh.target == TARGET_VS || sh.target == TARGET_ES)) { cf_node *c = sh.create_clause(NST_ALU_CLAUSE); alu_group_node *g = sh.create_alu_group(); alu_node *a = sh.create_alu(); a->bc.set_op(ALU_OP0_NOP); a->bc.last = 1; g->push_back(a); c->push_back(g); sh.root->push_back(c); c = sh.create_cf(CF_OP_NOP); sh.root->push_back(c); last_cf = c; } if (!ctx.is_cayman() && last_cf->bc.op_ptr->flags & CF_ALU) { last_cf = sh.create_cf(CF_OP_NOP); sh.root->push_back(last_cf); } if (ctx.is_cayman()) { if (!last_cf) { cf_node *c = sh.create_cf(CF_OP_CF_END); sh.root->push_back(c); } else last_cf->insert_after(sh.create_cf(CF_OP_CF_END)); } else last_cf->bc.end_of_program = 1; for (unsigned t = EXP_PIXEL; t < EXP_TYPE_COUNT; ++t) { cf_node *le = last_export[t]; if (le) le->bc.set_op(CF_OP_EXPORT_DONE); } sh.ngpr = ngpr; sh.nstack = nstack; return 0; }
int def_use::run() { run_on(sh.root, true); run_on(sh.root, false); return 0; }
int main(int argc, char **argv) { Bish::CodeGenerators::initialize(); int c; bool run_after_compile = false; std::string code_generator_name = "bash"; while ((c = getopt(argc,argv, "hrlu:")) != -1) { switch (c) { case 'h': usage(argv[0]); return 0; case 'r': run_after_compile = true; break; case 'l': show_generators_list(); return 1; case 'u': code_generator_name = std::string(optarg); break; default: break; } } if (optind >= argc) { usage(argv[0]); return 1; } std::string path(argv[optind]); std::stringstream s; Bish::Parser p; Bish::Module *m = path.compare("-") == 0 ? p.parse(std::cin) : p.parse(path); std::string args; if (optind + 1 < argc) { if (!run_after_compile) { std::cerr << "Can't pass arguments to script without -r.\n"; return 1; } for (unsigned i = optind+1; i < argc; i++) { args += argv[i]; args += " "; } } Bish::CodeGenerators::CodeGeneratorConstructor cg_constructor = Bish::CodeGenerators::get(code_generator_name); if (cg_constructor == NULL) { std::cerr << "No code generator " << code_generator_name << std::endl; return 1; } Bish::CodeGenerator *cg = cg_constructor(run_after_compile ? s : std::cout); Bish::compile(m, cg); if (run_after_compile) { const int exit_status = run_on(code_generator_name, s, args); exit(exit_status); } return 0; }