Random Number Generator Refactoring (removing from Module)

This patch removes the RNG from Module. Passes should instead create a new RNG for their use as needed.

Patch by Stephen Crane @rinon.

Differential revision: http://reviews.llvm.org/D4377

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@224444 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
JF Bastien
2014-12-17 18:12:10 +00:00
parent 9830b459be
commit 544f63e84a
4 changed files with 61 additions and 52 deletions

View File

@@ -47,7 +47,7 @@ template class llvm::SymbolTableListTraits<GlobalAlias, Module>;
//
Module::Module(StringRef MID, LLVMContext &C)
: Context(C), Materializer(), ModuleID(MID), RNG(nullptr), DL("") {
: Context(C), Materializer(), ModuleID(MID), DL("") {
ValSymTab = new ValueSymbolTable();
NamedMDSymTab = new StringMap<NamedMDNode *>();
Context.addModule(this);
@@ -62,9 +62,27 @@ Module::~Module() {
NamedMDList.clear();
delete ValSymTab;
delete static_cast<StringMap<NamedMDNode *> *>(NamedMDSymTab);
delete RNG;
}
RandomNumberGenerator *Module::createRNG(const Pass* P) const {
SmallString<32> Salt(P->getPassName());
// This RNG is guaranteed to produce the same random stream only
// when the Module ID and thus the input filename is the same. This
// might be problematic if the input filename extension changes
// (e.g. from .c to .bc or .ll).
//
// We could store this salt in NamedMetadata, but this would make
// the parameter non-const. This would unfortunately make this
// interface unusable by any Machine passes, since they only have a
// const reference to their IR Module. Alternatively we can always
// store salt metadata from the Module constructor.
Salt += sys::path::filename(getModuleIdentifier());
return new RandomNumberGenerator(Salt);
}
/// getNamedValue - Return the first global value in the module with
/// the specified name, of arbitrary type. This method returns null
/// if a global with the specified name is not found.
@@ -374,16 +392,6 @@ const DataLayout *Module::getDataLayout() const {
return &DL;
}
// We want reproducible builds, but ModuleID may be a full path so we just use
// the filename to salt the RNG (although it is not guaranteed to be unique).
RandomNumberGenerator &Module::getRNG() const {
if (RNG == nullptr) {
StringRef Salt = sys::path::filename(ModuleID);
RNG = new RandomNumberGenerator(Salt);
}
return *RNG;
}
//===----------------------------------------------------------------------===//
// Methods to control the materialization of GlobalValues in the Module.
//