OLD | NEW |
1 //===-- MipsISelLowering.cpp - Mips DAG Lowering Implementation -----------===// | 1 //===-- MipsISelLowering.cpp - Mips DAG Lowering Implementation -----------===// |
2 // | 2 // |
3 // The LLVM Compiler Infrastructure | 3 // The LLVM Compiler Infrastructure |
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 defines the interfaces that Mips uses to lower LLVM code into a | 10 // This file defines the interfaces that Mips uses to lower LLVM code into a |
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 setOperationAction(ISD::FREM, MVT::f32, Expand); | 333 setOperationAction(ISD::FREM, MVT::f32, Expand); |
334 setOperationAction(ISD::FREM, MVT::f64, Expand); | 334 setOperationAction(ISD::FREM, MVT::f64, Expand); |
335 | 335 |
336 setOperationAction(ISD::EH_RETURN, MVT::Other, Custom); | 336 setOperationAction(ISD::EH_RETURN, MVT::Other, Custom); |
337 | 337 |
338 setOperationAction(ISD::VASTART, MVT::Other, Custom); | 338 setOperationAction(ISD::VASTART, MVT::Other, Custom); |
339 setOperationAction(ISD::VAARG, MVT::Other, Custom); | 339 setOperationAction(ISD::VAARG, MVT::Other, Custom); |
340 setOperationAction(ISD::VACOPY, MVT::Other, Expand); | 340 setOperationAction(ISD::VACOPY, MVT::Other, Expand); |
341 setOperationAction(ISD::VAEND, MVT::Other, Expand); | 341 setOperationAction(ISD::VAEND, MVT::Other, Expand); |
342 | 342 |
| 343 // @LOCALMOD-BEGIN |
| 344 if (Subtarget.isTargetNaCl()) |
| 345 setOperationAction(ISD::INTRINSIC_WO_CHAIN, MVT::Other, Custom); |
| 346 else |
| 347 setOperationAction(ISD::INTRINSIC_WO_CHAIN, MVT::i64, Custom); |
| 348 // @LOCALMOD-END |
| 349 |
343 // Use the default for now | 350 // Use the default for now |
344 setOperationAction(ISD::STACKSAVE, MVT::Other, Expand); | 351 setOperationAction(ISD::STACKSAVE, MVT::Other, Expand); |
345 setOperationAction(ISD::STACKRESTORE, MVT::Other, Expand); | 352 setOperationAction(ISD::STACKRESTORE, MVT::Other, Expand); |
346 | 353 |
347 setOperationAction(ISD::ATOMIC_LOAD, MVT::i32, Expand); | 354 setOperationAction(ISD::ATOMIC_LOAD, MVT::i32, Expand); |
348 setOperationAction(ISD::ATOMIC_LOAD, MVT::i64, Expand); | 355 setOperationAction(ISD::ATOMIC_LOAD, MVT::i64, Expand); |
349 setOperationAction(ISD::ATOMIC_STORE, MVT::i32, Expand); | 356 setOperationAction(ISD::ATOMIC_STORE, MVT::i32, Expand); |
350 setOperationAction(ISD::ATOMIC_STORE, MVT::i64, Expand); | 357 setOperationAction(ISD::ATOMIC_STORE, MVT::i64, Expand); |
351 | 358 |
352 setInsertFencesForAtomic(true); | 359 setInsertFencesForAtomic(true); |
(...skipping 1262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1615 EVT Ty = Op.getValueType(); | 1622 EVT Ty = Op.getValueType(); |
1616 | 1623 |
1617 if (getTargetMachine().getRelocationModel() != Reloc::PIC_ && | 1624 if (getTargetMachine().getRelocationModel() != Reloc::PIC_ && |
1618 !Subtarget.isABI_N64()) | 1625 !Subtarget.isABI_N64()) |
1619 return getAddrNonPIC(N, Ty, DAG); | 1626 return getAddrNonPIC(N, Ty, DAG); |
1620 | 1627 |
1621 return getAddrLocal(N, Ty, DAG, | 1628 return getAddrLocal(N, Ty, DAG, |
1622 Subtarget.isABI_N32() || Subtarget.isABI_N64()); | 1629 Subtarget.isABI_N32() || Subtarget.isABI_N64()); |
1623 } | 1630 } |
1624 | 1631 |
| 1632 // @LOCALMOD-BEGIN |
| 1633 SDValue MipsTargetLowering:: |
| 1634 GetNaClThreadPointer(SelectionDAG &DAG, SDLoc DL) const { |
| 1635 EVT PtrVT = getPointerTy(); |
| 1636 SDValue ThreadPointer; |
| 1637 if (llvm::TLSUseCall) { |
| 1638 unsigned PtrSize = PtrVT.getSizeInBits(); |
| 1639 IntegerType *PtrTy = Type::getIntNTy(*DAG.getContext(), PtrSize); |
| 1640 |
| 1641 // We must check whether the __nacl_read_tp is defined in the module because |
| 1642 // local and global pic functions are called differently. If the function |
| 1643 // is local the address is calculated with %got and %lo relocations. |
| 1644 // Otherwise, the address is calculated with %call16 relocation. |
| 1645 const Function *NaClReadTp = NULL; |
| 1646 const Module *M = DAG.getMachineFunction().getFunction()->getParent(); |
| 1647 for (Module::const_iterator I = M->getFunctionList().begin(), |
| 1648 E = M->getFunctionList().end(); I != E; ++I) { |
| 1649 if (I->getName() == "__nacl_read_tp") { |
| 1650 NaClReadTp = I; |
| 1651 break; |
| 1652 } |
| 1653 } |
| 1654 |
| 1655 SDValue TlsReadTp; |
| 1656 if (NaClReadTp == NULL) |
| 1657 TlsReadTp = DAG.getExternalSymbol("__nacl_read_tp", PtrVT); |
| 1658 else |
| 1659 TlsReadTp = DAG.getGlobalAddress(NaClReadTp, DL, PtrVT); |
| 1660 |
| 1661 ArgListTy Args; |
| 1662 TargetLowering::CallLoweringInfo CLI(DAG); |
| 1663 CLI.setDebugLoc(DL).setChain(DAG.getEntryNode()) |
| 1664 .setCallee(CallingConv::C, PtrTy, TlsReadTp, std::move(Args), 0); |
| 1665 std::pair<SDValue, SDValue> CallResult = LowerCallTo(CLI); |
| 1666 |
| 1667 ThreadPointer = CallResult.first; |
| 1668 } else { |
| 1669 ThreadPointer = DAG.getCopyFromReg(DAG.getEntryNode(), DL, |
| 1670 Mips::T8, PtrVT); |
| 1671 } |
| 1672 return ThreadPointer; |
| 1673 } |
| 1674 // @LOCALMOD-END |
| 1675 |
1625 SDValue MipsTargetLowering:: | 1676 SDValue MipsTargetLowering:: |
1626 lowerGlobalTLSAddress(SDValue Op, SelectionDAG &DAG) const | 1677 lowerGlobalTLSAddress(SDValue Op, SelectionDAG &DAG) const |
1627 { | 1678 { |
1628 // If the relocation model is PIC, use the General Dynamic TLS Model or | 1679 // If the relocation model is PIC, use the General Dynamic TLS Model or |
1629 // Local Dynamic TLS model, otherwise use the Initial Exec or | 1680 // Local Dynamic TLS model, otherwise use the Initial Exec or |
1630 // Local Exec TLS Model. | 1681 // Local Exec TLS Model. |
1631 | 1682 |
1632 GlobalAddressSDNode *GA = cast<GlobalAddressSDNode>(Op); | 1683 GlobalAddressSDNode *GA = cast<GlobalAddressSDNode>(Op); |
1633 SDLoc DL(GA); | 1684 SDLoc DL(GA); |
1634 const GlobalValue *GV = GA->getGlobal(); | 1685 const GlobalValue *GV = GA->getGlobal(); |
1635 EVT PtrVT = getPointerTy(); | 1686 EVT PtrVT = getPointerTy(); |
1636 | 1687 |
1637 TLSModel::Model model = getTargetMachine().getTLSModel(GV); | 1688 TLSModel::Model model = getTargetMachine().getTLSModel(GV); |
1638 | 1689 |
| 1690 // @LOCALMOD-BEGIN |
| 1691 if (Subtarget.isTargetNaCl()) { |
| 1692 SDVTList VTs = DAG.getVTList(MVT::i32); |
| 1693 SDValue TGAHi = DAG.getTargetGlobalAddress(GV, DL, MVT::i32, 0, |
| 1694 MipsII::MO_TPREL_HI); |
| 1695 SDValue TGALo = DAG.getTargetGlobalAddress(GV, DL, MVT::i32, 0, |
| 1696 MipsII::MO_TPREL_LO); |
| 1697 SDValue Hi = DAG.getNode(MipsISD::Hi, DL, VTs, TGAHi); |
| 1698 SDValue Lo = DAG.getNode(MipsISD::Lo, DL, MVT::i32, TGALo); |
| 1699 SDValue Offset = DAG.getNode(ISD::ADD, DL, MVT::i32, Hi, Lo); |
| 1700 |
| 1701 SDValue ThreadPointer = GetNaClThreadPointer(DAG, DL); |
| 1702 // tprel_hi and tprel_lo relocations expect that thread pointer is offset |
| 1703 // by 0x7000 from the start of the TLS data area. |
| 1704 SDValue TPOffset = DAG.getConstant(0x7000, MVT::i32); |
| 1705 SDValue ThreadPointer2 = DAG.getNode(ISD::ADD, DL, PtrVT, ThreadPointer, |
| 1706 TPOffset); |
| 1707 return DAG.getNode(ISD::ADD, DL, PtrVT, ThreadPointer2, Offset); |
| 1708 } |
| 1709 // @LOCALMOD-END |
| 1710 |
1639 if (model == TLSModel::GeneralDynamic || model == TLSModel::LocalDynamic) { | 1711 if (model == TLSModel::GeneralDynamic || model == TLSModel::LocalDynamic) { |
1640 // General Dynamic and Local Dynamic TLS Model. | 1712 // General Dynamic and Local Dynamic TLS Model. |
1641 unsigned Flag = (model == TLSModel::LocalDynamic) ? MipsII::MO_TLSLDM | 1713 unsigned Flag = (model == TLSModel::LocalDynamic) ? MipsII::MO_TLSLDM |
1642 : MipsII::MO_TLSGD; | 1714 : MipsII::MO_TLSGD; |
1643 | 1715 |
1644 SDValue TGA = DAG.getTargetGlobalAddress(GV, DL, PtrVT, 0, Flag); | 1716 SDValue TGA = DAG.getTargetGlobalAddress(GV, DL, PtrVT, 0, Flag); |
1645 SDValue Argument = DAG.getNode(MipsISD::Wrapper, DL, PtrVT, | 1717 SDValue Argument = DAG.getNode(MipsISD::Wrapper, DL, PtrVT, |
1646 getGlobalReg(DAG, PtrVT), TGA); | 1718 getGlobalReg(DAG, PtrVT), TGA); |
1647 unsigned PtrSize = PtrVT.getSizeInBits(); | 1719 unsigned PtrSize = PtrVT.getSizeInBits(); |
1648 IntegerType *PtrTy = Type::getIntNTy(*DAG.getContext(), PtrSize); | 1720 IntegerType *PtrTy = Type::getIntNTy(*DAG.getContext(), PtrSize); |
(...skipping 2064 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3713 | 3785 |
3714 // Mark the registers allocated. | 3786 // Mark the registers allocated. |
3715 Size = RoundUpToAlignment(Size, RegSizeInBytes); | 3787 Size = RoundUpToAlignment(Size, RegSizeInBytes); |
3716 for (unsigned I = FirstReg; Size > 0 && (I < IntArgRegs.size()); | 3788 for (unsigned I = FirstReg; Size > 0 && (I < IntArgRegs.size()); |
3717 Size -= RegSizeInBytes, ++I, ++NumRegs) | 3789 Size -= RegSizeInBytes, ++I, ++NumRegs) |
3718 State->AllocateReg(IntArgRegs[I], ShadowRegs[I]); | 3790 State->AllocateReg(IntArgRegs[I], ShadowRegs[I]); |
3719 } | 3791 } |
3720 | 3792 |
3721 State->addInRegsParamInfo(FirstReg, FirstReg + NumRegs); | 3793 State->addInRegsParamInfo(FirstReg, FirstReg + NumRegs); |
3722 } | 3794 } |
OLD | NEW |