Skip to content

Commit 8d64314

Browse files
committed
Reland [IR] Increase max alignment to 4GB
Currently the max alignment representable is 1GB, see D108661. Setting the align of an object to 4GB is desirable in some cases to make sure the lower 32 bits are clear which can be used for some optimizations, e.g. https://crbug.com/1016945. This uses an extra bit in instructions that carry an alignment. We can store 15 bits of "free" information, and with this change some instructions (e.g. AtomicCmpXchgInst) use 14 bits. We can increase the max alignment representable above 4GB (up to 2^62) since we're only using 33 of the 64 values, but I've just limited it to 4GB for now. The one place we have to update the bitcode format is for the alloca instruction. It stores its alignment into 5 bits of a 32 bit bitfield. I've added another field which is 8 bits and should be future proof for a while. For backward compatibility, we check if the old field has a value and use that, otherwise use the new field. Updating clang's max allowed alignment will come in a future patch. Reviewed By: hans Differential Revision: https://reviews.llvm.org/D110451
1 parent 05de0ab commit 8d64314

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+176
-167
lines changed

clang/lib/CodeGen/CGBlocks.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -2695,8 +2695,8 @@ const BlockByrefInfo &CodeGenFunction::getBlockByrefInfo(const VarDecl *D) {
26952695
size = varOffset;
26962696

26972697
// Conversely, we might have to prevent LLVM from inserting padding.
2698-
} else if (CGM.getDataLayout().getABITypeAlignment(varTy)
2699-
> varAlign.getQuantity()) {
2698+
} else if (CGM.getDataLayout().getABITypeAlignment(varTy) >
2699+
uint64_t(varAlign.getQuantity())) {
27002700
packed = true;
27012701
}
27022702
types.push_back(varTy);

clang/lib/CodeGen/CGCall.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -5021,12 +5021,12 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
50215021
auto scalarAlign = CGM.getDataLayout().getPrefTypeAlignment(scalarType);
50225022

50235023
// Materialize to a temporary.
5024-
addr = CreateTempAlloca(
5025-
RV.getScalarVal()->getType(),
5026-
CharUnits::fromQuantity(std::max(
5027-
(unsigned)layout->getAlignment().value(), scalarAlign)),
5028-
"tmp",
5029-
/*ArraySize=*/nullptr, &AllocaAddr);
5024+
addr =
5025+
CreateTempAlloca(RV.getScalarVal()->getType(),
5026+
CharUnits::fromQuantity(std::max(
5027+
layout->getAlignment().value(), scalarAlign)),
5028+
"tmp",
5029+
/*ArraySize=*/nullptr, &AllocaAddr);
50305030
tempSize = EmitLifetimeStart(scalarSize, AllocaAddr.getPointer());
50315031

50325032
Builder.CreateStore(RV.getScalarVal(), addr);

clang/lib/CodeGen/CGDecl.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1142,7 +1142,7 @@ Address CodeGenModule::createUnnamedGlobalFrom(const VarDecl &D,
11421142
GV->setAlignment(Align.getAsAlign());
11431143
GV->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
11441144
CacheEntry = GV;
1145-
} else if (CacheEntry->getAlignment() < Align.getQuantity()) {
1145+
} else if (CacheEntry->getAlignment() < uint64_t(Align.getQuantity())) {
11461146
CacheEntry->setAlignment(Align.getAsAlign());
11471147
}
11481148

