Changeset 31868da


Ignore:
Timestamp:
Feb 28, 2017, 1:48:56 PM (7 years ago)
Author:
Aaron Moss <a3moss@…>
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:
fd061ed3
Parents:
356c62a
Message:

Start work on adding expression statistics to DeclStats? pass

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/CodeTools/DeclStats.cc

    r356c62a r31868da  
    130130                std::unordered_set<std::string> seen_names;  ///< Stores manglenames already seen to avoid double-counting
    131131                Stats total;
     132                /// Count of expressions with (depth, fanout)
     133                std::map<std::pair<unsigned, unsigned>, unsigned> exprs_by_fanout_at_depth;
    132134
    133135                /// Update arg pack stats based on a declaration list
     
    179181                        analyze( stats, seen, params, fnTy->get_parameters() );
    180182                        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                        }
    181194                }
    182195
     
    217230                }
    218231
     232                virtual void visit( UntypedExpr *expr ) {
     233                        analyzeExpr( expr, 0 );
     234                }
     235
    219236        private:
    220237                template<typename F>
     
    297314                        printAllMap("n_distinct_types_" + name, [&extract](const Stats& stats) { return extract(stats).n_types; });
    298315                        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                        }
    299325                }
    300326               
     
    322348                        printAllPack("assn_params", [](const Stats& stats) { return stats.assn_params; });
    323349                        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);
    324353                }
    325354        };
Note: See TracChangeset for help on using the changeset viewer.