| Ben Murdoch | c8c1d9e | 2017-03-08 14:04:23 +0000 | [diff] [blame^] | 1 | // Copyright 2016 the V8 project authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef V8_IC_HANDLER_CONFIGURATION_INL_H_ |
| 6 | #define V8_IC_HANDLER_CONFIGURATION_INL_H_ |
| 7 | |
| 8 | #include "src/ic/handler-configuration.h" |
| 9 | |
| 10 | #include "src/field-index-inl.h" |
| 11 | #include "src/objects-inl.h" |
| 12 | |
| 13 | namespace v8 { |
| 14 | namespace internal { |
| 15 | |
| 16 | Handle<Object> LoadHandler::LoadField(Isolate* isolate, |
| 17 | FieldIndex field_index) { |
| 18 | int config = KindBits::encode(kForFields) | |
| 19 | IsInobjectBits::encode(field_index.is_inobject()) | |
| 20 | IsDoubleBits::encode(field_index.is_double()) | |
| 21 | FieldOffsetBits::encode(field_index.offset()); |
| 22 | return handle(Smi::FromInt(config), isolate); |
| 23 | } |
| 24 | |
| 25 | Handle<Object> LoadHandler::LoadConstant(Isolate* isolate, int descriptor) { |
| 26 | int config = KindBits::encode(kForConstants) | |
| 27 | IsAccessorInfoBits::encode(false) | |
| 28 | DescriptorValueIndexBits::encode( |
| 29 | DescriptorArray::ToValueIndex(descriptor)); |
| 30 | return handle(Smi::FromInt(config), isolate); |
| 31 | } |
| 32 | |
| 33 | Handle<Object> LoadHandler::LoadApiGetter(Isolate* isolate, int descriptor) { |
| 34 | int config = KindBits::encode(kForConstants) | |
| 35 | IsAccessorInfoBits::encode(true) | |
| 36 | DescriptorValueIndexBits::encode( |
| 37 | DescriptorArray::ToValueIndex(descriptor)); |
| 38 | return handle(Smi::FromInt(config), isolate); |
| 39 | } |
| 40 | |
| 41 | Handle<Object> LoadHandler::EnableAccessCheckOnReceiver( |
| 42 | Isolate* isolate, Handle<Object> smi_handler) { |
| 43 | int config = Smi::cast(*smi_handler)->value(); |
| 44 | #ifdef DEBUG |
| 45 | Kind kind = KindBits::decode(config); |
| 46 | DCHECK_NE(kForElements, kind); |
| 47 | #endif |
| 48 | config = DoAccessCheckOnReceiverBits::update(config, true); |
| 49 | return handle(Smi::FromInt(config), isolate); |
| 50 | } |
| 51 | |
| 52 | Handle<Object> LoadHandler::EnableNegativeLookupOnReceiver( |
| 53 | Isolate* isolate, Handle<Object> smi_handler) { |
| 54 | int config = Smi::cast(*smi_handler)->value(); |
| 55 | #ifdef DEBUG |
| 56 | Kind kind = KindBits::decode(config); |
| 57 | DCHECK_NE(kForElements, kind); |
| 58 | #endif |
| 59 | config = DoNegativeLookupOnReceiverBits::update(config, true); |
| 60 | return handle(Smi::FromInt(config), isolate); |
| 61 | } |
| 62 | |
| 63 | Handle<Object> LoadHandler::LoadNonExistent( |
| 64 | Isolate* isolate, bool do_negative_lookup_on_receiver) { |
| 65 | int config = |
| 66 | KindBits::encode(kForNonExistent) | |
| 67 | DoNegativeLookupOnReceiverBits::encode(do_negative_lookup_on_receiver); |
| 68 | return handle(Smi::FromInt(config), isolate); |
| 69 | } |
| 70 | |
| 71 | Handle<Object> LoadHandler::LoadElement(Isolate* isolate, |
| 72 | ElementsKind elements_kind, |
| 73 | bool convert_hole_to_undefined, |
| 74 | bool is_js_array) { |
| 75 | int config = KindBits::encode(kForElements) | |
| 76 | ElementsKindBits::encode(elements_kind) | |
| 77 | ConvertHoleBits::encode(convert_hole_to_undefined) | |
| 78 | IsJsArrayBits::encode(is_js_array); |
| 79 | return handle(Smi::FromInt(config), isolate); |
| 80 | } |
| 81 | |
| 82 | Handle<Object> StoreHandler::StoreField(Isolate* isolate, Kind kind, |
| 83 | int descriptor, FieldIndex field_index, |
| 84 | Representation representation, |
| 85 | bool extend_storage) { |
| 86 | StoreHandler::FieldRepresentation field_rep; |
| 87 | switch (representation.kind()) { |
| 88 | case Representation::kSmi: |
| 89 | field_rep = StoreHandler::kSmi; |
| 90 | break; |
| 91 | case Representation::kDouble: |
| 92 | field_rep = StoreHandler::kDouble; |
| 93 | break; |
| 94 | case Representation::kHeapObject: |
| 95 | field_rep = StoreHandler::kHeapObject; |
| 96 | break; |
| 97 | case Representation::kTagged: |
| 98 | field_rep = StoreHandler::kTagged; |
| 99 | break; |
| 100 | default: |
| 101 | UNREACHABLE(); |
| 102 | return Handle<Object>::null(); |
| 103 | } |
| 104 | int value_index = DescriptorArray::ToValueIndex(descriptor); |
| 105 | |
| 106 | DCHECK(kind == kStoreField || kind == kTransitionToField); |
| 107 | DCHECK_IMPLIES(kind == kStoreField, !extend_storage); |
| 108 | |
| 109 | int config = StoreHandler::KindBits::encode(kind) | |
| 110 | StoreHandler::ExtendStorageBits::encode(extend_storage) | |
| 111 | StoreHandler::IsInobjectBits::encode(field_index.is_inobject()) | |
| 112 | StoreHandler::FieldRepresentationBits::encode(field_rep) | |
| 113 | StoreHandler::DescriptorValueIndexBits::encode(value_index) | |
| 114 | StoreHandler::FieldOffsetBits::encode(field_index.offset()); |
| 115 | return handle(Smi::FromInt(config), isolate); |
| 116 | } |
| 117 | |
| 118 | Handle<Object> StoreHandler::StoreField(Isolate* isolate, int descriptor, |
| 119 | FieldIndex field_index, |
| 120 | Representation representation) { |
| 121 | return StoreField(isolate, kStoreField, descriptor, field_index, |
| 122 | representation, false); |
| 123 | } |
| 124 | |
| 125 | Handle<Object> StoreHandler::TransitionToField(Isolate* isolate, int descriptor, |
| 126 | FieldIndex field_index, |
| 127 | Representation representation, |
| 128 | bool extend_storage) { |
| 129 | return StoreField(isolate, kTransitionToField, descriptor, field_index, |
| 130 | representation, extend_storage); |
| 131 | } |
| 132 | |
| 133 | Handle<Object> StoreHandler::TransitionToConstant(Isolate* isolate, |
| 134 | int descriptor) { |
| 135 | int value_index = DescriptorArray::ToValueIndex(descriptor); |
| 136 | int config = |
| 137 | StoreHandler::KindBits::encode(StoreHandler::kTransitionToConstant) | |
| 138 | StoreHandler::DescriptorValueIndexBits::encode(value_index); |
| 139 | return handle(Smi::FromInt(config), isolate); |
| 140 | } |
| 141 | |
| 142 | } // namespace internal |
| 143 | } // namespace v8 |
| 144 | |
| 145 | #endif // V8_IC_HANDLER_CONFIGURATION_INL_H_ |