[llvm-branch-commits] [RISCV] Support llvm.readsteadycounter intrinsic (PR #82322)

Yingwei Zheng via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Tue Feb 20 01:20:22 PST 2024


================
@@ -11725,13 +11727,27 @@ void RISCVTargetLowering::ReplaceNodeResults(SDNode *N,
     Results.push_back(Result);
     break;
   }
-  case ISD::READCYCLECOUNTER: {
-    assert(!Subtarget.is64Bit() &&
-           "READCYCLECOUNTER only has custom type legalization on riscv32");
+  case ISD::READCYCLECOUNTER:
+  case ISD::READSTEADYCOUNTER: {
+    assert(!Subtarget.is64Bit() && "READCYCLECOUNTER/READSTEADYCOUNTER only "
+                                   "has custom type legalization on riscv32");
 
+    SDValue LoCounter, HiCounter;
+    MVT XLenVT = Subtarget.getXLenVT();
+    if (N->getOpcode() == ISD::READCYCLECOUNTER) {
+      LoCounter = DAG.getConstant(
+          RISCVSysReg::lookupSysRegByName("CYCLE")->Encoding, DL, XLenVT);
+      HiCounter = DAG.getConstant(
+          RISCVSysReg::lookupSysRegByName("CYCLEH")->Encoding, DL, XLenVT);
+    } else if (N->getOpcode() == ISD::READSTEADYCOUNTER) {
----------------
dtcxzyw wrote:

```suggestion
    } else {
```

https://github.com/llvm/llvm-project/pull/82322


More information about the llvm-branch-commits mailing list