Commit 8a714722 authored by Qiu Chaofan's avatar Qiu Chaofan
Browse files

[NFC] [Clang] Use global enum for explicit float mode

Currently, there're multiple float types that can be represented by
__attribute__((mode(xx))). It's parsed, and then a corresponding type is
created if available.

This refactor moves the enum for mode into a global enum class visible
to ASTContext.

Reviewed By: aaron.ballman, erichkeane

Differential Revision: https://reviews.llvm.org/D111391
parent bad44d5f
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -102,6 +102,7 @@ class ParentMapContext;
class DynTypedNode;
class DynTypedNodeList;
class Expr;
enum class FloatModeKind;
class GlobalDecl;
class ItaniumMangleContext;
class MangleContext;
@@ -750,7 +751,8 @@ public:
  /// getRealTypeForBitwidth -
  /// sets floating point QualTy according to specified bitwidth.
  /// Returns empty type if there is no appropriate target types.
  QualType getRealTypeForBitwidth(unsigned DestWidth, bool ExplicitIEEE) const;
  QualType getRealTypeForBitwidth(unsigned DestWidth,
                                  FloatModeKind ExplicitType) const;

  bool AtomicUsesUnsupportedLibcall(const AtomicExpr *E) const;

+13 −12
Original line number Diff line number Diff line
@@ -53,6 +53,15 @@ class SourceManager;

namespace Builtin { struct Info; }

enum class FloatModeKind {
  NoFloat = 255,
  Float = 0,
  Double,
  LongDouble,
  Float128,
  Ibm128
};

/// Fields controlling how types are laid out in memory; these may need to
/// be copied for targets like AMDGPU that base their ABIs on an auxiliary
/// CPU target.
@@ -121,15 +130,6 @@ struct TransferrableTargetInfo {
    UnsignedLongLong
  };

  enum RealType {
    NoFloat = 255,
    Float = 0,
    Double,
    LongDouble,
    Float128,
    Ibm128
  };

protected:
  IntType SizeType, IntMaxType, PtrDiffType, IntPtrType, WCharType, WIntType,
      Char16Type, Char32Type, Int64Type, Int16Type, SigAtomicType,
@@ -401,7 +401,8 @@ public:
  /// is represented as one of those two). At this time, there is no support
  /// for an explicit "PPC double-double" type (i.e. __ibm128) so we only
  /// need to differentiate between "long double" and IEEE quad precision.
  RealType getRealTypeByWidth(unsigned BitWidth, bool ExplicitIEEE) const;
  FloatModeKind getRealTypeByWidth(unsigned BitWidth,
                                   FloatModeKind ExplicitType) const;

  /// Return the alignment (in bits) of the specified integer type enum.
  ///
@@ -847,8 +848,8 @@ public:

  /// Check whether the given real type should use the "fpret" flavor of
  /// Objective-C message passing on this target.
  bool useObjCFPRetForRealType(RealType T) const {
    return RealTypeUsesObjCFPRet & (1 << T);
  bool useObjCFPRetForRealType(FloatModeKind T) const {
    return RealTypeUsesObjCFPRet & (1 << (int)T);
  }

  /// Check whether _Complex long double should use the "fp2ret" flavor
+9 −9
Original line number Diff line number Diff line
@@ -11252,21 +11252,21 @@ QualType ASTContext::getIntTypeForBitwidth(unsigned DestWidth,
/// sets floating point QualTy according to specified bitwidth.
/// Returns empty type if there is no appropriate target types.
QualType ASTContext::getRealTypeForBitwidth(unsigned DestWidth,
                                            bool ExplicitIEEE) const {
  TargetInfo::RealType Ty =
      getTargetInfo().getRealTypeByWidth(DestWidth, ExplicitIEEE);
                                            FloatModeKind ExplicitType) const {
  FloatModeKind Ty =
      getTargetInfo().getRealTypeByWidth(DestWidth, ExplicitType);
  switch (Ty) {
  case TargetInfo::Float:
  case FloatModeKind::Float:
    return FloatTy;
  case TargetInfo::Double:
  case FloatModeKind::Double:
    return DoubleTy;
  case TargetInfo::LongDouble:
  case FloatModeKind::LongDouble:
    return LongDoubleTy;
  case TargetInfo::Float128:
  case FloatModeKind::Float128:
    return Float128Ty;
  case TargetInfo::Ibm128:
  case FloatModeKind::Ibm128:
    return Ibm128Ty;
  case TargetInfo::NoFloat:
  case FloatModeKind::NoFloat:
    return {};
  }

+11 −10
Original line number Diff line number Diff line
@@ -279,32 +279,33 @@ TargetInfo::IntType TargetInfo::getLeastIntTypeByWidth(unsigned BitWidth,
  return NoInt;
}

TargetInfo::RealType TargetInfo::getRealTypeByWidth(unsigned BitWidth,
                                                    bool ExplicitIEEE) const {
FloatModeKind TargetInfo::getRealTypeByWidth(unsigned BitWidth,
                                             FloatModeKind ExplicitType) const {
  if (getFloatWidth() == BitWidth)
    return Float;
    return FloatModeKind::Float;
  if (getDoubleWidth() == BitWidth)
    return Double;
    return FloatModeKind::Double;

  switch (BitWidth) {
  case 96:
    if (&getLongDoubleFormat() == &llvm::APFloat::x87DoubleExtended())
      return LongDouble;
      return FloatModeKind::LongDouble;
    break;
  case 128:
    // The caller explicitly asked for an IEEE compliant type but we still
    // have to check if the target supports it.
    if (ExplicitIEEE)
      return hasFloat128Type() ? Float128 : NoFloat;
    if (ExplicitType == FloatModeKind::Float128)
      return hasFloat128Type() ? FloatModeKind::Float128
                               : FloatModeKind::NoFloat;
    if (&getLongDoubleFormat() == &llvm::APFloat::PPCDoubleDouble() ||
        &getLongDoubleFormat() == &llvm::APFloat::IEEEquad())
      return LongDouble;
      return FloatModeKind::LongDouble;
    if (hasFloat128Type())
      return Float128;
      return FloatModeKind::Float128;
    break;
  }

  return NoFloat;
  return FloatModeKind::NoFloat;
}

/// getTypeAlign - Return the alignment (in bits) of the specified integer type
+3 −3
Original line number Diff line number Diff line
@@ -412,8 +412,8 @@ public:

    // Use fpret for all types.
    RealTypeUsesObjCFPRet =
        ((1 << TargetInfo::Float) | (1 << TargetInfo::Double) |
         (1 << TargetInfo::LongDouble));
        ((1 << (int)FloatModeKind::Float) | (1 << (int)FloatModeKind::Double) |
         (1 << (int)FloatModeKind::LongDouble));

    // x86-32 has atomics up to 8 bytes
    MaxAtomicPromoteWidth = 64;
@@ -692,7 +692,7 @@ public:
                                        "64-i64:64-f80:128-n8:16:32:64-S128");

    // Use fpret only for long double.
    RealTypeUsesObjCFPRet = (1 << TargetInfo::LongDouble);
    RealTypeUsesObjCFPRet = (1 << (int)FloatModeKind::LongDouble);

    // Use fp2ret for _Complex long double.
    ComplexLongDoubleUsesFP2Ret = true;
Loading