Changeset b38433b for src/Common


Ignore:
Timestamp:
Mar 5, 2019, 6:17:55 PM (7 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, persistent-indexer, pthread-emulation, qualifiedEnum
Children:
b830e046, c101756
Parents:
34737de (diff), 972540e (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/Common
Files:
5 added
7 edited

Legend:

Unmodified
Added
Removed
  • src/Common/PassVisitor.h

    r34737de rb38433b  
    55#include <stack>
    66
     7#include "Common/Stats.h"
    78#include "Common/utility.h"
    89
     
    426427};
    427428
     429#include "Common/Stats.h"
     430
     431extern 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
    428437#include "SynTree/TypeSubstitution.h"
    429438#include "PassVisitor.impl.h"
  • src/Common/PassVisitor.impl.h

    r34737de rb38433b  
    6767        SemanticErrorException errors;
    6868
     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);
    6972        for ( std::list< Declaration* >::iterator i = decls.begin(); ; ++i ) {
     73
     74
    7075                // splice in new declarations after previous decl
    7176                if ( !empty( afterDecls ) ) { decls.splice( i, *afterDecls ); }
     
    8388                if ( !empty( beforeDecls ) ) { decls.splice( i, *beforeDecls ); }
    8489        }
     90        pass_visitor_stats.depth--;
    8591        if ( ! errors.isEmpty() ) {
    8692                throw errors;
     
    94100        SemanticErrorException errors;
    95101
     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);
    96105        for ( std::list< Declaration* >::iterator i = decls.begin(); ; ++i ) {
    97106                // splice in new declarations after previous decl
     
    109118                if ( !empty( beforeDecls ) ) { decls.splice( i, *beforeDecls ); }
    110119        }
     120        pass_visitor_stats.depth--;
    111121        if ( ! errors.isEmpty() ) {
    112122                throw errors;
     
    126136        if ( ! visitor.get_visit_children() ) return;
    127137        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);
    128142        for ( typename Container::iterator i = container.begin(); i != container.end(); ++i ) {
    129143                try {
     
    135149                }
    136150        }
     151        pass_visitor_stats.depth--;
    137152        if ( ! errors.isEmpty() ) {
    138153                throw errors;
     
    153168        if ( ! mutator.get_visit_children() ) return;
    154169        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);
    155174        for ( typename Container::iterator i = container.begin(); i != container.end(); ++i ) {
    156175                try {
     
    163182                } // try
    164183        } // for
     184        pass_visitor_stats.depth--;
    165185        if ( ! errors.isEmpty() ) {
    166186                throw errors;
     
    185205        DeclList_t* afterDecls  = get_afterDecls();
    186206
     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);
    187210        for ( std::list< Statement* >::iterator i = statements.begin(); i != statements.end(); ++i ) {
    188211
     
    202225                if ( !empty( beforeStmts ) ) { statements.splice( i, *beforeStmts ); }
    203226        }
     227        pass_visitor_stats.depth--;
    204228
    205229        if ( !empty( afterDecls ) ) { splice( std::back_inserter( statements ), afterDecls); }
  • src/Common/Stats.h

    r34737de rb38433b  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // Heap.h --
     7// Stats.h --
    88//
    99// Author           : Thierry Delisle
     
    1616#pragma once
    1717
     18// Entry point for compiler analytics.
     19/*
     20The compiler currently supports 3 times of analytics:
     21         - generic counters
     22         - heap statistics
     23         - timiing statistics
     24
     25These can be enabled using the --stats option, to which a comma seperated list of options can be passed.
     26For more details see Stats.cc
     27
     28Counters:
     29        The counters are a generic tree of counters that print in a 2-column output format.
     30        They can count maximums, averages, totals, etc.
     31
     32        Currently all counters are under the same enable block, this could be changed if needed.
     33
     34Heap:
     35        Measures the total calls malloc and free as the peak number of allocations per pass
     36
     37Timing:
     38        Comming soon
     39*/
     40
     41
    1842#include "Common/Stats/Counter.h"
    1943#include "Common/Stats/Heap.h"
     44#include "Common/Stats/Time.h"
     45
     46namespace Stats {
     47        void parse_params(const char * const params);
     48        void print();
     49}
  • src/Common/Stats/Counter.cc

    r34737de rb38433b  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // Heap.h --
     7// Counter.cc --
    88//
    99// Author           : Thierry Delisle
     
    1818#include <algorithm>
    1919#include <cstring>
     20#include <functional>
    2021#include <iomanip>
    2122
    2223namespace Stats {
    2324        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 
    3625                void print() {
    37                         if(!BaseCounter::top.head) return;
     26                        if(!top.head) return;
    3827                        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) {
    4029                                nc = std::max(nc, (4 * level) + std::strlen(node->name));
    4130                        });
     
    4938
    5039
    51                         ForAllCounters(BaseCounter::top, 0, [&](BaseCounter * node, size_t level) {
     40                        Base::ForAll(top, 0, [&](Base::TreeImpl * node, size_t level) {
    5241                                std::cerr << std::string(level * 4, ' ');
    5342                                std::cerr << node->name;
     
    5847                                std::cerr << " |";
    5948                                std::cerr << '\n';
    60                                 delete node;
    61                         });
     49                        }, true);
    6250
    6351                        std::cerr << std::string(nct, '-') << std::endl;
    6452                }
    6553
    66                 BaseCounter::list_t BaseCounter::top;
     54                Base::TreeTop top;
     55
     56                extern bool enabled;
    6757        }
    6858}
  • src/Common/Stats/Counter.h

    r34737de rb38433b  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // Heap.h --
     7// Counter.h --
    88//
    99// Author           : Thierry Delisle
     
    1919#include <iostream>
    2020
     21#include "Common/Stats/Base.h"
     22
     23#if defined( NO_STATISTICS )
     24        #define NO_COUNTER_STATISTICS
     25#endif
     26
    2127namespace Stats {
    2228        namespace Counters {
    23                 void print();
     29#               if defined(NO_COUNTERS_STATISTICS)
    2430
    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;
    2958                        }
    3059
    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;
    3363                        }
    34                 protected:
    35                         virtual ~BaseCounter() = default;
     64#               else
     65                        extern bool enabled;
    3666
    37                         struct list_t {
    38                                 BaseCounter * head = nullptr;
    39                                 BaseCounter * tail = nullptr;
     67                        extern Base::TreeTop top;
    4068
    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;
    4677                        };
    4778
    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
    5096                        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{} {}
    53101
    54                 private:
    55                         const char * const name;
     102                                virtual void print(std::ostream & os) { os << sum / count; }
    56103
    57                         BaseCounter * next = nullptr;
    58                         list_t children;
     104                                inline void push(T value) { if(!enabled) return; sum += value; count++; }
    59105
    60                         static list_t top;
    61                 };
     106                        protected:
     107                                virtual ~AverageCounter() = default;
    62108
    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                        };
    67113
    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{} {}
    70119
    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; }
    79121
    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); }
    84123
    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;
    89126
    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                        };
    97130
    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);
    111135                        }
    112136
    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);
    119141                        }
    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
    151143        }
    152144}
  • src/Common/Stats/Heap.cc

    r34737de rb38433b  
    2121#include <iostream>
    2222
     23#if defined( NO_STATISTICS )
     24        #define NO_HEAP_STATISTICS
     25#endif
     26
    2327namespace Stats {
    2428        namespace Heap {
     
    2832                void print() {}
    2933#else
     34                extern bool enabled;
     35
    3036                struct StatBlock {
    3137                        const char * name  = nullptr;   ///< Name of this pass
     
    7783
    7884                void print() {
     85                        if(!enabled) return;
     86
    7987                        size_t nc = 0;
    8088                        size_t total_mallocs = 0;
     
    166174                        void * malloc( size_t size ) {
    167175                                static auto __malloc = reinterpret_cast<void * (*)(size_t)>(interpose_symbol( "malloc", nullptr ));
    168                                 if( passes_cnt > 0 ) {
     176                                if( enabled && passes_cnt > 0 ) {
    169177                                        passes[passes_cnt - 1].mallocs++;
    170178                                        passes[passes_cnt - 1].n_allocs++;
     
    177185                        void free( void * ptr ) {
    178186                                static auto __free = reinterpret_cast<void   (*)(void *)>(interpose_symbol( "free", nullptr ));
    179                                 if( passes_cnt > 0 ) {
     187                                if( enabled && passes_cnt > 0 ) {
    180188                                        passes[passes_cnt - 1].frees++;
    181189                                        passes[passes_cnt - 1].n_allocs--;
     
    186194                        void * calloc( size_t nelem, size_t size ) {
    187195                                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 ) {
    189197                                        passes[passes_cnt - 1].mallocs++;
    190198                                        passes[passes_cnt - 1].n_allocs++;
     
    198206                                static auto __realloc = reinterpret_cast<void * (*)(void *, size_t)>(interpose_symbol( "realloc", nullptr ));
    199207                                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 ?
    201209                                        passes[passes_cnt - 1].mallocs++;
    202210                                        passes[passes_cnt - 1].frees++;
  • src/Common/module.mk

    r34737de rb38433b  
    1717SRC_COMMON = \
    1818      Common/Assert.cc \
     19      Common/Eval.cc \
     20      Common/PassVisitor.cc \
     21      Common/SemanticError.cc \
     22      Common/Stats/Counter.cc \
    1923      Common/Stats/Heap.cc \
    20       Common/Stats/Counter.cc \
    21       Common/Eval.cc \
    22       Common/SemanticError.cc \
     24      Common/Stats/Stats.cc \
     25      Common/Stats/Time.cc \
    2326      Common/UniqueName.cc
    2427
Note: See TracChangeset for help on using the changeset viewer.