summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErick Ochoa <erick.ochoa@theobroma-systems.com>2020-06-04 13:39:49 +0200
committerErick Ochoa <erick.ochoa@theobroma-systems.com>2020-06-04 13:39:49 +0200
commit9ac3804b57a361a6e4bf91686afa768ccf725953 (patch)
treec07132048244a21a9c16e583a8311c4a0b1ceb40
parentcf126175de70a7333d321f80a83e495767490222 (diff)
collector and walker
-rw-r--r--gcc/Makefile.in2
-rw-r--r--gcc/gimple-collector.c201
-rw-r--r--gcc/gimple-collector.hpp24
-rw-r--r--gcc/gimple-walker.c136
-rw-r--r--gcc/gimple-walker.hpp27
-rw-r--r--gcc/ipa-prototype.c3
-rw-r--r--gcc/ipa-type-collector.c430
7 files changed, 400 insertions, 423 deletions
diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index c363f7f7bd1..7f8a633b7ff 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -1413,6 +1413,8 @@ OBJS = \
expr-collector.o \
type-walker.o \
type-collector.o \
+ gimple-collector.o \
+ gimple-walker.o \
type-stringifier.o \
compare-types.o \
collect-types.o \
diff --git a/gcc/gimple-collector.c b/gcc/gimple-collector.c
new file mode 100644
index 00000000000..7b29f35a7ab
--- /dev/null
+++ b/gcc/gimple-collector.c
@@ -0,0 +1,201 @@
+#include "config.h"
+#include "system.h"
+#include "coretypes.h"
+#include "backend.h"
+#include "tree.h"
+#include "gimple-expr.h"
+#include "predict.h"
+#include "alloc-pool.h"
+#include "tree-pass.h"
+#include "cgraph.h"
+#include "diagnostic.h"
+#include "fold-const.h"
+#include "gimple-fold.h"
+#include "symbol-summary.h"
+#include "tree-vrp.h"
+#include "ipa-prop.h"
+#include "tree-pretty-print.h"
+#include "tree-inline.h"
+#include "ipa-fnsummary.h"
+#include "ipa-utils.h"
+#include "tree-ssa-ccp.h"
+#include "stringpool.h"
+#include "attribs.h"
+#include "tree-ssa-alias.h"
+#include "tree-ssanames.h"
+#include "gimple.h"
+#include "cfg.h"
+#include "gimple-iterator.h"
+#include "gimple-ssa.h"
+
+#include "compare-types.h"
+#include "types-inlines.h"
+#include <set>
+#include <string>
+#include <map>
+
+#include "collect-types.h"
+#include "name-types.h"
+#include "type-stringifier.hpp"
+
+#include "ipa-type-collector.h"
+#include "type-collector.hpp"
+#include "expr-walker.hpp"
+#include "expr-collector.hpp"
+#include "gimple-collector.hpp"
+
+void
+GimpleTypeCollector::collect()
+{
+ _collect_globals();
+
+ cgraph_node *node = NULL;
+ long unsigned i = 0;
+ FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node)
+ {
+ node->get_untransformed_body();
+ collect(node);
+ }
+}
+
+void
+GimpleTypeCollector::_collect_globals()
+{
+ varpool_node *vnode = NULL;
+ unsigned long i = 0;
+ FOR_EACH_VARIABLE(vnode)
+ {
+ _collect_global(vnode);
+ }
+}
+
+void
+GimpleTypeCollector::_collect_global(varpool_node *vnode)
+{
+ gcc_assert(vnode);
+ struct ipa_ref *ref = NULL;
+ for (unsigned i = 0; vnode->iterate_referring(i, ref); i++)
+ {
+ tree var_decl = vnode->decl;
+ exprCollector.walk(var_decl);
+ }
+}
+
+void
+GimpleTypeCollector::collect(cgraph_node *cnode)
+{
+ gcc_assert(cnode);
+ _collect_decl(cnode);
+ _collect_locals(cnode);
+ _collect_ssa_names(cnode);
+ walk(cnode);
+}
+
+void
+GimpleTypeCollector::_collect_decl(cgraph_node *cnode)
+{
+ const_tree decl = cnode->decl;
+ gcc_assert(decl);
+ exprCollector.walk(decl);
+}
+
+void
+GimpleTypeCollector::_collect_ssa_names(cgraph_node *cnode)
+{
+ const_tree decl = cnode->decl;
+ gcc_assert(decl);
+ function *func = DECL_STRUCT_FUNCTION(decl);
+ gcc_assert(func);
+ size_t i = 0;
+ tree ssa_name = NULL;
+ push_cfun(func);
+ FOR_EACH_SSA_NAME(i, ssa_name, cfun)
+ {
+ gcc_assert(ssa_name);
+ exprCollector.walk(ssa_name);
+ }
+}
+
+void
+GimpleTypeCollector::_collect_locals(cgraph_node *cnode)
+{
+ const_tree decl = cnode->decl;
+ gcc_assert(decl);
+ function *func = DECL_STRUCT_FUNCTION(decl);
+ gcc_assert(func);
+ int i = 0;
+ tree var_decl = NULL;
+ FOR_EACH_LOCAL_DECL(func, i, var_decl)
+ {
+ gcc_assert(var_decl);
+ exprCollector.walk(decl);
+ }
+}
+
+void
+GimpleTypeCollector::_walk_pre(gassign *s)
+{
+ const_tree lhs = gimple_assign_lhs(s);
+ exprCollector.walk(lhs);
+
+ const enum gimple_rhs_class gclass = gimple_assign_rhs_class(s);
+ switch (gclass)
+ {
+ case GIMPLE_TERNARY_RHS:
+ {
+ const_tree rhs = gimple_assign_rhs3(s);
+ exprCollector.walk(rhs);
+ }
+ /* fall-through */
+ case GIMPLE_BINARY_RHS:
+ {
+ const_tree rhs = gimple_assign_rhs2(s);
+ exprCollector.walk(rhs);
+ }
+ /* fall-through */
+ case GIMPLE_UNARY_RHS:
+ case GIMPLE_SINGLE_RHS:
+ {
+ const_tree rhs = gimple_assign_rhs1(s);
+ exprCollector.walk(rhs);
+ }
+ break;
+ default:
+ gcc_unreachable();
+ break;
+ }
+}
+
+void
+GimpleTypeCollector::_walk_pre(greturn *s)
+{
+ const_tree retval = gimple_return_retval(s);
+ if (!retval) return;
+
+ exprCollector.walk(retval);
+}
+
+void
+GimpleTypeCollector::_walk_pre(gcond *s)
+{
+ const_tree lhs = gimple_cond_lhs(s);
+ exprCollector.walk(lhs);
+ const_tree rhs = gimple_cond_rhs(s);
+ exprCollector.walk(rhs);
+}
+
+void
+GimpleTypeCollector::_walk_pre(gcall *s)
+{
+ unsigned n = gimple_call_num_args(s);
+ for (unsigned i = 0; i < n; i++)
+ {
+ const_tree a = gimple_call_arg(s, i);
+ exprCollector.walk(a);
+ }
+
+ const_tree lhs = gimple_call_lhs(s);
+ if (!lhs) return;
+
+ exprCollector.walk(lhs);
+}
diff --git a/gcc/gimple-collector.hpp b/gcc/gimple-collector.hpp
new file mode 100644
index 00000000000..a27d37258fa
--- /dev/null
+++ b/gcc/gimple-collector.hpp
@@ -0,0 +1,24 @@
+#pragma once
+
+#include "gimple-walker.hpp"
+#include "expr-collector.hpp"
+
+class GimpleTypeCollector : public GimpleWalker
+{
+public:
+ GimpleTypeCollector() {};
+ void collect();
+private:
+ ExprCollector exprCollector;
+ void _collect_globals();
+ void _collect_global(varpool_node *);
+ void collect(cgraph_node *cnode);
+ void _collect_decl(cgraph_node *);
+ void _collect_locals(cgraph_node *);
+ void _collect_ssa_names(cgraph_node *);
+ virtual void _walk_pre(gassign *s);
+ virtual void _walk_pre(greturn *s);
+ virtual void _walk_pre(gcond *s);
+ virtual void _walk_pre(gcall *s);
+};
+
diff --git a/gcc/gimple-walker.c b/gcc/gimple-walker.c
new file mode 100644
index 00000000000..ca2f874ce3a
--- /dev/null
+++ b/gcc/gimple-walker.c
@@ -0,0 +1,136 @@
+#include "config.h"
+#include "system.h"
+#include "coretypes.h"
+#include "backend.h"
+#include "tree.h"
+#include "gimple-expr.h"
+#include "predict.h"
+#include "alloc-pool.h"
+#include "tree-pass.h"
+#include "cgraph.h"
+#include "diagnostic.h"
+#include "fold-const.h"
+#include "gimple-fold.h"
+#include "symbol-summary.h"
+#include "tree-vrp.h"
+#include "ipa-prop.h"
+#include "tree-pretty-print.h"
+#include "tree-inline.h"
+#include "ipa-fnsummary.h"
+#include "ipa-utils.h"
+#include "tree-ssa-ccp.h"
+#include "stringpool.h"
+#include "attribs.h"
+#include "tree-ssa-alias.h"
+#include "tree-ssanames.h"
+#include "gimple.h"
+#include "cfg.h"
+#include "gimple-iterator.h"
+#include "gimple-ssa.h"
+
+#include "compare-types.h"
+#include "types-inlines.h"
+#include <set>
+#include <string>
+#include <map>
+
+#include "collect-types.h"
+#include "name-types.h"
+#include "type-stringifier.hpp"
+
+#include "ipa-type-collector.h"
+#include "type-collector.hpp"
+#include "expr-walker.hpp"
+#include "expr-collector.hpp"
+#include "gimple-walker.hpp"
+
+void
+GimpleWalker::walk(cgraph_node* cnode)
+{
+ gcc_assert(cnode);
+ cnode->get_untransformed_body();
+ const_tree decl = cnode->decl;
+ gcc_assert(decl);
+ function *func = DECL_STRUCT_FUNCTION(decl);
+ gcc_assert(func);
+ basic_block bb = NULL;
+ push_cfun(func);
+ FOR_EACH_BB_FN(bb, func)
+ {
+ walk(bb);
+ }
+ pop_cfun();
+}
+
+void
+GimpleWalker::walk(basic_block bb)
+{
+ gcc_assert(bb);
+ for (auto gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi))
+ {
+ gimple *stmt = gsi_stmt(gsi);
+ walk(stmt);
+ }
+}
+
+void
+GimpleWalker::walk(gimple *stmt)
+{
+ _walk_pre(stmt);
+ _walk(stmt);
+ _walk_post(stmt);
+}
+
+void
+GimpleWalker::_walk(gimple *stmt)
+{
+ gcc_assert(stmt);
+
+#define GimpleWalkerWalk(type) \
+ if (type *s = dyn_cast<type *>(stmt)) \
+ { \
+ _walk_pre(stmt); \
+ walk(s); \
+ _walk_post(stmt); \
+ return; \
+ }
+
+ GimpleWalkerWalk(gassign);
+ GimpleWalkerWalk(greturn);
+ GimpleWalkerWalk(gcond);
+ GimpleWalkerWalk(gcall);
+ GimpleWalkerWalk(glabel);
+ GimpleWalkerWalk(gswitch);
+
+
+ const enum gimple_code code = gimple_code (stmt);
+ switch (code)
+ {
+ case GIMPLE_PREDICT: return;
+ default: break;
+ }
+ const char* name = gimple_code_name[code];
+ log("gimple code name %s\n", name);
+ gcc_unreachable();
+}
+
+#define GimpleWalkerFuncDef(type) \
+void \
+GimpleWalker::walk (type *e) \
+{ \
+ _walk_pre (e); \
+ _walk (e); \
+ _walk_post (e); \
+} \
+\
+void \
+GimpleWalker::_walk(type *e) \
+{ \
+}
+
+GimpleWalkerFuncDef(gassign);
+GimpleWalkerFuncDef(greturn);
+GimpleWalkerFuncDef(gcond);
+GimpleWalkerFuncDef(gcall);
+GimpleWalkerFuncDef(glabel);
+GimpleWalkerFuncDef(gswitch);
diff --git a/gcc/gimple-walker.hpp b/gcc/gimple-walker.hpp
new file mode 100644
index 00000000000..40d92257efe
--- /dev/null
+++ b/gcc/gimple-walker.hpp
@@ -0,0 +1,27 @@
+#pragma once
+
+class GimpleWalker
+{
+public:
+ GimpleWalker() {};
+ void walk(cgraph_node *cnode);
+
+private:
+
+ void walk(basic_block bb);
+
+#define GimpleWalkerFuncDecl(type) \
+ virtual void _walk_pre(type *stmt) {}; \
+ void walk(type *stmt); \
+ void _walk(type *stmt); \
+ virtual void _walk_post(type *stmt) {}
+
+ GimpleWalkerFuncDecl(gimple);
+ GimpleWalkerFuncDecl(gassign);
+ GimpleWalkerFuncDecl(greturn);
+ GimpleWalkerFuncDecl(gcond);
+ GimpleWalkerFuncDecl(gcall);
+ GimpleWalkerFuncDecl(glabel);
+ GimpleWalkerFuncDecl(gswitch);
+};
+
diff --git a/gcc/ipa-prototype.c b/gcc/ipa-prototype.c
index ddaaf87b642..ea13abb3fe1 100644
--- a/gcc/ipa-prototype.c
+++ b/gcc/ipa-prototype.c
@@ -41,6 +41,8 @@
#include <vector>
#include "type-escaper.hpp"
#include "expr-escaper.hpp"
+#include "gimple-walker.hpp"
+#include "gimple-collector.hpp"
//#define OPTIMIZED
#define SANITY_CHECKS
@@ -727,6 +729,7 @@ iphw_execute()
print_escaping_types_in_set(types);
sanity_check_escape_xor_not(types);
sanity_check_escape_union_not_equals_ptrset(types);
+ gcc_unreachable();
return 0;
}
diff --git a/gcc/ipa-type-collector.c b/gcc/ipa-type-collector.c
index f532a7f3e48..29b77e138a5 100644
--- a/gcc/ipa-type-collector.c
+++ b/gcc/ipa-type-collector.c
@@ -42,9 +42,9 @@
#include "type-collector.hpp"
#include "expr-walker.hpp"
#include "expr-collector.hpp"
+#include "gimple-collector.hpp"
//#define FUZZ_MODE 1
-static void collect_types(const_tree t);
namespace type_playground {
enum type_comparison_func_enum {
@@ -80,307 +80,12 @@ static type_comparison_func_t comparisons[type_comparisons] = {
}
+static TypeCollector _typeCollector;
+ptrset_t *TypeCollector::ptrset = NULL;
+static ExprCollector exprCollector;
+TypeCollector * ExprCollector::typeCollector = &_typeCollector;
-static void collect_types_from_expr(const_tree expr, ptrset_t &types);
-
-
-static void
-collect_types_from_stmt_assign_lhs(gimple *stmt, ptrset_t &types)
-{
- is_gimple_code(stmt, GIMPLE_ASSIGN);
- const_tree lhs = gimple_assign_lhs(stmt);
- gcc_assert(lhs);
- collect_types_from_expr(lhs, types);
-}
-
-static void
-collect_types_from_stmt_assign_rhs3(gimple *stmt, ptrset_t &types)
-{
- is_gimple_rhs_class(stmt, GIMPLE_TERNARY_RHS);
- const_tree rhs = gimple_assign_rhs3(stmt);
- gcc_assert(rhs);
- collect_types_from_expr(rhs, types);
-}
-
-static void
-collect_types_from_stmt_assign_rhs2(gimple *stmt, ptrset_t &types)
-{
- is_gimple_code(stmt, GIMPLE_ASSIGN);
- const enum gimple_rhs_class gclass = gimple_assign_rhs_class(stmt);
- const bool is_ternary = GIMPLE_TERNARY_RHS == gclass;
- const bool is_binary = GIMPLE_BINARY_RHS == gclass;
- const bool is_valid_input = is_ternary || is_binary;
- gcc_assert(is_valid_input);
- const_tree rhs = gimple_assign_rhs2(stmt);
- gcc_assert(rhs);
- collect_types_from_expr(rhs, types);
-}
-
-static void
-collect_types_from_stmt_assign_rhs1(gimple *stmt, ptrset_t &types)
-{
- is_gimple_code(stmt, GIMPLE_ASSIGN);
- const enum gimple_rhs_class gclass = gimple_assign_rhs_class(stmt);
- const bool is_ternary = GIMPLE_TERNARY_RHS == gclass;
- const bool is_binary = GIMPLE_BINARY_RHS == gclass;
- const bool is_unary = GIMPLE_UNARY_RHS == gclass;
- const bool is_single = GIMPLE_SINGLE_RHS == gclass;
- const bool is_valid_input = is_ternary || is_binary || is_unary || is_single;
- gcc_assert(is_valid_input);
- const_tree rhs = gimple_assign_rhs1(stmt);
- gcc_assert(rhs);
- collect_types_from_expr(rhs, types);
-}
-
-static void
-collect_types_from_stmt_assign_rhs(gimple *stmt, ptrset_t &types)
-{
- is_gimple_code(stmt, GIMPLE_ASSIGN);
- const enum gimple_rhs_class gclass = gimple_assign_rhs_class(stmt);
- switch (gclass)
- {
- case GIMPLE_TERNARY_RHS:
- collect_types_from_stmt_assign_rhs3(stmt, types);
- /* fall-through */
- case GIMPLE_BINARY_RHS:
- collect_types_from_stmt_assign_rhs2(stmt, types);
- /* fall-through */
- case GIMPLE_UNARY_RHS:
- case GIMPLE_SINGLE_RHS:
- collect_types_from_stmt_assign_rhs1(stmt, types);
- break;
- default:
- gcc_unreachable();
- break;
- }
-}
-
-static void
-collect_types_from_stmt_assign(gimple *stmt, ptrset_t &types)
-{
- is_gimple_code(stmt, GIMPLE_ASSIGN);
- collect_types_from_stmt_assign_lhs(stmt, types);
- collect_types_from_stmt_assign_rhs(stmt, types);
-}
-
-static void
-collect_types_from_stmt_call_lhs(gimple *stmt, ptrset_t &types)
-{
- is_gimple_code(stmt, GIMPLE_CALL);
- const_tree lhs = gimple_call_lhs(stmt);
- if (!lhs) return;
-
- tree fn = gimple_call_fndecl(stmt);
- if (!fn) return;
-
- const_tree decl_name = DECL_NAME(fn);
- const char *identifier = decl_name ? IDENTIFIER_POINTER(decl_name) : "";
- collect_types_from_expr(lhs, types);
-}
-
-static void
-collect_types_from_stmt_call_rhs(gimple *stmt, ptrset_t &types)
-{
- is_gimple_code(stmt, GIMPLE_CALL);
- unsigned num_args = gimple_call_num_args(stmt);
- for (unsigned i = 0; i < num_args; i++)
- {
- const_tree arg_i = gimple_call_arg(stmt, i);
- collect_types_from_expr(arg_i, types);
- }
-}
-
-static void
-collect_types_from_stmt_call(gimple *stmt, ptrset_t &types)
-{
- is_gimple_code(stmt, GIMPLE_CALL);
- collect_types_from_stmt_call_lhs(stmt, types);
- collect_types_from_stmt_call_rhs(stmt, types);
-}
-
-static void
-collect_types_from_stmt_cond_lhs(gimple *stmt, ptrset_t &types)
-{
- is_gimple_code(stmt, GIMPLE_COND);
- const_tree lhs = gimple_cond_lhs(stmt);
- gcc_assert(lhs);
- collect_types_from_expr(lhs, types);
-}
-
-static void
-collect_types_from_stmt_cond_rhs(gimple *stmt, ptrset_t &types)
-{
- is_gimple_code(stmt, GIMPLE_COND);
- const_tree rhs = gimple_cond_rhs(stmt);
- gcc_assert(rhs);
- collect_types_from_expr(rhs, types);
-}
-
-static void
-collect_types_from_stmt_cond(gimple *stmt, ptrset_t &types)
-{
- is_gimple_code(stmt, GIMPLE_COND);
- collect_types_from_stmt_cond_lhs(stmt, types);
- collect_types_from_stmt_cond_rhs(stmt, types);
-}
-
-static void
-collect_types_from_stmt_return(gimple *stmt, ptrset_t &types)
-{
- is_gimple_code(stmt, GIMPLE_RETURN);
- const_tree retval = gimple_return_retval(stmt);
- if (!retval) return;
-
- collect_types_from_expr(retval, types);
-}
-
-static void
-collect_types_from_stmt(gimple *stmt, ptrset_t &types)
-{
- gcc_assert(stmt);
- const enum gimple_code code = gimple_code(stmt);
- switch (code) {
- case GIMPLE_ASSIGN:
- collect_types_from_stmt_assign(stmt, types);
- break;
- case GIMPLE_CALL:
- collect_types_from_stmt_call(stmt, types);
- break;
- case GIMPLE_COND:
- collect_types_from_stmt_cond(stmt, types);
- break;
- case GIMPLE_RETURN:
- collect_types_from_stmt_return(stmt, types);
- break;
- case GIMPLE_LABEL:
- case GIMPLE_PREDICT:
- case GIMPLE_DEBUG:
- case GIMPLE_SWITCH:
-#ifdef FUZZ_MODE
- gcc_unreachable();
-#endif
- break;
- default:
- {
- const char* name = gimple_code_name[code];
- log("gimple code name %s\n", name);
- gcc_unreachable();
- }
- break;
- }
-}
-
-
-static void
-collect_types_from_cnode_decl(cgraph_node *cnode, ptrset_t &types)
-{
- gcc_assert(cnode);
- const_tree decl = cnode->decl;
- gcc_assert(decl);
- //collect_types_from_function_decl(decl, types);
-}
-
-static void
-collect_types_from_cnode_locals(cgraph_node *cnode, ptrset_t &types)
-{
- gcc_assert(cnode);
- const_tree decl = cnode->decl;
- gcc_assert(decl);
- collect_types_from_expr(decl, types);
- function *func = DECL_STRUCT_FUNCTION (decl);
- gcc_assert(func);
- int i = 0;
- tree var_decl = NULL;
- FOR_EACH_LOCAL_DECL(func, i, var_decl)
- {
- gcc_assert(var_decl);
- collect_types_from_expr(var_decl, types);
- }
-}
-
-static void
-collect_types_from_cnode_ssa_names(cgraph_node *cnode, ptrset_t &types)
-{
- gcc_assert(cnode);
- const_tree decl = cnode->decl;
- gcc_assert(decl);
- function *func = DECL_STRUCT_FUNCTION (decl);
- gcc_assert(func);
- size_t i = 0;
- tree ssa_name = NULL;
- push_cfun(func);
- FOR_EACH_SSA_NAME(i, ssa_name, cfun)
- {
- gcc_assert(ssa_name);
- collect_types_from_expr(ssa_name, types);
- }
- pop_cfun();
-}
-
-static void
-collect_types_from_bb(basic_block bb, ptrset_t &types)
-{
- gcc_assert(bb);
- for (auto gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi))
- {
- gimple *stmt = gsi_stmt(gsi);
- gcc_assert(stmt);
- collect_types_from_stmt(stmt, types);
- }
-}
-
-static void
-collect_types_from_cnode_bb(cgraph_node *cnode, ptrset_t &types)
-{
- gcc_assert(cnode);
- cnode->get_untransformed_body();
- tree decl = cnode->decl;
- gcc_assert(decl);
- function *func = DECL_STRUCT_FUNCTION(decl);
- gcc_assert(func);
- basic_block bb = NULL;
- push_cfun(func);
- FOR_EACH_BB_FN(bb, func)
- {
- gcc_assert(bb);
- collect_types_from_bb(bb, types);
- }
- pop_cfun();
-}
-
-static void
-collect_types_from_global(varpool_node *vnode, ptrset_t &types)
-{
- gcc_assert(vnode);
- struct ipa_ref *ref = NULL;
- for (unsigned i = 0; vnode->iterate_referring(i, ref); i++)
- {
- tree decl = vnode->decl;
- gcc_assert(decl);
- collect_types_from_expr(decl, types);
- }
-}
-
-static void
-collect_types_from_globals(ptrset_t &types)
-{
- varpool_node *vnode = NULL;
- unsigned long i = 0;
- FOR_EACH_VARIABLE (vnode)
- {
- collect_types_from_global(vnode, types);
- }
-}
-static void
-collect_types_from_functions_with_gimple_body(cgraph_node *cnode, ptrset_t &types)
-{
- gcc_assert(cnode);
- collect_types_from_cnode_decl(cnode, types);
- collect_types_from_cnode_locals(cnode, types);
- collect_types_from_cnode_ssa_names(cnode, types);
- collect_types_from_cnode_bb(cnode, types);
-}
static void
print_types_in_set(ptrset_t &types)
@@ -392,105 +97,6 @@ print_types_in_set(ptrset_t &types)
}
}
-static const bool
-filter_comparisons_functions_char(const char* function_name)
-{
- // Everything should run
- if (!flag_tp_comparison_functions) return true;
-
- const size_t buffer_size = 1024;
- const size_t cli_length = strlen(flag_tp_comparison_functions);
- gcc_assert(buffer_size > cli_length);
- char whitelist[buffer_size];
- strcpy(whitelist, flag_tp_comparison_functions);
-
-
- char* saveptr = whitelist;
- char* token = NULL;
- while (token = strtok_r(saveptr, ",", &saveptr))
- {
- const bool name_allowed = strcmp(token, function_name) == 0;
- if (name_allowed) return true;
- }
-
- return false;
-}
-
-static const bool
-filter_comparisons_functions_int(unsigned function_id)
-{
- if (!flag_tp_comparison_functions) return true;
-
- const char* function_name = type_playground::names[function_id];
- return filter_comparisons_functions_char(function_name);
-}
-
-static const bool
-filter_comparisons_functions(type_playground::type_comparison_func_t func)
-{
- if (!flag_tp_comparison_functions) return true;
-
- for (unsigned i = 0; i < type_playground::type_comparisons; i++)
- {
- if (func != type_playground::comparisons[i]) continue;
-
- return filter_comparisons_functions_int(i);
- }
-
- return false;
-}
-
-
-static void
-compare_types_in_set(ptrset_t &types)
-{
- for (auto i = types.points_to_record.cbegin(); i != types.points_to_record.cend(); ++i)
- {
- for (auto j = types.points_to_record.cbegin(); j != types.points_to_record.cend(); ++j)
- {
- const_tree a = *i;
- const_tree b = *j;
- for (unsigned k = 0; k < type_playground::type_comparisons; k++)
- {
- type_playground::type_comparison_func_t comparison = type_playground::comparisons[k];
- const bool allowed_to_run = filter_comparisons_functions(comparison);
- if (!allowed_to_run) continue;
-
- const bool result = comparison(a, b);
- }
- }
- }
-}
-
-static void
-filter_out_types_in_set(ptrset_t &types)
-{
- // compare everything
- if (!flag_tp_types_compared) return;
-
- const size_t buffer_size = 1024;
- const size_t cli_length = strlen(flag_tp_comparison_functions);
- gcc_assert(buffer_size > cli_length);
- char whitelist[buffer_size];
- strcpy(whitelist, flag_tp_types_compared);
-
- bool name_allowed = false;
- for (auto it = types.points_to_record.cbegin(); it != types.points_to_record.cend(); name_allowed ? ++it : it = types.points_to_record.erase(it))
- {
- const_tree type = *it;
- std::string observed_name = get_type_identifier(type);
- char* saveptr = whitelist;
- char* expected_name = NULL;
- name_allowed = false;
-
- while (expected_name = strtok_r(saveptr, ",", &saveptr))
- {
- name_allowed |= strcmp(expected_name, observed_name.c_str()) == 0;
- }
- }
-
-}
-
static void
sanity_check_ptr_xor_complement(ptrset_t &types)
{
@@ -521,31 +127,11 @@ sanity_check_ptr_xor_complement(ptrset_t &types)
void
collect_types(ptrset_t &types)
{
- collect_types_from_globals(types);
-
- cgraph_node *node = NULL;
- long unsigned i = 0;
- FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node)
- {
- node->get_untransformed_body();
- collect_types_from_functions_with_gimple_body(node, types);
- // We still need to collect types from
- // the function signatures of functions without gimple bodies...
- }
+ GimpleTypeCollector collector;
+ collector.collect();
sanity_check_ptr_xor_complement(types);
}
-static TypeCollector _typeCollector;
-ptrset_t *TypeCollector::ptrset = NULL;
-static ExprCollector exprCollector;
-TypeCollector * ExprCollector::typeCollector = &_typeCollector;
-
-static void
-collect_types_from_expr(const_tree expr, ptrset_t &types)
-{
- exprCollector.walk(expr);
-}
-
static unsigned int
iphw_execute()
@@ -556,8 +142,6 @@ iphw_execute()
//ExprCollector::typeCollector = &_typeCollector;
TypeCollector::ptrset = &types;
collect_types(types);
- filter_out_types_in_set(types);
- compare_types_in_set(types);
return 0;
}