[llvm] r302964 - [GISel]: Add a getConstantFPVRegVal utility

Aditya Nandakumar via llvm-commits llvm-commits at lists.llvm.org
Fri May 12 15:54:53 PDT 2017


Author: aditya_nandakumar
Date: Fri May 12 17:54:52 2017
New Revision: 302964

URL: http://llvm.org/viewvc/llvm-project?rev=302964&view=rev
Log:
[GISel]: Add a getConstantFPVRegVal utility

This might be useful across various GISel Passes

https://reviews.llvm.org/D33051

Modified:
    llvm/trunk/include/llvm/CodeGen/GlobalISel/Utils.h
    llvm/trunk/lib/CodeGen/GlobalISel/Utils.cpp

Modified: llvm/trunk/include/llvm/CodeGen/GlobalISel/Utils.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/GlobalISel/Utils.h?rev=302964&r1=302963&r2=302964&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/GlobalISel/Utils.h (original)
+++ llvm/trunk/include/llvm/CodeGen/GlobalISel/Utils.h Fri May 12 17:54:52 2017
@@ -30,6 +30,7 @@ class TargetInstrInfo;
 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 @@ void reportGISelFailure(MachineFunction
 
 Optional<int64_t> getConstantVRegVal(unsigned VReg,
                                      const MachineRegisterInfo &MRI);
+const ConstantFP* getConstantFPVRegVal(unsigned VReg,
+                                       const MachineRegisterInfo &MRI);
 
 } // End namespace llvm.
 #endif

Modified: llvm/trunk/lib/CodeGen/GlobalISel/Utils.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/GlobalISel/Utils.cpp?rev=302964&r1=302963&r2=302964&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/GlobalISel/Utils.cpp (original)
+++ llvm/trunk/lib/CodeGen/GlobalISel/Utils.cpp Fri May 12 17:54:52 2017
@@ -110,3 +110,11 @@ Optional<int64_t> llvm::getConstantVRegV
 
   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();
+}




More information about the llvm-commits mailing list