Changes in src/CodeTools/DeclStats.cc [1e6b350:eed5e48]
- File:
-
- 1 edited
-
src/CodeTools/DeclStats.cc (modified) (14 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/CodeTools/DeclStats.cc
r1e6b350 reed5e48 63 63 std::map<unsigned, unsigned> p_poly; ///< Count of decls with each percentage of polymorphic elements 64 64 VectorMap<unsigned> n_types; ///< Count of decls with each number of distinct types in the pack 65 /// Count of decls with each percentage of new types in lists.66 /// Types used in the parameter list that recur in the return list are not considered to be new.67 std::map<unsigned, unsigned> p_new;68 65 69 66 ArgPackStats& operator+= (const ArgPackStats& o) { … … 74 71 sum(p_poly, o.p_poly); 75 72 sum(n_types, o.n_types); 76 sum(p_new, o.p_new);77 73 78 74 return *this; … … 90 86 /// Count of uses of each non-basic type 91 87 std::unordered_map<std::string, unsigned> compound_type_names; 92 /// Count of decls using each basic type93 std::unordered_map<std::string, unsigned> basic_type_decls;94 /// Count of decls using each compound type95 std::unordered_map<std::string, unsigned> compound_type_decls;96 88 /// Stats for the parameter list 97 89 ArgPackStats params; … … 106 98 ArgPackStats assn_returns; 107 99 108 Stats() : n_decls(0), n_type_params(), by_name(), basic_type_names(), compound_type_names(), basic_type_decls(), compound_type_decls(),params(), returns(), n_assns(), assn_params(), assn_returns() {}100 Stats() : n_decls(0), n_type_params(), by_name(), basic_type_names(), compound_type_names(), params(), returns(), n_assns(), assn_params(), assn_returns() {} 109 101 110 102 public: … … 115 107 sum( basic_type_names, o.basic_type_names ); 116 108 sum( compound_type_names, o.compound_type_names ); 117 sum( basic_type_decls, o.basic_type_decls );118 sum( compound_type_decls, o.compound_type_decls );119 109 sum( params, o.params ); 120 110 sum( returns, o.returns ); … … 130 120 std::unordered_set<std::string> seen_names; ///< Stores manglenames already seen to avoid double-counting 131 121 Stats total; 132 /// Count of expressions with (depth, fanout)133 std::map<std::pair<unsigned, unsigned>, unsigned> exprs_by_fanout_at_depth;134 122 135 123 /// Update arg pack stats based on a declaration list 136 void analyze( Stats& stats, std::unordered_set<std::string>& seen,ArgPackStats& pstats, std::list<DeclarationWithType*>& decls ) {124 void analyze( Stats& stats, ArgPackStats& pstats, std::list<DeclarationWithType*>& decls ) { 137 125 std::unordered_set<std::string> types; 138 unsigned n = 0; ///< number of args/returns 139 unsigned n_basic = 0; ///< number of basic types 140 unsigned n_poly = 0; ///< number of polymorphic types 141 unsigned n_new = 0; ///< number of new types 126 unsigned n = 0; 127 unsigned n_basic = 0; 128 unsigned n_poly = 0; 142 129 for ( auto decl : decls ) { 143 130 Type* dt = decl->get_type(); … … 148 135 dt->print( ss ); 149 136 types.insert( ss.str() ); 150 bool this_new = seen.insert( ss.str() ).second;151 if ( this_new ) { ++n_new; }152 137 153 138 if ( dynamic_cast<BasicType*>( dt ) ) { 154 139 ++n_basic; 155 140 ++stats.basic_type_names[ ss.str() ]; 156 if ( this_new ) {157 ++stats.basic_type_decls[ ss.str() ];158 }159 141 } else if ( GenPoly::hasPolyBase( dt ) ) { 160 142 ++n_poly; 161 143 } else { 162 144 ++stats.compound_type_names[ ss.str() ]; 163 if ( this_new ) {164 ++stats.compound_type_decls[ ss.str() ];165 }166 145 } 167 146 } … … 172 151 ++pstats.p_basic[ n_basic*100/n ]; 173 152 ++pstats.p_poly[ n_poly*100/n ]; 174 ++pstats.p_new[ n_new*100/n ];175 153 } 176 154 ++pstats.n_types.at( types.size() ); … … 178 156 179 157 void analyzeFunc( FunctionType* fnTy, Stats& stats, ArgPackStats& params, ArgPackStats& returns ) { 180 std::unordered_set<std::string> seen; 181 analyze( stats, seen, params, fnTy->get_parameters() ); 182 analyze( stats, seen, returns, fnTy->get_returnVals() ); 183 } 184 185 void analyzeExpr( UntypedExpr *expr, unsigned depth ) { 186 auto& args = expr->get_args(); 187 unsigned fanout = args.size(); 188 ++exprs_by_fanout_at_depth[ std::make_pair(depth, fanout) ]; 189 for ( Expression* arg : args ) { 190 if ( UntypedExpr *uearg = dynamic_cast<UntypedExpr*>(arg) ) { 191 analyzeExpr( uearg, depth+1 ); 192 } 193 } 158 analyze( stats, params, fnTy->get_parameters() ); 159 analyze( stats, returns, fnTy->get_returnVals() ); 194 160 } 195 161 … … 200 166 // skip if already seen declaration for this function 201 167 const std::string& mangleName = decl->get_mangleName().empty() ? decl->get_name() : decl->get_mangleName(); 202 if ( ! seen_names.insert( mangleName ).second ) { 203 maybeAccept( decl->get_statements(), *this ); 204 return; 205 } 168 if ( ! seen_names.insert( mangleName ).second ) return; 206 169 207 170 Stats& stats = for_linkage[ decl->get_linkage() ]; … … 231 194 232 195 analyzeFunc( fnTy, stats, stats.params, stats.returns ); 233 234 // analyze expressions in decl statements235 maybeAccept( decl->get_statements(), *this );236 }237 238 virtual void visit( UntypedExpr *expr ) {239 analyzeExpr( expr, 0 );240 196 } 241 197 … … 319 275 printAllMap("%_poly_" + name, [&extract](const Stats& stats) { return extract(stats).p_poly; }); 320 276 printAllMap("n_distinct_types_" + name, [&extract](const Stats& stats) { return extract(stats).n_types; }); 321 printAllMap("%_new_types_in_" + name, [&extract](const Stats& stats) { return extract(stats).p_new; });322 }323 324 void printPairMap( const std::string& name,325 const std::map<std::pair<unsigned, unsigned>, unsigned>& map ) {326 for ( const auto& entry : map ) {327 const auto& key = entry.first;328 std::cout << "\"" << name << "\"," << key.first << "," << key.second << ","329 << entry.second << std::endl;330 }331 277 } 332 278 … … 345 291 printAll("basic_type_names", [](const Stats& stats) { return stats.basic_type_names.size(); }); 346 292 printAllSparseHisto("basic_type_uses", [](const Stats& stats) { return stats.basic_type_names; }); 347 printAllSparseHisto("decls_using_basic_type", [](const Stats& stats) { return stats.basic_type_decls; });348 293 printAll("compound_type_names", [](const Stats& stats) { return stats.compound_type_names.size(); }); 349 294 printAllSparseHisto("compound_type_uses", [](const Stats& stats) { return stats.compound_type_names; }); 350 printAllSparseHisto("decls_using_compound_type", [](const Stats& stats) { return stats.compound_type_decls; });351 295 printAllPack("params", [](const Stats& stats) { return stats.params; }); 352 296 printAllPack("returns", [](const Stats& stats) { return stats.returns; }); … … 354 298 printAllPack("assn_params", [](const Stats& stats) { return stats.assn_params; }); 355 299 printAllPack("assn_returns", [](const Stats& stats) { return stats.assn_returns; }); 356 std::cout << std::endl;357 358 printPairMap("exprs_by_depth+fanout", exprs_by_fanout_at_depth);359 300 } 360 301 };
Note:
See TracChangeset
for help on using the changeset viewer.