summaryrefslogtreecommitdiff
path: root/include/llvm
diff options
context:
space:
mode:
authorDale Johannesen <dalej@apple.com>2007-08-24 00:56:33 +0000
committerDale Johannesen <dalej@apple.com>2007-08-24 00:56:33 +0000
commit343e770983dcf53a1ea2dfca4e04d28ebc41138a (patch)
tree7a47d5e48fde4a3990a915df06776a2122625610 /include/llvm
parent57e4785123d830cfaa827474485596c9943cd2ae (diff)
downloadllvm-343e770983dcf53a1ea2dfca4e04d28ebc41138a.tar.gz
llvm-343e770983dcf53a1ea2dfca4e04d28ebc41138a.tar.bz2
llvm-343e770983dcf53a1ea2dfca4e04d28ebc41138a.tar.xz
Change internal representation of ConstantFP to use APFloat.
Interface to rest of the compiler unchanged, as yet. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@41348 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm')
-rw-r--r--include/llvm/ADT/APFloat.h16
-rw-r--r--include/llvm/Constants.h12
2 files changed, 25 insertions, 3 deletions
diff --git a/include/llvm/ADT/APFloat.h b/include/llvm/ADT/APFloat.h
index 89614d5d36..5387b48d59 100644
--- a/include/llvm/ADT/APFloat.h
+++ b/include/llvm/ADT/APFloat.h
@@ -118,6 +118,9 @@ namespace llvm {
static const fltSemantics IEEEdouble;
static const fltSemantics IEEEquad;
static const fltSemantics x87DoubleExtended;
+ /* And this psuedo, used to construct APFloats that cannot
+ conflict with anything real. */
+ static const fltSemantics Bogus;
static unsigned int semanticsPrecision(const fltSemantics &);
@@ -161,6 +164,8 @@ namespace llvm {
APFloat(const fltSemantics &, const char *);
APFloat(const fltSemantics &, integerPart);
APFloat(const fltSemantics &, fltCategory, bool negative);
+ APFloat(double d);
+ APFloat(float f);
APFloat(const APFloat &);
~APFloat();
@@ -179,10 +184,16 @@ namespace llvm {
opStatus convertFromInteger(const integerPart *, unsigned int, bool,
roundingMode);
opStatus convertFromString(const char *, roundingMode);
+ double convertToDouble() const;
+ float convertToFloat() const;
- /* Comparison with another floating point number. */
+ /* IEEE comparison with another floating point number (QNaNs
+ compare unordered, 0==-0). */
cmpResult compare(const APFloat &) const;
+ /* Bitwise comparison for equality (QNaNs compare equal, 0!=-0). */
+ bool operator==(const APFloat &) const;
+
/* Simple queries. */
fltCategory getCategory() const { return category; }
const fltSemantics &getSemantics() const { return *semantics; }
@@ -192,6 +203,9 @@ namespace llvm {
APFloat& operator=(const APFloat &);
+ /* Return an arbitrary integer value usable for hashing. */
+ uint32_t getHashValue() const;
+
private:
/* Trivial queries. */
diff --git a/include/llvm/Constants.h b/include/llvm/Constants.h
index bb32a1b730..4aa5afbcf9 100644
--- a/include/llvm/Constants.h
+++ b/include/llvm/Constants.h
@@ -23,6 +23,7 @@
#include "llvm/Constant.h"
#include "llvm/Type.h"
#include "llvm/ADT/APInt.h"
+#include "llvm/ADT/APFloat.h"
namespace llvm {
@@ -213,7 +214,7 @@ private:
/// ConstantFP - Floating Point Values [float, double]
///
class ConstantFP : public Constant {
- double Val;
+ APFloat Val;
ConstantFP(const ConstantFP &); // DO NOT IMPLEMENT
protected:
ConstantFP(const Type *Ty, double V);
@@ -223,7 +224,14 @@ public:
/// isValueValidForType - return true if Ty is big enough to represent V.
static bool isValueValidForType(const Type *Ty, double V);
- inline double getValue() const { return Val; }
+ inline double getValue() const {
+ if (&Val.getSemantics() == &APFloat::IEEEdouble)
+ return Val.convertToDouble();
+ else if (&Val.getSemantics() == &APFloat::IEEEsingle)
+ return (double)Val.convertToFloat();
+ else
+ assert(0);
+ }
/// isNullValue - Return true if this is the value that would be returned by
/// getNullValue. Don't depend on == for doubles to tell us it's zero, it