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

Side by Side Diff: src/ic.cc

Issue 18712002: Convert UnaryOpStub to a HydrogenCodeStub (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: address review Created 7 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « src/ic.h ('k') | src/objects.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 2383 matching lines...) Expand 10 before | Expand all | Expand 10 after
2394 Code::ExtraICState extra_ic_state = ic.target()->extra_ic_state(); 2394 Code::ExtraICState extra_ic_state = ic.target()->extra_ic_state();
2395 return ic.Store(state, 2395 return ic.Store(state,
2396 Code::GetStrictMode(extra_ic_state), 2396 Code::GetStrictMode(extra_ic_state),
2397 args.at<Object>(0), 2397 args.at<Object>(0),
2398 args.at<Object>(1), 2398 args.at<Object>(1),
2399 args.at<Object>(2), 2399 args.at<Object>(2),
2400 MISS_FORCE_GENERIC); 2400 MISS_FORCE_GENERIC);
2401 } 2401 }
2402 2402
2403 2403
2404 void UnaryOpIC::patch(Code* code) {
2405 set_target(code);
2406 }
2407
2408
2409 const char* UnaryOpIC::GetName(TypeInfo type_info) {
2410 switch (type_info) {
2411 case UNINITIALIZED: return "Uninitialized";
2412 case SMI: return "Smi";
2413 case NUMBER: return "Number";
2414 case GENERIC: return "Generic";
2415 default: return "Invalid";
2416 }
2417 }
2418
2419
2420 UnaryOpIC::State UnaryOpIC::ToState(TypeInfo type_info) {
2421 switch (type_info) {
2422 case UNINITIALIZED:
2423 return v8::internal::UNINITIALIZED;
2424 case SMI:
2425 case NUMBER:
2426 return MONOMORPHIC;
2427 case GENERIC:
2428 return v8::internal::GENERIC;
2429 }
2430 UNREACHABLE();
2431 return v8::internal::UNINITIALIZED;
2432 }
2433
2434
2435 Handle<Type> UnaryOpIC::TypeInfoToType(TypeInfo type_info, Isolate* isolate) {
2436 switch (type_info) {
2437 case UNINITIALIZED:
2438 return handle(Type::None(), isolate);
2439 case SMI:
2440 return handle(Type::Smi(), isolate);
2441 case NUMBER:
2442 return handle(Type::Number(), isolate);
2443 case GENERIC:
2444 return handle(Type::Any(), isolate);
2445 }
2446 UNREACHABLE();
2447 return handle(Type::Any(), isolate);
2448 }
2449
2450
2451 UnaryOpIC::TypeInfo UnaryOpIC::GetTypeInfo(Handle<Object> operand) {
2452 v8::internal::TypeInfo operand_type =
2453 v8::internal::TypeInfo::FromValue(operand);
2454 if (operand_type.IsSmi()) {
2455 return SMI;
2456 } else if (operand_type.IsNumber()) {
2457 return NUMBER;
2458 } else {
2459 return GENERIC;
2460 }
2461 }
2462
2463
2464 UnaryOpIC::TypeInfo UnaryOpIC::ComputeNewType(
2465 TypeInfo current_type,
2466 TypeInfo previous_type) {
2467 switch (previous_type) {
2468 case UNINITIALIZED:
2469 return current_type;
2470 case SMI:
2471 return (current_type == GENERIC) ? GENERIC : NUMBER;
2472 case NUMBER:
2473 return GENERIC;
2474 case GENERIC:
2475 // We should never do patching if we are in GENERIC state.
2476 UNREACHABLE();
2477 return GENERIC;
2478 }
2479 UNREACHABLE();
2480 return GENERIC;
2481 }
2482
2483
2484 void BinaryOpIC::patch(Code* code) { 2404 void BinaryOpIC::patch(Code* code) {
2485 set_target(code); 2405 set_target(code);
2486 } 2406 }
2487 2407
2488 2408
2489 const char* BinaryOpIC::GetName(TypeInfo type_info) { 2409 const char* BinaryOpIC::GetName(TypeInfo type_info) {
2490 switch (type_info) { 2410 switch (type_info) {
2491 case UNINITIALIZED: return "Uninitialized"; 2411 case UNINITIALIZED: return "Uninitialized";
2492 case SMI: return "Smi"; 2412 case SMI: return "Smi";
2493 case INT32: return "Int32"; 2413 case INT32: return "Int32";
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
2551 Isolate* isolate) { 2471 Isolate* isolate) {
2552 TypeInfo left_typeinfo, right_typeinfo, result_typeinfo; 2472 TypeInfo left_typeinfo, right_typeinfo, result_typeinfo;
2553 BinaryOpStub::decode_types_from_minor_key( 2473 BinaryOpStub::decode_types_from_minor_key(
2554 minor_key, &left_typeinfo, &right_typeinfo, &result_typeinfo); 2474 minor_key, &left_typeinfo, &right_typeinfo, &result_typeinfo);
2555 *left = TypeInfoToType(left_typeinfo, isolate); 2475 *left = TypeInfoToType(left_typeinfo, isolate);
2556 *right = TypeInfoToType(right_typeinfo, isolate); 2476 *right = TypeInfoToType(right_typeinfo, isolate);
2557 *result = TypeInfoToType(result_typeinfo, isolate); 2477 *result = TypeInfoToType(result_typeinfo, isolate);
2558 } 2478 }
2559 2479
2560 2480
2561 RUNTIME_FUNCTION(MaybeObject*, UnaryOp_Patch) { 2481 MaybeObject* UnaryOpIC::Transition(Handle<Object> object) {
2562 ASSERT(args.length() == 4); 2482 Code::ExtraICState extra_ic_state = target()->extended_extra_ic_state();
2483 UnaryOpStub stub(extra_ic_state);
2563 2484
2564 HandleScope scope(isolate); 2485 stub.UpdateStatus(object);
2565 Handle<Object> operand = args.at<Object>(0);
2566 Token::Value op = static_cast<Token::Value>(args.smi_at(1));
2567 UnaryOverwriteMode mode = static_cast<UnaryOverwriteMode>(args.smi_at(2));
2568 UnaryOpIC::TypeInfo previous_type =
2569 static_cast<UnaryOpIC::TypeInfo>(args.smi_at(3));
2570 2486
2571 UnaryOpIC::TypeInfo type = UnaryOpIC::GetTypeInfo(operand); 2487 Handle<Code> code = stub.GetCode(isolate());
2572 type = UnaryOpIC::ComputeNewType(type, previous_type); 2488 set_target(*code);
2573 2489
2574 UnaryOpStub stub(op, mode, type); 2490 return stub.Result(object, isolate());
2575 Handle<Code> code = stub.GetCode(isolate);
2576 if (!code.is_null()) {
2577 if (FLAG_trace_ic) {
2578 PrintF("[UnaryOpIC in ");
2579 JavaScriptFrame::PrintTop(isolate, stdout, false, true);
2580 PrintF(" %s => %s #%s @ %p]\n",
2581 UnaryOpIC::GetName(previous_type),
2582 UnaryOpIC::GetName(type),
2583 Token::Name(op),
2584 static_cast<void*>(*code));
2585 }
2586 UnaryOpIC ic(isolate);
2587 ic.patch(*code);
2588 }
2589
2590 Handle<JSBuiltinsObject> builtins(isolate->js_builtins_object());
2591 Object* builtin = NULL; // Initialization calms down the compiler.
2592 switch (op) {
2593 case Token::SUB:
2594 builtin = builtins->javascript_builtin(Builtins::UNARY_MINUS);
2595 break;
2596 case Token::BIT_NOT:
2597 builtin = builtins->javascript_builtin(Builtins::BIT_NOT);
2598 break;
2599 default:
2600 UNREACHABLE();
2601 }
2602
2603 Handle<JSFunction> builtin_function(JSFunction::cast(builtin), isolate);
2604
2605 bool caught_exception;
2606 Handle<Object> result = Execution::Call(builtin_function, operand, 0, NULL,
2607 &caught_exception);
2608 if (caught_exception) {
2609 return Failure::Exception();
2610 }
2611 return *result;
2612 } 2491 }
2613 2492
2614 2493
2494 RUNTIME_FUNCTION(MaybeObject*, UnaryOpIC_Miss) {
2495 HandleScope scope(isolate);
2496 Handle<Object> object = args.at<Object>(0);
2497 UnaryOpIC ic(isolate);
2498 return ic.Transition(object);
2499 }
2500
2501
2615 static BinaryOpIC::TypeInfo TypeInfoFromValue(Handle<Object> value, 2502 static BinaryOpIC::TypeInfo TypeInfoFromValue(Handle<Object> value,
2616 Token::Value op) { 2503 Token::Value op) {
2617 v8::internal::TypeInfo type = v8::internal::TypeInfo::FromValue(value); 2504 v8::internal::TypeInfo type = v8::internal::TypeInfo::FromValue(value);
2618 if (type.IsSmi()) return BinaryOpIC::SMI; 2505 if (type.IsSmi()) return BinaryOpIC::SMI;
2619 if (type.IsInteger32()) { 2506 if (type.IsInteger32()) {
2620 if (kSmiValueSize == 32) return BinaryOpIC::SMI; 2507 if (kSmiValueSize == 32) return BinaryOpIC::SMI;
2621 return BinaryOpIC::INT32; 2508 return BinaryOpIC::INT32;
2622 } 2509 }
2623 if (type.IsNumber()) return BinaryOpIC::NUMBER; 2510 if (type.IsNumber()) return BinaryOpIC::NUMBER;
2624 if (type.IsString()) return BinaryOpIC::STRING; 2511 if (type.IsString()) return BinaryOpIC::STRING;
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after
3062 2949
3063 MaybeObject* CompareNilIC::CompareNil(Handle<Object> object) { 2950 MaybeObject* CompareNilIC::CompareNil(Handle<Object> object) {
3064 Code::ExtraICState extra_ic_state = target()->extended_extra_ic_state(); 2951 Code::ExtraICState extra_ic_state = target()->extended_extra_ic_state();
3065 2952
3066 CompareNilICStub stub(extra_ic_state); 2953 CompareNilICStub stub(extra_ic_state);
3067 2954
3068 // Extract the current supported types from the patched IC and calculate what 2955 // Extract the current supported types from the patched IC and calculate what
3069 // types must be supported as a result of the miss. 2956 // types must be supported as a result of the miss.
3070 bool already_monomorphic = stub.IsMonomorphic(); 2957 bool already_monomorphic = stub.IsMonomorphic();
3071 2958
3072 CompareNilICStub::State old_state = stub.GetState(); 2959 stub.UpdateStatus(object);
3073 stub.Record(object);
3074 old_state.TraceTransition(stub.GetState());
3075 2960
3076 NilValue nil = stub.GetNilValue(); 2961 NilValue nil = stub.GetNilValue();
3077 2962
3078 // Find or create the specialized stub to support the new set of types. 2963 // Find or create the specialized stub to support the new set of types.
3079 Handle<Code> code; 2964 Handle<Code> code;
3080 if (stub.IsMonomorphic()) { 2965 if (stub.IsMonomorphic()) {
3081 Handle<Map> monomorphic_map(already_monomorphic 2966 Handle<Map> monomorphic_map(already_monomorphic
3082 ? target()->FindFirstMap() 2967 ? target()->FindFirstMap()
3083 : HeapObject::cast(*object)->map()); 2968 : HeapObject::cast(*object)->map());
3084 code = isolate()->stub_cache()->ComputeCompareNil(monomorphic_map, stub); 2969 code = isolate()->stub_cache()->ComputeCompareNil(monomorphic_map, stub);
(...skipping 16 matching lines...) Expand all
3101 RUNTIME_FUNCTION(MaybeObject*, Unreachable) { 2986 RUNTIME_FUNCTION(MaybeObject*, Unreachable) {
3102 UNREACHABLE(); 2987 UNREACHABLE();
3103 CHECK(false); 2988 CHECK(false);
3104 return isolate->heap()->undefined_value(); 2989 return isolate->heap()->undefined_value();
3105 } 2990 }
3106 2991
3107 2992
3108 MaybeObject* ToBooleanIC::ToBoolean(Handle<Object> object, 2993 MaybeObject* ToBooleanIC::ToBoolean(Handle<Object> object,
3109 Code::ExtraICState extra_ic_state) { 2994 Code::ExtraICState extra_ic_state) {
3110 ToBooleanStub stub(extra_ic_state); 2995 ToBooleanStub stub(extra_ic_state);
3111 bool to_boolean_value = stub.Record(object); 2996 bool to_boolean_value = stub.UpdateStatus(object);
3112 Handle<Code> code = stub.GetCode(isolate()); 2997 Handle<Code> code = stub.GetCode(isolate());
3113 set_target(*code); 2998 set_target(*code);
3114 return Smi::FromInt(to_boolean_value ? 1 : 0); 2999 return Smi::FromInt(to_boolean_value ? 1 : 0);
3115 } 3000 }
3116 3001
3117 3002
3118 RUNTIME_FUNCTION(MaybeObject*, ToBooleanIC_Miss) { 3003 RUNTIME_FUNCTION(MaybeObject*, ToBooleanIC_Miss) {
3119 ASSERT(args.length() == 1); 3004 ASSERT(args.length() == 1);
3120 HandleScope scope(isolate); 3005 HandleScope scope(isolate);
3121 Handle<Object> object = args.at<Object>(0); 3006 Handle<Object> object = args.at<Object>(0);
(...skipping 10 matching lines...) Expand all
3132 #undef ADDR 3017 #undef ADDR
3133 }; 3018 };
3134 3019
3135 3020
3136 Address IC::AddressFromUtilityId(IC::UtilityId id) { 3021 Address IC::AddressFromUtilityId(IC::UtilityId id) {
3137 return IC_utilities[id]; 3022 return IC_utilities[id];
3138 } 3023 }
3139 3024
3140 3025
3141 } } // namespace v8::internal 3026 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/ic.h ('k') | src/objects.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698