From bd73fc9f1e941eb5d64fc49c14bc379a5d4672fc Mon Sep 17 00:00:00 2001 From: Erick Ochoa Date: Tue, 23 Jun 2020 12:45:20 +0200 Subject: lots of logging but mcf training had no runtime errors --- gcc/expr-rewriter.c | 38 ++++++++++++++++++++++++++++---- gcc/gimple-rewriter.c | 31 +++++++++++++++++++++++++- gcc/gimple-walker.c | 1 + gcc/ipa-type-escape-analysis.c | 50 +++++++++++++++++++++++++++++++++++++++++- gcc/type-reconstructor.c | 5 +++-- 5 files changed, 117 insertions(+), 8 deletions(-) diff --git a/gcc/expr-rewriter.c b/gcc/expr-rewriter.c index 746c23b6c0b..892b7e6a415 100644 --- a/gcc/expr-rewriter.c +++ b/gcc/expr-rewriter.c @@ -99,6 +99,11 @@ ExprTypeRewriter::_walk_MEM_REF_post(const_tree e) void ExprTypeRewriter::_walk_SSA_NAME_post(const_tree t) { + // Here, we need to find out + log("we are in expr-rewriter SSA_NAME_post\n"); + TypeStringifier stringifier; + std::string name = stringifier.stringify(TREE_TYPE(t)); + log("%s\n", name.c_str()); } //TODO: @@ -198,6 +203,8 @@ ExprTypeRewriter::handle_pointer_arithmetic_nonconstant(gimple *s, tree op_0, tr // _3 = &array + _2; < -- this is where we are //enum tree_code code = TREE_CODE(op_1); //assert_is_type(op_1, SSA_NAME); + tree new_type = TREE_TYPE(gimple_assign_lhs(s)); + gimple *def_for_variable = SSA_NAME_DEF_STMT(op_1); // It is possible that we are in a negation statement... @@ -229,7 +236,8 @@ ExprTypeRewriter::handle_pointer_arithmetic_nonconstant(gimple *s, tree op_0, tr // op_0 is the variable // That means that the reorg_type is - tree reorg_type_tree = TREE_TYPE(op_0); + // The truth is that op_0 might not have the correct type + tree reorg_type_tree = new_type; tree reorg_inner_type = TREE_TYPE(reorg_type_tree); tree reorg_type_size_tree = TYPE_SIZE_UNIT(reorg_inner_type); int reorg_type_size_int = tree_to_shwi(reorg_type_size_tree); @@ -345,12 +353,34 @@ ExprTypeRewriter::_walk_post(const_tree e) const enum tree_code code = TREE_CODE(e); tree r_t = _map[t]; TREE_TYPE((tree)e) = r_t; - tree type_main_variant = TYPE_MAIN_VARIANT(TREE_TYPE(e)); - const bool do_we_have_mv_in_map = _map.find(type_main_variant) != _map.end(); + + return; + if (code != MEM_REF) return; + + TypeStringifier stringifier; + std::string name = stringifier.stringify(r_t); + tree m = TYPE_MAIN_VARIANT(r_t); + std::string name_m = stringifier.stringify(m); + const bool main_variant = TYPE_MAIN_VARIANT(r_t) == r_t; + log("main: %s\n", name_m.c_str()); + log("we are in memref: %s is_main_variant %s\n", name.c_str(), main_variant ? "t" : "f"); + tree type_size = TYPE_SIZE(r_t); + log("type size 1 %s?", type_size ? "t" : "f"); + if (!type_size) TYPE_SIZE(r_t) = TYPE_SIZE(m); + log("type size 2 %s?", TYPE_SIZE(r_t) ? "t" : "f"); + if (!TYPE_SIZE(r_t)) layout_type(r_t); + log("type size 3 %s?", TYPE_SIZE(r_t) ? "t" : "f"); + // still no type_size + gcc_assert(TYPE_SIZE(r_t)); + const enum tree_code cc = TREE_CODE(TYPE_SIZE(r_t)); + log("%s\n", get_tree_code_name(cc)); + + //tree type_main_variant = TYPE_MAIN_VARIANT(TREE_TYPE(e)); + //const bool do_we_have_mv_in_map = _map.find(type_main_variant) != _map.end(); // TODO: Fix this hack // We need to make sure that the type main variant is already good here... - TYPE_MAIN_VARIANT(TREE_TYPE(e)) = do_we_have_mv_in_map ? _map[type_main_variant] : TYPE_MAIN_VARIANT(TREE_TYPE(e)); + //TYPE_MAIN_VARIANT(TREE_TYPE(e)) = do_we_have_mv_in_map ? _map[type_main_variant] : TYPE_MAIN_VARIANT(TREE_TYPE(e)); } diff --git a/gcc/gimple-rewriter.c b/gcc/gimple-rewriter.c index 61fe1e9f0eb..31fcb74ed86 100644 --- a/gcc/gimple-rewriter.c +++ b/gcc/gimple-rewriter.c @@ -100,11 +100,22 @@ GimpleTypeRewriter::handle_pointer_arithmetic(gimple *s) tree op_0 = gimple_assign_rhs1(s); tree op_1 = gimple_assign_rhs2(s); + tree lhs = gimple_assign_lhs(s); tree op_0_t = TREE_TYPE(op_0); tree op_1_t = TREE_TYPE(op_1); + tree lhs_t = TREE_TYPE(lhs); const bool is_op_0_t_interesting = exprTypeRewriter.is_interesting_type(op_0_t); const bool is_op_1_t_interesting = exprTypeRewriter.is_interesting_type(op_1_t); - bool is_interesting_case = is_op_0_t_interesting || is_op_1_t_interesting; + const bool is_lhs_t_interesting = exprTypeRewriter.is_interesting_type(lhs_t); + bool is_interesting_case = is_op_0_t_interesting || is_op_1_t_interesting || is_lhs_t_interesting; + TypeStringifier stringifier; + std::string name_0 = stringifier.stringify(op_0_t); + std::string name_1 = stringifier.stringify(op_1_t); + std::string name_l = stringifier.stringify(lhs_t); + log("is interesting case %s\n", is_interesting_case ? "t" : "f"); + log("op_0 %s\n", name_0.c_str()); + log("op_1 %s\n", name_1.c_str()); + log("lhs_t%s\n", name_l.c_str()); if (!is_interesting_case) return; const enum tree_code op_1_code = TREE_CODE(op_1); @@ -177,7 +188,11 @@ GimpleTypeRewriter::_walk_pre(gassign *s) break; } + const enum tree_code e_code = gimple_expr_code(s); + log("is this the statment i'm looking for? %s\n", get_tree_code_name(e_code)); + print_gimple_stmt(dump_file, s, 0); + log("\n"); switch (e_code) { case POINTER_PLUS_EXPR: @@ -197,9 +212,23 @@ GimpleTypeRewriter::_walk_pre(gassign *s) log("%s\n", name.c_str()); } break; + case MULT_EXPR: + { + TypeStringifier stringifier; + tree op1 = gimple_assign_rhs2(s); + tree op2 = gimple_assign_rhs1(s); + tree op1_t = TREE_TYPE(op1); + tree op2_t = TREE_TYPE(op2); + std::string op1_s = stringifier.stringify(op1_t); + std::string op2_s = stringifier.stringify(op2_t); + log("multiplication\n"); + log("%s * %s\n", op1_s.c_str(), op2_s.c_str()); + } break; default: + { log("missing %s\n", get_tree_code_name(e_code)); + } break; } diff --git a/gcc/gimple-walker.c b/gcc/gimple-walker.c index 2755dcdab98..b1cf0c3a51d 100644 --- a/gcc/gimple-walker.c +++ b/gcc/gimple-walker.c @@ -242,6 +242,7 @@ GimpleWalker::_walk(gimple *stmt) switch (code) { case GIMPLE_PREDICT: return; + case GIMPLE_DEBUG: return; default: break; } const char* name = gimple_code_name[code]; diff --git a/gcc/ipa-type-escape-analysis.c b/gcc/ipa-type-escape-analysis.c index 8b9ff5bbee1..d69b3368b7f 100644 --- a/gcc/ipa-type-escape-analysis.c +++ b/gcc/ipa-type-escape-analysis.c @@ -273,13 +273,34 @@ collect_types() // Otherwise, it will lead to difficulties in the future since // we could be modifying many different types. // So we have to make sure that we are only modifying the types of interest. + for (auto i = types.points_to_record.cbegin(), e = types.points_to_record.cend(); i != e; ++i) + { + const_tree record = *i; + std::string name_from = stringifier.stringify(TYPE_MAIN_VARIANT(record)); + bool points_to_record = false; + const_tree tt = record; + + //TODO: + //This is our little hack to make sure that we are + //only modifying types which are of interest. + //However, we really shouldn't. + //Let's clean the input to reconstructor.walk + while (TREE_TYPE(tt)) { tt = TREE_TYPE(tt); }; + points_to_record = TREE_CODE(tt) == RECORD_TYPE; + if (!points_to_record) continue; + + bool in_map = record_field_offset_map.find(tt) != record_field_offset_map.end(); + if (!in_map) continue; + // We need to walk over the type main variant first... + reconstructor.walk(TYPE_MAIN_VARIANT(record)); + log("walking main variant %s\n", name_from.c_str()); + } for (auto i = types.points_to_record.cbegin(), e = types.points_to_record.cend(); i != e; ++i) { const_tree record = *i; std::string name_from = stringifier.stringify(record); - log("%s\n", name_from.c_str()); bool points_to_record = false; const_tree tt = record; @@ -294,12 +315,39 @@ collect_types() bool in_map = record_field_offset_map.find(tt) != record_field_offset_map.end(); if (!in_map) continue; + + // We need to walk over the type main variant first... reconstructor.walk(record); + log("walking non main%s\n", name_from.c_str()); } + TypeReconstructor::reorg_record_map_t map = reconstructor.get_map(); TypeReconstructor::reorg_field_map_t field_map = reconstructor.get_field_map(); + for (auto i = map.cbegin(), e = map.cend(); i != e; ++i) + { + const_tree o_record = i->first; + tree r_record = i->second; + tree m_record = TYPE_MAIN_VARIANT(r_record); + std::string name_from = stringifier.stringify(o_record); + std::string name_to = stringifier.stringify(r_record); + std::string name_to_mv = stringifier.stringify(m_record); + + log("map f: %s\n", name_from.c_str()); + log("map t: %s\n", name_to.c_str()); + log("map m: %s\n", name_to_mv.c_str()); + bool in_map = map.find(m_record) != map.end(); + if (!in_map) continue; + tree mm_record = map[m_record]; + std::string name_to_mmv = stringifier.stringify(mm_record); + log("map m2: %s\n", name_to_mmv.c_str()); + // TODO: This is a hack... + TYPE_MAIN_VARIANT(r_record) = mm_record; + // Do we need to layout the type again? + } + + GimpleTypeRewriter rewriter(map, field_map); rewriter.walk(); rewriter._rewrite_function_decl(); diff --git a/gcc/type-reconstructor.c b/gcc/type-reconstructor.c index 34f793f36b5..5adb6220b5d 100644 --- a/gcc/type-reconstructor.c +++ b/gcc/type-reconstructor.c @@ -217,8 +217,8 @@ TypeReconstructor::_walk_POINTER_TYPE_post(const_tree t) TREE_TYPE(copy) = is_modified ? _reorg_map[TREE_TYPE(t)] : TREE_TYPE(copy); TYPE_NAME(copy) = is_modified ? get_new_identifier(copy) : TYPE_NAME(copy); // This is useful so that we go again through type layout - TYPE_SIZE(copy) = is_modified ? NULL : TYPE_SIZE(copy); - if (is_modified) layout_type(copy); + //TYPE_SIZE(copy) = is_modified ? NULL : TYPE_SIZE(copy); + //if (is_modified) layout_type(copy); _reorg_map[t] = is_modified ? copy : (tree)t; } @@ -303,6 +303,7 @@ TypeReconstructor::_walk_RECORD_TYPE_post(const_tree t) TYPE_NAME(copy_variant) = get_new_identifier(copy); TYPE_SIZE(copy_variant) = NULL; TYPE_MAIN_VARIANT(copy_variant) = main_reorg; + TYPE_SIZE(main_reorg) = NULL; layout_type(copy_variant); _reorg_map[t] = copy_variant; } else { -- cgit v1.2.3