llvm.org GIT mirror llvm / bdbb295
Remove uses of deprecated std::random_shuffle in the LLVM code base. Reviewed as https://reviews.llvm.org/D29780. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@295325 91177308-0d34-0410-b5e6-96231b3b80d8 Marshall Clow 2 years ago
4 changed file(s) with 16 addition(s) and 14 deletion(s). Raw diff Collapse all Expand all
2020 #include "llvm/Support/raw_ostream.h"
2121 #include
2222 #include
23 #include
2324 using namespace llvm;
2425
2526 Error
3839 return E;
3940 }
4041
41 srand(time(nullptr));
42
42 std::mt19937 randomness(std::random_device{}());
4343 unsigned num = 1;
4444 while (1) {
4545 //
4646 // Step 1: Randomize the order of the optimizer passes.
4747 //
48 std::random_shuffle(PassesToRun.begin(), PassesToRun.end());
48 std::shuffle(PassesToRun.begin(), PassesToRun.end(), randomness);
4949
5050 //
5151 // Step 2: Run optimizer passes on the program and check for success.
1818 #include "llvm/Support/raw_ostream.h"
1919 #include
2020 #include
21 #include
2122 #include
2223
2324 namespace llvm {
4546 /// that bugpoint does.
4647 Expected reduceList(std::vector &TheList) {
4748 std::vector empty;
48 std::srand(0x6e5ea738); // Seed the random number generator
49 std::mt19937 randomness(0x6e5ea738); // Seed the random number generator
4950 Expected Result = doTest(TheList, empty);
5051 if (Error E = Result.takeError())
5152 return std::move(E);
9192 // distribution (improving the speed of convergence).
9293 if (ShufflingEnabled && NumOfIterationsWithoutProgress > MaxIterations) {
9394 std::vector ShuffledList(TheList);
94 std::random_shuffle(ShuffledList.begin(), ShuffledList.end());
95 std::shuffle(ShuffledList.begin(), ShuffledList.end(), randomness);
9596 errs() << "\n\n*** Testing shuffled set...\n\n";
9697 // Check that random shuffle doesn't lose the bug
9798 Expected Result = doTest(ShuffledList, empty);
2727 #include "llvm/Support/PrettyStackTrace.h"
2828 #include "llvm/Support/ToolOutputFile.h"
2929 #include
30 #include
3031 #include
3132
3233 namespace llvm {
112113 return Rand64() % y;
113114 }
114115
116 /// Make this like a C++11 random device
117 typedef uint32_t result_type;
118 uint32_t operator()() { return Rand32(); }
119 static constexpr result_type min() { return 0; }
120 static constexpr result_type max() { return 0x7ffff; }
121
115122 private:
116123 unsigned Seed;
117124 };
661668 BoolInst.push_back(&Instr);
662669 }
663670
664 std::random_shuffle(BoolInst.begin(), BoolInst.end(), R);
671 std::shuffle(BoolInst.begin(), BoolInst.end(), R);
665672
666673 for (auto *Instr : BoolInst) {
667674 BasicBlock *Curr = Instr->getParent();
1616 #include "llvm/Support/type_traits.h"
1717 #include "gtest/gtest.h"
1818 #include
19 #include
1920 #include
2021
2122 using namespace llvm;
2223
2324 namespace {
24
25 // The world's worst RNG, but it is deterministic and makes it easy to get
26 // *some* shuffling of elements.
27 static ptrdiff_t test_shuffle_rng(ptrdiff_t i) {
28 return (i + i * 33) % i;
29 }
30 static ptrdiff_t (*test_shuffle_rng_p)(ptrdiff_t) = &test_shuffle_rng;
3125
3226 template
3327 class TinyPtrVectorTest : public testing::Test {
4539 for (size_t i = 0, e = array_lengthof(TestValues); i != e; ++i)
4640 TestPtrs.push_back(&TestValues[i]);
4741
48 std::random_shuffle(TestPtrs.begin(), TestPtrs.end(), test_shuffle_rng_p);
42 std::shuffle(TestPtrs.begin(), TestPtrs.end(), std::mt19937{});
4943 }
5044
5145 ArrayRef testArray(size_t N) {