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