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 <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 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 Operand const operand_; | 263 Operand const operand_; |
264 Register const value_; | 264 Register const value_; |
265 Register const scratch0_; | 265 Register const scratch0_; |
266 Register const scratch1_; | 266 Register const scratch1_; |
267 RecordWriteMode const mode_; | 267 RecordWriteMode const mode_; |
268 }; | 268 }; |
269 | 269 |
270 class WasmOutOfLineTrap final : public OutOfLineCode { | 270 class WasmOutOfLineTrap final : public OutOfLineCode { |
271 public: | 271 public: |
272 WasmOutOfLineTrap(CodeGenerator* gen, int pc, bool frame_elided, | 272 WasmOutOfLineTrap(CodeGenerator* gen, int pc, bool frame_elided, |
273 int32_t position) | 273 int32_t position, Instruction* instr) |
274 : OutOfLineCode(gen), | 274 : OutOfLineCode(gen), |
275 gen_(gen), | 275 gen_(gen), |
276 pc_(pc), | 276 pc_(pc), |
277 frame_elided_(frame_elided), | 277 frame_elided_(frame_elided), |
278 position_(position) {} | 278 position_(position), |
| 279 instr_(instr) {} |
279 | 280 |
280 // TODO(eholk): Refactor this method to take the code generator as a | 281 // TODO(eholk): Refactor this method to take the code generator as a |
281 // parameter. | 282 // parameter. |
282 void Generate() final { | 283 void Generate() final { |
283 __ RecordProtectedInstructionLanding(pc_); | 284 __ RecordProtectedInstructionLanding(pc_); |
284 | 285 |
285 if (frame_elided_) { | 286 if (frame_elided_) { |
286 __ EnterFrame(StackFrame::WASM_COMPILED); | 287 __ EnterFrame(StackFrame::WASM_COMPILED); |
287 } | 288 } |
288 | 289 |
289 wasm::TrapReason trap_id = wasm::kTrapMemOutOfBounds; | 290 wasm::TrapReason trap_id = wasm::kTrapMemOutOfBounds; |
290 int trap_reason = wasm::WasmOpcodes::TrapReasonToMessageId(trap_id); | 291 int trap_reason = wasm::WasmOpcodes::TrapReasonToMessageId(trap_id); |
291 __ Push(Smi::FromInt(trap_reason)); | 292 __ Push(Smi::FromInt(trap_reason)); |
292 // TODO(eholk): use AssembleSourcePosition instead of passing in position_ | |
293 // as a parameter. See AssembleArchTrap as an example. Consider sharing code | |
294 // with AssembleArchTrap. | |
295 __ Push(Smi::FromInt(position_)); | 293 __ Push(Smi::FromInt(position_)); |
296 __ Move(rsi, Smi::kZero); | 294 __ Move(rsi, gen_->isolate()->native_context()); |
297 __ CallRuntime(Runtime::kThrowWasmError); | 295 __ CallRuntime(Runtime::kThrowWasmError); |
298 | 296 |
299 ReferenceMap* reference_map = | 297 if (instr_->reference_map() != nullptr) { |
300 new (gen_->code()->zone()) ReferenceMap(gen_->code()->zone()); | 298 gen_->RecordSafepoint(instr_->reference_map(), Safepoint::kSimple, 0, |
301 gen_->RecordSafepoint(reference_map, Safepoint::kSimple, 0, | 299 Safepoint::kNoLazyDeopt); |
302 Safepoint::kNoLazyDeopt); | 300 } |
303 } | 301 } |
304 | 302 |
305 private: | 303 private: |
306 CodeGenerator* gen_; | 304 CodeGenerator* gen_; |
307 int pc_; | 305 int pc_; |
308 bool frame_elided_; | 306 bool frame_elided_; |
309 int32_t position_; | 307 int32_t position_; |
| 308 Instruction* instr_; |
310 }; | 309 }; |
311 | 310 |
312 void EmitOOLTrapIfNeeded(Zone* zone, CodeGenerator* codegen, | 311 void EmitOOLTrapIfNeeded(Zone* zone, CodeGenerator* codegen, |
313 InstructionCode opcode, size_t input_count, | 312 InstructionCode opcode, size_t input_count, |
314 X64OperandConverter& i, int pc) { | 313 X64OperandConverter& i, int pc, Instruction* instr) { |
315 const X64MemoryProtection protection = | 314 const X64MemoryProtection protection = |
316 static_cast<X64MemoryProtection>(MiscField::decode(opcode)); | 315 static_cast<X64MemoryProtection>(MiscField::decode(opcode)); |
317 if (protection == X64MemoryProtection::kProtected) { | 316 if (protection == X64MemoryProtection::kProtected) { |
318 const bool frame_elided = !codegen->frame_access_state()->has_frame(); | 317 const bool frame_elided = !codegen->frame_access_state()->has_frame(); |
319 const int32_t position = i.InputInt32(input_count - 1); | 318 const int32_t position = i.InputInt32(input_count - 1); |
320 new (zone) WasmOutOfLineTrap(codegen, pc, frame_elided, position); | 319 new (zone) WasmOutOfLineTrap(codegen, pc, frame_elided, position, instr); |
321 } | 320 } |
322 } | 321 } |
323 } // namespace | 322 } // namespace |
324 | 323 |
325 | 324 |
326 #define ASSEMBLE_UNOP(asm_instr) \ | 325 #define ASSEMBLE_UNOP(asm_instr) \ |
327 do { \ | 326 do { \ |
328 if (instr->Output()->IsRegister()) { \ | 327 if (instr->Output()->IsRegister()) { \ |
329 __ asm_instr(i.OutputRegister()); \ | 328 __ asm_instr(i.OutputRegister()); \ |
330 } else { \ | 329 } else { \ |
(...skipping 1522 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1853 i.InputOperand(0)); | 1852 i.InputOperand(0)); |
1854 } | 1853 } |
1855 break; | 1854 break; |
1856 } | 1855 } |
1857 case kSSEFloat64SilenceNaN: | 1856 case kSSEFloat64SilenceNaN: |
1858 __ Xorpd(kScratchDoubleReg, kScratchDoubleReg); | 1857 __ Xorpd(kScratchDoubleReg, kScratchDoubleReg); |
1859 __ Subsd(i.InputDoubleRegister(0), kScratchDoubleReg); | 1858 __ Subsd(i.InputDoubleRegister(0), kScratchDoubleReg); |
1860 break; | 1859 break; |
1861 case kX64Movsxbl: | 1860 case kX64Movsxbl: |
1862 EmitOOLTrapIfNeeded(zone(), this, opcode, instr->InputCount(), i, | 1861 EmitOOLTrapIfNeeded(zone(), this, opcode, instr->InputCount(), i, |
1863 __ pc_offset()); | 1862 __ pc_offset(), instr); |
1864 ASSEMBLE_MOVX(movsxbl); | 1863 ASSEMBLE_MOVX(movsxbl); |
1865 __ AssertZeroExtended(i.OutputRegister()); | 1864 __ AssertZeroExtended(i.OutputRegister()); |
1866 break; | 1865 break; |
1867 case kX64Movzxbl: | 1866 case kX64Movzxbl: |
1868 EmitOOLTrapIfNeeded(zone(), this, opcode, instr->InputCount(), i, | 1867 EmitOOLTrapIfNeeded(zone(), this, opcode, instr->InputCount(), i, |
1869 __ pc_offset()); | 1868 __ pc_offset(), instr); |
1870 ASSEMBLE_MOVX(movzxbl); | 1869 ASSEMBLE_MOVX(movzxbl); |
1871 __ AssertZeroExtended(i.OutputRegister()); | 1870 __ AssertZeroExtended(i.OutputRegister()); |
1872 break; | 1871 break; |
1873 case kX64Movsxbq: | 1872 case kX64Movsxbq: |
1874 EmitOOLTrapIfNeeded(zone(), this, opcode, instr->InputCount(), i, | 1873 EmitOOLTrapIfNeeded(zone(), this, opcode, instr->InputCount(), i, |
1875 __ pc_offset()); | 1874 __ pc_offset(), instr); |
1876 ASSEMBLE_MOVX(movsxbq); | 1875 ASSEMBLE_MOVX(movsxbq); |
1877 break; | 1876 break; |
1878 case kX64Movzxbq: | 1877 case kX64Movzxbq: |
1879 EmitOOLTrapIfNeeded(zone(), this, opcode, instr->InputCount(), i, | 1878 EmitOOLTrapIfNeeded(zone(), this, opcode, instr->InputCount(), i, |
1880 __ pc_offset()); | 1879 __ pc_offset(), instr); |
1881 ASSEMBLE_MOVX(movzxbq); | 1880 ASSEMBLE_MOVX(movzxbq); |
1882 __ AssertZeroExtended(i.OutputRegister()); | 1881 __ AssertZeroExtended(i.OutputRegister()); |
1883 break; | 1882 break; |
1884 case kX64Movb: { | 1883 case kX64Movb: { |
1885 EmitOOLTrapIfNeeded(zone(), this, opcode, instr->InputCount(), i, | 1884 EmitOOLTrapIfNeeded(zone(), this, opcode, instr->InputCount(), i, |
1886 __ pc_offset()); | 1885 __ pc_offset(), instr); |
1887 size_t index = 0; | 1886 size_t index = 0; |
1888 Operand operand = i.MemoryOperand(&index); | 1887 Operand operand = i.MemoryOperand(&index); |
1889 if (HasImmediateInput(instr, index)) { | 1888 if (HasImmediateInput(instr, index)) { |
1890 __ movb(operand, Immediate(i.InputInt8(index))); | 1889 __ movb(operand, Immediate(i.InputInt8(index))); |
1891 } else { | 1890 } else { |
1892 __ movb(operand, i.InputRegister(index)); | 1891 __ movb(operand, i.InputRegister(index)); |
1893 } | 1892 } |
1894 break; | 1893 break; |
1895 } | 1894 } |
1896 case kX64Movsxwl: | 1895 case kX64Movsxwl: |
1897 EmitOOLTrapIfNeeded(zone(), this, opcode, instr->InputCount(), i, | 1896 EmitOOLTrapIfNeeded(zone(), this, opcode, instr->InputCount(), i, |
1898 __ pc_offset()); | 1897 __ pc_offset(), instr); |
1899 ASSEMBLE_MOVX(movsxwl); | 1898 ASSEMBLE_MOVX(movsxwl); |
1900 __ AssertZeroExtended(i.OutputRegister()); | 1899 __ AssertZeroExtended(i.OutputRegister()); |
1901 break; | 1900 break; |
1902 case kX64Movzxwl: | 1901 case kX64Movzxwl: |
1903 EmitOOLTrapIfNeeded(zone(), this, opcode, instr->InputCount(), i, | 1902 EmitOOLTrapIfNeeded(zone(), this, opcode, instr->InputCount(), i, |
1904 __ pc_offset()); | 1903 __ pc_offset(), instr); |
1905 ASSEMBLE_MOVX(movzxwl); | 1904 ASSEMBLE_MOVX(movzxwl); |
1906 __ AssertZeroExtended(i.OutputRegister()); | 1905 __ AssertZeroExtended(i.OutputRegister()); |
1907 break; | 1906 break; |
1908 case kX64Movsxwq: | 1907 case kX64Movsxwq: |
1909 EmitOOLTrapIfNeeded(zone(), this, opcode, instr->InputCount(), i, | 1908 EmitOOLTrapIfNeeded(zone(), this, opcode, instr->InputCount(), i, |
1910 __ pc_offset()); | 1909 __ pc_offset(), instr); |
1911 ASSEMBLE_MOVX(movsxwq); | 1910 ASSEMBLE_MOVX(movsxwq); |
1912 break; | 1911 break; |
1913 case kX64Movzxwq: | 1912 case kX64Movzxwq: |
1914 EmitOOLTrapIfNeeded(zone(), this, opcode, instr->InputCount(), i, | 1913 EmitOOLTrapIfNeeded(zone(), this, opcode, instr->InputCount(), i, |
1915 __ pc_offset()); | 1914 __ pc_offset(), instr); |
1916 ASSEMBLE_MOVX(movzxwq); | 1915 ASSEMBLE_MOVX(movzxwq); |
1917 __ AssertZeroExtended(i.OutputRegister()); | 1916 __ AssertZeroExtended(i.OutputRegister()); |
1918 break; | 1917 break; |
1919 case kX64Movw: { | 1918 case kX64Movw: { |
1920 EmitOOLTrapIfNeeded(zone(), this, opcode, instr->InputCount(), i, | 1919 EmitOOLTrapIfNeeded(zone(), this, opcode, instr->InputCount(), i, |
1921 __ pc_offset()); | 1920 __ pc_offset(), instr); |
1922 size_t index = 0; | 1921 size_t index = 0; |
1923 Operand operand = i.MemoryOperand(&index); | 1922 Operand operand = i.MemoryOperand(&index); |
1924 if (HasImmediateInput(instr, index)) { | 1923 if (HasImmediateInput(instr, index)) { |
1925 __ movw(operand, Immediate(i.InputInt16(index))); | 1924 __ movw(operand, Immediate(i.InputInt16(index))); |
1926 } else { | 1925 } else { |
1927 __ movw(operand, i.InputRegister(index)); | 1926 __ movw(operand, i.InputRegister(index)); |
1928 } | 1927 } |
1929 break; | 1928 break; |
1930 } | 1929 } |
1931 case kX64Movl: | 1930 case kX64Movl: |
1932 EmitOOLTrapIfNeeded(zone(), this, opcode, instr->InputCount(), i, | 1931 EmitOOLTrapIfNeeded(zone(), this, opcode, instr->InputCount(), i, |
1933 __ pc_offset()); | 1932 __ pc_offset(), instr); |
1934 if (instr->HasOutput()) { | 1933 if (instr->HasOutput()) { |
1935 if (instr->addressing_mode() == kMode_None) { | 1934 if (instr->addressing_mode() == kMode_None) { |
1936 if (instr->InputAt(0)->IsRegister()) { | 1935 if (instr->InputAt(0)->IsRegister()) { |
1937 __ movl(i.OutputRegister(), i.InputRegister(0)); | 1936 __ movl(i.OutputRegister(), i.InputRegister(0)); |
1938 } else { | 1937 } else { |
1939 __ movl(i.OutputRegister(), i.InputOperand(0)); | 1938 __ movl(i.OutputRegister(), i.InputOperand(0)); |
1940 } | 1939 } |
1941 } else { | 1940 } else { |
1942 __ movl(i.OutputRegister(), i.MemoryOperand()); | 1941 __ movl(i.OutputRegister(), i.MemoryOperand()); |
1943 } | 1942 } |
1944 __ AssertZeroExtended(i.OutputRegister()); | 1943 __ AssertZeroExtended(i.OutputRegister()); |
1945 } else { | 1944 } else { |
1946 size_t index = 0; | 1945 size_t index = 0; |
1947 Operand operand = i.MemoryOperand(&index); | 1946 Operand operand = i.MemoryOperand(&index); |
1948 if (HasImmediateInput(instr, index)) { | 1947 if (HasImmediateInput(instr, index)) { |
1949 __ movl(operand, i.InputImmediate(index)); | 1948 __ movl(operand, i.InputImmediate(index)); |
1950 } else { | 1949 } else { |
1951 __ movl(operand, i.InputRegister(index)); | 1950 __ movl(operand, i.InputRegister(index)); |
1952 } | 1951 } |
1953 } | 1952 } |
1954 break; | 1953 break; |
1955 case kX64Movsxlq: | 1954 case kX64Movsxlq: |
1956 EmitOOLTrapIfNeeded(zone(), this, opcode, instr->InputCount(), i, | 1955 EmitOOLTrapIfNeeded(zone(), this, opcode, instr->InputCount(), i, |
1957 __ pc_offset()); | 1956 __ pc_offset(), instr); |
1958 ASSEMBLE_MOVX(movsxlq); | 1957 ASSEMBLE_MOVX(movsxlq); |
1959 break; | 1958 break; |
1960 case kX64Movq: | 1959 case kX64Movq: |
1961 EmitOOLTrapIfNeeded(zone(), this, opcode, instr->InputCount(), i, | 1960 EmitOOLTrapIfNeeded(zone(), this, opcode, instr->InputCount(), i, |
1962 __ pc_offset()); | 1961 __ pc_offset(), instr); |
1963 if (instr->HasOutput()) { | 1962 if (instr->HasOutput()) { |
1964 __ movq(i.OutputRegister(), i.MemoryOperand()); | 1963 __ movq(i.OutputRegister(), i.MemoryOperand()); |
1965 } else { | 1964 } else { |
1966 size_t index = 0; | 1965 size_t index = 0; |
1967 Operand operand = i.MemoryOperand(&index); | 1966 Operand operand = i.MemoryOperand(&index); |
1968 if (HasImmediateInput(instr, index)) { | 1967 if (HasImmediateInput(instr, index)) { |
1969 __ movq(operand, i.InputImmediate(index)); | 1968 __ movq(operand, i.InputImmediate(index)); |
1970 } else { | 1969 } else { |
1971 __ movq(operand, i.InputRegister(index)); | 1970 __ movq(operand, i.InputRegister(index)); |
1972 } | 1971 } |
1973 } | 1972 } |
1974 break; | 1973 break; |
1975 case kX64Movss: | 1974 case kX64Movss: |
1976 EmitOOLTrapIfNeeded(zone(), this, opcode, instr->InputCount(), i, | 1975 EmitOOLTrapIfNeeded(zone(), this, opcode, instr->InputCount(), i, |
1977 __ pc_offset()); | 1976 __ pc_offset(), instr); |
1978 if (instr->HasOutput()) { | 1977 if (instr->HasOutput()) { |
1979 __ movss(i.OutputDoubleRegister(), i.MemoryOperand()); | 1978 __ movss(i.OutputDoubleRegister(), i.MemoryOperand()); |
1980 } else { | 1979 } else { |
1981 size_t index = 0; | 1980 size_t index = 0; |
1982 Operand operand = i.MemoryOperand(&index); | 1981 Operand operand = i.MemoryOperand(&index); |
1983 __ movss(operand, i.InputDoubleRegister(index)); | 1982 __ movss(operand, i.InputDoubleRegister(index)); |
1984 } | 1983 } |
1985 break; | 1984 break; |
1986 case kX64Movsd: | 1985 case kX64Movsd: |
1987 EmitOOLTrapIfNeeded(zone(), this, opcode, instr->InputCount(), i, | 1986 EmitOOLTrapIfNeeded(zone(), this, opcode, instr->InputCount(), i, |
1988 __ pc_offset()); | 1987 __ pc_offset(), instr); |
1989 if (instr->HasOutput()) { | 1988 if (instr->HasOutput()) { |
1990 __ Movsd(i.OutputDoubleRegister(), i.MemoryOperand()); | 1989 __ Movsd(i.OutputDoubleRegister(), i.MemoryOperand()); |
1991 } else { | 1990 } else { |
1992 size_t index = 0; | 1991 size_t index = 0; |
1993 Operand operand = i.MemoryOperand(&index); | 1992 Operand operand = i.MemoryOperand(&index); |
1994 __ Movsd(operand, i.InputDoubleRegister(index)); | 1993 __ Movsd(operand, i.InputDoubleRegister(index)); |
1995 } | 1994 } |
1996 break; | 1995 break; |
1997 case kX64BitcastFI: | 1996 case kX64BitcastFI: |
1998 if (instr->InputAt(0)->IsFPStackSlot()) { | 1997 if (instr->InputAt(0)->IsFPStackSlot()) { |
(...skipping 880 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2879 int padding_size = last_lazy_deopt_pc_ + space_needed - current_pc; | 2878 int padding_size = last_lazy_deopt_pc_ + space_needed - current_pc; |
2880 __ Nop(padding_size); | 2879 __ Nop(padding_size); |
2881 } | 2880 } |
2882 } | 2881 } |
2883 | 2882 |
2884 #undef __ | 2883 #undef __ |
2885 | 2884 |
2886 } // namespace compiler | 2885 } // namespace compiler |
2887 } // namespace internal | 2886 } // namespace internal |
2888 } // namespace v8 | 2887 } // namespace v8 |
OLD | NEW |