Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(245)

Side by Side Diff: src/IceTargetLoweringX8632.cpp

Issue 321993002: Add a few Subzero intrinsics (not the atomic ones yet). (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: bitwise sideeffects Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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; }
436
434 void TargetX8632::addProlog(CfgNode *Node) { 437 void TargetX8632::addProlog(CfgNode *Node) {
435 // If SimpleCoalescing is false, each variable without a register 438 // If SimpleCoalescing is false, each variable without a register
436 // gets its own unique stack slot, which leads to large stack 439 // gets its own unique stack slot, which leads to large stack
437 // frames. If SimpleCoalescing is true, then each "global" variable 440 // frames. If SimpleCoalescing is true, then each "global" variable
438 // without a register gets its own slot, but "local" variable slots 441 // without a register gets its own slot, but "local" variable slots
439 // are reused across basic blocks. E.g., if A and B are local to 442 // are reused across basic blocks. E.g., if A and B are local to
440 // block 1 and C is local to block 2, then C may share a slot with A 443 // block 1 and C is local to block 2, then C may share a slot with A
441 // or B. 444 // or B.
442 const bool SimpleCoalescing = true; 445 const bool SimpleCoalescing = true;
443 size_t InArgsSizeBytes = 0; 446 size_t InArgsSizeBytes = 0;
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
753 split64(Var); 756 split64(Var);
754 return Var->getLo(); 757 return Var->getLo();
755 } 758 }
756 if (ConstantInteger *Const = llvm::dyn_cast<ConstantInteger>(Operand)) { 759 if (ConstantInteger *Const = llvm::dyn_cast<ConstantInteger>(Operand)) {
757 uint64_t Mask = (1ull << 32) - 1; 760 uint64_t Mask = (1ull << 32) - 1;
758 return Ctx->getConstantInt(IceType_i32, Const->getValue() & Mask); 761 return Ctx->getConstantInt(IceType_i32, Const->getValue() & Mask);
759 } 762 }
760 if (OperandX8632Mem *Mem = llvm::dyn_cast<OperandX8632Mem>(Operand)) { 763 if (OperandX8632Mem *Mem = llvm::dyn_cast<OperandX8632Mem>(Operand)) {
761 return OperandX8632Mem::create(Func, IceType_i32, Mem->getBase(), 764 return OperandX8632Mem::create(Func, IceType_i32, Mem->getBase(),
762 Mem->getOffset(), Mem->getIndex(), 765 Mem->getOffset(), Mem->getIndex(),
763 Mem->getShift()); 766 Mem->getShift(), Mem->getSegmentRegister());
764 } 767 }
765 llvm_unreachable("Unsupported operand type"); 768 llvm_unreachable("Unsupported operand type");
766 return NULL; 769 return NULL;
767 } 770 }
768 771
769 Operand *TargetX8632::hiOperand(Operand *Operand) { 772 Operand *TargetX8632::hiOperand(Operand *Operand) {
770 assert(Operand->getType() == IceType_i64); 773 assert(Operand->getType() == IceType_i64);
771 if (Operand->getType() != IceType_i64) 774 if (Operand->getType() != IceType_i64)
772 return Operand; 775 return Operand;
773 if (Variable *Var = llvm::dyn_cast<Variable>(Operand)) { 776 if (Variable *Var = llvm::dyn_cast<Variable>(Operand)) {
774 split64(Var); 777 split64(Var);
775 return Var->getHi(); 778 return Var->getHi();
776 } 779 }
777 if (ConstantInteger *Const = llvm::dyn_cast<ConstantInteger>(Operand)) { 780 if (ConstantInteger *Const = llvm::dyn_cast<ConstantInteger>(Operand)) {
778 return Ctx->getConstantInt(IceType_i32, Const->getValue() >> 32); 781 return Ctx->getConstantInt(IceType_i32, Const->getValue() >> 32);
779 } 782 }
780 if (OperandX8632Mem *Mem = llvm::dyn_cast<OperandX8632Mem>(Operand)) { 783 if (OperandX8632Mem *Mem = llvm::dyn_cast<OperandX8632Mem>(Operand)) {
781 Constant *Offset = Mem->getOffset(); 784 Constant *Offset = Mem->getOffset();
782 if (Offset == NULL) 785 if (Offset == NULL)
783 Offset = Ctx->getConstantInt(IceType_i32, 4); 786 Offset = Ctx->getConstantInt(IceType_i32, 4);
784 else if (ConstantInteger *IntOffset = 787 else if (ConstantInteger *IntOffset =
785 llvm::dyn_cast<ConstantInteger>(Offset)) { 788 llvm::dyn_cast<ConstantInteger>(Offset)) {
786 Offset = Ctx->getConstantInt(IceType_i32, 4 + IntOffset->getValue()); 789 Offset = Ctx->getConstantInt(IceType_i32, 4 + IntOffset->getValue());
787 } else if (ConstantRelocatable *SymOffset = 790 } else if (ConstantRelocatable *SymOffset =
788 llvm::dyn_cast<ConstantRelocatable>(Offset)) { 791 llvm::dyn_cast<ConstantRelocatable>(Offset)) {
789 Offset = Ctx->getConstantSym(IceType_i32, 4 + SymOffset->getOffset(), 792 Offset = Ctx->getConstantSym(IceType_i32, 4 + SymOffset->getOffset(),
790 SymOffset->getName()); 793 SymOffset->getName());
791 } 794 }
792 return OperandX8632Mem::create(Func, IceType_i32, Mem->getBase(), Offset, 795 return OperandX8632Mem::create(Func, IceType_i32, Mem->getBase(), Offset,
793 Mem->getIndex(), Mem->getShift()); 796 Mem->getIndex(), Mem->getShift(),
797 Mem->getSegmentRegister());
794 } 798 }
795 llvm_unreachable("Unsupported operand type"); 799 llvm_unreachable("Unsupported operand type");
796 return NULL; 800 return NULL;
797 } 801 }
798 802
799 llvm::SmallBitVector TargetX8632::getRegisterSet(RegSetMask Include, 803 llvm::SmallBitVector TargetX8632::getRegisterSet(RegSetMask Include,
800 RegSetMask Exclude) const { 804 RegSetMask Exclude) const {
801 llvm::SmallBitVector Registers(Reg_NUM); 805 llvm::SmallBitVector Registers(Reg_NUM);
802 806
803 #define X(val, init, name, name16, name8, scratch, preserved, stackptr, \ 807 #define X(val, init, name, name16, name8, scratch, preserved, stackptr, \
(...skipping 955 matching lines...) Expand 10 before | Expand all | Expand 10 after
1759 legalize(Src0, IsSrc1ImmOrReg ? Legal_All : Legal_Reg, true); 1763 legalize(Src0, IsSrc1ImmOrReg ? Legal_All : Legal_Reg, true);
1760 InstX8632Label *Label = InstX8632Label::create(Func, this); 1764 InstX8632Label *Label = InstX8632Label::create(Func, this);
1761 _cmp(Src0New, Src1); 1765 _cmp(Src0New, Src1);
1762 _mov(Dest, One); 1766 _mov(Dest, One);
1763 _br(getIcmp32Mapping(Inst->getCondition()), Label); 1767 _br(getIcmp32Mapping(Inst->getCondition()), Label);
1764 Context.insert(InstFakeUse::create(Func, Dest)); 1768 Context.insert(InstFakeUse::create(Func, Dest));
1765 _mov(Dest, Zero); 1769 _mov(Dest, Zero);
1766 Context.insert(Label); 1770 Context.insert(Label);
1767 } 1771 }
1768 1772
1773 void TargetX8632::lowerIntrinsicCall(const InstIntrinsicCall *Instr) {
1774 switch (Instr->getIntrinsicInfo().ID) {
1775 case Intrinsics::AtomicCmpxchg:
1776 case Intrinsics::AtomicFence:
1777 case Intrinsics::AtomicFenceAll:
1778 case Intrinsics::AtomicIsLockFree:
1779 case Intrinsics::AtomicLoad:
1780 case Intrinsics::AtomicRMW:
1781 case Intrinsics::AtomicStore:
1782 case Intrinsics::Bswap:
1783 case Intrinsics::Ctlz:
1784 case Intrinsics::Ctpop:
1785 case Intrinsics::Cttz:
1786 Func->setError("Unhandled intrinsic");
1787 return;
1788 case Intrinsics::Longjmp: {
1789 InstCall *Call = makeHelperCall("longjmp", NULL, 2);
1790 Call->addArg(Instr->getArg(0));
1791 Call->addArg(Instr->getArg(1));
1792 lowerCall(Call);
1793 break;
1794 }
1795 case Intrinsics::Memcpy: {
1796 // In the future, we could potentially emit an inline memcpy/memset, etc.
1797 // for intrinsic calls w/ a known length.
1798 InstCall *Call = makeHelperCall("memcpy", NULL, 3);
1799 Call->addArg(Instr->getArg(0));
1800 Call->addArg(Instr->getArg(1));
1801 Call->addArg(Instr->getArg(2));
1802 lowerCall(Call);
1803 break;
1804 }
1805 case Intrinsics::Memmove: {
1806 InstCall *Call = makeHelperCall("memmove", NULL, 3);
1807 Call->addArg(Instr->getArg(0));
1808 Call->addArg(Instr->getArg(1));
1809 Call->addArg(Instr->getArg(2));
1810 lowerCall(Call);
1811 break;
1812 }
1813 case Intrinsics::Memset: {
1814 // The value operand needs to be extended to a stack slot size
1815 // because we "push" only works for a specific operand size.
1816 Operand *ValOp = Instr->getArg(1);
1817 assert(ValOp->getType() == IceType_i8);
1818 Variable *ValExt = makeReg(stackSlotType());
1819 _movzx(ValExt, ValOp);
1820 InstCall *Call = makeHelperCall("memset", NULL, 3);
1821 Call->addArg(Instr->getArg(0));
1822 Call->addArg(ValExt);
1823 Call->addArg(Instr->getArg(2));
1824 lowerCall(Call);
1825 break;
1826 }
1827 case Intrinsics::NaClReadTP: {
1828 Constant *Zero = Ctx->getConstantInt(IceType_i32, 0);
1829 Operand *Src = OperandX8632Mem::create(Func, IceType_i32, NULL, Zero, NULL,
1830 0, OperandX8632Mem::SegReg_GS);
1831 Variable *Dest = Instr->getDest();
1832 Variable *T = NULL;
1833 _mov(T, Src);
1834 _mov(Dest, T);
1835 break;
1836 }
1837 case Intrinsics::Setjmp: {
1838 InstCall *Call = makeHelperCall("setjmp", Instr->getDest(), 1);
1839 Call->addArg(Instr->getArg(0));
1840 lowerCall(Call);
1841 break;
1842 }
1843 case Intrinsics::Sqrt:
1844 case Intrinsics::Stacksave:
1845 case Intrinsics::Stackrestore:
1846 Func->setError("Unhandled intrinsic");
1847 return;
1848 case Intrinsics::Trap:
1849 _ud2();
1850 break;
1851 case Intrinsics::UnknownIntrinsic:
1852 Func->setError("Should not be lowering UnknownIntrinsic");
1853 return;
1854 }
1855 return;
1856 }
1857
1769 namespace { 1858 namespace {
1770 1859
1771 bool isAdd(const Inst *Inst) { 1860 bool isAdd(const Inst *Inst) {
1772 if (const InstArithmetic *Arith = 1861 if (const InstArithmetic *Arith =
1773 llvm::dyn_cast_or_null<const InstArithmetic>(Inst)) { 1862 llvm::dyn_cast_or_null<const InstArithmetic>(Inst)) {
1774 return (Arith->getOp() == InstArithmetic::Add); 1863 return (Arith->getOp() == InstArithmetic::Add);
1775 } 1864 }
1776 return false; 1865 return false;
1777 } 1866 }
1778 1867
1779 void computeAddressOpt(Variable *&Base, Variable *&Index, int32_t &Shift, 1868 void computeAddressOpt(Variable *&Base, Variable *&Index, uint16_t &Shift,
1780 int32_t &Offset) { 1869 int32_t &Offset) {
1781 (void)Offset; // TODO: pattern-match for non-zero offsets. 1870 (void)Offset; // TODO: pattern-match for non-zero offsets.
1782 if (Base == NULL) 1871 if (Base == NULL)
1783 return; 1872 return;
1784 // If the Base has more than one use or is live across multiple 1873 // If the Base has more than one use or is live across multiple
1785 // blocks, then don't go further. Alternatively (?), never consider 1874 // blocks, then don't go further. Alternatively (?), never consider
1786 // a transformation that would change a variable that is currently 1875 // a transformation that would change a variable that is currently
1787 // *not* live across basic block boundaries into one that *is*. 1876 // *not* live across basic block boundaries into one that *is*.
1788 if (Base->isMultiblockLife() /* || Base->getUseCount() > 1*/) 1877 if (Base->isMultiblockLife() /* || Base->getUseCount() > 1*/)
1789 return; 1878 return;
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
1950 2039
1951 InstAssign *Assign = InstAssign::create(Func, Inst->getDest(), Src0); 2040 InstAssign *Assign = InstAssign::create(Func, Inst->getDest(), Src0);
1952 lowerAssign(Assign); 2041 lowerAssign(Assign);
1953 } 2042 }
1954 2043
1955 void TargetX8632::doAddressOptLoad() { 2044 void TargetX8632::doAddressOptLoad() {
1956 Inst *Inst = *Context.getCur(); 2045 Inst *Inst = *Context.getCur();
1957 Variable *Dest = Inst->getDest(); 2046 Variable *Dest = Inst->getDest();
1958 Operand *Addr = Inst->getSrc(0); 2047 Operand *Addr = Inst->getSrc(0);
1959 Variable *Index = NULL; 2048 Variable *Index = NULL;
1960 int32_t Shift = 0; 2049 uint16_t Shift = 0;
1961 int32_t Offset = 0; // TODO: make Constant 2050 int32_t Offset = 0; // TODO: make Constant
2051 // Vanilla ICE load instructions should not use the segment registers,
2052 // and computeAddressOpt only works at the level of Variables and Constants,
2053 // not other OperandX8632Mem, so there should be no mention of segment
2054 // registers there either.
2055 const OperandX8632Mem::SegmentRegisters SegmentReg =
2056 OperandX8632Mem::DefaultSegment;
1962 Variable *Base = llvm::dyn_cast<Variable>(Addr); 2057 Variable *Base = llvm::dyn_cast<Variable>(Addr);
1963 computeAddressOpt(Base, Index, Shift, Offset); 2058 computeAddressOpt(Base, Index, Shift, Offset);
1964 if (Base && Addr != Base) { 2059 if (Base && Addr != Base) {
1965 Constant *OffsetOp = Ctx->getConstantInt(IceType_i32, Offset); 2060 Constant *OffsetOp = Ctx->getConstantInt(IceType_i32, Offset);
1966 Addr = OperandX8632Mem::create(Func, Dest->getType(), Base, OffsetOp, Index, 2061 Addr = OperandX8632Mem::create(Func, Dest->getType(), Base, OffsetOp, Index,
1967 Shift); 2062 Shift, SegmentReg);
1968 Inst->setDeleted(); 2063 Inst->setDeleted();
1969 Context.insert(InstLoad::create(Func, Dest, Addr)); 2064 Context.insert(InstLoad::create(Func, Dest, Addr));
1970 } 2065 }
1971 } 2066 }
1972 2067
1973 void TargetX8632::lowerPhi(const InstPhi * /*Inst*/) { 2068 void TargetX8632::lowerPhi(const InstPhi * /*Inst*/) {
1974 Func->setError("Phi found in regular instruction list"); 2069 Func->setError("Phi found in regular instruction list");
1975 } 2070 }
1976 2071
1977 void TargetX8632::lowerRet(const InstRet *Inst) { 2072 void TargetX8632::lowerRet(const InstRet *Inst) {
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
2066 Value = legalize(Value, Legal_Reg | Legal_Imm, true); 2161 Value = legalize(Value, Legal_Reg | Legal_Imm, true);
2067 _store(Value, NewAddr); 2162 _store(Value, NewAddr);
2068 } 2163 }
2069 } 2164 }
2070 2165
2071 void TargetX8632::doAddressOptStore() { 2166 void TargetX8632::doAddressOptStore() {
2072 InstStore *Inst = llvm::cast<InstStore>(*Context.getCur()); 2167 InstStore *Inst = llvm::cast<InstStore>(*Context.getCur());
2073 Operand *Data = Inst->getData(); 2168 Operand *Data = Inst->getData();
2074 Operand *Addr = Inst->getAddr(); 2169 Operand *Addr = Inst->getAddr();
2075 Variable *Index = NULL; 2170 Variable *Index = NULL;
2076 int32_t Shift = 0; 2171 uint16_t Shift = 0;
2077 int32_t Offset = 0; // TODO: make Constant 2172 int32_t Offset = 0; // TODO: make Constant
2078 Variable *Base = llvm::dyn_cast<Variable>(Addr); 2173 Variable *Base = llvm::dyn_cast<Variable>(Addr);
2174 // Vanilla ICE load instructions should not use the segment registers,
Jim Stichnoth 2014/06/16 23:05:16 load --> store
jvoung (off chromium) 2014/06/17 17:36:19 Done.
2175 // and computeAddressOpt only works at the level of Variables and Constants,
2176 // not other OperandX8632Mem, so there should be no mention of segment
2177 // registers there either.
2178 const OperandX8632Mem::SegmentRegisters SegmentReg =
2179 OperandX8632Mem::DefaultSegment;
2079 computeAddressOpt(Base, Index, Shift, Offset); 2180 computeAddressOpt(Base, Index, Shift, Offset);
2080 if (Base && Addr != Base) { 2181 if (Base && Addr != Base) {
2081 Constant *OffsetOp = Ctx->getConstantInt(IceType_i32, Offset); 2182 Constant *OffsetOp = Ctx->getConstantInt(IceType_i32, Offset);
2082 Addr = OperandX8632Mem::create(Func, Data->getType(), Base, OffsetOp, Index, 2183 Addr = OperandX8632Mem::create(Func, Data->getType(), Base, OffsetOp, Index,
2083 Shift); 2184 Shift, SegmentReg);
2084 Inst->setDeleted(); 2185 Inst->setDeleted();
2085 Context.insert(InstStore::create(Func, Data, Addr)); 2186 Context.insert(InstStore::create(Func, Data, Addr));
2086 } 2187 }
2087 } 2188 }
2088 2189
2089 void TargetX8632::lowerSwitch(const InstSwitch *Inst) { 2190 void TargetX8632::lowerSwitch(const InstSwitch *Inst) {
2090 // This implements the most naive possible lowering. 2191 // This implements the most naive possible lowering.
2091 // cmp a,val[0]; jeq label[0]; cmp a,val[1]; jeq label[1]; ... jmp default 2192 // cmp a,val[0]; jeq label[0]; cmp a,val[1]; jeq label[1]; ... jmp default
2092 Operand *Src0 = Inst->getComparison(); 2193 Operand *Src0 = Inst->getComparison();
2093 SizeT NumCases = Inst->getNumCases(); 2194 SizeT NumCases = Inst->getNumCases();
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
2132 Variable *Index = Mem->getIndex(); 2233 Variable *Index = Mem->getIndex();
2133 Variable *RegBase = NULL; 2234 Variable *RegBase = NULL;
2134 Variable *RegIndex = NULL; 2235 Variable *RegIndex = NULL;
2135 if (Base) { 2236 if (Base) {
2136 RegBase = legalizeToVar(Base, true); 2237 RegBase = legalizeToVar(Base, true);
2137 } 2238 }
2138 if (Index) { 2239 if (Index) {
2139 RegIndex = legalizeToVar(Index, true); 2240 RegIndex = legalizeToVar(Index, true);
2140 } 2241 }
2141 if (Base != RegBase || Index != RegIndex) { 2242 if (Base != RegBase || Index != RegIndex) {
2142 From = 2243 From = OperandX8632Mem::create(
2143 OperandX8632Mem::create(Func, Mem->getType(), RegBase, 2244 Func, Mem->getType(), RegBase, Mem->getOffset(), RegIndex,
2144 Mem->getOffset(), RegIndex, Mem->getShift()); 2245 Mem->getShift(), Mem->getSegmentRegister());
2145 } 2246 }
2146 2247
2147 if (!(Allowed & Legal_Mem)) { 2248 if (!(Allowed & Legal_Mem)) {
2148 Variable *Reg = makeReg(From->getType(), RegNum); 2249 Variable *Reg = makeReg(From->getType(), RegNum);
2149 _mov(Reg, From, RegNum); 2250 _mov(Reg, From, RegNum);
2150 From = Reg; 2251 From = Reg;
2151 } 2252 }
2152 return From; 2253 return From;
2153 } 2254 }
2154 if (llvm::isa<Constant>(From)) { 2255 if (llvm::isa<Constant>(From)) {
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
2261 // llvm-mc doesn't parse "dword ptr [.L$foo]". 2362 // llvm-mc doesn't parse "dword ptr [.L$foo]".
2262 Str << "dword ptr [L$" << IceType_f32 << "$" << getPoolEntryID() << "]"; 2363 Str << "dword ptr [L$" << IceType_f32 << "$" << getPoolEntryID() << "]";
2263 } 2364 }
2264 2365
2265 template <> void ConstantDouble::emit(GlobalContext *Ctx) const { 2366 template <> void ConstantDouble::emit(GlobalContext *Ctx) const {
2266 Ostream &Str = Ctx->getStrEmit(); 2367 Ostream &Str = Ctx->getStrEmit();
2267 Str << "qword ptr [L$" << IceType_f64 << "$" << getPoolEntryID() << "]"; 2368 Str << "qword ptr [L$" << IceType_f64 << "$" << getPoolEntryID() << "]";
2268 } 2369 }
2269 2370
2270 } // end of namespace Ice 2371 } // end of namespace Ice
OLDNEW
« src/IceIntrinsics.cpp ('K') | « src/IceTargetLoweringX8632.h ('k') | src/llvm2ice.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698