llvm.org GIT mirror llvm / fbec1c9
Have Module::createRNG return a unique_ptr Instead of a raw pointer, this makes memory management safer. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@307762 91177308-0d34-0410-b5e6-96231b3b80d8 Serge Guelton 2 years ago
3 changed file(s) with 4 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
248248 /// when other randomness consuming passes are added or removed. In
249249 /// addition, the random stream will be reproducible across LLVM
250250 /// versions when the pass does not change.
251 RandomNumberGenerator *createRNG(const Pass* P) const;
251 std::unique_ptr createRNG(const Pass* P) const;
252252
253253 /// @}
254254 /// @name Module Level Mutators
8787 delete static_cast *>(NamedMDSymTab);
8888 }
8989
90 RandomNumberGenerator *Module::createRNG(const Pass* P) const {
90 std::unique_ptr Module::createRNG(const Pass* P) const {
9191 SmallString<32> Salt(P->getPassName());
9292
9393 // This RNG is guaranteed to produce the same random stream only
102102 // store salt metadata from the Module constructor.
103103 Salt += sys::path::filename(getModuleIdentifier());
104104
105 return new RandomNumberGenerator(Salt);
105 return std::unique_ptr{new RandomNumberGenerator(Salt)};
106106 }
107107
108108 /// getNamedValue - Return the first global value in the module with
6262
6363 std::array RandomStreams[2];
6464 for (auto &RandomStream : RandomStreams) {
65 std::unique_ptr RNG{M.createRNG(&DP)};
65 std::unique_ptr RNG = M.createRNG(&DP);
6666 std::generate(RandomStream.begin(), RandomStream.end(),
6767 [&]() { return dist(*RNG); });
6868 }