diff options
author | Erick Ochoa <erick.ochoa@theobroma-systems.com> | 2020-03-09 12:23:06 +0100 |
---|---|---|
committer | Erick Ochoa <erick.ochoa@theobroma-systems.com> | 2020-04-28 23:35:47 +0200 |
commit | 5f9159551a2e2b60b20c1e2a2e76052d0f06c6b7 (patch) | |
tree | 728882c8a6d6092edff0161e3e35a44f05c1b012 | |
parent | 0505d8724fb62f09ecc70518f3ad90a1071d49bb (diff) |
Prints out if type of global variable escapes
-rw-r--r-- | gcc/ipa-hello-world.c | 46 |
1 files changed, 26 insertions, 20 deletions
diff --git a/gcc/ipa-hello-world.c b/gcc/ipa-hello-world.c index 93ba0ce62a0..e5f69308e3c 100644 --- a/gcc/ipa-hello-world.c +++ b/gcc/ipa-hello-world.c @@ -37,7 +37,9 @@ log (const char * const format, ...) } -typedef hash_map<const_tree, void*> type_map; +struct escaping_info_s { const_tree type; bool is_escaping; }; +typedef struct escaping_info_s escaping_info; +typedef hash_map<const_tree, escaping_info> type_map; static bool filter_type (type_map &escape_map, const_tree type); static bool @@ -95,7 +97,8 @@ filter_type (type_map &escape_map, const_tree type) if (retval) return retval; - escape_map.put(type, NULL); + escaping_info info = { type, false }; + escape_map.put(type, info); return retval; } @@ -141,7 +144,8 @@ collect_global(type_map &escape_map, varpool_node *vnode) tree type = TREE_TYPE(decl); gcc_assert(type); - escape_map.put (type, NULL); + escaping_info info = { type, false }; + escape_map.put (type, info); } } @@ -166,7 +170,8 @@ collect_parm_declarations (cgraph_node *cnode, type_map &escape_map) tree type = TREE_TYPE(parm); gcc_assert(type); - escape_map.put(type, NULL); + escaping_info info = { type, false }; + escape_map.put(type, info); } } @@ -183,9 +188,11 @@ collect_types(type_map &escape_map) } bool -_print_types( const_tree const &type, __attribute__((unused)) void**, __attribute((unused)) void*) +_print_types( const_tree const &type, escaping_info *info, __attribute((unused)) void*) { log("collected,%s\n", get_type_name(type)); + bool is_escaping = info->is_escaping; + log("type %s is escaping %s\n", get_type_name(type), is_escaping ? "true" : "false"); return true; } @@ -203,25 +210,24 @@ is_variable_escaping(varpool_node *vnode) return vnode->externally_visible; } -static bool -is_variable_escaping(const_tree variable) -{ - gcc_assert(variable); - enum tree_code code = TREE_CODE(variable); - gcc_assert(VAR_DECL == code); - varpool_node *vnode = varpool_node::get_create((tree) variable); - gcc_assert(vnode); - return is_variable_escaping(vnode); -} - void -is_any_variable_escaping() +is_any_variable_escaping(type_map &escape_map) { varpool_node *vnode = NULL; + // Global variables FOR_EACH_VARIABLE(vnode) { - bool escaping = is_variable_escaping(vnode); - log("variable %s is escaping %s\n", vnode->name(), escaping ? "true" : "false"); + bool is_escaping = is_variable_escaping(vnode); + log("variable %s is escaping %s\n", vnode->name(), is_escaping ? "true" : "false"); + tree decl = vnode->decl; + gcc_assert(decl); + tree type = TREE_TYPE(decl); + 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; } } @@ -230,7 +236,7 @@ iphw_execute() { type_map escape_map; collect_types(escape_map); - is_any_variable_escaping(); + is_any_variable_escaping(escape_map); print_types(escape_map); return 0; } |