Changes in / [0050a5f:874ffa4]
- Location:
- src
- Files:
-
- 4 added
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Common/PassVisitor.h
r0050a5f r874ffa4 5 5 #include <stack> 6 6 7 #include "Common/Stats.h" 7 8 #include "Common/utility.h" 8 9 … … 426 427 }; 427 428 429 #include "Common/Stats.h" 430 431 extern struct PassVisitorStats { 432 size_t depth = 0; 433 Stats::Counters::MaxCounter<double> * max = nullptr; 434 Stats::Counters::AverageCounter<double> * avg = nullptr; 435 } pass_visitor_stats; 436 428 437 #include "SynTree/TypeSubstitution.h" 429 438 #include "PassVisitor.impl.h" -
src/Common/PassVisitor.impl.h
r0050a5f r874ffa4 67 67 SemanticErrorException errors; 68 68 69 pass_visitor_stats.depth++; 70 pass_visitor_stats.max->push(pass_visitor_stats.depth); 71 pass_visitor_stats.avg->push(pass_visitor_stats.depth); 69 72 for ( std::list< Declaration* >::iterator i = decls.begin(); ; ++i ) { 73 74 70 75 // splice in new declarations after previous decl 71 76 if ( !empty( afterDecls ) ) { decls.splice( i, *afterDecls ); } … … 83 88 if ( !empty( beforeDecls ) ) { decls.splice( i, *beforeDecls ); } 84 89 } 90 pass_visitor_stats.depth--; 85 91 if ( ! errors.isEmpty() ) { 86 92 throw errors; … … 94 100 SemanticErrorException errors; 95 101 102 pass_visitor_stats.depth++; 103 pass_visitor_stats.max->push(pass_visitor_stats.depth); 104 pass_visitor_stats.avg->push(pass_visitor_stats.depth); 96 105 for ( std::list< Declaration* >::iterator i = decls.begin(); ; ++i ) { 97 106 // splice in new declarations after previous decl … … 109 118 if ( !empty( beforeDecls ) ) { decls.splice( i, *beforeDecls ); } 110 119 } 120 pass_visitor_stats.depth--; 111 121 if ( ! errors.isEmpty() ) { 112 122 throw errors; … … 126 136 if ( ! visitor.get_visit_children() ) return; 127 137 SemanticErrorException errors; 138 139 pass_visitor_stats.depth++; 140 pass_visitor_stats.max->push(pass_visitor_stats.depth); 141 pass_visitor_stats.avg->push(pass_visitor_stats.depth); 128 142 for ( typename Container::iterator i = container.begin(); i != container.end(); ++i ) { 129 143 try { … … 135 149 } 136 150 } 151 pass_visitor_stats.depth--; 137 152 if ( ! errors.isEmpty() ) { 138 153 throw errors; … … 153 168 if ( ! mutator.get_visit_children() ) return; 154 169 SemanticErrorException errors; 170 171 pass_visitor_stats.depth++; 172 pass_visitor_stats.max->push(pass_visitor_stats.depth); 173 pass_visitor_stats.avg->push(pass_visitor_stats.depth); 155 174 for ( typename Container::iterator i = container.begin(); i != container.end(); ++i ) { 156 175 try { … … 163 182 } // try 164 183 } // for 184 pass_visitor_stats.depth--; 165 185 if ( ! errors.isEmpty() ) { 166 186 throw errors; … … 185 205 DeclList_t* afterDecls = get_afterDecls(); 186 206 207 pass_visitor_stats.depth++; 208 pass_visitor_stats.max->push(pass_visitor_stats.depth); 209 pass_visitor_stats.avg->push(pass_visitor_stats.depth); 187 210 for ( std::list< Statement* >::iterator i = statements.begin(); i != statements.end(); ++i ) { 188 211 … … 202 225 if ( !empty( beforeStmts ) ) { statements.splice( i, *beforeStmts ); } 203 226 } 227 pass_visitor_stats.depth--; 204 228 205 229 if ( !empty( afterDecls ) ) { splice( std::back_inserter( statements ), afterDecls); } -
src/Common/Stats.h
r0050a5f r874ffa4 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // Heap.h --7 // Stats.h -- 8 8 // 9 9 // Author : Thierry Delisle … … 18 18 #include "Common/Stats/Counter.h" 19 19 #include "Common/Stats/Heap.h" 20 #include "Common/Stats/Time.h" 21 22 namespace Stats { 23 void parse_params(const char * const params); 24 void print(); 25 } -
src/Common/Stats/Counter.cc
r0050a5f r874ffa4 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // Heap.h--7 // Counter.cc -- 8 8 // 9 9 // Author : Thierry Delisle … … 18 18 #include <algorithm> 19 19 #include <cstring> 20 #include <functional> 20 21 #include <iomanip> 21 22 22 23 namespace Stats { 23 24 namespace Counters { 24 25 template<typename T>26 void ForAllCounters(BaseCounter::list_t & range, size_t level, T func) {27 auto it = range.head;28 while(it) {29 auto next = it->next;30 func(it, level);31 ForAllCounters(it->children, level + 1, func);32 it = next;33 }34 }35 36 25 void print() { 37 if(! BaseCounter::top.head) return;26 if(!top.head) return; 38 27 size_t nc = 0; 39 ForAllCounters(BaseCounter::top, 0, [&](BaseCounter* node, size_t level) {28 Base::ForAll(top, 0, [&](Base::TreeImpl * node, size_t level) { 40 29 nc = std::max(nc, (4 * level) + std::strlen(node->name)); 41 30 }); … … 49 38 50 39 51 ForAllCounters(BaseCounter::top, 0, [&](BaseCounter* node, size_t level) {40 Base::ForAll(top, 0, [&](Base::TreeImpl * node, size_t level) { 52 41 std::cerr << std::string(level * 4, ' '); 53 42 std::cerr << node->name; … … 58 47 std::cerr << " |"; 59 48 std::cerr << '\n'; 60 delete node; 61 }); 49 }, true); 62 50 63 51 std::cerr << std::string(nct, '-') << std::endl; 64 52 } 65 53 66 BaseCounter::list_t BaseCounter::top; 54 Base::TreeTop top; 55 56 extern bool enabled; 67 57 } 68 58 } -
src/Common/Stats/Counter.h
r0050a5f r874ffa4 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // Heap.h --7 // Counter.h -- 8 8 // 9 9 // Author : Thierry Delisle … … 19 19 #include <iostream> 20 20 21 #include "Common/Stats/Base.h" 22 23 #if defined( NO_STATISTICS ) 24 #define NO_COUNTER_STATISTICS 25 #endif 26 21 27 namespace Stats { 22 28 namespace Counters { 23 void print(); 29 # if defined(NO_COUNTERS_STATISTICS) 24 30 25 class BaseCounter { 26 public: 27 BaseCounter(const char * const name) : name(name) { 28 top.append(this); 31 static inline void print() {} 32 33 class CounterGroup { 34 public: 35 }; 36 37 class SimpleCounter { 38 public: 39 inline void operator++(int) {} 40 inline void operator+=(size_t) {} 41 }; 42 43 template<typename T> 44 class AverageCounter { 45 public: 46 inline void push(T value) {} 47 }; 48 49 template<typename T> 50 class MaxCounter { 51 public: 52 inline void push(T value) {} 53 }; 54 55 template<typename counter_t> 56 counter_t * build(const char * const name) { 57 return nullptr; 29 58 } 30 59 31 BaseCounter(const char * const name, BaseCounter * parent) : name(name) { 32 parent->children.append(this); 60 template<typename counter_t> 61 counter_t * build(const char * const name, Base::Tree<top> * parent) { 62 return nullptr; 33 63 } 34 protected: 35 virtual ~BaseCounter() = default;64 # else 65 extern bool enabled; 36 66 37 struct list_t { 38 BaseCounter * head = nullptr; 39 BaseCounter * tail = nullptr; 67 extern Base::TreeTop top; 40 68 41 void append(BaseCounter * node) { 42 if(!head) { head = node; } 43 else { tail->next = node;} 44 tail = node; 45 } 69 class CounterGroup : public Base::Tree<top> { 70 public: 71 CounterGroup(const char * const name ) : Base::Tree<top>(name) {} 72 CounterGroup(const char * const name, Base::Tree<top> * parent) : Base::Tree<top>(name, parent) {} 73 74 virtual void print(std::ostream & os) override { os << ""; } 75 protected: 76 virtual ~CounterGroup() = default; 46 77 }; 47 78 48 private: 49 virtual void print(std::ostream &) = 0; 79 class SimpleCounter : public Base::Tree<top> { 80 public: 81 SimpleCounter(const char * const name ) : Base::Tree<top>(name) {} 82 SimpleCounter(const char * const name, Base::Tree<top> * parent) : Base::Tree<top>(name, parent) {} 83 84 virtual void print(std::ostream & os) override { os << count; } 85 86 inline void operator++(int) { if(!enabled) return; count++; } 87 inline void operator+=(size_t value) { if(!enabled) return; count += value; } 88 89 protected: 90 virtual ~SimpleCounter() = default; 91 92 private: 93 size_t count = 0; 94 }; 95 50 96 template<typename T> 51 friend void ForAllCounters(BaseCounter::list_t &, size_t, T ); 52 friend void print(); 97 class AverageCounter : public Base::Tree<top> { 98 public: 99 AverageCounter(const char * const name ) : Base::Tree<top>(name), sum{} {} 100 AverageCounter(const char * const name, Base::Tree<top> * parent) : Base::Tree<top>(name, parent), sum{} {} 53 101 54 private: 55 const char * const name; 102 virtual void print(std::ostream & os) { os << sum / count; } 56 103 57 BaseCounter * next = nullptr; 58 list_t children; 104 inline void push(T value) { if(!enabled) return; sum += value; count++; } 59 105 60 static list_t top;61 };106 protected: 107 virtual ~AverageCounter() = default; 62 108 63 class CounterGroup : public BaseCounter {64 public:65 CounterGroup(const char * const name ) : BaseCounter(name) {}66 CounterGroup(const char * const name, BaseCounter * parent) : BaseCounter(name, parent) {}109 private: 110 T sum; 111 size_t count = 1; 112 }; 67 113 68 protected: 69 virtual ~CounterGroup() = default; 114 template<typename T> 115 class MaxCounter : public Base::Tree<top> { 116 public: 117 MaxCounter(const char * const name ) : Base::Tree<top>(name), max{} {} 118 MaxCounter(const char * const name, Base::Tree<top> * parent) : Base::Tree<top>(name, parent), max{} {} 70 119 71 private: 72 virtual void print(std::ostream & os) { 73 os << ""; 74 } 75 template<typename T> 76 friend void ForAllCounters(BaseCounter::list_t &, size_t, T ); 77 friend void print(); 78 }; 120 virtual void print(std::ostream & os) { os << max; } 79 121 80 class SimpleCounter : public BaseCounter { 81 public: 82 SimpleCounter(const char * const name ) : BaseCounter(name) {} 83 SimpleCounter(const char * const name, BaseCounter * parent) : BaseCounter(name, parent) {} 122 inline void push(T value) { if(!enabled) return; max = std::max(max, value); } 84 123 85 inline void operator++(int) { count++; } 86 inline void operator+=(size_t value) { count += value; } 87 protected: 88 virtual ~SimpleCounter() = default; 124 protected: 125 virtual ~MaxCounter() = default; 89 126 90 private: 91 virtual void print(std::ostream & os) { 92 os << count; 93 } 94 template<typename T> 95 friend void ForAllCounters(BaseCounter::list_t &, size_t, T ); 96 friend void print(); 127 private: 128 T max; 129 }; 97 130 98 size_t count = 0; 99 100 }; 101 102 template<typename T> 103 class AverageCounter : public BaseCounter { 104 public: 105 AverageCounter(const char * const name ) : BaseCounter(name), sum{} {} 106 AverageCounter(const char * const name, BaseCounter * parent) : BaseCounter(name, parent), sum{} {} 107 108 inline void push(T value) { 109 sum += value; 110 count++; 131 template<typename counter_t> 132 counter_t * build(const char * const name) { 133 if(!enabled) return nullptr; 134 return new counter_t(name); 111 135 } 112 136 113 protected: 114 virtual ~AverageCounter() = default; 115 116 private: 117 virtual void print(std::ostream & os) { 118 os << sum / count; 137 template<typename counter_t> 138 counter_t * build(const char * const name, Base::Tree<top> * parent) { 139 if(!enabled) return nullptr; 140 return new counter_t(name, parent); 119 141 } 120 template<typename F> 121 friend void ForAllCounters(BaseCounter::list_t &, size_t, F ); 122 friend void print(); 123 124 T sum; 125 size_t count = 1; 126 }; 127 128 template<typename T> 129 class MaxCounter : public BaseCounter { 130 public: 131 MaxCounter(const char * const name ) : BaseCounter(name), max{} {} 132 MaxCounter(const char * const name, BaseCounter * parent) : BaseCounter(name, parent), max{} {} 133 134 inline void push(T value) { 135 max = std::max(max, value); 136 } 137 138 protected: 139 virtual ~MaxCounter() = default; 140 141 private: 142 virtual void print(std::ostream & os) { 143 os << max; 144 } 145 template<typename F> 146 friend void ForAllCounters(BaseCounter::list_t &, size_t, F ); 147 friend void print(); 148 149 T max; 150 }; 142 # endif 151 143 } 152 144 } -
src/Common/Stats/Heap.cc
r0050a5f r874ffa4 21 21 #include <iostream> 22 22 23 #if defined( NO_STATISTICS ) 24 #define NO_HEAP_STATISTICS 25 #endif 26 23 27 namespace Stats { 24 28 namespace Heap { … … 28 32 void print() {} 29 33 #else 34 extern bool enabled; 35 30 36 struct StatBlock { 31 37 const char * name = nullptr; ///< Name of this pass … … 77 83 78 84 void print() { 85 if(!enabled) return; 86 79 87 size_t nc = 0; 80 88 size_t total_mallocs = 0; … … 166 174 void * malloc( size_t size ) { 167 175 static auto __malloc = reinterpret_cast<void * (*)(size_t)>(interpose_symbol( "malloc", nullptr )); 168 if( passes_cnt > 0 ) {176 if( enabled && passes_cnt > 0 ) { 169 177 passes[passes_cnt - 1].mallocs++; 170 178 passes[passes_cnt - 1].n_allocs++; … … 177 185 void free( void * ptr ) { 178 186 static auto __free = reinterpret_cast<void (*)(void *)>(interpose_symbol( "free", nullptr )); 179 if( passes_cnt > 0 ) {187 if( enabled && passes_cnt > 0 ) { 180 188 passes[passes_cnt - 1].frees++; 181 189 passes[passes_cnt - 1].n_allocs--; … … 186 194 void * calloc( size_t nelem, size_t size ) { 187 195 static auto __calloc = reinterpret_cast<void * (*)(size_t, size_t)>(interpose_symbol( "calloc", nullptr )); 188 if( passes_cnt > 0 ) {196 if( enabled && passes_cnt > 0 ) { 189 197 passes[passes_cnt - 1].mallocs++; 190 198 passes[passes_cnt - 1].n_allocs++; … … 198 206 static auto __realloc = reinterpret_cast<void * (*)(void *, size_t)>(interpose_symbol( "realloc", nullptr )); 199 207 void * s = __realloc( ptr, size ); 200 if ( s != ptr && passes_cnt > 0 ) { // did realloc get new storage ?208 if ( enabled && s != ptr && passes_cnt > 0 ) { // did realloc get new storage ? 201 209 passes[passes_cnt - 1].mallocs++; 202 210 passes[passes_cnt - 1].frees++; -
src/Common/module.mk
r0050a5f r874ffa4 17 17 SRC_COMMON = \ 18 18 Common/Assert.cc \ 19 Common/Eval.cc \ 20 Common/PassVisitor.cc \ 21 Common/SemanticError.cc \ 22 Common/Stats/Counter.cc \ 19 23 Common/Stats/Heap.cc \ 20 Common/Stats/Counter.cc \ 21 Common/Eval.cc \ 22 Common/SemanticError.cc \ 24 Common/Stats/Stats.cc \ 23 25 Common/UniqueName.cc 24 26 -
src/Makefile.in
r0050a5f r874ffa4 165 165 CodeGen/FixMain.$(OBJEXT) CodeGen/GenType.$(OBJEXT) \ 166 166 CodeGen/OperatorTable.$(OBJEXT) 167 am__objects_2 = Common/Assert.$(OBJEXT) Common/Stats/Heap.$(OBJEXT) \ 168 Common/Stats/Counter.$(OBJEXT) Common/Eval.$(OBJEXT) \ 169 Common/SemanticError.$(OBJEXT) Common/UniqueName.$(OBJEXT) 167 am__objects_2 = Common/Assert.$(OBJEXT) Common/Eval.$(OBJEXT) \ 168 Common/PassVisitor.$(OBJEXT) Common/SemanticError.$(OBJEXT) \ 169 Common/Stats/Counter.$(OBJEXT) Common/Stats/Heap.$(OBJEXT) \ 170 Common/Stats/Stats.$(OBJEXT) Common/UniqueName.$(OBJEXT) 170 171 am__objects_3 = ControlStruct/ForExprMutator.$(OBJEXT) \ 171 172 ControlStruct/LabelFixer.$(OBJEXT) \ … … 560 561 SRC_COMMON = \ 561 562 Common/Assert.cc \ 563 Common/Eval.cc \ 564 Common/PassVisitor.cc \ 565 Common/SemanticError.cc \ 566 Common/Stats/Counter.cc \ 562 567 Common/Stats/Heap.cc \ 563 Common/Stats/Counter.cc \ 564 Common/Eval.cc \ 565 Common/SemanticError.cc \ 568 Common/Stats/Stats.cc \ 566 569 Common/UniqueName.cc 567 570 … … 721 724 Common/Assert.$(OBJEXT): Common/$(am__dirstamp) \ 722 725 Common/$(DEPDIR)/$(am__dirstamp) 726 Common/Eval.$(OBJEXT): Common/$(am__dirstamp) \ 727 Common/$(DEPDIR)/$(am__dirstamp) 728 Common/PassVisitor.$(OBJEXT): Common/$(am__dirstamp) \ 729 Common/$(DEPDIR)/$(am__dirstamp) 730 Common/SemanticError.$(OBJEXT): Common/$(am__dirstamp) \ 731 Common/$(DEPDIR)/$(am__dirstamp) 723 732 Common/Stats/$(am__dirstamp): 724 733 @$(MKDIR_P) Common/Stats … … 727 736 @$(MKDIR_P) Common/Stats/$(DEPDIR) 728 737 @: > Common/Stats/$(DEPDIR)/$(am__dirstamp) 738 Common/Stats/Counter.$(OBJEXT): Common/Stats/$(am__dirstamp) \ 739 Common/Stats/$(DEPDIR)/$(am__dirstamp) 729 740 Common/Stats/Heap.$(OBJEXT): Common/Stats/$(am__dirstamp) \ 730 741 Common/Stats/$(DEPDIR)/$(am__dirstamp) 731 Common/Stats/ Counter.$(OBJEXT): Common/Stats/$(am__dirstamp) \742 Common/Stats/Stats.$(OBJEXT): Common/Stats/$(am__dirstamp) \ 732 743 Common/Stats/$(DEPDIR)/$(am__dirstamp) 733 Common/Eval.$(OBJEXT): Common/$(am__dirstamp) \734 Common/$(DEPDIR)/$(am__dirstamp)735 Common/SemanticError.$(OBJEXT): Common/$(am__dirstamp) \736 Common/$(DEPDIR)/$(am__dirstamp)737 744 Common/UniqueName.$(OBJEXT): Common/$(am__dirstamp) \ 738 745 Common/$(DEPDIR)/$(am__dirstamp) … … 1115 1122 @AMDEP_TRUE@@am__include@ @am__quote@Common/$(DEPDIR)/DebugMalloc.Po@am__quote@ 1116 1123 @AMDEP_TRUE@@am__include@ @am__quote@Common/$(DEPDIR)/Eval.Po@am__quote@ 1124 @AMDEP_TRUE@@am__include@ @am__quote@Common/$(DEPDIR)/PassVisitor.Po@am__quote@ 1117 1125 @AMDEP_TRUE@@am__include@ @am__quote@Common/$(DEPDIR)/SemanticError.Po@am__quote@ 1118 1126 @AMDEP_TRUE@@am__include@ @am__quote@Common/$(DEPDIR)/UniqueName.Po@am__quote@ 1119 1127 @AMDEP_TRUE@@am__include@ @am__quote@Common/Stats/$(DEPDIR)/Counter.Po@am__quote@ 1120 1128 @AMDEP_TRUE@@am__include@ @am__quote@Common/Stats/$(DEPDIR)/Heap.Po@am__quote@ 1129 @AMDEP_TRUE@@am__include@ @am__quote@Common/Stats/$(DEPDIR)/Stats.Po@am__quote@ 1121 1130 @AMDEP_TRUE@@am__include@ @am__quote@Concurrency/$(DEPDIR)/Keywords.Po@am__quote@ 1122 1131 @AMDEP_TRUE@@am__include@ @am__quote@Concurrency/$(DEPDIR)/Waitfor.Po@am__quote@ -
src/SymTab/Indexer.cc
r0050a5f r874ffa4 45 45 // Statistics block 46 46 namespace { 47 auto idtable_group = new Stats::Counters::CounterGroup("IdTable"); 48 auto idtable_find = new Stats::Counters::SimpleCounter("Find calls", idtable_group); 49 auto idtable_size = new Stats::Counters::AverageCounter<double>("Average Size", idtable_group); 50 auto idtable_key = new Stats::Counters::AverageCounter<double>("Average Key Size", idtable_group); 51 52 auto indexers_group = new Stats::Counters::CounterGroup("Indexers"); 53 auto indexers_count = new Stats::Counters::SimpleCounter("Count", indexers_group); 54 auto indexers_size = new Stats::Counters::AverageCounter<double>("Average Size", indexers_group); 55 auto indexers_depth_a = new Stats::Counters::AverageCounter<double>("Average Depth", indexers_group); 56 auto indexers_depth_m = new Stats::Counters::MaxCounter<size_t>("Max Depth", indexers_group); 47 48 static inline auto stats_idtable() { 49 using namespace Stats::Counters; 50 static auto group = build<CounterGroup>("IdTable"); 51 static struct { 52 SimpleCounter * find; 53 AverageCounter<double> * size; 54 AverageCounter<double> * key; 55 } ret = { 56 .find = build<SimpleCounter>("Find calls", group), 57 .size = build<AverageCounter<double>>("Average Size", group), 58 .key = build<AverageCounter<double>>("Average Key Size", group), 59 }; 60 return ret; 61 } 62 63 static inline auto stats_indexers() { 64 using namespace Stats::Counters; 65 static auto group = build<CounterGroup>("Indexers"); 66 static struct { 67 SimpleCounter * count; 68 AverageCounter<double> * size; 69 AverageCounter<double> * depth_a; 70 MaxCounter<size_t> * depth_m; 71 } ret = { 72 .count = build<SimpleCounter>("Count", group), 73 .size = build<AverageCounter<double>>("Average Size", group), 74 .depth_a = build<AverageCounter<double>>("Average Depth", group), 75 .depth_m = build<MaxCounter<size_t>>("Max Depth", group), 76 }; 77 return ret; 78 } 57 79 } 58 80 … … 214 236 215 237 Indexer::Indexer() : tables( 0 ), scope( 0 ) { 216 (* indexers_count)++;238 (*stats_indexers().count)++; 217 239 } 218 240 219 241 Indexer::Indexer( const Indexer &that ) : doDebug( that.doDebug ), tables( newRef( that.tables ) ), scope( that.scope ) { 220 (* indexers_count)++;242 (*stats_indexers().count)++; 221 243 } 222 244 … … 227 249 Indexer::~Indexer() { 228 250 if(tables) { 229 indexers_size->push( tables->idTable.size() );251 stats_indexers().size->push( tables->idTable.size() ); 230 252 size_t depth = 1; 231 253 for( auto crnt = tables->base.tables; crnt; crnt = crnt->base.tables ) { 232 254 ++depth; 233 255 } 234 indexers_depth_a->push( depth );235 indexers_depth_m->push( depth );256 stats_indexers().depth_a->push( depth ); 257 stats_indexers().depth_m->push( depth ); 236 258 } 237 259 deleteRef( tables ); … … 266 288 while ( searchTables ) { 267 289 268 (* idtable_find)++;269 idtable_key->push( id.size() );270 idtable_size->push( searchTables->idTable.size() );290 (*stats_idtable().find)++; 291 stats_idtable().key->push( id.size() ); 292 stats_idtable().size->push( searchTables->idTable.size() ); 271 293 IdTable::const_iterator decls = searchTables->idTable.find( id ); 272 294 if ( decls != searchTables->idTable.end() ) { … … 345 367 if ( tables->scope < scope ) return nullptr; 346 368 347 (* idtable_find)++;348 idtable_key->push( id.size() );349 idtable_size->push( tables->idTable.size() );369 (*stats_idtable().find)++; 370 stats_idtable().key->push( id.size() ); 371 stats_idtable().size->push( tables->idTable.size() ); 350 372 IdTable::const_iterator decls = tables->idTable.find( id ); 351 373 if ( decls != tables->idTable.end() ) { … … 366 388 if ( tables->scope < scope ) return false; 367 389 368 (* idtable_find)++;369 idtable_key->push( id.size() );370 idtable_size->push( tables->idTable.size() );390 (*stats_idtable().find)++; 391 stats_idtable().key->push( id.size() ); 392 stats_idtable().size->push( tables->idTable.size() ); 371 393 IdTable::const_iterator decls = tables->idTable.find( id ); 372 394 if ( decls != tables->idTable.end() ) { … … 385 407 if ( tables->scope < scope ) return false; 386 408 387 (* idtable_find)++;388 idtable_key->push( id.size() );389 idtable_size->push( tables->idTable.size() );409 (*stats_idtable().find)++; 410 stats_idtable().key->push( id.size() ); 411 stats_idtable().size->push( tables->idTable.size() ); 390 412 IdTable::const_iterator decls = tables->idTable.find( id ); 391 413 if ( decls != tables->idTable.end() ) { -
src/main.cc
r0050a5f r874ffa4 65 65 using namespace std; 66 66 67 #define PASS(name, pass) \ 67 68 void NewPass(const char * const name) { 69 Stats::Heap::newPass(name); 70 using namespace Stats::Counters; 71 static auto pass_visitor_group = build<CounterGroup>("Pass Visitor"); 72 auto pass = build<CounterGroup>(name, pass_visitor_group); 73 pass_visitor_stats.depth = 0; 74 pass_visitor_stats.avg = build<AverageCounter<double>>("Average Depth", pass); 75 pass_visitor_stats.max = build<MaxCounter<double>>("Max Depth", pass); 76 } 77 78 #define PASS(name, pass) \ 68 79 if ( errorp ) { cerr << name << endl; } \ 69 Stats::Heap::newPass(name);\80 NewPass(name); \ 70 81 pass; 71 82 … … 142 153 backtrace( 6 ); // skip first 6 stack frames 143 154 signal( SIGABRT, SIG_DFL); // reset default signal handler 144 155 raise( SIGABRT ); // reraise SIGABRT 145 156 } // sigAbortHandler 146 157 … … 181 192 } // if 182 193 194 NewPass("Parse"); 195 183 196 // read in the builtins, extras, and the prelude 184 197 if ( ! nopreludep ) { // include gcc builtins … … 233 246 234 247 // add the assignment statement after the initialization of a type parameter 235 PASS( " validate", SymTab::validate( translationUnit, symtabp ) );248 PASS( "Validate", SymTab::validate( translationUnit, symtabp ) ); 236 249 if ( symtabp ) { 237 250 deleteAll( translationUnit ); … … 250 263 } // if 251 264 252 PASS( " fixLabels", ControlStruct::fixLabels( translationUnit ) );253 PASS( " fixNames", CodeGen::fixNames( translationUnit ) );254 PASS( " genInit", InitTweak::genInit( translationUnit ) );255 PASS( " expandMemberTuples" , Tuples::expandMemberTuples( translationUnit ) );265 PASS( "Fix Labels", ControlStruct::fixLabels( translationUnit ) ); 266 PASS( "Fix Names", CodeGen::fixNames( translationUnit ) ); 267 PASS( "Gen Init", InitTweak::genInit( translationUnit ) ); 268 PASS( "Expand Member Tuples" , Tuples::expandMemberTuples( translationUnit ) ); 256 269 if ( libcfap ) { 257 270 // generate the bodies of cfa library functions … … 277 290 } 278 291 279 PASS( " resolve", ResolvExpr::resolve( translationUnit ) );292 PASS( "Resolve", ResolvExpr::resolve( translationUnit ) ); 280 293 if ( exprp ) { 281 294 dump( translationUnit ); … … 284 297 285 298 // fix ObjectDecl - replaces ConstructorInit nodes 286 PASS( " fixInit", InitTweak::fix( translationUnit, buildingLibrary() ) );299 PASS( "Fix Init", InitTweak::fix( translationUnit, buildingLibrary() ) ); 287 300 if ( ctorinitp ) { 288 301 dump ( translationUnit ); … … 290 303 } // if 291 304 292 PASS( " expandUniqueExpr", Tuples::expandUniqueExpr( translationUnit ) ); // xxx - is this the right place for this? want to expand ASAP so tha, sequent passes don't need to worry about double-visiting a unique expr - needs to go after InitTweak::fix so that copy constructed return declarations are reused293 294 PASS( " translateEHM" , ControlStruct::translateEHM( translationUnit ) );295 296 PASS( " generateWaitfor" , Concurrency::generateWaitFor( translationUnit ) );297 298 PASS( " convertSpecializations", GenPoly::convertSpecializations( translationUnit ) ); // needs to happen before tuple types are expanded299 300 PASS( " expandTuples", Tuples::expandTuples( translationUnit ) ); // xxx - is this the right place for this?305 PASS( "Expand Unique Expr", Tuples::expandUniqueExpr( translationUnit ) ); // xxx - is this the right place for this? want to expand ASAP so tha, sequent passes don't need to worry about double-visiting a unique expr - needs to go after InitTweak::fix so that copy constructed return declarations are reused 306 307 PASS( "Translate EHM" , ControlStruct::translateEHM( translationUnit ) ); 308 309 PASS( "Gen Waitfor" , Concurrency::generateWaitFor( translationUnit ) ); 310 311 PASS( "Convert Specializations", GenPoly::convertSpecializations( translationUnit ) ); // needs to happen before tuple types are expanded 312 313 PASS( "Expand Tuples", Tuples::expandTuples( translationUnit ) ); // xxx - is this the right place for this? 301 314 302 315 if ( tuplep ) { … … 305 318 } 306 319 307 PASS( " virtual expandCasts", Virtual::expandCasts( translationUnit ) ); // Must come after translateEHM308 309 PASS( " instantiateGenerics", GenPoly::instantiateGeneric( translationUnit ) );320 PASS( "Virtual Expand Casts", Virtual::expandCasts( translationUnit ) ); // Must come after translateEHM 321 322 PASS( "Instantiate Generics", GenPoly::instantiateGeneric( translationUnit ) ); 310 323 if ( genericsp ) { 311 324 dump( translationUnit ); 312 325 return 0; 313 326 } 314 PASS( " convertLvalue", GenPoly::convertLvalue( translationUnit ) );327 PASS( "Convert L-Value", GenPoly::convertLvalue( translationUnit ) ); 315 328 316 329 … … 319 332 return 0; 320 333 } // if 321 PASS( " box", GenPoly::box( translationUnit ) );334 PASS( "Box", GenPoly::box( translationUnit ) ); 322 335 323 336 if ( bcodegenp ) { … … 331 344 332 345 CodeTools::fillLocations( translationUnit ); 333 PASS( " codegen", CodeGen::generate( translationUnit, *output, ! noprotop, prettycodegenp, true, linemarks ) );346 PASS( "Code Gen", CodeGen::generate( translationUnit, *output, ! noprotop, prettycodegenp, true, linemarks ) ); 334 347 335 348 CodeGen::FixMain::fix( *output, (PreludeDirector + "/bootloader.c").c_str() ); … … 377 390 378 391 deleteAll( translationUnit ); 379 if(!libcfap && !treep) { 380 if(stats_counters) Stats::Counters::print(); 381 if(stats_heap) Stats::Heap::print(); 382 } 392 Stats::print(); 383 393 384 394 return 0; … … 421 431 while ( (c = getopt_long( argc, argv, "abBcCdefgGlLmnNpqrRstTvwW:yzZD:F:", long_opts, &long_index )) != -1 ) { 422 432 switch ( c ) { 423 424 433 case Ast: 434 case 'a': // dump AST 425 435 astp = true; 426 436 break; 427 428 437 case Bresolver: 438 case 'b': // print before resolver steps 429 439 bresolvep = true; 430 440 break; 431 441 case 'B': // print before box steps 432 442 bboxp = true; 433 443 break; 434 435 444 case CtorInitFix: 445 case 'c': // print after constructors and destructors are replaced 436 446 ctorinitp = true; 437 447 break; 438 448 case 'C': // print before code generation 439 449 bcodegenp = true; 440 450 break; 441 442 443 444 break; 445 446 451 case DeclStats: 452 case 'd': 453 declstatsp = true; 454 break; 455 case Expr: 456 case 'e': // dump AST after expression analysis 447 457 exprp = true; 448 458 break; 449 450 459 case ExprAlt: 460 case 'f': // print alternatives for expressions 451 461 expraltp = true; 452 462 break; 453 454 463 case Grammar: 464 case 'g': // bison debugging info (grammar rules) 455 465 yydebug = true; 456 466 break; 457 467 case 'G': // dump AST after instantiate generics 458 468 genericsp = true; 459 469 break; 460 461 470 case LibCFA: 471 case 'l': // generate libcfa.c 462 472 libcfap = true; 463 473 break; 464 465 474 case Linemarks: 475 case 'L': // print lines marks 466 476 linemarks = true; 467 477 break; 468 469 478 case Nopreamble: 479 case 'n': // do not read preamble 470 480 nopreludep = true; 471 481 break; 472 473 482 case Nolinemarks: 483 case 'N': // suppress line marks 474 484 linemarks = false; 475 485 break; 476 477 486 case Prototypes: 487 case 'p': // generate prototypes for preamble functions 478 488 noprotop = true; 479 489 break; 480 481 482 break; 483 484 485 break; 486 487 490 case PreludeDir: 491 PreludeDirector = optarg; 492 break; 493 case 'm': // don't replace the main 494 nomainp = true; 495 break; 496 case Parse: 497 case 'q': // dump parse tree 488 498 parsep = true; 489 499 break; 490 491 500 case Resolver: 501 case 'r': // print resolver steps 492 502 resolvep = true; 493 503 break; 494 504 case 'R': // dump resolv-proto instance 495 505 resolvprotop = true; 496 506 break; 497 case Stats: 498 { 499 std::stringstream ss(optarg); 500 while(ss.good()) { 501 std::string substr; 502 getline( ss, substr, ',' ); 503 if(substr == "counters") { 504 stats_counters = true; 505 } else if(substr == "heap") { 506 stats_heap = true; 507 } else if(substr == "none") { 508 stats_counters = false; 509 stats_heap = false; 510 } else { 511 std::cerr << "Ignoring unknown statistic " << substr << std::endl; 512 } 513 } 514 515 } 516 break; 517 case Symbol: 518 case 's': // print symbol table events 507 case Stats: 508 Stats::parse_params(optarg); 509 break; 510 case Symbol: 511 case 's': // print symbol table events 519 512 symtabp = true; 520 513 break; 521 522 514 case Tree: 515 case 't': // build in tree 523 516 treep = true; 524 517 break; 525 526 518 case TupleExpansion: 519 case 'T': // print after tuple expansion 527 520 tuplep = true; 528 521 break; 529 522 case 'v': // dump AST after decl validation pass 530 523 validp = true; 531 524 break; 532 525 case 'w': 533 526 Wsuppress = true; 534 527 break; 535 528 case 'W': 536 529 if ( strcmp( optarg, "all" ) == 0 ) { 537 530 SemanticWarning_EnableAll(); … … 550 543 } // if 551 544 break; 552 545 case 'y': // dump AST on error 553 546 errorp = true; 554 547 break; 555 548 case 'z': // dump as codegen rather than AST 556 549 codegenp = true; 557 550 break; … … 559 552 prettycodegenp = true; 560 553 break; 561 562 break; 563 554 case 'D': // ignore -Dxxx 555 break; 556 case 'F': // source file-name without suffix 564 557 filename = optarg; 565 558 break; 566 559 case '?': 567 560 if ( optopt ) { // short option ? 568 561 assertf( false, "Unknown option: -%c\n", (char)optopt ); … … 573 566 __attribute__((fallthrough)); 574 567 #endif 575 568 default: 576 569 abort(); 577 570 } // switch
Note: See TracChangeset
for help on using the changeset viewer.