Changes in / [7a054e82:b0fedd4]


Ignore:
Files:
1 added
6 deleted
11 edited

Legend:

Unmodified
Added
Removed
  • doc/generic_types/evaluation/.gitignore

    r7a054e82 rb0fedd4  
    11c-bench
    22cpp-bench
    3 cpp-vbench
    43cfa-bench
     4c2-bench
     5cpp2-bench
     6cfa2-bench
    57*.o
    68*.d
  • doc/generic_types/evaluation/Makefile

    r7a054e82 rb0fedd4  
    11CFA = my-cfa
    22DEPFLAGS = -MMD -MP
    3 CFLAGS = -O2 -flto
    4 CXXFLAGS = $(CFLAGS) --std=c++14
    53
    6 .PHONY: all clean distclean run-c run-cpp run-cfa run
     4.PHONY: all clean distclean bench
    75
    8 all: c-bench cpp-bench cfa-bench
     6all: c-bench cpp-bench cfa-bench c2-bench cpp2-bench cfa2-bench
    97
    108# rewrite object generation to auto-determine deps
     
    1513c-%.o : c-%.c
    1614c-%.o : c-%.c c-%.d
    17         $(COMPILE.c) $(OUTPUT_OPTION) -c $<
     15        $(COMPILE.c) -O0 $(OUTPUT_OPTION) -c $<
    1816
    1917cpp-%.o : cpp-%.cpp
    2018cpp-%.o : cpp-%.cpp cpp-%.d
    21         $(COMPILE.cpp) $(OUTPUT_OPTION) -c $<
     19        $(COMPILE.cpp) -O0 $(OUTPUT_OPTION) -c $<
    2220
    2321cfa-%.o : cfa-%.c
    2422cfa-%.o : cfa-%.c cfa-%.d
    25         $(COMPILE.cfa) $(OUTPUT_OPTION) -c $<
     23        $(COMPILE.cfa) -O0 $(OUTPUT_OPTION) -c $<
     24
     25c2-%.o : c-%.c
     26c2-%.o : c-%.c c-%.d
     27        $(COMPILE.c) -O2 $(OUTPUT_OPTION) -c $<
     28
     29cpp2-%.o : cpp-%.cpp
     30cpp2-%.o : cpp-%.cpp cpp-%.d
     31        $(COMPILE.cpp) -O2 $(OUTPUT_OPTION) -c $<
     32
     33cfa2-%.o : cfa-%.c
     34cfa2-%.o : cfa-%.c cfa-%.d
     35        $(COMPILE.cfa) -O2 $(OUTPUT_OPTION) -c $<
    2636
    2737COBJS = c-stack.o
    2838CPPOBJS =
    29 CPPVOBJS = cpp-vstack.o
    3039CFAOBJS = cfa-stack.o
     40C2OBJS = $(patsubst c-%,c2-%, $(COBJS))
     41CPP2OBJS = $(patsubst cpp-%,cpp2-%, $(CPPOBJS))
     42CFA2OBJS = $(patsubst cfa-%,cfa2-%, $(CFAOBJS))
    3143
    3244c-bench: c-bench.c c-bench.d $(COBJS)
    33         $(COMPILE.c) -o $@ $< $(COBJS) $(LDFLAGS)
     45        $(COMPILE.c) -O0 -o $@ $< $(COBJS) $(LDFLAGS)
    3446
    3547cpp-bench: cpp-bench.cpp cpp-bench.d $(CPPOBJS)
    36         $(COMPILE.cpp) -o $@ $< $(CPPOBJS) $(LDFLAGS)
    37 
    38 cpp-vbench: cpp-vbench.cpp cpp-vbench.d $(CPPVOBJS)
    39         $(COMPILE.cpp) -o $@ $< $(CPPVOBJS) $(LDFLAGS)
     48        $(COMPILE.cpp) -O0 -o $@ $< $(CPPOBJS) $(LDFLAGS)
    4049
    4150cfa-bench: cfa-bench.c cfa-bench.d $(CFAOBJS)
    42         $(COMPILE.cfa) -o $@ $< $(CFAOBJS) $(LDFLAGS)
     51        $(COMPILE.cfa) -O0 -o $@ $< $(CFAOBJS) $(LDFLAGS)
     52
     53c2-bench: c-bench.c c-bench.d $(C2OBJS)
     54        $(COMPILE.c) -O2 -o $@ $< $(C2OBJS) $(LDFLAGS)
     55
     56cpp2-bench: cpp-bench.cpp cpp-bench.d $(CPP2OBJS)
     57        $(COMPILE.cpp) -O2 -o $@ $< $(CPP2OBJS) $(LDFLAGS)
     58
     59cfa2-bench: cfa-bench.c cfa-bench.d $(CFA2OBJS)
     60        $(COMPILE.cfa) -O2 -o $@ $< $(CFA2OBJS) $(LDFLAGS)
    4361
    4462clean:
    4563        -rm $(COBJS) c-bench
    4664        -rm $(CPPOBJS) cpp-bench
    47         -rm $(CPPVOBJS) cpp-vbench
    4865        -rm $(CFAOBJS) cfa-bench
     66        -rm $(C2OBJS) c2-bench
     67        -rm $(CPP2OBJS) cpp2-bench
     68        -rm $(CFA2OBJS) cfa2-bench
    4969
    5070distclean: clean
    5171        -rm $(COBJS:.o=.d) c-bench.d
    5272        -rm $(CPPOBJS:.o=.d) cpp-bench.d
    53         -rm $(CPPVOBJS:.o=.d) cpp-vbench.d
    5473        -rm $(CFAOBJS:.o=.d) cfa-bench.d
    5574
    56 run-c: c-bench
     75bench: c-bench cpp-bench cfa-bench c2-bench cpp2-bench cfa2-bench
    5776        @echo '## C ##'
    5877        @./c-bench
    59         @printf 'source_size:\t%7d lines\n' `cat c-bench.c bench.h c-stack.h c-stack.c | wc -l`
    60         @printf 'binary_size:\t%7d bytes\n' `wc -c < c-bench`
    61 
    62 run-cfa: cfa-bench
     78        @echo '## C++ ##'
     79        @./cpp-bench
    6380        @echo '## Cforall ##'
    6481        @./cfa-bench
    65         @printf 'source_size:\t%7d lines\n' `cat cfa-bench.c bench.h cfa-stack.h cfa-stack.c | wc -l`
    66         @printf 'binary_size:\t%7d bytes\n' `wc -c < cfa-bench`
    67 
    68 run-cpp: cpp-bench
    69         @echo '## C++ ##'
    70         @./cpp-bench
    71         @printf 'source_size:\t%7d lines\n' `cat cpp-bench.cpp bench.hpp cpp-stack.hpp | wc -l`
    72         @printf 'binary_size:\t%7d bytes\n' `wc -c < cpp-bench`
    73 
    74 run-cppv: cpp-vbench
    75         @echo '## C++ virtual ##'
    76         @./cpp-vbench
    77         @printf 'source_size:\t%7d lines\n' `cat cpp-vbench.cpp bench.hpp object.hpp cpp-vstack.hpp cpp-vstack.cpp | wc -l`
    78         @printf 'binary_size:\t%7d bytes\n' `wc -c < cpp-vbench`
    79 
    80 run: run-c run-cfa run-cpp run-cppv
     82        @echo '## C -O2 ##'
     83        @./c2-bench
     84        @echo '## C++ -O2 ##'
     85        @./cpp2-bench
     86        @echo '## Cforall -O2 ##'
     87        @./cfa2-bench
    8188
    8289# so make doesn't fail without dependency files
  • doc/generic_types/evaluation/bench.h

    r7a054e82 rb0fedd4  
    1 #pragma once
    2 
    31#include <stdio.h>
    42#include <time.h>
    53
    6  #define N 100000000
    7  
     4#define N 200000000
    85
    96long ms_between(clock_t start, clock_t end) {
     
    129
    1310#define TIMED(name, code) { \
    14         volatile clock_t _start, _end; \
    15         _start = clock(); \
     11        clock_t start, end; \
     12        start = clock(); \
    1613        code \
    17         _end = clock(); \
    18         printf("%s:\t%7ld ms\n", name, ms_between(_start, _end)); \
     14        end = clock(); \
     15        printf("%s:\t%7ld ms\n", name, ms_between(start, end)); \
    1916}
    2017
    21 #define REPEAT_TIMED(name, code) TIMED( name, for (int _i = 0; _i < N; ++_i) { code } )
     18#define REPEAT_TIMED(name, code) TIMED( name, for (int i = 0; i < N; ++i) { code } )
  • doc/generic_types/evaluation/c-bench.c

    r7a054e82 rb0fedd4  
    22#include "bench.h"
    33#include "c-stack.h"
    4 
    5 void* copy_int( void* p ) {
    6         int* q = malloc(sizeof(int));
    7         *q = *(int*)p;
    8         return q;
    9 }
    104
    115int main(int argc, char** argv) {
     
    137
    148        struct stack s = new_stack();
     9
    1510        REPEAT_TIMED( "push_int",
    1611                int* x = malloc(sizeof(int));
     
    1914        )
    2015
    21         struct stack t;
    22         TIMED( "copy_int",
    23                 copy_stack(&t, &s, copy_int);
    24         )
    25 
    26         TIMED( "clear_int",
    27                 clear_stack(&s);
    28         )
    29 
    30         int sum;
    31         REPEAT_TIMED( "pop_int",
    32                 int* x = pop_stack(&t);
    33                 sum += *x;
    34                 free(x);
    35         )
     16        clear_stack(&s);
    3617}
  • doc/generic_types/evaluation/c-stack.c

    r7a054e82 rb0fedd4  
    1111}
    1212
    13 void copy_stack(struct stack* s, struct stack* t, void* (*copy)(void*)) {
    14         struct stack_node** crnt = &s->head;
    15         struct stack_node* next = t->head;
    16         while ( next ) {
    17                 *crnt = malloc(sizeof(struct stack_node));
    18                 **crnt = (struct stack_node){ copy(next->value) };
    19                 crnt = &(*crnt)->next;
    20                 next = next->next;
    21         }
    22         *crnt = 0;
    23 }
    24 
    2513void clear_stack(struct stack* s) {
    2614        struct stack_node* next = s->head;
     
    3119                free(crnt);
    3220        }
    33         s->head = NULL;
    3421}
    3522
  • doc/generic_types/evaluation/c-stack.h

    r7a054e82 rb0fedd4  
    1 #pragma once
    2 
    31struct stack_node;
    42
     
    97struct stack new_stack();
    108
    11 void copy_stack(struct stack* dst, struct stack* src, void* (*copy)(void*));
    12 
    139void clear_stack(struct stack* s);
    1410
  • doc/generic_types/evaluation/cfa-bench.c

    r7a054e82 rb0fedd4  
    77
    88        stack(int) s;
     9
    910        REPEAT_TIMED( "push_int",
    1011                push( &s, rand() );
    1112        )
    12 
    13         stack(int) t;
    14         TIMED( "copy_int",
    15                 t = s;
    16         )
    17 
    18         TIMED( "clear_int",
    19                 clear( &s );
    20         )
    21 
    22         int sum;
    23         REPEAT_TIMED( "pop_int",
    24                 sum += pop( &t );
    25         )
    2613}
  • doc/generic_types/evaluation/cfa-stack.c

    r7a054e82 rb0fedd4  
    1 #include <assert>
    21#include <stdlib>
    32#include "cfa-stack.h"
     
    98
    109forall(otype T) void ?{}(stack(T)* s) {
    11         (&s->head){ 0 };
    12 }
    13 
    14 forall(otype T) void copy(stack(T)* s, stack(T)* t) {
    15         stack_node(T)** crnt = &s->head;
    16         stack_node(T)* next = t->head;
    17         while ( next ) {
    18                 *crnt = ((stack_node(T)*)malloc()){ next->value };
    19                 stack_node(T)* acrnt = *crnt;
    20                 crnt = &acrnt->next;
    21                 next = next->next;
    22         }
    23         *crnt = 0;
    24 }
    25 
    26 forall(otype T) void ?{}(stack(T)* s, stack(T) t) {
    27         stack_node(T)** crnt = &s->head;
    28         stack_node(T)* next = t.head;
    29         while ( next ) {
    30                 *crnt = ((stack_node(T)*)malloc()){ next->value };
    31                 stack_node(T)* acrnt = *crnt;
    32                 crnt = &acrnt->next;
    33                 next = next->next;
    34         }
    35         *crnt = 0;
    36 }
    37 
    38 forall(otype T) stack(T) ?=?(stack(T)* s, stack(T) t) {
    39         if ( s->head == t.head ) return *s;
    40         clear(s);
    41         s{ t };
    42         return *s;
     10        ?{}( &s->head, 0 );
    4311}
    4412
    4513forall(otype T) void ^?{}(stack(T)* s) {
    46         clear(s);
     14        stack_node(T)* next = s->head;
     15        while ( next ) {
     16                stack_node(T)* crnt = next;
     17                next = crnt->next;
     18                delete(crnt);
     19        }
    4720}
    4821
     
    6235        return x;
    6336}
    64 
    65 forall(otype T) void clear(stack(T)* s) {
    66         stack_node(T)* next = s->head;
    67         while ( next ) {
    68                 stack_node(T)* crnt = next;
    69                 next = crnt->next;
    70                 delete(crnt);
    71         }
    72         s->head = 0;
    73 }
  • doc/generic_types/evaluation/cfa-stack.h

    r7a054e82 rb0fedd4  
    1 #pragma once
    2 
    31forall(otype T) struct stack_node;
    42
     
    97forall(otype T) void ?{}(stack(T)* s);
    108
    11 forall(otype T) void ?{}(stack(T)* s, stack(T) t);
    12 
    13 forall(otype T) stack(T) ?=?(stack(T)* s, stack(T) t);
    14 
    159forall(otype T) void ^?{}(stack(T)* s);
    1610
     
    2014
    2115forall(otype T) T pop(stack(T)* s);
    22 
    23 forall(otype T) void clear(stack(T)* s);
  • doc/generic_types/evaluation/cpp-bench.cpp

    r7a054e82 rb0fedd4  
    11#include <stdlib.h>
    2 #include "bench.hpp"
    3 #include "cpp-stack.hpp"
     2#include "bench.h"
     3#include "cpp-stack.h"
    44
    55int main(int argc, char** argv) {
     
    77
    88        stack<int> s;
     9
    910        REPEAT_TIMED( "push_int",
    1011                s.push( rand() );
    1112        )
    12 
    13         stack<int> t;
    14         TIMED( "copy_int",
    15                 t = s;
    16         )
    17 
    18         TIMED( "clear_int",
    19                 s.clear();
    20         )
    21 
    22         int sum;
    23         REPEAT_TIMED( "pop_int",
    24                 sum += t.pop();
    25         )
    2613}
  • src/GenPoly/Box.cc

    r7a054e82 rb0fedd4  
    3434#include "Parser/ParseNode.h"
    3535
    36 #include "SynTree/Attribute.h"
    3736#include "SynTree/Constant.h"
    3837#include "SynTree/Declaration.h"
     
    166165                        using Parent::mutate;
    167166
    168                         PolyGenericCalculator();
    169 
    170167                        template< typename DeclClass >
    171168                        DeclClass *handleDecl( DeclClass *decl, Type *type );
     
    201198                        ScopedSet< std::string > knownLayouts;          ///< Set of generic type layouts known in the current scope, indexed by sizeofName
    202199                        ScopedSet< std::string > knownOffsets;          ///< Set of non-generic types for which the offset array exists in the current scope, indexed by offsetofName
    203                         UniqueName bufNamer;                           ///< Namer for VLA buffers
    204200                };
    205201
     
    14561452////////////////////////////////////////// PolyGenericCalculator ////////////////////////////////////////////////////
    14571453
    1458                 PolyGenericCalculator::PolyGenericCalculator()
    1459                         : Parent(), knownLayouts(), knownOffsets(), bufNamer( "_buf" ) {}
    1460 
    14611454                void PolyGenericCalculator::beginTypeScope( Type *ty ) {
    14621455                        scopeTyVars.beginScope();
     
    15351528                        if ( ObjectDecl *objectDecl = dynamic_cast< ObjectDecl *>( declStmt->get_decl() ) ) {
    15361529                                if ( findGeneric( objectDecl->get_type() ) ) {
    1537                                         // change initialization of a polymorphic value object to allocate via a VLA
    1538                                         // (alloca was previously used, but can't be safely used in loops)
     1530                                        // change initialization of a polymorphic value object
     1531                                        // to allocate storage with alloca
    15391532                                        Type *declType = objectDecl->get_type();
    1540                                         std::string bufName = bufNamer.newName();
    1541                                         ObjectDecl *newBuf = new ObjectDecl( bufName, Type::StorageClasses(), LinkageSpec::C, 0,
    1542                                                 new ArrayType( Type::Qualifiers(), new BasicType( Type::Qualifiers(), BasicType::Kind::Char), new NameExpr( sizeofName( mangleType(declType) ) ),
    1543                                                 true, false, std::list<Attribute*>{ new Attribute( std::string{"aligned"}, std::list<Expression*>{ new ConstantExpr( Constant::from_int(8) ) } ) } ), 0 );
    1544                                         stmtsToAdd.push_back( new DeclStmt( noLabels, newBuf ) );
     1533                                        UntypedExpr *alloc = new UntypedExpr( new NameExpr( "__builtin_alloca" ) );
     1534                                        alloc->get_args().push_back( new NameExpr( sizeofName( mangleType( declType ) ) ) );
    15451535
    15461536                                        delete objectDecl->get_init();
    15471537
    1548                                         objectDecl->set_init( new SingleInit( new NameExpr( bufName ) ) );
     1538                                        std::list<Expression*> designators;
     1539                                        objectDecl->set_init( new SingleInit( alloc, designators, false ) ); // not constructed
    15491540                                }
    15501541                        }
Note: See TracChangeset for help on using the changeset viewer.