Index: include/llvm/IR/Module.h =================================================================== --- include/llvm/IR/Module.h +++ include/llvm/IR/Module.h @@ -186,6 +186,7 @@ ///< Format: (arch)(sub)-(vendor)-(sys0-(abi) void *NamedMDSymTab; ///< NamedMDNode names. DataLayout DL; ///< DataLayout associated with the module + unsigned VersionNum; ///< Module version number determined from parsing friend class Constant; @@ -240,6 +241,9 @@ /// @returns a string containing the module-scope inline assembly blocks. const std::string &getModuleInlineAsm() const { return GlobalScopeAsm; } + /// Get module version number. + const unsigned &getModuleVersionNum() const { return VersionNum; } + /// Get a RandomNumberGenerator salted for use with this module. The /// RNG can be seeded via -rng-seed= and is salted with the /// ModuleID and the provided pass salt. The returned RNG should not @@ -276,6 +280,9 @@ GlobalScopeAsm += '\n'; } + /// Set the module version number. + void setModuleVersionNum(unsigned V) { VersionNum = V; } + /// Append to the module-scope inline assembly blocks. /// A trailing newline is added if the input doesn't have one. void appendModuleInlineAsm(StringRef Asm) { Index: lib/Bitcode/Reader/BitcodeReader.cpp =================================================================== --- lib/Bitcode/Reader/BitcodeReader.cpp +++ lib/Bitcode/Reader/BitcodeReader.cpp @@ -419,7 +419,7 @@ if (Record.empty()) return error("Invalid record"); unsigned ModuleVersion = Record[0]; - if (ModuleVersion > 2) + if (ModuleVersion > 3) return error("Invalid value"); UseStrtab = ModuleVersion >= 2; return ModuleVersion; @@ -1045,7 +1045,7 @@ } } -static FastMathFlags getDecodedFastMathFlags(unsigned Val) { +static FastMathFlags getDecodedFastMathFlags(unsigned Val, bool UseOldFast) { FastMathFlags FMF; if (0 != (Val & FastMathFlags::AllowReassoc)) FMF.setAllowReassoc(); @@ -1061,6 +1061,10 @@ FMF.setAllowContract(true); if (0 != (Val & FastMathFlags::ApproxFunc)) FMF.setApproxFunc(); + // Support the old fast math, by bitcode version, as a mapping to reassoc + // which equates to UnsafeAlgebra, use this to upgrade to current fast. + if (FMF.allowReassoc() && UseOldFast) + FMF.setFast(); return FMF; } @@ -3235,6 +3239,7 @@ if (!VersionOrErr) return VersionOrErr.takeError(); UseRelativeIDs = *VersionOrErr >= 1; + TheModule->setModuleVersionNum(*VersionOrErr); break; } case bitc::MODULE_CODE_TRIPLE: { // TRIPLE: [strchr x N] @@ -3352,6 +3357,7 @@ InstructionList.clear(); unsigned ModuleValueListSize = ValueList.size(); unsigned ModuleMDLoaderSize = MDLoader->size(); + bool UseOldFast = (TheModule->getModuleVersionNum() < 3); // Add all the function arguments to the value table. for (Argument &I : F->args()) @@ -3529,7 +3535,7 @@ if (Record[OpNum] & (1 << bitc::PEO_EXACT)) cast(I)->setIsExact(true); } else if (isa(I)) { - FastMathFlags FMF = getDecodedFastMathFlags(Record[OpNum]); + FastMathFlags FMF = getDecodedFastMathFlags(Record[OpNum], UseOldFast); if (FMF.any()) I->setFastMathFlags(FMF); } @@ -3796,7 +3802,7 @@ bool IsFP = LHS->getType()->isFPOrFPVectorTy(); FastMathFlags FMF; if (IsFP && Record.size() > OpNum+1) - FMF = getDecodedFastMathFlags(Record[++OpNum]); + FMF = getDecodedFastMathFlags(Record[++OpNum], UseOldFast); if (OpNum+1 != Record.size()) return error("Invalid record"); @@ -4467,7 +4473,7 @@ FastMathFlags FMF; if ((CCInfo >> bitc::CALL_FMF) & 1) { - FMF = getDecodedFastMathFlags(Record[OpNum++]); + FMF = getDecodedFastMathFlags(Record[OpNum++], UseOldFast); if (!FMF.any()) return error("Fast math flags indicator set for call with no FMF"); } Index: lib/Bitcode/Writer/BitcodeWriter.cpp =================================================================== --- lib/Bitcode/Writer/BitcodeWriter.cpp +++ lib/Bitcode/Writer/BitcodeWriter.cpp @@ -139,7 +139,7 @@ void BitcodeWriterBase::writeModuleVersion() { // VERSION: [version#] - Stream.EmitRecord(bitc::MODULE_CODE_VERSION, ArrayRef{2}); + Stream.EmitRecord(bitc::MODULE_CODE_VERSION, ArrayRef{3}); } /// Base class to manage the module bitcode writing, currently subclassed for