Changeset a5294af


Ignore:
Timestamp:
May 25, 2023, 5:00:06 PM (6 months ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ast-experimental, master
Children:
a5aa5bf
Parents:
4246869 (diff), bccd70a (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

Files:
22 added
20 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/concurrency/channel.hfa

    r4246869 ra5294af  
    6262    bool closed;                      // indicates channel close/open
    6363    #ifdef CHAN_STATS
    64     size_t blocks, operations;      // counts total ops and ops resulting in a blocked thd
     64    size_t p_blocks, p_ops, c_blocks, c_ops;      // counts total ops and ops resulting in a blocked thd
    6565    #endif
    6666};
     
    7575    closed = false;
    7676    #ifdef CHAN_STATS
    77     blocks = 0;
    78     operations = 0;
     77    p_blocks = 0;
     78    p_ops = 0;
     79    c_blocks = 0;
     80    c_ops = 0;
    7981    #endif
    8082}
     
    8385static inline void ^?{}( channel(T) &c ) with(c) {
    8486    #ifdef CHAN_STATS
    85     printf("Channel %p Blocks: %lu, Operations: %lu, %.2f%% of ops blocked\n", &c, blocks, operations, ((double)blocks)/operations * 100);
    86     #endif
    87     verifyf( cons`isEmpty && prods`isEmpty, "Attempted to delete channel with waiting threads (Deadlock).\n" );
     87    printf("Channel %p Blocks: %lu,\t\tOperations: %lu,\t%.2f%% of ops blocked\n", &c, p_blocks + c_blocks, p_ops + c_ops, ((double)p_blocks + c_blocks)/(p_ops + c_ops) * 100);
     88    printf("Channel %p Consumer Blocks: %lu,\tConsumer Ops: %lu,\t%.2f%% of Consumer ops blocked\n", &c, p_blocks, p_ops, ((double)p_blocks)/p_ops * 100);
     89    printf("Channel %p Producer Blocks: %lu,\tProducer Ops: %lu,\t%.2f%% of Producer ops blocked\n", &c, c_blocks, c_ops, ((double)c_blocks)/c_ops * 100);
     90    #endif
     91    verifyf( __handle_waituntil_OR( cons ) || __handle_waituntil_OR( prods ) || cons`isEmpty && prods`isEmpty,
     92        "Attempted to delete channel with waiting threads (Deadlock).\n" );
    8893    if ( size != 0 ) delete( buffer );
    8994}
     
    149154    lock( mutex_lock );
    150155    #ifdef CHAN_STATS
    151     operations++;
     156    p_ops++;
    152157    #endif
    153158
     
    187192
    188193    #ifdef CHAN_STATS
    189     if ( !closed ) operations++;
     194    if ( !closed ) p_ops++;
    190195    #endif
    191196
     
    208213    if ( count == size ) {
    209214        #ifdef CHAN_STATS
    210         blocks++;
     215        p_blocks++;
    211216        #endif
    212217
     
    237242    lock( mutex_lock );
    238243    #ifdef CHAN_STATS
    239     operations++;
     244    c_ops++;
    240245    #endif
    241246
     
    285290
    286291    #ifdef CHAN_STATS
    287     if ( !closed ) operations++;
     292    if ( !closed ) c_ops++;
    288293    #endif
    289294
     
    305310    if ( count == 0 ) {
    306311        #ifdef CHAN_STATS
    307         blocks++;
     312        c_blocks++;
    308313        #endif
    309314        // check for if woken due to close
     
    323328///////////////////////////////////////////////////////////////////////////////////////////
    324329static inline bool unregister_chan( channel(T) & chan, select_node & node ) with(chan) {
    325     // if ( !node`isListed && !node.park_counter ) return false; // handle special OR case C_TODO: try adding this back
     330    if ( !node`isListed && !node.park_counter ) return false; // handle special OR case
    326331    lock( mutex_lock );
    327332    if ( node`isListed ) { // op wasn't performed
    328         #ifdef CHAN_STATS
    329         operations--;
    330         #endif
    331333        remove( node );
    332334        unlock( mutex_lock );
     
    362364
    363365    #ifdef CHAN_STATS
    364     if ( !closed ) operations++;
     366    if ( !closed ) c_ops++;
    365367    #endif
    366368
     
    407409    if ( count == 0 ) {
    408410        #ifdef CHAN_STATS
    409         blocks++;
     411        c_blocks++;
    410412        #endif
    411413       
     
    451453
    452454    #ifdef CHAN_STATS
    453     if ( !closed ) operations++;
     455    if ( !closed ) p_ops++;
    454456    #endif
    455457
     
    498500    if ( count == size ) {
    499501        #ifdef CHAN_STATS
    500         blocks++;
     502        p_blocks++;
    501503        #endif
    502504
  • libcfa/src/concurrency/locks.hfa

    r4246869 ra5294af  
    176176static inline void ?{}(mcs_spin_node & this) { this.next = 0p; this.locked = true; }
    177177
    178 static inline mcs_spin_node * volatile & ?`next ( mcs_spin_node * node ) {
    179         return node->next;
    180 }
    181 
    182178struct mcs_spin_lock {
    183179        mcs_spin_queue queue;
     
    185181
    186182static inline void lock(mcs_spin_lock & l, mcs_spin_node & n) {
     183    n.locked = true;
    187184        mcs_spin_node * prev = __atomic_exchange_n(&l.queue.tail, &n, __ATOMIC_SEQ_CST);
    188         n.locked = true;
    189         if(prev == 0p) return;
     185        if( prev == 0p ) return;
    190186        prev->next = &n;
    191         while(__atomic_load_n(&n.locked, __ATOMIC_RELAXED)) Pause();
     187        while( __atomic_load_n(&n.locked, __ATOMIC_RELAXED) ) Pause();
    192188}
    193189
     
    195191        mcs_spin_node * n_ptr = &n;
    196192        if (__atomic_compare_exchange_n(&l.queue.tail, &n_ptr, 0p, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) return;
    197         while (__atomic_load_n(&n.next, __ATOMIC_RELAXED) == 0p) {}
     193        while (__atomic_load_n(&n.next, __ATOMIC_RELAXED) == 0p) Pause();
    198194        n.next->locked = false;
    199195}
  • src/AST/Pass.impl.hpp

    r4246869 ra5294af  
    2020#include <unordered_map>
    2121
     22#include "AST/Copy.hpp"
    2223#include "AST/TranslationUnit.hpp"
    2324#include "AST/TypeSubstitution.hpp"
  • src/AST/Print.cpp

    r4246869 ra5294af  
    1616#include "Print.hpp"
    1717
     18#include "Attribute.hpp"
    1819#include "Decl.hpp"
    1920#include "Expr.hpp"
     21#include "Init.hpp"
    2022#include "Stmt.hpp"
    2123#include "Type.hpp"
    2224#include "TypeSubstitution.hpp"
    2325#include "CompilationState.h"
    24 
    25 #include "Common/utility.h" // for group_iterate
     26#include "Common/Iterate.hpp"
    2627
    2728using namespace std;
  • src/AST/SymbolTable.cpp

    r4246869 ra5294af  
    1818#include <cassert>
    1919
     20#include "Copy.hpp"
    2021#include "Decl.hpp"
    2122#include "Expr.hpp"
  • src/AST/TypeSubstitution.cpp

    r4246869 ra5294af  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Mon Jun  3 13:26:00 2017
    13 // Update Count     : 5
    14 //
     12// Last Modified On : Thr May 25 11:24:00 2023
     13// Update Count     : 6
     14//
     15
     16#include "TypeSubstitution.hpp"
    1517
    1618#include "Type.hpp"   // for TypeInstType, Type, StructInstType, UnionInstType
    17 #include "TypeSubstitution.hpp"
     19#include "Pass.hpp"   // for Pass, PureVisitor, WithGuards, WithVisitorRef
    1820
    1921namespace ast {
    20 
    21 
    22 // size_t TypeSubstitution::Substituter::traceId = Stats::Heap::new_stacktrace_id("TypeSubstitution");
    2322
    2423TypeSubstitution::TypeSubstitution() {
     
    119118}
    120119
     120// definitition must happen after PassVisitor is included so that WithGuards can be used
     121struct TypeSubstitution::Substituter : public WithGuards, public WithVisitorRef<Substituter>, public PureVisitor {
     122        //static size_t traceId;
     123
     124        Substituter( const TypeSubstitution & sub, bool freeOnly ) : sub( sub ), freeOnly( freeOnly ) {}
     125
     126        const Type * postvisit( const TypeInstType * aggregateUseType );
     127
     128        /// Records type variable bindings from forall-statements
     129        void previsit( const FunctionType * type );
     130        /// Records type variable bindings from forall-statements and instantiations of generic types
     131        // void handleAggregateType( const BaseInstType * type );
     132
     133        // void previsit( const StructInstType * aggregateUseType );
     134        // void previsit( const UnionInstType * aggregateUseType );
     135
     136        const TypeSubstitution & sub;
     137        int subCount = 0;
     138        bool freeOnly;
     139        typedef std::unordered_set< TypeEnvKey > BoundVarsType;
     140        BoundVarsType boundVars;
     141};
     142
     143// size_t TypeSubstitution::Substituter::traceId = Stats::Heap::new_stacktrace_id("TypeSubstitution");
     144
    121145void TypeSubstitution::normalize() {
    122146        Pass<Substituter> sub( *this, true );
     
    128152                }
    129153        } while ( sub.core.subCount );
     154}
     155
     156TypeSubstitution::ApplyResult<Node> TypeSubstitution::applyBase(
     157                const Node * input, bool isFree ) const {
     158        assert( input );
     159        Pass<Substituter> sub( *this, isFree );
     160        const Node * output = input->accept( sub );
     161        return { output, sub.core.subCount };
    130162}
    131163
  • src/AST/TypeSubstitution.hpp

    r4246869 ra5294af  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Apr 30 22:52:47 2019
    13 // Update Count     : 9
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Thr May 25 12:31:00 2023
     13// Update Count     : 10
    1414//
    1515
     
    4646        TypeSubstitution &operator=( const TypeSubstitution &other );
    4747
    48         template< typename SynTreeClass >
     48        template< typename node_t >
    4949        struct ApplyResult {
    50                 ast::ptr<SynTreeClass> node;
     50                ast::ptr<node_t> node;
    5151                int count;
    5252        };
    5353
    54         template< typename SynTreeClass > ApplyResult<SynTreeClass> apply( const SynTreeClass * input ) const;
    55         template< typename SynTreeClass > ApplyResult<SynTreeClass> applyFree( const SynTreeClass * input ) const;
     54        template< typename node_t >
     55        ApplyResult<node_t> apply( const node_t * input ) const {
     56                ApplyResult<Node> ret = applyBase( input, false );
     57                return { ret.node.strict_as<node_t>(), ret.count };
     58        }
    5659
    5760        template< typename node_t, enum Node::ref_type ref_t >
    5861        int apply( ptr_base< node_t, ref_t > & input ) const {
    59                 const node_t * p = input.get();
    60                 auto ret = apply(p);
    61                 input = ret.node;
     62                ApplyResult<Node> ret = applyBase( input.get(), false );
     63                input = ret.node.strict_as<node_t>();
    6264                return ret.count;
     65        }
     66
     67        template< typename node_t >
     68        ApplyResult<node_t> applyFree( const node_t * input ) const {
     69                ApplyResult<Node> ret = applyBase( input, true );
     70                return { ret.node.strict_as<node_t>(), ret.count };
    6371        }
    6472
    6573        template< typename node_t, enum Node::ref_type ref_t >
    6674        int applyFree( ptr_base< node_t, ref_t > & input ) const {
    67                 const node_t * p = input.get();
    68                 auto ret = applyFree(p);
    69                 input = ret.node;
     75                ApplyResult<Node> ret = applyBase( input.get(), true );
     76                input = ret.node.strict_as<node_t>();
    7077                return ret.count;
    7178        }
     
    97104        // Mutator that performs the substitution
    98105        struct Substituter;
     106        ApplyResult<Node> applyBase( const Node * input, bool isFree ) const;
    99107
    100108        // TODO: worry about traversing into a forall-qualified function type or type decl with assertions
     
    158166} // namespace ast
    159167
    160 // include needs to happen after TypeSubstitution is defined so that both TypeSubstitution and
    161 // PassVisitor are defined before PassVisitor implementation accesses TypeSubstitution internals.
    162 #include "Pass.hpp"
    163 #include "Copy.hpp"
    164 
    165 namespace ast {
    166 
    167 // definitition must happen after PassVisitor is included so that WithGuards can be used
    168 struct TypeSubstitution::Substituter : public WithGuards, public WithVisitorRef<Substituter>, public PureVisitor {
    169                 static size_t traceId;
    170 
    171                 Substituter( const TypeSubstitution & sub, bool freeOnly ) : sub( sub ), freeOnly( freeOnly ) {}
    172 
    173                 const Type * postvisit( const TypeInstType * aggregateUseType );
    174 
    175                 /// Records type variable bindings from forall-statements
    176                 void previsit( const FunctionType * type );
    177                 /// Records type variable bindings from forall-statements and instantiations of generic types
    178                 // void handleAggregateType( const BaseInstType * type );
    179 
    180                 // void previsit( const StructInstType * aggregateUseType );
    181                 // void previsit( const UnionInstType * aggregateUseType );
    182 
    183                 const TypeSubstitution & sub;
    184                 int subCount = 0;
    185                 bool freeOnly;
    186                 typedef std::unordered_set< TypeEnvKey > BoundVarsType;
    187                 BoundVarsType boundVars;
    188 
    189 };
    190 
    191 template< typename SynTreeClass >
    192 TypeSubstitution::ApplyResult<SynTreeClass> TypeSubstitution::apply( const SynTreeClass * input ) const {
    193         assert( input );
    194         Pass<Substituter> sub( *this, false );
    195         input = strict_dynamic_cast< const SynTreeClass * >( input->accept( sub ) );
    196         return { input, sub.core.subCount };
    197 }
    198 
    199 template< typename SynTreeClass >
    200 TypeSubstitution::ApplyResult<SynTreeClass> TypeSubstitution::applyFree( const SynTreeClass * input ) const {
    201         assert( input );
    202         Pass<Substituter> sub( *this, true );
    203         input = strict_dynamic_cast< const SynTreeClass * >( input->accept( sub ) );
    204         return { input, sub.core.subCount };
    205 }
    206 
    207 } // namespace ast
    208 
    209168// Local Variables: //
    210169// tab-width: 4 //
  • src/Concurrency/Waituntil.cpp

    r4246869 ra5294af  
    1414//
    1515
     16#include "Waituntil.hpp"
     17
    1618#include <string>
    1719
    18 #include "Waituntil.hpp"
     20#include "AST/Copy.hpp"
    1921#include "AST/Expr.hpp"
    2022#include "AST/Pass.hpp"
  • src/ControlStruct/ExceptDeclNew.cpp

    r4246869 ra5294af  
    1818#include <sstream>
    1919
     20#include "AST/Copy.hpp"
    2021#include "AST/Decl.hpp"
    2122#include "AST/Pass.hpp"
  • src/GenPoly/SpecializeNew.cpp

    r4246869 ra5294af  
    1616#include "Specialize.h"
    1717
     18#include "AST/Copy.hpp"                  // for deepCopy
    1819#include "AST/Inspect.hpp"               // for isIntrinsicCallExpr
    1920#include "AST/Pass.hpp"                  // for Pass
  • src/MakeLibCfaNew.cpp

    r4246869 ra5294af  
    1616#include "MakeLibCfa.h"
    1717
     18#include "AST/Copy.hpp"
    1819#include "AST/Fwd.hpp"
    1920#include "AST/Pass.hpp"
  • src/ResolvExpr/CommonType.cc

    r4246869 ra5294af  
    2121
    2222#include "AST/Decl.hpp"
     23#include "AST/Pass.hpp"
    2324#include "AST/Type.hpp"
    2425#include "Common/PassVisitor.h"
  • src/ResolvExpr/PolyCost.cc

    r4246869 ra5294af  
    1515
    1616#include "AST/SymbolTable.hpp"
     17#include "AST/Pass.hpp"
    1718#include "AST/Type.hpp"
    1819#include "AST/TypeEnvironment.hpp"
  • src/Tuples/Explode.cc

    r4246869 ra5294af  
    1717#include <list>                  // for list
    1818
     19#include "AST/Pass.hpp"          // for Pass
    1920#include "SynTree/Mutator.h"     // for Mutator
    2021#include "Common/PassVisitor.h"  // for PassVisitor
  • src/Validate/Autogen.cpp

    r4246869 ra5294af  
    2525
    2626#include "AST/Attribute.hpp"
     27#include "AST/Copy.hpp"
    2728#include "AST/Create.hpp"
    2829#include "AST/Decl.hpp"
  • src/Validate/FixQualifiedTypes.cpp

    r4246869 ra5294af  
    1616#include "Validate/FixQualifiedTypes.hpp"
    1717
     18#include "AST/Copy.hpp"
    1819#include "AST/LinkageSpec.hpp"             // for Linkage
    1920#include "AST/Pass.hpp"
  • src/Validate/GenericParameter.cpp

    r4246869 ra5294af  
    1616#include "GenericParameter.hpp"
    1717
     18#include "AST/Copy.hpp"
    1819#include "AST/Decl.hpp"
    1920#include "AST/Expr.hpp"
  • src/Validate/ReplaceTypedef.cpp

    r4246869 ra5294af  
    1616#include "ReplaceTypedef.hpp"
    1717
     18#include "AST/Copy.hpp"
    1819#include "AST/Pass.hpp"
    1920#include "Common/ScopedMap.h"
  • src/Virtual/ExpandCasts.cc

    r4246869 ra5294af  
    2020#include <string>                  // for string, allocator, operator==, ope...
    2121
     22#include "AST/Copy.hpp"
    2223#include "AST/Decl.hpp"
    2324#include "AST/Expr.hpp"
  • src/main.cc

    r4246869 ra5294af  
    3232
    3333#include "AST/Convert.hpp"
     34#include "AST/Pass.hpp"                     // for pass_visitor_stats
     35#include "AST/TranslationUnit.hpp"          // for TranslationUnit
    3436#include "AST/Util.hpp"                     // for checkInvariants
    3537#include "CompilationState.h"
Note: See TracChangeset for help on using the changeset viewer.