diff options
author | Erick Ochoa <erick.ochoa@theobroma-systems.com> | 2020-06-18 14:51:02 +0200 |
---|---|---|
committer | Erick Ochoa <erick.ochoa@theobroma-systems.com> | 2020-06-18 19:21:40 +0200 |
commit | 40aaf5f878de333caa96e7758fe758948dfd568e (patch) | |
tree | 91a5f746c432e5563b0f0cade9c04d527fcde6d4 | |
parent | 28f7c5935fcdf371223bf0ad62d8ee26e32f205d (diff) |
fixes memref
-rw-r--r-- | gcc/testsuite/gcc.dg/ipa/ipa-structreorg-42-mem-ref-0.c | 10 | ||||
-rw-r--r-- | gcc/type-reconstructor.c | 48 | ||||
-rw-r--r-- | gcc/type-walker.hpp | 2 |
3 files changed, 38 insertions, 22 deletions
diff --git a/gcc/testsuite/gcc.dg/ipa/ipa-structreorg-42-mem-ref-0.c b/gcc/testsuite/gcc.dg/ipa/ipa-structreorg-42-mem-ref-0.c index 5cc493d2f3f..527bf4058f2 100644 --- a/gcc/testsuite/gcc.dg/ipa/ipa-structreorg-42-mem-ref-0.c +++ b/gcc/testsuite/gcc.dg/ipa/ipa-structreorg-42-mem-ref-0.c @@ -1,7 +1,8 @@ /* { dg-do link } */ -/* { dg-options "-flto -flto-partition=none -fipa-dead-field-eliminate -fdump-ipa-structure-reorg -fipa-typelist-field=nextout -fipa-typelist-struct=arc" } */ +/* { dg-options "-flto -fipa-type-escape-analysis -fdump-ipa-type-escape-analysis " } */ #include <stdlib.h> +#include <stdio.h> typedef struct arc arc_t; typedef struct arc *arc_p; @@ -12,7 +13,8 @@ struct arc long cost; void *tail, *head; short ident; - arc_p nextout, nextin; + arc_p nextout; + arc_p nextin; long flow; long org_cost; }; @@ -25,5 +27,9 @@ main () register arc_t *arcnew = (arc_t*) malloc (num_threads * sizeof (arc_p)); deleted_arcs = (arc_p *) malloc (num_threads * num_threads * sizeof (arc_p)); deleted_arcs[num_threads - 1][num_threads - 1] = arcnew[0]; + printf("%d %d %d %d %d %d %d %d\n", arcnew->id, arcnew->cost, arcnew->tail, arcnew->head, arcnew->ident, arcnew->nextin, arcnew->flow, arcnew->org_cost); return 0; } + +/* { dg-final { scan-ipa-dump "replacing field flow 448 with flow 384" "type-escape-analysis" } } */ +/* { dg-final { scan-ipa-dump "replacing field org_cost 512 with flow 448" "type-escape-analysis" } } */ diff --git a/gcc/type-reconstructor.c b/gcc/type-reconstructor.c index df48c39267f..4c214165c75 100644 --- a/gcc/type-reconstructor.c +++ b/gcc/type-reconstructor.c @@ -180,6 +180,14 @@ TypeReconstructor::_walk_POINTER_TYPE_post(const_tree t) void TypeReconstructor::_walk_RECORD_TYPE_pre(const_tree t) { + const bool is_main_variant = TYPE_MAIN_VARIANT(t) == t; + if (!is_main_variant) { + const_tree main_variant = TYPE_MAIN_VARIANT(t); + _walk_RECORD_TYPE_pre(main_variant); + TypeWalker::_walk_RECORD_TYPE(main_variant); + _walk_RECORD_TYPE_post(main_variant); + } + set_is_not_modified_yet(t); for_reference.push(t); // We don't know if we will modify this type t @@ -208,6 +216,7 @@ TypeReconstructor::_walk_RECORD_TYPE_post(const_tree t) // So, now we want to do a couple of things. // First, is we need to change the TYPE_FIELDS // of the copy + bool is_modified = get_is_modified(t); tree prev_field = NULL; for (auto i = field_tuple_list.cbegin(), e = field_tuple_list.cend(); i != e; ++i) { @@ -215,6 +224,7 @@ TypeReconstructor::_walk_RECORD_TYPE_post(const_tree t) const_tree original_field = field_tuple.first; tree modified_field = field_tuple.second; if (!modified_field) { + is_modified = true; continue; } @@ -228,7 +238,21 @@ TypeReconstructor::_walk_RECORD_TYPE_post(const_tree t) } - bool is_modified = get_is_modified(t); + const bool is_main_variant = TYPE_MAIN_VARIANT(t) == t; + // We already must have done the main variant... + if (!is_main_variant) + { + tree main = TYPE_MAIN_VARIANT(t); + tree main_reorg = _reorg_map[main]; + TypeStringifier stringifier; + std::string main_s = stringifier.stringify(main_reorg); + tree copy_variant = build_variant_type_copy(main_reorg); + TYPE_NAME(copy_variant) = get_new_identifier(copy); + //TYPE_SIZE(copy_variant) = NULL; + //layout_type(copy_variant); + _reorg_map[t] = copy_variant; + return; + } // Ok, so now that we have fixed the TYPE_FIELDS of the copy... // We need to call layout_type copy = is_modified ? build_distinct_type_copy(copy) : copy; @@ -237,21 +261,6 @@ TypeReconstructor::_walk_RECORD_TYPE_post(const_tree t) TYPE_SIZE(copy) = is_modified ? NULL : TYPE_SIZE(copy); if (is_modified) layout_type(copy); _reorg_map[t] = is_modified ? copy : (tree)t; - - /* - if (for_reference.empty()) return; - gcc_assert(!in_progress.empty()); - - // Now we need to find out - // if we are modifying something in the parent as well? - const_tree possible_field = for_reference.top(); - const enum tree_code code = TREE_CODE(possible_field); - const bool is_field = FIELD_DECL == code; - if (!is_field) return; - - tree field_in_progress = in_progress.top(); - TREE_TYPE(field_in_progress) = copy; - */ } void @@ -310,13 +319,14 @@ TypeReconstructor::_walk_field_post(const_tree t) if (can_field_be_deleted) mark_all_pointing_here_as_modified(); const_tree original_type = TREE_TYPE(t); const bool type_memoized = is_memoized(original_type); - // here we did a modification - TREE_TYPE(copy) = type_memoized ? _reorg_map[TREE_TYPE(t)] : TREE_TYPE(copy); + TREE_TYPE(copy) = type_memoized ? _reorg_map[original_type] : TREE_TYPE(copy); + field_tuple_t tuple = std::make_pair(t, can_field_be_deleted ? NULL : copy); // Put the field into the vector field_tuple_list_t &field_tuple_list = field_list_stack.top(); field_tuple_list.push_back(tuple); - _reorg_fields[t] = copy; + const bool already_has_field = _reorg_fields.find(t) != _reorg_fields.end(); + _reorg_fields[t] = already_has_field ? _reorg_fields[t] : copy; } diff --git a/gcc/type-walker.hpp b/gcc/type-walker.hpp index 1849b601bd4..c2172dedf80 100644 --- a/gcc/type-walker.hpp +++ b/gcc/type-walker.hpp @@ -10,7 +10,7 @@ public: protected: typedef std::set<const_tree> tset_t; -private: +protected: tset_t tset; void _walk(const_tree t); |