[llvm] [RISCV] Implement foward inserting save/restore FRM instructions. (PR #77744)

Yeting Kuo via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 17 18:58:16 PST 2024


================
@@ -55,6 +61,107 @@ char RISCVInsertReadWriteCSR::ID = 0;
 INITIALIZE_PASS(RISCVInsertReadWriteCSR, DEBUG_TYPE,
                 RISCV_INSERT_READ_WRITE_CSR_NAME, false, false)
 
+// TODO: Use more accurate rounding mode at the start of MBB.
+bool RISCVInsertReadWriteCSR::emitWriteRoundingModeOpt(MachineBasicBlock &MBB) {
+  bool Changed = false;
+  MachineInstr *LastFRMChanger = nullptr;
+  std::optional<unsigned> CurrentRM = RISCVFPRndMode::DYN;
+  std::optional<Register> SavedFRM;
+
+  for (MachineInstr &MI : MBB) {
+    if (MI.getOpcode() == RISCV::SwapFRMImm ||
+        MI.getOpcode() == RISCV::WriteFRMImm) {
+      CurrentRM = MI.getOperand(0).getImm();
+      SavedFRM = std::nullopt;
+      continue;
+    }
+
+    if (MI.getOpcode() == RISCV::WriteFRM) {
+      CurrentRM = RISCVFPRndMode::DYN;
----------------
yetingk wrote:

My idea is using DYN as the right rounding mode when executing MI. And I found that I don't need  `std::optional` for CurrentRM, since we don't have variable frm instruction.

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


More information about the llvm-commits mailing list