From 60efd46f8cbe63b554835dc56c45e4dc4c4a18b2 Mon Sep 17 00:00:00 2001 From: Clemens Hammacher Date: Mon, 19 Mar 2018 15:54:57 +0100 Subject: [PATCH] [Liftoff] Merge two nearly identical functions EmitMonomorphicBinOp and EmitBinOpWithDifferentResultType were nearly identical, they just differ in one argument to GetUnusedRegister. This CL merges them. R=titzer@chromium.org Bug: v8:6600 Change-Id: Ief75beb410c8ba248b43cd382693f25bd9153d74 Reviewed-on: https://chromium-review.googlesource.com/968501 Commit-Queue: Clemens Hammacher Reviewed-by: Ben Titzer Cr-Commit-Position: refs/heads/master@{#52043} --- src/wasm/baseline/liftoff-compiler.cc | 51 ++++++++++++--------------- 1 file changed, 22 insertions(+), 29 deletions(-) diff --git a/src/wasm/baseline/liftoff-compiler.cc b/src/wasm/baseline/liftoff-compiler.cc index 6c10cf20bd..d954510125 100644 --- a/src/wasm/baseline/liftoff-compiler.cc +++ b/src/wasm/baseline/liftoff-compiler.cc @@ -655,23 +655,17 @@ class LiftoffCompiler { #undef CASE_TYPE_CONVERSION } - template - void EmitMonomorphicBinOp(EmitFn fn) { - static constexpr RegClass rc = reg_class_for(type); + template + void EmitBinOp(EmitFn fn) { + static constexpr RegClass src_rc = reg_class_for(src_type); + static constexpr RegClass result_rc = reg_class_for(result_type); LiftoffRegList pinned; LiftoffRegister rhs = pinned.set(__ PopToRegister(pinned)); LiftoffRegister lhs = pinned.set(__ PopToRegister(pinned)); - LiftoffRegister dst = __ GetUnusedRegister(rc, {lhs, rhs}, pinned); - fn(dst, lhs, rhs); - __ PushRegister(type, dst); - } - - template - void EmitBinOpWithDifferentResultType(EmitFn fn) { - LiftoffRegList pinned; - LiftoffRegister rhs = pinned.set(__ PopToRegister(pinned)); - LiftoffRegister lhs = pinned.set(__ PopToRegister(pinned)); - LiftoffRegister dst = __ GetUnusedRegister(reg_class_for(result_type)); + LiftoffRegister dst = + src_rc == result_rc + ? __ GetUnusedRegister(result_rc, {lhs, rhs}, pinned) + : __ GetUnusedRegister(result_rc); fn(dst, lhs, rhs); __ PushRegister(result_type, dst); } @@ -680,46 +674,45 @@ class LiftoffCompiler { const Value& lhs, const Value& rhs, Value* result) { #define CASE_I32_BINOP(opcode, fn) \ case WasmOpcode::kExpr##opcode: \ - return EmitMonomorphicBinOp( \ + return EmitBinOp( \ [=](LiftoffRegister dst, LiftoffRegister lhs, LiftoffRegister rhs) { \ __ emit_##fn(dst.gp(), lhs.gp(), rhs.gp()); \ }); #define CASE_FLOAT_BINOP(opcode, type, fn) \ case WasmOpcode::kExpr##opcode: \ - return EmitMonomorphicBinOp( \ + return EmitBinOp( \ [=](LiftoffRegister dst, LiftoffRegister lhs, LiftoffRegister rhs) { \ __ emit_##fn(dst.fp(), lhs.fp(), rhs.fp()); \ }); #define CASE_I32_CMPOP(opcode, cond) \ case WasmOpcode::kExpr##opcode: \ - return EmitMonomorphicBinOp( \ + return EmitBinOp( \ [=](LiftoffRegister dst, LiftoffRegister lhs, LiftoffRegister rhs) { \ __ emit_i32_set_cond(cond, dst.gp(), lhs.gp(), rhs.gp()); \ }); #define CASE_F32_CMPOP(opcode, cond) \ case WasmOpcode::kExpr##opcode: \ - return EmitBinOpWithDifferentResultType( \ + return EmitBinOp( \ [=](LiftoffRegister dst, LiftoffRegister lhs, LiftoffRegister rhs) { \ __ emit_f32_set_cond(cond, dst.gp(), lhs.fp(), rhs.fp()); \ }); -#define CASE_I32_SHIFTOP(opcode, fn) \ - case WasmOpcode::kExpr##opcode: \ - return EmitMonomorphicBinOp([=](LiftoffRegister dst, \ - LiftoffRegister src, \ - LiftoffRegister amount) { \ - __ emit_##fn(dst.gp(), src.gp(), amount.gp(), {}); \ - }); +#define CASE_I32_SHIFTOP(opcode, fn) \ + case WasmOpcode::kExpr##opcode: \ + return EmitBinOp( \ + [=](LiftoffRegister dst, LiftoffRegister lhs, LiftoffRegister rhs) { \ + __ emit_##fn(dst.gp(), lhs.gp(), rhs.gp(), {}); \ + }); #define CASE_I64_SHIFTOP(opcode, fn) \ case WasmOpcode::kExpr##opcode: \ - return EmitMonomorphicBinOp([=](LiftoffRegister dst, \ - LiftoffRegister src, \ - LiftoffRegister amount) { \ + return EmitBinOp([=](LiftoffRegister dst, \ + LiftoffRegister src, \ + LiftoffRegister amount) { \ __ emit_##fn(dst, src, amount.is_pair() ? amount.low_gp() : amount.gp(), \ {}); \ }); #define CASE_CCALL_BINOP(opcode, type, ext_ref_fn) \ case WasmOpcode::kExpr##opcode: \ - return EmitMonomorphicBinOp( \ + return EmitBinOp( \ [=](LiftoffRegister dst, LiftoffRegister lhs, LiftoffRegister rhs) { \ LiftoffRegister args[] = {lhs, rhs}; \ auto ext_ref = ExternalReference::ext_ref_fn(__ isolate()); \