Author: Fanbo Meng Date: 2021-03-29T09:44:33-04:00 New Revision: 0858f0e09e33f62fc1dcc45e0bdec47eee1e23ba
URL: https://github.com/llvm/llvm-project/commit/0858f0e09e33f62fc1dcc45e0bdec47eee1e23ba DIFF: https://github.com/llvm/llvm-project/commit/0858f0e09e33f62fc1dcc45e0bdec47eee1e23ba.diff LOG: [SystemZ][z/OS] Set maximum value to truncate attribute aligned to for static variables on z/OS target 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. Reviewed By: abhina.sreeskantharajan Differential Revision: https://reviews.llvm.org/D98864 Added: Modified: 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 Removed: ################################################################################ diff --git a/clang/include/clang/Basic/TargetInfo.h b/clang/include/clang/Basic/TargetInfo.h index 01ca9ca0d2a8..3ddb706dcf52 100644 --- a/clang/include/clang/Basic/TargetInfo.h +++ b/clang/include/clang/Basic/TargetInfo.h @@ -165,6 +165,10 @@ struct TransferrableTargetInfo { /// 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. @@ -784,6 +788,10 @@ class TargetInfo : public virtual TransferrableTargetInfo, 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 { diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index d52aea88e092..c824bcfa0866 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -1783,6 +1783,13 @@ CharUnits ASTContext::getDeclAlign(const Decl *D, bool ForAlignof) const { } } + // 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); } diff --git a/clang/lib/Basic/TargetInfo.cpp b/clang/lib/Basic/TargetInfo.cpp index 468c8a24498a..1783da8f9cfd 100644 --- a/clang/lib/Basic/TargetInfo.cpp +++ b/clang/lib/Basic/TargetInfo.cpp @@ -107,6 +107,7 @@ TargetInfo::TargetInfo(const llvm::Triple &T) : TargetOpts(), Triple(T) { UseLeadingZeroLengthBitfield = true; UseExplicitBitFieldAlignment = true; ZeroLengthBitfieldBoundary = 0; + MaxAlignedAttribute = 0; HalfFormat = &llvm::APFloat::IEEEhalf(); FloatFormat = &llvm::APFloat::IEEEsingle(); DoubleFormat = &llvm::APFloat::IEEEdouble(); diff --git a/clang/lib/Basic/Targets/OSTargets.h b/clang/lib/Basic/Targets/OSTargets.h index 568f759bfa0d..6e757adfa8bf 100644 --- a/clang/lib/Basic/Targets/OSTargets.h +++ b/clang/lib/Basic/Targets/OSTargets.h @@ -794,6 +794,7 @@ class LLVM_LIBRARY_VISIBILITY ZOSTargetInfo : public OSTargetInfo<Target> { 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->UseLeadingZeroLengthBitfield = false; diff --git a/clang/test/CodeGen/SystemZ/zos-alignment.c b/clang/test/CodeGen/SystemZ/zos-alignment.c index 703fd1a46c3b..9371a54403e4 100644 --- a/clang/test/CodeGen/SystemZ/zos-alignment.c +++ b/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; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits