diff options
Diffstat (limited to 'llvm/tools')
| -rw-r--r-- | llvm/tools/bugpoint/FindBugs.cpp | 6 | ||||
| -rw-r--r-- | llvm/tools/bugpoint/ListReducer.h | 5 | ||||
| -rw-r--r-- | llvm/tools/llvm-stress/llvm-stress.cpp | 9 |
3 files changed, 14 insertions, 6 deletions
diff --git a/llvm/tools/bugpoint/FindBugs.cpp b/llvm/tools/bugpoint/FindBugs.cpp index 156f4d0d78f..3093169ba8b 100644 --- a/llvm/tools/bugpoint/FindBugs.cpp +++ b/llvm/tools/bugpoint/FindBugs.cpp @@ -21,6 +21,7 @@ #include "llvm/Support/raw_ostream.h" #include <algorithm> #include <ctime> +#include <random> using namespace llvm; Error @@ -39,14 +40,13 @@ BugDriver::runManyPasses(const std::vector<std::string> &AllPasses) { return E; } - srand(time(nullptr)); - + std::mt19937 randomness(std::random_device{}()); unsigned num = 1; while (1) { // // Step 1: Randomize the order of the optimizer passes. // - std::random_shuffle(PassesToRun.begin(), PassesToRun.end()); + std::shuffle(PassesToRun.begin(), PassesToRun.end(), randomness); // // Step 2: Run optimizer passes on the program and check for success. diff --git a/llvm/tools/bugpoint/ListReducer.h b/llvm/tools/bugpoint/ListReducer.h index dcfa11d0692..0f9db022d55 100644 --- a/llvm/tools/bugpoint/ListReducer.h +++ b/llvm/tools/bugpoint/ListReducer.h @@ -19,6 +19,7 @@ #include "llvm/Support/raw_ostream.h" #include <algorithm> #include <cstdlib> +#include <random> #include <vector> namespace llvm { @@ -46,7 +47,7 @@ template <typename ElTy> struct ListReducer { /// that bugpoint does. Expected<bool> reduceList(std::vector<ElTy> &TheList) { std::vector<ElTy> empty; - std::srand(0x6e5ea738); // Seed the random number generator + std::mt19937 randomness(0x6e5ea738); // Seed the random number generator Expected<TestResult> Result = doTest(TheList, empty); if (Error E = Result.takeError()) return std::move(E); @@ -92,7 +93,7 @@ template <typename ElTy> struct ListReducer { // distribution (improving the speed of convergence). if (ShufflingEnabled && NumOfIterationsWithoutProgress > MaxIterations) { std::vector<ElTy> ShuffledList(TheList); - std::random_shuffle(ShuffledList.begin(), ShuffledList.end()); + std::shuffle(ShuffledList.begin(), ShuffledList.end(), randomness); errs() << "\n\n*** Testing shuffled set...\n\n"; // Check that random shuffle doesn't lose the bug Expected<TestResult> Result = doTest(ShuffledList, empty); diff --git a/llvm/tools/llvm-stress/llvm-stress.cpp b/llvm/tools/llvm-stress/llvm-stress.cpp index 731a24d0ac2..fdfa197e601 100644 --- a/llvm/tools/llvm-stress/llvm-stress.cpp +++ b/llvm/tools/llvm-stress/llvm-stress.cpp @@ -28,6 +28,7 @@ #include "llvm/Support/PrettyStackTrace.h" #include "llvm/Support/ToolOutputFile.h" #include <algorithm> +#include <random> #include <vector> namespace llvm { @@ -113,6 +114,12 @@ public: return Rand64() % y; } + /// Make this like a C++11 random device + typedef uint32_t result_type; + uint32_t operator()() { return Rand32(); } + static constexpr result_type min() { return 0; } + static constexpr result_type max() { return 0x7ffff; } + private: unsigned Seed; }; @@ -662,7 +669,7 @@ static void IntroduceControlFlow(Function *F, Random &R) { BoolInst.push_back(&Instr); } - std::random_shuffle(BoolInst.begin(), BoolInst.end(), R); + std::shuffle(BoolInst.begin(), BoolInst.end(), R); for (auto *Instr : BoolInst) { BasicBlock *Curr = Instr->getParent(); |

