[llvm] r318350 - [GISel][NFC]: Move getOpcodeDef from the LegalizationArtifactCombiner into GlobalISel/Utils for use elsewhere
Aditya Nandakumar via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 15 15:45:04 PST 2017
Author: aditya_nandakumar
Date: Wed Nov 15 15:45:04 2017
New Revision: 318350
URL: http://llvm.org/viewvc/llvm-project?rev=318350&view=rev
Log:
[GISel][NFC]: Move getOpcodeDef from the LegalizationArtifactCombiner into GlobalISel/Utils for use elsewhere
Modified:
llvm/trunk/include/llvm/CodeGen/GlobalISel/LegalizationArtifactCombiner.h
llvm/trunk/include/llvm/CodeGen/GlobalISel/Utils.h
llvm/trunk/lib/CodeGen/GlobalISel/Utils.cpp
Modified: llvm/trunk/include/llvm/CodeGen/GlobalISel/LegalizationArtifactCombiner.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/GlobalISel/LegalizationArtifactCombiner.h?rev=318350&r1=318349&r2=318350&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/GlobalISel/LegalizationArtifactCombiner.h (original)
+++ llvm/trunk/include/llvm/CodeGen/GlobalISel/LegalizationArtifactCombiner.h Wed Nov 15 15:45:04 2017
@@ -36,8 +36,8 @@ public:
SmallVectorImpl<MachineInstr *> &DeadInsts) {
if (MI.getOpcode() != TargetOpcode::G_ANYEXT)
return false;
- if (MachineInstr *DefMI =
- getOpcodeDef(TargetOpcode::G_TRUNC, MI.getOperand(1).getReg())) {
+ if (MachineInstr *DefMI = getOpcodeDef(TargetOpcode::G_TRUNC,
+ MI.getOperand(1).getReg(), MRI)) {
DEBUG(dbgs() << ".. Combine MI: " << MI;);
unsigned DstReg = MI.getOperand(0).getReg();
unsigned SrcReg = DefMI->getOperand(1).getReg();
@@ -55,8 +55,8 @@ public:
if (MI.getOpcode() != TargetOpcode::G_ZEXT)
return false;
- if (MachineInstr *DefMI =
- getOpcodeDef(TargetOpcode::G_TRUNC, MI.getOperand(1).getReg())) {
+ if (MachineInstr *DefMI = getOpcodeDef(TargetOpcode::G_TRUNC,
+ MI.getOperand(1).getReg(), MRI)) {
unsigned DstReg = MI.getOperand(0).getReg();
LLT DstTy = MRI.getType(DstReg);
if (isInstUnsupported(TargetOpcode::G_AND, DstTy) ||
@@ -83,8 +83,8 @@ public:
if (MI.getOpcode() != TargetOpcode::G_SEXT)
return false;
- if (MachineInstr *DefMI =
- getOpcodeDef(TargetOpcode::G_TRUNC, MI.getOperand(1).getReg())) {
+ if (MachineInstr *DefMI = getOpcodeDef(TargetOpcode::G_TRUNC,
+ MI.getOperand(1).getReg(), MRI)) {
unsigned DstReg = MI.getOperand(0).getReg();
LLT DstTy = MRI.getType(DstReg);
if (isInstUnsupported(TargetOpcode::G_SHL, DstTy) ||
@@ -118,7 +118,7 @@ public:
return false;
if (MachineInstr *DefMI = getOpcodeDef(TargetOpcode::G_IMPLICIT_DEF,
- MI.getOperand(1).getReg())) {
+ MI.getOperand(1).getReg(), MRI)) {
unsigned DstReg = MI.getOperand(0).getReg();
LLT DstTy = MRI.getType(DstReg);
if (isInstUnsupported(TargetOpcode::G_IMPLICIT_DEF, DstTy))
@@ -248,23 +248,6 @@ private:
return Action.first == LegalizerInfo::LegalizeAction::Unsupported ||
Action.first == LegalizerInfo::LegalizeAction::NotFound;
}
- /// See if Reg is defined by an single def instruction that is
- /// Opcode. Also try to do trivial folding if it's a COPY with
- /// same types. Returns null otherwise.
- MachineInstr *getOpcodeDef(unsigned Opcode, unsigned Reg) {
- auto *DefMI = MRI.getVRegDef(Reg);
- auto DstTy = MRI.getType(DefMI->getOperand(0).getReg());
- if (!DstTy.isValid())
- return nullptr;
- while (DefMI->getOpcode() == TargetOpcode::COPY) {
- unsigned SrcReg = DefMI->getOperand(1).getReg();
- auto SrcTy = MRI.getType(SrcReg);
- if (!SrcTy.isValid() || SrcTy != DstTy)
- break;
- DefMI = MRI.getVRegDef(SrcReg);
- }
- return DefMI->getOpcode() == Opcode ? DefMI : nullptr;
- }
};
} // namespace llvm
Modified: llvm/trunk/include/llvm/CodeGen/GlobalISel/Utils.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/GlobalISel/Utils.h?rev=318350&r1=318349&r2=318350&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/GlobalISel/Utils.h (original)
+++ llvm/trunk/include/llvm/CodeGen/GlobalISel/Utils.h Wed Nov 15 15:45:04 2017
@@ -79,5 +79,11 @@ Optional<int64_t> getConstantVRegVal(uns
const ConstantFP* getConstantFPVRegVal(unsigned VReg,
const MachineRegisterInfo &MRI);
+/// See if Reg is defined by an single def instruction that is
+/// Opcode. Also try to do trivial folding if it's a COPY with
+/// same types. Returns null otherwise.
+MachineInstr *getOpcodeDef(unsigned Opcode, unsigned Reg,
+ const MachineRegisterInfo &MRI);
+
} // End namespace llvm.
#endif
Modified: llvm/trunk/lib/CodeGen/GlobalISel/Utils.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/GlobalISel/Utils.cpp?rev=318350&r1=318349&r2=318350&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/GlobalISel/Utils.cpp (original)
+++ llvm/trunk/lib/CodeGen/GlobalISel/Utils.cpp Wed Nov 15 15:45:04 2017
@@ -129,3 +129,19 @@ const llvm::ConstantFP* llvm::getConstan
return nullptr;
return MI->getOperand(1).getFPImm();
}
+
+llvm::MachineInstr *llvm::getOpcodeDef(unsigned Opcode, unsigned Reg,
+ const MachineRegisterInfo &MRI) {
+ auto *DefMI = MRI.getVRegDef(Reg);
+ auto DstTy = MRI.getType(DefMI->getOperand(0).getReg());
+ if (!DstTy.isValid())
+ return nullptr;
+ while (DefMI->getOpcode() == TargetOpcode::COPY) {
+ unsigned SrcReg = DefMI->getOperand(1).getReg();
+ auto SrcTy = MRI.getType(SrcReg);
+ if (!SrcTy.isValid() || SrcTy != DstTy)
+ break;
+ DefMI = MRI.getVRegDef(SrcReg);
+ }
+ return DefMI->getOpcode() == Opcode ? DefMI : nullptr;
+}
More information about the llvm-commits
mailing list