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 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 __ CallRuntime(Runtime::kThrowWasmError); | 295 __ CallRuntime(Runtime::kThrowWasmError); |
296 } | 296 } |
297 | 297 |
298 private: | 298 private: |
299 Address pc_; | 299 Address pc_; |
300 bool frame_elided_; | 300 bool frame_elided_; |
301 Register context_; | 301 Register context_; |
302 int32_t position_; | 302 int32_t position_; |
303 }; | 303 }; |
304 | 304 |
| 305 void EmitOOLTrapIfNeeded(Zone* zone, CodeGenerator* codegen, |
| 306 InstructionCode opcode, X64OperandConverter& i, |
| 307 Address pc) { |
| 308 X64MemoryProtection protection = |
| 309 static_cast<X64MemoryProtection>(MiscField::decode(opcode)); |
| 310 if (protection == X64MemoryProtection::kProtected) { |
| 311 bool frame_elided = !codegen->frame_access_state()->has_frame(); |
| 312 new (zone) WasmOutOfLineTrap(codegen, pc, frame_elided, i.InputRegister(2), |
| 313 i.InputInt32(3)); |
| 314 } |
| 315 } |
305 } // namespace | 316 } // namespace |
306 | 317 |
307 | 318 |
308 #define ASSEMBLE_UNOP(asm_instr) \ | 319 #define ASSEMBLE_UNOP(asm_instr) \ |
309 do { \ | 320 do { \ |
310 if (instr->Output()->IsRegister()) { \ | 321 if (instr->Output()->IsRegister()) { \ |
311 __ asm_instr(i.OutputRegister()); \ | 322 __ asm_instr(i.OutputRegister()); \ |
312 } else { \ | 323 } else { \ |
313 __ asm_instr(i.OutputOperand()); \ | 324 __ asm_instr(i.OutputOperand()); \ |
314 } \ | 325 } \ |
(...skipping 1517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1832 i.InputOperand(0)); | 1843 i.InputOperand(0)); |
1833 } | 1844 } |
1834 break; | 1845 break; |
1835 } | 1846 } |
1836 case kSSEFloat64SilenceNaN: | 1847 case kSSEFloat64SilenceNaN: |
1837 __ Xorpd(kScratchDoubleReg, kScratchDoubleReg); | 1848 __ Xorpd(kScratchDoubleReg, kScratchDoubleReg); |
1838 __ Subsd(i.InputDoubleRegister(0), kScratchDoubleReg); | 1849 __ Subsd(i.InputDoubleRegister(0), kScratchDoubleReg); |
1839 break; | 1850 break; |
1840 case kX64Movsxbl: | 1851 case kX64Movsxbl: |
1841 ASSEMBLE_MOVX(movsxbl); | 1852 ASSEMBLE_MOVX(movsxbl); |
| 1853 EmitOOLTrapIfNeeded(zone(), this, opcode, i, __ pc()); |
1842 __ AssertZeroExtended(i.OutputRegister()); | 1854 __ AssertZeroExtended(i.OutputRegister()); |
1843 break; | 1855 break; |
1844 case kX64Movzxbl: | 1856 case kX64Movzxbl: |
1845 ASSEMBLE_MOVX(movzxbl); | 1857 ASSEMBLE_MOVX(movzxbl); |
| 1858 EmitOOLTrapIfNeeded(zone(), this, opcode, i, __ pc()); |
1846 __ AssertZeroExtended(i.OutputRegister()); | 1859 __ AssertZeroExtended(i.OutputRegister()); |
1847 break; | 1860 break; |
1848 case kX64Movsxbq: | 1861 case kX64Movsxbq: |
1849 ASSEMBLE_MOVX(movsxbq); | 1862 ASSEMBLE_MOVX(movsxbq); |
| 1863 EmitOOLTrapIfNeeded(zone(), this, opcode, i, __ pc()); |
1850 break; | 1864 break; |
1851 case kX64Movzxbq: | 1865 case kX64Movzxbq: |
1852 ASSEMBLE_MOVX(movzxbq); | 1866 ASSEMBLE_MOVX(movzxbq); |
| 1867 EmitOOLTrapIfNeeded(zone(), this, opcode, i, __ pc()); |
1853 __ AssertZeroExtended(i.OutputRegister()); | 1868 __ AssertZeroExtended(i.OutputRegister()); |
1854 break; | 1869 break; |
1855 case kX64Movb: { | 1870 case kX64Movb: { |
1856 size_t index = 0; | 1871 size_t index = 0; |
1857 Operand operand = i.MemoryOperand(&index); | 1872 Operand operand = i.MemoryOperand(&index); |
1858 if (HasImmediateInput(instr, index)) { | 1873 if (HasImmediateInput(instr, index)) { |
1859 __ movb(operand, Immediate(i.InputInt8(index))); | 1874 __ movb(operand, Immediate(i.InputInt8(index))); |
1860 } else { | 1875 } else { |
1861 __ movb(operand, i.InputRegister(index)); | 1876 __ movb(operand, i.InputRegister(index)); |
1862 } | 1877 } |
| 1878 EmitOOLTrapIfNeeded(zone(), this, opcode, i, __ pc()); |
1863 break; | 1879 break; |
1864 } | 1880 } |
1865 case kX64Movsxwl: | 1881 case kX64Movsxwl: |
1866 ASSEMBLE_MOVX(movsxwl); | 1882 ASSEMBLE_MOVX(movsxwl); |
| 1883 EmitOOLTrapIfNeeded(zone(), this, opcode, i, __ pc()); |
1867 __ AssertZeroExtended(i.OutputRegister()); | 1884 __ AssertZeroExtended(i.OutputRegister()); |
1868 break; | 1885 break; |
1869 case kX64Movzxwl: | 1886 case kX64Movzxwl: |
1870 ASSEMBLE_MOVX(movzxwl); | 1887 ASSEMBLE_MOVX(movzxwl); |
| 1888 EmitOOLTrapIfNeeded(zone(), this, opcode, i, __ pc()); |
1871 __ AssertZeroExtended(i.OutputRegister()); | 1889 __ AssertZeroExtended(i.OutputRegister()); |
1872 break; | 1890 break; |
1873 case kX64Movsxwq: | 1891 case kX64Movsxwq: |
1874 ASSEMBLE_MOVX(movsxwq); | 1892 ASSEMBLE_MOVX(movsxwq); |
| 1893 EmitOOLTrapIfNeeded(zone(), this, opcode, i, __ pc()); |
1875 break; | 1894 break; |
1876 case kX64Movzxwq: | 1895 case kX64Movzxwq: |
1877 ASSEMBLE_MOVX(movzxwq); | 1896 ASSEMBLE_MOVX(movzxwq); |
| 1897 EmitOOLTrapIfNeeded(zone(), this, opcode, i, __ pc()); |
1878 __ AssertZeroExtended(i.OutputRegister()); | 1898 __ AssertZeroExtended(i.OutputRegister()); |
1879 break; | 1899 break; |
1880 case kX64Movw: { | 1900 case kX64Movw: { |
1881 size_t index = 0; | 1901 size_t index = 0; |
1882 Operand operand = i.MemoryOperand(&index); | 1902 Operand operand = i.MemoryOperand(&index); |
1883 if (HasImmediateInput(instr, index)) { | 1903 if (HasImmediateInput(instr, index)) { |
1884 __ movw(operand, Immediate(i.InputInt16(index))); | 1904 __ movw(operand, Immediate(i.InputInt16(index))); |
1885 } else { | 1905 } else { |
1886 __ movw(operand, i.InputRegister(index)); | 1906 __ movw(operand, i.InputRegister(index)); |
1887 } | 1907 } |
| 1908 EmitOOLTrapIfNeeded(zone(), this, opcode, i, __ pc()); |
1888 break; | 1909 break; |
1889 } | 1910 } |
1890 case kX64Movl: | 1911 case kX64Movl: |
1891 case kX64TrapMovl: | |
1892 if (instr->HasOutput()) { | 1912 if (instr->HasOutput()) { |
1893 if (instr->addressing_mode() == kMode_None) { | 1913 if (instr->addressing_mode() == kMode_None) { |
1894 if (instr->InputAt(0)->IsRegister()) { | 1914 if (instr->InputAt(0)->IsRegister()) { |
1895 __ movl(i.OutputRegister(), i.InputRegister(0)); | 1915 __ movl(i.OutputRegister(), i.InputRegister(0)); |
1896 } else { | 1916 } else { |
1897 __ movl(i.OutputRegister(), i.InputOperand(0)); | 1917 __ movl(i.OutputRegister(), i.InputOperand(0)); |
1898 } | 1918 } |
1899 } else { | 1919 } else { |
1900 Address pc = __ pc(); | |
1901 __ movl(i.OutputRegister(), i.MemoryOperand()); | 1920 __ movl(i.OutputRegister(), i.MemoryOperand()); |
1902 | |
1903 if (arch_opcode == kX64TrapMovl) { | |
1904 bool frame_elided = !frame_access_state()->has_frame(); | |
1905 new (zone()) WasmOutOfLineTrap(this, pc, frame_elided, | |
1906 i.InputRegister(2), i.InputInt32(3)); | |
1907 } | |
1908 } | 1921 } |
| 1922 EmitOOLTrapIfNeeded(zone(), this, opcode, i, __ pc()); |
1909 __ AssertZeroExtended(i.OutputRegister()); | 1923 __ AssertZeroExtended(i.OutputRegister()); |
1910 } else { | 1924 } else { |
1911 size_t index = 0; | 1925 size_t index = 0; |
1912 Operand operand = i.MemoryOperand(&index); | 1926 Operand operand = i.MemoryOperand(&index); |
1913 if (HasImmediateInput(instr, index)) { | 1927 if (HasImmediateInput(instr, index)) { |
1914 __ movl(operand, i.InputImmediate(index)); | 1928 __ movl(operand, i.InputImmediate(index)); |
1915 } else { | 1929 } else { |
1916 __ movl(operand, i.InputRegister(index)); | 1930 __ movl(operand, i.InputRegister(index)); |
1917 } | 1931 } |
| 1932 EmitOOLTrapIfNeeded(zone(), this, opcode, i, __ pc()); |
1918 } | 1933 } |
1919 break; | 1934 break; |
1920 case kX64Movsxlq: | 1935 case kX64Movsxlq: |
1921 ASSEMBLE_MOVX(movsxlq); | 1936 ASSEMBLE_MOVX(movsxlq); |
| 1937 EmitOOLTrapIfNeeded(zone(), this, opcode, i, __ pc()); |
1922 break; | 1938 break; |
1923 case kX64Movq: | 1939 case kX64Movq: |
1924 if (instr->HasOutput()) { | 1940 if (instr->HasOutput()) { |
1925 __ movq(i.OutputRegister(), i.MemoryOperand()); | 1941 __ movq(i.OutputRegister(), i.MemoryOperand()); |
1926 } else { | 1942 } else { |
1927 size_t index = 0; | 1943 size_t index = 0; |
1928 Operand operand = i.MemoryOperand(&index); | 1944 Operand operand = i.MemoryOperand(&index); |
1929 if (HasImmediateInput(instr, index)) { | 1945 if (HasImmediateInput(instr, index)) { |
1930 __ movq(operand, i.InputImmediate(index)); | 1946 __ movq(operand, i.InputImmediate(index)); |
1931 } else { | 1947 } else { |
1932 __ movq(operand, i.InputRegister(index)); | 1948 __ movq(operand, i.InputRegister(index)); |
1933 } | 1949 } |
1934 } | 1950 } |
| 1951 EmitOOLTrapIfNeeded(zone(), this, opcode, i, __ pc()); |
1935 break; | 1952 break; |
1936 case kX64Movss: | 1953 case kX64Movss: |
1937 if (instr->HasOutput()) { | 1954 if (instr->HasOutput()) { |
1938 __ movss(i.OutputDoubleRegister(), i.MemoryOperand()); | 1955 __ movss(i.OutputDoubleRegister(), i.MemoryOperand()); |
1939 } else { | 1956 } else { |
1940 size_t index = 0; | 1957 size_t index = 0; |
1941 Operand operand = i.MemoryOperand(&index); | 1958 Operand operand = i.MemoryOperand(&index); |
1942 __ movss(operand, i.InputDoubleRegister(index)); | 1959 __ movss(operand, i.InputDoubleRegister(index)); |
1943 } | 1960 } |
| 1961 EmitOOLTrapIfNeeded(zone(), this, opcode, i, __ pc()); |
1944 break; | 1962 break; |
1945 case kX64Movsd: | 1963 case kX64Movsd: |
1946 if (instr->HasOutput()) { | 1964 if (instr->HasOutput()) { |
1947 __ Movsd(i.OutputDoubleRegister(), i.MemoryOperand()); | 1965 __ Movsd(i.OutputDoubleRegister(), i.MemoryOperand()); |
1948 } else { | 1966 } else { |
1949 size_t index = 0; | 1967 size_t index = 0; |
1950 Operand operand = i.MemoryOperand(&index); | 1968 Operand operand = i.MemoryOperand(&index); |
1951 __ Movsd(operand, i.InputDoubleRegister(index)); | 1969 __ Movsd(operand, i.InputDoubleRegister(index)); |
1952 } | 1970 } |
| 1971 EmitOOLTrapIfNeeded(zone(), this, opcode, i, __ pc()); |
1953 break; | 1972 break; |
1954 case kX64BitcastFI: | 1973 case kX64BitcastFI: |
1955 if (instr->InputAt(0)->IsFPStackSlot()) { | 1974 if (instr->InputAt(0)->IsFPStackSlot()) { |
1956 __ movl(i.OutputRegister(), i.InputOperand(0)); | 1975 __ movl(i.OutputRegister(), i.InputOperand(0)); |
1957 } else { | 1976 } else { |
1958 __ Movd(i.OutputRegister(), i.InputDoubleRegister(0)); | 1977 __ Movd(i.OutputRegister(), i.InputDoubleRegister(0)); |
1959 } | 1978 } |
1960 break; | 1979 break; |
1961 case kX64BitcastDL: | 1980 case kX64BitcastDL: |
1962 if (instr->InputAt(0)->IsFPStackSlot()) { | 1981 if (instr->InputAt(0)->IsFPStackSlot()) { |
(...skipping 814 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2777 int padding_size = last_lazy_deopt_pc_ + space_needed - current_pc; | 2796 int padding_size = last_lazy_deopt_pc_ + space_needed - current_pc; |
2778 __ Nop(padding_size); | 2797 __ Nop(padding_size); |
2779 } | 2798 } |
2780 } | 2799 } |
2781 | 2800 |
2782 #undef __ | 2801 #undef __ |
2783 | 2802 |
2784 } // namespace compiler | 2803 } // namespace compiler |
2785 } // namespace internal | 2804 } // namespace internal |
2786 } // namespace v8 | 2805 } // namespace v8 |
OLD | NEW |