Changes in / [7a054e82:b0fedd4]
- Files:
-
- 1 added
- 6 deleted
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/generic_types/evaluation/.gitignore
r7a054e82 rb0fedd4 1 1 c-bench 2 2 cpp-bench 3 cpp-vbench4 3 cfa-bench 4 c2-bench 5 cpp2-bench 6 cfa2-bench 5 7 *.o 6 8 *.d -
doc/generic_types/evaluation/Makefile
r7a054e82 rb0fedd4 1 1 CFA = my-cfa 2 2 DEPFLAGS = -MMD -MP 3 CFLAGS = -O2 -flto4 CXXFLAGS = $(CFLAGS) --std=c++145 3 6 .PHONY: all clean distclean run-c run-cpp run-cfa run4 .PHONY: all clean distclean bench 7 5 8 all: c-bench cpp-bench cfa-bench 6 all: c-bench cpp-bench cfa-bench c2-bench cpp2-bench cfa2-bench 9 7 10 8 # rewrite object generation to auto-determine deps … … 15 13 c-%.o : c-%.c 16 14 c-%.o : c-%.c c-%.d 17 $(COMPILE.c) $(OUTPUT_OPTION) -c $<15 $(COMPILE.c) -O0 $(OUTPUT_OPTION) -c $< 18 16 19 17 cpp-%.o : cpp-%.cpp 20 18 cpp-%.o : cpp-%.cpp cpp-%.d 21 $(COMPILE.cpp) $(OUTPUT_OPTION) -c $<19 $(COMPILE.cpp) -O0 $(OUTPUT_OPTION) -c $< 22 20 23 21 cfa-%.o : cfa-%.c 24 22 cfa-%.o : cfa-%.c cfa-%.d 25 $(COMPILE.cfa) $(OUTPUT_OPTION) -c $< 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 $< 26 36 27 37 COBJS = c-stack.o 28 38 CPPOBJS = 29 CPPVOBJS = cpp-vstack.o30 39 CFAOBJS = cfa-stack.o 40 C2OBJS = $(patsubst c-%,c2-%, $(COBJS)) 41 CPP2OBJS = $(patsubst cpp-%,cpp2-%, $(CPPOBJS)) 42 CFA2OBJS = $(patsubst cfa-%,cfa2-%, $(CFAOBJS)) 31 43 32 44 c-bench: c-bench.c c-bench.d $(COBJS) 33 $(COMPILE.c) - o $@ $< $(COBJS) $(LDFLAGS)45 $(COMPILE.c) -O0 -o $@ $< $(COBJS) $(LDFLAGS) 34 46 35 47 cpp-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) 40 49 41 50 cfa-bench: cfa-bench.c cfa-bench.d $(CFAOBJS) 42 $(COMPILE.cfa) -o $@ $< $(CFAOBJS) $(LDFLAGS) 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) 43 61 44 62 clean: 45 63 -rm $(COBJS) c-bench 46 64 -rm $(CPPOBJS) cpp-bench 47 -rm $(CPPVOBJS) cpp-vbench48 65 -rm $(CFAOBJS) cfa-bench 66 -rm $(C2OBJS) c2-bench 67 -rm $(CPP2OBJS) cpp2-bench 68 -rm $(CFA2OBJS) cfa2-bench 49 69 50 70 distclean: clean 51 71 -rm $(COBJS:.o=.d) c-bench.d 52 72 -rm $(CPPOBJS:.o=.d) cpp-bench.d 53 -rm $(CPPVOBJS:.o=.d) cpp-vbench.d54 73 -rm $(CFAOBJS:.o=.d) cfa-bench.d 55 74 56 run-c: c-bench75 bench: c-bench cpp-bench cfa-bench c2-bench cpp2-bench cfa2-bench 57 76 @echo '## C ##' 58 77 @./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 63 80 @echo '## Cforall ##' 64 81 @./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 81 88 82 89 # so make doesn't fail without dependency files -
doc/generic_types/evaluation/bench.h
r7a054e82 rb0fedd4 1 #pragma once2 3 1 #include <stdio.h> 4 2 #include <time.h> 5 3 6 #define N 100000000 7 4 #define N 200000000 8 5 9 6 long ms_between(clock_t start, clock_t end) { … … 12 9 13 10 #define TIMED(name, code) { \ 14 volatile clock_t _start, _end; \15 _start = clock(); \11 clock_t start, end; \ 12 start = clock(); \ 16 13 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)); \ 19 16 } 20 17 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 2 2 #include "bench.h" 3 3 #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 }10 4 11 5 int main(int argc, char** argv) { … … 13 7 14 8 struct stack s = new_stack(); 9 15 10 REPEAT_TIMED( "push_int", 16 11 int* x = malloc(sizeof(int)); … … 19 14 ) 20 15 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); 36 17 } -
doc/generic_types/evaluation/c-stack.c
r7a054e82 rb0fedd4 11 11 } 12 12 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 25 13 void clear_stack(struct stack* s) { 26 14 struct stack_node* next = s->head; … … 31 19 free(crnt); 32 20 } 33 s->head = NULL;34 21 } 35 22 -
doc/generic_types/evaluation/c-stack.h
r7a054e82 rb0fedd4 1 #pragma once2 3 1 struct stack_node; 4 2 … … 9 7 struct stack new_stack(); 10 8 11 void copy_stack(struct stack* dst, struct stack* src, void* (*copy)(void*));12 13 9 void clear_stack(struct stack* s); 14 10 -
doc/generic_types/evaluation/cfa-bench.c
r7a054e82 rb0fedd4 7 7 8 8 stack(int) s; 9 9 10 REPEAT_TIMED( "push_int", 10 11 push( &s, rand() ); 11 12 ) 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 )26 13 } -
doc/generic_types/evaluation/cfa-stack.c
r7a054e82 rb0fedd4 1 #include <assert>2 1 #include <stdlib> 3 2 #include "cfa-stack.h" … … 9 8 10 9 forall(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 ); 43 11 } 44 12 45 13 forall(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 } 47 20 } 48 21 … … 62 35 return x; 63 36 } 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 once2 3 1 forall(otype T) struct stack_node; 4 2 … … 9 7 forall(otype T) void ?{}(stack(T)* s); 10 8 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 15 9 forall(otype T) void ^?{}(stack(T)* s); 16 10 … … 20 14 21 15 forall(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 1 1 #include <stdlib.h> 2 #include "bench.h pp"3 #include "cpp-stack.h pp"2 #include "bench.h" 3 #include "cpp-stack.h" 4 4 5 5 int main(int argc, char** argv) { … … 7 7 8 8 stack<int> s; 9 9 10 REPEAT_TIMED( "push_int", 10 11 s.push( rand() ); 11 12 ) 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 )26 13 } -
src/GenPoly/Box.cc
r7a054e82 rb0fedd4 34 34 #include "Parser/ParseNode.h" 35 35 36 #include "SynTree/Attribute.h"37 36 #include "SynTree/Constant.h" 38 37 #include "SynTree/Declaration.h" … … 166 165 using Parent::mutate; 167 166 168 PolyGenericCalculator();169 170 167 template< typename DeclClass > 171 168 DeclClass *handleDecl( DeclClass *decl, Type *type ); … … 201 198 ScopedSet< std::string > knownLayouts; ///< Set of generic type layouts known in the current scope, indexed by sizeofName 202 199 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 buffers204 200 }; 205 201 … … 1456 1452 ////////////////////////////////////////// PolyGenericCalculator //////////////////////////////////////////////////// 1457 1453 1458 PolyGenericCalculator::PolyGenericCalculator()1459 : Parent(), knownLayouts(), knownOffsets(), bufNamer( "_buf" ) {}1460 1461 1454 void PolyGenericCalculator::beginTypeScope( Type *ty ) { 1462 1455 scopeTyVars.beginScope(); … … 1535 1528 if ( ObjectDecl *objectDecl = dynamic_cast< ObjectDecl *>( declStmt->get_decl() ) ) { 1536 1529 if ( findGeneric( objectDecl->get_type() ) ) { 1537 // change initialization of a polymorphic value object to allocate via a VLA1538 // (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 1539 1532 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 ) ) ) ); 1545 1535 1546 1536 delete objectDecl->get_init(); 1547 1537 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 1549 1540 } 1550 1541 }
Note: See TracChangeset
for help on using the changeset viewer.