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 8199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8210 | 8210 |
8211 | 8211 |
8212 bool HOptimizedGraphBuilder::TryInlineBuiltinFunctionCall(Call* expr) { | 8212 bool HOptimizedGraphBuilder::TryInlineBuiltinFunctionCall(Call* expr) { |
8213 if (!expr->target()->shared()->HasBuiltinFunctionId()) return false; | 8213 if (!expr->target()->shared()->HasBuiltinFunctionId()) return false; |
8214 BuiltinFunctionId id = expr->target()->shared()->builtin_function_id(); | 8214 BuiltinFunctionId id = expr->target()->shared()->builtin_function_id(); |
8215 switch (id) { | 8215 switch (id) { |
8216 case kMathExp: | 8216 case kMathExp: |
8217 if (!FLAG_fast_math) break; | 8217 if (!FLAG_fast_math) break; |
8218 // Fall through if FLAG_fast_math. | 8218 // Fall through if FLAG_fast_math. |
8219 case kMathRound: | 8219 case kMathRound: |
| 8220 case kMathFloor: |
| 8221 // If round has seen minus zero, don't inline, since that assumes |
| 8222 // returned value is an integer, which -0 definitely is not. |
| 8223 if (expr->ShouldHandleMinusZeroResult()) { |
| 8224 break; |
| 8225 } |
8220 case kMathFround: | 8226 case kMathFround: |
8221 case kMathFloor: | |
8222 case kMathAbs: | 8227 case kMathAbs: |
8223 case kMathSqrt: | 8228 case kMathSqrt: |
8224 case kMathLog: | 8229 case kMathLog: |
8225 case kMathClz32: | 8230 case kMathClz32: |
8226 if (expr->arguments()->length() == 1) { | 8231 if (expr->arguments()->length() == 1) { |
8227 HValue* argument = Pop(); | 8232 HValue* argument = Pop(); |
8228 Drop(2); // Receiver and function. | 8233 Drop(2); // Receiver and function. |
8229 HInstruction* op = NewUncasted<HUnaryMathOperation>(argument, id); | 8234 HInstruction* op = NewUncasted<HUnaryMathOperation>(argument, id); |
8230 ast_context()->ReturnInstruction(op, expr->id()); | 8235 ast_context()->ReturnInstruction(op, expr->id()); |
8231 return true; | 8236 return true; |
8232 } | 8237 } |
8233 break; | 8238 break; |
| 8239 case kMathCeil: |
| 8240 // If round/floor has seen minus zero, don't inline, since that assumes |
| 8241 // returned value is an integer, which -0 definitely is not. |
| 8242 if (expr->ShouldHandleMinusZeroResult()) { |
| 8243 break; |
| 8244 } |
| 8245 if (expr->arguments()->length() == 1) { |
| 8246 HValue* argument = Pop(); |
| 8247 Drop(2); // Receiver and function. |
| 8248 HValue* neg_arg = |
| 8249 AddUncasted<HMul>(graph()->GetConstantMinus1(), argument); |
| 8250 HValue* op = AddUncasted<HUnaryMathOperation>(neg_arg, kMathFloor); |
| 8251 HInstruction* neg_op = |
| 8252 NewUncasted<HMul>(graph()->GetConstantMinus1(), op); |
| 8253 ast_context()->ReturnInstruction(neg_op, expr->id()); |
| 8254 return true; |
| 8255 } |
| 8256 break; |
8234 case kMathImul: | 8257 case kMathImul: |
8235 if (expr->arguments()->length() == 2) { | 8258 if (expr->arguments()->length() == 2) { |
8236 HValue* right = Pop(); | 8259 HValue* right = Pop(); |
8237 HValue* left = Pop(); | 8260 HValue* left = Pop(); |
8238 Drop(2); // Receiver and function. | 8261 Drop(2); // Receiver and function. |
8239 HInstruction* op = | 8262 HInstruction* op = |
8240 HMul::NewImul(isolate(), zone(), context(), left, right); | 8263 HMul::NewImul(isolate(), zone(), context(), left, right); |
8241 ast_context()->ReturnInstruction(op, expr->id()); | 8264 ast_context()->ReturnInstruction(op, expr->id()); |
8242 return true; | 8265 return true; |
8243 } | 8266 } |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8317 Drop(2); // Receiver and function. | 8340 Drop(2); // Receiver and function. |
8318 HInstruction* result = NewUncasted<HStringCharFromCode>(argument); | 8341 HInstruction* result = NewUncasted<HStringCharFromCode>(argument); |
8319 ast_context()->ReturnInstruction(result, expr->id()); | 8342 ast_context()->ReturnInstruction(result, expr->id()); |
8320 return true; | 8343 return true; |
8321 } | 8344 } |
8322 break; | 8345 break; |
8323 case kMathExp: | 8346 case kMathExp: |
8324 if (!FLAG_fast_math) break; | 8347 if (!FLAG_fast_math) break; |
8325 // Fall through if FLAG_fast_math. | 8348 // Fall through if FLAG_fast_math. |
8326 case kMathRound: | 8349 case kMathRound: |
| 8350 case kMathFloor: |
| 8351 // If round/floor has seen minus zero, don't inline, since that assumes |
| 8352 // returned value is an integer, which -0 definitely is not. |
| 8353 if (expr->ShouldHandleMinusZeroResult()) { |
| 8354 break; |
| 8355 } |
8327 case kMathFround: | 8356 case kMathFround: |
8328 case kMathFloor: | |
8329 case kMathAbs: | 8357 case kMathAbs: |
8330 case kMathSqrt: | 8358 case kMathSqrt: |
8331 case kMathLog: | 8359 case kMathLog: |
8332 case kMathClz32: | 8360 case kMathClz32: |
8333 if (argument_count == 2) { | 8361 if (argument_count == 2) { |
8334 HValue* argument = Pop(); | 8362 HValue* argument = Pop(); |
8335 Drop(2); // Receiver and function. | 8363 Drop(2); // Receiver and function. |
8336 HInstruction* op = NewUncasted<HUnaryMathOperation>(argument, id); | 8364 HInstruction* op = NewUncasted<HUnaryMathOperation>(argument, id); |
8337 ast_context()->ReturnInstruction(op, expr->id()); | 8365 ast_context()->ReturnInstruction(op, expr->id()); |
8338 return true; | 8366 return true; |
8339 } | 8367 } |
8340 break; | 8368 break; |
| 8369 case kMathCeil: |
| 8370 // If round/floor has seen minus zero, don't inline, since that assumes |
| 8371 // returned value is an integer, which -0 definitely is not. |
| 8372 if (expr->ShouldHandleMinusZeroResult()) { |
| 8373 break; |
| 8374 } |
| 8375 if (argument_count == 2) { |
| 8376 HValue* argument = Pop(); |
| 8377 Drop(2); // Receiver and function. |
| 8378 HValue* neg_arg = |
| 8379 AddUncasted<HMul>(graph()->GetConstantMinus1(), argument); |
| 8380 HValue* op = AddUncasted<HUnaryMathOperation>(neg_arg, kMathFloor); |
| 8381 HInstruction* neg_op = |
| 8382 NewUncasted<HMul>(graph()->GetConstantMinus1(), op); |
| 8383 ast_context()->ReturnInstruction(neg_op, expr->id()); |
| 8384 return true; |
| 8385 } |
| 8386 break; |
8341 case kMathPow: | 8387 case kMathPow: |
8342 if (argument_count == 3) { | 8388 if (argument_count == 3) { |
8343 HValue* right = Pop(); | 8389 HValue* right = Pop(); |
8344 HValue* left = Pop(); | 8390 HValue* left = Pop(); |
8345 Drop(2); // Receiver and function. | 8391 Drop(2); // Receiver and function. |
8346 HInstruction* result = NULL; | 8392 HInstruction* result = NULL; |
8347 // Use sqrt() if exponent is 0.5 or -0.5. | 8393 // Use sqrt() if exponent is 0.5 or -0.5. |
8348 if (right->IsConstant() && HConstant::cast(right)->HasDoubleValue()) { | 8394 if (right->IsConstant() && HConstant::cast(right)->HasDoubleValue()) { |
8349 double exponent = HConstant::cast(right)->DoubleValue(); | 8395 double exponent = HConstant::cast(right)->DoubleValue(); |
8350 if (exponent == 0.5) { | 8396 if (exponent == 0.5) { |
(...skipping 3716 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12067 | 12113 |
12068 void HOptimizedGraphBuilder::GenerateMathClz32(CallRuntime* call) { | 12114 void HOptimizedGraphBuilder::GenerateMathClz32(CallRuntime* call) { |
12069 DCHECK(call->arguments()->length() == 1); | 12115 DCHECK(call->arguments()->length() == 1); |
12070 CHECK_ALIVE(VisitForValue(call->arguments()->at(0))); | 12116 CHECK_ALIVE(VisitForValue(call->arguments()->at(0))); |
12071 HValue* value = Pop(); | 12117 HValue* value = Pop(); |
12072 HInstruction* result = NewUncasted<HUnaryMathOperation>(value, kMathClz32); | 12118 HInstruction* result = NewUncasted<HUnaryMathOperation>(value, kMathClz32); |
12073 return ast_context()->ReturnInstruction(result, call->id()); | 12119 return ast_context()->ReturnInstruction(result, call->id()); |
12074 } | 12120 } |
12075 | 12121 |
12076 | 12122 |
12077 void HOptimizedGraphBuilder::GenerateMathFloor(CallRuntime* call) { | |
12078 DCHECK(call->arguments()->length() == 1); | |
12079 CHECK_ALIVE(VisitForValue(call->arguments()->at(0))); | |
12080 HValue* value = Pop(); | |
12081 HInstruction* result = NewUncasted<HUnaryMathOperation>(value, kMathFloor); | |
12082 return ast_context()->ReturnInstruction(result, call->id()); | |
12083 } | |
12084 | |
12085 | |
12086 void HOptimizedGraphBuilder::GenerateMathLogRT(CallRuntime* call) { | 12123 void HOptimizedGraphBuilder::GenerateMathLogRT(CallRuntime* call) { |
12087 DCHECK(call->arguments()->length() == 1); | 12124 DCHECK(call->arguments()->length() == 1); |
12088 CHECK_ALIVE(VisitForValue(call->arguments()->at(0))); | 12125 CHECK_ALIVE(VisitForValue(call->arguments()->at(0))); |
12089 HValue* value = Pop(); | 12126 HValue* value = Pop(); |
12090 HInstruction* result = NewUncasted<HUnaryMathOperation>(value, kMathLog); | 12127 HInstruction* result = NewUncasted<HUnaryMathOperation>(value, kMathLog); |
12091 return ast_context()->ReturnInstruction(result, call->id()); | 12128 return ast_context()->ReturnInstruction(result, call->id()); |
12092 } | 12129 } |
12093 | 12130 |
12094 | 12131 |
12095 void HOptimizedGraphBuilder::GenerateMathSqrt(CallRuntime* call) { | 12132 void HOptimizedGraphBuilder::GenerateMathSqrt(CallRuntime* call) { |
(...skipping 898 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12994 if (ShouldProduceTraceOutput()) { | 13031 if (ShouldProduceTraceOutput()) { |
12995 isolate()->GetHTracer()->TraceHydrogen(name(), graph_); | 13032 isolate()->GetHTracer()->TraceHydrogen(name(), graph_); |
12996 } | 13033 } |
12997 | 13034 |
12998 #ifdef DEBUG | 13035 #ifdef DEBUG |
12999 graph_->Verify(false); // No full verify. | 13036 graph_->Verify(false); // No full verify. |
13000 #endif | 13037 #endif |
13001 } | 13038 } |
13002 | 13039 |
13003 } } // namespace v8::internal | 13040 } } // namespace v8::internal |
OLD | NEW |