| 203 | } |
| 204 | |
| 205 | ExpressionClasses::Id ExpressionClasses::tryToSimplify(Expression const& _expr) |
| 206 | { |
| 207 | static Rules rules; |
| 208 | assertThrow(rules.isInitialized(), OptimizerException, "Rule list not properly initialized."); |
| 209 | |
| 210 | if ( |
| 211 | !_expr.item || |
| 212 | _expr.item->type() != Operation || |
| 213 | !SemanticInformation::isDeterministic(*_expr.item) |
| 214 | ) |
| 215 | return std::numeric_limits<unsigned>::max(); |
| 216 | |
| 217 | if (auto match = rules.findFirstMatch(_expr, *this)) |
| 218 | { |
| 219 | // Debug info |
| 220 | if (false) |
| 221 | { |
| 222 | std::cout << "Simplifying " << *_expr.item << "("; |
| 223 | for (Id arg: _expr.arguments) |
| 224 | std::cout << fullDAGToString(arg) << ", "; |
| 225 | std::cout << ")" << std::endl; |
| 226 | std::cout << "with rule " << match->pattern.toString() << std::endl; |
| 227 | std::cout << "to " << match->action().toString() << std::endl; |
| 228 | } |
| 229 | |
| 230 | return rebuildExpression(ExpressionTemplate(match->action(), _expr.item->debugData())); |
| 231 | } |
| 232 | |
| 233 | return std::numeric_limits<unsigned>::max(); |
| 234 | } |
| 235 | |
| 236 | ExpressionClasses::Id ExpressionClasses::rebuildExpression(ExpressionTemplate const& _template) |
| 237 | { |
nothing calls this directly
no test coverage detected