[llvm-branch-commits] [lld] [llvm] Reapply "[llvm][RISCV] Enable trailing fences for seq-cst stores by default (#87376)" (PR #90267)

Paul Kirth via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Mon Jul 1 10:54:26 PDT 2024


https://github.com/ilovepi updated https://github.com/llvm/llvm-project/pull/90267

>From 788f58b302f20a000db3a9741e54cc861c9dcb88 Mon Sep 17 00:00:00 2001
From: Paul Kirth <paulkirth at google.com>
Date: Mon, 1 Jul 2024 10:13:23 -0700
Subject: [PATCH] Fix mismerge

Created using spr 1.3.4
---
 lld/ELF/Arch/RISCV.cpp                        | 70 ++++++++-----------
 lld/test/ELF/riscv-attributes.s               |  4 +-
 llvm/include/llvm/Support/RISCVAttributes.h   |  4 +-
 .../MCTargetDesc/RISCVTargetStreamer.cpp      | 15 ++--
 4 files changed, 39 insertions(+), 54 deletions(-)

diff --git a/lld/ELF/Arch/RISCV.cpp b/lld/ELF/Arch/RISCV.cpp
index 1d9be92601006..0d0ab5de9acc1 100644
--- a/lld/ELF/Arch/RISCV.cpp
+++ b/lld/ELF/Arch/RISCV.cpp
@@ -1088,65 +1088,51 @@ static void mergeAtomic(DenseMap<unsigned, unsigned>::iterator it,
                         const InputSectionBase *oldSection,
                         const InputSectionBase *newSection, unsigned int oldTag,
                         unsigned int newTag) {
-  using RISCVAttrs::RISCVAtomicAbiTag;
+  using RISCVAttrs::RISCVAtomicAbiTag::AtomicABI;
   // Same tags stay the same, and UNKNOWN is compatible with anything
-  if (oldTag == newTag ||
-      newTag == static_cast<unsigned>(RISCVAtomicAbiTag::UNKNOWN))
+  if (oldTag == newTag || newTag == AtomicABI::UNKNOWN)
     return;
 
-  auto reportAbiError = [&]() {
-    errorOrWarn("atomic abi mismatch for " + oldSection->name + "\n>>> " +
-                toString(oldSection) + ": atomic_abi=" + Twine(oldTag) +
-                "\n>>> " + toString(newSection) +
-                ": atomic_abi=" + Twine(newTag));
-  };
-
-  switch (static_cast<RISCVAtomicAbiTag>(oldTag)) {
-  case RISCVAtomicAbiTag::UNKNOWN:
+  switch (oldTag) {
+  case AtomicABI::UNKNOWN:
     it->getSecond() = newTag;
     return;
-  case RISCVAtomicAbiTag::A6C:
-    switch (static_cast<RISCVAtomicAbiTag>(newTag)) {
-    case RISCVAtomicAbiTag::A6S:
-      it->getSecond() = static_cast<unsigned>(RISCVAtomicAbiTag::A6C);
+  case AtomicABI::A6C:
+    switch (newTag) {
+    case AtomicABI::A6S:
+      it->getSecond() = AtomicABI::A6C;
       return;
-    case RISCVAtomicAbiTag::A7:
-      reportAbiError();
+    case AtomicABI::A7:
+      errorOrWarn(toString(oldSection) + " has atomic_abi=" + Twine(oldTag) +
+                  " but " + toString(newSection) +
+                  " has atomic_abi=" + Twine(newTag));
       return;
-    case RISCVAttrs::RISCVAtomicAbiTag::UNKNOWN:
-    case RISCVAttrs::RISCVAtomicAbiTag::A6C:
-      break;
     };
-    break;
 
-  case RISCVAtomicAbiTag::A6S:
-    switch (static_cast<RISCVAtomicAbiTag>(newTag)) {
-    case RISCVAtomicAbiTag::A6C:
-      it->getSecond() = static_cast<unsigned>(RISCVAtomicAbiTag::A6C);
+  case AtomicABI::A6S:
+    switch (newTag) {
+    case AtomicABI::A6C:
+      it->getSecond() = AtomicABI::A6C;
       return;
-    case RISCVAtomicAbiTag::A7:
-      it->getSecond() = static_cast<unsigned>(RISCVAtomicAbiTag::A7);
+    case AtomicABI::A7:
+      it->getSecond() = AtomicABI::A7;
       return;
-    case RISCVAttrs::RISCVAtomicAbiTag::UNKNOWN:
-    case RISCVAttrs::RISCVAtomicAbiTag::A6S:
-      break;
     };
-    break;
 
-  case RISCVAtomicAbiTag::A7:
-    switch (static_cast<RISCVAtomicAbiTag>(newTag)) {
-    case RISCVAtomicAbiTag::A6S:
-      it->getSecond() = static_cast<unsigned>(RISCVAtomicAbiTag::A7);
+  case AtomicABI::A7:
+    switch (newTag) {
+    case AtomicABI::A6S:
+      it->getSecond() = AtomicABI::A7;
       return;
-    case RISCVAtomicAbiTag::A6C:
-      reportAbiError();
+    case AtomicABI::A6C:
+      errorOrWarn(toString(oldSection) + " has atomic_abi=" + Twine(oldTag) +
+                  " but " + toString(newSection) +
+                  " has atomic_abi=" + Twine(newTag));
       return;
-    case RISCVAttrs::RISCVAtomicAbiTag::UNKNOWN:
-    case RISCVAttrs::RISCVAtomicAbiTag::A7:
-      break;
     };
+  default:
+    llvm_unreachable("unknown AtomicABI");
   };
-  llvm_unreachable("unknown AtomicABI");
 }
 
 static RISCVAttributesSection *
diff --git a/lld/test/ELF/riscv-attributes.s b/lld/test/ELF/riscv-attributes.s
index 38b0fe8e7797e..91321f33297aa 100644
--- a/lld/test/ELF/riscv-attributes.s
+++ b/lld/test/ELF/riscv-attributes.s
@@ -48,9 +48,7 @@
 # RUN: llvm-mc -filetype=obj -triple=riscv64  atomic_abi_A6C.s -o atomic_abi_A6C.o
 # RUN: llvm-mc -filetype=obj -triple=riscv64  atomic_abi_A7.s -o atomic_abi_A7.o
 # RUN: not ld.lld atomic_abi_A6C.o atomic_abi_A7.o -o /dev/null 2>&1 | FileCheck %s --check-prefix=ATOMIC_ABI_ERROR --implicit-check-not=error:
-# ATOMIC_ABI_ERROR: error: atomic abi mismatch for .riscv.attributes
-# ATOMIC_ABI_ERROR-NEXT: >>> atomic_abi_A6C.o:(.riscv.attributes): atomic_abi=1
-# ATOMIC_ABI_ERROR-NEXT: >>> atomic_abi_A7.o:(.riscv.attributes): atomic_abi=3
+# ATOMIC_ABI_ERROR: error: atomic_abi_A6C.o:(.riscv.attributes) has atomic_abi=1 but atomic_abi_A7.o:(.riscv.attributes) has atomic_abi=3
 
 # RUN: llvm-mc -filetype=obj -triple=riscv64  atomic_abi_A6S.s -o atomic_abi_A6S.o
 # RUN: ld.lld atomic_abi_A6S.o atomic_abi_A6C.o -o atomic_abi_A6C_A6S
diff --git a/llvm/include/llvm/Support/RISCVAttributes.h b/llvm/include/llvm/Support/RISCVAttributes.h
index 07476e818cb77..5def890a72735 100644
--- a/llvm/include/llvm/Support/RISCVAttributes.h
+++ b/llvm/include/llvm/Support/RISCVAttributes.h
@@ -35,7 +35,8 @@ enum AttrType : unsigned {
   ATOMIC_ABI = 14,
 };
 
-enum class RISCVAtomicAbiTag : unsigned {
+namespace RISCVAtomicAbiTag {
+enum AtomicABI : unsigned {
   // Values for Tag_RISCV_atomic_abi
   // Defined at
   // https://github.com/riscv-non-isa/riscv-elf-psabi-doc/blob/master/riscv-elf.adoc#tag_riscv_atomic_abi-14-uleb128version
@@ -44,6 +45,7 @@ enum class RISCVAtomicAbiTag : unsigned {
   A6S = 2,
   A7 = 3,
 };
+} // namespace RISCVAtomicAbiTag
 
 enum { NOT_ALLOWED = 0, ALLOWED = 1 };
 
diff --git a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVTargetStreamer.cpp b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVTargetStreamer.cpp
index 99f57f47835ab..335f7ac14f951 100644
--- a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVTargetStreamer.cpp
+++ b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVTargetStreamer.cpp
@@ -23,10 +23,10 @@ using namespace llvm;
 
 // This option controls wether or not we emit ELF attributes for ABI features,
 // like RISC-V atomics or X3 usage.
-static cl::opt<bool> RiscvAbiAttr(
-    "riscv-abi-attributes",
-    cl::desc("Enable emitting RISC-V ELF attributes for ABI features"),
-    cl::Hidden);
+static cl::opt<bool>
+    RiscvAbiAttr("riscv-abi-attributes",
+              cl::desc("Enable emitting RISC-V ELF attributes for ABI features"),
+               cl::Hidden);
 
 RISCVTargetStreamer::RISCVTargetStreamer(MCStreamer &S) : MCTargetStreamer(S) {}
 
@@ -85,10 +85,9 @@ void RISCVTargetStreamer::emitTargetAttributes(const MCSubtargetInfo &STI,
   }
 
   if (RiscvAbiAttr && STI.hasFeature(RISCV::FeatureStdExtA)) {
-    unsigned AtomicABITag = static_cast<unsigned>(
-        STI.hasFeature(RISCV::FeatureNoTrailingSeqCstFence)
-            ? RISCVAttrs::RISCVAtomicAbiTag::A6C
-            : RISCVAttrs::RISCVAtomicAbiTag::A6S);
+    unsigned AtomicABITag = STI.hasFeature(RISCV::FeatureNoTrailingSeqCstFence)
+                                ? RISCVAttrs::RISCVAtomicAbiTag::AtomicABI::A6C
+                                : RISCVAttrs::RISCVAtomicAbiTag::AtomicABI::A6S;
     emitAttribute(RISCVAttrs::ATOMIC_ABI, AtomicABITag);
   }
 }



More information about the llvm-branch-commits mailing list