[PATCH] D99733: [GlobalISel]: Add a getConstantIntVRegVal utility
Petar Avramovic via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 1 08:02:54 PDT 2021
Petar.Avramovic created this revision.
Petar.Avramovic added reviewers: foad, arsenm.
Herald added subscribers: hiraditya, rovka.
Petar.Avramovic requested review of this revision.
Herald added subscribers: llvm-commits, wdng.
Herald added a project: LLVM.
Returns ConstantInt from G_CONSTANT instruction given its def register.
https://reviews.llvm.org/D99733
Files:
llvm/include/llvm/CodeGen/GlobalISel/Utils.h
llvm/lib/CodeGen/GlobalISel/Utils.cpp
Index: llvm/lib/CodeGen/GlobalISel/Utils.cpp
===================================================================
--- llvm/lib/CodeGen/GlobalISel/Utils.cpp
+++ llvm/lib/CodeGen/GlobalISel/Utils.cpp
@@ -365,6 +365,14 @@
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);
Index: llvm/include/llvm/CodeGen/GlobalISel/Utils.h
===================================================================
--- llvm/include/llvm/CodeGen/GlobalISel/Utils.h
+++ llvm/include/llvm/CodeGen/GlobalISel/Utils.h
@@ -41,6 +41,7 @@
class TargetPassConfig;
class TargetRegisterInfo;
class TargetRegisterClass;
+class ConstantInt;
class ConstantFP;
class APFloat;
@@ -189,6 +190,8 @@
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);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D99733.334700.patch
Type: text/x-patch
Size: 1559 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210401/4d1d5a6a/attachment.bin>
More information about the llvm-commits
mailing list