Mercurial > hg > CbC > CbC_llvm
comparison lib/Target/Mips/MipsISelLowering.cpp @ 95:afa8332a0e37 LLVM3.8
LLVM 3.8
author | Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 13 Oct 2015 17:48:58 +0900 |
parents | 60c9769439b8 |
children | 7d135dc70f03 |
comparison
equal
deleted
inserted
replaced
84:f3e34b893a5f | 95:afa8332a0e37 |
---|---|
25 #include "llvm/CodeGen/MachineFrameInfo.h" | 25 #include "llvm/CodeGen/MachineFrameInfo.h" |
26 #include "llvm/CodeGen/MachineFunction.h" | 26 #include "llvm/CodeGen/MachineFunction.h" |
27 #include "llvm/CodeGen/MachineInstrBuilder.h" | 27 #include "llvm/CodeGen/MachineInstrBuilder.h" |
28 #include "llvm/CodeGen/MachineJumpTableInfo.h" | 28 #include "llvm/CodeGen/MachineJumpTableInfo.h" |
29 #include "llvm/CodeGen/MachineRegisterInfo.h" | 29 #include "llvm/CodeGen/MachineRegisterInfo.h" |
30 #include "llvm/CodeGen/FunctionLoweringInfo.h" | |
30 #include "llvm/CodeGen/SelectionDAGISel.h" | 31 #include "llvm/CodeGen/SelectionDAGISel.h" |
31 #include "llvm/CodeGen/ValueTypes.h" | 32 #include "llvm/CodeGen/ValueTypes.h" |
32 #include "llvm/IR/CallingConv.h" | 33 #include "llvm/IR/CallingConv.h" |
33 #include "llvm/IR/DerivedTypes.h" | 34 #include "llvm/IR/DerivedTypes.h" |
34 #include "llvm/IR/GlobalVariable.h" | 35 #include "llvm/IR/GlobalVariable.h" |
51 static cl::opt<bool> | 52 static cl::opt<bool> |
52 NoZeroDivCheck("mno-check-zero-division", cl::Hidden, | 53 NoZeroDivCheck("mno-check-zero-division", cl::Hidden, |
53 cl::desc("MIPS: Don't trap on integer division by zero."), | 54 cl::desc("MIPS: Don't trap on integer division by zero."), |
54 cl::init(false)); | 55 cl::init(false)); |
55 | 56 |
56 cl::opt<bool> | |
57 EnableMipsFastISel("mips-fast-isel", cl::Hidden, | |
58 cl::desc("Allow mips-fast-isel to be used"), | |
59 cl::init(false)); | |
60 | |
61 static const MCPhysReg Mips64DPRegs[8] = { | 57 static const MCPhysReg Mips64DPRegs[8] = { |
62 Mips::D12_64, Mips::D13_64, Mips::D14_64, Mips::D15_64, | 58 Mips::D12_64, Mips::D13_64, Mips::D14_64, Mips::D15_64, |
63 Mips::D16_64, Mips::D17_64, Mips::D18_64, Mips::D19_64 | 59 Mips::D16_64, Mips::D17_64, Mips::D18_64, Mips::D19_64 |
64 }; | 60 }; |
65 | 61 |
110 return DAG.getTargetConstantPool(N->getConstVal(), Ty, N->getAlignment(), | 106 return DAG.getTargetConstantPool(N->getConstVal(), Ty, N->getAlignment(), |
111 N->getOffset(), Flag); | 107 N->getOffset(), Flag); |
112 } | 108 } |
113 | 109 |
114 const char *MipsTargetLowering::getTargetNodeName(unsigned Opcode) const { | 110 const char *MipsTargetLowering::getTargetNodeName(unsigned Opcode) const { |
115 switch (Opcode) { | 111 switch ((MipsISD::NodeType)Opcode) { |
112 case MipsISD::FIRST_NUMBER: break; | |
116 case MipsISD::JmpLink: return "MipsISD::JmpLink"; | 113 case MipsISD::JmpLink: return "MipsISD::JmpLink"; |
117 case MipsISD::TailCall: return "MipsISD::TailCall"; | 114 case MipsISD::TailCall: return "MipsISD::TailCall"; |
118 case MipsISD::Hi: return "MipsISD::Hi"; | 115 case MipsISD::Hi: return "MipsISD::Hi"; |
119 case MipsISD::Lo: return "MipsISD::Lo"; | 116 case MipsISD::Lo: return "MipsISD::Lo"; |
120 case MipsISD::GPRel: return "MipsISD::GPRel"; | 117 case MipsISD::GPRel: return "MipsISD::GPRel"; |
140 case MipsISD::DivRem16: return "MipsISD::DivRem16"; | 137 case MipsISD::DivRem16: return "MipsISD::DivRem16"; |
141 case MipsISD::DivRemU16: return "MipsISD::DivRemU16"; | 138 case MipsISD::DivRemU16: return "MipsISD::DivRemU16"; |
142 case MipsISD::BuildPairF64: return "MipsISD::BuildPairF64"; | 139 case MipsISD::BuildPairF64: return "MipsISD::BuildPairF64"; |
143 case MipsISD::ExtractElementF64: return "MipsISD::ExtractElementF64"; | 140 case MipsISD::ExtractElementF64: return "MipsISD::ExtractElementF64"; |
144 case MipsISD::Wrapper: return "MipsISD::Wrapper"; | 141 case MipsISD::Wrapper: return "MipsISD::Wrapper"; |
142 case MipsISD::DynAlloc: return "MipsISD::DynAlloc"; | |
145 case MipsISD::Sync: return "MipsISD::Sync"; | 143 case MipsISD::Sync: return "MipsISD::Sync"; |
146 case MipsISD::Ext: return "MipsISD::Ext"; | 144 case MipsISD::Ext: return "MipsISD::Ext"; |
147 case MipsISD::Ins: return "MipsISD::Ins"; | 145 case MipsISD::Ins: return "MipsISD::Ins"; |
148 case MipsISD::LWL: return "MipsISD::LWL"; | 146 case MipsISD::LWL: return "MipsISD::LWL"; |
149 case MipsISD::LWR: return "MipsISD::LWR"; | 147 case MipsISD::LWR: return "MipsISD::LWR"; |
159 case MipsISD::EXTR_W: return "MipsISD::EXTR_W"; | 157 case MipsISD::EXTR_W: return "MipsISD::EXTR_W"; |
160 case MipsISD::EXTR_R_W: return "MipsISD::EXTR_R_W"; | 158 case MipsISD::EXTR_R_W: return "MipsISD::EXTR_R_W"; |
161 case MipsISD::EXTR_RS_W: return "MipsISD::EXTR_RS_W"; | 159 case MipsISD::EXTR_RS_W: return "MipsISD::EXTR_RS_W"; |
162 case MipsISD::SHILO: return "MipsISD::SHILO"; | 160 case MipsISD::SHILO: return "MipsISD::SHILO"; |
163 case MipsISD::MTHLIP: return "MipsISD::MTHLIP"; | 161 case MipsISD::MTHLIP: return "MipsISD::MTHLIP"; |
162 case MipsISD::MULSAQ_S_W_PH: return "MipsISD::MULSAQ_S_W_PH"; | |
163 case MipsISD::MAQ_S_W_PHL: return "MipsISD::MAQ_S_W_PHL"; | |
164 case MipsISD::MAQ_S_W_PHR: return "MipsISD::MAQ_S_W_PHR"; | |
165 case MipsISD::MAQ_SA_W_PHL: return "MipsISD::MAQ_SA_W_PHL"; | |
166 case MipsISD::MAQ_SA_W_PHR: return "MipsISD::MAQ_SA_W_PHR"; | |
167 case MipsISD::DPAU_H_QBL: return "MipsISD::DPAU_H_QBL"; | |
168 case MipsISD::DPAU_H_QBR: return "MipsISD::DPAU_H_QBR"; | |
169 case MipsISD::DPSU_H_QBL: return "MipsISD::DPSU_H_QBL"; | |
170 case MipsISD::DPSU_H_QBR: return "MipsISD::DPSU_H_QBR"; | |
171 case MipsISD::DPAQ_S_W_PH: return "MipsISD::DPAQ_S_W_PH"; | |
172 case MipsISD::DPSQ_S_W_PH: return "MipsISD::DPSQ_S_W_PH"; | |
173 case MipsISD::DPAQ_SA_L_W: return "MipsISD::DPAQ_SA_L_W"; | |
174 case MipsISD::DPSQ_SA_L_W: return "MipsISD::DPSQ_SA_L_W"; | |
175 case MipsISD::DPA_W_PH: return "MipsISD::DPA_W_PH"; | |
176 case MipsISD::DPS_W_PH: return "MipsISD::DPS_W_PH"; | |
177 case MipsISD::DPAQX_S_W_PH: return "MipsISD::DPAQX_S_W_PH"; | |
178 case MipsISD::DPAQX_SA_W_PH: return "MipsISD::DPAQX_SA_W_PH"; | |
179 case MipsISD::DPAX_W_PH: return "MipsISD::DPAX_W_PH"; | |
180 case MipsISD::DPSX_W_PH: return "MipsISD::DPSX_W_PH"; | |
181 case MipsISD::DPSQX_S_W_PH: return "MipsISD::DPSQX_S_W_PH"; | |
182 case MipsISD::DPSQX_SA_W_PH: return "MipsISD::DPSQX_SA_W_PH"; | |
183 case MipsISD::MULSA_W_PH: return "MipsISD::MULSA_W_PH"; | |
164 case MipsISD::MULT: return "MipsISD::MULT"; | 184 case MipsISD::MULT: return "MipsISD::MULT"; |
165 case MipsISD::MULTU: return "MipsISD::MULTU"; | 185 case MipsISD::MULTU: return "MipsISD::MULTU"; |
166 case MipsISD::MADD_DSP: return "MipsISD::MADD_DSP"; | 186 case MipsISD::MADD_DSP: return "MipsISD::MADD_DSP"; |
167 case MipsISD::MADDU_DSP: return "MipsISD::MADDU_DSP"; | 187 case MipsISD::MADDU_DSP: return "MipsISD::MADDU_DSP"; |
168 case MipsISD::MSUB_DSP: return "MipsISD::MSUB_DSP"; | 188 case MipsISD::MSUB_DSP: return "MipsISD::MSUB_DSP"; |
195 case MipsISD::ILVL: return "MipsISD::ILVL"; | 215 case MipsISD::ILVL: return "MipsISD::ILVL"; |
196 case MipsISD::ILVR: return "MipsISD::ILVR"; | 216 case MipsISD::ILVR: return "MipsISD::ILVR"; |
197 case MipsISD::PCKEV: return "MipsISD::PCKEV"; | 217 case MipsISD::PCKEV: return "MipsISD::PCKEV"; |
198 case MipsISD::PCKOD: return "MipsISD::PCKOD"; | 218 case MipsISD::PCKOD: return "MipsISD::PCKOD"; |
199 case MipsISD::INSVE: return "MipsISD::INSVE"; | 219 case MipsISD::INSVE: return "MipsISD::INSVE"; |
200 default: return nullptr; | 220 } |
201 } | 221 return nullptr; |
202 } | 222 } |
203 | 223 |
204 MipsTargetLowering::MipsTargetLowering(const MipsTargetMachine &TM, | 224 MipsTargetLowering::MipsTargetLowering(const MipsTargetMachine &TM, |
205 const MipsSubtarget &STI) | 225 const MipsSubtarget &STI) |
206 : TargetLowering(TM), Subtarget(STI), ABI(TM.getABI()) { | 226 : TargetLowering(TM), Subtarget(STI), ABI(TM.getABI()) { |
219 setLoadExtAction(ISD::EXTLOAD, VT, MVT::i1, Promote); | 239 setLoadExtAction(ISD::EXTLOAD, VT, MVT::i1, Promote); |
220 setLoadExtAction(ISD::ZEXTLOAD, VT, MVT::i1, Promote); | 240 setLoadExtAction(ISD::ZEXTLOAD, VT, MVT::i1, Promote); |
221 setLoadExtAction(ISD::SEXTLOAD, VT, MVT::i1, Promote); | 241 setLoadExtAction(ISD::SEXTLOAD, VT, MVT::i1, Promote); |
222 } | 242 } |
223 | 243 |
224 // MIPS doesn't have extending float->double load/store | 244 // MIPS doesn't have extending float->double load/store. Set LoadExtAction |
225 for (MVT VT : MVT::fp_valuetypes()) | 245 // for f32, f16 |
246 for (MVT VT : MVT::fp_valuetypes()) { | |
226 setLoadExtAction(ISD::EXTLOAD, VT, MVT::f32, Expand); | 247 setLoadExtAction(ISD::EXTLOAD, VT, MVT::f32, Expand); |
248 setLoadExtAction(ISD::EXTLOAD, VT, MVT::f16, Expand); | |
249 } | |
250 | |
251 // Set LoadExtAction for f16 vectors to Expand | |
252 for (MVT VT : MVT::fp_vector_valuetypes()) { | |
253 MVT F16VT = MVT::getVectorVT(MVT::f16, VT.getVectorNumElements()); | |
254 if (F16VT.isValid()) | |
255 setLoadExtAction(ISD::EXTLOAD, VT, F16VT, Expand); | |
256 } | |
257 | |
258 setTruncStoreAction(MVT::f32, MVT::f16, Expand); | |
259 setTruncStoreAction(MVT::f64, MVT::f16, Expand); | |
260 | |
227 setTruncStoreAction(MVT::f64, MVT::f32, Expand); | 261 setTruncStoreAction(MVT::f64, MVT::f32, Expand); |
228 | 262 |
229 // Used by legalize types to correctly generate the setcc result. | 263 // Used by legalize types to correctly generate the setcc result. |
230 // Without this, every float setcc comes with a AND/OR with the result, | 264 // Without this, every float setcc comes with a AND/OR with the result, |
231 // we don't want this, since the fpcmp result goes to a flag register, | 265 // we don't want this, since the fpcmp result goes to a flag register, |
337 setOperationAction(ISD::FMA, MVT::f32, Expand); | 371 setOperationAction(ISD::FMA, MVT::f32, Expand); |
338 setOperationAction(ISD::FMA, MVT::f64, Expand); | 372 setOperationAction(ISD::FMA, MVT::f64, Expand); |
339 setOperationAction(ISD::FREM, MVT::f32, Expand); | 373 setOperationAction(ISD::FREM, MVT::f32, Expand); |
340 setOperationAction(ISD::FREM, MVT::f64, Expand); | 374 setOperationAction(ISD::FREM, MVT::f64, Expand); |
341 | 375 |
376 // Lower f16 conversion operations into library calls | |
377 setOperationAction(ISD::FP16_TO_FP, MVT::f32, Expand); | |
378 setOperationAction(ISD::FP_TO_FP16, MVT::f32, Expand); | |
379 setOperationAction(ISD::FP16_TO_FP, MVT::f64, Expand); | |
380 setOperationAction(ISD::FP_TO_FP16, MVT::f64, Expand); | |
381 | |
342 setOperationAction(ISD::EH_RETURN, MVT::Other, Custom); | 382 setOperationAction(ISD::EH_RETURN, MVT::Other, Custom); |
343 | 383 |
344 setOperationAction(ISD::VASTART, MVT::Other, Custom); | 384 setOperationAction(ISD::VASTART, MVT::Other, Custom); |
345 setOperationAction(ISD::VAARG, MVT::Other, Custom); | 385 setOperationAction(ISD::VAARG, MVT::Other, Custom); |
346 setOperationAction(ISD::VACOPY, MVT::Other, Expand); | 386 setOperationAction(ISD::VACOPY, MVT::Other, Expand); |
415 | 455 |
416 // Create a fast isel object. | 456 // Create a fast isel object. |
417 FastISel * | 457 FastISel * |
418 MipsTargetLowering::createFastISel(FunctionLoweringInfo &funcInfo, | 458 MipsTargetLowering::createFastISel(FunctionLoweringInfo &funcInfo, |
419 const TargetLibraryInfo *libInfo) const { | 459 const TargetLibraryInfo *libInfo) const { |
420 if (!EnableMipsFastISel) | 460 if (!funcInfo.MF->getTarget().Options.EnableFastISel) |
421 return TargetLowering::createFastISel(funcInfo, libInfo); | 461 return TargetLowering::createFastISel(funcInfo, libInfo); |
422 return Mips::createFastISel(funcInfo, libInfo); | 462 return Mips::createFastISel(funcInfo, libInfo); |
423 } | 463 } |
424 | 464 |
425 EVT MipsTargetLowering::getSetCCResultType(LLVMContext &, EVT VT) const { | 465 EVT MipsTargetLowering::getSetCCResultType(const DataLayout &, LLVMContext &, |
466 EVT VT) const { | |
426 if (!VT.isVector()) | 467 if (!VT.isVector()) |
427 return MVT::i32; | 468 return MVT::i32; |
428 return VT.changeVectorElementTypeToInteger(); | 469 return VT.changeVectorElementTypeToInteger(); |
429 } | 470 } |
430 | 471 |
522 // Assume the 3rd operand is a CondCodeSDNode. Add code to check the type of | 563 // Assume the 3rd operand is a CondCodeSDNode. Add code to check the type of |
523 // node if necessary. | 564 // node if necessary. |
524 ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(2))->get(); | 565 ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(2))->get(); |
525 | 566 |
526 return DAG.getNode(MipsISD::FPCmp, DL, MVT::Glue, LHS, RHS, | 567 return DAG.getNode(MipsISD::FPCmp, DL, MVT::Glue, LHS, RHS, |
527 DAG.getConstant(condCodeToFCC(CC), MVT::i32)); | 568 DAG.getConstant(condCodeToFCC(CC), DL, MVT::i32)); |
528 } | 569 } |
529 | 570 |
530 // Creates and returns a CMovFPT/F node. | 571 // Creates and returns a CMovFPT/F node. |
531 static SDValue createCMovFP(SelectionDAG &DAG, SDValue Cond, SDValue True, | 572 static SDValue createCMovFP(SelectionDAG &DAG, SDValue Cond, SDValue True, |
532 SDValue False, SDLoc DL) { | 573 SDValue False, SDLoc DL) { |
615 | 656 |
616 // Couldn't optimize. | 657 // Couldn't optimize. |
617 return SDValue(); | 658 return SDValue(); |
618 } | 659 } |
619 | 660 |
661 static SDValue performCMovFPCombine(SDNode *N, SelectionDAG &DAG, | |
662 TargetLowering::DAGCombinerInfo &DCI, | |
663 const MipsSubtarget &Subtarget) { | |
664 if (DCI.isBeforeLegalizeOps()) | |
665 return SDValue(); | |
666 | |
667 SDValue ValueIfTrue = N->getOperand(0), ValueIfFalse = N->getOperand(2); | |
668 | |
669 ConstantSDNode *FalseC = dyn_cast<ConstantSDNode>(ValueIfFalse); | |
670 if (!FalseC || FalseC->getZExtValue()) | |
671 return SDValue(); | |
672 | |
673 // Since RHS (False) is 0, we swap the order of the True/False operands | |
674 // (obviously also inverting the condition) so that we can | |
675 // take advantage of conditional moves using the $0 register. | |
676 // Example: | |
677 // return (a != 0) ? x : 0; | |
678 // load $reg, x | |
679 // movz $reg, $0, a | |
680 unsigned Opc = (N->getOpcode() == MipsISD::CMovFP_T) ? MipsISD::CMovFP_F : | |
681 MipsISD::CMovFP_T; | |
682 | |
683 SDValue FCC = N->getOperand(1), Glue = N->getOperand(3); | |
684 return DAG.getNode(Opc, SDLoc(N), ValueIfFalse.getValueType(), | |
685 ValueIfFalse, FCC, ValueIfTrue, Glue); | |
686 } | |
687 | |
620 static SDValue performANDCombine(SDNode *N, SelectionDAG &DAG, | 688 static SDValue performANDCombine(SDNode *N, SelectionDAG &DAG, |
621 TargetLowering::DAGCombinerInfo &DCI, | 689 TargetLowering::DAGCombinerInfo &DCI, |
622 const MipsSubtarget &Subtarget) { | 690 const MipsSubtarget &Subtarget) { |
623 // Pattern match EXT. | 691 // Pattern match EXT. |
624 // $dst = and ((sra or srl) $src , pos), (2**size - 1) | 692 // $dst = and ((sra or srl) $src , pos), (2**size - 1) |
650 // and Pos exceeds the word's size. | 718 // and Pos exceeds the word's size. |
651 EVT ValTy = N->getValueType(0); | 719 EVT ValTy = N->getValueType(0); |
652 if (SMPos != 0 || Pos + SMSize > ValTy.getSizeInBits()) | 720 if (SMPos != 0 || Pos + SMSize > ValTy.getSizeInBits()) |
653 return SDValue(); | 721 return SDValue(); |
654 | 722 |
655 return DAG.getNode(MipsISD::Ext, SDLoc(N), ValTy, | 723 SDLoc DL(N); |
656 ShiftRight.getOperand(0), DAG.getConstant(Pos, MVT::i32), | 724 return DAG.getNode(MipsISD::Ext, DL, ValTy, |
657 DAG.getConstant(SMSize, MVT::i32)); | 725 ShiftRight.getOperand(0), |
726 DAG.getConstant(Pos, DL, MVT::i32), | |
727 DAG.getConstant(SMSize, DL, MVT::i32)); | |
658 } | 728 } |
659 | 729 |
660 static SDValue performORCombine(SDNode *N, SelectionDAG &DAG, | 730 static SDValue performORCombine(SDNode *N, SelectionDAG &DAG, |
661 TargetLowering::DAGCombinerInfo &DCI, | 731 TargetLowering::DAGCombinerInfo &DCI, |
662 const MipsSubtarget &Subtarget) { | 732 const MipsSubtarget &Subtarget) { |
704 // same. | 774 // same. |
705 EVT ValTy = N->getValueType(0); | 775 EVT ValTy = N->getValueType(0); |
706 if ((Shamt != SMPos0) || (SMPos0 + SMSize0 > ValTy.getSizeInBits())) | 776 if ((Shamt != SMPos0) || (SMPos0 + SMSize0 > ValTy.getSizeInBits())) |
707 return SDValue(); | 777 return SDValue(); |
708 | 778 |
709 return DAG.getNode(MipsISD::Ins, SDLoc(N), ValTy, Shl.getOperand(0), | 779 SDLoc DL(N); |
710 DAG.getConstant(SMPos0, MVT::i32), | 780 return DAG.getNode(MipsISD::Ins, DL, ValTy, Shl.getOperand(0), |
711 DAG.getConstant(SMSize0, MVT::i32), And0.getOperand(0)); | 781 DAG.getConstant(SMPos0, DL, MVT::i32), |
782 DAG.getConstant(SMSize0, DL, MVT::i32), | |
783 And0.getOperand(0)); | |
712 } | 784 } |
713 | 785 |
714 static SDValue performADDCombine(SDNode *N, SelectionDAG &DAG, | 786 static SDValue performADDCombine(SDNode *N, SelectionDAG &DAG, |
715 TargetLowering::DAGCombinerInfo &DCI, | 787 TargetLowering::DAGCombinerInfo &DCI, |
716 const MipsSubtarget &Subtarget) { | 788 const MipsSubtarget &Subtarget) { |
748 case ISD::SDIVREM: | 820 case ISD::SDIVREM: |
749 case ISD::UDIVREM: | 821 case ISD::UDIVREM: |
750 return performDivRemCombine(N, DAG, DCI, Subtarget); | 822 return performDivRemCombine(N, DAG, DCI, Subtarget); |
751 case ISD::SELECT: | 823 case ISD::SELECT: |
752 return performSELECTCombine(N, DAG, DCI, Subtarget); | 824 return performSELECTCombine(N, DAG, DCI, Subtarget); |
825 case MipsISD::CMovFP_F: | |
826 case MipsISD::CMovFP_T: | |
827 return performCMovFPCombine(N, DAG, DCI, Subtarget); | |
753 case ISD::AND: | 828 case ISD::AND: |
754 return performANDCombine(N, DAG, DCI, Subtarget); | 829 return performANDCombine(N, DAG, DCI, Subtarget); |
755 case ISD::OR: | 830 case ISD::OR: |
756 return performORCombine(N, DAG, DCI, Subtarget); | 831 return performORCombine(N, DAG, DCI, Subtarget); |
757 case ISD::ADD: | 832 case ISD::ADD: |
1499 SDValue MipsTargetLowering::lowerBR_JT(SDValue Op, SelectionDAG &DAG) const { | 1574 SDValue MipsTargetLowering::lowerBR_JT(SDValue Op, SelectionDAG &DAG) const { |
1500 SDValue Chain = Op.getOperand(0); | 1575 SDValue Chain = Op.getOperand(0); |
1501 SDValue Table = Op.getOperand(1); | 1576 SDValue Table = Op.getOperand(1); |
1502 SDValue Index = Op.getOperand(2); | 1577 SDValue Index = Op.getOperand(2); |
1503 SDLoc DL(Op); | 1578 SDLoc DL(Op); |
1504 EVT PTy = getPointerTy(); | 1579 auto &TD = DAG.getDataLayout(); |
1580 EVT PTy = getPointerTy(TD); | |
1505 unsigned EntrySize = | 1581 unsigned EntrySize = |
1506 DAG.getMachineFunction().getJumpTableInfo()->getEntrySize(*getDataLayout()); | 1582 DAG.getMachineFunction().getJumpTableInfo()->getEntrySize(TD); |
1507 | 1583 |
1508 Index = DAG.getNode(ISD::MUL, DL, PTy, Index, | 1584 Index = DAG.getNode(ISD::MUL, DL, PTy, Index, |
1509 DAG.getConstant(EntrySize, PTy)); | 1585 DAG.getConstant(EntrySize, DL, PTy)); |
1510 SDValue Addr = DAG.getNode(ISD::ADD, DL, PTy, Index, Table); | 1586 SDValue Addr = DAG.getNode(ISD::ADD, DL, PTy, Index, Table); |
1511 | 1587 |
1512 EVT MemVT = EVT::getIntegerVT(*DAG.getContext(), EntrySize * 8); | 1588 EVT MemVT = EVT::getIntegerVT(*DAG.getContext(), EntrySize * 8); |
1513 Addr = DAG.getExtLoad(ISD::SEXTLOAD, DL, PTy, Chain, Addr, | 1589 Addr = |
1514 MachinePointerInfo::getJumpTable(), MemVT, false, false, | 1590 DAG.getExtLoad(ISD::SEXTLOAD, DL, PTy, Chain, Addr, |
1515 false, 0); | 1591 MachinePointerInfo::getJumpTable(DAG.getMachineFunction()), |
1592 MemVT, false, false, false, 0); | |
1516 Chain = Addr.getValue(1); | 1593 Chain = Addr.getValue(1); |
1517 | 1594 |
1518 if ((getTargetMachine().getRelocationModel() == Reloc::PIC_) || ABI.IsN64()) { | 1595 if ((getTargetMachine().getRelocationModel() == Reloc::PIC_) || ABI.IsN64()) { |
1519 // For PIC, the sequence is: | 1596 // For PIC, the sequence is: |
1520 // BRIND(load(Jumptable + index) + RelocBase) | 1597 // BRIND(load(Jumptable + index) + RelocBase) |
1542 | 1619 |
1543 SDValue CCNode = CondRes.getOperand(2); | 1620 SDValue CCNode = CondRes.getOperand(2); |
1544 Mips::CondCode CC = | 1621 Mips::CondCode CC = |
1545 (Mips::CondCode)cast<ConstantSDNode>(CCNode)->getZExtValue(); | 1622 (Mips::CondCode)cast<ConstantSDNode>(CCNode)->getZExtValue(); |
1546 unsigned Opc = invertFPCondCodeUser(CC) ? Mips::BRANCH_F : Mips::BRANCH_T; | 1623 unsigned Opc = invertFPCondCodeUser(CC) ? Mips::BRANCH_F : Mips::BRANCH_T; |
1547 SDValue BrCode = DAG.getConstant(Opc, MVT::i32); | 1624 SDValue BrCode = DAG.getConstant(Opc, DL, MVT::i32); |
1548 SDValue FCC0 = DAG.getRegister(Mips::FCC0, MVT::i32); | 1625 SDValue FCC0 = DAG.getRegister(Mips::FCC0, MVT::i32); |
1549 return DAG.getNode(MipsISD::FPBrcond, DL, Op.getValueType(), Chain, BrCode, | 1626 return DAG.getNode(MipsISD::FPBrcond, DL, Op.getValueType(), Chain, BrCode, |
1550 FCC0, Dest, CondRes); | 1627 FCC0, Dest, CondRes); |
1551 } | 1628 } |
1552 | 1629 |
1567 SDValue MipsTargetLowering:: | 1644 SDValue MipsTargetLowering:: |
1568 lowerSELECT_CC(SDValue Op, SelectionDAG &DAG) const | 1645 lowerSELECT_CC(SDValue Op, SelectionDAG &DAG) const |
1569 { | 1646 { |
1570 SDLoc DL(Op); | 1647 SDLoc DL(Op); |
1571 EVT Ty = Op.getOperand(0).getValueType(); | 1648 EVT Ty = Op.getOperand(0).getValueType(); |
1572 SDValue Cond = DAG.getNode(ISD::SETCC, DL, | 1649 SDValue Cond = |
1573 getSetCCResultType(*DAG.getContext(), Ty), | 1650 DAG.getNode(ISD::SETCC, DL, getSetCCResultType(DAG.getDataLayout(), |
1574 Op.getOperand(0), Op.getOperand(1), | 1651 *DAG.getContext(), Ty), |
1575 Op.getOperand(4)); | 1652 Op.getOperand(0), Op.getOperand(1), Op.getOperand(4)); |
1576 | 1653 |
1577 return DAG.getNode(ISD::SELECT, DL, Op.getValueType(), Cond, Op.getOperand(2), | 1654 return DAG.getNode(ISD::SELECT, DL, Op.getValueType(), Cond, Op.getOperand(2), |
1578 Op.getOperand(3)); | 1655 Op.getOperand(3)); |
1579 } | 1656 } |
1580 | 1657 |
1583 SDValue Cond = createFPCmp(DAG, Op); | 1660 SDValue Cond = createFPCmp(DAG, Op); |
1584 | 1661 |
1585 assert(Cond.getOpcode() == MipsISD::FPCmp && | 1662 assert(Cond.getOpcode() == MipsISD::FPCmp && |
1586 "Floating point operand expected."); | 1663 "Floating point operand expected."); |
1587 | 1664 |
1588 SDValue True = DAG.getConstant(1, MVT::i32); | 1665 SDLoc DL(Op); |
1589 SDValue False = DAG.getConstant(0, MVT::i32); | 1666 SDValue True = DAG.getConstant(1, DL, MVT::i32); |
1590 | 1667 SDValue False = DAG.getConstant(0, DL, MVT::i32); |
1591 return createCMovFP(DAG, Cond, True, False, SDLoc(Op)); | 1668 |
1669 return createCMovFP(DAG, Cond, True, False, DL); | |
1592 } | 1670 } |
1593 | 1671 |
1594 SDValue MipsTargetLowering::lowerGlobalAddress(SDValue Op, | 1672 SDValue MipsTargetLowering::lowerGlobalAddress(SDValue Op, |
1595 SelectionDAG &DAG) const { | 1673 SelectionDAG &DAG) const { |
1596 EVT Ty = Op.getValueType(); | 1674 EVT Ty = Op.getValueType(); |
1611 | 1689 |
1612 if (GV->hasInternalLinkage() || (GV->hasLocalLinkage() && !isa<Function>(GV))) | 1690 if (GV->hasInternalLinkage() || (GV->hasLocalLinkage() && !isa<Function>(GV))) |
1613 return getAddrLocal(N, SDLoc(N), Ty, DAG, ABI.IsN32() || ABI.IsN64()); | 1691 return getAddrLocal(N, SDLoc(N), Ty, DAG, ABI.IsN32() || ABI.IsN64()); |
1614 | 1692 |
1615 if (LargeGOT) | 1693 if (LargeGOT) |
1616 return getAddrGlobalLargeGOT(N, SDLoc(N), Ty, DAG, MipsII::MO_GOT_HI16, | 1694 return getAddrGlobalLargeGOT( |
1617 MipsII::MO_GOT_LO16, DAG.getEntryNode(), | 1695 N, SDLoc(N), Ty, DAG, MipsII::MO_GOT_HI16, MipsII::MO_GOT_LO16, |
1618 MachinePointerInfo::getGOT()); | 1696 DAG.getEntryNode(), |
1619 | 1697 MachinePointerInfo::getGOT(DAG.getMachineFunction())); |
1620 return getAddrGlobal(N, SDLoc(N), Ty, DAG, | 1698 |
1621 (ABI.IsN32() || ABI.IsN64()) ? MipsII::MO_GOT_DISP | 1699 return getAddrGlobal( |
1622 : MipsII::MO_GOT16, | 1700 N, SDLoc(N), Ty, DAG, |
1623 DAG.getEntryNode(), MachinePointerInfo::getGOT()); | 1701 (ABI.IsN32() || ABI.IsN64()) ? MipsII::MO_GOT_DISP : MipsII::MO_GOT16, |
1702 DAG.getEntryNode(), MachinePointerInfo::getGOT(DAG.getMachineFunction())); | |
1624 } | 1703 } |
1625 | 1704 |
1626 SDValue MipsTargetLowering::lowerBlockAddress(SDValue Op, | 1705 SDValue MipsTargetLowering::lowerBlockAddress(SDValue Op, |
1627 SelectionDAG &DAG) const { | 1706 SelectionDAG &DAG) const { |
1628 BlockAddressSDNode *N = cast<BlockAddressSDNode>(Op); | 1707 BlockAddressSDNode *N = cast<BlockAddressSDNode>(Op); |
1640 // If the relocation model is PIC, use the General Dynamic TLS Model or | 1719 // If the relocation model is PIC, use the General Dynamic TLS Model or |
1641 // Local Dynamic TLS model, otherwise use the Initial Exec or | 1720 // Local Dynamic TLS model, otherwise use the Initial Exec or |
1642 // Local Exec TLS Model. | 1721 // Local Exec TLS Model. |
1643 | 1722 |
1644 GlobalAddressSDNode *GA = cast<GlobalAddressSDNode>(Op); | 1723 GlobalAddressSDNode *GA = cast<GlobalAddressSDNode>(Op); |
1724 if (DAG.getTarget().Options.EmulatedTLS) | |
1725 return LowerToTLSEmulatedModel(GA, DAG); | |
1726 | |
1645 SDLoc DL(GA); | 1727 SDLoc DL(GA); |
1646 const GlobalValue *GV = GA->getGlobal(); | 1728 const GlobalValue *GV = GA->getGlobal(); |
1647 EVT PtrVT = getPointerTy(); | 1729 EVT PtrVT = getPointerTy(DAG.getDataLayout()); |
1648 | 1730 |
1649 TLSModel::Model model = getTargetMachine().getTLSModel(GV); | 1731 TLSModel::Model model = getTargetMachine().getTLSModel(GV); |
1650 | 1732 |
1651 if (model == TLSModel::GeneralDynamic || model == TLSModel::LocalDynamic) { | 1733 if (model == TLSModel::GeneralDynamic || model == TLSModel::LocalDynamic) { |
1652 // General Dynamic and Local Dynamic TLS Model. | 1734 // General Dynamic and Local Dynamic TLS Model. |
1734 if (getTargetMachine().getRelocationModel() != Reloc::PIC_ && !ABI.IsN64()) { | 1816 if (getTargetMachine().getRelocationModel() != Reloc::PIC_ && !ABI.IsN64()) { |
1735 const MipsTargetObjectFile *TLOF = | 1817 const MipsTargetObjectFile *TLOF = |
1736 static_cast<const MipsTargetObjectFile *>( | 1818 static_cast<const MipsTargetObjectFile *>( |
1737 getTargetMachine().getObjFileLowering()); | 1819 getTargetMachine().getObjFileLowering()); |
1738 | 1820 |
1739 if (TLOF->IsConstantInSmallSection(N->getConstVal(), getTargetMachine())) | 1821 if (TLOF->IsConstantInSmallSection(DAG.getDataLayout(), N->getConstVal(), |
1822 getTargetMachine())) | |
1740 // %gp_rel relocation | 1823 // %gp_rel relocation |
1741 return getAddrGPRel(N, SDLoc(N), Ty, DAG); | 1824 return getAddrGPRel(N, SDLoc(N), Ty, DAG); |
1742 | 1825 |
1743 return getAddrNonPIC(N, SDLoc(N), Ty, DAG); | 1826 return getAddrNonPIC(N, SDLoc(N), Ty, DAG); |
1744 } | 1827 } |
1750 MachineFunction &MF = DAG.getMachineFunction(); | 1833 MachineFunction &MF = DAG.getMachineFunction(); |
1751 MipsFunctionInfo *FuncInfo = MF.getInfo<MipsFunctionInfo>(); | 1834 MipsFunctionInfo *FuncInfo = MF.getInfo<MipsFunctionInfo>(); |
1752 | 1835 |
1753 SDLoc DL(Op); | 1836 SDLoc DL(Op); |
1754 SDValue FI = DAG.getFrameIndex(FuncInfo->getVarArgsFrameIndex(), | 1837 SDValue FI = DAG.getFrameIndex(FuncInfo->getVarArgsFrameIndex(), |
1755 getPointerTy()); | 1838 getPointerTy(MF.getDataLayout())); |
1756 | 1839 |
1757 // vastart just stores the address of the VarArgsFrameIndex slot into the | 1840 // vastart just stores the address of the VarArgsFrameIndex slot into the |
1758 // memory location argument. | 1841 // memory location argument. |
1759 const Value *SV = cast<SrcValueSDNode>(Op.getOperand(2))->getValue(); | 1842 const Value *SV = cast<SrcValueSDNode>(Op.getOperand(2))->getValue(); |
1760 return DAG.getStore(Op.getOperand(0), DL, FI, Op.getOperand(1), | 1843 return DAG.getStore(Op.getOperand(0), DL, FI, Op.getOperand(1), |
1769 unsigned Align = Node->getConstantOperandVal(3); | 1852 unsigned Align = Node->getConstantOperandVal(3); |
1770 const Value *SV = cast<SrcValueSDNode>(Node->getOperand(2))->getValue(); | 1853 const Value *SV = cast<SrcValueSDNode>(Node->getOperand(2))->getValue(); |
1771 SDLoc DL(Node); | 1854 SDLoc DL(Node); |
1772 unsigned ArgSlotSizeInBytes = (ABI.IsN32() || ABI.IsN64()) ? 8 : 4; | 1855 unsigned ArgSlotSizeInBytes = (ABI.IsN32() || ABI.IsN64()) ? 8 : 4; |
1773 | 1856 |
1774 SDValue VAListLoad = DAG.getLoad(getPointerTy(), DL, Chain, VAListPtr, | 1857 SDValue VAListLoad = |
1775 MachinePointerInfo(SV), false, false, false, | 1858 DAG.getLoad(getPointerTy(DAG.getDataLayout()), DL, Chain, VAListPtr, |
1776 0); | 1859 MachinePointerInfo(SV), false, false, false, 0); |
1777 SDValue VAList = VAListLoad; | 1860 SDValue VAList = VAListLoad; |
1778 | 1861 |
1779 // Re-align the pointer if necessary. | 1862 // Re-align the pointer if necessary. |
1780 // It should only ever be necessary for 64-bit types on O32 since the minimum | 1863 // It should only ever be necessary for 64-bit types on O32 since the minimum |
1781 // argument alignment is the same as the maximum type alignment for N32/N64. | 1864 // argument alignment is the same as the maximum type alignment for N32/N64. |
1785 // va_args for the i64 on O32 case). | 1868 // va_args for the i64 on O32 case). |
1786 if (Align > getMinStackArgumentAlignment()) { | 1869 if (Align > getMinStackArgumentAlignment()) { |
1787 assert(((Align & (Align-1)) == 0) && "Expected Align to be a power of 2"); | 1870 assert(((Align & (Align-1)) == 0) && "Expected Align to be a power of 2"); |
1788 | 1871 |
1789 VAList = DAG.getNode(ISD::ADD, DL, VAList.getValueType(), VAList, | 1872 VAList = DAG.getNode(ISD::ADD, DL, VAList.getValueType(), VAList, |
1790 DAG.getConstant(Align - 1, | 1873 DAG.getConstant(Align - 1, DL, VAList.getValueType())); |
1874 | |
1875 VAList = DAG.getNode(ISD::AND, DL, VAList.getValueType(), VAList, | |
1876 DAG.getConstant(-(int64_t)Align, DL, | |
1791 VAList.getValueType())); | 1877 VAList.getValueType())); |
1792 | |
1793 VAList = DAG.getNode(ISD::AND, DL, VAList.getValueType(), VAList, | |
1794 DAG.getConstant(-(int64_t)Align, | |
1795 VAList.getValueType())); | |
1796 } | 1878 } |
1797 | 1879 |
1798 // Increment the pointer, VAList, to the next vaarg. | 1880 // Increment the pointer, VAList, to the next vaarg. |
1799 unsigned ArgSizeInBytes = getDataLayout()->getTypeAllocSize(VT.getTypeForEVT(*DAG.getContext())); | 1881 auto &TD = DAG.getDataLayout(); |
1882 unsigned ArgSizeInBytes = | |
1883 TD.getTypeAllocSize(VT.getTypeForEVT(*DAG.getContext())); | |
1800 SDValue Tmp3 = DAG.getNode(ISD::ADD, DL, VAList.getValueType(), VAList, | 1884 SDValue Tmp3 = DAG.getNode(ISD::ADD, DL, VAList.getValueType(), VAList, |
1801 DAG.getConstant(RoundUpToAlignment(ArgSizeInBytes, ArgSlotSizeInBytes), | 1885 DAG.getConstant(RoundUpToAlignment(ArgSizeInBytes, |
1802 VAList.getValueType())); | 1886 ArgSlotSizeInBytes), |
1887 DL, VAList.getValueType())); | |
1803 // Store the incremented VAList to the legalized pointer | 1888 // Store the incremented VAList to the legalized pointer |
1804 Chain = DAG.getStore(VAListLoad.getValue(1), DL, Tmp3, VAListPtr, | 1889 Chain = DAG.getStore(VAListLoad.getValue(1), DL, Tmp3, VAListPtr, |
1805 MachinePointerInfo(SV), false, false, 0); | 1890 MachinePointerInfo(SV), false, false, 0); |
1806 | 1891 |
1807 // In big-endian mode we must adjust the pointer when the load size is smaller | 1892 // In big-endian mode we must adjust the pointer when the load size is smaller |
1810 // the correct half of the slot, and reduce the alignment from 8 (slot | 1895 // the correct half of the slot, and reduce the alignment from 8 (slot |
1811 // alignment) down to 4 (type alignment). | 1896 // alignment) down to 4 (type alignment). |
1812 if (!Subtarget.isLittle() && ArgSizeInBytes < ArgSlotSizeInBytes) { | 1897 if (!Subtarget.isLittle() && ArgSizeInBytes < ArgSlotSizeInBytes) { |
1813 unsigned Adjustment = ArgSlotSizeInBytes - ArgSizeInBytes; | 1898 unsigned Adjustment = ArgSlotSizeInBytes - ArgSizeInBytes; |
1814 VAList = DAG.getNode(ISD::ADD, DL, VAListPtr.getValueType(), VAList, | 1899 VAList = DAG.getNode(ISD::ADD, DL, VAListPtr.getValueType(), VAList, |
1815 DAG.getIntPtrConstant(Adjustment)); | 1900 DAG.getIntPtrConstant(Adjustment, DL)); |
1816 } | 1901 } |
1817 // Load the actual argument out of the pointer VAList | 1902 // Load the actual argument out of the pointer VAList |
1818 return DAG.getLoad(VT, DL, Chain, VAList, MachinePointerInfo(), false, false, | 1903 return DAG.getLoad(VT, DL, Chain, VAList, MachinePointerInfo(), false, false, |
1819 false, 0); | 1904 false, 0); |
1820 } | 1905 } |
1821 | 1906 |
1822 static SDValue lowerFCOPYSIGN32(SDValue Op, SelectionDAG &DAG, | 1907 static SDValue lowerFCOPYSIGN32(SDValue Op, SelectionDAG &DAG, |
1823 bool HasExtractInsert) { | 1908 bool HasExtractInsert) { |
1824 EVT TyX = Op.getOperand(0).getValueType(); | 1909 EVT TyX = Op.getOperand(0).getValueType(); |
1825 EVT TyY = Op.getOperand(1).getValueType(); | 1910 EVT TyY = Op.getOperand(1).getValueType(); |
1826 SDValue Const1 = DAG.getConstant(1, MVT::i32); | |
1827 SDValue Const31 = DAG.getConstant(31, MVT::i32); | |
1828 SDLoc DL(Op); | 1911 SDLoc DL(Op); |
1912 SDValue Const1 = DAG.getConstant(1, DL, MVT::i32); | |
1913 SDValue Const31 = DAG.getConstant(31, DL, MVT::i32); | |
1829 SDValue Res; | 1914 SDValue Res; |
1830 | 1915 |
1831 // If operand is of type f64, extract the upper 32-bit. Otherwise, bitcast it | 1916 // If operand is of type f64, extract the upper 32-bit. Otherwise, bitcast it |
1832 // to i32. | 1917 // to i32. |
1833 SDValue X = (TyX == MVT::f32) ? | 1918 SDValue X = (TyX == MVT::f32) ? |
1859 | 1944 |
1860 if (TyX == MVT::f32) | 1945 if (TyX == MVT::f32) |
1861 return DAG.getNode(ISD::BITCAST, DL, Op.getOperand(0).getValueType(), Res); | 1946 return DAG.getNode(ISD::BITCAST, DL, Op.getOperand(0).getValueType(), Res); |
1862 | 1947 |
1863 SDValue LowX = DAG.getNode(MipsISD::ExtractElementF64, DL, MVT::i32, | 1948 SDValue LowX = DAG.getNode(MipsISD::ExtractElementF64, DL, MVT::i32, |
1864 Op.getOperand(0), DAG.getConstant(0, MVT::i32)); | 1949 Op.getOperand(0), |
1950 DAG.getConstant(0, DL, MVT::i32)); | |
1865 return DAG.getNode(MipsISD::BuildPairF64, DL, MVT::f64, LowX, Res); | 1951 return DAG.getNode(MipsISD::BuildPairF64, DL, MVT::f64, LowX, Res); |
1866 } | 1952 } |
1867 | 1953 |
1868 static SDValue lowerFCOPYSIGN64(SDValue Op, SelectionDAG &DAG, | 1954 static SDValue lowerFCOPYSIGN64(SDValue Op, SelectionDAG &DAG, |
1869 bool HasExtractInsert) { | 1955 bool HasExtractInsert) { |
1870 unsigned WidthX = Op.getOperand(0).getValueSizeInBits(); | 1956 unsigned WidthX = Op.getOperand(0).getValueSizeInBits(); |
1871 unsigned WidthY = Op.getOperand(1).getValueSizeInBits(); | 1957 unsigned WidthY = Op.getOperand(1).getValueSizeInBits(); |
1872 EVT TyX = MVT::getIntegerVT(WidthX), TyY = MVT::getIntegerVT(WidthY); | 1958 EVT TyX = MVT::getIntegerVT(WidthX), TyY = MVT::getIntegerVT(WidthY); |
1873 SDValue Const1 = DAG.getConstant(1, MVT::i32); | |
1874 SDLoc DL(Op); | 1959 SDLoc DL(Op); |
1960 SDValue Const1 = DAG.getConstant(1, DL, MVT::i32); | |
1875 | 1961 |
1876 // Bitcast to integer nodes. | 1962 // Bitcast to integer nodes. |
1877 SDValue X = DAG.getNode(ISD::BITCAST, DL, TyX, Op.getOperand(0)); | 1963 SDValue X = DAG.getNode(ISD::BITCAST, DL, TyX, Op.getOperand(0)); |
1878 SDValue Y = DAG.getNode(ISD::BITCAST, DL, TyY, Op.getOperand(1)); | 1964 SDValue Y = DAG.getNode(ISD::BITCAST, DL, TyY, Op.getOperand(1)); |
1879 | 1965 |
1880 if (HasExtractInsert) { | 1966 if (HasExtractInsert) { |
1881 // ext E, Y, width(Y) - 1, 1 ; extract bit width(Y)-1 of Y | 1967 // ext E, Y, width(Y) - 1, 1 ; extract bit width(Y)-1 of Y |
1882 // ins X, E, width(X) - 1, 1 ; insert extracted bit at bit width(X)-1 of X | 1968 // ins X, E, width(X) - 1, 1 ; insert extracted bit at bit width(X)-1 of X |
1883 SDValue E = DAG.getNode(MipsISD::Ext, DL, TyY, Y, | 1969 SDValue E = DAG.getNode(MipsISD::Ext, DL, TyY, Y, |
1884 DAG.getConstant(WidthY - 1, MVT::i32), Const1); | 1970 DAG.getConstant(WidthY - 1, DL, MVT::i32), Const1); |
1885 | 1971 |
1886 if (WidthX > WidthY) | 1972 if (WidthX > WidthY) |
1887 E = DAG.getNode(ISD::ZERO_EXTEND, DL, TyX, E); | 1973 E = DAG.getNode(ISD::ZERO_EXTEND, DL, TyX, E); |
1888 else if (WidthY > WidthX) | 1974 else if (WidthY > WidthX) |
1889 E = DAG.getNode(ISD::TRUNCATE, DL, TyX, E); | 1975 E = DAG.getNode(ISD::TRUNCATE, DL, TyX, E); |
1890 | 1976 |
1891 SDValue I = DAG.getNode(MipsISD::Ins, DL, TyX, E, | 1977 SDValue I = DAG.getNode(MipsISD::Ins, DL, TyX, E, |
1892 DAG.getConstant(WidthX - 1, MVT::i32), Const1, X); | 1978 DAG.getConstant(WidthX - 1, DL, MVT::i32), Const1, |
1979 X); | |
1893 return DAG.getNode(ISD::BITCAST, DL, Op.getOperand(0).getValueType(), I); | 1980 return DAG.getNode(ISD::BITCAST, DL, Op.getOperand(0).getValueType(), I); |
1894 } | 1981 } |
1895 | 1982 |
1896 // (d)sll SllX, X, 1 | 1983 // (d)sll SllX, X, 1 |
1897 // (d)srl SrlX, SllX, 1 | 1984 // (d)srl SrlX, SllX, 1 |
1899 // (d)sll SllY, SrlX, width(Y)-1 | 1986 // (d)sll SllY, SrlX, width(Y)-1 |
1900 // or Or, SrlX, SllY | 1987 // or Or, SrlX, SllY |
1901 SDValue SllX = DAG.getNode(ISD::SHL, DL, TyX, X, Const1); | 1988 SDValue SllX = DAG.getNode(ISD::SHL, DL, TyX, X, Const1); |
1902 SDValue SrlX = DAG.getNode(ISD::SRL, DL, TyX, SllX, Const1); | 1989 SDValue SrlX = DAG.getNode(ISD::SRL, DL, TyX, SllX, Const1); |
1903 SDValue SrlY = DAG.getNode(ISD::SRL, DL, TyY, Y, | 1990 SDValue SrlY = DAG.getNode(ISD::SRL, DL, TyY, Y, |
1904 DAG.getConstant(WidthY - 1, MVT::i32)); | 1991 DAG.getConstant(WidthY - 1, DL, MVT::i32)); |
1905 | 1992 |
1906 if (WidthX > WidthY) | 1993 if (WidthX > WidthY) |
1907 SrlY = DAG.getNode(ISD::ZERO_EXTEND, DL, TyX, SrlY); | 1994 SrlY = DAG.getNode(ISD::ZERO_EXTEND, DL, TyX, SrlY); |
1908 else if (WidthY > WidthX) | 1995 else if (WidthY > WidthX) |
1909 SrlY = DAG.getNode(ISD::TRUNCATE, DL, TyX, SrlY); | 1996 SrlY = DAG.getNode(ISD::TRUNCATE, DL, TyX, SrlY); |
1910 | 1997 |
1911 SDValue SllY = DAG.getNode(ISD::SHL, DL, TyX, SrlY, | 1998 SDValue SllY = DAG.getNode(ISD::SHL, DL, TyX, SrlY, |
1912 DAG.getConstant(WidthX - 1, MVT::i32)); | 1999 DAG.getConstant(WidthX - 1, DL, MVT::i32)); |
1913 SDValue Or = DAG.getNode(ISD::OR, DL, TyX, SrlX, SllY); | 2000 SDValue Or = DAG.getNode(ISD::OR, DL, TyX, SrlX, SllY); |
1914 return DAG.getNode(ISD::BITCAST, DL, Op.getOperand(0).getValueType(), Or); | 2001 return DAG.getNode(ISD::BITCAST, DL, Op.getOperand(0).getValueType(), Or); |
1915 } | 2002 } |
1916 | 2003 |
1917 SDValue | 2004 SDValue |
1979 unsigned AddrReg = ABI.IsN64() ? Mips::V0_64 : Mips::V0; | 2066 unsigned AddrReg = ABI.IsN64() ? Mips::V0_64 : Mips::V0; |
1980 Chain = DAG.getCopyToReg(Chain, DL, OffsetReg, Offset, SDValue()); | 2067 Chain = DAG.getCopyToReg(Chain, DL, OffsetReg, Offset, SDValue()); |
1981 Chain = DAG.getCopyToReg(Chain, DL, AddrReg, Handler, Chain.getValue(1)); | 2068 Chain = DAG.getCopyToReg(Chain, DL, AddrReg, Handler, Chain.getValue(1)); |
1982 return DAG.getNode(MipsISD::EH_RETURN, DL, MVT::Other, Chain, | 2069 return DAG.getNode(MipsISD::EH_RETURN, DL, MVT::Other, Chain, |
1983 DAG.getRegister(OffsetReg, Ty), | 2070 DAG.getRegister(OffsetReg, Ty), |
1984 DAG.getRegister(AddrReg, getPointerTy()), | 2071 DAG.getRegister(AddrReg, getPointerTy(MF.getDataLayout())), |
1985 Chain.getValue(1)); | 2072 Chain.getValue(1)); |
1986 } | 2073 } |
1987 | 2074 |
1988 SDValue MipsTargetLowering::lowerATOMIC_FENCE(SDValue Op, | 2075 SDValue MipsTargetLowering::lowerATOMIC_FENCE(SDValue Op, |
1989 SelectionDAG &DAG) const { | 2076 SelectionDAG &DAG) const { |
1990 // FIXME: Need pseudo-fence for 'singlethread' fences | 2077 // FIXME: Need pseudo-fence for 'singlethread' fences |
1991 // FIXME: Set SType for weaker fences where supported/appropriate. | 2078 // FIXME: Set SType for weaker fences where supported/appropriate. |
1992 unsigned SType = 0; | 2079 unsigned SType = 0; |
1993 SDLoc DL(Op); | 2080 SDLoc DL(Op); |
1994 return DAG.getNode(MipsISD::Sync, DL, MVT::Other, Op.getOperand(0), | 2081 return DAG.getNode(MipsISD::Sync, DL, MVT::Other, Op.getOperand(0), |
1995 DAG.getConstant(SType, MVT::i32)); | 2082 DAG.getConstant(SType, DL, MVT::i32)); |
1996 } | 2083 } |
1997 | 2084 |
1998 SDValue MipsTargetLowering::lowerShiftLeftParts(SDValue Op, | 2085 SDValue MipsTargetLowering::lowerShiftLeftParts(SDValue Op, |
1999 SelectionDAG &DAG) const { | 2086 SelectionDAG &DAG) const { |
2000 SDLoc DL(Op); | 2087 SDLoc DL(Op); |
2007 // hi = (or (shl hi, shamt) (srl (srl lo, 1), ~shamt)) | 2094 // hi = (or (shl hi, shamt) (srl (srl lo, 1), ~shamt)) |
2008 // else: | 2095 // else: |
2009 // lo = 0 | 2096 // lo = 0 |
2010 // hi = (shl lo, shamt[4:0]) | 2097 // hi = (shl lo, shamt[4:0]) |
2011 SDValue Not = DAG.getNode(ISD::XOR, DL, MVT::i32, Shamt, | 2098 SDValue Not = DAG.getNode(ISD::XOR, DL, MVT::i32, Shamt, |
2012 DAG.getConstant(-1, MVT::i32)); | 2099 DAG.getConstant(-1, DL, MVT::i32)); |
2013 SDValue ShiftRight1Lo = DAG.getNode(ISD::SRL, DL, VT, Lo, | 2100 SDValue ShiftRight1Lo = DAG.getNode(ISD::SRL, DL, VT, Lo, |
2014 DAG.getConstant(1, VT)); | 2101 DAG.getConstant(1, DL, VT)); |
2015 SDValue ShiftRightLo = DAG.getNode(ISD::SRL, DL, VT, ShiftRight1Lo, Not); | 2102 SDValue ShiftRightLo = DAG.getNode(ISD::SRL, DL, VT, ShiftRight1Lo, Not); |
2016 SDValue ShiftLeftHi = DAG.getNode(ISD::SHL, DL, VT, Hi, Shamt); | 2103 SDValue ShiftLeftHi = DAG.getNode(ISD::SHL, DL, VT, Hi, Shamt); |
2017 SDValue Or = DAG.getNode(ISD::OR, DL, VT, ShiftLeftHi, ShiftRightLo); | 2104 SDValue Or = DAG.getNode(ISD::OR, DL, VT, ShiftLeftHi, ShiftRightLo); |
2018 SDValue ShiftLeftLo = DAG.getNode(ISD::SHL, DL, VT, Lo, Shamt); | 2105 SDValue ShiftLeftLo = DAG.getNode(ISD::SHL, DL, VT, Lo, Shamt); |
2019 SDValue Cond = DAG.getNode(ISD::AND, DL, MVT::i32, Shamt, | 2106 SDValue Cond = DAG.getNode(ISD::AND, DL, MVT::i32, Shamt, |
2020 DAG.getConstant(0x20, MVT::i32)); | 2107 DAG.getConstant(VT.getSizeInBits(), DL, MVT::i32)); |
2021 Lo = DAG.getNode(ISD::SELECT, DL, VT, Cond, | 2108 Lo = DAG.getNode(ISD::SELECT, DL, VT, Cond, |
2022 DAG.getConstant(0, VT), ShiftLeftLo); | 2109 DAG.getConstant(0, DL, VT), ShiftLeftLo); |
2023 Hi = DAG.getNode(ISD::SELECT, DL, VT, Cond, ShiftLeftLo, Or); | 2110 Hi = DAG.getNode(ISD::SELECT, DL, VT, Cond, ShiftLeftLo, Or); |
2024 | 2111 |
2025 SDValue Ops[2] = {Lo, Hi}; | 2112 SDValue Ops[2] = {Lo, Hi}; |
2026 return DAG.getMergeValues(Ops, DL); | 2113 return DAG.getMergeValues(Ops, DL); |
2027 } | 2114 } |
2045 // hi = (sra hi, 31) | 2132 // hi = (sra hi, 31) |
2046 // else: | 2133 // else: |
2047 // lo = (srl hi, shamt[4:0]) | 2134 // lo = (srl hi, shamt[4:0]) |
2048 // hi = 0 | 2135 // hi = 0 |
2049 SDValue Not = DAG.getNode(ISD::XOR, DL, MVT::i32, Shamt, | 2136 SDValue Not = DAG.getNode(ISD::XOR, DL, MVT::i32, Shamt, |
2050 DAG.getConstant(-1, MVT::i32)); | 2137 DAG.getConstant(-1, DL, MVT::i32)); |
2051 SDValue ShiftLeft1Hi = DAG.getNode(ISD::SHL, DL, VT, Hi, | 2138 SDValue ShiftLeft1Hi = DAG.getNode(ISD::SHL, DL, VT, Hi, |
2052 DAG.getConstant(1, VT)); | 2139 DAG.getConstant(1, DL, VT)); |
2053 SDValue ShiftLeftHi = DAG.getNode(ISD::SHL, DL, VT, ShiftLeft1Hi, Not); | 2140 SDValue ShiftLeftHi = DAG.getNode(ISD::SHL, DL, VT, ShiftLeft1Hi, Not); |
2054 SDValue ShiftRightLo = DAG.getNode(ISD::SRL, DL, VT, Lo, Shamt); | 2141 SDValue ShiftRightLo = DAG.getNode(ISD::SRL, DL, VT, Lo, Shamt); |
2055 SDValue Or = DAG.getNode(ISD::OR, DL, VT, ShiftLeftHi, ShiftRightLo); | 2142 SDValue Or = DAG.getNode(ISD::OR, DL, VT, ShiftLeftHi, ShiftRightLo); |
2056 SDValue ShiftRightHi = DAG.getNode(IsSRA ? ISD::SRA : ISD::SRL, | 2143 SDValue ShiftRightHi = DAG.getNode(IsSRA ? ISD::SRA : ISD::SRL, |
2057 DL, VT, Hi, Shamt); | 2144 DL, VT, Hi, Shamt); |
2058 SDValue Cond = DAG.getNode(ISD::AND, DL, MVT::i32, Shamt, | 2145 SDValue Cond = DAG.getNode(ISD::AND, DL, MVT::i32, Shamt, |
2059 DAG.getConstant(0x20, MVT::i32)); | 2146 DAG.getConstant(VT.getSizeInBits(), DL, MVT::i32)); |
2060 SDValue Shift31 = DAG.getNode(ISD::SRA, DL, VT, Hi, DAG.getConstant(31, VT)); | 2147 SDValue Ext = DAG.getNode(ISD::SRA, DL, VT, Hi, |
2148 DAG.getConstant(VT.getSizeInBits() - 1, DL, VT)); | |
2061 Lo = DAG.getNode(ISD::SELECT, DL, VT, Cond, ShiftRightHi, Or); | 2149 Lo = DAG.getNode(ISD::SELECT, DL, VT, Cond, ShiftRightHi, Or); |
2062 Hi = DAG.getNode(ISD::SELECT, DL, VT, Cond, | 2150 Hi = DAG.getNode(ISD::SELECT, DL, VT, Cond, |
2063 IsSRA ? Shift31 : DAG.getConstant(0, VT), ShiftRightHi); | 2151 IsSRA ? Ext : DAG.getConstant(0, DL, VT), ShiftRightHi); |
2064 | 2152 |
2065 SDValue Ops[2] = {Lo, Hi}; | 2153 SDValue Ops[2] = {Lo, Hi}; |
2066 return DAG.getMergeValues(Ops, DL); | 2154 return DAG.getMergeValues(Ops, DL); |
2067 } | 2155 } |
2068 | 2156 |
2074 SDLoc DL(LD); | 2162 SDLoc DL(LD); |
2075 SDVTList VTList = DAG.getVTList(VT, MVT::Other); | 2163 SDVTList VTList = DAG.getVTList(VT, MVT::Other); |
2076 | 2164 |
2077 if (Offset) | 2165 if (Offset) |
2078 Ptr = DAG.getNode(ISD::ADD, DL, BasePtrVT, Ptr, | 2166 Ptr = DAG.getNode(ISD::ADD, DL, BasePtrVT, Ptr, |
2079 DAG.getConstant(Offset, BasePtrVT)); | 2167 DAG.getConstant(Offset, DL, BasePtrVT)); |
2080 | 2168 |
2081 SDValue Ops[] = { Chain, Ptr, Src }; | 2169 SDValue Ops[] = { Chain, Ptr, Src }; |
2082 return DAG.getMemIntrinsicNode(Opc, DL, VTList, Ops, MemVT, | 2170 return DAG.getMemIntrinsicNode(Opc, DL, VTList, Ops, MemVT, |
2083 LD->getMemOperand()); | 2171 LD->getMemOperand()); |
2084 } | 2172 } |
2139 // (set tmp0, (lwl (add baseptr, 3), undef)) | 2227 // (set tmp0, (lwl (add baseptr, 3), undef)) |
2140 // (set tmp1, (lwr baseptr, tmp0)) | 2228 // (set tmp1, (lwr baseptr, tmp0)) |
2141 // (set tmp2, (shl tmp1, 32)) | 2229 // (set tmp2, (shl tmp1, 32)) |
2142 // (set dst, (srl tmp2, 32)) | 2230 // (set dst, (srl tmp2, 32)) |
2143 SDLoc DL(LD); | 2231 SDLoc DL(LD); |
2144 SDValue Const32 = DAG.getConstant(32, MVT::i32); | 2232 SDValue Const32 = DAG.getConstant(32, DL, MVT::i32); |
2145 SDValue SLL = DAG.getNode(ISD::SHL, DL, MVT::i64, LWR, Const32); | 2233 SDValue SLL = DAG.getNode(ISD::SHL, DL, MVT::i64, LWR, Const32); |
2146 SDValue SRL = DAG.getNode(ISD::SRL, DL, MVT::i64, SLL, Const32); | 2234 SDValue SRL = DAG.getNode(ISD::SRL, DL, MVT::i64, SLL, Const32); |
2147 SDValue Ops[] = { SRL, LWR.getValue(1) }; | 2235 SDValue Ops[] = { SRL, LWR.getValue(1) }; |
2148 return DAG.getMergeValues(Ops, DL); | 2236 return DAG.getMergeValues(Ops, DL); |
2149 } | 2237 } |
2155 SDLoc DL(SD); | 2243 SDLoc DL(SD); |
2156 SDVTList VTList = DAG.getVTList(MVT::Other); | 2244 SDVTList VTList = DAG.getVTList(MVT::Other); |
2157 | 2245 |
2158 if (Offset) | 2246 if (Offset) |
2159 Ptr = DAG.getNode(ISD::ADD, DL, BasePtrVT, Ptr, | 2247 Ptr = DAG.getNode(ISD::ADD, DL, BasePtrVT, Ptr, |
2160 DAG.getConstant(Offset, BasePtrVT)); | 2248 DAG.getConstant(Offset, DL, BasePtrVT)); |
2161 | 2249 |
2162 SDValue Ops[] = { Chain, Value, Ptr }; | 2250 SDValue Ops[] = { Chain, Value, Ptr }; |
2163 return DAG.getMemIntrinsicNode(Opc, DL, VTList, Ops, MemVT, | 2251 return DAG.getMemIntrinsicNode(Opc, DL, VTList, Ops, MemVT, |
2164 SD->getMemOperand()); | 2252 SD->getMemOperand()); |
2165 } | 2253 } |
2237 // the old stack pointer. | 2325 // the old stack pointer. |
2238 MachineFrameInfo *MFI = DAG.getMachineFunction().getFrameInfo(); | 2326 MachineFrameInfo *MFI = DAG.getMachineFunction().getFrameInfo(); |
2239 EVT ValTy = Op->getValueType(0); | 2327 EVT ValTy = Op->getValueType(0); |
2240 int FI = MFI->CreateFixedObject(Op.getValueSizeInBits() / 8, 0, false); | 2328 int FI = MFI->CreateFixedObject(Op.getValueSizeInBits() / 8, 0, false); |
2241 SDValue InArgsAddr = DAG.getFrameIndex(FI, ValTy); | 2329 SDValue InArgsAddr = DAG.getFrameIndex(FI, ValTy); |
2242 return DAG.getNode(ISD::ADD, SDLoc(Op), ValTy, InArgsAddr, | 2330 SDLoc DL(Op); |
2243 DAG.getConstant(0, ValTy)); | 2331 return DAG.getNode(ISD::ADD, DL, ValTy, InArgsAddr, |
2332 DAG.getConstant(0, DL, ValTy)); | |
2244 } | 2333 } |
2245 | 2334 |
2246 SDValue MipsTargetLowering::lowerFP_TO_SINT(SDValue Op, | 2335 SDValue MipsTargetLowering::lowerFP_TO_SINT(SDValue Op, |
2247 SelectionDAG &DAG) const { | 2336 SelectionDAG &DAG) const { |
2248 EVT FPTy = EVT::getFloatingPointVT(Op.getValueSizeInBits()); | 2337 EVT FPTy = EVT::getFloatingPointVT(Op.getValueSizeInBits()); |
2270 // For vararg functions, all arguments are passed in A0, A1, A2, A3 and stack. | 2359 // For vararg functions, all arguments are passed in A0, A1, A2, A3 and stack. |
2271 //===----------------------------------------------------------------------===// | 2360 //===----------------------------------------------------------------------===// |
2272 | 2361 |
2273 static bool CC_MipsO32(unsigned ValNo, MVT ValVT, MVT LocVT, | 2362 static bool CC_MipsO32(unsigned ValNo, MVT ValVT, MVT LocVT, |
2274 CCValAssign::LocInfo LocInfo, ISD::ArgFlagsTy ArgFlags, | 2363 CCValAssign::LocInfo LocInfo, ISD::ArgFlagsTy ArgFlags, |
2275 CCState &State, const MCPhysReg *F64Regs) { | 2364 CCState &State, ArrayRef<MCPhysReg> F64Regs) { |
2276 const MipsSubtarget &Subtarget = static_cast<const MipsSubtarget &>( | 2365 const MipsSubtarget &Subtarget = static_cast<const MipsSubtarget &>( |
2277 State.getMachineFunction().getSubtarget()); | 2366 State.getMachineFunction().getSubtarget()); |
2278 | |
2279 static const unsigned IntRegsSize = 4, FloatRegsSize = 2; | |
2280 | 2367 |
2281 static const MCPhysReg IntRegs[] = { Mips::A0, Mips::A1, Mips::A2, Mips::A3 }; | 2368 static const MCPhysReg IntRegs[] = { Mips::A0, Mips::A1, Mips::A2, Mips::A3 }; |
2282 static const MCPhysReg F32Regs[] = { Mips::F12, Mips::F14 }; | 2369 static const MCPhysReg F32Regs[] = { Mips::F12, Mips::F14 }; |
2283 | 2370 |
2284 // Do not process byval args here. | 2371 // Do not process byval args here. |
2312 unsigned Reg; | 2399 unsigned Reg; |
2313 | 2400 |
2314 // f32 and f64 are allocated in A0, A1, A2, A3 when either of the following | 2401 // f32 and f64 are allocated in A0, A1, A2, A3 when either of the following |
2315 // is true: function is vararg, argument is 3rd or higher, there is previous | 2402 // is true: function is vararg, argument is 3rd or higher, there is previous |
2316 // argument which is not f32 or f64. | 2403 // argument which is not f32 or f64. |
2317 bool AllocateFloatsInIntReg = State.isVarArg() || ValNo > 1 | 2404 bool AllocateFloatsInIntReg = State.isVarArg() || ValNo > 1 || |
2318 || State.getFirstUnallocated(F32Regs, FloatRegsSize) != ValNo; | 2405 State.getFirstUnallocated(F32Regs) != ValNo; |
2319 unsigned OrigAlign = ArgFlags.getOrigAlign(); | 2406 unsigned OrigAlign = ArgFlags.getOrigAlign(); |
2320 bool isI64 = (ValVT == MVT::i32 && OrigAlign == 8); | 2407 bool isI64 = (ValVT == MVT::i32 && OrigAlign == 8); |
2321 | 2408 |
2322 if (ValVT == MVT::i32 || (ValVT == MVT::f32 && AllocateFloatsInIntReg)) { | 2409 if (ValVT == MVT::i32 || (ValVT == MVT::f32 && AllocateFloatsInIntReg)) { |
2323 Reg = State.AllocateReg(IntRegs, IntRegsSize); | 2410 Reg = State.AllocateReg(IntRegs); |
2324 // If this is the first part of an i64 arg, | 2411 // If this is the first part of an i64 arg, |
2325 // the allocated register must be either A0 or A2. | 2412 // the allocated register must be either A0 or A2. |
2326 if (isI64 && (Reg == Mips::A1 || Reg == Mips::A3)) | 2413 if (isI64 && (Reg == Mips::A1 || Reg == Mips::A3)) |
2327 Reg = State.AllocateReg(IntRegs, IntRegsSize); | 2414 Reg = State.AllocateReg(IntRegs); |
2328 LocVT = MVT::i32; | 2415 LocVT = MVT::i32; |
2329 } else if (ValVT == MVT::f64 && AllocateFloatsInIntReg) { | 2416 } else if (ValVT == MVT::f64 && AllocateFloatsInIntReg) { |
2330 // Allocate int register and shadow next int register. If first | 2417 // Allocate int register and shadow next int register. If first |
2331 // available register is Mips::A1 or Mips::A3, shadow it too. | 2418 // available register is Mips::A1 or Mips::A3, shadow it too. |
2332 Reg = State.AllocateReg(IntRegs, IntRegsSize); | 2419 Reg = State.AllocateReg(IntRegs); |
2333 if (Reg == Mips::A1 || Reg == Mips::A3) | 2420 if (Reg == Mips::A1 || Reg == Mips::A3) |
2334 Reg = State.AllocateReg(IntRegs, IntRegsSize); | 2421 Reg = State.AllocateReg(IntRegs); |
2335 State.AllocateReg(IntRegs, IntRegsSize); | 2422 State.AllocateReg(IntRegs); |
2336 LocVT = MVT::i32; | 2423 LocVT = MVT::i32; |
2337 } else if (ValVT.isFloatingPoint() && !AllocateFloatsInIntReg) { | 2424 } else if (ValVT.isFloatingPoint() && !AllocateFloatsInIntReg) { |
2338 // we are guaranteed to find an available float register | 2425 // we are guaranteed to find an available float register |
2339 if (ValVT == MVT::f32) { | 2426 if (ValVT == MVT::f32) { |
2340 Reg = State.AllocateReg(F32Regs, FloatRegsSize); | 2427 Reg = State.AllocateReg(F32Regs); |
2341 // Shadow int register | 2428 // Shadow int register |
2342 State.AllocateReg(IntRegs, IntRegsSize); | 2429 State.AllocateReg(IntRegs); |
2343 } else { | 2430 } else { |
2344 Reg = State.AllocateReg(F64Regs, FloatRegsSize); | 2431 Reg = State.AllocateReg(F64Regs); |
2345 // Shadow int registers | 2432 // Shadow int registers |
2346 unsigned Reg2 = State.AllocateReg(IntRegs, IntRegsSize); | 2433 unsigned Reg2 = State.AllocateReg(IntRegs); |
2347 if (Reg2 == Mips::A1 || Reg2 == Mips::A3) | 2434 if (Reg2 == Mips::A1 || Reg2 == Mips::A3) |
2348 State.AllocateReg(IntRegs, IntRegsSize); | 2435 State.AllocateReg(IntRegs); |
2349 State.AllocateReg(IntRegs, IntRegsSize); | 2436 State.AllocateReg(IntRegs); |
2350 } | 2437 } |
2351 } else | 2438 } else |
2352 llvm_unreachable("Cannot handle this ValVT."); | 2439 llvm_unreachable("Cannot handle this ValVT."); |
2353 | 2440 |
2354 if (!Reg) { | 2441 if (!Reg) { |
2396 SDValue | 2483 SDValue |
2397 MipsTargetLowering::passArgOnStack(SDValue StackPtr, unsigned Offset, | 2484 MipsTargetLowering::passArgOnStack(SDValue StackPtr, unsigned Offset, |
2398 SDValue Chain, SDValue Arg, SDLoc DL, | 2485 SDValue Chain, SDValue Arg, SDLoc DL, |
2399 bool IsTailCall, SelectionDAG &DAG) const { | 2486 bool IsTailCall, SelectionDAG &DAG) const { |
2400 if (!IsTailCall) { | 2487 if (!IsTailCall) { |
2401 SDValue PtrOff = DAG.getNode(ISD::ADD, DL, getPointerTy(), StackPtr, | 2488 SDValue PtrOff = |
2402 DAG.getIntPtrConstant(Offset)); | 2489 DAG.getNode(ISD::ADD, DL, getPointerTy(DAG.getDataLayout()), StackPtr, |
2490 DAG.getIntPtrConstant(Offset, DL)); | |
2403 return DAG.getStore(Chain, DL, Arg, PtrOff, MachinePointerInfo(), false, | 2491 return DAG.getStore(Chain, DL, Arg, PtrOff, MachinePointerInfo(), false, |
2404 false, 0); | 2492 false, 0); |
2405 } | 2493 } |
2406 | 2494 |
2407 MachineFrameInfo *MFI = DAG.getMachineFunction().getFrameInfo(); | 2495 MachineFrameInfo *MFI = DAG.getMachineFunction().getFrameInfo(); |
2408 int FI = MFI->CreateFixedObject(Arg.getValueSizeInBits() / 8, Offset, false); | 2496 int FI = MFI->CreateFixedObject(Arg.getValueSizeInBits() / 8, Offset, false); |
2409 SDValue FIN = DAG.getFrameIndex(FI, getPointerTy()); | 2497 SDValue FIN = DAG.getFrameIndex(FI, getPointerTy(DAG.getDataLayout())); |
2410 return DAG.getStore(Chain, DL, Arg, FIN, MachinePointerInfo(), | 2498 return DAG.getStore(Chain, DL, Arg, FIN, MachinePointerInfo(), |
2411 /*isVolatile=*/ true, false, 0); | 2499 /*isVolatile=*/ true, false, 0); |
2412 } | 2500 } |
2413 | 2501 |
2414 void MipsTargetLowering:: | 2502 void MipsTargetLowering:: |
2451 Ops.push_back(CLI.DAG.getRegister(RegsToPass[i].first, | 2539 Ops.push_back(CLI.DAG.getRegister(RegsToPass[i].first, |
2452 RegsToPass[i].second.getValueType())); | 2540 RegsToPass[i].second.getValueType())); |
2453 | 2541 |
2454 // Add a register mask operand representing the call-preserved registers. | 2542 // Add a register mask operand representing the call-preserved registers. |
2455 const TargetRegisterInfo *TRI = Subtarget.getRegisterInfo(); | 2543 const TargetRegisterInfo *TRI = Subtarget.getRegisterInfo(); |
2456 const uint32_t *Mask = TRI->getCallPreservedMask(CLI.CallConv); | 2544 const uint32_t *Mask = |
2545 TRI->getCallPreservedMask(CLI.DAG.getMachineFunction(), CLI.CallConv); | |
2457 assert(Mask && "Missing call preserved mask for calling convention"); | 2546 assert(Mask && "Missing call preserved mask for calling convention"); |
2458 if (Subtarget.inMips16HardFloat()) { | 2547 if (Subtarget.inMips16HardFloat()) { |
2459 if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(CLI.Callee)) { | 2548 if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(CLI.Callee)) { |
2460 llvm::StringRef Sym = G->getGlobal()->getName(); | 2549 llvm::StringRef Sym = G->getGlobal()->getName(); |
2461 Function *F = G->getGlobal()->getParent()->getFunction(Sym); | 2550 Function *F = G->getGlobal()->getParent()->getFunction(Sym); |
2522 // Chain is the output chain of the last Load/Store or CopyToReg node. | 2611 // Chain is the output chain of the last Load/Store or CopyToReg node. |
2523 // ByValChain is the output chain of the last Memcpy node created for copying | 2612 // ByValChain is the output chain of the last Memcpy node created for copying |
2524 // byval arguments to the stack. | 2613 // byval arguments to the stack. |
2525 unsigned StackAlignment = TFL->getStackAlignment(); | 2614 unsigned StackAlignment = TFL->getStackAlignment(); |
2526 NextStackOffset = RoundUpToAlignment(NextStackOffset, StackAlignment); | 2615 NextStackOffset = RoundUpToAlignment(NextStackOffset, StackAlignment); |
2527 SDValue NextStackOffsetVal = DAG.getIntPtrConstant(NextStackOffset, true); | 2616 SDValue NextStackOffsetVal = DAG.getIntPtrConstant(NextStackOffset, DL, true); |
2528 | 2617 |
2529 if (!IsTailCall) | 2618 if (!IsTailCall) |
2530 Chain = DAG.getCALLSEQ_START(Chain, NextStackOffsetVal, DL); | 2619 Chain = DAG.getCALLSEQ_START(Chain, NextStackOffsetVal, DL); |
2531 | 2620 |
2532 SDValue StackPtr = DAG.getCopyFromReg( | 2621 SDValue StackPtr = |
2533 Chain, DL, ABI.IsN64() ? Mips::SP_64 : Mips::SP, getPointerTy()); | 2622 DAG.getCopyFromReg(Chain, DL, ABI.IsN64() ? Mips::SP_64 : Mips::SP, |
2623 getPointerTy(DAG.getDataLayout())); | |
2534 | 2624 |
2535 // With EABI is it possible to have 16 args on registers. | 2625 // With EABI is it possible to have 16 args on registers. |
2536 std::deque< std::pair<unsigned, SDValue> > RegsToPass; | 2626 std::deque< std::pair<unsigned, SDValue> > RegsToPass; |
2537 SmallVector<SDValue, 8> MemOpChains; | 2627 SmallVector<SDValue, 8> MemOpChains; |
2538 | 2628 |
2574 (ValVT == MVT::f64 && LocVT == MVT::i64) || | 2664 (ValVT == MVT::f64 && LocVT == MVT::i64) || |
2575 (ValVT == MVT::i64 && LocVT == MVT::f64)) | 2665 (ValVT == MVT::i64 && LocVT == MVT::f64)) |
2576 Arg = DAG.getNode(ISD::BITCAST, DL, LocVT, Arg); | 2666 Arg = DAG.getNode(ISD::BITCAST, DL, LocVT, Arg); |
2577 else if (ValVT == MVT::f64 && LocVT == MVT::i32) { | 2667 else if (ValVT == MVT::f64 && LocVT == MVT::i32) { |
2578 SDValue Lo = DAG.getNode(MipsISD::ExtractElementF64, DL, MVT::i32, | 2668 SDValue Lo = DAG.getNode(MipsISD::ExtractElementF64, DL, MVT::i32, |
2579 Arg, DAG.getConstant(0, MVT::i32)); | 2669 Arg, DAG.getConstant(0, DL, MVT::i32)); |
2580 SDValue Hi = DAG.getNode(MipsISD::ExtractElementF64, DL, MVT::i32, | 2670 SDValue Hi = DAG.getNode(MipsISD::ExtractElementF64, DL, MVT::i32, |
2581 Arg, DAG.getConstant(1, MVT::i32)); | 2671 Arg, DAG.getConstant(1, DL, MVT::i32)); |
2582 if (!Subtarget.isLittle()) | 2672 if (!Subtarget.isLittle()) |
2583 std::swap(Lo, Hi); | 2673 std::swap(Lo, Hi); |
2584 unsigned LocRegLo = VA.getLocReg(); | 2674 unsigned LocRegLo = VA.getLocReg(); |
2585 unsigned LocRegHigh = getNextIntArgReg(LocRegLo); | 2675 unsigned LocRegHigh = getNextIntArgReg(LocRegLo); |
2586 RegsToPass.push_back(std::make_pair(LocRegLo, Lo)); | 2676 RegsToPass.push_back(std::make_pair(LocRegLo, Lo)); |
2615 if (UseUpperBits) { | 2705 if (UseUpperBits) { |
2616 unsigned ValSizeInBits = Outs[i].ArgVT.getSizeInBits(); | 2706 unsigned ValSizeInBits = Outs[i].ArgVT.getSizeInBits(); |
2617 unsigned LocSizeInBits = VA.getLocVT().getSizeInBits(); | 2707 unsigned LocSizeInBits = VA.getLocVT().getSizeInBits(); |
2618 Arg = DAG.getNode( | 2708 Arg = DAG.getNode( |
2619 ISD::SHL, DL, VA.getLocVT(), Arg, | 2709 ISD::SHL, DL, VA.getLocVT(), Arg, |
2620 DAG.getConstant(LocSizeInBits - ValSizeInBits, VA.getLocVT())); | 2710 DAG.getConstant(LocSizeInBits - ValSizeInBits, DL, VA.getLocVT())); |
2621 } | 2711 } |
2622 | 2712 |
2623 // Arguments that can be passed on register must be kept at | 2713 // Arguments that can be passed on register must be kept at |
2624 // RegsToPass vector | 2714 // RegsToPass vector |
2625 if (VA.isRegLoc()) { | 2715 if (VA.isRegLoc()) { |
2666 Callee = getAddrGlobal(G, DL, Ty, DAG, MipsII::MO_GOT_CALL, Chain, | 2756 Callee = getAddrGlobal(G, DL, Ty, DAG, MipsII::MO_GOT_CALL, Chain, |
2667 FuncInfo->callPtrInfo(Val)); | 2757 FuncInfo->callPtrInfo(Val)); |
2668 IsCallReloc = true; | 2758 IsCallReloc = true; |
2669 } | 2759 } |
2670 } else | 2760 } else |
2671 Callee = DAG.getTargetGlobalAddress(G->getGlobal(), DL, getPointerTy(), 0, | 2761 Callee = DAG.getTargetGlobalAddress(G->getGlobal(), DL, |
2762 getPointerTy(DAG.getDataLayout()), 0, | |
2672 MipsII::MO_NO_FLAG); | 2763 MipsII::MO_NO_FLAG); |
2673 GlobalOrExternal = true; | 2764 GlobalOrExternal = true; |
2674 } | 2765 } |
2675 else if (ExternalSymbolSDNode *S = dyn_cast<ExternalSymbolSDNode>(Callee)) { | 2766 else if (ExternalSymbolSDNode *S = dyn_cast<ExternalSymbolSDNode>(Callee)) { |
2676 const char *Sym = S->getSymbol(); | 2767 const char *Sym = S->getSymbol(); |
2677 | 2768 |
2678 if (!ABI.IsN64() && !IsPIC) // !N64 && static | 2769 if (!ABI.IsN64() && !IsPIC) // !N64 && static |
2679 Callee = | 2770 Callee = DAG.getTargetExternalSymbol( |
2680 DAG.getTargetExternalSymbol(Sym, getPointerTy(), MipsII::MO_NO_FLAG); | 2771 Sym, getPointerTy(DAG.getDataLayout()), MipsII::MO_NO_FLAG); |
2681 else if (LargeGOT) { | 2772 else if (LargeGOT) { |
2682 Callee = getAddrGlobalLargeGOT(S, DL, Ty, DAG, MipsII::MO_CALL_HI16, | 2773 Callee = getAddrGlobalLargeGOT(S, DL, Ty, DAG, MipsII::MO_CALL_HI16, |
2683 MipsII::MO_CALL_LO16, Chain, | 2774 MipsII::MO_CALL_LO16, Chain, |
2684 FuncInfo->callPtrInfo(Sym)); | 2775 FuncInfo->callPtrInfo(Sym)); |
2685 IsCallReloc = true; | 2776 IsCallReloc = true; |
2704 Chain = DAG.getNode(MipsISD::JmpLink, DL, NodeTys, Ops); | 2795 Chain = DAG.getNode(MipsISD::JmpLink, DL, NodeTys, Ops); |
2705 SDValue InFlag = Chain.getValue(1); | 2796 SDValue InFlag = Chain.getValue(1); |
2706 | 2797 |
2707 // Create the CALLSEQ_END node. | 2798 // Create the CALLSEQ_END node. |
2708 Chain = DAG.getCALLSEQ_END(Chain, NextStackOffsetVal, | 2799 Chain = DAG.getCALLSEQ_END(Chain, NextStackOffsetVal, |
2709 DAG.getIntPtrConstant(0, true), InFlag, DL); | 2800 DAG.getIntPtrConstant(0, DL, true), InFlag, DL); |
2710 InFlag = Chain.getValue(1); | 2801 InFlag = Chain.getValue(1); |
2711 | 2802 |
2712 // Handle result values, copying them out of physregs into vregs that we | 2803 // Handle result values, copying them out of physregs into vregs that we |
2713 // return. | 2804 // return. |
2714 return LowerCallResult(Chain, InFlag, CallConv, IsVarArg, Ins, DL, DAG, | 2805 return LowerCallResult(Chain, InFlag, CallConv, IsVarArg, Ins, DL, DAG, |
2743 unsigned LocSizeInBits = VA.getLocVT().getSizeInBits(); | 2834 unsigned LocSizeInBits = VA.getLocVT().getSizeInBits(); |
2744 unsigned Shift = | 2835 unsigned Shift = |
2745 VA.getLocInfo() == CCValAssign::ZExtUpper ? ISD::SRL : ISD::SRA; | 2836 VA.getLocInfo() == CCValAssign::ZExtUpper ? ISD::SRL : ISD::SRA; |
2746 Val = DAG.getNode( | 2837 Val = DAG.getNode( |
2747 Shift, DL, VA.getLocVT(), Val, | 2838 Shift, DL, VA.getLocVT(), Val, |
2748 DAG.getConstant(LocSizeInBits - ValSizeInBits, VA.getLocVT())); | 2839 DAG.getConstant(LocSizeInBits - ValSizeInBits, DL, VA.getLocVT())); |
2749 } | 2840 } |
2750 | 2841 |
2751 switch (VA.getLocInfo()) { | 2842 switch (VA.getLocInfo()) { |
2752 default: | 2843 default: |
2753 llvm_unreachable("Unknown loc info!"); | 2844 llvm_unreachable("Unknown loc info!"); |
2796 unsigned LocSizeInBits = VA.getLocVT().getSizeInBits(); | 2887 unsigned LocSizeInBits = VA.getLocVT().getSizeInBits(); |
2797 unsigned Opcode = | 2888 unsigned Opcode = |
2798 VA.getLocInfo() == CCValAssign::ZExtUpper ? ISD::SRL : ISD::SRA; | 2889 VA.getLocInfo() == CCValAssign::ZExtUpper ? ISD::SRL : ISD::SRA; |
2799 Val = DAG.getNode( | 2890 Val = DAG.getNode( |
2800 Opcode, DL, VA.getLocVT(), Val, | 2891 Opcode, DL, VA.getLocVT(), Val, |
2801 DAG.getConstant(LocSizeInBits - ValSizeInBits, VA.getLocVT())); | 2892 DAG.getConstant(LocSizeInBits - ValSizeInBits, DL, VA.getLocVT())); |
2802 break; | 2893 break; |
2803 } | 2894 } |
2804 } | 2895 } |
2805 | 2896 |
2806 // If this is an value smaller than the argument slot size (32-bit for O32, | 2897 // If this is an value smaller than the argument slot size (32-bit for O32, |
2932 | 3023 |
2933 if (ABI.IsO32()) { | 3024 if (ABI.IsO32()) { |
2934 // We ought to be able to use LocVT directly but O32 sets it to i32 | 3025 // We ought to be able to use LocVT directly but O32 sets it to i32 |
2935 // when allocating floating point values to integer registers. | 3026 // when allocating floating point values to integer registers. |
2936 // This shouldn't influence how we load the value into registers unless | 3027 // This shouldn't influence how we load the value into registers unless |
2937 // we are targetting softfloat. | 3028 // we are targeting softfloat. |
2938 if (VA.getValVT().isFloatingPoint() && !Subtarget.abiUsesSoftFloat()) | 3029 if (VA.getValVT().isFloatingPoint() && !Subtarget.useSoftFloat()) |
2939 LocVT = VA.getValVT(); | 3030 LocVT = VA.getValVT(); |
2940 } | 3031 } |
2941 | 3032 |
2942 // sanity check | 3033 // sanity check |
2943 assert(VA.isMemLoc()); | 3034 assert(VA.isMemLoc()); |
2945 // The stack pointer offset is relative to the caller stack frame. | 3036 // The stack pointer offset is relative to the caller stack frame. |
2946 int FI = MFI->CreateFixedObject(LocVT.getSizeInBits() / 8, | 3037 int FI = MFI->CreateFixedObject(LocVT.getSizeInBits() / 8, |
2947 VA.getLocMemOffset(), true); | 3038 VA.getLocMemOffset(), true); |
2948 | 3039 |
2949 // Create load nodes to retrieve arguments from the stack | 3040 // Create load nodes to retrieve arguments from the stack |
2950 SDValue FIN = DAG.getFrameIndex(FI, getPointerTy()); | 3041 SDValue FIN = DAG.getFrameIndex(FI, getPointerTy(DAG.getDataLayout())); |
2951 SDValue ArgValue = DAG.getLoad(LocVT, DL, Chain, FIN, | 3042 SDValue ArgValue = DAG.getLoad( |
2952 MachinePointerInfo::getFixedStack(FI), | 3043 LocVT, DL, Chain, FIN, |
2953 false, false, false, 0); | 3044 MachinePointerInfo::getFixedStack(DAG.getMachineFunction(), FI), |
3045 false, false, false, 0); | |
2954 OutChains.push_back(ArgValue.getValue(1)); | 3046 OutChains.push_back(ArgValue.getValue(1)); |
2955 | 3047 |
2956 ArgValue = UnpackFromArgumentSlot(ArgValue, VA, Ins[i].ArgVT, DL, DAG); | 3048 ArgValue = UnpackFromArgumentSlot(ArgValue, VA, Ins[i].ArgVT, DL, DAG); |
2957 | 3049 |
2958 InVals.push_back(ArgValue); | 3050 InVals.push_back(ArgValue); |
2999 const SmallVectorImpl<ISD::OutputArg> &Outs, | 3091 const SmallVectorImpl<ISD::OutputArg> &Outs, |
3000 LLVMContext &Context) const { | 3092 LLVMContext &Context) const { |
3001 SmallVector<CCValAssign, 16> RVLocs; | 3093 SmallVector<CCValAssign, 16> RVLocs; |
3002 MipsCCState CCInfo(CallConv, IsVarArg, MF, RVLocs, Context); | 3094 MipsCCState CCInfo(CallConv, IsVarArg, MF, RVLocs, Context); |
3003 return CCInfo.CheckReturn(Outs, RetCC_Mips); | 3095 return CCInfo.CheckReturn(Outs, RetCC_Mips); |
3096 } | |
3097 | |
3098 bool | |
3099 MipsTargetLowering::shouldSignExtendTypeInLibCall(EVT Type, bool IsSigned) const { | |
3100 if (Subtarget.hasMips3() && Subtarget.useSoftFloat()) { | |
3101 if (Type == MVT::i32) | |
3102 return true; | |
3103 } | |
3104 return IsSigned; | |
3004 } | 3105 } |
3005 | 3106 |
3006 SDValue | 3107 SDValue |
3007 MipsTargetLowering::LowerReturn(SDValue Chain, | 3108 MipsTargetLowering::LowerReturn(SDValue Chain, |
3008 CallingConv::ID CallConv, bool IsVarArg, | 3109 CallingConv::ID CallConv, bool IsVarArg, |
3061 if (UseUpperBits) { | 3162 if (UseUpperBits) { |
3062 unsigned ValSizeInBits = Outs[i].ArgVT.getSizeInBits(); | 3163 unsigned ValSizeInBits = Outs[i].ArgVT.getSizeInBits(); |
3063 unsigned LocSizeInBits = VA.getLocVT().getSizeInBits(); | 3164 unsigned LocSizeInBits = VA.getLocVT().getSizeInBits(); |
3064 Val = DAG.getNode( | 3165 Val = DAG.getNode( |
3065 ISD::SHL, DL, VA.getLocVT(), Val, | 3166 ISD::SHL, DL, VA.getLocVT(), Val, |
3066 DAG.getConstant(LocSizeInBits - ValSizeInBits, VA.getLocVT())); | 3167 DAG.getConstant(LocSizeInBits - ValSizeInBits, DL, VA.getLocVT())); |
3067 } | 3168 } |
3068 | 3169 |
3069 Chain = DAG.getCopyToReg(Chain, DL, VA.getLocReg(), Val, Flag); | 3170 Chain = DAG.getCopyToReg(Chain, DL, VA.getLocReg(), Val, Flag); |
3070 | 3171 |
3071 // Guarantee that all emitted copies are stuck together with flags. | 3172 // Guarantee that all emitted copies are stuck together with flags. |
3081 MipsFunctionInfo *MipsFI = MF.getInfo<MipsFunctionInfo>(); | 3182 MipsFunctionInfo *MipsFI = MF.getInfo<MipsFunctionInfo>(); |
3082 unsigned Reg = MipsFI->getSRetReturnReg(); | 3183 unsigned Reg = MipsFI->getSRetReturnReg(); |
3083 | 3184 |
3084 if (!Reg) | 3185 if (!Reg) |
3085 llvm_unreachable("sret virtual register not created in the entry block"); | 3186 llvm_unreachable("sret virtual register not created in the entry block"); |
3086 SDValue Val = DAG.getCopyFromReg(Chain, DL, Reg, getPointerTy()); | 3187 SDValue Val = |
3188 DAG.getCopyFromReg(Chain, DL, Reg, getPointerTy(DAG.getDataLayout())); | |
3087 unsigned V0 = ABI.IsN64() ? Mips::V0_64 : Mips::V0; | 3189 unsigned V0 = ABI.IsN64() ? Mips::V0_64 : Mips::V0; |
3088 | 3190 |
3089 Chain = DAG.getCopyToReg(Chain, DL, V0, Val, Flag); | 3191 Chain = DAG.getCopyToReg(Chain, DL, V0, Val, Flag); |
3090 Flag = Chain.getValue(1); | 3192 Flag = Chain.getValue(1); |
3091 RetOps.push_back(DAG.getRegister(V0, getPointerTy())); | 3193 RetOps.push_back(DAG.getRegister(V0, getPointerTy(DAG.getDataLayout()))); |
3092 } | 3194 } |
3093 | 3195 |
3094 RetOps[0] = Chain; // Update chain. | 3196 RetOps[0] = Chain; // Update chain. |
3095 | 3197 |
3096 // Add the flag if we have it. | 3198 // Add the flag if we have it. |
3105 // Mips Inline Assembly Support | 3207 // Mips Inline Assembly Support |
3106 //===----------------------------------------------------------------------===// | 3208 //===----------------------------------------------------------------------===// |
3107 | 3209 |
3108 /// getConstraintType - Given a constraint letter, return the type of | 3210 /// getConstraintType - Given a constraint letter, return the type of |
3109 /// constraint it is for this target. | 3211 /// constraint it is for this target. |
3110 MipsTargetLowering::ConstraintType MipsTargetLowering:: | 3212 MipsTargetLowering::ConstraintType |
3111 getConstraintType(const std::string &Constraint) const | 3213 MipsTargetLowering::getConstraintType(StringRef Constraint) const { |
3112 { | |
3113 // Mips specific constraints | 3214 // Mips specific constraints |
3114 // GCC config/mips/constraints.md | 3215 // GCC config/mips/constraints.md |
3115 // | 3216 // |
3116 // 'd' : An address register. Equivalent to r | 3217 // 'd' : An address register. Equivalent to r |
3117 // unless generating MIPS16 code. | 3218 // unless generating MIPS16 code. |
3133 return C_RegisterClass; | 3234 return C_RegisterClass; |
3134 case 'R': | 3235 case 'R': |
3135 return C_Memory; | 3236 return C_Memory; |
3136 } | 3237 } |
3137 } | 3238 } |
3239 | |
3240 if (Constraint == "ZC") | |
3241 return C_Memory; | |
3242 | |
3138 return TargetLowering::getConstraintType(Constraint); | 3243 return TargetLowering::getConstraintType(Constraint); |
3139 } | 3244 } |
3140 | 3245 |
3141 /// Examine constraint type and operand type and determine a weight value. | 3246 /// Examine constraint type and operand type and determine a weight value. |
3142 /// This object must already have been set up with the operand type | 3247 /// This object must already have been set up with the operand type |
3193 | 3298 |
3194 /// This is a helper function to parse a physical register string and split it | 3299 /// This is a helper function to parse a physical register string and split it |
3195 /// into non-numeric and numeric parts (Prefix and Reg). The first boolean flag | 3300 /// into non-numeric and numeric parts (Prefix and Reg). The first boolean flag |
3196 /// that is returned indicates whether parsing was successful. The second flag | 3301 /// that is returned indicates whether parsing was successful. The second flag |
3197 /// is true if the numeric part exists. | 3302 /// is true if the numeric part exists. |
3198 static std::pair<bool, bool> | 3303 static std::pair<bool, bool> parsePhysicalReg(StringRef C, StringRef &Prefix, |
3199 parsePhysicalReg(StringRef C, std::string &Prefix, | 3304 unsigned long long &Reg) { |
3200 unsigned long long &Reg) { | |
3201 if (C.front() != '{' || C.back() != '}') | 3305 if (C.front() != '{' || C.back() != '}') |
3202 return std::make_pair(false, false); | 3306 return std::make_pair(false, false); |
3203 | 3307 |
3204 // Search for the first numeric character. | 3308 // Search for the first numeric character. |
3205 StringRef::const_iterator I, B = C.begin() + 1, E = C.end() - 1; | 3309 StringRef::const_iterator I, B = C.begin() + 1, E = C.end() - 1; |
3206 I = std::find_if(B, E, std::ptr_fun(isdigit)); | 3310 I = std::find_if(B, E, std::ptr_fun(isdigit)); |
3207 | 3311 |
3208 Prefix.assign(B, I - B); | 3312 Prefix = StringRef(B, I - B); |
3209 | 3313 |
3210 // The second flag is set to false if no numeric characters were found. | 3314 // The second flag is set to false if no numeric characters were found. |
3211 if (I == E) | 3315 if (I == E) |
3212 return std::make_pair(true, false); | 3316 return std::make_pair(true, false); |
3213 | 3317 |
3219 std::pair<unsigned, const TargetRegisterClass *> MipsTargetLowering:: | 3323 std::pair<unsigned, const TargetRegisterClass *> MipsTargetLowering:: |
3220 parseRegForInlineAsmConstraint(StringRef C, MVT VT) const { | 3324 parseRegForInlineAsmConstraint(StringRef C, MVT VT) const { |
3221 const TargetRegisterInfo *TRI = | 3325 const TargetRegisterInfo *TRI = |
3222 Subtarget.getRegisterInfo(); | 3326 Subtarget.getRegisterInfo(); |
3223 const TargetRegisterClass *RC; | 3327 const TargetRegisterClass *RC; |
3224 std::string Prefix; | 3328 StringRef Prefix; |
3225 unsigned long long Reg; | 3329 unsigned long long Reg; |
3226 | 3330 |
3227 std::pair<bool, bool> R = parsePhysicalReg(C, Prefix, Reg); | 3331 std::pair<bool, bool> R = parsePhysicalReg(C, Prefix, Reg); |
3228 | 3332 |
3229 if (!R.first) | 3333 if (!R.first) |
3235 return std::make_pair(0U, nullptr); | 3339 return std::make_pair(0U, nullptr); |
3236 | 3340 |
3237 RC = TRI->getRegClass(Prefix == "hi" ? | 3341 RC = TRI->getRegClass(Prefix == "hi" ? |
3238 Mips::HI32RegClassID : Mips::LO32RegClassID); | 3342 Mips::HI32RegClassID : Mips::LO32RegClassID); |
3239 return std::make_pair(*(RC->begin()), RC); | 3343 return std::make_pair(*(RC->begin()), RC); |
3240 } else if (Prefix.compare(0, 4, "$msa") == 0) { | 3344 } else if (Prefix.startswith("$msa")) { |
3241 // Parse $msa(ir|csr|access|save|modify|request|map|unmap) | 3345 // Parse $msa(ir|csr|access|save|modify|request|map|unmap) |
3242 | 3346 |
3243 // No numeric characters follow the name. | 3347 // No numeric characters follow the name. |
3244 if (R.second) | 3348 if (R.second) |
3245 return std::make_pair(0U, nullptr); | 3349 return std::make_pair(0U, nullptr); |
3291 } | 3395 } |
3292 | 3396 |
3293 /// Given a register class constraint, like 'r', if this corresponds directly | 3397 /// Given a register class constraint, like 'r', if this corresponds directly |
3294 /// to an LLVM register class, return a register of 0 and the register class | 3398 /// to an LLVM register class, return a register of 0 and the register class |
3295 /// pointer. | 3399 /// pointer. |
3296 std::pair<unsigned, const TargetRegisterClass*> MipsTargetLowering:: | 3400 std::pair<unsigned, const TargetRegisterClass *> |
3297 getRegForInlineAsmConstraint(const std::string &Constraint, MVT VT) const | 3401 MipsTargetLowering::getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI, |
3298 { | 3402 StringRef Constraint, |
3403 MVT VT) const { | |
3299 if (Constraint.size() == 1) { | 3404 if (Constraint.size() == 1) { |
3300 switch (Constraint[0]) { | 3405 switch (Constraint[0]) { |
3301 case 'd': // Address register. Same as 'r' unless generating MIPS16 code. | 3406 case 'd': // Address register. Same as 'r' unless generating MIPS16 code. |
3302 case 'y': // Same as 'r'. Exists for compatibility. | 3407 case 'y': // Same as 'r'. Exists for compatibility. |
3303 case 'r': | 3408 case 'r': |
3349 R = parseRegForInlineAsmConstraint(Constraint, VT); | 3454 R = parseRegForInlineAsmConstraint(Constraint, VT); |
3350 | 3455 |
3351 if (R.second) | 3456 if (R.second) |
3352 return R; | 3457 return R; |
3353 | 3458 |
3354 return TargetLowering::getRegForInlineAsmConstraint(Constraint, VT); | 3459 return TargetLowering::getRegForInlineAsmConstraint(TRI, Constraint, VT); |
3355 } | 3460 } |
3356 | 3461 |
3357 /// LowerAsmOperandForConstraint - Lower the specified operand into the Ops | 3462 /// LowerAsmOperandForConstraint - Lower the specified operand into the Ops |
3358 /// vector. If it is invalid, don't add anything to Ops. | 3463 /// vector. If it is invalid, don't add anything to Ops. |
3359 void MipsTargetLowering::LowerAsmOperandForConstraint(SDValue Op, | 3464 void MipsTargetLowering::LowerAsmOperandForConstraint(SDValue Op, |
3360 std::string &Constraint, | 3465 std::string &Constraint, |
3361 std::vector<SDValue>&Ops, | 3466 std::vector<SDValue>&Ops, |
3362 SelectionDAG &DAG) const { | 3467 SelectionDAG &DAG) const { |
3468 SDLoc DL(Op); | |
3363 SDValue Result; | 3469 SDValue Result; |
3364 | 3470 |
3365 // Only support length 1 constraints for now. | 3471 // Only support length 1 constraints for now. |
3366 if (Constraint.length() > 1) return; | 3472 if (Constraint.length() > 1) return; |
3367 | 3473 |
3372 // If this fails, the parent routine will give an error | 3478 // If this fails, the parent routine will give an error |
3373 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Op)) { | 3479 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Op)) { |
3374 EVT Type = Op.getValueType(); | 3480 EVT Type = Op.getValueType(); |
3375 int64_t Val = C->getSExtValue(); | 3481 int64_t Val = C->getSExtValue(); |
3376 if (isInt<16>(Val)) { | 3482 if (isInt<16>(Val)) { |
3377 Result = DAG.getTargetConstant(Val, Type); | 3483 Result = DAG.getTargetConstant(Val, DL, Type); |
3378 break; | 3484 break; |
3379 } | 3485 } |
3380 } | 3486 } |
3381 return; | 3487 return; |
3382 case 'J': // integer zero | 3488 case 'J': // integer zero |
3383 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Op)) { | 3489 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Op)) { |
3384 EVT Type = Op.getValueType(); | 3490 EVT Type = Op.getValueType(); |
3385 int64_t Val = C->getZExtValue(); | 3491 int64_t Val = C->getZExtValue(); |
3386 if (Val == 0) { | 3492 if (Val == 0) { |
3387 Result = DAG.getTargetConstant(0, Type); | 3493 Result = DAG.getTargetConstant(0, DL, Type); |
3388 break; | 3494 break; |
3389 } | 3495 } |
3390 } | 3496 } |
3391 return; | 3497 return; |
3392 case 'K': // unsigned 16 bit immediate | 3498 case 'K': // unsigned 16 bit immediate |
3393 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Op)) { | 3499 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Op)) { |
3394 EVT Type = Op.getValueType(); | 3500 EVT Type = Op.getValueType(); |
3395 uint64_t Val = (uint64_t)C->getZExtValue(); | 3501 uint64_t Val = (uint64_t)C->getZExtValue(); |
3396 if (isUInt<16>(Val)) { | 3502 if (isUInt<16>(Val)) { |
3397 Result = DAG.getTargetConstant(Val, Type); | 3503 Result = DAG.getTargetConstant(Val, DL, Type); |
3398 break; | 3504 break; |
3399 } | 3505 } |
3400 } | 3506 } |
3401 return; | 3507 return; |
3402 case 'L': // signed 32 bit immediate where lower 16 bits are 0 | 3508 case 'L': // signed 32 bit immediate where lower 16 bits are 0 |
3403 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Op)) { | 3509 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Op)) { |
3404 EVT Type = Op.getValueType(); | 3510 EVT Type = Op.getValueType(); |
3405 int64_t Val = C->getSExtValue(); | 3511 int64_t Val = C->getSExtValue(); |
3406 if ((isInt<32>(Val)) && ((Val & 0xffff) == 0)){ | 3512 if ((isInt<32>(Val)) && ((Val & 0xffff) == 0)){ |
3407 Result = DAG.getTargetConstant(Val, Type); | 3513 Result = DAG.getTargetConstant(Val, DL, Type); |
3408 break; | 3514 break; |
3409 } | 3515 } |
3410 } | 3516 } |
3411 return; | 3517 return; |
3412 case 'N': // immediate in the range of -65535 to -1 (inclusive) | 3518 case 'N': // immediate in the range of -65535 to -1 (inclusive) |
3413 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Op)) { | 3519 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Op)) { |
3414 EVT Type = Op.getValueType(); | 3520 EVT Type = Op.getValueType(); |
3415 int64_t Val = C->getSExtValue(); | 3521 int64_t Val = C->getSExtValue(); |
3416 if ((Val >= -65535) && (Val <= -1)) { | 3522 if ((Val >= -65535) && (Val <= -1)) { |
3417 Result = DAG.getTargetConstant(Val, Type); | 3523 Result = DAG.getTargetConstant(Val, DL, Type); |
3418 break; | 3524 break; |
3419 } | 3525 } |
3420 } | 3526 } |
3421 return; | 3527 return; |
3422 case 'O': // signed 15 bit immediate | 3528 case 'O': // signed 15 bit immediate |
3423 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Op)) { | 3529 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Op)) { |
3424 EVT Type = Op.getValueType(); | 3530 EVT Type = Op.getValueType(); |
3425 int64_t Val = C->getSExtValue(); | 3531 int64_t Val = C->getSExtValue(); |
3426 if ((isInt<15>(Val))) { | 3532 if ((isInt<15>(Val))) { |
3427 Result = DAG.getTargetConstant(Val, Type); | 3533 Result = DAG.getTargetConstant(Val, DL, Type); |
3428 break; | 3534 break; |
3429 } | 3535 } |
3430 } | 3536 } |
3431 return; | 3537 return; |
3432 case 'P': // immediate in the range of 1 to 65535 (inclusive) | 3538 case 'P': // immediate in the range of 1 to 65535 (inclusive) |
3433 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Op)) { | 3539 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Op)) { |
3434 EVT Type = Op.getValueType(); | 3540 EVT Type = Op.getValueType(); |
3435 int64_t Val = C->getSExtValue(); | 3541 int64_t Val = C->getSExtValue(); |
3436 if ((Val <= 65535) && (Val >= 1)) { | 3542 if ((Val <= 65535) && (Val >= 1)) { |
3437 Result = DAG.getTargetConstant(Val, Type); | 3543 Result = DAG.getTargetConstant(Val, DL, Type); |
3438 break; | 3544 break; |
3439 } | 3545 } |
3440 } | 3546 } |
3441 return; | 3547 return; |
3442 } | 3548 } |
3447 } | 3553 } |
3448 | 3554 |
3449 TargetLowering::LowerAsmOperandForConstraint(Op, Constraint, Ops, DAG); | 3555 TargetLowering::LowerAsmOperandForConstraint(Op, Constraint, Ops, DAG); |
3450 } | 3556 } |
3451 | 3557 |
3452 bool MipsTargetLowering::isLegalAddressingMode(const AddrMode &AM, | 3558 bool MipsTargetLowering::isLegalAddressingMode(const DataLayout &DL, |
3453 Type *Ty) const { | 3559 const AddrMode &AM, Type *Ty, |
3560 unsigned AS) const { | |
3454 // No global is ever allowed as a base. | 3561 // No global is ever allowed as a base. |
3455 if (AM.BaseGV) | 3562 if (AM.BaseGV) |
3456 return false; | 3563 return false; |
3457 | 3564 |
3458 switch (AM.Scale) { | 3565 switch (AM.Scale) { |
3497 unsigned MipsTargetLowering::getJumpTableEncoding() const { | 3604 unsigned MipsTargetLowering::getJumpTableEncoding() const { |
3498 if (ABI.IsN64()) | 3605 if (ABI.IsN64()) |
3499 return MachineJumpTableInfo::EK_GPRel64BlockAddress; | 3606 return MachineJumpTableInfo::EK_GPRel64BlockAddress; |
3500 | 3607 |
3501 return TargetLowering::getJumpTableEncoding(); | 3608 return TargetLowering::getJumpTableEncoding(); |
3609 } | |
3610 | |
3611 bool MipsTargetLowering::useSoftFloat() const { | |
3612 return Subtarget.useSoftFloat(); | |
3502 } | 3613 } |
3503 | 3614 |
3504 void MipsTargetLowering::copyByValRegs( | 3615 void MipsTargetLowering::copyByValRegs( |
3505 SDValue Chain, SDLoc DL, std::vector<SDValue> &OutChains, SelectionDAG &DAG, | 3616 SDValue Chain, SDLoc DL, std::vector<SDValue> &OutChains, SelectionDAG &DAG, |
3506 const ISD::ArgFlagsTy &Flags, SmallVectorImpl<SDValue> &InVals, | 3617 const ISD::ArgFlagsTy &Flags, SmallVectorImpl<SDValue> &InVals, |
3521 (int)((ByValArgRegs.size() - FirstReg) * GPRSizeInBytes); | 3632 (int)((ByValArgRegs.size() - FirstReg) * GPRSizeInBytes); |
3522 else | 3633 else |
3523 FrameObjOffset = VA.getLocMemOffset(); | 3634 FrameObjOffset = VA.getLocMemOffset(); |
3524 | 3635 |
3525 // Create frame object. | 3636 // Create frame object. |
3526 EVT PtrTy = getPointerTy(); | 3637 EVT PtrTy = getPointerTy(DAG.getDataLayout()); |
3527 int FI = MFI->CreateFixedObject(FrameObjSize, FrameObjOffset, true); | 3638 int FI = MFI->CreateFixedObject(FrameObjSize, FrameObjOffset, true); |
3528 SDValue FIN = DAG.getFrameIndex(FI, PtrTy); | 3639 SDValue FIN = DAG.getFrameIndex(FI, PtrTy); |
3529 InVals.push_back(FIN); | 3640 InVals.push_back(FIN); |
3530 | 3641 |
3531 if (!NumRegs) | 3642 if (!NumRegs) |
3538 for (unsigned I = 0; I < NumRegs; ++I) { | 3649 for (unsigned I = 0; I < NumRegs; ++I) { |
3539 unsigned ArgReg = ByValArgRegs[FirstReg + I]; | 3650 unsigned ArgReg = ByValArgRegs[FirstReg + I]; |
3540 unsigned VReg = addLiveIn(MF, ArgReg, RC); | 3651 unsigned VReg = addLiveIn(MF, ArgReg, RC); |
3541 unsigned Offset = I * GPRSizeInBytes; | 3652 unsigned Offset = I * GPRSizeInBytes; |
3542 SDValue StorePtr = DAG.getNode(ISD::ADD, DL, PtrTy, FIN, | 3653 SDValue StorePtr = DAG.getNode(ISD::ADD, DL, PtrTy, FIN, |
3543 DAG.getConstant(Offset, PtrTy)); | 3654 DAG.getConstant(Offset, DL, PtrTy)); |
3544 SDValue Store = DAG.getStore(Chain, DL, DAG.getRegister(VReg, RegTy), | 3655 SDValue Store = DAG.getStore(Chain, DL, DAG.getRegister(VReg, RegTy), |
3545 StorePtr, MachinePointerInfo(FuncArg, Offset), | 3656 StorePtr, MachinePointerInfo(FuncArg, Offset), |
3546 false, false, 0); | 3657 false, false, 0); |
3547 OutChains.push_back(Store); | 3658 OutChains.push_back(Store); |
3548 } | 3659 } |
3558 const CCValAssign &VA) const { | 3669 const CCValAssign &VA) const { |
3559 unsigned ByValSizeInBytes = Flags.getByValSize(); | 3670 unsigned ByValSizeInBytes = Flags.getByValSize(); |
3560 unsigned OffsetInBytes = 0; // From beginning of struct | 3671 unsigned OffsetInBytes = 0; // From beginning of struct |
3561 unsigned RegSizeInBytes = Subtarget.getGPRSizeInBytes(); | 3672 unsigned RegSizeInBytes = Subtarget.getGPRSizeInBytes(); |
3562 unsigned Alignment = std::min(Flags.getByValAlign(), RegSizeInBytes); | 3673 unsigned Alignment = std::min(Flags.getByValAlign(), RegSizeInBytes); |
3563 EVT PtrTy = getPointerTy(), RegTy = MVT::getIntegerVT(RegSizeInBytes * 8); | 3674 EVT PtrTy = getPointerTy(DAG.getDataLayout()), |
3675 RegTy = MVT::getIntegerVT(RegSizeInBytes * 8); | |
3564 unsigned NumRegs = LastReg - FirstReg; | 3676 unsigned NumRegs = LastReg - FirstReg; |
3565 | 3677 |
3566 if (NumRegs) { | 3678 if (NumRegs) { |
3567 const ArrayRef<MCPhysReg> ArgRegs = ABI.GetByValArgRegs(); | 3679 ArrayRef<MCPhysReg> ArgRegs = ABI.GetByValArgRegs(); |
3568 bool LeftoverBytes = (NumRegs * RegSizeInBytes > ByValSizeInBytes); | 3680 bool LeftoverBytes = (NumRegs * RegSizeInBytes > ByValSizeInBytes); |
3569 unsigned I = 0; | 3681 unsigned I = 0; |
3570 | 3682 |
3571 // Copy words to registers. | 3683 // Copy words to registers. |
3572 for (; I < NumRegs - LeftoverBytes; ++I, OffsetInBytes += RegSizeInBytes) { | 3684 for (; I < NumRegs - LeftoverBytes; ++I, OffsetInBytes += RegSizeInBytes) { |
3573 SDValue LoadPtr = DAG.getNode(ISD::ADD, DL, PtrTy, Arg, | 3685 SDValue LoadPtr = DAG.getNode(ISD::ADD, DL, PtrTy, Arg, |
3574 DAG.getConstant(OffsetInBytes, PtrTy)); | 3686 DAG.getConstant(OffsetInBytes, DL, PtrTy)); |
3575 SDValue LoadVal = DAG.getLoad(RegTy, DL, Chain, LoadPtr, | 3687 SDValue LoadVal = DAG.getLoad(RegTy, DL, Chain, LoadPtr, |
3576 MachinePointerInfo(), false, false, false, | 3688 MachinePointerInfo(), false, false, false, |
3577 Alignment); | 3689 Alignment); |
3578 MemOpChains.push_back(LoadVal.getValue(1)); | 3690 MemOpChains.push_back(LoadVal.getValue(1)); |
3579 unsigned ArgReg = ArgRegs[FirstReg + I]; | 3691 unsigned ArgReg = ArgRegs[FirstReg + I]; |
3595 if (RemainingSizeInBytes < LoadSizeInBytes) | 3707 if (RemainingSizeInBytes < LoadSizeInBytes) |
3596 continue; | 3708 continue; |
3597 | 3709 |
3598 // Load subword. | 3710 // Load subword. |
3599 SDValue LoadPtr = DAG.getNode(ISD::ADD, DL, PtrTy, Arg, | 3711 SDValue LoadPtr = DAG.getNode(ISD::ADD, DL, PtrTy, Arg, |
3600 DAG.getConstant(OffsetInBytes, PtrTy)); | 3712 DAG.getConstant(OffsetInBytes, DL, |
3713 PtrTy)); | |
3601 SDValue LoadVal = DAG.getExtLoad( | 3714 SDValue LoadVal = DAG.getExtLoad( |
3602 ISD::ZEXTLOAD, DL, RegTy, Chain, LoadPtr, MachinePointerInfo(), | 3715 ISD::ZEXTLOAD, DL, RegTy, Chain, LoadPtr, MachinePointerInfo(), |
3603 MVT::getIntegerVT(LoadSizeInBytes * 8), false, false, false, | 3716 MVT::getIntegerVT(LoadSizeInBytes * 8), false, false, false, |
3604 Alignment); | 3717 Alignment); |
3605 MemOpChains.push_back(LoadVal.getValue(1)); | 3718 MemOpChains.push_back(LoadVal.getValue(1)); |
3611 Shamt = TotalBytesLoaded * 8; | 3724 Shamt = TotalBytesLoaded * 8; |
3612 else | 3725 else |
3613 Shamt = (RegSizeInBytes - (TotalBytesLoaded + LoadSizeInBytes)) * 8; | 3726 Shamt = (RegSizeInBytes - (TotalBytesLoaded + LoadSizeInBytes)) * 8; |
3614 | 3727 |
3615 SDValue Shift = DAG.getNode(ISD::SHL, DL, RegTy, LoadVal, | 3728 SDValue Shift = DAG.getNode(ISD::SHL, DL, RegTy, LoadVal, |
3616 DAG.getConstant(Shamt, MVT::i32)); | 3729 DAG.getConstant(Shamt, DL, MVT::i32)); |
3617 | 3730 |
3618 if (Val.getNode()) | 3731 if (Val.getNode()) |
3619 Val = DAG.getNode(ISD::OR, DL, RegTy, Val, Shift); | 3732 Val = DAG.getNode(ISD::OR, DL, RegTy, Val, Shift); |
3620 else | 3733 else |
3621 Val = Shift; | 3734 Val = Shift; |
3632 } | 3745 } |
3633 | 3746 |
3634 // Copy remainder of byval arg to it with memcpy. | 3747 // Copy remainder of byval arg to it with memcpy. |
3635 unsigned MemCpySize = ByValSizeInBytes - OffsetInBytes; | 3748 unsigned MemCpySize = ByValSizeInBytes - OffsetInBytes; |
3636 SDValue Src = DAG.getNode(ISD::ADD, DL, PtrTy, Arg, | 3749 SDValue Src = DAG.getNode(ISD::ADD, DL, PtrTy, Arg, |
3637 DAG.getConstant(OffsetInBytes, PtrTy)); | 3750 DAG.getConstant(OffsetInBytes, DL, PtrTy)); |
3638 SDValue Dst = DAG.getNode(ISD::ADD, DL, PtrTy, StackPtr, | 3751 SDValue Dst = DAG.getNode(ISD::ADD, DL, PtrTy, StackPtr, |
3639 DAG.getIntPtrConstant(VA.getLocMemOffset())); | 3752 DAG.getIntPtrConstant(VA.getLocMemOffset(), DL)); |
3640 Chain = DAG.getMemcpy(Chain, DL, Dst, Src, DAG.getConstant(MemCpySize, PtrTy), | 3753 Chain = DAG.getMemcpy(Chain, DL, Dst, Src, |
3754 DAG.getConstant(MemCpySize, DL, PtrTy), | |
3641 Alignment, /*isVolatile=*/false, /*AlwaysInline=*/false, | 3755 Alignment, /*isVolatile=*/false, /*AlwaysInline=*/false, |
3756 /*isTailCall=*/false, | |
3642 MachinePointerInfo(), MachinePointerInfo()); | 3757 MachinePointerInfo(), MachinePointerInfo()); |
3643 MemOpChains.push_back(Chain); | 3758 MemOpChains.push_back(Chain); |
3644 } | 3759 } |
3645 | 3760 |
3646 void MipsTargetLowering::writeVarArgRegs(std::vector<SDValue> &OutChains, | 3761 void MipsTargetLowering::writeVarArgRegs(std::vector<SDValue> &OutChains, |
3647 SDValue Chain, SDLoc DL, | 3762 SDValue Chain, SDLoc DL, |
3648 SelectionDAG &DAG, | 3763 SelectionDAG &DAG, |
3649 CCState &State) const { | 3764 CCState &State) const { |
3650 const ArrayRef<MCPhysReg> ArgRegs = ABI.GetVarArgRegs(); | 3765 ArrayRef<MCPhysReg> ArgRegs = ABI.GetVarArgRegs(); |
3651 unsigned Idx = State.getFirstUnallocated(ArgRegs.data(), ArgRegs.size()); | 3766 unsigned Idx = State.getFirstUnallocated(ArgRegs); |
3652 unsigned RegSizeInBytes = Subtarget.getGPRSizeInBytes(); | 3767 unsigned RegSizeInBytes = Subtarget.getGPRSizeInBytes(); |
3653 MVT RegTy = MVT::getIntegerVT(RegSizeInBytes * 8); | 3768 MVT RegTy = MVT::getIntegerVT(RegSizeInBytes * 8); |
3654 const TargetRegisterClass *RC = getRegClassFor(RegTy); | 3769 const TargetRegisterClass *RC = getRegClassFor(RegTy); |
3655 MachineFunction &MF = DAG.getMachineFunction(); | 3770 MachineFunction &MF = DAG.getMachineFunction(); |
3656 MachineFrameInfo *MFI = MF.getFrameInfo(); | 3771 MachineFrameInfo *MFI = MF.getFrameInfo(); |
3680 for (unsigned I = Idx; I < ArgRegs.size(); | 3795 for (unsigned I = Idx; I < ArgRegs.size(); |
3681 ++I, VaArgOffset += RegSizeInBytes) { | 3796 ++I, VaArgOffset += RegSizeInBytes) { |
3682 unsigned Reg = addLiveIn(MF, ArgRegs[I], RC); | 3797 unsigned Reg = addLiveIn(MF, ArgRegs[I], RC); |
3683 SDValue ArgValue = DAG.getCopyFromReg(Chain, DL, Reg, RegTy); | 3798 SDValue ArgValue = DAG.getCopyFromReg(Chain, DL, Reg, RegTy); |
3684 FI = MFI->CreateFixedObject(RegSizeInBytes, VaArgOffset, true); | 3799 FI = MFI->CreateFixedObject(RegSizeInBytes, VaArgOffset, true); |
3685 SDValue PtrOff = DAG.getFrameIndex(FI, getPointerTy()); | 3800 SDValue PtrOff = DAG.getFrameIndex(FI, getPointerTy(DAG.getDataLayout())); |
3686 SDValue Store = DAG.getStore(Chain, DL, ArgValue, PtrOff, | 3801 SDValue Store = DAG.getStore(Chain, DL, ArgValue, PtrOff, |
3687 MachinePointerInfo(), false, false, 0); | 3802 MachinePointerInfo(), false, false, 0); |
3688 cast<StoreSDNode>(Store.getNode())->getMemOperand()->setValue( | 3803 cast<StoreSDNode>(Store.getNode())->getMemOperand()->setValue( |
3689 (Value *)nullptr); | 3804 (Value *)nullptr); |
3690 OutChains.push_back(Store); | 3805 OutChains.push_back(Store); |
3702 unsigned FirstReg = 0; | 3817 unsigned FirstReg = 0; |
3703 unsigned NumRegs = 0; | 3818 unsigned NumRegs = 0; |
3704 | 3819 |
3705 if (State->getCallingConv() != CallingConv::Fast) { | 3820 if (State->getCallingConv() != CallingConv::Fast) { |
3706 unsigned RegSizeInBytes = Subtarget.getGPRSizeInBytes(); | 3821 unsigned RegSizeInBytes = Subtarget.getGPRSizeInBytes(); |
3707 const ArrayRef<MCPhysReg> IntArgRegs = ABI.GetByValArgRegs(); | 3822 ArrayRef<MCPhysReg> IntArgRegs = ABI.GetByValArgRegs(); |
3708 // FIXME: The O32 case actually describes no shadow registers. | 3823 // FIXME: The O32 case actually describes no shadow registers. |
3709 const MCPhysReg *ShadowRegs = | 3824 const MCPhysReg *ShadowRegs = |
3710 ABI.IsO32() ? IntArgRegs.data() : Mips64DPRegs; | 3825 ABI.IsO32() ? IntArgRegs.data() : Mips64DPRegs; |
3711 | 3826 |
3712 // We used to check the size as well but we can't do that anymore since | 3827 // We used to check the size as well but we can't do that anymore since |
3713 // CCState::HandleByVal() rounds up the size after calling this function. | 3828 // CCState::HandleByVal() rounds up the size after calling this function. |
3714 assert(!(Align % RegSizeInBytes) && | 3829 assert(!(Align % RegSizeInBytes) && |
3715 "Byval argument's alignment should be a multiple of" | 3830 "Byval argument's alignment should be a multiple of" |
3716 "RegSizeInBytes."); | 3831 "RegSizeInBytes."); |
3717 | 3832 |
3718 FirstReg = State->getFirstUnallocated(IntArgRegs.data(), IntArgRegs.size()); | 3833 FirstReg = State->getFirstUnallocated(IntArgRegs); |
3719 | 3834 |
3720 // If Align > RegSizeInBytes, the first arg register must be even. | 3835 // If Align > RegSizeInBytes, the first arg register must be even. |
3721 // FIXME: This condition happens to do the right thing but it's not the | 3836 // FIXME: This condition happens to do the right thing but it's not the |
3722 // right way to test it. We want to check that the stack frame offset | 3837 // right way to test it. We want to check that the stack frame offset |
3723 // of the register is aligned. | 3838 // of the register is aligned. |
3813 return BB; | 3928 return BB; |
3814 } | 3929 } |
3815 | 3930 |
3816 // FIXME? Maybe this could be a TableGen attribute on some registers and | 3931 // FIXME? Maybe this could be a TableGen attribute on some registers and |
3817 // this table could be generated automatically from RegInfo. | 3932 // this table could be generated automatically from RegInfo. |
3818 unsigned MipsTargetLowering::getRegisterByName(const char* RegName, | 3933 unsigned MipsTargetLowering::getRegisterByName(const char* RegName, EVT VT, |
3819 EVT VT) const { | 3934 SelectionDAG &DAG) const { |
3820 // Named registers is expected to be fairly rare. For now, just support $28 | 3935 // Named registers is expected to be fairly rare. For now, just support $28 |
3821 // since the linux kernel uses it. | 3936 // since the linux kernel uses it. |
3822 if (Subtarget.isGP64bit()) { | 3937 if (Subtarget.isGP64bit()) { |
3823 unsigned Reg = StringSwitch<unsigned>(RegName) | 3938 unsigned Reg = StringSwitch<unsigned>(RegName) |
3824 .Case("$28", Mips::GP_64) | 3939 .Case("$28", Mips::GP_64) |