Changeset 675716e


Ignore:
Timestamp:
Mar 1, 2019, 3:10:09 PM (5 years ago)
Author:
tdelisle <tdelisle@…>
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:
1cb7fab2
Parents:
8e70823
Message:

Instrumented PassVisitor? to print average/max depth

Location:
src
Files:
1 added
8 edited

Legend:

Unmodified
Added
Removed
  • src/Common/PassVisitor.h

    r8e70823 r675716e  
    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

    r8e70823 r675716e  
    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/Base.h

    r8e70823 r675716e  
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2019 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// Heap.h --
     8//
     9// Author           : Thierry Delisle
     10// Created On       : Fri Mar 03 14:53:53 2019
     11// Last Modified By :
     12// Last Modified On :
     13// Update Count     :
     14//
     15
    116#pragma once
    217
  • src/Common/Stats/Counter.cc

    r8e70823 r675716e  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // Heap.h --
     7// Counter.cc --
    88//
    99// Author           : Thierry Delisle
  • src/Common/Stats/Counter.h

    r8e70823 r675716e  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // Heap.h --
     7// Counter.h --
    88//
    99// Author           : Thierry Delisle
  • src/Common/module.mk

    r8e70823 r675716e  
    1717SRC_COMMON = \
    1818      Common/Assert.cc \
     19      Common/Eval.cc \
     20      Common/PassVisitor.cc \
     21      Common/SemanticError.cc \
    1922      Common/Stats/Heap.cc \
    2023      Common/Stats/Counter.cc \
    21       Common/Eval.cc \
    22       Common/SemanticError.cc \
    2324      Common/UniqueName.cc
    2425
  • src/Makefile.in

    r8e70823 r675716e  
    165165        CodeGen/FixMain.$(OBJEXT) CodeGen/GenType.$(OBJEXT) \
    166166        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)
     167am__objects_2 = Common/Assert.$(OBJEXT) Common/Eval.$(OBJEXT) \
     168        Common/PassVisitor.$(OBJEXT) Common/SemanticError.$(OBJEXT) \
     169        Common/Stats/Heap.$(OBJEXT) Common/Stats/Counter.$(OBJEXT) \
     170        Common/UniqueName.$(OBJEXT)
    170171am__objects_3 = ControlStruct/ForExprMutator.$(OBJEXT) \
    171172        ControlStruct/LabelFixer.$(OBJEXT) \
     
    560561SRC_COMMON = \
    561562      Common/Assert.cc \
     563      Common/Eval.cc \
     564      Common/PassVisitor.cc \
     565      Common/SemanticError.cc \
    562566      Common/Stats/Heap.cc \
    563567      Common/Stats/Counter.cc \
    564       Common/Eval.cc \
    565       Common/SemanticError.cc \
    566568      Common/UniqueName.cc
    567569
     
    721723Common/Assert.$(OBJEXT): Common/$(am__dirstamp) \
    722724        Common/$(DEPDIR)/$(am__dirstamp)
     725Common/Eval.$(OBJEXT): Common/$(am__dirstamp) \
     726        Common/$(DEPDIR)/$(am__dirstamp)
     727Common/PassVisitor.$(OBJEXT): Common/$(am__dirstamp) \
     728        Common/$(DEPDIR)/$(am__dirstamp)
     729Common/SemanticError.$(OBJEXT): Common/$(am__dirstamp) \
     730        Common/$(DEPDIR)/$(am__dirstamp)
    723731Common/Stats/$(am__dirstamp):
    724732        @$(MKDIR_P) Common/Stats
     
    731739Common/Stats/Counter.$(OBJEXT): Common/Stats/$(am__dirstamp) \
    732740        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)
    737741Common/UniqueName.$(OBJEXT): Common/$(am__dirstamp) \
    738742        Common/$(DEPDIR)/$(am__dirstamp)
     
    11151119@AMDEP_TRUE@@am__include@ @am__quote@Common/$(DEPDIR)/DebugMalloc.Po@am__quote@
    11161120@AMDEP_TRUE@@am__include@ @am__quote@Common/$(DEPDIR)/Eval.Po@am__quote@
     1121@AMDEP_TRUE@@am__include@ @am__quote@Common/$(DEPDIR)/PassVisitor.Po@am__quote@
    11171122@AMDEP_TRUE@@am__include@ @am__quote@Common/$(DEPDIR)/SemanticError.Po@am__quote@
    11181123@AMDEP_TRUE@@am__include@ @am__quote@Common/$(DEPDIR)/UniqueName.Po@am__quote@
  • src/main.cc

    r8e70823 r675716e  
    6565using namespace std;
    6666
    67 #define PASS(name, pass)                   \
     67auto pass_visitor_group = new Stats::Counters::CounterGroup("Pass Visitor");
     68
     69void NewPass(const char * const name) {
     70        Stats::Heap::newPass(name);
     71        auto pass = new Stats::Counters::CounterGroup(name, pass_visitor_group);
     72        pass_visitor_stats.depth = 0;
     73        pass_visitor_stats.avg = new Stats::Counters::AverageCounter<double>("Average Depth", pass);
     74        pass_visitor_stats.max = new Stats::Counters::MaxCounter<double>("Max Depth", pass);
     75}
     76
     77#define PASS(name, pass)                  \
    6878        if ( errorp ) { cerr << name << endl; } \
    69         Stats::Heap::newPass(name);               \
     79        NewPass(name);                          \
    7080        pass;
    7181
     
    142152        backtrace( 6 );                                                                         // skip first 6 stack frames
    143153        signal( SIGABRT, SIG_DFL);                                                      // reset default signal handler
    144     raise( SIGABRT );                                                                   // reraise SIGABRT
     154                raise( SIGABRT );                                                                       // reraise SIGABRT
    145155} // sigAbortHandler
    146156
     
    181191                } // if
    182192
     193                NewPass("Parse");
     194
    183195                // read in the builtins, extras, and the prelude
    184196                if ( ! nopreludep ) {                                                   // include gcc builtins
     
    233245
    234246                // add the assignment statement after the initialization of a type parameter
    235                 PASS( "validate", SymTab::validate( translationUnit, symtabp ) );
     247                PASS( "Validate", SymTab::validate( translationUnit, symtabp ) );
    236248                if ( symtabp ) {
    237249                        deleteAll( translationUnit );
     
    250262                } // if
    251263
    252                 PASS( "fixLabels", ControlStruct::fixLabels( translationUnit ) );
    253                 PASS( "fixNames", CodeGen::fixNames( translationUnit ) );
    254                 PASS( "genInit", InitTweak::genInit( translationUnit ) );
    255                 PASS( "expandMemberTuples" , Tuples::expandMemberTuples( translationUnit ) );
     264                PASS( "Fix Labels", ControlStruct::fixLabels( translationUnit ) );
     265                PASS( "Fix Names", CodeGen::fixNames( translationUnit ) );
     266                PASS( "Gen Init", InitTweak::genInit( translationUnit ) );
     267                PASS( "Expand Member Tuples" , Tuples::expandMemberTuples( translationUnit ) );
    256268                if ( libcfap ) {
    257269                        // generate the bodies of cfa library functions
     
    277289                }
    278290
    279                 PASS( "resolve", ResolvExpr::resolve( translationUnit ) );
     291                PASS( "Resolve", ResolvExpr::resolve( translationUnit ) );
    280292                if ( exprp ) {
    281293                        dump( translationUnit );
     
    284296
    285297                // fix ObjectDecl - replaces ConstructorInit nodes
    286                 PASS( "fixInit", InitTweak::fix( translationUnit, buildingLibrary() ) );
     298                PASS( "Fix Init", InitTweak::fix( translationUnit, buildingLibrary() ) );
    287299                if ( ctorinitp ) {
    288300                        dump ( translationUnit );
     
    290302                } // if
    291303
    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 reused
    293 
    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 expanded
    299 
    300                 PASS( "expandTuples", Tuples::expandTuples( translationUnit ) ); // xxx - is this the right place for this?
     304                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
     305
     306                PASS( "Translate EHM" , ControlStruct::translateEHM( translationUnit ) );
     307
     308                PASS( "Gen Waitfor" , Concurrency::generateWaitFor( translationUnit ) );
     309
     310                PASS( "Convert Specializations",  GenPoly::convertSpecializations( translationUnit ) ); // needs to happen before tuple types are expanded
     311
     312                PASS( "Expand Tuples", Tuples::expandTuples( translationUnit ) ); // xxx - is this the right place for this?
    301313
    302314                if ( tuplep ) {
     
    305317                }
    306318
    307                 PASS( "virtual expandCasts", Virtual::expandCasts( translationUnit ) ); // Must come after translateEHM
    308 
    309                 PASS( "instantiateGenerics", GenPoly::instantiateGeneric( translationUnit ) );
     319                PASS( "Virtual Expand Casts", Virtual::expandCasts( translationUnit ) ); // Must come after translateEHM
     320
     321                PASS( "Instantiate Generics", GenPoly::instantiateGeneric( translationUnit ) );
    310322                if ( genericsp ) {
    311323                        dump( translationUnit );
    312324                        return 0;
    313325                }
    314                 PASS( "convertLvalue", GenPoly::convertLvalue( translationUnit ) );
     326                PASS( "Convert L-Value", GenPoly::convertLvalue( translationUnit ) );
    315327
    316328
     
    319331                        return 0;
    320332                } // if
    321                 PASS( "box", GenPoly::box( translationUnit ) );
     333                PASS( "Box", GenPoly::box( translationUnit ) );
    322334
    323335                if ( bcodegenp ) {
     
    331343
    332344                CodeTools::fillLocations( translationUnit );
    333                 PASS( "codegen", CodeGen::generate( translationUnit, *output, ! noprotop, prettycodegenp, true, linemarks ) );
     345                PASS( "Code Gen", CodeGen::generate( translationUnit, *output, ! noprotop, prettycodegenp, true, linemarks ) );
    334346
    335347                CodeGen::FixMain::fix( *output, (PreludeDirector + "/bootloader.c").c_str() );
     
    421433        while ( (c = getopt_long( argc, argv, "abBcCdefgGlLmnNpqrRstTvwW:yzZD:F:", long_opts, &long_index )) != -1 ) {
    422434                switch ( c ) {
    423                   case Ast:
    424                   case 'a':                                                                             // dump AST
     435                        case Ast:
     436                        case 'a':                                                                               // dump AST
    425437                        astp = true;
    426438                        break;
    427                   case Bresolver:
    428                   case 'b':                                                                             // print before resolver steps
     439                        case Bresolver:
     440                        case 'b':                                                                               // print before resolver steps
    429441                        bresolvep = true;
    430442                        break;
    431                   case 'B':                                                                             // print before box steps
     443                        case 'B':                                                                               // print before box steps
    432444                        bboxp = true;
    433445                        break;
    434                   case CtorInitFix:
    435                   case 'c':                                                                             // print after constructors and destructors are replaced
     446                        case CtorInitFix:
     447                        case 'c':                                                                               // print after constructors and destructors are replaced
    436448                        ctorinitp = true;
    437449                        break;
    438                   case 'C':                                                                             // print before code generation
     450                        case 'C':                                                                               // print before code generation
    439451                        bcodegenp = true;
    440452                        break;
    441                   case DeclStats:
    442                   case 'd':
    443                     declstatsp = true;
    444                         break;
    445                   case Expr:
    446                   case 'e':                                                                             // dump AST after expression analysis
     453                        case DeclStats:
     454                        case 'd':
     455                                declstatsp = true;
     456                        break;
     457                        case Expr:
     458                        case 'e':                                                                               // dump AST after expression analysis
    447459                        exprp = true;
    448460                        break;
    449                   case ExprAlt:
    450                   case 'f':                                                                             // print alternatives for expressions
     461                        case ExprAlt:
     462                        case 'f':                                                                               // print alternatives for expressions
    451463                        expraltp = true;
    452464                        break;
    453                   case Grammar:
    454                   case 'g':                                                                             // bison debugging info (grammar rules)
     465                        case Grammar:
     466                        case 'g':                                                                               // bison debugging info (grammar rules)
    455467                        yydebug = true;
    456468                        break;
    457                   case 'G':                                                                             // dump AST after instantiate generics
     469                        case 'G':                                                                               // dump AST after instantiate generics
    458470                        genericsp = true;
    459471                        break;
    460                   case LibCFA:
    461                   case 'l':                                                                             // generate libcfa.c
     472                        case LibCFA:
     473                        case 'l':                                                                               // generate libcfa.c
    462474                        libcfap = true;
    463475                        break;
    464                   case Linemarks:
    465                   case 'L':                                                                             // print lines marks
     476                        case Linemarks:
     477                        case 'L':                                                                               // print lines marks
    466478                        linemarks = true;
    467479                        break;
    468                   case Nopreamble:
    469                   case 'n':                                                                             // do not read preamble
     480                        case Nopreamble:
     481                        case 'n':                                                                               // do not read preamble
    470482                        nopreludep = true;
    471483                        break;
    472                   case Nolinemarks:
    473                   case 'N':                                                                             // suppress line marks
     484                        case Nolinemarks:
     485                        case 'N':                                                                               // suppress line marks
    474486                        linemarks = false;
    475487                        break;
    476                   case Prototypes:
    477                   case 'p':                                                                             // generate prototypes for preamble functions
     488                        case Prototypes:
     489                        case 'p':                                                                               // generate prototypes for preamble functions
    478490                        noprotop = true;
    479491                        break;
    480                   case PreludeDir:
    481                         PreludeDirector = optarg;
    482                         break;
    483                   case 'm':                                                                             // don't replace the main
    484                         nomainp = true;
    485                         break;
    486                   case Parse:
    487                   case 'q':                                                                             // dump parse tree
     492                        case PreludeDir:
     493                                PreludeDirector = optarg;
     494                        break;
     495                        case 'm':                                                                               // don't replace the main
     496                                nomainp = true;
     497                        break;
     498                        case Parse:
     499                        case 'q':                                                                               // dump parse tree
    488500                        parsep = true;
    489501                        break;
    490                   case Resolver:
    491                   case 'r':                                                                             // print resolver steps
     502                        case Resolver:
     503                        case 'r':                                                                               // print resolver steps
    492504                        resolvep = true;
    493505                        break;
    494                   case 'R':                                                                             // dump resolv-proto instance
     506                        case 'R':                                                                               // dump resolv-proto instance
    495507                        resolvprotop = true;
    496508                        break;
    497                   case Stats:
     509                        case Stats:
    498510                        {
    499511                                std::stringstream ss(optarg);
     
    515527                        }
    516528                        break;
    517                   case Symbol:
    518                   case 's':                                                                             // print symbol table events
     529                        case Symbol:
     530                        case 's':                                                                               // print symbol table events
    519531                        symtabp = true;
    520532                        break;
    521                   case Tree:
    522                   case 't':                                                                             // build in tree
     533                        case Tree:
     534                        case 't':                                                                               // build in tree
    523535                        treep = true;
    524536                        break;
    525                   case TupleExpansion:
    526                   case 'T':                                                                             // print after tuple expansion
     537                        case TupleExpansion:
     538                        case 'T':                                                                               // print after tuple expansion
    527539                        tuplep = true;
    528540                        break;
    529                   case 'v':                                                                             // dump AST after decl validation pass
     541                        case 'v':                                                                               // dump AST after decl validation pass
    530542                        validp = true;
    531543                        break;
    532                   case 'w':
     544                        case 'w':
    533545                        Wsuppress = true;
    534546                        break;
    535                   case 'W':
     547                        case 'W':
    536548                        if ( strcmp( optarg, "all" ) == 0 ) {
    537549                                SemanticWarning_EnableAll();
     
    550562                        } // if
    551563                        break;
    552                   case 'y':                                                                             // dump AST on error
     564                        case 'y':                                                                               // dump AST on error
    553565                        errorp = true;
    554566                        break;
    555                   case 'z':                                                                             // dump as codegen rather than AST
     567                        case 'z':                                                                               // dump as codegen rather than AST
    556568                        codegenp = true;
    557569                        break;
     
    559571                        prettycodegenp = true;
    560572                        break;
    561                   case 'D':                                                                             // ignore -Dxxx
    562                         break;
    563                   case 'F':                                                                             // source file-name without suffix
     573                        case 'D':                                                                               // ignore -Dxxx
     574                        break;
     575                        case 'F':                                                                               // source file-name without suffix
    564576                        filename = optarg;
    565577                        break;
    566                   case '?':
     578                        case '?':
    567579                        if ( optopt ) {                                                         // short option ?
    568580                                assertf( false, "Unknown option: -%c\n", (char)optopt );
     
    573585                                __attribute__((fallthrough));
    574586                        #endif
    575                   default:
     587                        default:
    576588                        abort();
    577589                } // switch
Note: See TracChangeset for help on using the changeset viewer.