Author: Chen Zheng Date: 2021-01-21T20:10:25-05:00 New Revision: 8120cfedf55ade13a0a1a4a4629911aa2f8ed9c3
URL: https://github.com/llvm/llvm-project/commit/8120cfedf55ade13a0a1a4a4629911aa2f8ed9c3 DIFF: https://github.com/llvm/llvm-project/commit/8120cfedf55ade13a0a1a4a4629911aa2f8ed9c3.diff LOG: [NFC] [TargetRegisterInfo] add another API to get srcreg through copy. Reviewed By: nemanjai, jsji Differential Revision: https://reviews.llvm.org/D92069 Added: Modified: llvm/include/llvm/CodeGen/TargetRegisterInfo.h llvm/lib/CodeGen/TargetRegisterInfo.cpp Removed: ################################################################################ diff --git a/llvm/include/llvm/CodeGen/TargetRegisterInfo.h b/llvm/include/llvm/CodeGen/TargetRegisterInfo.h index 6f32729a1e83..253f71cb5f1a 100644 --- a/llvm/include/llvm/CodeGen/TargetRegisterInfo.h +++ b/llvm/include/llvm/CodeGen/TargetRegisterInfo.h @@ -415,6 +415,16 @@ class TargetRegisterInfo : public MCRegisterInfo { virtual Register lookThruCopyLike(Register SrcReg, const MachineRegisterInfo *MRI) const; + /// Find the original SrcReg unless it is the target of a copy-like operation, + /// in which case we chain backwards through all such operations to the + /// ultimate source register. If a physical register is encountered, we stop + /// the search. + /// Return the original SrcReg if all the definitions in the chain only have + /// one user and not a physical register. + virtual Register + lookThruSingleUseCopyChain(Register SrcReg, + const MachineRegisterInfo *MRI) const; + /// Return a null-terminated list of all of the callee-saved registers on /// this target. The register should be in the order of desired callee-save /// stack frame offset. The first register is closest to the incoming stack diff --git a/llvm/lib/CodeGen/TargetRegisterInfo.cpp b/llvm/lib/CodeGen/TargetRegisterInfo.cpp index 4a190c9f50af..5fd7eef5808f 100644 --- a/llvm/lib/CodeGen/TargetRegisterInfo.cpp +++ b/llvm/lib/CodeGen/TargetRegisterInfo.cpp @@ -533,6 +533,31 @@ TargetRegisterInfo::lookThruCopyLike(Register SrcReg, } } +Register TargetRegisterInfo::lookThruSingleUseCopyChain( + Register SrcReg, const MachineRegisterInfo *MRI) const { + while (true) { + const MachineInstr *MI = MRI->getVRegDef(SrcReg); + // Found the real definition, return it if it has a single use. + if (!MI->isCopyLike()) + return MRI->hasOneNonDBGUse(SrcReg) ? SrcReg : Register(); + + Register CopySrcReg; + if (MI->isCopy()) + CopySrcReg = MI->getOperand(1).getReg(); + else { + assert(MI->isSubregToReg() && "Bad opcode for lookThruCopyLike"); + CopySrcReg = MI->getOperand(2).getReg(); + } + + // Continue only if the next definition in the chain is for a virtual + // register that has a single use. + if (!CopySrcReg.isVirtual() || !MRI->hasOneNonDBGUse(CopySrcReg)) + return Register(); + + SrcReg = CopySrcReg; + } +} + void TargetRegisterInfo::getOffsetOpcodes( const StackOffset &Offset, SmallVectorImpl<uint64_t> &Ops) const { assert(!Offset.getScalable() && "Scalable offsets are not handled"); _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits