diff options
Diffstat (limited to 'gcc/expr-rewriter.c')
-rw-r--r-- | gcc/expr-rewriter.c | 69 |
1 files changed, 11 insertions, 58 deletions
diff --git a/gcc/expr-rewriter.c b/gcc/expr-rewriter.c index fc45233de92..746c23b6c0b 100644 --- a/gcc/expr-rewriter.c +++ b/gcc/expr-rewriter.c @@ -35,8 +35,6 @@ ExprTypeRewriter::_walk_PARM_DECL_post(const_tree t) tree ttemp = TREE_TYPE(temp); const bool is_interesting = is_interesting_type(ttemp); if (!is_interesting) return; - log("interesting parameter\n"); - relayout_decl(temp); } @@ -50,7 +48,7 @@ ExprTypeRewriter::_walk_FUNCTION_DECL_post(const_tree t) TypeStringifier stringifier; std::string name = stringifier.stringify(ret_type); - // TODO: You cannot use is interesting here because you haven't + // WARNING: You cannot use is interesting here because you haven't // changed the return type // This is because the return type is not an expression. // Therefore it is awkward to do this in the expr-walker... @@ -60,28 +58,19 @@ ExprTypeRewriter::_walk_FUNCTION_DECL_post(const_tree t) tree r_t = _map[ret_type]; TREE_TYPE(fn_type) = r_t; - std::string r_t_2 = stringifier.stringify(r_t); - log("rewriting %s with %s return type\n", name.c_str(), r_t_2.c_str()); - //relayout_decl((tree)t); - - } void ExprTypeRewriter::_walk_MEM_REF_post(const_tree e) { - // The second operand is a pointer constant. Its type specifying - // the type used for type based alias analysis + // The second operand is a pointer constant. + // Its type specifying the type used for type based alias analysis tree op1 = TREE_OPERAND(e, 1); gcc_assert(TREE_CODE(op1) == INTEGER_CST); tree t = TREE_TYPE(op1); const bool already_rewritten = is_interesting_type(t); - // Let's find out what is the previous offset - int old_offset = tree_to_uhwi(op1); - log("old offset is %d\n", old_offset); - // This is where we do the transformation if (!already_rewritten) return; @@ -97,30 +86,23 @@ ExprTypeRewriter::_walk_MEM_REF_post(const_tree e) tree reorg_type_size_tree = TYPE_SIZE_UNIT(reorg_base_type); int reorg_type_size_int = tree_to_shwi(reorg_type_size_tree); + // Let's find out what is the previous offset + int old_offset = tree_to_uhwi(op1); int remainder = old_offset % old_type_size_int; int new_offset = old_offset / old_type_size_int * reorg_type_size_int + remainder; tree new_offset_tree = build_int_cst(TREE_TYPE(op1), new_offset); TREE_OPERAND(e, 1) = new_offset_tree; - log ("we rewrote old offset with %d\n", new_offset); } void ExprTypeRewriter::_walk_SSA_NAME_post(const_tree t) { - tree temp = (tree)(t); - bool is_interesting = SSA_NAME_VAR(temp) != NULL_TREE; - if (!is_interesting) return; - - tree ttemp = TREE_TYPE(temp); - is_interesting = ttemp ? is_interesting_type(ttemp) : false; - if (!is_interesting) return; - log("interesting ssa name\n"); - - //relayout_decl(SSA_NAME_VAR(temp)); } +//TODO: +//Change name of this method... bool ExprTypeRewriter::is_interesting_type(tree t) { @@ -362,16 +344,14 @@ ExprTypeRewriter::_walk_post(const_tree e) const enum tree_code code = TREE_CODE(e); tree r_t = _map[t]; - TypeStringifier stringifier; - const std::string r_t_name = stringifier.stringify(r_t); - const std::string t_name = stringifier.stringify(t); - log("replacing %s with %s in %s\n", t_name.c_str(), r_t_name.c_str(), get_tree_code_name(code)); TREE_TYPE((tree)e) = r_t; tree type_main_variant = TYPE_MAIN_VARIANT(TREE_TYPE(e)); - std::string mv_name = stringifier.stringify(type_main_variant); const bool do_we_have_mv_in_map = _map.find(type_main_variant) != _map.end(); + + // TODO: Fix this hack + // We need to make sure that the type main variant is already good here... TYPE_MAIN_VARIANT(TREE_TYPE(e)) = do_we_have_mv_in_map ? _map[type_main_variant] : TYPE_MAIN_VARIANT(TREE_TYPE(e)); - log("What is my type main variant? %s\n", mv_name.c_str()); + } void @@ -381,11 +361,6 @@ ExprTypeRewriter::_walk_COMPONENT_REF_post(const_tree e) const_tree r = TREE_OPERAND(e, 0); tree record_type = TREE_TYPE(r); const bool in_map1 = _map.find(record_type) != _map.end(); - TypeStringifier stringifier; - std::string name = stringifier.stringify(record_type); - log("component ref HERE HERE %s in map ? %s\n", in_map1 ? "t" : "f", name.c_str()); - //TREE_TYPE((tree)e) = in_map1 ? _map[record_type] : TREE_TYPE((tree)r); - const_tree f = TREE_OPERAND(e, 1); // So, what we need is a map between this field and the new field @@ -405,30 +380,8 @@ ExprTypeRewriter::_walk_COMPONENT_REF_post(const_tree e) unsigned nf_offset = 8 * nf_byte_offset + nf_bit_offset; TREE_OPERAND(e, 1) = n_f; - tree record = DECL_CONTEXT(n_f); - - // It is possible here that we are in a write - // and we need to delete this gimple statment. - // So, how do we know if it is a write? - // Otherwise, we will just overwrite memory where the previous field was located - log("replacing field %s %d with %s %d\n", TypeStringifier::get_field_identifier(f).c_str(), f_offset, TypeStringifier::get_field_identifier(n_f).c_str(), nf_offset); - - gcc_assert(record); - assert_is_type(record, RECORD_TYPE); - const bool in_map3 = _map.find(record) != _map.end(); - std::string context_name = stringifier.stringify(record); - log("what is the declaration context of this field? %s\n", context_name.c_str()); - // For some reason context is the old type... so let's see if we can change it.. - DECL_CONTEXT(n_f) = in_map3 ? _map[record] : DECL_CONTEXT(n_f); - context_name = stringifier.stringify(DECL_CONTEXT(n_f)); - if (in_map3) relayout_decl(n_f); - log("did my context changed? %s\n", context_name.c_str()); - - - if (!is_deleted) return; - log("deleting field %s %d\n", TypeStringifier::get_field_identifier(f).c_str(), f_offset); _delete = true; } |