8 #include "firm_types.h"
10 #include "ia32_new_nodes.h"
11 #include "bearch_ia32_t.h"
14 * creates a unique ident by adding a number to a tag
16 * @param tag the tag string, must contain a %d if a number
19 static ident *unique_id(const char *tag)
21 static unsigned id = 0;
24 snprintf(str, sizeof(str), tag, ++id);
25 return new_id_from_str(str);
31 * Transforms a SymConst.
33 * @param mod the debug module
34 * @param block the block the new node should belong to
35 * @param node the ir SymConst node
36 * @param mode mode of the SymConst
37 * @return the created ia32 Const node
39 static ir_node *gen_SymConst(ia32_transform_env_t *env) {
41 dbg_info *dbg = env->dbg;
42 ir_mode *mode = env->mode;
43 ir_graph *irg = env->irg;
44 ir_node *block = env->block;
46 if (mode_is_float(mode)) {
47 cnst = new_rd_ia32_fConst(dbg, irg, block, mode);
51 cnst = new_rd_ia32_Const(dbg, irg, block, mode);
54 set_ia32_Const_attr(cnst, env->irn);
61 * @param mod the debug module
62 * @param block the block the new node should belong to
63 * @param node the ir Const node
64 * @param mode mode of the Const
65 * @return the created ia32 Const node
67 static ir_node *gen_Const(ia32_transform_env_t *env) {
72 dbg_info *dbg = env->dbg;
73 ir_mode *mode = env->mode;
74 ir_graph *irg = env->irg;
75 ir_node *block = env->block;
76 ir_node *node = env->irn;
78 if (mode_is_float(mode)) {
79 tp = get_Const_type(node);
80 if (tp == firm_unknown_type) {
81 tp = new_type_primitive(unique_id("tp_ia32_float_%u"), mode);
84 ent = new_entity(get_glob_type(), unique_id("ia32FloatCnst_%u"), tp);
86 set_entity_ld_ident(ent, get_entity_ident(ent));
87 set_entity_visibility(ent, visibility_local);
88 set_entity_variability(ent, variability_constant);
89 set_entity_allocation(ent, allocation_static);
91 set_atomic_ent_value(ent, node);
95 cnst = new_rd_SymConst(dbg, irg, block, sym, symconst_addr_ent);
97 cnst = gen_SymConst(env);
100 cnst = new_rd_ia32_Const(dbg, irg, block, mode);
101 set_ia32_Const_attr(cnst, node);
110 * Transforms (all) Const's into ia32_Const and places them in the
111 * block where they are used (or in the cfg-pred Block in case of Phi's)
113 void ia32_place_consts(ir_node *irn, void *env) {
114 ia32_code_gen_t *cg = env;
115 ia32_transform_env_t tenv;
117 ir_node *pred, *cnst;
124 mode = get_irn_mode(irn);
126 tenv.arch_env = cg->arch_env;
127 tenv.block = get_nodes_block(irn);
130 tenv.mod = firm_dbg_register("ir.be.ia32.optimize");
132 /* Loop over all predecessors and check for Sym/Const nodes */
133 for (i = 0; i < get_irn_arity(irn); i++) {
134 pred = get_irn_n(irn, i);
136 opc = get_irn_opcode(pred);
138 tenv.mode = get_irn_mode(pred);
139 tenv.dbg = get_irn_dbg_info(pred);
141 /* If it's a Phi, then we need to create the */
142 /* new Const in it's predecessor block */
144 tenv.block = get_Block_cfgpred_block(get_nodes_block(irn), i);
149 cnst = gen_Const(&tenv);
152 cnst = gen_SymConst(&tenv);
158 /* if we found a const, then set it */
160 set_irn_n(irn, i, cnst);