From 0fad5c480e79d476651d50262573e019aac5f5c5 Mon Sep 17 00:00:00 2001 From: Michael Ilseman Date: Tue, 27 Nov 2012 00:43:38 +0000 Subject: [PATCH] Fast-math flags for the bitcode Added in bitcode enum for the serializing of fast-math flags. Added in the reading/writing of fast-math flags from the OptimizationFlags record for BinaryOps. llvm-svn: 168646 --- include/llvm/Bitcode/LLVMBitCodes.h | 10 ++++++++++ lib/Bitcode/Reader/BitcodeReader.cpp | 15 +++++++++++++++ lib/Bitcode/Writer/BitcodeWriter.cpp | 12 ++++++++++++ 3 files changed, 37 insertions(+) diff --git a/include/llvm/Bitcode/LLVMBitCodes.h b/include/llvm/Bitcode/LLVMBitCodes.h index 511e3a377a1..3c7c2b3a06f 100644 --- a/include/llvm/Bitcode/LLVMBitCodes.h +++ b/include/llvm/Bitcode/LLVMBitCodes.h @@ -240,6 +240,16 @@ namespace bitc { PEO_EXACT = 0 }; + /// Flags for serializing FPMathOperator's + /// SubclassOptionalData contents. + enum FastMathFlags { + FMF_UNSAFE_ALGEBRA = 0, + FMF_NO_NANS = 1, + FMF_NO_INFS = 2, + FMF_NO_SIGNED_ZEROS = 3, + FMF_ALLOW_RECIPROCAL = 4 + }; + /// Encoded AtomicOrdering values. enum AtomicOrderingCodes { ORDERING_NOTATOMIC = 0, diff --git a/lib/Bitcode/Reader/BitcodeReader.cpp b/lib/Bitcode/Reader/BitcodeReader.cpp index d3c8678578d..f31637e044f 100644 --- a/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/lib/Bitcode/Reader/BitcodeReader.cpp @@ -2044,7 +2044,22 @@ bool BitcodeReader::ParseFunctionBody(Function *F) { Opc == Instruction::AShr) { if (Record[OpNum] & (1 << bitc::PEO_EXACT)) cast(I)->setIsExact(true); + } else if (isa(I)) { + FastMathFlags FMF; + FMF.UnsafeAlgebra = + 0 != (Record[OpNum] & (1 << bitc::FMF_UNSAFE_ALGEBRA)); + FMF.NoNaNs + = 0 != (Record[OpNum] & (1 << bitc::FMF_NO_NANS)); + FMF.NoInfs + = 0 != (Record[OpNum] & (1 << bitc::FMF_NO_INFS)); + FMF.NoSignedZeros + = 0 != (Record[OpNum] & (1 << bitc::FMF_NO_SIGNED_ZEROS)); + FMF.AllowReciprocal + = 0 != (Record[OpNum] & (1 << bitc::FMF_ALLOW_RECIPROCAL)); + if (FMF.any()) + I->setFastMathFlags(FMF); } + } break; } diff --git a/lib/Bitcode/Writer/BitcodeWriter.cpp b/lib/Bitcode/Writer/BitcodeWriter.cpp index cf3c9fd74eb..6206479b8d7 100644 --- a/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -553,6 +553,18 @@ static uint64_t GetOptimizationFlags(const Value *V) { dyn_cast(V)) { if (PEO->isExact()) Flags |= 1 << bitc::PEO_EXACT; + } else if (const FPMathOperator *FPMO = + dyn_cast(V)) { + if (FPMO->hasUnsafeAlgebra()) + Flags |= 1 << bitc::FMF_UNSAFE_ALGEBRA; + if (FPMO->hasNoNaNs()) + Flags |= 1 << bitc::FMF_NO_NANS; + if (FPMO->hasNoInfs()) + Flags |= 1 << bitc::FMF_NO_INFS; + if (FPMO->hasNoSignedZeros()) + Flags |= 1 << bitc::FMF_NO_SIGNED_ZEROS; + if (FPMO->hasAllowReciprocal()) + Flags |= 1 << bitc::FMF_ALLOW_RECIPROCAL; } return Flags;