[llvm] r284865 - Analysis: Move llvm::getConstantRangeFromMetadata to IR library.
Peter Collingbourne via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 21 12:59:26 PDT 2016
Author: pcc
Date: Fri Oct 21 14:59:26 2016
New Revision: 284865
URL: http://llvm.org/viewvc/llvm-project?rev=284865&view=rev
Log:
Analysis: Move llvm::getConstantRangeFromMetadata to IR library.
We're about to start using it there.
Differential Revision: https://reviews.llvm.org/D25877
Modified:
llvm/trunk/include/llvm/Analysis/ValueTracking.h
llvm/trunk/include/llvm/IR/ConstantRange.h
llvm/trunk/lib/Analysis/ValueTracking.cpp
llvm/trunk/lib/IR/ConstantRange.cpp
llvm/trunk/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
llvm/trunk/lib/Transforms/Scalar/GuardWidening.cpp
Modified: llvm/trunk/include/llvm/Analysis/ValueTracking.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/ValueTracking.h?rev=284865&r1=284864&r2=284865&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Analysis/ValueTracking.h (original)
+++ llvm/trunk/include/llvm/Analysis/ValueTracking.h Fri Oct 21 14:59:26 2016
@@ -16,7 +16,6 @@
#define LLVM_ANALYSIS_VALUETRACKING_H
#include "llvm/IR/CallSite.h"
-#include "llvm/IR/ConstantRange.h"
#include "llvm/IR/Instruction.h"
#include "llvm/IR/IntrinsicInst.h"
#include "llvm/Support/DataTypes.h"
@@ -462,11 +461,6 @@ template <typename T> class ArrayRef;
return Result;
}
- /// Parse out a conservative ConstantRange from !range metadata.
- ///
- /// E.g. if RangeMD is !{i32 0, i32 10, i32 15, i32 20} then return [0, 20).
- ConstantRange getConstantRangeFromMetadata(const MDNode &RangeMD);
-
/// Return true if RHS is known to be implied true by LHS. Return false if
/// RHS is known to be implied false by LHS. Otherwise, return None if no
/// implication can be made.
Modified: llvm/trunk/include/llvm/IR/ConstantRange.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/ConstantRange.h?rev=284865&r1=284864&r2=284865&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/ConstantRange.h (original)
+++ llvm/trunk/include/llvm/IR/ConstantRange.h Fri Oct 21 14:59:26 2016
@@ -38,6 +38,8 @@
namespace llvm {
+class MDNode;
+
/// This class represents a range of values.
///
class ConstantRange {
@@ -330,6 +332,11 @@ inline raw_ostream &operator<<(raw_ostre
return OS;
}
+/// Parse out a conservative ConstantRange from !range metadata.
+///
+/// E.g. if RangeMD is !{i32 0, i32 10, i32 15, i32 20} then return [0, 20).
+ConstantRange getConstantRangeFromMetadata(const MDNode &RangeMD);
+
} // End llvm namespace
#endif
Modified: llvm/trunk/lib/Analysis/ValueTracking.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ValueTracking.cpp?rev=284865&r1=284864&r2=284865&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/ValueTracking.cpp (original)
+++ llvm/trunk/lib/Analysis/ValueTracking.cpp Fri Oct 21 14:59:26 2016
@@ -4082,28 +4082,6 @@ SelectPatternResult llvm::matchSelectPat
LHS, RHS);
}
-ConstantRange llvm::getConstantRangeFromMetadata(const MDNode &Ranges) {
- const unsigned NumRanges = Ranges.getNumOperands() / 2;
- assert(NumRanges >= 1 && "Must have at least one range!");
- assert(Ranges.getNumOperands() % 2 == 0 && "Must be a sequence of pairs");
-
- auto *FirstLow = mdconst::extract<ConstantInt>(Ranges.getOperand(0));
- auto *FirstHigh = mdconst::extract<ConstantInt>(Ranges.getOperand(1));
-
- ConstantRange CR(FirstLow->getValue(), FirstHigh->getValue());
-
- for (unsigned i = 1; i < NumRanges; ++i) {
- auto *Low = mdconst::extract<ConstantInt>(Ranges.getOperand(2 * i + 0));
- auto *High = mdconst::extract<ConstantInt>(Ranges.getOperand(2 * i + 1));
-
- // Note: unionWith will potentially create a range that contains values not
- // contained in any of the original N ranges.
- CR = CR.unionWith(ConstantRange(Low->getValue(), High->getValue()));
- }
-
- return CR;
-}
-
/// Return true if "icmp Pred LHS RHS" is always true.
static bool isTruePredicate(CmpInst::Predicate Pred,
const Value *LHS, const Value *RHS,
Modified: llvm/trunk/lib/IR/ConstantRange.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/ConstantRange.cpp?rev=284865&r1=284864&r2=284865&view=diff
==============================================================================
--- llvm/trunk/lib/IR/ConstantRange.cpp (original)
+++ llvm/trunk/lib/IR/ConstantRange.cpp Fri Oct 21 14:59:26 2016
@@ -922,3 +922,25 @@ void ConstantRange::print(raw_ostream &O
LLVM_DUMP_METHOD void ConstantRange::dump() const {
print(dbgs());
}
+
+ConstantRange llvm::getConstantRangeFromMetadata(const MDNode &Ranges) {
+ const unsigned NumRanges = Ranges.getNumOperands() / 2;
+ assert(NumRanges >= 1 && "Must have at least one range!");
+ assert(Ranges.getNumOperands() % 2 == 0 && "Must be a sequence of pairs");
+
+ auto *FirstLow = mdconst::extract<ConstantInt>(Ranges.getOperand(0));
+ auto *FirstHigh = mdconst::extract<ConstantInt>(Ranges.getOperand(1));
+
+ ConstantRange CR(FirstLow->getValue(), FirstHigh->getValue());
+
+ for (unsigned i = 1; i < NumRanges; ++i) {
+ auto *Low = mdconst::extract<ConstantInt>(Ranges.getOperand(2 * i + 0));
+ auto *High = mdconst::extract<ConstantInt>(Ranges.getOperand(2 * i + 1));
+
+ // Note: unionWith will potentially create a range that contains values not
+ // contained in any of the original N ranges.
+ CR = CR.unionWith(ConstantRange(Low->getValue(), High->getValue()));
+ }
+
+ return CR;
+}
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp?rev=284865&r1=284864&r2=284865&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp Fri Oct 21 14:59:26 2016
@@ -15,6 +15,7 @@
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/Analysis/Loads.h"
+#include "llvm/IR/ConstantRange.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/IntrinsicInst.h"
Modified: llvm/trunk/lib/Transforms/Scalar/GuardWidening.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/GuardWidening.cpp?rev=284865&r1=284864&r2=284865&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/GuardWidening.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/GuardWidening.cpp Fri Oct 21 14:59:26 2016
@@ -46,6 +46,7 @@
#include "llvm/Analysis/LoopInfo.h"
#include "llvm/Analysis/PostDominators.h"
#include "llvm/Analysis/ValueTracking.h"
+#include "llvm/IR/ConstantRange.h"
#include "llvm/IR/Dominators.h"
#include "llvm/IR/IntrinsicInst.h"
#include "llvm/IR/PatternMatch.h"
More information about the llvm-commits
mailing list