From 4ea5ac1e2e7af28f3236eab65e79089ba0011ac9 Mon Sep 17 00:00:00 2001 From: Craig Topper Date: Wed, 30 Oct 2024 15:54:07 -0700 Subject: [PATCH 1/2] [GISel] Return const APInt & from getIConstantFromReg. NFC This matches what the call to ConstantInt::getValue returns. Let the caller make a copy if needed. --- llvm/include/llvm/CodeGen/GlobalISel/Utils.h | 2 +- llvm/lib/CodeGen/GlobalISel/Utils.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/llvm/include/llvm/CodeGen/GlobalISel/Utils.h b/llvm/include/llvm/CodeGen/GlobalISel/Utils.h index 4016247376c4f..37653631cc238 100644 --- a/llvm/include/llvm/CodeGen/GlobalISel/Utils.h +++ b/llvm/include/llvm/CodeGen/GlobalISel/Utils.h @@ -180,7 +180,7 @@ std::optional getIConstantVRegSExtVal(Register VReg, const MachineRegisterInfo &MRI); /// \p VReg is defined by a G_CONSTANT, return the corresponding value. -APInt getIConstantFromReg(Register VReg, const MachineRegisterInfo &MRI); +const APInt &getIConstantFromReg(Register VReg, const MachineRegisterInfo &MRI); /// Simple struct used to hold a constant integer value and a virtual /// register. diff --git a/llvm/lib/CodeGen/GlobalISel/Utils.cpp b/llvm/lib/CodeGen/GlobalISel/Utils.cpp index dcbbb0871a844..549cba02bbdd6 100644 --- a/llvm/lib/CodeGen/GlobalISel/Utils.cpp +++ b/llvm/lib/CodeGen/GlobalISel/Utils.cpp @@ -287,7 +287,7 @@ std::optional llvm::getIConstantVRegVal(Register VReg, return ValAndVReg->Value; } -APInt llvm::getIConstantFromReg(Register Reg, const MachineRegisterInfo &MRI) { +const APInt &llvm::getIConstantFromReg(Register Reg, const MachineRegisterInfo &MRI) { MachineInstr *Const = MRI.getVRegDef(Reg); assert((Const && Const->getOpcode() == TargetOpcode::G_CONSTANT) && "expected a G_CONSTANT on Reg"); From 578866d42746c6ce886b480e8f1ae70cc6caeaf9 Mon Sep 17 00:00:00 2001 From: Craig Topper Date: Wed, 30 Oct 2024 16:02:27 -0700 Subject: [PATCH 2/2] fixup! clang-format --- llvm/lib/CodeGen/GlobalISel/Utils.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/llvm/lib/CodeGen/GlobalISel/Utils.cpp b/llvm/lib/CodeGen/GlobalISel/Utils.cpp index 549cba02bbdd6..5cee07461d7e2 100644 --- a/llvm/lib/CodeGen/GlobalISel/Utils.cpp +++ b/llvm/lib/CodeGen/GlobalISel/Utils.cpp @@ -287,7 +287,8 @@ std::optional llvm::getIConstantVRegVal(Register VReg, return ValAndVReg->Value; } -const APInt &llvm::getIConstantFromReg(Register Reg, const MachineRegisterInfo &MRI) { +const APInt &llvm::getIConstantFromReg(Register Reg, + const MachineRegisterInfo &MRI) { MachineInstr *Const = MRI.getVRegDef(Reg); assert((Const && Const->getOpcode() == TargetOpcode::G_CONSTANT) && "expected a G_CONSTANT on Reg");