From f4de6f96601cf42390dae0d5874506f8c3db5859 Mon Sep 17 00:00:00 2001 From: Erick Ochoa Date: Mon, 22 Jun 2020 17:04:30 +0200 Subject: cleanup --- gcc/expr-rewriter.c | 69 +++++++----------------------------------- gcc/ipa-type-escape-analysis.c | 43 +++++++++----------------- gcc/type-reconstructor.c | 14 +++++++++ 3 files changed, 40 insertions(+), 86 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; } diff --git a/gcc/ipa-type-escape-analysis.c b/gcc/ipa-type-escape-analysis.c index fbb85fa746b..8b9ff5bbee1 100644 --- a/gcc/ipa-type-escape-analysis.c +++ b/gcc/ipa-type-escape-analysis.c @@ -156,28 +156,15 @@ collect_types() collector.walk(); collector.print_collected(); ptrset_t types = collector.get_pointer_set(); - // what if we had 2 sets here - // points_to_record and not_points_to_record - //GimpleEscaper gimpleEscaper(types); - //gimpleEscaper.walk(); - //if (flag_print_escape_analysis) gimpleEscaper.print_reasons(); - //ptrset_t escaping = gimpleEscaper.get_sets(); GimpleCaster caster(types); caster.walk(); if (flag_print_cast_analysis) caster.print_reasons(); - // what if we had other 2 sets here - // is_escaping and is_not_escaping - // We intersect is_not_escaping and points_to_record ptrset_t casting = caster.get_sets(); - // Here we need to do fixed point... fix_escaping_types_in_set(casting); GimpleAccesser accesser; accesser.walk(); if (flag_print_access_analysis) accesser.print_accesses(); record_field_map_t record_field_map = accesser.get_map(); - // here we need something similar... - // We need to say that for all records on field_map... if two are equal - // then we will need to mark OR the accesses to fields TypeIncompleteEquality equality; bool has_fields_that_can_be_deleted = false; typedef std::set field_offsets_t; @@ -278,6 +265,15 @@ collect_types() TypeReconstructor reconstructor(record_field_offset_map); TypeStringifier stringifier; + // TODO: + // Here, what we want to do is we want to rewrite only the + // types which we believe we can rewrite, that and all types which + // point to those types... + // + // Otherwise, it will lead to difficulties in the future since + // we could be modifying many different types. + // So we have to make sure that we are only modifying the types of interest. + for (auto i = types.points_to_record.cbegin(), e = types.points_to_record.cend(); i != e; ++i) { @@ -286,6 +282,12 @@ collect_types() log("%s\n", name_from.c_str()); bool points_to_record = false; const_tree tt = record; + + //TODO: + //This is our little hack to make sure that we are + //only modifying types which are of interest. + //However, we really shouldn't. + //Let's clean the input to reconstructor.walk while (TREE_TYPE(tt)) { tt = TREE_TYPE(tt); }; points_to_record = TREE_CODE(tt) == RECORD_TYPE; if (!points_to_record) continue; @@ -298,21 +300,6 @@ collect_types() TypeReconstructor::reorg_record_map_t map = reconstructor.get_map(); TypeReconstructor::reorg_field_map_t field_map = reconstructor.get_field_map(); - for (auto i = map.cbegin(), e = map.cend(); i != e; ++i) - { - const_tree from = i->first; - const_tree to = i->second; - std::string name_from = stringifier.stringify(from); - std::string name_to = to ? stringifier.stringify(to) : std::string("NULL"); - tree mv = TYPE_MAIN_VARIANT(to); - std::string name_mv = to ? stringifier.stringify(mv) : std::string("NULL"); - log("%s -> %s\n", name_from.c_str(), name_to.c_str()); - log("TYPE_MAIN_VARIANT(%s) = %s\n", name_to.c_str(), name_mv.c_str()); - tree type_size_unit_tree = TYPE_SIZE_UNIT(to); - int type_size_unit_int = tree_fits_uhwi_p(type_size_unit_tree) ? tree_to_uhwi(type_size_unit_tree) : -1; - log("TYPE_SIZE_UNIT(%s) = %d\n", name_to.c_str(), type_size_unit_int); - } - GimpleTypeRewriter rewriter(map, field_map); rewriter.walk(); rewriter._rewrite_function_decl(); diff --git a/gcc/type-reconstructor.c b/gcc/type-reconstructor.c index f39dec94484..34f793f36b5 100644 --- a/gcc/type-reconstructor.c +++ b/gcc/type-reconstructor.c @@ -34,6 +34,20 @@ #include "type-stringifier.hpp" #include "stor-layout.h" + +// TODO: +// I think it might be possible that we need to create +// new nodes as opposed to copying the nodes. +// I say this because I think the copy is a shallow copy +// and it might be making things difficult if we don't +// know everything that is happening... +// so we might want to rewrite this class... +// +// +// TODO: +// Also, there's a bug in which the TYPE_MAIN_VARIANT is an old type... +// which is not a good thing. + void TypeReconstructor::set_is_not_modified_yet(const_tree t) { -- cgit v1.2.3