| OLD | NEW |
| 1 // Copyright 2016 the V8 project authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/v8.h" | 5 #include "src/v8.h" |
| 6 | 6 |
| 7 #include "src/wasm/asm-types.h" | 7 #include "src/wasm/asm-types.h" |
| 8 | 8 |
| 9 namespace v8 { | 9 namespace v8 { |
| 10 namespace internal { | 10 namespace internal { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 switch (avt->Bitset()) { | 22 switch (avt->Bitset()) { |
| 23 #define RETURN_TYPE_NAME(CamelName, string_name, number, parent_types) \ | 23 #define RETURN_TYPE_NAME(CamelName, string_name, number, parent_types) \ |
| 24 case AsmValueType::kAsm##CamelName: \ | 24 case AsmValueType::kAsm##CamelName: \ |
| 25 return string_name; | 25 return string_name; |
| 26 FOR_EACH_ASM_VALUE_TYPE_LIST(RETURN_TYPE_NAME) | 26 FOR_EACH_ASM_VALUE_TYPE_LIST(RETURN_TYPE_NAME) |
| 27 #undef RETURN_TYPE_NAME | 27 #undef RETURN_TYPE_NAME |
| 28 default: | 28 default: |
| 29 UNREACHABLE(); | 29 UNREACHABLE(); |
| 30 } | 30 } |
| 31 } | 31 } |
| 32 |
| 32 return this->AsCallableType()->Name(); | 33 return this->AsCallableType()->Name(); |
| 33 } | 34 } |
| 34 | 35 |
| 35 bool AsmType::IsExactly(AsmType* that) { | 36 bool AsmType::IsExactly(AsmType* that) { |
| 36 // TODO(jpp): maybe this can become this == that. | 37 // TODO(jpp): maybe this can become this == that. |
| 37 AsmValueType* avt = this->AsValueType(); | 38 AsmValueType* avt = this->AsValueType(); |
| 38 if (avt != nullptr) { | 39 if (avt != nullptr) { |
| 39 AsmValueType* tavt = that->AsValueType(); | 40 AsmValueType* tavt = that->AsValueType(); |
| 40 if (tavt == nullptr) { | 41 if (tavt == nullptr) { |
| 41 return false; | 42 return false; |
| 42 } | 43 } |
| 43 return avt->Bitset() == tavt->Bitset(); | 44 return avt->Bitset() == tavt->Bitset(); |
| 44 } | 45 } |
| 46 |
| 45 // TODO(jpp): is it useful to allow non-value types to be tested with | 47 // TODO(jpp): is it useful to allow non-value types to be tested with |
| 46 // IsExactly? | 48 // IsExactly? |
| 47 return that == this; | 49 return that == this; |
| 48 } | 50 } |
| 49 | 51 |
| 50 bool AsmType::IsA(AsmType* that) { | 52 bool AsmType::IsA(AsmType* that) { |
| 51 // IsA is used for querying inheritance relationships. Therefore it is only | 53 // IsA is used for querying inheritance relationships. Therefore it is only |
| 52 // meaningful for basic types. | 54 // meaningful for basic types. |
| 53 AsmValueType* tavt = that->AsValueType(); | 55 AsmValueType* tavt = that->AsValueType(); |
| 54 if (tavt != nullptr) { | 56 if (tavt != nullptr) { |
| 55 AsmValueType* avt = this->AsValueType(); | 57 AsmValueType* avt = this->AsValueType(); |
| 56 if (avt == nullptr) { | 58 if (avt == nullptr) { |
| 57 return false; | 59 return false; |
| 58 } | 60 } |
| 59 return (avt->Bitset() & tavt->Bitset()) == tavt->Bitset(); | 61 return (avt->Bitset() & tavt->Bitset()) == tavt->Bitset(); |
| 60 } | 62 } |
| 63 |
| 61 // TODO(jpp): is it useful to allow non-value types to be tested with IsA? | 64 // TODO(jpp): is it useful to allow non-value types to be tested with IsA? |
| 62 return that == this; | 65 return that == this; |
| 63 } | 66 } |
| 64 | 67 |
| 65 int32_t AsmType::ElementSizeInBytes() { | 68 int32_t AsmType::ElementSizeInBytes() { |
| 66 auto* value = AsValueType(); | 69 auto* value = AsValueType(); |
| 67 if (value == nullptr) { | 70 if (value == nullptr) { |
| 68 return AsmType::kNotHeapType; | 71 return AsmType::kNotHeapType; |
| 69 } | 72 } |
| 70 switch (value->Bitset()) { | 73 switch (value->Bitset()) { |
| 71 case AsmValueType::kAsmInt8Array: | 74 case AsmValueType::kAsmInt8Array: |
| 72 case AsmValueType::kAsmUint8Array: | 75 case AsmValueType::kAsmUint8Array: |
| 76 case AsmValueType::kAsmUint8ClampedArray: |
| 73 return 1; | 77 return 1; |
| 74 case AsmValueType::kAsmInt16Array: | 78 case AsmValueType::kAsmInt16Array: |
| 75 case AsmValueType::kAsmUint16Array: | 79 case AsmValueType::kAsmUint16Array: |
| 76 return 2; | 80 return 2; |
| 77 case AsmValueType::kAsmInt32Array: | 81 case AsmValueType::kAsmInt32Array: |
| 78 case AsmValueType::kAsmUint32Array: | 82 case AsmValueType::kAsmUint32Array: |
| 79 case AsmValueType::kAsmFloat32Array: | 83 case AsmValueType::kAsmFloat32Array: |
| 80 return 4; | 84 return 4; |
| 81 case AsmValueType::kAsmFloat64Array: | 85 case AsmValueType::kAsmFloat64Array: |
| 82 return 8; | 86 return 8; |
| 83 default: | 87 default: |
| 84 return AsmType::kNotHeapType; | 88 return AsmType::kNotHeapType; |
| 85 } | 89 } |
| 86 } | 90 } |
| 87 | 91 |
| 88 AsmType* AsmType::LoadType() { | 92 AsmType* AsmType::LoadType() { |
| 89 auto* value = AsValueType(); | 93 auto* value = AsValueType(); |
| 90 if (value == nullptr) { | 94 if (value == nullptr) { |
| 91 return AsmType::None(); | 95 return AsmType::None(); |
| 92 } | 96 } |
| 93 switch (value->Bitset()) { | 97 switch (value->Bitset()) { |
| 94 case AsmValueType::kAsmInt8Array: | 98 case AsmValueType::kAsmInt8Array: |
| 95 case AsmValueType::kAsmUint8Array: | 99 case AsmValueType::kAsmUint8Array: |
| 100 case AsmValueType::kAsmUint8ClampedArray: |
| 96 case AsmValueType::kAsmInt16Array: | 101 case AsmValueType::kAsmInt16Array: |
| 97 case AsmValueType::kAsmUint16Array: | 102 case AsmValueType::kAsmUint16Array: |
| 98 case AsmValueType::kAsmInt32Array: | 103 case AsmValueType::kAsmInt32Array: |
| 99 case AsmValueType::kAsmUint32Array: | 104 case AsmValueType::kAsmUint32Array: |
| 100 return AsmType::Intish(); | 105 return AsmType::Intish(); |
| 101 case AsmValueType::kAsmFloat32Array: | 106 case AsmValueType::kAsmFloat32Array: |
| 102 return AsmType::FloatQ(); | 107 return AsmType::FloatQ(); |
| 103 case AsmValueType::kAsmFloat64Array: | 108 case AsmValueType::kAsmFloat64Array: |
| 104 return AsmType::DoubleQ(); | 109 return AsmType::DoubleQ(); |
| 105 default: | 110 default: |
| 106 return AsmType::None(); | 111 return AsmType::None(); |
| 107 } | 112 } |
| 108 } | 113 } |
| 109 | 114 |
| 110 AsmType* AsmType::StoreType() { | 115 AsmType* AsmType::StoreType() { |
| 111 auto* value = AsValueType(); | 116 auto* value = AsValueType(); |
| 112 if (value == nullptr) { | 117 if (value == nullptr) { |
| 113 return AsmType::None(); | 118 return AsmType::None(); |
| 114 } | 119 } |
| 115 switch (value->Bitset()) { | 120 switch (value->Bitset()) { |
| 116 case AsmValueType::kAsmInt8Array: | 121 case AsmValueType::kAsmInt8Array: |
| 117 case AsmValueType::kAsmUint8Array: | 122 case AsmValueType::kAsmUint8Array: |
| 123 case AsmValueType::kAsmUint8ClampedArray: |
| 118 case AsmValueType::kAsmInt16Array: | 124 case AsmValueType::kAsmInt16Array: |
| 119 case AsmValueType::kAsmUint16Array: | 125 case AsmValueType::kAsmUint16Array: |
| 120 case AsmValueType::kAsmInt32Array: | 126 case AsmValueType::kAsmInt32Array: |
| 121 case AsmValueType::kAsmUint32Array: | 127 case AsmValueType::kAsmUint32Array: |
| 122 return AsmType::Intish(); | 128 return AsmType::Intish(); |
| 123 case AsmValueType::kAsmFloat32Array: | 129 case AsmValueType::kAsmFloat32Array: |
| 124 return AsmType::FloatishDoubleQ(); | 130 return AsmType::FloatishDoubleQ(); |
| 125 case AsmValueType::kAsmFloat64Array: | 131 case AsmValueType::kAsmFloat64Array: |
| 126 return AsmType::FloatQDoubleQ(); | 132 return AsmType::FloatQDoubleQ(); |
| 127 default: | 133 default: |
| 128 return AsmType::None(); | 134 return AsmType::None(); |
| 129 } | 135 } |
| 130 } | 136 } |
| 131 | 137 |
| 132 std::string AsmFunctionType::Name() { | 138 std::string AsmFunctionType::Name() { |
| 139 if (IsFroundType()) { |
| 140 return "fround"; |
| 141 } |
| 142 |
| 133 std::string ret; | 143 std::string ret; |
| 134 ret += "("; | 144 ret += "("; |
| 135 for (size_t ii = 0; ii < args_.size(); ++ii) { | 145 for (size_t ii = 0; ii < args_.size(); ++ii) { |
| 136 ret += args_[ii]->Name(); | 146 ret += args_[ii]->Name(); |
| 137 if (ii != args_.size() - 1) { | 147 if (ii != args_.size() - 1) { |
| 138 ret += ", "; | 148 ret += ", "; |
| 139 } | 149 } |
| 140 } | 150 } |
| 141 if (IsMinMaxType()) { | 151 if (IsMinMaxType()) { |
| 142 DCHECK_EQ(args_.size(), 2); | 152 DCHECK_EQ(args_.size(), 2); |
| 143 ret += "..."; | 153 ret += "..."; |
| 144 } | 154 } |
| 145 ret += ") -> "; | 155 ret += ") -> "; |
| 146 ret += return_type_->Name(); | 156 ret += return_type_->Name(); |
| 147 return ret; | 157 return ret; |
| 148 } | 158 } |
| 149 | 159 |
| 150 namespace { | 160 namespace { |
| 151 class AsmFroundType final : public AsmFunctionType { | 161 class AsmFroundType final : public AsmFunctionType { |
| 152 public: | 162 public: |
| 153 bool IsFroundType() const override { return true; } | 163 bool IsFroundType() const override { return true; } |
| 154 | 164 |
| 155 private: | 165 private: |
| 156 friend AsmType; | 166 friend AsmType; |
| 157 | 167 |
| 158 AsmFroundType(Zone* zone, AsmType* src) | 168 explicit AsmFroundType(Zone* zone) |
| 159 : AsmFunctionType(zone, AsmType::Float()) { | 169 : AsmFunctionType(zone, AsmType::Float()) {} |
| 160 AddArgument(src); | 170 |
| 161 } | 171 AsmType* ValidateCall(AsmType* function_type) override; |
| 162 }; | 172 }; |
| 163 } // namespace | 173 } // namespace |
| 164 | 174 |
| 165 AsmType* AsmType::FroundType(Zone* zone, AsmType* src) { | 175 AsmType* AsmType::FroundType(Zone* zone) { |
| 166 DCHECK(src->AsValueType() != nullptr); | 176 auto* Fround = new (zone) AsmFroundType(zone); |
| 167 auto* Fround = new (zone) AsmFroundType(zone, src); | |
| 168 return reinterpret_cast<AsmType*>(Fround); | 177 return reinterpret_cast<AsmType*>(Fround); |
| 169 } | 178 } |
| 170 | 179 |
| 180 AsmType* AsmFroundType::ValidateCall(AsmType* function_type) { |
| 181 auto* callable = function_type->AsFunctionType(); |
| 182 if (callable->Arguments().size() != 1) { |
| 183 return AsmType::None(); |
| 184 } |
| 185 |
| 186 auto* arg = callable->Arguments()[0]; |
| 187 if (!arg->IsA(AsmType::Floatish()) && !arg->IsA(AsmType::DoubleQ()) && |
| 188 !arg->IsA(AsmType::Signed()) && !arg->IsA(AsmType::Unsigned())) { |
| 189 return AsmType::None(); |
| 190 } |
| 191 |
| 192 return AsmType::Float(); |
| 193 } |
| 194 |
| 171 namespace { | 195 namespace { |
| 172 class AsmMinMaxType final : public AsmFunctionType { | 196 class AsmMinMaxType final : public AsmFunctionType { |
| 173 public: | 197 public: |
| 174 bool IsMinMaxType() const override { return true; } | 198 bool IsMinMaxType() const override { return true; } |
| 175 | 199 |
| 176 private: | 200 private: |
| 177 friend AsmType; | 201 friend AsmType; |
| 178 | 202 |
| 179 AsmMinMaxType(Zone* zone, AsmType* type) : AsmFunctionType(zone, type) { | 203 AsmMinMaxType(Zone* zone, AsmType* dest, AsmType* src) |
| 180 AddArgument(type); | 204 : AsmFunctionType(zone, dest) { |
| 181 AddArgument(type); | 205 AddArgument(src); |
| 206 AddArgument(src); |
| 182 } | 207 } |
| 183 | 208 |
| 184 AsmType* ValidateCall(AsmType* function_type) override { | 209 AsmType* ValidateCall(AsmType* function_type) override { |
| 185 auto* callable = function_type->AsFunctionType(); | 210 auto* callable = function_type->AsFunctionType(); |
| 186 if (callable == nullptr) { | 211 if (callable == nullptr) { |
| 187 return nullptr; | 212 return nullptr; |
| 188 } | 213 } |
| 189 | 214 |
| 190 if (!ReturnType()->IsExactly(callable->ReturnType())) { | 215 if (!ReturnType()->IsExactly(callable->ReturnType())) { |
| 191 return AsmType::None(); | 216 return AsmType::None(); |
| 192 } | 217 } |
| 193 | 218 |
| 194 if (callable->Arguments().size() < 2) { | 219 if (callable->Arguments().size() < 2) { |
| 195 return AsmType::None(); | 220 return AsmType::None(); |
| 196 } | 221 } |
| 197 | 222 |
| 198 for (size_t ii = 0; ii < Arguments().size(); ++ii) { | 223 for (size_t ii = 0; ii < Arguments().size(); ++ii) { |
| 199 if (!Arguments()[0]->IsExactly(callable->Arguments()[ii])) { | 224 if (!Arguments()[0]->IsExactly(callable->Arguments()[ii])) { |
| 200 return AsmType::None(); | 225 return AsmType::None(); |
| 201 } | 226 } |
| 202 } | 227 } |
| 203 | 228 |
| 204 return ReturnType(); | 229 return ReturnType(); |
| 205 } | 230 } |
| 206 }; | 231 }; |
| 207 } // namespace | 232 } // namespace |
| 208 | 233 |
| 209 AsmType* AsmType::MinMaxType(Zone* zone, AsmType* type) { | 234 AsmType* AsmType::MinMaxType(Zone* zone, AsmType* dest, AsmType* src) { |
| 210 DCHECK(type->AsValueType() != nullptr); | 235 DCHECK(dest->AsValueType() != nullptr); |
| 211 auto* MinMax = new (zone) AsmMinMaxType(zone, type); | 236 DCHECK(src->AsValueType() != nullptr); |
| 237 auto* MinMax = new (zone) AsmMinMaxType(zone, dest, src); |
| 212 return reinterpret_cast<AsmType*>(MinMax); | 238 return reinterpret_cast<AsmType*>(MinMax); |
| 213 } | 239 } |
| 214 | 240 |
| 215 AsmType* AsmFunctionType::ValidateCall(AsmType* function_type) { | 241 AsmType* AsmFunctionType::ValidateCall(AsmType* function_type) { |
| 216 auto* callable = function_type->AsFunctionType(); | 242 auto* callable = function_type->AsFunctionType(); |
| 217 if (callable == nullptr) { | 243 if (callable == nullptr) { |
| 218 return nullptr; | 244 return nullptr; |
| 219 } | 245 } |
| 220 | 246 |
| 221 if (!return_type_->IsExactly(callable->return_type_)) { | 247 if (!return_type_->IsExactly(callable->return_type_)) { |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 } | 292 } |
| 267 | 293 |
| 268 void AsmOverloadedFunctionType::AddOverload(AsmType* overload) { | 294 void AsmOverloadedFunctionType::AddOverload(AsmType* overload) { |
| 269 DCHECK(overload->AsFunctionType() != nullptr); | 295 DCHECK(overload->AsFunctionType() != nullptr); |
| 270 overloads_.push_back(overload); | 296 overloads_.push_back(overload); |
| 271 } | 297 } |
| 272 | 298 |
| 273 } // namespace wasm | 299 } // namespace wasm |
| 274 } // namespace internal | 300 } // namespace internal |
| 275 } // namespace v8 | 301 } // namespace v8 |
| OLD | NEW |