From e09a1dc47515d27ba5ca572a225208bb0d79fb3f Mon Sep 17 00:00:00 2001 From: Anirudh Prasad Date: Fri, 24 Sep 2021 14:05:55 -0400 Subject: [PATCH] [SystemZ][z/OS] Add GOFF Support to the DataLayout - This patch adds in the GOFF mangling support to the LLVM data layout string. A corresponding additional line has been added into the data layout section in the language reference documentation. - Furthermore, this patch also sets the right data layout string for the z/OS target in the SystemZ backend. Reviewed By: uweigand, Kai, abhina.sreeskantharajan, MaskRay Differential Revision: https://reviews.llvm.org/D109362 --- clang/lib/Basic/Targets/SystemZ.h | 14 +++++++++-- clang/test/CodeGen/target-data.c | 32 ++++++------------------ llvm/docs/LangRef.rst | 1 + llvm/include/llvm/IR/DataLayout.h | 4 +++ llvm/lib/IR/DataLayout.cpp | 5 ++++ llvm/lib/Target/SystemZ/SystemZTargetMachine.cpp | 5 ++-- llvm/unittests/IR/ManglerTest.cpp | 18 +++++++++++++ 7 files changed, 51 insertions(+), 28 deletions(-) diff --git a/clang/lib/Basic/Targets/SystemZ.h b/clang/lib/Basic/Targets/SystemZ.h index b749c3f..d3e3ed5 100644 --- a/clang/lib/Basic/Targets/SystemZ.h +++ b/clang/lib/Basic/Targets/SystemZ.h @@ -46,7 +46,17 @@ public: LongDoubleFormat = &llvm::APFloat::IEEEquad(); DefaultAlignForAttributeAligned = 64; MinGlobalAlign = 16; - resetDataLayout("E-m:e-i1:8:16-i8:8:16-i64:64-f128:64-a:8:16-n32:64"); + if (Triple.isOSzOS()) { + // All vector types are default aligned on an 8-byte boundary, even if the + // vector facility is not available. That is different from Linux. + MaxVectorAlign = 64; + // Compared to Linux/ELF, the data layout differs only in some details: + // - name mangling is GOFF + // - 128 bit vector types are 64 bit aligned + resetDataLayout( + "E-m:l-i1:8:16-i8:8:16-i64:64-f128:64-v128:64-a:8:16-n32:64"); + } else + resetDataLayout("E-m:e-i1:8:16-i8:8:16-i64:64-f128:64-a:8:16-n32:64"); MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 64; HasStrictFP = true; } @@ -129,7 +139,7 @@ public: HasVector &= !SoftFloat; // If we use the vector ABI, vector types are 64-bit aligned. - if (HasVector) { + if (HasVector && !getTriple().isOSzOS()) { MaxVectorAlign = 64; resetDataLayout("E-m:e-i1:8:16-i8:8:16-i64:64-f128:64" "-v128:64-a:8:16-n32:64"); diff --git a/clang/test/CodeGen/target-data.c b/clang/test/CodeGen/target-data.c index 10f35f5..0749493 100644 --- a/clang/test/CodeGen/target-data.c +++ b/clang/test/CodeGen/target-data.c @@ -219,40 +219,24 @@ // RUN: FileCheck %s -check-prefix=HEXAGON // HEXAGON: target datalayout = "e-m:e-p:32:32:32-a:0-n16:32-i64:64:64-i32:32:32-i16:16:16-i1:8:8-f32:32:32-f64:64:64-v32:32:32-v64:64:64-v512:512:512-v1024:1024:1024-v2048:2048:2048" -// RUN: %clang_cc1 -triple s390x-unknown -o - -emit-llvm %s | \ -// RUN: FileCheck %s -check-prefix=SYSTEMZ // RUN: %clang_cc1 -triple s390x-unknown -target-cpu z10 -o - -emit-llvm %s | \ // RUN: FileCheck %s -check-prefix=SYSTEMZ -// RUN: %clang_cc1 -triple s390x-unknown -target-cpu arch8 -o - -emit-llvm %s | \ -// RUN: FileCheck %s -check-prefix=SYSTEMZ -// RUN: %clang_cc1 -triple s390x-unknown -target-cpu z196 -o - -emit-llvm %s | \ -// RUN: FileCheck %s -check-prefix=SYSTEMZ -// RUN: %clang_cc1 -triple s390x-unknown -target-cpu arch9 -o - -emit-llvm %s | \ -// RUN: FileCheck %s -check-prefix=SYSTEMZ -// RUN: %clang_cc1 -triple s390x-unknown -target-cpu zEC12 -o - -emit-llvm %s | \ -// RUN: FileCheck %s -check-prefix=SYSTEMZ -// RUN: %clang_cc1 -triple s390x-unknown -target-cpu arch10 -o - -emit-llvm %s | \ -// RUN: FileCheck %s -check-prefix=SYSTEMZ // RUN: %clang_cc1 -triple s390x-unknown -target-cpu z13 -target-feature +soft-float -o - -emit-llvm %s | \ // RUN: FileCheck %s -check-prefix=SYSTEMZ // SYSTEMZ: target datalayout = "E-m:e-i1:8:16-i8:8:16-i64:64-f128:64-a:8:16-n32:64" // RUN: %clang_cc1 -triple s390x-unknown -target-cpu z13 -o - -emit-llvm %s | \ // RUN: FileCheck %s -check-prefix=SYSTEMZ-VECTOR -// RUN: %clang_cc1 -triple s390x-unknown -target-cpu arch11 -o - -emit-llvm %s | \ -// RUN: FileCheck %s -check-prefix=SYSTEMZ-VECTOR -// RUN: %clang_cc1 -triple s390x-unknown -target-cpu z14 -o - -emit-llvm %s | \ -// RUN: FileCheck %s -check-prefix=SYSTEMZ-VECTOR -// RUN: %clang_cc1 -triple s390x-unknown -target-cpu arch12 -o - -emit-llvm %s | \ -// RUN: FileCheck %s -check-prefix=SYSTEMZ-VECTOR -// RUN: %clang_cc1 -triple s390x-unknown -target-cpu z15 -o - -emit-llvm %s | \ -// RUN: FileCheck %s -check-prefix=SYSTEMZ-VECTOR -// RUN: %clang_cc1 -triple s390x-unknown -target-cpu arch13 -o - -emit-llvm %s | \ -// RUN: FileCheck %s -check-prefix=SYSTEMZ-VECTOR -// RUN: %clang_cc1 -triple s390x-unknown -target-cpu arch14 -o - -emit-llvm %s | \ -// RUN: FileCheck %s -check-prefix=SYSTEMZ-VECTOR // SYSTEMZ-VECTOR: target datalayout = "E-m:e-i1:8:16-i8:8:16-i64:64-f128:64-v128:64-a:8:16-n32:64" +// RUN: %clang_cc1 -triple s390x-none-zos -target-cpu z10 -o - -emit-llvm %s | \ +// RUN: FileCheck %s -check-prefix=ZOS +// RUN: %clang_cc1 -triple s390x-none-zos -target-cpu z13 -target-feature +soft-float -o - -emit-llvm %s | \ +// RUN: FileCheck %s -check-prefix=ZOS +// RUN: %clang_cc1 -triple s390x-none-zos -target-cpu z13 -o - -emit-llvm %s | \ +// RUN: FileCheck %s -check-prefix=ZOS +// ZOS: target datalayout = "E-m:l-i1:8:16-i8:8:16-i64:64-f128:64-v128:64-a:8:16-n32:64" + // RUN: %clang_cc1 -triple msp430-unknown -o - -emit-llvm %s | \ // RUN: FileCheck %s -check-prefix=MSP430 // MSP430: target datalayout = "e-m:e-p:16:16-i32:16-i64:16-f32:16-f64:16-a:8-n8:16-S16" diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst index 765f17e..8240b8d 100644 --- a/llvm/docs/LangRef.rst +++ b/llvm/docs/LangRef.rst @@ -2605,6 +2605,7 @@ as follows: options are * ``e``: ELF mangling: Private symbols get a ``.L`` prefix. + * ``l``: GOFF mangling: Private symbols get a ``@`` prefix. * ``m``: Mips mangling: Private symbols get a ``$`` prefix. * ``o``: Mach-O mangling: Private symbols get ``L`` prefix. Other symbols get a ``_`` prefix. diff --git a/llvm/include/llvm/IR/DataLayout.h b/llvm/include/llvm/IR/DataLayout.h index ec618bc..8c37aeb 100644 --- a/llvm/include/llvm/IR/DataLayout.h +++ b/llvm/include/llvm/IR/DataLayout.h @@ -135,6 +135,7 @@ private: MM_MachO, MM_WinCOFF, MM_WinCOFFX86, + MM_GOFF, MM_Mips, MM_XCOFF }; @@ -316,6 +317,7 @@ public: switch (ManglingMode) { case MM_None: case MM_ELF: + case MM_GOFF: case MM_Mips: case MM_WinCOFF: case MM_XCOFF: @@ -334,6 +336,8 @@ public: case MM_ELF: case MM_WinCOFF: return ".L"; + case MM_GOFF: + return "@"; case MM_Mips: return "$"; case MM_MachO: diff --git a/llvm/lib/IR/DataLayout.cpp b/llvm/lib/IR/DataLayout.cpp index 4f6140e..5de47b8 100644 --- a/llvm/lib/IR/DataLayout.cpp +++ b/llvm/lib/IR/DataLayout.cpp @@ -151,6 +151,8 @@ PointerAlignElem::operator==(const PointerAlignElem &rhs) const { //===----------------------------------------------------------------------===// const char *DataLayout::getManglingComponent(const Triple &T) { + if (T.isOSBinFormatGOFF()) + return "-m:l"; if (T.isOSBinFormatMachO()) return "-m:o"; if (T.isOSWindows() && T.isOSBinFormatCOFF()) @@ -500,6 +502,9 @@ Error DataLayout::parseSpecifier(StringRef Desc) { case 'e': ManglingMode = MM_ELF; break; + case 'l': + ManglingMode = MM_GOFF; + break; case 'o': ManglingMode = MM_MachO; break; diff --git a/llvm/lib/Target/SystemZ/SystemZTargetMachine.cpp b/llvm/lib/Target/SystemZ/SystemZTargetMachine.cpp index a886f9b..0a565d3 100644 --- a/llvm/lib/Target/SystemZ/SystemZTargetMachine.cpp +++ b/llvm/lib/Target/SystemZ/SystemZTargetMachine.cpp @@ -84,8 +84,9 @@ static std::string computeDataLayout(const Triple &TT, StringRef CPU, // 128-bit floats are aligned only to 64 bits. Ret += "-f128:64"; - // When using the vector ABI, 128-bit vectors are also aligned to 64 bits. - if (VectorABI) + // When using the vector ABI on Linux, 128-bit vectors are also aligned to 64 + // bits. On z/OS, vector types are always aligned to 64 bits. + if (VectorABI || TT.isOSzOS()) Ret += "-v128:64"; // We prefer 16 bits of aligned for all globals; see above. diff --git a/llvm/unittests/IR/ManglerTest.cpp b/llvm/unittests/IR/ManglerTest.cpp index 641e346..8ad95a8 100644 --- a/llvm/unittests/IR/ManglerTest.cpp +++ b/llvm/unittests/IR/ManglerTest.cpp @@ -156,4 +156,22 @@ TEST(ManglerTest, XCOFF) { "L..foo"); } +TEST(ManglerTest, GOFF) { + LLVMContext Ctx; + DataLayout DL("m:l"); // GOFF + Module Mod("test", Ctx); + Mod.setDataLayout(DL); + Mangler Mang; + + EXPECT_EQ(mangleStr("foo", Mang, DL), "foo"); + EXPECT_EQ(mangleStr("\01foo", Mang, DL), "foo"); + EXPECT_EQ(mangleStr("?foo", Mang, DL), "?foo"); + EXPECT_EQ(mangleFunc("foo", llvm::GlobalValue::ExternalLinkage, + llvm::CallingConv::C, Mod, Mang), + "foo"); + EXPECT_EQ(mangleFunc("foo", llvm::GlobalValue::PrivateLinkage, + llvm::CallingConv::C, Mod, Mang), + "@foo"); +} + } // end anonymous namespace -- 2.7.4