Changeset f37147b for src/CodeTools
- Timestamp:
- Feb 28, 2017, 3:24:35 PM (9 years ago)
- 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:
- 20221d4, dd020c0
- Parents:
- d0ffed1 (diff), 14f6bb39 (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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/CodeTools/DeclStats.cc
rd0ffed1 rf37147b 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; 65 68 66 69 ArgPackStats& operator+= (const ArgPackStats& o) { … … 71 74 sum(p_poly, o.p_poly); 72 75 sum(n_types, o.n_types); 76 sum(p_new, o.p_new); 73 77 74 78 return *this; … … 86 90 /// Count of uses of each non-basic type 87 91 std::unordered_map<std::string, unsigned> compound_type_names; 92 /// Count of decls using each basic type 93 std::unordered_map<std::string, unsigned> basic_type_decls; 94 /// Count of decls using each compound type 95 std::unordered_map<std::string, unsigned> compound_type_decls; 88 96 /// Stats for the parameter list 89 97 ArgPackStats params; … … 98 106 ArgPackStats assn_returns; 99 107 100 Stats() : n_decls(0), n_type_params(), by_name(), basic_type_names(), compound_type_names(), params(), returns(), n_assns(), assn_params(), assn_returns() {}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() {} 101 109 102 110 public: … … 107 115 sum( basic_type_names, o.basic_type_names ); 108 116 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 ); 109 119 sum( params, o.params ); 110 120 sum( returns, o.returns ); … … 120 130 std::unordered_set<std::string> seen_names; ///< Stores manglenames already seen to avoid double-counting 121 131 Stats total; 132 /// Count of expressions with (depth, fanout) 133 std::map<std::pair<unsigned, unsigned>, unsigned> exprs_by_fanout_at_depth; 122 134 123 135 /// Update arg pack stats based on a declaration list 124 void analyze( Stats& stats, ArgPackStats& pstats, std::list<DeclarationWithType*>& decls ) {136 void analyze( Stats& stats, std::unordered_set<std::string>& seen, ArgPackStats& pstats, std::list<DeclarationWithType*>& decls ) { 125 137 std::unordered_set<std::string> types; 126 unsigned n = 0; 127 unsigned n_basic = 0; 128 unsigned n_poly = 0; 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 129 142 for ( auto decl : decls ) { 130 143 Type* dt = decl->get_type(); … … 135 148 dt->print( ss ); 136 149 types.insert( ss.str() ); 150 bool this_new = seen.insert( ss.str() ).second; 151 if ( this_new ) { ++n_new; } 137 152 138 153 if ( dynamic_cast<BasicType*>( dt ) ) { 139 154 ++n_basic; 140 155 ++stats.basic_type_names[ ss.str() ]; 156 if ( this_new ) { 157 ++stats.basic_type_decls[ ss.str() ]; 158 } 141 159 } else if ( GenPoly::hasPolyBase( dt ) ) { 142 160 ++n_poly; 143 161 } else { 144 162 ++stats.compound_type_names[ ss.str() ]; 163 if ( this_new ) { 164 ++stats.compound_type_decls[ ss.str() ]; 165 } 145 166 } 146 167 } … … 151 172 ++pstats.p_basic[ n_basic*100/n ]; 152 173 ++pstats.p_poly[ n_poly*100/n ]; 174 ++pstats.p_new[ n_new*100/n ]; 153 175 } 154 176 ++pstats.n_types.at( types.size() ); … … 156 178 157 179 void analyzeFunc( FunctionType* fnTy, Stats& stats, ArgPackStats& params, ArgPackStats& returns ) { 158 analyze( stats, params, fnTy->get_parameters() ); 159 analyze( stats, returns, fnTy->get_returnVals() ); 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 } 160 194 } 161 195 … … 196 230 } 197 231 232 virtual void visit( UntypedExpr *expr ) { 233 analyzeExpr( expr, 0 ); 234 } 235 198 236 private: 199 237 template<typename F> … … 275 313 printAllMap("%_poly_" + name, [&extract](const Stats& stats) { return extract(stats).p_poly; }); 276 314 printAllMap("n_distinct_types_" + name, [&extract](const Stats& stats) { return extract(stats).n_types; }); 315 printAllMap("%_new_types_in_" + name, [&extract](const Stats& stats) { return extract(stats).p_new; }); 316 } 317 318 void printPairMap( const std::string& name, 319 const std::map<std::pair<unsigned, unsigned>, unsigned>& map ) { 320 for ( const auto& entry : map ) { 321 const auto& key = entry.first; 322 std::cout << "\"" << name << "\"," << key.first << "," << key.second << "," 323 << entry.second << std::endl; 324 } 277 325 } 278 326 … … 291 339 printAll("basic_type_names", [](const Stats& stats) { return stats.basic_type_names.size(); }); 292 340 printAllSparseHisto("basic_type_uses", [](const Stats& stats) { return stats.basic_type_names; }); 341 printAllSparseHisto("decls_using_basic_type", [](const Stats& stats) { return stats.basic_type_decls; }); 293 342 printAll("compound_type_names", [](const Stats& stats) { return stats.compound_type_names.size(); }); 294 343 printAllSparseHisto("compound_type_uses", [](const Stats& stats) { return stats.compound_type_names; }); 344 printAllSparseHisto("decls_using_compound_type", [](const Stats& stats) { return stats.compound_type_decls; }); 295 345 printAllPack("params", [](const Stats& stats) { return stats.params; }); 296 346 printAllPack("returns", [](const Stats& stats) { return stats.returns; }); … … 298 348 printAllPack("assn_params", [](const Stats& stats) { return stats.assn_params; }); 299 349 printAllPack("assn_returns", [](const Stats& stats) { return stats.assn_returns; }); 350 std::cout << std::endl; 351 352 printPairMap("exprs_by_depth+fanout", exprs_by_fanout_at_depth); 300 353 } 301 354 };
Note:
See TracChangeset
for help on using the changeset viewer.