Skip to content

Commit

Permalink
Revert "[IR] Increase max alignment to 4GB"
Browse files Browse the repository at this point in the history
This reverts commit df84c1f.

Breaks some bots
  • Loading branch information
aeubanks committed Oct 6, 2021
1 parent 2130117 commit 72cf8b6
Show file tree
Hide file tree
Showing 48 changed files with 152 additions and 161 deletions.
4 changes: 2 additions & 2 deletions clang/lib/CodeGen/CGBlocks.cpp
Expand Up @@ -2695,8 +2695,8 @@ const BlockByrefInfo &CodeGenFunction::getBlockByrefInfo(const VarDecl *D) {
size = varOffset;

// Conversely, we might have to prevent LLVM from inserting padding.
} else if (CGM.getDataLayout().getABITypeAlignment(varTy) >
uint64_t(varAlign.getQuantity())) {
} else if (CGM.getDataLayout().getABITypeAlignment(varTy)
> varAlign.getQuantity()) {
packed = true;
}
types.push_back(varTy);
Expand Down
12 changes: 6 additions & 6 deletions clang/lib/CodeGen/CGCall.cpp
Expand Up @@ -5021,12 +5021,12 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
auto scalarAlign = CGM.getDataLayout().getPrefTypeAlignment(scalarType);

// Materialize to a temporary.
addr =
CreateTempAlloca(RV.getScalarVal()->getType(),
CharUnits::fromQuantity(std::max(
layout->getAlignment().value(), scalarAlign)),
"tmp",
/*ArraySize=*/nullptr, &AllocaAddr);
addr = CreateTempAlloca(
RV.getScalarVal()->getType(),
CharUnits::fromQuantity(std::max(
(unsigned)layout->getAlignment().value(), scalarAlign)),
"tmp",
/*ArraySize=*/nullptr, &AllocaAddr);
tempSize = EmitLifetimeStart(scalarSize, AllocaAddr.getPointer());

Builder.CreateStore(RV.getScalarVal(), addr);
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/CodeGen/CGDecl.cpp
Expand Up @@ -1142,7 +1142,7 @@ Address CodeGenModule::createUnnamedGlobalFrom(const VarDecl &D,
GV->setAlignment(Align.getAsAlign());
GV->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
CacheEntry = GV;
} else if (CacheEntry->getAlignment() < uint64_t(Align.getQuantity())) {
} else if (CacheEntry->getAlignment() < Align.getQuantity()) {
CacheEntry->setAlignment(Align.getAsAlign());
}

