Changeset 53bb8f1 for src/ResolvExpr/Cost.h
- Timestamp:
- Mar 12, 2019, 3:00:54 PM (7 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 30e32b2, a2545593
- Parents:
- 9d9a451 (diff), 91d6584 (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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/Cost.h
r9d9a451 r53bb8f1 9 9 // Author : Richard C. Bilson 10 10 // Created On : Sun May 17 09:39:50 2015 11 // Last Modified By : Aaron B. Moss12 // Last Modified On : Fri Oct 05 14:32:00 201813 // Update Count : 711 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Feb 7 20:54:29 2019 13 // Update Count : 8 14 14 // 15 15 … … 21 21 class Cost { 22 22 private: 23 Cost( int unsafeCost, int polyCost, int safeCost, int varCost, int specCost, 24 int referenceCost ); 25 23 Cost( int unsafeCost, int polyCost, int safeCost, int signCost, 24 int varCost, int specCost, int referenceCost ); 26 25 public: 27 26 Cost & incUnsafe( int inc = 1 ); 28 27 Cost & incPoly( int inc = 1 ); 29 28 Cost & incSafe( int inc = 1 ); 29 Cost & incSign( int inc = 1 ); 30 30 Cost & incVar( int inc = 1 ); 31 31 Cost & decSpec( int inc = 1 ); … … 35 35 int get_polyCost() const { return polyCost; } 36 36 int get_safeCost() const { return safeCost; } 37 int get_signCost() const { return signCost; } 37 38 int get_varCost() const { return varCost; } 38 39 int get_specCost() const { return specCost; } … … 40 41 41 42 Cost operator+( const Cost &other ) const; 42 Cost operator-( const Cost &other ) const;43 43 Cost &operator+=( const Cost &other ); 44 44 bool operator<( const Cost &other ) const; … … 55 55 static const Cost poly; 56 56 static const Cost safe; 57 static const Cost sign; 57 58 static const Cost var; 58 59 static const Cost spec; … … 63 64 int polyCost; ///< Count of parameters and return values bound to some poly type 64 65 int safeCost; ///< Safe (widening) conversions 66 int signCost; ///< Count of safe sign conversions 65 67 int varCost; ///< Count of polymorphic type variables 66 68 int specCost; ///< Polymorphic type specializations (type assertions), negative cost … … 68 70 }; 69 71 70 inline Cost::Cost( int unsafeCost, int polyCost, int safeCost, int varCost, int specCost,71 int referenceCost )72 : unsafeCost( unsafeCost ), polyCost( polyCost ), safeCost( safeCost ), varCost( varCost ),73 specCost( specCost ), referenceCost( referenceCost ) {}72 inline Cost::Cost( int unsafeCost, int polyCost, int safeCost, int signCost, 73 int varCost, int specCost, int referenceCost ) 74 : unsafeCost( unsafeCost ), polyCost( polyCost ), safeCost( safeCost ), signCost( signCost ), 75 varCost( varCost ), specCost( specCost ), referenceCost( referenceCost ) {} 74 76 75 77 inline Cost & Cost::incUnsafe( int inc ) { … … 88 90 if ( *this == infinity ) return *this; 89 91 safeCost += inc; 92 return *this; 93 } 94 95 inline Cost & Cost::incSign( int inc ) { 96 if ( *this == infinity ) return *this; 97 signCost += inc; 90 98 return *this; 91 99 } … … 111 119 inline Cost Cost::operator+( const Cost &other ) const { 112 120 if ( *this == infinity || other == infinity ) return infinity; 113 return Cost{ 114 unsafeCost + other.unsafeCost, polyCost + other.polyCost, safeCost + other.safeCost, 115 varCost + other.varCost, specCost + other.specCost,121 return Cost{ 122 unsafeCost + other.unsafeCost, polyCost + other.polyCost, safeCost + other.safeCost, 123 signCost + other.signCost, varCost + other.varCost, specCost + other.specCost, 116 124 referenceCost + other.referenceCost }; 117 }118 119 inline Cost Cost::operator-( const Cost &other ) const {120 if ( *this == infinity || other == infinity ) return infinity;121 return Cost{122 unsafeCost - other.unsafeCost, polyCost - other.polyCost, safeCost - other.safeCost,123 varCost - other.varCost, specCost - other.specCost,124 referenceCost - other.referenceCost };125 125 } 126 126 … … 134 134 polyCost += other.polyCost; 135 135 safeCost += other.safeCost; 136 signCost += other.signCost; 136 137 varCost += other.varCost; 137 138 specCost += other.specCost; … … 156 157 } else if ( safeCost < other.safeCost ) { 157 158 return true; 159 } else if ( signCost > other.signCost ) { 160 return false; 161 } else if ( signCost < other.signCost ) { 162 return true; 158 163 } else if ( varCost > other.varCost ) { 159 164 return false; … … 180 185 c = polyCost - other.polyCost; if ( c ) return c; 181 186 c = safeCost - other.safeCost; if ( c ) return c; 187 c = signCost - other.signCost; if ( c ) return c; 182 188 c = varCost - other.varCost; if ( c ) return c; 183 189 c = specCost - other.specCost; if ( c ) return c; … … 189 195 && polyCost == other.polyCost 190 196 && safeCost == other.safeCost 197 && signCost == other.signCost 191 198 && varCost == other.varCost 192 199 && specCost == other.specCost … … 199 206 200 207 inline std::ostream &operator<<( std::ostream &os, const Cost &cost ) { 201 return os << "( " << cost.unsafeCost << ", " << cost.polyCost << ", " 202 << cost.safeCost << ", " << cost.varCost << ", " << cost.specCost << ", " 208 return os << "( " << cost.unsafeCost << ", " << cost.polyCost << ", " 209 << cost.safeCost << ", " << cost.signCost << ", " 210 << cost.varCost << ", " << cost.specCost << ", " 203 211 << cost.referenceCost << " )"; 204 212 }
Note:
See TracChangeset
for help on using the changeset viewer.