-static int be_is_NoReg(ia32_code_gen_t *cg, const ir_node *irn) {
- be_abi_irg_t *babi = cg->birg->abi;
- const arch_register_t *fp_noreg = USE_SSE2(cg) ?
- &ia32_xmm_regs[REG_XMM_NOREG] : &ia32_vfp_regs[REG_VFP_NOREG];
-
- return (be_abi_get_callee_save_irn(babi, &ia32_gp_regs[REG_GP_NOREG]) == irn) ||
- (be_abi_get_callee_save_irn(babi, fp_noreg) == irn);
-}
-
-
-
-/*************************************************
- * _____ _ _
- * / ____| | | | |
- * | | ___ _ __ ___| |_ __ _ _ __ | |_ ___
- * | | / _ \| '_ \/ __| __/ _` | '_ \| __/ __|
- * | |___| (_) | | | \__ \ || (_| | | | | |_\__ \
- * \_____\___/|_| |_|___/\__\__,_|_| |_|\__|___/
- *
- *************************************************/
-
-/**
- * creates a unique ident by adding a number to a tag
- *
- * @param tag the tag string, must contain a %d if a number
- * should be added
- */
-static ident *unique_id(const char *tag)
-{
- static unsigned id = 0;
- char str[256];
-
- snprintf(str, sizeof(str), tag, ++id);
- return new_id_from_str(str);
-}
-
-/**
- * Transforms a SymConst.
- *
- * @param mod the debug module
- * @param block the block the new node should belong to
- * @param node the ir SymConst node
- * @param mode mode of the SymConst
- * @return the created ia32 Const node
- */
-static ir_node *gen_SymConst(ia32_transform_env_t *env) {
- dbg_info *dbg = env->dbg;
- ir_mode *mode = env->mode;
- ir_graph *irg = env->irg;
- ir_node *block = env->block;
- ir_node *cnst;
-
- if (mode_is_float(mode)) {
- FP_USED(env->cg);
- if (USE_SSE2(env->cg))
- cnst = new_rd_ia32_xConst(dbg, irg, block, get_irg_no_mem(irg), mode);
- else
- cnst = new_rd_ia32_vfConst(dbg, irg, block, get_irg_no_mem(irg), mode);
- }
- else
- cnst = new_rd_ia32_Const(dbg, irg, block, get_irg_no_mem(irg), mode);
-
- set_ia32_Const_attr(cnst, env->irn);
-
- return cnst;
-}
-
-/**
- * Get a primitive type for a mode.
- */
-static ir_type *get_prim_type(pmap *types, ir_mode *mode)
-{
- pmap_entry *e = pmap_find(types, mode);
- ir_type *res;
-
- if (! e) {
- char buf[64];
- snprintf(buf, sizeof(buf), "prim_type_%s", get_mode_name(mode));
- res = new_type_primitive(new_id_from_str(buf), mode);
- pmap_insert(types, mode, res);
- }
- else
- res = e->value;
- return res;
-}
-
-/**
- * Get an entity that is initialized with a tarval
- */
-static entity *get_entity_for_tv(ia32_code_gen_t *cg, ir_node *cnst)
-{
- tarval *tv = get_Const_tarval(cnst);
- pmap_entry *e = pmap_find(cg->isa->tv_ent, tv);
- entity *res;
- ir_graph *rem;
-
- if (! e) {
- ir_mode *mode = get_irn_mode(cnst);
- ir_type *tp = get_Const_type(cnst);
- if (tp == firm_unknown_type)
- tp = get_prim_type(cg->isa->types, mode);
-
- res = new_entity(get_glob_type(), unique_id(".LC%u"), tp);
-
- set_entity_ld_ident(res, get_entity_ident(res));
- set_entity_visibility(res, visibility_local);
- set_entity_variability(res, variability_constant);
- set_entity_allocation(res, allocation_static);
-
- /* we create a new entity here: It's initialization must resist on the
- const code irg */
- rem = current_ir_graph;
- current_ir_graph = get_const_code_irg();
- set_atomic_ent_value(res, new_Const_type(tv, tp));
- current_ir_graph = rem;
-
- pmap_insert(cg->isa->tv_ent, tv, res);
- }
- else
- res = e->value;
- return res;
-}
-
-/**
- * Transforms a Const.
- *
- * @param mod the debug module
- * @param block the block the new node should belong to
- * @param node the ir Const node
- * @param mode mode of the Const
- * @return the created ia32 Const node
- */
-static ir_node *gen_Const(ia32_transform_env_t *env) {
- ir_node *cnst, *load;
- symconst_symbol sym;
- ir_graph *irg = env->irg;
- ir_node *block = env->block;
- ir_node *node = env->irn;
- dbg_info *dbg = env->dbg;
- ir_mode *mode = env->mode;
-
- if (mode_is_float(mode)) {
- FP_USED(env->cg);
- if (! USE_SSE2(env->cg)) {
- cnst_classify_t clss = classify_Const(node);
-
- if (clss == CNST_NULL)
- return new_rd_ia32_vfldz(dbg, irg, block, mode);
- else if (clss == CNST_ONE)
- return new_rd_ia32_vfld1(dbg, irg, block, mode);
- }
- sym.entity_p = get_entity_for_tv(env->cg, node);
-
-
- cnst = new_rd_SymConst(dbg, irg, block, sym, symconst_addr_ent);
- load = new_r_Load(irg, block, get_irg_no_mem(irg), cnst, mode);
- load = new_r_Proj(irg, block, load, mode, pn_Load_res);
- env->irn = cnst;
- env->mode = mode_P;
- cnst = gen_SymConst(env);
- set_Load_ptr(get_Proj_pred(load), cnst);
- cnst = load;
- }
- else {
- cnst = new_rd_ia32_Const(dbg, irg, block, get_irg_no_mem(irg), get_irn_mode(node));
- set_ia32_Const_attr(cnst, node);
- }
- return cnst;
-}
-
-/**
- * Transforms (all) Const's into ia32_Const and places them in the
- * block where they are used (or in the cfg-pred Block in case of Phi's).
- * Additionally all reference nodes are changed into mode_Is nodes.
- * NOTE: irn must be a firm constant!
- */
-static void ia32_transform_const(ir_node *irn, void *env) {
- ia32_code_gen_t *cg = env;
- ir_node *cnst = NULL;
- ia32_transform_env_t tenv;
-
- tenv.cg = cg;
- tenv.irg = cg->irg;
- tenv.mode = get_irn_mode(irn);
- tenv.dbg = get_irn_dbg_info(irn);
- tenv.irn = irn;
- DEBUG_ONLY(tenv.mod = cg->mod;)
-
- /* place const either in the smallest dominator of all its users or the original block */
- if (cg->opt & IA32_OPT_PLACECNST)
- tenv.block = node_users_smallest_common_dominator(irn, 1);
- else
- tenv.block = get_nodes_block(irn);
-
- switch (get_irn_opcode(irn)) {
- case iro_Const:
- cnst = gen_Const(&tenv);
- break;
- case iro_SymConst:
- cnst = gen_SymConst(&tenv);
- break;
- default:
- assert(0 && "Wrong usage of ia32_transform_const!");
- }
-
- assert(cnst && "Could not create ia32 Const");
-
- /* set the new ia32 const */
- exchange(irn, cnst);
-}
-
-/**
- * Transform all firm consts and assure, we visit each const only once.
- */
-static void ia32_place_consts_walker(ir_node *irn, void *env) {
- ia32_code_gen_t *cg = env;
-
- if(!is_Const(irn) && !is_SymConst(irn))
- return;
-
- ia32_transform_const(irn, cg);
-}
-
-/**
- * Replace reference modes with mode_Iu and preserve store value modes.
- */
-static void ia32_set_modes(ir_node *irn, void *env) {
- if (is_Block(irn))
- return;
-
- /* transform all reference nodes into mode_Iu nodes */
- if (mode_is_reference(get_irn_mode(irn))) {
- set_irn_mode(irn, mode_Iu);
- }