summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErick Ochoa <erick.ochoa@theobroma-systems.com>2020-06-04 14:05:41 +0200
committerErick Ochoa <erick.ochoa@theobroma-systems.com>2020-06-04 14:05:41 +0200
commit247fbdc30ea94d20ec179e801156490beb68f65a (patch)
tree8806e021ac18c166267e3058ba6053f8f79aad4b
parent9ac3804b57a361a6e4bf91686afa768ccf725953 (diff)
gimple collector
-rw-r--r--gcc/expr-collector.c2
-rw-r--r--gcc/expr-collector.hpp6
-rw-r--r--gcc/gimple-collector.hpp12
-rw-r--r--gcc/ipa-prototype.c1
-rw-r--r--gcc/ipa-type-collector.c6
-rw-r--r--gcc/type-collector.c37
-rw-r--r--gcc/type-collector.hpp6
7 files changed, 47 insertions, 23 deletions
diff --git a/gcc/expr-collector.c b/gcc/expr-collector.c
index 2e20ba5100a..1271c63cfdf 100644
--- a/gcc/expr-collector.c
+++ b/gcc/expr-collector.c
@@ -34,5 +34,5 @@ ExprCollector::_walk_pre(const_tree e)
{
const_tree t = TREE_TYPE(e);
gcc_assert(t);
- typeCollector->collect(t);
+ typeCollector.collect(t);
}
diff --git a/gcc/expr-collector.hpp b/gcc/expr-collector.hpp
index aba79d64307..7b3ca3ccd6a 100644
--- a/gcc/expr-collector.hpp
+++ b/gcc/expr-collector.hpp
@@ -4,11 +4,11 @@
#include "type-collector.hpp"
class ExprCollector : public ExprWalker {
+private:
+ TypeCollector typeCollector;
public:
ExprCollector() {};
- // TODO: You can get rid of this pointer
- // if you make ExprCollector a singleton.
- static TypeCollector* typeCollector;
+ ptrset_t get_pointer_set() { return typeCollector.get_pointer_set(); }
private:
virtual void _walk_pre(const_tree e) final;
};
diff --git a/gcc/gimple-collector.hpp b/gcc/gimple-collector.hpp
index a27d37258fa..30a5f61846f 100644
--- a/gcc/gimple-collector.hpp
+++ b/gcc/gimple-collector.hpp
@@ -5,20 +5,22 @@
class GimpleTypeCollector : public GimpleWalker
{
+private:
+ ExprCollector exprCollector;
public:
GimpleTypeCollector() {};
void collect();
+ ptrset_t get_pointer_set() { return exprCollector.get_pointer_set(); }
private:
- ExprCollector exprCollector;
void _collect_globals();
void _collect_global(varpool_node *);
void collect(cgraph_node *cnode);
void _collect_decl(cgraph_node *);
void _collect_locals(cgraph_node *);
void _collect_ssa_names(cgraph_node *);
- virtual void _walk_pre(gassign *s);
- virtual void _walk_pre(greturn *s);
- virtual void _walk_pre(gcond *s);
- virtual void _walk_pre(gcall *s);
+ virtual void _walk_pre(gassign *s) final;
+ virtual void _walk_pre(greturn *s) final;
+ virtual void _walk_pre(gcond *s) final;
+ virtual void _walk_pre(gcall *s) final;
};
diff --git a/gcc/ipa-prototype.c b/gcc/ipa-prototype.c
index ea13abb3fe1..be14113007d 100644
--- a/gcc/ipa-prototype.c
+++ b/gcc/ipa-prototype.c
@@ -715,7 +715,6 @@ static unsigned int
iphw_execute()
{
ptrset_t types;
- TypeCollector::ptrset = &types;
TypeEscaper::types = &types;
ExprEscaper::typeEscaper = &_typeEscaper;
collect_types(types);
diff --git a/gcc/ipa-type-collector.c b/gcc/ipa-type-collector.c
index 29b77e138a5..4bf2ca4f9af 100644
--- a/gcc/ipa-type-collector.c
+++ b/gcc/ipa-type-collector.c
@@ -81,11 +81,7 @@ static type_comparison_func_t comparisons[type_comparisons] = {
static TypeCollector _typeCollector;
-ptrset_t *TypeCollector::ptrset = NULL;
static ExprCollector exprCollector;
-TypeCollector * ExprCollector::typeCollector = &_typeCollector;
-
-
static void
print_types_in_set(ptrset_t &types)
@@ -129,6 +125,7 @@ collect_types(ptrset_t &types)
{
GimpleTypeCollector collector;
collector.collect();
+ types = collector.get_pointer_set();
sanity_check_ptr_xor_complement(types);
}
@@ -140,7 +137,6 @@ iphw_execute()
//test_naming_types::run_tests();
ptrset_t types;
//ExprCollector::typeCollector = &_typeCollector;
- TypeCollector::ptrset = &types;
collect_types(types);
return 0;
}
diff --git a/gcc/type-collector.c b/gcc/type-collector.c
index 3def624c4ac..d17dde42933 100644
--- a/gcc/type-collector.c
+++ b/gcc/type-collector.c
@@ -35,10 +35,10 @@
void
TypeCollector::collect(const_tree t)
{
- const bool in_set = ptrset->in_universe(t);
+ const bool in_set = ptrset.in_universe(t);
// memoization...
if (in_set) return;
- gcc_assert(ptrset && t);
+ gcc_assert(t);
if (!ptr.empty())
{
@@ -50,13 +50,40 @@ TypeCollector::collect(const_tree t)
walk(t);
}
+void
+TypeCollector::_sanity_check()
+{
+ for (auto i = ptrset.points_to_record.cbegin(), e = ptrset.points_to_record.cend(); i != e; ++i)
+ {
+ for (auto j = ptrset.complement.cbegin(), f = ptrset.complement.cend(); j != f; ++j)
+ {
+ const_tree type_ptr = *i;
+ gcc_assert(type_ptr);
+ const_tree type_com = *j;
+ gcc_assert(type_com);
+ const bool valid_sets = type_ptr != type_com;
+ if (valid_sets) continue;
+ // Normally, we want a stronger type comparison
+ // that is not just the pointer address
+ // but this is the first sanity check and then we will need to determine
+ // the stronger type comparison.
+ // But first we will need to fix the types...
+ TypeStringifier stringifier;
+ std::string name_ptr = stringifier.stringify(type_ptr);
+ std::string name_com = stringifier.stringify(type_com);
+ log("%p %s == %p %s\n", type_ptr, name_ptr.c_str(), type_com, name_com.c_str());
+ gcc_unreachable();
+ }
+ }
+}
+
bool
TypeCollector::is_memoized(const_tree t)
{
- const bool in_set = ptrset->in_universe(t);
+ const bool in_set = ptrset.in_universe(t);
if (!in_set) return false;
- const bool points_to_record = ptrset->in_points_to_record(t);
+ const bool points_to_record = ptrset.in_points_to_record(t);
for (auto i = ptr.begin(), e = ptr.end(); i != e; ++i)
{
i->second |= points_to_record;
@@ -151,7 +178,7 @@ TypeCollector::_walk_boolean_post(const_tree t)
void
TypeCollector::_collect_simple(const_tree t)
{
- ptrset->insert(t, ptr[t]);
+ ptrset.insert(t, ptr[t]);
ptr.erase(t);
}
diff --git a/gcc/type-collector.hpp b/gcc/type-collector.hpp
index 98b08d99f83..44d7695ccc5 100644
--- a/gcc/type-collector.hpp
+++ b/gcc/type-collector.hpp
@@ -9,11 +9,11 @@ class TypeCollector : public TypeWalker {
public:
void collect(const_tree t);
TypeCollector() {};
-
- static ptrset_t* ptrset;
+ ptrset_t get_pointer_set() { _sanity_check(); return ptrset; }
private:
std::map<const_tree, bool> ptr;
-
+ ptrset_t ptrset;
+ void _sanity_check();
void _collect_simple(const_tree t);
virtual bool is_memoized(const_tree t);