diff options
author | Erick Ochoa <erick.ochoa@theobroma-systems.com> | 2020-10-30 14:16:37 +0100 |
---|---|---|
committer | Erick Ochoa <erick.ochoa@theobroma-systems.com> | 2020-10-30 14:16:37 +0100 |
commit | 8e7fbfc3cb9ce35bd8fd06cc20fd22b579d26e93 (patch) | |
tree | a7db299e5cd4389413ceaadd7b411b1ffe9a647e | |
parent | 95ad1ab7abc363bf975610b0bafcd31ddb9d8578 (diff) |
making sure gcc builds
49 files changed, 23 insertions, 5050 deletions
@@ -7,12 +7,7 @@ installdir=${1:-"gcc-inst"} mkdir -p $HOME/code/gcc-build/ mkdir -p $HOME/code/${installdir}/ pushd $HOME/code/gcc-build/ -if find . -mindepth 1 -print -quit 2>/dev/null | grep -q . ; then - echo "not empty?" -else - $OLDPWD/configure --disable-bootstrap --disable-libsanitizer --enable-__cxa_atexit --enable-shared --disable-libsanitizer --enable-languages=c,c++,fortran --enable-lto --enable-gold --enable-linker-build-id --with-cpu-emag --prefix="$HOME/code/${installdir}/" -fi - +$OLDPWD/configure --disable-bootstrap --disable-libsanitizer --enable-__cxa_atexit --enable-shared --disable-libsanitizer --enable-languages=c,c++,fortran --enable-lto --enable-gold --enable-linker-build-id --with-cpu-emag --prefix="$HOME/code/${installdir}/" make -j `nproc` make install -j `nproc` make check-gcc RUNTESTFLAGS="ipa.exp" diff --git a/gcc/collect-types.c b/gcc/collect-types.c deleted file mode 100644 index f4ad113b56f..00000000000 --- a/gcc/collect-types.c +++ /dev/null @@ -1,86 +0,0 @@ -#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 "types-inlines.h" -#include "type-stringifier.hpp" -#include <set> - -#include "collect-types.h" - - -void -points_to_record_sets_s::insert(const_tree type, bool in_points_to_record) -{ - gcc_assert(type); - this->universe.insert(type); - in_points_to_record ? this->points_to_record.insert(type) : this->complement.insert(type); - const bool in_points_to_set = this->in_points_to_record(type); - const bool in_complement = this->in_complement(type); - const bool _xor = in_points_to_set != in_complement; - // sanity check... - gcc_assert(_xor); -} - -bool -points_to_record_sets_s::in_universe(const_tree type) const -{ - gcc_assert(type); - const bool seen_before = this->universe.find(type) != this->universe.end(); - return seen_before; -} - -bool -points_to_record_sets_s::in_points_to_record(const_tree type) const -{ - gcc_assert(type); - const bool seen_before = this->points_to_record.find(type) != this->points_to_record.end(); - return seen_before; -} - -bool -points_to_record_sets_s::in_complement(const_tree type) const -{ - gcc_assert(type); - const bool seen_before = this->complement.find(type) != this->complement.end(); - return seen_before; -} - -void -points_to_record_sets_s::print_in_points_to_record() const -{ - TypeStringifier stringifier; - for (auto i = this->points_to_record.cbegin(), e = this->points_to_record.cend(); i != e; ++i) - { - const_tree t = *i; - gcc_assert(t); - std::string name = stringifier.stringify(t); - log("collected: %s\n", name.c_str()); - } -} diff --git a/gcc/collect-types.h b/gcc/collect-types.h deleted file mode 100644 index a2439557332..00000000000 --- a/gcc/collect-types.h +++ /dev/null @@ -1,21 +0,0 @@ -#pragma once - -#include "tree.h" -#include <set> - - -typedef std::set<const_tree> typeset; -struct points_to_record_sets_s { - typeset universe; - typeset points_to_record; - typeset complement; - typeset escaping; - typeset non_escaping; - bool in_universe(const_tree) const; - bool in_points_to_record(const_tree) const; - bool in_complement(const_tree) const; - void insert(const_tree, bool); - void print_in_points_to_record() const; -}; - -typedef struct points_to_record_sets_s ptrset_t; diff --git a/gcc/common.opt b/gcc/common.opt index 7eb8150a258..902065d2b04 100644 --- a/gcc/common.opt +++ b/gcc/common.opt @@ -1877,10 +1877,6 @@ fipa-dead-field-eliminate Common Report Var(flag_ipa_dead_field_eliminate) Init(0) Optimization Structure reorganization optimization, dead field elimination. -fipa-field-reorder -Common Report Var(flag_ipa_field_reorder) Init(0) Optimization -Structure reorganization optimization, field reordering. - fipa-instance-interleave Common Report Var(flag_ipa_instance_interleave) Init(0) Optimization Structure reorganization optimization, instance interleaving. @@ -3492,4 +3488,20 @@ fipa-field-reorder Common Report Var(flag_ipa_field_reorder) Optimization Reorder fields. +fipa-typelist-struct= +Common Joined Report Var(flag_ipa_typelist_struct) Init(0) +TBD + +fipa-typelist-field= +Common Joined Report Var(flag_ipa_typelist_field) Init(0) +TBD + +ftp-types-compared= +Common Joined Report Var(flag_tp_types_compared) Init(0) +TBD + +ftp-comparison-functions= +Common Joined Report Var(flag_tp_comparison_functions) Init(0) +TBD + ; This comment is to ensure we retain the blank line above. diff --git a/gcc/expr-accessor.c b/gcc/expr-accessor.c deleted file mode 100644 index 6169f6d6b52..00000000000 --- a/gcc/expr-accessor.c +++ /dev/null @@ -1,106 +0,0 @@ -#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" // needed for gimple-iterator.h -#include "gimple-iterator.h" -#include "gimple-ssa.h" -#include <stdbool.h> - - -#include "types-inlines.h" -#include "type-stringifier.hpp" -#include "expr-accessor.hpp" -#include "expr-walker.hpp" -#include "type-accessor.hpp" - -void -ExprAccessor::add_all_fields_in_struct(const_tree t) -{ - // Inefficient - TypeAccessor typeAccessor(record_field_map); - typeAccessor.walk(t); -} - -void -ExprAccessor::_walk_pre(const_tree e) -{ - const_tree t = TREE_TYPE(e); - add_all_fields_in_struct(t); -} - -void -ExprAccessor::update(const_tree e, unsigned access) -{ - _access = access; - walk(e); -} - -void -ExprAccessor::_walk_COMPONENT_REF_pre(const_tree e) -{ - assert_is_type(e, COMPONENT_REF); - const_tree op0 = TREE_OPERAND(e, 0); - gcc_assert(op0); - const_tree op0_t = TREE_TYPE(op0); - gcc_assert(op0_t); - // op0_t can either be a RECORD_TYPE or a UNION_TYPE - const enum tree_code code = TREE_CODE(op0_t); - const bool is_record = RECORD_TYPE == code; - const bool is_union = UNION_TYPE == code; - const bool valid = is_record != is_union; - gcc_assert(valid); - - const_tree op1 = TREE_OPERAND(e, 1); - assert_is_type(op1, FIELD_DECL); - const bool record_already_in_map = record_field_map.find(op0_t) != record_field_map.end(); - field_access_map_t field_map; - field_map = record_already_in_map ? record_field_map[op0_t] : field_map; - const bool field_already_in_map = field_map.find(op1) != field_map.end(); - unsigned prev_access = field_already_in_map ? field_map[op1] : Empty; - - prev_access |= _access; - field_map[op1] = prev_access; - add_all_fields_in_struct(op0_t); - record_field_map[op0_t] = field_map; -} - -void -ExprAccessor::print_accesses() -{ - for (auto i = record_field_map.cbegin(), e = record_field_map.cend(); i != e; ++i) - { - const_tree record = i->first; - field_access_map_t field_map = i->second; - for (auto j = field_map.cbegin(), f = field_map.cend(); j != f; ++j) - { - const_tree field = j->first; - const std::string name_r = TypeStringifier::get_type_identifier(record); - const std::string name_f = TypeStringifier::get_field_identifier(field); - unsigned access = j->second; - log("%s.%s = 0x%04x\n", name_r.c_str(), name_f.c_str(), access); - } - } -} diff --git a/gcc/expr-accessor.hpp b/gcc/expr-accessor.hpp deleted file mode 100644 index bdc43e46aa7..00000000000 --- a/gcc/expr-accessor.hpp +++ /dev/null @@ -1,31 +0,0 @@ -#pragma once - -#include "ipa-prototype.h" -#include "expr-walker.hpp" -#include "type-escaper.hpp" -#include "collect-types.h" -#include "type-accessor.hpp" -#include <tuple> -#include <map> - -constexpr unsigned Empty = 0x0u; -constexpr unsigned Read = 0x01u; -constexpr unsigned Write = 0x02u; - -typedef std::map<const_tree, unsigned> field_access_map_t; -typedef std::map<const_tree, field_access_map_t> record_field_map_t; - -class ExprAccessor : public ExprWalker -{ -public: - ExprAccessor() {}; - void update(const_tree e, unsigned a); - void print_accesses(); - void add_all_fields_in_struct(const_tree t); - record_field_map_t get_map() { return record_field_map; }; -private: - unsigned _access; - record_field_map_t record_field_map; - virtual void _walk_COMPONENT_REF_pre(const_tree e); - virtual void _walk_pre(const_tree t); -}; diff --git a/gcc/expr-escaper.c b/gcc/expr-escaper.c deleted file mode 100644 index a7750feb9e7..00000000000 --- a/gcc/expr-escaper.c +++ /dev/null @@ -1,63 +0,0 @@ -#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" // needed for gimple-iterator.h -#include "gimple-iterator.h" -#include "gimple-ssa.h" -#include <stdbool.h> - - -#include "types-inlines.h" -#include "type-escaper.hpp" -#include "expr-escaper.hpp" - - -void -ExprEscaper::update(const_tree t, Reason r) -{ - gcc_assert(t); - _r = r; - walk(t); -} - -void -ExprEscaper::_walk_pre(const_tree e) -{ - const_tree t = TREE_TYPE(e); - gcc_assert(t); - typeEscaper.update(t, _r); -} - -void -ExprEscaper::_walk_CONSTRUCTOR_pre(const_tree e) -{ - if (TREE_CLOBBER_P(e)) return; - - _r.global_is_visible = true; // just for now... - const_tree t = TREE_TYPE(e); - typeEscaper.update(t, _r); -} - diff --git a/gcc/expr-escaper.hpp b/gcc/expr-escaper.hpp deleted file mode 100644 index c58e1830133..00000000000 --- a/gcc/expr-escaper.hpp +++ /dev/null @@ -1,23 +0,0 @@ -#pragma once - -#include "ipa-prototype.h" -#include "expr-walker.hpp" -#include "type-escaper.hpp" -#include "collect-types.h" - -class ExprEscaper : public ExprWalker -{ -public: - TypeEscaper typeEscaper; - ExprEscaper(ptrset_t &types) : typeEscaper(types) {}; - ptrset_t get_sets() { return typeEscaper.get_sets(); }; - void update(const_tree t, Reason r); - void update_single_level(const_tree t, Reason r) { typeEscaper.update_single_level(TREE_TYPE(t), r); }; - void print_reasons() { typeEscaper.print_reasons(); }; -private: - Reason _r; - virtual void _walk_pre(const_tree e); - virtual void _walk_CONSTRUCTOR_pre(const_tree e); -}; - - diff --git a/gcc/expr-rewriter.c b/gcc/expr-rewriter.c deleted file mode 100644 index 66295d32c74..00000000000 --- a/gcc/expr-rewriter.c +++ /dev/null @@ -1,432 +0,0 @@ -#include "config.h" -#include "system.h" -#include "coretypes.h" -#include "tree.h" -#include "options.h" -#include "cgraph.h" -#include "tree-pass.h" -#include "tree-cfg.h" -#include "tree-pretty-print.h" -#include "gimple-pretty-print.h" -#include "stringpool.h" //get_identifier -#include "basic-block.h" //needed for gimple.h -#include "function.h" //needed for gimple.h -#include "gimple.h" -#include "cfg.h" // needed for gimple-iterator.h -#include "gimple-iterator.h" -#include "stor-layout.h" // layout_type -#include "fold-const.h" //build_fold_addr_expr -#include "gimple-ssa.h" // update_stmt -#include "attribs.h" // decl_attributes -#include "gimplify.h" //unshare_expr -#include "value-range.h" // make_ssa_name dependency -#include "tree-ssanames.h" // make_ssa_name -#include "ssa.h" -#include "tree-into-ssa.h" -#include "expr-rewriter.hpp" -#include "type-stringifier.hpp" -#include <string> -#include <map> - -void -ExprTypeRewriter::_walk_PARM_DECL_post(const_tree t) -{ - tree temp = (tree)(t); - tree ttemp = TREE_TYPE(temp); - const bool is_interesting = is_interesting_type(ttemp); - if (!is_interesting) return; - relayout_decl(temp); -} - -void -ExprTypeRewriter::_walk_FUNCTION_DECL_post(const_tree t) -{ - tree fn_type = TREE_TYPE(t); - gcc_assert(t); - tree ret_type = TREE_TYPE(fn_type); - if (!ret_type) return; - - TypeStringifier stringifier; - std::string name = stringifier.stringify(ret_type); - // WARNING: You cannot use is interesting here because you haven't - // changed the return type - // This is because the return type is not an expression. - // Therefore it is awkward to do this in the expr-walker... - // const bool is_interesting = is_interesting_type(ret_type); - const bool is_interesting = _map.find(ret_type) != _map.end(); - if (!is_interesting) return; - - tree r_t = _map[ret_type]; - TREE_TYPE(fn_type) = r_t; -} - -void -ExprTypeRewriter::_walk_MEM_REF_post(const_tree e) -{ - // The second operand is a pointer constant. - // Its type specifying the type used for type based alias analysis - tree op1 = TREE_OPERAND(e, 1); - gcc_assert(TREE_CODE(op1) == INTEGER_CST); - - tree t = TREE_TYPE(op1); - const bool already_rewritten = is_interesting_type(t); - - // This is where we do the transformation - if (!already_rewritten) return; - - const_tree old_type = _imap[t]; - assert_is_type(old_type, POINTER_TYPE); - const_tree old_base_type = TREE_TYPE(old_type); - tree old_type_size_tree = TYPE_SIZE_UNIT(old_base_type); - int old_type_size_int = tree_to_shwi(old_type_size_tree); - - tree reorg_type = t; - assert_is_type(reorg_type, POINTER_TYPE); - tree reorg_base_type = TREE_TYPE(reorg_type); - tree reorg_type_size_tree = TYPE_SIZE_UNIT(reorg_base_type); - int reorg_type_size_int = tree_to_shwi(reorg_type_size_tree); - - // Let's find out what is the previous offset - int old_offset = tree_to_uhwi(op1); - int remainder = old_offset % old_type_size_int; - - int new_offset = old_offset / old_type_size_int * reorg_type_size_int + remainder; - - tree new_offset_tree = build_int_cst(TREE_TYPE(op1), new_offset); - TREE_OPERAND(e, 1) = new_offset_tree; -} - -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: -//Change name of this method... -bool -ExprTypeRewriter::is_interesting_type(tree t) -{ - const bool in_imap = _imap.find(t) != _imap.end(); - bool interesting = in_imap; - if (!interesting) return false; - - tree possibly_copy = (tree)_imap[t]; - const bool is_copy = possibly_copy == t; - interesting = !is_copy; - if (!interesting) return false; - - // Let's just do a quick sanity check - tree interesting_type = t; - const bool has_valid_suffix = strstr(TypeStringifier::get_type_identifier(interesting_type).c_str(), ".reorg"); - gcc_assert(has_valid_suffix); - return true; -} - -void -ExprTypeRewriter::handle_pointer_arithmetic_diff(gimple *s, tree op_0, tree op_1) -{ - - // lhs = op0 - op1 // <-- we are here - // ... SNIP ... - // var = lhs / [ex] old_struct_size // <-- we want to be here - // - // Let's explore the uses of lhs - tree lhs = gimple_assign_lhs(s); - - tree reorg_type = TREE_TYPE(op_0); - const enum tree_code code = TREE_CODE(reorg_type); - const bool is_pointer = POINTER_TYPE == code; - const bool is_array = ARRAY_TYPE == code; - const bool is_valid_input = is_pointer != is_array; - gcc_assert(is_valid_input); - - tree inner_reorg_type = TREE_TYPE(reorg_type); - gcc_assert(inner_reorg_type); - tree reorg_type_size_tree = TYPE_SIZE_UNIT(inner_reorg_type); - int reorg_type_size_int = tree_to_shwi(reorg_type_size_tree); - - tree old_type = (tree)_imap[reorg_type]; - tree inner_old_type = TREE_TYPE(old_type); - gcc_assert(old_type); - tree old_type_size_tree = TYPE_SIZE_UNIT(inner_old_type); - int old_type_size_int = tree_to_shwi(old_type_size_tree); - - - gimple *stmt; - imm_use_iterator iterator; - FOR_EACH_IMM_USE_STMT(stmt, iterator, lhs) - { - // stmt is a use of lhs - // gimple_expr_code is only valid for non-debug statements - bool is_debug = is_gimple_debug (stmt); - if (is_debug) - continue; - - enum tree_code code = gimple_expr_code (stmt); - bool is_exact_div = code == EXACT_DIV_EXPR; - if (!is_exact_div) - continue; - - tree divisor = gimple_op (stmt, 2); - enum tree_code divisor_code = TREE_CODE (divisor); - bool is_constant = divisor_code == INTEGER_CST; - if (!is_constant) - continue; - - int divisor_int = tree_to_shwi (divisor); - bool is_same_size = divisor_int == old_type_size_int; - if (!is_same_size) - continue; - - tree new_integer_cst_tree = build_int_cst(TREE_TYPE(divisor), reorg_type_size_int); - gimple_set_op (stmt, 2, new_integer_cst_tree); - } -} - -void -ExprTypeRewriter::handle_pointer_arithmetic_nonconstant(gimple *s, tree op_0, tree op_1, bool is_pointer_plus) -{ - if (!is_pointer_plus) - { - handle_pointer_arithmetic_diff(s, op_0, op_1); - return; - } - // _1 = _0 * 72 - // ... SNIP ... - // _2 = _1 + CONSTANT; - // ... SNIP ... - // _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... - // Example: - // _2 = _1 * 72; - // ... SNIP ... - // _3 = -_2; < -- def_for_variable **might** be this stmt. - // ... SNIP ... - // _4 = &array + _3; - // Let's find out how many operands we have - unsigned num_operands = gimple_num_ops(def_for_variable); - // Here operands is kind of a minomer. - // operand 0 is the lhs - // operand 1 is the rhs - // I.e. lhs = (unary_operator) rhs; - bool get_another_definition = num_operands == 2; - tree possibly_not_needed = get_another_definition ? gimple_op (def_for_variable, 1) : NULL; - def_for_variable = get_another_definition ? SSA_NAME_DEF_STMT(possibly_not_needed) : def_for_variable; - - // Example: - // _2 = _1 * 72; <-- Now we are here... - // ... SNIP ... - // _3 = -_2; - // ... SNIP ... - // _4 = &array + _3; - - enum gimple_code gcode = gimple_code(def_for_variable); - switch (gcode) - { - //TODO: FIXME: - //This is unsafe, waiting for the sizeof solution - case GIMPLE_COND: - case GIMPLE_CALL: - case GIMPLE_ASSIGN: - break; - default: - return; - break; - } - enum tree_code code = gimple_expr_code (def_for_variable); - const bool is_plus_expr = PLUS_EXPR == code; - - // op_0 is the variable - // That means that the reorg_type is - // 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); - // That means that the old type is - tree old_type_tree = (tree)_imap[reorg_type_tree]; - tree old_inner_type = TREE_TYPE(old_type_tree); - tree old_type_size_tree = TYPE_SIZE_UNIT(old_inner_type); - int old_type_size_int = tree_to_shwi(old_type_size_tree); - - if (is_plus_expr) - { - // If we are here it is because we are adding an offset. - // It is usually whenever we do somehting like - // _2 = _1 + CONSTANT; <-- to change - // _3 = &array + _2; - tree constant_plus = gimple_op (def_for_variable, 2); - assert_is_type(constant_plus, INTEGER_CST); - - int old_integer_cst_int = tree_to_uhwi(constant_plus); - int modulo = old_integer_cst_int % old_type_size_int; - int new_integer_cst_int = old_integer_cst_int / old_type_size_int * reorg_type_size_int + modulo; - - tree new_integer_cst_tree = build_int_cst(TREE_TYPE(constant_plus), new_integer_cst_int); - gimple_set_op(def_for_variable, 2, new_integer_cst_tree); - - tree variable = gimple_op (def_for_variable, 1); - def_for_variable = SSA_NAME_DEF_STMT(variable); - num_operands = gimple_num_ops (def_for_variable); - get_another_definition = num_operands == 2; - def_for_variable = get_another_definition ? SSA_NAME_DEF_STMT(gimple_op(def_for_variable, 1)) : def_for_variable; - code = gimple_expr_code(def_for_variable); - - - } - - if (code == MULT_EXPR) { - - tree op_0_earlier = gimple_assign_rhs1(def_for_variable); - tree op_1_earlier = gimple_assign_rhs2(def_for_variable); - - // We should be able to just call the constant implementation - //handle_pointer_arithmetic_constants(def_for_variable, op_0, op_1); - //However... - //these variables no longer hold the type needed for them to change correctly - //so, let's do it from here... - - assert_is_type(op_1_earlier, INTEGER_CST); - - - tree old_integer_cst_tree = op_1_earlier; - int old_integer_cst_int = tree_to_uhwi(old_integer_cst_tree); - - int offset = old_integer_cst_int % old_type_size_int ; - int new_integer_cst_int = old_integer_cst_int / old_type_size_int * reorg_type_size_int + offset; - log("%d = %d / %d * %d + %d\n", new_integer_cst_int, old_integer_cst_int, old_type_size_int, reorg_type_size_int, offset); - - tree new_integer_cst_tree = build_int_cst(TREE_TYPE(old_integer_cst_tree), new_integer_cst_int); - gimple_set_op(def_for_variable, 2, new_integer_cst_tree); - } -} - -void -ExprTypeRewriter::handle_pointer_arithmetic_constants(gimple *s, tree p, tree i, bool is_pointer_plus) -{ - // So, because we have already changed the type - // tree p will either be the original type - // if we do not need to modify this expression - // How do we know if we have an original type? - // It is when we don't have a type in our map - tree possibly_reorged_type = TREE_TYPE(p); - bool is_interesting_case = is_interesting_type(possibly_reorged_type); - if (!is_interesting_case) return; - - tree reorg_type = possibly_reorged_type; // this is the type of the variable - const_tree original_type = _imap[reorg_type]; - // If we are here, that means that our type has the ".reorg" suffix - const bool has_suffix = strstr(TypeStringifier::get_type_identifier(reorg_type).c_str(), ".reorg"); - bool is_valid_input = has_suffix; - gcc_assert(is_valid_input); - - // We need to know what size is the previous original type - tree inner_reorg_type = TREE_TYPE(reorg_type); - tree inner_orig_type = TREE_TYPE(original_type); - tree old_size_tree = TYPE_SIZE_UNIT(inner_orig_type); - int old_size_int = tree_to_shwi(old_size_tree); - tree new_size_tree = TYPE_SIZE_UNIT(inner_reorg_type); - int new_size_int = tree_to_shwi(new_size_tree); - tree old_integer_cst_tree = i; - int old_integer_cst_int = tree_to_uhwi(old_integer_cst_tree); - - int offset = old_integer_cst_int % old_size_int; - const bool is_modulo = offset == 0; - is_valid_input = is_modulo; - gcc_assert(is_valid_input); - - int new_integer_cst_int = old_integer_cst_int / old_size_int * new_size_int + offset; - log("%d = %d / %d * %d\n", new_integer_cst_int, old_integer_cst_int, old_size_int, new_size_int); - - tree new_integer_cst_tree = build_int_cst(TREE_TYPE(old_integer_cst_tree), new_integer_cst_int); - gimple_set_op(s, 2, new_integer_cst_tree); - - -} - -void -ExprTypeRewriter::_walk_post(const_tree e) -{ - gcc_assert(e); - tree t = TREE_TYPE(e); - const bool in_map = _map.find(t) != _map.end(); - if (!in_map) return; - - const enum tree_code code = TREE_CODE(e); - tree r_t = _map[t]; - TREE_TYPE((tree)e) = r_t; - - 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)); - -} - -void -ExprTypeRewriter::_walk_COMPONENT_REF_post(const_tree e) -{ - - const_tree r = TREE_OPERAND(e, 0); - tree record_type = TREE_TYPE(r); - const bool in_map1 = _map.find(record_type) != _map.end(); - - const_tree f = TREE_OPERAND(e, 1); - // So, what we need is a map between this field and the new field - const bool in_map = _map2.find(f) != _map2.end(); - if (!in_map) return; - - auto p = _map2[f]; - tree n_f = p.first; - bool is_deleted = p.second; - - unsigned f_byte_offset = tree_to_uhwi(DECL_FIELD_OFFSET(f)); - unsigned f_bit_offset = tree_to_uhwi(DECL_FIELD_BIT_OFFSET(f)); - unsigned f_offset = 8 * f_byte_offset + f_bit_offset; - - unsigned nf_byte_offset = tree_to_uhwi(DECL_FIELD_OFFSET(n_f)); - unsigned nf_bit_offset = tree_to_uhwi(DECL_FIELD_BIT_OFFSET(n_f)); - unsigned nf_offset = 8 * nf_byte_offset + nf_bit_offset; - TREE_OPERAND(e, 1) = n_f; - - if (!is_deleted) return; - - _delete = true; - -} - - diff --git a/gcc/expr-rewriter.hpp b/gcc/expr-rewriter.hpp deleted file mode 100644 index 23c0005bcd5..00000000000 --- a/gcc/expr-rewriter.hpp +++ /dev/null @@ -1,33 +0,0 @@ -#pragma once - -#include "expr-walker.hpp" -#include "type-reconstructor.hpp" - -class ExprTypeRewriter : public ExprWalker -{ -public: - ExprTypeRewriter(TypeReconstructor::reorg_record_map_t map, TypeReconstructor::reorg_field_map_t map2) : _delete(false), _map(map), _map2(map2) { - for (auto i = map.cbegin(), e = map.cend(); i != e; ++i) - { - const_tree original = i->first; - tree modified = i->second; - _imap[modified] = original; - } - }; - void handle_pointer_arithmetic_constants(gimple *s, tree p, tree i, bool); - void handle_pointer_arithmetic_diff(gimple *s, tree p, tree i); - void handle_pointer_arithmetic_nonconstant(gimple *s, tree p, tree i, bool); - bool is_interesting_type(tree); - bool delete_statement(); - bool _delete; -private: - TypeReconstructor::reorg_record_map_t _map; - TypeReconstructor::reorg_field_map_t _map2; - std::map<tree, const_tree> _imap; - void _walk_post(const_tree e); - void _walk_MEM_REF_post(const_tree e); - void _walk_COMPONENT_REF_post(const_tree e); - void _walk_PARM_DECL_post(const_tree e); - void _walk_SSA_NAME_post(const_tree e); - void _walk_FUNCTION_DECL_post(const_tree e); -}; diff --git a/gcc/expr-walker.c b/gcc/expr-walker.c deleted file mode 100644 index f5f795dfa97..00000000000 --- a/gcc/expr-walker.c +++ /dev/null @@ -1,312 +0,0 @@ -#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 "expr-walker.hpp" -#include "types-inlines.h" - -void -ExprWalker::walk(const_tree e) -{ - _walk_pre(e); - _walk(e); - _walk_post(e); -} - -void -ExprWalker::_walk(const_tree e) -{ - gcc_assert(e); - const enum tree_code code = TREE_CODE(e); - switch (code) - { - case INTEGER_CST: - walk_INTEGER_CST(e); - break; - case REAL_CST: - walk_REAL_CST(e); - break; - case STRING_CST: - walk_STRING_CST(e); - break; - case BIT_FIELD_REF: - walk_BIT_FIELD_REF(e); - break; - case ARRAY_REF: - walk_ARRAY_REF(e); - break; - case MEM_REF: - walk_MEM_REF(e); - break; - case COMPONENT_REF: - walk_COMPONENT_REF(e); - break; - case SSA_NAME: - walk_SSA_NAME(e); - break; - case ADDR_EXPR: - walk_ADDR_EXPR(e); - break; - case VIEW_CONVERT_EXPR: - walk_VIEW_CONVERT_EXPR(e); - break; - case IMAGPART_EXPR: - walk_IMAGPART_EXPR(e); - break; - case VAR_DECL: - walk_VAR_DECL(e); - break; - case FIELD_DECL: - walk_FIELD_DECL(e); - break; - case RESULT_DECL: - walk_RESULT_DECL(e); - break; - case PARM_DECL: - walk_PARM_DECL(e); - break; - case FUNCTION_DECL: - walk_FUNCTION_DECL(e); - break; - case CONSTRUCTOR: - walk_CONSTRUCTOR(e); - break; - case LE_EXPR: - walk_LE_EXPR(e); - break; - case EQ_EXPR: - walk_EQ_EXPR(e); - break; - case GT_EXPR: - walk_GT_EXPR(e); - break; - default: - { - log("missing %s\n", get_tree_code_name(code)); - gcc_unreachable(); - } - break; - } -} - -#define ExprWalkerFuncDef(code) \ -void \ -ExprWalker::walk_ ## code (const_tree e) \ -{ \ - assert_is_type(e, code); \ - _walk_pre(e); \ - _walk_ ## code ## _pre (e); \ - _walk_ ## code (e); \ - _walk_ ## code ## _post (e); \ - _walk_post(e); \ -} - -ExprWalkerFuncDef(CONSTRUCTOR) -ExprWalkerFuncDef(INTEGER_CST) -ExprWalkerFuncDef(REAL_CST) -ExprWalkerFuncDef(STRING_CST) -ExprWalkerFuncDef(BIT_FIELD_REF) -ExprWalkerFuncDef(ARRAY_REF) -ExprWalkerFuncDef(MEM_REF) -ExprWalkerFuncDef(COMPONENT_REF) -ExprWalkerFuncDef(SSA_NAME) -ExprWalkerFuncDef(ADDR_EXPR) -ExprWalkerFuncDef(VIEW_CONVERT_EXPR) -ExprWalkerFuncDef(IMAGPART_EXPR) -ExprWalkerFuncDef(FIELD_DECL) -ExprWalkerFuncDef(VAR_DECL) -ExprWalkerFuncDef(RESULT_DECL) -ExprWalkerFuncDef(PARM_DECL) -ExprWalkerFuncDef(FUNCTION_DECL) -ExprWalkerFuncDef(LE_EXPR) -ExprWalkerFuncDef(EQ_EXPR) -ExprWalkerFuncDef(GT_EXPR) - -void -ExprWalker::_walk_leaf(const_tree e, const enum tree_code c) -{ - assert_is_type(e, c); -} - -void -ExprWalker::_walk_op_n(const_tree e, unsigned n) -{ - gcc_assert(e); - const_tree op_n = TREE_OPERAND(e, n); - gcc_assert(op_n); - walk(op_n); -} - -void -ExprWalker::_walk_op_0(const_tree e, const enum tree_code c) -{ - assert_is_type(e, c); - _walk_op_n(e, 0); -} - -void -ExprWalker::_walk_op_1(const_tree e, const enum tree_code c) -{ - assert_is_type(e, c); - _walk_op_n(e, 0); - _walk_op_n(e, 1); -} - -void -ExprWalker::_walk_CONSTRUCTOR(const_tree e) -{ -#ifdef FUZZ_MODE - gcc_unreachable(); -#endif -} - -void -ExprWalker::_walk_LE_EXPR(const_tree e) -{ - _walk_op_1(e, LE_EXPR); -} - -void -ExprWalker::_walk_EQ_EXPR(const_tree e) -{ - _walk_op_1(e, EQ_EXPR); -} - -void -ExprWalker::_walk_GT_EXPR(const_tree e) -{ - _walk_op_1(e, GT_EXPR); -} - - -void -ExprWalker::_walk_INTEGER_CST(const_tree e) -{ - _walk_leaf(e, INTEGER_CST); -} - -void -ExprWalker::_walk_REAL_CST(const_tree e) -{ - _walk_leaf(e, REAL_CST); -} - -void -ExprWalker::_walk_STRING_CST(const_tree e) -{ - _walk_leaf(e, STRING_CST); -} - -void -ExprWalker::_walk_BIT_FIELD_REF(const_tree e) -{ -#ifdef FUZZ_MODE - gcc_unreachable(); -#endif -} - -void -ExprWalker::_walk_ARRAY_REF(const_tree e) -{ - _walk_op_1(e, ARRAY_REF); -} - -void -ExprWalker::_walk_MEM_REF(const_tree e) -{ - _walk_op_1(e, MEM_REF); -} - -void -ExprWalker::_walk_COMPONENT_REF(const_tree e) -{ - _walk_op_1(e, COMPONENT_REF); -} - -void -ExprWalker::_walk_SSA_NAME(const_tree e) -{ - _walk_leaf(e, SSA_NAME); -} - -void -ExprWalker::_walk_ADDR_EXPR(const_tree e) -{ - _walk_op_0(e, ADDR_EXPR); -} - -void -ExprWalker::_walk_VIEW_CONVERT_EXPR(const_tree e) -{ -#ifdef FUZZ_MODE - gcc_unreachable(); -#endif -} - -void -ExprWalker::_walk_IMAGPART_EXPR(const_tree e) -{ -#ifdef FUZZ_MODE - gcc_unreachable(); -#endif -} - -void -ExprWalker::_walk_FIELD_DECL(const_tree e) -{ - _walk_leaf(e, FIELD_DECL); -} - -void -ExprWalker::_walk_VAR_DECL(const_tree e) -{ - _walk_leaf(e, VAR_DECL); -} - -void -ExprWalker::_walk_RESULT_DECL(const_tree e) -{ - _walk_leaf(e, RESULT_DECL); -} - -void -ExprWalker::_walk_PARM_DECL(const_tree e) -{ - _walk_leaf(e, PARM_DECL); -} - -void -ExprWalker::_walk_FUNCTION_DECL(const_tree e) -{ - _walk_leaf(e, FUNCTION_DECL); - for (tree parm = DECL_ARGUMENTS(e); parm; parm = DECL_CHAIN(parm)) - { - walk(parm); - } - -} diff --git a/gcc/expr-walker.hpp b/gcc/expr-walker.hpp deleted file mode 100644 index e38084c8838..00000000000 --- a/gcc/expr-walker.hpp +++ /dev/null @@ -1,47 +0,0 @@ -#pragma once - -#include "types-inlines.h" - - -class ExprWalker -{ -public: - ExprWalker() {}; - void walk(const_tree e); -private: - virtual void _walk_pre(__attribute__((unused)) const_tree e) {}; - void _walk(const_tree e); - virtual void _walk_post(__attribute__((unused)) const_tree e) {}; - inline void _walk_leaf(const_tree e, const enum tree_code c); - inline void _walk_op_n(const_tree e, unsigned n); - inline void _walk_op_0(const_tree e, const enum tree_code c); - inline void _walk_op_1(const_tree e, const enum tree_code c); - -#define ExprWalkerFuncDecl(code) \ - virtual void _walk_ ## code ## _pre(__attribute__((unused)) const_tree e) {}; \ - void walk_ ## code (const_tree e); \ - void _walk_ ## code (const_tree e); \ - virtual void _walk_ ## code ## _post(__attribute__((unused)) const_tree e) {} - - ExprWalkerFuncDecl(CONSTRUCTOR); - ExprWalkerFuncDecl(INTEGER_CST); - ExprWalkerFuncDecl(REAL_CST); - ExprWalkerFuncDecl(STRING_CST); - ExprWalkerFuncDecl(BIT_FIELD_REF); - ExprWalkerFuncDecl(ARRAY_REF); - ExprWalkerFuncDecl(MEM_REF); - ExprWalkerFuncDecl(COMPONENT_REF); - ExprWalkerFuncDecl(SSA_NAME); - ExprWalkerFuncDecl(ADDR_EXPR); - ExprWalkerFuncDecl(VIEW_CONVERT_EXPR); - ExprWalkerFuncDecl(IMAGPART_EXPR); - ExprWalkerFuncDecl(FIELD_DECL); - ExprWalkerFuncDecl(VAR_DECL); - ExprWalkerFuncDecl(RESULT_DECL); - ExprWalkerFuncDecl(PARM_DECL); - ExprWalkerFuncDecl(FUNCTION_DECL); - ExprWalkerFuncDecl(LE_EXPR); - ExprWalkerFuncDecl(EQ_EXPR); - ExprWalkerFuncDecl(GT_EXPR); -}; - diff --git a/gcc/gimple-accesser.c b/gcc/gimple-accesser.c deleted file mode 100644 index 18d74f499c0..00000000000 --- a/gcc/gimple-accesser.c +++ /dev/null @@ -1,105 +0,0 @@ -#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 "types-inlines.h" -#include "gimple-accesser.hpp" - - -void -GimpleAccesser::_walk_pre(gassign *s) -{ - // There seems to be quite a bit of code duplication here... - const enum gimple_rhs_class code = gimple_assign_rhs_class(s); - switch (code) - { - case GIMPLE_TERNARY_RHS: - { - const_tree rhs3 = gimple_assign_rhs3(s); - gcc_assert(rhs3); - exprAccessor.update(rhs3, Read); - } - /* fall-through */ - case GIMPLE_BINARY_RHS: - { - const_tree rhs2 = gimple_assign_rhs2(s); - gcc_assert(rhs2); - exprAccessor.update(rhs2, Read); - } - /* fall-through */ - case GIMPLE_UNARY_RHS: - case GIMPLE_SINGLE_RHS: - { - const_tree rhs1 = gimple_assign_rhs1(s); - exprAccessor.update(rhs1, Read); - const_tree lhs = gimple_assign_lhs(s); - if (!lhs) break; - exprAccessor.update(lhs, Write); - break; - } - default: - gcc_unreachable(); - break; - } -} - -void -GimpleAccesser::_walk_pre(gcall *s) -{ - tree fndecl = gimple_call_fndecl(s); - unsigned n = gimple_call_num_args(s); - for (unsigned i = 0; i < n; i++) - { - const_tree a = gimple_call_arg(s, i); - gcc_assert(a); - exprAccessor.update(a, Read); - } - - const_tree lhs = gimple_call_lhs(s); - if (!lhs) return; - exprAccessor.update(lhs, Write); -} - -void -GimpleAccesser::_walk_pre(greturn *s) -{ - const_tree val = gimple_return_retval(s); - if (!val) return; - exprAccessor.update(val, Read); -} - -void -GimpleAccesser::_walk_pre(gcond *s) -{ - const_tree lhs = gimple_cond_lhs(s); - const_tree rhs = gimple_cond_rhs(s); - gcc_assert(lhs && rhs); - exprAccessor.update(lhs, Read); - exprAccessor.update(rhs, Read); -} diff --git a/gcc/gimple-accesser.hpp b/gcc/gimple-accesser.hpp deleted file mode 100644 index 81228724daa..00000000000 --- a/gcc/gimple-accesser.hpp +++ /dev/null @@ -1,25 +0,0 @@ -#pragma once - -#include "gimple-walker.hpp" -#include "expr-accessor.hpp" - -/* - * GimpleAccesser is intended to walk gimple - * and update a map that will hold information - * on whether a type was casted or not. - */ -class GimpleAccesser : public GimpleWalker -{ -public: - GimpleAccesser() : GimpleWalker() {}; - void print_accesses() { exprAccessor.print_accesses(); }; - record_field_map_t get_map() { return exprAccessor.get_map(); }; -private: - ExprAccessor exprAccessor; - virtual void _walk_pre(gcall *s) final; - virtual void _walk_pre(gassign *s) final; - virtual void _walk_pre(greturn *s) final; - virtual void _walk_pre(gcond *s) final; - // Do we need a glabel? I don't think so... - // But we might need a gswitch. -}; diff --git a/gcc/gimple-caster.c b/gcc/gimple-caster.c deleted file mode 100644 index 04283c9237a..00000000000 --- a/gcc/gimple-caster.c +++ /dev/null @@ -1,116 +0,0 @@ -#include "gimple-caster.hpp" -#include "gimple-pretty-print.h" - -#include "type-incomplete-equality.hpp" -#include "type-stringifier.hpp" - - -void -GimpleCaster::_walk_pre(gassign *s) -{ - const enum gimple_rhs_class code = gimple_assign_rhs_class(s); - const bool valid_input = GIMPLE_SINGLE_RHS == code; - if (!valid_input) return; - - // I originally was using gimple_assign_cast_p - // but that proved to be insufficient... - // So we have to use our equality comparison... - TypeIncompleteEquality equality; - const_tree lhs = gimple_assign_lhs(s); - const_tree rhs = gimple_assign_rhs1(s); - gcc_assert(lhs && rhs); - Reason reason {}; - const_tree t_lhs = TREE_TYPE(lhs); - const_tree t_rhs = TREE_TYPE(rhs); - gcc_assert(t_lhs && t_rhs); - bool is_cast = !equality.equal(t_lhs, t_rhs); - TypeStringifier stringifier; - const std::string name_l = stringifier.stringify(t_lhs); - const std::string name_r = stringifier.stringify(t_rhs); - // If it is cast, we might need to look at the definition of rhs - // If the definition comes from a known function... then we are good... - bool is_ssa = TREE_CODE(rhs) == SSA_NAME; - while (is_ssa) { - gimple *def_for_rhs = SSA_NAME_DEF_STMT(rhs); - gcall *is_call = dyn_cast<gcall*>(def_for_rhs); - // poor man's goto - if (!is_call) break; - - const_tree fn = gimple_call_fndecl(is_call); - // poor man's goto - if (!fn) break; - - bool known_function = GimpleEscaper::filter_known_function(fn); - is_cast = !known_function; - - is_ssa = false; - } - reason.type_is_casted = is_cast; - exprEscaper.update(lhs, reason); - exprEscaper.update(rhs, reason); - // TODO: - // I think this will re-do the work... But it might be necessary? - GimpleEscaper::_walk_pre(s); -} - -void -GimpleCaster::_walk_pre(gcall *s) -{ - GimpleEscaper::_walk_pre(s); - - const_tree fn = gimple_call_fndecl(s); - // If there's no function declaration, how do we - // know the argument types? - if (!fn) return; - - cgraph_node *node = cgraph_node::get(fn); - const bool known_function = GimpleEscaper::filter_known_function(node) || GimpleEscaper::filter_known_function(fn); - if (known_function) return; - - const_tree f_t = TREE_TYPE(fn); - TypeIncompleteEquality equality; - TypeStringifier stringifier; - - unsigned i = 0; - unsigned n = gimple_call_num_args(s); - for (tree a = TYPE_ARG_TYPES(f_t); NULL_TREE != a; a = TREE_CHAIN(a)) - { - const_tree formal_t = TREE_VALUE(a); - // There seems to be a final VOID_TYPE at the end of some functions? - const enum tree_code code = TREE_CODE(formal_t); - const bool is_void = VOID_TYPE == code; - if (is_void) continue; - - const_tree real = gimple_call_arg(s, i); - const_tree real_t = TREE_TYPE(real); - const bool is_casted = !equality.equal(formal_t, real_t); - const std::string name_r = stringifier.stringify(real_t); - const std::string name_f = stringifier.stringify(formal_t); - Reason arg_reason; - arg_reason.type_is_casted = is_casted; - exprEscaper.update(real, arg_reason); - i++; - } - - /* - unsigned n = gimple_call_num_args(s); - for (unsigned i = 0; i < n; i++) - { - const_tree a = gimple_call_arg(s, i); - gcc_assert(a); - exprEscaper.update(a, reason); - } - */ - - const_tree lhs = gimple_call_lhs(s); - if (!lhs) return; - - const_tree r_t = TREE_TYPE(f_t); - const_tree l_t TREE_TYPE(lhs); - const bool is_casted = !equality.equal(r_t, l_t); - const std::string name_r_t = stringifier.stringify(r_t); - const std::string name_l_t = stringifier.stringify(r_t); - Reason ret_reason; - ret_reason.type_is_casted = is_casted; - exprEscaper.update(lhs, ret_reason); -} diff --git a/gcc/gimple-caster.hpp b/gcc/gimple-caster.hpp deleted file mode 100644 index 74086606862..00000000000 --- a/gcc/gimple-caster.hpp +++ /dev/null @@ -1,19 +0,0 @@ -#pragma once - -#include "gimple-escaper.hpp" - -/* - * GimpleCaster is intended to walk gimple - * and update a map that will hold information - * on whether a type was casted or not. - */ -class GimpleCaster : public GimpleEscaper -{ -public: - GimpleCaster(ptrset_t &types) : GimpleEscaper(types) {}; -private: - virtual void _walk_pre(gcall *s) final; - // Find out which structs are casted. - // Technically we could find this out on parent - virtual void _walk_pre(gassign *s) final; -}; diff --git a/gcc/gimple-collector.c b/gcc/gimple-collector.c deleted file mode 100644 index 3a38e2334dd..00000000000 --- a/gcc/gimple-collector.c +++ /dev/null @@ -1,124 +0,0 @@ -#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 "types-inlines.h" -#include <set> -#include <string> -#include <map> - -#include "collect-types.h" -#include "type-stringifier.hpp" - -#include "type-collector.hpp" -#include "expr-walker.hpp" -#include "expr-collector.hpp" -#include "gimple-collector.hpp" - -void -GimpleTypeCollector::_walk_pre(const_tree t) -{ - exprCollector.walk(t); -} - -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); -} - -void -GimpleTypeCollector::print_collected() -{ - ptrset_t sets = get_pointer_set(); - sets.print_in_points_to_record(); - -} diff --git a/gcc/gimple-collector.hpp b/gcc/gimple-collector.hpp deleted file mode 100644 index 0c7bba0720e..00000000000 --- a/gcc/gimple-collector.hpp +++ /dev/null @@ -1,22 +0,0 @@ -#pragma once - -#include "gimple-walker.hpp" -#include "expr-collector.hpp" - -class GimpleTypeCollector : public GimpleWalker -{ -private: - ExprCollector exprCollector; -public: - GimpleTypeCollector() {}; - ptrset_t get_pointer_set() { return exprCollector.get_pointer_set(); } - // TODO: I believe this could be made const - void print_collected(); -private: - virtual void _walk_pre(const_tree) final; - virtual void _walk_pre(gassign *s) final; - virtual void _walk_pre(greturn *s) final; - virtual void _walk_pre(gcond *s) final; - virtual void _walk_pre(gcall *s) final; -}; - diff --git a/gcc/gimple-escaper.c b/gcc/gimple-escaper.c deleted file mode 100644 index 0b45cee3ee9..00000000000 --- a/gcc/gimple-escaper.c +++ /dev/null @@ -1,263 +0,0 @@ -#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" // needed for gimple-iterator.h -#include "gimple-iterator.h" -#include "gimple-ssa.h" -#include "gimple-pretty-print.h" -#include <stdbool.h> - -#include "gimple-escaper.hpp" -#include "type-stringifier.hpp" -#include "type-incomplete-equality.hpp" - - -void -GimpleEscaper::_init() -{ - cgraph_node *cnode = NULL; - FOR_EACH_FUNCTION(cnode) - { - gcc_assert(cnode); - const bool filter = GimpleEscaper::filter_known_function(cnode); - if (filter) continue; - - const_tree decl = cnode->decl; - gcc_assert(decl); - undefined.insert(decl); - } - - FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(cnode) - { - gcc_assert(cnode); - cnode->get_untransformed_body(); - const_tree decl = cnode->decl; - gcc_assert(decl); - undefined.erase(decl); - } -} - -bool -GimpleEscaper::is_function_escaping(cgraph_node *cnode) -{ - const bool filter = GimpleEscaper::filter_known_function(cnode); - if (filter) return false; - - return cnode->externally_visible; -} - -bool -GimpleEscaper::is_function_escaping(const_tree fndecl) -{ - if (!fndecl) return true; - - if (!TREE_PUBLIC(fndecl) || DECL_EXTERNAL(fndecl)) return false; - - return true; -} - -bool -GimpleEscaper::is_variable_escaping(varpool_node *vnode) -{ - gcc_assert(vnode); - return vnode->externally_visible; -} - -void -GimpleEscaper::_walk_global(varpool_node *vnode) -{ - gcc_assert(vnode); - const_tree var_decl = vnode->decl; - Reason reason {} ; - const bool is_escaping = is_variable_escaping(vnode); - reason.global_is_visible = is_escaping; - - tree initial = DECL_INITIAL (var_decl); - const bool constructor = initial ? TREE_CODE (initial) == CONSTRUCTOR : false; - const bool error_mark = initial ? TREE_CODE (initial) == ERROR_MARK: false; - reason.global_is_visible |= constructor || error_mark; // static initialization... - - TypeStringifier stringifier; - std::string name = stringifier.stringify(TREE_TYPE(var_decl)); - log("%s %s\n", vnode->name(), name.c_str()); - exprEscaper.update(var_decl, reason); - GimpleWalker::_walk_global(vnode); - -} - -bool -GimpleEscaper::filter_known_function(const_tree fndecl) -{ - assert_is_type(fndecl, FUNCTION_DECL); - if (fndecl_built_in_p (fndecl)) - { - switch (DECL_FUNCTION_CODE (fndecl)) - { - case BUILT_IN_FREE: - case BUILT_IN_MALLOC: - case BUILT_IN_REALLOC: - case BUILT_IN_CALLOC: - case BUILT_IN_MEMSET: - return true; - break; - default: - break; - } - } - - - const_tree identifier_node = DECL_NAME(fndecl); - gcc_assert(identifier_node); - bool filter = false; - const char *_specqsort= "spec_qsort"; - const char *_med3 = "arc_compare"; - const char *_getArcPosition = "getArcPosition"; - const char *_med3_ = "med3.part.0"; - const char *_med3_2 = "med3"; - const char* name = IDENTIFIER_POINTER(identifier_node); - gcc_assert(name); - filter |= strcmp(_specqsort, name) == 0; - filter |= strcmp(_med3, name) == 0; - filter |= strcmp(_med3_, name) == 0; - filter |= strcmp(_med3_2, name) == 0; - filter |= strcmp(_getArcPosition, name) == 0; - return filter; -} - -bool -GimpleEscaper::filter_known_function(cgraph_node *node) -{ - if (!node) return false; - return filter_known_function(node->decl); -} - -void -GimpleEscaper::_walk_pre(const_tree t) -{ - // Is any global variable escaping? - Reason reason; - exprEscaper.update(t, reason); -} - -void -GimpleEscaper::_walk_pre(gassign *s) -{ - Reason reason; - const enum gimple_rhs_class code = gimple_assign_rhs_class(s); - switch (code) - { - case GIMPLE_TERNARY_RHS: - { - const_tree rhs3 = gimple_assign_rhs3(s); - exprEscaper.update(rhs3, reason); - } - /* fall-through */ - case GIMPLE_BINARY_RHS: - { - const_tree rhs2 = gimple_assign_rhs2(s); - exprEscaper.update(rhs2, reason); - } - /* fall-through */ - case GIMPLE_UNARY_RHS: - case GIMPLE_SINGLE_RHS: - { - const_tree rhs1 = gimple_assign_rhs1(s); - exprEscaper.update(rhs1, reason); - const_tree lhs = gimple_assign_lhs(s); - if (!lhs) break; - exprEscaper.update(lhs, reason); - } - break; - default: - gcc_unreachable(); - break; - } -} - -void -GimpleEscaper::_walk_pre(greturn *s) -{ - Reason reason; - const_tree val = gimple_return_retval(s); - if (!val) return; - exprEscaper.update(val, reason); -} - -void -GimpleEscaper::_walk_pre(gcond *s) -{ - Reason reason; - const_tree lhs = gimple_cond_lhs(s); - const_tree rhs = gimple_cond_rhs(s); - gcc_assert(lhs && rhs); - exprEscaper.update(lhs, reason); - exprEscaper.update(rhs, reason); -} - -void -GimpleEscaper::_walk_pre(gcall *s) -{ - const_tree fn = gimple_call_fndecl(s); - // gcc_assert(fn); - // The above will not always be true - cgraph_node *node = fn ? cgraph_node::get(fn) : NULL; - // const bool fn_and_node = fn && node; - // const bool not_function_and_not_node = !fn && !node; - // const bool test = fn_and_node ^ not_function_and_not_node; - // gcc_assert(test); - // The above is not true... - // which means that there are functions with function declarations - // but no corresponding cgraph_node. - // - // What does that mean for our analysis? - // It means that we cannot find out if a function is escaping all the time..? - // Or at least via the cnode... - // It seems to me that the correct way to deal with this is saying that - // functions which do not have a cgraph_node should be escaping, - // but this will mark some interesting types as escaping... - const bool _is_function_escaping = node ? is_function_escaping(node) : is_function_escaping(fn); - const bool is_undefined = undefined.find(fn) != undefined.end(); - const bool _is_escaping = is_undefined || _is_function_escaping; - - TypeStringifier stringifier; - Reason arg_reason; - arg_reason.parameter_is_visible = _is_escaping; - arg_reason.is_indirect = !fn; - unsigned n = gimple_call_num_args(s); - for (unsigned i = 0; i < n; i++) - { - const_tree a = gimple_call_arg(s, i); - gcc_assert(a); - exprEscaper.update(a, arg_reason); - } - - const_tree lhs = gimple_call_lhs(s); - if (!lhs) return; - Reason return_reason; - return_reason.return_is_visible = _is_escaping; - return_reason.is_indirect = !fn; - exprEscaper.update(lhs, return_reason); -} diff --git a/gcc/gimple-escaper.hpp b/gcc/gimple-escaper.hpp deleted file mode 100644 index 490ebc20fe0..00000000000 --- a/gcc/gimple-escaper.hpp +++ /dev/null @@ -1,30 +0,0 @@ -#pragma once - -#include "gimple-walker.hpp" -#include "expr-escaper.hpp" -#include "collect-types.h" - -class GimpleEscaper : public GimpleWalker -{ -public: - GimpleEscaper(ptrset_t &types) : exprEscaper(types) { _init(); }; - ExprEscaper exprEscaper; - ptrset_t get_sets() { return exprEscaper.get_sets(); }; - void print_reasons() { exprEscaper.print_reasons(); }; -protected: - typedef std::set<const_tree> undefset; - undefset undefined; - void _init(); - static bool filter_known_function(cgraph_node *); - static bool filter_known_function(const_tree); - static bool is_function_escaping(cgraph_node *); - static bool is_function_escaping(const_tree); - static bool is_variable_escaping(varpool_node *); - static bool _is_assignment_casted(gassign *s); - virtual void _walk_global(varpool_node *); - virtual void _walk_pre(gassign *s) ; - virtual void _walk_pre(greturn *s) ; - virtual void _walk_pre(gcond *s) ; - virtual void _walk_pre(gcall *s) ; - virtual void _walk_pre(const_tree) ; -}; diff --git a/gcc/gimple-rewriter.c b/gcc/gimple-rewriter.c deleted file mode 100644 index 31fcb74ed86..00000000000 --- a/gcc/gimple-rewriter.c +++ /dev/null @@ -1,268 +0,0 @@ -#include "config.h" -#include "system.h" -#include "coretypes.h" -#include "tree.h" -#include "options.h" -#include "cgraph.h" -#include "tree-pass.h" -#include "tree-cfg.h" -#include "tree-pretty-print.h" -#include "gimple-pretty-print.h" -#include "stringpool.h" //get_identifier -#include "basic-block.h" //needed for gimple.h -#include "function.h" //needed for gimple.h -#include "gimple.h" -#include "cfg.h" // needed for gimple-iterator.h -#include "gimple-iterator.h" -#include "stor-layout.h" // layout_type -#include "fold-const.h" //build_fold_addr_expr -#include "gimple-ssa.h" // update_stmt -#include "attribs.h" // decl_attributes -#include "gimplify.h" //unshare_expr -#include "value-range.h" // make_ssa_name dependency -#include "tree-ssanames.h" // make_ssa_name -#include "ssa.h" -#include "tree-into-ssa.h" -#include "gimple-rewriter.hpp" -#include "type-stringifier.hpp" - -void -GimpleTypeRewriter::_walk_pre(const_tree e) -{ - // This is for local variables - // and other declarations - exprTypeRewriter.walk(e); - bool _delete = exprTypeRewriter._delete; - exprTypeRewriter._delete = false; - // I don't think it is possible here (local variable delcarations and such); - gcc_assert(!_delete); - const bool is_interesting = exprTypeRewriter.is_interesting_type(TREE_TYPE(e)); - - /* - const bool is_ssa_name = TREE_CODE(e) == SSA_NAME; - if (is_ssa_name) - { - tree l = (tree) e; - if (SSA_NAME_VAR(l) == NULL_TREE) return; - if (TREE_TYPE(l) != TREE_TYPE(SSA_NAME_VAR(l))) { log("unequal\n"); } - - TREE_TYPE(l) = TREE_TYPE(SSA_NAME_VAR(l)); - TypeStringifier stringifier; - std::string name = stringifier.stringify(TREE_TYPE(l)); - log("new name %s\n", name.c_str()); - } - */ - - const bool is_var_decl = TREE_CODE(e) == VAR_DECL; - const bool is_valid = is_interesting && is_var_decl; - if (!is_valid) return; - relayout_decl((tree)e); -} - -void -GimpleTypeRewriter::_walk_pre(gimple *s) -{ -} - -void -GimpleTypeRewriter::_walk_pre(gcall *s) -{ -} - -void -GimpleTypeRewriter::_walk_pre(greturn *s) -{ - const_tree val = gimple_return_retval(s); - if (!val) return; - log("rewriting a return value\n"); - exprTypeRewriter.walk(val); - bool _delete = exprTypeRewriter._delete; - exprTypeRewriter._delete = false; - // We can't probably have a write in a return statement. - gcc_assert(!_delete); -} - -void -GimpleTypeRewriter::handle_pointer_arithmetic(gimple *s) -{ - const enum tree_code p = POINTER_PLUS_EXPR; - const enum tree_code d = POINTER_DIFF_EXPR; - const enum tree_code e = gimple_expr_code(s); - const bool is_pointer_plus = p == e; - const bool is_pointer_diff = d == e; - bool is_valid_input = is_pointer_plus != is_pointer_diff; - gcc_assert(is_valid_input); - // TODO: Implement pointer diff - - const enum gimple_rhs_class rhs_class = gimple_assign_rhs_class(s); - is_valid_input = GIMPLE_BINARY_RHS == rhs_class; - gcc_assert(is_valid_input); - - 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); - 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); - const enum tree_code op_0_code = TREE_CODE(op_0); - const bool is_op_0_icst = INTEGER_CST == op_0_code; - const bool is_op_1_icst = INTEGER_CST == op_1_code; - const bool is_constant_case = is_op_0_icst != is_op_1_icst; - if (!is_constant_case) - { - exprTypeRewriter.handle_pointer_arithmetic_nonconstant(s, op_0, op_1, is_pointer_plus); - bool _delete = exprTypeRewriter._delete; - exprTypeRewriter._delete = false; - // probably no deletion in pointer arithmetic... - gcc_assert(!_delete); - return; - } - - tree integer_constant = is_op_0_icst ? op_0 : op_1; - tree maybe_pointer = is_op_0_icst ? op_1 : op_0; - const_tree maybe_pointer_t = TREE_TYPE(maybe_pointer); - assert_is_type(maybe_pointer_t, POINTER_TYPE); - tree pointer_variable = maybe_pointer; - - exprTypeRewriter.handle_pointer_arithmetic_constants(s, pointer_variable, integer_constant, is_pointer_plus); - bool _delete = exprTypeRewriter._delete; - exprTypeRewriter._delete = false; - // probably no deletion in pointer arithmetic - gcc_assert(!_delete); -} - - -void -GimpleTypeRewriter::_walk_pre(gassign *s) -{ - const enum gimple_rhs_class code = gimple_assign_rhs_class(s); - - switch (code) - { - case GIMPLE_TERNARY_RHS: - { - const_tree rhs3 = gimple_assign_rhs3(s); - exprTypeRewriter.walk(rhs3); - } - /* fall-through */ - case GIMPLE_BINARY_RHS: - { - const_tree rhs2 = gimple_assign_rhs2(s); - exprTypeRewriter.walk(rhs2); - } - /* fall-through */ - case GIMPLE_UNARY_RHS: - case GIMPLE_SINGLE_RHS: - { - const_tree rhs1 = gimple_assign_rhs1(s); - exprTypeRewriter.walk(rhs1); - const_tree lhs = gimple_assign_lhs(s); - if (!lhs) break; - // Here is the only place where we likely can delete a statement. - exprTypeRewriter.walk(lhs); - bool _delete = exprTypeRewriter._delete; - exprTypeRewriter._delete = false; - if (_delete) - { - _deleted = true; - } - } - break; - default: - gcc_unreachable(); - 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: - case POINTER_DIFF_EXPR: - handle_pointer_arithmetic(s); - break; - case COMPONENT_REF: - { - log("i am missing a component ref\n"); - print_gimple_stmt(dump_file, s, 0); - log("\n"); - - TypeStringifier stringifier; - tree e = gimple_assign_rhs1(s); - const_tree type = TREE_TYPE(e); - std::string name = stringifier.stringify(type); - 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; - } - -} - -void -GimpleTypeRewriter::_walk_pre(gcond *s) -{ -} - -void -GimpleTypeRewriter::_rewrite_function_decl() -{ - // NOTE: It seems we only need to rewrite the return type - // for now... - cgraph_node *node = NULL; - FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) - { - node->get_untransformed_body(); - tree fndecl = node->decl; - gcc_assert(fndecl); - exprTypeRewriter.walk(fndecl); - tree decl = DECL_RESULT(fndecl); - if (decl) exprTypeRewriter.walk(decl); - } -} - -void -GimpleTypeRewriter::_walk_pre(gphi *s) -{ - unsigned n = gimple_phi_num_args (s); - for (unsigned i = 0; i < n; i++) - { - tree a = gimple_phi_arg_def(s, i); - exprTypeRewriter.walk(a); - } -} diff --git a/gcc/gimple-rewriter.hpp b/gcc/gimple-rewriter.hpp deleted file mode 100644 index 03d5bfa21ad..00000000000 --- a/gcc/gimple-rewriter.hpp +++ /dev/null @@ -1,22 +0,0 @@ -#pragma once - -#include "gimple-walker.hpp" -#include "expr-rewriter.hpp" -#include "type-reconstructor.hpp" - -class GimpleTypeRewriter : public GimpleWalker -{ -public: - GimpleTypeRewriter(TypeReconstructor::reorg_record_map_t map, TypeReconstructor::reorg_field_map_t map2) : exprTypeRewriter(map, map2) {}; - void _rewrite_function_decl(); -private: - ExprTypeRewriter exprTypeRewriter; - void handle_pointer_arithmetic(gimple *s); - virtual void _walk_pre(gphi* ) final; - virtual void _walk_pre(const_tree) final; - virtual void _walk_pre(gimple*) final; - virtual void _walk_pre(gcall *s) final; - virtual void _walk_pre(greturn *s) final; - virtual void _walk_pre(gassign *s) final; - virtual void _walk_pre(gcond *s) final; -}; diff --git a/gcc/gimple-walker.c b/gcc/gimple-walker.c deleted file mode 100644 index 1a858419c27..00000000000 --- a/gcc/gimple-walker.c +++ /dev/null @@ -1,257 +0,0 @@ -#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 "types-inlines.h" -#include <set> -#include <string> -#include <map> - -#include "collect-types.h" -#include "type-stringifier.hpp" - -#include "type-collector.hpp" -#include "expr-walker.hpp" -#include "expr-collector.hpp" -#include "gimple-walker.hpp" -#include "tree-cfg.h" - -inline static void -print_function (cgraph_node *cnode) -{ - if (!dump_file) - return; - gcc_assert (cnode); - cnode->get_untransformed_body (); - dump_function_to_file (cnode->decl, dump_file, TDF_NONE); -} - -void -GimpleWalker::walk() -{ - _walk_globals(); - - std::set<tree> fndecls; - cgraph_node *node = NULL; - FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) - { - print_function(node); - node->get_untransformed_body(); - const bool already_in_set = fndecls.find(node->decl) != fndecls.end(); - if (already_in_set) continue; - _walk_cnode(node); - fndecls.insert(node->decl); - } -} - -void -GimpleWalker::_walk_globals() -{ - varpool_node *vnode = NULL; - FOR_EACH_VARIABLE(vnode) - { - _walk_global(vnode); - } -} - -void -GimpleWalker::_walk_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; - walk(var_decl); - } -} - -void -GimpleWalker::_walk_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); - walk(ssa_name); - } - pop_cfun(); -} - -void -GimpleWalker::_walk_cnode(cgraph_node *cnode) -{ - gcc_assert(cnode); - _walk_decl(cnode); - _walk_locals(cnode); - _walk_ssa_names(cnode); - _walk_bb(cnode); -} - - -void -GimpleWalker::_walk_decl(cgraph_node *cnode) -{ - const_tree decl = cnode->decl; - gcc_assert(decl); - walk(decl); -} - -void -GimpleWalker::_walk_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); - walk(var_decl); - } -} - - -void -GimpleWalker::_walk_bb(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); - bool first = true; - gimple_stmt_iterator gsi = gsi_start_bb(bb); - - while (!gsi_end_p(gsi)) - { - gimple *stmt = gsi_stmt(gsi); - walk(stmt); - if (_deleted) unlink_stmt_vdef (stmt); - if (_deleted) { gsi_remove(&gsi, true); } - else { gsi_next(&gsi); } - _deleted = false; - } - - - for (gimple_stmt_iterator gsi = gsi_start_phis(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*); - GimpleWalkerWalk(gphi*); - - - const enum gimple_code code = gimple_code (stmt); - switch (code) - { - case GIMPLE_PREDICT: return; - case GIMPLE_DEBUG: 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 (__attribute__((unused)) type e) \ -{ \ -} - -GimpleWalkerFuncDef(const_tree) -GimpleWalkerFuncDef(gassign *) -GimpleWalkerFuncDef(greturn *) -GimpleWalkerFuncDef(gcond *) -GimpleWalkerFuncDef(gcall *) -GimpleWalkerFuncDef(glabel *) -GimpleWalkerFuncDef(gswitch *) -GimpleWalkerFuncDef(gphi *) - diff --git a/gcc/gimple-walker.hpp b/gcc/gimple-walker.hpp deleted file mode 100644 index 6c3742afb0b..00000000000 --- a/gcc/gimple-walker.hpp +++ /dev/null @@ -1,69 +0,0 @@ -#pragma once - -#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 <set> - -class GimpleWalker -{ -public: - GimpleWalker() : _deleted(false) {}; - void walk(); - -protected: - - bool _deleted; - virtual void _walk_global(varpool_node*); - void _walk_globals(); - void _walk_ssa_names(cgraph_node *cnode); - void _walk_cnode(cgraph_node *cnode); - void _walk_decl(cgraph_node *cnode); - void _walk_locals(cgraph_node *cnode); - void _walk_bb(cgraph_node *cnode); - void _walk(basic_block bb); - -#define GimpleWalkerFuncDecl(type) \ - virtual void _walk_pre(type stmt) {}; \ - void walk(type stmt); \ - void _walk(type stmt); \ - virtual void _walk_post(type stmt) {} - - GimpleWalkerFuncDecl(const_tree); - GimpleWalkerFuncDecl(gimple*); - GimpleWalkerFuncDecl(gassign*); - GimpleWalkerFuncDecl(greturn*); - GimpleWalkerFuncDecl(gcond*); - GimpleWalkerFuncDecl(gcall*); - GimpleWalkerFuncDecl(glabel*); - GimpleWalkerFuncDecl(gswitch*); - GimpleWalkerFuncDecl(gphi*); -}; - diff --git a/gcc/ipa-prototype.c b/gcc/ipa-prototype.c deleted file mode 100644 index 76d5b223900..00000000000 --- a/gcc/ipa-prototype.c +++ /dev/null @@ -1,330 +0,0 @@ -#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" // needed for gimple-iterator.h -#include "gimple-iterator.h" -#include "gimple-ssa.h" -#include <stdbool.h> - - -#include "types-inlines.h" -#include "ipa-prototype.h" -#include "type-collector.hpp" -#include "type-stringifier.hpp" -#include <map> -#include <vector> -#include "type-escaper.hpp" -#include "expr-escaper.hpp" -#include "gimple-walker.hpp" -#include "gimple-collector.hpp" -#include "gimple-escaper.hpp" -#include "type-structural-equality.hpp" -#include "type-structural-main-variant.hpp" -#include "type-incomplete-equality.hpp" - -//#define OPTIMIZED -#define SANITY_CHECKS - -typedef std::set<const_tree> undefset; - -void -Reason::print() const -{ - log("e=%d g=%d p=%d r=%d c=%d v=%d u=%d i=%d\n", this->is_escaping(), this->global_is_visible, this->parameter_is_visible, this->return_is_visible, this->type_is_casted, this->type_is_volatile, this->type_is_in_union, this->is_indirect); -} - -Reason -Reason::operator|(const Reason &other) -{ - Reason retval {}; - retval.global_is_visible = this->global_is_visible | other.global_is_visible; - retval.parameter_is_visible = this->parameter_is_visible | other.parameter_is_visible; - retval.return_is_visible = this->return_is_visible | other.return_is_visible; - retval.type_is_casted = this->type_is_casted | other.type_is_casted; - retval.type_is_volatile = this->type_is_volatile | other.type_is_volatile; - retval.type_is_in_union = this->type_is_in_union | other.type_is_in_union; - retval.is_indirect = this->is_indirect | other.is_indirect; - return retval; -} - -Reason& -Reason::operator|=(const Reason &other) -{ - this->global_is_visible |= other.global_is_visible; - this->parameter_is_visible |= other.parameter_is_visible; - this->return_is_visible |= other.return_is_visible; - this->type_is_casted |= other.type_is_casted; - this->type_is_volatile |= other.type_is_volatile; - this->type_is_in_union |= other.type_is_in_union; - this->is_indirect |= other.is_indirect; - return *this; -} - - - -static inline void -assert_type_is_in_ptrset(const_tree type, ptrset_t &types) -{ -#ifdef SANITY_CHECKS - gcc_assert(types.in_points_to_record(type)); -#endif -} - -static inline void -assert_type_is_in_universe(const_tree type, ptrset_t &types) -{ -#ifdef SANITY_CHECKS - gcc_assert(types.in_universe(type)); -#endif -} - -static bool -is_variable_escaping(varpool_node *vnode) -{ - gcc_assert(vnode); - return vnode->externally_visible; -} - -static void -place_escaping_types_in_set(ptrset_t &types, typemap &calc) -{ - for (auto i = calc.cbegin(), e = calc.cend(); i != e; ++i) - { - const_tree type = i->first; - // We should have seen it before - assert_type_is_in_universe(type, types); - - // We should only track interesting types - // Types which are not in points_to_record are the ones - // that are pointed to by records. - // I think it is possible to prune them ahead of time... - if (!types.in_points_to_record(type)) continue; - - const Reason reason = i->second; - reason.is_escaping() ? types.escaping.insert(type) : types.non_escaping.insert(type); - } -} - -static void -sanity_check_escape_xor_not(ptrset_t &types) -{ - for (auto i = types.escaping.cbegin(), e = types.escaping.cend(); i != e; ++i) - { - for (auto j = types.non_escaping.cbegin(), f = types.non_escaping.cend(); j != f; ++j) - { - const_tree type_esc = *i; - gcc_assert(type_esc); - const_tree type_non = *j; - gcc_assert(type_non); - //const bool valid_sets = !eq_type_compare(type_esc, type_non); - //if (valid_sets) continue; - //log("comparing %s == %s\n", type_to_string(type_esc).c_str(), type_to_string(type_non).c_str()); - //TODO: Remove this comment once we have restricted the "repairing" of sets a bit more. - //gcc_assert(valid_sets); - } - } -} - -static void -sanity_check_escape_union_not_equals_ptrset(ptrset_t &types) -{ - typeset _union; - for (auto i = types.escaping.cbegin(), e = types.escaping.cend(); i != e; ++i) - { - const_tree type = *i; - _union.insert(type); - } - - for (auto i = types.non_escaping.cbegin(), e = types.non_escaping.cend(); i != e; ++i) - { - const_tree type = *i; - _union.insert(type); - } - - - for (auto i = types.points_to_record.cbegin(), e = types.points_to_record.cend(); i != e; ++i) - { - const_tree type = *i; - const bool in_union = _union.find(type) != _union.end(); - if (in_union) continue; - //log("this type was not found in union %s\n", type_to_string(type).c_str()); - //TODO: FIXME: This has to be enabled for the sanity check to work - //But at the moment there's one type which isn't working correctly :( - gcc_unreachable(); - } - -} - -static void -fix_escaping_types_in_set(ptrset_t &types) -{ - bool fixed_point_reached = false; - TypeIncompleteEquality structuralEquality; - TypeStringifier stringifier; - do { - std::vector<const_tree> fixes; - fixed_point_reached = true; - for (auto i = types.escaping.cbegin(), e = types.escaping.cend(); i != e; ++i) - { - for (auto j = types.non_escaping.cbegin(), f = types.non_escaping.cend(); j != f; ++j) - { - const_tree type_esc = *i; - gcc_assert(type_esc); - const_tree type_non = *j; - gcc_assert(type_non); - // There can be cases where incomplete types are marked as non-escaping - // and complete types counter parts are marked as escaping. - //const bool interesting_case = eq_type_compare(type_esc, type_non); - //TODO: We are going to need a different type comparison because this one - //fails to take into account the recursion... - TypeStringifier stringifier; - std::string type_esc_name = TypeStringifier::get_type_identifier(type_esc); - std::string type_non_name = TypeStringifier::get_type_identifier(type_non); - //std::string file("FILE"); - //bool i_care = type_esc_name.compare(file) == 0; - //i_care &= type_non_name.compare(file) == 0; - - type_esc_name = stringifier.stringify(type_esc); - type_non_name = stringifier.stringify(type_non); - - const bool equal = structuralEquality.equal(type_esc, type_non); - if (!equal) continue; - - log("recalulating %s == %s\n", type_esc_name.c_str(), type_non_name.c_str()); - fixed_point_reached = false; - // Add incomplete to escaping - // delete incomplete from non_escaping - // We shouldn't do that inside our iteration loop. - fixes.push_back(type_non); - } - } - - for (auto i = fixes.cbegin(), e = fixes.cend(); i != e; ++i) - { - const_tree escaping_type = *i; - types.escaping.insert(escaping_type); - types.non_escaping.erase(escaping_type); - } - } while (!fixed_point_reached); -} - -static void -print_escaping_types_in_set(ptrset_t &types) -{ - std::vector<const_tree> fixes; - for (auto i = types.non_escaping.cbegin(), e = types.non_escaping.cend(); i != e; ++i) - { - const_tree type_non = *i; - gcc_assert(type_non); - const enum tree_code code = TREE_CODE(type_non); - const bool is_function = FUNCTION_TYPE == code; - // I just don't want to print out functions. - if (is_function) continue; - TypeStringifier stringifier; - std::string name = stringifier.stringify(type_non); - log("non_escaping: %s \n", name.c_str()); - } - -} - -static void -print_sequal_types(ptrset_t &types) -{ - std::vector<const_tree> fixes; - TypeStructuralEquality structuralEquality; - TypeStringifier stringifier; - for (auto i = types.universe.cbegin(), e = types.universe.cend(); i != e; ++i) - { - for (auto j = types.universe.cbegin(), e = types.universe.cend(); j != e; ++j) - { - const_tree t_i = *i; - const_tree t_j = *j; - const bool eq = structuralEquality.equal(t_i, t_j); - std::string n_i = stringifier.stringify(t_i); - std::string n_j = stringifier.stringify(t_j); - log("%s = %s == %s\n", eq ? "t" : "f", n_i.c_str(), n_j.c_str()); - } - } -} - - -static unsigned int -iphw_execute() -{ - - GimpleTypeCollector collector; - collector.walk(); - ptrset_t types = collector.get_pointer_set(); - - GimpleEscaper gimpleEscaper(types); - gimpleEscaper.walk(); - - typemap eacalc; // Escape Analysis Calculation - // Intermediate results - // Do not read escape analysis results from here - //calculate_escaping_types(types, eacalc); - //print_sequal_types(types); - place_escaping_types_in_set(types, gimpleEscaper.exprEscaper.typeEscaper.calc); - fix_escaping_types_in_set(types); - // -fipa-protytpe -fdump-ipa-prototype - print_escaping_types_in_set(types); - sanity_check_escape_xor_not(types); - sanity_check_escape_union_not_equals_ptrset(types); - gcc_unreachable(); - return 0; -} - -namespace { -const pass_data pass_data_ipa_prototype = -{ - SIMPLE_IPA_PASS, - "prototype", - OPTGROUP_NONE, - TV_NONE, - (PROP_cfg | PROP_ssa), - 0, - 0, - 0, - 0, -}; - -class pass_ipa_prototype : public simple_ipa_opt_pass -{ -public: - pass_ipa_prototype (gcc::context *ctx) - : simple_ipa_opt_pass(pass_data_ipa_prototype, ctx) - {} - - virtual bool gate(function*) { return flag_ipa_prototype; } - virtual unsigned execute (function*) { return iphw_execute(); } -}; -} // anon namespace - -simple_ipa_opt_pass* -make_pass_ipa_prototype (gcc::context *ctx) -{ - return new pass_ipa_prototype (ctx); -} diff --git a/gcc/ipa-prototype.h b/gcc/ipa-prototype.h deleted file mode 100644 index f77e0de3b32..00000000000 --- a/gcc/ipa-prototype.h +++ /dev/null @@ -1,60 +0,0 @@ -#pragma once - -#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 <map> - -struct Reason { - inline bool is_escaping() const { - return this->global_is_visible - || this->parameter_is_visible - || this->return_is_visible - || this->type_is_casted - || this->type_is_volatile - || this->type_is_in_union - || this->is_indirect; - } - bool global_is_visible : 1; - bool parameter_is_visible : 1; - bool return_is_visible : 1; - bool type_is_casted : 1; - bool type_is_volatile : 1; - bool type_is_in_union : 1; - bool is_indirect : 1; - Reason operator|(const Reason &); - Reason& operator|=(const Reason &); - void print() const; - Reason() : global_is_visible(0), parameter_is_visible(0), return_is_visible(0), type_is_casted(0), type_is_volatile(0), type_is_in_union(0), is_indirect(0) {}; -}; - - -typedef std::map<const_tree, Reason> typemap; - diff --git a/gcc/ipa-str-reorg-dead-field-eliminate.c b/gcc/ipa-str-reorg-dead-field-eliminate.c index f918974f719..203b31a44a2 100644 --- a/gcc/ipa-str-reorg-dead-field-eliminate.c +++ b/gcc/ipa-str-reorg-dead-field-eliminate.c @@ -51,8 +51,6 @@ along with GCC; see the file COPYING3. If not see #include "ipa-utils.h" #include "ipa-str-reorg-utils.h" -#include "gimple-caster.hpp" - #define test_write(M, ...) \ if (dump_file) \ { \ @@ -2764,13 +2762,13 @@ str_reorg_dead_field_eliminate (__attribute__((unused)) Info *info) int str_reorg_dead_field_eliminate_qual (Info *info) { - GimpleCaster caster(info->sets); - caster.walk(); + //GimpleCaster caster(info->sets); + //caster.walk(); // sets here now holds the types that // are casted... // So, maybe we want to print them? - caster.print_reasons(); - ptrset_t sets = caster.get_sets(); + //caster.print_reasons(); + //ptrset_t sets = caster.get_sets(); return 0; } int diff --git a/gcc/ipa-structure-reorg.c b/gcc/ipa-structure-reorg.c index f2578414e47..155b5b4fe68 100644 --- a/gcc/ipa-structure-reorg.c +++ b/gcc/ipa-structure-reorg.c @@ -28,8 +28,6 @@ along with GCC; see the file COPYING3. If not see #include "gimple.h" #include "gimple-iterator.h" #include "gimple-walk.h" -#include "gimple-collector.hpp" -#include "gimple-escaper.hpp" #include "tree-pass.h" #include "tree-cfg.h" #include "cfgloop.h" @@ -39,13 +37,13 @@ along with GCC; see the file COPYING3. If not see #include "tree-pretty-print.h" #include "gimple-pretty-print.h" #include "langhooks.h" -#include "collect-types.h" #include "stor-layout.h" #include "tree-dfa.h" #include <vector> #include <map> #include <set> #include "ipa-structure-reorg.h" +#include "gimple-ssa.h" #include "tree-phinodes.h" #include "ssa-iterators.h" @@ -170,7 +168,6 @@ ipa_structure_reorg ( void) { if ( flag_ipa_structure_reorg || flag_ipa_dead_field_eliminate ) { - log("before str_reorg_dead_field_eliminate_qual \n"); str_reorg_dead_field_eliminate_qual ( &info); // Because I just want to do this now... #if KLUDGE @@ -270,34 +267,6 @@ final_debug_info ( Info *info) static unsigned int reorg_analysis ( Info *info) { - // TODO: - // Gary, this main "analysis" method seems to have a lot of - // instance interleave specific code. Shouldn't this method - // concretely be just the escape analysis? - - - // TODO: - // Gary, this is me adding a way to run the escape analysis... - // It is only triggered when flag_ipa_structure_reorg is - // specified since I am not sure what this function should - // concretely do. - // Eric this is not really helping me... ;-) - //DEBUG_L("reorg_analysis: entered\n"); - // Eric, I think is depercated if not correct me. - #if INTEGRATION_FUNCTIONAL - const bool run_escape_analysis = flag_ipa_dead_field_eliminate && !flag_ipa_instance_interleave && !flag_ipa_field_reorder; - if (run_escape_analysis) - { - GimpleTypeCollector collector; - collector.walk(); - ptrset_t types = collector.get_pointer_set(); - GimpleEscaper gimpleEscaper(types); - gimpleEscaper.walk(); - info->sets = gimpleEscaper.get_sets(); - info->sets.print_in_points_to_record(); - return true; - } - #endif struct cgraph_node *node; @@ -1016,9 +985,7 @@ reorg_qualification ( Info *info) // TBD // This only does a generic legality qualification and each // subpass does its own performance qualification. - log("before reorg_leaglity...\n"); unsigned int retval = reorg_legality( info); - log("after reorg_leaglity...\n"); return retval; } @@ -1026,17 +993,14 @@ reorg_qualification ( Info *info) // Return false if nothing qualified bool reorg_legality( Info *info) { - log("before transformation leagality...\n"); bool retval = transformation_legality( info); - log("after transformation leagality...\n"); return retval; } bool Info::is_non_escaping_set_empty() { - bool retval = this->sets.non_escaping.empty(); - return retval; + return true; } // Return false if nothing qualified diff --git a/gcc/ipa-structure-reorg.h b/gcc/ipa-structure-reorg.h index 5c432907607..f8200b845b7 100644 --- a/gcc/ipa-structure-reorg.h +++ b/gcc/ipa-structure-reorg.h @@ -36,7 +36,6 @@ typedef struct RT_Reorder RT_Reorder; typedef struct RT_Interleave RT_Interleave; #include <set> -#include "collect-types.h" struct RT_Elim { int dummy; @@ -173,9 +172,6 @@ struct Info { // Gcc doesn't have global decls readily available // so this holds them std::map <tree,BoolPair_t> *struct_types; // desing bug fix - // ptrset_t holds types which point to records - // and types which escape - ptrset_t sets; int num_deleted; double total_cache_accesses; FILE *reorg_dump_file; diff --git a/gcc/passes.def b/gcc/passes.def index f93c589b124..b12d59acd9b 100644 --- a/gcc/passes.def +++ b/gcc/passes.def @@ -174,7 +174,6 @@ along with GCC; see the file COPYING3. If not see NEXT_PASS (pass_ipa_type_escape_analysis); NEXT_PASS (pass_ipa_field_reorder); NEXT_PASS (pass_ipa_structure_reorg); - NEXT_PASS (pass_ipa_prototype); NEXT_PASS (pass_ipa_pta); NEXT_PASS (pass_omp_simd_clone); TERMINATE_PASS_LIST (all_late_ipa_passes) diff --git a/gcc/tree-pass.h b/gcc/tree-pass.h index 5871c43bb75..a121e139fbd 100644 --- a/gcc/tree-pass.h +++ b/gcc/tree-pass.h @@ -501,7 +501,6 @@ 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_prototype (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); diff --git a/gcc/type-accessor.c b/gcc/type-accessor.c deleted file mode 100644 index a332115d879..00000000000 --- a/gcc/type-accessor.c +++ /dev/null @@ -1,34 +0,0 @@ -#include "type-accessor.hpp" -#include "type-stringifier.hpp" - -void -TypeAccessor::_walk_RECORD_TYPE_pre(const_tree t) -{ - log("type walking\n"); - add_all_fields_in_struct(t); -} - -void -TypeAccessor::add_all_fields_in_struct(const_tree t) -{ - TypeStringifier stringifier; - std::string name = stringifier.stringify(t); - log("am i in add all fields ? %s\n", name.c_str()); - const enum tree_code c = TREE_CODE(t); - const bool is_record = RECORD_TYPE == c; - if (!is_record) return; - - const bool record_already_in_map = _map.find(t) != _map.end(); - field_access_map_t field_map; - field_map = record_already_in_map ? _map[t] : field_map; - - // Let's add all fields to the field map as empty. - for (tree field = TYPE_FIELDS(t); field; field = DECL_CHAIN(field)) - { - const bool field_already_in_map_2 = field_map.find(field) != field_map.end(); - if (field_already_in_map_2) continue; - field_map[field] = Empty; - } - - _map[t] = field_map; -} diff --git a/gcc/type-accessor.hpp b/gcc/type-accessor.hpp deleted file mode 100644 index d86bf287f1a..00000000000 --- a/gcc/type-accessor.hpp +++ /dev/null @@ -1,47 +0,0 @@ -#pragma once - -#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 "expr-accessor.hpp" -#include "type-walker.hpp" - -typedef std::map<const_tree, unsigned> field_access_map_t; -typedef std::map<const_tree, field_access_map_t> record_field_map_t; - -class TypeAccessor : public TypeWalker -{ -public: - TypeAccessor(record_field_map_t &map) : _map(map) { }; -private: - record_field_map_t &_map; - virtual void _walk_RECORD_TYPE_pre(const_tree t) final; - void add_all_fields_in_struct(const_tree t); -}; diff --git a/gcc/type-collector.c b/gcc/type-collector.c deleted file mode 100644 index e5bccb0a34a..00000000000 --- a/gcc/type-collector.c +++ /dev/null @@ -1,271 +0,0 @@ -#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 "type-collector.hpp" -#include "type-stringifier.hpp" -#include "types-inlines.h" - -void -TypeCollector::collect(const_tree t) -{ - const bool in_set = ptrset.in_universe(t); - // memoization... - if (in_set) return; - gcc_assert(t); - - if (!ptr.empty()) - { - TypeStringifier stringifier; - std::string in_name = stringifier.stringify(t); - gcc_unreachable(); - } - walk(t); -} - -void -TypeCollector::_sanity_check() -{ - for (auto i = ptrset.points_to_record.cbegin(), e = ptrset.points_to_record.cend(); i != e; ++i) - { - for (auto j = ptrset.complement.cbegin(), f = ptrset.complement.cend(); j != f; ++j) - { - const_tree type_ptr = *i; - gcc_assert(type_ptr); - const_tree type_com = *j; - gcc_assert(type_com); - const bool valid_sets = type_ptr != type_com; - if (valid_sets) continue; - // Normally, we want a stronger type comparison - // that is not just the pointer address - // but this is the first sanity check and then we will need to determine - // the stronger type comparison. - // But first we will need to fix the types... - TypeStringifier stringifier; - std::string name_ptr = stringifier.stringify(type_ptr); - std::string name_com = stringifier.stringify(type_com); - log("%p %s == %p %s\n", type_ptr, name_ptr.c_str(), type_com, name_com.c_str()); - gcc_unreachable(); - } - } -} - -bool -TypeCollector::is_memoized(const_tree t) -{ - const bool in_set = ptrset.in_universe(t); - if (!in_set) return false; - - const bool points_to_record = ptrset.in_points_to_record(t); - for (auto i = ptr.begin(), e = ptr.end(); i != e; ++i) - { - i->second |= points_to_record; - } - return true; -} - -void -TypeCollector::_walk_VOID_TYPE_pre(const_tree t) -{ - ptr[t] = false; -} - -void -TypeCollector::_walk_VOID_TYPE_post(const_tree t) -{ - _collect_simple(t); -} - -void -TypeCollector::_walk_INTEGER_TYPE_pre(const_tree t) -{ - ptr[t] = false; -} - -void -TypeCollector::_walk_INTEGER_TYPE_post(const_tree t) -{ - _collect_simple(t); -} - -void -TypeCollector::_walk_REAL_TYPE_pre(const_tree t) -{ - ptr[t] = false; -} - -void -TypeCollector::_walk_REAL_TYPE_post(const_tree t) -{ - _collect_simple(t); -} - -void -TypeCollector::_walk_FIXED_POINT_TYPE_pre(const_tree t) -{ - ptr[t] = false; -} - -void -TypeCollector::_walk_FIXED_POINT_TYPE_post(const_tree t) -{ - _collect_simple(t); -} - -void -TypeCollector::_walk_COMPLEX_TYPE_pre(const_tree t) -{ - ptr[t] = false; -} - -void -TypeCollector::_walk_COMPLEX_TYPE_post(const_tree t) -{ - _collect_simple(t); -} - -void -TypeCollector::_walk_ENUMERAL_TYPE_pre(const_tree t) -{ - ptr[t] = false; -} - -void -TypeCollector::_walk_ENUMERAL_TYPE_post(const_tree t) -{ - _collect_simple(t); -} - -void -TypeCollector::_walk_BOOLEAN_TYPE_pre(const_tree t) -{ - ptr[t] = false; -} - -void -TypeCollector::_walk_BOOLEAN_TYPE_post(const_tree t) -{ - _collect_simple(t); -} - -void -TypeCollector::_collect_simple(const_tree t) -{ - ptrset.insert(t, ptr[t]); - ptr.erase(t); -} - -void -TypeCollector::_walk_ARRAY_TYPE_pre(const_tree t) -{ - ptr[t] = false; -} - -void -TypeCollector::_walk_ARRAY_TYPE_post(const_tree t) -{ - _collect_simple(t); -} - -void -TypeCollector::_walk_POINTER_TYPE_pre(const_tree t) -{ - ptr[t] = false; -} - -void -TypeCollector::_walk_POINTER_TYPE_post(const_tree t) -{ - _collect_simple(t); -} - -void -TypeCollector::_walk_REFERENCE_TYPE_pre(const_tree t) -{ - ptr[t] = false; -} - -void -TypeCollector::_walk_REFERENCE_TYPE_post(const_tree t) -{ - _collect_simple(t); -} - -void -TypeCollector::_walk_RECORD_TYPE_post(const_tree t) -{ - // All in ptr point to record - for (auto i = ptr.begin(), e = ptr.end(); i != e; ++i) - { - i->second = true; - } - _collect_simple(t); -} - -void -TypeCollector::_walk_RECORD_TYPE_pre(const_tree t) -{ - ptr[t] = false; -} - -void -TypeCollector::_walk_UNION_TYPE_pre(const_tree t) -{ - ptr[t] = false; -} - -void -TypeCollector::_walk_UNION_TYPE_post(const_tree t) -{ - _collect_simple(t); -} - -void -TypeCollector::_walk_FUNCTION_TYPE_post(const_tree t) -{ - _collect_simple(t); -} - -void -TypeCollector::_walk_FUNCTION_TYPE_pre(const_tree t) -{ - ptr[t] = false; -} - -void -TypeCollector::_walk_METHOD_TYPE_post(const_tree t) -{ - _collect_simple(t); -} - -void -TypeCollector::_walk_METHOD_TYPE_pre(const_tree t) -{ - ptr[t] = false; -} diff --git a/gcc/type-collector.hpp b/gcc/type-collector.hpp deleted file mode 100644 index 0252747ee9a..00000000000 --- a/gcc/type-collector.hpp +++ /dev/null @@ -1,49 +0,0 @@ -#pragma once - -#include "type-walker.hpp" -#include "collect-types.h" -#include <map> -#include <stack> - -class TypeCollector : public TypeWalker { -public: - void collect(const_tree t); - TypeCollector() {}; - ptrset_t get_pointer_set() { _sanity_check(); return ptrset; } -private: - std::map<const_tree, bool> ptr; - ptrset_t ptrset; - void _sanity_check(); - void _collect_simple(const_tree t); - virtual bool is_memoized(const_tree t); - - virtual void _walk_VOID_TYPE_pre(const_tree t); - virtual void _walk_VOID_TYPE_post(const_tree t); - virtual void _walk_INTEGER_TYPE_pre(const_tree t); - virtual void _walk_INTEGER_TYPE_post(const_tree t); - virtual void _walk_REAL_TYPE_pre(const_tree t); - virtual void _walk_REAL_TYPE_post(const_tree t); - virtual void _walk_FIXED_POINT_TYPE_pre(const_tree t); - virtual void _walk_FIXED_POINT_TYPE_post(const_tree t); - virtual void _walk_COMPLEX_TYPE_pre(const_tree t); - virtual void _walk_COMPLEX_TYPE_post(const_tree t); - virtual void _walk_ENUMERAL_TYPE_pre(const_tree t); - virtual void _walk_ENUMERAL_TYPE_post(const_tree t); - virtual void _walk_BOOLEAN_TYPE_pre(const_tree t); - virtual void _walk_BOOLEAN_TYPE_post(const_tree t); - virtual void _walk_ARRAY_TYPE_pre(const_tree t); - virtual void _walk_ARRAY_TYPE_post(const_tree t); - virtual void _walk_POINTER_TYPE_pre(const_tree t); - virtual void _walk_POINTER_TYPE_post(const_tree t); - virtual void _walk_REFERENCE_TYPE_pre(const_tree t); - virtual void _walk_REFERENCE_TYPE_post(const_tree t); - virtual void _walk_RECORD_TYPE_pre(const_tree t); - virtual void _walk_RECORD_TYPE_post(const_tree t); - virtual void _walk_UNION_TYPE_pre(const_tree t); - virtual void _walk_UNION_TYPE_post(const_tree t); - virtual void _walk_FUNCTION_TYPE_pre(const_tree t); - virtual void _walk_FUNCTION_TYPE_post(const_tree t); - virtual void _walk_METHOD_TYPE_pre(const_tree t); - virtual void _walk_METHOD_TYPE_post(const_tree t); -}; - diff --git a/gcc/type-escaper.c b/gcc/type-escaper.c deleted file mode 100644 index 870c2453bba..00000000000 --- a/gcc/type-escaper.c +++ /dev/null @@ -1,231 +0,0 @@ -#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" // needed for gimple-iterator.h -#include "gimple-iterator.h" -#include "gimple-ssa.h" -#include <stdbool.h> -#include "types-inlines.h" - -#include "type-escaper.hpp" -#include "type-stringifier.hpp" - -bool -TypeEscaper::is_memoized(const_tree t) -{ - const bool in_set = calc.find(t) != calc.end(); - if (!in_set) return false; - - const bool will_not_escape = !_reason.is_escaping(); - if (will_not_escape) return true; - - const bool already_escaping = in_set && calc[t].is_escaping(); - if (already_escaping) return true; - - return false; -} - -static inline void -assert_type_is_in_universe(const_tree type, ptrset_t &types) -{ -#ifdef SANITY_CHECKS - gcc_assert(types.in_universe(type)); -#endif -} - -ptrset_t -TypeEscaper::get_sets() -{ - place_escaping_types_in_set(); - return _ptrset; -} - -void -TypeEscaper::place_escaping_types_in_set() -{ - TypeStringifier stringifier; - for (auto i = calc.cbegin(), e = calc.cend(); i != e; ++i) - { - const_tree type = i->first; - // We should have seen it before - assert_type_is_in_universe(type, _ptrset); - - // We should only track interesting types - // Types which are not in points_to_record are the ones - // that are pointed to by records. - // I think it is possible to prune them ahead of time... - if (!_ptrset.in_points_to_record(type)) continue; - - const Reason reason = i->second; - std::string name = stringifier.stringify(type); - reason.is_escaping() ? _ptrset.escaping.insert(type) : _ptrset.non_escaping.insert(type); - } -} - -void -TypeEscaper::update(const_tree t, Reason r) -{ - gcc_assert(t); - _reason = r; - walk(t); -} - -void -TypeEscaper::update_single_level(const_tree t, Reason r) -{ - gcc_assert(t); - const bool already_in_typemap = calc.find(t) != calc.end(); - already_in_typemap ? calc[t] |= r : calc[t] = r; -} - -void -TypeEscaper::_update(const_tree t) -{ - gcc_assert(t); - // assert type is in universe - const bool already_in_typemap = calc.find(t) != calc.end(); - // Do we have to invalidate all types which point to a volatile type? - // Or do we have to invalidate all types pointed to by a volatile type? - // Or do we only invalidate all types which are volatile. - // This is only the third option. - const bool is_volatile = TYPE_VOLATILE(t); - Reason _is_volatile; - _is_volatile.type_is_volatile = is_volatile; - Reason _inner = _reason | _is_volatile; - _inner.type_is_casted = _inside_indirect_field > 0 ? false : _inner.type_is_casted; - if (_inside_function > 0) _inner.type_is_casted = false; - already_in_typemap ? calc[t] |= _inner : calc[t] = _inner; -} - -void -TypeEscaper::_walk_ARRAY_TYPE_pre(const_tree t) -{ - _update(t); -} - -void -TypeEscaper::_walk_POINTER_TYPE_pre(const_tree t) -{ - _inside_indirect_field = _inside_field > 0 ? _inside_indirect_field + 1 : _inside_indirect_field; - _update(t); -} - -void -TypeEscaper::_walk_POINTER_TYPE_post(const_tree t) -{ - _inside_indirect_field = _inside_field > 0 ? _inside_indirect_field - 1 : _inside_indirect_field; -} - -void -TypeEscaper::_walk_REFERENCE_TYPE_pre(const_tree t) -{ - _update(t); -} - -void -TypeEscaper::_walk_RECORD_TYPE_pre(const_tree t) -{ - _update(t); -} - -void -TypeEscaper::_walk_UNION_TYPE_pre(const_tree t) -{ - _inside_union++; - bool is_escaping = _inside_union > 0; - _update(t); - // After us... so that we can see what is our previous value - _reason.type_is_in_union |= is_escaping; -} - -void -TypeEscaper::_walk_field_pre(const_tree t) -{ - _inside_field++; -} - -void -TypeEscaper::_walk_field_post(const_tree t) -{ - _inside_field--; -} - -void -TypeEscaper::_walk_UNION_TYPE_post(const_tree t) -{ - _inside_union--; - Reason prev = calc[t]; - _update(t); - _reason = prev; -} - -void -TypeEscaper::_walk_FUNCTION_TYPE_pre(const_tree t) -{ - _inside_function++; -} - -void -TypeEscaper::_walk_FUNCTION_TYPE_post(const_tree t) -{ - _inside_function--; -} -void -TypeEscaper::_walk_function_or_method(const_tree t) -{ -} - - -void -TypeEscaper::_walk_FUNCTION_TYPE(const_tree t) -{ -} - -void -TypeEscaper::_walk_METHOD_TYPE(const_tree t) -{ -} - - -void -TypeEscaper::_walk_METHOD_TYPE_pre(const_tree t) -{ -} - -void -TypeEscaper::print_reasons() -{ - TypeStringifier stringifier; - for (auto i = calc.cbegin(), e = calc.cend(); i != e; ++i) - { - const_tree t = i->first; - std::string name = stringifier.stringify(t); - const bool in_universe = _ptrset.in_universe(t); - Reason r = i->second; - log("%s reason: ", name.c_str()); - r.print(); - } -} diff --git a/gcc/type-escaper.hpp b/gcc/type-escaper.hpp deleted file mode 100644 index 3647374f716..00000000000 --- a/gcc/type-escaper.hpp +++ /dev/null @@ -1,42 +0,0 @@ -#pragma once - -#include "type-walker.hpp" -#include "ipa-prototype.h" -#include "collect-types.h" -#include <map> - -class TypeEscaper : public TypeWalker -{ -public: - TypeEscaper(ptrset_t &p) : _ptrset(p), _inside_union(0), _inside_field(0), _inside_indirect_field(0), _inside_function(0) {}; - void update(const_tree t, Reason r); - void update_single_level(const_tree t, Reason r); - ptrset_t get_sets(); - ptrset_t &_ptrset; - typemap calc; - void print_reasons(); - virtual void _walk_POINTER_TYPE_pre(const_tree t) final; - virtual void _walk_POINTER_TYPE_post(const_tree t) final; - virtual void _walk_REFERENCE_TYPE_pre(const_tree t) final; - virtual void _walk_ARRAY_TYPE_pre(const_tree t) final; - virtual void _walk_RECORD_TYPE_pre(const_tree t) final; - virtual void _walk_UNION_TYPE_pre(const_tree t) final; - virtual void _walk_UNION_TYPE_post(const_tree t) override final; - virtual void _walk_METHOD_TYPE_pre(const_tree t) final override; - virtual void _walk_FUNCTION_TYPE_pre(const_tree t) final override; - virtual void _walk_FUNCTION_TYPE_post(const_tree t) final override; - virtual void _walk_METHOD_TYPE(const_tree t) final override; - virtual void _walk_FUNCTION_TYPE(const_tree t) final override; - virtual void _walk_function_or_method(const_tree t) final override; - virtual void _walk_field_pre(const_tree t) final; - virtual void _walk_field_post(const_tree t) final; - virtual bool is_memoized(const_tree t); - unsigned _inside_union; - unsigned _inside_field; - unsigned _inside_indirect_field; - unsigned _inside_function; - Reason _reason; - void _update(const_tree t); - void place_escaping_types_in_set(); -}; - diff --git a/gcc/type-incomplete-equality.c b/gcc/type-incomplete-equality.c deleted file mode 100644 index 88072c40022..00000000000 --- a/gcc/type-incomplete-equality.c +++ /dev/null @@ -1,61 +0,0 @@ -#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" // needed for gimple-iterator.h -#include "gimple-iterator.h" -#include "gimple-ssa.h" -#include <stdbool.h> - - -#include "types-inlines.h" -#include "type-structural-equality.hpp" -#include "type-structural-main-variant.hpp" -#include "type-canonical-equality.hpp" -#include "type-incomplete-equality.hpp" -#include "type-stringifier.hpp" - -bool -TypeIncompleteEquality::_equal(const_tree l, const_tree r) -{ - bool valid_inputs = l && r; - if (!valid_inputs) return l == r; - - // if any of these are incomplete, then we can only compare using identifiers... - const bool complete_l = is_complete(l); - const bool complete_r = is_complete(r); - bool can_compare_structurally = complete_l && complete_r; - if (can_compare_structurally) return TypeStructuralEquality::_equal(l, r); - - const_tree m_l = TYPE_MAIN_VARIANT(l); - const_tree m_r = TYPE_MAIN_VARIANT(r); - gcc_assert(m_l && m_r); - can_compare_structurally = m_l == m_r; - if (can_compare_structurally) return true; - - const std::string n_l = TypeStringifier::get_type_identifier(m_l); - const std::string n_r = TypeStringifier::get_type_identifier(m_r); - return n_l.compare(n_r) == 0; -} diff --git a/gcc/type-incomplete-equality.hpp b/gcc/type-incomplete-equality.hpp deleted file mode 100644 index 4188f49713c..00000000000 --- a/gcc/type-incomplete-equality.hpp +++ /dev/null @@ -1,10 +0,0 @@ -#pragma once - -#include "type-canonical-equality.hpp" - -class TypeIncompleteEquality : public TypeCanonicalEquality { -public: - TypeIncompleteEquality () {}; -protected: - virtual bool _equal(const_tree l, const_tree r); -}; diff --git a/gcc/type-reconstructor.c b/gcc/type-reconstructor.c deleted file mode 100644 index 91d4f383ea7..00000000000 --- a/gcc/type-reconstructor.c +++ /dev/null @@ -1,412 +0,0 @@ -#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" // needed for gimple-iterator.h -#include "gimple-iterator.h" -#include "gimple-ssa.h" -#include <stdbool.h> -#include "types-inlines.h" - -#include "type-reconstructor.hpp" -#include "type-stringifier.hpp" -#include "stor-layout.h" - - -// TODO: -// I think it might be possible that we need to create -// new nodes as opposed to copying the nodes. -// I say this because I think the copy is a shallow copy -// and it might be making things difficult if we don't -// know everything that is happening... -// so we might want to rewrite this class... -// -// -// TODO: -// Also, there's a bug in which the TYPE_MAIN_VARIANT is an old type... -// which is not a good thing. - -void -TypeReconstructor::set_is_not_modified_yet(const_tree t) -{ - gcc_assert(t); - const bool is_in_reorg_map = _reorg_map.find(t) != _reorg_map.end(); - modified_map[t] = false; - if (is_in_reorg_map) mark_all_pointing_here_as_modified(); - - const_tree tt = TREE_TYPE(t); - if (!tt) return; - - const bool is_in_reorg_map_2 = _reorg_map.find(tt) != _reorg_map.end(); - log ("is in reorg_map_2 ? %s\n", is_in_reorg_map_2 ? "t" : "f"); - if (!is_in_reorg_map_2) return; - - tree type = _reorg_map[tt]; - const bool is_modified = strstr(TypeStringifier::get_type_identifier(type).c_str(), ".reorg"); - log("is modified %s\n", is_modified ? "t" : "f"); - if (!is_modified) return; - - mark_all_pointing_here_as_modified(); - -} - -void -TypeReconstructor::mark_all_pointing_here_as_modified() -{ - for (auto i = modified_map.begin(), e = modified_map.end(); i != e; ++i) - { - const_tree type = i->first; - i->second = true; - } -} - -bool -TypeReconstructor::get_is_modified(const_tree t) -{ - gcc_assert(t); - const bool in_map = modified_map.find(t) != modified_map.end(); - gcc_assert(in_map); - bool retval = modified_map[t]; - modified_map.erase(t); - - bool points_to_record = false; - tree tt = (tree)t; - while (TREE_TYPE(tt)) - { - tt = TREE_TYPE(tt); - } - points_to_record = TREE_CODE(tt) == RECORD_TYPE; - - - return retval && points_to_record; -} - -bool -TypeReconstructor::is_memoized(const_tree t) -{ - const bool already_changed = _reorg_map.find(t) != _reorg_map.end(); - mark_all_pointing_here_as_modified(); - const bool has_typed_cached_values = TYPE_CACHED_VALUES_P (t); - TypeStringifier stringifier; - std::string name = stringifier.stringify(t); - return already_changed; -} - -static tree -get_new_identifier(const_tree type) -{ - const char* identifier = TypeStringifier::get_type_identifier(type).c_str(); - const bool is_new_type = strstr(identifier, "reorg"); - gcc_assert(!is_new_type); - char *new_name; - asprintf(&new_name, "%s.reorg", identifier); - return get_identifier(new_name); -} - -// Invariant for all _pre functions: -// _reorg_map[t] == NULL (due to memoization) -// -// Invariant for all _post functions: -// _reorg_map[TREE_TYPE(t)] != NULL -// unless TREE_TYPE(t) is not a type which points to a record -// a.k.a. no modifications -// -// To preserve invariant, we must include -// the following at the end of all _post functions: -// _reorg_map[t] = /* reorg type */ -// -// How information is passed? -// To further _post functions via stacks -// -// To previous _post functions via _reorg_map (and maybe others?) -// -// -void -TypeReconstructor::_walk_ARRAY_TYPE_pre(const_tree t) -{ - for_reference.push(t); - set_is_not_modified_yet(t); - - tree copy = build_variant_type_copy((tree) t); - tree domain = TYPE_DOMAIN(t); - if (domain) { - tree copy_domain = copy_node(domain); - tree min = TYPE_MIN_VALUE(domain); - tree max = TYPE_MAX_VALUE(domain); - TYPE_MIN_VALUE(copy_domain) = copy_node(min); - TYPE_MAX_VALUE(copy_domain) = copy_node(max); - } - in_progress.push(copy); - -} - -void -TypeReconstructor::_walk_ARRAY_TYPE_post(const_tree t) -{ - const_tree t2 = for_reference.top(); - gcc_assert(t2 == t); - for_reference.pop(); - tree copy = in_progress.top(); - in_progress.pop(); - - bool is_modified = get_is_modified(t); - - TREE_TYPE(copy) = build_variant_type_copy(TREE_TYPE(copy)); - copy = is_modified ? build_distinct_type_copy(copy) : copy; - 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); - tree domain = TYPE_DOMAIN(t); - if (domain) { - tree copy_domain = copy_node(domain); - tree min = TYPE_MIN_VALUE(domain); - tree max = TYPE_MAX_VALUE(domain); - TYPE_MIN_VALUE(copy_domain) = copy_node(min); - TYPE_MAX_VALUE(copy_domain) = copy_node(max); - } - TypeStringifier stringifier; - //std::string name = stringifier.stringify(copy); - log("are we going to crash is modified %s %s\n", is_modified ? "t" : "f", TypeStringifier::get_type_identifier(copy).c_str()); - if (is_modified) layout_type(copy); - TYPE_CACHED_VALUES_P (copy) = false; - //TYPE_CACHED_VALUES (copy) = TYPE_CACHED_VALUES(t); - tree tt = (tree)t; - while (TREE_TYPE(tt)) { tt = TREE_TYPE(tt); }; - - const bool points_to_record = TREE_CODE(tt) == RECORD_TYPE; - if (!points_to_record) return; - - _reorg_map[t] = is_modified ? copy : (tree)t; -} - -void -TypeReconstructor::_walk_POINTER_TYPE_pre(const_tree t) -{ - for_reference.push(t); - set_is_not_modified_yet(t); - - tree copy = build_variant_type_copy((tree) t); - in_progress.push(copy); -} - -void -TypeReconstructor::_walk_POINTER_TYPE_post(const_tree t) -{ - const_tree t2 = for_reference.top(); - gcc_assert(t2 == t); - for_reference.pop(); - tree copy = in_progress.top(); - in_progress.pop(); - - bool is_modified = get_is_modified(t); - - copy = is_modified ? build_variant_type_copy(copy) : copy; - 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_CACHED_VALUES_P (copy) = false; - //TYPE_CACHED_VALUES (copy) = TYPE_CACHED_VALUES(t); - //Let's just make sure that we are pointing to a a struct... - - tree tt = (tree)t; - while (TREE_TYPE(tt)) { tt = TREE_TYPE(tt); }; - const bool points_to_record = TREE_CODE(tt) == RECORD_TYPE; - if (!points_to_record) return; - - _reorg_map[t] = is_modified ? copy : (tree)t; -} - -void -TypeReconstructor::_walk_RECORD_TYPE_pre(const_tree t) -{ - const bool is_main_variant = TYPE_MAIN_VARIANT(t) == t; - if (!is_main_variant) { - const_tree main_variant = TYPE_MAIN_VARIANT(t); - _walk_RECORD_TYPE_pre(main_variant); - TypeWalker::_walk_RECORD_TYPE(main_variant); - _walk_RECORD_TYPE_post(main_variant); - } - - set_is_not_modified_yet(t); - for_reference.push(t); - // We don't know if we will modify this type t - // So, let's make a copy. Just in case. - tree copy = build_variant_type_copy((tree) t); - in_progress.push(copy); - field_list_stack.push( field_tuple_list_t() ); -} - -void -TypeReconstructor::_walk_RECORD_TYPE_post(const_tree t) -{ - const_tree t2 = for_reference.top(); - gcc_assert(t2 == t); - for_reference.pop(); - - tree copy = in_progress.top(); - in_progress.pop(); - field_tuple_list_t field_tuple_list = field_list_stack.top(); - field_list_stack.pop(); - - // So, here all the work has been done to make sure - // that the fields produced a field_tuple_list_t - // with old fields and pointers to new fields. - // There might be NULL values if new fields are eliminated. - // So, now we want to do a couple of things. - // First, is we need to change the TYPE_FIELDS - // of the copy - bool is_modified = get_is_modified(t); - tree prev_field = NULL; - for (auto i = field_tuple_list.cbegin(), e = field_tuple_list.cend(); i != e; ++i) - { - field_tuple_t field_tuple = *i; - const_tree original_field = field_tuple.first; - tree modified_field = field_tuple.second; - if (!modified_field) { - is_modified = true; - continue; - } - - tree current_field = modified_field; - if (!prev_field) { - TYPE_FIELDS(copy) = current_field; - } else { - DECL_CHAIN(prev_field) = current_field; - } - prev_field = current_field; - } - - // We only had one field - if (!prev_field && is_modified) { - log("deleting all fields for struct %s\n", TypeStringifier::get_type_identifier(copy).c_str()); - TYPE_FIELDS(copy) = NULL; - } - - - const bool is_main_variant = TYPE_MAIN_VARIANT(t) == t; - // We already must have done the main variant... - if (!is_main_variant) - { - tree main = TYPE_MAIN_VARIANT(t); - tree main_reorg = _reorg_map[main]; - TypeStringifier stringifier; - std::string main_s = stringifier.stringify(main_reorg); - log("is modified %s main variant reorged build variant type %s\n", is_modified ? "T" : "F", main_s.c_str()); - tree copy_variant = build_variant_type_copy(main_reorg); - 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 { - // Ok, so now that we have fixed the TYPE_FIELDS of the copy... - // We need to call layout_type - copy = is_modified ? build_distinct_type_copy(copy) : 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); - TYPE_MAIN_VARIANT(copy) = is_modified ? copy : TYPE_MAIN_VARIANT(copy); - tree main_variant = TYPE_MAIN_VARIANT(copy); - TypeStringifier stringifier; - std::string main_s = stringifier.stringify(main_variant); - log("main variant reorged build distinct %s\n", main_s.c_str()); - if (is_modified) layout_type(copy); - _reorg_map[t] = is_modified ? copy : (tree)t; - } - - tree record = _reorg_map[t]; - for (tree field = TYPE_FIELDS(record); field; field = DECL_CHAIN(field)) - { - relayout_decl(field); - } - -} - -void -TypeReconstructor::_walk_UNION_TYPE_pre(const_tree t) -{ -} - -void -TypeReconstructor::_walk_UNION_TYPE_post(const_tree t) -{ -} - -void -TypeReconstructor::_walk_field_pre(const_tree t) -{ - for_reference.push(t); - // We don't know if we will rewrite the field - // that we are working on. So proactively, let's make - // a copy - tree copy = copy_node((tree) t); - tree type_copy = build_variant_type_copy((tree)(TREE_TYPE(t))); - TREE_TYPE(copy) = type_copy; - // To communicate this field to the other methods, - // let's put it in the "in_progress" stack. - in_progress.push(copy); -} - -void -TypeReconstructor::_walk_field_post(const_tree t) -{ - const_tree t2 = for_reference.top(); - gcc_assert(t2 == t); - for_reference.pop(); - - // Let's get the copy we were working on. - tree copy = in_progress.top(); - // Let's put the stack in the same position... - in_progress.pop(); - - // What record does this field belongs to? - const_tree record = for_reference.top(); - - field_offsets_t field_offsets = _records[record]; - // What's the field offset? - unsigned f_byte_offset = tree_to_uhwi(DECL_FIELD_OFFSET(t)); - unsigned f_bit_offset = tree_to_uhwi(DECL_FIELD_BIT_OFFSET(t)); - unsigned f_offset = 8 * f_byte_offset + f_bit_offset; - - const bool can_field_be_deleted = field_offsets.find(f_offset) != field_offsets.end(); - if (can_field_be_deleted) mark_all_pointing_here_as_modified(); - const_tree original_type = TREE_TYPE(t); - const bool type_memoized = is_memoized(original_type); - - TREE_TYPE(copy) = type_memoized ? _reorg_map[original_type] : TREE_TYPE(copy); - - field_tuple_t tuple = std::make_pair(t, can_field_be_deleted ? NULL : copy); - - // Put the field into the vector - field_tuple_list_t &field_tuple_list = field_list_stack.top(); - field_tuple_list.push_back(tuple); - const bool already_has_field = _reorg_fields.find(t) != _reorg_fields.end(); - if (already_has_field) return; - _reorg_fields[t] = std::make_pair(copy, can_field_be_deleted); -} diff --git a/gcc/type-reconstructor.hpp b/gcc/type-reconstructor.hpp deleted file mode 100644 index 4623fc88346..00000000000 --- a/gcc/type-reconstructor.hpp +++ /dev/null @@ -1,47 +0,0 @@ -#pragma once - -#include <set> -#include <map> -#include <stack> -#include <vector> - -#include "type-walker.hpp" - -class TypeReconstructor : public TypeWalker -{ -public: - typedef std::map<const_tree, tree> reorg_record_map_t; - typedef std::map<const_tree, std::pair<tree, bool>> reorg_field_map_t; - typedef std::map<const_tree, bool> is_modified_map_t; - typedef std::set<unsigned> field_offsets_t; - typedef std::map<const_tree, field_offsets_t> record_field_offset_map_t; -private: - std::stack<tree> in_progress; - std::stack<const_tree> for_reference; - typedef std::pair<const_tree, tree> field_tuple_t; - typedef std::vector<field_tuple_t> field_tuple_list_t; - typedef std::stack<field_tuple_list_t> field_tuple_list_stack_t; - record_field_offset_map_t _records; - field_tuple_list_stack_t field_list_stack; - reorg_record_map_t _reorg_map; - reorg_field_map_t _reorg_fields; - is_modified_map_t modified_map; - void set_is_not_modified_yet(const_tree); - void mark_all_pointing_here_as_modified(); - bool get_is_modified(const_tree); - virtual void _walk_field_pre(const_tree); - virtual void _walk_field_post(const_tree); - virtual void _walk_RECORD_TYPE_pre(const_tree); - virtual void _walk_RECORD_TYPE_post(const_tree); - virtual void _walk_UNION_TYPE_pre(const_tree); - virtual void _walk_UNION_TYPE_post(const_tree); - virtual void _walk_ARRAY_TYPE_pre(const_tree); - virtual void _walk_ARRAY_TYPE_post(const_tree); - virtual void _walk_POINTER_TYPE_pre(const_tree); - virtual void _walk_POINTER_TYPE_post(const_tree); -public: - virtual bool is_memoized(const_tree t); - TypeReconstructor(record_field_offset_map_t records) : _records(records) {}; - reorg_record_map_t get_map() { return _reorg_map; }; - reorg_field_map_t get_field_map() { return _reorg_fields; }; -}; diff --git a/gcc/type-stringifier.c b/gcc/type-stringifier.c deleted file mode 100644 index 39e4e0ec9dc..00000000000 --- a/gcc/type-stringifier.c +++ /dev/null @@ -1,246 +0,0 @@ -#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 "type-stringifier.hpp" -#include "types-inlines.h" -#include <string> - -std::string -TypeStringifier::stringify(const_tree t) -{ - _stringification.clear(); - gcc_assert(t); - walk(t); - return _stringification; -} - -void -TypeStringifier::_walk_VOID_TYPE_pre(const_tree t) -{ - _stringify_simple(t); -} - -void -TypeStringifier::_walk_INTEGER_TYPE_pre(const_tree t) -{ - _stringify_simple(t); -} - -void -TypeStringifier::_walk_REAL_TYPE_pre(const_tree t) -{ - _stringify_simple(t); -} - -void -TypeStringifier::_walk_FIXED_POINT_TYPE_pre(const_tree t) -{ - _stringify_simple(t); -} - -void -TypeStringifier::_walk_COMPLEX_TYPE_pre(const_tree t) -{ - _stringify_simple(t); -} - -void -TypeStringifier::_walk_OFFSET_TYPE_pre(const_tree t) -{ - _stringify_simple(t); -} - -void -TypeStringifier::_walk_BOOLEAN_TYPE_pre(const_tree t) -{ - _stringify_simple(t); -} - -void -TypeStringifier::_stringify_simple(const_tree t) -{ - gcc_assert(t); - const enum tree_code code = TREE_CODE(t); - this->_stringification += std::string(get_tree_code_name(code)); -} - -void -TypeStringifier::_walk_POINTER_TYPE_post(__attribute__((unused))const_tree t) -{ - this->_stringification += std::string("*"); -} - -void -TypeStringifier::_walk_ARRAY_TYPE_post(__attribute__((unused))const_tree t) -{ - this->_stringification += std::string("[]"); -} - -void -TypeStringifier::_walk_REFERENCE_TYPE_post(__attribute__((unused))const_tree t) -{ - this->_stringification += std::string("&"); -} - -void -TypeStringifier::_walk_UNION_TYPE_pre(const_tree t) -{ - this->_stringification += std::string(" union "); - _stringify_aggregate_pre(t); -} - -void -TypeStringifier::_walk_UNION_TYPE_post(const_tree t) -{ - _stringify_aggregate_post(t); -} - -void -TypeStringifier::_walk_RECORD_TYPE_pre(const_tree t) -{ - this->_stringification += std::string(" record "); - _stringify_aggregate_pre(t); -} - -void -TypeStringifier::_walk_RECORD_TYPE_post(const_tree t) -{ - _stringify_aggregate_post(t); -} - -void -TypeStringifier::_stringify_aggregate_pre(const_tree t) -{ - this->_stringification += TypeStringifier::get_type_identifier(t) + std::string(" {"); -} - -void -TypeStringifier::_stringify_aggregate_post(__attribute__((unused))const_tree t) -{ - this->_stringification += std::string("}"); -} - -void -TypeStringifier::_walk_field_post(const_tree t) -{ - this->_stringification += std::string(" ") + TypeStringifier::get_field_identifier(t) + std::string(";"); -} - -void -TypeStringifier::_walk_METHOD_TYPE_pre(const_tree t) -{ - _stringify_fm_pre(t); -} - -void -TypeStringifier::_walk_METHOD_TYPE_post(const_tree t) -{ - _stringify_fm_post(t); -} - -void -TypeStringifier::_walk_FUNCTION_TYPE_pre(const_tree t) -{ - _stringify_fm_pre(t); -} - -void -TypeStringifier::_walk_FUNCTION_TYPE_post(const_tree t) -{ - _stringify_fm_post(t); -} - -void -TypeStringifier::_stringify_fm_pre(__attribute__((unused)) const_tree t) -{ - this->_stringification += std::string("function { "); -} - -void -TypeStringifier::_stringify_fm_post(__attribute__((unused))const_tree t) -{ - this->_stringification += std::string("}"); -} - -void -TypeStringifier::_walk_return_pre(__attribute__((unused)) const_tree t) -{ - this->_stringification += std::string("("); -} - -void -TypeStringifier::_walk_return_post(__attribute__((unused)) const_tree t) -{ - this->_stringification += std::string(")"); -} - -void -TypeStringifier::_walk_args_pre(__attribute__((unused)) const_tree t) -{ - this->_stringification += std::string("("); -} - -void -TypeStringifier::_walk_args_post(__attribute__((unused)) const_tree t) -{ - this->_stringification += std::string(")"); -} - -void -TypeStringifier::_walk_arg_post(__attribute__((unused)) const_tree t) -{ - this->_stringification += std::string(", "); -} - -std::string -TypeStringifier::get_type_identifier(const_tree t) -{ - tree name = TYPE_NAME(t); - const bool no_name = NULL_TREE == name; - if (no_name) return std::string(""); - - const enum tree_code name_code = TREE_CODE(name); - const bool is_name_type_decl = TYPE_DECL == name_code; - name = is_name_type_decl ? DECL_NAME(name) : name; - const char* identifier_ptr = IDENTIFIER_POINTER(name); - gcc_assert(identifier_ptr); - return std::string(identifier_ptr); -} - -std::string -TypeStringifier::get_field_identifier(const_tree t) -{ - assert_is_type(t, FIELD_DECL); - const_tree decl_name = DECL_NAME(t); - if (!decl_name) return std::string(""); - - const char* identifier = IDENTIFIER_POINTER(decl_name); - return std::string(identifier); -} diff --git a/gcc/type-stringifier.hpp b/gcc/type-stringifier.hpp deleted file mode 100644 index b2e1261fc62..00000000000 --- a/gcc/type-stringifier.hpp +++ /dev/null @@ -1,48 +0,0 @@ -#pragma once - -#include "type-walker.hpp" -#include <string> - -class TypeStringifier : public TypeWalker -{ -private: - std::string _stringification; - - - void _stringify_simple(const_tree t); - void _stringify_aggregate_pre(const_tree t); - void _stringify_aggregate_post(const_tree t); - void _stringify_fm_pre(const_tree t); - void _stringify_fm_post(const_tree t); - - virtual void _walk_VOID_TYPE_pre(const_tree t); - virtual void _walk_INTEGER_TYPE_pre(const_tree t); - virtual void _walk_REAL_TYPE_pre(const_tree t); - virtual void _walk_FIXED_POINT_TYPE_pre(const_tree t); - virtual void _walk_COMPLEX_TYPE_pre(const_tree t); - virtual void _walk_BOOLEAN_TYPE_pre(const_tree t); - virtual void _walk_OFFSET_TYPE_pre(const_tree t); - virtual void _walk_POINTER_TYPE_post(const_tree t); - virtual void _walk_REFERENCE_TYPE_post(const_tree t); - virtual void _walk_ARRAY_TYPE_post(const_tree t); - virtual void _walk_RECORD_TYPE_pre(const_tree t); - virtual void _walk_RECORD_TYPE_post(const_tree t); - virtual void _walk_UNION_TYPE_pre(const_tree t); - virtual void _walk_UNION_TYPE_post(const_tree t); - virtual void _walk_field_post(const_tree t); - virtual void _walk_return_pre(const_tree t); - virtual void _walk_return_post(const_tree t); - virtual void _walk_args_pre(const_tree t); - virtual void _walk_args_post(const_tree t); - virtual void _walk_arg_post(const_tree t); - virtual void _walk_METHOD_TYPE_pre(const_tree t); - virtual void _walk_METHOD_TYPE_post(const_tree t); - virtual void _walk_FUNCTION_TYPE_pre(const_tree t); - virtual void _walk_FUNCTION_TYPE_post(const_tree t); -public: - static std::string get_type_identifier(const_tree t); - static std::string get_field_identifier(const_tree t); - std::string stringify(const_tree t); - TypeStringifier() {}; -}; - diff --git a/gcc/type-structural-equality.c b/gcc/type-structural-equality.c deleted file mode 100644 index 6195c259158..00000000000 --- a/gcc/type-structural-equality.c +++ /dev/null @@ -1,199 +0,0 @@ -#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" // needed for gimple-iterator.h -#include "gimple-iterator.h" -#include "gimple-ssa.h" -#include <stdbool.h> - - -#include "types-inlines.h" -#include "type-structural-equality.hpp" -#include "type-stringifier.hpp" - -bool -TypeStructuralEquality::equal(const_tree l, const_tree r) -{ - return _equal(l, r); -} - -bool -TypeStructuralEquality::_equal(const_tree l, const_tree r) -{ - bool valid_inputs = l && r; - if (!valid_inputs) return l == r; - - bool equal_codes = _equal_code(l, r); - if (!equal_codes) return equal_codes; - - bool recurse_l = set_l.find(l) != set_l.end(); - bool recurse_r = set_r.find(r) != set_r.end(); - // TODO: Is this the case every time? - bool recurse = recurse_l || recurse_r; - if (recurse) return recurse; - - set_l.insert(l); - set_r.insert(r); - const enum tree_code code = TREE_CODE(l); - bool equal_children = false; - switch(code) - { -#define TSE_CASE(code) \ - case code: \ - equal_children = _walk_ ## code (l, r); \ - break - - TSE_CASE(VOID_TYPE); - TSE_CASE(INTEGER_TYPE); - TSE_CASE(REAL_TYPE); - TSE_CASE(FIXED_POINT_TYPE); - TSE_CASE(COMPLEX_TYPE); - TSE_CASE(ENUMERAL_TYPE); - TSE_CASE(BOOLEAN_TYPE); - TSE_CASE(OFFSET_TYPE); - TSE_CASE(RECORD_TYPE); - TSE_CASE(POINTER_TYPE); - TSE_CASE(REFERENCE_TYPE); - TSE_CASE(ARRAY_TYPE); - TSE_CASE(UNION_TYPE); - TSE_CASE(FUNCTION_TYPE); - TSE_CASE(METHOD_TYPE); - default: - gcc_unreachable(); - break; - } - - set_l.erase(l); - set_r.erase(r); - return equal_children; - -} - -bool -TypeStructuralEquality::_equal_code(const_tree l, const_tree r) -{ - const enum tree_code code_l = TREE_CODE(l); - const enum tree_code code_r = TREE_CODE(r); - const bool equal = code_l == code_r; - return equal; -} - -#define TSE_FUNC_DEF_SIMPLE(code) \ -bool \ -TypeStructuralEquality::_walk_ ## code (const_tree l, const_tree r) \ -{ \ - return _equal_code(l, r); \ -} - -TSE_FUNC_DEF_SIMPLE(VOID_TYPE) -TSE_FUNC_DEF_SIMPLE(INTEGER_TYPE) -TSE_FUNC_DEF_SIMPLE(REAL_TYPE) -TSE_FUNC_DEF_SIMPLE(FIXED_POINT_TYPE) -TSE_FUNC_DEF_SIMPLE(ENUMERAL_TYPE) -TSE_FUNC_DEF_SIMPLE(BOOLEAN_TYPE) -TSE_FUNC_DEF_SIMPLE(OFFSET_TYPE) -TSE_FUNC_DEF_SIMPLE(COMPLEX_TYPE) - -bool -TypeStructuralEquality::_equal_wrapper(const_tree l, const_tree r) -{ - const_tree inner_l = TREE_TYPE(l); - const_tree inner_r = TREE_TYPE(r); - return _equal(inner_l, inner_r); -} - -#define TSE_FUNC_DEF_WRAPPER(code) \ -bool \ -TypeStructuralEquality::_walk_ ## code (const_tree l, const_tree r) \ -{ \ - return _equal_wrapper(l, r); \ -} - -TSE_FUNC_DEF_WRAPPER(REFERENCE_TYPE) -TSE_FUNC_DEF_WRAPPER(ARRAY_TYPE) -TSE_FUNC_DEF_WRAPPER(POINTER_TYPE) - -#define TSE_FUNC_DEF_CONTAINER(code) \ -bool \ -TypeStructuralEquality::_walk_ ## code (const_tree l, const_tree r) \ -{ \ - const_tree field_l = TYPE_FIELDS(l); \ - const_tree field_r = TYPE_FIELDS(r); \ - bool efield_l = field_l; \ - bool efield_r = field_r; \ - bool still_equal = efield_l == efield_r; \ - if (!still_equal) return still_equal; \ - \ - while (field_l && field_r && still_equal) \ - { \ - const_tree tfield_l = TREE_TYPE(field_l); \ - const_tree tfield_r = TREE_TYPE(field_r); \ - still_equal &= _equal(tfield_l, tfield_r); \ - field_l = DECL_CHAIN(field_l); \ - field_r = DECL_CHAIN(field_r); \ - efield_l = field_l; \ - efield_r = field_r; \ - still_equal &= efield_l == efield_r; \ - } \ - return still_equal; \ -} - -TSE_FUNC_DEF_CONTAINER(RECORD_TYPE) -TSE_FUNC_DEF_CONTAINER(UNION_TYPE) - -#define TSE_FUNC_DEF_FUNC(code) \ -bool \ -TypeStructuralEquality::_walk_ ## code (const_tree l, const_tree r) \ -{ \ - const_tree tret_l = TREE_TYPE(l); \ - const_tree tret_r = TREE_TYPE(r); \ - bool still_equal = _equal(tret_l, tret_r); \ - if (!still_equal) return still_equal; \ - \ - const_tree arg_l = TYPE_ARG_TYPES(l); \ - const_tree arg_r = TYPE_ARG_TYPES(r); \ - bool earg_l = arg_l; \ - bool earg_r = arg_r; \ - still_equal &= earg_l == earg_r; \ - while (arg_l && arg_r && still_equal) \ - { \ - const_tree targ_l = TREE_VALUE(arg_l); \ - const_tree targ_r = TREE_VALUE(arg_r); \ - still_equal &= _equal(targ_l, targ_r); \ - arg_l = TREE_CHAIN(arg_l); \ - arg_r = TREE_CHAIN(arg_r); \ - earg_l = arg_l; \ - earg_r = arg_r; \ - still_equal &= earg_l == earg_r; \ - } \ - return still_equal; \ -} - -TSE_FUNC_DEF_FUNC(FUNCTION_TYPE) -TSE_FUNC_DEF_FUNC(METHOD_TYPE) - - - diff --git a/gcc/type-structural-equality.hpp b/gcc/type-structural-equality.hpp deleted file mode 100644 index b5f1944bd31..00000000000 --- a/gcc/type-structural-equality.hpp +++ /dev/null @@ -1,38 +0,0 @@ -#pragma once - -#include <set> - -class TypeStructuralEquality { -public: - TypeStructuralEquality() {}; - bool equal(const_tree a, const_tree b); -protected: - virtual bool _equal(const_tree a, const_tree b); -private: - typedef std::set<const_tree> tset_t; - - tset_t set_l; - tset_t set_r; - bool _equal_code(const_tree a, const_tree b); - bool _equal_wrapper(const_tree a, const_tree b); - -#define TSE_FUNC_DECL(code) \ - virtual bool _walk_ ## code (const_tree l, const_tree r) - TSE_FUNC_DECL(VOID_TYPE); - TSE_FUNC_DECL(COMPLEX_TYPE); - TSE_FUNC_DECL(INTEGER_TYPE); - TSE_FUNC_DECL(REAL_TYPE); - TSE_FUNC_DECL(FIXED_POINT_TYPE); - TSE_FUNC_DECL(POINTER_TYPE); - TSE_FUNC_DECL(ENUMERAL_TYPE); - TSE_FUNC_DECL(BOOLEAN_TYPE); - TSE_FUNC_DECL(OFFSET_TYPE); - TSE_FUNC_DECL(RECORD_TYPE); - TSE_FUNC_DECL(REFERENCE_TYPE); - TSE_FUNC_DECL(ARRAY_TYPE); - TSE_FUNC_DECL(UNION_TYPE); - TSE_FUNC_DECL(FUNCTION_TYPE); - TSE_FUNC_DECL(METHOD_TYPE); - - const_tree left; -}; diff --git a/gcc/type-structural-main-variant.c b/gcc/type-structural-main-variant.c deleted file mode 100644 index 9cc95d5ec63..00000000000 --- a/gcc/type-structural-main-variant.c +++ /dev/null @@ -1,49 +0,0 @@ -#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" // needed for gimple-iterator.h -#include "gimple-iterator.h" -#include "gimple-ssa.h" -#include <stdbool.h> - - -#include "types-inlines.h" -#include "type-structural-equality.hpp" -#include "type-structural-main-variant.hpp" - -bool -TypeStructuralEqualityMainVariant::_equal(const_tree l, const_tree r) -{ - bool valid_inputs = l && r; - if (!valid_inputs) return l == r; - - const_tree mv_l = TYPE_MAIN_VARIANT(l); - const_tree mv_r = TYPE_MAIN_VARIANT(r); - const bool mv_equal = mv_l == mv_r; - if (mv_equal) return mv_equal; - - return TypeStructuralEquality::_equal(l, r); -} diff --git a/gcc/type-structural-main-variant.hpp b/gcc/type-structural-main-variant.hpp deleted file mode 100644 index 2fa00aad350..00000000000 --- a/gcc/type-structural-main-variant.hpp +++ /dev/null @@ -1,10 +0,0 @@ -#pragma once - -#include "type-structural-equality.hpp" - -class TypeStructuralEqualityMainVariant : public TypeStructuralEquality { -public: - TypeStructuralEqualityMainVariant() {}; -protected: - virtual bool _equal(const_tree l, const_tree r); -}; diff --git a/gcc/type-walker.c b/gcc/type-walker.c deleted file mode 100644 index d7554c9e6af..00000000000 --- a/gcc/type-walker.c +++ /dev/null @@ -1,282 +0,0 @@ -#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 "type-walker.hpp" -#include "types-inlines.h" - -void -TypeWalker::walk(const_tree t) -{ - gcc_assert(t); - this->tset.clear(); - this->_walk(t); -} - -void -TypeWalker::_walk(const_tree type) -{ - if (!type) return; - gcc_assert(type); - - // This is an optimization - const bool _is_memoized = is_memoized(type); - if (_is_memoized) return; - - // This is for correctness... - const bool in_set = tset.find(type) != tset.end(); - if (in_set) return; - - tset.insert(type); - const enum tree_code code = TREE_CODE(type); - switch (code) - { - case VOID_TYPE: - this->walk_VOID_TYPE(type); - break; - case INTEGER_TYPE: - this->walk_INTEGER_TYPE(type); - break; - case REAL_TYPE: - this->walk_REAL_TYPE(type); - break; - case FIXED_POINT_TYPE: - this->walk_FIXED_POINT_TYPE(type); - break; - case COMPLEX_TYPE: - this->walk_COMPLEX_TYPE(type); - break; - case ENUMERAL_TYPE: - this->walk_ENUMERAL_TYPE(type); - break; - case BOOLEAN_TYPE: - this->walk_BOOLEAN_TYPE(type); - break; - case OFFSET_TYPE: - this->walk_OFFSET_TYPE(type); - break; - case RECORD_TYPE: - this->walk_RECORD_TYPE(type); - break; - case POINTER_TYPE: - this->walk_POINTER_TYPE(type); - break; - case REFERENCE_TYPE: - this->walk_REFERENCE_TYPE(type); - break; - case ARRAY_TYPE: - this->walk_ARRAY_TYPE(type); - break; - case UNION_TYPE: - this->walk_UNION_TYPE(type); - break; - case FUNCTION_TYPE: - this->walk_FUNCTION_TYPE(type); - break; - case METHOD_TYPE: - this->walk_METHOD_TYPE(type); - break; - case QUAL_UNION_TYPE: - case LANG_TYPE: - default: - { - log("missing %s\n", get_tree_code_name(code)); - gcc_unreachable(); - } - break; - } - - tset.erase(type); -} - - -#define TypeWalkerFuncDef(code) \ -void \ -TypeWalker::walk_ ## code (const_tree t) \ -{ \ - assert_is_type(t, code); \ - _walk_ ## code ## _pre(t); \ - _walk_ ## code (t); \ - _walk_ ## code ## _post(t); \ -} - -#define TypeWalkerFuncDefInternal(code) \ -void TypeWalker::_walk_ ## code (__attribute__((unused)) const_tree t) {} - -TypeWalkerFuncDef(VOID_TYPE) -TypeWalkerFuncDefInternal(VOID_TYPE) -TypeWalkerFuncDef(INTEGER_TYPE) -TypeWalkerFuncDefInternal(INTEGER_TYPE) -TypeWalkerFuncDef(REAL_TYPE) -TypeWalkerFuncDefInternal(REAL_TYPE) -TypeWalkerFuncDef(BOOLEAN_TYPE) -TypeWalkerFuncDefInternal(BOOLEAN_TYPE) -TypeWalkerFuncDef(OFFSET_TYPE) -TypeWalkerFuncDefInternal(OFFSET_TYPE) -TypeWalkerFuncDef(FIXED_POINT_TYPE) -TypeWalkerFuncDefInternal(FIXED_POINT_TYPE) -TypeWalkerFuncDef(COMPLEX_TYPE) -TypeWalkerFuncDefInternal(COMPLEX_TYPE) -TypeWalkerFuncDef(ENUMERAL_TYPE) -TypeWalkerFuncDefInternal(ENUMERAL_TYPE) - -void -TypeWalker::_walk_wrapper(const_tree t) -{ - const_tree inner_type = TREE_TYPE(t); - gcc_assert(inner_type); - _walk(inner_type); -} - -#define TypeWalkerFuncDefWrapper(code) \ -void \ -TypeWalker::_walk_ ## code (const_tree t) \ -{ \ - _walk_wrapper(t); \ -} - -TypeWalkerFuncDef(POINTER_TYPE) -TypeWalkerFuncDefWrapper(POINTER_TYPE) -TypeWalkerFuncDefWrapper(REFERENCE_TYPE) -TypeWalkerFuncDef(REFERENCE_TYPE) -TypeWalkerFuncDef(ARRAY_TYPE) -TypeWalkerFuncDefWrapper(ARRAY_TYPE) - -TypeWalkerFuncDef(RECORD_TYPE) - -void -TypeWalker::_walk_RECORD_TYPE(const_tree t) -{ - _walk_record_or_union(t); -} - -TypeWalkerFuncDef(UNION_TYPE) - -void -TypeWalker::_walk_UNION_TYPE(const_tree t) -{ - _walk_record_or_union(t); -} - -void -TypeWalker::_walk_record_or_union(const_tree t) -{ - for (tree field = TYPE_FIELDS(t); field; field = DECL_CHAIN(field)) - { - gcc_assert(field); - walk_field(field); - } -} - -void -TypeWalker::walk_field(const_tree t) -{ - _walk_field_pre(t); - _walk_field(t); - _walk_field_post(t); -} - -void -TypeWalker::_walk_field(const_tree t) -{ - const_tree inner_type = TREE_TYPE(t); - gcc_assert(inner_type); - _walk(inner_type); -} - -TypeWalkerFuncDef(FUNCTION_TYPE) - -void -TypeWalker::_walk_FUNCTION_TYPE(const_tree t) -{ - _walk_function_or_method(t); -} - -TypeWalkerFuncDef(METHOD_TYPE) - -void -TypeWalker::_walk_METHOD_TYPE(const_tree t) -{ - _walk_function_or_method(t); -} - -void -TypeWalker::_walk_function_or_method(const_tree t) -{ - const_tree ret_type = TREE_TYPE(t); - walk_return(ret_type); - walk_args(t); -} - -void -TypeWalker::walk_return(const_tree t) -{ - _walk_return_pre(t); - _walk_return(t); - _walk_return_post(t); -} - -void -TypeWalker::_walk_return(const_tree t) -{ - _walk(t); -} - -void -TypeWalker::walk_args(const_tree t) -{ - _walk_args_pre(t); - _walk_args(t); - _walk_args_post(t); -} - -void -TypeWalker::_walk_args(const_tree t) -{ - for (tree arg_node = TYPE_ARG_TYPES(t); NULL_TREE != arg_node; arg_node = TREE_CHAIN(arg_node)) - { - const_tree arg_node_type = TREE_VALUE(arg_node); - gcc_assert(arg_node_type); - walk_arg(arg_node_type); - } -} - -void -TypeWalker::walk_arg(const_tree t) -{ - _walk_arg_pre(t); - _walk_arg(t); - _walk_arg_post(t); -} - -void -TypeWalker::_walk_arg(const_tree t) -{ - _walk(t); -} diff --git a/gcc/type-walker.hpp b/gcc/type-walker.hpp deleted file mode 100644 index 60c979481ee..00000000000 --- a/gcc/type-walker.hpp +++ /dev/null @@ -1,50 +0,0 @@ -#pragma once - -#include <set> - -class TypeWalker { -public: - TypeWalker() {}; - void walk(const_tree t); - -protected: - typedef std::set<const_tree> tset_t; - -protected: - tset_t tset; - - void _walk(const_tree t); - void _walk_wrapper(const_tree t); - void _walk_record_or_union(const_tree t); - virtual void _walk_function_or_method(const_tree t); - virtual bool is_memoized(__attribute__((unused))const_tree t) { return false; }; - -#define TypeWalkerFuncDecl(code) \ - virtual void _walk_ ## code ## _pre(const_tree t) {}; \ - virtual void walk_ ## code (const_tree t); \ - virtual void _walk_ ## code (const_tree t); \ - virtual void _walk_ ## code ## _post(const_tree t) {} - - TypeWalkerFuncDecl(VOID_TYPE); - TypeWalkerFuncDecl(INTEGER_TYPE); - TypeWalkerFuncDecl(REAL_TYPE); - TypeWalkerFuncDecl(FIXED_POINT_TYPE); - TypeWalkerFuncDecl(COMPLEX_TYPE); - TypeWalkerFuncDecl(ENUMERAL_TYPE); - TypeWalkerFuncDecl(BOOLEAN_TYPE); - TypeWalkerFuncDecl(OFFSET_TYPE); - TypeWalkerFuncDecl(RECORD_TYPE); - TypeWalkerFuncDecl(POINTER_TYPE); - TypeWalkerFuncDecl(REFERENCE_TYPE); - TypeWalkerFuncDecl(ARRAY_TYPE); - TypeWalkerFuncDecl(UNION_TYPE); - TypeWalkerFuncDecl(FUNCTION_TYPE); - TypeWalkerFuncDecl(METHOD_TYPE); - - // These are not types... - TypeWalkerFuncDecl(field); - TypeWalkerFuncDecl(return); - TypeWalkerFuncDecl(args); - TypeWalkerFuncDecl(arg); -}; - |