Debian Codegraph @

external/llvm/releases/17.0.0/patches_external/unify-max-alignment-with-generic-max.patch

raw
1 /*========================== begin_copyright_notice ============================
2
3 Copyright (C) 2025 Intel Corporation
4
5 SPDX-License-Identifier: MIT
6
7 ============================= end_copyright_notice ===========================*/
8
9 /*========================== begin_copyright_notice ============================
10
11 Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
12 See https://llvm.org/LICENSE.txt for license information.
13 SPDX-License-Identifier: Apache-2.0 with LLVM-exception
14
15 ============================= end_copyright_notice ===========================*/
16
17 This is backport of this fix: https://github.com/llvm/llvm-project/pull/99257
18
19 "[IR] Unify max alignment for arguments with generic max align."
20
21 From 47f034550a5fb9ef6adee6347cd3c00e70ca663d Mon Sep 17 00:00:00 2001
22 From: Eli Friedman <[email protected]>
23 Date: Tue, 16 Jul 2024 16:03:38 -0700
24 Subject: [PATCH 1/3] Unify max alignment for arguments with generic max align.
25
26 The 2^14 limit was completely arbitrary; the generic limit is still
27 arbitrary, but at least it's the same arbitrary limit as everything
28 else.
29
30 While I'm here, also add a verifier check for the ByValOrByRefSize.
31 ---
32 llvm/include/llvm/CodeGen/TargetCallingConv.h | 8 ++---
33 llvm/lib/IR/Verifier.cpp | 34 +++++++++++--------
34 2 files changed, 23 insertions(+), 19 deletions(-)
35
36 diff --git a/llvm/include/llvm/CodeGen/TargetCallingConv.h b/llvm/include/llvm/CodeGen/TargetCallingConv.h
37 index 89ea9bcb2a40..70a2d8e5faaf 100644
38 --- a/llvm/include/llvm/CodeGen/TargetCallingConv.h
39 +++ b/llvm/include/llvm/CodeGen/TargetCallingConv.h
40 @@ -45,9 +45,9 @@ namespace ISD {
41 unsigned IsHva : 1; ///< HVA field for
42 unsigned IsHvaStart : 1; ///< HVA structure start
43 unsigned IsSecArgPass : 1; ///< Second argument
44 - unsigned MemAlign : 4; ///< Log 2 of alignment when arg is passed in memory
45 - ///< (including byval/byref). The max alignment is
46 - ///< verified in IR verification.
47 + unsigned MemAlign : 6; ///< Log 2 of alignment when arg is passed in memory
48 + ///< (including byval/byref). The max alignment is
49 + ///< verified in IR verification.
50 unsigned OrigAlign : 5; ///< Log 2 of original alignment
51 unsigned IsInConsecutiveRegsLast : 1;
52 unsigned IsInConsecutiveRegs : 1;
53 @@ -67,7 +67,7 @@ namespace ISD {
54 IsSecArgPass(0), MemAlign(0), OrigAlign(0),
55 IsInConsecutiveRegsLast(0), IsInConsecutiveRegs(0),
56 IsCopyElisionCandidate(0), IsPointer(0) {
57 - static_assert(sizeof(*this) == 3 * sizeof(unsigned), "flags are too big");
58 + static_assert(sizeof(*this) == 4 * sizeof(unsigned), "flags are too big");
59 }
60
61 bool isZExt() const { return IsZExt; }
62 diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
63 index 1408ce293ca6..2370bfd0a2be 100644
64 --- a/llvm/lib/IR/Verifier.cpp
65 +++ b/llvm/lib/IR/Verifier.cpp
66 @@ -291,13 +291,6 @@ namespace {
67
68 class Verifier : public InstVisitor<Verifier>, VerifierSupport {
69 friend class InstVisitor<Verifier>;
70 -
71 - // ISD::ArgFlagsTy::MemAlign only have 4 bits for alignment, so
72 - // the alignment size should not exceed 2^15. Since encode(Align)
73 - // would plus the shift value by 1, the alignment size should
74 - // not exceed 2^14, otherwise it can NOT be properly lowered
75 - // in backend.
76 - static constexpr unsigned ParamMaxAlignment = 1 << 14;
77 DominatorTree DT;
78
79 /// When verifying a basic block, keep track of all of the
80 @@ -1939,31 +1932,43 @@ void Verifier::verifyParameterAttrs(AttributeSet Attrs, Type *Ty,
81 }
82
83 if (isa<PointerType>(Ty)) {
84 + if (Attrs.hasAttribute(Attribute::Alignment)) {
85 + Align AttrAlign = Attrs.getAlignment().valueOrOne();
86 + Check(AttrAlign.value() <= Value::MaximumAlignment,
87 + "huge alignment values are unsupported", V);
88 + }
89 if (Attrs.hasAttribute(Attribute::ByVal)) {
90 - if (Attrs.hasAttribute(Attribute::Alignment)) {
91 - Align AttrAlign = Attrs.getAlignment().valueOrOne();
92 - Align MaxAlign(ParamMaxAlignment);
93 - Check(AttrAlign <= MaxAlign,
94 - "Attribute 'align' exceed the max size 2^14", V);
95 - }
96 SmallPtrSet<Type *, 4> Visited;
97 Check(Attrs.getByValType()->isSized(&Visited),
98 "Attribute 'byval' does not support unsized types!", V);
99 + Check(DL.getTypeAllocSize(Attrs.getByValType()).getKnownMinValue() <
100 + (1ULL << 32),
101 + "huge 'byval' arguments are unsupported", V);
102 }
103 if (Attrs.hasAttribute(Attribute::ByRef)) {
104 SmallPtrSet<Type *, 4> Visited;
105 Check(Attrs.getByRefType()->isSized(&Visited),
106 "Attribute 'byref' does not support unsized types!", V);
107 + Check(DL.getTypeAllocSize(Attrs.getByRefType()).getKnownMinValue() <
108 + (1ULL << 32),
109 + "huge 'byref' arguments are unsupported", V);
110 }
111 if (Attrs.hasAttribute(Attribute::InAlloca)) {
112 SmallPtrSet<Type *, 4> Visited;
113 Check(Attrs.getInAllocaType()->isSized(&Visited),
114 "Attribute 'inalloca' does not support unsized types!", V);
115 + Check(DL.getTypeAllocSize(Attrs.getInAllocaType()).getKnownMinValue() <
116 + (1ULL << 32),
117 + "huge 'inalloca' arguments are unsupported", V);
118 }
119 if (Attrs.hasAttribute(Attribute::Preallocated)) {
120 SmallPtrSet<Type *, 4> Visited;
121 Check(Attrs.getPreallocatedType()->isSized(&Visited),
122 "Attribute 'preallocated' does not support unsized types!", V);
123 + Check(
124 + DL.getTypeAllocSize(Attrs.getPreallocatedType()).getKnownMinValue() <
125 + (1ULL << 32),
126 + "huge 'preallocated' arguments are unsupported", V);
127 }
128 }
129
130 @@ -3424,8 +3429,7 @@ void Verifier::visitCallBase(CallBase &Call) {
131 if (!Ty->isSized())
132 return;
133 Align ABIAlign = DL.getABITypeAlign(Ty);
134 - Align MaxAlign(ParamMaxAlignment);
135 - Check(ABIAlign <= MaxAlign,
136 + Check(ABIAlign.value() <= Value::MaximumAlignment,
137 "Incorrect alignment of " + Message + " to called function!", Call);
138 };
139
140
141 --
142 2.43.0
143