summaryrefslogtreecommitdiffstats
path: root/llvm/lib/VMCore/Instructions.cpp
diff options
context:
space:
mode:
authorDuncan Sands <baldrick@free.fr>2012-04-16 16:28:59 +0000
committerDuncan Sands <baldrick@free.fr>2012-04-16 16:28:59 +0000
commit05f4df8d725c89708b1ac1394b695c9fc19c61b9 (patch)
treeddc53954bbd1c7afb505256055aeda02ad86b4be /llvm/lib/VMCore/Instructions.cpp
parent4190b507c58fc2e48f0f017f2109a29d99b0d54c (diff)
downloadbcm5719-llvm-05f4df8d725c89708b1ac1394b695c9fc19c61b9.tar.gz
bcm5719-llvm-05f4df8d725c89708b1ac1394b695c9fc19c61b9.zip
Make it possible to indicate relaxed floating point requirements at the IR level
through the use of 'fpmath' metadata. Currently this only provides a 'fpaccuracy' value, which may be a number in ULPs or the keyword 'fast', however the intent is that this will be extended with additional information about NaN's, infinities etc later. No optimizations have been hooked up to this so far. llvm-svn: 154822
Diffstat (limited to 'llvm/lib/VMCore/Instructions.cpp')
-rw-r--r--llvm/lib/VMCore/Instructions.cpp38
1 files changed, 38 insertions, 0 deletions
diff --git a/llvm/lib/VMCore/Instructions.cpp b/llvm/lib/VMCore/Instructions.cpp
index 8db6ac9a33f..185cd0557c1 100644
--- a/llvm/lib/VMCore/Instructions.cpp
+++ b/llvm/lib/VMCore/Instructions.cpp
@@ -2003,6 +2003,44 @@ bool BinaryOperator::isExact() const {
}
//===----------------------------------------------------------------------===//
+// FPMathOperator Class
+//===----------------------------------------------------------------------===//
+
+/// getFPAccuracy - Get the maximum error permitted by this operation in ULPs.
+/// An accuracy of 0.0 means that the operation should be performed with the
+/// default precision. A huge value is returned if the accuracy is 'fast'.
+float FPMathOperator::getFPAccuracy() const {
+ const MDNode *MD =
+ cast<Instruction>(this)->getMetadata(LLVMContext::MD_fpmath);
+ if (!MD)
+ return 0.0;
+ Value *Op = MD->getOperand(0);
+ if (const ConstantFP *Accuracy = dyn_cast<ConstantFP>(Op))
+ return Accuracy->getValueAPF().convertToFloat();
+ // If it's not a floating point number then it must be 'fast'.
+ assert(isa<MDString>(Op) && cast<MDString>(Op)->getString() == "fast" &&
+ "Expected the 'fast' keyword!");
+ return HUGE_VALF;
+}
+
+/// isFastFPAccuracy - Return true if the accuracy is 'fast'. This says that
+/// speed is more important than accuracy.
+bool FPMathOperator::isFastFPAccuracy() const {
+ const MDNode *MD =
+ cast<Instruction>(this)->getMetadata(LLVMContext::MD_fpmath);
+ if (!MD)
+ return false;
+ Value *Op = MD->getOperand(0);
+ if (isa<ConstantFP>(Op))
+ return false;
+ // If it's not a floating point number then it must be 'fast'.
+ assert(isa<MDString>(Op) && cast<MDString>(Op)->getString() == "fast" &&
+ "Expected the 'fast' keyword!");
+ return true;
+}
+
+
+//===----------------------------------------------------------------------===//
// CastInst Class
//===----------------------------------------------------------------------===//
OpenPOWER on IntegriCloud