ByValInfo.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /*
  2. * Copyright (C) 2012 Apple Inc. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  7. * 1. Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * 2. Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. *
  13. * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
  14. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  15. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  16. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
  17. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  18. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  19. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  20. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  21. * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  22. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  23. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24. */
  25. #ifndef ByValInfo_h
  26. #define ByValInfo_h
  27. #include <wtf/Platform.h>
  28. #if ENABLE(JIT)
  29. #include "ClassInfo.h"
  30. #include "CodeLocation.h"
  31. #include "IndexingType.h"
  32. #include "JITStubRoutine.h"
  33. #include "Structure.h"
  34. namespace JSC {
  35. enum JITArrayMode {
  36. JITInt32,
  37. JITDouble,
  38. JITContiguous,
  39. JITArrayStorage,
  40. JITInt8Array,
  41. JITInt16Array,
  42. JITInt32Array,
  43. JITUint8Array,
  44. JITUint8ClampedArray,
  45. JITUint16Array,
  46. JITUint32Array,
  47. JITFloat32Array,
  48. JITFloat64Array
  49. };
  50. inline bool isOptimizableIndexingType(IndexingType indexingType)
  51. {
  52. switch (indexingType) {
  53. case ALL_INT32_INDEXING_TYPES:
  54. case ALL_DOUBLE_INDEXING_TYPES:
  55. case ALL_CONTIGUOUS_INDEXING_TYPES:
  56. case ARRAY_WITH_ARRAY_STORAGE_INDEXING_TYPES:
  57. return true;
  58. default:
  59. return false;
  60. }
  61. }
  62. inline bool hasOptimizableIndexingForClassInfo(const ClassInfo* classInfo)
  63. {
  64. return classInfo->typedArrayStorageType != TypedArrayNone;
  65. }
  66. inline bool hasOptimizableIndexing(Structure* structure)
  67. {
  68. return isOptimizableIndexingType(structure->indexingType())
  69. || hasOptimizableIndexingForClassInfo(structure->classInfo());
  70. }
  71. inline JITArrayMode jitArrayModeForIndexingType(IndexingType indexingType)
  72. {
  73. switch (indexingType) {
  74. case ALL_INT32_INDEXING_TYPES:
  75. return JITInt32;
  76. case ALL_DOUBLE_INDEXING_TYPES:
  77. return JITDouble;
  78. case ALL_CONTIGUOUS_INDEXING_TYPES:
  79. return JITContiguous;
  80. case ARRAY_WITH_ARRAY_STORAGE_INDEXING_TYPES:
  81. return JITArrayStorage;
  82. default:
  83. CRASH();
  84. return JITContiguous;
  85. }
  86. }
  87. inline JITArrayMode jitArrayModeForClassInfo(const ClassInfo* classInfo)
  88. {
  89. switch (classInfo->typedArrayStorageType) {
  90. case TypedArrayInt8:
  91. return JITInt8Array;
  92. case TypedArrayInt16:
  93. return JITInt16Array;
  94. case TypedArrayInt32:
  95. return JITInt32Array;
  96. case TypedArrayUint8:
  97. return JITUint8Array;
  98. case TypedArrayUint8Clamped:
  99. return JITUint8ClampedArray;
  100. case TypedArrayUint16:
  101. return JITUint16Array;
  102. case TypedArrayUint32:
  103. return JITUint32Array;
  104. case TypedArrayFloat32:
  105. return JITFloat32Array;
  106. case TypedArrayFloat64:
  107. return JITFloat64Array;
  108. default:
  109. CRASH();
  110. return JITContiguous;
  111. }
  112. }
  113. inline JITArrayMode jitArrayModeForStructure(Structure* structure)
  114. {
  115. if (isOptimizableIndexingType(structure->indexingType()))
  116. return jitArrayModeForIndexingType(structure->indexingType());
  117. ASSERT(hasOptimizableIndexingForClassInfo(structure->classInfo()));
  118. return jitArrayModeForClassInfo(structure->classInfo());
  119. }
  120. struct ByValInfo {
  121. ByValInfo() { }
  122. ByValInfo(unsigned bytecodeIndex, CodeLocationJump badTypeJump, JITArrayMode arrayMode, int16_t badTypeJumpToDone, int16_t returnAddressToSlowPath)
  123. : bytecodeIndex(bytecodeIndex)
  124. , badTypeJump(badTypeJump)
  125. , arrayMode(arrayMode)
  126. , badTypeJumpToDone(badTypeJumpToDone)
  127. , returnAddressToSlowPath(returnAddressToSlowPath)
  128. , slowPathCount(0)
  129. {
  130. }
  131. unsigned bytecodeIndex;
  132. CodeLocationJump badTypeJump;
  133. JITArrayMode arrayMode; // The array mode that was baked into the inline JIT code.
  134. int16_t badTypeJumpToDone;
  135. int16_t returnAddressToSlowPath;
  136. unsigned slowPathCount;
  137. RefPtr<JITStubRoutine> stubRoutine;
  138. };
  139. inline unsigned getByValInfoBytecodeIndex(ByValInfo* info)
  140. {
  141. return info->bytecodeIndex;
  142. }
  143. } // namespace JSC
  144. #endif // ENABLE(JIT)
  145. #endif // ByValInfo_h