summaryrefslogtreecommitdiff
path: root/gcc/gimple-collector.c
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 /gcc/gimple-collector.c
parentcf126175de70a7333d321f80a83e495767490222 (diff)
collector and walker
Diffstat (limited to 'gcc/gimple-collector.c')
-rw-r--r--gcc/gimple-collector.c201
1 files changed, 201 insertions, 0 deletions
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);
+}