diff options
author | Erick Ochoa <erick.ochoa@theobroma-systems.com> | 2020-05-28 10:07:29 +0200 |
---|---|---|
committer | Erick Ochoa <erick.ochoa@theobroma-systems.com> | 2020-05-28 10:07:29 +0200 |
commit | fe1741a4a31cd2d5b430d53322f886865ede5787 (patch) | |
tree | 209f67ebab420910ca1e11cf9c8acd3af4d66d71 | |
parent | 2117ebc711d83376589e8e08d16ed7dadc869a16 (diff) |
comparison weird case
-rw-r--r-- | gcc/compare-types.c | 16 | ||||
-rw-r--r-- | gcc/compare-types.h | 23 | ||||
-rw-r--r-- | gcc/ipa-hello-world.c | 48 | ||||
-rw-r--r-- | gcc/ipa-type-collector.c | 2 | ||||
-rw-r--r-- | gcc/types-inlines.h | 9 |
5 files changed, 79 insertions, 19 deletions
diff --git a/gcc/compare-types.c b/gcc/compare-types.c index 7a476432118..9a615c2dd2a 100644 --- a/gcc/compare-types.c +++ b/gcc/compare-types.c @@ -40,7 +40,7 @@ is_incomplete_type(const_tree a) return NULL_TREE == type_size; } -bool +unsigned eq_main_variant(const_tree a, const_tree b) { gcc_assert(a && b); @@ -51,7 +51,7 @@ eq_main_variant(const_tree a, const_tree b) return are_equal; } -bool +unsigned eq_canonical_internal(const_tree a, const_tree b) { gcc_assert(a && b); @@ -195,13 +195,13 @@ eq_method_types(const_tree a, const_tree b, const bool force_structural) static bool eq_structural(const_tree a, const_tree b, const bool force_structural = false); -bool +unsigned eq_pointer(const_tree a, const_tree b) { return a == b; } -bool +unsigned eq_identifier(const_tree a, const_tree b) { // TODO: Note, we have had the following miscomparison: @@ -283,7 +283,7 @@ eq_structural(const_tree a, const_tree b, const bool force_structural) return false; } -bool +unsigned eq_canonical(const_tree a, const_tree b) { gcc_assert(a && b); @@ -295,19 +295,19 @@ eq_canonical(const_tree a, const_tree b) } -bool +unsigned eq_type_compare(const_tree a, const_tree b) { return eq_types(a, b); } -bool +unsigned eq_type_structural(const_tree a, const_tree b) { return eq_types(a, b, true); } -bool +unsigned eq_types(const_tree a, const_tree b, const bool force_structural) { gcc_assert(a && b); diff --git a/gcc/compare-types.h b/gcc/compare-types.h index 2c690fc3081..384819ce2d7 100644 --- a/gcc/compare-types.h +++ b/gcc/compare-types.h @@ -1,11 +1,18 @@ #pragma once + namespace test_type_equality { void run_tests(); }; -extern bool eq_identifier(const_tree a, const_tree b); -extern bool eq_pointer(const_tree a, const_tree b); -extern bool eq_main_variant(const_tree a, const_tree b); -extern bool eq_canonical(const_tree a, const_tree b); -extern bool eq_canonical_internal(const_tree a, const_tree b); -extern bool eq_type_compare(const_tree a, const_tree b); -extern bool eq_type_structural(const_tree a, const_tree b); -extern bool eq_types(const_tree a, const_tree b, const bool force_structural = false); + +static constexpr unsigned not_equal = 0; +static constexpr unsigned equal_incomplete = 1 << 1; +// equal should be the last one +static constexpr unsigned equal = 1 << 2; + +extern unsigned eq_identifier(const_tree a, const_tree b); +extern unsigned eq_pointer(const_tree a, const_tree b); +extern unsigned eq_main_variant(const_tree a, const_tree b); +extern unsigned eq_canonical(const_tree a, const_tree b); +extern unsigned eq_canonical_internal(const_tree a, const_tree b); +extern unsigned eq_type_compare(const_tree a, const_tree b); +extern unsigned eq_type_structural(const_tree a, const_tree b); +extern unsigned eq_types(const_tree a, const_tree b, const bool force_structural = false); diff --git a/gcc/ipa-hello-world.c b/gcc/ipa-hello-world.c index 68e152a5d81..98cf274e6c6 100644 --- a/gcc/ipa-hello-world.c +++ b/gcc/ipa-hello-world.c @@ -33,6 +33,7 @@ #include "ipa-type-collector.h" #include "ipa-hello-world.h" #include <map> +#include <vector> //#define OPTIMIZED #define SANITY_CHECKS @@ -626,12 +627,53 @@ sanity_check_escape_xor_not(ptrset_t &types) const_tree type_non = *j; gcc_assert(type_non); const bool valid_sets = !eq_type_compare(type_esc, type_non); + if (valid_sets) continue; log("comparing %s == %s\n", type_to_string(type_esc).c_str(), type_to_string(type_non).c_str()); - gcc_assert(valid_sets); + //gcc_assert(valid_sets); } } } +static void +fix_escaping_types_in_set(ptrset_t &types) +{ + std::vector<const_tree> fixes; + for (auto i = types.escaping.cbegin(), e = types.escaping.cend(); i != e; ++i) + { + for (auto j = types.non_escaping.cbegin(), f = types.non_escaping.cend(); j != f; ++j) + { + const_tree type_esc = *i; + gcc_assert(type_esc); + const_tree type_non = *j; + gcc_assert(type_non); + // There can be cases where incomplete types are marked as non-escaping + // and complete types counter parts are marked as escaping. + const bool interesting_case = eq_type_compare(type_esc, type_non); + if (!interesting_case) continue; + + // TODO: I would really like to constrain this more + // By making sure that they are equal explicitly because of incompletenes... + // * type_non must be incomplete + // * type_non must be pointing to an incomplete type and match the structure of type_esc (those which can be compared) + log("checking for incompleteness %s == %s\n", type_to_string(type_esc).c_str(), type_to_string(type_non).c_str()); + if (is_complete(type_non)) continue; + + log("fixing %s == %s\n", type_to_string(type_esc).c_str(), type_to_string(type_non).c_str()); + // Add incomplete to escaping + // delete incomplete from non_escaping + // We shouldn't do that inside our iteration loop. + fixes.push_back(type_non); + } + } + + for (auto i = fixes.cbegin(), e = fixes.cend(); i != e; ++i) + { + const_tree escaping_type = *i; + types.escaping.insert(escaping_type); + types.non_escaping.erase(escaping_type); + } +} + static unsigned int iphw_execute() { @@ -643,8 +685,10 @@ iphw_execute() // Do not read escape analysis results from here calculate_escaping_types(types, eacalc); place_escaping_types_in_set(types, eacalc); - print_escaping_types(eacalc); sanity_check_escape_xor_not(types); + fix_escaping_types_in_set(types); + sanity_check_escape_xor_not(types); + gcc_assert(false); return 0; } diff --git a/gcc/ipa-type-collector.c b/gcc/ipa-type-collector.c index e8c3130a74a..9b70cea5c0d 100644 --- a/gcc/ipa-type-collector.c +++ b/gcc/ipa-type-collector.c @@ -61,7 +61,7 @@ static const char* names[type_comparisons] = { "EQ_STRUCTURAL", "EQ_COMPARE" }; -typedef bool (*type_comparison_func_t)(const_tree, const_tree); +typedef unsigned (*type_comparison_func_t)(const_tree, const_tree); static type_comparison_func_t comparisons[type_comparisons] = { eq_pointer, eq_identifier, diff --git a/gcc/types-inlines.h b/gcc/types-inlines.h index e9d35d95cc1..404176c7cea 100644 --- a/gcc/types-inlines.h +++ b/gcc/types-inlines.h @@ -29,6 +29,15 @@ assert_is_complete(const_tree a) gcc_assert(NULL_TREE != type_size); } +inline bool +is_complete(const_tree a) +{ + gcc_assert(a); + const_tree type_size = TYPE_SIZE(a); + const bool _is_complete = NULL_TREE != type_size; + return _is_complete; +} + inline void assert_is_type(const_tree a, const enum tree_code expected_code) { |