summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Kramer <benny.kra@googlemail.com>2013-07-11 15:37:27 +0000
committerBenjamin Kramer <benny.kra@googlemail.com>2013-07-11 15:37:27 +0000
commit318b7cc7f10d41370929ff93274de29c11f87b81 (patch)
treeb139fce649ddd301017da2b400f51a76b93a3d7e
parent71857ccdb83b6374f7a791c2dae45ce9934a85af (diff)
downloadllvm-318b7cc7f10d41370929ff93274de29c11f87b81.tar.gz
llvm-318b7cc7f10d41370929ff93274de29c11f87b81.tar.bz2
llvm-318b7cc7f10d41370929ff93274de29c11f87b81.tar.xz
Use move semantics if possible to construct ConstantRanges.
Arithmetic on ConstantRanges creates a lot of large temporary APInts that benefit from move semantics. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@186091 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/llvm/Support/ConstantRange.h12
-rw-r--r--lib/Support/ConstantRange.cpp11
2 files changed, 16 insertions, 7 deletions
diff --git a/include/llvm/Support/ConstantRange.h b/include/llvm/Support/ConstantRange.h
index 0f29256b80..f757c6ea60 100644
--- a/include/llvm/Support/ConstantRange.h
+++ b/include/llvm/Support/ConstantRange.h
@@ -42,6 +42,14 @@ namespace llvm {
class ConstantRange {
APInt Lower, Upper;
+#if LLVM_HAS_RVALUE_REFERENCES
+ // If we have move semantics, pass APInts by value and move them into place.
+ typedef APInt APIntMoveTy;
+#else
+ // Otherwise pass by const ref to save one copy.
+ typedef const APInt &APIntMoveTy;
+#endif
+
public:
/// Initialize a full (the default) or empty set for the specified bit width.
///
@@ -49,12 +57,12 @@ public:
/// Initialize a range to hold the single specified value.
///
- ConstantRange(const APInt &Value);
+ ConstantRange(APIntMoveTy Value);
/// @brief Initialize a range of values explicitly. This will assert out if
/// Lower==Upper and Lower != Min or Max value for its type. It will also
/// assert out if the two APInt's are not the same bit width.
- ConstantRange(const APInt &Lower, const APInt &Upper);
+ ConstantRange(APIntMoveTy Lower, APIntMoveTy Upper);
/// makeICmpRegion - Produce the smallest range that contains all values that
/// might satisfy the comparison specified by Pred when compared to any value
diff --git a/lib/Support/ConstantRange.cpp b/lib/Support/ConstantRange.cpp
index 5c5895026b..d770381dcd 100644
--- a/lib/Support/ConstantRange.cpp
+++ b/lib/Support/ConstantRange.cpp
@@ -38,13 +38,14 @@ ConstantRange::ConstantRange(uint32_t BitWidth, bool Full) {
/// Initialize a range to hold the single specified value.
///
-ConstantRange::ConstantRange(const APInt &V) : Lower(V), Upper(V + 1) {}
+ConstantRange::ConstantRange(APIntMoveTy V)
+ : Lower(llvm_move(V)), Upper(Lower + 1) {}
-ConstantRange::ConstantRange(const APInt &L, const APInt &U) :
- Lower(L), Upper(U) {
- assert(L.getBitWidth() == U.getBitWidth() &&
+ConstantRange::ConstantRange(APIntMoveTy L, APIntMoveTy U)
+ : Lower(llvm_move(L)), Upper(llvm_move(U)) {
+ assert(Lower.getBitWidth() == Upper.getBitWidth() &&
"ConstantRange with unequal bit widths");
- assert((L != U || (L.isMaxValue() || L.isMinValue())) &&
+ assert((Lower != Upper || (Lower.isMaxValue() || Lower.isMinValue())) &&
"Lower == Upper, but they aren't min or max value!");
}