[llvm] [GISel] Return const APInt & from getIConstantFromReg. NFC (PR #114320)

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 30 15:56:25 PDT 2024


https://github.com/topperc created https://github.com/llvm/llvm-project/pull/114320

This matches what the call to ConstantInt::getValue returns. Let the caller make a copy if needed.

>From 4ea5ac1e2e7af28f3236eab65e79089ba0011ac9 Mon Sep 17 00:00:00 2001
From: Craig Topper <craig.topper at sifive.com>
Date: Wed, 30 Oct 2024 15:54:07 -0700
Subject: [PATCH] [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 4016247376c4f6..37653631cc2388 100644
--- a/llvm/include/llvm/CodeGen/GlobalISel/Utils.h
+++ b/llvm/include/llvm/CodeGen/GlobalISel/Utils.h
@@ -180,7 +180,7 @@ std::optional<int64_t> 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 dcbbb0871a8445..549cba02bbdd6f 100644
--- a/llvm/lib/CodeGen/GlobalISel/Utils.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/Utils.cpp
@@ -287,7 +287,7 @@ std::optional<APInt> 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");



More information about the llvm-commits mailing list