Changeset 9939dc3 for src/Tuples
- Timestamp:
- May 17, 2022, 3:44:08 PM (6 weeks ago)
- Branches:
- master
- Children:
- 767a8ef
- Parents:
- fa2a3b1
- Location:
- src/Tuples
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Tuples/TupleExpansion.cc
rfa2a3b1 r9939dc3 9 9 // Author : Rodolfo G. Esteves 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Fri Dec 13 23:45:51 201913 // Update Count : 2 411 // Last Modified By : Andrew Beach 12 // Last Modified On : Tue May 17 15:02:00 2022 13 // Update Count : 25 14 14 // 15 15 … … 367 367 return nullptr; 368 368 } 369 370 namespace {371 /// determines if impurity (read: side-effects) may exist in a piece of code. Currently gives a very crude approximation, wherein any function call expression means the code may be impure372 struct ImpurityDetector : public WithShortCircuiting {373 ImpurityDetector( bool ignoreUnique ) : ignoreUnique( ignoreUnique ) {}374 375 void previsit( const ApplicationExpr * appExpr ) {376 visit_children = false;377 if ( const DeclarationWithType * function = InitTweak::getFunction( appExpr ) ) {378 if ( function->linkage == LinkageSpec::Intrinsic ) {379 if ( function->name == "*?" || function->name == "?[?]" ) {380 // intrinsic dereference, subscript are pure, but need to recursively look for impurity381 visit_children = true;382 return;383 }384 }385 }386 maybeImpure = true;387 }388 void previsit( const UntypedExpr * ) { maybeImpure = true; visit_children = false; }389 void previsit( const UniqueExpr * ) {390 if ( ignoreUnique ) {391 // bottom out at unique expression.392 // The existence of a unique expression doesn't change the purity of an expression.393 // That is, even if the wrapped expression is impure, the wrapper protects the rest of the expression.394 visit_children = false;395 return;396 }397 }398 399 bool maybeImpure = false;400 bool ignoreUnique;401 };402 } // namespace403 404 bool maybeImpure( const Expression * expr ) {405 PassVisitor<ImpurityDetector> detector( false );406 expr->accept( detector );407 return detector.pass.maybeImpure;408 }409 410 bool maybeImpureIgnoreUnique( const Expression * expr ) {411 PassVisitor<ImpurityDetector> detector( true );412 expr->accept( detector );413 return detector.pass.maybeImpure;414 }415 369 } // namespace Tuples 416 370 -
src/Tuples/Tuples.cc
rfa2a3b1 r9939dc3 10 10 // Created On : Mon Jun 17 14:41:00 2019 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Tue Jun 18 9:31:00 201913 // Update Count : 112 // Last Modified On : Mon May 16 16:15:00 2022 13 // Update Count : 2 14 14 // 15 15 … … 18 18 #include "AST/Pass.hpp" 19 19 #include "AST/LinkageSpec.hpp" 20 #include "Common/PassVisitor.h" 20 21 #include "InitTweak/InitTweak.h" 21 22 … … 23 24 24 25 namespace { 26 /// Checks if impurity (read: side-effects) may exist in a piece of code. 27 /// Currently gives a very crude approximation, wherein any function 28 /// call expression means the code may be impure. 29 struct ImpurityDetector_old : public WithShortCircuiting { 30 bool const ignoreUnique; 31 bool maybeImpure; 32 33 ImpurityDetector_old( bool ignoreUnique ) : 34 ignoreUnique( ignoreUnique ), maybeImpure( false ) 35 {} 36 37 void previsit( const ApplicationExpr * appExpr ) { 38 visit_children = false; 39 if ( const DeclarationWithType * function = 40 InitTweak::getFunction( appExpr ) ) { 41 if ( function->linkage == LinkageSpec::Intrinsic ) { 42 if ( function->name == "*?" || function->name == "?[?]" ) { 43 // intrinsic dereference, subscript are pure, 44 // but need to recursively look for impurity 45 visit_children = true; 46 return; 47 } 48 } 49 } 50 maybeImpure = true; 51 } 52 53 void previsit( const UntypedExpr * ) { 54 maybeImpure = true; 55 visit_children = false; 56 } 57 58 void previsit( const UniqueExpr * ) { 59 if ( ignoreUnique ) { 60 // bottom out at unique expression. 61 // The existence of a unique expression doesn't change the purity of an expression. 62 // That is, even if the wrapped expression is impure, the wrapper protects the rest of the expression. 63 visit_children = false; 64 return; 65 } 66 } 67 }; 68 69 bool detectImpurity( const Expression * expr, bool ignoreUnique ) { 70 PassVisitor<ImpurityDetector_old> detector( ignoreUnique ); 71 expr->accept( detector ); 72 return detector.pass.maybeImpure; 73 } 74 25 75 /// Determines if impurity (read: side-effects) may exist in a piece of code. Currently gives 26 76 /// a very crude approximation, wherein any function call expression means the code may be 27 77 /// impure. 28 78 struct ImpurityDetector : public ast::WithShortCircuiting { 29 bool maybeImpure= false;79 bool result = false; 30 80 31 81 void previsit( ast::ApplicationExpr const * appExpr ) { … … 36 86 } 37 87 } 38 maybeImpure= true; visit_children = false;88 result = true; visit_children = false; 39 89 } 40 90 void previsit( ast::UntypedExpr const * ) { 41 maybeImpure= true; visit_children = false;91 result = true; visit_children = false; 42 92 } 43 93 }; 94 44 95 struct ImpurityDetectorIgnoreUnique : public ImpurityDetector { 45 96 using ImpurityDetector::previsit; … … 48 99 } 49 100 }; 50 51 template<typename Detector>52 bool detectImpurity( const ast::Expr * expr ) {53 ast::Pass<Detector> detector;54 expr->accept( detector );55 return detector.core.maybeImpure;56 }57 101 } // namespace 58 102 59 103 bool maybeImpure( const ast::Expr * expr ) { 60 return detectImpurity<ImpurityDetector>( expr );104 return ast::Pass<ImpurityDetector>::read( expr ); 61 105 } 62 106 63 107 bool maybeImpureIgnoreUnique( const ast::Expr * expr ) { 64 return detectImpurity<ImpurityDetectorIgnoreUnique>( expr ); 108 return ast::Pass<ImpurityDetectorIgnoreUnique>::read( expr ); 109 } 110 111 bool maybeImpure( const Expression * expr ) { 112 return detectImpurity( expr, false ); 113 } 114 115 bool maybeImpureIgnoreUnique( const Expression * expr ) { 116 return detectImpurity( expr, true ); 65 117 } 66 118 -
src/Tuples/module.mk
rfa2a3b1 r9939dc3 10 10 ## Author : Richard C. Bilson 11 11 ## Created On : Mon Jun 1 17:49:17 2015 12 ## Last Modified By : Henry Xue13 ## Last Modified On : Mon Aug 23 15:36:09 202114 ## Update Count : 212 ## Last Modified By : Andrew Beach 13 ## Last Modified On : Mon May 17 15:00:00 2022 14 ## Update Count : 3 15 15 ############################################################################### 16 16 … … 24 24 Tuples/Tuples.h 25 25 26 SRC += $(SRC_TUPLES) 26 27 27 SRC += $(SRC_TUPLES)28 28 SRCDEMANGLE += $(SRC_TUPLES)
Note: See TracChangeset
for help on using the changeset viewer.