From c28dac8bdbc761e2bcacb61cdbf5d8ee2f2f4ae1 Mon Sep 17 00:00:00 2001
From: Michael Ilseman <milseman@apple.com>
Date: Thu, 15 Nov 2012 09:08:57 -0800
Subject: [PATCH 3/8] Fast-math interfaces for Instructions

Add in getter/setter methods for Instructions, allowing them to be the interface to FPMathOperator similarly to now NUS/NSW is handled.
---
 include/llvm/Instruction.h |   53 ++++++++++++++++++++++++++-
 lib/VMCore/Instruction.cpp |   86 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 138 insertions(+), 1 deletion(-)

diff --git a/include/llvm/Instruction.h b/include/llvm/Instruction.h
index 4b0deaf..a00e084 100644
--- a/include/llvm/Instruction.h
+++ b/include/llvm/Instruction.h
@@ -21,6 +21,7 @@
 
 namespace llvm {
 
+struct FastMathFlags;
 class LLVMContext;
 class MDNode;
 
@@ -175,7 +176,57 @@ public:
 
   /// getDebugLoc - Return the debug location for this node as a DebugLoc.
   const DebugLoc &getDebugLoc() const { return DbgLoc; }
-  
+
+  /// setHasUnsafeAlgebra - Set or clear the unsafe-algebra flag on this
+  /// instruction, which must be an operator which supports this flag. See
+  /// LangRef.html for the meaning of this flag.
+  void setHasUnsafeAlgebra(bool B);
+
+  /// setHasNoNaNs - Set or clear the no-nans flag on this instruction, which
+  /// must be an operator which supports this flag. See LangRef.html for the
+  /// meaning of this flag.
+  void setHasNoNaNs(bool B);
+
+  /// setHasNoInfs - Set or clear the no-infs flag on this instruction, which
+  /// must be an operator which supports this flag. See LangRef.html for the
+  /// meaning of this flag.
+  void setHasNoInfs(bool B);
+
+  /// setHasNoSignedZeros - Set or clear the no-signed-zeros flag on this
+  /// instruction, which must be an operator which supports this flag. See
+  /// LangRef.html for the meaning of this flag.
+  void setHasNoSignedZeros(bool B);
+
+  /// setHasAllowReciprocal - Set or clear the allow-reciprocal flag on this
+  /// instruction, which must be an operator which supports this flag. See
+  /// LangRef.html for the meaning of this flag.
+  void setHasAllowReciprocal(bool B);
+
+  /// setFastMathFlags - Convenience function for setting all the fast-math
+  /// flags on this instruction, which must be an operator which supports these
+  /// flags. See LangRef.html for the meaning of these flats.
+  void setFastMathFlags(FastMathFlags FMF);
+
+  /// hasUnsafeAlgebra - Determine whether the unsafe-algebra flag is set.
+  bool hasUnsafeAlgebra() const;
+
+  /// hasNoNaNs - Determine whether the no-NaNs flag is set.
+  bool hasNoNaNs() const;
+
+  /// hasNoInfs - Determine whether the no-infs flag is set.
+  bool hasNoInfs() const;
+
+  /// hasNoSignedZeros - Determine whether the no-signed-zeros flag is set.
+  bool hasNoSignedZeros() const;
+
+  /// hasAllowReciprocal - Determine whether the allow-reciprocal flag is set.
+  bool hasAllowReciprocal() const;
+
+  /// getFastMathFlags - Convenience function for getting all the fast-math
+  /// flags, which must be an operator which supports these flags. See
+  /// LangRef.html for the meaning of these flats.
+  FastMathFlags getFastMathFlags() const;
+
 private:
   /// hasMetadataHashEntry - Return true if we have an entry in the on-the-side
   /// metadata hash.
diff --git a/lib/VMCore/Instruction.cpp b/lib/VMCore/Instruction.cpp
index c0d1fee..29b68f3 100644
--- a/lib/VMCore/Instruction.cpp
+++ b/lib/VMCore/Instruction.cpp
@@ -16,6 +16,7 @@
 #include "llvm/Instructions.h"
 #include "llvm/Constants.h"
 #include "llvm/Module.h"
+#include "llvm/Operator.h"
 #include "llvm/Support/CallSite.h"
 #include "llvm/Support/LeakDetector.h"
 using namespace llvm;
@@ -92,6 +93,91 @@ void Instruction::moveBefore(Instruction *MovePos) {
                                              this);
 }
 
