summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErick Ochoa <erick.ochoa@theobroma-systems.com>2020-06-08 16:11:12 +0200
committerErick Ochoa <erick.ochoa@theobroma-systems.com>2020-06-08 16:32:57 +0200
commit8417ba15c91443e5bfca945c3cf412523d2c1e0c (patch)
tree4566b66cd659fd29e7cad4ef53af3311d617f6b4
parent2881cf2cc09827a7cb499862352d848b2ef9b016 (diff)
Adds type-escape-analysis for testing
-rw-r--r--gcc/Makefile.in1
-rw-r--r--gcc/common.opt5
-rw-r--r--gcc/ipa-type-escape-analysis.c101
-rw-r--r--gcc/passes.def1
-rw-r--r--gcc/testsuite/gcc.dg/ipa/ipa-ea-00-collect-global-record-0.c6
-rw-r--r--gcc/testsuite/gcc.dg/ipa/ipa-ea-01-collect-global-pointers-to-record-0.c6
-rw-r--r--gcc/testsuite/gcc.dg/ipa/ipa-ea-02-collect-global-array-to-record-0.c6
-rw-r--r--gcc/testsuite/gcc.dg/ipa/ipa-ea-03-collect-nested-record-0.c7
-rw-r--r--gcc/tree-pass.h4
9 files changed, 124 insertions, 13 deletions
diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index 75f1086c74b..1f7a349a4c6 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -1408,6 +1408,7 @@ OBJS = \
init-regs.o \
internal-fn.o \
ipa-prototype.o \
+ ipa-type-escape-analysis.o \
type-walker.o \
expr-walker.o \
gimple-walker.o \
diff --git a/gcc/common.opt b/gcc/common.opt
index 19b0b255bdc..cdbaecf86ac 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -3453,4 +3453,9 @@ Common Joined Report Var(flag_tp_comparison_functions) Init(0)
fipa-prototype
Common Report Var(flag_ipa_prototype) Optimization
TBD
+
+fipa-type-escape-analysis
+Common Report Var(flag_ipa_type_escape_analysis) Optimization
+This flag is only used for debugging the type escape analysis
+
; This comment is to ensure we retain the blank line above.
diff --git a/gcc/ipa-type-escape-analysis.c b/gcc/ipa-type-escape-analysis.c
new file mode 100644
index 00000000000..be5f00f93de
--- /dev/null
+++ b/gcc/ipa-type-escape-analysis.c
@@ -0,0 +1,101 @@
+#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 "gimple-collector.hpp"
+
+
+static unsigned int iphw_execute();
+
+namespace {
+/* ==What is type-escape-analysis?==
+ * type-escape-analysis is a SIMPLE_IPA_PASS that performs no transformations.
+ * type-escape-analysis only performs analysis and outputs to a WPA dump file.
+ *
+ * ==Why should we run type-escape-analysis?==
+ * type-escape-analysis is useful to run unit tests in gcc.
+ * By having the type-escape-analysis execute during WPA we are able to use
+ * the dejagnu framework to see if an expected output matches the observed
+ * output in the wpa dump file.
+ *
+ * ==How do we use type-escape-analysis?==
+ * Compile with
+ * -flto -fipa-type-escape-analysis -fdump-ipa-type-escape-analysis
+ *
+ * To use type-escape-analysis in tests use the following lines
+ * { dg-do link }
+ * { dg-options "-flto -fipa-type-escape-analysis -fdump-ipa-type-escape-analysis" }
+ * C code to test...
+ * { dg-final { scan-wpa-ipa-dump "regex" "type-escape-analysis" } }
+ *
+ * ==TODO==
+ * At the moment, the tests are not set up to work with the current framework,
+ * so I will need to update them in the following day.
+ */
+const pass_data pass_data_ipa_type_escape_analysis =
+{
+ SIMPLE_IPA_PASS,
+ "type-escape-analysis",
+ OPTGROUP_NONE,
+ TV_NONE,
+ (PROP_cfg | PROP_ssa),
+ 0,
+ 0,
+ 0,
+ 0,
+};
+
+class pass_ipa_type_escape_analysis : public simple_ipa_opt_pass
+{
+public:
+ pass_ipa_type_escape_analysis (gcc::context *ctx)
+ : simple_ipa_opt_pass(pass_data_ipa_type_escape_analysis, ctx)
+ {}
+
+ virtual bool gate(function*) { return flag_ipa_type_escape_analysis; }
+ virtual unsigned execute (function*) { return iphw_execute(); }
+};
+} // anon namespace
+
+simple_ipa_opt_pass*
+make_pass_ipa_type_escape_analysis (gcc::context *ctx)
+{
+ return new pass_ipa_type_escape_analysis (ctx);
+}
+
+static void collect_types();
+
+static unsigned int
+iphw_execute()
+{
+ collect_types();
+ return 0;
+}
+
+static void
+collect_types()
+{
+ GimpleTypeCollector collector;
+ collector.walk();
+ collector.print_collected();
+}
diff --git a/gcc/passes.def b/gcc/passes.def
index 4c8391281f2..3060f267c66 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_type_escape_analysis);
NEXT_PASS (pass_ipa_cp);
NEXT_PASS (pass_ipa_sra);
NEXT_PASS (pass_ipa_cdtor_merge);
diff --git a/gcc/testsuite/gcc.dg/ipa/ipa-ea-00-collect-global-record-0.c b/gcc/testsuite/gcc.dg/ipa/ipa-ea-00-collect-global-record-0.c
index f9c4af5d6cf..9d096b3747f 100644
--- a/gcc/testsuite/gcc.dg/ipa/ipa-ea-00-collect-global-record-0.c
+++ b/gcc/testsuite/gcc.dg/ipa/ipa-ea-00-collect-global-record-0.c
@@ -7,7 +7,9 @@ struct astruct_s astruct;
int
main ()
{
- astruct.a = 0;
+ astruct.a = 0;
}
-/* { dg-final { scan-ipa-dump "collected,astruct_s" "type-escape-analysis" } } */
+// Please note that braces and semicollons are replaced with dots in order
+// to parse correctly
+/* { dg-final { scan-ipa-dump "collected: record astruct_s .boolean_type a.boolean_type b.boolean_type c.." "type-escape-analysis" } } */
diff --git a/gcc/testsuite/gcc.dg/ipa/ipa-ea-01-collect-global-pointers-to-record-0.c b/gcc/testsuite/gcc.dg/ipa/ipa-ea-01-collect-global-pointers-to-record-0.c
index e1147844f18..94cd66d8ef7 100644
--- a/gcc/testsuite/gcc.dg/ipa/ipa-ea-01-collect-global-pointers-to-record-0.c
+++ b/gcc/testsuite/gcc.dg/ipa/ipa-ea-01-collect-global-pointers-to-record-0.c
@@ -12,5 +12,7 @@ main ()
astruct = NULL;
}
-/* { dg-final { scan-ipa-dump "collected,astruct_s" "type-escape-analysis" } } */
-/* { dg-final { scan-ipa-dump "collected,astruct_s*" "type-escape-analysis" } } */
+// This is for the structure
+/* { dg-final { scan-ipa-dump "collected: record astruct_s .boolean_type a.boolean_type b.boolean_type c.." "type-escape-analysis" } } */
+// This one has an extra dot to mark the * for the pointer
+/* { dg-final { scan-ipa-dump "collected: record astruct_s .boolean_type a.boolean_type b.boolean_type c..." "type-escape-analysis" } } */
diff --git a/gcc/testsuite/gcc.dg/ipa/ipa-ea-02-collect-global-array-to-record-0.c b/gcc/testsuite/gcc.dg/ipa/ipa-ea-02-collect-global-array-to-record-0.c
index aed61d4ef69..3cacc4a3838 100644
--- a/gcc/testsuite/gcc.dg/ipa/ipa-ea-02-collect-global-array-to-record-0.c
+++ b/gcc/testsuite/gcc.dg/ipa/ipa-ea-02-collect-global-array-to-record-0.c
@@ -12,5 +12,7 @@ main ()
struct astruct_s another = astruct[0];
}
-/* { dg-final { scan-ipa-dump "collected,astruct_s" "type-escape-analysis" } } */
-/* { dg-final { scan-ipa-dump "collected,astruct_s[]" "type-escape-analysis" } } */
+// This one is for the structure
+/* { dg-final { scan-ipa-dump "collected: record astruct_s .boolean_type a.boolean_type b.boolean_type c.." "type-escape-analysis" } } */
+// This one is for the array. That's why it has two dots at the end
+/* { dg-final { scan-ipa-dump "collected: record astruct_s .boolean_type a.boolean_type b.boolean_type c...." "type-escape-analysis" } } */
diff --git a/gcc/testsuite/gcc.dg/ipa/ipa-ea-03-collect-nested-record-0.c b/gcc/testsuite/gcc.dg/ipa/ipa-ea-03-collect-nested-record-0.c
index e300b0b598a..2feb88a1a60 100644
--- a/gcc/testsuite/gcc.dg/ipa/ipa-ea-03-collect-nested-record-0.c
+++ b/gcc/testsuite/gcc.dg/ipa/ipa-ea-03-collect-nested-record-0.c
@@ -4,7 +4,6 @@
#include <stddef.h>
struct astruct_s { _Bool a; _Bool b; _Bool c;};
-struct astruct_s astruct[2];
struct outer_struct { _Bool d; struct astruct_s a; };
struct outer_struct bstruct;
@@ -12,9 +11,7 @@ int
main ()
{
bstruct.d = 0;
- struct astruct_s another = astruct[0];
}
-/* { dg-final { scan-ipa-dump "collected,astruct_s" "type-escape-analysis" } } */
-/* { dg-final { scan-ipa-dump "collected,outer_struct" "type-escape-analysis" } } */
-/* { dg-final { scan-ipa-dump "collected,astruct_s[]" "type-escape-analysis" } } */
+// We only care about collecting the inner struct for this test
+/* { dg-final { scan-ipa-dump "collected: record astruct_s .boolean_type a.boolean_type b.boolean_type c.." "type-escape-analysis" } } */
diff --git a/gcc/tree-pass.h b/gcc/tree-pass.h
index ddf1edb9c90..24f7b7d4f5c 100644
--- a/gcc/tree-pass.h
+++ b/gcc/tree-pass.h
@@ -510,8 +510,8 @@ extern ipa_opt_pass_d *make_pass_ipa_devirt (gcc::context *ctxt);
extern ipa_opt_pass_d *make_pass_ipa_reference (gcc::context *ctxt);
extern ipa_opt_pass_d *make_pass_ipa_hsa (gcc::context *ctxt);
extern ipa_opt_pass_d *make_pass_ipa_pure_const (gcc::context *ctxt);
-extern simple_ipa_opt_pass *
-make_pass_ipa_structure_reorg (gcc::context *ctxt);
+extern simple_ipa_opt_pass *make_pass_ipa_structure_reorg (gcc::context *ctxt);
+extern simple_ipa_opt_pass *make_pass_ipa_type_escape_analysis (gcc::context *ctxt);
extern simple_ipa_opt_pass *make_pass_ipa_pta (gcc::context *ctxt);
extern simple_ipa_opt_pass *make_pass_ipa_tm (gcc::context *ctxt);
extern simple_ipa_opt_pass *make_pass_target_clone (gcc::context *ctxt);