OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/hydrogen.h" | 5 #include "src/hydrogen.h" |
6 | 6 |
7 #include <sstream> | 7 #include <sstream> |
8 | 8 |
9 #include "src/v8.h" | 9 #include "src/v8.h" |
10 | 10 |
(...skipping 8312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8323 | 8323 |
8324 | 8324 |
8325 bool HOptimizedGraphBuilder::TryInlineBuiltinFunctionCall(Call* expr) { | 8325 bool HOptimizedGraphBuilder::TryInlineBuiltinFunctionCall(Call* expr) { |
8326 if (!expr->target()->shared()->HasBuiltinFunctionId()) return false; | 8326 if (!expr->target()->shared()->HasBuiltinFunctionId()) return false; |
8327 BuiltinFunctionId id = expr->target()->shared()->builtin_function_id(); | 8327 BuiltinFunctionId id = expr->target()->shared()->builtin_function_id(); |
8328 switch (id) { | 8328 switch (id) { |
8329 case kMathExp: | 8329 case kMathExp: |
8330 if (!FLAG_fast_math) break; | 8330 if (!FLAG_fast_math) break; |
8331 // Fall through if FLAG_fast_math. | 8331 // Fall through if FLAG_fast_math. |
8332 case kMathRound: | 8332 case kMathRound: |
| 8333 case kMathFloor: |
| 8334 // If round has seen minus zero, don't inline, since that assumes |
| 8335 // returned value is an integer, which -0 definitely is not. |
| 8336 if (expr->ShouldHandleMinusZeroResult()) { |
| 8337 break; |
| 8338 } |
8333 case kMathFround: | 8339 case kMathFround: |
8334 case kMathFloor: | |
8335 case kMathAbs: | 8340 case kMathAbs: |
8336 case kMathSqrt: | 8341 case kMathSqrt: |
8337 case kMathLog: | 8342 case kMathLog: |
8338 case kMathClz32: | 8343 case kMathClz32: |
8339 if (expr->arguments()->length() == 1) { | 8344 if (expr->arguments()->length() == 1) { |
8340 HValue* argument = Pop(); | 8345 HValue* argument = Pop(); |
8341 Drop(2); // Receiver and function. | 8346 Drop(2); // Receiver and function. |
8342 HInstruction* op = NewUncasted<HUnaryMathOperation>(argument, id); | 8347 HInstruction* op = NewUncasted<HUnaryMathOperation>(argument, id); |
8343 ast_context()->ReturnInstruction(op, expr->id()); | 8348 ast_context()->ReturnInstruction(op, expr->id()); |
8344 return true; | 8349 return true; |
8345 } | 8350 } |
8346 break; | 8351 break; |
| 8352 case kMathCeil: |
| 8353 // If round/floor has seen minus zero, don't inline, since that assumes |
| 8354 // returned value is an integer, which -0 definitely is not. |
| 8355 if (expr->ShouldHandleMinusZeroResult()) { |
| 8356 break; |
| 8357 } |
| 8358 if (expr->arguments()->length() == 1) { |
| 8359 HValue* argument = Pop(); |
| 8360 Drop(2); // Receiver and function. |
| 8361 HValue* op = NULL; |
| 8362 { |
| 8363 NoObservableSideEffectsScope s(this); |
| 8364 HValue* neg_arg = |
| 8365 AddUncasted<HMul>(graph()->GetConstantMinus1(), argument); |
| 8366 op = AddUncasted<HUnaryMathOperation>(neg_arg, kMathFloor); |
| 8367 } |
| 8368 HInstruction* neg_op = |
| 8369 NewUncasted<HMul>(graph()->GetConstantMinus1(), op); |
| 8370 ast_context()->ReturnInstruction(neg_op, expr->id()); |
| 8371 return true; |
| 8372 } |
| 8373 break; |
8347 case kMathImul: | 8374 case kMathImul: |
8348 if (expr->arguments()->length() == 2) { | 8375 if (expr->arguments()->length() == 2) { |
8349 HValue* right = Pop(); | 8376 HValue* right = Pop(); |
8350 HValue* left = Pop(); | 8377 HValue* left = Pop(); |
8351 Drop(2); // Receiver and function. | 8378 Drop(2); // Receiver and function. |
8352 HInstruction* op = | 8379 HInstruction* op = |
8353 HMul::NewImul(isolate(), zone(), context(), left, right); | 8380 HMul::NewImul(isolate(), zone(), context(), left, right); |
8354 ast_context()->ReturnInstruction(op, expr->id()); | 8381 ast_context()->ReturnInstruction(op, expr->id()); |
8355 return true; | 8382 return true; |
8356 } | 8383 } |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8430 Drop(2); // Receiver and function. | 8457 Drop(2); // Receiver and function. |
8431 HInstruction* result = NewUncasted<HStringCharFromCode>(argument); | 8458 HInstruction* result = NewUncasted<HStringCharFromCode>(argument); |
8432 ast_context()->ReturnInstruction(result, expr->id()); | 8459 ast_context()->ReturnInstruction(result, expr->id()); |
8433 return true; | 8460 return true; |
8434 } | 8461 } |
8435 break; | 8462 break; |
8436 case kMathExp: | 8463 case kMathExp: |
8437 if (!FLAG_fast_math) break; | 8464 if (!FLAG_fast_math) break; |
8438 // Fall through if FLAG_fast_math. | 8465 // Fall through if FLAG_fast_math. |
8439 case kMathRound: | 8466 case kMathRound: |
| 8467 case kMathFloor: |
| 8468 // If round/floor has seen minus zero, don't inline, since that assumes |
| 8469 // returned value is an integer, which -0 definitely is not. |
| 8470 if (expr->ShouldHandleMinusZeroResult()) { |
| 8471 break; |
| 8472 } |
8440 case kMathFround: | 8473 case kMathFround: |
8441 case kMathFloor: | |
8442 case kMathAbs: | 8474 case kMathAbs: |
8443 case kMathSqrt: | 8475 case kMathSqrt: |
8444 case kMathLog: | 8476 case kMathLog: |
8445 case kMathClz32: | 8477 case kMathClz32: |
8446 if (argument_count == 2) { | 8478 if (argument_count == 2) { |
8447 HValue* argument = Pop(); | 8479 HValue* argument = Pop(); |
8448 Drop(2); // Receiver and function. | 8480 Drop(2); // Receiver and function. |
8449 HInstruction* op = NewUncasted<HUnaryMathOperation>(argument, id); | 8481 HInstruction* op = NewUncasted<HUnaryMathOperation>(argument, id); |
8450 ast_context()->ReturnInstruction(op, expr->id()); | 8482 ast_context()->ReturnInstruction(op, expr->id()); |
8451 return true; | 8483 return true; |
8452 } | 8484 } |
8453 break; | 8485 break; |
| 8486 case kMathCeil: |
| 8487 // If round/floor has seen minus zero, don't inline, since that assumes |
| 8488 // returned value is an integer, which -0 definitely is not. |
| 8489 if (expr->ShouldHandleMinusZeroResult()) { |
| 8490 break; |
| 8491 } |
| 8492 if (argument_count == 2) { |
| 8493 HValue* argument = Pop(); |
| 8494 Drop(2); // Receiver and function. |
| 8495 HValue* op = NULL; |
| 8496 { |
| 8497 NoObservableSideEffectsScope s(this); |
| 8498 HValue* neg_arg = |
| 8499 AddUncasted<HMul>(graph()->GetConstantMinus1(), argument); |
| 8500 op = AddUncasted<HUnaryMathOperation>(neg_arg, kMathFloor); |
| 8501 } |
| 8502 HInstruction* neg_op = |
| 8503 NewUncasted<HMul>(graph()->GetConstantMinus1(), op); |
| 8504 ast_context()->ReturnInstruction(neg_op, expr->id()); |
| 8505 return true; |
| 8506 } |
| 8507 break; |
8454 case kMathPow: | 8508 case kMathPow: |
8455 if (argument_count == 3) { | 8509 if (argument_count == 3) { |
8456 HValue* right = Pop(); | 8510 HValue* right = Pop(); |
8457 HValue* left = Pop(); | 8511 HValue* left = Pop(); |
8458 Drop(2); // Receiver and function. | 8512 Drop(2); // Receiver and function. |
8459 HInstruction* result = NULL; | 8513 HInstruction* result = NULL; |
8460 // Use sqrt() if exponent is 0.5 or -0.5. | 8514 // Use sqrt() if exponent is 0.5 or -0.5. |
8461 if (right->IsConstant() && HConstant::cast(right)->HasDoubleValue()) { | 8515 if (right->IsConstant() && HConstant::cast(right)->HasDoubleValue()) { |
8462 double exponent = HConstant::cast(right)->DoubleValue(); | 8516 double exponent = HConstant::cast(right)->DoubleValue(); |
8463 if (exponent == 0.5) { | 8517 if (exponent == 0.5) { |
(...skipping 3715 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12179 | 12233 |
12180 void HOptimizedGraphBuilder::GenerateMathClz32(CallRuntime* call) { | 12234 void HOptimizedGraphBuilder::GenerateMathClz32(CallRuntime* call) { |
12181 DCHECK(call->arguments()->length() == 1); | 12235 DCHECK(call->arguments()->length() == 1); |
12182 CHECK_ALIVE(VisitForValue(call->arguments()->at(0))); | 12236 CHECK_ALIVE(VisitForValue(call->arguments()->at(0))); |
12183 HValue* value = Pop(); | 12237 HValue* value = Pop(); |
12184 HInstruction* result = NewUncasted<HUnaryMathOperation>(value, kMathClz32); | 12238 HInstruction* result = NewUncasted<HUnaryMathOperation>(value, kMathClz32); |
12185 return ast_context()->ReturnInstruction(result, call->id()); | 12239 return ast_context()->ReturnInstruction(result, call->id()); |
12186 } | 12240 } |
12187 | 12241 |
12188 | 12242 |
12189 void HOptimizedGraphBuilder::GenerateMathFloor(CallRuntime* call) { | |
12190 DCHECK(call->arguments()->length() == 1); | |
12191 CHECK_ALIVE(VisitForValue(call->arguments()->at(0))); | |
12192 HValue* value = Pop(); | |
12193 HInstruction* result = NewUncasted<HUnaryMathOperation>(value, kMathFloor); | |
12194 return ast_context()->ReturnInstruction(result, call->id()); | |
12195 } | |
12196 | |
12197 | |
12198 void HOptimizedGraphBuilder::GenerateMathLogRT(CallRuntime* call) { | 12243 void HOptimizedGraphBuilder::GenerateMathLogRT(CallRuntime* call) { |
12199 DCHECK(call->arguments()->length() == 1); | 12244 DCHECK(call->arguments()->length() == 1); |
12200 CHECK_ALIVE(VisitForValue(call->arguments()->at(0))); | 12245 CHECK_ALIVE(VisitForValue(call->arguments()->at(0))); |
12201 HValue* value = Pop(); | 12246 HValue* value = Pop(); |
12202 HInstruction* result = NewUncasted<HUnaryMathOperation>(value, kMathLog); | 12247 HInstruction* result = NewUncasted<HUnaryMathOperation>(value, kMathLog); |
12203 return ast_context()->ReturnInstruction(result, call->id()); | 12248 return ast_context()->ReturnInstruction(result, call->id()); |
12204 } | 12249 } |
12205 | 12250 |
12206 | 12251 |
12207 void HOptimizedGraphBuilder::GenerateMathSqrt(CallRuntime* call) { | 12252 void HOptimizedGraphBuilder::GenerateMathSqrt(CallRuntime* call) { |
(...skipping 898 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13106 if (ShouldProduceTraceOutput()) { | 13151 if (ShouldProduceTraceOutput()) { |
13107 isolate()->GetHTracer()->TraceHydrogen(name(), graph_); | 13152 isolate()->GetHTracer()->TraceHydrogen(name(), graph_); |
13108 } | 13153 } |
13109 | 13154 |
13110 #ifdef DEBUG | 13155 #ifdef DEBUG |
13111 graph_->Verify(false); // No full verify. | 13156 graph_->Verify(false); // No full verify. |
13112 #endif | 13157 #endif |
13113 } | 13158 } |
13114 | 13159 |
13115 } } // namespace v8::internal | 13160 } } // namespace v8::internal |
OLD | NEW |