+/// setHasUnsafeAlgebra - Set or clear the unsafe-algebra flag on this
+/// instruction, which must be an operator which supports this flag. See
+/// LangRef.html for the meaning of this flag.
+void Instruction::setHasUnsafeAlgebra(bool B) {
+  assert(isa<FPMathOperator>(this) && "setting fast-math flag on invalid op");
+  cast<FPMathOperator>(this)->setHasUnsafeAlgebra(B);
+}
+
+/// setHasNoNaNs - Set or clear the NoNaNs flag on this instruction, which must
+/// be an operator which supports this flag. See LangRef.html for the meaning of
+/// this flag.
+void Instruction::setHasNoNaNs(bool B) {
+  assert(isa<FPMathOperator>(this) && "setting fast-math flag on invalid op");
+  cast<FPMathOperator>(this)->setHasNoNaNs(B);
+}
+
+/// setHasNoInfs - Set or clear the no-infs flag on this instruction, which must
+/// be an operator which supports this flag. See LangRef.html for the meaning of
+/// this flag.
+void Instruction::setHasNoInfs(bool B) {
+  assert(isa<FPMathOperator>(this) && "setting fast-math flag on invalid op");
+  cast<FPMathOperator>(this)->setHasNoInfs(B);
+}
+
+/// setHasNoSignedZeros - Set or clear the no-signed-zeros flag on this
+/// instruction, which must be an operator which supports this flag. See
+/// LangRef.html for the meaning of this flag.
+void Instruction::setHasNoSignedZeros(bool B) {
+  assert(isa<FPMathOperator>(this) && "setting fast-math flag on invalid op");
+  cast<FPMathOperator>(this)->setHasNoSignedZeros(B);
+}
+
+/// setHasAllowReciprocal - Set or clear the allow-reciprocal flag on this
+/// instruction, which must be an operator which supports this flag. See
+/// LangRef.html for the meaning of this flag.
+void Instruction::setHasAllowReciprocal(bool B) {
+  assert(isa<FPMathOperator>(this) && "setting fast-math flag on invalid op");
+  cast<FPMathOperator>(this)->setHasAllowReciprocal(B);
+}
+
+/// setFastMathFlags - Convenience function for setting all the fast-math flags
+/// on this instruction, which must be an operator which supports these
+/// flags. See LangRef.html for the meaning of these flats.
+void Instruction::setFastMathFlags(FastMathFlags FMF) {
+  assert(isa<FPMathOperator>(this) && "setting fast-math flag on invalid op");
+  cast<FPMathOperator>(this)->setFastMathFlags(FMF);
+}
+
+/// hasUnsafeAlgebra - Determine whether the unsafe-algebra flag is set.
+bool Instruction::hasUnsafeAlgebra() const {
+  assert(isa<FPMathOperator>(this) && "setting fast-math flag on invalid op");
+  return cast<FPMathOperator>(this)->hasUnsafeAlgebra();
+}
+
+/// hasNoNaNs - Determine whether the no-NaNs flag is set.
+bool Instruction::hasNoNaNs() const {
+  assert(isa<FPMathOperator>(this) && "setting fast-math flag on invalid op");
+  return cast<FPMathOperator>(this)->hasNoNaNs();
+}
+
+/// hasNoInfs - Determine whether the no-infs flag is set.
+bool Instruction::hasNoInfs() const {
+  assert(isa<FPMathOperator>(this) && "setting fast-math flag on invalid op");
+  return cast<FPMathOperator>(this)->hasNoInfs();
+}
+
+/// hasNoSignedZeros - Determine whether the no-signed-zeros flag is set.
+bool Instruction::hasNoSignedZeros() const {
+  assert(isa<FPMathOperator>(this) && "setting fast-math flag on invalid op");
+  return cast<FPMathOperator>(this)->hasNoSignedZeros();
+}
+
+/// hasAllowReciprocal - Determine whether the allow-reciprocal flag is set.
+bool Instruction::hasAllowReciprocal() const {
+  assert(isa<FPMathOperator>(this) && "setting fast-math flag on invalid op");
+  return cast<FPMathOperator>(this)->hasAllowReciprocal();
+}
+
+/// getFastMathFlags - Convenience function for getting all the fast-math
+/// flags, which must be an operator which supports these flags. See
+/// LangRef.html for the meaning of these flats.
+FastMathFlags Instruction::getFastMathFlags() const {
+  assert(isa<FPMathOperator>(this) && "setting fast-math flag on invalid op");
+  return cast<FPMathOperator>(this)->getFastMathFlags();
+}
 
 const char *Instruction::getOpcodeName(unsigned OpCode) {
   switch (OpCode) {
-- 
1.7.9.6 (Apple Git-31.1)

