]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
RISC-V: Weaken mem_thread_fence
authorPatrick O'Neill <patrick@rivosinc.com>
Fri, 7 Apr 2023 17:44:09 +0000 (10:44 -0700)
committerPatrick O'Neill <patrick@rivosinc.com>
Tue, 2 May 2023 20:08:04 +0000 (13:08 -0700)
This change brings atomic fences in line with table A.6 of the ISA
manual.

Relax mem_thread_fence according to the memmodel given.

2023-04-27 Patrick O'Neill <patrick@rivosinc.com>

gcc/ChangeLog:

* config/riscv/sync.md (mem_thread_fence_1): Change fence
depending on the given memory model.

Signed-off-by: Patrick O'Neill <patrick@rivosinc.com>
gcc/config/riscv/sync.md

index 3e6345e83a3541778f0de09f68506af7de1bd26c..ba132d8a1cea79ac38a88f19c9119ed6461d6e4f 100644 (file)
   DONE;
 })
 
-;; Until the RISC-V memory model (hence its mapping from C++) is finalized,
-;; conservatively emit a full FENCE.
 (define_insn "mem_thread_fence_1"
   [(set (match_operand:BLK 0 "" "")
        (unspec:BLK [(match_dup 0)] UNSPEC_MEMORY_BARRIER))
    (match_operand:SI 1 "const_int_operand" "")] ;; model
   ""
-  "fence\tiorw,iorw")
+  {
+    enum memmodel model = (enum memmodel) INTVAL (operands[1]);
+    model = memmodel_base (model);
+    if (model == MEMMODEL_SEQ_CST)
+       return "fence\trw,rw";
+    else if (model == MEMMODEL_ACQ_REL)
+       return "fence.tso";
+    else if (model == MEMMODEL_ACQUIRE)
+       return "fence\tr,rw";
+    else if (model == MEMMODEL_RELEASE)
+       return "fence\trw,w";
+  }
+  [(set (attr "length") (const_int 4))])
 
 ;; Atomic memory operations.