OLD | NEW |
---|---|
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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/compiler/wasm-compiler.h" | 5 #include "src/compiler/wasm-compiler.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "src/assembler-inl.h" | 9 #include "src/assembler-inl.h" |
10 #include "src/base/platform/elapsed-timer.h" | 10 #include "src/base/platform/elapsed-timer.h" |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
172 return builder_->Control(); | 172 return builder_->Control(); |
173 } | 173 } |
174 | 174 |
175 // Add a check that traps if {node} is zero. | 175 // Add a check that traps if {node} is zero. |
176 Node* ZeroCheck64(wasm::TrapReason reason, Node* node, | 176 Node* ZeroCheck64(wasm::TrapReason reason, Node* node, |
177 wasm::WasmCodePosition position) { | 177 wasm::WasmCodePosition position) { |
178 return TrapIfEq64(reason, node, 0, position); | 178 return TrapIfEq64(reason, node, 0, position); |
179 } | 179 } |
180 | 180 |
181 Builtins::Name GetBuiltinIdForTrap(wasm::TrapReason reason) { | 181 Builtins::Name GetBuiltinIdForTrap(wasm::TrapReason reason) { |
182 if (builder_->module_ && !builder_->module_->instance->context.is_null()) { | 182 bool in_cctest = |
183 switch (reason) { | 183 !builder_->module_ || builder_->module_->instance->context.is_null(); |
184 #define TRAPREASON_TO_MESSAGE(name) \ | 184 if (in_cctest) { |
185 case wasm::k##name: \ | 185 // We use Builtins::builtin_count as a marker to tell the code generator |
186 return Builtins::kThrowWasm##name; | |
187 FOREACH_WASM_TRAPREASON(TRAPREASON_TO_MESSAGE) | |
188 #undef TRAPREASON_TO_MESSAGE | |
189 default: | |
190 UNREACHABLE(); | |
191 return Builtins::builtin_count; | |
192 } | |
193 } else { | |
194 // We use Runtime::kNumFunctions as a marker to tell the code generator | |
195 // to generate a call to a testing c-function instead of a runtime | 186 // to generate a call to a testing c-function instead of a runtime |
196 // function. This code should only be called from a cctest. | 187 // function. This code should only be called from a cctest. |
197 return Builtins::builtin_count; | 188 return Builtins::builtin_count; |
198 } | 189 } |
190 | |
191 switch (reason) { | |
192 #define TRAPREASON_TO_MESSAGE(name) \ | |
193 case wasm::k##name: \ | |
194 return Builtins::kThrowWasm##name; | |
195 FOREACH_WASM_TRAPREASON(TRAPREASON_TO_MESSAGE) | |
196 #undef TRAPREASON_TO_MESSAGE | |
197 default: | |
198 UNREACHABLE(); | |
199 return Builtins::builtin_count; | |
200 } | |
199 } | 201 } |
200 | 202 |
201 #if V8_TARGET_ARCH_X64 || V8_TARGET_ARCH_IA32 || V8_TARGET_ARCH_ARM || \ | 203 #if V8_TARGET_ARCH_X64 || V8_TARGET_ARCH_IA32 || V8_TARGET_ARCH_ARM || \ |
202 V8_TARGET_ARCH_ARM64 || V8_TARGET_ARCH_MIPS || V8_TARGET_ARCH_MIPS64 || \ | 204 V8_TARGET_ARCH_ARM64 || V8_TARGET_ARCH_MIPS || V8_TARGET_ARCH_MIPS64 || \ |
203 V8_TARGET_ARCH_PPC || V8_TARGET_ARCH_PPC64 || V8_TARGET_ARCH_S390 || \ | 205 V8_TARGET_ARCH_PPC || V8_TARGET_ARCH_PPC64 || V8_TARGET_ARCH_S390 || \ |
204 V8_TARGET_ARCH_S390X || V8_TARGET_ARCH_X87 | 206 V8_TARGET_ARCH_S390X || V8_TARGET_ARCH_X87 |
205 #define WASM_TRAP_IF_SUPPORTED | 207 #define WASM_TRAP_IF_SUPPORTED |
206 #endif | 208 #endif |
207 | 209 |
208 // Add a trap if {cond} is true. | 210 // Add a trap if {cond} is true. |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
360 jsgraph_(jsgraph), | 362 jsgraph_(jsgraph), |
361 module_(module_env), | 363 module_(module_env), |
362 signature_tables_(zone), | 364 signature_tables_(zone), |
363 function_tables_(zone), | 365 function_tables_(zone), |
364 function_table_sizes_(zone), | 366 function_table_sizes_(zone), |
365 cur_buffer_(def_buffer_), | 367 cur_buffer_(def_buffer_), |
366 cur_bufsize_(kDefaultBufferSize), | 368 cur_bufsize_(kDefaultBufferSize), |
367 trap_(new (zone) WasmTrapHelper(this)), | 369 trap_(new (zone) WasmTrapHelper(this)), |
368 sig_(sig), | 370 sig_(sig), |
369 source_position_table_(source_position_table) { | 371 source_position_table_(source_position_table) { |
370 for (size_t i = 0; i < sig->parameter_count(); i++) { | 372 for (size_t i = 0, e = sig->parameter_count(); i < e && !has_simd_; ++i) { |
titzer
2017/02/28 15:15:07
You could also just iterate from sig->parameter_co
Clemens Hammacher
2017/03/01 16:41:11
Done (iterate while > 0 and use "i-1" in the body,
| |
371 if (sig->GetParam(i) == wasm::kWasmS128) has_simd_ = true; | 373 if (sig->GetParam(i) == wasm::kWasmS128) has_simd_ = true; |
titzer
2017/02/28 15:15:07
And could also just break if found, instead of che
Clemens Hammacher
2017/03/01 16:41:11
I expect this to be eliminated by the compiler (SS
| |
372 } | 374 } |
373 for (size_t i = 0; i < sig->return_count(); i++) { | 375 for (size_t i = 0, e = sig->return_count(); i < e && !has_simd_; ++i) { |
374 if (sig->GetReturn(i) == wasm::kWasmS128) has_simd_ = true; | 376 if (sig->GetReturn(i) == wasm::kWasmS128) has_simd_ = true; |
375 } | 377 } |
376 DCHECK_NOT_NULL(jsgraph_); | 378 DCHECK_NOT_NULL(jsgraph_); |
377 } | 379 } |
378 | 380 |
379 Node* WasmGraphBuilder::Error() { return jsgraph()->Dead(); } | 381 Node* WasmGraphBuilder::Error() { return jsgraph()->Dead(); } |
380 | 382 |
381 Node* WasmGraphBuilder::Start(unsigned params) { | 383 Node* WasmGraphBuilder::Start(unsigned params) { |
382 Node* start = graph()->NewNode(jsgraph()->common()->Start(params)); | 384 Node* start = graph()->NewNode(jsgraph()->common()->Start(params)); |
383 graph()->SetStart(start); | 385 graph()->SetStart(start); |
(...skipping 2659 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3043 RelocInfo::WASM_MEMORY_REFERENCE); | 3045 RelocInfo::WASM_MEMORY_REFERENCE); |
3044 } | 3046 } |
3045 } | 3047 } |
3046 | 3048 |
3047 Node* WasmGraphBuilder::CurrentMemoryPages() { | 3049 Node* WasmGraphBuilder::CurrentMemoryPages() { |
3048 Runtime::FunctionId function_id = Runtime::kWasmMemorySize; | 3050 Runtime::FunctionId function_id = Runtime::kWasmMemorySize; |
3049 const Runtime::Function* function = Runtime::FunctionForId(function_id); | 3051 const Runtime::Function* function = Runtime::FunctionForId(function_id); |
3050 CallDescriptor* desc = Linkage::GetRuntimeCallDescriptor( | 3052 CallDescriptor* desc = Linkage::GetRuntimeCallDescriptor( |
3051 jsgraph()->zone(), function_id, function->nargs, Operator::kNoThrow, | 3053 jsgraph()->zone(), function_id, function->nargs, Operator::kNoThrow, |
3052 CallDescriptor::kNoFlags); | 3054 CallDescriptor::kNoFlags); |
3053 wasm::ModuleEnv* module = module_; | |
3054 Node* inputs[] = { | 3055 Node* inputs[] = { |
3055 jsgraph()->CEntryStubConstant(function->result_size), // C entry | 3056 jsgraph()->CEntryStubConstant(function->result_size), // C entry |
3056 jsgraph()->ExternalConstant( | 3057 jsgraph()->ExternalConstant( |
3057 ExternalReference(function_id, jsgraph()->isolate())), // ref | 3058 ExternalReference(function_id, jsgraph()->isolate())), // ref |
3058 jsgraph()->Int32Constant(function->nargs), // arity | 3059 jsgraph()->Int32Constant(function->nargs), // arity |
3059 jsgraph()->HeapConstant(module->instance->context), // context | 3060 jsgraph()->HeapConstant(module_->instance->context), // context |
3060 *effect_, | 3061 *effect_, |
3061 *control_}; | 3062 *control_}; |
3062 Node* call = graph()->NewNode(jsgraph()->common()->Call(desc), | 3063 Node* call = graph()->NewNode(jsgraph()->common()->Call(desc), |
3063 static_cast<int>(arraysize(inputs)), inputs); | 3064 static_cast<int>(arraysize(inputs)), inputs); |
3064 | 3065 |
3065 Node* result = BuildChangeSmiToInt32(call); | 3066 Node* result = BuildChangeSmiToInt32(call); |
3066 | 3067 |
3067 *effect_ = call; | 3068 *effect_ = call; |
3068 return result; | 3069 return result; |
3069 } | 3070 } |
(...skipping 1060 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4130 function_->code_end_offset - function_->code_start_offset, | 4131 function_->code_end_offset - function_->code_start_offset, |
4131 codegen_ms); | 4132 codegen_ms); |
4132 } | 4133 } |
4133 | 4134 |
4134 return code; | 4135 return code; |
4135 } | 4136 } |
4136 | 4137 |
4137 } // namespace compiler | 4138 } // namespace compiler |
4138 } // namespace internal | 4139 } // namespace internal |
4139 } // namespace v8 | 4140 } // namespace v8 |
OLD | NEW |