[llvm] r245329 - MachineRegisterInfo: Introduce isPhysRegUsed()

James Y Knight via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 19 07:53:07 PDT 2015


What about the other code which was converted to use reg_nodbg_empty in
r242173? Shouldn't it also be moved back to isPhysRegUsed now?

On Tue, Aug 18, 2015 at 2:54 PM, Matthias Braun via llvm-commits <
llvm-commits at lists.llvm.org> wrote:

> Author: matze
> Date: Tue Aug 18 13:54:27 2015
> New Revision: 245329
>
> URL: http://llvm.org/viewvc/llvm-project?rev=245329&view=rev
> Log:
> MachineRegisterInfo: Introduce isPhysRegUsed()
>
> This method checks whether a physical regiser or any of its aliases are
> used in the function.
>
> Using this function in SIRegisterInfo::findUnusedReg() should also fix
> this reported failure:
>
>
> http://lists.llvm.org/pipermail/llvm-commits/Week-of-Mon-20150803/292143.html
> http://reviews.llvm.org/rL242173#inline-533
>
> The report doesn't come with a testcase and I don't know enough about
> AMDGPU to create one myself.
>
> Modified:
>     llvm/trunk/include/llvm/CodeGen/MachineRegisterInfo.h
>     llvm/trunk/lib/CodeGen/ExecutionDepsFix.cpp
>     llvm/trunk/lib/CodeGen/MachineRegisterInfo.cpp
>     llvm/trunk/lib/Target/AMDGPU/SIRegisterInfo.cpp
>
> Modified: llvm/trunk/include/llvm/CodeGen/MachineRegisterInfo.h
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/MachineRegisterInfo.h?rev=245329&r1=245328&r2=245329&view=diff
>
> ==============================================================================
> --- llvm/trunk/include/llvm/CodeGen/MachineRegisterInfo.h (original)
> +++ llvm/trunk/include/llvm/CodeGen/MachineRegisterInfo.h Tue Aug 18
> 13:54:27 2015
> @@ -644,9 +644,16 @@ public:
>    /// Return true if the specified register is modified in this function.
>    /// This checks that no defining machine operands exist for the
> register or
>    /// any of its aliases. Definitions found on functions marked noreturn
> are
> -  /// ignored.
> +  /// ignored. The register is also considered modified when it is set in
> the
> +  /// UsedPhysRegMask.
>    bool isPhysRegModified(unsigned PhysReg) const;
>
> +  /// Return true if the specified register is modified or read in this
> +  /// function. This checks that no machine operands exist for the
> register or
> +  /// any of its aliases. The register is also considered used when it is
> set
> +  /// in the UsedPhysRegMask.
> +  bool isPhysRegUsed(unsigned PhysReg) const;
> +
>    /// addPhysRegsUsedFromRegMask - Mark any registers not in RegMask as
> used.
>    /// This corresponds to the bit mask attached to register mask operands.
>    void addPhysRegsUsedFromRegMask(const uint32_t *RegMask) {
>
> Modified: llvm/trunk/lib/CodeGen/ExecutionDepsFix.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/ExecutionDepsFix.cpp?rev=245329&r1=245328&r2=245329&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/CodeGen/ExecutionDepsFix.cpp (original)
> +++ llvm/trunk/lib/CodeGen/ExecutionDepsFix.cpp Tue Aug 18 13:54:27 2015
> @@ -733,13 +733,12 @@ bool ExeDepsFix::runOnMachineFunction(Ma
>    // completely.
>    bool anyregs = false;
>    const MachineRegisterInfo &MRI = mf.getRegInfo();
> -  for (TargetRegisterClass::const_iterator I = RC->begin(), E = RC->end();
> -       I != E && !anyregs; ++I)
> -    for (MCRegAliasIterator AI(*I, TRI, true); AI.isValid(); ++AI)
> -      if (!MRI.reg_nodbg_empty(*AI)) {
> -        anyregs = true;
> -        break;
> -      }
> +  for (unsigned Reg : *RC) {
> +    if (MRI.isPhysRegUsed(Reg)) {
> +      anyregs = true;
> +      break;
> +    }
> +  }
>    if (!anyregs) return false;
>
>    // Initialize the AliasMap on the first use.
>
> Modified: llvm/trunk/lib/CodeGen/MachineRegisterInfo.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineRegisterInfo.cpp?rev=245329&r1=245328&r2=245329&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/CodeGen/MachineRegisterInfo.cpp (original)
> +++ llvm/trunk/lib/CodeGen/MachineRegisterInfo.cpp Tue Aug 18 13:54:27 2015
> @@ -489,3 +489,15 @@ bool MachineRegisterInfo::isPhysRegModif
>    }
>    return false;
>  }
> +
> +bool MachineRegisterInfo::isPhysRegUsed(unsigned PhysReg) const {
> +  if (UsedPhysRegMask.test(PhysReg))
> +    return true;
> +  const TargetRegisterInfo *TRI = getTargetRegisterInfo();
> +  for (MCRegAliasIterator AliasReg(PhysReg, TRI, true);
> AliasReg.isValid();
> +       ++AliasReg) {
> +    if (!reg_nodbg_empty(*AliasReg))
> +      return true;
> +  }
> +  return false;
> +}
>
> Modified: llvm/trunk/lib/Target/AMDGPU/SIRegisterInfo.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/AMDGPU/SIRegisterInfo.cpp?rev=245329&r1=245328&r2=245329&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/Target/AMDGPU/SIRegisterInfo.cpp (original)
> +++ llvm/trunk/lib/Target/AMDGPU/SIRegisterInfo.cpp Tue Aug 18 13:54:27
> 2015
> @@ -495,12 +495,9 @@ unsigned SIRegisterInfo::getPreloadedVal
>  //         AMDGPU::NoRegister.
>  unsigned SIRegisterInfo::findUnusedRegister(const MachineRegisterInfo
> &MRI,
>                                             const TargetRegisterClass *RC)
> const {
> -
> -  for (TargetRegisterClass::iterator I = RC->begin(), E = RC->end();
> -       I != E; ++I) {
> -    if (MRI.reg_nodbg_empty(*I))
> -      return *I;
> -  }
> +  for (unsigned Reg : *RC)
> +    if (!MRI.isPhysRegUsed(Reg))
> +      return Reg;
>    return AMDGPU::NoRegister;
>  }
>
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150819/a49e33cd/attachment.html>


More information about the llvm-commits mailing list