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

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: Rename UseSourcePosition to IsSourcePositionUsed 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
« no previous file with comments | « src/compiler/wasm-compiler.cc ('k') | src/compiler/x64/instruction-selector-x64.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 namespace {
2230
2231 Condition FlagsConditionToCondition(FlagsCondition condition) {
2232 switch (condition) {
2233 case kUnorderedEqual:
2234 case kEqual:
2235 return equal;
2236 case kUnorderedNotEqual:
2237 case kNotEqual:
2238 return not_equal;
2239 case kSignedLessThan:
2240 return less;
2241 case kSignedGreaterThanOrEqual:
2242 return greater_equal;
2243 case kSignedLessThanOrEqual:
2244 return less_equal;
2245 case kSignedGreaterThan:
2246 return greater;
2247 case kUnsignedLessThan:
2248 return below;
2249 case kUnsignedGreaterThanOrEqual:
2250 return above_equal;
2251 case kUnsignedLessThanOrEqual:
2252 return below_equal;
2253 case kUnsignedGreaterThan:
2254 return above;
2255 case kOverflow:
2256 return overflow;
2257 case kNotOverflow:
2258 return no_overflow;
2259 default:
2260 break;
2261 }
2262 UNREACHABLE();
2263 return no_condition;
2264 }
2265
2266 } // namespace
2229 2267
2230 // Assembles branches after this instruction. 2268 // Assembles branches after this instruction.
2231 void CodeGenerator::AssembleArchBranch(Instruction* instr, BranchInfo* branch) { 2269 void CodeGenerator::AssembleArchBranch(Instruction* instr, BranchInfo* branch) {
2232 X64OperandConverter i(this, instr); 2270 X64OperandConverter i(this, instr);
2233 Label::Distance flabel_distance = 2271 Label::Distance flabel_distance =
2234 branch->fallthru ? Label::kNear : Label::kFar; 2272 branch->fallthru ? Label::kNear : Label::kFar;
2235 Label* tlabel = branch->true_label; 2273 Label* tlabel = branch->true_label;
2236 Label* flabel = branch->false_label; 2274 Label* flabel = branch->false_label;
2237 switch (branch->condition) { 2275 if (branch->condition == kUnorderedEqual) {
2238 case kUnorderedEqual: 2276 __ j(parity_even, flabel, flabel_distance);
2239 __ j(parity_even, flabel, flabel_distance); 2277 } else if (branch->condition == kUnorderedNotEqual) {
2240 // Fall through. 2278 __ 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 } 2279 }
2280 __ j(FlagsConditionToCondition(branch->condition), tlabel);
2281
2284 if (!branch->fallthru) __ jmp(flabel, flabel_distance); 2282 if (!branch->fallthru) __ jmp(flabel, flabel_distance);
2285 } 2283 }
2286 2284
2287 2285
2288 void CodeGenerator::AssembleArchJump(RpoNumber target) { 2286 void CodeGenerator::AssembleArchJump(RpoNumber target) {
2289 if (!IsNextInAssemblyOrder(target)) __ jmp(GetLabel(target)); 2287 if (!IsNextInAssemblyOrder(target)) __ jmp(GetLabel(target));
2290 } 2288 }
2291 2289
2290 void CodeGenerator::AssembleArchTrap(Instruction* instr,
2291 FlagsCondition condition) {
2292 class OutOfLineTrap final : public OutOfLineCode {
2293 public:
2294 OutOfLineTrap(CodeGenerator* gen, bool frame_elided, Instruction* instr)
2295 : OutOfLineCode(gen),
2296 frame_elided_(frame_elided),
2297 instr_(instr),
2298 gen_(gen) {}
2299
2300 void Generate() final {
2301 X64OperandConverter i(gen_, instr_);
2302
2303 Runtime::FunctionId trap_id = static_cast<Runtime::FunctionId>(
2304 i.InputInt32(instr_->InputCount() - 1));
2305 bool old_has_frame = __ has_frame();
2306 if (frame_elided_) {
2307 __ set_has_frame(true);
2308 __ EnterFrame(StackFrame::WASM);
2309 }
2310 GenerateCallToTrap(trap_id);
2311 if (frame_elided_) {
2312 __ set_has_frame(old_has_frame);
2313 }
2314 if (FLAG_debug_code) {
2315 __ ud2();
2316 }
2317 }
2318
2319 private:
2320 void GenerateCallToTrap(Runtime::FunctionId trap_id) {
2321 if (trap_id == Runtime::kNumFunctions) {
2322 // We cannot test calls to the runtime in cctest/test-run-wasm.
2323 // Therefore we emit a call to C here instead of a call to the runtime.
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_);
2331 __ CallRuntime(trap_id);
2332 }
2333 ReferenceMap* reference_map =
2334 new (gen_->zone()) ReferenceMap(gen_->zone());
2335 gen_->RecordSafepoint(reference_map, Safepoint::kSimple, 0,
2336 Safepoint::kNoLazyDeopt);
2337 }
2338
2339 bool frame_elided_;
2340 Instruction* instr_;
2341 CodeGenerator* gen_;
2342 };
2343 bool frame_elided = !frame_access_state()->has_frame();
2344 auto ool = new (zone()) OutOfLineTrap(this, frame_elided, instr);
2345 Label* tlabel = ool->entry();
2346 Label end;
2347 if (condition == kUnorderedEqual) {
2348 __ j(parity_even, &end);
2349 } else if (condition == kUnorderedNotEqual) {
2350 __ j(parity_even, tlabel);
2351 }
2352 __ j(FlagsConditionToCondition(condition), tlabel);
2353 __ bind(&end);
2354 }
2292 2355
2293 // Assembles boolean materializations after this instruction. 2356 // Assembles boolean materializations after this instruction.
2294 void CodeGenerator::AssembleArchBoolean(Instruction* instr, 2357 void CodeGenerator::AssembleArchBoolean(Instruction* instr,
2295 FlagsCondition condition) { 2358 FlagsCondition condition) {
2296 X64OperandConverter i(this, instr); 2359 X64OperandConverter i(this, instr);
2297 Label done; 2360 Label done;
2298 2361
2299 // Materialize a full 64-bit 1 or 0 value. The result register is always the 2362 // Materialize a full 64-bit 1 or 0 value. The result register is always the
2300 // last output of the instruction. 2363 // last output of the instruction.
2301 Label check; 2364 Label check;
2302 DCHECK_NE(0u, instr->OutputCount()); 2365 DCHECK_NE(0u, instr->OutputCount());
2303 Register reg = i.OutputRegister(instr->OutputCount() - 1); 2366 Register reg = i.OutputRegister(instr->OutputCount() - 1);
2304 Condition cc = no_condition; 2367 if (condition == kUnorderedEqual) {
2305 switch (condition) { 2368 __ j(parity_odd, &check, Label::kNear);
2306 case kUnorderedEqual: 2369 __ movl(reg, Immediate(0));
2307 __ j(parity_odd, &check, Label::kNear); 2370 __ jmp(&done, Label::kNear);
2308 __ movl(reg, Immediate(0)); 2371 } else if (condition == kUnorderedNotEqual) {
2309 __ jmp(&done, Label::kNear); 2372 __ j(parity_odd, &check, Label::kNear);
2310 // Fall through. 2373 __ movl(reg, Immediate(1));
2311 case kEqual: 2374 __ 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 } 2375 }
2356 __ bind(&check); 2376 __ bind(&check);
2357 __ setcc(cc, reg); 2377 __ setcc(FlagsConditionToCondition(condition), reg);
2358 __ movzxbl(reg, reg); 2378 __ movzxbl(reg, reg);
2359 __ bind(&done); 2379 __ bind(&done);
2360 } 2380 }
2361 2381
2362 2382
2363 void CodeGenerator::AssembleArchLookupSwitch(Instruction* instr) { 2383 void CodeGenerator::AssembleArchLookupSwitch(Instruction* instr) {
2364 X64OperandConverter i(this, instr); 2384 X64OperandConverter i(this, instr);
2365 Register input = i.InputRegister(0); 2385 Register input = i.InputRegister(0);
2366 for (size_t index = 2; index < instr->InputCount(); index += 2) { 2386 for (size_t index = 2; index < instr->InputCount(); index += 2) {
2367 __ cmpl(input, Immediate(i.InputInt32(index + 0))); 2387 __ 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; 2840 int padding_size = last_lazy_deopt_pc_ + space_needed - current_pc;
2821 __ Nop(padding_size); 2841 __ Nop(padding_size);
2822 } 2842 }
2823 } 2843 }
2824 2844
2825 #undef __ 2845 #undef __
2826 2846
2827 } // namespace compiler 2847 } // namespace compiler
2828 } // namespace internal 2848 } // namespace internal
2829 } // namespace v8 2849 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/wasm-compiler.cc ('k') | src/compiler/x64/instruction-selector-x64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698