Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5 | #if V8_TARGET_ARCH_MIPS64 |
| 6 | |
| 7 | #include "src/codegen.h" |
| 8 | #include "src/ic/ic.h" |
| 9 | #include "src/ic/ic-compiler.h" |
| 10 | #include "src/ic/stub-cache.h" |
| 11 | |
| 12 | namespace v8 { |
| 13 | namespace internal { |
| 14 | |
| 15 | |
| 16 | // ---------------------------------------------------------------------------- |
| 17 | // Static IC stub generators. |
| 18 | // |
| 19 | |
| 20 | #define __ ACCESS_MASM(masm) |
| 21 | |
| 22 | |
| 23 | static void GenerateGlobalInstanceTypeCheck(MacroAssembler* masm, Register type, |
| 24 | Label* global_object) { |
| 25 | // Register usage: |
| 26 | // type: holds the receiver instance type on entry. |
| 27 | __ Branch(global_object, eq, type, Operand(JS_GLOBAL_OBJECT_TYPE)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 28 | __ Branch(global_object, eq, type, Operand(JS_GLOBAL_PROXY_TYPE)); |
| 29 | } |
| 30 | |
| 31 | |
| 32 | // Helper function used from LoadIC GenerateNormal. |
| 33 | // |
| 34 | // elements: Property dictionary. It is not clobbered if a jump to the miss |
| 35 | // label is done. |
| 36 | // name: Property name. It is not clobbered if a jump to the miss label is |
| 37 | // done |
| 38 | // result: Register for the result. It is only updated if a jump to the miss |
| 39 | // label is not done. Can be the same as elements or name clobbering |
| 40 | // one of these in the case of not jumping to the miss label. |
| 41 | // The two scratch registers need to be different from elements, name and |
| 42 | // result. |
| 43 | // The generated code assumes that the receiver has slow properties, |
| 44 | // is not a global object and does not have interceptors. |
| 45 | // The address returned from GenerateStringDictionaryProbes() in scratch2 |
| 46 | // is used. |
| 47 | static void GenerateDictionaryLoad(MacroAssembler* masm, Label* miss, |
| 48 | Register elements, Register name, |
| 49 | Register result, Register scratch1, |
| 50 | Register scratch2) { |
| 51 | // Main use of the scratch registers. |
| 52 | // scratch1: Used as temporary and to hold the capacity of the property |
| 53 | // dictionary. |
| 54 | // scratch2: Used as temporary. |
| 55 | Label done; |
| 56 | |
| 57 | // Probe the dictionary. |
| 58 | NameDictionaryLookupStub::GeneratePositiveLookup(masm, miss, &done, elements, |
| 59 | name, scratch1, scratch2); |
| 60 | |
| 61 | // If probing finds an entry check that the value is a normal |
| 62 | // property. |
| 63 | __ bind(&done); // scratch2 == elements + 4 * index. |
| 64 | const int kElementsStartOffset = |
| 65 | NameDictionary::kHeaderSize + |
| 66 | NameDictionary::kElementsStartIndex * kPointerSize; |
| 67 | const int kDetailsOffset = kElementsStartOffset + 2 * kPointerSize; |
| 68 | __ ld(scratch1, FieldMemOperand(scratch2, kDetailsOffset)); |
| 69 | __ And(at, scratch1, |
| 70 | Operand(Smi::FromInt(PropertyDetails::TypeField::kMask))); |
| 71 | __ Branch(miss, ne, at, Operand(zero_reg)); |
| 72 | |
| 73 | // Get the value at the masked, scaled index and return. |
| 74 | __ ld(result, |
| 75 | FieldMemOperand(scratch2, kElementsStartOffset + 1 * kPointerSize)); |
| 76 | } |
| 77 | |
| 78 | |
| 79 | // Helper function used from StoreIC::GenerateNormal. |
| 80 | // |
| 81 | // elements: Property dictionary. It is not clobbered if a jump to the miss |
| 82 | // label is done. |
| 83 | // name: Property name. It is not clobbered if a jump to the miss label is |
| 84 | // done |
| 85 | // value: The value to store. |
| 86 | // The two scratch registers need to be different from elements, name and |
| 87 | // result. |
| 88 | // The generated code assumes that the receiver has slow properties, |
| 89 | // is not a global object and does not have interceptors. |
| 90 | // The address returned from GenerateStringDictionaryProbes() in scratch2 |
| 91 | // is used. |
| 92 | static void GenerateDictionaryStore(MacroAssembler* masm, Label* miss, |
| 93 | Register elements, Register name, |
| 94 | Register value, Register scratch1, |
| 95 | Register scratch2) { |
| 96 | // Main use of the scratch registers. |
| 97 | // scratch1: Used as temporary and to hold the capacity of the property |
| 98 | // dictionary. |
| 99 | // scratch2: Used as temporary. |
| 100 | Label done; |
| 101 | |
| 102 | // Probe the dictionary. |
| 103 | NameDictionaryLookupStub::GeneratePositiveLookup(masm, miss, &done, elements, |
| 104 | name, scratch1, scratch2); |
| 105 | |
| 106 | // If probing finds an entry in the dictionary check that the value |
| 107 | // is a normal property that is not read only. |
| 108 | __ bind(&done); // scratch2 == elements + 4 * index. |
| 109 | const int kElementsStartOffset = |
| 110 | NameDictionary::kHeaderSize + |
| 111 | NameDictionary::kElementsStartIndex * kPointerSize; |
| 112 | const int kDetailsOffset = kElementsStartOffset + 2 * kPointerSize; |
| 113 | const int kTypeAndReadOnlyMask = |
| 114 | (PropertyDetails::TypeField::kMask | |
| 115 | PropertyDetails::AttributesField::encode(READ_ONLY)); |
| 116 | __ ld(scratch1, FieldMemOperand(scratch2, kDetailsOffset)); |
| 117 | __ And(at, scratch1, Operand(Smi::FromInt(kTypeAndReadOnlyMask))); |
| 118 | __ Branch(miss, ne, at, Operand(zero_reg)); |
| 119 | |
| 120 | // Store the value at the masked, scaled index and return. |
| 121 | const int kValueOffset = kElementsStartOffset + kPointerSize; |
| 122 | __ Daddu(scratch2, scratch2, Operand(kValueOffset - kHeapObjectTag)); |
| 123 | __ sd(value, MemOperand(scratch2)); |
| 124 | |
| 125 | // Update the write barrier. Make sure not to clobber the value. |
| 126 | __ mov(scratch1, value); |
| 127 | __ RecordWrite(elements, scratch2, scratch1, kRAHasNotBeenSaved, |
| 128 | kDontSaveFPRegs); |
| 129 | } |
| 130 | |
| 131 | |
| 132 | // Checks the receiver for special cases (value type, slow case bits). |
| 133 | // Falls through for regular JS object. |
| 134 | static void GenerateKeyedLoadReceiverCheck(MacroAssembler* masm, |
| 135 | Register receiver, Register map, |
| 136 | Register scratch, |
| 137 | int interceptor_bit, Label* slow) { |
| 138 | // Check that the object isn't a smi. |
| 139 | __ JumpIfSmi(receiver, slow); |
| 140 | // Get the map of the receiver. |
| 141 | __ ld(map, FieldMemOperand(receiver, HeapObject::kMapOffset)); |
| 142 | // Check bit field. |
| 143 | __ lbu(scratch, FieldMemOperand(map, Map::kBitFieldOffset)); |
| 144 | __ And(at, scratch, |
| 145 | Operand((1 << Map::kIsAccessCheckNeeded) | (1 << interceptor_bit))); |
| 146 | __ Branch(slow, ne, at, Operand(zero_reg)); |
| 147 | // Check that the object is some kind of JS object EXCEPT JS Value type. |
| 148 | // In the case that the object is a value-wrapper object, |
| 149 | // we enter the runtime system to make sure that indexing into string |
| 150 | // objects work as intended. |
| 151 | DCHECK(JS_OBJECT_TYPE > JS_VALUE_TYPE); |
| 152 | __ lbu(scratch, FieldMemOperand(map, Map::kInstanceTypeOffset)); |
| 153 | __ Branch(slow, lt, scratch, Operand(JS_OBJECT_TYPE)); |
| 154 | } |
| 155 | |
| 156 | |
| 157 | // Loads an indexed element from a fast case array. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 158 | static void GenerateFastArrayLoad(MacroAssembler* masm, Register receiver, |
| 159 | Register key, Register elements, |
| 160 | Register scratch1, Register scratch2, |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 161 | Register result, Label* slow) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 162 | // Register use: |
| 163 | // |
| 164 | // receiver - holds the receiver on entry. |
| 165 | // Unchanged unless 'result' is the same register. |
| 166 | // |
| 167 | // key - holds the smi key on entry. |
| 168 | // Unchanged unless 'result' is the same register. |
| 169 | // |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 170 | // result - holds the result on exit if the load succeeded. |
| 171 | // Allowed to be the the same as 'receiver' or 'key'. |
| 172 | // Unchanged on bailout so 'receiver' and 'key' can be safely |
| 173 | // used by further computation. |
| 174 | // |
| 175 | // Scratch registers: |
| 176 | // |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 177 | // elements - holds the elements of the receiver and its prototypes. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 178 | // |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 179 | // scratch1 - used to hold elements length, bit fields, base addresses. |
| 180 | // |
| 181 | // scratch2 - used to hold maps, prototypes, and the loaded value. |
| 182 | Label check_prototypes, check_next_prototype; |
| 183 | Label done, in_bounds, absent; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 184 | |
| 185 | __ ld(elements, FieldMemOperand(receiver, JSObject::kElementsOffset)); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 186 | __ AssertFastElements(elements); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 187 | |
| 188 | // Check that the key (index) is within bounds. |
| 189 | __ ld(scratch1, FieldMemOperand(elements, FixedArray::kLengthOffset)); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 190 | __ Branch(&in_bounds, lo, key, Operand(scratch1)); |
| 191 | // Out-of-bounds. Check the prototype chain to see if we can just return |
| 192 | // 'undefined'. |
| 193 | // Negative keys can't take the fast OOB path. |
| 194 | __ Branch(slow, lt, key, Operand(zero_reg)); |
| 195 | __ bind(&check_prototypes); |
| 196 | __ ld(scratch2, FieldMemOperand(receiver, HeapObject::kMapOffset)); |
| 197 | __ bind(&check_next_prototype); |
| 198 | __ ld(scratch2, FieldMemOperand(scratch2, Map::kPrototypeOffset)); |
| 199 | // scratch2: current prototype |
| 200 | __ LoadRoot(at, Heap::kNullValueRootIndex); |
| 201 | __ Branch(&absent, eq, scratch2, Operand(at)); |
| 202 | __ ld(elements, FieldMemOperand(scratch2, JSObject::kElementsOffset)); |
| 203 | __ ld(scratch2, FieldMemOperand(scratch2, HeapObject::kMapOffset)); |
| 204 | // elements: elements of current prototype |
| 205 | // scratch2: map of current prototype |
| 206 | __ lbu(scratch1, FieldMemOperand(scratch2, Map::kInstanceTypeOffset)); |
| 207 | __ Branch(slow, lo, scratch1, Operand(JS_OBJECT_TYPE)); |
| 208 | __ lbu(scratch1, FieldMemOperand(scratch2, Map::kBitFieldOffset)); |
| 209 | __ And(at, scratch1, Operand((1 << Map::kIsAccessCheckNeeded) | |
| 210 | (1 << Map::kHasIndexedInterceptor))); |
| 211 | __ Branch(slow, ne, at, Operand(zero_reg)); |
| 212 | __ LoadRoot(at, Heap::kEmptyFixedArrayRootIndex); |
| 213 | __ Branch(slow, ne, elements, Operand(at)); |
| 214 | __ Branch(&check_next_prototype); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 215 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 216 | __ bind(&absent); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 217 | __ LoadRoot(result, Heap::kUndefinedValueRootIndex); |
| 218 | __ Branch(&done); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 219 | |
| 220 | __ bind(&in_bounds); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 221 | // Fast case: Do the load. |
| 222 | __ Daddu(scratch1, elements, |
| 223 | Operand(FixedArray::kHeaderSize - kHeapObjectTag)); |
| 224 | // The key is a smi. |
| 225 | STATIC_ASSERT(kSmiTag == 0 && kSmiTagSize < kPointerSizeLog2); |
| 226 | __ SmiScale(at, key, kPointerSizeLog2); |
| 227 | __ daddu(at, at, scratch1); |
| 228 | __ ld(scratch2, MemOperand(at)); |
| 229 | |
| 230 | __ LoadRoot(at, Heap::kTheHoleValueRootIndex); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 231 | // In case the loaded value is the_hole we have to check the prototype chain. |
| 232 | __ Branch(&check_prototypes, eq, scratch2, Operand(at)); |
| 233 | __ Move(result, scratch2); |
| 234 | __ bind(&done); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | |
| 238 | // Checks whether a key is an array index string or a unique name. |
| 239 | // Falls through if a key is a unique name. |
| 240 | static void GenerateKeyNameCheck(MacroAssembler* masm, Register key, |
| 241 | Register map, Register hash, |
| 242 | Label* index_string, Label* not_unique) { |
| 243 | // The key is not a smi. |
| 244 | Label unique; |
| 245 | // Is it a name? |
| 246 | __ GetObjectType(key, map, hash); |
| 247 | __ Branch(not_unique, hi, hash, Operand(LAST_UNIQUE_NAME_TYPE)); |
| 248 | STATIC_ASSERT(LAST_UNIQUE_NAME_TYPE == FIRST_NONSTRING_TYPE); |
| 249 | __ Branch(&unique, eq, hash, Operand(LAST_UNIQUE_NAME_TYPE)); |
| 250 | |
| 251 | // Is the string an array index, with cached numeric value? |
| 252 | __ lwu(hash, FieldMemOperand(key, Name::kHashFieldOffset)); |
| 253 | __ And(at, hash, Operand(Name::kContainsCachedArrayIndexMask)); |
| 254 | __ Branch(index_string, eq, at, Operand(zero_reg)); |
| 255 | |
| 256 | // Is the string internalized? We know it's a string, so a single |
| 257 | // bit test is enough. |
| 258 | // map: key map |
| 259 | __ lbu(hash, FieldMemOperand(map, Map::kInstanceTypeOffset)); |
| 260 | STATIC_ASSERT(kInternalizedTag == 0); |
| 261 | __ And(at, hash, Operand(kIsNotInternalizedMask)); |
| 262 | __ Branch(not_unique, ne, at, Operand(zero_reg)); |
| 263 | |
| 264 | __ bind(&unique); |
| 265 | } |
| 266 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 267 | void LoadIC::GenerateNormal(MacroAssembler* masm) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 268 | Register dictionary = a0; |
| 269 | DCHECK(!dictionary.is(LoadDescriptor::ReceiverRegister())); |
| 270 | DCHECK(!dictionary.is(LoadDescriptor::NameRegister())); |
| 271 | Label slow; |
| 272 | |
| 273 | __ ld(dictionary, FieldMemOperand(LoadDescriptor::ReceiverRegister(), |
| 274 | JSObject::kPropertiesOffset)); |
| 275 | GenerateDictionaryLoad(masm, &slow, dictionary, |
| 276 | LoadDescriptor::NameRegister(), v0, a3, a4); |
| 277 | __ Ret(); |
| 278 | |
| 279 | // Dictionary load failed, go slow (but don't miss). |
| 280 | __ bind(&slow); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 281 | GenerateRuntimeGetProperty(masm); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 282 | } |
| 283 | |
| 284 | |
| 285 | // A register that isn't one of the parameters to the load ic. |
| 286 | static const Register LoadIC_TempRegister() { return a3; } |
| 287 | |
| 288 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 289 | static void LoadIC_PushArgs(MacroAssembler* masm) { |
| 290 | Register receiver = LoadDescriptor::ReceiverRegister(); |
| 291 | Register name = LoadDescriptor::NameRegister(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 292 | Register slot = LoadDescriptor::SlotRegister(); |
| 293 | Register vector = LoadWithVectorDescriptor::VectorRegister(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 294 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 295 | __ Push(receiver, name, slot, vector); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 296 | } |
| 297 | |
| 298 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 299 | void LoadIC::GenerateMiss(MacroAssembler* masm) { |
| 300 | // The return address is on the stack. |
| 301 | Isolate* isolate = masm->isolate(); |
| 302 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 303 | DCHECK(!AreAliased(a4, a5, LoadWithVectorDescriptor::SlotRegister(), |
| 304 | LoadWithVectorDescriptor::VectorRegister())); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 305 | __ IncrementCounter(isolate->counters()->ic_load_miss(), 1, a4, a5); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 306 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 307 | LoadIC_PushArgs(masm); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 308 | |
| 309 | // Perform tail call to the entry. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 310 | __ TailCallRuntime(Runtime::kLoadIC_Miss); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 311 | } |
| 312 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 313 | void LoadIC::GenerateRuntimeGetProperty(MacroAssembler* masm) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 314 | // The return address is in ra. |
| 315 | |
| 316 | __ mov(LoadIC_TempRegister(), LoadDescriptor::ReceiverRegister()); |
| 317 | __ Push(LoadIC_TempRegister(), LoadDescriptor::NameRegister()); |
| 318 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 319 | // Do tail-call to runtime routine. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 320 | __ TailCallRuntime(Runtime::kGetProperty); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 321 | } |
| 322 | |
| 323 | |
| 324 | void KeyedLoadIC::GenerateMiss(MacroAssembler* masm) { |
| 325 | // The return address is in ra. |
| 326 | Isolate* isolate = masm->isolate(); |
| 327 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 328 | DCHECK(!AreAliased(a4, a5, LoadWithVectorDescriptor::SlotRegister(), |
| 329 | LoadWithVectorDescriptor::VectorRegister())); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 330 | __ IncrementCounter(isolate->counters()->ic_keyed_load_miss(), 1, a4, a5); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 331 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 332 | LoadIC_PushArgs(masm); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 333 | |
| 334 | // Perform tail call to the entry. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 335 | __ TailCallRuntime(Runtime::kKeyedLoadIC_Miss); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 336 | } |
| 337 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 338 | void KeyedLoadIC::GenerateRuntimeGetProperty(MacroAssembler* masm) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 339 | // The return address is in ra. |
| 340 | |
| 341 | __ Push(LoadDescriptor::ReceiverRegister(), LoadDescriptor::NameRegister()); |
| 342 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 343 | // Do tail-call to runtime routine. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 344 | __ TailCallRuntime(Runtime::kKeyedGetProperty); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 345 | } |
| 346 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 347 | void KeyedLoadIC::GenerateMegamorphic(MacroAssembler* masm) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 348 | // The return address is in ra. |
| 349 | Label slow, check_name, index_smi, index_name, property_array_property; |
| 350 | Label probe_dictionary, check_number_dictionary; |
| 351 | |
| 352 | Register key = LoadDescriptor::NameRegister(); |
| 353 | Register receiver = LoadDescriptor::ReceiverRegister(); |
| 354 | DCHECK(key.is(a2)); |
| 355 | DCHECK(receiver.is(a1)); |
| 356 | |
| 357 | Isolate* isolate = masm->isolate(); |
| 358 | |
| 359 | // Check that the key is a smi. |
| 360 | __ JumpIfNotSmi(key, &check_name); |
| 361 | __ bind(&index_smi); |
| 362 | // Now the key is known to be a smi. This place is also jumped to from below |
| 363 | // where a numeric string is converted to a smi. |
| 364 | |
| 365 | GenerateKeyedLoadReceiverCheck(masm, receiver, a0, a3, |
| 366 | Map::kHasIndexedInterceptor, &slow); |
| 367 | |
| 368 | // Check the receiver's map to see if it has fast elements. |
| 369 | __ CheckFastElements(a0, a3, &check_number_dictionary); |
| 370 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 371 | GenerateFastArrayLoad(masm, receiver, key, a0, a3, a4, v0, &slow); |
| 372 | __ IncrementCounter(isolate->counters()->ic_keyed_load_generic_smi(), 1, a4, |
| 373 | a3); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 374 | __ Ret(); |
| 375 | |
| 376 | __ bind(&check_number_dictionary); |
| 377 | __ ld(a4, FieldMemOperand(receiver, JSObject::kElementsOffset)); |
| 378 | __ ld(a3, FieldMemOperand(a4, JSObject::kMapOffset)); |
| 379 | |
| 380 | // Check whether the elements is a number dictionary. |
| 381 | // a3: elements map |
| 382 | // a4: elements |
| 383 | __ LoadRoot(at, Heap::kHashTableMapRootIndex); |
| 384 | __ Branch(&slow, ne, a3, Operand(at)); |
| 385 | __ dsra32(a0, key, 0); |
| 386 | __ LoadFromNumberDictionary(&slow, a4, key, v0, a0, a3, a5); |
| 387 | __ Ret(); |
| 388 | |
| 389 | // Slow case, key and receiver still in a2 and a1. |
| 390 | __ bind(&slow); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 391 | __ IncrementCounter(isolate->counters()->ic_keyed_load_generic_slow(), 1, a4, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 392 | a3); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 393 | GenerateRuntimeGetProperty(masm); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 394 | |
| 395 | __ bind(&check_name); |
| 396 | GenerateKeyNameCheck(masm, key, a0, a3, &index_name, &slow); |
| 397 | |
| 398 | GenerateKeyedLoadReceiverCheck(masm, receiver, a0, a3, |
| 399 | Map::kHasNamedInterceptor, &slow); |
| 400 | |
| 401 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 402 | // If the receiver is a fast-case object, check the stub cache. Otherwise |
| 403 | // probe the dictionary. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 404 | __ ld(a3, FieldMemOperand(receiver, JSObject::kPropertiesOffset)); |
| 405 | __ ld(a4, FieldMemOperand(a3, HeapObject::kMapOffset)); |
| 406 | __ LoadRoot(at, Heap::kHashTableMapRootIndex); |
| 407 | __ Branch(&probe_dictionary, eq, a4, Operand(at)); |
| 408 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 409 | // The handlers in the stub cache expect a vector and slot. Since we won't |
| 410 | // change the IC from any downstream misses, a dummy vector can be used. |
| 411 | Register vector = LoadWithVectorDescriptor::VectorRegister(); |
| 412 | Register slot = LoadWithVectorDescriptor::SlotRegister(); |
| 413 | DCHECK(!AreAliased(vector, slot, a4, a5, a6, t1)); |
| 414 | Handle<TypeFeedbackVector> dummy_vector = |
| 415 | TypeFeedbackVector::DummyVector(masm->isolate()); |
| 416 | int slot_index = dummy_vector->GetIndex( |
| 417 | FeedbackVectorSlot(TypeFeedbackVector::kDummyKeyedLoadICSlot)); |
| 418 | __ LoadRoot(vector, Heap::kDummyVectorRootIndex); |
| 419 | __ li(slot, Operand(Smi::FromInt(slot_index))); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 420 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 421 | Code::Flags flags = Code::RemoveTypeAndHolderFromFlags( |
| 422 | Code::ComputeHandlerFlags(Code::LOAD_IC)); |
| 423 | masm->isolate()->stub_cache()->GenerateProbe(masm, Code::LOAD_IC, flags, |
| 424 | receiver, key, a4, a5, a6, t1); |
| 425 | // Cache miss. |
| 426 | GenerateMiss(masm); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 427 | |
| 428 | // Do a quick inline probe of the receiver's dictionary, if it |
| 429 | // exists. |
| 430 | __ bind(&probe_dictionary); |
| 431 | // a3: elements |
| 432 | __ ld(a0, FieldMemOperand(receiver, HeapObject::kMapOffset)); |
| 433 | __ lbu(a0, FieldMemOperand(a0, Map::kInstanceTypeOffset)); |
| 434 | GenerateGlobalInstanceTypeCheck(masm, a0, &slow); |
| 435 | // Load the property to v0. |
| 436 | GenerateDictionaryLoad(masm, &slow, a3, key, v0, a5, a4); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 437 | __ IncrementCounter(isolate->counters()->ic_keyed_load_generic_symbol(), 1, |
| 438 | a4, a3); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 439 | __ Ret(); |
| 440 | |
| 441 | __ bind(&index_name); |
| 442 | __ IndexFromHash(a3, key); |
| 443 | // Now jump to the place where smi keys are handled. |
| 444 | __ Branch(&index_smi); |
| 445 | } |
| 446 | |
| 447 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 448 | static void KeyedStoreGenerateMegamorphicHelper( |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 449 | MacroAssembler* masm, Label* fast_object, Label* fast_double, Label* slow, |
| 450 | KeyedStoreCheckMap check_map, KeyedStoreIncrementLength increment_length, |
| 451 | Register value, Register key, Register receiver, Register receiver_map, |
| 452 | Register elements_map, Register elements) { |
| 453 | Label transition_smi_elements; |
| 454 | Label finish_object_store, non_double_value, transition_double_elements; |
| 455 | Label fast_double_without_map_check; |
| 456 | |
| 457 | // Fast case: Do the store, could be either Object or double. |
| 458 | __ bind(fast_object); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 459 | Register scratch = a4; |
| 460 | Register scratch2 = t0; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 461 | Register address = a5; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 462 | DCHECK(!AreAliased(value, key, receiver, receiver_map, elements_map, elements, |
| 463 | scratch, scratch2, address)); |
| 464 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 465 | if (check_map == kCheckMap) { |
| 466 | __ ld(elements_map, FieldMemOperand(elements, HeapObject::kMapOffset)); |
| 467 | __ Branch(fast_double, ne, elements_map, |
| 468 | Operand(masm->isolate()->factory()->fixed_array_map())); |
| 469 | } |
| 470 | |
| 471 | // HOLECHECK: guards "A[i] = V" |
| 472 | // We have to go to the runtime if the current value is the hole because |
| 473 | // there may be a callback on the element. |
| 474 | Label holecheck_passed1; |
| 475 | __ Daddu(address, elements, FixedArray::kHeaderSize - kHeapObjectTag); |
| 476 | __ SmiScale(at, key, kPointerSizeLog2); |
| 477 | __ daddu(address, address, at); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 478 | __ ld(scratch, MemOperand(address)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 479 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 480 | __ Branch(&holecheck_passed1, ne, scratch, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 481 | Operand(masm->isolate()->factory()->the_hole_value())); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 482 | __ JumpIfDictionaryInPrototypeChain(receiver, elements_map, scratch, slow); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 483 | |
| 484 | __ bind(&holecheck_passed1); |
| 485 | |
| 486 | // Smi stores don't require further checks. |
| 487 | Label non_smi_value; |
| 488 | __ JumpIfNotSmi(value, &non_smi_value); |
| 489 | |
| 490 | if (increment_length == kIncrementLength) { |
| 491 | // Add 1 to receiver->length. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 492 | __ Daddu(scratch, key, Operand(Smi::FromInt(1))); |
| 493 | __ sd(scratch, FieldMemOperand(receiver, JSArray::kLengthOffset)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 494 | } |
| 495 | // It's irrelevant whether array is smi-only or not when writing a smi. |
| 496 | __ Daddu(address, elements, |
| 497 | Operand(FixedArray::kHeaderSize - kHeapObjectTag)); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 498 | __ SmiScale(scratch, key, kPointerSizeLog2); |
| 499 | __ Daddu(address, address, scratch); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 500 | __ sd(value, MemOperand(address)); |
| 501 | __ Ret(); |
| 502 | |
| 503 | __ bind(&non_smi_value); |
| 504 | // Escape to elements kind transition case. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 505 | __ CheckFastObjectElements(receiver_map, scratch, &transition_smi_elements); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 506 | |
| 507 | // Fast elements array, store the value to the elements backing store. |
| 508 | __ bind(&finish_object_store); |
| 509 | if (increment_length == kIncrementLength) { |
| 510 | // Add 1 to receiver->length. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 511 | __ Daddu(scratch, key, Operand(Smi::FromInt(1))); |
| 512 | __ sd(scratch, FieldMemOperand(receiver, JSArray::kLengthOffset)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 513 | } |
| 514 | __ Daddu(address, elements, |
| 515 | Operand(FixedArray::kHeaderSize - kHeapObjectTag)); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 516 | __ SmiScale(scratch, key, kPointerSizeLog2); |
| 517 | __ Daddu(address, address, scratch); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 518 | __ sd(value, MemOperand(address)); |
| 519 | // Update write barrier for the elements array address. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 520 | __ mov(scratch, value); // Preserve the value which is returned. |
| 521 | __ RecordWrite(elements, address, scratch, kRAHasNotBeenSaved, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 522 | kDontSaveFPRegs, EMIT_REMEMBERED_SET, OMIT_SMI_CHECK); |
| 523 | __ Ret(); |
| 524 | |
| 525 | __ bind(fast_double); |
| 526 | if (check_map == kCheckMap) { |
| 527 | // Check for fast double array case. If this fails, call through to the |
| 528 | // runtime. |
| 529 | __ LoadRoot(at, Heap::kFixedDoubleArrayMapRootIndex); |
| 530 | __ Branch(slow, ne, elements_map, Operand(at)); |
| 531 | } |
| 532 | |
| 533 | // HOLECHECK: guards "A[i] double hole?" |
| 534 | // We have to see if the double version of the hole is present. If so |
| 535 | // go to the runtime. |
| 536 | __ Daddu(address, elements, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 537 | Operand(FixedDoubleArray::kHeaderSize + Register::kExponentOffset - |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 538 | kHeapObjectTag)); |
| 539 | __ SmiScale(at, key, kPointerSizeLog2); |
| 540 | __ daddu(address, address, at); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 541 | __ lw(scratch, MemOperand(address)); |
| 542 | __ Branch(&fast_double_without_map_check, ne, scratch, |
| 543 | Operand(static_cast<int32_t>(kHoleNanUpper32))); |
| 544 | __ JumpIfDictionaryInPrototypeChain(receiver, elements_map, scratch, slow); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 545 | |
| 546 | __ bind(&fast_double_without_map_check); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 547 | __ StoreNumberToDoubleElements(value, key, elements, scratch, scratch2, |
| 548 | &transition_double_elements); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 549 | if (increment_length == kIncrementLength) { |
| 550 | // Add 1 to receiver->length. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 551 | __ Daddu(scratch, key, Operand(Smi::FromInt(1))); |
| 552 | __ sd(scratch, FieldMemOperand(receiver, JSArray::kLengthOffset)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 553 | } |
| 554 | __ Ret(); |
| 555 | |
| 556 | __ bind(&transition_smi_elements); |
| 557 | // Transition the array appropriately depending on the value type. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 558 | __ ld(scratch, FieldMemOperand(value, HeapObject::kMapOffset)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 559 | __ LoadRoot(at, Heap::kHeapNumberMapRootIndex); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 560 | __ Branch(&non_double_value, ne, scratch, Operand(at)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 561 | |
| 562 | // Value is a double. Transition FAST_SMI_ELEMENTS -> |
| 563 | // FAST_DOUBLE_ELEMENTS and complete the store. |
| 564 | __ LoadTransitionedArrayMapConditional( |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 565 | FAST_SMI_ELEMENTS, FAST_DOUBLE_ELEMENTS, receiver_map, scratch, slow); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 566 | AllocationSiteMode mode = |
| 567 | AllocationSite::GetMode(FAST_SMI_ELEMENTS, FAST_DOUBLE_ELEMENTS); |
| 568 | ElementsTransitionGenerator::GenerateSmiToDouble(masm, receiver, key, value, |
| 569 | receiver_map, mode, slow); |
| 570 | __ ld(elements, FieldMemOperand(receiver, JSObject::kElementsOffset)); |
| 571 | __ jmp(&fast_double_without_map_check); |
| 572 | |
| 573 | __ bind(&non_double_value); |
| 574 | // Value is not a double, FAST_SMI_ELEMENTS -> FAST_ELEMENTS |
| 575 | __ LoadTransitionedArrayMapConditional(FAST_SMI_ELEMENTS, FAST_ELEMENTS, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 576 | receiver_map, scratch, slow); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 577 | mode = AllocationSite::GetMode(FAST_SMI_ELEMENTS, FAST_ELEMENTS); |
| 578 | ElementsTransitionGenerator::GenerateMapChangeElementsTransition( |
| 579 | masm, receiver, key, value, receiver_map, mode, slow); |
| 580 | __ ld(elements, FieldMemOperand(receiver, JSObject::kElementsOffset)); |
| 581 | __ jmp(&finish_object_store); |
| 582 | |
| 583 | __ bind(&transition_double_elements); |
| 584 | // Elements are FAST_DOUBLE_ELEMENTS, but value is an Object that's not a |
| 585 | // HeapNumber. Make sure that the receiver is a Array with FAST_ELEMENTS and |
| 586 | // transition array from FAST_DOUBLE_ELEMENTS to FAST_ELEMENTS |
| 587 | __ LoadTransitionedArrayMapConditional(FAST_DOUBLE_ELEMENTS, FAST_ELEMENTS, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 588 | receiver_map, scratch, slow); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 589 | mode = AllocationSite::GetMode(FAST_DOUBLE_ELEMENTS, FAST_ELEMENTS); |
| 590 | ElementsTransitionGenerator::GenerateDoubleToObject( |
| 591 | masm, receiver, key, value, receiver_map, mode, slow); |
| 592 | __ ld(elements, FieldMemOperand(receiver, JSObject::kElementsOffset)); |
| 593 | __ jmp(&finish_object_store); |
| 594 | } |
| 595 | |
| 596 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 597 | void KeyedStoreIC::GenerateMegamorphic(MacroAssembler* masm, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 598 | LanguageMode language_mode) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 599 | // ---------- S t a t e -------------- |
| 600 | // -- a0 : value |
| 601 | // -- a1 : key |
| 602 | // -- a2 : receiver |
| 603 | // -- ra : return address |
| 604 | // ----------------------------------- |
| 605 | Label slow, fast_object, fast_object_grow; |
| 606 | Label fast_double, fast_double_grow; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 607 | Label array, extra, check_if_double_array, maybe_name_key, miss; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 608 | |
| 609 | // Register usage. |
| 610 | Register value = StoreDescriptor::ValueRegister(); |
| 611 | Register key = StoreDescriptor::NameRegister(); |
| 612 | Register receiver = StoreDescriptor::ReceiverRegister(); |
| 613 | DCHECK(value.is(a0)); |
| 614 | Register receiver_map = a3; |
| 615 | Register elements_map = a6; |
| 616 | Register elements = a7; // Elements array of the receiver. |
| 617 | // a4 and a5 are used as general scratch registers. |
| 618 | |
| 619 | // Check that the key is a smi. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 620 | __ JumpIfNotSmi(key, &maybe_name_key); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 621 | // Check that the object isn't a smi. |
| 622 | __ JumpIfSmi(receiver, &slow); |
| 623 | // Get the map of the object. |
| 624 | __ ld(receiver_map, FieldMemOperand(receiver, HeapObject::kMapOffset)); |
| 625 | // Check that the receiver does not require access checks and is not observed. |
| 626 | // The generic stub does not perform map checks or handle observed objects. |
| 627 | __ lbu(a4, FieldMemOperand(receiver_map, Map::kBitFieldOffset)); |
| 628 | __ And(a4, a4, |
| 629 | Operand(1 << Map::kIsAccessCheckNeeded | 1 << Map::kIsObserved)); |
| 630 | __ Branch(&slow, ne, a4, Operand(zero_reg)); |
| 631 | // Check if the object is a JS array or not. |
| 632 | __ lbu(a4, FieldMemOperand(receiver_map, Map::kInstanceTypeOffset)); |
| 633 | __ Branch(&array, eq, a4, Operand(JS_ARRAY_TYPE)); |
| 634 | // Check that the object is some kind of JSObject. |
| 635 | __ Branch(&slow, lt, a4, Operand(FIRST_JS_OBJECT_TYPE)); |
| 636 | |
| 637 | // Object case: Check key against length in the elements array. |
| 638 | __ ld(elements, FieldMemOperand(receiver, JSObject::kElementsOffset)); |
| 639 | // Check array bounds. Both the key and the length of FixedArray are smis. |
| 640 | __ ld(a4, FieldMemOperand(elements, FixedArray::kLengthOffset)); |
| 641 | __ Branch(&fast_object, lo, key, Operand(a4)); |
| 642 | |
| 643 | // Slow case, handle jump to runtime. |
| 644 | __ bind(&slow); |
| 645 | // Entry registers are intact. |
| 646 | // a0: value. |
| 647 | // a1: key. |
| 648 | // a2: receiver. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 649 | PropertyICCompiler::GenerateRuntimeSetProperty(masm, language_mode); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 650 | // Never returns to here. |
| 651 | |
| 652 | __ bind(&maybe_name_key); |
| 653 | __ ld(a4, FieldMemOperand(key, HeapObject::kMapOffset)); |
| 654 | __ lb(a4, FieldMemOperand(a4, Map::kInstanceTypeOffset)); |
| 655 | __ JumpIfNotUniqueNameInstanceType(a4, &slow); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 656 | |
| 657 | // The handlers in the stub cache expect a vector and slot. Since we won't |
| 658 | // change the IC from any downstream misses, a dummy vector can be used. |
| 659 | Register vector = VectorStoreICDescriptor::VectorRegister(); |
| 660 | Register slot = VectorStoreICDescriptor::SlotRegister(); |
| 661 | |
| 662 | DCHECK(!AreAliased(vector, slot, a5, a6, a7, t0)); |
| 663 | Handle<TypeFeedbackVector> dummy_vector = |
| 664 | TypeFeedbackVector::DummyVector(masm->isolate()); |
| 665 | int slot_index = dummy_vector->GetIndex( |
| 666 | FeedbackVectorSlot(TypeFeedbackVector::kDummyKeyedStoreICSlot)); |
| 667 | __ LoadRoot(vector, Heap::kDummyVectorRootIndex); |
| 668 | __ li(slot, Operand(Smi::FromInt(slot_index))); |
| 669 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 670 | Code::Flags flags = Code::RemoveTypeAndHolderFromFlags( |
| 671 | Code::ComputeHandlerFlags(Code::STORE_IC)); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 672 | masm->isolate()->stub_cache()->GenerateProbe(masm, Code::STORE_IC, flags, |
| 673 | receiver, key, a5, a6, a7, t0); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 674 | // Cache miss. |
| 675 | __ Branch(&miss); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 676 | |
| 677 | // Extra capacity case: Check if there is extra capacity to |
| 678 | // perform the store and update the length. Used for adding one |
| 679 | // element to the array by writing to array[array.length]. |
| 680 | __ bind(&extra); |
| 681 | // Condition code from comparing key and array length is still available. |
| 682 | // Only support writing to array[array.length]. |
| 683 | __ Branch(&slow, ne, key, Operand(a4)); |
| 684 | // Check for room in the elements backing store. |
| 685 | // Both the key and the length of FixedArray are smis. |
| 686 | __ ld(a4, FieldMemOperand(elements, FixedArray::kLengthOffset)); |
| 687 | __ Branch(&slow, hs, key, Operand(a4)); |
| 688 | __ ld(elements_map, FieldMemOperand(elements, HeapObject::kMapOffset)); |
| 689 | __ Branch(&check_if_double_array, ne, elements_map, |
| 690 | Heap::kFixedArrayMapRootIndex); |
| 691 | |
| 692 | __ jmp(&fast_object_grow); |
| 693 | |
| 694 | __ bind(&check_if_double_array); |
| 695 | __ Branch(&slow, ne, elements_map, Heap::kFixedDoubleArrayMapRootIndex); |
| 696 | __ jmp(&fast_double_grow); |
| 697 | |
| 698 | // Array case: Get the length and the elements array from the JS |
| 699 | // array. Check that the array is in fast mode (and writable); if it |
| 700 | // is the length is always a smi. |
| 701 | __ bind(&array); |
| 702 | __ ld(elements, FieldMemOperand(receiver, JSObject::kElementsOffset)); |
| 703 | |
| 704 | // Check the key against the length in the array. |
| 705 | __ ld(a4, FieldMemOperand(receiver, JSArray::kLengthOffset)); |
| 706 | __ Branch(&extra, hs, key, Operand(a4)); |
| 707 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 708 | KeyedStoreGenerateMegamorphicHelper( |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 709 | masm, &fast_object, &fast_double, &slow, kCheckMap, kDontIncrementLength, |
| 710 | value, key, receiver, receiver_map, elements_map, elements); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 711 | KeyedStoreGenerateMegamorphicHelper(masm, &fast_object_grow, |
| 712 | &fast_double_grow, &slow, kDontCheckMap, |
| 713 | kIncrementLength, value, key, receiver, |
| 714 | receiver_map, elements_map, elements); |
| 715 | |
| 716 | __ bind(&miss); |
| 717 | GenerateMiss(masm); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 718 | } |
| 719 | |
| 720 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 721 | static void StoreIC_PushArgs(MacroAssembler* masm) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 722 | __ Push(StoreDescriptor::ReceiverRegister(), StoreDescriptor::NameRegister(), |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 723 | StoreDescriptor::ValueRegister(), |
| 724 | VectorStoreICDescriptor::SlotRegister(), |
| 725 | VectorStoreICDescriptor::VectorRegister()); |
| 726 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 727 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 728 | |
| 729 | void KeyedStoreIC::GenerateMiss(MacroAssembler* masm) { |
| 730 | StoreIC_PushArgs(masm); |
| 731 | |
| 732 | __ TailCallRuntime(Runtime::kKeyedStoreIC_Miss); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 733 | } |
| 734 | |
| 735 | |
| 736 | void StoreIC::GenerateMegamorphic(MacroAssembler* masm) { |
| 737 | Register receiver = StoreDescriptor::ReceiverRegister(); |
| 738 | Register name = StoreDescriptor::NameRegister(); |
| 739 | DCHECK(receiver.is(a1)); |
| 740 | DCHECK(name.is(a2)); |
| 741 | DCHECK(StoreDescriptor::ValueRegister().is(a0)); |
| 742 | |
| 743 | // Get the receiver from the stack and probe the stub cache. |
| 744 | Code::Flags flags = Code::RemoveTypeAndHolderFromFlags( |
| 745 | Code::ComputeHandlerFlags(Code::STORE_IC)); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 746 | masm->isolate()->stub_cache()->GenerateProbe(masm, Code::STORE_IC, flags, |
| 747 | receiver, name, a3, a4, a5, a6); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 748 | |
| 749 | // Cache miss: Jump to runtime. |
| 750 | GenerateMiss(masm); |
| 751 | } |
| 752 | |
| 753 | |
| 754 | void StoreIC::GenerateMiss(MacroAssembler* masm) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 755 | StoreIC_PushArgs(masm); |
| 756 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 757 | // Perform tail call to the entry. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 758 | __ TailCallRuntime(Runtime::kStoreIC_Miss); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 759 | } |
| 760 | |
| 761 | |
| 762 | void StoreIC::GenerateNormal(MacroAssembler* masm) { |
| 763 | Label miss; |
| 764 | Register receiver = StoreDescriptor::ReceiverRegister(); |
| 765 | Register name = StoreDescriptor::NameRegister(); |
| 766 | Register value = StoreDescriptor::ValueRegister(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 767 | Register dictionary = a5; |
| 768 | DCHECK(!AreAliased( |
| 769 | value, receiver, name, VectorStoreICDescriptor::VectorRegister(), |
| 770 | VectorStoreICDescriptor::SlotRegister(), dictionary, a6, a7)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 771 | |
| 772 | __ ld(dictionary, FieldMemOperand(receiver, JSObject::kPropertiesOffset)); |
| 773 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 774 | GenerateDictionaryStore(masm, &miss, dictionary, name, value, a6, a7); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 775 | Counters* counters = masm->isolate()->counters(); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 776 | __ IncrementCounter(counters->ic_store_normal_hit(), 1, a6, a7); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 777 | __ Ret(); |
| 778 | |
| 779 | __ bind(&miss); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 780 | __ IncrementCounter(counters->ic_store_normal_miss(), 1, a6, a7); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 781 | GenerateMiss(masm); |
| 782 | } |
| 783 | |
| 784 | |
| 785 | #undef __ |
| 786 | |
| 787 | |
| 788 | Condition CompareIC::ComputeCondition(Token::Value op) { |
| 789 | switch (op) { |
| 790 | case Token::EQ_STRICT: |
| 791 | case Token::EQ: |
| 792 | return eq; |
| 793 | case Token::LT: |
| 794 | return lt; |
| 795 | case Token::GT: |
| 796 | return gt; |
| 797 | case Token::LTE: |
| 798 | return le; |
| 799 | case Token::GTE: |
| 800 | return ge; |
| 801 | default: |
| 802 | UNREACHABLE(); |
| 803 | return kNoCondition; |
| 804 | } |
| 805 | } |
| 806 | |
| 807 | |
| 808 | bool CompareIC::HasInlinedSmiCode(Address address) { |
| 809 | // The address of the instruction following the call. |
| 810 | Address andi_instruction_address = |
| 811 | address + Assembler::kCallTargetAddressOffset; |
| 812 | |
| 813 | // If the instruction following the call is not a andi at, rx, #yyy, nothing |
| 814 | // was inlined. |
| 815 | Instr instr = Assembler::instr_at(andi_instruction_address); |
| 816 | return Assembler::IsAndImmediate(instr) && |
| 817 | Assembler::GetRt(instr) == static_cast<uint32_t>(zero_reg.code()); |
| 818 | } |
| 819 | |
| 820 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 821 | void PatchInlinedSmiCode(Isolate* isolate, Address address, |
| 822 | InlinedSmiCheck check) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 823 | Address andi_instruction_address = |
| 824 | address + Assembler::kCallTargetAddressOffset; |
| 825 | |
| 826 | // If the instruction following the call is not a andi at, rx, #yyy, nothing |
| 827 | // was inlined. |
| 828 | Instr instr = Assembler::instr_at(andi_instruction_address); |
| 829 | if (!(Assembler::IsAndImmediate(instr) && |
| 830 | Assembler::GetRt(instr) == static_cast<uint32_t>(zero_reg.code()))) { |
| 831 | return; |
| 832 | } |
| 833 | |
| 834 | // The delta to the start of the map check instruction and the |
| 835 | // condition code uses at the patched jump. |
| 836 | int delta = Assembler::GetImmediate16(instr); |
| 837 | delta += Assembler::GetRs(instr) * kImm16Mask; |
| 838 | // If the delta is 0 the instruction is andi at, zero_reg, #0 which also |
| 839 | // signals that nothing was inlined. |
| 840 | if (delta == 0) { |
| 841 | return; |
| 842 | } |
| 843 | |
| 844 | if (FLAG_trace_ic) { |
| 845 | PrintF("[ patching ic at %p, andi=%p, delta=%d\n", address, |
| 846 | andi_instruction_address, delta); |
| 847 | } |
| 848 | |
| 849 | Address patch_address = |
| 850 | andi_instruction_address - delta * Instruction::kInstrSize; |
| 851 | Instr instr_at_patch = Assembler::instr_at(patch_address); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 852 | // This is patching a conditional "jump if not smi/jump if smi" site. |
| 853 | // Enabling by changing from |
| 854 | // andi at, rx, 0 |
| 855 | // Branch <target>, eq, at, Operand(zero_reg) |
| 856 | // to: |
| 857 | // andi at, rx, #kSmiTagMask |
| 858 | // Branch <target>, ne, at, Operand(zero_reg) |
| 859 | // and vice-versa to be disabled again. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 860 | CodePatcher patcher(isolate, patch_address, 2); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 861 | Register reg = Register::from_code(Assembler::GetRs(instr_at_patch)); |
| 862 | if (check == ENABLE_INLINED_SMI_CHECK) { |
| 863 | DCHECK(Assembler::IsAndImmediate(instr_at_patch)); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 864 | DCHECK_EQ(0u, Assembler::GetImmediate16(instr_at_patch)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 865 | patcher.masm()->andi(at, reg, kSmiTagMask); |
| 866 | } else { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 867 | DCHECK_EQ(check, DISABLE_INLINED_SMI_CHECK); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 868 | DCHECK(Assembler::IsAndImmediate(instr_at_patch)); |
| 869 | patcher.masm()->andi(at, reg, 0); |
| 870 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 871 | Instr branch_instr = |
| 872 | Assembler::instr_at(patch_address + Instruction::kInstrSize); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 873 | DCHECK(Assembler::IsBranch(branch_instr)); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 874 | |
| 875 | uint32_t opcode = Assembler::GetOpcodeField(branch_instr); |
| 876 | // Currently only the 'eq' and 'ne' cond values are supported and the simple |
| 877 | // branch instructions and their r6 variants (with opcode being the branch |
| 878 | // type). There are some special cases (see Assembler::IsBranch()) so |
| 879 | // extending this would be tricky. |
| 880 | DCHECK(opcode == BEQ || // BEQ |
| 881 | opcode == BNE || // BNE |
| 882 | opcode == POP10 || // BEQC |
| 883 | opcode == POP30 || // BNEC |
| 884 | opcode == POP66 || // BEQZC |
| 885 | opcode == POP76); // BNEZC |
| 886 | switch (opcode) { |
| 887 | case BEQ: |
| 888 | opcode = BNE; // change BEQ to BNE. |
| 889 | break; |
| 890 | case POP10: |
| 891 | opcode = POP30; // change BEQC to BNEC. |
| 892 | break; |
| 893 | case POP66: |
| 894 | opcode = POP76; // change BEQZC to BNEZC. |
| 895 | break; |
| 896 | case BNE: |
| 897 | opcode = BEQ; // change BNE to BEQ. |
| 898 | break; |
| 899 | case POP30: |
| 900 | opcode = POP10; // change BNEC to BEQC. |
| 901 | break; |
| 902 | case POP76: |
| 903 | opcode = POP66; // change BNEZC to BEQZC. |
| 904 | break; |
| 905 | default: |
| 906 | UNIMPLEMENTED(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 907 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 908 | patcher.ChangeBranchCondition(branch_instr, opcode); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 909 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 910 | } // namespace internal |
| 911 | } // namespace v8 |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 912 | |
| 913 | #endif // V8_TARGET_ARCH_MIPS64 |