summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErick Ochoa <erick.ochoa@theobroma-systems.com>2020-06-22 15:58:14 +0200
committerErick Ochoa <erick.ochoa@theobroma-systems.com>2020-06-26 12:42:32 +0200
commiteedbb7e4235b4ea143402760a508d6f14b17cc8e (patch)
tree7f38182c5a3875cbc68b13418313d4251ca83a6e
parente238de8b1859419c6ac05aec1afa05fd1a5ab731 (diff)
main variant
-rw-r--r--\8
-rw-r--r--gcc/expr-rewriter.c27
-rw-r--r--gcc/ipa-type-escape-analysis.c3
-rw-r--r--gcc/type-reconstructor.c57
-rw-r--r--gcc/type-walker.c1
5 files changed, 82 insertions, 14 deletions
diff --git a/\ b/\
new file mode 100644
index 00000000000..fa7443fd1c4
--- /dev/null
+++ b/\
@@ -0,0 +1,8 @@
+#pragma once
+
+#include "gimple-walker.hpp"
+#include "expr-escaper.hpp"
+
+class GimpleEscaper : public GimpleWalker
+{
+}
diff --git a/gcc/expr-rewriter.c b/gcc/expr-rewriter.c
index eac5b05c986..fc45233de92 100644
--- a/gcc/expr-rewriter.c
+++ b/gcc/expr-rewriter.c
@@ -63,6 +63,8 @@ ExprTypeRewriter::_walk_FUNCTION_DECL_post(const_tree t)
std::string r_t_2 = stringifier.stringify(r_t);
log("rewriting %s with %s return type\n", name.c_str(), r_t_2.c_str());
//relayout_decl((tree)t);
+
+
}
void
@@ -360,11 +362,16 @@ ExprTypeRewriter::_walk_post(const_tree e)
const enum tree_code code = TREE_CODE(e);
tree r_t = _map[t];
- TypeStringifier stringifer;
- const std::string r_t_name = stringifer.stringify(r_t);
- const std::string t_name = stringifer.stringify(t);
+ TypeStringifier stringifier;
+ const std::string r_t_name = stringifier.stringify(r_t);
+ const std::string t_name = stringifier.stringify(t);
log("replacing %s with %s in %s\n", t_name.c_str(), r_t_name.c_str(), get_tree_code_name(code));
TREE_TYPE((tree)e) = r_t;
+ tree type_main_variant = TYPE_MAIN_VARIANT(TREE_TYPE(e));
+ std::string mv_name = stringifier.stringify(type_main_variant);
+ const bool do_we_have_mv_in_map = _map.find(type_main_variant) != _map.end();
+ TYPE_MAIN_VARIANT(TREE_TYPE(e)) = do_we_have_mv_in_map ? _map[type_main_variant] : TYPE_MAIN_VARIANT(TREE_TYPE(e));
+ log("What is my type main variant? %s\n", mv_name.c_str());
}
void
@@ -398,12 +405,26 @@ ExprTypeRewriter::_walk_COMPONENT_REF_post(const_tree e)
unsigned nf_offset = 8 * nf_byte_offset + nf_bit_offset;
TREE_OPERAND(e, 1) = n_f;
+ tree record = DECL_CONTEXT(n_f);
+
// It is possible here that we are in a write
// and we need to delete this gimple statment.
// So, how do we know if it is a write?
// Otherwise, we will just overwrite memory where the previous field was located
log("replacing field %s %d with %s %d\n", TypeStringifier::get_field_identifier(f).c_str(), f_offset, TypeStringifier::get_field_identifier(n_f).c_str(), nf_offset);
+ gcc_assert(record);
+ assert_is_type(record, RECORD_TYPE);
+ const bool in_map3 = _map.find(record) != _map.end();
+ std::string context_name = stringifier.stringify(record);
+ log("what is the declaration context of this field? %s\n", context_name.c_str());
+ // For some reason context is the old type... so let's see if we can change it..
+ DECL_CONTEXT(n_f) = in_map3 ? _map[record] : DECL_CONTEXT(n_f);
+ context_name = stringifier.stringify(DECL_CONTEXT(n_f));
+ if (in_map3) relayout_decl(n_f);
+ log("did my context changed? %s\n", context_name.c_str());
+
+
if (!is_deleted) return;
diff --git a/gcc/ipa-type-escape-analysis.c b/gcc/ipa-type-escape-analysis.c
index 681aaa6ec11..11cc7132ade 100644
--- a/gcc/ipa-type-escape-analysis.c
+++ b/gcc/ipa-type-escape-analysis.c
@@ -295,7 +295,10 @@ collect_types()
const_tree to = i->second;
std::string name_from = stringifier.stringify(from);
std::string name_to = to ? stringifier.stringify(to) : std::string("NULL");
+ tree mv = TYPE_MAIN_VARIANT(to);
+ std::string name_mv = to ? stringifier.stringify(mv) : std::string("NULL");
log("%s -> %s\n", name_from.c_str(), name_to.c_str());
+ log("TYPE_MAIN_VARIANT(%s) = %s\n", name_to.c_str(), name_mv.c_str());
}
GimpleTypeRewriter rewriter(map, field_map);
diff --git a/gcc/type-reconstructor.c b/gcc/type-reconstructor.c
index 769733d33b5..bcde1890638 100644
--- a/gcc/type-reconstructor.c
+++ b/gcc/type-reconstructor.c
@@ -40,6 +40,7 @@ TypeReconstructor::set_is_not_modified_yet(const_tree t)
gcc_assert(t);
const bool is_in_reorg_map = _reorg_map.find(t) != _reorg_map.end();
modified_map[t] = false;
+ if (is_in_reorg_map) mark_all_pointing_here_as_modified();
const_tree tt = TREE_TYPE(t);
if (!tt) return;
@@ -82,7 +83,7 @@ bool
TypeReconstructor::is_memoized(const_tree t)
{
const bool already_changed = _reorg_map.find(t) != _reorg_map.end();
- //mark_all_pointing_here_as_modified();
+ mark_all_pointing_here_as_modified();
return already_changed;
}
@@ -122,6 +123,14 @@ TypeReconstructor::_walk_ARRAY_TYPE_pre(const_tree t)
set_is_not_modified_yet(t);
tree copy = build_variant_type_copy((tree) t);
+ tree domain = TYPE_DOMAIN(t);
+ if (domain) {
+ tree copy_domain = copy_node(domain);
+ tree min = TYPE_MIN_VALUE(domain);
+ tree max = TYPE_MAX_VALUE(domain);
+ TYPE_MIN_VALUE(copy_domain) = copy_node(min);
+ TYPE_MAX_VALUE(copy_domain) = copy_node(max);
+ }
in_progress.push(copy);
}
@@ -137,11 +146,23 @@ TypeReconstructor::_walk_ARRAY_TYPE_post(const_tree t)
bool is_modified = get_is_modified(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);
TYPE_NAME(copy) = is_modified ? get_new_identifier(copy) : TYPE_NAME(copy);
// This is useful so that we go again through type layout
TYPE_SIZE(copy) = is_modified ? NULL : TYPE_SIZE(copy);
+ tree domain = TYPE_DOMAIN(t);
+ if (domain) {
+ tree copy_domain = copy_node(domain);
+ tree min = TYPE_MIN_VALUE(domain);
+ tree max = TYPE_MAX_VALUE(domain);
+ TYPE_MIN_VALUE(copy_domain) = copy_node(min);
+ TYPE_MAX_VALUE(copy_domain) = copy_node(max);
+ }
+ TypeStringifier stringifier;
+ //std::string name = stringifier.stringify(copy);
+ log("are we going to crash is modified %s %s\n", is_modified ? "t" : "f", TypeStringifier::get_type_identifier(t));
if (is_modified) layout_type(copy);
_reorg_map[t] = is_modified ? copy : (tree)t;
@@ -253,21 +274,35 @@ TypeReconstructor::_walk_RECORD_TYPE_post(const_tree t)
tree main_reorg = _reorg_map[main];
TypeStringifier stringifier;
std::string main_s = stringifier.stringify(main_reorg);
+ log("is modified %s main variant reorged build variant type %s\n", is_modified ? "T" : "F", main_s.c_str());
tree copy_variant = build_variant_type_copy(main_reorg);
TYPE_NAME(copy_variant) = get_new_identifier(copy);
- //TYPE_SIZE(copy_variant) = NULL;
- //layout_type(copy_variant);
+ TYPE_SIZE(copy_variant) = NULL;
+ TYPE_MAIN_VARIANT(copy_variant) = main_reorg;
+ layout_type(copy_variant);
_reorg_map[t] = copy_variant;
- return;
- }
+ } else {
// Ok, so now that we have fixed the TYPE_FIELDS of the copy...
// We need to call layout_type
- copy = is_modified ? build_distinct_type_copy(copy) : copy;
- TYPE_NAME(copy) = is_modified ? get_new_identifier(copy) : TYPE_NAME(copy);
- // This is useful so that we go again through type layout
- TYPE_SIZE(copy) = is_modified ? NULL : TYPE_SIZE(copy);
- if (is_modified) layout_type(copy);
- _reorg_map[t] = is_modified ? copy : (tree)t;
+ copy = is_modified ? build_distinct_type_copy(copy) : copy;
+ TYPE_NAME(copy) = is_modified ? get_new_identifier(copy) : TYPE_NAME(copy);
+ // This is useful so that we go again through type layout
+ TYPE_SIZE(copy) = is_modified ? NULL : TYPE_SIZE(copy);
+ TYPE_MAIN_VARIANT(copy) = is_modified ? copy : TYPE_MAIN_VARIANT(copy);
+ tree main_variant = TYPE_MAIN_VARIANT(copy);
+ TypeStringifier stringifier;
+ std::string main_s = stringifier.stringify(main_variant);
+ log("main variant reorged build distinct %s\n", main_s.c_str());
+ if (is_modified) layout_type(copy);
+ _reorg_map[t] = is_modified ? copy : (tree)t;
+ }
+
+ tree record = _reorg_map[t];
+ for (tree field = TYPE_FIELDS(record); field; field = DECL_CHAIN(field))
+ {
+ relayout_decl(field);
+ }
+
}
void
diff --git a/gcc/type-walker.c b/gcc/type-walker.c
index b79daef043d..d7554c9e6af 100644
--- a/gcc/type-walker.c
+++ b/gcc/type-walker.c
@@ -42,6 +42,7 @@ TypeWalker::walk(const_tree t)
void
TypeWalker::_walk(const_tree type)
{
+ if (!type) return;
gcc_assert(type);
// This is an optimization