Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Side by Side Diff: src/compiler/wasm-compiler.cc

Issue 2562393002: [wasm] Introduce the TrapIf and TrapUnless operators to generate trap code. (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
171 // Add a trap if {cond} is true. 184 // Add a trap if {cond} is true.
172 void AddTrapIfTrue(wasm::TrapReason reason, Node* cond, 185 void AddTrapIfTrue(wasm::TrapReason reason, Node* cond,
173 wasm::WasmCodePosition position) { 186 wasm::WasmCodePosition position) {
187 #if V8_TARGET_ARCH_X64
titzer 2016/12/12 14:21:33 Can you introduce another preprocessor definition,
ahaas 2016/12/13 12:38:59 Done.
188 if (FLAG_wasm_trap_if) {
189 int32_t trap_id = GetFunctionIdForTrap(reason);
190 Node* node = graph()->NewNode(common()->TrapIf(trap_id), cond,
191 builder_->Effect(), builder_->Control());
192 *builder_->control_ = node;
193 builder_->SetSourcePosition(node, position);
194 return;
195 }
196 #endif // V8_TARGET_ARCH_X64
174 AddTrapIf(reason, cond, true, position); 197 AddTrapIf(reason, cond, true, position);
titzer 2016/12/12 14:21:33 Can we rename this internal function to BuildTrapI
ahaas 2016/12/13 12:38:59 Done.
175 } 198 }
176 199
177 // Add a trap if {cond} is false. 200 // Add a trap if {cond} is false.
178 void AddTrapIfFalse(wasm::TrapReason reason, Node* cond, 201 void AddTrapIfFalse(wasm::TrapReason reason, Node* cond,
179 wasm::WasmCodePosition position) { 202 wasm::WasmCodePosition position) {
203 #if V8_TARGET_ARCH_X64
204 if (FLAG_wasm_trap_if) {
205 int32_t trap_id = GetFunctionIdForTrap(reason);
206
207 Node* node = graph()->NewNode(common()->TrapUnless(trap_id), cond,
208 builder_->Effect(), builder_->Control());
209 *builder_->control_ = node;
210 builder_->SetSourcePosition(node, position);
211 return;
212 }
213 #endif // V8_TARGET_ARCH_X64
214
180 AddTrapIf(reason, cond, false, position); 215 AddTrapIf(reason, cond, false, position);
181 } 216 }
182 217
183 // Add a trap if {cond} is true or false according to {iftrue}. 218 // Add a trap if {cond} is true or false according to {iftrue}.
184 void AddTrapIf(wasm::TrapReason reason, Node* cond, bool iftrue, 219 void AddTrapIf(wasm::TrapReason reason, Node* cond, bool iftrue,
185 wasm::WasmCodePosition position) { 220 wasm::WasmCodePosition position) {
186 Node** effect_ptr = builder_->effect_; 221 Node** effect_ptr = builder_->effect_;
187 Node** control_ptr = builder_->control_; 222 Node** control_ptr = builder_->control_;
188 Node* before = *effect_ptr; 223 Node* before = *effect_ptr;
189 BranchHint hint = iftrue ? BranchHint::kFalse : BranchHint::kTrue; 224 BranchHint hint = iftrue ? BranchHint::kFalse : BranchHint::kTrue;
(...skipping 3421 matching lines...) Expand 10 before | Expand all | Expand 10 after
3611 Smi::FromInt(instruction.instr_offset)); 3646 Smi::FromInt(instruction.instr_offset));
3612 fn_protected->set(Code::kTrapDataSize * i + Code::kTrapLandingOffset, 3647 fn_protected->set(Code::kTrapDataSize * i + Code::kTrapLandingOffset,
3613 Smi::FromInt(instruction.landing_offset)); 3648 Smi::FromInt(instruction.landing_offset));
3614 } 3649 }
3615 return fn_protected; 3650 return fn_protected;
3616 } 3651 }
3617 3652
3618 } // namespace compiler 3653 } // namespace compiler
3619 } // namespace internal 3654 } // namespace internal
3620 } // namespace v8 3655 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698