Changeset 35cd219


Ignore:
Timestamp:
Feb 14, 2017, 3:58:01 PM (7 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
cf97ccb, efd60d67
Parents:
9bb90a86 (diff), e58dfb9 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

Location:
src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/CodeTools/DeclStats.cc

    r9bb90a86 r35cd219  
    1818#include <iostream>
    1919#include <map>
     20#include <sstream>
    2021#include <string>
    2122#include <unordered_map>
     
    7172                                return *this;
    7273                        }
    73 
    74                         /// Update based on a declaration list
    75                         ArgPackStats& operator+= ( std::list<DeclarationWithType*>& decls ) {
    76                                 unsigned nn = 0;
    77                                 unsigned nn_basic = 0;
    78                                 unsigned nn_poly = 0;
    79                                 for ( auto decl : decls ) {
    80                                         nn += decl->get_type()->size();
    81                                         if ( dynamic_cast<BasicType*>( decl->get_type() ) ) ++nn_basic;
    82                                         else if ( GenPoly::hasPolyBase( decl->get_type() ) ) ++nn_poly;
    83                                 }
    84                                 ++n.at( nn );
    85                                 ++n_basic.at( nn_basic );
    86                                 ++n_poly.at( nn_poly );
    87                                 if ( nn > 0 ) {
    88                                         ++p_basic[ nn_basic*100/nn ];
    89                                         ++p_poly[ nn_poly*100/nn ];
    90                                 }
    91                                
    92                                 return *this;
    93                         }
    9474                };
    9575               
     
    10080                        /// Count of declarations with each name
    10181                        std::unordered_map<std::string, unsigned> by_name;
     82                        /// Count of uses of each basic type
     83                        std::unordered_map<std::string, unsigned> basic_type_names;
     84                        /// Count of uses of each non-basic type
     85                        std::unordered_map<std::string, unsigned> compound_type_names;
    10286                        /// Stats for the parameter list
    10387                        ArgPackStats params;
     
    11296                        ArgPackStats assn_returns;
    11397                       
    114                         Stats() : n_decls(0), n_type_params(), by_name(), params(), returns(), n_assns(), assn_params(), assn_returns() {}
     98                        Stats() : n_decls(0), n_type_params(), by_name(), basic_type_names(), compound_type_names(), params(), returns(), n_assns(), assn_params(), assn_returns() {}
    11599
    116100                public:
     
    119103                                sum( n_type_params, o.n_type_params );
    120104                                sum( by_name, o.by_name );
     105                                sum( basic_type_names, o.basic_type_names );
     106                                sum( compound_type_names, o.compound_type_names );
    121107                                sum( params, o.params );
    122108                                sum( returns, o.returns );
     
    133119                Stats total;
    134120
    135                 void analyzeFunc( FunctionType* fnTy, ArgPackStats& params, ArgPackStats& returns ) {
    136                         params += fnTy->get_parameters();
    137                         returns += fnTy->get_returnVals();
     121                /// Update arg pack stats based on a declaration list
     122                void analyze( Stats& stats, ArgPackStats& pstats, std::list<DeclarationWithType*>& decls ) {
     123                        unsigned n = 0;
     124                        unsigned n_basic = 0;
     125                        unsigned n_poly = 0;
     126                        for ( auto decl : decls ) {
     127                                n += decl->get_type()->size();
     128                                if ( BasicType* bt = dynamic_cast<BasicType*>( decl->get_type() ) ) {
     129                                        ++n_basic;
     130                                        std::stringstream ss;
     131                                        bt->print( ss );
     132                                        ++stats.basic_type_names[ ss.str() ];
     133                                } else if ( GenPoly::hasPolyBase( decl->get_type() ) ) {
     134                                        ++n_poly;
     135                                } else {
     136                                        std::stringstream ss;
     137                                        decl->get_type()->print( ss );
     138                                        ++stats.compound_type_names[ ss.str() ];
     139                                }
     140                        }
     141                        ++pstats.n.at( n );
     142                        ++pstats.n_basic.at( n_basic );
     143                        ++pstats.n_poly.at( n_poly );
     144                        if ( n > 0 ) {
     145                                ++pstats.p_basic[ n_basic*100/n ];
     146                                ++pstats.p_poly[ n_poly*100/n ];
     147                        }
     148                }
     149               
     150                void analyzeFunc( FunctionType* fnTy, Stats& stats, ArgPackStats& params, ArgPackStats& returns ) {
     151                        analyze( stats, params, fnTy->get_parameters() );
     152                        analyze( stats, returns, fnTy->get_returnVals() );
    138153                }
    139154
     
    164179                                                assnTy = assnDecl->get_functionType();
    165180                                        }
    166                                         if ( assnTy ) analyzeFunc( assnTy, stats.assn_params, stats.assn_returns );
     181                                        if ( assnTy ) analyzeFunc( assnTy, stats, stats.assn_params, stats.assn_returns );
    167182                                }
    168183                        }
     
    171186                        ++stats.by_name[ decl->get_name() ];
    172187
    173                         analyzeFunc( fnTy, stats.params, stats.returns );
     188                        analyzeFunc( fnTy, stats, stats.params, stats.returns );
    174189                }
    175190
     
    266281                        printAll("unique_names", [](const Stats& stats) { return stats.by_name.size(); });
    267282                        printAllSparseHisto("overloads", [](const Stats& stats) { return stats.by_name; });
     283                        printAll("basic_type_names", [](const Stats& stats) { return stats.basic_type_names.size(); });
     284                        printAllSparseHisto("basic_type_uses", [](const Stats& stats) { return stats.basic_type_names; });
     285                        printAll("compound_type_names", [](const Stats& stats) { return stats.compound_type_names.size(); });
     286                        printAllSparseHisto("compound_type_uses", [](const Stats& stats) { return stats.compound_type_names; });
    268287                        printAllPack("params", [](const Stats& stats) { return stats.params; });
    269288                        printAllPack("returns", [](const Stats& stats) { return stats.returns; });
  • src/Common/ScopedMap.h

    r9bb90a86 r35cd219  
    230230        }
    231231
     232        /// Finds the given key in the provided scope; returns end() for none such
     233        iterator findAt( size_type scope, const Key& key ) {
     234                typename Scope::iterator val = scopes[scope].find( key );
     235                if ( val != scopes[scope].end() ) return iterator( scopes, val, scope );
     236                return end();
     237        }
     238        const_iterator findAt( size_type scope, const Key& key ) const {
     239                return const_iterator( const_cast< ScopedMap< Key, Value >* >(this)->findAt( scope, key ) );
     240        }
     241
    232242        /// Finds the given key in the outermost scope inside the given scope where it occurs
    233243        iterator findNext( const_iterator &it, const Key &key ) {
  • src/Common/VectorMap.h

    r9bb90a86 r35cd219  
    3838        typedef const const_value_type* const_pointer;
    3939       
    40         class iterator : public std::iterator< std::bidirectional_iterator_tag,
     40        class iterator : public std::iterator< std::random_access_iterator_tag,
    4141                                               value_type,
    42                                                                                     difference_type,
    43                                                                                         pointer,
    44                                                                                         reference > {
     42                                                                                   difference_type,
     43                                                                                   pointer,
     44                                                                                   reference > {
    4545        friend class VectorMap;
    4646        friend class const_iterator;
     
    7474                iterator operator-- (int) { iterator tmp = *this; --(*this); return tmp; }
    7575
     76                iterator& operator+= (difference_type i) {
     77                        // SHENANIGANS: same reasons as operator++
     78                        new(&data) value_type{ (data.first + i), *(&data.second + i) };
     79                        return *this;
     80                }
     81
     82                iterator operator+ (difference_type i) const { iterator tmp = *this; return tmp += i; }
     83
     84                iterator& operator-= (difference_type i) {
     85                        // SHENANIGANS: same reasons as operator++
     86                        new(&data) value_type{ (data.first - i), *(&data.second - i) };
     87                        return *this;
     88                }
     89
     90                iterator operator- (difference_type i) const { iterator tmp = *this; return tmp -= i; }
     91
     92                difference_type operator- (const iterator& o) const { return data.first - o.data.first; }
     93
     94                value_type operator[] (difference_type i) const {
     95                        // SHENANIGANS: same reasons as operator++
     96                        return value_type{ (data.first + i), *(&data.second + i) };
     97                }
     98
    7699                bool operator== (const iterator& o) const {
    77100                        return data.first == o.data.first && &data.second == &o.data.second;
    78101                }
     102               
    79103                bool operator!= (const iterator& that) const { return !(*this == that); }
     104
     105                bool operator< (const iterator& o) const { return data.first < o.data.first; }
     106
     107                bool operator> (const iterator& o) const { return data.first > o.data.first; }
     108
     109                bool operator<= (const iterator& o) const { return data.first <= o.data.first; }
     110
     111                bool operator>= (const iterator& o) const { return data.first >= o.data.first; }
    80112        };
    81113
     
    118150                const_iterator operator-- (int) { const_iterator tmp = *this; --(*this); return tmp; }
    119151
     152                const_iterator& operator+= (difference_type i) {
     153                        // SHENANIGANS: same reasons as iterator::operator++
     154                        new(&data) const_value_type{ (data.first + i), *(&data.second + i) };
     155                        return *this;
     156                }
     157
     158                const_iterator operator+ (difference_type i) const {
     159                        const_iterator tmp = *this; return tmp += i;
     160                }
     161
     162                const_iterator& operator-= (difference_type i) {
     163                        // SHENANIGANS: same reasons as iterator::operator++
     164                        new(&data) const_value_type{ (data.first - i), *(&data.second - i) };
     165                        return *this;
     166                }
     167
     168                const_iterator operator- (difference_type i) const {
     169                        const_iterator tmp = *this; return tmp -= i;
     170                }
     171
     172                difference_type operator- (const const_iterator& o) const {
     173                        return data.first - o.data.first;
     174                }
     175
     176                const_value_type operator[] (difference_type i) const {
     177                        // SHENANIGANS: same reasons as iterator::operator++
     178                        return const_value_type{ (data.first + i), *(&data.second + i) };
     179                }
     180
    120181                bool operator== (const const_iterator& o) const {
    121182                        return data.first == o.data.first && &data.second == &o.data.second;
    122183                }
     184               
    123185                bool operator!= (const const_iterator& that) const { return !(*this == that); }
     186
     187                bool operator< (const const_iterator& o) const { return data.first < o.data.first; }
     188
     189                bool operator> (const const_iterator& o) const { return data.first > o.data.first; }
     190
     191                bool operator<= (const const_iterator& o) const { return data.first <= o.data.first; }
     192
     193                bool operator>= (const const_iterator& o) const { return data.first >= o.data.first; }
    124194        };
    125195
     
    163233};
    164234
     235template<typename T>
     236typename VectorMap<T>::iterator operator+ (typename VectorMap<T>::difference_type i,
     237                                           const typename VectorMap<T>::iterator& it) {
     238        return it + i;
     239}
     240
     241template<typename T>
     242typename VectorMap<T>::const_iterator operator+ (typename VectorMap<T>::difference_type i,
     243                                                 const typename VectorMap<T>::const_iterator& it) {
     244        return it + i;
     245}
     246
    165247#endif // _VECTORMAP_H
    166248
  • src/GenPoly/InstantiateGeneric.cc

    r9bb90a86 r35cd219  
    122122                /// Adds a value for a (key, typeList) pair to the current scope
    123123                void insert( Key *key, const std::list< TypeExpr* > &params, Value *value ) {
    124                         instantiations[ key ].push_back( Instantiation( TypeList( params ), value ) );
     124                        auto it = instantiations.findAt( instantiations.currentScope(), key );
     125                        if ( it == instantiations.end() ) {
     126                                instantiations.insert( key, ValueList{ Instantiation{ TypeList( params ), value } } );
     127                        } else {
     128                                it->second.push_back( Instantiation{ TypeList( params ), value } );
     129                        }
    125130                }
    126131        };
Note: See TracChangeset for help on using the changeset viewer.