[llvm] dad2b6e - [PowerPC][AIX] Support toc-data attribute for read-only globals.

Sean Fertile via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 27 07:48:51 PST 2022


Author: Yousuf Ali
Date: 2022-01-27T10:47:22-05:00
New Revision: dad2b6e797df82c9ea5377394e09aacf6d824560

URL: https://github.com/llvm/llvm-project/commit/dad2b6e797df82c9ea5377394e09aacf6d824560
DIFF: https://github.com/llvm/llvm-project/commit/dad2b6e797df82c9ea5377394e09aacf6d824560.diff

LOG: [PowerPC][AIX] Support toc-data attribute for read-only globals.

The patch handles the addition of constant global variables to the table
of contents.

Differential Revision: https://reviews.llvm.org/D116181

Added: 
    llvm/test/CodeGen/PowerPC/toc-data-const.ll

Modified: 
    llvm/lib/MC/MCSectionXCOFF.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/MC/MCSectionXCOFF.cpp b/llvm/lib/MC/MCSectionXCOFF.cpp
index 7f7380bf810d9..2ff4839d3706f 100644
--- a/llvm/lib/MC/MCSectionXCOFF.cpp
+++ b/llvm/lib/MC/MCSectionXCOFF.cpp
@@ -34,7 +34,8 @@ void MCSectionXCOFF::PrintSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
   }
 
   if (getKind().isReadOnly()) {
-    if (getMappingClass() != XCOFF::XMC_RO)
+    if (getMappingClass() != XCOFF::XMC_RO &&
+        getMappingClass() != XCOFF::XMC_TD)
       report_fatal_error("Unhandled storage-mapping class for .rodata csect.");
     printCsectDirective(OS);
     return;
@@ -70,7 +71,8 @@ void MCSectionXCOFF::PrintSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
   }
 
   if (isCsect() && getMappingClass() == XCOFF::XMC_TD) {
-    assert((getKind().isBSSExtern() || getKind().isBSSLocal()) &&
+    assert((getKind().isBSSExtern() || getKind().isBSSLocal() ||
+            getKind().isReadOnlyWithRel()) &&
            "Unexepected section kind for toc-data");
     printCsectDirective(OS);
     return;

diff  --git a/llvm/test/CodeGen/PowerPC/toc-data-const.ll b/llvm/test/CodeGen/PowerPC/toc-data-const.ll
new file mode 100644
index 0000000000000..2b87480d101c2
--- /dev/null
+++ b/llvm/test/CodeGen/PowerPC/toc-data-const.ll
@@ -0,0 +1,26 @@
+; RUN: llc -mtriple powerpc-ibm-aix-xcoff < %s | FileCheck %s --check-prefix CHECK
+; RUN: llc -mtriple powerpc64-ibm-aix-xcoff < %s | FileCheck %s --check-prefix CHECK
+
+ at i1 = external constant i32 #0
+ at i2 = constant i32* @i1 #0
+
+define i32 @read() {
+  %1  = load i32, i32* @i1, align 4
+  ret i32 %1
+}
+
+define i32** @retptr() {
+  ret i32** @i2
+}
+
+; CHECK:       .read:
+; CHECK:        la 3, i1[TD](2)
+
+; CHECK:       .retptr:
+; CHECK:        la 3, i2[TD](2)
+
+; CHECK-DAG:   .toc
+; CHECK:         .extern i1[TD]
+; CHECK:         .csect i2[TD]
+
+attributes #0 = { "toc-data" }


        


More information about the llvm-commits mailing list