summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErick Ochoa <erick.ochoa@theobroma-systems.com>2020-05-11 15:21:45 +0200
committerErick Ochoa <erick.ochoa@theobroma-systems.com>2020-05-11 15:21:45 +0200
commitf83a37c808392a8a6dddd214f58dae929ded95f4 (patch)
tree455f5e50ce11447870f8ec5204d7dab2d2864ea9
parent64f58f3e4c9230a77ecf069018c8fff151114bcb (diff)
Type playground performs comparisons
-rw-r--r--gcc/compare-types.c21
-rw-r--r--gcc/compare-types.h4
-rw-r--r--gcc/ipa-hello-world.c33
-rw-r--r--gcc/name-types.c1
4 files changed, 53 insertions, 6 deletions
diff --git a/gcc/compare-types.c b/gcc/compare-types.c
index 641cc1fca90..860a0de076a 100644
--- a/gcc/compare-types.c
+++ b/gcc/compare-types.c
@@ -31,7 +31,7 @@
#include "compare-types.h"
#include "types-inlines.h"
-static bool
+bool
eq_main_variant(const_tree a, const_tree b)
{
gcc_assert(a && b);
@@ -150,8 +150,8 @@ eq_function_or_method_types(const_tree a, const_tree b, const bool force_structu
const bool different_lengths = (bool)parm_a != (bool)parm_b;
if (different_lengths) return false;
- const_tree parm_type_a = TREE_TYPE(parm_a);
- const_tree parm_type_b = TREE_TYPE(parm_b);
+ const_tree parm_type_a = TREE_VALUE(parm_a);
+ const_tree parm_type_b = TREE_VALUE(parm_b);
gcc_assert(parm_type_a && parm_type_b);
const bool same_field_types = eq_types(parm_type_a, parm_type_b, force_structural);
if (!same_field_types) return false;
@@ -248,7 +248,7 @@ eq_structural(const_tree a, const_tree b, const bool force_structural)
return false;
}
-static bool
+bool
eq_canonical(const_tree a, const_tree b)
{
gcc_assert(a && b);
@@ -259,6 +259,19 @@ eq_canonical(const_tree a, const_tree b)
return are_equal;
}
+
+bool
+eq_type_compare(const_tree a, const_tree b)
+{
+ return eq_types(a, b);
+}
+
+bool
+eq_type_structural(const_tree a, const_tree b)
+{
+ return eq_types(a, b, true);
+}
+
bool
eq_types(const_tree a, const_tree b, const bool force_structural)
{
diff --git a/gcc/compare-types.h b/gcc/compare-types.h
index 63474713807..68a79ce4c0a 100644
--- a/gcc/compare-types.h
+++ b/gcc/compare-types.h
@@ -1,4 +1,8 @@
#pragma once
namespace test_type_equality { void run_tests(); };
+extern bool eq_main_variant(const_tree a, const_tree b);
+extern bool eq_canonical(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);
diff --git a/gcc/ipa-hello-world.c b/gcc/ipa-hello-world.c
index 72294961af6..a6b6aa5a36c 100644
--- a/gcc/ipa-hello-world.c
+++ b/gcc/ipa-hello-world.c
@@ -36,6 +36,16 @@
#include "collect-types.h"
#include "name-types.h"
+namespace type_playground {
+static unsigned const type_comparisons = 4;
+typedef bool (*type_comparison_func_t)(const_tree, const_tree);
+static type_comparison_func_t comparisons[type_comparisons] = {
+ eq_main_variant,
+ eq_canonical,
+ eq_type_structural,
+ eq_type_compare
+};
+}
inline void
log(const char* const fmt, ...)
@@ -122,6 +132,27 @@ print_types_in_set(typeset &types)
}
}
+static void
+compare_types_in_set(typeset &types)
+{
+ for (auto i = types.cbegin(); i != types.cend(); ++i)
+ {
+ for (auto j = types.cbegin(); j != types.cend(); ++j)
+ {
+ const_tree a = *i;
+ const_tree b = *j;
+ log("%s x %s = ", type_to_string(a).c_str(), type_to_string(b).c_str());
+ for (unsigned k = 0; k < type_playground::type_comparisons; k++)
+ {
+ type_playground::type_comparison_func_t comparison = type_playground::comparisons[k];
+ const bool result = comparison(a, b);
+ log("%s, ", result ? "t" : "f");
+ }
+ log("\n");
+ }
+ }
+}
+
static unsigned int
iphw_execute()
{
@@ -135,7 +166,7 @@ iphw_execute()
collect_types_from_functions_with_gimple_body(node, types);
}
- print_types_in_set(types);
+ compare_types_in_set(types);
return 0;
}
diff --git a/gcc/name-types.c b/gcc/name-types.c
index fb490d0c8f4..693ebf28400 100644
--- a/gcc/name-types.c
+++ b/gcc/name-types.c
@@ -103,7 +103,6 @@ type_to_string_get_type_size(const_tree type)
if (fits_shwi) return tree_to_shwi (type_size);
return 0;
-
}
static const std::string