summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErick Ochoa <erick.ochoa@theobroma-systems.com>2020-05-06 12:16:17 +0200
committerErick Ochoa <erick.ochoa@theobroma-systems.com>2020-06-03 16:05:53 +0200
commit4d5d5a895a3f335cd7183d9c4c3f0807bcdca78e (patch)
tree0691ad80d65f76889ef5e0ebca14b557f93a254f
parent079632de497a58a78971b8fc35cf3a52148857d1 (diff)
experiment with alias
-rw-r--r--gcc/Makefile.in1
-rw-r--r--gcc/common.opt4
-rw-r--r--gcc/ipa-hello-world.c126
-rw-r--r--gcc/passes.def1
-rw-r--r--gcc/tree-pass.h1
5 files changed, 133 insertions, 0 deletions
diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index aab1dbba57b..98dfaffce25 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -1407,6 +1407,7 @@ OBJS = \
incpath.o \
init-regs.o \
internal-fn.o \
+ ipa-hello-world.o \
ipa-cp.o \
ipa-sra.o \
ipa-devirt.o \
diff --git a/gcc/common.opt b/gcc/common.opt
index 1b770bc11a9..3f852ed4cb8 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -3420,4 +3420,8 @@ fipa-ra
Common Report Var(flag_ipa_ra) Optimization
Use caller save register across calls if possible.
+fipa-hello-world
+Common Report Var(flag_ipa_hello_world) Optimization
+TBD
+
; This comment is to ensure we retain the blank line above.
diff --git a/gcc/ipa-hello-world.c b/gcc/ipa-hello-world.c
new file mode 100644
index 00000000000..00e276a4bd7
--- /dev/null
+++ b/gcc/ipa-hello-world.c
@@ -0,0 +1,126 @@
+#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"
+
+void inline
+log(const char* const fmt, ...)
+{
+ if (!dump_file) return;
+
+ va_list args;
+ va_start(args, fmt);
+ vfprintf(dump_file, fmt, args);
+ va_end(args);
+}
+
+static void
+alias_experiment_gimple_body(const cgraph_node *cnode)
+{
+ gcc_assert(cnode);
+
+ function *func = DECL_STRUCT_FUNCTION(cnode->decl);
+
+ // We are looking first into SSA becaues of
+ // this documentation...
+ // Points-to and escape analysis.
+ // Points-to analysis builds a set of constraints from the GIMPLE SSA IL
+ // representing all pointer operations and facts we do or do not know
+ // about pointers. Solving this set of constraints yields a conservatively
+ // correct solution for each pointer variable in the program (though we are
+ // only interested in SSA name pointers) as to what it may possibly point to.
+ // https://gcc.gnu.org/onlinedocs/gccint/Alias-analysis.html
+
+ size_t j = 0;
+ tree var_decl = NULL;
+ FOR_EACH_LOCAL_DECL(func, j, var_decl)
+ {
+ const_tree identifier_node = DECL_NAME(var_decl);
+ if (!identifier_node) continue;
+ const char* const identifier_pointer = IDENTIFIER_POINTER(identifier_node);
+ log("var_decl = %s\n", identifier_pointer);
+ if (POINTER_TYPE_P(TREE_TYPE(var_decl))) break;
+ }
+
+ size_t i = 0;
+ tree ssa_name = NULL;
+ push_cfun(func);
+ FOR_EACH_SSA_NAME(i, ssa_name, cfun)
+ {
+ struct ptr_info_def *pi = SSA_NAME_PTR_INFO(ssa_name);
+ if (!pi) continue;
+ log("i have a pi");
+ pt_solution_includes(&pi->pt, var_decl);
+ }
+ pop_cfun();
+
+
+}
+
+static unsigned int
+iphw_execute()
+{
+ cgraph_node *node = NULL;
+ FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node)
+ {
+ alias_experiment_gimple_body (node);
+ }
+ return 0;
+}
+
+namespace {
+const pass_data pass_data_ipa_hello_world =
+{
+ SIMPLE_IPA_PASS,
+ "hello-world",
+ OPTGROUP_NONE,
+ TV_NONE,
+ (PROP_cfg | PROP_ssa),
+ 0,
+ 0,
+ TODO_rebuild_alias,
+ 0,
+};
+
+class pass_ipa_hello_world : public simple_ipa_opt_pass
+{
+public:
+ pass_ipa_hello_world (gcc::context *ctx)
+ : simple_ipa_opt_pass(pass_data_ipa_hello_world, ctx)
+ {}
+
+ virtual bool gate(function*) { return flag_ipa_hello_world; }
+ virtual unsigned execute (function*) { return iphw_execute(); }
+};
+} // anon namespace
+
+simple_ipa_opt_pass*
+make_pass_ipa_hello_world (gcc::context *ctx)
+{
+ return new pass_ipa_hello_world (ctx);
+}
diff --git a/gcc/passes.def b/gcc/passes.def
index 92cbe587a8a..442e1e7b0e1 100644
--- a/gcc/passes.def
+++ b/gcc/passes.def
@@ -149,6 +149,7 @@ along with GCC; see the file COPYING3. If not see
NEXT_PASS (pass_ipa_profile);
NEXT_PASS (pass_ipa_icf);
NEXT_PASS (pass_ipa_devirt);
+ NEXT_PASS (pass_ipa_hello_world);
NEXT_PASS (pass_ipa_cp);
NEXT_PASS (pass_ipa_sra);
NEXT_PASS (pass_ipa_cdtor_merge);
diff --git a/gcc/tree-pass.h b/gcc/tree-pass.h
index 576b3f67434..30782a91c30 100644
--- a/gcc/tree-pass.h
+++ b/gcc/tree-pass.h
@@ -502,6 +502,7 @@ extern ipa_opt_pass_d *make_pass_ipa_fn_summary (gcc::context *ctxt);
extern ipa_opt_pass_d *make_pass_ipa_inline (gcc::context *ctxt);
extern simple_ipa_opt_pass *make_pass_ipa_free_lang_data (gcc::context *ctxt);
extern simple_ipa_opt_pass *make_pass_ipa_free_fn_summary (gcc::context *ctxt);
+extern simple_ipa_opt_pass *make_pass_ipa_hello_world (gcc::context *ctxt);
extern ipa_opt_pass_d *make_pass_ipa_cp (gcc::context *ctxt);
extern ipa_opt_pass_d *make_pass_ipa_sra (gcc::context *ctxt);
extern ipa_opt_pass_d *make_pass_ipa_icf (gcc::context *ctxt);