Skip to content

[ADT][APFloat] Make sure EBO is performed on APFloat #111641

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 42 additions & 8 deletions llvm/include/llvm/ADT/APFloat.h
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,38 @@ struct APFloatBase {

namespace detail {

class IEEEFloat final : public APFloatBase {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any reason to keep APFloatBase as a class? It seems like it's just a namespace

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried this before submitting the patch. We cannot import an unscoped enum from a namespace to a class.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most of these enums should probably move to enum class anyway

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These unscoped enums are widely used in llvm via APFloat::***. It would be a heavy work to convert all uses of unscoped enums to scoped enums :(

using integerPart = APFloatBase::integerPart;
using uninitializedTag = APFloatBase::uninitializedTag;
using roundingMode = APFloatBase::roundingMode;
using opStatus = APFloatBase::opStatus;
using cmpResult = APFloatBase::cmpResult;
using fltCategory = APFloatBase::fltCategory;
using ExponentType = APFloatBase::ExponentType;
static constexpr uninitializedTag uninitialized = APFloatBase::uninitialized;
static constexpr roundingMode rmNearestTiesToEven =
APFloatBase::rmNearestTiesToEven;
static constexpr roundingMode rmNearestTiesToAway =
APFloatBase::rmNearestTiesToAway;
static constexpr roundingMode rmTowardNegative = APFloatBase::rmTowardNegative;
static constexpr roundingMode rmTowardPositive = APFloatBase::rmTowardPositive;
static constexpr roundingMode rmTowardZero = APFloatBase::rmTowardZero;
static constexpr unsigned integerPartWidth = APFloatBase::integerPartWidth;
static constexpr cmpResult cmpEqual = APFloatBase::cmpEqual;
static constexpr cmpResult cmpLessThan = APFloatBase::cmpLessThan;
static constexpr cmpResult cmpGreaterThan = APFloatBase::cmpGreaterThan;
static constexpr cmpResult cmpUnordered = APFloatBase::cmpUnordered;
static constexpr opStatus opOK = APFloatBase::opOK;
static constexpr opStatus opInvalidOp = APFloatBase::opInvalidOp;
static constexpr opStatus opDivByZero = APFloatBase::opDivByZero;
static constexpr opStatus opOverflow = APFloatBase::opOverflow;
static constexpr opStatus opUnderflow = APFloatBase::opUnderflow;
static constexpr opStatus opInexact = APFloatBase::opInexact;
static constexpr fltCategory fcInfinity = APFloatBase::fcInfinity;
static constexpr fltCategory fcNaN = APFloatBase::fcNaN;
static constexpr fltCategory fcNormal = APFloatBase::fcNormal;
static constexpr fltCategory fcZero = APFloatBase::fcZero;

class IEEEFloat final {
public:
/// \name Constructors
/// @{
Expand Down Expand Up @@ -433,7 +464,7 @@ class IEEEFloat final : public APFloatBase {
bool isFinite() const { return !isNaN() && !isInfinity(); }

/// Returns true if and only if the float is plus or minus zero.
bool isZero() const { return category == fcZero; }
bool isZero() const { return category == fltCategory::fcZero; }

/// IEEE-754R isSubnormal(): Returns true if and only if the float is a
/// denormal.
Expand All @@ -455,7 +486,7 @@ class IEEEFloat final : public APFloatBase {

fltCategory getCategory() const { return category; }
const fltSemantics &getSemantics() const { return *semantics; }
bool isNonZero() const { return category != fcZero; }
bool isNonZero() const { return category != fltCategory::fcZero; }
bool isFiniteNonZero() const { return isFinite() && !isZero(); }
bool isPosZero() const { return isZero() && !isNegative(); }
bool isNegZero() const { return isZero() && isNegative(); }
Expand Down Expand Up @@ -719,14 +750,14 @@ class IEEEFloat final : public APFloatBase {

hash_code hash_value(const IEEEFloat &Arg);
int ilogb(const IEEEFloat &Arg);
IEEEFloat scalbn(IEEEFloat X, int Exp, IEEEFloat::roundingMode);
IEEEFloat frexp(const IEEEFloat &Val, int &Exp, IEEEFloat::roundingMode RM);
IEEEFloat scalbn(IEEEFloat X, int Exp, roundingMode);
IEEEFloat frexp(const IEEEFloat &Val, int &Exp, roundingMode RM);

// This mode implements more precise float in terms of two APFloats.
// The interface and layout is designed for arbitrary underlying semantics,
// though currently only PPCDoubleDouble semantics are supported, whose
// corresponding underlying semantics are IEEEdouble.
class DoubleAPFloat final : public APFloatBase {
class DoubleAPFloat final {
// Note: this must be the first data member.
const fltSemantics *Semantics;
std::unique_ptr<APFloat[]> Floats;
Expand Down Expand Up @@ -819,8 +850,8 @@ class DoubleAPFloat final : public APFloatBase {
};

hash_code hash_value(const DoubleAPFloat &Arg);
DoubleAPFloat scalbn(const DoubleAPFloat &Arg, int Exp, IEEEFloat::roundingMode RM);
DoubleAPFloat frexp(const DoubleAPFloat &X, int &Exp, IEEEFloat::roundingMode);
DoubleAPFloat scalbn(const DoubleAPFloat &Arg, int Exp, roundingMode RM);
DoubleAPFloat frexp(const DoubleAPFloat &X, int &Exp, roundingMode);

} // End detail namespace

Expand Down Expand Up @@ -1440,6 +1471,9 @@ class APFloat : public APFloatBase {
friend DoubleAPFloat;
};

static_assert(sizeof(APFloat) == sizeof(detail::IEEEFloat),
"Empty base class optimization is not performed.");

/// See friend declarations above.
///
/// These additional declarations are required in order to compile LLVM with IBM
Expand Down
Loading
Loading