[PATCH] D33051: [GISel]: Add a getConstantFPVRegVal utility

Aditya Nandakumar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed May 10 09:43:10 PDT 2017


aditya_nandakumar created this revision.

This might be useful across various GISel passes.


Repository:
  rL LLVM

https://reviews.llvm.org/D33051

Files:
  include/llvm/CodeGen/GlobalISel/Utils.h
  lib/CodeGen/GlobalISel/Utils.cpp


Index: lib/CodeGen/GlobalISel/Utils.cpp
===================================================================
--- lib/CodeGen/GlobalISel/Utils.cpp
+++ lib/CodeGen/GlobalISel/Utils.cpp
@@ -110,3 +110,11 @@
 
   return None;
 }
+
+const llvm::ConstantFP* llvm::getConstantFPVRegVal(unsigned VReg,
+                                       const MachineRegisterInfo &MRI) {
+  MachineInstr *MI = MRI.getVRegDef(VReg);
+  if (TargetOpcode::G_FCONSTANT != MI->getOpcode())
+    return nullptr;
+  return MI->getOperand(1).getFPImm();
+}
Index: include/llvm/CodeGen/GlobalISel/Utils.h
===================================================================
--- include/llvm/CodeGen/GlobalISel/Utils.h
+++ include/llvm/CodeGen/GlobalISel/Utils.h
@@ -30,6 +30,7 @@
 class TargetPassConfig;
 class TargetRegisterInfo;
 class Twine;
+class ConstantFP;
 
 /// Try to constrain Reg so that it is usable by argument OpIdx of the
 /// provided MCInstrDesc \p II. If this fails, create a new virtual
@@ -62,6 +63,8 @@
 
 Optional<int64_t> getConstantVRegVal(unsigned VReg,
                                      const MachineRegisterInfo &MRI);
+const ConstantFP* getConstantFPVRegVal(unsigned VReg,
+                                       const MachineRegisterInfo &MRI);
 
 } // End namespace llvm.
 #endif


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D33051.98480.patch
Type: text/x-patch
Size: 1285 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170510/c302893b/attachment.bin>


More information about the llvm-commits mailing list