summaryrefslogtreecommitdiff
path: root/gcc/gimple-walker.c
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/gimple-walker.c')
-rw-r--r--gcc/gimple-walker.c136
1 files changed, 136 insertions, 0 deletions
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);