Skip to content

Commit 4fd5d93

Browse files
authored
[RISCV] Emitting proper atomic ABI tag when Zalasr is enabled (llvm#121017)
When Zalasr is enabled, it will emit the A7 atomic ABI tag. Zalasr is the load-acquire and store-release extension, and the reason A7 (and A6S) exists is to support it. The A7 atomic ABI is compatible with A6S (which is what is currently emitted as the tag), but A7 is not compatible with A6C, while A6C and A6S are compatible. https://github.com/riscv-non-isa/riscv-elf-psabi-doc/blob/master/riscv-atomic.adoc#risc-v-atomics-mappings https://github.com/riscv-non-isa/riscv-elf-psabi-doc/blob/master/riscv-elf.adoc#tag_riscv_atomic_abi-14-uleb128version
1 parent 41e58b6 commit 4fd5d93

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

llvm/lib/Target/RISCV/MCTargetDesc/RISCVTargetStreamer.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,13 @@ void RISCVTargetStreamer::emitTargetAttributes(const MCSubtargetInfo &STI,
8585
}
8686

8787
if (RiscvAbiAttr && STI.hasFeature(RISCV::FeatureStdExtA)) {
88-
unsigned AtomicABITag = static_cast<unsigned>(
89-
STI.hasFeature(RISCV::FeatureNoTrailingSeqCstFence)
90-
? RISCVAttrs::RISCVAtomicAbiTag::A6C
91-
: RISCVAttrs::RISCVAtomicAbiTag::A6S);
88+
unsigned AtomicABITag;
89+
if (STI.hasFeature(RISCV::FeatureStdExtZalasr))
90+
AtomicABITag = static_cast<unsigned>(RISCVAttrs::RISCVAtomicAbiTag::A7);
91+
else if (STI.hasFeature(RISCV::FeatureNoTrailingSeqCstFence))
92+
AtomicABITag = static_cast<unsigned>(RISCVAttrs::RISCVAtomicAbiTag::A6C);
93+
else
94+
AtomicABITag = static_cast<unsigned>(RISCVAttrs::RISCVAtomicAbiTag::A6S);
9295
emitAttribute(RISCVAttrs::ATOMIC_ABI, AtomicABITag);
9396
}
9497
}

llvm/test/CodeGen/RISCV/attributes.ll

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@
160160
; RUN: llc -mtriple=riscv64 -mattr=+m,+zmmul %s -o - | FileCheck --check-prefixes=CHECK,RV64MZMMUL %s
161161
; RUN: llc -mtriple=riscv64 -mattr=+a,no-trailing-seq-cst-fence --riscv-abi-attributes %s -o - | FileCheck --check-prefixes=CHECK,RV64A,A6C %s
162162
; RUN: llc -mtriple=riscv64 -mattr=+a --riscv-abi-attributes %s -o - | FileCheck --check-prefixes=CHECK,RV64A,A6S %s
163+
; RUN: llc -mtriple=riscv64 -mattr=+a,experimental-zalasr --riscv-abi-attributes %s -o - | FileCheck --check-prefixes=CHECK,RV64ZALASRA,A7 %s
163164
; RUN: llc -mtriple=riscv64 -mattr=+b %s -o - | FileCheck --check-prefixes=CHECK,RV64B %s
164165
; RUN: llc -mtriple=riscv64 -mattr=+f %s -o - | FileCheck --check-prefixes=CHECK,RV64F %s
165166
; RUN: llc -mtriple=riscv64 -mattr=+d %s -o - | FileCheck --check-prefixes=CHECK,RV64D %s
@@ -608,6 +609,7 @@
608609
; RV64ZVFBFWMA: .attribute 5, "rv64i2p1_f2p2_zicsr2p0_zfbfmin1p0_zve32f1p0_zve32x1p0_zvfbfmin1p0_zvfbfwma1p0_zvl32b1p0"
609610
; RV64ZACAS: .attribute 5, "rv64i2p1_zaamo1p0_zacas1p0"
610611
; RV64ZALASR: .attribute 5, "rv64i2p1_zalasr0p1"
612+
; RV64ZALASRA: .attribute 5, "rv64i2p1_a2p1_zaamo1p0_zalasr0p1_zalrsc1p0"
611613
; RV64ZICFILP: .attribute 5, "rv64i2p1_zicfilp1p0_zicsr2p0"
612614
; RV64ZABHA: .attribute 5, "rv64i2p1_zaamo1p0_zabha1p0"
613615
; RV64ZVBC32E: .attribute 5, "rv64i2p1_zicsr2p0_zvbc32e0p7_zve32x1p0_zvl32b1p0"
@@ -645,4 +647,5 @@ define i8 @atomic_load_i8_seq_cst(ptr %a) nounwind {
645647
ret i8 %1
646648
; A6S: .attribute 14, 2
647649
; A6C: .attribute 14, 1
650+
; A7: .attribute 14, 3
648651
}

0 commit comments

Comments
 (0)