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) { |
| 172 int32_t trap_id; |
| 173 if (builder_->module_ && !builder_->module_->instance->context.is_null()) { |
| 174 trap_id = wasm::WasmOpcodes::TrapReasonToFunctionId(reason); |
| 175 } else { |
| 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 |
| 178 // function. This code should only be called from a cctest. |
| 179 trap_id = Runtime::kNumFunctions; |
| 180 } |
| 181 return trap_id; |
| 182 } |
| 183 |
| 184 #if V8_TARGET_ARCH_X64 |
| 185 #define WASM_TRAP_IF_SUPPORTED |
| 186 #endif |
| 187 |
171 // Add a trap if {cond} is true. | 188 // Add a trap if {cond} is true. |
172 void AddTrapIfTrue(wasm::TrapReason reason, Node* cond, | 189 void AddTrapIfTrue(wasm::TrapReason reason, Node* cond, |
173 wasm::WasmCodePosition position) { | 190 wasm::WasmCodePosition position) { |
174 AddTrapIf(reason, cond, true, position); | 191 #ifdef WASM_TRAP_IF_SUPPORTED |
| 192 if (FLAG_wasm_trap_if) { |
| 193 int32_t trap_id = GetFunctionIdForTrap(reason); |
| 194 Node* node = graph()->NewNode(common()->TrapIf(trap_id), cond, |
| 195 builder_->Effect(), builder_->Control()); |
| 196 *builder_->control_ = node; |
| 197 builder_->SetSourcePosition(node, position); |
| 198 return; |
| 199 } |
| 200 #endif // V8_TARGET_ARCH_X64 |
| 201 BuildTrapIf(reason, cond, true, position); |
175 } | 202 } |
176 | 203 |
177 // Add a trap if {cond} is false. | 204 // Add a trap if {cond} is false. |
178 void AddTrapIfFalse(wasm::TrapReason reason, Node* cond, | 205 void AddTrapIfFalse(wasm::TrapReason reason, Node* cond, |
179 wasm::WasmCodePosition position) { | 206 wasm::WasmCodePosition position) { |
180 AddTrapIf(reason, cond, false, position); | 207 #ifdef WASM_TRAP_IF_SUPPORTED |
| 208 if (FLAG_wasm_trap_if) { |
| 209 int32_t trap_id = GetFunctionIdForTrap(reason); |
| 210 |
| 211 Node* node = graph()->NewNode(common()->TrapUnless(trap_id), cond, |
| 212 builder_->Effect(), builder_->Control()); |
| 213 *builder_->control_ = node; |
| 214 builder_->SetSourcePosition(node, position); |
| 215 return; |
| 216 } |
| 217 #endif // V8_TARGET_ARCH_X64 |
| 218 |
| 219 BuildTrapIf(reason, cond, false, position); |
181 } | 220 } |
182 | 221 |
183 // 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}. |
184 void AddTrapIf(wasm::TrapReason reason, Node* cond, bool iftrue, | 223 void BuildTrapIf(wasm::TrapReason reason, Node* cond, bool iftrue, |
185 wasm::WasmCodePosition position) { | 224 wasm::WasmCodePosition position) { |
186 Node** effect_ptr = builder_->effect_; | 225 Node** effect_ptr = builder_->effect_; |
187 Node** control_ptr = builder_->control_; | 226 Node** control_ptr = builder_->control_; |
188 Node* before = *effect_ptr; | 227 Node* before = *effect_ptr; |
189 BranchHint hint = iftrue ? BranchHint::kFalse : BranchHint::kTrue; | 228 BranchHint hint = iftrue ? BranchHint::kFalse : BranchHint::kTrue; |
190 Node* branch = graph()->NewNode(common()->Branch(hint), cond, *control_ptr); | 229 Node* branch = graph()->NewNode(common()->Branch(hint), cond, *control_ptr); |
191 Node* if_true = graph()->NewNode(common()->IfTrue(), branch); | 230 Node* if_true = graph()->NewNode(common()->IfTrue(), branch); |
192 Node* if_false = graph()->NewNode(common()->IfFalse(), branch); | 231 Node* if_false = graph()->NewNode(common()->IfFalse(), branch); |
193 | 232 |
194 *control_ptr = iftrue ? if_true : if_false; | 233 *control_ptr = iftrue ? if_true : if_false; |
195 ConnectTrap(reason, position); | 234 ConnectTrap(reason, position); |
(...skipping 1888 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2084 if (jsgraph()->machine()->Is32()) { | 2123 if (jsgraph()->machine()->Is32()) { |
2085 return BuildDiv64Call( | 2124 return BuildDiv64Call( |
2086 left, right, ExternalReference::wasm_int64_mod(jsgraph()->isolate()), | 2125 left, right, ExternalReference::wasm_int64_mod(jsgraph()->isolate()), |
2087 MachineType::Int64(), wasm::kTrapRemByZero, position); | 2126 MachineType::Int64(), wasm::kTrapRemByZero, position); |
2088 } | 2127 } |
2089 trap_->ZeroCheck64(wasm::kTrapRemByZero, right, position); | 2128 trap_->ZeroCheck64(wasm::kTrapRemByZero, right, position); |
2090 Diamond d(jsgraph()->graph(), jsgraph()->common(), | 2129 Diamond d(jsgraph()->graph(), jsgraph()->common(), |
2091 graph()->NewNode(jsgraph()->machine()->Word64Equal(), right, | 2130 graph()->NewNode(jsgraph()->machine()->Word64Equal(), right, |
2092 jsgraph()->Int64Constant(-1))); | 2131 jsgraph()->Int64Constant(-1))); |
2093 | 2132 |
| 2133 d.Chain(*control_); |
| 2134 |
2094 Node* rem = graph()->NewNode(jsgraph()->machine()->Int64Mod(), left, right, | 2135 Node* rem = graph()->NewNode(jsgraph()->machine()->Int64Mod(), left, right, |
2095 d.if_false); | 2136 d.if_false); |
2096 | 2137 |
2097 return d.Phi(MachineRepresentation::kWord64, jsgraph()->Int64Constant(0), | 2138 return d.Phi(MachineRepresentation::kWord64, jsgraph()->Int64Constant(0), |
2098 rem); | 2139 rem); |
2099 } | 2140 } |
2100 | 2141 |
2101 Node* WasmGraphBuilder::BuildI64DivU(Node* left, Node* right, | 2142 Node* WasmGraphBuilder::BuildI64DivU(Node* left, Node* right, |
2102 wasm::WasmCodePosition position) { | 2143 wasm::WasmCodePosition position) { |
2103 if (jsgraph()->machine()->Is32()) { | 2144 if (jsgraph()->machine()->Is32()) { |
(...skipping 1507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3611 Smi::FromInt(instruction.instr_offset)); | 3652 Smi::FromInt(instruction.instr_offset)); |
3612 fn_protected->set(Code::kTrapDataSize * i + Code::kTrapLandingOffset, | 3653 fn_protected->set(Code::kTrapDataSize * i + Code::kTrapLandingOffset, |
3613 Smi::FromInt(instruction.landing_offset)); | 3654 Smi::FromInt(instruction.landing_offset)); |
3614 } | 3655 } |
3615 return fn_protected; | 3656 return fn_protected; |
3616 } | 3657 } |
3617 | 3658 |
3618 } // namespace compiler | 3659 } // namespace compiler |
3619 } // namespace internal | 3660 } // namespace internal |
3620 } // namespace v8 | 3661 } // namespace v8 |
OLD | NEW |