static void replace_with_call(ir_node *node) { widen_builtin(node); ir_type *const mtp = get_Builtin_type(node); ir_builtin_kind const kind = get_Builtin_kind(node); char const *const name = get_builtin_name(kind); ir_type *const arg1 = get_method_param_type(mtp, 0); char const *const machmode = get_gcc_machmode(arg1); ident *const id = new_id_fmt("__%s%s2", name, machmode); ir_entity *const entity = create_compilerlib_entity(get_id_str(id), mtp); dbg_info *const dbgi = get_irn_dbg_info(node); ir_node *const block = get_nodes_block(node); ir_node *const mem = get_Builtin_mem(node); ir_graph *const irg = get_irn_irg(node); ir_node *const callee = new_r_Address(irg, entity); int const n_params = get_Builtin_n_params(node); ir_node **const params = get_Builtin_param_arr(node); ir_node *const call = new_rd_Call(dbgi, block, mem, callee, n_params, params, mtp); ir_node *const call_mem = new_r_Proj(call, mode_M, pn_Call_M); ir_node *const call_ress = new_r_Proj(call, mode_T, pn_Call_T_result); ir_type *const res_type = get_method_res_type(mtp, 0); ir_mode *const res_mode = get_type_mode(res_type); ir_node *const call_res = new_r_Proj(call_ress, res_mode, 0); ir_node *const in[] = { [pn_Builtin_M] = call_mem, [pn_Builtin_max + 1] = call_res, };
/** * dumps a opcode hash into human readable form */ static void simple_dump_opcode_hash(dumper_t *dmp, pset *set) { counter_t f_alive; counter_t f_new_node; counter_t f_Id; counter_t f_normlized; cnt_clr(&f_alive); cnt_clr(&f_new_node); cnt_clr(&f_Id); cnt_clr(&f_normlized); fprintf(dmp->f, "%-16s %-8s %-8s %-8s %-8s\n", "Opcode", "alive", "created", "->Id", "normalized"); foreach_pset(set, node_entry_t, entry) { fprintf(dmp->f, "%-16s %8u %8u %8u %8u\n", get_id_str(entry->op->name), cnt_to_uint(&entry->cnt_alive), cnt_to_uint(&entry->new_node), cnt_to_uint(&entry->into_Id), cnt_to_uint(&entry->normalized) ); cnt_add(&f_alive, &entry->cnt_alive); cnt_add(&f_new_node, &entry->new_node); cnt_add(&f_Id, &entry->into_Id); cnt_add(&f_normlized, &entry->normalized); }
/** * Dumps a node. */ static void vcg_dump_node(pattern_dumper_t *self, unsigned id, unsigned op_code, unsigned mode_code, void *attr) { vcg_private_t *priv = (vcg_private_t*)self->data; ir_op *op = stat_get_op_from_opcode(op_code); ir_mode *mode = ir_get_mode(mode_code); long l = attr ? *(long *)attr : 0; if (priv->pattern_id > priv->max_pattern) return; if (attr) { fprintf(priv->f, " node: {title: \"n%u_%u\" label: \"%s%s %ld n%u\" }\n", priv->pattern_id, id, get_id_str(op->name), mode ? get_mode_name(mode) : "", l, id); } else { fprintf(priv->f, " node: {title: \"n%u_%u\" label: \"%s%s n%u\" }\n", priv->pattern_id, id, get_id_str(op->name), mode ? get_mode_name(mode) : "", id); } }
/** * Dumps a node. */ static void stdout_dump_node(pattern_dumper_t *self, unsigned id, unsigned op_code, unsigned mode_code, void *attr) { FILE *f = (FILE*)self->data; ir_op *op = stat_get_op_from_opcode(op_code); ir_mode *mode = ir_get_mode(mode_code); (void) attr; /* if (env->options & OPT_ENC_GRAPH) */ fprintf(f, "%u:", id); fprintf(f, "%s", get_id_str(op->name)); if (mode) fprintf(f, "%s", get_mode_name(mode)); }
ir_node *x86_match_ASM(ir_node const *const node, x86_clobber_name_t const *const additional_clobber_names, x86_asm_constraint_list_t const *const constraints) { unsigned const n_operands = be_count_asm_operands(node); ir_graph *const irg = get_irn_irg(node); struct obstack *const obst = get_irg_obstack(irg); x86_asm_operand_t *const operands = NEW_ARR_DZ(x86_asm_operand_t, obst, n_operands); int const n_inputs = get_ASM_n_inputs(node); size_t const n_out_constraints = get_ASM_n_output_constraints(node); ir_asm_constraint const *const in_constraints = get_ASM_input_constraints(node); ir_asm_constraint const *const out_constraints = get_ASM_output_constraints(node); /* construct output constraints */ size_t const n_clobbers = get_ASM_n_clobbers(node); arch_register_req_t const **out_reqs = NEW_ARR_F(arch_register_req_t const*, 0); for (unsigned o = 0; o < n_out_constraints; ++o) { ir_asm_constraint const *const constraint = &out_constraints[o]; be_asm_constraint_t parsed_constraint; parse_asm_constraints(&parsed_constraint, constraints, constraint->constraint, true); arch_register_req_t const *const req = be_make_register_req(obst, &parsed_constraint, n_out_constraints, out_reqs, o); ARR_APP1(arch_register_req_t const*, out_reqs, req); x86_asm_operand_t *const op = &operands[constraint->pos]; set_operand_if_invalid(op, ASM_OP_OUT_REG, o, constraint); } /* parse clobbers */ unsigned clobber_bits[isa_if->n_register_classes]; memset(&clobber_bits, 0, sizeof(clobber_bits)); ident **const clobbers = get_ASM_clobbers(node); for (size_t c = 0; c < n_clobbers; ++c) { char const *const clobber = get_id_str(clobbers[c]); arch_register_t const *const reg = x86_parse_clobber(additional_clobber_names, clobber); if (reg != NULL) { assert(reg->cls->n_regs <= sizeof(unsigned) * 8); /* x87 registers may still be used as input, even if clobbered. */ if (reg->cls != &ia32_reg_classes[CLASS_ia32_fp]) clobber_bits[reg->cls->index] |= 1U << reg->index; ARR_APP1(arch_register_req_t const*, out_reqs, reg->single_req); } }
const char* get_type_tpop_name(const ir_type *tp) { assert(tp && tp->kind == k_type); return get_id_str(tp->type_op->name); }
const char *get_mode_name(const ir_mode *mode) { return get_id_str(mode->name); }
main(int argc, char **argv) { pthread_attr_t attr; pthread_t *threadids; void *status; struct ldap_thread_fns tfns; struct ldap_extra_thread_fns extrafns; int rc, c, errflg, i, inited_attr; int doadd, dodelete, domodify, docompare, dosearch, dobind; int option_extthreads, option_restart; int each_thread_count, thread_count; extern int optind; extern char *optarg; doadd = dodelete = domodify = docompare = dobind = dosearch = 0; option_extthreads = option_restart = 0; inited_attr = 0; errflg = 0; each_thread_count = 1; /* how many of each type of thread? */ rc = LDAP_SUCCESS; /* optimistic */ while ((c = getopt(argc, argv, "abcdmrsERi:n:o:S:")) != EOF) { switch (c) { case 'a': /* perform add operations */ ++doadd; break; case 'b': /* perform bind operations */ ++dobind; break; case 'c': /* perform compare operations */ ++docompare; break; case 'd': /* perform delete operations */ ++dodelete; break; case 'm': /* perform modify operations */ ++domodify; break; case 'r': /* use range filters in searches */ ++range_filters; break; case 's': /* perform search operations */ ++dosearch; break; case 'E': /* use extended thread functions */ ++option_extthreads; break; case 'R': /* turn on LDAP_OPT_RESTART */ ++option_restart; break; case 'i': /* highest # used for entry names */ maxid = atoi(optarg); break; case 'n': /* # threads for each operation */ if ((each_thread_count = atoi(optarg)) < 1) { fprintf(stderr, "thread count must be > 0\n"); ++errflg; } break; case 'o': /* operations to perform per thread */ if ((maxops = atoi(optarg)) < 0) { fprintf(stderr, "operation limit must be >= 0\n"); ++errflg; } break; case 'S': /* random number seed */ if (*optarg == 'r') { int seed = (int)time((time_t *)0); srandom(seed); printf("Random seed: %d\n", seed); } else { srandom(atoi(optarg)); } break; default: ++errflg; break; } } /* Check command-line syntax. */ thread_count = each_thread_count * (doadd + dodelete + domodify + dobind + docompare + dosearch); if (thread_count < 1) { fprintf(stderr, "Specify at least one of -a, -b, -c, -d, -m, or -s\n"); ++errflg; } if (errflg || argc - optind != 2) { fprintf(stderr, "usage: %s [-abcdmrsER] [-i id] [-n thr]" " [-o oplim] [-S sd] host port\n", argv[0]); fputs( "\nWhere:\n" "\t\"id\" is the highest entry id (name) to use" " (default is MAXINT)\n" "\t\"thr\" is the number of threads for each operation" " (default is 1)\n" "\t\"oplim\" is the number of ops done by each thread" " (default is infinite)\n" "\t\"sd\" is a random() number seed (default is 1). Use" " the letter r for\n" "\t\tsd to seed random() using time of day.\n" "\t\"host\" is the hostname of an LDAP directory server\n" "\t\"port\" is the TCP port of the LDAP directory server\n", stderr); fputs( "\nAnd the single character options are:\n" "\t-a\tstart thread(s) to perform add operations\n" "\t-b\tstart thread(s) to perform bind operations\n" "\t-c\tstart thread(s) to perform compare operations\n" "\t-d\tstart thread(s) to perform delete operations\n" "\t-m\tstart thread(s) to perform modify operations\n" "\t-s\tstart thread(s) to perform search operations\n" "\t-r\tuse range filters in searches\n" "\t-E\tinstall LDAP_OPT_EXTRA_THREAD_FN_PTRS\n" "\t-R\tturn on LDAP_OPT_RESTART\n", stderr); return (LDAP_PARAM_ERROR); } /* Create a key. */ if (pthread_key_create(&key, free) != 0) { perror("pthread_key_create"); } tsd_setup(); /* Allocate space for thread ids */ if ((threadids = (pthread_t *)calloc(thread_count, sizeof(pthread_t))) == NULL) { rc = LDAP_LOCAL_ERROR; goto clean_up_and_return; } /* Initialize the LDAP session. */ if ((ld = ldap_init(argv[optind], atoi(argv[optind + 1]))) == NULL) { perror("ldap_init"); rc = LDAP_LOCAL_ERROR; goto clean_up_and_return; } /* Set the function pointers for dealing with mutexes and error information. */ memset(&tfns, '\0', sizeof(struct ldap_thread_fns)); tfns.ltf_mutex_alloc = (void *(*)(void))my_mutex_alloc; tfns.ltf_mutex_free = (void (*)(void *))my_mutex_free; tfns.ltf_mutex_lock = (int (*)(void *))pthread_mutex_lock; tfns.ltf_mutex_unlock = (int (*)(void *))pthread_mutex_unlock; tfns.ltf_get_errno = get_errno; tfns.ltf_set_errno = set_errno; tfns.ltf_get_lderrno = get_ld_error; tfns.ltf_set_lderrno = set_ld_error; tfns.ltf_lderrno_arg = NULL; /* Set up this session to use those function pointers. */ rc = ldap_set_option(ld, LDAP_OPT_THREAD_FN_PTRS, (void *)&tfns); if (rc < 0) { rc = ldap_get_lderrno(ld, NULL, NULL); fprintf(stderr, "ldap_set_option (LDAP_OPT_THREAD_FN_PTRS): %s\n", ldap_err2string(rc)); goto clean_up_and_return; } if (option_extthreads) { /* Set the function pointers for working with semaphores. */ memset(&extrafns, '\0', sizeof(struct ldap_extra_thread_fns)); extrafns.ltf_mutex_trylock = (int (*)(void *))pthread_mutex_trylock; extrafns.ltf_sema_alloc = (void *(*)(void))my_sema_alloc; extrafns.ltf_sema_free = (void (*)(void *))my_sema_free; extrafns.ltf_sema_wait = (int (*)(void *))my_sema_wait; extrafns.ltf_sema_post = (int (*)(void *))my_sema_post; /* Set up this session to use those function pointers. */ if (ldap_set_option(ld, LDAP_OPT_EXTRA_THREAD_FN_PTRS, (void *)&extrafns) != 0) { rc = ldap_get_lderrno(ld, NULL, NULL); ldap_perror(ld, "ldap_set_option" " (LDAP_OPT_EXTRA_THREAD_FN_PTRS)"); goto clean_up_and_return; } } if (option_restart && ldap_set_option(ld, LDAP_OPT_RESTART, LDAP_OPT_ON) != 0) { rc = ldap_get_lderrno(ld, NULL, NULL); ldap_perror(ld, "ldap_set_option(LDAP_OPT_RESTART)"); goto clean_up_and_return; } /* Attempt to bind to the server. */ rc = ldap_simple_bind_s(ld, NAME, PASSWORD); if (rc != LDAP_SUCCESS) { fprintf(stderr, "ldap_simple_bind_s: %s\n", ldap_err2string(rc)); goto clean_up_and_return; } /* Initialize the attribute. */ if (pthread_attr_init(&attr) != 0) { perror("pthread_attr_init"); rc = LDAP_LOCAL_ERROR; goto clean_up_and_return; } ++inited_attr; /* Specify that the threads are joinable. */ pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE); /* Create all the requested threads */ thread_count = 0; if (domodify) { for (i = 0; i < each_thread_count; ++i) { if (pthread_create(&threadids[thread_count], &attr, modify_thread, get_id_str(thread_count)) != 0) { perror("pthread_create modify_thread"); rc = LDAP_LOCAL_ERROR; goto clean_up_and_return; } ++thread_count; } } if (doadd) { for (i = 0; i < each_thread_count; ++i) { if (pthread_create(&threadids[thread_count], &attr, add_thread, get_id_str(thread_count)) != 0) { perror("pthread_create add_thread"); rc = LDAP_LOCAL_ERROR; goto clean_up_and_return; } ++thread_count; } } if (dodelete) { for (i = 0; i < each_thread_count; ++i) { if (pthread_create(&threadids[thread_count], &attr, delete_thread, get_id_str(thread_count)) != 0) { perror("pthread_create delete_thread"); rc = LDAP_LOCAL_ERROR; goto clean_up_and_return; } ++thread_count; } } if (dobind) { for (i = 0; i < each_thread_count; ++i) { if (pthread_create(&threadids[thread_count], &attr, bind_thread, get_id_str(thread_count)) != 0) { perror("pthread_create bind_thread"); rc = LDAP_LOCAL_ERROR; goto clean_up_and_return; } ++thread_count; } } if (docompare) { for (i = 0; i < each_thread_count; ++i) { if (pthread_create(&threadids[thread_count], &attr, compare_thread, get_id_str(thread_count)) != 0) { perror("pthread_create compare_thread"); rc = LDAP_LOCAL_ERROR; goto clean_up_and_return; } ++thread_count; } } if (dosearch) { for (i = 0; i < each_thread_count; ++i) { if (pthread_create(&threadids[thread_count], &attr, search_thread, get_id_str(thread_count)) != 0) { perror("pthread_create search_thread"); rc = LDAP_LOCAL_ERROR; goto clean_up_and_return; } ++thread_count; } } /* Wait until these threads exit. */ for (i = 0; i < thread_count; ++i) { pthread_join(threadids[i], &status); } clean_up_and_return: if (ld != NULL) { set_ld_error(0, NULL, NULL, NULL); /* disposes of memory */ ldap_unbind(ld); } if (threadids != NULL) { free(threadids); } if (inited_attr) { pthread_attr_destroy(&attr); } tsd_cleanup(); return (rc); }