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

Side by Side Diff: src/hydrogen-instructions.cc

Issue 174863002: Implement KnownSuccessor method to some control instructions. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 9 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/hydrogen-instructions.h ('k') | src/objects-inl.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 1197 matching lines...) Expand 10 before | Expand all | Expand 10 after
1208 if (to_ == JS_FUNCTION_TYPE) stream->Add(" function"); 1208 if (to_ == JS_FUNCTION_TYPE) stream->Add(" function");
1209 break; 1209 break;
1210 default: 1210 default:
1211 break; 1211 break;
1212 } 1212 }
1213 } 1213 }
1214 1214
1215 1215
1216 void HTypeofIsAndBranch::PrintDataTo(StringStream* stream) { 1216 void HTypeofIsAndBranch::PrintDataTo(StringStream* stream) {
1217 value()->PrintNameTo(stream); 1217 value()->PrintNameTo(stream);
1218 stream->Add(" == %o", *type_literal_); 1218 stream->Add(" == %o", *type_literal_.handle());
1219 HControlInstruction::PrintDataTo(stream); 1219 HControlInstruction::PrintDataTo(stream);
1220 } 1220 }
1221 1221
1222 1222
1223 static String* TypeOfString(HConstant* constant, Isolate* isolate) {
1224 Heap* heap = isolate->heap();
1225 if (constant->HasNumberValue()) return heap->number_string();
1226 if (constant->IsUndetectable()) return heap->undefined_string();
1227 if (constant->HasStringValue()) return heap->string_string();
1228 switch (constant->GetInstanceType()) {
1229 case ODDBALL_TYPE: {
1230 Unique<Object> unique = constant->GetUnique();
1231 if (unique.IsKnownGlobal(heap->true_value()) ||
1232 unique.IsKnownGlobal(heap->false_value())) {
1233 return heap->boolean_string();
1234 }
1235 if (unique.IsKnownGlobal(heap->null_value())) {
1236 return FLAG_harmony_typeof ? heap->null_string()
1237 : heap->object_string();
1238 }
1239 ASSERT(unique.IsKnownGlobal(heap->undefined_value()));
1240 return heap->undefined_string();
1241 }
1242 case SYMBOL_TYPE:
1243 return heap->symbol_string();
1244 case JS_FUNCTION_TYPE:
1245 case JS_FUNCTION_PROXY_TYPE:
1246 return heap->function_string();
1247 default:
1248 return heap->object_string();
1249 }
1250 }
1251
1252
1223 bool HTypeofIsAndBranch::KnownSuccessorBlock(HBasicBlock** block) { 1253 bool HTypeofIsAndBranch::KnownSuccessorBlock(HBasicBlock** block) {
1224 if (value()->representation().IsSpecialization()) { 1254 if (FLAG_fold_constants && value()->IsConstant()) {
1225 if (compares_number_type()) { 1255 HConstant* constant = HConstant::cast(value());
1226 *block = FirstSuccessor(); 1256 String* type_string = TypeOfString(constant, isolate());
1227 } else { 1257 bool same_type = type_literal_.IsKnownGlobal(type_string);
1228 *block = SecondSuccessor(); 1258 *block = same_type ? FirstSuccessor() : SecondSuccessor();
1229 } 1259 return true;
1260 } else if (value()->representation().IsSpecialization()) {
1261 bool number_type =
1262 type_literal_.IsKnownGlobal(isolate()->heap()->number_string());
1263 *block = number_type ? FirstSuccessor() : SecondSuccessor();
1230 return true; 1264 return true;
1231 } 1265 }
1232 *block = NULL; 1266 *block = NULL;
1233 return false; 1267 return false;
1234 } 1268 }
1235 1269
1236 1270
1237 void HCheckMapValue::PrintDataTo(StringStream* stream) { 1271 void HCheckMapValue::PrintDataTo(StringStream* stream) {
1238 value()->PrintNameTo(stream); 1272 value()->PrintNameTo(stream);
1239 stream->Add(" "); 1273 stream->Add(" ");
(...skipping 1251 matching lines...) Expand 10 before | Expand all | Expand 10 after
2491 } 2525 }
2492 2526
2493 2527
2494 HConstant::HConstant(Handle<Object> handle, Representation r) 2528 HConstant::HConstant(Handle<Object> handle, Representation r)
2495 : HTemplateInstruction<0>(HType::TypeFromValue(handle)), 2529 : HTemplateInstruction<0>(HType::TypeFromValue(handle)),
2496 object_(Unique<Object>::CreateUninitialized(handle)), 2530 object_(Unique<Object>::CreateUninitialized(handle)),
2497 has_smi_value_(false), 2531 has_smi_value_(false),
2498 has_int32_value_(false), 2532 has_int32_value_(false),
2499 has_double_value_(false), 2533 has_double_value_(false),
2500 has_external_reference_value_(false), 2534 has_external_reference_value_(false),
2501 is_internalized_string_(false),
2502 is_not_in_new_space_(true), 2535 is_not_in_new_space_(true),
2503 is_cell_(false), 2536 boolean_value_(handle->BooleanValue()),
2504 boolean_value_(handle->BooleanValue()) { 2537 is_undetectable_(false),
2538 instance_type_(kUnknownInstanceType) {
2505 if (handle->IsHeapObject()) { 2539 if (handle->IsHeapObject()) {
2506 Heap* heap = Handle<HeapObject>::cast(handle)->GetHeap(); 2540 Handle<HeapObject> heap_obj = Handle<HeapObject>::cast(handle);
2541 Heap* heap = heap_obj->GetHeap();
2507 is_not_in_new_space_ = !heap->InNewSpace(*handle); 2542 is_not_in_new_space_ = !heap->InNewSpace(*handle);
2543 instance_type_ = heap_obj->map()->instance_type();
2544 is_undetectable_ = heap_obj->map()->is_undetectable();
2508 } 2545 }
2509 if (handle->IsNumber()) { 2546 if (handle->IsNumber()) {
2510 double n = handle->Number(); 2547 double n = handle->Number();
2511 has_int32_value_ = IsInteger32(n); 2548 has_int32_value_ = IsInteger32(n);
2512 int32_value_ = DoubleToInt32(n); 2549 int32_value_ = DoubleToInt32(n);
2513 has_smi_value_ = has_int32_value_ && Smi::IsValid(int32_value_); 2550 has_smi_value_ = has_int32_value_ && Smi::IsValid(int32_value_);
2514 double_value_ = n; 2551 double_value_ = n;
2515 has_double_value_ = true; 2552 has_double_value_ = true;
2516 // TODO(titzer): if this heap number is new space, tenure a new one. 2553 // TODO(titzer): if this heap number is new space, tenure a new one.
2517 } else {
2518 is_internalized_string_ = handle->IsInternalizedString();
2519 } 2554 }
2520 2555
2521 is_cell_ = !handle.is_null() &&
2522 (handle->IsCell() || handle->IsPropertyCell());
2523 Initialize(r); 2556 Initialize(r);
2524 } 2557 }
2525 2558
2526 2559
2527 HConstant::HConstant(Unique<Object> unique, 2560 HConstant::HConstant(Unique<Object> unique,
2528 Representation r, 2561 Representation r,
2529 HType type, 2562 HType type,
2530 bool is_internalize_string,
2531 bool is_not_in_new_space, 2563 bool is_not_in_new_space,
2532 bool is_cell, 2564 bool boolean_value,
2533 bool boolean_value) 2565 bool is_undetectable,
2566 InstanceType instance_type)
2534 : HTemplateInstruction<0>(type), 2567 : HTemplateInstruction<0>(type),
2535 object_(unique), 2568 object_(unique),
2536 has_smi_value_(false), 2569 has_smi_value_(false),
2537 has_int32_value_(false), 2570 has_int32_value_(false),
2538 has_double_value_(false), 2571 has_double_value_(false),
2539 has_external_reference_value_(false), 2572 has_external_reference_value_(false),
2540 is_internalized_string_(is_internalize_string),
2541 is_not_in_new_space_(is_not_in_new_space), 2573 is_not_in_new_space_(is_not_in_new_space),
2542 is_cell_(is_cell), 2574 boolean_value_(boolean_value),
2543 boolean_value_(boolean_value) { 2575 is_undetectable_(is_undetectable),
2576 instance_type_(instance_type) {
2544 ASSERT(!unique.handle().is_null()); 2577 ASSERT(!unique.handle().is_null());
2545 ASSERT(!type.IsTaggedNumber()); 2578 ASSERT(!type.IsTaggedNumber());
2546 Initialize(r); 2579 Initialize(r);
2547 } 2580 }
2548 2581
2549 2582
2550 HConstant::HConstant(int32_t integer_value, 2583 HConstant::HConstant(int32_t integer_value,
2551 Representation r, 2584 Representation r,
2552 bool is_not_in_new_space, 2585 bool is_not_in_new_space,
2553 Unique<Object> object) 2586 Unique<Object> object)
2554 : object_(object), 2587 : object_(object),
2555 has_smi_value_(Smi::IsValid(integer_value)), 2588 has_smi_value_(Smi::IsValid(integer_value)),
2556 has_int32_value_(true), 2589 has_int32_value_(true),
2557 has_double_value_(true), 2590 has_double_value_(true),
2558 has_external_reference_value_(false), 2591 has_external_reference_value_(false),
2559 is_internalized_string_(false),
2560 is_not_in_new_space_(is_not_in_new_space), 2592 is_not_in_new_space_(is_not_in_new_space),
2561 is_cell_(false),
2562 boolean_value_(integer_value != 0), 2593 boolean_value_(integer_value != 0),
2594 is_undetectable_(false),
2563 int32_value_(integer_value), 2595 int32_value_(integer_value),
2564 double_value_(FastI2D(integer_value)) { 2596 double_value_(FastI2D(integer_value)),
2597 instance_type_(kUnknownInstanceType) {
2565 // It's possible to create a constant with a value in Smi-range but stored 2598 // It's possible to create a constant with a value in Smi-range but stored
2566 // in a (pre-existing) HeapNumber. See crbug.com/349878. 2599 // in a (pre-existing) HeapNumber. See crbug.com/349878.
2567 bool could_be_heapobject = r.IsTagged() && !object.handle().is_null(); 2600 bool could_be_heapobject = r.IsTagged() && !object.handle().is_null();
2568 bool is_smi = has_smi_value_ && !could_be_heapobject; 2601 bool is_smi = has_smi_value_ && !could_be_heapobject;
2569 set_type(is_smi ? HType::Smi() : HType::TaggedNumber()); 2602 set_type(is_smi ? HType::Smi() : HType::TaggedNumber());
2570 Initialize(r); 2603 Initialize(r);
2571 } 2604 }
2572 2605
2573 2606
2574 HConstant::HConstant(double double_value, 2607 HConstant::HConstant(double double_value,
2575 Representation r, 2608 Representation r,
2576 bool is_not_in_new_space, 2609 bool is_not_in_new_space,
2577 Unique<Object> object) 2610 Unique<Object> object)
2578 : object_(object), 2611 : object_(object),
2579 has_int32_value_(IsInteger32(double_value)), 2612 has_int32_value_(IsInteger32(double_value)),
2580 has_double_value_(true), 2613 has_double_value_(true),
2581 has_external_reference_value_(false), 2614 has_external_reference_value_(false),
2582 is_internalized_string_(false),
2583 is_not_in_new_space_(is_not_in_new_space), 2615 is_not_in_new_space_(is_not_in_new_space),
2584 is_cell_(false),
2585 boolean_value_(double_value != 0 && !std::isnan(double_value)), 2616 boolean_value_(double_value != 0 && !std::isnan(double_value)),
2617 is_undetectable_(false),
2586 int32_value_(DoubleToInt32(double_value)), 2618 int32_value_(DoubleToInt32(double_value)),
2587 double_value_(double_value) { 2619 double_value_(double_value),
2620 instance_type_(kUnknownInstanceType) {
2588 has_smi_value_ = has_int32_value_ && Smi::IsValid(int32_value_); 2621 has_smi_value_ = has_int32_value_ && Smi::IsValid(int32_value_);
2589 // It's possible to create a constant with a value in Smi-range but stored 2622 // It's possible to create a constant with a value in Smi-range but stored
2590 // in a (pre-existing) HeapNumber. See crbug.com/349878. 2623 // in a (pre-existing) HeapNumber. See crbug.com/349878.
2591 bool could_be_heapobject = r.IsTagged() && !object.handle().is_null(); 2624 bool could_be_heapobject = r.IsTagged() && !object.handle().is_null();
2592 bool is_smi = has_smi_value_ && !could_be_heapobject; 2625 bool is_smi = has_smi_value_ && !could_be_heapobject;
2593 set_type(is_smi ? HType::Smi() : HType::TaggedNumber()); 2626 set_type(is_smi ? HType::Smi() : HType::TaggedNumber());
2594 Initialize(r); 2627 Initialize(r);
2595 } 2628 }
2596 2629
2597 2630
2598 HConstant::HConstant(ExternalReference reference) 2631 HConstant::HConstant(ExternalReference reference)
2599 : HTemplateInstruction<0>(HType::None()), 2632 : HTemplateInstruction<0>(HType::None()),
2600 object_(Unique<Object>(Handle<Object>::null())), 2633 object_(Unique<Object>(Handle<Object>::null())),
2601 has_smi_value_(false), 2634 has_smi_value_(false),
2602 has_int32_value_(false), 2635 has_int32_value_(false),
2603 has_double_value_(false), 2636 has_double_value_(false),
2604 has_external_reference_value_(true), 2637 has_external_reference_value_(true),
2605 is_internalized_string_(false),
2606 is_not_in_new_space_(true), 2638 is_not_in_new_space_(true),
2607 is_cell_(false),
2608 boolean_value_(true), 2639 boolean_value_(true),
2609 external_reference_value_(reference) { 2640 is_undetectable_(false),
2641 external_reference_value_(reference),
2642 instance_type_(kUnknownInstanceType) {
2610 Initialize(Representation::External()); 2643 Initialize(Representation::External());
2611 } 2644 }
2612 2645
2613 2646
2614 void HConstant::Initialize(Representation r) { 2647 void HConstant::Initialize(Representation r) {
2615 if (r.IsNone()) { 2648 if (r.IsNone()) {
2616 if (has_smi_value_ && SmiValuesAre31Bits()) { 2649 if (has_smi_value_ && SmiValuesAre31Bits()) {
2617 r = Representation::Smi(); 2650 r = Representation::Smi();
2618 } else if (has_int32_value_) { 2651 } else if (has_int32_value_) {
2619 r = Representation::Integer32(); 2652 r = Representation::Integer32();
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
2698 if (has_double_value_) { 2731 if (has_double_value_) {
2699 return new(zone) HConstant(double_value_, r, is_not_in_new_space_, object_); 2732 return new(zone) HConstant(double_value_, r, is_not_in_new_space_, object_);
2700 } 2733 }
2701 if (has_external_reference_value_) { 2734 if (has_external_reference_value_) {
2702 return new(zone) HConstant(external_reference_value_); 2735 return new(zone) HConstant(external_reference_value_);
2703 } 2736 }
2704 ASSERT(!object_.handle().is_null()); 2737 ASSERT(!object_.handle().is_null());
2705 return new(zone) HConstant(object_, 2738 return new(zone) HConstant(object_,
2706 r, 2739 r,
2707 type_, 2740 type_,
2708 is_internalized_string_,
2709 is_not_in_new_space_, 2741 is_not_in_new_space_,
2710 is_cell_, 2742 boolean_value_,
2711 boolean_value_); 2743 is_undetectable_,
2744 instance_type_);
2712 } 2745 }
2713 2746
2714 2747
2715 Maybe<HConstant*> HConstant::CopyToTruncatedInt32(Zone* zone) { 2748 Maybe<HConstant*> HConstant::CopyToTruncatedInt32(Zone* zone) {
2716 HConstant* res = NULL; 2749 HConstant* res = NULL;
2717 if (has_int32_value_) { 2750 if (has_int32_value_) {
2718 res = new(zone) HConstant(int32_value_, 2751 res = new(zone) HConstant(int32_value_,
2719 Representation::Integer32(), 2752 Representation::Integer32(),
2720 is_not_in_new_space_, 2753 is_not_in_new_space_,
2721 object_); 2754 object_);
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
3015 3048
3016 void HCompareObjectEqAndBranch::PrintDataTo(StringStream* stream) { 3049 void HCompareObjectEqAndBranch::PrintDataTo(StringStream* stream) {
3017 left()->PrintNameTo(stream); 3050 left()->PrintNameTo(stream);
3018 stream->Add(" "); 3051 stream->Add(" ");
3019 right()->PrintNameTo(stream); 3052 right()->PrintNameTo(stream);
3020 HControlInstruction::PrintDataTo(stream); 3053 HControlInstruction::PrintDataTo(stream);
3021 } 3054 }
3022 3055
3023 3056
3024 bool HCompareObjectEqAndBranch::KnownSuccessorBlock(HBasicBlock** block) { 3057 bool HCompareObjectEqAndBranch::KnownSuccessorBlock(HBasicBlock** block) {
3025 if (left()->IsConstant() && right()->IsConstant()) { 3058 if (FLAG_fold_constants && left()->IsConstant() && right()->IsConstant()) {
3026 bool comparison_result = 3059 *block = HConstant::cast(left())->Equals(HConstant::cast(right()))
3027 HConstant::cast(left())->Equals(HConstant::cast(right())); 3060 ? FirstSuccessor() : SecondSuccessor();
3028 *block = comparison_result
3029 ? FirstSuccessor()
3030 : SecondSuccessor();
3031 return true; 3061 return true;
3032 } 3062 }
3033 *block = NULL; 3063 *block = NULL;
3064 return false;
3065 }
3066
3067
3068 bool ConstantIsObject(HConstant* constant, Isolate* isolate) {
3069 if (constant->HasNumberValue()) return false;
3070 if (constant->GetUnique().IsKnownGlobal(isolate->heap()->null_value())) {
3071 return true;
3072 }
3073 if (constant->IsUndetectable()) return false;
3074 InstanceType type = constant->GetInstanceType();
3075 return (FIRST_NONCALLABLE_SPEC_OBJECT_TYPE <= type) &&
3076 (type <= LAST_NONCALLABLE_SPEC_OBJECT_TYPE);
3077 }
3078
3079
3080 bool HIsObjectAndBranch::KnownSuccessorBlock(HBasicBlock** block) {
3081 if (FLAG_fold_constants && value()->IsConstant()) {
3082 *block = ConstantIsObject(HConstant::cast(value()), isolate())
3083 ? FirstSuccessor() : SecondSuccessor();
3084 return true;
3085 }
3086 *block = NULL;
3087 return false;
3088 }
3089
3090
3091 bool HIsStringAndBranch::KnownSuccessorBlock(HBasicBlock** block) {
3092 if (FLAG_fold_constants && value()->IsConstant()) {
3093 *block = HConstant::cast(value())->HasStringValue()
3094 ? FirstSuccessor() : SecondSuccessor();
3095 return true;
3096 }
3097 *block = NULL;
3098 return false;
3099 }
3100
3101
3102 bool HIsSmiAndBranch::KnownSuccessorBlock(HBasicBlock** block) {
3103 if (FLAG_fold_constants && value()->IsConstant()) {
3104 *block = HConstant::cast(value())->HasSmiValue()
3105 ? FirstSuccessor() : SecondSuccessor();
3106 return true;
3107 }
3108 *block = NULL;
3109 return false;
3110 }
3111
3112
3113 bool HIsUndetectableAndBranch::KnownSuccessorBlock(HBasicBlock** block) {
3114 if (FLAG_fold_constants && value()->IsConstant()) {
3115 *block = HConstant::cast(value())->IsUndetectable()
3116 ? FirstSuccessor() : SecondSuccessor();
3117 return true;
3118 }
3119 *block = NULL;
3120 return false;
3121 }
3122
3123
3124 bool HHasInstanceTypeAndBranch::KnownSuccessorBlock(HBasicBlock** block) {
3125 if (FLAG_fold_constants && value()->IsConstant()) {
3126 InstanceType type = HConstant::cast(value())->GetInstanceType();
3127 *block = (from_ <= type) && (type <= to_)
3128 ? FirstSuccessor() : SecondSuccessor();
3129 return true;
3130 }
3131 *block = NULL;
3034 return false; 3132 return false;
3035 } 3133 }
3036 3134
3037 3135
3038 void HCompareHoleAndBranch::InferRepresentation( 3136 void HCompareHoleAndBranch::InferRepresentation(
3039 HInferRepresentationPhase* h_infer) { 3137 HInferRepresentationPhase* h_infer) {
3040 ChangeRepresentation(value()->representation()); 3138 ChangeRepresentation(value()->representation());
3041 } 3139 }
3042 3140
3043 3141
3044 bool HCompareMinusZeroAndBranch::KnownSuccessorBlock(HBasicBlock** block) { 3142 bool HCompareMinusZeroAndBranch::KnownSuccessorBlock(HBasicBlock** block) {
3143 if (FLAG_fold_constants && value()->IsConstant()) {
3144 HConstant* constant = HConstant::cast(value());
3145 if (constant->HasDoubleValue()) {
3146 *block = IsMinusZero(constant->DoubleValue())
3147 ? FirstSuccessor() : SecondSuccessor();
3148 }
3149 return true;
Jakob Kummerow 2014/03/10 14:51:08 I think this needs to be inside the if() {...} blo
3150 }
3045 if (value()->representation().IsSmiOrInteger32()) { 3151 if (value()->representation().IsSmiOrInteger32()) {
3046 // A Smi or Integer32 cannot contain minus zero. 3152 // A Smi or Integer32 cannot contain minus zero.
3047 *block = SecondSuccessor(); 3153 *block = SecondSuccessor();
3048 return true; 3154 return true;
3049 } 3155 }
3050 *block = NULL; 3156 *block = NULL;
3051 return false; 3157 return false;
3052 } 3158 }
3053 3159
3054 3160
(...skipping 1382 matching lines...) Expand 10 before | Expand all | Expand 10 after
4437 break; 4543 break;
4438 case kExternalMemory: 4544 case kExternalMemory:
4439 stream->Add("[external-memory]"); 4545 stream->Add("[external-memory]");
4440 break; 4546 break;
4441 } 4547 }
4442 4548
4443 stream->Add("@%d", offset()); 4549 stream->Add("@%d", offset());
4444 } 4550 }
4445 4551
4446 } } // namespace v8::internal 4552 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/hydrogen-instructions.h ('k') | src/objects-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698