Skip to content

Commit

Permalink
[Alignment][NFC] Deprecate ensureMaxAlignment
Browse files Browse the repository at this point in the history
Summary:
This is patch is part of a series to introduce an Alignment type.
See this thread for context: http://lists.llvm.org/pipermail/llvm-dev/2019-July/133851.html
See this patch for the introduction of the type: https://reviews.llvm.org/D64790

Reviewers: courbet

Subscribers: hiraditya, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D76368
  • Loading branch information
gchatelet committed Mar 23, 2020
1 parent 6a6a83c commit ea64ee0
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 12 deletions.
2 changes: 1 addition & 1 deletion llvm/include/llvm/CodeGen/CallingConvLower.h
Expand Up @@ -435,7 +435,7 @@ class CCState {

void ensureMaxAlignment(Align Alignment) {
if (!AnalyzingMustTailForwardedRegs)
MF.getFrameInfo().ensureMaxAlignment(Alignment.value());
MF.getFrameInfo().ensureMaxAlignment(Alignment);
}

/// Version of AllocateStack with extra register to be shadowed.
Expand Down
5 changes: 3 additions & 2 deletions llvm/include/llvm/CodeGen/MachineFrameInfo.h
Expand Up @@ -484,7 +484,7 @@ class MachineFrameInfo {

// Only ensure max alignment for the default stack.
if (getStackID(ObjectIdx) == 0)
ensureMaxAlignment(Align);
ensureMaxAlignment(assumeAligned(Align));
}

/// setObjectAlignment - Change the alignment of the specified stack object.
Expand Down Expand Up @@ -594,7 +594,8 @@ class MachineFrameInfo {
/// Make sure the function is at least Align bytes aligned.
void ensureMaxAlignment(Align Alignment);
/// FIXME: Remove this once transition to Align is over.
inline void ensureMaxAlignment(unsigned Align) {
LLVM_ATTRIBUTE_DEPRECATED(inline void ensureMaxAlignment(unsigned Align),
"Use the version that uses Align instead") {
ensureMaxAlignment(assumeAligned(Align));
}

Expand Down
6 changes: 6 additions & 0 deletions llvm/include/llvm/CodeGen/TargetRegisterInfo.h
Expand Up @@ -285,6 +285,12 @@ class TargetRegisterInfo : public MCRegisterInfo {
return getRegClassInfo(RC).SpillAlignment / 8;
}

/// Return the minimum required alignment in bytes for a spill slot for
/// a register of this class.
Align getSpillAlign(const TargetRegisterClass &RC) const {
return Align(getRegClassInfo(RC).SpillAlignment / 8);
}

/// Return true if the given TargetRegisterClass has the ValueType T.
bool isTypeLegalForClass(const TargetRegisterClass &RC, MVT T) const {
for (auto I = legalclasstypes_begin(RC); *I != MVT::Other; ++I)
Expand Down
7 changes: 7 additions & 0 deletions llvm/include/llvm/IR/Function.h
Expand Up @@ -349,6 +349,13 @@ class Function : public GlobalObject, public ilist_node<Function> {
return 0;
}

/// Return the stack alignment for the function.
MaybeAlign getFnStackAlign() const {
if (!hasFnAttribute(Attribute::StackAlignment))
return None;
return AttributeSets.getStackAlignment(AttributeList::FunctionIndex);
}

/// hasGC/getGC/setGC/clearGC - The name of the garbage collection algorithm
/// to use during code generation.
bool hasGC() const {
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/CodeGen/MIRParser/MIRParser.cpp
Expand Up @@ -654,7 +654,7 @@ bool MIRParserImpl::initializeFrameInfo(PerFunctionMIParsingState &PFS,
MFI.setStackSize(YamlMFI.StackSize);
MFI.setOffsetAdjustment(YamlMFI.OffsetAdjustment);
if (YamlMFI.MaxAlignment)
MFI.ensureMaxAlignment(YamlMFI.MaxAlignment);
MFI.ensureMaxAlignment(Align(YamlMFI.MaxAlignment));
MFI.setAdjustsStack(YamlMFI.AdjustsStack);
MFI.setHasCalls(YamlMFI.HasCalls);
if (YamlMFI.MaxCallFrameSize != ~0u)
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/CodeGen/MachineFunction.cpp
Expand Up @@ -172,7 +172,7 @@ void MachineFunction::init() {
F.hasFnAttribute(Attribute::StackAlignment));

if (F.hasFnAttribute(Attribute::StackAlignment))
FrameInfo->ensureMaxAlignment(F.getFnStackAlignment());
FrameInfo->ensureMaxAlignment(*F.getFnStackAlign());

ConstantPool = new (Allocator) MachineConstantPool(getDataLayout());
Alignment = STI->getTargetLowering()->getMinFunctionAlignment();
Expand Down
8 changes: 4 additions & 4 deletions llvm/lib/Target/Hexagon/HexagonISelLowering.cpp
Expand Up @@ -432,7 +432,7 @@ HexagonTargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI,
DAG.getCopyFromReg(Chain, dl, HRI.getStackRegister(), PtrVT);

bool NeedsArgAlign = false;
unsigned LargestAlignSeen = 0;
Align LargestAlignSeen;
// Walk the register/memloc assignments, inserting copies/loads.
for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) {
CCValAssign &VA = ArgLocs[i];
Expand Down Expand Up @@ -469,8 +469,8 @@ HexagonTargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI,
StackPtr.getValueType());
MemAddr = DAG.getNode(ISD::ADD, dl, MVT::i32, StackPtr, MemAddr);
if (ArgAlign)
LargestAlignSeen = std::max(LargestAlignSeen,
(unsigned)VA.getLocVT().getStoreSizeInBits() >> 3);
LargestAlignSeen = std::max(
LargestAlignSeen, Align(VA.getLocVT().getStoreSizeInBits() / 8));
if (Flags.isByVal()) {
// The argument is a struct passed by value. According to LLVM, "Arg"
// is a pointer.
Expand All @@ -493,7 +493,7 @@ HexagonTargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI,

if (NeedsArgAlign && Subtarget.hasV60Ops()) {
LLVM_DEBUG(dbgs() << "Function needs byte stack align due to call args\n");
unsigned VecAlign = HRI.getSpillAlignment(Hexagon::HvxVRRegClass);
Align VecAlign(HRI.getSpillAlignment(Hexagon::HvxVRRegClass));
LargestAlignSeen = std::max(LargestAlignSeen, VecAlign);
MFI.ensureMaxAlignment(LargestAlignSeen);
}
Expand Down
6 changes: 3 additions & 3 deletions llvm/lib/Target/X86/X86FrameLowering.cpp
Expand Up @@ -2229,16 +2229,16 @@ bool X86FrameLowering::assignCalleeSavedSpillSlots(

const TargetRegisterClass *RC = TRI->getMinimalPhysRegClass(Reg, VT);
unsigned Size = TRI->getSpillSize(*RC);
unsigned Align = TRI->getSpillAlignment(*RC);
Align Alignment = TRI->getSpillAlign(*RC);
// ensure alignment
assert(SpillSlotOffset < 0 && "SpillSlotOffset should always < 0 on X86");
SpillSlotOffset = -alignTo(-SpillSlotOffset, Align);
SpillSlotOffset = -alignTo(-SpillSlotOffset, Alignment);

// spill into slot
SpillSlotOffset -= Size;
int SlotIndex = MFI.CreateFixedSpillStackObject(Size, SpillSlotOffset);
CSI[i - 1].setFrameIdx(SlotIndex);
MFI.ensureMaxAlignment(Align);
MFI.ensureMaxAlignment(Alignment);

// Save the start offset and size of XMM in stack frame for funclets.
if (X86::VR128RegClass.contains(Reg)) {
Expand Down

0 comments on commit ea64ee0

Please sign in to comment.