OSDN Git Service

[LVI] Add an API to LazyValueInfo so that it can export ConstantRanges
authorJohn Regehr <regehr@cs.utah.edu>
Mon, 2 May 2016 19:58:00 +0000 (19:58 +0000)
committerJohn Regehr <regehr@cs.utah.edu>
Mon, 2 May 2016 19:58:00 +0000 (19:58 +0000)
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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@268291 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Analysis/LazyValueInfo.h
lib/Analysis/LazyValueInfo.cpp

index 4200206..b51237e 100644 (file)
@@ -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,
index cb1ad5e..cb26da5 100644 (file)
@@ -1485,6 +1485,22 @@ Constant *LazyValueInfo::getConstant(Value *V, BasicBlock *BB,
   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,