-/**
- * 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_place_env_t *penv = env;
- opcode opc = get_irn_opcode(irn);
-
- /* transform only firm consts which are not already visited */
- if ((opc != iro_Const && opc != iro_SymConst) || bitset_is_set(penv->visited, get_irn_idx(irn)))
- return;
-
- /* mark const visited */
- bitset_set(penv->visited, get_irn_idx(irn));
-
- ia32_transform_const(irn, penv->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);
- }
-}
-
-/**
- * Walks over the graph, transforms all firm consts into ia32 consts
- * and places them into the "best" block.
- * @param cg The ia32 codegenerator object
- */
-static void ia32_transform_all_firm_consts(ia32_code_gen_t *cg) {
- ia32_place_env_t penv;
-
- penv.cg = cg;
- penv.visited = bitset_irg_malloc(cg->irg);
- irg_walk_graph(cg->irg, NULL, ia32_place_consts_walker, &penv);
- bitset_free(penv.visited);
-}
-
-/* Place all consts and change pointer arithmetics into unsigned integer arithmetics. */