diff options
author | Erick Ochoa <erick.ochoa@theobroma-systems.com> | 2020-03-09 15:29:15 +0100 |
---|---|---|
committer | Erick Ochoa <erick.ochoa@theobroma-systems.com> | 2020-04-28 23:35:48 +0200 |
commit | 85bf30ba742a1142f7c3249b87fb72d829f40aca (patch) | |
tree | bfe7e21af2f267e3ab3f7173d015358ce289e04e | |
parent | b084c84c358b7632e0896473de598bcd3f756339 (diff) |
collecting some types
-rw-r--r-- | gcc/ipa-hello-world.c | 130 |
1 files changed, 130 insertions, 0 deletions
diff --git a/gcc/ipa-hello-world.c b/gcc/ipa-hello-world.c index 738e385396d..67cc996bbf7 100644 --- a/gcc/ipa-hello-world.c +++ b/gcc/ipa-hello-world.c @@ -22,6 +22,10 @@ #include "tree-ssa-ccp.h" #include "stringpool.h" #include "attribs.h" +#include "gimple.h" +#include "cfg.h" // needed for gimple-iterator.h +#include "gimple-iterator.h" + #include "ipa-str-reorg-utils.h" // First we need to collect all types @@ -176,6 +180,130 @@ collect_parm_declarations (cgraph_node *cnode, type_map &escape_map) } static void +collect_local_declarations (cgraph_node *cnode, type_map &escape_map) +{ + gcc_assert(cnode); + int i = 0; + function *func = DECL_STRUCT_FUNCTION (cnode->decl); + cnode->get_untransformed_body (); + tree var_decl = NULL; + FOR_EACH_LOCAL_DECL (func, i, var_decl) + { + gcc_assert(var_decl); + bool filter_out = filter_var_decl(escape_map, var_decl); + if (filter_out) continue; + + tree tree_type = TREE_TYPE(var_decl); + gcc_assert(tree_type); + escaping_info info = { tree_type, false }; + escape_map.put(tree_type, info); + } +} + +static void +collect_pointer_plus (tree lhs, tree rhs1, tree rhs2, type_map &escape_map) +{ + 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; + bool is_rhs1_boring = rhs1_type ? filter_type(escape_map, rhs1_type) : true; + const_tree rhs2_type = rhs2 ? TREE_TYPE(rhs2): NULL; + bool is_rhs2_boring = rhs2_type ? filter_type(escape_map, rhs2_type) : true; + + if (!is_lhs_boring) + { + escaping_info info = { lhs_type , false }; + escape_map.put(lhs_type, info); + } + if (!is_rhs1_boring) + { + escaping_info info = { rhs1_type, false }; + escape_map.put(rhs1_type, info); + } + if (!is_rhs2_boring) + { + escaping_info info = {rhs2_type, false}; + escape_map.put(rhs2_type, info); + } + +} + +static void +collect_assign_rhs (gimple *stmt, type_map &escape_map) +{ + enum tree_code code = gimple_expr_code (stmt); + switch (code) + { + case POINTER_PLUS_EXPR: + case POINTER_DIFF_EXPR: + case COMPONENT_REF: + { + tree rhs2 = gimple_assign_rhs2(stmt); + tree rhs1 = gimple_assign_rhs1(stmt); + tree lhs = gimple_assign_lhs (stmt); + collect_pointer_plus (lhs, rhs1, rhs2, escape_map); + break; + } + default: + break; + } +} + +static void +collect_assign (gimple *stmt, type_map &escape_map) +{ + gcc_assert(stmt); + collect_assign_rhs (stmt, escape_map); +} + +static void +collect_stmt (gimple *stmt, type_map &escape_map) +{ + gcc_assert (stmt); + const enum gimple_code code = gimple_code (stmt); + switch (code) + { + case GIMPLE_ASSIGN: + collect_assign(stmt, escape_map); + break; + default: + break; + } + + return; +} + +static void +collect_basic_block (basic_block bb, type_map &escape_map) +{ + gcc_assert(bb); + for (gimple_stmt_iterator gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next(&gsi)) + { + gimple *stmt = gsi_stmt (gsi); + collect_stmt (stmt, escape_map); + } +} + +static void +collect_function_body (cgraph_node *cnode, type_map &escape_map) +{ + gcc_assert (cnode); + cnode->get_untransformed_body(); + basic_block bb = NULL; + tree decl = cnode->decl; + gcc_assert(decl); + function *func = DECL_STRUCT_FUNCTION (decl); + gcc_assert(func); + push_cfun(func); + FOR_EACH_BB_FN (bb, func) + { + gcc_assert(bb); + collect_basic_block (bb, escape_map); + } + pop_cfun(); +} + +static void collect_types(type_map &escape_map) { collect_globals(escape_map); @@ -184,6 +312,8 @@ collect_types(type_map &escape_map) FOR_EACH_DEFINED_FUNCTION (cnode) { collect_parm_declarations (cnode, escape_map); + collect_function_body (cnode, escape_map); + collect_local_declarations (cnode, escape_map); } } |