@@ -357,6 +357,10 @@ MipsTargetLowering::MipsTargetLowering(const MipsTargetMachine &TM,
357357 setOperationAction (ISD::FCOPYSIGN, MVT::f64 , Custom);
358358 setOperationAction (ISD::FP_TO_SINT, MVT::i32 , Custom);
359359
360+ if (Subtarget.hasMips32r2 () ||
361+ getTargetMachine ().getTargetTriple ().isOSLinux ())
362+ setOperationAction (ISD::READCYCLECOUNTER, MVT::i64 , Custom);
363+
360364 // Lower fmin/fmax/fclass operations for MIPS R6.
361365 if (Subtarget.hasMips32r6 ()) {
362366 setOperationAction (ISD::FMINNUM_IEEE, MVT::f32 , Legal);
@@ -1315,6 +1319,8 @@ LowerOperation(SDValue Op, SelectionDAG &DAG) const
13151319 case ISD::STORE: return lowerSTORE (Op, DAG);
13161320 case ISD::EH_DWARF_CFA: return lowerEH_DWARF_CFA (Op, DAG);
13171321 case ISD::FP_TO_SINT: return lowerFP_TO_SINT (Op, DAG);
1322+ case ISD::READCYCLECOUNTER:
1323+ return lowerREADCYCLECOUNTER (Op, DAG);
13181324 }
13191325 return SDValue ();
13201326}
@@ -2096,6 +2102,44 @@ MachineBasicBlock *MipsTargetLowering::emitAtomicCmpSwapPartword(
20962102 return exitMBB;
20972103}
20982104
2105+ SDValue MipsTargetLowering::lowerREADCYCLECOUNTER (SDValue Op,
2106+ SelectionDAG &DAG) const {
2107+ SmallVector<SDValue, 3 > Results;
2108+ SDLoc DL (Op);
2109+ MachineFunction &MF = DAG.getMachineFunction ();
2110+ unsigned RdhwrOpc, DestReg;
2111+ EVT PtrVT = getPointerTy (DAG.getDataLayout ());
2112+
2113+ if (PtrVT == MVT::i64 ) {
2114+ RdhwrOpc = Mips::RDHWR64;
2115+ DestReg = MF.getRegInfo ().createVirtualRegister (getRegClassFor (MVT::i64 ));
2116+ SDNode *Rdhwr = DAG.getMachineNode (RdhwrOpc, DL, MVT::i64 , MVT::Glue,
2117+ DAG.getRegister (Mips::HWR2, MVT::i32 ),
2118+ DAG.getTargetConstant (0 , DL, MVT::i32 ));
2119+ SDValue Chain = DAG.getCopyToReg (DAG.getEntryNode (), DL, DestReg,
2120+ SDValue (Rdhwr, 0 ), SDValue (Rdhwr, 1 ));
2121+ SDValue ResNode =
2122+ DAG.getCopyFromReg (Chain, DL, DestReg, MVT::i64 , Chain.getValue (1 ));
2123+ Results.push_back (ResNode);
2124+ Results.push_back (ResNode.getValue (1 ));
2125+ } else {
2126+ RdhwrOpc = Mips::RDHWR;
2127+ DestReg = MF.getRegInfo ().createVirtualRegister (getRegClassFor (MVT::i32 ));
2128+ SDNode *Rdhwr = DAG.getMachineNode (RdhwrOpc, DL, MVT::i32 , MVT::Glue,
2129+ DAG.getRegister (Mips::HWR2, MVT::i32 ),
2130+ DAG.getTargetConstant (0 , DL, MVT::i32 ));
2131+ SDValue Chain = DAG.getCopyToReg (DAG.getEntryNode (), DL, DestReg,
2132+ SDValue (Rdhwr, 0 ), SDValue (Rdhwr, 1 ));
2133+ SDValue ResNode =
2134+ DAG.getCopyFromReg (Chain, DL, DestReg, MVT::i32 , Chain.getValue (1 ));
2135+ Results.push_back (DAG.getNode (ISD::BUILD_PAIR, DL, MVT::i64 , ResNode,
2136+ DAG.getConstant (0 , DL, MVT::i32 )));
2137+ Results.push_back (ResNode.getValue (1 ));
2138+ }
2139+
2140+ return DAG.getMergeValues (Results, DL);
2141+ }
2142+
20992143SDValue MipsTargetLowering::lowerBRCOND (SDValue Op, SelectionDAG &DAG) const {
21002144 // The first operand is the chain, the second is the condition, the third is
21012145 // the block to branch to if the condition is true.
0 commit comments