clang/lib/CodeGen/CodeGenModule.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -5386,7 +5386,7 @@ CodeGenModule::GetAddrOfConstantStringFromLiteral(const StringLiteral *S,
53865386
if (!LangOpts.WritableStrings) {
53875387
Entry = &ConstantStringMap[C];
53885388
if (auto GV = *Entry) {
5389-
if (Alignment.getQuantity() > GV->getAlignment())
5389+
if (uint64_t(Alignment.getQuantity()) > GV->getAlignment())
53905390
GV->setAlignment(Alignment.getAsAlign());
53915391
return ConstantAddress(castStringLiteralToDefaultAddressSpace(*this, GV),
53925392
Alignment);
@@ -5449,7 +5449,7 @@ ConstantAddress CodeGenModule::GetAddrOfConstantCString(
54495449
if (!LangOpts.WritableStrings) {
54505450
Entry = &ConstantStringMap[C];
54515451
if (auto GV = *Entry) {
5452-
if (Alignment.getQuantity() > GV->getAlignment())
5452+
if (uint64_t(Alignment.getQuantity()) > GV->getAlignment())
54535453
GV->setAlignment(Alignment.getAsAlign());
54545454
return ConstantAddress(castStringLiteralToDefaultAddressSpace(*this, GV),
54555455
Alignment);

clang/test/CodeGen/builtin-assume-aligned.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ int test6() {
117117
// CHECK-NEXT: store i32* [[A]], i32** [[A_ADDR]], align 8
118118
// CHECK-NEXT: [[TMP0:%.*]] = load i32*, i32** [[A_ADDR]], align 8
119119
// CHECK-NEXT: [[TMP1:%.*]] = bitcast i32* [[TMP0]] to i8*
120-
// CHECK-NEXT: call void @llvm.assume(i1 true) [ "align"(i8* [[TMP1]], i64 1073741824) ]
120+
// CHECK-NEXT: call void @llvm.assume(i1 true) [ "align"(i8* [[TMP1]], i64 4294967296) ]
121121
// CHECK-NEXT: [[TMP2:%.*]] = bitcast i8* [[TMP1]] to i32*
122122
// CHECK-NEXT: store i32* [[TMP2]], i32** [[A_ADDR]], align 8
123123
// CHECK-NEXT: [[TMP3:%.*]] = load i32*, i32** [[A_ADDR]], align 8

clang/test/CodeGen/catch-alignment-assumption-attribute-align_value-on-paramvar.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
// CHECK-SANITIZE-ANYRECOVER: @[[LINE_100_ALIGNMENT_ASSUMPTION:.*]] = {{.*}}, i32 100, i32 10 }, {{.*}}* @[[CHAR]] }
88

99
char **passthrough(__attribute__((align_value(0x80000000))) char **x) {
10-
// CHECK-NOSANITIZE: define{{.*}} i8** @{{.*}}(i8** align 1073741824 %[[X:.*]])
10+
// CHECK-NOSANITIZE: define{{.*}} i8** @{{.*}}(i8** align 2147483648 %[[X:.*]])
1111
// CHECK-SANITIZE: define{{.*}} i8** @{{.*}}(i8** %[[X:.*]])
1212
// CHECK-NEXT: [[entry:.*]]:
1313
// CHECK-NEXT: %[[X_ADDR:.*]] = alloca i8**, align 8

clang/test/CodeGen/catch-alignment-assumption-builtin_assume_aligned-three-params-variable.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,17 @@ void *caller(char **x, unsigned long offset) {
1818
// CHECK-NEXT: %[[OFFSET_RELOADED:.*]] = load i64, i64* %[[OFFSET_ADDR]], align 8
1919
// CHECK-SANITIZE-NEXT: %[[PTRINT:.*]] = ptrtoint i8* %[[BITCAST]] to i64
2020
// CHECK-SANITIZE-NEXT: %[[OFFSETPTR:.*]] = sub i64 %[[PTRINT]], %[[OFFSET_RELOADED]]
21-
// CHECK-SANITIZE-NEXT: %[[MASKEDPTR:.*]] = and i64 %[[OFFSETPTR]], 1073741823
21+
// CHECK-SANITIZE-NEXT: %[[MASKEDPTR:.*]] = and i64 %[[OFFSETPTR]], 2147483647
2222
// CHECK-SANITIZE-NEXT: %[[MASKCOND:.*]] = icmp eq i64 %[[MASKEDPTR]], 0
2323
// CHECK-SANITIZE-NEXT: %[[PTRINT_DUP:.*]] = ptrtoint i8* %[[BITCAST]] to i64, !nosanitize
2424
// CHECK-SANITIZE-NEXT: br i1 %[[MASKCOND]], label %[[CONT:.*]], label %[[HANDLER_ALIGNMENT_ASSUMPTION:[^,]+]],{{.*}} !nosanitize
2525
// CHECK-SANITIZE: [[HANDLER_ALIGNMENT_ASSUMPTION]]:
26-
// CHECK-SANITIZE-NORECOVER-NEXT: call void @__ubsan_handle_alignment_assumption_abort(i8* bitcast ({ {{{.*}}}, {{{.*}}}, {{{.*}}}* }* @[[LINE_100_ALIGNMENT_ASSUMPTION]] to i8*), i64 %[[PTRINT_DUP]], i64 1073741824, i64 %[[OFFSET_RELOADED]]){{.*}}, !nosanitize
27-
// CHECK-SANITIZE-RECOVER-NEXT: call void @__ubsan_handle_alignment_assumption(i8* bitcast ({ {{{.*}}}, {{{.*}}}, {{{.*}}}* }* @[[LINE_100_ALIGNMENT_ASSUMPTION]] to i8*), i64 %[[PTRINT_DUP]], i64 1073741824, i64 %[[OFFSET_RELOADED]]){{.*}}, !nosanitize
26+
// CHECK-SANITIZE-NORECOVER-NEXT: call void @__ubsan_handle_alignment_assumption_abort(i8* bitcast ({ {{{.*}}}, {{{.*}}}, {{{.*}}}* }* @[[LINE_100_ALIGNMENT_ASSUMPTION]] to i8*), i64 %[[PTRINT_DUP]], i64 2147483648, i64 %[[OFFSET_RELOADED]]){{.*}}, !nosanitize
27+
// CHECK-SANITIZE-RECOVER-NEXT: call void @__ubsan_handle_alignment_assumption(i8* bitcast ({ {{{.*}}}, {{{.*}}}, {{{.*}}}* }* @[[LINE_100_ALIGNMENT_ASSUMPTION]] to i8*), i64 %[[PTRINT_DUP]], i64 2147483648, i64 %[[OFFSET_RELOADED]]){{.*}}, !nosanitize
2828
// CHECK-SANITIZE-TRAP-NEXT: call void @llvm.ubsantrap(i8 23){{.*}}, !nosanitize
2929
// CHECK-SANITIZE-UNREACHABLE-NEXT: unreachable, !nosanitize
3030
// CHECK-SANITIZE: [[CONT]]:
31-
// CHECK-NEXT: call void @llvm.assume(i1 true) [ "align"(i8* %[[BITCAST]], i64 1073741824, i64 %[[OFFSET_RELOADED]]) ]
31+
// CHECK-NEXT: call void @llvm.assume(i1 true) [ "align"(i8* %[[BITCAST]], i64 2147483648, i64 %[[OFFSET_RELOADED]]) ]
3232
// CHECK-NEXT: ret i8* %[[BITCAST]]
3333
// CHECK-NEXT: }
3434
#line 100

clang/test/CodeGen/catch-alignment-assumption-builtin_assume_aligned-three-params.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,17 @@ void *caller(char **x) {
1515
// CHECK-NEXT: %[[BITCAST:.*]] = bitcast i8** %[[X_RELOADED]] to i8*
1616
// CHECK-SANITIZE-NEXT: %[[PTRINT:.*]] = ptrtoint i8* %[[BITCAST]] to i64
1717
// CHECK-SANITIZE-NEXT: %[[OFFSETPTR:.*]] = sub i64 %[[PTRINT]], 42
18-
// CHECK-SANITIZE-NEXT: %[[MASKEDPTR:.*]] = and i64 %[[OFFSETPTR]], 1073741823
18+
// CHECK-SANITIZE-NEXT: %[[MASKEDPTR:.*]] = and i64 %[[OFFSETPTR]], 2147483647
1919
// CHECK-SANITIZE-NEXT: %[[MASKCOND:.*]] = icmp eq i64 %[[MASKEDPTR]], 0
2020
// CHECK-SANITIZE-NEXT: %[[PTRINT_DUP:.*]] = ptrtoint i8* %[[BITCAST]] to i64, !nosanitize
2121
// CHECK-SANITIZE-NEXT: br i1 %[[MASKCOND]], label %[[CONT:.*]], label %[[HANDLER_ALIGNMENT_ASSUMPTION:[^,]+]],{{.*}} !nosanitize
2222
// CHECK-SANITIZE: [[HANDLER_ALIGNMENT_ASSUMPTION]]:
23-
// CHECK-SANITIZE-NORECOVER-NEXT: call void @__ubsan_handle_alignment_assumption_abort(i8* bitcast ({ {{{.*}}}, {{{.*}}}, {{{.*}}}* }* @[[LINE_100_ALIGNMENT_ASSUMPTION]] to i8*), i64 %[[PTRINT_DUP]], i64 1073741824, i64 42){{.*}}, !nosanitize
24-
// CHECK-SANITIZE-RECOVER-NEXT: call void @__ubsan_handle_alignment_assumption(i8* bitcast ({ {{{.*}}}, {{{.*}}}, {{{.*}}}* }* @[[LINE_100_ALIGNMENT_ASSUMPTION]] to i8*), i64 %[[PTRINT_DUP]], i64 1073741824, i64 42){{.*}}, !nosanitize
23+
// CHECK-SANITIZE-NORECOVER-NEXT: call void @__ubsan_handle_alignment_assumption_abort(i8* bitcast ({ {{{.*}}}, {{{.*}}}, {{{.*}}}* }* @[[LINE_100_ALIGNMENT_ASSUMPTION]] to i8*), i64 %[[PTRINT_DUP]], i64 2147483648, i64 42){{.*}}, !nosanitize
24+
// CHECK-SANITIZE-RECOVER-NEXT: call void @__ubsan_handle_alignment_assumption(i8* bitcast ({ {{{.*}}}, {{{.*}}}, {{{.*}}}* }* @[[LINE_100_ALIGNMENT_ASSUMPTION]] to i8*), i64 %[[PTRINT_DUP]], i64 2147483648, i64 42){{.*}}, !nosanitize
2525
// CHECK-SANITIZE-TRAP-NEXT: call void @llvm.ubsantrap(i8 23){{.*}}, !nosanitize
2626
// CHECK-SANITIZE-UNREACHABLE-NEXT: unreachable, !nosanitize
2727
// CHECK-SANITIZE: [[CONT]]:
28-
// CHECK-NEXT: call void @llvm.assume(i1 true) [ "align"(i8* %[[BITCAST]], i64 1073741824, i64 42) ]
28+
// CHECK-NEXT: call void @llvm.assume(i1 true) [ "align"(i8* %[[BITCAST]], i64 2147483648, i64 42) ]
2929
// CHECK-NEXT: ret i8* %[[BITCAST]]
3030
// CHECK-NEXT: }
3131
#line 100

clang/test/CodeGen/catch-alignment-assumption-builtin_assume_aligned-two-params.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@ void *caller(char **x) {
1414
// CHECK-NEXT: %[[X_RELOADED:.*]] = load i8**, i8*** %[[X_ADDR]], align 8
1515
// CHECK-NEXT: %[[BITCAST:.*]] = bitcast i8** %[[X_RELOADED]] to i8*
1616
// CHECK-SANITIZE-NEXT: %[[PTRINT:.*]] = ptrtoint i8* %[[BITCAST]] to i64
17-
// CHECK-SANITIZE-NEXT: %[[MASKEDPTR:.*]] = and i64 %[[PTRINT]], 1073741823
17+
// CHECK-SANITIZE-NEXT: %[[MASKEDPTR:.*]] = and i64 %[[PTRINT]], 2147483647
1818
// CHECK-SANITIZE-NEXT: %[[MASKCOND:.*]] = icmp eq i64 %[[MASKEDPTR]], 0
1919
// CHECK-SANITIZE-NEXT: %[[PTRINT_DUP:.*]] = ptrtoint i8* %[[BITCAST]] to i64, !nosanitize
2020
// CHECK-SANITIZE-NEXT: br i1 %[[MASKCOND]], label %[[CONT:.*]], label %[[HANDLER_ALIGNMENT_ASSUMPTION:[^,]+]],{{.*}} !nosanitize
2121
// CHECK-SANITIZE: [[HANDLER_ALIGNMENT_ASSUMPTION]]:
22-
// CHECK-SANITIZE-NORECOVER-NEXT: call void @__ubsan_handle_alignment_assumption_abort(i8* bitcast ({ {{{.*}}}, {{{.*}}}, {{{.*}}}* }* @[[LINE_100_ALIGNMENT_ASSUMPTION]] to i8*), i64 %[[PTRINT_DUP]], i64 1073741824, i64 0){{.*}}, !nosanitize
23-
// CHECK-SANITIZE-RECOVER-NEXT: call void @__ubsan_handle_alignment_assumption(i8* bitcast ({ {{{.*}}}, {{{.*}}}, {{{.*}}}* }* @[[LINE_100_ALIGNMENT_ASSUMPTION]] to i8*), i64 %[[PTRINT_DUP]], i64 1073741824, i64 0){{.*}}, !nosanitize
22+
// CHECK-SANITIZE-NORECOVER-NEXT: call void @__ubsan_handle_alignment_assumption_abort(i8* bitcast ({ {{{.*}}}, {{{.*}}}, {{{.*}}}* }* @[[LINE_100_ALIGNMENT_ASSUMPTION]] to i8*), i64 %[[PTRINT_DUP]], i64 2147483648, i64 0){{.*}}, !nosanitize
23+
// CHECK-SANITIZE-RECOVER-NEXT: call void @__ubsan_handle_alignment_assumption(i8* bitcast ({ {{{.*}}}, {{{.*}}}, {{{.*}}}* }* @[[LINE_100_ALIGNMENT_ASSUMPTION]] to i8*), i64 %[[PTRINT_DUP]], i64 2147483648, i64 0){{.*}}, !nosanitize
2424
// CHECK-SANITIZE-TRAP-NEXT: call void @llvm.ubsantrap(i8 23){{.*}}, !nosanitize
2525
// CHECK-SANITIZE-UNREACHABLE-NEXT: unreachable, !nosanitize
2626
// CHECK-SANITIZE: [[CONT]]:
27-
// CHECK-NEXT: call void @llvm.assume(i1 true) [ "align"(i8* %[[BITCAST]], i64 1073741824) ]
27+
// CHECK-NEXT: call void @llvm.assume(i1 true) [ "align"(i8* %[[BITCAST]], i64 2147483648) ]
2828
// CHECK-NEXT: ret i8* %[[BITCAST]]
2929
// CHECK-NEXT: }
3030
#line 100

llvm/include/llvm/Bitcode/BitcodeCommon.h

+6-2
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,14 @@
1919
namespace llvm {
2020

2121
struct AllocaPackedValues {
22-
using Align = Bitfield::Element<unsigned, 0, 5>;
23-
using UsedWithInAlloca = Bitfield::Element<bool, Align::NextBit, 1>;
22+
// We increased the number of bits needed to represent alignment to be more
23+
// than 5, but to preserve backward compatibility we store the upper bits
24+
// separately.
25+
using AlignLower = Bitfield::Element<unsigned, 0, 5>;
26+
using UsedWithInAlloca = Bitfield::Element<bool, AlignLower::NextBit, 1>;
2427
using ExplicitType = Bitfield::Element<bool, UsedWithInAlloca::NextBit, 1>;
2528
using SwiftError = Bitfield::Element<bool, ExplicitType::NextBit, 1>;
29+
using AlignUpper = Bitfield::Element<unsigned, SwiftError::NextBit, 3>;
2630
};
2731

2832
} // namespace llvm

llvm/include/llvm/IR/DataLayout.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ class DataLayout {
518518

519519
/// Returns the minimum ABI-required alignment for the specified type.
520520
/// FIXME: Deprecate this function once migration to Align is over.
521-
unsigned getABITypeAlignment(Type *Ty) const;
521+
uint64_t getABITypeAlignment(Type *Ty) const;
522522

523523
/// Returns the minimum ABI-required alignment for the specified type.
524524
Align getABITypeAlign(Type *Ty) const;
@@ -541,7 +541,7 @@ class DataLayout {
541541
///
542542
/// This is always at least as good as the ABI alignment.
543543
/// FIXME: Deprecate this function once migration to Align is over.
544-
unsigned getPrefTypeAlignment(Type *Ty) const;
544+
uint64_t getPrefTypeAlignment(Type *Ty) const;
545545

546546
/// Returns the preferred stack/global alignment for the specified
547547
/// type.

llvm/include/llvm/IR/GlobalObject.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class GlobalObject : public GlobalValue {
5151

5252
Comdat *ObjComdat;
5353
enum {
54-
LastAlignmentBit = 4,
54+
LastAlignmentBit = 5,
5555
HasSectionHashEntryBit,
5656

5757
GlobalObjectBits,
@@ -68,7 +68,7 @@ class GlobalObject : public GlobalValue {
6868
GlobalObject(const GlobalObject &) = delete;
6969

7070
/// FIXME: Remove this function once transition to Align is over.
71-
unsigned getAlignment() const {
71+
uint64_t getAlignment() const {
7272
MaybeAlign Align = getAlign();
7373
return Align ? Align->value() : 0;
7474
}

llvm/include/llvm/IR/Instruction.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@ class Instruction : public User,
5959
// Template alias so that all Instruction storing alignment use the same
6060
// definiton.
6161
// Valid alignments are powers of two from 2^0 to 2^MaxAlignmentExponent =
62-
// 2^30. We store them as Log2(Alignment), so we need 5 bits to encode the 31
62+
// 2^32. We store them as Log2(Alignment), so we need 6 bits to encode the 33
6363
// possible values.
6464
template <unsigned Offset>
6565
using AlignmentBitfieldElementT =
66-
typename Bitfield::Element<unsigned, Offset, 5,
66+
typename Bitfield::Element<unsigned, Offset, 6,
6767
Value::MaxAlignmentExponent>;
6868

6969
template <unsigned Offset>

llvm/include/llvm/IR/Instructions.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ class AllocaInst : public UnaryInstruction {
126126
}
127127

128128
// FIXME: Remove this one transition to Align is over.
129-
unsigned getAlignment() const { return getAlign().value(); }
129+
uint64_t getAlignment() const { return getAlign().value(); }
130130

131131
/// Return true if this alloca is in the entry block of the function and is a
132132
/// constant size. If so, the code generator will fold it into the
@@ -217,7 +217,7 @@ class LoadInst : public UnaryInstruction {
217217
/// Return the alignment of the access that is being performed.
218218
/// FIXME: Remove this function once transition to Align is over.
219219
/// Use getAlign() instead.
220-
unsigned getAlignment() const { return getAlign().value(); }
220+
uint64_t getAlignment() const { return getAlign().value(); }
221221

222222
/// Return the alignment of the access that is being performed.
223223
Align getAlign() const {
@@ -348,7 +348,7 @@ class StoreInst : public Instruction {
348348
/// Return the alignment of the access that is being performed
349349
/// FIXME: Remove this function once transition to Align is over.
350350
/// Use getAlign() instead.
351-
unsigned getAlignment() const { return getAlign().value(); }
351+
uint64_t getAlignment() const { return getAlign().value(); }
352352

353353
Align getAlign() const {
354354
return Align(1ULL << (getSubclassData<AlignmentField>()));

llvm/include/llvm/IR/Value.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -785,8 +785,8 @@ class Value {
785785
///
786786
/// This is the greatest alignment value supported by load, store, and alloca
787787
/// instructions, and global values.
788-
static constexpr unsigned MaxAlignmentExponent = 30;
789-
static constexpr unsigned MaximumAlignment = 1u << MaxAlignmentExponent;
788+
static constexpr unsigned MaxAlignmentExponent = 32;
789+
static constexpr uint64_t MaximumAlignment = 1ULL << MaxAlignmentExponent;
790790

791791
/// Mutate the type of this Value to be of the specified type.
792792
///

llvm/include/llvm/Transforms/IPO/Attributor.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -3413,18 +3413,18 @@ struct AADereferenceable
34133413
};
34143414

34153415
using AAAlignmentStateType =
3416-
IncIntegerState<uint32_t, Value::MaximumAlignment, 1>;
3416+
IncIntegerState<uint64_t, Value::MaximumAlignment, 1>;
34173417
/// An abstract interface for all align attributes.
34183418
struct AAAlign : public IRAttribute<
34193419
Attribute::Alignment,
34203420
StateWrapper<AAAlignmentStateType, AbstractAttribute>> {
34213421
AAAlign(const IRPosition &IRP, Attributor &A) : IRAttribute(IRP) {}
34223422

34233423
/// Return assumed alignment.
3424-
unsigned getAssumedAlign() const { return getAssumed(); }
3424+
uint64_t getAssumedAlign() const { return getAssumed(); }
34253425

34263426
/// Return known alignment.
3427-
unsigned getKnownAlign() const { return getKnown(); }
3427+
uint64_t getKnownAlign() const { return getKnown(); }
34283428

34293429
/// See AbstractAttribute::getName()
34303430
const std::string getName() const override { return "AAAlign"; }

llvm/include/llvm/Transforms/Utils/ASanStackFrameLayout.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ struct ASanStackVariableDescription {
3333
uint64_t Size; // Size of the variable in bytes.
3434
size_t LifetimeSize; // Size in bytes to use for lifetime analysis check.
3535
// Will be rounded up to Granularity.
36-
size_t Alignment; // Alignment of the variable (power of 2).
36+
uint64_t Alignment; // Alignment of the variable (power of 2).
3737
AllocaInst *AI; // The actual AllocaInst.
3838
size_t Offset; // Offset from the beginning of the frame;
3939
// set by ComputeASanStackFrameLayout.

llvm/lib/AsmParser/LLParser.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -1927,7 +1927,7 @@ bool LLParser::parseOptionalAlignment(MaybeAlign &Alignment, bool AllowParens) {
19271927
if (!EatIfPresent(lltok::kw_align))
19281928
return false;
19291929
LocTy AlignLoc = Lex.getLoc();
1930-
uint32_t Value = 0;
1930+
uint64_t Value = 0;
19311931

19321932
LocTy ParenLoc = Lex.getLoc();
19331933
bool HaveParens = false;
@@ -1936,13 +1936,13 @@ bool LLParser::parseOptionalAlignment(MaybeAlign &Alignment, bool AllowParens) {
19361936
HaveParens = true;
19371937
}
19381938

1939-
if (parseUInt32(Value))
1939+
if (parseUInt64(Value))
19401940
return true;
19411941

19421942
if (HaveParens && !EatIfPresent(lltok::rparen))
19431943
return error(ParenLoc, "expected ')'");
19441944

1945-
if (!isPowerOf2_32(Value))
1945+
if (!isPowerOf2_64(Value))
19461946
return error(AlignLoc, "alignment is not a power of two");
19471947
if (Value > Value::MaximumAlignment)
19481948
return error(AlignLoc, "huge alignments are not supported yet");

llvm/lib/Bitcode/Reader/BitcodeReader.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -4930,8 +4930,10 @@ Error BitcodeReader::parseFunctionBody(Function *F) {
49304930
Type *OpTy = getTypeByID(Record[1]);
49314931
Value *Size = getFnValueByID(Record[2], OpTy);
49324932
MaybeAlign Align;
4933-
if (Error Err =
4934-
parseAlignmentValue(Bitfield::get<APV::Align>(Rec), Align)) {
4933+
uint64_t AlignExp =
4934+
Bitfield::get<APV::AlignLower>(Rec) |
4935+
(Bitfield::get<APV::AlignUpper>(Rec) << APV::AlignLower::Bits);
4936+
if (Error Err = parseAlignmentValue(AlignExp, Align)) {
49354937
return Err;
49364938
}
49374939
if (!Ty || !Size)

llvm/lib/Bitcode/Writer/BitcodeWriter.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -3055,7 +3055,11 @@ void ModuleBitcodeWriter::writeInstruction(const Instruction &I,
30553055
Vals.push_back(VE.getValueID(I.getOperand(0))); // size.
30563056
using APV = AllocaPackedValues;
30573057
unsigned Record = 0;
3058-
Bitfield::set<APV::Align>(Record, getEncodedAlign(AI.getAlign()));
3058+
unsigned EncodedAlign = getEncodedAlign(AI.getAlign());
3059+
Bitfield::set<APV::AlignLower>(
3060+
Record, EncodedAlign & ((1 << APV::AlignLower::Bits) - 1));
3061+
Bitfield::set<APV::AlignUpper>(Record,
3062+
EncodedAlign >> APV::AlignLower::Bits);
30593063
Bitfield::set<APV::UsedWithInAlloca>(Record, AI.isUsedWithInAlloca());
30603064
Bitfield::set<APV::ExplicitType>(Record, true);
30613065
Bitfield::set<APV::SwiftError>(Record, AI.isSwiftError());

0 commit comments

Comments
 (0)