1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
|
/*
* Copyright (C) 2012-2015 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
#include "DFGArrayMode.h"
#if ENABLE(DFG_JIT)
#include "ArrayPrototype.h"
#include "DFGAbstractValue.h"
#include "DFGGraph.h"
#include "JSCInlines.h"
namespace JSC { namespace DFG {
ArrayMode ArrayMode::fromObserved(const ConcurrentJITLocker& locker, ArrayProfile* profile, Array::Action action, bool makeSafe)
{
Array::Class nonArray;
if (profile->usesOriginalArrayStructures(locker))
nonArray = Array::OriginalNonArray;
else
nonArray = Array::NonArray;
ArrayModes observed = profile->observedArrayModes(locker);
switch (observed) {
case 0:
return ArrayMode(Array::Unprofiled);
case asArrayModes(NonArray):
if (action == Array::Write && !profile->mayInterceptIndexedAccesses(locker))
return ArrayMode(Array::SelectUsingArguments, nonArray, Array::OutOfBounds, Array::Convert);
return ArrayMode(Array::SelectUsingPredictions, nonArray).withSpeculationFromProfile(locker, profile, makeSafe);
case asArrayModes(ArrayWithUndecided):
if (action == Array::Write)
return ArrayMode(Array::SelectUsingArguments, Array::Array, Array::OutOfBounds, Array::Convert);
return ArrayMode(Array::Undecided, Array::Array, Array::OutOfBounds, Array::AsIs).withProfile(locker, profile, makeSafe);
case asArrayModes(NonArray) | asArrayModes(ArrayWithUndecided):
if (action == Array::Write && !profile->mayInterceptIndexedAccesses(locker))
return ArrayMode(Array::SelectUsingArguments, Array::PossiblyArray, Array::OutOfBounds, Array::Convert);
return ArrayMode(Array::SelectUsingPredictions).withSpeculationFromProfile(locker, profile, makeSafe);
case asArrayModes(NonArrayWithInt32):
return ArrayMode(Array::Int32, nonArray, Array::AsIs).withProfile(locker, profile, makeSafe);
case asArrayModes(ArrayWithInt32):
return ArrayMode(Array::Int32, Array::Array, Array::AsIs).withProfile(locker, profile, makeSafe);
case asArrayModes(NonArrayWithInt32) | asArrayModes(ArrayWithInt32):
return ArrayMode(Array::Int32, Array::PossiblyArray, Array::AsIs).withProfile(locker, profile, makeSafe);
case asArrayModes(NonArrayWithDouble):
return ArrayMode(Array::Double, nonArray, Array::AsIs).withProfile(locker, profile, makeSafe);
case asArrayModes(ArrayWithDouble):
return ArrayMode(Array::Double, Array::Array, Array::AsIs).withProfile(locker, profile, makeSafe);
case asArrayModes(NonArrayWithDouble) | asArrayModes(ArrayWithDouble):
return ArrayMode(Array::Double, Array::PossiblyArray, Array::AsIs).withProfile(locker, profile, makeSafe);
case asArrayModes(NonArrayWithContiguous):
return ArrayMode(Array::Contiguous, nonArray, Array::AsIs).withProfile(locker, profile, makeSafe);
case asArrayModes(ArrayWithContiguous):
return ArrayMode(Array::Contiguous, Array::Array, Array::AsIs).withProfile(locker, profile, makeSafe);
case asArrayModes(NonArrayWithContiguous) | asArrayModes(ArrayWithContiguous):
return ArrayMode(Array::Contiguous, Array::PossiblyArray, Array::AsIs).withProfile(locker, profile, makeSafe);
case asArrayModes(NonArrayWithArrayStorage):
return ArrayMode(Array::ArrayStorage, nonArray, Array::AsIs).withProfile(locker, profile, makeSafe);
case asArrayModes(NonArrayWithSlowPutArrayStorage):
case asArrayModes(NonArrayWithArrayStorage) | asArrayModes(NonArrayWithSlowPutArrayStorage):
return ArrayMode(Array::SlowPutArrayStorage, nonArray, Array::AsIs).withProfile(locker, profile, makeSafe);
case asArrayModes(ArrayWithArrayStorage):
return ArrayMode(Array::ArrayStorage, Array::Array, Array::AsIs).withProfile(locker, profile, makeSafe);
case asArrayModes(ArrayWithSlowPutArrayStorage):
case asArrayModes(ArrayWithArrayStorage) | asArrayModes(ArrayWithSlowPutArrayStorage):
return ArrayMode(Array::SlowPutArrayStorage, Array::Array, Array::AsIs).withProfile(locker, profile, makeSafe);
case asArrayModes(NonArrayWithArrayStorage) | asArrayModes(ArrayWithArrayStorage):
return ArrayMode(Array::ArrayStorage, Array::PossiblyArray, Array::AsIs).withProfile(locker, profile, makeSafe);
case asArrayModes(NonArrayWithSlowPutArrayStorage) | asArrayModes(ArrayWithSlowPutArrayStorage):
case asArrayModes(NonArrayWithArrayStorage) | asArrayModes(ArrayWithArrayStorage) | asArrayModes(NonArrayWithSlowPutArrayStorage) | asArrayModes(ArrayWithSlowPutArrayStorage):
return ArrayMode(Array::SlowPutArrayStorage, Array::PossiblyArray, Array::AsIs).withProfile(locker, profile, makeSafe);
case Int8ArrayMode:
return ArrayMode(Array::Int8Array, nonArray, Array::AsIs).withProfile(locker, profile, makeSafe);
case Int16ArrayMode:
return ArrayMode(Array::Int16Array, nonArray, Array::AsIs).withProfile(locker, profile, makeSafe);
case Int32ArrayMode:
return ArrayMode(Array::Int32Array, nonArray, Array::AsIs).withProfile(locker, profile, makeSafe);
case Uint8ArrayMode:
return ArrayMode(Array::Uint8Array, nonArray, Array::AsIs).withProfile(locker, profile, makeSafe);
case Uint8ClampedArrayMode:
return ArrayMode(Array::Uint8ClampedArray, nonArray, Array::AsIs).withProfile(locker, profile, makeSafe);
case Uint16ArrayMode:
return ArrayMode(Array::Uint16Array, nonArray, Array::AsIs).withProfile(locker, profile, makeSafe);
case Uint32ArrayMode:
return ArrayMode(Array::Uint32Array, nonArray, Array::AsIs).withProfile(locker, profile, makeSafe);
case Float32ArrayMode:
return ArrayMode(Array::Float32Array, nonArray, Array::AsIs).withProfile(locker, profile, makeSafe);
case Float64ArrayMode:
return ArrayMode(Array::Float64Array, nonArray, Array::AsIs).withProfile(locker, profile, makeSafe);
default:
if ((observed & asArrayModes(NonArray)) && profile->mayInterceptIndexedAccesses(locker))
return ArrayMode(Array::SelectUsingPredictions).withSpeculationFromProfile(locker, profile, makeSafe);
Array::Type type;
Array::Class arrayClass;
if (shouldUseSlowPutArrayStorage(observed))
type = Array::SlowPutArrayStorage;
else if (shouldUseFastArrayStorage(observed))
type = Array::ArrayStorage;
else if (shouldUseContiguous(observed))
type = Array::Contiguous;
else if (shouldUseDouble(observed))
type = Array::Double;
else if (shouldUseInt32(observed))
type = Array::Int32;
else
type = Array::SelectUsingArguments;
if (hasSeenArray(observed) && hasSeenNonArray(observed))
arrayClass = Array::PossiblyArray;
else if (hasSeenArray(observed))
arrayClass = Array::Array;
else if (hasSeenNonArray(observed))
arrayClass = nonArray;
else
arrayClass = Array::PossiblyArray;
return ArrayMode(type, arrayClass, Array::Convert).withProfile(locker, profile, makeSafe);
}
}
ArrayMode ArrayMode::refine(
Graph& graph, Node* node,
SpeculatedType base, SpeculatedType index, SpeculatedType value) const
{
if (!base || !index) {
// It can be that we had a legitimate arrayMode but no incoming predictions. That'll
// happen if we inlined code based on, say, a global variable watchpoint, but later
// realized that the callsite could not have possibly executed. It may be worthwhile
// to fix that, but for now I'm leaving it as-is.
return ArrayMode(Array::ForceExit);
}
if (!isInt32Speculation(index))
return ArrayMode(Array::Generic);
// If we had exited because of an exotic object behavior, then don't try to specialize.
if (graph.hasExitSite(node->origin.semantic, ExoticObjectMode))
return ArrayMode(Array::Generic);
// Note: our profiling currently doesn't give us good information in case we have
// an unlikely control flow path that sets the base to a non-cell value. Value
// profiling and prediction propagation will probably tell us that the value is
// either a cell or not, but that doesn't tell us which is more likely: that this
// is an array access on a cell (what we want and can optimize) or that the user is
// doing a crazy by-val access on a primitive (we can't easily optimize this and
// don't want to). So, for now, we assume that if the base is not a cell according
// to value profiling, but the array profile tells us something else, then we
// should just trust the array profile.
switch (type()) {
case Array::SelectUsingArguments:
if (!value)
return withType(Array::ForceExit);
if (isInt32Speculation(value))
return withTypeAndConversion(Array::Int32, Array::Convert);
if (isFullNumberSpeculation(value))
return withTypeAndConversion(Array::Double, Array::Convert);
return withTypeAndConversion(Array::Contiguous, Array::Convert);
case Array::Undecided: {
// If we have an OriginalArray and the JSArray prototype chain is sane,
// any indexed access always return undefined. We have a fast path for that.
JSGlobalObject* globalObject = graph.globalObjectFor(node->origin.semantic);
if (node->op() == GetByVal
&& arrayClass() == Array::OriginalArray
&& globalObject->arrayPrototypeChainIsSane()
&& !graph.hasExitSite(node->origin.semantic, OutOfBounds)) {
graph.watchpoints().addLazily(globalObject->arrayPrototype()->structure()->transitionWatchpointSet());
graph.watchpoints().addLazily(globalObject->objectPrototype()->structure()->transitionWatchpointSet());
return withSpeculation(Array::SaneChain);
}
return ArrayMode(Array::Generic);
}
case Array::Int32:
if (!value || isInt32Speculation(value))
return *this;
if (isFullNumberSpeculation(value))
return withTypeAndConversion(Array::Double, Array::Convert);
return withTypeAndConversion(Array::Contiguous, Array::Convert);
case Array::Double:
if (!value || isFullNumberSpeculation(value))
return *this;
return withTypeAndConversion(Array::Contiguous, Array::Convert);
case Array::Contiguous:
return *this;
case Array::Int8Array:
case Array::Int16Array:
case Array::Int32Array:
case Array::Uint8Array:
case Array::Uint8ClampedArray:
case Array::Uint16Array:
case Array::Uint32Array:
case Array::Float32Array:
case Array::Float64Array:
switch (node->op()) {
case PutByVal:
if (graph.hasExitSite(node->origin.semantic, OutOfBounds) || !isInBounds())
return withSpeculation(Array::OutOfBounds);
return withSpeculation(Array::InBounds);
default:
return withSpeculation(Array::InBounds);
}
return *this;
case Array::Unprofiled:
case Array::SelectUsingPredictions: {
base &= ~SpecOther;
if (isStringSpeculation(base))
return withType(Array::String);
if (isDirectArgumentsSpeculation(base) || isScopedArgumentsSpeculation(base)) {
// Handle out-of-bounds accesses as generic accesses.
if (graph.hasExitSite(node->origin.semantic, OutOfBounds) || !isInBounds())
return ArrayMode(Array::Generic);
if (isDirectArgumentsSpeculation(base))
return withType(Array::DirectArguments);
return withType(Array::ScopedArguments);
}
ArrayMode result;
switch (node->op()) {
case PutByVal:
if (graph.hasExitSite(node->origin.semantic, OutOfBounds) || !isInBounds())
result = withSpeculation(Array::OutOfBounds);
else
result = withSpeculation(Array::InBounds);
break;
default:
result = withSpeculation(Array::InBounds);
break;
}
if (isInt8ArraySpeculation(base))
return result.withType(Array::Int8Array);
if (isInt16ArraySpeculation(base))
return result.withType(Array::Int16Array);
if (isInt32ArraySpeculation(base))
return result.withType(Array::Int32Array);
if (isUint8ArraySpeculation(base))
return result.withType(Array::Uint8Array);
if (isUint8ClampedArraySpeculation(base))
return result.withType(Array::Uint8ClampedArray);
if (isUint16ArraySpeculation(base))
return result.withType(Array::Uint16Array);
if (isUint32ArraySpeculation(base))
return result.withType(Array::Uint32Array);
if (isFloat32ArraySpeculation(base))
return result.withType(Array::Float32Array);
if (isFloat64ArraySpeculation(base))
return result.withType(Array::Float64Array);
if (type() == Array::Unprofiled)
return ArrayMode(Array::ForceExit);
return ArrayMode(Array::Generic);
}
default:
return *this;
}
}
Structure* ArrayMode::originalArrayStructure(Graph& graph, const CodeOrigin& codeOrigin) const
{
JSGlobalObject* globalObject = graph.globalObjectFor(codeOrigin);
switch (arrayClass()) {
case Array::OriginalArray: {
switch (type()) {
case Array::Int32:
return globalObject->originalArrayStructureForIndexingType(ArrayWithInt32);
case Array::Double:
return globalObject->originalArrayStructureForIndexingType(ArrayWithDouble);
case Array::Contiguous:
return globalObject->originalArrayStructureForIndexingType(ArrayWithContiguous);
case Array::Undecided:
return globalObject->originalArrayStructureForIndexingType(ArrayWithUndecided);
case Array::ArrayStorage:
return globalObject->originalArrayStructureForIndexingType(ArrayWithArrayStorage);
default:
CRASH();
return 0;
}
}
case Array::OriginalNonArray: {
TypedArrayType type = typedArrayType();
if (type == NotTypedArray)
return 0;
return globalObject->typedArrayStructure(type);
}
default:
return 0;
}
}
Structure* ArrayMode::originalArrayStructure(Graph& graph, Node* node) const
{
return originalArrayStructure(graph, node->origin.semantic);
}
bool ArrayMode::alreadyChecked(Graph& graph, Node* node, const AbstractValue& value, IndexingType shape) const
{
switch (arrayClass()) {
case Array::OriginalArray: {
if (value.m_structure.isTop())
return false;
for (unsigned i = value.m_structure.size(); i--;) {
Structure* structure = value.m_structure[i];
if ((structure->indexingType() & IndexingShapeMask) != shape)
return false;
if (!(structure->indexingType() & IsArray))
return false;
if (!graph.globalObjectFor(node->origin.semantic)->isOriginalArrayStructure(structure))
return false;
}
return true;
}
case Array::Array: {
if (arrayModesAlreadyChecked(value.m_arrayModes, asArrayModes(shape | IsArray)))
return true;
if (value.m_structure.isTop())
return false;
for (unsigned i = value.m_structure.size(); i--;) {
Structure* structure = value.m_structure[i];
if ((structure->indexingType() & IndexingShapeMask) != shape)
return false;
if (!(structure->indexingType() & IsArray))
return false;
}
return true;
}
default: {
if (arrayModesAlreadyChecked(value.m_arrayModes, asArrayModes(shape) | asArrayModes(shape | IsArray)))
return true;
if (value.m_structure.isTop())
return false;
for (unsigned i = value.m_structure.size(); i--;) {
Structure* structure = value.m_structure[i];
if ((structure->indexingType() & IndexingShapeMask) != shape)
return false;
}
return true;
} }
}
bool ArrayMode::alreadyChecked(Graph& graph, Node* node, const AbstractValue& value) const
{
switch (type()) {
case Array::Generic:
return true;
case Array::ForceExit:
return false;
case Array::String:
return speculationChecked(value.m_type, SpecString);
case Array::Int32:
return alreadyChecked(graph, node, value, Int32Shape);
case Array::Double:
return alreadyChecked(graph, node, value, DoubleShape);
case Array::Contiguous:
return alreadyChecked(graph, node, value, ContiguousShape);
case Array::ArrayStorage:
return alreadyChecked(graph, node, value, ArrayStorageShape);
case Array::Undecided:
return alreadyChecked(graph, node, value, UndecidedShape);
case Array::SlowPutArrayStorage:
switch (arrayClass()) {
case Array::OriginalArray: {
CRASH();
return false;
}
case Array::Array: {
if (arrayModesAlreadyChecked(value.m_arrayModes, asArrayModes(ArrayWithArrayStorage) | asArrayModes(ArrayWithSlowPutArrayStorage)))
return true;
if (value.m_structure.isTop())
return false;
for (unsigned i = value.m_structure.size(); i--;) {
Structure* structure = value.m_structure[i];
if (!hasAnyArrayStorage(structure->indexingType()))
return false;
if (!(structure->indexingType() & IsArray))
return false;
}
return true;
}
default: {
if (arrayModesAlreadyChecked(value.m_arrayModes, asArrayModes(NonArrayWithArrayStorage) | asArrayModes(ArrayWithArrayStorage) | asArrayModes(NonArrayWithSlowPutArrayStorage) | asArrayModes(ArrayWithSlowPutArrayStorage)))
return true;
if (value.m_structure.isTop())
return false;
for (unsigned i = value.m_structure.size(); i--;) {
Structure* structure = value.m_structure[i];
if (!hasAnyArrayStorage(structure->indexingType()))
return false;
}
return true;
} }
case Array::DirectArguments:
return speculationChecked(value.m_type, SpecDirectArguments);
case Array::ScopedArguments:
return speculationChecked(value.m_type, SpecScopedArguments);
case Array::Int8Array:
return speculationChecked(value.m_type, SpecInt8Array);
case Array::Int16Array:
return speculationChecked(value.m_type, SpecInt16Array);
case Array::Int32Array:
return speculationChecked(value.m_type, SpecInt32Array);
case Array::Uint8Array:
return speculationChecked(value.m_type, SpecUint8Array);
case Array::Uint8ClampedArray:
return speculationChecked(value.m_type, SpecUint8ClampedArray);
case Array::Uint16Array:
return speculationChecked(value.m_type, SpecUint16Array);
case Array::Uint32Array:
return speculationChecked(value.m_type, SpecUint32Array);
case Array::Float32Array:
return speculationChecked(value.m_type, SpecFloat32Array);
case Array::Float64Array:
return speculationChecked(value.m_type, SpecFloat64Array);
case Array::AnyTypedArray:
return speculationChecked(value.m_type, SpecTypedArrayView);
case Array::SelectUsingPredictions:
case Array::Unprofiled:
case Array::SelectUsingArguments:
break;
}
CRASH();
return false;
}
const char* arrayTypeToString(Array::Type type)
{
switch (type) {
case Array::SelectUsingPredictions:
return "SelectUsingPredictions";
case Array::SelectUsingArguments:
return "SelectUsingArguments";
case Array::Unprofiled:
return "Unprofiled";
case Array::Generic:
return "Generic";
case Array::ForceExit:
return "ForceExit";
case Array::String:
return "String";
case Array::Undecided:
return "Undecided";
case Array::Int32:
return "Int32";
case Array::Double:
return "Double";
case Array::Contiguous:
return "Contiguous";
case Array::ArrayStorage:
return "ArrayStorage";
case Array::SlowPutArrayStorage:
return "SlowPutArrayStorage";
case Array::DirectArguments:
return "DirectArguments";
case Array::ScopedArguments:
return "ScopedArguments";
case Array::Int8Array:
return "Int8Array";
case Array::Int16Array:
return "Int16Array";
case Array::Int32Array:
return "Int32Array";
case Array::Uint8Array:
return "Uint8Array";
case Array::Uint8ClampedArray:
return "Uint8ClampedArray";
case Array::Uint16Array:
return "Uint16Array";
case Array::Uint32Array:
return "Uint32Array";
case Array::Float32Array:
return "Float32Array";
case Array::Float64Array:
return "Float64Array";
case Array::AnyTypedArray:
return "AnyTypedArray";
default:
// Better to return something then it is to crash. Remember, this method
// is being called from our main diagnostic tool, the IR dumper. It's like
// a stack trace. So if we get here then probably something has already
// gone wrong.
return "Unknown!";
}
}
const char* arrayClassToString(Array::Class arrayClass)
{
switch (arrayClass) {
case Array::Array:
return "Array";
case Array::OriginalArray:
return "OriginalArray";
case Array::NonArray:
return "NonArray";
case Array::OriginalNonArray:
return "OriginalNonArray";
case Array::PossiblyArray:
return "PossiblyArray";
default:
return "Unknown!";
}
}
const char* arraySpeculationToString(Array::Speculation speculation)
{
switch (speculation) {
case Array::SaneChain:
return "SaneChain";
case Array::InBounds:
return "InBounds";
case Array::ToHole:
return "ToHole";
case Array::OutOfBounds:
return "OutOfBounds";
default:
return "Unknown!";
}
}
const char* arrayConversionToString(Array::Conversion conversion)
{
switch (conversion) {
case Array::AsIs:
return "AsIs";
case Array::Convert:
return "Convert";
default:
return "Unknown!";
}
}
IndexingType toIndexingShape(Array::Type type)
{
switch (type) {
case Array::Int32:
return Int32Shape;
case Array::Double:
return DoubleShape;
case Array::Contiguous:
return ContiguousShape;
case Array::ArrayStorage:
return ArrayStorageShape;
case Array::SlowPutArrayStorage:
return SlowPutArrayStorageShape;
default:
return NoIndexingShape;
}
}
TypedArrayType toTypedArrayType(Array::Type type)
{
switch (type) {
case Array::Int8Array:
return TypeInt8;
case Array::Int16Array:
return TypeInt16;
case Array::Int32Array:
return TypeInt32;
case Array::Uint8Array:
return TypeUint8;
case Array::Uint8ClampedArray:
return TypeUint8Clamped;
case Array::Uint16Array:
return TypeUint16;
case Array::Uint32Array:
return TypeUint32;
case Array::Float32Array:
return TypeFloat32;
case Array::Float64Array:
return TypeFloat64;
case Array::AnyTypedArray:
RELEASE_ASSERT_NOT_REACHED();
return NotTypedArray;
default:
return NotTypedArray;
}
}
Array::Type toArrayType(TypedArrayType type)
{
switch (type) {
case TypeInt8:
return Array::Int8Array;
case TypeInt16:
return Array::Int16Array;
case TypeInt32:
return Array::Int32Array;
case TypeUint8:
return Array::Uint8Array;
case TypeUint8Clamped:
return Array::Uint8ClampedArray;
case TypeUint16:
return Array::Uint16Array;
case TypeUint32:
return Array::Uint32Array;
case TypeFloat32:
return Array::Float32Array;
case TypeFloat64:
return Array::Float64Array;
default:
return Array::Generic;
}
}
Array::Type refineTypedArrayType(Array::Type oldType, TypedArrayType newType)
{
if (oldType == Array::Generic)
return oldType;
Array::Type newArrayType = toArrayType(newType);
if (newArrayType == Array::Generic)
return newArrayType;
if (oldType != newArrayType)
return Array::AnyTypedArray;
return oldType;
}
bool permitsBoundsCheckLowering(Array::Type type)
{
switch (type) {
case Array::Int32:
case Array::Double:
case Array::Contiguous:
case Array::Int8Array:
case Array::Int16Array:
case Array::Int32Array:
case Array::Uint8Array:
case Array::Uint8ClampedArray:
case Array::Uint16Array:
case Array::Uint32Array:
case Array::Float32Array:
case Array::Float64Array:
case Array::AnyTypedArray:
return true;
default:
// These don't allow for bounds check lowering either because the bounds
// check involves something other than GetArrayLength (like ArrayStorage),
// or because the bounds check isn't a speculation (like String, sort of),
// or because the type implies an impure access.
return false;
}
}
bool ArrayMode::permitsBoundsCheckLowering() const
{
return DFG::permitsBoundsCheckLowering(type()) && isInBounds();
}
void ArrayMode::dump(PrintStream& out) const
{
out.print(type(), arrayClass(), speculation(), conversion());
}
} } // namespace JSC::DFG
namespace WTF {
void printInternal(PrintStream& out, JSC::DFG::Array::Type type)
{
out.print(JSC::DFG::arrayTypeToString(type));
}
void printInternal(PrintStream& out, JSC::DFG::Array::Class arrayClass)
{
out.print(JSC::DFG::arrayClassToString(arrayClass));
}
void printInternal(PrintStream& out, JSC::DFG::Array::Speculation speculation)
{
out.print(JSC::DFG::arraySpeculationToString(speculation));
}
void printInternal(PrintStream& out, JSC::DFG::Array::Conversion conversion)
{
out.print(JSC::DFG::arrayConversionToString(conversion));
}
} // namespace WTF
#endif // ENABLE(DFG_JIT)
|