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
This commit is contained in:
Dominic Chen 2020-01-24 17:21:14 -05:00
parent f465b1aff4
commit 73713f3e5e
No known key found for this signature in database
GPG Key ID: 7661C15B1B8EC438
3 changed files with 7 additions and 5 deletions

View File

@ -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<RandomNumberGenerator> createRNG(const Pass* P) const;
std::unique_ptr<RandomNumberGenerator> createRNG(const StringRef Name) const;
/// Return true if size-info optimization remark is enabled, false
/// otherwise.

View File

@ -86,8 +86,9 @@ Module::~Module() {
IFuncList.clear();
}
std::unique_ptr<RandomNumberGenerator> Module::createRNG(const Pass* P) const {
SmallString<32> Salt(P->getPassName());
std::unique_ptr<RandomNumberGenerator>
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<RandomNumberGenerator> Module::createRNG(const Pass* P) const {
// store salt metadata from the Module constructor.
Salt += sys::path::filename(getModuleIdentifier());
return std::unique_ptr<RandomNumberGenerator>(new RandomNumberGenerator(Salt));
return std::unique_ptr<RandomNumberGenerator>(
new RandomNumberGenerator(Salt));
}
/// getNamedValue - Return the first global value in the module with

View File

@ -63,7 +63,7 @@ TEST(ModuleTest, randomNumberGenerator) {
std::array<int, NBCheck> RandomStreams[2];
for (auto &RandomStream : RandomStreams) {
std::unique_ptr<RandomNumberGenerator> RNG = M.createRNG(&DP);
std::unique_ptr<RandomNumberGenerator> RNG = M.createRNG(DP->getPassName());
std::generate(RandomStream.begin(), RandomStream.end(),
[&]() { return dist(*RNG); });
}