[llvm] 5665fc9 - [AIX][XCOFF] Add support for generating assembly code for one-byte mergable strings

Xing Xue via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 20 08:27:28 PST 2019


Author: Xing Xue
Date: 2019-11-20T11:26:49-05:00
New Revision: 5665fc91fe93fa4293eb5aceff4884826d8cecb1

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

LOG: [AIX][XCOFF] Add support for generating assembly code for one-byte mergable strings

This patch adds support for generating assembly code for one-byte mergeable strings.

Generating assembly code for multi-byte mergeable strings and the `XCOFF` object code for mergeable strings will be supported later.

Reviewers: hubert.reinterpretcast, jasonliu, daltenty, sfertile, DiggerLin, Xiangling_L

Reviewed by: daltenty

Subscribers: wuzish, nemanjai, hiraditya, kbarton, jsji, llvm-commits

Tags: #llvm

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

Added: 
    llvm/test/CodeGen/PowerPC/aix-xcoff-mergeable-str.ll

Modified: 
    llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
    llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
index 5d5f77b83ef3..34ed476112f9 100644
--- a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
+++ b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
@@ -1849,6 +1849,24 @@ MCSection *TargetLoweringObjectFileXCOFF::SelectSectionForGlobal(
         SC, Kind, /* BeginSymbolName */ nullptr);
   }
 
+  if (Kind.isMergeableCString()) {
+    if (!Kind.isMergeable1ByteCString())
+      report_fatal_error("Unhandled multi-byte mergeable string kind.");
+
+    unsigned Align = GO->getParent()->getDataLayout().getPreferredAlignment(
+        cast<GlobalVariable>(GO));
+
+    unsigned EntrySize = getEntrySizeForKind(Kind);
+    std::string SizeSpec = ".rodata.str" + utostr(EntrySize) + ".";
+    SmallString<128> Name;
+    Name = SizeSpec + utostr(Align);
+
+    return getContext().getXCOFFSection(
+        Name, XCOFF::XMC_RO, XCOFF::XTY_SD,
+        TargetLoweringObjectFileXCOFF::getStorageClassForGlobal(GO),
+        Kind, /* BeginSymbolName */ nullptr);
+  }
+
   if (Kind.isText())
     return TextSection;
 
@@ -1861,8 +1879,7 @@ MCSection *TargetLoweringObjectFileXCOFF::SelectSectionForGlobal(
   if (Kind.isBSS())
     return DataSection;
 
-  if (Kind.isReadOnly() && !Kind.isMergeableConst() &&
-      !Kind.isMergeableCString())
+  if (Kind.isReadOnly() && !Kind.isMergeableConst())
     return ReadOnlySection;
 
   report_fatal_error("XCOFF other section types not yet implemented.");
@@ -1920,6 +1937,7 @@ XCOFF::StorageClass TargetLoweringObjectFileXCOFF::getStorageClassForGlobal(
     const GlobalObject *GO) {
   switch (GO->getLinkage()) {
   case GlobalValue::InternalLinkage:
+  case GlobalValue::PrivateLinkage:
     return XCOFF::C_HIDEXT;
   case GlobalValue::ExternalLinkage:
   case GlobalValue::CommonLinkage:

diff  --git a/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp b/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
index e4b3d4684761..1b1d27ee3cc3 100644
--- a/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
+++ b/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
@@ -1749,7 +1749,8 @@ void PPCAIXAsmPrinter::EmitGlobalVariable(const GlobalVariable *GV) {
   SectionKind GVKind = getObjFileLowering().getKindForGlobal(GV, TM);
   if ((!GVKind.isCommon() && !GVKind.isBSS() && !GVKind.isData() &&
        !GVKind.isReadOnly()) ||
-      GVKind.isMergeableCString() || GVKind.isMergeableConst())
+      GVKind.isMergeable2ByteCString() || GVKind.isMergeable4ByteCString() ||
+      GVKind.isMergeableConst())
     report_fatal_error("Encountered a global variable kind that is "
                        "not supported yet.");
 

diff  --git a/llvm/test/CodeGen/PowerPC/aix-xcoff-mergeable-str.ll b/llvm/test/CodeGen/PowerPC/aix-xcoff-mergeable-str.ll
new file mode 100644
index 000000000000..1b12ebb7169c
--- /dev/null
+++ b/llvm/test/CodeGen/PowerPC/aix-xcoff-mergeable-str.ll
@@ -0,0 +1,28 @@
+; This file tests the codegen of mergeable strings in AIX assembly only.
+; Once the codegen of mergeable strings for XCOFF object files is supported
+; the test in this file should be merged into aix-xcoff-data.ll with additional
+; tests for XCOFF object files.
+
+; RUN: llc -verify-machineinstrs -mcpu=pwr7 \
+; RUN:     -mtriple powerpc-ibm-aix-xcoff < %s | FileCheck %s
+; RUN: llc -verify-machineinstrs -mcpu=pwr7 \
+; RUN:     -mtriple powerpc64-ibm-aix-xcoff < %s | FileCheck %s
+
+ at strA = private unnamed_addr constant [14 x i8] c"hello world!\0A\00", align 1
+
+; CHECK:      .csect .rodata.str1.1[RO]
+; CHECK-NEXT: .LstrA:
+; CHECK-NEXT: .byte   104
+; CHECK-NEXT: .byte   101
+; CHECK-NEXT: .byte   108
+; CHECK-NEXT: .byte   108
+; CHECK-NEXT: .byte   111
+; CHECK-NEXT: .byte   32
+; CHECK-NEXT: .byte   119
+; CHECK-NEXT: .byte   111
+; CHECK-NEXT: .byte   114
+; CHECK-NEXT: .byte   108
+; CHECK-NEXT: .byte   100
+; CHECK-NEXT: .byte   33
+; CHECK-NEXT: .byte   10
+; CHECK-NEXT: .byte   0


        


More information about the llvm-commits mailing list