diff --git a/llvm/lib/Target/AArch64/AArch64CallingConvention.cpp b/llvm/lib/Target/AArch64/AArch64CallingConvention.cpp --- a/llvm/lib/Target/AArch64/AArch64CallingConvention.cpp +++ b/llvm/lib/Target/AArch64/AArch64CallingConvention.cpp @@ -38,18 +38,17 @@ static bool finishStackBlock(SmallVectorImpl &PendingMembers, MVT LocVT, ISD::ArgFlagsTy &ArgFlags, - CCState &State, unsigned SlotAlign) { + CCState &State, Align SlotAlign) { unsigned Size = LocVT.getSizeInBits() / 8; const Align StackAlign = State.getMachineFunction().getDataLayout().getStackAlignment(); const Align OrigAlign(ArgFlags.getOrigAlign()); - const Align Align = std::min(OrigAlign, StackAlign); + const Align Alignment = std::min(OrigAlign, StackAlign); for (auto &It : PendingMembers) { - It.convertToMem(State.AllocateStack( - Size, std::max((unsigned)Align.value(), SlotAlign))); + It.convertToMem(State.AllocateStack(Size, std::max(Alignment, SlotAlign))); State.addLoc(It); - SlotAlign = 1; + SlotAlign = Align(1); } // All pending members have now been allocated @@ -72,7 +71,7 @@ if (!ArgFlags.isInConsecutiveRegsLast()) return true; - return finishStackBlock(PendingMembers, LocVT, ArgFlags, State, 8); + return finishStackBlock(PendingMembers, LocVT, ArgFlags, State, Align(8)); } /// Given an [N x Ty] block, it should be passed in a consecutive sequence of @@ -146,7 +145,7 @@ for (auto Reg : RegList) State.AllocateReg(Reg); - unsigned SlotAlign = Subtarget.isTargetDarwin() ? 1 : 8; + const Align SlotAlign = Subtarget.isTargetDarwin() ? Align(1) : Align(8); return finishStackBlock(PendingMembers, LocVT, ArgFlags, State, SlotAlign); } diff --git a/llvm/lib/Target/ARM/ARMCallingConv.cpp b/llvm/lib/Target/ARM/ARMCallingConv.cpp --- a/llvm/lib/Target/ARM/ARMCallingConv.cpp +++ b/llvm/lib/Target/ARM/ARMCallingConv.cpp @@ -32,9 +32,8 @@ return false; // Put the whole thing on the stack. - State.addLoc(CCValAssign::getCustomMem(ValNo, ValVT, - State.AllocateStack(8, 4), - LocVT, LocInfo)); + State.addLoc(CCValAssign::getCustomMem( + ValNo, ValVT, State.AllocateStack(8, Align(4)), LocVT, LocInfo)); return true; } @@ -42,9 +41,8 @@ if (unsigned Reg = State.AllocateReg(RegList)) State.addLoc(CCValAssign::getCustomReg(ValNo, ValVT, Reg, LocVT, LocInfo)); else - State.addLoc(CCValAssign::getCustomMem(ValNo, ValVT, - State.AllocateStack(4, 4), - LocVT, LocInfo)); + State.addLoc(CCValAssign::getCustomMem( + ValNo, ValVT, State.AllocateStack(4, Align(4)), LocVT, LocInfo)); return true; } @@ -81,9 +79,8 @@ return false; // Put the whole thing on the stack. - State.addLoc(CCValAssign::getCustomMem(ValNo, ValVT, - State.AllocateStack(8, 8), - LocVT, LocInfo)); + State.addLoc(CCValAssign::getCustomMem( + ValNo, ValVT, State.AllocateStack(8, Align(8)), LocVT, LocInfo)); return true; } @@ -193,8 +190,9 @@ // Try to allocate a contiguous block of registers, each of the correct // size to hold one member. auto &DL = State.getMachineFunction().getDataLayout(); - unsigned StackAlign = DL.getStackAlignment().value(); - unsigned Align = std::min(PendingMembers[0].getExtraInfo(), StackAlign); + const Align StackAlign = DL.getStackAlignment(); + const Align FirstMemberAlign(PendingMembers[0].getExtraInfo()); + Align Alignment = std::min(FirstMemberAlign, StackAlign); ArrayRef RegList; switch (LocVT.SimpleTy) { @@ -204,7 +202,7 @@ // First consume all registers that would give an unaligned object. Whether // we go on stack or in regs, no-one will be using them in future. - unsigned RegAlign = alignTo(Align, 4) / 4; + unsigned RegAlign = alignTo(Alignment.value(), 4) / 4; while (RegIdx % RegAlign != 0 && RegIdx < RegList.size()) State.AllocateReg(RegList[RegIdx++]); @@ -247,7 +245,7 @@ unsigned RegIdx = State.getFirstUnallocated(RegList); for (auto &It : PendingMembers) { if (RegIdx >= RegList.size()) - It.convertToMem(State.AllocateStack(Size, Size)); + It.convertToMem(State.AllocateStack(Size, Align(Size))); else It.convertToReg(State.AllocateReg(RegList[RegIdx++])); @@ -265,12 +263,12 @@ // After the first item has been allocated, the rest are packed as tightly as // possible. (E.g. an incoming i64 would have starting Align of 8, but we'll // be allocating a bunch of i32 slots). - unsigned RestAlign = std::min(Align, Size); + const Align RestAlign = std::min(Alignment, Align(Size)); for (auto &It : PendingMembers) { - It.convertToMem(State.AllocateStack(Size, Align)); + It.convertToMem(State.AllocateStack(Size, Alignment)); State.addLoc(It); - Align = RestAlign; + Alignment = RestAlign; } // All pending members have now been allocated