summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErick Ochoa <erick.ochoa@theobroma-systems.com>2020-03-19 14:58:33 +0100
committerErick Ochoa <erick.ochoa@theobroma-systems.com>2020-04-28 23:35:52 +0200
commit4656d6c601d375b07050e23094e4b01f9a44522a (patch)
tree011f17e668130e5c8f768be0c2696b5e6e754278
parenta9f25a144c5f0d9d7bdd4db562cbca589637dd52 (diff)
wip
-rw-r--r--gcc/ipa-type-escape-analysis.c36
-rw-r--r--gcc/testsuite/gcc.dg/ipa/ipa-ea-13-calling-printf-0.c15
2 files changed, 33 insertions, 18 deletions
diff --git a/gcc/ipa-type-escape-analysis.c b/gcc/ipa-type-escape-analysis.c
index 20789b60d70..2438dcef02d 100644
--- a/gcc/ipa-type-escape-analysis.c
+++ b/gcc/ipa-type-escape-analysis.c
@@ -78,7 +78,7 @@ update_escape_info_pointer (const_tree pointer_type, type_map &escape_map, bool
gcc_assert(is_pointer_type);
escaping_info *info = escape_map.get(pointer_type);
- if (!info) return;
+ if (!info) { log("no info\n"); return;}
info->is_escaping |= is_escaping;
info->reason = union_op(info->reason, reason);
@@ -96,7 +96,7 @@ update_escape_info_array (const_tree array_type, type_map &escape_map, bool is_e
gcc_assert(is_array_type);
escaping_info *info = escape_map.get(array_type);
- if (!info) return;
+ if (!info) { log("no info\n"); return;}
info->is_escaping |= is_escaping;
info->reason = union_op(info->reason, reason);
@@ -134,7 +134,7 @@ void
update_escape_info (const_tree type, type_map &escape_map, bool is_escaping, escaping_reason reason)
{
// INFO: This is an optimization.
- if (!is_escaping) return;
+ if (!is_escaping) { log("is not escaping\n"); return; }
gcc_assert(type);
enum tree_code tree_code_type = TREE_CODE(type);
@@ -465,11 +465,13 @@ static bool
is_function_escaping(const cgraph_node *cnode)
{
gcc_assert(cnode);
- return cnode->externally_visible || !cnode->definition;
+ return cnode->externally_visible; /* TODO: How are FOR_EACH_FUNCTION and FOR_EACH_DEFINED_FUNCTION different */ // || !cnode->definition;
}
+void calculate_escaping_parameters(const cgraph_node *cnode, type_map &escape_map, bool override = false);
+
void
-calculate_escaping_parameters(const cgraph_node *cnode, type_map &escape_map)
+calculate_escaping_parameters(const cgraph_node *cnode, type_map &escape_map, bool override)
{
gcc_assert(cnode);
tree function = cnode->decl;
@@ -478,25 +480,26 @@ calculate_escaping_parameters(const cgraph_node *cnode, type_map &escape_map)
bool is_function_decl = FUNCTION_DECL == code;
gcc_assert (is_function_decl);
- bool is_escaping = is_function_escaping(cnode);
+ bool is_escaping = is_function_escaping(cnode) || override;
function_args_iterator iter;
tree arg;
const_tree function_type = TREE_TYPE(function);
FOREACH_FUNCTION_ARGS (function_type, arg, iter)
{
- const_tree main_type = TYPE_MAIN_VARIANT(arg);
- log("parameter type %s is escaping %s\n", get_type_name(main_type), is_escaping ? "true" : "false");
+ //const_tree main_type = TYPE_MAIN_VARIANT(arg);
+ log("parameter type %s is escaping %s\n", get_type_name(arg), is_escaping ? "true" : "false");
escaping_reason reason = new_escaping_reason();
reason.parameter_is_visible = is_escaping;
- update_escape_info(main_type, escape_map, is_escaping, reason);
+ update_escape_info(arg, escape_map, is_escaping, reason);
}
}
+void is_return_type_escaping(const cgraph_node *cnode, type_map &escape_map, bool override = false);
void
-is_return_type_escaping(const cgraph_node *cnode, type_map &escape_map)
+is_return_type_escaping(const cgraph_node *cnode, type_map &escape_map, bool override)
{
gcc_assert(cnode);
- bool is_escaping = is_function_escaping(cnode);
+ bool is_escaping = is_function_escaping(cnode) || override;
tree function = cnode->decl;
gcc_assert(function);
enum tree_code code = TREE_CODE(function);
@@ -532,13 +535,10 @@ _calculate_escaping_types_from_function_signatures (
gcc_assert(escape_map);
gcc_assert(cnode);
- cgraph_node *node = cnode->ultimate_alias_target ();
- push_cfun(DECL_STRUCT_FUNCTION(node->decl));
- bool is_escaping = is_function_escaping(node);
- log("undefined function %s is escaping %s\n", node->name(), is_escaping ? "true" : "false");
- calculate_escaping_parameters(node, *escape_map);
- is_return_type_escaping(node, *escape_map);
- pop_cfun();
+ bool is_escaping = true;
+ log("undefined 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;
}
diff --git a/gcc/testsuite/gcc.dg/ipa/ipa-ea-13-calling-printf-0.c b/gcc/testsuite/gcc.dg/ipa/ipa-ea-13-calling-printf-0.c
new file mode 100644
index 00000000000..aa3e97b5444
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/ipa/ipa-ea-13-calling-printf-0.c
@@ -0,0 +1,15 @@
+/* { dg-do link } */
+/* { dg-options "-flto -fipa-type-escape-analysis -fdump-ipa-type-escape-analysis" } */
+
+#include <stddef.h>
+#include <stdio.h>
+
+int main(int argc, char** argv)
+{
+ char *filename = "helloworld.txt";
+ FILE* f = fopen(filename);
+ fclose(f);
+}
+
+
+/* { dg-final { scan-wpa-ipa-dump "type FILE is escaping true" "type-escape-analysis" } } */