[llvm] r202106 - [SROA] Add a debugging tool which shuffles the slices sequence prior to

Adrian Prantl aprantl at apple.com
Mon Mar 3 18:11:17 PST 2014


I see. Shouldn’t it be a call to std::stable_sort(), then?

-- adrian

On Mar 3, 2014, at 18:09, Reid Kleckner <rnk at google.com> wrote:

> If there are equal elements in the list, this should jostle them around a bit.
> 
> 
> On Mon, Mar 3, 2014 at 4:59 PM, Adrian Prantl <aprantl at apple.com> wrote:
> 
> On Feb 24, 2014, at 19:59, Chandler Carruth <chandlerc at gmail.com> wrote:
> 
> > Author: chandlerc
> > Date: Mon Feb 24 21:59:29 2014
> > New Revision: 202106
> >
> > URL: http://llvm.org/viewvc/llvm-project?rev=202106&view=rev
> > Log:
> > [SROA] Add a debugging tool which shuffles the slices sequence prior to
> > sorting it. This helps uncover latent reliance on the original ordering
> > which aren't guaranteed to be preserved by std::sort (but often are),
> > and which are based on the use-def chain orderings which also aren't
> > (technically) guaranteed.
> >
> > Only available in C++11 debug builds, and behind a flag to prevent noise
> > at the moment, but this is generally useful so figured I'd put it in the
> > tree rather than keeping it out-of-tree.
> >
> > Modified:
> >    llvm/trunk/lib/Transforms/Scalar/SROA.cpp
> >
> > Modified: llvm/trunk/lib/Transforms/Scalar/SROA.cpp
> > URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/SROA.cpp?rev=202106&r1=202105&r2=202106&view=diff
> > ==============================================================================
> > --- llvm/trunk/lib/Transforms/Scalar/SROA.cpp (original)
> > +++ llvm/trunk/lib/Transforms/Scalar/SROA.cpp Mon Feb 24 21:59:29 2014
> > @@ -51,10 +51,17 @@
> > #include "llvm/Support/Debug.h"
> > #include "llvm/Support/ErrorHandling.h"
> > #include "llvm/Support/MathExtras.h"
> > +#include "llvm/Support/TimeValue.h"
> > #include "llvm/Support/raw_ostream.h"
> > #include "llvm/Transforms/Utils/Local.h"
> > #include "llvm/Transforms/Utils/PromoteMemToReg.h"
> > #include "llvm/Transforms/Utils/SSAUpdater.h"
> > +
> > +#if __cplusplus >= 201103L && !defined(NDEBUG)
> > +// We only use this for a debug check in C++11
> > +#include <random>
> > +#endif
> > +
> > using namespace llvm;
> >
> > STATISTIC(NumAllocasAnalyzed, "Number of allocas analyzed for replacement");
> > @@ -73,6 +80,11 @@ STATISTIC(NumVectorized, "Number of vect
> > static cl::opt<bool>
> > ForceSSAUpdater("force-ssa-updater", cl::init(false), cl::Hidden);
> >
> > +/// Hidden option to enable randomly shuffling the slices to help uncover
> > +/// instability in their order.
> > +static cl::opt<bool> SROARandomShuffleSlices("sroa-random-shuffle-slices",
> > +                                             cl::init(false), cl::Hidden);
> > +
> > namespace {
> > /// \brief A custom IRBuilder inserter which prefixes all names if they are
> > /// preserved.
> > @@ -690,6 +702,13 @@ AllocaSlices::AllocaSlices(const DataLay
> >                               std::mem_fun_ref(&Slice::isDead)),
> >                Slices.end());
> >
> > +#if __cplusplus >= 201103L && !defined(NDEBUG)
> > +  if (SROARandomShuffleSlices) {
> > +    std::mt19937 MT(static_cast<unsigned>(sys::TimeValue::now().msec()));
> > +    std::shuffle(Slices.begin(), Slices.end(), MT);
> > +  }
> > +#endif
> > +
> >   // Sort the uses. This arranges for the offsets to be in ascending order,
> >   // and the sizes to be in descending order.
> >   std::sort(Slices.begin(), Slices.end());
> 
> Maybe I’m missing something obvious here, but isn’t the shuffle a no-op if it is followed immediately by a sort?
> 
> -- adrian
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140303/a6a8fd41/attachment.html>


More information about the llvm-commits mailing list