| Index: src/compiler/x64/code-generator-x64.cc
 | 
| diff --git a/src/compiler/x64/code-generator-x64.cc b/src/compiler/x64/code-generator-x64.cc
 | 
| index 212a06eac3cd4a92231c75e56d497e93c2ea58a5..33e219e7ed6a519bdd060c18998315df9e16c941 100644
 | 
| --- a/src/compiler/x64/code-generator-x64.cc
 | 
| +++ b/src/compiler/x64/code-generator-x64.cc
 | 
| @@ -271,13 +271,13 @@ class OutOfLineRecordWrite final : public OutOfLineCode {
 | 
|  class WasmOutOfLineTrap final : public OutOfLineCode {
 | 
|   public:
 | 
|    WasmOutOfLineTrap(CodeGenerator* gen, int pc, bool frame_elided,
 | 
| -                    Register context, int32_t position)
 | 
| +                    int32_t position, Instruction* instr)
 | 
|        : OutOfLineCode(gen),
 | 
|          gen_(gen),
 | 
|          pc_(pc),
 | 
|          frame_elided_(frame_elided),
 | 
| -        context_(context),
 | 
| -        position_(position) {}
 | 
| +        position_(position),
 | 
| +        instr_(instr) {}
 | 
|  
 | 
|    // TODO(eholk): Refactor this method to take the code generator as a
 | 
|    // parameter.
 | 
| @@ -294,27 +294,32 @@ class WasmOutOfLineTrap final : public OutOfLineCode {
 | 
|      int trap_reason = wasm::WasmOpcodes::TrapReasonToMessageId(trap_id);
 | 
|      __ Push(Smi::FromInt(trap_reason));
 | 
|      __ Push(Smi::FromInt(position_));
 | 
| -    __ Move(rsi, context_);
 | 
| +    __ Move(rsi, gen_->isolate()->native_context());
 | 
|      __ CallRuntime(Runtime::kThrowWasmError);
 | 
| +
 | 
| +    if (instr_->reference_map() != nullptr) {
 | 
| +      gen_->RecordSafepoint(instr_->reference_map(), Safepoint::kSimple, 0,
 | 
| +                            Safepoint::kNoLazyDeopt);
 | 
| +    }
 | 
|    }
 | 
|  
 | 
|   private:
 | 
|    CodeGenerator* gen_;
 | 
|    int pc_;
 | 
|    bool frame_elided_;
 | 
| -  Register context_;
 | 
|    int32_t position_;
 | 
| +  Instruction* instr_;
 | 
|  };
 | 
|  
 | 
|  void EmitOOLTrapIfNeeded(Zone* zone, CodeGenerator* codegen,
 | 
| -                         InstructionCode opcode, X64OperandConverter& i,
 | 
| -                         int pc) {
 | 
| -  X64MemoryProtection protection =
 | 
| +                         InstructionCode opcode, size_t input_count,
 | 
| +                         X64OperandConverter& i, int pc, Instruction* instr) {
 | 
| +  const X64MemoryProtection protection =
 | 
|        static_cast<X64MemoryProtection>(MiscField::decode(opcode));
 | 
|    if (protection == X64MemoryProtection::kProtected) {
 | 
| -    bool frame_elided = !codegen->frame_access_state()->has_frame();
 | 
| -    new (zone) WasmOutOfLineTrap(codegen, pc, frame_elided, i.InputRegister(2),
 | 
| -                                 i.InputInt32(3));
 | 
| +    const bool frame_elided = !codegen->frame_access_state()->has_frame();
 | 
| +    const int32_t position = i.InputInt32(input_count - 1);
 | 
| +    new (zone) WasmOutOfLineTrap(codegen, pc, frame_elided, position, instr);
 | 
|    }
 | 
|  }
 | 
|  }  // namespace
 | 
