From dc3af2b9fe44c02028c1b0cae56db11a3e1a6cd8 Mon Sep 17 00:00:00 2001 From: Guillaume Chatelet Date: Mon, 5 Aug 2019 09:49:09 +0000 Subject: [PATCH] [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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@367822 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/CodeGen/CallingConvLower.h | 11 ++++++----- include/llvm/CodeGen/TargetCallingConv.h | 15 +++++++++++---- lib/CodeGen/CallingConvLower.cpp | 19 +++++++++---------- 3 files changed, 26 insertions(+), 19 deletions(-) diff --git a/include/llvm/CodeGen/CallingConvLower.h b/include/llvm/CodeGen/CallingConvLower.h index aa339e1cc91..e0b05751b3b 100644 --- a/include/llvm/CodeGen/CallingConvLower.h +++ b/include/llvm/CodeGen/CallingConvLower.h @@ -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 UsedRegs; SmallVector PendingLocs; SmallVector 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. diff --git a/include/llvm/CodeGen/TargetCallingConv.h b/include/llvm/CodeGen/TargetCallingConv.h index aebeeecbe50..d25a9a24591 100644 --- a/include/llvm/CodeGen/TargetCallingConv.h +++ b/include/llvm/CodeGen/TargetCallingConv.h @@ -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 @@ -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"); } diff --git a/lib/CodeGen/CallingConvLower.cpp b/lib/CodeGen/CallingConvLower.cpp index 497fcb14784..92da621fabb 100644 --- a/lib/CodeGen/CallingConvLower.cpp +++ b/lib/CodeGen/CallingConvLower.cpp @@ -32,7 +32,6 @@ CCState::CCState(CallingConv::ID CC, bool isVarArg, MachineFunction &mf, 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, bool isVarArg, MachineFunction &mf, /// 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(CallingConv::ID CC, MVT VT) { void CCState::getRemainingRegParmsForType(SmallVectorImpl &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. -- 2.11.4.GIT