summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gcc/ipa-hello-world.c30
-rw-r--r--gcc/testsuite/gcc.dg/ipa/ipa-ea-08-parameter-escapes-0.c28
2 files changed, 55 insertions, 3 deletions
diff --git a/gcc/ipa-hello-world.c b/gcc/ipa-hello-world.c
index 85092f85453..cbe293d2df0 100644
--- a/gcc/ipa-hello-world.c
+++ b/gcc/ipa-hello-world.c
@@ -218,15 +218,41 @@ is_function_escaping(cgraph_node *cnode)
}
void
+calculate_escaping_parameters(cgraph_node *cnode, type_map &escape_map)
+{
+ tree function = cnode->decl;
+ gcc_assert(function);
+ enum tree_code code = TREE_CODE (function);
+ bool is_function_decl = FUNCTION_DECL == code;
+ gcc_assert (is_function_decl);
+
+ bool is_escaping = is_function_escaping(cnode);
+ for (tree parm = DECL_ARGUMENTS (function); parm; parm = DECL_CHAIN(parm))
+ {
+ tree decl_name = DECL_NAME(parm);
+ gcc_assert(decl_name);
+ const char* identifier = IDENTIFIER_POINTER(decl_name);
+ gcc_assert(identifier);
+ tree tree_type = TREE_TYPE(parm);
+ gcc_assert(tree_type);
+ escaping_info *info = escape_map.get(tree_type);
+ gcc_assert(info);
+ info->is_escaping |= is_escaping;
+ log("variable %s is escaping %s\n", identifier, is_escaping ? "true" : "false");
+ }
+}
+
+void
is_any_function_escaping(type_map &escape_map)
{
cgraph_node *cnode = NULL;
FOR_EACH_FUNCTION (cnode)
{
+ cnode->get_untransformed_body();
log("function name = %s\n", cnode->name());
bool is_escaping = is_function_escaping(cnode);
log("function %s is escaping %s\n", cnode->name(), is_escaping ? "true" : "false");
-
+ calculate_escaping_parameters(cnode, escape_map);
}
}
@@ -245,8 +271,6 @@ is_any_variable_escaping(type_map &escape_map)
gcc_assert(type);
escaping_info *info = escape_map.get(type);
gcc_assert(info);
- // If there is any variable of this type that escapes.
- // This type will escape
info->is_escaping |= is_escaping;
}
}
diff --git a/gcc/testsuite/gcc.dg/ipa/ipa-ea-08-parameter-escapes-0.c b/gcc/testsuite/gcc.dg/ipa/ipa-ea-08-parameter-escapes-0.c
new file mode 100644
index 00000000000..e4c78d3abd3
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/ipa/ipa-ea-08-parameter-escapes-0.c
@@ -0,0 +1,28 @@
+/* { dg-do link } */
+/* { dg-options "-flto -fipa-hello-world -fdump-ipa-hello-world" } */
+/* { dg-require-effective-target lto } */
+
+
+#include <stddef.h>
+
+struct astruct_s { _Bool a; _Bool b; _Bool c;};
+struct astruct_s astruct; // This should not escape
+struct bstruct_s { _Bool a; _Bool b; _Bool c;};
+struct bstruct_s bstruct; // This should not escape
+
+__attribute__((externally_visible)) void escaping(struct astruct_s cstruct) {}
+void non_escaping(struct astruct_s dstruct) {}
+
+int main()
+{
+ astruct.a = 0;
+ bstruct.b = 0;
+}
+
+
+/* { dg-final { scan-wpa-ipa-dump "collected,astruct_s" "hello-world" } } */
+/* { dg-final { scan-wpa-ipa-dump "variable bstruct is escaping false" "hello-world" } } */
+/* { dg-final { scan-wpa-ipa-dump "collected,bstruct_s" "hello-world" } } */
+/* { dg-final { scan-wpa-ipa-dump "variable astruct is escaping false" "hello-world" } } */
+/* { dg-final { scan-wpa-ipa-dump "variable cstruct is escaping true" "hello-world" } } */
+/* { dg-final { scan-wpa-ipa-dump "variable dstruct is escaping false" "hello-world" } } */