Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(477)

Side by Side Diff: src/code-stubs-hydrogen.cc

Issue 1114563003: Optimize the typeof operator. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Ports. Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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/v8.h" 5 #include "src/v8.h"
6 6
7 #include "src/bailout-reason.h" 7 #include "src/bailout-reason.h"
8 #include "src/code-stubs.h" 8 #include "src/code-stubs.h"
9 #include "src/field-index.h" 9 #include "src/field-index.h"
10 #include "src/hydrogen.h" 10 #include "src/hydrogen.h"
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 HValue* number = GetParameter(NumberToStringStub::kNumber); 292 HValue* number = GetParameter(NumberToStringStub::kNumber);
293 return BuildNumberToString(number, Type::Number(zone())); 293 return BuildNumberToString(number, Type::Number(zone()));
294 } 294 }
295 295
296 296
297 Handle<Code> NumberToStringStub::GenerateCode() { 297 Handle<Code> NumberToStringStub::GenerateCode() {
298 return DoGenerateCode(this); 298 return DoGenerateCode(this);
299 } 299 }
300 300
301 301
302 // Returns the type string of a value; see ECMA-262, 11.4.3 (p 47).
303 // Possible optimizations: put the type string into the oddballs.
304 template <>
305 HValue* CodeStubGraphBuilder<TypeofStub>::BuildCodeStub() {
306 Factory* factory = isolate()->factory();
307 HConstant* number_string = Add<HConstant>(factory->number_string());
308 HValue* object = GetParameter(TypeofStub::kObject);
309
310 IfBuilder is_smi(this);
311 HValue* smi_check = is_smi.If<HIsSmiAndBranch>(object);
312 is_smi.Then();
313 { Push(number_string); }
314 is_smi.Else();
315 {
316 HValue* map = AddLoadMap(object, smi_check);
317 HConstant* number_map =
318 Add<HConstant>(isolate()->factory()->heap_number_map());
319 IfBuilder is_number(this);
320 is_number.If<HCompareObjectEqAndBranch>(map, number_map);
321 is_number.Then();
322 { Push(number_string); }
323 is_number.Else();
324 {
325 // Is it an undetectable object?
326 HConstant* undefined_string = Add<HConstant>(factory->undefined_string());
327 HValue* bit_field =
328 Add<HLoadNamedField>(map, nullptr, HObjectAccess::ForMapBitField());
329 HValue* is_undetectable_mask = Add<HConstant>(1 << Map::kIsUndetectable);
330 HValue* is_undetectable_test = AddUncasted<HBitwise>(
331 Token::BIT_AND, bit_field, is_undetectable_mask);
332 IfBuilder is_undetectable(this);
333 is_undetectable.If<HCompareNumericAndBranch>(
334 is_undetectable_test, graph()->GetConstant0(), Token::NE);
335 is_undetectable.Then();
336 {
337 // typeof an undetectable object is 'undefined'.
338 Push(undefined_string);
339 }
340 is_undetectable.Else();
341 {
342 HValue* instance_type = Add<HLoadNamedField>(
343 map, nullptr, HObjectAccess::ForMapInstanceType());
344 IfBuilder is_string(this);
345 is_string.If<HCompareNumericAndBranch>(
346 instance_type, Add<HConstant>(FIRST_NONSTRING_TYPE), Token::LT);
347 is_string.Then();
348 { Push(Add<HConstant>(factory->string_string())); }
349 is_string.Else();
350
351 HConstant* object_string = Add<HConstant>(factory->object_string());
352 IfBuilder is_oddball(this);
353 is_oddball.If<HCompareNumericAndBranch>(
354 instance_type, Add<HConstant>(ODDBALL_TYPE), Token::EQ);
355 is_oddball.Then();
356 {
357 IfBuilder is_true_or_false(this);
358 is_true_or_false.If<HCompareObjectEqAndBranch>(
359 object, graph()->GetConstantTrue());
360 is_true_or_false.OrIf<HCompareObjectEqAndBranch>(
361 object, graph()->GetConstantFalse());
362 is_true_or_false.Then();
363 { Push(Add<HConstant>(factory->boolean_string())); }
364 is_true_or_false.Else();
365 {
366 IfBuilder is_null(this);
367 is_null.If<HCompareObjectEqAndBranch>(object,
368 graph()->GetConstantNull());
369 is_null.Then();
370 { Push(object_string); }
371 is_null.Else();
372 { Push(undefined_string); }
373 }
374 is_true_or_false.End();
375 }
376 is_oddball.Else();
377 {
378 IfBuilder is_symbol(this);
379 is_symbol.If<HCompareNumericAndBranch>(
380 instance_type, Add<HConstant>(SYMBOL_TYPE), Token::EQ);
381 is_symbol.Then();
382 { Push(Add<HConstant>(factory->symbol_string())); }
383 is_symbol.Else();
384 {
385 IfBuilder is_function(this);
386 HConstant* js_function = Add<HConstant>(JS_FUNCTION_TYPE);
387 HConstant* js_function_proxy =
388 Add<HConstant>(JS_FUNCTION_PROXY_TYPE);
389 is_function.If<HCompareNumericAndBranch>(instance_type, js_function,
390 Token::EQ);
391 is_function.OrIf<HCompareNumericAndBranch>(
392 instance_type, js_function_proxy, Token::EQ);
393 is_function.Then();
394 { Push(Add<HConstant>(factory->function_string())); }
395 is_function.Else();
396 {
397 // For any kind of object not handled above, the spec rule for
398 // host objects gives that it is okay to return "object".
399 Push(object_string);
400 }
401 is_function.End();
402 }
403 is_symbol.End();
404 }
405 is_oddball.End();
406 is_string.End();
407 }
408 is_undetectable.End();
409 }
410 is_number.End();
411 }
412 is_smi.End();
413
414 return environment()->Pop();
415 }
416
417
418 Handle<Code> TypeofStub::GenerateCode() { return DoGenerateCode(this); }
419
420
302 template <> 421 template <>
303 HValue* CodeStubGraphBuilder<FastCloneShallowArrayStub>::BuildCodeStub() { 422 HValue* CodeStubGraphBuilder<FastCloneShallowArrayStub>::BuildCodeStub() {
304 Factory* factory = isolate()->factory(); 423 Factory* factory = isolate()->factory();
305 HValue* undefined = graph()->GetConstantUndefined(); 424 HValue* undefined = graph()->GetConstantUndefined();
306 AllocationSiteMode alloc_site_mode = casted_stub()->allocation_site_mode(); 425 AllocationSiteMode alloc_site_mode = casted_stub()->allocation_site_mode();
307 426
308 // This stub is very performance sensitive, the generated code must be tuned 427 // This stub is very performance sensitive, the generated code must be tuned
309 // so that it doesn't build and eager frame. 428 // so that it doesn't build and eager frame.
310 info()->MarkMustNotHaveEagerFrame(); 429 info()->MarkMustNotHaveEagerFrame();
311 430
(...skipping 1737 matching lines...) Expand 10 before | Expand all | Expand 10 after
2049 // need. 2168 // need.
2050 info()->MarkMustNotHaveEagerFrame(); 2169 info()->MarkMustNotHaveEagerFrame();
2051 2170
2052 // Probe the stub cache. 2171 // Probe the stub cache.
2053 Add<HTailCallThroughMegamorphicCache>(receiver, name); 2172 Add<HTailCallThroughMegamorphicCache>(receiver, name);
2054 2173
2055 // We never continue. 2174 // We never continue.
2056 return graph()->GetConstant0(); 2175 return graph()->GetConstant0();
2057 } 2176 }
2058 } } // namespace v8::internal 2177 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698