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/isolate-inl.h" | 9 #include "src/isolate-inl.h" |
10 | 10 |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 position); | 161 position); |
162 return builder_->Control(); | 162 return builder_->Control(); |
163 } | 163 } |
164 | 164 |
165 // Add a check that traps if {node} is zero. | 165 // Add a check that traps if {node} is zero. |
166 Node* ZeroCheck64(wasm::TrapReason reason, Node* node, | 166 Node* ZeroCheck64(wasm::TrapReason reason, Node* node, |
167 wasm::WasmCodePosition position) { | 167 wasm::WasmCodePosition position) { |
168 return TrapIfEq64(reason, node, 0, position); | 168 return TrapIfEq64(reason, node, 0, position); |
169 } | 169 } |
170 | 170 |
171 int32_t GetFunctionIdForTrap(wasm::TrapReason reason) { | 171 Runtime::FunctionId GetFunctionIdForTrap(wasm::TrapReason reason) { |
172 int32_t trap_id; | 172 Runtime::FunctionId trap_id; |
173 if (builder_->module_ && !builder_->module_->instance->context.is_null()) { | 173 if (builder_->module_ && !builder_->module_->instance->context.is_null()) { |
174 trap_id = wasm::WasmOpcodes::TrapReasonToFunctionId(reason); | 174 trap_id = wasm::WasmOpcodes::TrapReasonToFunctionId(reason); |
175 } else { | 175 } else { |
176 // We use Runtime::kNumFunctions as a marker to tell the code generator | 176 // We use Runtime::kNumFunctions as a marker to tell the code generator |
177 // to generate a call to a testing c-function instead of a runtime | 177 // to generate a call to a testing c-function instead of a runtime |
178 // function. This code should only be called from a cctest. | 178 // function. This code should only be called from a cctest. |
179 trap_id = Runtime::kNumFunctions; | 179 trap_id = Runtime::kNumFunctions; |
180 } | 180 } |
181 return trap_id; | 181 return trap_id; |
182 } | 182 } |
183 | 183 |
184 #if V8_TARGET_ARCH_X64 | 184 #if V8_TARGET_ARCH_X64 || V8_TARGET_ARCH_IA32 |
185 #define WASM_TRAP_IF_SUPPORTED | 185 #define WASM_TRAP_IF_SUPPORTED |
186 #endif | 186 #endif |
187 | 187 |
188 // Add a trap if {cond} is true. | 188 // Add a trap if {cond} is true. |
189 void AddTrapIfTrue(wasm::TrapReason reason, Node* cond, | 189 void AddTrapIfTrue(wasm::TrapReason reason, Node* cond, |
190 wasm::WasmCodePosition position) { | 190 wasm::WasmCodePosition position) { |
191 #ifdef WASM_TRAP_IF_SUPPORTED | 191 #ifdef WASM_TRAP_IF_SUPPORTED |
192 if (FLAG_wasm_trap_if) { | 192 if (FLAG_wasm_trap_if) { |
193 int32_t trap_id = GetFunctionIdForTrap(reason); | 193 int32_t trap_id = GetFunctionIdForTrap(reason); |
194 Node* node = graph()->NewNode(common()->TrapIf(trap_id), cond, | 194 Node* node = graph()->NewNode(common()->TrapIf(trap_id), cond, |
195 builder_->Effect(), builder_->Control()); | 195 builder_->Effect(), builder_->Control()); |
196 *builder_->control_ = node; | 196 *builder_->control_ = node; |
197 builder_->SetSourcePosition(node, position); | 197 builder_->SetSourcePosition(node, position); |
198 return; | 198 return; |
199 } | 199 } |
200 #endif // V8_TARGET_ARCH_X64 | 200 #endif // WASM_TRAP_IF_SUPPORTED |
201 BuildTrapIf(reason, cond, true, position); | 201 BuildTrapIf(reason, cond, true, position); |
202 } | 202 } |
203 | 203 |
204 // Add a trap if {cond} is false. | 204 // Add a trap if {cond} is false. |
205 void AddTrapIfFalse(wasm::TrapReason reason, Node* cond, | 205 void AddTrapIfFalse(wasm::TrapReason reason, Node* cond, |
206 wasm::WasmCodePosition position) { | 206 wasm::WasmCodePosition position) { |
207 #ifdef WASM_TRAP_IF_SUPPORTED | 207 #ifdef WASM_TRAP_IF_SUPPORTED |
208 if (FLAG_wasm_trap_if) { | 208 if (FLAG_wasm_trap_if) { |
209 int32_t trap_id = GetFunctionIdForTrap(reason); | 209 int32_t trap_id = GetFunctionIdForTrap(reason); |
210 | 210 |
211 Node* node = graph()->NewNode(common()->TrapUnless(trap_id), cond, | 211 Node* node = graph()->NewNode(common()->TrapUnless(trap_id), cond, |
212 builder_->Effect(), builder_->Control()); | 212 builder_->Effect(), builder_->Control()); |
213 *builder_->control_ = node; | 213 *builder_->control_ = node; |
214 builder_->SetSourcePosition(node, position); | 214 builder_->SetSourcePosition(node, position); |
215 return; | 215 return; |
216 } | 216 } |
217 #endif // V8_TARGET_ARCH_X64 | 217 #endif // WASM_TRAP_IF_SUPPORTED |
218 | 218 |
219 BuildTrapIf(reason, cond, false, position); | 219 BuildTrapIf(reason, cond, false, position); |
220 } | 220 } |
221 | 221 |
222 // Add a trap if {cond} is true or false according to {iftrue}. | 222 // Add a trap if {cond} is true or false according to {iftrue}. |
223 void BuildTrapIf(wasm::TrapReason reason, Node* cond, bool iftrue, | 223 void BuildTrapIf(wasm::TrapReason reason, Node* cond, bool iftrue, |
224 wasm::WasmCodePosition position) { | 224 wasm::WasmCodePosition position) { |
225 Node** effect_ptr = builder_->effect_; | 225 Node** effect_ptr = builder_->effect_; |
226 Node** control_ptr = builder_->control_; | 226 Node** control_ptr = builder_->control_; |
227 Node* before = *effect_ptr; | 227 Node* before = *effect_ptr; |
(...skipping 3424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3652 Smi::FromInt(instruction.instr_offset)); | 3652 Smi::FromInt(instruction.instr_offset)); |
3653 fn_protected->set(Code::kTrapDataSize * i + Code::kTrapLandingOffset, | 3653 fn_protected->set(Code::kTrapDataSize * i + Code::kTrapLandingOffset, |
3654 Smi::FromInt(instruction.landing_offset)); | 3654 Smi::FromInt(instruction.landing_offset)); |
3655 } | 3655 } |
3656 return fn_protected; | 3656 return fn_protected; |
3657 } | 3657 } |
3658 | 3658 |
3659 } // namespace compiler | 3659 } // namespace compiler |
3660 } // namespace internal | 3660 } // namespace internal |
3661 } // namespace v8 | 3661 } // namespace v8 |
OLD | NEW |