diff --git a/llvm/include/llvm/CodeGen/GlobalISel/Utils.h b/llvm/include/llvm/CodeGen/GlobalISel/Utils.h index 1a592b6e576f48..5bb36ad0a477bc 100644 --- a/llvm/include/llvm/CodeGen/GlobalISel/Utils.h +++ b/llvm/include/llvm/CodeGen/GlobalISel/Utils.h @@ -41,6 +41,7 @@ class TargetLowering; class TargetPassConfig; class TargetRegisterInfo; class TargetRegisterClass; +class ConstantInt; class ConstantFP; class APFloat; @@ -189,6 +190,8 @@ getConstantVRegValWithLookThrough(Register VReg, const MachineRegisterInfo &MRI, bool LookThroughInstrs = true, bool HandleFConstants = true, bool LookThroughAnyExt = false); +const ConstantInt *getConstantIntVRegVal(Register VReg, + const MachineRegisterInfo &MRI); const ConstantFP* getConstantFPVRegVal(Register VReg, const MachineRegisterInfo &MRI); diff --git a/llvm/lib/CodeGen/GlobalISel/Utils.cpp b/llvm/lib/CodeGen/GlobalISel/Utils.cpp index 0b89ae4903b1e9..b8dc131664ee04 100644 --- a/llvm/lib/CodeGen/GlobalISel/Utils.cpp +++ b/llvm/lib/CodeGen/GlobalISel/Utils.cpp @@ -365,6 +365,14 @@ Optional llvm::getConstantVRegValWithLookThrough( return ValueAndVReg{Val, VReg}; } +const ConstantInt *llvm::getConstantIntVRegVal(Register VReg, + const MachineRegisterInfo &MRI) { + MachineInstr *MI = MRI.getVRegDef(VReg); + if (MI->getOpcode() != TargetOpcode::G_CONSTANT) + return nullptr; + return MI->getOperand(1).getCImm(); +} + const ConstantFP * llvm::getConstantFPVRegVal(Register VReg, const MachineRegisterInfo &MRI) { MachineInstr *MI = MRI.getVRegDef(VReg);