summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErick Ochoa <erick.ochoa@theobroma-systems.com>2020-06-03 14:08:05 +0200
committerErick Ochoa <erick.ochoa@theobroma-systems.com>2020-06-03 16:06:04 +0200
commit5e26465d33febeac3d019b9213787676a9a31ee2 (patch)
tree0640e4cf258d5253cf41d3263a0276b09fa3b583
parent7492af8c8acefcc10175f8518dc83735c16380d0 (diff)
replace marking escaping types with walker
-rw-r--r--gcc/ipa-hello-world.c181
1 files changed, 11 insertions, 170 deletions
diff --git a/gcc/ipa-hello-world.c b/gcc/ipa-hello-world.c
index 52ad819bc5b..de409a16229 100644
--- a/gcc/ipa-hello-world.c
+++ b/gcc/ipa-hello-world.c
@@ -97,176 +97,9 @@ assert_type_is_in_ptrset(const_tree type, ptrset_t &types)
#endif
}
-static void
-update_typemap(const_tree type, ptrset_t &types, Reason reason, typemap &calc)
-{
- gcc_assert(type);
- assert_type_is_in_universe(type, types);
- const bool already_in_typemap = calc.find(type) != calc.end();
- already_in_typemap ? calc[type] |= reason : calc[type] = reason;
- //TypeStringifier stringifier;
- //std::string name = stringifier.stringify(type);
- //log("updating %s\n", name.c_str());
- //reason.print();
-}
static void update_escape_info( const_tree type, ptrset_t &types, Reason reason, typemap &calc);
-static void
-update_escape_info_wrapper(const_tree type, ptrset_t &types, Reason reason, typemap &calc)
-{
- gcc_assert(type);
- update_typemap(type, types, reason, calc);
- const_tree inner_type = TREE_TYPE(type);
- update_escape_info(inner_type, types, reason, calc);
-}
-
-static void
-update_escape_info_array(const_tree type, ptrset_t &types, Reason reason, typemap &calc)
-{
- assert_is_type(type, ARRAY_TYPE);
- update_escape_info_wrapper(type, types, reason, calc);
-}
-
-static void
-update_escape_info_pointer(const_tree type, ptrset_t &types, Reason reason, typemap &calc)
-{
- assert_is_type(type, POINTER_TYPE);
- update_escape_info_wrapper(type, types, reason, calc);
-}
-
-static void
-update_escape_info_reference(const_tree type, ptrset_t &types, Reason reason, typemap &calc)
-{
- assert_is_type(type, REFERENCE_TYPE);
- update_escape_info_wrapper(type, types, reason, calc);
-}
-
-static void
-update_escape_info_record(const_tree type, ptrset_t &types, Reason reason, typemap &calc)
-{
- assert_is_type(type, RECORD_TYPE);
- update_typemap(type, types, reason, calc);
- for (tree field = TYPE_FIELDS(type); field; field = DECL_CHAIN(field))
- {
- const_tree field_type = TREE_TYPE(field);
- gcc_assert(field_type);
- update_escape_info(field_type, types, reason, calc);
- }
-}
-
-static void
-update_escape_info_union(const_tree type, ptrset_t &types, Reason reason, typemap &calc)
-{
- assert_is_type(type, UNION_TYPE);
- Reason inner_reason {};
- inner_reason.type_is_in_union = true;
- inner_reason.is_escaping = true;
- inner_reason |= reason;
-
- update_typemap(type, types, reason, calc);
- for (tree field = TYPE_FIELDS(type); field; field = DECL_CHAIN(field))
- {
- const_tree field_type = TREE_TYPE(field);
- gcc_assert(field_type);
- // We cannot change type that are on the surface level
- // of unions. (This is a type of casting).
- // But we might be able to change the types which
- // are pointed by these types.
- update_typemap(field_type, types, inner_reason, calc);
- update_escape_info(field_type, types, reason, calc);
- }
-}
-
-static void
-update_escape_info_qual_union(const_tree type, ptrset_t &types, Reason reason, typemap &calc)
-{
- assert_is_type(type, QUAL_UNION_TYPE);
- update_escape_info_union(type, types, reason, calc);
-}
-
-static void
-update_escape_info_function(const_tree type, ptrset_t &types, Reason reason, typemap &calc)
-{
- assert_is_type(type, FUNCTION_TYPE);
- update_typemap(type, types, reason, calc);
- //Note, this is for function pointers, but we don't need to update the
- //arguments because as long as the definition is not escaping, I think we are good...
- // So, instead, let's do a new reason that's empty
- Reason reason2 {};
- const_tree ret_type = TREE_TYPE(type);
- gcc_assert(ret_type);
- update_escape_info(ret_type, types, reason2, calc);
-
- tree arg_node = TYPE_ARG_TYPES(type);
- while (NULL_TREE != arg_node)
- {
- tree arg_node_type = TREE_VALUE(arg_node);
- gcc_assert(arg_node_type);
- update_escape_info(arg_node_type, types, reason2, calc);
- arg_node = TREE_CHAIN(arg_node);
- }
-}
-
-static void
-update_escape_info( const_tree type, ptrset_t &types, Reason reason, typemap &calc)
-{
- if (!type) return;
-
- //assert_type_is_in_universe(type, types);
-
-#ifdef OPTIMIZED
- // if (!reason.is_escaping) return;
- // Above not necessarily true, since we might point to a union
- // and unions are illegal?
- // instead use the following
- const bool in_set = calc.find(type) != calc.end(type);
- const bool will_not_escape = in_set && !reason.is_escaping;
- if (will_not_escape) return;
-
- const bool already_escaping = in_set && calc[type].is_escaping;
- if (already_escaping) return;
-#endif
-
-
- bool is_interesting = types.in_points_to_record(type);
- if (!is_interesting) return;
-
- gcc_assert(type);
- const enum tree_code code = TREE_CODE(type);
- switch (code)
- {
- case ARRAY_TYPE:
- update_escape_info_array(type, types, reason, calc);
- break;
- case RECORD_TYPE:
- update_escape_info_record(type, types, reason, calc);
- break;
- case UNION_TYPE:
- update_escape_info_union(type, types, reason, calc);
- break;
- case QUAL_UNION_TYPE:
- update_escape_info_qual_union(type, types, reason, calc);
- break;
- case REFERENCE_TYPE:
- update_escape_info_reference(type, types, reason, calc);
- break;
- case POINTER_TYPE:
- update_escape_info_pointer(type, types, reason, calc);
- break;
- case FUNCTION_TYPE:
- update_escape_info_function(type, types, reason, calc);
- break;
- case METHOD_TYPE:
- default:
- gcc_unreachable();
- break;
- }
-
- update_typemap(type, types, reason, calc);
-}
-
-
static bool
is_variable_escaping(varpool_node *vnode)
{
@@ -504,7 +337,7 @@ update_escape_info_expr(ptrset_t &types, typemap &calc, const_tree expr, Reason
const_tree type = TREE_TYPE(expr);
gcc_assert(type);
if (!types.in_points_to_record(type)) return;
- update_typemap(type, types, reason, calc);
+ update_escape_info(type, types, reason, calc);
const enum tree_code code = TREE_CODE(expr);
switch (code)
@@ -837,7 +670,7 @@ calculate_escaping_locals(ptrset_t &types, typemap &calc, cgraph_node *cnode)
const_tree func_type = TREE_TYPE(decl);
assert_is_type(func_type, FUNCTION_TYPE);
update_escape_info_expr(types, calc, decl, reason);
- if (types.in_points_to_record(func_type)) update_typemap(func_type, types, reason, calc);
+ if (types.in_points_to_record(func_type)) update_escape_info(func_type, types, reason, calc);
int i = 0;
tree var_decl = NULL;
FOR_EACH_LOCAL_DECL(func, i, var_decl)
@@ -1038,6 +871,14 @@ print_escaping_types_in_set(ptrset_t &types)
ptrset_t *TypeEscaper::types = NULL;
typemap TypeEscaper::calc;
+static TypeEscaper typeEscaper;
+
+static void
+update_escape_info( const_tree type, ptrset_t &types, Reason reason, typemap &calc)
+{
+ typeEscaper.update(type, reason);
+}
+
static unsigned int
iphw_execute()
@@ -1051,7 +892,7 @@ iphw_execute()
// Intermediate results
// Do not read escape analysis results from here
calculate_escaping_types(types, eacalc);
- place_escaping_types_in_set(types, eacalc);
+ place_escaping_types_in_set(types, typeEscaper.calc);
fix_escaping_types_in_set(types);
print_escaping_types_in_set(types);
sanity_check_escape_xor_not(types);