summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErick Ochoa <erick.ochoa@theobroma-systems.com>2020-04-29 16:38:16 +0200
committerErick Ochoa <erick.ochoa@theobroma-systems.com>2020-04-29 16:38:16 +0200
commitef42be8fb31d7edc6e4ae159b9ddb84046c58647 (patch)
tree2afe84800410621df9253e68068e1f9245ea987a
parentdcb323b7255f914574f6361982d58e8398b9b14a (diff)
Fixes bug
-rw-r--r--gcc/ipa-hello-world.c19
-rw-r--r--gcc/ipa-type-escape-analysis.c52
2 files changed, 62 insertions, 9 deletions
diff --git a/gcc/ipa-hello-world.c b/gcc/ipa-hello-world.c
index 2513a344574..20c122f3a16 100644
--- a/gcc/ipa-hello-world.c
+++ b/gcc/ipa-hello-world.c
@@ -112,6 +112,7 @@ void count_access_for_types_in_expr(const_tree expr, const record_set &non_escap
void
count_access_for_type_in_component_ref(const_tree component_ref, const record_set &non_escaping_records, field_access_counter &counter, const enum access_code access)
{
+ log("types in component_ref\n");
gcc_assert(component_ref);
enum tree_code tree_code_component_ref = TREE_CODE(component_ref);
const bool is_component_ref = COMPONENT_REF == tree_code_component_ref;
@@ -120,6 +121,7 @@ count_access_for_type_in_component_ref(const_tree component_ref, const record_se
const_tree _struct = TREE_OPERAND(component_ref, 0);
gcc_assert(_struct);
+ log ("going in recursion\n");
count_access_for_types_in_expr(_struct, non_escaping_records, counter, READ_ACCESS);
const_tree tree_type_struct = TREE_TYPE(_struct);
gcc_assert(tree_type_struct);
@@ -135,7 +137,7 @@ count_access_for_type_in_component_ref(const_tree component_ref, const record_se
gcc_assert(is_record_type);
//FIXME: Future proofing or making things more difficult to read?
- const bool in_set =
+ bool in_set =
#if __cplusplus > 201703L
non_escaping_records.contains(tree_type_struct)
#else
@@ -143,8 +145,18 @@ count_access_for_type_in_component_ref(const_tree component_ref, const record_se
#endif
;
+ in_set |=
+#if __cplusplus > 201703L
+ non_escaping_records.contains(TYPE_MAIN_VARIANT(tree_type_struct))
+#else
+ non_escaping_records.find(TYPE_MAIN_VARIANT(tree_type_struct)) != non_escaping_records.end()
+#endif
+ ;
+
+
log("%s is in non_escaping_records ? %s\n", get_type_name(tree_type_struct), in_set ? "true" : "false");
log("access is %s\n", access == READ_ACCESS ? "read_access" : "write_access");
+ log("%s is escaping %s\n", get_type_name(tree_type_struct), in_set ? "true" : "false");
if (!in_set) return;
const_tree field = TREE_OPERAND(component_ref, 1);
@@ -216,6 +228,7 @@ count_access_for_type_in_array_expr(const_tree expr, const record_set &non_escap
void
count_access_for_types_in_expr(const_tree expr, const record_set &non_escaping_records, field_access_counter &counter, const enum access_code access)
{
+ log("types in expr\n");
gcc_assert(expr);
enum tree_code tree_code_expr = TREE_CODE(expr);
switch (tree_code_expr)
@@ -256,6 +269,7 @@ count_access_for_types_in_rhs(gimple *stmt, const record_set &non_escaping_recor
const bool is_assign = GIMPLE_ASSIGN == gimple_code_stmt;
gcc_assert(is_assign);
+ log("types in rhs\n");
const enum gimple_rhs_class gimple_rhs_class_stmt = gimple_assign_rhs_class(stmt);
switch (gimple_rhs_class_stmt)
{
@@ -435,12 +449,15 @@ count_access_for_types_in_linking_unit(const record_set &non_escaping_records)
bool
_calculate_non_escaping_records(const_tree const &type, escaping_info *info, record_set *non_escaping_records)
{
+
gcc_assert(info);
+ log("NOW: %s is escaping %s\n", get_type_name(type), info->is_escaping ? "true" : "false");
if (info->is_escaping) return true;
gcc_assert(non_escaping_records);
enum tree_code tree_code_type = TREE_CODE(type);
const bool is_record_type = RECORD_TYPE == tree_code_type;
+ log("NOW: %s is record %s\n", get_type_name(type), is_record_type ? "true" : "false");
if (!is_record_type) return true;
non_escaping_records->insert(type);
diff --git a/gcc/ipa-type-escape-analysis.c b/gcc/ipa-type-escape-analysis.c
index a491c82f222..4872aa61ad0 100644
--- a/gcc/ipa-type-escape-analysis.c
+++ b/gcc/ipa-type-escape-analysis.c
@@ -210,8 +210,9 @@ filter_type (type_map &escape_map, const_tree type)
default: break;
}
- if (retval) return retval;
+ log("filter_type %s boring ? %s\n", get_type_name(type), retval ? "true" : "false");
+ if (retval) return retval;
escaping_reason reason = new_escaping_reason();
escaping_info info = { type , false , reason};
escape_map.put(type, info);
@@ -321,9 +322,48 @@ collect_local_declarations (cgraph_node *cnode, type_map &escape_map)
}
}
+static void collect_expr (const_tree expr, type_map &escape_map);
+
+static void
+collect_expr_in_component_ref(const_tree cref, type_map &escape_map)
+{
+ gcc_assert(cref);
+ const enum tree_code code = TREE_CODE(cref);
+ const bool is_cref = COMPONENT_REF == code;
+ gcc_assert(is_cref);
+
+ const_tree _struct = TREE_OPERAND(cref, 0);
+ gcc_assert(_struct);
+
+ const_tree _struct_type = TREE_TYPE(_struct);
+ log("we are in collect_expr_in_component_ref %s\n", get_type_name(_struct_type));
+ escaping_reason reason = new_escaping_reason();
+ escaping_info info = { _struct_type, false , reason};
+ escape_map.put(_struct_type, info);
+
+ collect_expr(_struct, escape_map);
+
+}
+
+static void
+collect_expr (const_tree expr, type_map &escape_map)
+{
+ gcc_assert(expr);
+ enum tree_code tree_code_expr = TREE_CODE(expr);
+ switch (tree_code_expr)
+ {
+ case COMPONENT_REF:
+ collect_expr_in_component_ref(expr, escape_map);
+ break;
+ default:
+ break;
+ }
+}
+
static void
collect_pointer_plus (tree lhs, tree rhs1, tree rhs2, type_map &escape_map)
{
+ log("collect_pointer_plus\n");
const_tree lhs_type = lhs ? TREE_TYPE(lhs) : NULL;
bool is_lhs_boring = lhs_type ? filter_type(escape_map, lhs_type) : true;
const_tree rhs1_type = rhs1 ? TREE_TYPE(rhs1) : NULL;
@@ -339,15 +379,11 @@ collect_pointer_plus (tree lhs, tree rhs1, tree rhs2, type_map &escape_map)
}
if (!is_rhs1_boring)
{
- escaping_reason reason = new_escaping_reason();
- escaping_info info = { rhs1_type, false , reason};
- escape_map.put(rhs1_type, info);
+ collect_expr(rhs1, escape_map);
}
if (!is_rhs2_boring)
{
- escaping_reason reason = new_escaping_reason();
- escaping_info info = {rhs2_type, false, reason};
- escape_map.put(rhs2_type, info);
+ collect_expr(rhs2, escape_map);
}
}
@@ -567,7 +603,7 @@ calculate_escaping_types_from_function_signatures (
gcc_assert(escape_map);
gcc_assert(cnode);
bool is_escaping = true;
- log("undefined function %s is escaping %s\n", cnode->name(), is_escaping ? "true" : "false");
+ log("function %s is escaping %s\n", cnode->name(), is_escaping ? "true" : "false");
calculate_escaping_parameters(cnode, *escape_map, is_escaping);
is_return_type_escaping(cnode, *escape_map, is_escaping);
return true;