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

Side by Side Diff: src/compiler/x64/code-generator-x64.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 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 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/code-generator.h" 5 #include "src/compiler/code-generator.h"
6 6
7 #include <limits> 7 #include <limits>
8 8
9 #include "src/compilation-info.h" 9 #include "src/compilation-info.h"
10 #include "src/compiler/code-generator-impl.h" 10 #include "src/compiler/code-generator-impl.h"
(...skipping 2208 matching lines...) Expand 10 before | Expand all | Expand 10 after
2219 case kAtomicLoadWord32: 2219 case kAtomicLoadWord32:
2220 case kAtomicStoreWord8: 2220 case kAtomicStoreWord8:
2221 case kAtomicStoreWord16: 2221 case kAtomicStoreWord16:
2222 case kAtomicStoreWord32: 2222 case kAtomicStoreWord32:
2223 UNREACHABLE(); // Won't be generated by instruction selector. 2223 UNREACHABLE(); // Won't be generated by instruction selector.
2224 break; 2224 break;
2225 } 2225 }
2226 return kSuccess; 2226 return kSuccess;
2227 } // NOLINT(readability/fn_size) 2227 } // NOLINT(readability/fn_size)
2228 2228
2229 static Condition ToCC(FlagsCondition condition) {
2230 switch (condition) {
2231 case kUnorderedEqual:
2232 case kEqual:
2233 return equal;
2234 break;
2235 case kUnorderedNotEqual:
2236 case kNotEqual:
2237 return not_equal;
2238 break;
2239 case kSignedLessThan:
2240 return less;
2241 break;
2242 case kSignedGreaterThanOrEqual:
2243 return greater_equal;
2244 break;
2245 case kSignedLessThanOrEqual:
2246 return less_equal;
2247 break;
2248 case kSignedGreaterThan:
2249 return greater;
2250 break;
2251 case kUnsignedLessThan:
2252 return below;
2253 break;
2254 case kUnsignedGreaterThanOrEqual:
2255 return above_equal;
2256 break;
2257 case kUnsignedLessThanOrEqual:
2258 return below_equal;
2259 break;
2260 case kUnsignedGreaterThan:
2261 return above;
2262 break;
2263 case kOverflow:
2264 return overflow;
2265 break;
2266 case kNotOverflow:
2267 return no_overflow;
2268 break;
2269 default:
2270 UNREACHABLE();
2271 return no_condition;
2272 break;
2273 }
2274 }
2229 2275
2230 // Assembles branches after this instruction. 2276 // Assembles branches after this instruction.
2231 void CodeGenerator::AssembleArchBranch(Instruction* instr, BranchInfo* branch) { 2277 void CodeGenerator::AssembleArchBranch(Instruction* instr, BranchInfo* branch) {
2232 X64OperandConverter i(this, instr); 2278 X64OperandConverter i(this, instr);
2233 Label::Distance flabel_distance = 2279 Label::Distance flabel_distance =
2234 branch->fallthru ? Label::kNear : Label::kFar; 2280 branch->fallthru ? Label::kNear : Label::kFar;
2235 Label* tlabel = branch->true_label; 2281 Label* tlabel = branch->true_label;
2236 Label* flabel = branch->false_label; 2282 Label* flabel = branch->false_label;
2237 switch (branch->condition) { 2283 if (branch->condition == kUnorderedEqual) {
2238 case kUnorderedEqual: 2284 __ j(parity_even, flabel, flabel_distance);
2239 __ j(parity_even, flabel, flabel_distance); 2285 } else if (branch->condition == kUnorderedNotEqual) {
2240 // Fall through. 2286 __ j(parity_even, tlabel);
2241 case kEqual:
2242 __ j(equal, tlabel);
2243 break;
2244 case kUnorderedNotEqual:
2245 __ j(parity_even, tlabel);
2246 // Fall through.
2247 case kNotEqual:
2248 __ j(not_equal, tlabel);
2249 break;
2250 case kSignedLessThan:
2251 __ j(less, tlabel);
2252 break;
2253 case kSignedGreaterThanOrEqual:
2254 __ j(greater_equal, tlabel);
2255 break;
2256 case kSignedLessThanOrEqual:
2257 __ j(less_equal, tlabel);
2258 break;
2259 case kSignedGreaterThan:
2260 __ j(greater, tlabel);
2261 break;
2262 case kUnsignedLessThan:
2263 __ j(below, tlabel);
2264 break;
2265 case kUnsignedGreaterThanOrEqual:
2266 __ j(above_equal, tlabel);
2267 break;
2268 case kUnsignedLessThanOrEqual:
2269 __ j(below_equal, tlabel);
2270 break;
2271 case kUnsignedGreaterThan:
2272 __ j(above, tlabel);
2273 break;
2274 case kOverflow:
2275 __ j(overflow, tlabel);
2276 break;
2277 case kNotOverflow:
2278 __ j(no_overflow, tlabel);
2279 break;
2280 default:
2281 UNREACHABLE();
2282 break;
2283 } 2287 }
2288 __ j(ToCC(branch->condition), tlabel);
2289
2284 if (!branch->fallthru) __ jmp(flabel, flabel_distance); 2290 if (!branch->fallthru) __ jmp(flabel, flabel_distance);
2285 } 2291 }
2286 2292
2287 2293
2288 void CodeGenerator::AssembleArchJump(RpoNumber target) { 2294 void CodeGenerator::AssembleArchJump(RpoNumber target) {
2289 if (!IsNextInAssemblyOrder(target)) __ jmp(GetLabel(target)); 2295 if (!IsNextInAssemblyOrder(target)) __ jmp(GetLabel(target));
2290 } 2296 }
2291 2297
2298 void CodeGenerator::AssembleArchTrap(Instruction* instr,
2299 FlagsCondition condition) {
2300 class OutOfLineTrap final : public OutOfLineCode {
2301 public:
2302 OutOfLineTrap(CodeGenerator* gen, bool frame_elided, Instruction* instr)
2303 : OutOfLineCode(gen),
2304 frame_elided_(frame_elided),
2305 instr_(instr),
2306 gen_(gen) {}
2307
2308 void Generate() final {
2309 X64OperandConverter i(gen_, instr_);
2310
2311 Runtime::FunctionId trap_id = static_cast<Runtime::FunctionId>(
2312 i.InputInt32(instr_->InputCount() - 1));
2313 if (frame_elided_) {
titzer 2016/12/12 14:21:34 We don't need the frame teardown, since the call t
2314 FrameScope f(masm(), StackFrame::WASM);
2315 GenerateCallToTrap(trap_id);
2316 } else {
2317 GenerateCallToTrap(trap_id);
2318 }
2319 }
2320
2321 private:
2322 void GenerateCallToTrap(Runtime::FunctionId trap_id) {
2323 if (trap_id == Runtime::kNumFunctions) {
titzer 2016/12/12 14:21:33 You should probably leave a comment here that this
2324 __ PrepareCallCFunction(0);
2325 __ CallCFunction(
2326 ExternalReference::wasm_call_trap_callback_for_testing(isolate()),
2327 0);
2328 } else {
2329 __ Move(rsi, isolate()->native_context());
2330 gen_->AssembleSourcePosition(instr_);
titzer 2016/12/12 14:21:33 Should the source position recording be after the
ahaas 2016/12/13 12:38:59 I looked up other code, and there it is recorded b
2331 __ CallRuntime(trap_id);
2332 }
2333 }
2334
2335 bool frame_elided_;
2336 Instruction* instr_;
2337 CodeGenerator* gen_;
2338 };
2339 bool frame_elided = !frame_access_state()->has_frame();
2340 auto ool = new (zone()) OutOfLineTrap(this, frame_elided, instr);
2341 Label* tlabel = ool->entry();
2342 Label end;
2343 if (condition == kUnorderedEqual) {
2344 __ j(parity_even, &end);
2345 } else if (condition == kUnorderedNotEqual) {
2346 __ j(parity_even, tlabel);
2347 }
2348 __ j(ToCC(condition), tlabel);
2349 __ bind(&end);
2350 }
2292 2351
2293 // Assembles boolean materializations after this instruction. 2352 // Assembles boolean materializations after this instruction.
2294 void CodeGenerator::AssembleArchBoolean(Instruction* instr, 2353 void CodeGenerator::AssembleArchBoolean(Instruction* instr,
2295 FlagsCondition condition) { 2354 FlagsCondition condition) {
2296 X64OperandConverter i(this, instr); 2355 X64OperandConverter i(this, instr);
2297 Label done; 2356 Label done;
2298 2357
2299 // Materialize a full 64-bit 1 or 0 value. The result register is always the 2358 // Materialize a full 64-bit 1 or 0 value. The result register is always the
2300 // last output of the instruction. 2359 // last output of the instruction.
2301 Label check; 2360 Label check;
2302 DCHECK_NE(0u, instr->OutputCount()); 2361 DCHECK_NE(0u, instr->OutputCount());
2303 Register reg = i.OutputRegister(instr->OutputCount() - 1); 2362 Register reg = i.OutputRegister(instr->OutputCount() - 1);
2304 Condition cc = no_condition; 2363 if (condition == kUnorderedEqual) {
2305 switch (condition) { 2364 __ j(parity_odd, &check, Label::kNear);
2306 case kUnorderedEqual: 2365 __ movl(reg, Immediate(0));
2307 __ j(parity_odd, &check, Label::kNear); 2366 __ jmp(&done, Label::kNear);
2308 __ movl(reg, Immediate(0)); 2367 } else if (condition == kUnorderedNotEqual) {
2309 __ jmp(&done, Label::kNear); 2368 __ j(parity_odd, &check, Label::kNear);
2310 // Fall through. 2369 __ movl(reg, Immediate(1));
2311 case kEqual: 2370 __ jmp(&done, Label::kNear);
2312 cc = equal;
2313 break;
2314 case kUnorderedNotEqual:
2315 __ j(parity_odd, &check, Label::kNear);
2316 __ movl(reg, Immediate(1));
2317 __ jmp(&done, Label::kNear);
2318 // Fall through.
2319 case kNotEqual:
2320 cc = not_equal;
2321 break;
2322 case kSignedLessThan:
2323 cc = less;
2324 break;
2325 case kSignedGreaterThanOrEqual:
2326 cc = greater_equal;
2327 break;
2328 case kSignedLessThanOrEqual:
2329 cc = less_equal;
2330 break;
2331 case kSignedGreaterThan:
2332 cc = greater;
2333 break;
2334 case kUnsignedLessThan:
2335 cc = below;
2336 break;
2337 case kUnsignedGreaterThanOrEqual:
2338 cc = above_equal;
2339 break;
2340 case kUnsignedLessThanOrEqual:
2341 cc = below_equal;
2342 break;
2343 case kUnsignedGreaterThan:
2344 cc = above;
2345 break;
2346 case kOverflow:
2347 cc = overflow;
2348 break;
2349 case kNotOverflow:
2350 cc = no_overflow;
2351 break;
2352 default:
2353 UNREACHABLE();
2354 break;
2355 } 2371 }
2356 __ bind(&check); 2372 __ bind(&check);
2357 __ setcc(cc, reg); 2373 __ setcc(ToCC(condition), reg);
2358 __ movzxbl(reg, reg); 2374 __ movzxbl(reg, reg);
2359 __ bind(&done); 2375 __ bind(&done);
2360 } 2376 }
2361 2377
2362 2378
2363 void CodeGenerator::AssembleArchLookupSwitch(Instruction* instr) { 2379 void CodeGenerator::AssembleArchLookupSwitch(Instruction* instr) {
2364 X64OperandConverter i(this, instr); 2380 X64OperandConverter i(this, instr);
2365 Register input = i.InputRegister(0); 2381 Register input = i.InputRegister(0);
2366 for (size_t index = 2; index < instr->InputCount(); index += 2) { 2382 for (size_t index = 2; index < instr->InputCount(); index += 2) {
2367 __ cmpl(input, Immediate(i.InputInt32(index + 0))); 2383 __ cmpl(input, Immediate(i.InputInt32(index + 0)));
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after
2820 int padding_size = last_lazy_deopt_pc_ + space_needed - current_pc; 2836 int padding_size = last_lazy_deopt_pc_ + space_needed - current_pc;
2821 __ Nop(padding_size); 2837 __ Nop(padding_size);
2822 } 2838 }
2823 } 2839 }
2824 2840
2825 #undef __ 2841 #undef __
2826 2842
2827 } // namespace compiler 2843 } // namespace compiler
2828 } // namespace internal 2844 } // namespace internal
2829 } // namespace v8 2845 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698