| OLD | NEW |
| 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 "src/compilation-info.h" | 7 #include "src/compilation-info.h" |
| 8 #include "src/compiler/code-generator-impl.h" | 8 #include "src/compiler/code-generator-impl.h" |
| 9 #include "src/compiler/gap-resolver.h" | 9 #include "src/compiler/gap-resolver.h" |
| 10 #include "src/compiler/node-matchers.h" | 10 #include "src/compiler/node-matchers.h" |
| 11 #include "src/compiler/osr.h" | 11 #include "src/compiler/osr.h" |
| 12 #include "src/wasm/wasm-module.h" |
| 12 #include "src/x64/assembler-x64.h" | 13 #include "src/x64/assembler-x64.h" |
| 13 #include "src/x64/macro-assembler-x64.h" | 14 #include "src/x64/macro-assembler-x64.h" |
| 14 | 15 |
| 15 namespace v8 { | 16 namespace v8 { |
| 16 namespace internal { | 17 namespace internal { |
| 17 namespace compiler { | 18 namespace compiler { |
| 18 | 19 |
| 19 #define __ masm()-> | 20 #define __ masm()-> |
| 20 | 21 |
| 21 // Adds X64 specific methods for decoding operands. | 22 // Adds X64 specific methods for decoding operands. |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 | 254 |
| 254 private: | 255 private: |
| 255 Register const object_; | 256 Register const object_; |
| 256 Operand const operand_; | 257 Operand const operand_; |
| 257 Register const value_; | 258 Register const value_; |
| 258 Register const scratch0_; | 259 Register const scratch0_; |
| 259 Register const scratch1_; | 260 Register const scratch1_; |
| 260 RecordWriteMode const mode_; | 261 RecordWriteMode const mode_; |
| 261 }; | 262 }; |
| 262 | 263 |
| 264 class OutOfLineTrap final : public OutOfLineCode { |
| 265 public: |
| 266 OutOfLineTrap(CodeGenerator* gen, Address pc, bool needs_frame, |
| 267 Register context, int32_t position) |
| 268 : OutOfLineCode(gen), |
| 269 pc_(pc), |
| 270 needs_frame_(needs_frame), |
| 271 context_(context), |
| 272 position_(position) {} |
| 273 |
| 274 void Generate() final { |
| 275 const auto landing = __ GetPC(); |
| 276 |
| 277 // Save the location of this OOL code so the trap handler can find it. |
| 278 const auto offset = |
| 279 reinterpret_cast<intptr_t>(landing) - reinterpret_cast<intptr_t>(pc_); |
| 280 RelocInfo rinfo(isolate(), pc_, RelocInfo::WASM_TRAP_LANDING, offset, NULL); |
| 281 __ RecordRelocInfo(&rinfo); |
| 282 |
| 283 if (needs_frame_) { |
| 284 __ EnterFrame(StackFrame::WASM); |
| 285 } |
| 286 |
| 287 // TODO(eholk): plumb these two arguments from wasm-compiler.cc |
| 288 auto trap_id = wasm::kTrapMemOutOfBounds; |
| 289 auto trap_reason = wasm::WasmOpcodes::TrapReasonToMessageId(trap_id); |
| 290 __ Push(Smi::FromInt(trap_reason)); |
| 291 __ Push(Smi::FromInt(position_)); |
| 292 __ Move(rsi, context_); |
| 293 __ CallRuntime(Runtime::kThrowWasmError); |
| 294 } |
| 295 |
| 296 private: |
| 297 Address pc_; |
| 298 bool needs_frame_; |
| 299 Register context_; |
| 300 int32_t position_; |
| 301 }; |
| 302 |
| 263 } // namespace | 303 } // namespace |
| 264 | 304 |
| 265 | 305 |
| 266 #define ASSEMBLE_UNOP(asm_instr) \ | 306 #define ASSEMBLE_UNOP(asm_instr) \ |
| 267 do { \ | 307 do { \ |
| 268 if (instr->Output()->IsRegister()) { \ | 308 if (instr->Output()->IsRegister()) { \ |
| 269 __ asm_instr(i.OutputRegister()); \ | 309 __ asm_instr(i.OutputRegister()); \ |
| 270 } else { \ | 310 } else { \ |
| 271 __ asm_instr(i.OutputOperand()); \ | 311 __ asm_instr(i.OutputOperand()); \ |
| 272 } \ | 312 } \ |
| (...skipping 1569 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1842 size_t index = 0; | 1882 size_t index = 0; |
| 1843 Operand operand = i.MemoryOperand(&index); | 1883 Operand operand = i.MemoryOperand(&index); |
| 1844 if (HasImmediateInput(instr, index)) { | 1884 if (HasImmediateInput(instr, index)) { |
| 1845 __ movw(operand, Immediate(i.InputInt16(index))); | 1885 __ movw(operand, Immediate(i.InputInt16(index))); |
| 1846 } else { | 1886 } else { |
| 1847 __ movw(operand, i.InputRegister(index)); | 1887 __ movw(operand, i.InputRegister(index)); |
| 1848 } | 1888 } |
| 1849 break; | 1889 break; |
| 1850 } | 1890 } |
| 1851 case kX64Movl: | 1891 case kX64Movl: |
| 1892 case kX64TrapMovl: |
| 1852 if (instr->HasOutput()) { | 1893 if (instr->HasOutput()) { |
| 1853 if (instr->addressing_mode() == kMode_None) { | 1894 if (instr->addressing_mode() == kMode_None) { |
| 1854 if (instr->InputAt(0)->IsRegister()) { | 1895 if (instr->InputAt(0)->IsRegister()) { |
| 1855 __ movl(i.OutputRegister(), i.InputRegister(0)); | 1896 __ movl(i.OutputRegister(), i.InputRegister(0)); |
| 1856 } else { | 1897 } else { |
| 1857 __ movl(i.OutputRegister(), i.InputOperand(0)); | 1898 __ movl(i.OutputRegister(), i.InputOperand(0)); |
| 1858 } | 1899 } |
| 1859 } else { | 1900 } else { |
| 1901 auto pc = __ GetPC(); |
| 1860 __ movl(i.OutputRegister(), i.MemoryOperand()); | 1902 __ movl(i.OutputRegister(), i.MemoryOperand()); |
| 1903 |
| 1904 if (arch_opcode == kX64TrapMovl) { |
| 1905 const auto needs_frame = !frame_access_state()->has_frame(); |
| 1906 new (zone()) OutOfLineTrap(this, pc, needs_frame, |
| 1907 i.InputRegister(2), i.InputInt32(3)); |
| 1908 } |
| 1861 } | 1909 } |
| 1862 __ AssertZeroExtended(i.OutputRegister()); | 1910 __ AssertZeroExtended(i.OutputRegister()); |
| 1863 } else { | 1911 } else { |
| 1864 size_t index = 0; | 1912 size_t index = 0; |
| 1865 Operand operand = i.MemoryOperand(&index); | 1913 Operand operand = i.MemoryOperand(&index); |
| 1866 if (HasImmediateInput(instr, index)) { | 1914 if (HasImmediateInput(instr, index)) { |
| 1867 __ movl(operand, i.InputImmediate(index)); | 1915 __ movl(operand, i.InputImmediate(index)); |
| 1868 } else { | 1916 } else { |
| 1869 __ movl(operand, i.InputRegister(index)); | 1917 __ movl(operand, i.InputRegister(index)); |
| 1870 } | 1918 } |
| (...skipping 799 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2670 int padding_size = last_lazy_deopt_pc_ + space_needed - current_pc; | 2718 int padding_size = last_lazy_deopt_pc_ + space_needed - current_pc; |
| 2671 __ Nop(padding_size); | 2719 __ Nop(padding_size); |
| 2672 } | 2720 } |
| 2673 } | 2721 } |
| 2674 | 2722 |
| 2675 #undef __ | 2723 #undef __ |
| 2676 | 2724 |
| 2677 } // namespace compiler | 2725 } // namespace compiler |
| 2678 } // namespace internal | 2726 } // namespace internal |
| 2679 } // namespace v8 | 2727 } // namespace v8 |
| OLD | NEW |