comparison lib/Target/Mips/MipsISelLowering.cpp @ 120:1172e4bd9c6f

update 4.0.0
author mir3636
date Fri, 25 Nov 2016 19:14:25 +0900
parents 7d135dc70f03
children 803732b1fca8
comparison
equal deleted inserted replaced
101:34baf5011add 120:1172e4bd9c6f
266 // we don't want this, since the fpcmp result goes to a flag register, 266 // we don't want this, since the fpcmp result goes to a flag register,
267 // which is used implicitly by brcond and select operations. 267 // which is used implicitly by brcond and select operations.
268 AddPromotedToType(ISD::SETCC, MVT::i1, MVT::i32); 268 AddPromotedToType(ISD::SETCC, MVT::i1, MVT::i32);
269 269
270 // Mips Custom Operations 270 // Mips Custom Operations
271 setOperationAction(ISD::BR_JT, MVT::Other, Custom); 271 setOperationAction(ISD::BR_JT, MVT::Other, Expand);
272 setOperationAction(ISD::GlobalAddress, MVT::i32, Custom); 272 setOperationAction(ISD::GlobalAddress, MVT::i32, Custom);
273 setOperationAction(ISD::BlockAddress, MVT::i32, Custom); 273 setOperationAction(ISD::BlockAddress, MVT::i32, Custom);
274 setOperationAction(ISD::GlobalTLSAddress, MVT::i32, Custom); 274 setOperationAction(ISD::GlobalTLSAddress, MVT::i32, Custom);
275 setOperationAction(ISD::JumpTable, MVT::i32, Custom); 275 setOperationAction(ISD::JumpTable, MVT::i32, Custom);
276 setOperationAction(ISD::ConstantPool, MVT::i32, Custom); 276 setOperationAction(ISD::ConstantPool, MVT::i32, Custom);
303 setOperationAction(ISD::SHL_PARTS, MVT::i32, Custom); 303 setOperationAction(ISD::SHL_PARTS, MVT::i32, Custom);
304 setOperationAction(ISD::SRA_PARTS, MVT::i32, Custom); 304 setOperationAction(ISD::SRA_PARTS, MVT::i32, Custom);
305 setOperationAction(ISD::SRL_PARTS, MVT::i32, Custom); 305 setOperationAction(ISD::SRL_PARTS, MVT::i32, Custom);
306 } 306 }
307 307
308 setOperationAction(ISD::ADD, MVT::i32, Custom); 308 setOperationAction(ISD::EH_DWARF_CFA, MVT::i32, Custom);
309 if (Subtarget.isGP64bit()) 309 if (Subtarget.isGP64bit())
310 setOperationAction(ISD::ADD, MVT::i64, Custom); 310 setOperationAction(ISD::EH_DWARF_CFA, MVT::i64, Custom);
311 311
312 setOperationAction(ISD::SDIV, MVT::i32, Expand); 312 setOperationAction(ISD::SDIV, MVT::i32, Expand);
313 setOperationAction(ISD::SREM, MVT::i32, Expand); 313 setOperationAction(ISD::SREM, MVT::i32, Expand);
314 setOperationAction(ISD::UDIV, MVT::i32, Expand); 314 setOperationAction(ISD::UDIV, MVT::i32, Expand);
315 setOperationAction(ISD::UREM, MVT::i32, Expand); 315 setOperationAction(ISD::UREM, MVT::i32, Expand);
339 setOperationAction(ISD::CTPOP, MVT::i32, Expand); 339 setOperationAction(ISD::CTPOP, MVT::i32, Expand);
340 setOperationAction(ISD::CTPOP, MVT::i64, Expand); 340 setOperationAction(ISD::CTPOP, MVT::i64, Expand);
341 } 341 }
342 setOperationAction(ISD::CTTZ, MVT::i32, Expand); 342 setOperationAction(ISD::CTTZ, MVT::i32, Expand);
343 setOperationAction(ISD::CTTZ, MVT::i64, Expand); 343 setOperationAction(ISD::CTTZ, MVT::i64, Expand);
344 setOperationAction(ISD::CTTZ_ZERO_UNDEF, MVT::i32, Expand);
345 setOperationAction(ISD::CTTZ_ZERO_UNDEF, MVT::i64, Expand);
346 setOperationAction(ISD::CTLZ_ZERO_UNDEF, MVT::i32, Expand);
347 setOperationAction(ISD::CTLZ_ZERO_UNDEF, MVT::i64, Expand);
348 setOperationAction(ISD::ROTL, MVT::i32, Expand); 344 setOperationAction(ISD::ROTL, MVT::i32, Expand);
349 setOperationAction(ISD::ROTL, MVT::i64, Expand); 345 setOperationAction(ISD::ROTL, MVT::i64, Expand);
350 setOperationAction(ISD::DYNAMIC_STACKALLOC, MVT::i32, Expand); 346 setOperationAction(ISD::DYNAMIC_STACKALLOC, MVT::i32, Expand);
351 setOperationAction(ISD::DYNAMIC_STACKALLOC, MVT::i64, Expand); 347 setOperationAction(ISD::DYNAMIC_STACKALLOC, MVT::i64, Expand);
352 348
394 if (!Subtarget.isGP64bit()) { 390 if (!Subtarget.isGP64bit()) {
395 setOperationAction(ISD::ATOMIC_LOAD, MVT::i64, Expand); 391 setOperationAction(ISD::ATOMIC_LOAD, MVT::i64, Expand);
396 setOperationAction(ISD::ATOMIC_STORE, MVT::i64, Expand); 392 setOperationAction(ISD::ATOMIC_STORE, MVT::i64, Expand);
397 } 393 }
398 394
399 setInsertFencesForAtomic(true);
400 395
401 if (!Subtarget.hasMips32r2()) { 396 if (!Subtarget.hasMips32r2()) {
402 setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i8, Expand); 397 setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i8, Expand);
403 setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i16, Expand); 398 setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i16, Expand);
404 } 399 }
427 setTargetDAGCombine(ISD::UDIVREM); 422 setTargetDAGCombine(ISD::UDIVREM);
428 setTargetDAGCombine(ISD::SELECT); 423 setTargetDAGCombine(ISD::SELECT);
429 setTargetDAGCombine(ISD::AND); 424 setTargetDAGCombine(ISD::AND);
430 setTargetDAGCombine(ISD::OR); 425 setTargetDAGCombine(ISD::OR);
431 setTargetDAGCombine(ISD::ADD); 426 setTargetDAGCombine(ISD::ADD);
427 setTargetDAGCombine(ISD::AssertZext);
428
429 if (ABI.IsO32()) {
430 // These libcalls are not available in 32-bit.
431 setLibcallName(RTLIB::SHL_I128, nullptr);
432 setLibcallName(RTLIB::SRL_I128, nullptr);
433 setLibcallName(RTLIB::SRA_I128, nullptr);
434 }
432 435
433 setMinFunctionAlignment(Subtarget.isGP64bit() ? 3 : 2); 436 setMinFunctionAlignment(Subtarget.isGP64bit() ? 3 : 2);
434 437
435 // The arguments on the stack are defined in terms of 4-byte slots on O32 438 // The arguments on the stack are defined in terms of 4-byte slots on O32
436 // and 8-byte slots on N32/N64. 439 // and 8-byte slots on N32/N64.
453 456
454 // Create a fast isel object. 457 // Create a fast isel object.
455 FastISel * 458 FastISel *
456 MipsTargetLowering::createFastISel(FunctionLoweringInfo &funcInfo, 459 MipsTargetLowering::createFastISel(FunctionLoweringInfo &funcInfo,
457 const TargetLibraryInfo *libInfo) const { 460 const TargetLibraryInfo *libInfo) const {
458 if (!funcInfo.MF->getTarget().Options.EnableFastISel) 461 const MipsTargetMachine &TM =
459 return TargetLowering::createFastISel(funcInfo, libInfo); 462 static_cast<const MipsTargetMachine &>(funcInfo.MF->getTarget());
460 return Mips::createFastISel(funcInfo, libInfo); 463
464 // We support only the standard encoding [MIPS32,MIPS32R5] ISAs.
465 bool UseFastISel = TM.Options.EnableFastISel && Subtarget.hasMips32() &&
466 !Subtarget.hasMips32r6() && !Subtarget.inMips16Mode() &&
467 !Subtarget.inMicroMipsMode();
468
469 // Disable if we don't generate PIC or the ABI isn't O32.
470 if (!TM.isPositionIndependent() || !TM.getABI().IsO32())
471 UseFastISel = false;
472
473 return UseFastISel ? Mips::createFastISel(funcInfo, libInfo) : nullptr;
461 } 474 }
462 475
463 EVT MipsTargetLowering::getSetCCResultType(const DataLayout &, LLVMContext &, 476 EVT MipsTargetLowering::getSetCCResultType(const DataLayout &, LLVMContext &,
464 EVT VT) const { 477 EVT VT) const {
465 if (!VT.isVector()) 478 if (!VT.isVector())
566 DAG.getConstant(condCodeToFCC(CC), DL, MVT::i32)); 579 DAG.getConstant(condCodeToFCC(CC), DL, MVT::i32));
567 } 580 }
568 581
569 // Creates and returns a CMovFPT/F node. 582 // Creates and returns a CMovFPT/F node.
570 static SDValue createCMovFP(SelectionDAG &DAG, SDValue Cond, SDValue True, 583 static SDValue createCMovFP(SelectionDAG &DAG, SDValue Cond, SDValue True,
571 SDValue False, SDLoc DL) { 584 SDValue False, const SDLoc &DL) {
572 ConstantSDNode *CC = cast<ConstantSDNode>(Cond.getOperand(2)); 585 ConstantSDNode *CC = cast<ConstantSDNode>(Cond.getOperand(2));
573 bool invert = invertFPCondCodeUser((Mips::CondCode)CC->getSExtValue()); 586 bool invert = invertFPCondCodeUser((Mips::CondCode)CC->getSExtValue());
574 SDValue FCC0 = DAG.getRegister(Mips::FCC0, MVT::i32); 587 SDValue FCC0 = DAG.getRegister(Mips::FCC0, MVT::i32);
575 588
576 return DAG.getNode((invert ? MipsISD::CMovFP_F : MipsISD::CMovFP_T), DL, 589 return DAG.getNode((invert ? MipsISD::CMovFP_F : MipsISD::CMovFP_T), DL,
804 SDLoc DL(N); 817 SDLoc DL(N);
805 818
806 SDValue Add1 = DAG.getNode(ISD::ADD, DL, ValTy, N->getOperand(0), 819 SDValue Add1 = DAG.getNode(ISD::ADD, DL, ValTy, N->getOperand(0),
807 Add.getOperand(0)); 820 Add.getOperand(0));
808 return DAG.getNode(ISD::ADD, DL, ValTy, Add1, Lo); 821 return DAG.getNode(ISD::ADD, DL, ValTy, Add1, Lo);
822 }
823
824 static SDValue performAssertZextCombine(SDNode *N, SelectionDAG &DAG,
825 TargetLowering::DAGCombinerInfo &DCI,
826 const MipsSubtarget &Subtarget) {
827 SDValue N0 = N->getOperand(0);
828 EVT NarrowerVT = cast<VTSDNode>(N->getOperand(1))->getVT();
829
830 if (N0.getOpcode() != ISD::TRUNCATE)
831 return SDValue();
832
833 if (N0.getOperand(0).getOpcode() != ISD::AssertZext)
834 return SDValue();
835
836 // fold (AssertZext (trunc (AssertZext x))) -> (trunc (AssertZext x))
837 // if the type of the extension of the innermost AssertZext node is
838 // smaller from that of the outermost node, eg:
839 // (AssertZext:i32 (trunc:i32 (AssertZext:i64 X, i32)), i8)
840 // -> (trunc:i32 (AssertZext X, i8))
841 SDValue WiderAssertZext = N0.getOperand(0);
842 EVT WiderVT = cast<VTSDNode>(WiderAssertZext->getOperand(1))->getVT();
843
844 if (NarrowerVT.bitsLT(WiderVT)) {
845 SDValue NewAssertZext = DAG.getNode(
846 ISD::AssertZext, SDLoc(N), WiderAssertZext.getValueType(),
847 WiderAssertZext.getOperand(0), DAG.getValueType(NarrowerVT));
848 return DAG.getNode(ISD::TRUNCATE, SDLoc(N), N->getValueType(0),
849 NewAssertZext);
850 }
851
852 return SDValue();
809 } 853 }
810 854
811 SDValue MipsTargetLowering::PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) 855 SDValue MipsTargetLowering::PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI)
812 const { 856 const {
813 SelectionDAG &DAG = DCI.DAG; 857 SelectionDAG &DAG = DCI.DAG;
827 return performANDCombine(N, DAG, DCI, Subtarget); 871 return performANDCombine(N, DAG, DCI, Subtarget);
828 case ISD::OR: 872 case ISD::OR:
829 return performORCombine(N, DAG, DCI, Subtarget); 873 return performORCombine(N, DAG, DCI, Subtarget);
830 case ISD::ADD: 874 case ISD::ADD:
831 return performADDCombine(N, DAG, DCI, Subtarget); 875 return performADDCombine(N, DAG, DCI, Subtarget);
876 case ISD::AssertZext:
877 return performAssertZextCombine(N, DAG, DCI, Subtarget);
832 } 878 }
833 879
834 return SDValue(); 880 return SDValue();
835 } 881 }
836 882
862 SDValue MipsTargetLowering:: 908 SDValue MipsTargetLowering::
863 LowerOperation(SDValue Op, SelectionDAG &DAG) const 909 LowerOperation(SDValue Op, SelectionDAG &DAG) const
864 { 910 {
865 switch (Op.getOpcode()) 911 switch (Op.getOpcode())
866 { 912 {
867 case ISD::BR_JT: return lowerBR_JT(Op, DAG);
868 case ISD::BRCOND: return lowerBRCOND(Op, DAG); 913 case ISD::BRCOND: return lowerBRCOND(Op, DAG);
869 case ISD::ConstantPool: return lowerConstantPool(Op, DAG); 914 case ISD::ConstantPool: return lowerConstantPool(Op, DAG);
870 case ISD::GlobalAddress: return lowerGlobalAddress(Op, DAG); 915 case ISD::GlobalAddress: return lowerGlobalAddress(Op, DAG);
871 case ISD::BlockAddress: return lowerBlockAddress(Op, DAG); 916 case ISD::BlockAddress: return lowerBlockAddress(Op, DAG);
872 case ISD::GlobalTLSAddress: return lowerGlobalTLSAddress(Op, DAG); 917 case ISD::GlobalTLSAddress: return lowerGlobalTLSAddress(Op, DAG);
883 case ISD::SHL_PARTS: return lowerShiftLeftParts(Op, DAG); 928 case ISD::SHL_PARTS: return lowerShiftLeftParts(Op, DAG);
884 case ISD::SRA_PARTS: return lowerShiftRightParts(Op, DAG, true); 929 case ISD::SRA_PARTS: return lowerShiftRightParts(Op, DAG, true);
885 case ISD::SRL_PARTS: return lowerShiftRightParts(Op, DAG, false); 930 case ISD::SRL_PARTS: return lowerShiftRightParts(Op, DAG, false);
886 case ISD::LOAD: return lowerLOAD(Op, DAG); 931 case ISD::LOAD: return lowerLOAD(Op, DAG);
887 case ISD::STORE: return lowerSTORE(Op, DAG); 932 case ISD::STORE: return lowerSTORE(Op, DAG);
888 case ISD::ADD: return lowerADD(Op, DAG); 933 case ISD::EH_DWARF_CFA: return lowerEH_DWARF_CFA(Op, DAG);
889 case ISD::FP_TO_SINT: return lowerFP_TO_SINT(Op, DAG); 934 case ISD::FP_TO_SINT: return lowerFP_TO_SINT(Op, DAG);
890 } 935 }
891 return SDValue(); 936 return SDValue();
892 } 937 }
893 938
904 unsigned VReg = MF.getRegInfo().createVirtualRegister(RC); 949 unsigned VReg = MF.getRegInfo().createVirtualRegister(RC);
905 MF.getRegInfo().addLiveIn(PReg, VReg); 950 MF.getRegInfo().addLiveIn(PReg, VReg);
906 return VReg; 951 return VReg;
907 } 952 }
908 953
909 static MachineBasicBlock *insertDivByZeroTrap(MachineInstr *MI, 954 static MachineBasicBlock *insertDivByZeroTrap(MachineInstr &MI,
910 MachineBasicBlock &MBB, 955 MachineBasicBlock &MBB,
911 const TargetInstrInfo &TII, 956 const TargetInstrInfo &TII,
912 bool Is64Bit) { 957 bool Is64Bit, bool IsMicroMips) {
913 if (NoZeroDivCheck) 958 if (NoZeroDivCheck)
914 return &MBB; 959 return &MBB;
915 960
916 // Insert instruction "teq $divisor_reg, $zero, 7". 961 // Insert instruction "teq $divisor_reg, $zero, 7".
917 MachineBasicBlock::iterator I(MI); 962 MachineBasicBlock::iterator I(MI);
918 MachineInstrBuilder MIB; 963 MachineInstrBuilder MIB;
919 MachineOperand &Divisor = MI->getOperand(2); 964 MachineOperand &Divisor = MI.getOperand(2);
920 MIB = BuildMI(MBB, std::next(I), MI->getDebugLoc(), TII.get(Mips::TEQ)) 965 MIB = BuildMI(MBB, std::next(I), MI.getDebugLoc(),
921 .addReg(Divisor.getReg(), getKillRegState(Divisor.isKill())) 966 TII.get(IsMicroMips ? Mips::TEQ_MM : Mips::TEQ))
922 .addReg(Mips::ZERO).addImm(7); 967 .addReg(Divisor.getReg(), getKillRegState(Divisor.isKill()))
968 .addReg(Mips::ZERO)
969 .addImm(7);
923 970
924 // Use the 32-bit sub-register if this is a 64-bit division. 971 // Use the 32-bit sub-register if this is a 64-bit division.
925 if (Is64Bit) 972 if (Is64Bit)
926 MIB->getOperand(0).setSubReg(Mips::sub_32); 973 MIB->getOperand(0).setSubReg(Mips::sub_32);
927 974
933 980
934 return &MBB; 981 return &MBB;
935 } 982 }
936 983
937 MachineBasicBlock * 984 MachineBasicBlock *
938 MipsTargetLowering::EmitInstrWithCustomInserter(MachineInstr *MI, 985 MipsTargetLowering::EmitInstrWithCustomInserter(MachineInstr &MI,
939 MachineBasicBlock *BB) const { 986 MachineBasicBlock *BB) const {
940 switch (MI->getOpcode()) { 987 switch (MI.getOpcode()) {
941 default: 988 default:
942 llvm_unreachable("Unexpected instr type to insert"); 989 llvm_unreachable("Unexpected instr type to insert");
943 case Mips::ATOMIC_LOAD_ADD_I8: 990 case Mips::ATOMIC_LOAD_ADD_I8:
944 return emitAtomicBinaryPartword(MI, BB, 1, Mips::ADDu); 991 return emitAtomicBinaryPartword(MI, BB, 1, Mips::ADDu);
945 case Mips::ATOMIC_LOAD_ADD_I16: 992 case Mips::ATOMIC_LOAD_ADD_I16:
1015 case Mips::PseudoUDIV: 1062 case Mips::PseudoUDIV:
1016 case Mips::DIV: 1063 case Mips::DIV:
1017 case Mips::DIVU: 1064 case Mips::DIVU:
1018 case Mips::MOD: 1065 case Mips::MOD:
1019 case Mips::MODU: 1066 case Mips::MODU:
1020 return insertDivByZeroTrap(MI, *BB, *Subtarget.getInstrInfo(), false); 1067 return insertDivByZeroTrap(MI, *BB, *Subtarget.getInstrInfo(), false,
1068 false);
1069 case Mips::SDIV_MM_Pseudo:
1070 case Mips::UDIV_MM_Pseudo:
1071 case Mips::SDIV_MM:
1072 case Mips::UDIV_MM:
1073 case Mips::DIV_MMR6:
1074 case Mips::DIVU_MMR6:
1075 case Mips::MOD_MMR6:
1076 case Mips::MODU_MMR6:
1077 return insertDivByZeroTrap(MI, *BB, *Subtarget.getInstrInfo(), false, true);
1021 case Mips::PseudoDSDIV: 1078 case Mips::PseudoDSDIV:
1022 case Mips::PseudoDUDIV: 1079 case Mips::PseudoDUDIV:
1023 case Mips::DDIV: 1080 case Mips::DDIV:
1024 case Mips::DDIVU: 1081 case Mips::DDIVU:
1025 case Mips::DMOD: 1082 case Mips::DMOD:
1026 case Mips::DMODU: 1083 case Mips::DMODU:
1027 return insertDivByZeroTrap(MI, *BB, *Subtarget.getInstrInfo(), true); 1084 return insertDivByZeroTrap(MI, *BB, *Subtarget.getInstrInfo(), true, false);
1085 case Mips::DDIV_MM64R6:
1086 case Mips::DDIVU_MM64R6:
1087 case Mips::DMOD_MM64R6:
1088 case Mips::DMODU_MM64R6:
1089 return insertDivByZeroTrap(MI, *BB, *Subtarget.getInstrInfo(), true, true);
1028 case Mips::SEL_D: 1090 case Mips::SEL_D:
1091 case Mips::SEL_D_MMR6:
1029 return emitSEL_D(MI, BB); 1092 return emitSEL_D(MI, BB);
1030 1093
1031 case Mips::PseudoSELECT_I: 1094 case Mips::PseudoSELECT_I:
1032 case Mips::PseudoSELECT_I64: 1095 case Mips::PseudoSELECT_I64:
1033 case Mips::PseudoSELECT_S: 1096 case Mips::PseudoSELECT_S:
1049 } 1112 }
1050 } 1113 }
1051 1114
1052 // This function also handles Mips::ATOMIC_SWAP_I32 (when BinOpcode == 0), and 1115 // This function also handles Mips::ATOMIC_SWAP_I32 (when BinOpcode == 0), and
1053 // Mips::ATOMIC_LOAD_NAND_I32 (when Nand == true) 1116 // Mips::ATOMIC_LOAD_NAND_I32 (when Nand == true)
1054 MachineBasicBlock * 1117 MachineBasicBlock *MipsTargetLowering::emitAtomicBinary(MachineInstr &MI,
1055 MipsTargetLowering::emitAtomicBinary(MachineInstr *MI, MachineBasicBlock *BB, 1118 MachineBasicBlock *BB,
1056 unsigned Size, unsigned BinOpcode, 1119 unsigned Size,
1057 bool Nand) const { 1120 unsigned BinOpcode,
1121 bool Nand) const {
1058 assert((Size == 4 || Size == 8) && "Unsupported size for EmitAtomicBinary."); 1122 assert((Size == 4 || Size == 8) && "Unsupported size for EmitAtomicBinary.");
1059 1123
1060 MachineFunction *MF = BB->getParent(); 1124 MachineFunction *MF = BB->getParent();
1061 MachineRegisterInfo &RegInfo = MF->getRegInfo(); 1125 MachineRegisterInfo &RegInfo = MF->getRegInfo();
1062 const TargetRegisterClass *RC = getRegClassFor(MVT::getIntegerVT(Size * 8)); 1126 const TargetRegisterClass *RC = getRegClassFor(MVT::getIntegerVT(Size * 8));
1063 const TargetInstrInfo *TII = Subtarget.getInstrInfo(); 1127 const TargetInstrInfo *TII = Subtarget.getInstrInfo();
1064 DebugLoc DL = MI->getDebugLoc(); 1128 const bool ArePtrs64bit = ABI.ArePtrs64bit();
1129 DebugLoc DL = MI.getDebugLoc();
1065 unsigned LL, SC, AND, NOR, ZERO, BEQ; 1130 unsigned LL, SC, AND, NOR, ZERO, BEQ;
1066 1131
1067 if (Size == 4) { 1132 if (Size == 4) {
1068 if (isMicroMips) { 1133 if (isMicroMips) {
1069 LL = Mips::LL_MM; 1134 LL = Mips::LL_MM;
1070 SC = Mips::SC_MM; 1135 SC = Mips::SC_MM;
1071 } else { 1136 } else {
1072 LL = Subtarget.hasMips32r6() ? Mips::LL_R6 : Mips::LL; 1137 LL = Subtarget.hasMips32r6()
1073 SC = Subtarget.hasMips32r6() ? Mips::SC_R6 : Mips::SC; 1138 ? (ArePtrs64bit ? Mips::LL64_R6 : Mips::LL_R6)
1139 : (ArePtrs64bit ? Mips::LL64 : Mips::LL);
1140 SC = Subtarget.hasMips32r6()
1141 ? (ArePtrs64bit ? Mips::SC64_R6 : Mips::SC_R6)
1142 : (ArePtrs64bit ? Mips::SC64 : Mips::SC);
1074 } 1143 }
1144
1075 AND = Mips::AND; 1145 AND = Mips::AND;
1076 NOR = Mips::NOR; 1146 NOR = Mips::NOR;
1077 ZERO = Mips::ZERO; 1147 ZERO = Mips::ZERO;
1078 BEQ = Mips::BEQ; 1148 BEQ = Mips::BEQ;
1079 } else { 1149 } else {
1083 NOR = Mips::NOR64; 1153 NOR = Mips::NOR64;
1084 ZERO = Mips::ZERO_64; 1154 ZERO = Mips::ZERO_64;
1085 BEQ = Mips::BEQ64; 1155 BEQ = Mips::BEQ64;
1086 } 1156 }
1087 1157
1088 unsigned OldVal = MI->getOperand(0).getReg(); 1158 unsigned OldVal = MI.getOperand(0).getReg();
1089 unsigned Ptr = MI->getOperand(1).getReg(); 1159 unsigned Ptr = MI.getOperand(1).getReg();
1090 unsigned Incr = MI->getOperand(2).getReg(); 1160 unsigned Incr = MI.getOperand(2).getReg();
1091 1161
1092 unsigned StoreVal = RegInfo.createVirtualRegister(RC); 1162 unsigned StoreVal = RegInfo.createVirtualRegister(RC);
1093 unsigned AndRes = RegInfo.createVirtualRegister(RC); 1163 unsigned AndRes = RegInfo.createVirtualRegister(RC);
1094 unsigned Success = RegInfo.createVirtualRegister(RC); 1164 unsigned Success = RegInfo.createVirtualRegister(RC);
1095 1165
1132 StoreVal = Incr; 1202 StoreVal = Incr;
1133 } 1203 }
1134 BuildMI(BB, DL, TII->get(SC), Success).addReg(StoreVal).addReg(Ptr).addImm(0); 1204 BuildMI(BB, DL, TII->get(SC), Success).addReg(StoreVal).addReg(Ptr).addImm(0);
1135 BuildMI(BB, DL, TII->get(BEQ)).addReg(Success).addReg(ZERO).addMBB(loopMBB); 1205 BuildMI(BB, DL, TII->get(BEQ)).addReg(Success).addReg(ZERO).addMBB(loopMBB);
1136 1206
1137 MI->eraseFromParent(); // The instruction is gone now. 1207 MI.eraseFromParent(); // The instruction is gone now.
1138 1208
1139 return exitMBB; 1209 return exitMBB;
1140 } 1210 }
1141 1211
1142 MachineBasicBlock *MipsTargetLowering::emitSignExtendToI32InReg( 1212 MachineBasicBlock *MipsTargetLowering::emitSignExtendToI32InReg(
1143 MachineInstr *MI, MachineBasicBlock *BB, unsigned Size, unsigned DstReg, 1213 MachineInstr &MI, MachineBasicBlock *BB, unsigned Size, unsigned DstReg,
1144 unsigned SrcReg) const { 1214 unsigned SrcReg) const {
1145 const TargetInstrInfo *TII = Subtarget.getInstrInfo(); 1215 const TargetInstrInfo *TII = Subtarget.getInstrInfo();
1146 DebugLoc DL = MI->getDebugLoc(); 1216 const DebugLoc &DL = MI.getDebugLoc();
1147 1217
1148 if (Subtarget.hasMips32r2() && Size == 1) { 1218 if (Subtarget.hasMips32r2() && Size == 1) {
1149 BuildMI(BB, DL, TII->get(Mips::SEB), DstReg).addReg(SrcReg); 1219 BuildMI(BB, DL, TII->get(Mips::SEB), DstReg).addReg(SrcReg);
1150 return BB; 1220 return BB;
1151 } 1221 }
1168 1238
1169 return BB; 1239 return BB;
1170 } 1240 }
1171 1241
1172 MachineBasicBlock *MipsTargetLowering::emitAtomicBinaryPartword( 1242 MachineBasicBlock *MipsTargetLowering::emitAtomicBinaryPartword(
1173 MachineInstr *MI, MachineBasicBlock *BB, unsigned Size, unsigned BinOpcode, 1243 MachineInstr &MI, MachineBasicBlock *BB, unsigned Size, unsigned BinOpcode,
1174 bool Nand) const { 1244 bool Nand) const {
1175 assert((Size == 1 || Size == 2) && 1245 assert((Size == 1 || Size == 2) &&
1176 "Unsupported size for EmitAtomicBinaryPartial."); 1246 "Unsupported size for EmitAtomicBinaryPartial.");
1177 1247
1178 MachineFunction *MF = BB->getParent(); 1248 MachineFunction *MF = BB->getParent();
1179 MachineRegisterInfo &RegInfo = MF->getRegInfo(); 1249 MachineRegisterInfo &RegInfo = MF->getRegInfo();
1180 const TargetRegisterClass *RC = getRegClassFor(MVT::i32); 1250 const TargetRegisterClass *RC = getRegClassFor(MVT::i32);
1251 const bool ArePtrs64bit = ABI.ArePtrs64bit();
1252 const TargetRegisterClass *RCp =
1253 getRegClassFor(ArePtrs64bit ? MVT::i64 : MVT::i32);
1181 const TargetInstrInfo *TII = Subtarget.getInstrInfo(); 1254 const TargetInstrInfo *TII = Subtarget.getInstrInfo();
1182 DebugLoc DL = MI->getDebugLoc(); 1255 DebugLoc DL = MI.getDebugLoc();
1183 1256
1184 unsigned Dest = MI->getOperand(0).getReg(); 1257 unsigned Dest = MI.getOperand(0).getReg();
1185 unsigned Ptr = MI->getOperand(1).getReg(); 1258 unsigned Ptr = MI.getOperand(1).getReg();
1186 unsigned Incr = MI->getOperand(2).getReg(); 1259 unsigned Incr = MI.getOperand(2).getReg();
1187 1260
1188 unsigned AlignedAddr = RegInfo.createVirtualRegister(RC); 1261 unsigned AlignedAddr = RegInfo.createVirtualRegister(RCp);
1189 unsigned ShiftAmt = RegInfo.createVirtualRegister(RC); 1262 unsigned ShiftAmt = RegInfo.createVirtualRegister(RC);
1190 unsigned Mask = RegInfo.createVirtualRegister(RC); 1263 unsigned Mask = RegInfo.createVirtualRegister(RC);
1191 unsigned Mask2 = RegInfo.createVirtualRegister(RC); 1264 unsigned Mask2 = RegInfo.createVirtualRegister(RC);
1192 unsigned NewVal = RegInfo.createVirtualRegister(RC); 1265 unsigned NewVal = RegInfo.createVirtualRegister(RC);
1193 unsigned OldVal = RegInfo.createVirtualRegister(RC); 1266 unsigned OldVal = RegInfo.createVirtualRegister(RC);
1194 unsigned Incr2 = RegInfo.createVirtualRegister(RC); 1267 unsigned Incr2 = RegInfo.createVirtualRegister(RC);
1195 unsigned MaskLSB2 = RegInfo.createVirtualRegister(RC); 1268 unsigned MaskLSB2 = RegInfo.createVirtualRegister(RCp);
1196 unsigned PtrLSB2 = RegInfo.createVirtualRegister(RC); 1269 unsigned PtrLSB2 = RegInfo.createVirtualRegister(RC);
1197 unsigned MaskUpper = RegInfo.createVirtualRegister(RC); 1270 unsigned MaskUpper = RegInfo.createVirtualRegister(RC);
1198 unsigned AndRes = RegInfo.createVirtualRegister(RC); 1271 unsigned AndRes = RegInfo.createVirtualRegister(RC);
1199 unsigned BinOpRes = RegInfo.createVirtualRegister(RC); 1272 unsigned BinOpRes = RegInfo.createVirtualRegister(RC);
1200 unsigned MaskedOldVal0 = RegInfo.createVirtualRegister(RC); 1273 unsigned MaskedOldVal0 = RegInfo.createVirtualRegister(RC);
1201 unsigned StoreVal = RegInfo.createVirtualRegister(RC); 1274 unsigned StoreVal = RegInfo.createVirtualRegister(RC);
1202 unsigned MaskedOldVal1 = RegInfo.createVirtualRegister(RC); 1275 unsigned MaskedOldVal1 = RegInfo.createVirtualRegister(RC);
1203 unsigned SrlRes = RegInfo.createVirtualRegister(RC); 1276 unsigned SrlRes = RegInfo.createVirtualRegister(RC);
1204 unsigned Success = RegInfo.createVirtualRegister(RC); 1277 unsigned Success = RegInfo.createVirtualRegister(RC);
1205 1278
1279 unsigned LL, SC;
1280 if (isMicroMips) {
1281 LL = Mips::LL_MM;
1282 SC = Mips::SC_MM;
1283 } else {
1284 LL = Subtarget.hasMips32r6() ? (ArePtrs64bit ? Mips::LL64_R6 : Mips::LL_R6)
1285 : (ArePtrs64bit ? Mips::LL64 : Mips::LL);
1286 SC = Subtarget.hasMips32r6() ? (ArePtrs64bit ? Mips::SC64_R6 : Mips::SC_R6)
1287 : (ArePtrs64bit ? Mips::SC64 : Mips::SC);
1288 }
1289
1206 // insert new blocks after the current block 1290 // insert new blocks after the current block
1207 const BasicBlock *LLVM_BB = BB->getBasicBlock(); 1291 const BasicBlock *LLVM_BB = BB->getBasicBlock();
1208 MachineBasicBlock *loopMBB = MF->CreateMachineBasicBlock(LLVM_BB); 1292 MachineBasicBlock *loopMBB = MF->CreateMachineBasicBlock(LLVM_BB);
1209 MachineBasicBlock *sinkMBB = MF->CreateMachineBasicBlock(LLVM_BB); 1293 MachineBasicBlock *sinkMBB = MF->CreateMachineBasicBlock(LLVM_BB);
1210 MachineBasicBlock *exitMBB = MF->CreateMachineBasicBlock(LLVM_BB); 1294 MachineBasicBlock *exitMBB = MF->CreateMachineBasicBlock(LLVM_BB);
1232 // sll mask,maskupper,shiftamt 1316 // sll mask,maskupper,shiftamt
1233 // nor mask2,$0,mask 1317 // nor mask2,$0,mask
1234 // sll incr2,incr,shiftamt 1318 // sll incr2,incr,shiftamt
1235 1319
1236 int64_t MaskImm = (Size == 1) ? 255 : 65535; 1320 int64_t MaskImm = (Size == 1) ? 255 : 65535;
1237 BuildMI(BB, DL, TII->get(Mips::ADDiu), MaskLSB2) 1321 BuildMI(BB, DL, TII->get(ABI.GetPtrAddiuOp()), MaskLSB2)
1238 .addReg(Mips::ZERO).addImm(-4); 1322 .addReg(ABI.GetNullPtr()).addImm(-4);
1239 BuildMI(BB, DL, TII->get(Mips::AND), AlignedAddr) 1323 BuildMI(BB, DL, TII->get(ABI.GetPtrAndOp()), AlignedAddr)
1240 .addReg(Ptr).addReg(MaskLSB2); 1324 .addReg(Ptr).addReg(MaskLSB2);
1241 BuildMI(BB, DL, TII->get(Mips::ANDi), PtrLSB2).addReg(Ptr).addImm(3); 1325 BuildMI(BB, DL, TII->get(Mips::ANDi), PtrLSB2)
1326 .addReg(Ptr, 0, ArePtrs64bit ? Mips::sub_32 : 0).addImm(3);
1242 if (Subtarget.isLittle()) { 1327 if (Subtarget.isLittle()) {
1243 BuildMI(BB, DL, TII->get(Mips::SLL), ShiftAmt).addReg(PtrLSB2).addImm(3); 1328 BuildMI(BB, DL, TII->get(Mips::SLL), ShiftAmt).addReg(PtrLSB2).addImm(3);
1244 } else { 1329 } else {
1245 unsigned Off = RegInfo.createVirtualRegister(RC); 1330 unsigned Off = RegInfo.createVirtualRegister(RC);
1246 BuildMI(BB, DL, TII->get(Mips::XORi), Off) 1331 BuildMI(BB, DL, TII->get(Mips::XORi), Off)
1272 // or storeval,maskedoldval0,newval 1357 // or storeval,maskedoldval0,newval
1273 // sc success,storeval,0(alignedaddr) 1358 // sc success,storeval,0(alignedaddr)
1274 // beq success,$0,loopMBB 1359 // beq success,$0,loopMBB
1275 1360
1276 BB = loopMBB; 1361 BB = loopMBB;
1277 unsigned LL = isMicroMips ? Mips::LL_MM : Mips::LL;
1278 BuildMI(BB, DL, TII->get(LL), OldVal).addReg(AlignedAddr).addImm(0); 1362 BuildMI(BB, DL, TII->get(LL), OldVal).addReg(AlignedAddr).addImm(0);
1279 if (Nand) { 1363 if (Nand) {
1280 // and andres, oldval, incr2 1364 // and andres, oldval, incr2
1281 // nor binopres, $0, andres 1365 // nor binopres, $0, andres
1282 // and newval, binopres, mask 1366 // and newval, binopres, mask
1296 1380
1297 BuildMI(BB, DL, TII->get(Mips::AND), MaskedOldVal0) 1381 BuildMI(BB, DL, TII->get(Mips::AND), MaskedOldVal0)
1298 .addReg(OldVal).addReg(Mask2); 1382 .addReg(OldVal).addReg(Mask2);
1299 BuildMI(BB, DL, TII->get(Mips::OR), StoreVal) 1383 BuildMI(BB, DL, TII->get(Mips::OR), StoreVal)
1300 .addReg(MaskedOldVal0).addReg(NewVal); 1384 .addReg(MaskedOldVal0).addReg(NewVal);
1301 unsigned SC = isMicroMips ? Mips::SC_MM : Mips::SC;
1302 BuildMI(BB, DL, TII->get(SC), Success) 1385 BuildMI(BB, DL, TII->get(SC), Success)
1303 .addReg(StoreVal).addReg(AlignedAddr).addImm(0); 1386 .addReg(StoreVal).addReg(AlignedAddr).addImm(0);
1304 BuildMI(BB, DL, TII->get(Mips::BEQ)) 1387 BuildMI(BB, DL, TII->get(Mips::BEQ))
1305 .addReg(Success).addReg(Mips::ZERO).addMBB(loopMBB); 1388 .addReg(Success).addReg(Mips::ZERO).addMBB(loopMBB);
1306 1389
1314 .addReg(OldVal).addReg(Mask); 1397 .addReg(OldVal).addReg(Mask);
1315 BuildMI(BB, DL, TII->get(Mips::SRLV), SrlRes) 1398 BuildMI(BB, DL, TII->get(Mips::SRLV), SrlRes)
1316 .addReg(MaskedOldVal1).addReg(ShiftAmt); 1399 .addReg(MaskedOldVal1).addReg(ShiftAmt);
1317 BB = emitSignExtendToI32InReg(MI, BB, Size, Dest, SrlRes); 1400 BB = emitSignExtendToI32InReg(MI, BB, Size, Dest, SrlRes);
1318 1401
1319 MI->eraseFromParent(); // The instruction is gone now. 1402 MI.eraseFromParent(); // The instruction is gone now.
1320 1403
1321 return exitMBB; 1404 return exitMBB;
1322 } 1405 }
1323 1406
1324 MachineBasicBlock * MipsTargetLowering::emitAtomicCmpSwap(MachineInstr *MI, 1407 MachineBasicBlock *MipsTargetLowering::emitAtomicCmpSwap(MachineInstr &MI,
1325 MachineBasicBlock *BB, 1408 MachineBasicBlock *BB,
1326 unsigned Size) const { 1409 unsigned Size) const {
1327 assert((Size == 4 || Size == 8) && "Unsupported size for EmitAtomicCmpSwap."); 1410 assert((Size == 4 || Size == 8) && "Unsupported size for EmitAtomicCmpSwap.");
1328 1411
1329 MachineFunction *MF = BB->getParent(); 1412 MachineFunction *MF = BB->getParent();
1330 MachineRegisterInfo &RegInfo = MF->getRegInfo(); 1413 MachineRegisterInfo &RegInfo = MF->getRegInfo();
1331 const TargetRegisterClass *RC = getRegClassFor(MVT::getIntegerVT(Size * 8)); 1414 const TargetRegisterClass *RC = getRegClassFor(MVT::getIntegerVT(Size * 8));
1332 const TargetInstrInfo *TII = Subtarget.getInstrInfo(); 1415 const TargetInstrInfo *TII = Subtarget.getInstrInfo();
1333 DebugLoc DL = MI->getDebugLoc(); 1416 const bool ArePtrs64bit = ABI.ArePtrs64bit();
1417 DebugLoc DL = MI.getDebugLoc();
1334 unsigned LL, SC, ZERO, BNE, BEQ; 1418 unsigned LL, SC, ZERO, BNE, BEQ;
1335 1419
1336 if (Size == 4) { 1420 if (Size == 4) {
1337 if (isMicroMips) { 1421 if (isMicroMips) {
1338 LL = Mips::LL_MM; 1422 LL = Mips::LL_MM;
1339 SC = Mips::SC_MM; 1423 SC = Mips::SC_MM;
1340 } else { 1424 } else {
1341 LL = Subtarget.hasMips32r6() ? Mips::LL_R6 : Mips::LL; 1425 LL = Subtarget.hasMips32r6()
1342 SC = Subtarget.hasMips32r6() ? Mips::SC_R6 : Mips::SC; 1426 ? (ArePtrs64bit ? Mips::LL64_R6 : Mips::LL_R6)
1343 } 1427 : (ArePtrs64bit ? Mips::LL64 : Mips::LL);
1428 SC = Subtarget.hasMips32r6()
1429 ? (ArePtrs64bit ? Mips::SC64_R6 : Mips::SC_R6)
1430 : (ArePtrs64bit ? Mips::SC64 : Mips::SC);
1431 }
1432
1344 ZERO = Mips::ZERO; 1433 ZERO = Mips::ZERO;
1345 BNE = Mips::BNE; 1434 BNE = Mips::BNE;
1346 BEQ = Mips::BEQ; 1435 BEQ = Mips::BEQ;
1347 } else { 1436 } else {
1348 LL = Subtarget.hasMips64r6() ? Mips::LLD_R6 : Mips::LLD; 1437 LL = Subtarget.hasMips64r6() ? Mips::LLD_R6 : Mips::LLD;
1350 ZERO = Mips::ZERO_64; 1439 ZERO = Mips::ZERO_64;
1351 BNE = Mips::BNE64; 1440 BNE = Mips::BNE64;
1352 BEQ = Mips::BEQ64; 1441 BEQ = Mips::BEQ64;
1353 } 1442 }
1354 1443
1355 unsigned Dest = MI->getOperand(0).getReg(); 1444 unsigned Dest = MI.getOperand(0).getReg();
1356 unsigned Ptr = MI->getOperand(1).getReg(); 1445 unsigned Ptr = MI.getOperand(1).getReg();
1357 unsigned OldVal = MI->getOperand(2).getReg(); 1446 unsigned OldVal = MI.getOperand(2).getReg();
1358 unsigned NewVal = MI->getOperand(3).getReg(); 1447 unsigned NewVal = MI.getOperand(3).getReg();
1359 1448
1360 unsigned Success = RegInfo.createVirtualRegister(RC); 1449 unsigned Success = RegInfo.createVirtualRegister(RC);
1361 1450
1362 // insert new blocks after the current block 1451 // insert new blocks after the current block
1363 const BasicBlock *LLVM_BB = BB->getBasicBlock(); 1452 const BasicBlock *LLVM_BB = BB->getBasicBlock();
1398 BuildMI(BB, DL, TII->get(SC), Success) 1487 BuildMI(BB, DL, TII->get(SC), Success)
1399 .addReg(NewVal).addReg(Ptr).addImm(0); 1488 .addReg(NewVal).addReg(Ptr).addImm(0);
1400 BuildMI(BB, DL, TII->get(BEQ)) 1489 BuildMI(BB, DL, TII->get(BEQ))
1401 .addReg(Success).addReg(ZERO).addMBB(loop1MBB); 1490 .addReg(Success).addReg(ZERO).addMBB(loop1MBB);
1402 1491
1403 MI->eraseFromParent(); // The instruction is gone now. 1492 MI.eraseFromParent(); // The instruction is gone now.
1404 1493
1405 return exitMBB; 1494 return exitMBB;
1406 } 1495 }
1407 1496
1408 MachineBasicBlock * 1497 MachineBasicBlock *MipsTargetLowering::emitAtomicCmpSwapPartword(
1409 MipsTargetLowering::emitAtomicCmpSwapPartword(MachineInstr *MI, 1498 MachineInstr &MI, MachineBasicBlock *BB, unsigned Size) const {
1410 MachineBasicBlock *BB,
1411 unsigned Size) const {
1412 assert((Size == 1 || Size == 2) && 1499 assert((Size == 1 || Size == 2) &&
1413 "Unsupported size for EmitAtomicCmpSwapPartial."); 1500 "Unsupported size for EmitAtomicCmpSwapPartial.");
1414 1501
1415 MachineFunction *MF = BB->getParent(); 1502 MachineFunction *MF = BB->getParent();
1416 MachineRegisterInfo &RegInfo = MF->getRegInfo(); 1503 MachineRegisterInfo &RegInfo = MF->getRegInfo();
1417 const TargetRegisterClass *RC = getRegClassFor(MVT::i32); 1504 const TargetRegisterClass *RC = getRegClassFor(MVT::i32);
1505 const bool ArePtrs64bit = ABI.ArePtrs64bit();
1506 const TargetRegisterClass *RCp =
1507 getRegClassFor(ArePtrs64bit ? MVT::i64 : MVT::i32);
1418 const TargetInstrInfo *TII = Subtarget.getInstrInfo(); 1508 const TargetInstrInfo *TII = Subtarget.getInstrInfo();
1419 DebugLoc DL = MI->getDebugLoc(); 1509 DebugLoc DL = MI.getDebugLoc();
1420 1510
1421 unsigned Dest = MI->getOperand(0).getReg(); 1511 unsigned Dest = MI.getOperand(0).getReg();
1422 unsigned Ptr = MI->getOperand(1).getReg(); 1512 unsigned Ptr = MI.getOperand(1).getReg();
1423 unsigned CmpVal = MI->getOperand(2).getReg(); 1513 unsigned CmpVal = MI.getOperand(2).getReg();
1424 unsigned NewVal = MI->getOperand(3).getReg(); 1514 unsigned NewVal = MI.getOperand(3).getReg();
1425 1515
1426 unsigned AlignedAddr = RegInfo.createVirtualRegister(RC); 1516 unsigned AlignedAddr = RegInfo.createVirtualRegister(RCp);
1427 unsigned ShiftAmt = RegInfo.createVirtualRegister(RC); 1517 unsigned ShiftAmt = RegInfo.createVirtualRegister(RC);
1428 unsigned Mask = RegInfo.createVirtualRegister(RC); 1518 unsigned Mask = RegInfo.createVirtualRegister(RC);
1429 unsigned Mask2 = RegInfo.createVirtualRegister(RC); 1519 unsigned Mask2 = RegInfo.createVirtualRegister(RC);
1430 unsigned ShiftedCmpVal = RegInfo.createVirtualRegister(RC); 1520 unsigned ShiftedCmpVal = RegInfo.createVirtualRegister(RC);
1431 unsigned OldVal = RegInfo.createVirtualRegister(RC); 1521 unsigned OldVal = RegInfo.createVirtualRegister(RC);
1432 unsigned MaskedOldVal0 = RegInfo.createVirtualRegister(RC); 1522 unsigned MaskedOldVal0 = RegInfo.createVirtualRegister(RC);
1433 unsigned ShiftedNewVal = RegInfo.createVirtualRegister(RC); 1523 unsigned ShiftedNewVal = RegInfo.createVirtualRegister(RC);
1434 unsigned MaskLSB2 = RegInfo.createVirtualRegister(RC); 1524 unsigned MaskLSB2 = RegInfo.createVirtualRegister(RCp);
1435 unsigned PtrLSB2 = RegInfo.createVirtualRegister(RC); 1525 unsigned PtrLSB2 = RegInfo.createVirtualRegister(RC);
1436 unsigned MaskUpper = RegInfo.createVirtualRegister(RC); 1526 unsigned MaskUpper = RegInfo.createVirtualRegister(RC);
1437 unsigned MaskedCmpVal = RegInfo.createVirtualRegister(RC); 1527 unsigned MaskedCmpVal = RegInfo.createVirtualRegister(RC);
1438 unsigned MaskedNewVal = RegInfo.createVirtualRegister(RC); 1528 unsigned MaskedNewVal = RegInfo.createVirtualRegister(RC);
1439 unsigned MaskedOldVal1 = RegInfo.createVirtualRegister(RC); 1529 unsigned MaskedOldVal1 = RegInfo.createVirtualRegister(RC);
1440 unsigned StoreVal = RegInfo.createVirtualRegister(RC); 1530 unsigned StoreVal = RegInfo.createVirtualRegister(RC);
1441 unsigned SrlRes = RegInfo.createVirtualRegister(RC); 1531 unsigned SrlRes = RegInfo.createVirtualRegister(RC);
1442 unsigned Success = RegInfo.createVirtualRegister(RC); 1532 unsigned Success = RegInfo.createVirtualRegister(RC);
1533 unsigned LL, SC;
1534
1535 if (isMicroMips) {
1536 LL = Mips::LL_MM;
1537 SC = Mips::SC_MM;
1538 } else {
1539 LL = Subtarget.hasMips32r6() ? (ArePtrs64bit ? Mips::LL64_R6 : Mips::LL_R6)
1540 : (ArePtrs64bit ? Mips::LL64 : Mips::LL);
1541 SC = Subtarget.hasMips32r6() ? (ArePtrs64bit ? Mips::SC64_R6 : Mips::SC_R6)
1542 : (ArePtrs64bit ? Mips::SC64 : Mips::SC);
1543 }
1443 1544
1444 // insert new blocks after the current block 1545 // insert new blocks after the current block
1445 const BasicBlock *LLVM_BB = BB->getBasicBlock(); 1546 const BasicBlock *LLVM_BB = BB->getBasicBlock();
1446 MachineBasicBlock *loop1MBB = MF->CreateMachineBasicBlock(LLVM_BB); 1547 MachineBasicBlock *loop1MBB = MF->CreateMachineBasicBlock(LLVM_BB);
1447 MachineBasicBlock *loop2MBB = MF->CreateMachineBasicBlock(LLVM_BB); 1548 MachineBasicBlock *loop2MBB = MF->CreateMachineBasicBlock(LLVM_BB);
1468 // FIXME: computation of newval2 can be moved to loop2MBB. 1569 // FIXME: computation of newval2 can be moved to loop2MBB.
1469 // thisMBB: 1570 // thisMBB:
1470 // addiu masklsb2,$0,-4 # 0xfffffffc 1571 // addiu masklsb2,$0,-4 # 0xfffffffc
1471 // and alignedaddr,ptr,masklsb2 1572 // and alignedaddr,ptr,masklsb2
1472 // andi ptrlsb2,ptr,3 1573 // andi ptrlsb2,ptr,3
1574 // xori ptrlsb2,ptrlsb2,3 # Only for BE
1473 // sll shiftamt,ptrlsb2,3 1575 // sll shiftamt,ptrlsb2,3
1474 // ori maskupper,$0,255 # 0xff 1576 // ori maskupper,$0,255 # 0xff
1475 // sll mask,maskupper,shiftamt 1577 // sll mask,maskupper,shiftamt
1476 // nor mask2,$0,mask 1578 // nor mask2,$0,mask
1477 // andi maskedcmpval,cmpval,255 1579 // andi maskedcmpval,cmpval,255
1478 // sll shiftedcmpval,maskedcmpval,shiftamt 1580 // sll shiftedcmpval,maskedcmpval,shiftamt
1479 // andi maskednewval,newval,255 1581 // andi maskednewval,newval,255
1480 // sll shiftednewval,maskednewval,shiftamt 1582 // sll shiftednewval,maskednewval,shiftamt
1481 int64_t MaskImm = (Size == 1) ? 255 : 65535; 1583 int64_t MaskImm = (Size == 1) ? 255 : 65535;
1482 BuildMI(BB, DL, TII->get(Mips::ADDiu), MaskLSB2) 1584 BuildMI(BB, DL, TII->get(ArePtrs64bit ? Mips::DADDiu : Mips::ADDiu), MaskLSB2)
1483 .addReg(Mips::ZERO).addImm(-4); 1585 .addReg(ABI.GetNullPtr()).addImm(-4);
1484 BuildMI(BB, DL, TII->get(Mips::AND), AlignedAddr) 1586 BuildMI(BB, DL, TII->get(ArePtrs64bit ? Mips::AND64 : Mips::AND), AlignedAddr)
1485 .addReg(Ptr).addReg(MaskLSB2); 1587 .addReg(Ptr).addReg(MaskLSB2);
1486 BuildMI(BB, DL, TII->get(Mips::ANDi), PtrLSB2).addReg(Ptr).addImm(3); 1588 BuildMI(BB, DL, TII->get(Mips::ANDi), PtrLSB2)
1589 .addReg(Ptr, 0, ArePtrs64bit ? Mips::sub_32 : 0).addImm(3);
1487 if (Subtarget.isLittle()) { 1590 if (Subtarget.isLittle()) {
1488 BuildMI(BB, DL, TII->get(Mips::SLL), ShiftAmt).addReg(PtrLSB2).addImm(3); 1591 BuildMI(BB, DL, TII->get(Mips::SLL), ShiftAmt).addReg(PtrLSB2).addImm(3);
1489 } else { 1592 } else {
1490 unsigned Off = RegInfo.createVirtualRegister(RC); 1593 unsigned Off = RegInfo.createVirtualRegister(RC);
1491 BuildMI(BB, DL, TII->get(Mips::XORi), Off) 1594 BuildMI(BB, DL, TII->get(Mips::XORi), Off)
1509 // loop1MBB: 1612 // loop1MBB:
1510 // ll oldval,0(alginedaddr) 1613 // ll oldval,0(alginedaddr)
1511 // and maskedoldval0,oldval,mask 1614 // and maskedoldval0,oldval,mask
1512 // bne maskedoldval0,shiftedcmpval,sinkMBB 1615 // bne maskedoldval0,shiftedcmpval,sinkMBB
1513 BB = loop1MBB; 1616 BB = loop1MBB;
1514 unsigned LL = isMicroMips ? Mips::LL_MM : Mips::LL;
1515 BuildMI(BB, DL, TII->get(LL), OldVal).addReg(AlignedAddr).addImm(0); 1617 BuildMI(BB, DL, TII->get(LL), OldVal).addReg(AlignedAddr).addImm(0);
1516 BuildMI(BB, DL, TII->get(Mips::AND), MaskedOldVal0) 1618 BuildMI(BB, DL, TII->get(Mips::AND), MaskedOldVal0)
1517 .addReg(OldVal).addReg(Mask); 1619 .addReg(OldVal).addReg(Mask);
1518 BuildMI(BB, DL, TII->get(Mips::BNE)) 1620 BuildMI(BB, DL, TII->get(Mips::BNE))
1519 .addReg(MaskedOldVal0).addReg(ShiftedCmpVal).addMBB(sinkMBB); 1621 .addReg(MaskedOldVal0).addReg(ShiftedCmpVal).addMBB(sinkMBB);
1526 BB = loop2MBB; 1628 BB = loop2MBB;
1527 BuildMI(BB, DL, TII->get(Mips::AND), MaskedOldVal1) 1629 BuildMI(BB, DL, TII->get(Mips::AND), MaskedOldVal1)
1528 .addReg(OldVal).addReg(Mask2); 1630 .addReg(OldVal).addReg(Mask2);
1529 BuildMI(BB, DL, TII->get(Mips::OR), StoreVal) 1631 BuildMI(BB, DL, TII->get(Mips::OR), StoreVal)
1530 .addReg(MaskedOldVal1).addReg(ShiftedNewVal); 1632 .addReg(MaskedOldVal1).addReg(ShiftedNewVal);
1531 unsigned SC = isMicroMips ? Mips::SC_MM : Mips::SC;
1532 BuildMI(BB, DL, TII->get(SC), Success) 1633 BuildMI(BB, DL, TII->get(SC), Success)
1533 .addReg(StoreVal).addReg(AlignedAddr).addImm(0); 1634 .addReg(StoreVal).addReg(AlignedAddr).addImm(0);
1534 BuildMI(BB, DL, TII->get(Mips::BEQ)) 1635 BuildMI(BB, DL, TII->get(Mips::BEQ))
1535 .addReg(Success).addReg(Mips::ZERO).addMBB(loop1MBB); 1636 .addReg(Success).addReg(Mips::ZERO).addMBB(loop1MBB);
1536 1637
1541 1642
1542 BuildMI(BB, DL, TII->get(Mips::SRLV), SrlRes) 1643 BuildMI(BB, DL, TII->get(Mips::SRLV), SrlRes)
1543 .addReg(MaskedOldVal0).addReg(ShiftAmt); 1644 .addReg(MaskedOldVal0).addReg(ShiftAmt);
1544 BB = emitSignExtendToI32InReg(MI, BB, Size, Dest, SrlRes); 1645 BB = emitSignExtendToI32InReg(MI, BB, Size, Dest, SrlRes);
1545 1646
1546 MI->eraseFromParent(); // The instruction is gone now. 1647 MI.eraseFromParent(); // The instruction is gone now.
1547 1648
1548 return exitMBB; 1649 return exitMBB;
1549 } 1650 }
1550 1651
1551 MachineBasicBlock *MipsTargetLowering::emitSEL_D(MachineInstr *MI, 1652 MachineBasicBlock *MipsTargetLowering::emitSEL_D(MachineInstr &MI,
1552 MachineBasicBlock *BB) const { 1653 MachineBasicBlock *BB) const {
1553 MachineFunction *MF = BB->getParent(); 1654 MachineFunction *MF = BB->getParent();
1554 const TargetRegisterInfo *TRI = Subtarget.getRegisterInfo(); 1655 const TargetRegisterInfo *TRI = Subtarget.getRegisterInfo();
1555 const TargetInstrInfo *TII = Subtarget.getInstrInfo(); 1656 const TargetInstrInfo *TII = Subtarget.getInstrInfo();
1556 MachineRegisterInfo &RegInfo = MF->getRegInfo(); 1657 MachineRegisterInfo &RegInfo = MF->getRegInfo();
1557 DebugLoc DL = MI->getDebugLoc(); 1658 DebugLoc DL = MI.getDebugLoc();
1558 MachineBasicBlock::iterator II(MI); 1659 MachineBasicBlock::iterator II(MI);
1559 1660
1560 unsigned Fc = MI->getOperand(1).getReg(); 1661 unsigned Fc = MI.getOperand(1).getReg();
1561 const auto &FGR64RegClass = TRI->getRegClass(Mips::FGR64RegClassID); 1662 const auto &FGR64RegClass = TRI->getRegClass(Mips::FGR64RegClassID);
1562 1663
1563 unsigned Fc2 = RegInfo.createVirtualRegister(FGR64RegClass); 1664 unsigned Fc2 = RegInfo.createVirtualRegister(FGR64RegClass);
1564 1665
1565 BuildMI(*BB, II, DL, TII->get(Mips::SUBREG_TO_REG), Fc2) 1666 BuildMI(*BB, II, DL, TII->get(Mips::SUBREG_TO_REG), Fc2)
1567 .addReg(Fc) 1668 .addReg(Fc)
1568 .addImm(Mips::sub_lo); 1669 .addImm(Mips::sub_lo);
1569 1670
1570 // We don't erase the original instruction, we just replace the condition 1671 // We don't erase the original instruction, we just replace the condition
1571 // register with the 64-bit super-register. 1672 // register with the 64-bit super-register.
1572 MI->getOperand(1).setReg(Fc2); 1673 MI.getOperand(1).setReg(Fc2);
1573 1674
1574 return BB; 1675 return BB;
1575 }
1576
1577 //===----------------------------------------------------------------------===//
1578 // Misc Lower Operation implementation
1579 //===----------------------------------------------------------------------===//
1580 SDValue MipsTargetLowering::lowerBR_JT(SDValue Op, SelectionDAG &DAG) const {
1581 SDValue Chain = Op.getOperand(0);
1582 SDValue Table = Op.getOperand(1);
1583 SDValue Index = Op.getOperand(2);
1584 SDLoc DL(Op);
1585 auto &TD = DAG.getDataLayout();
1586 EVT PTy = getPointerTy(TD);
1587 unsigned EntrySize =
1588 DAG.getMachineFunction().getJumpTableInfo()->getEntrySize(TD);
1589
1590 Index = DAG.getNode(ISD::MUL, DL, PTy, Index,
1591 DAG.getConstant(EntrySize, DL, PTy));
1592 SDValue Addr = DAG.getNode(ISD::ADD, DL, PTy, Index, Table);
1593
1594 EVT MemVT = EVT::getIntegerVT(*DAG.getContext(), EntrySize * 8);
1595 Addr =
1596 DAG.getExtLoad(ISD::SEXTLOAD, DL, PTy, Chain, Addr,
1597 MachinePointerInfo::getJumpTable(DAG.getMachineFunction()),
1598 MemVT, false, false, false, 0);
1599 Chain = Addr.getValue(1);
1600
1601 if ((getTargetMachine().getRelocationModel() == Reloc::PIC_) || ABI.IsN64()) {
1602 // For PIC, the sequence is:
1603 // BRIND(load(Jumptable + index) + RelocBase)
1604 // RelocBase can be JumpTable, GOT or some sort of global base.
1605 Addr = DAG.getNode(ISD::ADD, DL, PTy, Addr,
1606 getPICJumpTableRelocBase(Table, DAG));
1607 }
1608
1609 return DAG.getNode(ISD::BRIND, DL, MVT::Other, Chain, Addr);
1610 } 1676 }
1611 1677
1612 SDValue MipsTargetLowering::lowerBRCOND(SDValue Op, SelectionDAG &DAG) const { 1678 SDValue MipsTargetLowering::lowerBRCOND(SDValue Op, SelectionDAG &DAG) const {
1613 // The first operand is the chain, the second is the condition, the third is 1679 // The first operand is the chain, the second is the condition, the third is
1614 // the block to branch to if the condition is true. 1680 // the block to branch to if the condition is true.
1665 SelectionDAG &DAG) const { 1731 SelectionDAG &DAG) const {
1666 EVT Ty = Op.getValueType(); 1732 EVT Ty = Op.getValueType();
1667 GlobalAddressSDNode *N = cast<GlobalAddressSDNode>(Op); 1733 GlobalAddressSDNode *N = cast<GlobalAddressSDNode>(Op);
1668 const GlobalValue *GV = N->getGlobal(); 1734 const GlobalValue *GV = N->getGlobal();
1669 1735
1670 if (getTargetMachine().getRelocationModel() != Reloc::PIC_ && !ABI.IsN64()) { 1736 if (!isPositionIndependent() && !ABI.IsN64()) {
1671 const MipsTargetObjectFile *TLOF = 1737 const MipsTargetObjectFile *TLOF =
1672 static_cast<const MipsTargetObjectFile *>( 1738 static_cast<const MipsTargetObjectFile *>(
1673 getTargetMachine().getObjFileLowering()); 1739 getTargetMachine().getObjFileLowering());
1674 if (TLOF->IsGlobalInSmallSection(GV, getTargetMachine())) 1740 const GlobalObject *GO = GV->getBaseObject();
1741 if (GO && TLOF->IsGlobalInSmallSection(GO, getTargetMachine()))
1675 // %gp_rel relocation 1742 // %gp_rel relocation
1676 return getAddrGPRel(N, SDLoc(N), Ty, DAG); 1743 return getAddrGPRel(N, SDLoc(N), Ty, DAG);
1677 1744
1678 // %hi/%lo relocation 1745 // %hi/%lo relocation
1679 return getAddrNonPIC(N, SDLoc(N), Ty, DAG); 1746 return getAddrNonPIC(N, SDLoc(N), Ty, DAG);
1680 } 1747 }
1681 1748
1682 if (GV->hasInternalLinkage() || (GV->hasLocalLinkage() && !isa<Function>(GV))) 1749 // Every other architecture would use shouldAssumeDSOLocal in here, but
1750 // mips is special.
1751 // * In PIC code mips requires got loads even for local statics!
1752 // * To save on got entries, for local statics the got entry contains the
1753 // page and an additional add instruction takes care of the low bits.
1754 // * It is legal to access a hidden symbol with a non hidden undefined,
1755 // so one cannot guarantee that all access to a hidden symbol will know
1756 // it is hidden.
1757 // * Mips linkers don't support creating a page and a full got entry for
1758 // the same symbol.
1759 // * Given all that, we have to use a full got entry for hidden symbols :-(
1760 if (GV->hasLocalLinkage())
1683 return getAddrLocal(N, SDLoc(N), Ty, DAG, ABI.IsN32() || ABI.IsN64()); 1761 return getAddrLocal(N, SDLoc(N), Ty, DAG, ABI.IsN32() || ABI.IsN64());
1684 1762
1685 if (LargeGOT) 1763 if (LargeGOT)
1686 return getAddrGlobalLargeGOT( 1764 return getAddrGlobalLargeGOT(
1687 N, SDLoc(N), Ty, DAG, MipsII::MO_GOT_HI16, MipsII::MO_GOT_LO16, 1765 N, SDLoc(N), Ty, DAG, MipsII::MO_GOT_HI16, MipsII::MO_GOT_LO16,
1688 DAG.getEntryNode(), 1766 DAG.getEntryNode(),
1689 MachinePointerInfo::getGOT(DAG.getMachineFunction())); 1767 MachinePointerInfo::getGOT(DAG.getMachineFunction()));
1690 1768
1691 return getAddrGlobal( 1769 return getAddrGlobal(
1692 N, SDLoc(N), Ty, DAG, 1770 N, SDLoc(N), Ty, DAG,
1693 (ABI.IsN32() || ABI.IsN64()) ? MipsII::MO_GOT_DISP : MipsII::MO_GOT16, 1771 (ABI.IsN32() || ABI.IsN64()) ? MipsII::MO_GOT_DISP : MipsII::MO_GOT,
1694 DAG.getEntryNode(), MachinePointerInfo::getGOT(DAG.getMachineFunction())); 1772 DAG.getEntryNode(), MachinePointerInfo::getGOT(DAG.getMachineFunction()));
1695 } 1773 }
1696 1774
1697 SDValue MipsTargetLowering::lowerBlockAddress(SDValue Op, 1775 SDValue MipsTargetLowering::lowerBlockAddress(SDValue Op,
1698 SelectionDAG &DAG) const { 1776 SelectionDAG &DAG) const {
1699 BlockAddressSDNode *N = cast<BlockAddressSDNode>(Op); 1777 BlockAddressSDNode *N = cast<BlockAddressSDNode>(Op);
1700 EVT Ty = Op.getValueType(); 1778 EVT Ty = Op.getValueType();
1701 1779
1702 if (getTargetMachine().getRelocationModel() != Reloc::PIC_ && !ABI.IsN64()) 1780 if (!isPositionIndependent() && !ABI.IsN64())
1703 return getAddrNonPIC(N, SDLoc(N), Ty, DAG); 1781 return getAddrNonPIC(N, SDLoc(N), Ty, DAG);
1704 1782
1705 return getAddrLocal(N, SDLoc(N), Ty, DAG, ABI.IsN32() || ABI.IsN64()); 1783 return getAddrLocal(N, SDLoc(N), Ty, DAG, ABI.IsN32() || ABI.IsN64());
1706 } 1784 }
1707 1785
1741 Entry.Ty = PtrTy; 1819 Entry.Ty = PtrTy;
1742 Args.push_back(Entry); 1820 Args.push_back(Entry);
1743 1821
1744 TargetLowering::CallLoweringInfo CLI(DAG); 1822 TargetLowering::CallLoweringInfo CLI(DAG);
1745 CLI.setDebugLoc(DL).setChain(DAG.getEntryNode()) 1823 CLI.setDebugLoc(DL).setChain(DAG.getEntryNode())
1746 .setCallee(CallingConv::C, PtrTy, TlsGetAddr, std::move(Args), 0); 1824 .setCallee(CallingConv::C, PtrTy, TlsGetAddr, std::move(Args));
1747 std::pair<SDValue, SDValue> CallResult = LowerCallTo(CLI); 1825 std::pair<SDValue, SDValue> CallResult = LowerCallTo(CLI);
1748 1826
1749 SDValue Ret = CallResult.first; 1827 SDValue Ret = CallResult.first;
1750 1828
1751 if (model != TLSModel::LocalDynamic) 1829 if (model != TLSModel::LocalDynamic)
1766 // Initial Exec TLS Model 1844 // Initial Exec TLS Model
1767 SDValue TGA = DAG.getTargetGlobalAddress(GV, DL, PtrVT, 0, 1845 SDValue TGA = DAG.getTargetGlobalAddress(GV, DL, PtrVT, 0,
1768 MipsII::MO_GOTTPREL); 1846 MipsII::MO_GOTTPREL);
1769 TGA = DAG.getNode(MipsISD::Wrapper, DL, PtrVT, getGlobalReg(DAG, PtrVT), 1847 TGA = DAG.getNode(MipsISD::Wrapper, DL, PtrVT, getGlobalReg(DAG, PtrVT),
1770 TGA); 1848 TGA);
1771 Offset = DAG.getLoad(PtrVT, DL, 1849 Offset =
1772 DAG.getEntryNode(), TGA, MachinePointerInfo(), 1850 DAG.getLoad(PtrVT, DL, DAG.getEntryNode(), TGA, MachinePointerInfo());
1773 false, false, false, 0);
1774 } else { 1851 } else {
1775 // Local Exec TLS Model 1852 // Local Exec TLS Model
1776 assert(model == TLSModel::LocalExec); 1853 assert(model == TLSModel::LocalExec);
1777 SDValue TGAHi = DAG.getTargetGlobalAddress(GV, DL, PtrVT, 0, 1854 SDValue TGAHi = DAG.getTargetGlobalAddress(GV, DL, PtrVT, 0,
1778 MipsII::MO_TPREL_HI); 1855 MipsII::MO_TPREL_HI);
1791 lowerJumpTable(SDValue Op, SelectionDAG &DAG) const 1868 lowerJumpTable(SDValue Op, SelectionDAG &DAG) const
1792 { 1869 {
1793 JumpTableSDNode *N = cast<JumpTableSDNode>(Op); 1870 JumpTableSDNode *N = cast<JumpTableSDNode>(Op);
1794 EVT Ty = Op.getValueType(); 1871 EVT Ty = Op.getValueType();
1795 1872
1796 if (getTargetMachine().getRelocationModel() != Reloc::PIC_ && !ABI.IsN64()) 1873 if (!isPositionIndependent() && !ABI.IsN64())
1797 return getAddrNonPIC(N, SDLoc(N), Ty, DAG); 1874 return getAddrNonPIC(N, SDLoc(N), Ty, DAG);
1798 1875
1799 return getAddrLocal(N, SDLoc(N), Ty, DAG, ABI.IsN32() || ABI.IsN64()); 1876 return getAddrLocal(N, SDLoc(N), Ty, DAG, ABI.IsN32() || ABI.IsN64());
1800 } 1877 }
1801 1878
1803 lowerConstantPool(SDValue Op, SelectionDAG &DAG) const 1880 lowerConstantPool(SDValue Op, SelectionDAG &DAG) const
1804 { 1881 {
1805 ConstantPoolSDNode *N = cast<ConstantPoolSDNode>(Op); 1882 ConstantPoolSDNode *N = cast<ConstantPoolSDNode>(Op);
1806 EVT Ty = Op.getValueType(); 1883 EVT Ty = Op.getValueType();
1807 1884
1808 if (getTargetMachine().getRelocationModel() != Reloc::PIC_ && !ABI.IsN64()) { 1885 if (!isPositionIndependent() && !ABI.IsN64()) {
1809 const MipsTargetObjectFile *TLOF = 1886 const MipsTargetObjectFile *TLOF =
1810 static_cast<const MipsTargetObjectFile *>( 1887 static_cast<const MipsTargetObjectFile *>(
1811 getTargetMachine().getObjFileLowering()); 1888 getTargetMachine().getObjFileLowering());
1812 1889
1813 if (TLOF->IsConstantInSmallSection(DAG.getDataLayout(), N->getConstVal(), 1890 if (TLOF->IsConstantInSmallSection(DAG.getDataLayout(), N->getConstVal(),
1831 1908
1832 // vastart just stores the address of the VarArgsFrameIndex slot into the 1909 // vastart just stores the address of the VarArgsFrameIndex slot into the
1833 // memory location argument. 1910 // memory location argument.
1834 const Value *SV = cast<SrcValueSDNode>(Op.getOperand(2))->getValue(); 1911 const Value *SV = cast<SrcValueSDNode>(Op.getOperand(2))->getValue();
1835 return DAG.getStore(Op.getOperand(0), DL, FI, Op.getOperand(1), 1912 return DAG.getStore(Op.getOperand(0), DL, FI, Op.getOperand(1),
1836 MachinePointerInfo(SV), false, false, 0); 1913 MachinePointerInfo(SV));
1837 } 1914 }
1838 1915
1839 SDValue MipsTargetLowering::lowerVAARG(SDValue Op, SelectionDAG &DAG) const { 1916 SDValue MipsTargetLowering::lowerVAARG(SDValue Op, SelectionDAG &DAG) const {
1840 SDNode *Node = Op.getNode(); 1917 SDNode *Node = Op.getNode();
1841 EVT VT = Node->getValueType(0); 1918 EVT VT = Node->getValueType(0);
1844 unsigned Align = Node->getConstantOperandVal(3); 1921 unsigned Align = Node->getConstantOperandVal(3);
1845 const Value *SV = cast<SrcValueSDNode>(Node->getOperand(2))->getValue(); 1922 const Value *SV = cast<SrcValueSDNode>(Node->getOperand(2))->getValue();
1846 SDLoc DL(Node); 1923 SDLoc DL(Node);
1847 unsigned ArgSlotSizeInBytes = (ABI.IsN32() || ABI.IsN64()) ? 8 : 4; 1924 unsigned ArgSlotSizeInBytes = (ABI.IsN32() || ABI.IsN64()) ? 8 : 4;
1848 1925
1849 SDValue VAListLoad = 1926 SDValue VAListLoad = DAG.getLoad(getPointerTy(DAG.getDataLayout()), DL, Chain,
1850 DAG.getLoad(getPointerTy(DAG.getDataLayout()), DL, Chain, VAListPtr, 1927 VAListPtr, MachinePointerInfo(SV));
1851 MachinePointerInfo(SV), false, false, false, 0);
1852 SDValue VAList = VAListLoad; 1928 SDValue VAList = VAListLoad;
1853 1929
1854 // Re-align the pointer if necessary. 1930 // Re-align the pointer if necessary.
1855 // It should only ever be necessary for 64-bit types on O32 since the minimum 1931 // It should only ever be necessary for 64-bit types on O32 since the minimum
1856 // argument alignment is the same as the maximum type alignment for N32/N64. 1932 // argument alignment is the same as the maximum type alignment for N32/N64.
1877 DAG.getNode(ISD::ADD, DL, VAList.getValueType(), VAList, 1953 DAG.getNode(ISD::ADD, DL, VAList.getValueType(), VAList,
1878 DAG.getConstant(alignTo(ArgSizeInBytes, ArgSlotSizeInBytes), 1954 DAG.getConstant(alignTo(ArgSizeInBytes, ArgSlotSizeInBytes),
1879 DL, VAList.getValueType())); 1955 DL, VAList.getValueType()));
1880 // Store the incremented VAList to the legalized pointer 1956 // Store the incremented VAList to the legalized pointer
1881 Chain = DAG.getStore(VAListLoad.getValue(1), DL, Tmp3, VAListPtr, 1957 Chain = DAG.getStore(VAListLoad.getValue(1), DL, Tmp3, VAListPtr,
1882 MachinePointerInfo(SV), false, false, 0); 1958 MachinePointerInfo(SV));
1883 1959
1884 // In big-endian mode we must adjust the pointer when the load size is smaller 1960 // In big-endian mode we must adjust the pointer when the load size is smaller
1885 // than the argument slot size. We must also reduce the known alignment to 1961 // than the argument slot size. We must also reduce the known alignment to
1886 // match. For example in the N64 ABI, we must add 4 bytes to the offset to get 1962 // match. For example in the N64 ABI, we must add 4 bytes to the offset to get
1887 // the correct half of the slot, and reduce the alignment from 8 (slot 1963 // the correct half of the slot, and reduce the alignment from 8 (slot
1890 unsigned Adjustment = ArgSlotSizeInBytes - ArgSizeInBytes; 1966 unsigned Adjustment = ArgSlotSizeInBytes - ArgSizeInBytes;
1891 VAList = DAG.getNode(ISD::ADD, DL, VAListPtr.getValueType(), VAList, 1967 VAList = DAG.getNode(ISD::ADD, DL, VAListPtr.getValueType(), VAList,
1892 DAG.getIntPtrConstant(Adjustment, DL)); 1968 DAG.getIntPtrConstant(Adjustment, DL));
1893 } 1969 }
1894 // Load the actual argument out of the pointer VAList 1970 // Load the actual argument out of the pointer VAList
1895 return DAG.getLoad(VT, DL, Chain, VAList, MachinePointerInfo(), false, false, 1971 return DAG.getLoad(VT, DL, Chain, VAList, MachinePointerInfo());
1896 false, 0);
1897 } 1972 }
1898 1973
1899 static SDValue lowerFCOPYSIGN32(SDValue Op, SelectionDAG &DAG, 1974 static SDValue lowerFCOPYSIGN32(SDValue Op, SelectionDAG &DAG,
1900 bool HasExtractInsert) { 1975 bool HasExtractInsert) {
1901 EVT TyX = Op.getOperand(0).getValueType(); 1976 EVT TyX = Op.getOperand(0).getValueType();
2005 lowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) const { 2080 lowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) const {
2006 // check the depth 2081 // check the depth
2007 assert((cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue() == 0) && 2082 assert((cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue() == 0) &&
2008 "Frame address can only be determined for current frame."); 2083 "Frame address can only be determined for current frame.");
2009 2084
2010 MachineFrameInfo *MFI = DAG.getMachineFunction().getFrameInfo(); 2085 MachineFrameInfo &MFI = DAG.getMachineFunction().getFrameInfo();
2011 MFI->setFrameAddressIsTaken(true); 2086 MFI.setFrameAddressIsTaken(true);
2012 EVT VT = Op.getValueType(); 2087 EVT VT = Op.getValueType();
2013 SDLoc DL(Op); 2088 SDLoc DL(Op);
2014 SDValue FrameAddr = DAG.getCopyFromReg( 2089 SDValue FrameAddr = DAG.getCopyFromReg(
2015 DAG.getEntryNode(), DL, ABI.IsN64() ? Mips::FP_64 : Mips::FP, VT); 2090 DAG.getEntryNode(), DL, ABI.IsN64() ? Mips::FP_64 : Mips::FP, VT);
2016 return FrameAddr; 2091 return FrameAddr;
2024 // check the depth 2099 // check the depth
2025 assert((cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue() == 0) && 2100 assert((cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue() == 0) &&
2026 "Return address can be determined only for current frame."); 2101 "Return address can be determined only for current frame.");
2027 2102
2028 MachineFunction &MF = DAG.getMachineFunction(); 2103 MachineFunction &MF = DAG.getMachineFunction();
2029 MachineFrameInfo *MFI = MF.getFrameInfo(); 2104 MachineFrameInfo &MFI = MF.getFrameInfo();
2030 MVT VT = Op.getSimpleValueType(); 2105 MVT VT = Op.getSimpleValueType();
2031 unsigned RA = ABI.IsN64() ? Mips::RA_64 : Mips::RA; 2106 unsigned RA = ABI.IsN64() ? Mips::RA_64 : Mips::RA;
2032 MFI->setReturnAddressIsTaken(true); 2107 MFI.setReturnAddressIsTaken(true);
2033 2108
2034 // Return RA, which contains the return address. Mark it an implicit live-in. 2109 // Return RA, which contains the return address. Mark it an implicit live-in.
2035 unsigned Reg = MF.addLiveIn(RA, getRegClassFor(VT)); 2110 unsigned Reg = MF.addLiveIn(RA, getRegClassFor(VT));
2036 return DAG.getCopyFromReg(DAG.getEntryNode(), SDLoc(Op), Reg, VT); 2111 return DAG.getCopyFromReg(DAG.getEntryNode(), SDLoc(Op), Reg, VT);
2037 } 2112 }
2281 return SDValue(); 2356 return SDValue();
2282 2357
2283 EVT FPTy = EVT::getFloatingPointVT(Val.getValueSizeInBits()); 2358 EVT FPTy = EVT::getFloatingPointVT(Val.getValueSizeInBits());
2284 SDValue Tr = DAG.getNode(MipsISD::TruncIntFP, SDLoc(Val), FPTy, 2359 SDValue Tr = DAG.getNode(MipsISD::TruncIntFP, SDLoc(Val), FPTy,
2285 Val.getOperand(0)); 2360 Val.getOperand(0));
2286
2287 return DAG.getStore(SD->getChain(), SDLoc(SD), Tr, SD->getBasePtr(), 2361 return DAG.getStore(SD->getChain(), SDLoc(SD), Tr, SD->getBasePtr(),
2288 SD->getPointerInfo(), SD->isVolatile(), 2362 SD->getPointerInfo(), SD->getAlignment(),
2289 SD->isNonTemporal(), SD->getAlignment()); 2363 SD->getMemOperand()->getFlags());
2290 } 2364 }
2291 2365
2292 SDValue MipsTargetLowering::lowerSTORE(SDValue Op, SelectionDAG &DAG) const { 2366 SDValue MipsTargetLowering::lowerSTORE(SDValue Op, SelectionDAG &DAG) const {
2293 StoreSDNode *SD = cast<StoreSDNode>(Op); 2367 StoreSDNode *SD = cast<StoreSDNode>(Op);
2294 EVT MemVT = SD->getMemoryVT(); 2368 EVT MemVT = SD->getMemoryVT();
2300 return lowerUnalignedIntStore(SD, DAG, Subtarget.isLittle()); 2374 return lowerUnalignedIntStore(SD, DAG, Subtarget.isLittle());
2301 2375
2302 return lowerFP_TO_SINT_STORE(SD, DAG); 2376 return lowerFP_TO_SINT_STORE(SD, DAG);
2303 } 2377 }
2304 2378
2305 SDValue MipsTargetLowering::lowerADD(SDValue Op, SelectionDAG &DAG) const { 2379 SDValue MipsTargetLowering::lowerEH_DWARF_CFA(SDValue Op,
2306 if (Op->getOperand(0).getOpcode() != ISD::FRAMEADDR 2380 SelectionDAG &DAG) const {
2307 || cast<ConstantSDNode> 2381
2308 (Op->getOperand(0).getOperand(0))->getZExtValue() != 0 2382 // Return a fixed StackObject with offset 0 which points to the old stack
2309 || Op->getOperand(1).getOpcode() != ISD::FRAME_TO_ARGS_OFFSET) 2383 // pointer.
2310 return SDValue(); 2384 MachineFrameInfo &MFI = DAG.getMachineFunction().getFrameInfo();
2311
2312 // The pattern
2313 // (add (frameaddr 0), (frame_to_args_offset))
2314 // results from lowering llvm.eh.dwarf.cfa intrinsic. Transform it to
2315 // (add FrameObject, 0)
2316 // where FrameObject is a fixed StackObject with offset 0 which points to
2317 // the old stack pointer.
2318 MachineFrameInfo *MFI = DAG.getMachineFunction().getFrameInfo();
2319 EVT ValTy = Op->getValueType(0); 2385 EVT ValTy = Op->getValueType(0);
2320 int FI = MFI->CreateFixedObject(Op.getValueSizeInBits() / 8, 0, false); 2386 int FI = MFI.CreateFixedObject(Op.getValueSizeInBits() / 8, 0, false);
2321 SDValue InArgsAddr = DAG.getFrameIndex(FI, ValTy); 2387 return DAG.getFrameIndex(FI, ValTy);
2322 SDLoc DL(Op);
2323 return DAG.getNode(ISD::ADD, DL, ValTy, InArgsAddr,
2324 DAG.getConstant(0, DL, ValTy));
2325 } 2388 }
2326 2389
2327 SDValue MipsTargetLowering::lowerFP_TO_SINT(SDValue Op, 2390 SDValue MipsTargetLowering::lowerFP_TO_SINT(SDValue Op,
2328 SelectionDAG &DAG) const { 2391 SelectionDAG &DAG) const {
2329 EVT FPTy = EVT::getFloatingPointVT(Op.getValueSizeInBits()); 2392 EVT FPTy = EVT::getFloatingPointVT(Op.getValueSizeInBits());
2470 static unsigned getNextIntArgReg(unsigned Reg) { 2533 static unsigned getNextIntArgReg(unsigned Reg) {
2471 assert((Reg == Mips::A0) || (Reg == Mips::A2)); 2534 assert((Reg == Mips::A0) || (Reg == Mips::A2));
2472 return (Reg == Mips::A0) ? Mips::A1 : Mips::A3; 2535 return (Reg == Mips::A0) ? Mips::A1 : Mips::A3;
2473 } 2536 }
2474 2537
2475 SDValue 2538 SDValue MipsTargetLowering::passArgOnStack(SDValue StackPtr, unsigned Offset,
2476 MipsTargetLowering::passArgOnStack(SDValue StackPtr, unsigned Offset, 2539 SDValue Chain, SDValue Arg,
2477 SDValue Chain, SDValue Arg, SDLoc DL, 2540 const SDLoc &DL, bool IsTailCall,
2478 bool IsTailCall, SelectionDAG &DAG) const { 2541 SelectionDAG &DAG) const {
2479 if (!IsTailCall) { 2542 if (!IsTailCall) {
2480 SDValue PtrOff = 2543 SDValue PtrOff =
2481 DAG.getNode(ISD::ADD, DL, getPointerTy(DAG.getDataLayout()), StackPtr, 2544 DAG.getNode(ISD::ADD, DL, getPointerTy(DAG.getDataLayout()), StackPtr,
2482 DAG.getIntPtrConstant(Offset, DL)); 2545 DAG.getIntPtrConstant(Offset, DL));
2483 return DAG.getStore(Chain, DL, Arg, PtrOff, MachinePointerInfo(), false, 2546 return DAG.getStore(Chain, DL, Arg, PtrOff, MachinePointerInfo());
2484 false, 0); 2547 }
2485 } 2548
2486 2549 MachineFrameInfo &MFI = DAG.getMachineFunction().getFrameInfo();
2487 MachineFrameInfo *MFI = DAG.getMachineFunction().getFrameInfo(); 2550 int FI = MFI.CreateFixedObject(Arg.getValueSizeInBits() / 8, Offset, false);
2488 int FI = MFI->CreateFixedObject(Arg.getValueSizeInBits() / 8, Offset, false);
2489 SDValue FIN = DAG.getFrameIndex(FI, getPointerTy(DAG.getDataLayout())); 2551 SDValue FIN = DAG.getFrameIndex(FI, getPointerTy(DAG.getDataLayout()));
2490 return DAG.getStore(Chain, DL, Arg, FIN, MachinePointerInfo(), 2552 return DAG.getStore(Chain, DL, Arg, FIN, MachinePointerInfo(),
2491 /*isVolatile=*/ true, false, 0); 2553 /* Alignment = */ 0, MachineMemOperand::MOVolatile);
2492 } 2554 }
2493 2555
2494 void MipsTargetLowering:: 2556 void MipsTargetLowering::
2495 getOpndList(SmallVectorImpl<SDValue> &Ops, 2557 getOpndList(SmallVectorImpl<SDValue> &Ops,
2496 std::deque< std::pair<unsigned, SDValue> > &RegsToPass, 2558 std::deque< std::pair<unsigned, SDValue> > &RegsToPass,
2566 bool &IsTailCall = CLI.IsTailCall; 2628 bool &IsTailCall = CLI.IsTailCall;
2567 CallingConv::ID CallConv = CLI.CallConv; 2629 CallingConv::ID CallConv = CLI.CallConv;
2568 bool IsVarArg = CLI.IsVarArg; 2630 bool IsVarArg = CLI.IsVarArg;
2569 2631
2570 MachineFunction &MF = DAG.getMachineFunction(); 2632 MachineFunction &MF = DAG.getMachineFunction();
2571 MachineFrameInfo *MFI = MF.getFrameInfo(); 2633 MachineFrameInfo &MFI = MF.getFrameInfo();
2572 const TargetFrameLowering *TFL = Subtarget.getFrameLowering(); 2634 const TargetFrameLowering *TFL = Subtarget.getFrameLowering();
2573 MipsFunctionInfo *FuncInfo = MF.getInfo<MipsFunctionInfo>(); 2635 MipsFunctionInfo *FuncInfo = MF.getInfo<MipsFunctionInfo>();
2574 bool IsPIC = getTargetMachine().getRelocationModel() == Reloc::PIC_; 2636 bool IsPIC = isPositionIndependent();
2575 2637
2576 // Analyze operands of the call, assigning locations to each operand. 2638 // Analyze operands of the call, assigning locations to each operand.
2577 SmallVector<CCValAssign, 16> ArgLocs; 2639 SmallVector<CCValAssign, 16> ArgLocs;
2578 MipsCCState CCInfo( 2640 MipsCCState CCInfo(
2579 CallConv, IsVarArg, DAG.getMachineFunction(), ArgLocs, *DAG.getContext(), 2641 CallConv, IsVarArg, DAG.getMachineFunction(), ArgLocs, *DAG.getContext(),
2586 CCInfo.AnalyzeCallOperands(Outs, CC_Mips, CLI.getArgs(), Callee.getNode()); 2648 CCInfo.AnalyzeCallOperands(Outs, CC_Mips, CLI.getArgs(), Callee.getNode());
2587 2649
2588 // Get a count of how many bytes are to be pushed on the stack. 2650 // Get a count of how many bytes are to be pushed on the stack.
2589 unsigned NextStackOffset = CCInfo.getNextStackOffset(); 2651 unsigned NextStackOffset = CCInfo.getNextStackOffset();
2590 2652
2591 // Check if it's really possible to do a tail call. 2653 // Check if it's really possible to do a tail call. Restrict it to functions
2592 if (IsTailCall) 2654 // that are part of this compilation unit.
2655 bool InternalLinkage = false;
2656 if (IsTailCall) {
2593 IsTailCall = isEligibleForTailCallOptimization( 2657 IsTailCall = isEligibleForTailCallOptimization(
2594 CCInfo, NextStackOffset, *MF.getInfo<MipsFunctionInfo>()); 2658 CCInfo, NextStackOffset, *MF.getInfo<MipsFunctionInfo>());
2595 2659 if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee)) {
2660 InternalLinkage = G->getGlobal()->hasInternalLinkage();
2661 IsTailCall &= (InternalLinkage || G->getGlobal()->hasLocalLinkage() ||
2662 G->getGlobal()->hasPrivateLinkage() ||
2663 G->getGlobal()->hasHiddenVisibility() ||
2664 G->getGlobal()->hasProtectedVisibility());
2665 }
2666 }
2596 if (!IsTailCall && CLI.CS && CLI.CS->isMustTailCall()) 2667 if (!IsTailCall && CLI.CS && CLI.CS->isMustTailCall())
2597 report_fatal_error("failed to perform tail call elimination on a call " 2668 report_fatal_error("failed to perform tail call elimination on a call "
2598 "site marked musttail"); 2669 "site marked musttail");
2599 2670
2600 if (IsTailCall) 2671 if (IsTailCall)
2612 2683
2613 SDValue StackPtr = 2684 SDValue StackPtr =
2614 DAG.getCopyFromReg(Chain, DL, ABI.IsN64() ? Mips::SP_64 : Mips::SP, 2685 DAG.getCopyFromReg(Chain, DL, ABI.IsN64() ? Mips::SP_64 : Mips::SP,
2615 getPointerTy(DAG.getDataLayout())); 2686 getPointerTy(DAG.getDataLayout()));
2616 2687
2617 // With EABI is it possible to have 16 args on registers.
2618 std::deque< std::pair<unsigned, SDValue> > RegsToPass; 2688 std::deque< std::pair<unsigned, SDValue> > RegsToPass;
2619 SmallVector<SDValue, 8> MemOpChains; 2689 SmallVector<SDValue, 8> MemOpChains;
2620 2690
2621 CCInfo.rewindByValRegsInfo(); 2691 CCInfo.rewindByValRegsInfo();
2622 2692
2674 case CCValAssign::BCvt: 2744 case CCValAssign::BCvt:
2675 Arg = DAG.getNode(ISD::BITCAST, DL, LocVT, Arg); 2745 Arg = DAG.getNode(ISD::BITCAST, DL, LocVT, Arg);
2676 break; 2746 break;
2677 case CCValAssign::SExtUpper: 2747 case CCValAssign::SExtUpper:
2678 UseUpperBits = true; 2748 UseUpperBits = true;
2679 // Fallthrough 2749 LLVM_FALLTHROUGH;
2680 case CCValAssign::SExt: 2750 case CCValAssign::SExt:
2681 Arg = DAG.getNode(ISD::SIGN_EXTEND, DL, LocVT, Arg); 2751 Arg = DAG.getNode(ISD::SIGN_EXTEND, DL, LocVT, Arg);
2682 break; 2752 break;
2683 case CCValAssign::ZExtUpper: 2753 case CCValAssign::ZExtUpper:
2684 UseUpperBits = true; 2754 UseUpperBits = true;
2685 // Fallthrough 2755 LLVM_FALLTHROUGH;
2686 case CCValAssign::ZExt: 2756 case CCValAssign::ZExt:
2687 Arg = DAG.getNode(ISD::ZERO_EXTEND, DL, LocVT, Arg); 2757 Arg = DAG.getNode(ISD::ZERO_EXTEND, DL, LocVT, Arg);
2688 break; 2758 break;
2689 case CCValAssign::AExtUpper: 2759 case CCValAssign::AExtUpper:
2690 UseUpperBits = true; 2760 UseUpperBits = true;
2691 // Fallthrough 2761 LLVM_FALLTHROUGH;
2692 case CCValAssign::AExt: 2762 case CCValAssign::AExt:
2693 Arg = DAG.getNode(ISD::ANY_EXTEND, DL, LocVT, Arg); 2763 Arg = DAG.getNode(ISD::ANY_EXTEND, DL, LocVT, Arg);
2694 break; 2764 break;
2695 } 2765 }
2696 2766
2726 // If the callee is a GlobalAddress/ExternalSymbol node (quite common, every 2796 // If the callee is a GlobalAddress/ExternalSymbol node (quite common, every
2727 // direct call is) turn it into a TargetGlobalAddress/TargetExternalSymbol 2797 // direct call is) turn it into a TargetGlobalAddress/TargetExternalSymbol
2728 // node so that legalize doesn't hack it. 2798 // node so that legalize doesn't hack it.
2729 bool IsPICCall = (ABI.IsN64() || IsPIC); // true if calls are translated to 2799 bool IsPICCall = (ABI.IsN64() || IsPIC); // true if calls are translated to
2730 // jalr $25 2800 // jalr $25
2731 bool GlobalOrExternal = false, InternalLinkage = false, IsCallReloc = false;
2732 SDValue CalleeLo; 2801 SDValue CalleeLo;
2733 EVT Ty = Callee.getValueType(); 2802 EVT Ty = Callee.getValueType();
2803 bool GlobalOrExternal = false, IsCallReloc = false;
2734 2804
2735 if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee)) { 2805 if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee)) {
2736 if (IsPICCall) { 2806 if (IsPICCall) {
2737 const GlobalValue *Val = G->getGlobal(); 2807 const GlobalValue *Val = G->getGlobal();
2738 InternalLinkage = Val->hasInternalLinkage(); 2808 InternalLinkage = Val->hasInternalLinkage();
2779 SDVTList NodeTys = DAG.getVTList(MVT::Other, MVT::Glue); 2849 SDVTList NodeTys = DAG.getVTList(MVT::Other, MVT::Glue);
2780 2850
2781 getOpndList(Ops, RegsToPass, IsPICCall, GlobalOrExternal, InternalLinkage, 2851 getOpndList(Ops, RegsToPass, IsPICCall, GlobalOrExternal, InternalLinkage,
2782 IsCallReloc, CLI, Callee, Chain); 2852 IsCallReloc, CLI, Callee, Chain);
2783 2853
2784 if (IsTailCall) 2854 if (IsTailCall) {
2855 MF.getFrameInfo().setHasTailCall();
2785 return DAG.getNode(MipsISD::TailCall, DL, MVT::Other, Ops); 2856 return DAG.getNode(MipsISD::TailCall, DL, MVT::Other, Ops);
2857 }
2786 2858
2787 Chain = DAG.getNode(MipsISD::JmpLink, DL, NodeTys, Ops); 2859 Chain = DAG.getNode(MipsISD::JmpLink, DL, NodeTys, Ops);
2788 SDValue InFlag = Chain.getValue(1); 2860 SDValue InFlag = Chain.getValue(1);
2789 2861
2790 // Create the CALLSEQ_END node. 2862 // Create the CALLSEQ_END node.
2800 2872
2801 /// LowerCallResult - Lower the result values of a call into the 2873 /// LowerCallResult - Lower the result values of a call into the
2802 /// appropriate copies out of appropriate physical registers. 2874 /// appropriate copies out of appropriate physical registers.
2803 SDValue MipsTargetLowering::LowerCallResult( 2875 SDValue MipsTargetLowering::LowerCallResult(
2804 SDValue Chain, SDValue InFlag, CallingConv::ID CallConv, bool IsVarArg, 2876 SDValue Chain, SDValue InFlag, CallingConv::ID CallConv, bool IsVarArg,
2805 const SmallVectorImpl<ISD::InputArg> &Ins, SDLoc DL, SelectionDAG &DAG, 2877 const SmallVectorImpl<ISD::InputArg> &Ins, const SDLoc &DL,
2806 SmallVectorImpl<SDValue> &InVals, 2878 SelectionDAG &DAG, SmallVectorImpl<SDValue> &InVals,
2807 TargetLowering::CallLoweringInfo &CLI) const { 2879 TargetLowering::CallLoweringInfo &CLI) const {
2808 // Assign locations to each value returned by this call. 2880 // Assign locations to each value returned by this call.
2809 SmallVector<CCValAssign, 16> RVLocs; 2881 SmallVector<CCValAssign, 16> RVLocs;
2810 MipsCCState CCInfo(CallConv, IsVarArg, DAG.getMachineFunction(), RVLocs, 2882 MipsCCState CCInfo(CallConv, IsVarArg, DAG.getMachineFunction(), RVLocs,
2811 *DAG.getContext()); 2883 *DAG.getContext());
2862 2934
2863 return Chain; 2935 return Chain;
2864 } 2936 }
2865 2937
2866 static SDValue UnpackFromArgumentSlot(SDValue Val, const CCValAssign &VA, 2938 static SDValue UnpackFromArgumentSlot(SDValue Val, const CCValAssign &VA,
2867 EVT ArgVT, SDLoc DL, SelectionDAG &DAG) { 2939 EVT ArgVT, const SDLoc &DL,
2940 SelectionDAG &DAG) {
2868 MVT LocVT = VA.getLocVT(); 2941 MVT LocVT = VA.getLocVT();
2869 EVT ValVT = VA.getValVT(); 2942 EVT ValVT = VA.getValVT();
2870 2943
2871 // Shift into the upper bits if necessary. 2944 // Shift into the upper bits if necessary.
2872 switch (VA.getLocInfo()) { 2945 switch (VA.getLocInfo()) {
2920 //===----------------------------------------------------------------------===// 2993 //===----------------------------------------------------------------------===//
2921 // Formal Arguments Calling Convention Implementation 2994 // Formal Arguments Calling Convention Implementation
2922 //===----------------------------------------------------------------------===// 2995 //===----------------------------------------------------------------------===//
2923 /// LowerFormalArguments - transform physical registers into virtual registers 2996 /// LowerFormalArguments - transform physical registers into virtual registers
2924 /// and generate load operations for arguments places on the stack. 2997 /// and generate load operations for arguments places on the stack.
2925 SDValue 2998 SDValue MipsTargetLowering::LowerFormalArguments(
2926 MipsTargetLowering::LowerFormalArguments(SDValue Chain, 2999 SDValue Chain, CallingConv::ID CallConv, bool IsVarArg,
2927 CallingConv::ID CallConv, 3000 const SmallVectorImpl<ISD::InputArg> &Ins, const SDLoc &DL,
2928 bool IsVarArg, 3001 SelectionDAG &DAG, SmallVectorImpl<SDValue> &InVals) const {
2929 const SmallVectorImpl<ISD::InputArg> &Ins,
2930 SDLoc DL, SelectionDAG &DAG,
2931 SmallVectorImpl<SDValue> &InVals)
2932 const {
2933 MachineFunction &MF = DAG.getMachineFunction(); 3002 MachineFunction &MF = DAG.getMachineFunction();
2934 MachineFrameInfo *MFI = MF.getFrameInfo(); 3003 MachineFrameInfo &MFI = MF.getFrameInfo();
2935 MipsFunctionInfo *MipsFI = MF.getInfo<MipsFunctionInfo>(); 3004 MipsFunctionInfo *MipsFI = MF.getInfo<MipsFunctionInfo>();
2936 3005
2937 MipsFI->setVarArgsFrameIndex(0); 3006 MipsFI->setVarArgsFrameIndex(0);
2938 3007
2939 // Used with vargs to acumulate store chains. 3008 // Used with vargs to acumulate store chains.
3028 3097
3029 // sanity check 3098 // sanity check
3030 assert(VA.isMemLoc()); 3099 assert(VA.isMemLoc());
3031 3100
3032 // The stack pointer offset is relative to the caller stack frame. 3101 // The stack pointer offset is relative to the caller stack frame.
3033 int FI = MFI->CreateFixedObject(LocVT.getSizeInBits() / 8, 3102 int FI = MFI.CreateFixedObject(LocVT.getSizeInBits() / 8,
3034 VA.getLocMemOffset(), true); 3103 VA.getLocMemOffset(), true);
3035 3104
3036 // Create load nodes to retrieve arguments from the stack 3105 // Create load nodes to retrieve arguments from the stack
3037 SDValue FIN = DAG.getFrameIndex(FI, getPointerTy(DAG.getDataLayout())); 3106 SDValue FIN = DAG.getFrameIndex(FI, getPointerTy(DAG.getDataLayout()));
3038 SDValue ArgValue = DAG.getLoad( 3107 SDValue ArgValue = DAG.getLoad(
3039 LocVT, DL, Chain, FIN, 3108 LocVT, DL, Chain, FIN,
3040 MachinePointerInfo::getFixedStack(DAG.getMachineFunction(), FI), 3109 MachinePointerInfo::getFixedStack(DAG.getMachineFunction(), FI));
3041 false, false, false, 0);
3042 OutChains.push_back(ArgValue.getValue(1)); 3110 OutChains.push_back(ArgValue.getValue(1));
3043 3111
3044 ArgValue = UnpackFromArgumentSlot(ArgValue, VA, Ins[i].ArgVT, DL, DAG); 3112 ArgValue = UnpackFromArgumentSlot(ArgValue, VA, Ins[i].ArgVT, DL, DAG);
3045 3113
3046 InVals.push_back(ArgValue); 3114 InVals.push_back(ArgValue);
3100 return IsSigned; 3168 return IsSigned;
3101 } 3169 }
3102 3170
3103 SDValue 3171 SDValue
3104 MipsTargetLowering::LowerInterruptReturn(SmallVectorImpl<SDValue> &RetOps, 3172 MipsTargetLowering::LowerInterruptReturn(SmallVectorImpl<SDValue> &RetOps,
3105 SDLoc DL, SelectionDAG &DAG) const { 3173 const SDLoc &DL,
3174 SelectionDAG &DAG) const {
3106 3175
3107 MachineFunction &MF = DAG.getMachineFunction(); 3176 MachineFunction &MF = DAG.getMachineFunction();
3108 MipsFunctionInfo *MipsFI = MF.getInfo<MipsFunctionInfo>(); 3177 MipsFunctionInfo *MipsFI = MF.getInfo<MipsFunctionInfo>();
3109 3178
3110 MipsFI->setISR(); 3179 MipsFI->setISR();
3115 SDValue 3184 SDValue
3116 MipsTargetLowering::LowerReturn(SDValue Chain, CallingConv::ID CallConv, 3185 MipsTargetLowering::LowerReturn(SDValue Chain, CallingConv::ID CallConv,
3117 bool IsVarArg, 3186 bool IsVarArg,
3118 const SmallVectorImpl<ISD::OutputArg> &Outs, 3187 const SmallVectorImpl<ISD::OutputArg> &Outs,
3119 const SmallVectorImpl<SDValue> &OutVals, 3188 const SmallVectorImpl<SDValue> &OutVals,
3120 SDLoc DL, SelectionDAG &DAG) const { 3189 const SDLoc &DL, SelectionDAG &DAG) const {
3121 // CCValAssign - represent the assignment of 3190 // CCValAssign - represent the assignment of
3122 // the return value to a location 3191 // the return value to a location
3123 SmallVector<CCValAssign, 16> RVLocs; 3192 SmallVector<CCValAssign, 16> RVLocs;
3124 MachineFunction &MF = DAG.getMachineFunction(); 3193 MachineFunction &MF = DAG.getMachineFunction();
3125 3194
3147 case CCValAssign::BCvt: 3216 case CCValAssign::BCvt:
3148 Val = DAG.getNode(ISD::BITCAST, DL, VA.getLocVT(), Val); 3217 Val = DAG.getNode(ISD::BITCAST, DL, VA.getLocVT(), Val);
3149 break; 3218 break;
3150 case CCValAssign::AExtUpper: 3219 case CCValAssign::AExtUpper:
3151 UseUpperBits = true; 3220 UseUpperBits = true;
3152 // Fallthrough 3221 LLVM_FALLTHROUGH;
3153 case CCValAssign::AExt: 3222 case CCValAssign::AExt:
3154 Val = DAG.getNode(ISD::ANY_EXTEND, DL, VA.getLocVT(), Val); 3223 Val = DAG.getNode(ISD::ANY_EXTEND, DL, VA.getLocVT(), Val);
3155 break; 3224 break;
3156 case CCValAssign::ZExtUpper: 3225 case CCValAssign::ZExtUpper:
3157 UseUpperBits = true; 3226 UseUpperBits = true;
3158 // Fallthrough 3227 LLVM_FALLTHROUGH;
3159 case CCValAssign::ZExt: 3228 case CCValAssign::ZExt:
3160 Val = DAG.getNode(ISD::ZERO_EXTEND, DL, VA.getLocVT(), Val); 3229 Val = DAG.getNode(ISD::ZERO_EXTEND, DL, VA.getLocVT(), Val);
3161 break; 3230 break;
3162 case CCValAssign::SExtUpper: 3231 case CCValAssign::SExtUpper:
3163 UseUpperBits = true; 3232 UseUpperBits = true;
3164 // Fallthrough 3233 LLVM_FALLTHROUGH;
3165 case CCValAssign::SExt: 3234 case CCValAssign::SExt:
3166 Val = DAG.getNode(ISD::SIGN_EXTEND, DL, VA.getLocVT(), Val); 3235 Val = DAG.getNode(ISD::SIGN_EXTEND, DL, VA.getLocVT(), Val);
3167 break; 3236 break;
3168 } 3237 }
3169 3238
3623 bool MipsTargetLowering::useSoftFloat() const { 3692 bool MipsTargetLowering::useSoftFloat() const {
3624 return Subtarget.useSoftFloat(); 3693 return Subtarget.useSoftFloat();
3625 } 3694 }
3626 3695
3627 void MipsTargetLowering::copyByValRegs( 3696 void MipsTargetLowering::copyByValRegs(
3628 SDValue Chain, SDLoc DL, std::vector<SDValue> &OutChains, SelectionDAG &DAG, 3697 SDValue Chain, const SDLoc &DL, std::vector<SDValue> &OutChains,
3629 const ISD::ArgFlagsTy &Flags, SmallVectorImpl<SDValue> &InVals, 3698 SelectionDAG &DAG, const ISD::ArgFlagsTy &Flags,
3630 const Argument *FuncArg, unsigned FirstReg, unsigned LastReg, 3699 SmallVectorImpl<SDValue> &InVals, const Argument *FuncArg,
3631 const CCValAssign &VA, MipsCCState &State) const { 3700 unsigned FirstReg, unsigned LastReg, const CCValAssign &VA,
3701 MipsCCState &State) const {
3632 MachineFunction &MF = DAG.getMachineFunction(); 3702 MachineFunction &MF = DAG.getMachineFunction();
3633 MachineFrameInfo *MFI = MF.getFrameInfo(); 3703 MachineFrameInfo &MFI = MF.getFrameInfo();
3634 unsigned GPRSizeInBytes = Subtarget.getGPRSizeInBytes(); 3704 unsigned GPRSizeInBytes = Subtarget.getGPRSizeInBytes();
3635 unsigned NumRegs = LastReg - FirstReg; 3705 unsigned NumRegs = LastReg - FirstReg;
3636 unsigned RegAreaSize = NumRegs * GPRSizeInBytes; 3706 unsigned RegAreaSize = NumRegs * GPRSizeInBytes;
3637 unsigned FrameObjSize = std::max(Flags.getByValSize(), RegAreaSize); 3707 unsigned FrameObjSize = std::max(Flags.getByValSize(), RegAreaSize);
3638 int FrameObjOffset; 3708 int FrameObjOffset;
3645 else 3715 else
3646 FrameObjOffset = VA.getLocMemOffset(); 3716 FrameObjOffset = VA.getLocMemOffset();
3647 3717
3648 // Create frame object. 3718 // Create frame object.
3649 EVT PtrTy = getPointerTy(DAG.getDataLayout()); 3719 EVT PtrTy = getPointerTy(DAG.getDataLayout());
3650 int FI = MFI->CreateFixedObject(FrameObjSize, FrameObjOffset, true); 3720 int FI = MFI.CreateFixedObject(FrameObjSize, FrameObjOffset, true);
3651 SDValue FIN = DAG.getFrameIndex(FI, PtrTy); 3721 SDValue FIN = DAG.getFrameIndex(FI, PtrTy);
3652 InVals.push_back(FIN); 3722 InVals.push_back(FIN);
3653 3723
3654 if (!NumRegs) 3724 if (!NumRegs)
3655 return; 3725 return;
3663 unsigned VReg = addLiveIn(MF, ArgReg, RC); 3733 unsigned VReg = addLiveIn(MF, ArgReg, RC);
3664 unsigned Offset = I * GPRSizeInBytes; 3734 unsigned Offset = I * GPRSizeInBytes;
3665 SDValue StorePtr = DAG.getNode(ISD::ADD, DL, PtrTy, FIN, 3735 SDValue StorePtr = DAG.getNode(ISD::ADD, DL, PtrTy, FIN,
3666 DAG.getConstant(Offset, DL, PtrTy)); 3736 DAG.getConstant(Offset, DL, PtrTy));
3667 SDValue Store = DAG.getStore(Chain, DL, DAG.getRegister(VReg, RegTy), 3737 SDValue Store = DAG.getStore(Chain, DL, DAG.getRegister(VReg, RegTy),
3668 StorePtr, MachinePointerInfo(FuncArg, Offset), 3738 StorePtr, MachinePointerInfo(FuncArg, Offset));
3669 false, false, 0);
3670 OutChains.push_back(Store); 3739 OutChains.push_back(Store);
3671 } 3740 }
3672 } 3741 }
3673 3742
3674 // Copy byVal arg to registers and stack. 3743 // Copy byVal arg to registers and stack.
3675 void MipsTargetLowering::passByValArg( 3744 void MipsTargetLowering::passByValArg(
3676 SDValue Chain, SDLoc DL, 3745 SDValue Chain, const SDLoc &DL,
3677 std::deque<std::pair<unsigned, SDValue>> &RegsToPass, 3746 std::deque<std::pair<unsigned, SDValue>> &RegsToPass,
3678 SmallVectorImpl<SDValue> &MemOpChains, SDValue StackPtr, 3747 SmallVectorImpl<SDValue> &MemOpChains, SDValue StackPtr,
3679 MachineFrameInfo *MFI, SelectionDAG &DAG, SDValue Arg, unsigned FirstReg, 3748 MachineFrameInfo &MFI, SelectionDAG &DAG, SDValue Arg, unsigned FirstReg,
3680 unsigned LastReg, const ISD::ArgFlagsTy &Flags, bool isLittle, 3749 unsigned LastReg, const ISD::ArgFlagsTy &Flags, bool isLittle,
3681 const CCValAssign &VA) const { 3750 const CCValAssign &VA) const {
3682 unsigned ByValSizeInBytes = Flags.getByValSize(); 3751 unsigned ByValSizeInBytes = Flags.getByValSize();
3683 unsigned OffsetInBytes = 0; // From beginning of struct 3752 unsigned OffsetInBytes = 0; // From beginning of struct
3684 unsigned RegSizeInBytes = Subtarget.getGPRSizeInBytes(); 3753 unsigned RegSizeInBytes = Subtarget.getGPRSizeInBytes();
3695 // Copy words to registers. 3764 // Copy words to registers.
3696 for (; I < NumRegs - LeftoverBytes; ++I, OffsetInBytes += RegSizeInBytes) { 3765 for (; I < NumRegs - LeftoverBytes; ++I, OffsetInBytes += RegSizeInBytes) {
3697 SDValue LoadPtr = DAG.getNode(ISD::ADD, DL, PtrTy, Arg, 3766 SDValue LoadPtr = DAG.getNode(ISD::ADD, DL, PtrTy, Arg,
3698 DAG.getConstant(OffsetInBytes, DL, PtrTy)); 3767 DAG.getConstant(OffsetInBytes, DL, PtrTy));
3699 SDValue LoadVal = DAG.getLoad(RegTy, DL, Chain, LoadPtr, 3768 SDValue LoadVal = DAG.getLoad(RegTy, DL, Chain, LoadPtr,
3700 MachinePointerInfo(), false, false, false, 3769 MachinePointerInfo(), Alignment);
3701 Alignment);
3702 MemOpChains.push_back(LoadVal.getValue(1)); 3770 MemOpChains.push_back(LoadVal.getValue(1));
3703 unsigned ArgReg = ArgRegs[FirstReg + I]; 3771 unsigned ArgReg = ArgRegs[FirstReg + I];
3704 RegsToPass.push_back(std::make_pair(ArgReg, LoadVal)); 3772 RegsToPass.push_back(std::make_pair(ArgReg, LoadVal));
3705 } 3773 }
3706 3774
3723 SDValue LoadPtr = DAG.getNode(ISD::ADD, DL, PtrTy, Arg, 3791 SDValue LoadPtr = DAG.getNode(ISD::ADD, DL, PtrTy, Arg,
3724 DAG.getConstant(OffsetInBytes, DL, 3792 DAG.getConstant(OffsetInBytes, DL,
3725 PtrTy)); 3793 PtrTy));
3726 SDValue LoadVal = DAG.getExtLoad( 3794 SDValue LoadVal = DAG.getExtLoad(
3727 ISD::ZEXTLOAD, DL, RegTy, Chain, LoadPtr, MachinePointerInfo(), 3795 ISD::ZEXTLOAD, DL, RegTy, Chain, LoadPtr, MachinePointerInfo(),
3728 MVT::getIntegerVT(LoadSizeInBytes * 8), false, false, false, 3796 MVT::getIntegerVT(LoadSizeInBytes * 8), Alignment);
3729 Alignment);
3730 MemOpChains.push_back(LoadVal.getValue(1)); 3797 MemOpChains.push_back(LoadVal.getValue(1));
3731 3798
3732 // Shift the loaded value. 3799 // Shift the loaded value.
3733 unsigned Shamt; 3800 unsigned Shamt;
3734 3801
3769 MachinePointerInfo(), MachinePointerInfo()); 3836 MachinePointerInfo(), MachinePointerInfo());
3770 MemOpChains.push_back(Chain); 3837 MemOpChains.push_back(Chain);
3771 } 3838 }
3772 3839
3773 void MipsTargetLowering::writeVarArgRegs(std::vector<SDValue> &OutChains, 3840 void MipsTargetLowering::writeVarArgRegs(std::vector<SDValue> &OutChains,
3774 SDValue Chain, SDLoc DL, 3841 SDValue Chain, const SDLoc &DL,
3775 SelectionDAG &DAG, 3842 SelectionDAG &DAG,
3776 CCState &State) const { 3843 CCState &State) const {
3777 ArrayRef<MCPhysReg> ArgRegs = ABI.GetVarArgRegs(); 3844 ArrayRef<MCPhysReg> ArgRegs = ABI.GetVarArgRegs();
3778 unsigned Idx = State.getFirstUnallocated(ArgRegs); 3845 unsigned Idx = State.getFirstUnallocated(ArgRegs);
3779 unsigned RegSizeInBytes = Subtarget.getGPRSizeInBytes(); 3846 unsigned RegSizeInBytes = Subtarget.getGPRSizeInBytes();
3780 MVT RegTy = MVT::getIntegerVT(RegSizeInBytes * 8); 3847 MVT RegTy = MVT::getIntegerVT(RegSizeInBytes * 8);
3781 const TargetRegisterClass *RC = getRegClassFor(RegTy); 3848 const TargetRegisterClass *RC = getRegClassFor(RegTy);
3782 MachineFunction &MF = DAG.getMachineFunction(); 3849 MachineFunction &MF = DAG.getMachineFunction();
3783 MachineFrameInfo *MFI = MF.getFrameInfo(); 3850 MachineFrameInfo &MFI = MF.getFrameInfo();
3784 MipsFunctionInfo *MipsFI = MF.getInfo<MipsFunctionInfo>(); 3851 MipsFunctionInfo *MipsFI = MF.getInfo<MipsFunctionInfo>();
3785 3852
3786 // Offset of the first variable argument from stack pointer. 3853 // Offset of the first variable argument from stack pointer.
3787 int VaArgOffset; 3854 int VaArgOffset;
3788 3855
3794 (int)(RegSizeInBytes * (ArgRegs.size() - Idx)); 3861 (int)(RegSizeInBytes * (ArgRegs.size() - Idx));
3795 } 3862 }
3796 3863
3797 // Record the frame index of the first variable argument 3864 // Record the frame index of the first variable argument
3798 // which is a value necessary to VASTART. 3865 // which is a value necessary to VASTART.
3799 int FI = MFI->CreateFixedObject(RegSizeInBytes, VaArgOffset, true); 3866 int FI = MFI.CreateFixedObject(RegSizeInBytes, VaArgOffset, true);
3800 MipsFI->setVarArgsFrameIndex(FI); 3867 MipsFI->setVarArgsFrameIndex(FI);
3801 3868
3802 // Copy the integer registers that have not been used for argument passing 3869 // Copy the integer registers that have not been used for argument passing
3803 // to the argument register save area. For O32, the save area is allocated 3870 // to the argument register save area. For O32, the save area is allocated
3804 // in the caller's stack frame, while for N32/64, it is allocated in the 3871 // in the caller's stack frame, while for N32/64, it is allocated in the
3805 // callee's stack frame. 3872 // callee's stack frame.
3806 for (unsigned I = Idx; I < ArgRegs.size(); 3873 for (unsigned I = Idx; I < ArgRegs.size();
3807 ++I, VaArgOffset += RegSizeInBytes) { 3874 ++I, VaArgOffset += RegSizeInBytes) {
3808 unsigned Reg = addLiveIn(MF, ArgRegs[I], RC); 3875 unsigned Reg = addLiveIn(MF, ArgRegs[I], RC);
3809 SDValue ArgValue = DAG.getCopyFromReg(Chain, DL, Reg, RegTy); 3876 SDValue ArgValue = DAG.getCopyFromReg(Chain, DL, Reg, RegTy);
3810 FI = MFI->CreateFixedObject(RegSizeInBytes, VaArgOffset, true); 3877 FI = MFI.CreateFixedObject(RegSizeInBytes, VaArgOffset, true);
3811 SDValue PtrOff = DAG.getFrameIndex(FI, getPointerTy(DAG.getDataLayout())); 3878 SDValue PtrOff = DAG.getFrameIndex(FI, getPointerTy(DAG.getDataLayout()));
3812 SDValue Store = DAG.getStore(Chain, DL, ArgValue, PtrOff, 3879 SDValue Store =
3813 MachinePointerInfo(), false, false, 0); 3880 DAG.getStore(Chain, DL, ArgValue, PtrOff, MachinePointerInfo());
3814 cast<StoreSDNode>(Store.getNode())->getMemOperand()->setValue( 3881 cast<StoreSDNode>(Store.getNode())->getMemOperand()->setValue(
3815 (Value *)nullptr); 3882 (Value *)nullptr);
3816 OutChains.push_back(Store); 3883 OutChains.push_back(Store);
3817 } 3884 }
3818 } 3885 }
3860 } 3927 }
3861 3928
3862 State->addInRegsParamInfo(FirstReg, FirstReg + NumRegs); 3929 State->addInRegsParamInfo(FirstReg, FirstReg + NumRegs);
3863 } 3930 }
3864 3931
3865 MachineBasicBlock * 3932 MachineBasicBlock *MipsTargetLowering::emitPseudoSELECT(MachineInstr &MI,
3866 MipsTargetLowering::emitPseudoSELECT(MachineInstr *MI, MachineBasicBlock *BB, 3933 MachineBasicBlock *BB,
3867 bool isFPCmp, unsigned Opc) const { 3934 bool isFPCmp,
3935 unsigned Opc) const {
3868 assert(!(Subtarget.hasMips4() || Subtarget.hasMips32()) && 3936 assert(!(Subtarget.hasMips4() || Subtarget.hasMips32()) &&
3869 "Subtarget already supports SELECT nodes with the use of" 3937 "Subtarget already supports SELECT nodes with the use of"
3870 "conditional-move instructions."); 3938 "conditional-move instructions.");
3871 3939
3872 const TargetInstrInfo *TII = 3940 const TargetInstrInfo *TII =
3873 Subtarget.getInstrInfo(); 3941 Subtarget.getInstrInfo();
3874 DebugLoc DL = MI->getDebugLoc(); 3942 DebugLoc DL = MI.getDebugLoc();
3875 3943
3876 // To "insert" a SELECT instruction, we actually have to insert the 3944 // To "insert" a SELECT instruction, we actually have to insert the
3877 // diamond control-flow pattern. The incoming instruction knows the 3945 // diamond control-flow pattern. The incoming instruction knows the
3878 // destination vreg to set, the condition code register to branch on, the 3946 // destination vreg to set, the condition code register to branch on, the
3879 // true/false values to select between, and a branch opcode to use. 3947 // true/false values to select between, and a branch opcode to use.
3903 BB->addSuccessor(sinkMBB); 3971 BB->addSuccessor(sinkMBB);
3904 3972
3905 if (isFPCmp) { 3973 if (isFPCmp) {
3906 // bc1[tf] cc, sinkMBB 3974 // bc1[tf] cc, sinkMBB
3907 BuildMI(BB, DL, TII->get(Opc)) 3975 BuildMI(BB, DL, TII->get(Opc))
3908 .addReg(MI->getOperand(1).getReg()) 3976 .addReg(MI.getOperand(1).getReg())
3909 .addMBB(sinkMBB); 3977 .addMBB(sinkMBB);
3910 } else { 3978 } else {
3911 // bne rs, $0, sinkMBB 3979 // bne rs, $0, sinkMBB
3912 BuildMI(BB, DL, TII->get(Opc)) 3980 BuildMI(BB, DL, TII->get(Opc))
3913 .addReg(MI->getOperand(1).getReg()) 3981 .addReg(MI.getOperand(1).getReg())
3914 .addReg(Mips::ZERO) 3982 .addReg(Mips::ZERO)
3915 .addMBB(sinkMBB); 3983 .addMBB(sinkMBB);
3916 } 3984 }
3917 3985
3918 // copy0MBB: 3986 // copy0MBB:
3919 // %FalseValue = ... 3987 // %FalseValue = ...
3920 // # fallthrough to sinkMBB 3988 // # fallthrough to sinkMBB
3926 // sinkMBB: 3994 // sinkMBB:
3927 // %Result = phi [ %TrueValue, thisMBB ], [ %FalseValue, copy0MBB ] 3995 // %Result = phi [ %TrueValue, thisMBB ], [ %FalseValue, copy0MBB ]
3928 // ... 3996 // ...
3929 BB = sinkMBB; 3997 BB = sinkMBB;
3930 3998
3931 BuildMI(*BB, BB->begin(), DL, 3999 BuildMI(*BB, BB->begin(), DL, TII->get(Mips::PHI), MI.getOperand(0).getReg())
3932 TII->get(Mips::PHI), MI->getOperand(0).getReg()) 4000 .addReg(MI.getOperand(2).getReg())
3933 .addReg(MI->getOperand(2).getReg()).addMBB(thisMBB) 4001 .addMBB(thisMBB)
3934 .addReg(MI->getOperand(3).getReg()).addMBB(copy0MBB); 4002 .addReg(MI.getOperand(3).getReg())
3935 4003 .addMBB(copy0MBB);
3936 MI->eraseFromParent(); // The pseudo instruction is gone now. 4004
4005 MI.eraseFromParent(); // The pseudo instruction is gone now.
3937 4006
3938 return BB; 4007 return BB;
3939 } 4008 }
3940 4009
3941 // FIXME? Maybe this could be a TableGen attribute on some registers and 4010 // FIXME? Maybe this could be a TableGen attribute on some registers and