[clang] [llvm] [RISC-V] Add CSR read/write builtins (PR #85091)

Nemanja Ivanovic via cfe-commits cfe-commits at lists.llvm.org
Thu Mar 14 02:13:38 PDT 2024


================
@@ -74,6 +74,21 @@ let TargetPrefix = "riscv" in {
 
 } // TargetPrefix = "riscv"
 
+let TargetPrefix = "riscv" in {
+  // Zicsr
+  def int_riscv_csrr :
+    DefaultAttrsIntrinsic<[llvm_i32_ty], [llvm_i32_ty],
+                          [IntrNoMem, IntrHasSideEffects, ImmArg<ArgIndex<0>>]>;
+  def int_riscv_csrr64 :
+    DefaultAttrsIntrinsic<[llvm_i64_ty], [llvm_i64_ty],
+                          [IntrNoMem, IntrHasSideEffects, ImmArg<ArgIndex<0>>]>;
+  def int_riscv_csrw :
+    DefaultAttrsIntrinsic<[], [llvm_i32_ty, llvm_i32_ty],
+                          [IntrNoMem, IntrHasSideEffects, ImmArg<ArgIndex<0>>]>;
+  def int_riscv_csrw64 :
+    DefaultAttrsIntrinsic<[], [llvm_i64_ty, llvm_i64_ty],
+                          [IntrNoMem, IntrHasSideEffects, ImmArg<ArgIndex<0>>]>;
+} // TargetPrefix = "riscv"
----------------
nemanjai wrote:

TBH, I only implemented these two initially for 2 reasons
1. The user that requested them only needs these for now
2. To validate the approach with the community

I think ultimately, we could provide read, write, set, clear and swap (and handle producing the immediate forms if the operand allows it).

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


More information about the cfe-commits mailing list