OLD | NEW |
---|---|
1 //===- subzero/src/IceTargetLoweringX8632.cpp - x86-32 lowering -----------===// | 1 //===- subzero/src/IceTargetLoweringX8632.cpp - x86-32 lowering -----------===// |
2 // | 2 // |
3 // The Subzero Code Generator | 3 // The Subzero Code Generator |
4 // | 4 // |
5 // This file is distributed under the University of Illinois Open Source | 5 // This file is distributed under the University of Illinois Open Source |
6 // License. See LICENSE.TXT for details. | 6 // License. See LICENSE.TXT for details. |
7 // | 7 // |
8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
9 // | 9 // |
10 // This file implements the TargetLoweringX8632 class, which | 10 // This file implements the TargetLoweringX8632 class, which |
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
424 if (Arg->hasReg()) { | 424 if (Arg->hasReg()) { |
425 assert(Ty != IceType_i64); | 425 assert(Ty != IceType_i64); |
426 OperandX8632Mem *Mem = OperandX8632Mem::create( | 426 OperandX8632Mem *Mem = OperandX8632Mem::create( |
427 Func, Ty, FramePtr, | 427 Func, Ty, FramePtr, |
428 Ctx->getConstantInt(IceType_i32, Arg->getStackOffset())); | 428 Ctx->getConstantInt(IceType_i32, Arg->getStackOffset())); |
429 _mov(Arg, Mem); | 429 _mov(Arg, Mem); |
430 } | 430 } |
431 InArgsSizeBytes += typeWidthInBytesOnStack(Ty); | 431 InArgsSizeBytes += typeWidthInBytesOnStack(Ty); |
432 } | 432 } |
433 | 433 |
434 // static | |
435 Type TargetX8632::stackSlotType() { return IceType_i32; } | 434 Type TargetX8632::stackSlotType() { return IceType_i32; } |
436 | 435 |
437 void TargetX8632::addProlog(CfgNode *Node) { | 436 void TargetX8632::addProlog(CfgNode *Node) { |
438 // If SimpleCoalescing is false, each variable without a register | 437 // If SimpleCoalescing is false, each variable without a register |
439 // gets its own unique stack slot, which leads to large stack | 438 // gets its own unique stack slot, which leads to large stack |
440 // frames. If SimpleCoalescing is true, then each "global" variable | 439 // frames. If SimpleCoalescing is true, then each "global" variable |
441 // without a register gets its own slot, but "local" variable slots | 440 // without a register gets its own slot, but "local" variable slots |
442 // are reused across basic blocks. E.g., if A and B are local to | 441 // are reused across basic blocks. E.g., if A and B are local to |
443 // block 1 and C is local to block 2, then C may share a slot with A | 442 // block 1 and C is local to block 2, then C may share a slot with A |
444 // or B. | 443 // or B. |
(...skipping 1163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1608 assert(Src0RM->getType() == IceType_f64); | 1607 assert(Src0RM->getType() == IceType_f64); |
1609 // a.i64 = bitcast b.f64 ==> | 1608 // a.i64 = bitcast b.f64 ==> |
1610 // s.f64 = spill b.f64 | 1609 // s.f64 = spill b.f64 |
1611 // t_lo.i32 = lo(s.f64) | 1610 // t_lo.i32 = lo(s.f64) |
1612 // a_lo.i32 = t_lo.i32 | 1611 // a_lo.i32 = t_lo.i32 |
1613 // t_hi.i32 = hi(s.f64) | 1612 // t_hi.i32 = hi(s.f64) |
1614 // a_hi.i32 = t_hi.i32 | 1613 // a_hi.i32 = t_hi.i32 |
1615 Variable *Spill = Func->makeVariable(IceType_f64, Context.getNode()); | 1614 Variable *Spill = Func->makeVariable(IceType_f64, Context.getNode()); |
1616 Spill->setWeight(RegWeight::Zero); | 1615 Spill->setWeight(RegWeight::Zero); |
1617 Spill->setPreferredRegister(llvm::dyn_cast<Variable>(Src0RM), true); | 1616 Spill->setPreferredRegister(llvm::dyn_cast<Variable>(Src0RM), true); |
1618 _mov(Spill, Src0RM); | 1617 _movq(Spill, Src0RM); |
1619 | 1618 |
1620 Variable *DestLo = llvm::cast<Variable>(loOperand(Dest)); | 1619 Variable *DestLo = llvm::cast<Variable>(loOperand(Dest)); |
1621 Variable *DestHi = llvm::cast<Variable>(hiOperand(Dest)); | 1620 Variable *DestHi = llvm::cast<Variable>(hiOperand(Dest)); |
1622 Variable *T_Lo = makeReg(IceType_i32); | 1621 Variable *T_Lo = makeReg(IceType_i32); |
1623 Variable *T_Hi = makeReg(IceType_i32); | 1622 Variable *T_Hi = makeReg(IceType_i32); |
1624 VariableSplit *SpillLo = | 1623 VariableSplit *SpillLo = |
1625 VariableSplit::create(Func, Spill, VariableSplit::Low); | 1624 VariableSplit::create(Func, Spill, VariableSplit::Low); |
1626 VariableSplit *SpillHi = | 1625 VariableSplit *SpillHi = |
1627 VariableSplit::create(Func, Spill, VariableSplit::High); | 1626 VariableSplit::create(Func, Spill, VariableSplit::High); |
1628 | 1627 |
(...skipping 22 matching lines...) Expand all Loading... | |
1651 VariableSplit *SpillHi = | 1650 VariableSplit *SpillHi = |
1652 VariableSplit::create(Func, Spill, VariableSplit::High); | 1651 VariableSplit::create(Func, Spill, VariableSplit::High); |
1653 _mov(T_Lo, loOperand(Src0)); | 1652 _mov(T_Lo, loOperand(Src0)); |
1654 // Technically, the Spill is defined after the _store happens, but | 1653 // Technically, the Spill is defined after the _store happens, but |
1655 // SpillLo is considered a "use" of Spill so define Spill before it | 1654 // SpillLo is considered a "use" of Spill so define Spill before it |
1656 // is used. | 1655 // is used. |
1657 Context.insert(InstFakeDef::create(Func, Spill)); | 1656 Context.insert(InstFakeDef::create(Func, Spill)); |
1658 _store(T_Lo, SpillLo); | 1657 _store(T_Lo, SpillLo); |
1659 _mov(T_Hi, hiOperand(Src0)); | 1658 _mov(T_Hi, hiOperand(Src0)); |
1660 _store(T_Hi, SpillHi); | 1659 _store(T_Hi, SpillHi); |
1661 _mov(Dest, Spill); | 1660 _movq(Dest, Spill); |
1662 } break; | 1661 } break; |
1663 } | 1662 } |
1664 break; | 1663 break; |
1665 } | 1664 } |
1666 } | 1665 } |
1667 } | 1666 } |
1668 | 1667 |
1669 void TargetX8632::lowerFcmp(const InstFcmp *Inst) { | 1668 void TargetX8632::lowerFcmp(const InstFcmp *Inst) { |
1670 Operand *Src0 = Inst->getSrc(0); | 1669 Operand *Src0 = Inst->getSrc(0); |
1671 Operand *Src1 = Inst->getSrc(1); | 1670 Operand *Src1 = Inst->getSrc(1); |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1793 _mov(Dest, One); | 1792 _mov(Dest, One); |
1794 _br(getIcmp32Mapping(Inst->getCondition()), Label); | 1793 _br(getIcmp32Mapping(Inst->getCondition()), Label); |
1795 Context.insert(InstFakeUse::create(Func, Dest)); | 1794 Context.insert(InstFakeUse::create(Func, Dest)); |
1796 _mov(Dest, Zero); | 1795 _mov(Dest, Zero); |
1797 Context.insert(Label); | 1796 Context.insert(Label); |
1798 } | 1797 } |
1799 | 1798 |
1800 void TargetX8632::lowerIntrinsicCall(const InstIntrinsicCall *Instr) { | 1799 void TargetX8632::lowerIntrinsicCall(const InstIntrinsicCall *Instr) { |
1801 switch (Instr->getIntrinsicInfo().ID) { | 1800 switch (Instr->getIntrinsicInfo().ID) { |
1802 case Intrinsics::AtomicCmpxchg: | 1801 case Intrinsics::AtomicCmpxchg: |
1802 if (!Intrinsics::VerifyMemoryOrder( | |
1803 llvm::cast<ConstantInteger>(Instr->getArg(3))->getValue())) { | |
1804 Func->setError("Unexpected memory ordering (success) for AtomicCmpxchg"); | |
1805 return; | |
1806 } | |
1807 if (!Intrinsics::VerifyMemoryOrder( | |
1808 llvm::cast<ConstantInteger>(Instr->getArg(4))->getValue())) { | |
1809 Func->setError("Unexpected memory ordering (failure) for AtomicCmpxchg"); | |
1810 return; | |
1811 } | |
1812 // TODO(jvoung): fill it in. | |
1813 Func->setError("Unhandled intrinsic"); | |
1814 return; | |
1803 case Intrinsics::AtomicFence: | 1815 case Intrinsics::AtomicFence: |
1816 if (!Intrinsics::VerifyMemoryOrder( | |
1817 llvm::cast<ConstantInteger>(Instr->getArg(0))->getValue())) { | |
1818 Func->setError("Unexpected memory ordering for AtomicFence"); | |
1819 return; | |
1820 } | |
1821 _mfence(); | |
1822 return; | |
1804 case Intrinsics::AtomicFenceAll: | 1823 case Intrinsics::AtomicFenceAll: |
1805 case Intrinsics::AtomicIsLockFree: | 1824 // NOTE: FenceAll should prevent and load/store from being moved |
1806 case Intrinsics::AtomicLoad: | 1825 // across the fence (both atomic and non-atomic). The InstX8632Mfence |
1826 // instruction is currently marked coarsely as "HasSideEffects". | |
1827 _mfence(); | |
1828 return; | |
1829 case Intrinsics::AtomicIsLockFree: { | |
1830 // X86 is always lock free for 8/16/32/64 bit accesses. | |
1831 // TODO(jvoung): Since the result is constant when given a constant | |
1832 // byte size, this opens up DCE opportunities. | |
1833 Operand *ByteSize = Instr->getArg(0); | |
1834 Variable *Dest = Instr->getDest(); | |
1835 if (ConstantInteger *CI = llvm::dyn_cast<ConstantInteger>(ByteSize)) { | |
1836 Constant *Result; | |
1837 switch (CI->getValue()) { | |
1838 default: | |
1839 Result = Ctx->getConstantZero(IceType_i32); | |
JF
2014/06/24 23:50:37
Well, LOCK CMPXCHG16B can actually be used in x86
jvoung (off chromium)
2014/06/25 01:31:42
Okay, I see why you wanted the bit width check. Si
| |
1840 break; | |
1841 case 1: | |
1842 case 2: | |
1843 case 4: | |
1844 case 8: | |
1845 Result = Ctx->getConstantInt(IceType_i32, 1); | |
1846 break; | |
1847 } | |
1848 _mov(Dest, Result); | |
1849 return; | |
1850 } | |
1851 // The PNaCl ABI requires the byte size to be a compile-time constant. | |
1852 Func->setError("AtomicIsLockFree byte size should be compile-time const"); | |
1853 return; | |
1854 } | |
1855 case Intrinsics::AtomicLoad: { | |
1856 // We require the memory address to be naturally aligned. | |
1857 // Given that is the case, then normal loads are atomic. | |
1858 if (!Intrinsics::VerifyMemoryOrder( | |
1859 llvm::cast<ConstantInteger>(Instr->getArg(1))->getValue())) { | |
1860 Func->setError("Unexpected memory ordering for AtomicLoad"); | |
1861 return; | |
1862 } | |
1863 Variable *Dest = Instr->getDest(); | |
1864 if (Dest->getType() == IceType_i64) { | |
1865 // Follow what GCC does and use a movq instead of what lowerLoad() | |
1866 // normally does (split the load into two). | |
1867 // Thus, this skips load/arithmetic op folding. Load/arithmetic folding | |
1868 // can't happen anyway, since this is x86-32 and integer arithmetic only | |
1869 // happens on 32-bit quantities. | |
1870 Variable *T = makeReg(IceType_f64); | |
1871 OperandX8632Mem *Addr = FormMemoryOperand(Instr->getArg(0), IceType_f64); | |
1872 _movq(T, Addr); | |
1873 // Then cast the bits back out of the XMM register to the i64 Dest. | |
1874 InstCast *Cast = InstCast::create(Func, InstCast::Bitcast, Dest, T); | |
1875 lowerCast(Cast); | |
1876 // Make sure that the atomic load isn't elided. | |
1877 Context.insert(InstFakeUse::create(Func, Dest->getLo())); | |
1878 Context.insert(InstFakeUse::create(Func, Dest->getHi())); | |
1879 return; | |
1880 } | |
1881 InstLoad *Load = InstLoad::create(Func, Dest, Instr->getArg(0)); | |
1882 lowerLoad(Load); | |
1883 // Make sure the atomic load isn't elided. | |
1884 Context.insert(InstFakeUse::create(Func, Dest)); | |
1885 return; | |
1886 } | |
1807 case Intrinsics::AtomicRMW: | 1887 case Intrinsics::AtomicRMW: |
1808 case Intrinsics::AtomicStore: | 1888 if (!Intrinsics::VerifyMemoryOrder( |
1889 llvm::cast<ConstantInteger>(Instr->getArg(3))->getValue())) { | |
1890 Func->setError("Unexpected memory ordering for AtomicRMW"); | |
1891 return; | |
1892 } | |
1893 lowerAtomicRMW(Instr->getDest(), | |
1894 static_cast<uint32_t>(llvm::cast<ConstantInteger>( | |
1895 Instr->getArg(0))->getValue()), | |
1896 Instr->getArg(1), Instr->getArg(2)); | |
1897 return; | |
1898 case Intrinsics::AtomicStore: { | |
1899 if (!Intrinsics::VerifyMemoryOrder( | |
1900 llvm::cast<ConstantInteger>(Instr->getArg(2))->getValue())) { | |
1901 Func->setError("Unexpected memory ordering for AtomicStore"); | |
1902 return; | |
1903 } | |
1904 // We require the memory address to be naturally aligned. | |
1905 // Given that is the case, then normal stores are atomic. | |
1906 // Add a fence after the store to make it visible. | |
1907 Operand *Value = Instr->getArg(0); | |
1908 Operand *Ptr = Instr->getArg(1); | |
1909 if (Value->getType() == IceType_i64) { | |
1910 // Use a movq instead of what lowerStore() normally does | |
1911 // (split the store into two), following what GCC does. | |
1912 // Cast the bits from int -> to an xmm register first. | |
1913 Variable *T = makeReg(IceType_f64); | |
1914 InstCast *Cast = InstCast::create(Func, InstCast::Bitcast, T, Value); | |
1915 lowerCast(Cast); | |
1916 // Then store XMM w/ a movq. | |
1917 OperandX8632Mem *Addr = FormMemoryOperand(Ptr, IceType_f64); | |
1918 _storeq(T, Addr); | |
1919 _mfence(); | |
1920 return; | |
1921 } | |
1922 InstStore *Store = InstStore::create(Func, Value, Ptr); | |
1923 lowerStore(Store); | |
1924 _mfence(); | |
1925 return; | |
1926 } | |
1809 case Intrinsics::Bswap: | 1927 case Intrinsics::Bswap: |
1810 case Intrinsics::Ctlz: | 1928 case Intrinsics::Ctlz: |
1811 case Intrinsics::Ctpop: | 1929 case Intrinsics::Ctpop: |
1812 case Intrinsics::Cttz: | 1930 case Intrinsics::Cttz: |
1931 // TODO(jvoung): fill it in. | |
1813 Func->setError("Unhandled intrinsic"); | 1932 Func->setError("Unhandled intrinsic"); |
1814 return; | 1933 return; |
1815 case Intrinsics::Longjmp: { | 1934 case Intrinsics::Longjmp: { |
1816 InstCall *Call = makeHelperCall("longjmp", NULL, 2); | 1935 InstCall *Call = makeHelperCall("longjmp", NULL, 2); |
1817 Call->addArg(Instr->getArg(0)); | 1936 Call->addArg(Instr->getArg(0)); |
1818 Call->addArg(Instr->getArg(1)); | 1937 Call->addArg(Instr->getArg(1)); |
1819 lowerCall(Call); | 1938 lowerCall(Call); |
1820 break; | 1939 return; |
1821 } | 1940 } |
1822 case Intrinsics::Memcpy: { | 1941 case Intrinsics::Memcpy: { |
1823 // In the future, we could potentially emit an inline memcpy/memset, etc. | 1942 // In the future, we could potentially emit an inline memcpy/memset, etc. |
1824 // for intrinsic calls w/ a known length. | 1943 // for intrinsic calls w/ a known length. |
1825 InstCall *Call = makeHelperCall("memcpy", NULL, 3); | 1944 InstCall *Call = makeHelperCall("memcpy", NULL, 3); |
1826 Call->addArg(Instr->getArg(0)); | 1945 Call->addArg(Instr->getArg(0)); |
1827 Call->addArg(Instr->getArg(1)); | 1946 Call->addArg(Instr->getArg(1)); |
1828 Call->addArg(Instr->getArg(2)); | 1947 Call->addArg(Instr->getArg(2)); |
1829 lowerCall(Call); | 1948 lowerCall(Call); |
1830 break; | 1949 return; |
1831 } | 1950 } |
1832 case Intrinsics::Memmove: { | 1951 case Intrinsics::Memmove: { |
1833 InstCall *Call = makeHelperCall("memmove", NULL, 3); | 1952 InstCall *Call = makeHelperCall("memmove", NULL, 3); |
1834 Call->addArg(Instr->getArg(0)); | 1953 Call->addArg(Instr->getArg(0)); |
1835 Call->addArg(Instr->getArg(1)); | 1954 Call->addArg(Instr->getArg(1)); |
1836 Call->addArg(Instr->getArg(2)); | 1955 Call->addArg(Instr->getArg(2)); |
1837 lowerCall(Call); | 1956 lowerCall(Call); |
1838 break; | 1957 return; |
1839 } | 1958 } |
1840 case Intrinsics::Memset: { | 1959 case Intrinsics::Memset: { |
1841 // The value operand needs to be extended to a stack slot size | 1960 // The value operand needs to be extended to a stack slot size |
1842 // because we "push" only works for a specific operand size. | 1961 // because we "push" only works for a specific operand size. |
1843 Operand *ValOp = Instr->getArg(1); | 1962 Operand *ValOp = Instr->getArg(1); |
1844 assert(ValOp->getType() == IceType_i8); | 1963 assert(ValOp->getType() == IceType_i8); |
1845 Variable *ValExt = makeReg(stackSlotType()); | 1964 Variable *ValExt = makeReg(stackSlotType()); |
1846 _movzx(ValExt, ValOp); | 1965 _movzx(ValExt, ValOp); |
1847 InstCall *Call = makeHelperCall("memset", NULL, 3); | 1966 InstCall *Call = makeHelperCall("memset", NULL, 3); |
1848 Call->addArg(Instr->getArg(0)); | 1967 Call->addArg(Instr->getArg(0)); |
1849 Call->addArg(ValExt); | 1968 Call->addArg(ValExt); |
1850 Call->addArg(Instr->getArg(2)); | 1969 Call->addArg(Instr->getArg(2)); |
1851 lowerCall(Call); | 1970 lowerCall(Call); |
1852 break; | 1971 return; |
1853 } | 1972 } |
1854 case Intrinsics::NaClReadTP: { | 1973 case Intrinsics::NaClReadTP: { |
1855 Constant *Zero = Ctx->getConstantInt(IceType_i32, 0); | 1974 Constant *Zero = Ctx->getConstantZero(IceType_i32); |
1856 Operand *Src = OperandX8632Mem::create(Func, IceType_i32, NULL, Zero, NULL, | 1975 Operand *Src = OperandX8632Mem::create(Func, IceType_i32, NULL, Zero, NULL, |
1857 0, OperandX8632Mem::SegReg_GS); | 1976 0, OperandX8632Mem::SegReg_GS); |
1858 Variable *Dest = Instr->getDest(); | 1977 Variable *Dest = Instr->getDest(); |
1859 Variable *T = NULL; | 1978 Variable *T = NULL; |
1860 _mov(T, Src); | 1979 _mov(T, Src); |
1861 _mov(Dest, T); | 1980 _mov(Dest, T); |
1862 break; | 1981 return; |
1863 } | 1982 } |
1864 case Intrinsics::Setjmp: { | 1983 case Intrinsics::Setjmp: { |
1865 InstCall *Call = makeHelperCall("setjmp", Instr->getDest(), 1); | 1984 InstCall *Call = makeHelperCall("setjmp", Instr->getDest(), 1); |
1866 Call->addArg(Instr->getArg(0)); | 1985 Call->addArg(Instr->getArg(0)); |
1867 lowerCall(Call); | 1986 lowerCall(Call); |
1868 break; | 1987 return; |
1869 } | 1988 } |
1870 case Intrinsics::Sqrt: | 1989 case Intrinsics::Sqrt: |
1871 case Intrinsics::Stacksave: | 1990 case Intrinsics::Stacksave: |
1872 case Intrinsics::Stackrestore: | 1991 case Intrinsics::Stackrestore: |
1992 // TODO(jvoung): fill it in. | |
1873 Func->setError("Unhandled intrinsic"); | 1993 Func->setError("Unhandled intrinsic"); |
1874 return; | 1994 return; |
1875 case Intrinsics::Trap: | 1995 case Intrinsics::Trap: |
1876 _ud2(); | 1996 _ud2(); |
1877 break; | 1997 return; |
1878 case Intrinsics::UnknownIntrinsic: | 1998 case Intrinsics::UnknownIntrinsic: |
1879 Func->setError("Should not be lowering UnknownIntrinsic"); | 1999 Func->setError("Should not be lowering UnknownIntrinsic"); |
1880 return; | 2000 return; |
1881 } | 2001 } |
1882 return; | 2002 return; |
1883 } | 2003 } |
1884 | 2004 |
2005 void TargetX8632::lowerAtomicRMW(Variable *Dest, uint32_t Operation, | |
2006 Operand *Ptr, Operand *Val) { | |
2007 switch (Operation) { | |
2008 default: | |
2009 Func->setError("Unknown AtomicRMW operation"); | |
2010 return; | |
2011 case Intrinsics::AtomicAdd: { | |
2012 if (Dest->getType() == IceType_i64) { | |
2013 // Do a nasty cmpxchg8b loop. Factor this into a function. | |
2014 // TODO(jvoung): fill it in. | |
2015 Func->setError("Unhandled AtomicRMW operation"); | |
2016 return; | |
2017 } | |
2018 OperandX8632Mem *Addr = FormMemoryOperand(Ptr, Dest->getType()); | |
2019 const bool Locked = true; | |
2020 Variable *T = NULL; | |
2021 _mov(T, Val); | |
2022 _xadd(Addr, T, Locked); | |
2023 _mov(Dest, T); | |
2024 return; | |
2025 } | |
2026 case Intrinsics::AtomicSub: { | |
2027 if (Dest->getType() == IceType_i64) { | |
2028 // Do a nasty cmpxchg8b loop. | |
2029 // TODO(jvoung): fill it in. | |
2030 Func->setError("Unhandled AtomicRMW operation"); | |
2031 return; | |
2032 } | |
2033 // Generate a memory operand from Ptr. | |
2034 // neg... | |
2035 // Then do the same as AtomicAdd. | |
2036 // TODO(jvoung): fill it in. | |
2037 Func->setError("Unhandled AtomicRMW operation"); | |
2038 return; | |
2039 } | |
2040 case Intrinsics::AtomicOr: | |
2041 case Intrinsics::AtomicAnd: | |
2042 case Intrinsics::AtomicXor: | |
2043 case Intrinsics::AtomicExchange: | |
2044 // TODO(jvoung): fill it in. | |
2045 Func->setError("Unhandled AtomicRMW operation"); | |
2046 return; | |
2047 } | |
2048 } | |
2049 | |
1885 namespace { | 2050 namespace { |
1886 | 2051 |
1887 bool isAdd(const Inst *Inst) { | 2052 bool isAdd(const Inst *Inst) { |
1888 if (const InstArithmetic *Arith = | 2053 if (const InstArithmetic *Arith = |
1889 llvm::dyn_cast_or_null<const InstArithmetic>(Inst)) { | 2054 llvm::dyn_cast_or_null<const InstArithmetic>(Inst)) { |
1890 return (Arith->getOp() == InstArithmetic::Add); | 2055 return (Arith->getOp() == InstArithmetic::Add); |
1891 } | 2056 } |
1892 return false; | 2057 return false; |
1893 } | 2058 } |
1894 | 2059 |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2011 | 2176 |
2012 } // anonymous namespace | 2177 } // anonymous namespace |
2013 | 2178 |
2014 void TargetX8632::lowerLoad(const InstLoad *Inst) { | 2179 void TargetX8632::lowerLoad(const InstLoad *Inst) { |
2015 // A Load instruction can be treated the same as an Assign | 2180 // A Load instruction can be treated the same as an Assign |
2016 // instruction, after the source operand is transformed into an | 2181 // instruction, after the source operand is transformed into an |
2017 // OperandX8632Mem operand. Note that the address mode | 2182 // OperandX8632Mem operand. Note that the address mode |
2018 // optimization already creates an OperandX8632Mem operand, so it | 2183 // optimization already creates an OperandX8632Mem operand, so it |
2019 // doesn't need another level of transformation. | 2184 // doesn't need another level of transformation. |
2020 Type Ty = Inst->getDest()->getType(); | 2185 Type Ty = Inst->getDest()->getType(); |
2021 Operand *Src0 = Inst->getSourceAddress(); | 2186 Operand *Src0 = FormMemoryOperand(Inst->getSourceAddress(), Ty); |
2022 // Address mode optimization already creates an OperandX8632Mem | |
2023 // operand, so it doesn't need another level of transformation. | |
2024 if (!llvm::isa<OperandX8632Mem>(Src0)) { | |
2025 Variable *Base = llvm::dyn_cast<Variable>(Src0); | |
2026 Constant *Offset = llvm::dyn_cast<Constant>(Src0); | |
2027 assert(Base || Offset); | |
2028 Src0 = OperandX8632Mem::create(Func, Ty, Base, Offset); | |
2029 } | |
2030 | 2187 |
2031 // Fuse this load with a subsequent Arithmetic instruction in the | 2188 // Fuse this load with a subsequent Arithmetic instruction in the |
2032 // following situations: | 2189 // following situations: |
2033 // a=[mem]; c=b+a ==> c=b+[mem] if last use of a and a not in b | 2190 // a=[mem]; c=b+a ==> c=b+[mem] if last use of a and a not in b |
2034 // a=[mem]; c=a+b ==> c=b+[mem] if commutative and above is true | 2191 // a=[mem]; c=a+b ==> c=b+[mem] if commutative and above is true |
2035 // | 2192 // |
2036 // TODO: Clean up and test thoroughly. | 2193 // TODO: Clean up and test thoroughly. |
2194 // (E.g., if there is an mfence-all make sure the load ends up on the | |
2195 // same side of the fence). | |
2037 // | 2196 // |
2038 // TODO: Why limit to Arithmetic instructions? This could probably be | 2197 // TODO: Why limit to Arithmetic instructions? This could probably be |
2039 // applied to most any instruction type. Look at all source operands | 2198 // applied to most any instruction type. Look at all source operands |
2040 // in the following instruction, and if there is one instance of the | 2199 // in the following instruction, and if there is one instance of the |
2041 // load instruction's dest variable, and that instruction ends that | 2200 // load instruction's dest variable, and that instruction ends that |
2042 // variable's live range, then make the substitution. Deal with | 2201 // variable's live range, then make the substitution. Deal with |
2043 // commutativity optimization in the arithmetic instruction lowering. | 2202 // commutativity optimization in the arithmetic instruction lowering. |
2044 InstArithmetic *NewArith = NULL; | 2203 InstArithmetic *NewArith = NULL; |
2045 if (InstArithmetic *Arith = | 2204 if (InstArithmetic *Arith = |
2046 llvm::dyn_cast_or_null<InstArithmetic>(Context.getNextInst())) { | 2205 llvm::dyn_cast_or_null<InstArithmetic>(Context.getNextInst())) { |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2157 SrcF = legalize(SrcF, Legal_Reg | Legal_Imm, true); | 2316 SrcF = legalize(SrcF, Legal_Reg | Legal_Imm, true); |
2158 _mov(Dest, SrcF); | 2317 _mov(Dest, SrcF); |
2159 } | 2318 } |
2160 | 2319 |
2161 Context.insert(Label); | 2320 Context.insert(Label); |
2162 } | 2321 } |
2163 | 2322 |
2164 void TargetX8632::lowerStore(const InstStore *Inst) { | 2323 void TargetX8632::lowerStore(const InstStore *Inst) { |
2165 Operand *Value = Inst->getData(); | 2324 Operand *Value = Inst->getData(); |
2166 Operand *Addr = Inst->getAddr(); | 2325 Operand *Addr = Inst->getAddr(); |
2167 OperandX8632Mem *NewAddr = llvm::dyn_cast<OperandX8632Mem>(Addr); | 2326 OperandX8632Mem *NewAddr = FormMemoryOperand(Addr, Value->getType()); |
2168 // Address mode optimization already creates an OperandX8632Mem | |
2169 // operand, so it doesn't need another level of transformation. | |
2170 if (!NewAddr) { | |
2171 // The address will be either a constant (which represents a global | |
2172 // variable) or a variable, so either the Base or Offset component | |
2173 // of the OperandX8632Mem will be set. | |
2174 Variable *Base = llvm::dyn_cast<Variable>(Addr); | |
2175 Constant *Offset = llvm::dyn_cast<Constant>(Addr); | |
2176 assert(Base || Offset); | |
2177 NewAddr = OperandX8632Mem::create(Func, Value->getType(), Base, Offset); | |
2178 } | |
2179 NewAddr = llvm::cast<OperandX8632Mem>(legalize(NewAddr)); | |
2180 | 2327 |
2181 if (NewAddr->getType() == IceType_i64) { | 2328 if (NewAddr->getType() == IceType_i64) { |
2182 Value = legalize(Value); | 2329 Value = legalize(Value); |
2183 Operand *ValueHi = legalize(hiOperand(Value), Legal_Reg | Legal_Imm, true); | 2330 Operand *ValueHi = legalize(hiOperand(Value), Legal_Reg | Legal_Imm, true); |
2184 Operand *ValueLo = legalize(loOperand(Value), Legal_Reg | Legal_Imm, true); | 2331 Operand *ValueLo = legalize(loOperand(Value), Legal_Reg | Legal_Imm, true); |
2185 _store(ValueHi, llvm::cast<OperandX8632Mem>(hiOperand(NewAddr))); | 2332 _store(ValueHi, llvm::cast<OperandX8632Mem>(hiOperand(NewAddr))); |
2186 _store(ValueLo, llvm::cast<OperandX8632Mem>(loOperand(NewAddr))); | 2333 _store(ValueLo, llvm::cast<OperandX8632Mem>(loOperand(NewAddr))); |
2187 } else { | 2334 } else { |
2188 Value = legalize(Value, Legal_Reg | Legal_Imm, true); | 2335 Value = legalize(Value, Legal_Reg | Legal_Imm, true); |
2189 _store(Value, NewAddr); | 2336 _store(Value, NewAddr); |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2287 // | 2434 // |
2288 // If in the future the implementation is changed to lower undef | 2435 // If in the future the implementation is changed to lower undef |
2289 // values to uninitialized registers, a FakeDef will be needed: | 2436 // values to uninitialized registers, a FakeDef will be needed: |
2290 // Context.insert(InstFakeDef::create(Func, Reg)); | 2437 // Context.insert(InstFakeDef::create(Func, Reg)); |
2291 // This is in order to ensure that the live range of Reg is not | 2438 // This is in order to ensure that the live range of Reg is not |
2292 // overestimated. If the constant being lowered is a 64 bit value, | 2439 // overestimated. If the constant being lowered is a 64 bit value, |
2293 // then the result should be split and the lo and hi components will | 2440 // then the result should be split and the lo and hi components will |
2294 // need to go in uninitialized registers. | 2441 // need to go in uninitialized registers. |
2295 From = Ctx->getConstantZero(From->getType()); | 2442 From = Ctx->getConstantZero(From->getType()); |
2296 } | 2443 } |
2297 bool NeedsReg = !(Allowed & Legal_Imm) || | 2444 bool NeedsReg = |
2445 !(Allowed & Legal_Imm) || | |
2298 // ConstantFloat and ConstantDouble are actually memory operands. | 2446 // ConstantFloat and ConstantDouble are actually memory operands. |
2299 (!(Allowed & Legal_Mem) && (From->getType() == IceType_f32 || | 2447 (!(Allowed & Legal_Mem) && |
2300 From->getType() == IceType_f64)); | 2448 (From->getType() == IceType_f32 || From->getType() == IceType_f64)); |
2301 if (NeedsReg) { | 2449 if (NeedsReg) { |
2302 Variable *Reg = makeReg(From->getType(), RegNum); | 2450 Variable *Reg = makeReg(From->getType(), RegNum); |
2303 _mov(Reg, From); | 2451 _mov(Reg, From); |
2304 From = Reg; | 2452 From = Reg; |
2305 } | 2453 } |
2306 return From; | 2454 return From; |
2307 } | 2455 } |
2308 if (Variable *Var = llvm::dyn_cast<Variable>(From)) { | 2456 if (Variable *Var = llvm::dyn_cast<Variable>(From)) { |
2309 // We need a new physical register for the operand if: | 2457 // We need a new physical register for the operand if: |
2310 // Mem is not allowed and Var->getRegNum() is unknown, or | 2458 // Mem is not allowed and Var->getRegNum() is unknown, or |
(...skipping 12 matching lines...) Expand all Loading... | |
2323 llvm_unreachable("Unhandled operand kind in legalize()"); | 2471 llvm_unreachable("Unhandled operand kind in legalize()"); |
2324 return From; | 2472 return From; |
2325 } | 2473 } |
2326 | 2474 |
2327 // Provide a trivial wrapper to legalize() for this common usage. | 2475 // Provide a trivial wrapper to legalize() for this common usage. |
2328 Variable *TargetX8632::legalizeToVar(Operand *From, bool AllowOverlap, | 2476 Variable *TargetX8632::legalizeToVar(Operand *From, bool AllowOverlap, |
2329 int32_t RegNum) { | 2477 int32_t RegNum) { |
2330 return llvm::cast<Variable>(legalize(From, Legal_Reg, AllowOverlap, RegNum)); | 2478 return llvm::cast<Variable>(legalize(From, Legal_Reg, AllowOverlap, RegNum)); |
2331 } | 2479 } |
2332 | 2480 |
2481 OperandX8632Mem *TargetX8632::FormMemoryOperand(Operand *Operand, Type Ty) { | |
2482 OperandX8632Mem *Mem = llvm::dyn_cast<OperandX8632Mem>(Operand); | |
2483 // It may be the case that address mode optimization already creates | |
2484 // an OperandX8632Mem, so in that case it wouldn't need another level | |
2485 // of transformation. | |
2486 if (!Mem) { | |
2487 Variable *Base = llvm::dyn_cast<Variable>(Operand); | |
2488 Constant *Offset = llvm::dyn_cast<Constant>(Operand); | |
2489 assert(Base || Offset); | |
2490 Mem = OperandX8632Mem::create(Func, Ty, Base, Offset); | |
2491 } | |
2492 return llvm::cast<OperandX8632Mem>(legalize(Mem)); | |
2493 } | |
2494 | |
2333 Variable *TargetX8632::makeReg(Type Type, int32_t RegNum) { | 2495 Variable *TargetX8632::makeReg(Type Type, int32_t RegNum) { |
2334 // There aren't any 64-bit integer registers for x86-32. | 2496 // There aren't any 64-bit integer registers for x86-32. |
2335 assert(Type != IceType_i64); | 2497 assert(Type != IceType_i64); |
2336 Variable *Reg = Func->makeVariable(Type, Context.getNode()); | 2498 Variable *Reg = Func->makeVariable(Type, Context.getNode()); |
2337 if (RegNum == Variable::NoRegister) | 2499 if (RegNum == Variable::NoRegister) |
2338 Reg->setWeightInfinite(); | 2500 Reg->setWeightInfinite(); |
2339 else | 2501 else |
2340 Reg->setRegNum(RegNum); | 2502 Reg->setRegNum(RegNum); |
2341 return Reg; | 2503 return Reg; |
2342 } | 2504 } |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2409 // llvm-mc doesn't parse "dword ptr [.L$foo]". | 2571 // llvm-mc doesn't parse "dword ptr [.L$foo]". |
2410 Str << "dword ptr [L$" << IceType_f32 << "$" << getPoolEntryID() << "]"; | 2572 Str << "dword ptr [L$" << IceType_f32 << "$" << getPoolEntryID() << "]"; |
2411 } | 2573 } |
2412 | 2574 |
2413 template <> void ConstantDouble::emit(GlobalContext *Ctx) const { | 2575 template <> void ConstantDouble::emit(GlobalContext *Ctx) const { |
2414 Ostream &Str = Ctx->getStrEmit(); | 2576 Ostream &Str = Ctx->getStrEmit(); |
2415 Str << "qword ptr [L$" << IceType_f64 << "$" << getPoolEntryID() << "]"; | 2577 Str << "qword ptr [L$" << IceType_f64 << "$" << getPoolEntryID() << "]"; |
2416 } | 2578 } |
2417 | 2579 |
2418 } // end of namespace Ice | 2580 } // end of namespace Ice |
OLD | NEW |