Changeset 7a054e82


Ignore:
Timestamp:
Apr 10, 2017, 3:17:29 PM (7 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
b715c9a
Parents:
b0fedd4 (diff), b276be5 (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:
6 added
1 deleted
11 edited

Legend:

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

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

    rb0fedd4 r7a054e82  
    11CFA = my-cfa
    22DEPFLAGS = -MMD -MP
     3CFLAGS = -O2 -flto
     4CXXFLAGS = $(CFLAGS) --std=c++14
    35
    4 .PHONY: all clean distclean bench
     6.PHONY: all clean distclean run-c run-cpp run-cfa run
    57
    6 all: c-bench cpp-bench cfa-bench c2-bench cpp2-bench cfa2-bench
     8all: c-bench cpp-bench cfa-bench
    79
    810# rewrite object generation to auto-determine deps
     
    1315c-%.o : c-%.c
    1416c-%.o : c-%.c c-%.d
    15         $(COMPILE.c) -O0 $(OUTPUT_OPTION) -c $<
     17        $(COMPILE.c) $(OUTPUT_OPTION) -c $<
    1618
    1719cpp-%.o : cpp-%.cpp
    1820cpp-%.o : cpp-%.cpp cpp-%.d
    19         $(COMPILE.cpp) -O0 $(OUTPUT_OPTION) -c $<
     21        $(COMPILE.cpp) $(OUTPUT_OPTION) -c $<
    2022
    2123cfa-%.o : cfa-%.c
    2224cfa-%.o : cfa-%.c cfa-%.d
    23         $(COMPILE.cfa) -O0 $(OUTPUT_OPTION) -c $<
    24 
    25 c2-%.o : c-%.c
    26 c2-%.o : c-%.c c-%.d
    27         $(COMPILE.c) -O2 $(OUTPUT_OPTION) -c $<
    28 
    29 cpp2-%.o : cpp-%.cpp
    30 cpp2-%.o : cpp-%.cpp cpp-%.d
    31         $(COMPILE.cpp) -O2 $(OUTPUT_OPTION) -c $<
    32 
    33 cfa2-%.o : cfa-%.c
    34 cfa2-%.o : cfa-%.c cfa-%.d
    35         $(COMPILE.cfa) -O2 $(OUTPUT_OPTION) -c $<
     25        $(COMPILE.cfa) $(OUTPUT_OPTION) -c $<
    3626
    3727COBJS = c-stack.o
    3828CPPOBJS =
     29CPPVOBJS = cpp-vstack.o
    3930CFAOBJS = cfa-stack.o
    40 C2OBJS = $(patsubst c-%,c2-%, $(COBJS))
    41 CPP2OBJS = $(patsubst cpp-%,cpp2-%, $(CPPOBJS))
    42 CFA2OBJS = $(patsubst cfa-%,cfa2-%, $(CFAOBJS))
    4331
    4432c-bench: c-bench.c c-bench.d $(COBJS)
    45         $(COMPILE.c) -O0 -o $@ $< $(COBJS) $(LDFLAGS)
     33        $(COMPILE.c) -o $@ $< $(COBJS) $(LDFLAGS)
    4634
    4735cpp-bench: cpp-bench.cpp cpp-bench.d $(CPPOBJS)
    48         $(COMPILE.cpp) -O0 -o $@ $< $(CPPOBJS) $(LDFLAGS)
     36        $(COMPILE.cpp) -o $@ $< $(CPPOBJS) $(LDFLAGS)
     37
     38cpp-vbench: cpp-vbench.cpp cpp-vbench.d $(CPPVOBJS)
     39        $(COMPILE.cpp) -o $@ $< $(CPPVOBJS) $(LDFLAGS)
    4940
    5041cfa-bench: cfa-bench.c cfa-bench.d $(CFAOBJS)
    51         $(COMPILE.cfa) -O0 -o $@ $< $(CFAOBJS) $(LDFLAGS)
    52 
    53 c2-bench: c-bench.c c-bench.d $(C2OBJS)
    54         $(COMPILE.c) -O2 -o $@ $< $(C2OBJS) $(LDFLAGS)
    55 
    56 cpp2-bench: cpp-bench.cpp cpp-bench.d $(CPP2OBJS)
    57         $(COMPILE.cpp) -O2 -o $@ $< $(CPP2OBJS) $(LDFLAGS)
    58 
    59 cfa2-bench: cfa-bench.c cfa-bench.d $(CFA2OBJS)
    60         $(COMPILE.cfa) -O2 -o $@ $< $(CFA2OBJS) $(LDFLAGS)
     42        $(COMPILE.cfa) -o $@ $< $(CFAOBJS) $(LDFLAGS)
    6143
    6244clean:
    6345        -rm $(COBJS) c-bench
    6446        -rm $(CPPOBJS) cpp-bench
     47        -rm $(CPPVOBJS) cpp-vbench
    6548        -rm $(CFAOBJS) cfa-bench
    66         -rm $(C2OBJS) c2-bench
    67         -rm $(CPP2OBJS) cpp2-bench
    68         -rm $(CFA2OBJS) cfa2-bench
    6949
    7050distclean: clean
    7151        -rm $(COBJS:.o=.d) c-bench.d
    7252        -rm $(CPPOBJS:.o=.d) cpp-bench.d
     53        -rm $(CPPVOBJS:.o=.d) cpp-vbench.d
    7354        -rm $(CFAOBJS:.o=.d) cfa-bench.d
    7455
    75 bench: c-bench cpp-bench cfa-bench c2-bench cpp2-bench cfa2-bench
     56run-c: c-bench
    7657        @echo '## C ##'
    7758        @./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
     62run-cfa: cfa-bench
     63        @echo '## Cforall ##'
     64        @./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
     68run-cpp: cpp-bench
    7869        @echo '## C++ ##'
    7970        @./cpp-bench
    80         @echo '## Cforall ##'
    81         @./cfa-bench
    82         @echo '## C -O2 ##'
    83         @./c2-bench
    84         @echo '## C++ -O2 ##'
    85         @./cpp2-bench
    86         @echo '## Cforall -O2 ##'
    87         @./cfa2-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
     74run-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
     80run: run-c run-cfa run-cpp run-cppv
    8881
    8982# so make doesn't fail without dependency files
  • doc/generic_types/evaluation/bench.h

    rb0fedd4 r7a054e82  
     1#pragma once
     2
    13#include <stdio.h>
    24#include <time.h>
    35
    4 #define N 200000000
     6 #define N 100000000
     7 
    58
    69long ms_between(clock_t start, clock_t end) {
     
    912
    1013#define TIMED(name, code) { \
    11         clock_t start, end; \
    12         start = clock(); \
     14        volatile clock_t _start, _end; \
     15        _start = clock(); \
    1316        code \
    14         end = clock(); \
    15         printf("%s:\t%7ld ms\n", name, ms_between(start, end)); \
     17        _end = clock(); \
     18        printf("%s:\t%7ld ms\n", name, ms_between(_start, _end)); \
    1619}
    1720
    18 #define REPEAT_TIMED(name, code) TIMED( name, for (int i = 0; i < N; ++i) { code } )
     21#define REPEAT_TIMED(name, code) TIMED( name, for (int _i = 0; _i < N; ++_i) { code } )
  • doc/generic_types/evaluation/c-bench.c

    rb0fedd4 r7a054e82  
    22#include "bench.h"
    33#include "c-stack.h"
     4
     5void* copy_int( void* p ) {
     6        int* q = malloc(sizeof(int));
     7        *q = *(int*)p;
     8        return q;
     9}
    410
    511int main(int argc, char** argv) {
     
    713
    814        struct stack s = new_stack();
    9 
    1015        REPEAT_TIMED( "push_int",
    1116                int* x = malloc(sizeof(int));
     
    1419        )
    1520
    16         clear_stack(&s);
     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        )
    1736}
  • doc/generic_types/evaluation/c-stack.c

    rb0fedd4 r7a054e82  
    1111}
    1212
     13void 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
    1325void clear_stack(struct stack* s) {
    1426        struct stack_node* next = s->head;
     
    1931                free(crnt);
    2032        }
     33        s->head = NULL;
    2134}
    2235
  • doc/generic_types/evaluation/c-stack.h

    rb0fedd4 r7a054e82  
     1#pragma once
     2
    13struct stack_node;
    24
     
    79struct stack new_stack();
    810
     11void copy_stack(struct stack* dst, struct stack* src, void* (*copy)(void*));
     12
    913void clear_stack(struct stack* s);
    1014
  • doc/generic_types/evaluation/cfa-bench.c

    rb0fedd4 r7a054e82  
    77
    88        stack(int) s;
    9 
    109        REPEAT_TIMED( "push_int",
    1110                push( &s, rand() );
    1211        )
     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        )
    1326}
  • doc/generic_types/evaluation/cfa-stack.c

    rb0fedd4 r7a054e82  
     1#include <assert>
    12#include <stdlib>
    23#include "cfa-stack.h"
     
    89
    910forall(otype T) void ?{}(stack(T)* s) {
    10         ?{}( &s->head, 0 );
     11        (&s->head){ 0 };
     12}
     13
     14forall(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
     26forall(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
     38forall(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;
    1143}
    1244
    1345forall(otype T) void ^?{}(stack(T)* 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         }
     46        clear(s);
    2047}
    2148
     
    3562        return x;
    3663}
     64
     65forall(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

    rb0fedd4 r7a054e82  
     1#pragma once
     2
    13forall(otype T) struct stack_node;
    24
     
    79forall(otype T) void ?{}(stack(T)* s);
    810
     11forall(otype T) void ?{}(stack(T)* s, stack(T) t);
     12
     13forall(otype T) stack(T) ?=?(stack(T)* s, stack(T) t);
     14
    915forall(otype T) void ^?{}(stack(T)* s);
    1016
     
    1420
    1521forall(otype T) T pop(stack(T)* s);
     22
     23forall(otype T) void clear(stack(T)* s);
  • doc/generic_types/evaluation/cpp-bench.cpp

    rb0fedd4 r7a054e82  
    11#include <stdlib.h>
    2 #include "bench.h"
    3 #include "cpp-stack.h"
     2#include "bench.hpp"
     3#include "cpp-stack.hpp"
    44
    55int main(int argc, char** argv) {
     
    77
    88        stack<int> s;
    9 
    109        REPEAT_TIMED( "push_int",
    1110                s.push( rand() );
    1211        )
     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        )
    1326}
  • src/GenPoly/Box.cc

    rb0fedd4 r7a054e82  
    3434#include "Parser/ParseNode.h"
    3535
     36#include "SynTree/Attribute.h"
    3637#include "SynTree/Constant.h"
    3738#include "SynTree/Declaration.h"
     
    165166                        using Parent::mutate;
    166167
     168                        PolyGenericCalculator();
     169
    167170                        template< typename DeclClass >
    168171                        DeclClass *handleDecl( DeclClass *decl, Type *type );
     
    198201                        ScopedSet< std::string > knownLayouts;          ///< Set of generic type layouts known in the current scope, indexed by sizeofName
    199202                        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
    200204                };
    201205
     
    14521456////////////////////////////////////////// PolyGenericCalculator ////////////////////////////////////////////////////
    14531457
     1458                PolyGenericCalculator::PolyGenericCalculator()
     1459                        : Parent(), knownLayouts(), knownOffsets(), bufNamer( "_buf" ) {}
     1460
    14541461                void PolyGenericCalculator::beginTypeScope( Type *ty ) {
    14551462                        scopeTyVars.beginScope();
     
    15281535                        if ( ObjectDecl *objectDecl = dynamic_cast< ObjectDecl *>( declStmt->get_decl() ) ) {
    15291536                                if ( findGeneric( objectDecl->get_type() ) ) {
    1530                                         // change initialization of a polymorphic value object
    1531                                         // to allocate storage with alloca
     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)
    15321539                                        Type *declType = objectDecl->get_type();
    1533                                         UntypedExpr *alloc = new UntypedExpr( new NameExpr( "__builtin_alloca" ) );
    1534                                         alloc->get_args().push_back( new NameExpr( sizeofName( mangleType( declType ) ) ) );
     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 ) );
    15351545
    15361546                                        delete objectDecl->get_init();
    15371547
    1538                                         std::list<Expression*> designators;
    1539                                         objectDecl->set_init( new SingleInit( alloc, designators, false ) ); // not constructed
     1548                                        objectDecl->set_init( new SingleInit( new NameExpr( bufName ) ) );
    15401549                                }
    15411550                        }
Note: See TracChangeset for help on using the changeset viewer.