Expand Down
4 changes: 2 additions & 2 deletions clang/lib/CodeGen/CodeGenModule.cpp
Expand Up @@ -5386,7 +5386,7 @@ CodeGenModule::GetAddrOfConstantStringFromLiteral(const StringLiteral *S,
if (!LangOpts.WritableStrings) {
Entry = &ConstantStringMap[C];
if (auto GV = *Entry) {
if (uint64_t(Alignment.getQuantity()) > GV->getAlignment())
if (Alignment.getQuantity() > GV->getAlignment())
GV->setAlignment(Alignment.getAsAlign());
return ConstantAddress(castStringLiteralToDefaultAddressSpace(*this, GV),
Alignment);
Expand Down Expand Up @@ -5449,7 +5449,7 @@ ConstantAddress CodeGenModule::GetAddrOfConstantCString(
if (!LangOpts.WritableStrings) {
Entry = &ConstantStringMap[C];
if (auto GV = *Entry) {
if (uint64_t(Alignment.getQuantity()) > GV->getAlignment())
if (Alignment.getQuantity() > GV->getAlignment())
GV->setAlignment(Alignment.getAsAlign());
return ConstantAddress(castStringLiteralToDefaultAddressSpace(*this, GV),
Alignment);
Expand Down
8 changes: 2 additions & 6 deletions llvm/include/llvm/Bitcode/BitcodeCommon.h
Expand Up @@ -19,14 +19,10 @@
namespace llvm {

struct AllocaPackedValues {
// We increased the number of bits needed to represent alignment to be more
// than 5, but to preserve backward compatibility we store the upper bits
// separately.
using AlignLower = Bitfield::Element<unsigned, 0, 5>;
using UsedWithInAlloca = Bitfield::Element<bool, AlignLower::NextBit, 1>;
using Align = Bitfield::Element<unsigned, 0, 5>;
using UsedWithInAlloca = Bitfield::Element<bool, Align::NextBit, 1>;
using ExplicitType = Bitfield::Element<bool, UsedWithInAlloca::NextBit, 1>;
using SwiftError = Bitfield::Element<bool, ExplicitType::NextBit, 1>;
using AlignUpper = Bitfield::Element<unsigned, SwiftError::NextBit, 3>;
};

} // namespace llvm
Expand Down
4 changes: 2 additions & 2 deletions llvm/include/llvm/IR/DataLayout.h
Expand Up @@ -518,7 +518,7 @@ class DataLayout {

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

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

/// Returns the preferred stack/global alignment for the specified
/// type.
Expand Down
4 changes: 2 additions & 2 deletions llvm/include/llvm/IR/GlobalObject.h
Expand Up @@ -51,7 +51,7 @@ class GlobalObject : public GlobalValue {

Comdat *ObjComdat;
enum {
LastAlignmentBit = 5,
LastAlignmentBit = 4,
HasSectionHashEntryBit,

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

/// FIXME: Remove this function once transition to Align is over.
uint64_t getAlignment() const {
unsigned getAlignment() const {
MaybeAlign Align = getAlign();
return Align ? Align->value() : 0;
}
Expand Down
4 changes: 2 additions & 2 deletions llvm/include/llvm/IR/Instruction.h
Expand Up @@ -59,11 +59,11 @@ class Instruction : public User,
// Template alias so that all Instruction storing alignment use the same
// definiton.
// Valid alignments are powers of two from 2^0 to 2^MaxAlignmentExponent =
// 2^32. We store them as Log2(Alignment), so we need 6 bits to encode the 33
// 2^30. We store them as Log2(Alignment), so we need 5 bits to encode the 31
// possible values.
template <unsigned Offset>
using AlignmentBitfieldElementT =
typename Bitfield::Element<unsigned, Offset, 6,
typename Bitfield::Element<unsigned, Offset, 5,
Value::MaxAlignmentExponent>;

template <unsigned Offset>
Expand Down
6 changes: 3 additions & 3 deletions llvm/include/llvm/IR/Instructions.h
Expand Up @@ -126,7 +126,7 @@ class AllocaInst : public UnaryInstruction {
}

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

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

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

Align getAlign() const {
return Align(1ULL << (getSubclassData<AlignmentField>()));
Expand Down
4 changes: 2 additions & 2 deletions llvm/include/llvm/IR/Value.h
Expand Up @@ -785,8 +785,8 @@ class Value {
///
/// This is the greatest alignment value supported by load, store, and alloca
/// instructions, and global values.
static constexpr unsigned MaxAlignmentExponent = 32;
static constexpr uint64_t MaximumAlignment = 1ULL << MaxAlignmentExponent;
static constexpr unsigned MaxAlignmentExponent = 30;
static constexpr unsigned MaximumAlignment = 1u << MaxAlignmentExponent;

/// Mutate the type of this Value to be of the specified type.
///
Expand Down
6 changes: 3 additions & 3 deletions llvm/include/llvm/Transforms/IPO/Attributor.h
Expand Up @@ -3413,18 +3413,18 @@ struct AADereferenceable
};

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

/// Return assumed alignment.
uint64_t getAssumedAlign() const { return getAssumed(); }
unsigned getAssumedAlign() const { return getAssumed(); }

/// Return known alignment.
uint64_t getKnownAlign() const { return getKnown(); }
unsigned getKnownAlign() const { return getKnown(); }

/// See AbstractAttribute::getName()
const std::string getName() const override { return "AAAlign"; }
Expand Down
6 changes: 3 additions & 3 deletions llvm/lib/AsmParser/LLParser.cpp
Expand Up @@ -1927,7 +1927,7 @@ bool LLParser::parseOptionalAlignment(MaybeAlign &Alignment, bool AllowParens) {
if (!EatIfPresent(lltok::kw_align))
return false;
LocTy AlignLoc = Lex.getLoc();
uint64_t Value = 0;
uint32_t Value = 0;

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

if (parseUInt64(Value))
if (parseUInt32(Value))
return true;

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

if (!isPowerOf2_64(Value))
if (!isPowerOf2_32(Value))
return error(AlignLoc, "alignment is not a power of two");
if (Value > Value::MaximumAlignment)
return error(AlignLoc, "huge alignments are not supported yet");
Expand Down
6 changes: 2 additions & 4 deletions llvm/lib/Bitcode/Reader/BitcodeReader.cpp
Expand Up @@ -4930,10 +4930,8 @@ Error BitcodeReader::parseFunctionBody(Function *F) {
Type *OpTy = getTypeByID(Record[1]);
Value *Size = getFnValueByID(Record[2], OpTy);
MaybeAlign Align;
uint64_t AlignExp =
Bitfield::get<APV::AlignLower>(Rec) |
(Bitfield::get<APV::AlignUpper>(Rec) << APV::AlignLower::Bits);
if (Error Err = parseAlignmentValue(AlignExp, Align)) {
if (Error Err =
parseAlignmentValue(Bitfield::get<APV::Align>(Rec), Align)) {
return Err;
}
if (!Ty || !Size)
Expand Down
6 changes: 1 addition & 5 deletions llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
Expand Up @@ -3055,11 +3055,7 @@ void ModuleBitcodeWriter::writeInstruction(const Instruction &I,
Vals.push_back(VE.getValueID(I.getOperand(0))); // size.
using APV = AllocaPackedValues;
unsigned Record = 0;
unsigned EncodedAlign = getEncodedAlign(AI.getAlign());
Bitfield::set<APV::AlignLower>(
Record, EncodedAlign & ((1 << APV::AlignLower::Bits) - 1));
Bitfield::set<APV::AlignUpper>(Record,
EncodedAlign >> APV::AlignLower::Bits);
Bitfield::set<APV::Align>(Record, getEncodedAlign(AI.getAlign()));
Bitfield::set<APV::UsedWithInAlloca>(Record, AI.isUsedWithInAlloca());
Bitfield::set<APV::ExplicitType>(Record, true);
Bitfield::set<APV::SwiftError>(Record, AI.isSwiftError());
Expand Down
12 changes: 6 additions & 6 deletions llvm/lib/CodeGen/MIRParser/MIParser.cpp
Expand Up @@ -498,7 +498,7 @@ class MIParser {
MachineOperand &Dest,
Optional<unsigned> &TiedDefIdx);
bool parseOffset(int64_t &Offset);
bool parseAlignment(uint64_t &Alignment);
bool parseAlignment(unsigned &Alignment);
bool parseAddrspace(unsigned &Addrspace);
bool parseSectionID(Optional<MBBSectionID> &SID);
bool parseOperandsOffset(MachineOperand &Op);
Expand Down Expand Up @@ -676,7 +676,7 @@ bool MIParser::parseBasicBlockDefinition(
bool IsLandingPad = false;
bool IsEHFuncletEntry = false;
Optional<MBBSectionID> SectionID;
uint64_t Alignment = 0;
unsigned Alignment = 0;
BasicBlock *BB = nullptr;
if (consumeIfPresent(MIToken::lparen)) {
do {
Expand Down Expand Up @@ -2898,16 +2898,16 @@ bool MIParser::parseOffset(int64_t &Offset) {
return false;
}

bool MIParser::parseAlignment(uint64_t &Alignment) {
bool MIParser::parseAlignment(unsigned &Alignment) {
assert(Token.is(MIToken::kw_align) || Token.is(MIToken::kw_basealign));
lex();
if (Token.isNot(MIToken::IntegerLiteral) || Token.integerValue().isSigned())
return error("expected an integer literal after 'align'");
if (getUint64(Alignment))
if (getUnsigned(Alignment))
return true;
lex();

if (!isPowerOf2_64(Alignment))
if (!isPowerOf2_32(Alignment))
return error("expected a power-of-2 literal after 'align'");

return false;
Expand Down Expand Up @@ -3261,7 +3261,7 @@ bool MIParser::parseMachineMemoryOperand(MachineMemOperand *&Dest) {
if (parseMachinePointerInfo(Ptr))
return true;
}
uint64_t BaseAlignment =
unsigned BaseAlignment =
(Size != MemoryLocation::UnknownSize ? PowerOf2Ceil(Size) : 1);
AAMDNodes AAInfo;
MDNode *Range = nullptr;
Expand Down
11 changes: 6 additions & 5 deletions llvm/lib/CodeGen/SafeStack.cpp
Expand Up @@ -147,7 +147,7 @@ class SafeStack {
///
/// 16 seems like a reasonable upper bound on the alignment of objects that we
/// might expect to appear on the stack on most common targets.
static constexpr uint64_t StackAlignment = 16;
enum { StackAlignment = 16 };

/// Return the value of the stack canary.
Value *getStackGuard(IRBuilder<> &IRB, Function &F);
Expand Down Expand Up @@ -544,7 +544,8 @@ Value *SafeStack::moveStaticAllocasToUnsafeStack(
Size = 1; // Don't create zero-sized stack objects.

// Ensure the object is properly aligned.
uint64_t Align = std::max(DL.getPrefTypeAlignment(Ty), AI->getAlignment());
unsigned Align =
std::max((unsigned)DL.getPrefTypeAlignment(Ty), AI->getAlignment());

SSL.addObject(AI, Size, Align,
ClColoring ? SSC.getLiveRange(AI) : NoColoringRange);
Expand Down Expand Up @@ -675,9 +676,9 @@ void SafeStack::moveDynamicAllocasToUnsafeStack(
SP = IRB.CreateSub(SP, Size);

// Align the SP value to satisfy the AllocaInst, type and stack alignments.
uint64_t Align =
std::max(std::max(DL.getPrefTypeAlignment(Ty), AI->getAlignment()),
StackAlignment);
unsigned Align = std::max(
std::max((unsigned)DL.getPrefTypeAlignment(Ty), AI->getAlignment()),
(unsigned)StackAlignment);

assert(isPowerOf2_32(Align));
Value *NewTop = IRB.CreateIntToPtr(
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/IR/DataLayout.cpp
Expand Up @@ -819,7 +819,7 @@ Align DataLayout::getAlignment(Type *Ty, bool abi_or_pref) const {
}

/// TODO: Remove this function once the transition to Align is over.
uint64_t DataLayout::getABITypeAlignment(Type *Ty) const {
unsigned DataLayout::getABITypeAlignment(Type *Ty) const {
return getABITypeAlign(Ty).value();
}

Expand All @@ -828,7 +828,7 @@ Align DataLayout::getABITypeAlign(Type *Ty) const {
}

/// TODO: Remove this function once the transition to Align is over.
uint64_t DataLayout::getPrefTypeAlignment(Type *Ty) const {
unsigned DataLayout::getPrefTypeAlignment(Type *Ty) const {
return getPrefTypeAlign(Ty).value();
}

Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
Expand Up @@ -176,7 +176,7 @@ const char kAMDGPUAddressPrivateName[] = "llvm.amdgcn.is.private";
// Accesses sizes are powers of two: 1, 2, 4, 8, 16.
static const size_t kNumberOfAccessSizes = 5;

static const uint64_t kAllocaRzSize = 32;
static const unsigned kAllocaRzSize = 32;

// ASanAccessInfo implementation constants.
constexpr size_t kCompileKernelShift = 0;
Expand Down Expand Up @@ -3578,7 +3578,7 @@ void FunctionStackPoisoner::poisonAlloca(Value *V, uint64_t Size,
void FunctionStackPoisoner::handleDynamicAllocaCall(AllocaInst *AI) {
IRBuilder<> IRB(AI);

const uint64_t Alignment = std::max(kAllocaRzSize, AI->getAlignment());
const unsigned Alignment = std::max(kAllocaRzSize, AI->getAlignment());
const uint64_t AllocaRedzoneMask = kAllocaRzSize - 1;

Value *Zero = Constant::getNullValue(IntptrTy);
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
Expand Up @@ -356,7 +356,7 @@ class HWAddressSanitizer {
bool WithFrameRecord;

void init(Triple &TargetTriple, bool InstrumentWithCalls);
uint64_t getObjectAlignment() const { return 1ULL << Scale; }
unsigned getObjectAlignment() const { return 1U << Scale; }
};

ShadowMapping Mapping;
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/Assembler/align-inst-alloca.ll
@@ -1,6 +1,6 @@
; RUN: not llvm-as %s -o /dev/null 2>/dev/null

define void @foo() {
%p = alloca i1, align 8589934592
%p = alloca i1, align 2147483648
ret void
}
2 changes: 1 addition & 1 deletion llvm/test/Assembler/align-inst-load.ll
@@ -1,6 +1,6 @@
; RUN: not llvm-as %s -o /dev/null 2>/dev/null

define void @foo(i1* %p) {
load i1, i1* %p, align 8589934592
load i1, i1* %p, align 2147483648
ret void
}
2 changes: 1 addition & 1 deletion llvm/test/Assembler/align-inst-store.ll
@@ -1,6 +1,6 @@
; RUN: not llvm-as %s -o /dev/null 2>/dev/null

define void @foo(i1* %p) {
store i1 false, i1* %p, align 8589934592
store i1 false, i1* %p, align 2147483648
ret void
}
8 changes: 4 additions & 4 deletions llvm/test/Assembler/align-inst.ll
@@ -1,11 +1,11 @@
; RUN: llvm-as %s -o /dev/null
; RUN: verify-uselistorder %s

@A = global i1 0, align 4294967296
@A = global i1 0, align 1073741824

define void @foo() {
%p = alloca i1, align 4294967296
load i1, i1* %p, align 4294967296
store i1 false, i1* %p, align 4294967296
%p = alloca i1, align 1073741824
load i1, i1* %p, align 1073741824
store i1 false, i1* %p, align 1073741824
ret void
}
Binary file modified llvm/test/Bitcode/Inputs/invalid-align.bc
Binary file not shown.

0 comments on commit 72cf8b6

Please sign in to comment.