[llvm] r367822 - [LLVM][Alignment] Introduce Alignment In CallingConv
Guillaume Chatelet via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 5 02:49:09 PDT 2019
Author: gchatelet
Date: Mon Aug 5 02:49:09 2019
New Revision: 367822
URL: http://llvm.org/viewvc/llvm-project?rev=367822&view=rev
Log:
[LLVM][Alignment] Introduce Alignment In CallingConv
Summary:
This is patch is part of a serie 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
Subscribers: hiraditya, llvm-commits, courbet, jfb
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D65659
Modified:
llvm/trunk/include/llvm/CodeGen/CallingConvLower.h
llvm/trunk/include/llvm/CodeGen/TargetCallingConv.h
llvm/trunk/lib/CodeGen/CallingConvLower.cpp
Modified: llvm/trunk/include/llvm/CodeGen/CallingConvLower.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/CallingConvLower.h?rev=367822&r1=367821&r2=367822&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/CallingConvLower.h (original)
+++ llvm/trunk/include/llvm/CodeGen/CallingConvLower.h Mon Aug 5 02:49:09 2019
@@ -20,6 +20,7 @@
#include "llvm/CodeGen/TargetCallingConv.h"
#include "llvm/IR/CallingConv.h"
#include "llvm/MC/MCRegisterInfo.h"
+#include "llvm/Support/Alignment.h"
namespace llvm {
@@ -197,7 +198,7 @@ private:
LLVMContext &Context;
unsigned StackOffset;
- unsigned MaxStackArgAlign;
+ Align MaxStackArgAlign;
SmallVector<uint32_t, 16> UsedRegs;
SmallVector<CCValAssign, 4> PendingLocs;
SmallVector<ISD::ArgFlagsTy, 4> PendingArgFlags;
@@ -421,8 +422,8 @@ public:
/// AllocateStack - Allocate a chunk of stack space with the specified size
/// and alignment.
- unsigned AllocateStack(unsigned Size, unsigned Align) {
- assert(Align && ((Align - 1) & Align) == 0); // Align is power of 2.
+ unsigned AllocateStack(unsigned Size, unsigned Alignment) {
+ const llvm::Align Align(Alignment);
StackOffset = alignTo(StackOffset, Align);
unsigned Result = StackOffset;
StackOffset += Size;
@@ -431,9 +432,9 @@ public:
return Result;
}
- void ensureMaxAlignment(unsigned Align) {
+ void ensureMaxAlignment(llvm::Align Align) {
if (!AnalyzingMustTailForwardedRegs)
- MF.getFrameInfo().ensureMaxAlignment(Align);
+ MF.getFrameInfo().ensureMaxAlignment(Align.value());
}
/// Version of AllocateStack with extra register to be shadowed.
Modified: llvm/trunk/include/llvm/CodeGen/TargetCallingConv.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/TargetCallingConv.h?rev=367822&r1=367821&r2=367822&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/TargetCallingConv.h (original)
+++ llvm/trunk/include/llvm/CodeGen/TargetCallingConv.h Mon Aug 5 02:49:09 2019
@@ -14,6 +14,7 @@
#define LLVM_CODEGEN_TARGETCALLINGCONV_H
#include "llvm/CodeGen/ValueTypes.h"
+#include "llvm/Support/Alignment.h"
#include "llvm/Support/MachineValueType.h"
#include "llvm/Support/MathExtras.h"
#include <cassert>
@@ -120,15 +121,21 @@ namespace ISD {
bool isPointer() const { return IsPointer; }
void setPointer() { IsPointer = 1; }
- unsigned getByValAlign() const { return (1U << ByValAlign) / 2; }
+ unsigned getByValAlign() const {
+ MaybeAlign A = decodeMaybeAlign(ByValAlign);
+ return A ? A->value() : 0;
+ }
void setByValAlign(unsigned A) {
- ByValAlign = Log2_32(A) + 1;
+ ByValAlign = encode(llvm::Align(A));
assert(getByValAlign() == A && "bitfield overflow");
}
- unsigned getOrigAlign() const { return (1U << OrigAlign) / 2; }
+ unsigned getOrigAlign() const {
+ MaybeAlign A = decodeMaybeAlign(OrigAlign);
+ return A ? A->value() : 0;
+ }
void setOrigAlign(unsigned A) {
- OrigAlign = Log2_32(A) + 1;
+ OrigAlign = encode(llvm::Align(A));
assert(getOrigAlign() == A && "bitfield overflow");
}
Modified: llvm/trunk/lib/CodeGen/CallingConvLower.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/CallingConvLower.cpp?rev=367822&r1=367821&r2=367822&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/CallingConvLower.cpp (original)
+++ llvm/trunk/lib/CodeGen/CallingConvLower.cpp Mon Aug 5 02:49:09 2019
@@ -32,7 +32,6 @@ CCState::CCState(CallingConv::ID CC, boo
TRI(*MF.getSubtarget().getRegisterInfo()), Locs(locs), Context(C) {
// No stack is used.
StackOffset = 0;
- MaxStackArgAlign = 1;
clearByValRegsInfo();
UsedRegs.resize((TRI.getNumRegs()+31)/32);
@@ -41,20 +40,20 @@ CCState::CCState(CallingConv::ID CC, boo
/// Allocate space on the stack large enough to pass an argument by value.
/// The size and alignment information of the argument is encoded in
/// its parameter attribute.
-void CCState::HandleByVal(unsigned ValNo, MVT ValVT,
- MVT LocVT, CCValAssign::LocInfo LocInfo,
- int MinSize, int MinAlign,
- ISD::ArgFlagsTy ArgFlags) {
- unsigned Align = ArgFlags.getByValAlign();
+void CCState::HandleByVal(unsigned ValNo, MVT ValVT, MVT LocVT,
+ CCValAssign::LocInfo LocInfo, int MinSize,
+ int MinAlignment, ISD::ArgFlagsTy ArgFlags) {
+ llvm::Align MinAlign(MinAlignment);
+ llvm::Align Align(ArgFlags.getByValAlign());
unsigned Size = ArgFlags.getByValSize();
if (MinSize > (int)Size)
Size = MinSize;
- if (MinAlign > (int)Align)
+ if (MinAlign > Align)
Align = MinAlign;
ensureMaxAlignment(Align);
- MF.getSubtarget().getTargetLowering()->HandleByVal(this, Size, Align);
+ MF.getSubtarget().getTargetLowering()->HandleByVal(this, Size, Align.value());
Size = unsigned(alignTo(Size, MinAlign));
- unsigned Offset = AllocateStack(Size, Align);
+ unsigned Offset = AllocateStack(Size, Align.value());
addLoc(CCValAssign::getMem(ValNo, ValVT, Offset, LocVT, LocInfo));
}
@@ -209,7 +208,7 @@ static bool isValueTypeInRegForCC(Callin
void CCState::getRemainingRegParmsForType(SmallVectorImpl<MCPhysReg> &Regs,
MVT VT, CCAssignFn Fn) {
unsigned SavedStackOffset = StackOffset;
- unsigned SavedMaxStackArgAlign = MaxStackArgAlign;
+ llvm::Align SavedMaxStackArgAlign = MaxStackArgAlign;
unsigned NumLocs = Locs.size();
// Set the 'inreg' flag if it is used for this calling convention.
More information about the llvm-commits
mailing list