diff options
author | Erick Ochoa <erick.ochoa@theobroma-systems.com> | 2020-06-18 12:41:28 +0200 |
---|---|---|
committer | Erick Ochoa <erick.ochoa@theobroma-systems.com> | 2020-06-18 19:21:40 +0200 |
commit | 3a3a5ef9b009db9c18cfd3034ef54ce8659d47d3 (patch) | |
tree | 66868105091844697233eabba28e7b7e3534e482 | |
parent | 7d2ffd13c68f26387a8bb3b27601f894e3036b4d (diff) |
return type
-rw-r--r-- | gcc/expr-rewriter.c | 23 | ||||
-rw-r--r-- | gcc/expr-rewriter.hpp | 1 | ||||
-rw-r--r-- | gcc/expr-walker.c | 1 | ||||
-rw-r--r-- | gcc/gimple-rewriter.c | 21 | ||||
-rw-r--r-- | gcc/gimple-rewriter.hpp | 1 | ||||
-rw-r--r-- | gcc/ipa-type-escape-analysis.c | 1 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/ipa/ipa-structreorg-38-return-values-0.c | 3 |
7 files changed, 50 insertions, 1 deletions
diff --git a/gcc/expr-rewriter.c b/gcc/expr-rewriter.c index 6afb3158dc9..ef8f93244e6 100644 --- a/gcc/expr-rewriter.c +++ b/gcc/expr-rewriter.c @@ -41,6 +41,29 @@ ExprTypeRewriter::_walk_PARM_DECL_post(const_tree t) } void +ExprTypeRewriter::_walk_FUNCTION_DECL_post(const_tree t) +{ + tree fn_type = TREE_TYPE(t); + gcc_assert(t); + tree ret_type = TREE_TYPE(fn_type); + if (!ret_type) return; + + TypeStringifier stringifier; + std::string name = stringifier.stringify(ret_type); + // TODO: You cannot use is interesting here because you haven't + // changed the return type + // This is because the return type is not an expression. + // Therefore it is awkward to do this in the expr-walker... + // const bool is_interesting = is_interesting_type(ret_type); + const bool is_interesting = _map.find(ret_type) != _map.end(); + if (!is_interesting) return; + + tree r_t = _map[ret_type]; + TREE_TYPE(fn_type) = r_t; + log("rewriting a return type\n"); +} + +void ExprTypeRewriter::_walk_SSA_NAME_post(const_tree t) { tree temp = (tree)(t); diff --git a/gcc/expr-rewriter.hpp b/gcc/expr-rewriter.hpp index 0f0c310319c..936392b7af2 100644 --- a/gcc/expr-rewriter.hpp +++ b/gcc/expr-rewriter.hpp @@ -26,4 +26,5 @@ private: void _walk_COMPONENT_REF_post(const_tree e); void _walk_PARM_DECL_post(const_tree e); void _walk_SSA_NAME_post(const_tree e); + void _walk_FUNCTION_DECL_post(const_tree e); }; diff --git a/gcc/expr-walker.c b/gcc/expr-walker.c index 73a8625323d..f5f795dfa97 100644 --- a/gcc/expr-walker.c +++ b/gcc/expr-walker.c @@ -308,4 +308,5 @@ ExprWalker::_walk_FUNCTION_DECL(const_tree e) { walk(parm); } + } diff --git a/gcc/gimple-rewriter.c b/gcc/gimple-rewriter.c index 7518844d658..ddd969226d5 100644 --- a/gcc/gimple-rewriter.c +++ b/gcc/gimple-rewriter.c @@ -51,6 +51,10 @@ GimpleTypeRewriter::_walk_pre(gcall *s) void GimpleTypeRewriter::_walk_pre(greturn *s) { + const_tree val = gimple_return_retval(s); + if (!val) return; + log("rewriting a return value\n"); + exprTypeRewriter.walk(val); } void @@ -150,3 +154,20 @@ void GimpleTypeRewriter::_walk_pre(gcond *s) { } + +void +GimpleTypeRewriter::_rewrite_function_decl() +{ + // NOTE: It seems we only need to rewrite the return type + // for now... + cgraph_node *node = NULL; + FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) + { + node->get_untransformed_body(); + tree fndecl = node->decl; + gcc_assert(fndecl); + exprTypeRewriter.walk(fndecl); + } + + +} diff --git a/gcc/gimple-rewriter.hpp b/gcc/gimple-rewriter.hpp index 1b9ec6bd0c6..4cc7ac49f65 100644 --- a/gcc/gimple-rewriter.hpp +++ b/gcc/gimple-rewriter.hpp @@ -8,6 +8,7 @@ class GimpleTypeRewriter : public GimpleWalker { public: GimpleTypeRewriter(TypeReconstructor::reorg_record_map_t map, TypeReconstructor::reorg_field_map_t map2) : exprTypeRewriter(map, map2) {}; + void _rewrite_function_decl(); private: ExprTypeRewriter exprTypeRewriter; void handle_pointer_arithmetic(gimple *s); diff --git a/gcc/ipa-type-escape-analysis.c b/gcc/ipa-type-escape-analysis.c index fe48b552997..3ce6763558b 100644 --- a/gcc/ipa-type-escape-analysis.c +++ b/gcc/ipa-type-escape-analysis.c @@ -300,6 +300,7 @@ collect_types() GimpleTypeRewriter rewriter(map, field_map); rewriter.walk(); + rewriter._rewrite_function_decl(); GimpleWalker walker; walker.walk(); // Just for printing... diff --git a/gcc/testsuite/gcc.dg/ipa/ipa-structreorg-38-return-values-0.c b/gcc/testsuite/gcc.dg/ipa/ipa-structreorg-38-return-values-0.c index 0df611a7d7b..db81ae564df 100644 --- a/gcc/testsuite/gcc.dg/ipa/ipa-structreorg-38-return-values-0.c +++ b/gcc/testsuite/gcc.dg/ipa/ipa-structreorg-38-return-values-0.c @@ -1,5 +1,5 @@ /* { dg-do run } */ -/* { dg-options "-flto -flto-partition=none -fipa-dead-field-eliminate -fdump-ipa-structure-reorg -fipa-typelist-field=b -fipa-typelist-struct=astruct_s" } */ +/* { dg-options "-flto -fipa-type-escape-analysis -fdump-ipa-type-escape-analysis " } */ #include <assert.h> #include <stdio.h> @@ -29,6 +29,7 @@ main (int argc, char **argv) { struct astruct_s astruct; astruct = foo (argc); + printf("%d %d %d\n", astruct.a, astruct.c, astruct.d); _Bool *a = &(astruct.a); assert (!*a); _Bool *c = a + 1; |