[llvm] r307762 - Have Module::createRNG return a unique_ptr

David Blaikie via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 17 08:50:30 PDT 2017


On Wed, Jul 12, 2017 at 1:04 AM Serge Guelton via llvm-commits <
llvm-commits at lists.llvm.org> wrote:

> Author: serge_sans_paille
> Date: Wed Jul 12 01:03:44 2017
> New Revision: 307762
>
> URL: http://llvm.org/viewvc/llvm-project?rev=307762&view=rev
> Log:
> Have Module::createRNG return a unique_ptr
>
> Instead of a raw pointer, this makes memory management safer.
>
> Modified:
>     llvm/trunk/include/llvm/IR/Module.h
>     llvm/trunk/lib/IR/Module.cpp
>     llvm/trunk/unittests/IR/ModuleTest.cpp
>
> Modified: llvm/trunk/include/llvm/IR/Module.h
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/Module.h?rev=307762&r1=307761&r2=307762&view=diff
>
> ==============================================================================
> --- llvm/trunk/include/llvm/IR/Module.h (original)
> +++ llvm/trunk/include/llvm/IR/Module.h Wed Jul 12 01:03:44 2017
> @@ -249,7 +249,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.
> -  RandomNumberGenerator *createRNG(const Pass* P) const;
> +  std::unique_ptr<RandomNumberGenerator> createRNG(const Pass* P) const;
>
>  /// @}
>  /// @name Module Level Mutators
>
> Modified: llvm/trunk/lib/IR/Module.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Module.cpp?rev=307762&r1=307761&r2=307762&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/IR/Module.cpp (original)
> +++ llvm/trunk/lib/IR/Module.cpp Wed Jul 12 01:03:44 2017
> @@ -88,7 +88,7 @@ Module::~Module() {
>    delete static_cast<StringMap<NamedMDNode *> *>(NamedMDSymTab);
>  }
>
> -RandomNumberGenerator *Module::createRNG(const Pass* P) const {
> +std::unique_ptr<RandomNumberGenerator> Module::createRNG(const Pass* P)
> const {
>    SmallString<32> Salt(P->getPassName());
>
>    // This RNG is guaranteed to produce the same random stream only
> @@ -103,7 +103,7 @@ RandomNumberGenerator *Module::createRNG
>    // store salt metadata from the Module constructor.
>    Salt += sys::path::filename(getModuleIdentifier());
>
> -  return new RandomNumberGenerator(Salt);
> +  return std::unique_ptr<RandomNumberGenerator>{new
> RandomNumberGenerator(Salt)};
>

Use () here when calling a ctor? (seems especially weird to use () for one
ctor call but {} for the other)

& I guess you can't use llvm::make_unique here because the
RandomNumberGenerator ctor is private?


>  }
>
>  /// getNamedValue - Return the first global value in the module with
>
> Modified: llvm/trunk/unittests/IR/ModuleTest.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/IR/ModuleTest.cpp?rev=307762&r1=307761&r2=307762&view=diff
>
> ==============================================================================
> --- llvm/trunk/unittests/IR/ModuleTest.cpp (original)
> +++ llvm/trunk/unittests/IR/ModuleTest.cpp Wed Jul 12 01:03:44 2017
> @@ -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);
>      std::generate(RandomStream.begin(), RandomStream.end(),
>                    [&]() { return dist(*RNG); });
>    }
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170717/4341bf10/attachment-0001.html>


More information about the llvm-commits mailing list