[llvm] r186091 - Use move semantics if possible to construct ConstantRanges.

Benjamin Kramer benny.kra at googlemail.com
Thu Jul 11 08:37:27 PDT 2013


Author: d0k
Date: Thu Jul 11 10:37:27 2013
New Revision: 186091

URL: http://llvm.org/viewvc/llvm-project?rev=186091&view=rev
Log:
Use move semantics if possible to construct ConstantRanges.

Arithmetic on ConstantRanges creates a lot of large temporary APInts that
benefit from move semantics.

Modified:
    llvm/trunk/include/llvm/Support/ConstantRange.h
    llvm/trunk/lib/Support/ConstantRange.cpp

Modified: llvm/trunk/include/llvm/Support/ConstantRange.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/ConstantRange.h?rev=186091&r1=186090&r2=186091&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/ConstantRange.h (original)
+++ llvm/trunk/include/llvm/Support/ConstantRange.h Thu Jul 11 10:37:27 2013
@@ -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

Modified: llvm/trunk/lib/Support/ConstantRange.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/ConstantRange.cpp?rev=186091&r1=186090&r2=186091&view=diff
==============================================================================
--- llvm/trunk/lib/Support/ConstantRange.cpp (original)
+++ llvm/trunk/lib/Support/ConstantRange.cpp Thu Jul 11 10:37:27 2013
@@ -38,13 +38,14 @@ ConstantRange::ConstantRange(uint32_t Bi
 
 /// 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!");
 }
 





More information about the llvm-commits mailing list