From 73713f3e5ef2ecf1e5afafa89f76ab89cc06b18e Mon Sep 17 00:00:00 2001 From: Dominic Chen Date: Fri, 24 Jan 2020 17:21:14 -0500 Subject: [PATCH] RNG: Take pass name as argument instead of pass pointer. Summary: With the new pass manager, it is not possible to obtain a pointer to the pass. Reviewers: jfb, rinon, yln Subscribers: hiraditya, dexonsmith, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D73390 --- llvm/include/llvm/IR/Module.h | 2 +- llvm/lib/IR/Module.cpp | 8 +++++--- llvm/unittests/IR/ModuleTest.cpp | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/llvm/include/llvm/IR/Module.h b/llvm/include/llvm/IR/Module.h index c65113a..3895e99 100644 --- a/llvm/include/llvm/IR/Module.h +++ b/llvm/include/llvm/IR/Module.h @@ -259,7 +259,7 @@ public: /// when other randomness consuming passes are added or removed. In /// addition, the random stream will be reproducible across LLVM /// versions when the pass does not change. - std::unique_ptr createRNG(const Pass* P) const; + std::unique_ptr createRNG(const StringRef Name) const; /// Return true if size-info optimization remark is enabled, false /// otherwise. diff --git a/llvm/lib/IR/Module.cpp b/llvm/lib/IR/Module.cpp index c2083f5..f1acf46 100644 --- a/llvm/lib/IR/Module.cpp +++ b/llvm/lib/IR/Module.cpp @@ -86,8 +86,9 @@ Module::~Module() { IFuncList.clear(); } -std::unique_ptr Module::createRNG(const Pass* P) const { - SmallString<32> Salt(P->getPassName()); +std::unique_ptr +Module::createRNG(const StringRef Name) const { + SmallString<32> Salt(Name); // This RNG is guaranteed to produce the same random stream only // when the Module ID and thus the input filename is the same. This @@ -101,7 +102,8 @@ std::unique_ptr Module::createRNG(const Pass* P) const { // store salt metadata from the Module constructor. Salt += sys::path::filename(getModuleIdentifier()); - return std::unique_ptr(new RandomNumberGenerator(Salt)); + return std::unique_ptr( + new RandomNumberGenerator(Salt)); } /// getNamedValue - Return the first global value in the module with diff --git a/llvm/unittests/IR/ModuleTest.cpp b/llvm/unittests/IR/ModuleTest.cpp index 12eba70..15180bc 100644 --- a/llvm/unittests/IR/ModuleTest.cpp +++ b/llvm/unittests/IR/ModuleTest.cpp @@ -63,7 +63,7 @@ TEST(ModuleTest, randomNumberGenerator) { std::array RandomStreams[2]; for (auto &RandomStream : RandomStreams) { - std::unique_ptr RNG = M.createRNG(&DP); + std::unique_ptr RNG = M.createRNG(DP->getPassName()); std::generate(RandomStream.begin(), RandomStream.end(), [&]() { return dist(*RNG); }); } -- 2.7.4