forked from riscvarchive/riscv-gcc
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The RISC-V Ztso extension currently has no effect on generated code. With the additional ordering constraints guarenteed by Ztso, we can emit more optimized atomic mappings than the RVWMO mappings. This PR implements the Ztso psABI mappings[1]. [1] riscv-non-isa/riscv-elf-psabi-doc#391 2023-08-08 Patrick O'Neill <patrick@rivosinc.com> gcc/ChangeLog: * common/config/riscv/riscv-common.cc: Add Ztso and mark Ztso as dependent on 'a' extension. * config/riscv/riscv-opts.h (MASK_ZTSO): New mask. (TARGET_ZTSO): New target. * config/riscv/riscv.cc (riscv_memmodel_needs_amo_acquire): Add Ztso case. (riscv_memmodel_needs_amo_release): Add Ztso case. (riscv_print_operand): Add Ztso case for LR/SC annotations. * config/riscv/riscv.md: Import sync-rvwmo.md and sync-ztso.md. * config/riscv/riscv.opt: Add Ztso target variable. * config/riscv/sync.md (mem_thread_fence_1): Expand to RVWMO or Ztso specific insn. (atomic_load<mode>): Expand to RVWMO or Ztso specific insn. (atomic_store<mode>): Expand to RVWMO or Ztso specific insn. * config/riscv/sync-rvwmo.md: New file. Seperate out RVWMO specific load/store/fence mappings. * config/riscv/sync-ztso.md: New file. Seperate out Ztso specific load/store/fence mappings. gcc/testsuite/ChangeLog: * gcc.target/riscv/amo-table-ztso-amo-add-1.c: New test. * gcc.target/riscv/amo-table-ztso-amo-add-2.c: New test. * gcc.target/riscv/amo-table-ztso-amo-add-3.c: New test. * gcc.target/riscv/amo-table-ztso-amo-add-4.c: New test. * gcc.target/riscv/amo-table-ztso-amo-add-5.c: New test. * gcc.target/riscv/amo-table-ztso-compare-exchange-1.c: New test. * gcc.target/riscv/amo-table-ztso-compare-exchange-2.c: New test. * gcc.target/riscv/amo-table-ztso-compare-exchange-3.c: New test. * gcc.target/riscv/amo-table-ztso-compare-exchange-4.c: New test. * gcc.target/riscv/amo-table-ztso-compare-exchange-5.c: New test. * gcc.target/riscv/amo-table-ztso-compare-exchange-6.c: New test. * gcc.target/riscv/amo-table-ztso-compare-exchange-7.c: New test. * gcc.target/riscv/amo-table-ztso-fence-1.c: New test. * gcc.target/riscv/amo-table-ztso-fence-2.c: New test. * gcc.target/riscv/amo-table-ztso-fence-3.c: New test. * gcc.target/riscv/amo-table-ztso-fence-4.c: New test. * gcc.target/riscv/amo-table-ztso-fence-5.c: New test. * gcc.target/riscv/amo-table-ztso-load-1.c: New test. * gcc.target/riscv/amo-table-ztso-load-2.c: New test. * gcc.target/riscv/amo-table-ztso-load-3.c: New test. * gcc.target/riscv/amo-table-ztso-store-1.c: New test. * gcc.target/riscv/amo-table-ztso-store-2.c: New test. * gcc.target/riscv/amo-table-ztso-store-3.c: New test. * gcc.target/riscv/amo-table-ztso-subword-amo-add-1.c: New test. * gcc.target/riscv/amo-table-ztso-subword-amo-add-2.c: New test. * gcc.target/riscv/amo-table-ztso-subword-amo-add-3.c: New test. * gcc.target/riscv/amo-table-ztso-subword-amo-add-4.c: New test. * gcc.target/riscv/amo-table-ztso-subword-amo-add-5.c: New test. Signed-off-by: Patrick O'Neill <patrick@rivosinc.com>
- Loading branch information
1 parent
937591d
commit 0ac3232
Showing
36 changed files
with
612 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
;; Machine description for RISC-V atomic operations. | ||
;; Copyright (C) 2011-2023 Free Software Foundation, Inc. | ||
;; Contributed by Andrew Waterman (andrew@sifive.com). | ||
;; Based on MIPS target for GNU compiler. | ||
|
||
;; This file is part of GCC. | ||
|
||
;; GCC is free software; you can redistribute it and/or modify | ||
;; it under the terms of the GNU General Public License as published by | ||
;; the Free Software Foundation; either version 3, or (at your option) | ||
;; any later version. | ||
|
||
;; GCC is distributed in the hope that it will be useful, | ||
;; but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
;; GNU General Public License for more details. | ||
|
||
;; You should have received a copy of the GNU General Public License | ||
;; along with GCC; see the file COPYING3. If not see | ||
;; <http://www.gnu.org/licenses/>. | ||
|
||
;; Memory barrier. | ||
|
||
(define_insn "mem_thread_fence_rvwmo" | ||
[(set (match_operand:BLK 0 "" "") | ||
(unspec:BLK [(match_dup 0)] UNSPEC_MEMORY_BARRIER)) | ||
(match_operand:SI 1 "const_int_operand" "")] ;; model | ||
"!TARGET_ZTSO" | ||
{ | ||
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"; | ||
else | ||
gcc_unreachable (); | ||
} | ||
[(set (attr "length") (const_int 4))]) | ||
|
||
;; Atomic memory operations. | ||
|
||
(define_insn "atomic_load_rvwmo<mode>" | ||
[(set (match_operand:GPR 0 "register_operand" "=r") | ||
(unspec_volatile:GPR | ||
[(match_operand:GPR 1 "memory_operand" "A") | ||
(match_operand:SI 2 "const_int_operand")] ;; model | ||
UNSPEC_ATOMIC_LOAD))] | ||
"TARGET_ATOMIC && !TARGET_ZTSO" | ||
{ | ||
enum memmodel model = (enum memmodel) INTVAL (operands[2]); | ||
model = memmodel_base (model); | ||
|
||
if (model == MEMMODEL_SEQ_CST) | ||
return "fence\trw,rw\;" | ||
"l<amo>\t%0,%1\;" | ||
"fence\tr,rw"; | ||
if (model == MEMMODEL_ACQUIRE) | ||
return "l<amo>\t%0,%1\;" | ||
"fence\tr,rw"; | ||
else | ||
return "l<amo>\t%0,%1"; | ||
} | ||
[(set_attr "type" "atomic") | ||
(set (attr "length") (const_int 12))]) | ||
|
||
;; Implement atomic stores with conservative fences. | ||
;; This allows us to be compatible with the ISA manual Table A.6 and Table A.7. | ||
(define_insn "atomic_store_rvwmo<mode>" | ||
[(set (match_operand:GPR 0 "memory_operand" "=A") | ||
(unspec_volatile:GPR | ||
[(match_operand:GPR 1 "reg_or_0_operand" "rJ") | ||
(match_operand:SI 2 "const_int_operand")] ;; model | ||
UNSPEC_ATOMIC_STORE))] | ||
"TARGET_ATOMIC && !TARGET_ZTSO" | ||
{ | ||
enum memmodel model = (enum memmodel) INTVAL (operands[2]); | ||
model = memmodel_base (model); | ||
|
||
if (model == MEMMODEL_SEQ_CST) | ||
return "fence\trw,w\;" | ||
"s<amo>\t%z1,%0\;" | ||
"fence\trw,rw"; | ||
if (model == MEMMODEL_RELEASE) | ||
return "fence\trw,w\;" | ||
"s<amo>\t%z1,%0"; | ||
else | ||
return "s<amo>\t%z1,%0"; | ||
} | ||
[(set_attr "type" "atomic") | ||
(set (attr "length") (const_int 12))]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
;; Machine description for RISC-V atomic operations. | ||
;; Copyright (C) 2011-2023 Free Software Foundation, Inc. | ||
;; Contributed by Andrew Waterman (andrew@sifive.com). | ||
;; Based on MIPS target for GNU compiler. | ||
|
||
;; This file is part of GCC. | ||
|
||
;; GCC is free software; you can redistribute it and/or modify | ||
;; it under the terms of the GNU General Public License as published by | ||
;; the Free Software Foundation; either version 3, or (at your option) | ||
;; any later version. | ||
|
||
;; GCC is distributed in the hope that it will be useful, | ||
;; but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
;; GNU General Public License for more details. | ||
|
||
;; You should have received a copy of the GNU General Public License | ||
;; along with GCC; see the file COPYING3. If not see | ||
;; <http://www.gnu.org/licenses/>. | ||
|
||
;; Memory barriers. | ||
|
||
(define_insn "mem_thread_fence_ztso" | ||
[(set (match_operand:BLK 0 "" "") | ||
(unspec:BLK [(match_dup 0)] UNSPEC_MEMORY_BARRIER)) | ||
(match_operand:SI 1 "const_int_operand" "")] ;; model | ||
"TARGET_ZTSO" | ||
{ | ||
enum memmodel model = (enum memmodel) INTVAL (operands[1]); | ||
model = memmodel_base (model); | ||
|
||
if (model == MEMMODEL_SEQ_CST) | ||
return "fence\trw,rw"; | ||
else | ||
gcc_unreachable (); | ||
} | ||
[(set (attr "length") (const_int 4))]) | ||
|
||
;; Atomic memory operations. | ||
|
||
(define_insn "atomic_load_ztso<mode>" | ||
[(set (match_operand:GPR 0 "register_operand" "=r") | ||
(unspec_volatile:GPR | ||
[(match_operand:GPR 1 "memory_operand" "A") | ||
(match_operand:SI 2 "const_int_operand")] ;; model | ||
UNSPEC_ATOMIC_LOAD))] | ||
"TARGET_ATOMIC && TARGET_ZTSO" | ||
{ | ||
enum memmodel model = (enum memmodel) INTVAL (operands[2]); | ||
model = memmodel_base (model); | ||
|
||
if (model == MEMMODEL_SEQ_CST) | ||
return "fence\trw,rw\;" | ||
"l<amo>\t%0,%1\;"; | ||
else | ||
return "l<amo>\t%0,%1"; | ||
} | ||
[(set_attr "type" "atomic") | ||
(set (attr "length") (const_int 12))]) | ||
|
||
(define_insn "atomic_store_ztso<mode>" | ||
[(set (match_operand:GPR 0 "memory_operand" "=A") | ||
(unspec_volatile:GPR | ||
[(match_operand:GPR 1 "reg_or_0_operand" "rJ") | ||
(match_operand:SI 2 "const_int_operand")] ;; model | ||
UNSPEC_ATOMIC_STORE))] | ||
"TARGET_ATOMIC && TARGET_ZTSO" | ||
{ | ||
enum memmodel model = (enum memmodel) INTVAL (operands[2]); | ||
model = memmodel_base (model); | ||
|
||
if (model == MEMMODEL_SEQ_CST) | ||
return "s<amo>\t%z1,%0\;" | ||
"fence\trw,rw"; | ||
else | ||
return "s<amo>\t%z1,%0"; | ||
} | ||
[(set_attr "type" "atomic") | ||
(set (attr "length") (const_int 8))]) |
Oops, something went wrong.