From 7a46e36d518868fd77518c9e0dc13786ffb969c5 Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Wed, 8 Apr 2020 10:49:37 -0400 Subject: [PATCH] CodeGen: Use Register more in CallLowering Some of these MCPhysReg uses should probably be MCRegister, but right now this would require more invasive changes. --- llvm/include/llvm/CodeGen/CallingConvLower.h | 36 +++++++++++++++------------- llvm/lib/CodeGen/CallingConvLower.cpp | 6 ++--- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/llvm/include/llvm/CodeGen/CallingConvLower.h b/llvm/include/llvm/CodeGen/CallingConvLower.h index c4ecd84..cdba366 100644 --- a/llvm/include/llvm/CodeGen/CallingConvLower.h +++ b/llvm/include/llvm/CodeGen/CallingConvLower.h @@ -165,9 +165,9 @@ public: /// Describes a register that needs to be forwarded from the prologue to a /// musttail call. struct ForwardedRegister { - ForwardedRegister(unsigned VReg, MCPhysReg PReg, MVT VT) + ForwardedRegister(Register VReg, MCPhysReg PReg, MVT VT) : VReg(VReg), PReg(PReg), VT(VT) {} - unsigned VReg; + Register VReg; MCPhysReg PReg; MVT VT; }; @@ -282,8 +282,8 @@ public: /// isAllocated - Return true if the specified register (or an alias) is /// allocated. - bool isAllocated(unsigned Reg) const { - return UsedRegs[Reg/32] & (1 << (Reg&31)); + bool isAllocated(MCRegister Reg) const { + return UsedRegs[Reg / 32] & (1 << (Reg & 31)); } /// AnalyzeFormalArguments - Analyze an array of argument values, @@ -333,7 +333,7 @@ public: /// A shadow allocated register is a register that was allocated /// but wasn't added to the location list (Locs). /// \returns true if the register was allocated as shadow or false otherwise. - bool IsShadowAllocatedReg(unsigned Reg) const; + bool IsShadowAllocatedReg(MCRegister Reg) const; /// AnalyzeCallResult - Same as above except it's specialized for calls which /// produce a single value. @@ -351,15 +351,17 @@ public: /// AllocateReg - Attempt to allocate one register. If it is not available, /// return zero. Otherwise, return the register, marking it and any aliases /// as allocated. - unsigned AllocateReg(unsigned Reg) { - if (isAllocated(Reg)) return 0; + MCRegister AllocateReg(MCPhysReg Reg) { + if (isAllocated(Reg)) + return MCRegister(); MarkAllocated(Reg); return Reg; } /// Version of AllocateReg with extra register to be shadowed. - unsigned AllocateReg(unsigned Reg, unsigned ShadowReg) { - if (isAllocated(Reg)) return 0; + MCRegister AllocateReg(MCPhysReg Reg, MCPhysReg ShadowReg) { + if (isAllocated(Reg)) + return MCRegister(); MarkAllocated(Reg); MarkAllocated(ShadowReg); return Reg; @@ -368,13 +370,13 @@ public: /// AllocateReg - Attempt to allocate one of the specified registers. If none /// are available, return zero. Otherwise, return the first one available, /// marking it and any aliases as allocated. - unsigned AllocateReg(ArrayRef Regs) { + MCPhysReg AllocateReg(ArrayRef Regs) { unsigned FirstUnalloc = getFirstUnallocated(Regs); if (FirstUnalloc == Regs.size()) - return 0; // Didn't find the reg. + return MCRegister(); // Didn't find the reg. // Mark the register and any aliases as allocated. - unsigned Reg = Regs[FirstUnalloc]; + MCPhysReg Reg = Regs[FirstUnalloc]; MarkAllocated(Reg); return Reg; } @@ -382,7 +384,7 @@ public: /// AllocateRegBlock - Attempt to allocate a block of RegsRequired consecutive /// registers. If this is not possible, return zero. Otherwise, return the first /// register of the block that were allocated, marking the entire block as allocated. - unsigned AllocateRegBlock(ArrayRef Regs, unsigned RegsRequired) { + MCPhysReg AllocateRegBlock(ArrayRef Regs, unsigned RegsRequired) { if (RegsRequired > Regs.size()) return 0; @@ -409,13 +411,13 @@ public: } /// Version of AllocateReg with list of registers to be shadowed. - unsigned AllocateReg(ArrayRef Regs, const MCPhysReg *ShadowRegs) { + MCRegister AllocateReg(ArrayRef Regs, const MCPhysReg *ShadowRegs) { unsigned FirstUnalloc = getFirstUnallocated(Regs); if (FirstUnalloc == Regs.size()) - return 0; // Didn't find the reg. + return MCRegister(); // Didn't find the reg. // Mark the register and any aliases as allocated. - unsigned Reg = Regs[FirstUnalloc], ShadowReg = ShadowRegs[FirstUnalloc]; + MCRegister Reg = Regs[FirstUnalloc], ShadowReg = ShadowRegs[FirstUnalloc]; MarkAllocated(Reg); MarkAllocated(ShadowReg); return Reg; @@ -569,7 +571,7 @@ public: private: /// MarkAllocated - Mark a register and all of its aliases as allocated. - void MarkAllocated(unsigned Reg); + void MarkAllocated(MCPhysReg Reg); }; } // end namespace llvm diff --git a/llvm/lib/CodeGen/CallingConvLower.cpp b/llvm/lib/CodeGen/CallingConvLower.cpp index 4078ece..12c4f1b 100644 --- a/llvm/lib/CodeGen/CallingConvLower.cpp +++ b/llvm/lib/CodeGen/CallingConvLower.cpp @@ -59,12 +59,12 @@ void CCState::HandleByVal(unsigned ValNo, MVT ValVT, MVT LocVT, } /// Mark a register and all of its aliases as allocated. -void CCState::MarkAllocated(unsigned Reg) { +void CCState::MarkAllocated(MCPhysReg Reg) { for (MCRegAliasIterator AI(Reg, &TRI, true); AI.isValid(); ++AI) - UsedRegs[*AI/32] |= 1 << (*AI&31); + UsedRegs[*AI / 32] |= 1 << (*AI & 31); } -bool CCState::IsShadowAllocatedReg(unsigned Reg) const { +bool CCState::IsShadowAllocatedReg(MCRegister Reg) const { if (!isAllocated(Reg)) return false; -- 2.7.4