diff options
author | Guillaume Chatelet <gchatelet@google.com> | 2019-08-05 09:49:09 +0000 |
---|---|---|
committer | Guillaume Chatelet <gchatelet@google.com> | 2019-08-05 09:49:09 +0000 |
commit | 6c5fb61f8bcc4323a5f128a748e12bfc51b185a4 (patch) | |
tree | 67c8203d60f71b6426e2b8cd56814f520da48254 | |
parent | e204786b6cc968bfe725b21241c00228d1159e75 (diff) | |
download | bcm5719-llvm-6c5fb61f8bcc4323a5f128a748e12bfc51b185a4.tar.gz bcm5719-llvm-6c5fb61f8bcc4323a5f128a748e12bfc51b185a4.zip |
[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
llvm-svn: 367822
-rw-r--r-- | llvm/include/llvm/CodeGen/CallingConvLower.h | 11 | ||||
-rw-r--r-- | llvm/include/llvm/CodeGen/TargetCallingConv.h | 15 | ||||
-rw-r--r-- | llvm/lib/CodeGen/CallingConvLower.cpp | 19 |
3 files changed, 26 insertions, 19 deletions
diff --git a/llvm/include/llvm/CodeGen/CallingConvLower.h b/llvm/include/llvm/CodeGen/CallingConvLower.h index aa339e1cc91..e0b05751b3b 100644 --- a/llvm/include/llvm/CodeGen/CallingConvLower.h +++ b/llvm/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<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. diff --git a/llvm/include/llvm/CodeGen/TargetCallingConv.h b/llvm/include/llvm/CodeGen/TargetCallingConv.h index aebeeecbe50..d25a9a24591 100644 --- a/llvm/include/llvm/CodeGen/TargetCallingConv.h +++ b/llvm/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 <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"); } diff --git a/llvm/lib/CodeGen/CallingConvLower.cpp b/llvm/lib/CodeGen/CallingConvLower.cpp index 497fcb14784..92da621fabb 100644 --- a/llvm/lib/CodeGen/CallingConvLower.cpp +++ b/llvm/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<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. |