[llvm] r268291 - [LVI] Add an API to LazyValueInfo so that it can export ConstantRanges

John Regehr via llvm-commits llvm-commits at lists.llvm.org
Mon May 2 12:58:01 PDT 2016


Author: regehr
Date: Mon May  2 14:58:00 2016
New Revision: 268291

URL: http://llvm.org/viewvc/llvm-project?rev=268291&view=rev
Log:

[LVI] Add an API to LazyValueInfo so that it can export ConstantRanges
that it computes. Currently this is used for testing and precision
tuning, but it might be used by optimizations later.

Differential Revision: http://reviews.llvm.org/D19179


Modified:
    llvm/trunk/include/llvm/Analysis/LazyValueInfo.h
    llvm/trunk/lib/Analysis/LazyValueInfo.cpp

Modified: llvm/trunk/include/llvm/Analysis/LazyValueInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/LazyValueInfo.h?rev=268291&r1=268290&r2=268291&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Analysis/LazyValueInfo.h (original)
+++ llvm/trunk/include/llvm/Analysis/LazyValueInfo.h Mon May  2 14:58:00 2016
@@ -20,6 +20,7 @@
 namespace llvm {
   class AssumptionCache;
   class Constant;
+  class ConstantRange;
   class DataLayout;
   class DominatorTree;
   class Instruction;
@@ -65,6 +66,11 @@ public:
   /// constant at the end of the specified block.  Return null if not.
   Constant *getConstant(Value *V, BasicBlock *BB, Instruction *CxtI = nullptr);
 
+  /// Return the ConstantRange constraint that is known to hold for the
+  /// specified value at the end of the specified block. This may only be called
+  /// on integer-typed Values.
+  ConstantRange getConstantRange(Value *V, BasicBlock *BB, Instruction *CxtI = nullptr);
+
   /// Determine whether the specified value is known to be a
   /// constant on the specified edge.  Return null if not.
   Constant *getConstantOnEdge(Value *V, BasicBlock *FromBB, BasicBlock *ToBB,

Modified: llvm/trunk/lib/Analysis/LazyValueInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/LazyValueInfo.cpp?rev=268291&r1=268290&r2=268291&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/LazyValueInfo.cpp (original)
+++ llvm/trunk/lib/Analysis/LazyValueInfo.cpp Mon May  2 14:58:00 2016
@@ -1485,6 +1485,22 @@ Constant *LazyValueInfo::getConstant(Val
   return nullptr;
 }
 
+ConstantRange LazyValueInfo::getConstantRange(Value *V, BasicBlock *BB,
+					      Instruction *CxtI) {
+  assert(V->getType()->isIntegerTy());
+  unsigned Width = V->getType()->getIntegerBitWidth();
+  const DataLayout &DL = BB->getModule()->getDataLayout();
+  LVILatticeVal Result =
+      getCache(PImpl, AC, &DL, DT).getValueInBlock(V, BB, CxtI);
+  assert(!Result.isConstant());
+  if (Result.isUndefined())
+    return ConstantRange(Width, /*isFullSet=*/false);
+  if (Result.isConstantRange())
+    return Result.getConstantRange();
+  else
+    return ConstantRange(Width, /*isFullSet=*/true);
+}
+
 /// Determine whether the specified value is known to be a
 /// constant on the specified edge. Return null if not.
 Constant *LazyValueInfo::getConstantOnEdge(Value *V, BasicBlock *FromBB,




More information about the llvm-commits mailing list