diff options
author | Erick Ochoa <erick.ochoa@theobroma-systems.com> | 2020-11-30 16:17:58 +0100 |
---|---|---|
committer | Erick Ochoa <erick.ochoa@theobroma-systems.com> | 2020-11-30 16:17:58 +0100 |
commit | 802f9273ddbb7c28ee56b2453cbaa08ab34d7a29 (patch) | |
tree | 934ff5571e1263546a217b3f0d2cdd34a21f524d | |
parent | 5980da7c775e1c89e54e9cbd3df8b820a6cb3b8f (diff) |
half of type_reconstructor from STL to GCC
-rw-r--r-- | gcc/ipa-dfe.c | 52 | ||||
-rw-r--r-- | gcc/ipa-dfe.h | 14 | ||||
-rw-r--r-- | gcc/ipa-field-reorder.c | 26 |
3 files changed, 47 insertions, 45 deletions
diff --git a/gcc/ipa-dfe.c b/gcc/ipa-dfe.c index a2f580069dd..7f2dd2612db 100644 --- a/gcc/ipa-dfe.c +++ b/gcc/ipa-dfe.c @@ -222,21 +222,17 @@ get_types_replacement (record_field_offset_map_t record_field_offset_map, reconstructor.walk (record); } - reorg_record_map_t map = reconstructor.get_map (); - reorg_record_map2_t map2; - - for (auto i = map.begin(), e = map.end(); i != e; ++i) - { - map2.put(i->first, i->second); - } + //reorg_record_map_t map = reconstructor.get_map (); + reorg_record_map2_t *map2 = reconstructor.get_map2 (); reorg_field_map_t field_map = reconstructor.get_field_map (); + std::map<tree, tree> map; // Here, we are just making sure that we are not doing anything too crazy. // Also, we found some types for which TYPE_CACHED_VALUES_P is not being // rewritten. This is probably indicative of a bug in TypeReconstructor. - for (hash_map<tree, tree>::iterator i = map2.begin (), - e = map2.end (); + for (hash_map<tree, tree>::iterator i = map2->begin (), + e = map2->end (); i != e; ++i) { tree o_record = (*i).first; @@ -246,6 +242,7 @@ get_types_replacement (record_field_offset_map_t record_field_offset_map, std::string r_name = r_record ? stringifier.stringify (r_record) : std::string (""); log ("modified: %s\n", r_name.c_str ()); + map.insert({o_record, r_record}); if (!r_record) continue; tree m_record = TYPE_MAIN_VARIANT (r_record); @@ -254,16 +251,17 @@ get_types_replacement (record_field_offset_map_t record_field_offset_map, TYPE_CACHED_VALUES_P (_o_record) = false; TYPE_CACHED_VALUES_P (m_record) = false; - bool in_map = map2.get (m_record); + bool in_map = map2->get (m_record); if (!in_map) continue; - tree mm_record = *map2.get (m_record); + tree mm_record = *map2->get (m_record); // Info: I think this is no longer needed... // Please verify TYPE_MAIN_VARIANT (r_record) = mm_record; } // TODO: Ok, we will need to change this some time... + return std::make_pair (map, field_map); } @@ -355,10 +353,10 @@ specific_type_collector::_walk_RECORD_TYPE_post (tree t) /* * old RECORD_TYPE -> new RECORD_TYPE. */ -reorg_record_map_t -type_reconstructor::get_map () +reorg_record_map2_t* +type_reconstructor::get_map2 () { - return _reorg_map; + return _reorg_map2; } /* @@ -374,7 +372,7 @@ void type_reconstructor::set_is_not_modified_yet (tree t) { gcc_assert (t); - const bool is_in_reorg_map = _reorg_map.find (t) != _reorg_map.end (); + const bool is_in_reorg_map = _reorg_map2->get (t); modified_map[t] = false; if (is_in_reorg_map) mark_all_pointing_here_as_modified (); @@ -383,11 +381,11 @@ type_reconstructor::set_is_not_modified_yet (tree t) if (!tt) return; - const bool is_in_reorg_map_2 = _reorg_map.find (tt) != _reorg_map.end (); + const bool is_in_reorg_map_2 = _reorg_map2->get (tt); if (!is_in_reorg_map_2) return; - tree type = _reorg_map[tt]; + tree type = *_reorg_map2->get(tt); bool is_modified = strstr (type_stringifier::get_type_identifier (type).c_str (), ".reorg"); is_modified @@ -433,7 +431,7 @@ type_reconstructor::get_is_modified (tree t) bool type_reconstructor::is_memoized (tree t) { - const bool already_changed = _reorg_map.find (t) != _reorg_map.end (); + const bool already_changed = _reorg_map2->get (t); mark_all_pointing_here_as_modified (); return already_changed; } @@ -506,7 +504,7 @@ type_reconstructor::_walk_ARRAY_TYPE_post (tree t) TREE_TYPE (copy) = build_variant_type_copy (TREE_TYPE (copy)); copy = is_modified ? build_distinct_type_copy (copy) : copy; - TREE_TYPE (copy) = is_modified ? _reorg_map[TREE_TYPE (t)] : TREE_TYPE (copy); + TREE_TYPE (copy) = is_modified ? *_reorg_map2->get(TREE_TYPE (t)) : TREE_TYPE (copy); TYPE_NAME (copy) = is_modified ? get_new_identifier (copy, this->get_new_suffix ()) : TYPE_NAME (copy); @@ -535,7 +533,7 @@ type_reconstructor::_walk_ARRAY_TYPE_post (tree t) if (!points_to_record) return; - _reorg_map[t] = is_modified ? copy : _t; + _reorg_map2->put (t, is_modified ? copy : _t); } void @@ -561,7 +559,7 @@ type_reconstructor::_walk_POINTER_TYPE_post (tree t) bool is_modified = get_is_modified (t); copy = is_modified ? build_variant_type_copy (copy) : copy; - TREE_TYPE (copy) = is_modified ? _reorg_map[TREE_TYPE (t)] : TREE_TYPE (copy); + TREE_TYPE (copy) = is_modified ? *_reorg_map2->get(TREE_TYPE (t)) : TREE_TYPE (copy); TYPE_NAME (copy) = is_modified ? get_new_identifier (copy, this->get_new_suffix ()) : TYPE_NAME (copy); @@ -577,7 +575,7 @@ type_reconstructor::_walk_POINTER_TYPE_post (tree t) if (!points_to_record) return; - _reorg_map[t] = is_modified ? copy : _t; + _reorg_map2->put(t, is_modified ? copy : _t); } void @@ -657,7 +655,7 @@ type_reconstructor::_walk_RECORD_TYPE_post (tree t) if (!is_main_variant) { tree main = TYPE_MAIN_VARIANT (t); - tree main_reorg = _reorg_map[main]; + tree main_reorg = *_reorg_map2->get(main); tree copy_variant = build_variant_type_copy (main_reorg); TYPE_NAME (copy_variant) = get_new_identifier (copy, this->get_new_suffix ()); @@ -665,7 +663,7 @@ type_reconstructor::_walk_RECORD_TYPE_post (tree t) TYPE_MAIN_VARIANT (copy_variant) = main_reorg; TYPE_SIZE (main_reorg) = NULL; layout_type (copy_variant); - _reorg_map[t] = copy_variant; + _reorg_map2->put(t, copy_variant); } else { @@ -681,10 +679,10 @@ type_reconstructor::_walk_RECORD_TYPE_post (tree t) if (is_modified) layout_type (copy); tree _t = tree_to_tree (t); - _reorg_map[t] = is_modified ? copy : _t; + _reorg_map2->put(t, is_modified ? copy : _t); } - tree record = _reorg_map[t]; + tree record = *_reorg_map2->get(t); for (tree field = TYPE_FIELDS (record); field; field = DECL_CHAIN (field)) { relayout_decl (field); @@ -736,7 +734,7 @@ type_reconstructor::_walk_field_post (tree t) const bool type_memoized = is_memoized (original_type); TREE_TYPE (copy) - = type_memoized ? _reorg_map[original_type] : TREE_TYPE (copy); + = type_memoized ? *_reorg_map2->get(original_type) : TREE_TYPE (copy); field_tuple_t tuple = std::make_pair (t, can_field_be_deleted ? NULL : copy); diff --git a/gcc/ipa-dfe.h b/gcc/ipa-dfe.h index d869a52a31f..548dd59f1c2 100644 --- a/gcc/ipa-dfe.h +++ b/gcc/ipa-dfe.h @@ -71,13 +71,21 @@ class type_reconstructor : public type_walker public: type_reconstructor (record_field_offset_map_t records, const char *suffix) : _records (records), _suffix (suffix) - {}; + { + _reorg_map2 = new reorg_record_map2_t; + }; + ~type_reconstructor() + { + // I think we need this a little bit longer... + // but I don't think there is a copy constructor for this... + delete _reorg_map2; + } /* Whether a type has already been modified. */ virtual bool is_memoized (tree t); // Final result for record map. - reorg_record_map_t get_map (); + reorg_record_map2_t *get_map2 (); /* Final result for field map. */ reorg_field_map_t get_field_map (); @@ -114,7 +122,7 @@ protected: field_tuple_list_stack_t field_list_stack; // old RECORD_TYPE -> new RECORD_TYPE - reorg_record_map_t _reorg_map; + reorg_record_map2_t *_reorg_map2; // old FIELD_DECL -> new FIELD_DECL reorg_field_map_t _reorg_fields; diff --git a/gcc/ipa-field-reorder.c b/gcc/ipa-field-reorder.c index 11e5320b096..751c986c380 100644 --- a/gcc/ipa-field-reorder.c +++ b/gcc/ipa-field-reorder.c @@ -342,7 +342,7 @@ TypeReconstructorFieldReordering::_walk_RECORD_TYPE_post (tree t) if (!is_main_variant) { tree main = TYPE_MAIN_VARIANT (t); - tree main_reorg = _reorg_map[main]; + tree main_reorg = *_reorg_map2->get(main); tree copy_variant = build_distinct_type_copy (main_reorg); TYPE_NAME (copy_variant) = get_new_identifier (copy, this->get_new_suffix ()); @@ -350,7 +350,7 @@ TypeReconstructorFieldReordering::_walk_RECORD_TYPE_post (tree t) TYPE_ALIAS_SET (copy_variant) = -1; layout_type (copy_variant); TYPE_MAIN_VARIANT (copy_variant) = main_reorg; - _reorg_map[t] = copy_variant; + _reorg_map2->put (t, copy_variant); } else { @@ -366,10 +366,10 @@ TypeReconstructorFieldReordering::_walk_RECORD_TYPE_post (tree t) if (is_modified) layout_type (copy); tree _t = tree_to_tree (t); - _reorg_map[t] = is_modified ? copy : _t; + _reorg_map2->put (t, is_modified ? copy : _t); } - tree record = _reorg_map[t]; + tree record = *_reorg_map2->get(t); for (tree field = TYPE_FIELDS (record); field; field = DECL_CHAIN (field)) { relayout_decl (field); @@ -551,13 +551,8 @@ get_reordered_field_maps (record_field_offset_map_t record_field_offset_map, } typedef hash_map<tree, tree> reorg_record_map2_t; - reorg_record_map2_t map2; - reorg_record_map_t map = reconstructor.get_map (); - - for (auto i = map.begin(), e = map.end(); i != e; ++i) - { - map2.put((*i).first, (*i).second); - } + reorg_record_map2_t *map2 = reconstructor.get_map2 (); + std::map<tree, tree> map; reorg_field_map_t field_map = reconstructor.get_field_map (); @@ -565,8 +560,8 @@ get_reordered_field_maps (record_field_offset_map_t record_field_offset_map, // Also, we found some types for which TYPE_CACHED_VALUES_P is not being // rewritten. This is probably indicative of a bug in // TypeReconstructorFieldReordering. - for (reorg_record_map2_t::iterator i = map2.begin (), - e = map2.end (); + for (reorg_record_map2_t::iterator i = map2->begin (), + e = map2->end (); i != e; ++i) { tree o_record = (*i).first; @@ -576,6 +571,7 @@ get_reordered_field_maps (record_field_offset_map_t record_field_offset_map, std::string r_name = r_record ? stringifier.stringify (r_record) : std::string (""); log ("modified: %s\n", r_name.c_str ()); + map.insert({o_record, r_record}); if (!r_record) continue; tree m_record = TYPE_MAIN_VARIANT (r_record); @@ -584,10 +580,10 @@ get_reordered_field_maps (record_field_offset_map_t record_field_offset_map, TYPE_CACHED_VALUES_P (_o_record) = false; TYPE_CACHED_VALUES_P (m_record) = false; - bool in_map = map2.get (m_record); + bool in_map = map2->get (m_record); if (!in_map) continue; - tree mm_record = *map2.get(m_record); + tree mm_record = *map2->get(m_record); // Info: I think this is no longer needed... // Please verify TYPE_MAIN_VARIANT (r_record) = mm_record; |