Changeset 9c35431 for src


Ignore:
Timestamp:
Nov 29, 2017, 2:00:32 PM (7 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
c13e8dc8
Parents:
c6e2c18 (diff), 389528b0 (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' into cleanup-dtors

Location:
src
Files:
9 added
26 edited

Legend:

Unmodified
Added
Removed
  • src/Concurrency/Waitfor.cc

    rc6e2c18 r9c35431  
    416416                                makeAccStatement( acceptables, index, "is_dtor", detectIsDtor( clause.target.function )                                    , indexer ),
    417417                                makeAccStatement( acceptables, index, "func"   , new CastExpr( clause.target.function, fptr_t )                            , indexer ),
    418                                 makeAccStatement( acceptables, index, "list"   , new VariableExpr( monitors )                                              , indexer ),
     418                                makeAccStatement( acceptables, index, "data"   , new VariableExpr( monitors )                                              , indexer ),
    419419                                makeAccStatement( acceptables, index, "size"   , new ConstantExpr( Constant::from_ulong( clause.target.arguments.size() ) ), indexer ),
    420420                                setter->clone()
  • src/GenPoly/InstantiateGeneric.cc

    rc6e2c18 r9c35431  
    2121#include <vector>                      // for vector
    2222
     23#include "CodeGen/OperatorTable.h"
    2324#include "Common/PassVisitor.h"        // for PassVisitor, WithDeclsToAdd
    2425#include "Common/ScopedMap.h"          // for ScopedMap
     
    2728#include "Common/utility.h"            // for deleteAll, cloneAll
    2829#include "GenPoly.h"                   // for isPolyType, typesPolyCompatible
     30#include "InitTweak/InitTweak.h"
    2931#include "ResolvExpr/typeops.h"
    3032#include "ScopedSet.h"                 // for ScopedSet, ScopedSet<>::iterator
     
    154156
    155157        /// Add cast to dtype-static member expressions so that type information is not lost in GenericInstantiator
    156         struct FixDtypeStatic final {
     158        struct FixDtypeStatic final : public WithGuards, public WithVisitorRef<FixDtypeStatic>, public WithShortCircuiting, public WithStmtsToAdd {
    157159                Expression * postmutate( MemberExpr * memberExpr );
     160
     161                void premutate( ApplicationExpr * appExpr );
     162                void premutate( AddressExpr * addrExpr );
    158163
    159164                template<typename AggrInst>
    160165                Expression * fixMemberExpr( AggrInst * inst, MemberExpr * memberExpr );
     166
     167                bool isLvalueArg = false;
    161168        };
    162169
     
    501508                if ( isDtypeStatic( baseParams ) ) {
    502509                        if ( ! ResolvExpr::typesCompatible( memberExpr->result, memberExpr->member->get_type(), SymTab::Indexer() ) ) {
    503                                 // type of member and type of expression differ, so add cast to actual type
    504                                 return new CastExpr( memberExpr, memberExpr->result->clone() );
     510                                // type of member and type of expression differ
     511                                Type * concType = memberExpr->result->clone();
     512                                if ( isLvalueArg ) {
     513                                        // result must be C lvalue, so make a new reference variable with the correct actual type to replace the member expression
     514                                        //   forall(dtype T)
     515                                        //   struct Ptr {
     516                                        //     T * x
     517                                        //   };
     518                                        //   Ptr(int) p;
     519                                        //   int i;
     520                                        //   p.x = &i;
     521                                        // becomes
     522                                        //   int *& _dtype_static_member_0 = (int **)&p.x;
     523                                        //   _dtype_static_member_0 = &i;
     524                                        // Note: this currently creates more temporaries than is strictly necessary, since it does not check for duplicate uses of the same member expression.
     525                                        static UniqueName tmpNamer( "_dtype_static_member_" );
     526                                        Expression * init = new CastExpr( new AddressExpr( memberExpr ), new PointerType( Type::Qualifiers(), concType->clone() ) );
     527                                        ObjectDecl * tmp = ObjectDecl::newObject( tmpNamer.newName(), new ReferenceType( Type::Qualifiers(), concType ), new SingleInit( init ) );
     528                                        stmtsToAddBefore.push_back( new DeclStmt( noLabels, tmp ) );
     529                                        return new VariableExpr( tmp );
     530                                } else {
     531                                        // can simply add a cast to actual type
     532                                        return new CastExpr( memberExpr, concType );
     533                                }
    505534                        }
    506535                }
     
    520549        }
    521550
     551        void FixDtypeStatic::premutate( ApplicationExpr * appExpr ) {
     552                GuardValue( isLvalueArg );
     553                isLvalueArg = false;
     554                DeclarationWithType * function = InitTweak::getFunction( appExpr );
     555                if ( function->linkage == LinkageSpec::Intrinsic && CodeGen::isAssignment( function->name ) ) {
     556                        // explicitly visit children because only the first argument must be a C lvalue.
     557                        visit_children = false;
     558                        appExpr->env = maybeMutate( appExpr->env, *visitor );
     559                        appExpr->result = maybeMutate( appExpr->result, *visitor );
     560                        appExpr->function = maybeMutate( appExpr->function, *visitor );
     561                        isLvalueArg = true;
     562                        for ( Expression * arg : appExpr->args ) {
     563                                arg = maybeMutate( arg, *visitor );
     564                                isLvalueArg = false;
     565                        }
     566                }
     567        }
     568
     569        void FixDtypeStatic::premutate( AddressExpr * ) {
     570                // argument of & must be C lvalue
     571                GuardValue( isLvalueArg );
     572                isLvalueArg = true;
     573        }
    522574} // namespace GenPoly
    523575
  • src/Parser/ParseNode.h

    rc6e2c18 r9c35431  
    1010// Created On       : Sat May 16 13:28:16 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Sep 23 18:11:22 2017
    13 // Update Count     : 821
     12// Last Modified On : Mon Nov 27 17:33:35 2017
     13// Update Count     : 824
    1414//
    1515
     
    292292        DeclarationNode * set_extension( bool exten ) { extension = exten; return this; }
    293293  public:
     294        DeclarationNode * get_last() { return (DeclarationNode *)ParseNode::get_last(); }
     295
    294296        struct Variable_t {
    295297//              const std::string * name;
  • src/Parser/parser.yy

    rc6e2c18 r9c35431  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Nov 26 11:36:36 2017
    13 // Update Count     : 2969
     12// Last Modified On : Mon Nov 27 17:23:35 2017
     13// Update Count     : 2992
    1414//
    1515
     
    13641364                        $$ = $3->addQualifiers( $1 )->addQualifiers( $2 );
    13651365                }
    1366         | cfa_function_declaration pop ',' push identifier_or_type_name
    1367                 {
    1368                         typedefTable.addToEnclosingScope( *$5, TypedefTable::ID );
    1369                         $$ = $1->appendList( $1->cloneType( $5 ) );
     1366        | cfa_function_declaration pop ',' push identifier_or_type_name '(' push cfa_parameter_type_list_opt pop ')'
     1367                {
     1368                        // Append the return type at the start (left-hand-side) to each identifier in the list.
     1369                        DeclarationNode * ret = new DeclarationNode;
     1370                        ret->type = maybeClone( $1->type->base );
     1371                        $$ = $1->appendList( DeclarationNode::newFunction( $5, ret, $8, nullptr, true ) );
    13701372                }
    13711373        ;
     
    24162418                        typedefTable.addToEnclosingScope( TypedefTable::ID );
    24172419                        typedefTable.leaveScope();
    2418                         $$ = $1->addFunctionBody( $3 );
     2420                        // Add the function body to the last identifier in the function definition list, i.e., foo3:
     2421                        //   [const double] foo1(), foo2( int ), foo3( double ) { return 3.0; }
     2422                        $1->get_last()->addFunctionBody( $3 );
     2423                        $$ = $1;
    24192424                }
    24202425        | declaration_specifier function_declarator with_clause_opt compound_statement
  • src/ResolvExpr/AlternativeFinder.cc

    rc6e2c18 r9c35431  
    897897                // sum cost and accumulate actuals
    898898                std::list<Expression*>& args = appExpr->get_args();
    899                 Cost cost = Cost::zero;
     899                Cost cost = func.cost;
    900900                const ArgPack* pack = &result;
    901901                while ( pack->expr ) {
  • src/SynTree/Expression.cc

    rc6e2c18 r9c35431  
    356356        Type * res = member->get_type()->clone();
    357357        sub.apply( res );
    358         set_result( res );
    359         get_result()->set_lvalue( true );
     358        result = res;
     359        result->set_lvalue( true );
     360        result->get_qualifiers() |= aggregate->result->get_qualifiers();
    360361}
    361362
  • src/benchmark/Makefile.am

    rc6e2c18 r9c35431  
    9494        ctxswitch-cfa_thread.run        \
    9595        ctxswitch-upp_coroutine.run     \
    96         ctxswitch-upp_thread.run
     96        ctxswitch-upp_thread.run        \
     97        ctxswitch-goroutine.run         \
     98        ctxswitch-java_thread.run
    9799
    98100ctxswitch-cfa_coroutine$(EXEEXT):
     
    111113        @@BACKEND_CC@ ctxswitch/pthreads.c  -DBENCH_N=50000000  -I. -lrt -pthread                    ${AM_CFLAGS} ${CFLAGS} ${ccflags}
    112114
     115ctxswitch-goroutine$(EXEEXT):
     116        @go build -o a.out ctxswitch/goroutine.go
     117
     118ctxswitch-java_thread$(EXEEXT):
     119        @javac ctxswitch/JavaThread.java
     120        @echo "#!/bin/sh" > a.out
     121        @echo "cd ctxswitch && java JavaThread" >> a.out
     122        @chmod a+x a.out
     123
    113124## =========================================================================================================
    114125mutex$(EXEEXT) :\
    115126        mutex-function.run      \
     127        mutex-fetch_add.run     \
    116128        mutex-pthread_lock.run  \
    117129        mutex-upp.run           \
    118130        mutex-cfa1.run          \
    119131        mutex-cfa2.run          \
    120         mutex-cfa4.run
     132        mutex-cfa4.run          \
     133        mutex-java_thread.run
    121134
    122135mutex-function$(EXEEXT):
    123136        @@BACKEND_CC@ mutex/function.c    -DBENCH_N=500000000   -I. -lrt -pthread                    ${AM_CFLAGS} ${CFLAGS} ${ccflags}
    124137
     138mutex-fetch_add$(EXEEXT):
     139        @@BACKEND_CC@ mutex/fetch_add.c   -DBENCH_N=500000000   -I. -lrt -pthread                    ${AM_CFLAGS} ${CFLAGS} ${ccflags}
     140
    125141mutex-pthread_lock$(EXEEXT):
    126142        @@BACKEND_CC@ mutex/pthreads.c    -DBENCH_N=50000000    -I. -lrt -pthread                    ${AM_CFLAGS} ${CFLAGS} ${ccflags}
     
    137153mutex-cfa4$(EXEEXT):
    138154        @${CC}        mutex/cfa4.c        -DBENCH_N=5000000     -I. -nodebug -lrt -quiet @CFA_FLAGS@ ${AM_CFLAGS} ${CFLAGS} ${ccflags}
     155
     156mutex-java_thread$(EXEEXT):
     157        @javac mutex/JavaThread.java
     158        @echo "#!/bin/sh" > a.out
     159        @echo "cd mutex && java JavaThread" >> a.out
     160        @chmod a+x a.out
    139161
    140162## =========================================================================================================
     
    143165        signal-cfa1.run         \
    144166        signal-cfa2.run         \
    145         signal-cfa4.run
     167        signal-cfa4.run         \
     168        signal-java_thread.run
    146169
    147170signal-upp$(EXEEXT):
     
    156179signal-cfa4$(EXEEXT):
    157180        @${CC}        schedint/cfa4.c     -DBENCH_N=500000      -I. -nodebug -lrt -quiet @CFA_FLAGS@ ${AM_CFLAGS} ${CFLAGS} ${ccflags}
     181
     182signal-java_thread$(EXEEXT):
     183        @javac schedint/JavaThread.java
     184        @echo "#!/bin/sh" > a.out
     185        @echo "cd schedint && java JavaThread" >> a.out
     186        @chmod a+x a.out
     187
    158188
    159189## =========================================================================================================
     
    183213        creation-cfa_thread.run                 \
    184214        creation-upp_coroutine.run              \
    185         creation-upp_thread.run
     215        creation-upp_thread.run                 \
     216        creation-goroutine.run                  \
     217        creation-java_thread.run
    186218
    187219creation-cfa_coroutine$(EXEEXT):
     
    202234creation-pthread$(EXEEXT):
    203235        @@BACKEND_CC@ creation/pthreads.c  -DBENCH_N=250000     -I. -lrt -pthread                    ${AM_CFLAGS} ${CFLAGS} ${ccflags}
     236
     237creation-goroutine$(EXEEXT):
     238        @go build -o a.out creation/goroutine.go
     239
     240creation-java_thread$(EXEEXT):
     241        @javac creation/JavaThread.java
     242        @echo "#!/bin/sh" > a.out
     243        @echo "cd creation && java JavaThread" >> a.out
     244        @chmod a+x a.out
    204245
    205246## =========================================================================================================
  • src/benchmark/Makefile.in

    rc6e2c18 r9c35431  
    507507        ctxswitch-cfa_thread.run        \
    508508        ctxswitch-upp_coroutine.run     \
    509         ctxswitch-upp_thread.run
     509        ctxswitch-upp_thread.run        \
     510        ctxswitch-goroutine.run         \
     511        ctxswitch-java_thread.run
    510512
    511513ctxswitch-cfa_coroutine$(EXEEXT):
     
    524526        @@BACKEND_CC@ ctxswitch/pthreads.c  -DBENCH_N=50000000  -I. -lrt -pthread                    ${AM_CFLAGS} ${CFLAGS} ${ccflags}
    525527
     528ctxswitch-goroutine$(EXEEXT):
     529        @go build -o a.out ctxswitch/goroutine.go
     530
     531ctxswitch-java_thread$(EXEEXT):
     532        @javac ctxswitch/JavaThread.java
     533        @echo "#!/bin/sh" > a.out
     534        @echo "cd ctxswitch && java JavaThread" >> a.out
     535        @chmod a+x a.out
     536
    526537mutex$(EXEEXT) :\
    527538        mutex-function.run      \
     539        mutex-fetch_add.run     \
    528540        mutex-pthread_lock.run  \
    529541        mutex-upp.run           \
    530542        mutex-cfa1.run          \
    531543        mutex-cfa2.run          \
    532         mutex-cfa4.run
     544        mutex-cfa4.run          \
     545        mutex-java_thread.run
    533546
    534547mutex-function$(EXEEXT):
    535548        @@BACKEND_CC@ mutex/function.c    -DBENCH_N=500000000   -I. -lrt -pthread                    ${AM_CFLAGS} ${CFLAGS} ${ccflags}
    536549
     550mutex-fetch_add$(EXEEXT):
     551        @@BACKEND_CC@ mutex/fetch_add.c   -DBENCH_N=500000000   -I. -lrt -pthread                    ${AM_CFLAGS} ${CFLAGS} ${ccflags}
     552
    537553mutex-pthread_lock$(EXEEXT):
    538554        @@BACKEND_CC@ mutex/pthreads.c    -DBENCH_N=50000000    -I. -lrt -pthread                    ${AM_CFLAGS} ${CFLAGS} ${ccflags}
     
    549565mutex-cfa4$(EXEEXT):
    550566        @${CC}        mutex/cfa4.c        -DBENCH_N=5000000     -I. -nodebug -lrt -quiet @CFA_FLAGS@ ${AM_CFLAGS} ${CFLAGS} ${ccflags}
     567
     568mutex-java_thread$(EXEEXT):
     569        @javac mutex/JavaThread.java
     570        @echo "#!/bin/sh" > a.out
     571        @echo "cd mutex && java JavaThread" >> a.out
     572        @chmod a+x a.out
    551573
    552574signal$(EXEEXT) :\
     
    567589signal-cfa4$(EXEEXT):
    568590        @${CC}        schedint/cfa4.c     -DBENCH_N=500000      -I. -nodebug -lrt -quiet @CFA_FLAGS@ ${AM_CFLAGS} ${CFLAGS} ${ccflags}
     591
     592signal-java_thread$(EXEEXT):
     593        @javac schedint/JavaThread.java
     594        @echo "#!/bin/sh" > a.out
     595        @echo "cd schedint && java JavaThread" >> a.out
     596        @chmod a+x a.out
    569597
    570598waitfor$(EXEEXT) :\
     
    592620        creation-cfa_thread.run                 \
    593621        creation-upp_coroutine.run              \
    594         creation-upp_thread.run
     622        creation-upp_thread.run                 \
     623        creation-goroutine.run                  \
     624        creation-java_thread.run
    595625
    596626creation-cfa_coroutine$(EXEEXT):
     
    611641creation-pthread$(EXEEXT):
    612642        @@BACKEND_CC@ creation/pthreads.c  -DBENCH_N=250000     -I. -lrt -pthread                    ${AM_CFLAGS} ${CFLAGS} ${ccflags}
     643
     644creation-goroutine$(EXEEXT):
     645        @go build -o a.out creation/goroutine.go
     646
     647creation-java_thread$(EXEEXT):
     648        @javac creation/JavaThread.java
     649        @echo "#!/bin/sh" > a.out
     650        @echo "cd creation && java JavaThread" >> a.out
     651        @chmod a+x a.out
    613652
    614653compile$(EXEEXT) :\
  • src/benchmark/bench.h

    rc6e2c18 r9c35431  
    11#pragma once
    22
    3 #if defined(__CFORALL__)
     3#if defined(__cforall)
    44extern "C" {
    55#endif
     
    88        #include <sys/times.h>                                  // times
    99        #include <time.h>
    10 #if defined(__CFORALL__)
     10#if defined(__cforall)
    1111}
    1212#endif
  • src/libcfa/Makefile.am

    rc6e2c18 r9c35431  
    100100        math                            \
    101101        gmp                             \
     102        bits/containers.h               \
    102103        bits/defs.h             \
    103104        bits/locks.h            \
  • src/libcfa/Makefile.in

    rc6e2c18 r9c35431  
    264264        containers/result containers/vector concurrency/coroutine \
    265265        concurrency/thread concurrency/kernel concurrency/monitor \
    266         ${shell echo stdhdr/*} math gmp bits/defs.h bits/locks.h \
    267         concurrency/invoke.h libhdr.h libhdr/libalign.h \
     266        ${shell echo stdhdr/*} math gmp bits/containers.h bits/defs.h \
     267        bits/locks.h concurrency/invoke.h libhdr.h libhdr/libalign.h \
    268268        libhdr/libdebug.h libhdr/libtools.h
    269269HEADERS = $(nobase_cfa_include_HEADERS)
     
    437437        math                            \
    438438        gmp                             \
     439        bits/containers.h               \
    439440        bits/defs.h             \
    440441        bits/locks.h            \
  • src/libcfa/bits/containers.h

    rc6e2c18 r9c35431  
    1515#pragma once
    1616
    17 #include <stddef.h>
     17#include "bits/defs.h"
     18#include "libhdr.h"
    1819
    19 #include "libhdr.h"
     20//-----------------------------------------------------------------------------
     21// Array
     22//-----------------------------------------------------------------------------
     23
     24#ifdef __cforall
     25        forall(dtype T)
     26#else
     27        #define T void
     28#endif
     29struct __small_array {
     30        T *           data;
     31        __lock_size_t size;
     32};
     33#undef T
     34
     35#ifdef __cforall
     36        #define __small_array_t(T) __small_array(T)
     37#else
     38        #define __small_array_t(T) struct __small_array
     39#endif
     40
     41#ifdef __cforall
     42        // forall(otype T | sized(T))
     43        // static inline void ?{}(__small_array(T) & this) {}
     44
     45        forall(dtype T | sized(T))
     46        static inline T& ?[?]( __small_array(T) & this, __lock_size_t idx) {
     47                return ((typeof(this.data))this.data)[idx];
     48        }
     49
     50        forall(dtype T | sized(T))
     51        static inline T& ?[?]( const __small_array(T) & this, __lock_size_t idx) {
     52                return ((typeof(this.data))this.data)[idx];
     53        }
     54
     55        forall(dtype T | sized(T))
     56        static inline T* begin( const __small_array(T) & this ) {
     57                return ((typeof(this.data))this.data);
     58        }
     59
     60        forall(dtype T | sized(T))
     61        static inline T* end( const __small_array(T) & this ) {
     62                return ((typeof(this.data))this.data) + this.size;
     63        }
     64#endif
    2065
    2166//-----------------------------------------------------------------------------
     
    2368//-----------------------------------------------------------------------------
    2469
    25 #ifdef __CFORALL__
     70#ifdef __cforall
    2671        trait is_node(dtype T) {
    2772                T*& get_next( T& );
     
    3277// Stack
    3378//-----------------------------------------------------------------------------
    34 #ifdef __CFORALL__
     79#ifdef __cforall
    3580        forall(dtype TYPE | is_node(TYPE))
    3681        #define T TYPE
     
    4186        T * top;
    4287};
     88#undef T
    4389
    44 #ifdef __CFORALL__
     90#ifdef __cforall
    4591#define __stack_t(T) __stack(T)
    4692#else
     
    4894#endif
    4995
    50 #ifdef __CFORALL__
     96#ifdef __cforall
    5197        forall(dtype T | is_node(T))
    52         void ?{}( __stack(T) & this ) {
    53                 this.top = NULL;
     98        static inline void ?{}( __stack(T) & this ) {
     99                (this.top){ NULL };
    54100        }
    55101
    56102        forall(dtype T | is_node(T) | sized(T))
    57         void push( __stack(T) & this, T * val ) {
     103        static inline void push( __stack(T) & this, T * val ) {
    58104                verify( !get_next( *val ) );
    59105                get_next( *val ) = this.top;
     
    62108
    63109        forall(dtype T | is_node(T) | sized(T))
    64         T * pop( __stack(T) & this ) {
     110        static inline T * pop( __stack(T) & this ) {
    65111                T * top = this.top;
    66112                if( top ) {
     
    75121// Queue
    76122//-----------------------------------------------------------------------------
    77 #ifdef __CFORALL__
    78         forall(dtype T | is_node(T))
     123#ifdef __cforall
     124        forall(dtype TYPE | is_node(TYPE))
    79125        #define T TYPE
    80126#else
     
    85131        T ** tail;
    86132};
     133#undef T
    87134
    88 #ifdef __CFORALL__
     135#ifdef __cforall
     136#define __queue_t(T) __queue(T)
     137#else
     138#define __queue_t(T) struct __queue
     139#endif
     140
     141#ifdef __cforall
    89142        forall(dtype T | is_node(T))
    90         void ?{}( __queue(T) & this ) {
    91                 this.head = NULL;
    92                 this.tail = &this.head;
     143        static inline void ?{}( __queue(T) & this ) {
     144                (this.head){ NULL };
     145                (this.tail){ &this.head };
    93146        }
    94147
    95148        forall(dtype T | is_node(T) | sized(T))
    96         void append( __queue(T) & this, T * val ) {
     149        static inline void append( __queue(T) & this, T * val ) {
    97150                verify(this.tail != NULL);
    98151                *this.tail = val;
     
    101154
    102155        forall(dtype T | is_node(T) | sized(T))
    103         T * pop_head( __queue(T) & this ) {
     156        static inline T * pop_head( __queue(T) & this ) {
    104157                T * head = this.head;
    105158                if( head ) {
     
    114167
    115168        forall(dtype T | is_node(T) | sized(T))
    116         T * remove( __queue(T) & this, T ** it ) {
     169        static inline T * remove( __queue(T) & this, T ** it ) {
    117170                T * val = *it;
    118171                verify( val );
  • src/libcfa/bits/defs.h

    rc6e2c18 r9c35431  
    1717
    1818#include <stdbool.h>
     19#include <stddef.h>
    1920#include <stdint.h>
    2021
     
    2223#define likely  (x)    __builtin_expect(!!(x), 1)
    2324#define thread_local _Thread_local
     25
     26typedef void (*fptr_t)();
     27typedef int_fast16_t __lock_size_t;
     28
     29#ifdef __cforall
     30#define __cfa_anonymous_object
     31#else
     32#define __cfa_anonymous_object __cfa_anonymous_object
     33#endif
  • src/libcfa/bits/locks.h

    rc6e2c18 r9c35431  
    5656} __ALIGN__;
    5757
    58 #ifdef __CFORALL__
     58#ifdef __cforall
    5959        extern void yield( unsigned int );
    6060        extern thread_local struct thread_desc *    volatile this_thread;
  • src/libcfa/concurrency/invoke.h

    rc6e2c18 r9c35431  
    1414//
    1515
     16#include "bits/containers.h"
    1617#include "bits/defs.h"
    1718#include "bits/locks.h"
    1819
    19 #ifdef __CFORALL__
     20#ifdef __cforall
    2021extern "C" {
    2122#endif
     
    2526#define _INVOKE_H_
    2627
    27         typedef void (*fptr_t)();
    28         typedef int_fast16_t __lock_size_t;
    29 
    30         struct __thread_queue_t {
    31                 struct thread_desc * head;
    32                 struct thread_desc ** tail;
    33         };
    34 
    35         struct __condition_stack_t {
    36                 struct __condition_criterion_t * top;
    37         };
    38 
    39         #ifdef __CFORALL__
     28        #ifdef __cforall
    4029        extern "Cforall" {
    41                 void ?{}( struct __thread_queue_t & );
    42                 void append( struct __thread_queue_t &, struct thread_desc * );
    43                 struct thread_desc * pop_head( struct __thread_queue_t & );
    44                 struct thread_desc * remove( struct __thread_queue_t &, struct thread_desc ** );
    45 
    46                 void ?{}( struct __condition_stack_t & );
    47                 void push( struct __condition_stack_t &, struct __condition_criterion_t * );
    48                 struct __condition_criterion_t * pop( struct __condition_stack_t & );
     30                static inline struct thread_desc             * & get_next( struct thread_desc             & this );
     31                static inline struct __condition_criterion_t * & get_next( struct __condition_criterion_t & this );
    4932        }
    5033        #endif
     
    10083
    10184                // list of acceptable functions, null if any
    102                 struct __acceptable_t * clauses;
    103 
    104                 // number of acceptable functions
    105                 __lock_size_t size;
     85                __small_array_t(struct __acceptable_t) __cfa_anonymous_object;
    10686        };
    10787
     
    11494
    11595                // queue of threads that are blocked waiting for the monitor
    116                 struct __thread_queue_t entry_queue;
     96                __queue_t(struct thread_desc) entry_queue;
    11797
    11898                // stack of conditions to run next once we exit the monitor
    119                 struct __condition_stack_t signal_stack;
     99                __stack_t(struct __condition_criterion_t) signal_stack;
    120100
    121101                // monitor routines can be called recursively, we need to keep track of that
     
    131111        struct __monitor_group_t {
    132112                // currently held monitors
    133                 struct monitor_desc ** list;
    134 
    135                 // number of currently held monitors
    136                 __lock_size_t size;
     113                __small_array_t(monitor_desc*) __cfa_anonymous_object;
    137114
    138115                // last function that acquired monitors
     
    159136     };
    160137
    161      #ifdef __CFORALL__
     138     #ifdef __cforall
    162139     extern "Cforall" {
    163                 static inline monitor_desc * ?[?]( const __monitor_group_t & this, ptrdiff_t index ) {
    164                         return this.list[index];
     140                static inline thread_desc * & get_next( thread_desc & this ) {
     141                        return this.next;
     142                }
     143
     144                static inline struct __condition_criterion_t * & get_next( struct __condition_criterion_t & this );
     145
     146                static inline void ?{}(__monitor_group_t & this) {
     147                        (this.data){NULL};
     148                        (this.size){0};
     149                        (this.func){NULL};
     150                }
     151
     152                static inline void ?{}(__monitor_group_t & this, struct monitor_desc ** data, __lock_size_t size, fptr_t func) {
     153                        (this.data){data};
     154                        (this.size){size};
     155                        (this.func){func};
    165156                }
    166157
    167158                static inline bool ?==?( const __monitor_group_t & lhs, const __monitor_group_t & rhs ) {
    168                         if( (lhs.list != 0) != (rhs.list != 0) ) return false;
     159                        if( (lhs.data != 0) != (rhs.data != 0) ) return false;
    169160                        if( lhs.size != rhs.size ) return false;
    170161                        if( lhs.func != rhs.func ) return false;
     
    177168
    178169                        return true;
     170                }
     171
     172                static inline void ?=?(__monitor_group_t & lhs, const __monitor_group_t & rhs) {
     173                        lhs.data = rhs.data;
     174                        lhs.size = rhs.size;
     175                        lhs.func = rhs.func;
    179176                }
    180177        }
     
    210207#endif //_INVOKE_PRIVATE_H_
    211208#endif //! defined(__CFA_INVOKE_PRIVATE__)
    212 #ifdef __CFORALL__
     209#ifdef __cforall
    213210}
    214211#endif
  • src/libcfa/concurrency/kernel

    rc6e2c18 r9c35431  
    2626//-----------------------------------------------------------------------------
    2727// Locks
    28 // // Lock the spinlock, spin if already acquired
    29 // void lock      ( spinlock * DEBUG_CTX_PARAM2 );
    30 
    31 // // Lock the spinlock, yield repeatedly if already acquired
    32 // void lock_yield( spinlock * DEBUG_CTX_PARAM2 );
    33 
    34 // // Lock the spinlock, return false if already acquired
    35 // bool try_lock  ( spinlock * DEBUG_CTX_PARAM2 );
    36 
    37 // // Unlock the spinlock
    38 // void unlock    ( spinlock * );
    39 
    4028struct semaphore {
    4129        __spinlock_t lock;
    4230        int count;
    43         __thread_queue_t waiting;
     31        __queue_t(thread_desc) waiting;
    4432};
    4533
     
    5745
    5846        // Ready queue for threads
    59         __thread_queue_t ready_queue;
     47        __queue_t(thread_desc) ready_queue;
    6048
    6149        // Preemption rate on this cluster
  • src/libcfa/concurrency/kernel.c

    rc6e2c18 r9c35431  
    164164
    165165void ?{}(cluster & this) {
    166         ( this.ready_queue ){};
     166        (this.ready_queue){};
    167167        ( this.ready_queue_lock ){};
    168168
     
    611611}
    612612
    613 //-----------------------------------------------------------------------------
    614 // Queues
    615 void ?{}( __thread_queue_t & this ) {
    616         this.head = NULL;
    617         this.tail = &this.head;
    618 }
    619 
    620 void append( __thread_queue_t & this, thread_desc * t ) {
    621         verify(this.tail != NULL);
    622         *this.tail = t;
    623         this.tail = &t->next;
    624 }
    625 
    626 thread_desc * pop_head( __thread_queue_t & this ) {
    627         thread_desc * head = this.head;
    628         if( head ) {
    629                 this.head = head->next;
    630                 if( !head->next ) {
    631                         this.tail = &this.head;
    632                 }
    633                 head->next = NULL;
    634         }
    635         return head;
    636 }
    637 
    638 thread_desc * remove( __thread_queue_t & this, thread_desc ** it ) {
    639         thread_desc * thrd = *it;
    640         verify( thrd );
    641 
    642         (*it) = thrd->next;
    643 
    644         if( this.tail == &thrd->next ) {
    645                 this.tail = it;
    646         }
    647 
    648         thrd->next = NULL;
    649 
    650         verify( (this.head == NULL) == (&this.head == this.tail) );
    651         verify( *this.tail == NULL );
    652         return thrd;
    653 }
    654 
    655 void ?{}( __condition_stack_t & this ) {
    656         this.top = NULL;
    657 }
    658 
    659 void push( __condition_stack_t & this, __condition_criterion_t * t ) {
    660         verify( !t->next );
    661         t->next = this.top;
    662         this.top = t;
    663 }
    664 
    665 __condition_criterion_t * pop( __condition_stack_t & this ) {
    666         __condition_criterion_t * top = this.top;
    667         if( top ) {
    668                 this.top = top->next;
    669                 top->next = NULL;
    670         }
    671         return top;
    672 }
    673 
    674613// Local Variables: //
    675614// mode: c //
  • src/libcfa/concurrency/monitor

    rc6e2c18 r9c35431  
    3434        this.recursion     = 0;
    3535        this.mask.accepted = NULL;
    36         this.mask.clauses  = NULL;
     36        this.mask.data     = NULL;
    3737        this.mask.size     = 0;
    3838        this.dtor_node     = NULL;
     
    4040
    4141struct monitor_guard_t {
    42         monitor_desc ** m;
    43         __lock_size_t   count;
    44         monitor_desc ** prev_mntrs;
    45         __lock_size_t   prev_count;
    46         fptr_t          prev_func;
     42        monitor_desc **         m;
     43        __lock_size_t           count;
     44        __monitor_group_t prev;
    4745};
    4846
     
    5149
    5250struct monitor_dtor_guard_t {
    53         monitor_desc * m;
    54         monitor_desc ** prev_mntrs;
    55         __lock_size_t   prev_count;
    56         fptr_t          prev_func;
     51        monitor_desc *    m;
     52        __monitor_group_t prev;
    5753};
    5854
     
    8379};
    8480
     81static inline __condition_criterion_t * & get_next( __condition_criterion_t & this ) {
     82        return this.next;
     83}
     84
    8585struct __condition_node_t {
    8686        // Thread that needs to be woken when all criteria are met
     
    100100};
    101101
    102 struct __condition_blocked_queue_t {
    103         __condition_node_t * head;
    104         __condition_node_t ** tail;
    105 };
     102static inline __condition_node_t * & get_next( __condition_node_t & this ) {
     103        return this.next;
     104}
    106105
    107106void ?{}(__condition_node_t & this, thread_desc * waiting_thread, __lock_size_t count, uintptr_t user_info );
     
    109108void ?{}(__condition_criterion_t & this, monitor_desc * target, __condition_node_t * owner );
    110109
    111 void ?{}( __condition_blocked_queue_t & );
    112 void append( __condition_blocked_queue_t &, __condition_node_t * );
    113 __condition_node_t * pop_head( __condition_blocked_queue_t & );
    114 
    115110struct condition {
    116111        // Link list which contains the blocked threads as-well as the information needed to unblock them
    117         __condition_blocked_queue_t blocked;
     112        __queue_t(__condition_node_t) blocked;
    118113
    119114        // Array of monitor pointers (Monitors are NOT contiguous in memory)
  • src/libcfa/concurrency/monitor.c

    rc6e2c18 r9c35431  
    280280static inline void enter( __monitor_group_t monitors ) {
    281281        for( __lock_size_t i = 0; i < monitors.size; i++) {
    282                 __enter_monitor_desc( monitors.list[i], monitors );
     282                __enter_monitor_desc( monitors[i], monitors );
    283283        }
    284284}
     
    303303
    304304        // Save previous thread context
    305         this.[prev_mntrs, prev_count, prev_func] = this_thread->monitors.[list, size, func];
     305        this.prev = this_thread->monitors;
    306306
    307307        // Update thread context (needed for conditions)
    308         this_thread->monitors.[list, size, func] = [m, count, func];
     308        (this_thread->monitors){m, count, func};
    309309
    310310        // LIB_DEBUG_PRINT_SAFE("MGUARD : enter %d\n", count);
     
    328328
    329329        // Restore thread context
    330         this_thread->monitors.[list, size, func] = this.[prev_mntrs, prev_count, prev_func];
     330        this_thread->monitors = this.prev;
    331331}
    332332
     
    338338
    339339        // Save previous thread context
    340         this.[prev_mntrs, prev_count, prev_func] = this_thread->monitors.[list, size, func];
     340        this.prev = this_thread->monitors;
    341341
    342342        // Update thread context (needed for conditions)
    343         this_thread->monitors.[list, size, func] = [m, 1, func];
     343        (this_thread->monitors){m, 1, func};
    344344
    345345        __enter_monitor_dtor( this.m, func );
     
    352352
    353353        // Restore thread context
    354         this_thread->monitors.[list, size, func] = this.[prev_mntrs, prev_count, prev_func];
     354        this_thread->monitors = this.prev;
    355355}
    356356
     
    437437
    438438                for(int i = 0; i < this.monitor_count; i++) {
    439                         if ( this.monitors[i] != this_thrd->monitors.list[i] ) {
    440                                 abortf( "Signal on condition %p made with different monitor, expected %p got %i", &this, this.monitors[i], this_thrd->monitors.list[i] );
     439                        if ( this.monitors[i] != this_thrd->monitors[i] ) {
     440                                abortf( "Signal on condition %p made with different monitor, expected %p got %i", &this, this.monitors[i], this_thrd->monitors[i] );
    441441                        }
    442442                }
     
    510510                "Possible cause is not checking if the condition is empty before reading stored data."
    511511        );
    512         return this.blocked.head->user_info;
     512        return ((typeof(this.blocked.head))this.blocked.head)->user_info;
    513513}
    514514
     
    554554                if( next ) {
    555555                        *mask.accepted = index;
    556                         if( mask.clauses[index].is_dtor ) {
     556                        __acceptable_t& accepted = mask[index];
     557                        if( accepted.is_dtor ) {
    557558                                LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel : dtor already there\n");
    558                                 verifyf( mask.clauses[index].size == 1        , "ERROR: Accepted dtor has more than 1 mutex parameter." );
    559 
    560                                 monitor_desc * mon2dtor = mask.clauses[index].list[0];
     559                                verifyf( accepted.size == 1, "ERROR: Accepted dtor has more than 1 mutex parameter." );
     560
     561                                monitor_desc * mon2dtor = accepted[0];
    561562                                verifyf( mon2dtor->dtor_node, "ERROR: Accepted monitor has no dtor_node." );
    562563
     
    596597
    597598                        LIB_DEBUG_PRINT_BUFFER_LOCAL( "Kernel : accepted %d\n", *mask.accepted);
    598 
    599599                        return;
    600600                }
     
    671671static inline void reset_mask( monitor_desc * this ) {
    672672        this->mask.accepted = NULL;
    673         this->mask.clauses = NULL;
     673        this->mask.data = NULL;
    674674        this->mask.size = 0;
    675675}
     
    697697
    698698static inline bool is_accepted( monitor_desc * this, const __monitor_group_t & group ) {
    699         __acceptable_t * it = this->mask.clauses; // Optim
     699        __acceptable_t * it = this->mask.data; // Optim
    700700        __lock_size_t count = this->mask.size;
    701701
     
    820820        if( !this.monitors ) {
    821821                // LIB_DEBUG_PRINT_SAFE("Branding\n");
    822                 assertf( thrd->monitors.list != NULL, "No current monitor to brand condition %p", thrd->monitors.list );
     822                assertf( thrd->monitors.data != NULL, "No current monitor to brand condition %p", thrd->monitors.data );
    823823                this.monitor_count = thrd->monitors.size;
    824824
    825825                this.monitors = (monitor_desc **)malloc( this.monitor_count * sizeof( *this.monitors ) );
    826826                for( int i = 0; i < this.monitor_count; i++ ) {
    827                         this.monitors[i] = thrd->monitors.list[i];
     827                        this.monitors[i] = thrd->monitors[i];
    828828                }
    829829        }
     
    832832static inline [thread_desc *, int] search_entry_queue( const __waitfor_mask_t & mask, monitor_desc * monitors [], __lock_size_t count ) {
    833833
    834         __thread_queue_t & entry_queue = monitors[0]->entry_queue;
     834        __queue_t(thread_desc) & entry_queue = monitors[0]->entry_queue;
    835835
    836836        // For each thread in the entry-queue
     
    841841                // For each acceptable check if it matches
    842842                int i = 0;
    843                 __acceptable_t * end = mask.clauses + mask.size;
    844                 for( __acceptable_t * it = mask.clauses; it != end; it++, i++ ) {
     843                __acceptable_t * end   = end  (mask);
     844                __acceptable_t * begin = begin(mask);
     845                for( __acceptable_t * it = begin; it != end; it++, i++ ) {
    845846                        // Check if we have a match
    846847                        if( *it == (*thrd_it)->monitors ) {
     
    872873        __lock_size_t max = 0;
    873874        for( __lock_size_t i = 0; i < mask.size; i++ ) {
    874                 max += mask.clauses[i].size;
     875                __acceptable_t & accepted = mask[i];
     876                max += accepted.size;
    875877        }
    876878        return max;
     
    880882        __lock_size_t size = 0;
    881883        for( __lock_size_t i = 0; i < mask.size; i++ ) {
    882                 __libcfa_small_sort( mask.clauses[i].list, mask.clauses[i].size );
    883                 for( __lock_size_t j = 0; j < mask.clauses[i].size; j++) {
    884                         insert_unique( storage, size, mask.clauses[i].list[j] );
     884                __acceptable_t & accepted = mask[i];
     885                __libcfa_small_sort( accepted.data, accepted.size );
     886                for( __lock_size_t j = 0; j < accepted.size; j++) {
     887                        insert_unique( storage, size, accepted[j] );
    885888                }
    886889        }
     
    888891        __libcfa_small_sort( storage, size );
    889892        return size;
    890 }
    891 
    892 void ?{}( __condition_blocked_queue_t & this ) {
    893         this.head = NULL;
    894         this.tail = &this.head;
    895 }
    896 
    897 void append( __condition_blocked_queue_t & this, __condition_node_t * c ) {
    898         verify(this.tail != NULL);
    899         *this.tail = c;
    900         this.tail = &c->next;
    901 }
    902 
    903 __condition_node_t * pop_head( __condition_blocked_queue_t & this ) {
    904         __condition_node_t * head = this.head;
    905         if( head ) {
    906                 this.head = head->next;
    907                 if( !head->next ) {
    908                         this.tail = &this.head;
    909                 }
    910                 head->next = NULL;
    911         }
    912         return head;
    913893}
    914894
  • src/libcfa/exception.h

    rc6e2c18 r9c35431  
    1717
    1818
    19 #ifdef __CFORALL__
     19#ifdef __cforall
    2020extern "C" {
    2121#endif
     
    6868struct __cfaehm__cleanup_hook {};
    6969
    70 #ifdef __CFORALL__
     70#ifdef __cforall
    7171}
    7272#endif
  • src/libcfa/stdhdr/assert.h

    rc6e2c18 r9c35431  
    44// The contents of this file are covered under the licence agreement in the
    55// file "LICENCE" distributed with Cforall.
    6 // 
    7 // assert.h -- 
    8 // 
     6//
     7// assert.h --
     8//
    99// Author           : Peter A. Buhr
    1010// Created On       : Mon Jul  4 23:25:26 2016
     
    1212// Last Modified On : Mon Jul 31 23:09:32 2017
    1313// Update Count     : 13
    14 // 
     14//
    1515
    16 #ifdef __CFORALL__
     16#ifdef __cforall
    1717extern "C" {
    18 #endif //__CFORALL__
     18#endif //__cforall
    1919
    2020#include_next <assert.h>
     
    3030#endif
    3131
    32 #ifdef __CFORALL__
     32#ifdef __cforall
    3333} // extern "C"
    34 #endif //__CFORALL__
     34#endif //__cforall
    3535
    3636// Local Variables: //
  • src/libcfa/virtual.h

    rc6e2c18 r9c35431  
    1616#pragma once
    1717
    18 #ifdef __CFORALL__
     18#ifdef __cforall
    1919extern "C" {
    2020#endif
     
    3535                struct __cfa__parent_vtable const * const * child );
    3636
    37 #ifdef __CFORALL__
     37#ifdef __cforall
    3838}
    3939#endif
  • src/tests/Makefile.am

    rc6e2c18 r9c35431  
    1111## Created On       : Sun May 31 09:08:15 2015
    1212## Last Modified By : Peter A. Buhr
    13 ## Last Modified On : Tue Oct 10 14:04:40 2017
    14 ## Update Count     : 47
     13## Last Modified On : Mon Nov 27 21:34:33 2017
     14## Update Count     : 48
    1515###############################################################################
    1616
     
    118118        ${CC} ${AM_CFLAGS} ${CFLAGS} -CFA -XCFA -p ${<} -o ${@}
    119119
     120functions: functions.c @CFA_BINDIR@/@CFA_NAME@
     121        ${CC} ${AM_CFLAGS} ${CFLAGS} -CFA -XCFA -p ${<} -o ${@}
     122
    120123KRfunctions : KRfunctions.c @CFA_BINDIR@/@CFA_NAME@
    121124        ${CC} ${AM_CFLAGS} ${CFLAGS} -CFA -XCFA -p ${<} -o ${@}
  • src/tests/Makefile.in

    rc6e2c18 r9c35431  
    871871        ${CC} ${AM_CFLAGS} ${CFLAGS} -CFA -XCFA -p ${<} -o ${@}
    872872
     873functions: functions.c @CFA_BINDIR@/@CFA_NAME@
     874        ${CC} ${AM_CFLAGS} ${CFLAGS} -CFA -XCFA -p ${<} -o ${@}
     875
    873876KRfunctions : KRfunctions.c @CFA_BINDIR@/@CFA_NAME@
    874877        ${CC} ${AM_CFLAGS} ${CFLAGS} -CFA -XCFA -p ${<} -o ${@}
  • src/tests/designations.c

    rc6e2c18 r9c35431  
    1717// In particular, since the syntax for designations in Cforall differs from that of C, preprocessor substitution
    1818// is used for the designation syntax
    19 #ifdef __CFORALL__
     19#ifdef __cforall
    2020#define DES :
    2121#else
  • src/tests/functions.c

    rc6e2c18 r9c35431  
    1010// Created On       : Wed Aug 17 08:39:58 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Aug 17 08:40:52 2016
    13 // Update Count     : 1
     12// Last Modified On : Mon Nov 27 18:08:54 2017
     13// Update Count     : 11
    1414//
    1515
     
    6666// Cforall extensions
    6767
    68 [] f( );
     68// [] f( );
    6969[int] f( );
    70 [] f(int);
     70// [] f(int);
    7171[int] f(int);
    72 [] f( ) {}
     72// [] f( ) {}
    7373[int] f( ) {}
    74 [] f(int) {}
     74// [] f(int) {}
    7575[int] f(int) {}
    7676
    7777[int x] f( );
    78 [] f(int x);
    79 [int x] f(int x);
    80 [int x] f( ) {}
    81 [] f(int x) {}
    82 [int x] f(int x) {}
     78// [] f(int x);
     79//[int x] f(int x);
     80//[int x] f( ) {}
     81// [] f(int x) {}
     82//[int x] f(int x) {}
    8383
    8484[int, int x] f( );
    85 [] f(int, int x);
     85// [] f(int, int x);
    8686[int, int x] f(int, int x);
    8787[int, int x] f( ) {}
    88 [] f(int, int x) {}
     88// [] f(int, int x) {}
    8989[int, int x] f(int, int x) {}
    9090
    9191[int, int x, int] f( );
    92 [] f(int, int x, int);
     92// [] f(int, int x, int);
    9393[int, int x, int] f(int, int x, int);
    9494[int, int x, int] f( ) {}
    95 [] f(int, int x, int) {}
     95// [] f(int, int x, int) {}
    9696[int, int x, int] f(int, int x, int) {}
    9797
    9898[int, int x, * int y] f( );
    99 [] f(int, int x, * int y);
     99// [] f(int, int x, * int y);
    100100[int, int x, * int y] f(int, int x, * int y);
    101101[int, int x, * int y] f( ) {}
    102 [] f(int, int x, * int y) {}
     102// [] f(int, int x, * int y) {}
    103103[int, int x, * int y] f(int, int x, * int y) {}
    104104
    105 [ int ] f11( int ), f12;  // => int f11( int ), f12( int );
     105// function prototypes
     106
     107[ int ] f11( int ), f12();  // => int f11( int ), f12( void );
     108
     109const double bar1(), bar2( int ), bar3( double );               // C version
     110[const double] foo(), foo( int ), foo( double ) { return 3.0; } // CFA version
     111struct S { int i; };
     112[S] rtn( int ) {}
     113
    106114
    107115[int] f(
     
    109117        [int](int)
    110118        ) {
    111         int (*(*p)[][10])[][3];
     119        int (*(*pc)[][10])[][3];
    112120        * [][10] * [][3] int p;
    113121        * [] * [int](int) p;
Note: See TracChangeset for help on using the changeset viewer.