+void Module::setDataLayout(StringRef Desc) {
+ DL.reset(Desc);
+
+ if (Desc.empty()) {
+ DataLayoutStr = "";
+ } else {
+ DataLayoutStr = DL.getStringRepresentation();
+ // DataLayoutStr is now equivalent to Desc, but since the representation
+ // is not unique, they may not be identical.
+ }
+}
+
+void Module::setDataLayout(const DataLayout *Other) {
+ if (!Other) {
+ DataLayoutStr = "";
+ DL.reset("");
+ } else {
+ DL = *Other;
+ DataLayoutStr = DL.getStringRepresentation();
+ }
+}
+
+const DataLayout *Module::getDataLayout() const {
+ if (DataLayoutStr.empty())
+ return nullptr;
+ 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;
+}
+