@@ -359,6 +359,10 @@ MipsTargetLowering::MipsTargetLowering(const MipsTargetMachine &TM,
359359 setOperationAction (ISD::FCOPYSIGN, MVT::f64 , Custom);
360360 setOperationAction (ISD::FP_TO_SINT, MVT::i32 , Custom);
361361
362+ if (Subtarget.hasMips32r2 () ||
363+ getTargetMachine ().getTargetTriple ().isOSLinux ())
364+ setOperationAction (ISD::READCYCLECOUNTER, MVT::i64 , Custom);
365+
362366 // Lower fmin/fmax/fclass operations for MIPS R6.
363367 if (Subtarget.hasMips32r6 ()) {
364368 setOperationAction (ISD::FMINNUM_IEEE, MVT::f32 , Legal);
@@ -1311,6 +1315,8 @@ LowerOperation(SDValue Op, SelectionDAG &DAG) const
13111315 case ISD::STORE: return lowerSTORE (Op, DAG);
13121316 case ISD::EH_DWARF_CFA: return lowerEH_DWARF_CFA (Op, DAG);
13131317 case ISD::FP_TO_SINT: return lowerFP_TO_SINT (Op, DAG);
1318+ case ISD::READCYCLECOUNTER:
1319+ return lowerREADCYCLECOUNTER (Op, DAG);
13141320 }
13151321 return SDValue ();
13161322}
@@ -2092,6 +2098,44 @@ MachineBasicBlock *MipsTargetLowering::emitAtomicCmpSwapPartword(
20922098 return exitMBB;
20932099}
20942100
2101+ SDValue MipsTargetLowering::lowerREADCYCLECOUNTER (SDValue Op,
2102+ SelectionDAG &DAG) const {
2103+ SmallVector<SDValue, 3 > Results;
2104+ SDLoc DL (Op);
2105+ MachineFunction &MF = DAG.getMachineFunction ();
2106+ unsigned RdhwrOpc, DestReg;
2107+ EVT PtrVT = getPointerTy (DAG.getDataLayout ());
2108+
2109+ if (PtrVT == MVT::i64 ) {
2110+ RdhwrOpc = Mips::RDHWR64;
2111+ DestReg = MF.getRegInfo ().createVirtualRegister (getRegClassFor (MVT::i64 ));
2112+ SDNode *Rdhwr = DAG.getMachineNode (RdhwrOpc, DL, MVT::i64 , MVT::Glue,
2113+ DAG.getRegister (Mips::HWR2, MVT::i32 ),
2114+ DAG.getTargetConstant (0 , DL, MVT::i32 ));
2115+ SDValue Chain = DAG.getCopyToReg (DAG.getEntryNode (), DL, DestReg,
2116+ SDValue (Rdhwr, 0 ), SDValue (Rdhwr, 1 ));
2117+ SDValue ResNode =
2118+ DAG.getCopyFromReg (Chain, DL, DestReg, MVT::i64 , Chain.getValue (1 ));
2119+ Results.push_back (ResNode);
2120+ Results.push_back (ResNode.getValue (1 ));
2121+ } else {
2122+ RdhwrOpc = Mips::RDHWR;
2123+ DestReg = MF.getRegInfo ().createVirtualRegister (getRegClassFor (MVT::i32 ));
2124+ SDNode *Rdhwr = DAG.getMachineNode (RdhwrOpc, DL, MVT::i32 , MVT::Glue,
2125+ DAG.getRegister (Mips::HWR2, MVT::i32 ),
2126+ DAG.getTargetConstant (0 , DL, MVT::i32 ));
2127+ SDValue Chain = DAG.getCopyToReg (DAG.getEntryNode (), DL, DestReg,
2128+ SDValue (Rdhwr, 0 ), SDValue (Rdhwr, 1 ));
2129+ SDValue ResNode =
2130+ DAG.getCopyFromReg (Chain, DL, DestReg, MVT::i32 , Chain.getValue (1 ));
2131+ Results.push_back (DAG.getNode (ISD::BUILD_PAIR, DL, MVT::i64 , ResNode,
2132+ DAG.getConstant (0 , DL, MVT::i32 )));
2133+ Results.push_back (ResNode.getValue (1 ));
2134+ }
2135+
2136+ return DAG.getMergeValues (Results, DL);
2137+ }
2138+
20952139SDValue MipsTargetLowering::lowerBRCOND (SDValue Op, SelectionDAG &DAG) const {
20962140 // The first operand is the chain, the second is the condition, the third is
20972141 // the block to branch to if the condition is true.
0 commit comments