| @@ -1853,25 +1858,31 @@ CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction(
 | 
|        __ Subsd(i.InputDoubleRegister(0), kScratchDoubleReg);
 | 
|        break;
 | 
|      case kX64Movsxbl:
 | 
| +      EmitOOLTrapIfNeeded(zone(), this, opcode, instr->InputCount(), i,
 | 
| +                          __ pc_offset(), instr);
 | 
|        ASSEMBLE_MOVX(movsxbl);
 | 
| -      EmitOOLTrapIfNeeded(zone(), this, opcode, i, __ pc_offset());
 | 
|        __ AssertZeroExtended(i.OutputRegister());
 | 
|        break;
 | 
|      case kX64Movzxbl:
 | 
| +      EmitOOLTrapIfNeeded(zone(), this, opcode, instr->InputCount(), i,
 | 
| +                          __ pc_offset(), instr);
 | 
|        ASSEMBLE_MOVX(movzxbl);
 | 
| -      EmitOOLTrapIfNeeded(zone(), this, opcode, i, __ pc_offset());
 | 
|        __ AssertZeroExtended(i.OutputRegister());
 | 
|        break;
 | 
|      case kX64Movsxbq:
 | 
| +      EmitOOLTrapIfNeeded(zone(), this, opcode, instr->InputCount(), i,
 | 
| +                          __ pc_offset(), instr);
 | 
|        ASSEMBLE_MOVX(movsxbq);
 | 
| -      EmitOOLTrapIfNeeded(zone(), this, opcode, i, __ pc_offset());
 | 
|        break;
 | 
|      case kX64Movzxbq:
 | 
| +      EmitOOLTrapIfNeeded(zone(), this, opcode, instr->InputCount(), i,
 | 
| +                          __ pc_offset(), instr);
 | 
|        ASSEMBLE_MOVX(movzxbq);
 | 
| -      EmitOOLTrapIfNeeded(zone(), this, opcode, i, __ pc_offset());
 | 
|        __ AssertZeroExtended(i.OutputRegister());
 | 
|        break;
 | 
|      case kX64Movb: {
 | 
| +      EmitOOLTrapIfNeeded(zone(), this, opcode, instr->InputCount(), i,
 | 
| +                          __ pc_offset(), instr);
 | 
|        size_t index = 0;
 | 
|        Operand operand = i.MemoryOperand(&index);
 | 
|        if (HasImmediateInput(instr, index)) {
 | 
| @@ -1879,29 +1890,34 @@ CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction(
 | 
|        } else {
 | 
|          __ movb(operand, i.InputRegister(index));
 | 
|        }
 | 
| -      EmitOOLTrapIfNeeded(zone(), this, opcode, i, __ pc_offset());
 | 
|        break;
 | 
|      }
 | 
|      case kX64Movsxwl:
 | 
| +      EmitOOLTrapIfNeeded(zone(), this, opcode, instr->InputCount(), i,
 | 
| +                          __ pc_offset(), instr);
 | 
|        ASSEMBLE_MOVX(movsxwl);
 | 
| -      EmitOOLTrapIfNeeded(zone(), this, opcode, i, __ pc_offset());
 | 
|        __ AssertZeroExtended(i.OutputRegister());
 | 
|        break;
 | 
|      case kX64Movzxwl:
 | 
| +      EmitOOLTrapIfNeeded(zone(), this, opcode, instr->InputCount(), i,
 | 
| +                          __ pc_offset(), instr);
 | 
|        ASSEMBLE_MOVX(movzxwl);
 | 
| -      EmitOOLTrapIfNeeded(zone(), this, opcode, i, __ pc_offset());
 | 
|        __ AssertZeroExtended(i.OutputRegister());
 | 
|        break;
 | 
|      case kX64Movsxwq:
 | 
| +      EmitOOLTrapIfNeeded(zone(), this, opcode, instr->InputCount(), i,
 | 
| +                          __ pc_offset(), instr);
 | 
|        ASSEMBLE_MOVX(movsxwq);
 | 
| -      EmitOOLTrapIfNeeded(zone(), this, opcode, i, __ pc_offset());
 | 
|        break;
 | 
|      case kX64Movzxwq:
 | 
| +      EmitOOLTrapIfNeeded(zone(), this, opcode, instr->InputCount(), i,
 | 
| +                          __ pc_offset(), instr);
 | 
|        ASSEMBLE_MOVX(movzxwq);
 | 
| -      EmitOOLTrapIfNeeded(zone(), this, opcode, i, __ pc_offset());
 | 
|        __ AssertZeroExtended(i.OutputRegister());
 | 
|        break;
 | 
|      case kX64Movw: {
 | 
| +      EmitOOLTrapIfNeeded(zone(), this, opcode, instr->InputCount(), i,
 | 
| +                          __ pc_offset(), instr);
 | 
|        size_t index = 0;
 | 
|        Operand operand = i.MemoryOperand(&index);
 | 
|        if (HasImmediateInput(instr, index)) {
 | 
| @@ -1909,10 +1925,11 @@ CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction(
 | 
|        } else {
 | 
|          __ movw(operand, i.InputRegister(index));
 | 
|        }
 | 
| -      EmitOOLTrapIfNeeded(zone(), this, opcode, i, __ pc_offset());
 | 
|        break;
 | 
|      }
 | 
|      case kX64Movl:
 | 
| +      EmitOOLTrapIfNeeded(zone(), this, opcode, instr->InputCount(), i,
 | 
| +                          __ pc_offset(), instr);
 | 
|        if (instr->HasOutput()) {
 | 
|          if (instr->addressing_mode() == kMode_None) {
 | 
|            if (instr->InputAt(0)->IsRegister()) {
 | 
| @@ -1923,7 +1940,6 @@ CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction(
 | 
|          } else {
 | 
|            __ movl(i.OutputRegister(), i.MemoryOperand());
 | 
|          }
 | 
| -        EmitOOLTrapIfNeeded(zone(), this, opcode, i, __ pc_offset());
 | 
|          __ AssertZeroExtended(i.OutputRegister());
 | 
|        } else {
 | 
|          size_t index = 0;
 | 
| @@ -1933,14 +1949,16 @@ CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction(
 | 
|          } else {
 | 
|            __ movl(operand, i.InputRegister(index));
 | 
|          }
 | 
| -        EmitOOLTrapIfNeeded(zone(), this, opcode, i, __ pc_offset());
 | 
|        }
 | 
|        break;
 | 
|      case kX64Movsxlq:
 | 
| +      EmitOOLTrapIfNeeded(zone(), this, opcode, instr->InputCount(), i,
 | 
| +                          __ pc_offset(), instr);
 | 
|        ASSEMBLE_MOVX(movsxlq);
 | 
| -      EmitOOLTrapIfNeeded(zone(), this, opcode, i, __ pc_offset());
 | 
|        break;
 | 
|      case kX64Movq:
 | 
| +      EmitOOLTrapIfNeeded(zone(), this, opcode, instr->InputCount(), i,
 | 
| +                          __ pc_offset(), instr);
 | 
|        if (instr->HasOutput()) {
 | 
|          __ movq(i.OutputRegister(), i.MemoryOperand());
 | 
|        } else {
 | 
| @@ -1952,9 +1970,10 @@ CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction(
 | 
|            __ movq(operand, i.InputRegister(index));
 | 
|          }
 | 
|        }
 | 
| -      EmitOOLTrapIfNeeded(zone(), this, opcode, i, __ pc_offset());
 | 
|        break;
 | 
|      case kX64Movss:
 | 
| +      EmitOOLTrapIfNeeded(zone(), this, opcode, instr->InputCount(), i,
 | 
| +                          __ pc_offset(), instr);
 | 
|        if (instr->HasOutput()) {
 | 
|          __ movss(i.OutputDoubleRegister(), i.MemoryOperand());
 | 
|        } else {
 | 
| @@ -1962,9 +1981,10 @@ CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction(
 | 
|          Operand operand = i.MemoryOperand(&index);
 | 
|          __ movss(operand, i.InputDoubleRegister(index));
 | 
|        }
 | 
| -      EmitOOLTrapIfNeeded(zone(), this, opcode, i, __ pc_offset());
 | 
|        break;
 | 
|      case kX64Movsd:
 | 
| +      EmitOOLTrapIfNeeded(zone(), this, opcode, instr->InputCount(), i,
 | 
| +                          __ pc_offset(), instr);
 | 
|        if (instr->HasOutput()) {
 | 
|          __ Movsd(i.OutputDoubleRegister(), i.MemoryOperand());
 | 
|        } else {
 | 
| @@ -1972,7 +1992,6 @@ CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction(
 | 
|          Operand operand = i.MemoryOperand(&index);
 | 
|          __ Movsd(operand, i.InputDoubleRegister(index));
 | 
|        }
 | 
| -      EmitOOLTrapIfNeeded(zone(), this, opcode, i, __ pc_offset());
 | 
|        break;
 | 
|      case kX64BitcastFI:
 | 
|        if (instr->InputAt(0)->IsFPStackSlot()) {
 | 
| 
 |