summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErick Ochoa <erick.ochoa@theobroma-systems.com>2020-06-05 12:36:32 +0200
committerErick Ochoa <erick.ochoa@theobroma-systems.com>2020-06-05 12:36:32 +0200
commitfc4bf48f24b4d75ab1b09a1a283235a35622a600 (patch)
treea288dca35b66a959cdc79acf95c2c053b30a2bbb
parent03a00f8a6666082fb1b5b6412613e912edd888fa (diff)
equality
-rw-r--r--gcc/Makefile.in2
-rw-r--r--gcc/ipa-prototype.c8
-rw-r--r--gcc/type-canonical-equality.c53
-rw-r--r--gcc/type-canonical-equality.hpp10
-rw-r--r--gcc/type-incomplete-equality.c55
-rw-r--r--gcc/type-incomplete-equality.hpp10
-rw-r--r--gcc/type-stringifier.hpp4
-rw-r--r--gcc/type-structural-main-variant.hpp3
-rw-r--r--gcc/types-inlines.h6
9 files changed, 145 insertions, 6 deletions
diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index 20492cc1be2..aae84bf3b2b 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -1419,6 +1419,8 @@ OBJS = \
type-escaper.o \
type-structural-equality.o \
type-structural-main-variant.o \
+ type-canonical-equality.o \
+ type-incomplete-equality.o \
expr-escaper.o \
gimple-escaper.o \
type-stringifier.o \
diff --git a/gcc/ipa-prototype.c b/gcc/ipa-prototype.c
index 9c35a483213..846c484b4c2 100644
--- a/gcc/ipa-prototype.c
+++ b/gcc/ipa-prototype.c
@@ -42,6 +42,8 @@
#include "gimple-collector.hpp"
#include "gimple-escaper.hpp"
#include "type-structural-equality.hpp"
+#include "type-structural-main-variant.hpp"
+#include "type-incomplete-equality.hpp"
//#define OPTIMIZED
#define SANITY_CHECKS
@@ -181,6 +183,8 @@ static void
fix_escaping_types_in_set(ptrset_t &types)
{
bool fixed_point_reached = false;
+ TypeIncompleteEquality structuralEquality;
+ TypeStringifier stringifier;
do {
std::vector<const_tree> fixes;
fixed_point_reached = true;
@@ -197,7 +201,7 @@ fix_escaping_types_in_set(ptrset_t &types)
//const bool interesting_case = eq_type_compare(type_esc, type_non);
//TODO: We are going to need a different type comparison because this one
//fails to take into account the recursion...
- const bool interesting_case = type_esc == type_non;
+ const bool interesting_case = structuralEquality.equal(type_esc, type_non);
if (!interesting_case) continue;
TypeStringifier stringifier;
@@ -277,7 +281,7 @@ iphw_execute()
// Intermediate results
// Do not read escape analysis results from here
//calculate_escaping_types(types, eacalc);
- print_sequal_types(types);
+ //print_sequal_types(types);
place_escaping_types_in_set(types, gimpleEscaper.exprEscaper.typeEscaper.calc);
fix_escaping_types_in_set(types);
// -fipa-protytpe -fdump-ipa-prototype
diff --git a/gcc/type-canonical-equality.c b/gcc/type-canonical-equality.c
new file mode 100644
index 00000000000..f6e88f624c2
--- /dev/null
+++ b/gcc/type-canonical-equality.c
@@ -0,0 +1,53 @@
+#include "config.h"
+#include "system.h"
+#include "coretypes.h"
+#include "backend.h"
+#include "tree.h"
+#include "gimple-expr.h"
+#include "predict.h"
+#include "alloc-pool.h"
+#include "tree-pass.h"
+#include "cgraph.h"
+#include "diagnostic.h"
+#include "fold-const.h"
+#include "gimple-fold.h"
+#include "symbol-summary.h"
+#include "tree-vrp.h"
+#include "ipa-prop.h"
+#include "tree-pretty-print.h"
+#include "tree-inline.h"
+#include "ipa-fnsummary.h"
+#include "ipa-utils.h"
+#include "tree-ssa-ccp.h"
+#include "stringpool.h"
+#include "attribs.h"
+#include "tree-ssa-alias.h"
+#include "tree-ssanames.h"
+#include "gimple.h"
+#include "cfg.h" // needed for gimple-iterator.h
+#include "gimple-iterator.h"
+#include "gimple-ssa.h"
+#include <stdbool.h>
+
+
+#include "types-inlines.h"
+#include "type-structural-equality.hpp"
+#include "type-structural-main-variant.hpp"
+#include "type-canonical-equality.hpp"
+
+bool
+TypeCanonicalEquality::_equal(const_tree l, const_tree r)
+{
+ bool valid_inputs = l && r;
+ if (!valid_inputs) return l == r;
+
+ const_tree canonical_l = TYPE_CANONICAL(l);
+ const_tree canonical_r = TYPE_CANONICAL(r);
+ const bool can_compare_canonical = canonical_l && canonical_r;
+ if (!can_compare_canonical) return TypeStructuralEquality::_equal(l, r);
+
+ const bool different = canonical_l == canonical_r;
+ if (different) return false;
+
+ return TypeStructuralEqualityMainVariant::_equal(l, r);
+}
diff --git a/gcc/type-canonical-equality.hpp b/gcc/type-canonical-equality.hpp
new file mode 100644
index 00000000000..98a159b4dd0
--- /dev/null
+++ b/gcc/type-canonical-equality.hpp
@@ -0,0 +1,10 @@
+#pragma once
+
+#include "type-structural-main-variant.hpp"
+
+class TypeCanonicalEquality : public TypeStructuralEqualityMainVariant {
+public:
+ TypeCanonicalEquality() {};
+protected:
+ virtual bool _equal(const_tree l, const_tree r);
+};
diff --git a/gcc/type-incomplete-equality.c b/gcc/type-incomplete-equality.c
new file mode 100644
index 00000000000..ad49b5ee5a5
--- /dev/null
+++ b/gcc/type-incomplete-equality.c
@@ -0,0 +1,55 @@
+#include "config.h"
+#include "system.h"
+#include "coretypes.h"
+#include "backend.h"
+#include "tree.h"
+#include "gimple-expr.h"
+#include "predict.h"
+#include "alloc-pool.h"
+#include "tree-pass.h"
+#include "cgraph.h"
+#include "diagnostic.h"
+#include "fold-const.h"
+#include "gimple-fold.h"
+#include "symbol-summary.h"
+#include "tree-vrp.h"
+#include "ipa-prop.h"
+#include "tree-pretty-print.h"
+#include "tree-inline.h"
+#include "ipa-fnsummary.h"
+#include "ipa-utils.h"
+#include "tree-ssa-ccp.h"
+#include "stringpool.h"
+#include "attribs.h"
+#include "tree-ssa-alias.h"
+#include "tree-ssanames.h"
+#include "gimple.h"
+#include "cfg.h" // needed for gimple-iterator.h
+#include "gimple-iterator.h"
+#include "gimple-ssa.h"
+#include <stdbool.h>
+
+
+#include "types-inlines.h"
+#include "type-structural-equality.hpp"
+#include "type-structural-main-variant.hpp"
+#include "type-canonical-equality.hpp"
+#include "type-incomplete-equality.hpp"
+#include "type-stringifier.hpp"
+
+bool
+TypeIncompleteEquality::_equal(const_tree l, const_tree r)
+{
+ bool valid_inputs = l && r;
+ if (!valid_inputs) return l == r;
+
+ // if any of these are incomplete, then we can only compare using identifiers...
+ const bool complete_l = is_complete(l);
+ const bool complete_r = is_complete(r);
+ const bool can_compare_completely = complete_l && complete_r;
+ if (can_compare_completely) return TypeCanonicalEquality::_equal(l, r);
+
+ const std::string n_l = TypeStringifier::get_type_identifier(l);
+ const std::string n_r = TypeStringifier::get_type_identifier(r);
+ return n_l.compare(n_r) == 0;
+}
diff --git a/gcc/type-incomplete-equality.hpp b/gcc/type-incomplete-equality.hpp
new file mode 100644
index 00000000000..4188f49713c
--- /dev/null
+++ b/gcc/type-incomplete-equality.hpp
@@ -0,0 +1,10 @@
+#pragma once
+
+#include "type-canonical-equality.hpp"
+
+class TypeIncompleteEquality : public TypeCanonicalEquality {
+public:
+ TypeIncompleteEquality () {};
+protected:
+ virtual bool _equal(const_tree l, const_tree r);
+};
diff --git a/gcc/type-stringifier.hpp b/gcc/type-stringifier.hpp
index 25e43d34ab1..b2e1261fc62 100644
--- a/gcc/type-stringifier.hpp
+++ b/gcc/type-stringifier.hpp
@@ -8,8 +8,6 @@ class TypeStringifier : public TypeWalker
private:
std::string _stringification;
- static std::string get_type_identifier(const_tree t);
- static std::string get_field_identifier(const_tree t);
void _stringify_simple(const_tree t);
void _stringify_aggregate_pre(const_tree t);
@@ -42,6 +40,8 @@ private:
virtual void _walk_FUNCTION_TYPE_pre(const_tree t);
virtual void _walk_FUNCTION_TYPE_post(const_tree t);
public:
+ static std::string get_type_identifier(const_tree t);
+ static std::string get_field_identifier(const_tree t);
std::string stringify(const_tree t);
TypeStringifier() {};
};
diff --git a/gcc/type-structural-main-variant.hpp b/gcc/type-structural-main-variant.hpp
index dda6eadcd59..2fa00aad350 100644
--- a/gcc/type-structural-main-variant.hpp
+++ b/gcc/type-structural-main-variant.hpp
@@ -5,7 +5,6 @@
class TypeStructuralEqualityMainVariant : public TypeStructuralEquality {
public:
TypeStructuralEqualityMainVariant() {};
-private:
-
+protected:
virtual bool _equal(const_tree l, const_tree r);
};
diff --git a/gcc/types-inlines.h b/gcc/types-inlines.h
index 40ff45c491b..ef2629afeec 100644
--- a/gcc/types-inlines.h
+++ b/gcc/types-inlines.h
@@ -40,6 +40,12 @@ is_complete(const_tree a)
return _is_complete;
}
+inline bool
+is_incomplete(const_tree a)
+{
+ return !is_complete(a);
+}
+
inline void
assert_is_type(const_tree a, const enum tree_code expected_code)
{