[PATCH] D98864: [SystemZ][z/OS] Set maximum value to truncate attribute aligned to for static variables on z/OS target
Fanbo Meng via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Mar 18 06:49:51 PDT 2021
fanbo-meng created this revision.
fanbo-meng added reviewers: abhina.sreeskantharajan, muiez, Kai, anirudhp, DanielMcIntosh-IBM.
fanbo-meng requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
On z/OS there is a hard limitation on on the maximum requestable alignment in aligned attribute for static variables. We need to truncate values greater than that.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D98864
Files:
clang/include/clang/Basic/TargetInfo.h
clang/lib/AST/ASTContext.cpp
clang/lib/Basic/TargetInfo.cpp
clang/lib/Basic/Targets/OSTargets.h
clang/test/CodeGen/SystemZ/zos-alignment.c
Index: clang/test/CodeGen/SystemZ/zos-alignment.c
===================================================================
--- clang/test/CodeGen/SystemZ/zos-alignment.c
+++ clang/test/CodeGen/SystemZ/zos-alignment.c
@@ -1,4 +1,16 @@
-// RUN: %clang_cc1 -emit-llvm-only -triple s390x-none-zos -fdump-record-layouts %s | FileCheck %s
+// RUN: %clang_cc1 -emit-llvm-only -triple s390x-none-zos -fdump-record-layouts %s | FileCheck %s --check-prefix=CHECK
+// RUN: %clang_cc1 -emit-llvm -triple s390x-none-zos %s -o - | FileCheck %s --check-prefix=DECL
+
+static int __attribute__((aligned(32))) v0;
+int __attribute__((aligned(32))) v1;
+typedef int __attribute__((aligned(32))) int32;
+static int32 v2;
+int32 v3;
+int f0() { return v0 + v1 + v2 + v3; }
+// DECL: @v0 {{.*}} align 16
+// DECL-NEXT: @v1 {{.*}} align 32
+// DECL-NEXT: @v2 {{.*}} align 16
+// DECL-NEXT: @v3 {{.*}} align 32
struct s0 {
short a:3;
Index: clang/lib/Basic/Targets/OSTargets.h
===================================================================
--- clang/lib/Basic/Targets/OSTargets.h
+++ clang/lib/Basic/Targets/OSTargets.h
@@ -788,6 +788,7 @@
ZOSTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
: OSTargetInfo<Target>(Triple, Opts) {
this->WCharType = TargetInfo::UnsignedInt;
+ this->MaxAlignedAttribute = 128;
this->UseBitFieldTypeAlignment = false;
this->UseZeroLengthBitfieldAlignment = true;
this->ZeroLengthBitfieldBoundary = 32;
Index: clang/lib/Basic/TargetInfo.cpp
===================================================================
--- clang/lib/Basic/TargetInfo.cpp
+++ clang/lib/Basic/TargetInfo.cpp
@@ -106,6 +106,7 @@
UseZeroLengthBitfieldAlignment = false;
UseExplicitBitFieldAlignment = true;
ZeroLengthBitfieldBoundary = 0;
+ MaxAlignedAttribute = 0;
HalfFormat = &llvm::APFloat::IEEEhalf();
FloatFormat = &llvm::APFloat::IEEEsingle();
DoubleFormat = &llvm::APFloat::IEEEdouble();
Index: clang/lib/AST/ASTContext.cpp
===================================================================
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -1783,6 +1783,13 @@
}
}
+ // Some targets have hard limitation on the maximum requestable alignment in
+ // aligned attribute for static variables.
+ const unsigned MaxAlignedAttr = getTargetInfo().getMaxAlignedAttribute();
+ const auto *VD = dyn_cast<VarDecl>(D);
+ if (MaxAlignedAttr && VD && VD->getStorageClass() == SC_Static)
+ Align = std::min(Align, MaxAlignedAttr);
+
return toCharUnitsFromBits(Align);
}
Index: clang/include/clang/Basic/TargetInfo.h
===================================================================
--- clang/include/clang/Basic/TargetInfo.h
+++ clang/include/clang/Basic/TargetInfo.h
@@ -161,6 +161,10 @@
/// If non-zero, specifies a fixed alignment value for bitfields that follow
/// zero length bitfield, regardless of the zero length bitfield type.
unsigned ZeroLengthBitfieldBoundary;
+
+ /// If non-zero, specifies a maximum alignment to truncate alignment
+ /// specified in the aligned attribute of a static variable to this value.
+ unsigned MaxAlignedAttribute;
};
/// OpenCL type kinds.
@@ -774,6 +778,12 @@
return ZeroLengthBitfieldBoundary;
}
+ /// Get the maximum alignment in bits for a static variable with
+ /// aligned attribute.
+ unsigned getMaxAlignedAttribute() const {
+ return MaxAlignedAttribute;
+ }
+
/// Check whether explicit bitfield alignment attributes should be
// honored, as in "__attribute__((aligned(2))) int b : 1;".
bool useExplicitBitFieldAlignment() const {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D98864.331544.patch
Type: text/x-patch
Size: 3620 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210318/6d49e976/attachment-0001.bin>
More information about the cfe-commits
mailing list