[llvm] r259208 - [RS4GC] Minor local cleanup to StabilizeOrder; NFC

Sanjoy Das via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 29 08:50:35 PST 2016


Author: sanjoy
Date: Fri Jan 29 10:50:34 2016
New Revision: 259208

URL: http://llvm.org/viewvc/llvm-project?rev=259208&view=rev
Log:
[RS4GC] Minor local cleanup to StabilizeOrder; NFC

 - Locally declare struct, and call it BaseDerivedPair
 - Use a lambda to compare, instead of a singleton with uninitialized
   fields
 - Add a constructor to BaseDerivedPair and use SmallVector::emplace_back

Modified:
    llvm/trunk/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp

Modified: llvm/trunk/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp?rev=259208&r1=259207&r2=259208&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp Fri Jan 29 10:50:34 2016
@@ -1516,33 +1516,32 @@ makeStatepointExplicitImpl(const CallSit
   CreateGCRelocates(LiveVariables, LiveStartIdx, BasePtrs, Token, Builder);
 }
 
-namespace {
-struct NameOrdering {
-  Value *Base;
-  Value *Derived;
-
-  bool operator()(NameOrdering const &a, NameOrdering const &b) {
-    return -1 == a.Derived->getName().compare(b.Derived->getName());
-  }
-};
-}
-
 static void StabilizeOrder(SmallVectorImpl<Value *> &BaseVec,
                            SmallVectorImpl<Value *> &LiveVec) {
   assert(BaseVec.size() == LiveVec.size());
 
-  SmallVector<NameOrdering, 64> Temp;
-  for (size_t i = 0; i < BaseVec.size(); i++) {
-    NameOrdering v;
-    v.Base = BaseVec[i];
-    v.Derived = LiveVec[i];
-    Temp.push_back(v);
-  }
+  struct BaseDerivedPair {
+    Value *Base;
+    Value *Derived;
+
+    BaseDerivedPair(Value *B, Value *D) : Base(B), Derived(D) {}
+  };
+
+  SmallVector<BaseDerivedPair, 64> NameOrdering;
+  NameOrdering.reserve(BaseVec.size());
+
+  for (size_t i = 0, e = BaseVec.size(); i < e; i++)
+    NameOrdering.emplace_back(BaseVec[i], LiveVec[i]);
+
+  auto Compare = [](BaseDerivedPair &L, BaseDerivedPair &R) {
+    return L.Derived->getName() < R.Derived->getName();
+  };
+
+  std::sort(NameOrdering.begin(), NameOrdering.end(), Compare);
 
-  std::sort(Temp.begin(), Temp.end(), NameOrdering());
   for (size_t i = 0; i < BaseVec.size(); i++) {
-    BaseVec[i] = Temp[i].Base;
-    LiveVec[i] = Temp[i].Derived;
+    BaseVec[i] = NameOrdering[i].Base;
+    LiveVec[i] = NameOrdering[i].Derived;
   }
 }
 




More information about the llvm-commits mailing list