diff options
author | Erick Ochoa <erick.ochoa@theobroma-systems.com> | 2020-06-03 11:36:03 +0200 |
---|---|---|
committer | Erick Ochoa <erick.ochoa@theobroma-systems.com> | 2020-09-08 09:00:43 +0200 |
commit | b3108b3a9fb06aa97710cc76273860cd12d2f90f (patch) | |
tree | c391d705c6c2c115a4df2c2e21aafe6395b2d90e | |
parent | 31f1169d34f6a43cc1c65e4fab06157bc1ffabcc (diff) |
stringifier and expression walker
-rw-r--r-- | gcc/Makefile.in | 2 | ||||
-rw-r--r-- | gcc/ipa-hello-world.c | 18 | ||||
-rw-r--r-- | gcc/ipa-type-collector-2.c | 256 | ||||
-rw-r--r-- | gcc/ipa-type-collector-2.hpp | 300 | ||||
-rw-r--r-- | gcc/ipa-type-collector.c | 15 | ||||
-rw-r--r-- | gcc/type-collector.c | 5 | ||||
-rw-r--r-- | gcc/type-collector.hpp | 8 | ||||
-rw-r--r-- | gcc/type-stringifier.c | 246 | ||||
-rw-r--r-- | gcc/type-stringifier.hpp | 212 | ||||
-rw-r--r-- | gcc/type-walker.c | 9 |
10 files changed, 564 insertions, 507 deletions
diff --git a/gcc/Makefile.in b/gcc/Makefile.in index c14e25752af..887d834c1e8 100644 --- a/gcc/Makefile.in +++ b/gcc/Makefile.in @@ -1412,8 +1412,10 @@ OBJS = \ ipa-hello-world.o \ ipa-escape-analysis.o \ ipa-type-collector.o \ + ipa-type-collector-2.o \ type-walker.o \ type-collector.o \ + type-stringifier.o \ compare-types.o \ collect-types.o \ name-types.o \ diff --git a/gcc/ipa-hello-world.c b/gcc/ipa-hello-world.c index 6d31926eab1..914ffaed768 100644 --- a/gcc/ipa-hello-world.c +++ b/gcc/ipa-hello-world.c @@ -36,6 +36,7 @@ #include "ipa-type-collector.h" #include "ipa-hello-world.h" #include "type-collector.hpp" +#include "type-stringifier.hpp" #include <map> #include <vector> @@ -101,11 +102,12 @@ update_typemap(const_tree type, ptrset_t &types, Reason reason, typemap &calc) { gcc_assert(type); assert_type_is_in_universe(type, types); - assert_type_is_in_ptrset(type, types); const bool already_in_typemap = calc.find(type) != calc.end(); already_in_typemap ? calc[type] |= reason : calc[type] = reason; - log("updating %s\n", type_to_string(type).c_str()); - reason.print(); + //TypeStringifier stringifier; + //std::string name = stringifier.stringify(type); + //log("updating %s\n", name.c_str()); + //reason.print(); } static void update_escape_info( const_tree type, ptrset_t &types, Reason reason, typemap &calc); @@ -909,8 +911,13 @@ place_escaping_types_in_set(ptrset_t &types, typemap &calc) const_tree type = i->first; // We should have seen it before assert_type_is_in_universe(type, types); + // We should only track interesting types - assert_type_is_in_ptrset(type, 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); } @@ -1043,10 +1050,9 @@ iphw_execute() calculate_escaping_types(types, eacalc); place_escaping_types_in_set(types, eacalc); fix_escaping_types_in_set(types); + print_escaping_types_in_set(types); //sanity_check_escape_xor_not(types); //sanity_check_escape_union_not_equals_ptrset(types); - print_escaping_types_in_set(types); - //gcc_assert(false); return 0; } diff --git a/gcc/ipa-type-collector-2.c b/gcc/ipa-type-collector-2.c new file mode 100644 index 00000000000..986aa3df926 --- /dev/null +++ b/gcc/ipa-type-collector-2.c @@ -0,0 +1,256 @@ +#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 "ipa-type-collector-2.hpp" +#include "types-inlines.h" + +void +ExprWalker::walk(const_tree e) +{ + _walk(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; + default: + gcc_unreachable(); + break; + } +} + +#define ExprWalkerFuncDef(code) \ +void \ +ExprWalker::walk_ ## code (const_tree e) \ +{ \ + assert_is_type(e, code); \ + _walk_ ## code ## _pre (e); \ + _walk_ ## code (e); \ + _walk_ ## code ## _post (e); \ +} + +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) + +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, 1); +} + +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); +} diff --git a/gcc/ipa-type-collector-2.hpp b/gcc/ipa-type-collector-2.hpp index 07c773a69fe..d2663e996d1 100644 --- a/gcc/ipa-type-collector-2.hpp +++ b/gcc/ipa-type-collector-2.hpp @@ -3,293 +3,39 @@ #include "types-inlines.h" -template<class T> class ExprWalker { public: ExprWalker() {}; void walk(const_tree e); private: - T typeWalker; - void _walk(const_tree e, T& t); - inline void _walk_leaf(const_tree e, T& t, const enum tree_code c); - inline void _walk_op_n(const_tree e, T& t, unsigned n); - inline void _walk_op_0(const_tree e, T& t, const enum tree_code c); - inline void _walk_op_1(const_tree e, T& t, const enum tree_code c); + void _walk(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) \ inline virtual void _walk_ ## code ## _pre(const_tree e) {}; \ - void walk_ ## code (const_tree e, T& t); \ - void _walk_ ## code (const_tree e, T& t); \ + void walk_ ## code (const_tree e); \ + void _walk_ ## code (const_tree e); \ inline virtual void _walk_ ## code ##_post(const_tree e) {} - 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(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); }; -template <class T> -void -ExprWalker<T>::walk(const_tree e) -{ - _walk(e, typeWalker); -} - -template <class T> -void -ExprWalker<T>::_walk(const_tree e, T& t) -{ - gcc_assert(e); - const enum tree_code code = TREE_CODE(e); - switch (code) - { - case INTEGER_CST: - walk_integer_cst(e, t); - break; - case REAL_CST: - walk_real_cst(e, t); - break; - case STRING_CST: - walk_string_cst(e, t); - break; - case BIT_FIELD_REF: - walk_bit_field_ref(e, t); - break; - case ARRAY_REF: - walk_array_ref(e, t); - break; - case MEM_REF: - walk_mem_ref(e, t); - break; - case COMPONENT_REF: - walk_component_ref(e, t); - break; - case SSA_NAME: - walk_ssa_name(e, t); - break; - case ADDR_EXPR: - walk_addr_expr(e, t); - break; - case VIEW_CONVERT_EXPR: - walk_view_convert_expr(e, t); - break; - case IMAGPART_EXPR: - walk_imagpart_expr(e, t); - break; - case VAR_DECL: - walk_var_decl(e, t); - break; - case FIELD_DECL: - walk_field_decl(e, t); - break; - case RESULT_DECL: - walk_result_decl(e, t); - break; - case PARM_DECL: - walk_parm_decl(e, t); - break; - case FUNCTION_DECL: - walk_function_decl(e, t); - break; - default: - gcc_unreachable(); - break; - } -} - -#define ExprWalkerFuncDef(code) \ -template <class T> \ -void \ -ExprWalker<T>::walk_ ## code (const_tree e, T& t) \ -{ \ - _walk_ ## code ## _pre (e); \ - _walk_ ## code (e, t); \ - _walk_ ## code ## _post (e); \ -} - -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) - -template <class T> -void -ExprWalker<T>::_walk_leaf(const_tree e, T& t, const enum tree_code c) -{ - assert_is_type(e, c); - const_tree type = TREE_TYPE(e); - gcc_assert(type); - t.walk(type); -} - -template <class T> -void -ExprWalker<T>::_walk_op_n(const_tree e, T& t, unsigned n) -{ - gcc_assert(e); - const_tree op_n = TREE_OPERAND(e, n); - gcc_assert(op_n); - _walk(op_n, t); -} - -template <class T> -void -ExprWalker<T>::_walk_op_0(const_tree e, T& t, const enum tree_code c) -{ - assert_is_type(e, c); - _walk_op_n(e, t, 0); -} - -template <class T> -void -ExprWalker<T>::_walk_op_1(const_tree e, T& t, const enum tree_code c) -{ - assert_is_type(e, c); - _walk_op_n(e, t, 1); -} - -template<class T> -void -ExprWalker<T>::_walk_integer_cst(const_tree e, T& t) -{ - _walk_leaf(e, t, INTEGER_CST); -} - -template<class T> -void -ExprWalker<T>::_walk_real_cst(const_tree e, T& t) -{ - _walk_leaf(e, t, REAL_CST); -} - -template<class T> -void -ExprWalker<T>::_walk_string_cst(const_tree e, T& t) -{ - _walk_leaf(e, t, STRING_CST); -} - -template<class T> -void -ExprWalker<T>::_walk_bit_field_ref(const_tree e, T& t) -{ -#ifdef FUZZ_MODE - gcc_unreachable(); -#endif -} - -template<class T> -void -ExprWalker<T>::_walk_array_ref(const_tree e, T& t) -{ - _walk_op_1(e, t, ARRAY_REF); -} - -template<class T> -void -ExprWalker<T>::_walk_mem_ref(const_tree e, T& t) -{ - _walk_op_1(e, t, MEM_REF); -} - -template<class T> -void -ExprWalker<T>::_walk_component_ref(const_tree e, T& t) -{ - _walk_op_1(e, t, COMPONENT_REF); -} - -template <class T> -void -ExprWalker<T>::_walk_ssa_name(const_tree e, T &t) -{ - _walk_leaf(e, t, SSA_NAME); -} - -template <class T> -void -ExprWalker<T>::_walk_addr_expr(const_tree e, T &t) -{ - _walk_op_0(e, t, ADDR_EXPR); -} - -template <class T> -void -ExprWalker<T>::_walk_view_convert_expr(const_tree e, T &t) -{ -#ifdef FUZZ_MODE - gcc_unreachable(); -#endif -} - -template <class T> -void -ExprWalker<T>::_walk_imagpart_expr(const_tree e, T &t) -{ -#ifdef FUZZ_MODE - gcc_unreachable(); -#endif -} - -template <class T> -void -ExprWalker<T>::_walk_field_decl(const_tree e, T &t) -{ - _walk_leaf(e, t, FIELD_DECL); -} - -template <class T> -void -ExprWalker<T>::_walk_var_decl(const_tree e, T &t) -{ - _walk_leaf(e, t, VAR_DECL); -} - -template <class T> -void -ExprWalker<T>::_walk_result_decl(const_tree e, T &t) -{ - _walk_leaf(e, t, RESULT_DECL); -} - -template <class T> -void -ExprWalker<T>::_walk_parm_decl(const_tree e, T &t) -{ - _walk_leaf(e, t, PARM_DECL); -} - -template <class T> -void -ExprWalker<T>::_walk_function_decl(const_tree e, T &t) -{ - assert_is_type(e, FUNCTION_DECL); - const_tree decl_type = TREE_TYPE(e); - gcc_assert(decl_type); - t.walk(decl_type); -} diff --git a/gcc/ipa-type-collector.c b/gcc/ipa-type-collector.c index d89737e1a1a..3601a96e48e 100644 --- a/gcc/ipa-type-collector.c +++ b/gcc/ipa-type-collector.c @@ -35,6 +35,7 @@ #include "collect-types.h" #include "name-types.h" +#include "type-stringifier.hpp" #include "ipa-type-collector.h" #include "type-collector.hpp" @@ -779,8 +780,18 @@ sanity_check_ptr_xor_complement(ptrset_t &types) gcc_assert(type_ptr); const_tree type_com = *j; gcc_assert(type_com); - const bool valid_sets = !eq_type_compare(type_ptr, type_com); - gcc_assert(valid_sets); + 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(); } } } diff --git a/gcc/type-collector.c b/gcc/type-collector.c index af8778b8554..53c9e313ee6 100644 --- a/gcc/type-collector.c +++ b/gcc/type-collector.c @@ -29,6 +29,8 @@ #include "gimple-ssa.h" #include "type-collector.hpp" +#include "type-stringifier.hpp" +#include "types-inlines.h" void TypeCollector::collect(const_tree t) @@ -36,7 +38,6 @@ TypeCollector::collect(const_tree t) const bool in_set = ptrset->in_universe(t); // memoization... if (in_set) return; - this->_points_to_record = false; gcc_assert(ptrset && t); gcc_assert(ptr.size() == 0); walk(t); @@ -51,7 +52,7 @@ TypeCollector::is_memoized(const_tree t) const bool points_to_record = ptrset->in_points_to_record(t); for (auto i = ptr.begin(), e = ptr.end(); i != e; ++i) { - i->second = true; + i->second |= points_to_record; } return true; } diff --git a/gcc/type-collector.hpp b/gcc/type-collector.hpp index 425b54c5062..98b08d99f83 100644 --- a/gcc/type-collector.hpp +++ b/gcc/type-collector.hpp @@ -3,12 +3,15 @@ #include "type-walker.hpp" #include "collect-types.h" #include <map> +#include <stack> class TypeCollector : public TypeWalker { public: + void collect(const_tree t); + TypeCollector() {}; + static ptrset_t* ptrset; private: - bool _points_to_record; std::map<const_tree, bool> ptr; void _collect_simple(const_tree t); @@ -42,8 +45,5 @@ private: virtual void _walk_function_post(const_tree t); virtual void _walk_method_pre(const_tree t); virtual void _walk_method_post(const_tree t); -public: - void collect(const_tree t); - TypeCollector() : _points_to_record(false) {}; }; diff --git a/gcc/type-stringifier.c b/gcc/type-stringifier.c new file mode 100644 index 00000000000..3b2a50604e0 --- /dev/null +++ b/gcc/type-stringifier.c @@ -0,0 +1,246 @@ +#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_pre(const_tree t) +{ + _stringify_simple(t); +} + +void +TypeStringifier::_walk_integer_pre(const_tree t) +{ + _stringify_simple(t); +} + +void +TypeStringifier::_walk_real_pre(const_tree t) +{ + _stringify_simple(t); +} + +void +TypeStringifier::_walk_fixed_point_pre(const_tree t) +{ + _stringify_simple(t); +} + +void +TypeStringifier::_walk_complex_pre(const_tree t) +{ + _stringify_simple(t); +} + +void +TypeStringifier::_walk_offset_pre(const_tree t) +{ + _stringify_simple(t); +} + +void +TypeStringifier::_walk_boolean_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_post(const_tree t) +{ + this->_stringification += std::string("*"); +} + +void +TypeStringifier::_walk_array_post(const_tree t) +{ + this->_stringification += std::string("[]"); +} + +void +TypeStringifier::_walk_reference_post(const_tree t) +{ + this->_stringification += std::string("&"); +} + +void +TypeStringifier::_walk_union_pre(const_tree t) +{ + this->_stringification += std::string(" union "); + _stringify_aggregate_pre(t); +} + +void +TypeStringifier::_walk_union_post(const_tree t) +{ + _stringify_aggregate_post(t); +} + +void +TypeStringifier::_walk_record_pre(const_tree t) +{ + this->_stringification += std::string(" record "); + _stringify_aggregate_pre(t); +} + +void +TypeStringifier::_walk_record_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(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_pre(const_tree t) +{ + _stringify_fm_pre(t); +} + +void +TypeStringifier::_walk_method_post(const_tree t) +{ + _stringify_fm_post(t); +} + +void +TypeStringifier::_walk_function_pre(const_tree t) +{ + _stringify_fm_pre(t); +} + +void +TypeStringifier::_walk_function_post(const_tree t) +{ + _stringify_fm_post(t); +} + +void +TypeStringifier::_stringify_fm_pre(const_tree t) +{ + this->_stringification += std::string("function { "); +} + +void +TypeStringifier::_stringify_fm_post(const_tree t) +{ + this->_stringification += std::string("}"); +} + +void +TypeStringifier::_walk_return_pre(const_tree t) +{ + this->_stringification += std::string("("); +} + +void +TypeStringifier::_walk_return_post(const_tree t) +{ + this->_stringification += std::string(")"); +} + +void +TypeStringifier::_walk_args_pre(const_tree t) +{ + this->_stringification += std::string("("); +} + +void +TypeStringifier::_walk_args_post(const_tree t) +{ + this->_stringification += std::string(")"); +} + +void +TypeStringifier::_walk_arg_post(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 index 98e0546b8d7..49e9054ab5e 100644 --- a/gcc/type-stringifier.hpp +++ b/gcc/type-stringifier.hpp @@ -46,215 +46,3 @@ public: TypeStringifier() {}; }; -std::string -TypeStringifier::stringify(const_tree t) -{ - _stringification.clear(); - gcc_assert(t); - walk(t); - return _stringification; -} - -void -TypeStringifier::_walk_void_pre(const_tree t) -{ - _stringify_simple(t); -} - -void -TypeStringifier::_walk_integer_pre(const_tree t) -{ - _stringify_simple(t); -} - -void -TypeStringifier::_walk_real_pre(const_tree t) -{ - _stringify_simple(t); -} - -void -TypeStringifier::_walk_fixed_point_pre(const_tree t) -{ - _stringify_simple(t); -} - -void -TypeStringifier::_walk_complex_pre(const_tree t) -{ - _stringify_simple(t); -} - -void -TypeStringifier::_walk_offset_pre(const_tree t) -{ - _stringify_simple(t); -} - -void -TypeStringifier::_walk_boolean_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_post(const_tree t) -{ - this->_stringification += std::string("*"); -} - -void -TypeStringifier::_walk_array_post(const_tree t) -{ - this->_stringification += std::string("[]"); -} - -void -TypeStringifier::_walk_reference_post(const_tree t) -{ - this->_stringification += std::string("&"); -} - -void -TypeStringifier::_walk_union_pre(const_tree t) -{ - this->_stringification += std::string(" union "); - _stringify_aggregate_pre(t); -} - -void -TypeStringifier::_walk_union_post(const_tree t) -{ - _stringify_aggregate_post(t); -} - -void -TypeStringifier::_walk_record_pre(const_tree t) -{ - this->_stringification += std::string(" record "); - _stringify_aggregate_pre(t); -} - -void -TypeStringifier::_walk_record_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(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_pre(const_tree t) -{ - _stringify_fm_pre(t); -} - -void -TypeStringifier::_walk_method_post(const_tree t) -{ - _stringify_fm_post(t); -} - -void -TypeStringifier::_walk_function_pre(const_tree t) -{ - _stringify_fm_pre(t); -} - -void -TypeStringifier::_walk_function_post(const_tree t) -{ - _stringify_fm_post(t); -} - -void -TypeStringifier::_stringify_fm_pre(const_tree t) -{ - this->_stringification += std::string("function { "); -} - -void -TypeStringifier::_stringify_fm_post(const_tree t) -{ - this->_stringification += std::string("}"); -} - -void -TypeStringifier::_walk_return_pre(const_tree t) -{ - this->_stringification += std::string("("); -} - -void -TypeStringifier::_walk_return_post(const_tree t) -{ - this->_stringification += std::string(")"); -} - -void -TypeStringifier::_walk_args_pre(const_tree t) -{ - this->_stringification += std::string("("); -} - -void -TypeStringifier::_walk_args_post(const_tree t) -{ - this->_stringification += std::string(")"); -} - -void -TypeStringifier::_walk_arg_post(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-walker.c b/gcc/type-walker.c index df672d8bdf0..5b5d3520f19 100644 --- a/gcc/type-walker.c +++ b/gcc/type-walker.c @@ -43,14 +43,15 @@ void TypeWalker::_walk(const_tree type, tset_t &tset) { gcc_assert(type); - // Have we encountered this type before? If so, we are likely - // recurring... - const bool in_set = tset.find(type) != tset.end(); - if (in_set) return; + // 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) |