[llvm] r259208 - [RS4GC] Minor local cleanup to StabilizeOrder; NFC
David Blaikie via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 29 09:02:44 PST 2016
On Fri, Jan 29, 2016 at 8:50 AM, Sanjoy Das via llvm-commits <
llvm-commits at lists.llvm.org> wrote:
> 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) {}
>
You could drop this ctor
> + };
> +
> + 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]);
>
And just use braced init here:
push_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);
>
I'd probably just inline the lambda into the sort call.
>
> - std::sort(Temp.begin(), Temp.end(), NameOrdering());
> for (size_t i = 0; i < BaseVec.size(); i++) {
>
But, honestly - it'd be really nice if we could just sort these in place.
But that'd probably require a few abstractions we don't have just yet (a
range merge/zip tool mostly).
> - BaseVec[i] = Temp[i].Base;
> - LiveVec[i] = Temp[i].Derived;
> + BaseVec[i] = NameOrdering[i].Base;
> + LiveVec[i] = NameOrdering[i].Derived;
> }
> }
>
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160129/474b0ed8/attachment.html>
More information about the llvm-commits
mailing list