[clang] 8a71472 - [NFC] [Clang] Use global enum for explicit float mode
Qiu Chaofan via cfe-commits
cfe-commits at lists.llvm.org
Fri Oct 8 19:43:04 PDT 2021
Author: Qiu Chaofan
Date: 2021-10-09T10:39:10+08:00
New Revision: 8a714722e2aa8a62d7812bd78babc99b7a6aeef6
URL: https://github.com/llvm/llvm-project/commit/8a714722e2aa8a62d7812bd78babc99b7a6aeef6
DIFF: https://github.com/llvm/llvm-project/commit/8a714722e2aa8a62d7812bd78babc99b7a6aeef6.diff
LOG: [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
Added:
Modified:
clang/include/clang/AST/ASTContext.h
clang/include/clang/Basic/TargetInfo.h
clang/lib/AST/ASTContext.cpp
clang/lib/Basic/TargetInfo.cpp
clang/lib/Basic/Targets/X86.h
clang/lib/CodeGen/CGCall.cpp
clang/lib/Sema/SemaDeclAttr.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/AST/ASTContext.h b/clang/include/clang/AST/ASTContext.h
index d4e813c5ed9d7..443df3790fc13 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -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 @@ class ASTContext : public RefCountedBase<ASTContext> {
/// 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;
diff --git a/clang/include/clang/Basic/TargetInfo.h b/clang/include/clang/Basic/TargetInfo.h
index e959108e2ac03..98a4f4a4343f8 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -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 @@ class TargetInfo : public virtual TransferrableTargetInfo,
/// 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
diff erentiate 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 @@ class TargetInfo : public virtual TransferrableTargetInfo,
/// 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
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 4085477bc45ad..0ce93905a44e2 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -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 {};
}
diff --git a/clang/lib/Basic/TargetInfo.cpp b/clang/lib/Basic/TargetInfo.cpp
index a70abd1c9243b..2d9110a5fc447 100644
--- a/clang/lib/Basic/TargetInfo.cpp
+++ b/clang/lib/Basic/TargetInfo.cpp
@@ -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
diff --git a/clang/lib/Basic/Targets/X86.h b/clang/lib/Basic/Targets/X86.h
index 568d62286b0fa..2c4ab0494fbb2 100644
--- a/clang/lib/Basic/Targets/X86.h
+++ b/clang/lib/Basic/Targets/X86.h
@@ -412,8 +412,8 @@ class LLVM_LIBRARY_VISIBILITY X86_32TargetInfo : public X86TargetInfo {
// 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 @@ class LLVM_LIBRARY_VISIBILITY X86_64TargetInfo : public X86TargetInfo {
"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;
diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 21774021c302f..daea09be3e70b 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -1564,11 +1564,11 @@ bool CodeGenModule::ReturnTypeUsesFPRet(QualType ResultType) {
default:
return false;
case BuiltinType::Float:
- return getTarget().useObjCFPRetForRealType(TargetInfo::Float);
+ return getTarget().useObjCFPRetForRealType(FloatModeKind::Float);
case BuiltinType::Double:
- return getTarget().useObjCFPRetForRealType(TargetInfo::Double);
+ return getTarget().useObjCFPRetForRealType(FloatModeKind::Double);
case BuiltinType::LongDouble:
- return getTarget().useObjCFPRetForRealType(TargetInfo::LongDouble);
+ return getTarget().useObjCFPRetForRealType(FloatModeKind::LongDouble);
}
}
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index c78fec1b7dcfe..1b9a63c15e71e 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -4203,9 +4203,10 @@ bool Sema::checkMSInheritanceAttrOnDefinition(
/// attribute.
static void parseModeAttrArg(Sema &S, StringRef Str, unsigned &DestWidth,
bool &IntegerMode, bool &ComplexMode,
- bool &ExplicitIEEE) {
+ FloatModeKind &ExplicitType) {
IntegerMode = true;
ComplexMode = false;
+ ExplicitType = FloatModeKind::NoFloat;
switch (Str.size()) {
case 2:
switch (Str[0]) {
@@ -4225,11 +4226,11 @@ static void parseModeAttrArg(Sema &S, StringRef Str, unsigned &DestWidth,
DestWidth = 96;
break;
case 'K': // KFmode - IEEE quad precision (__float128)
- ExplicitIEEE = true;
+ ExplicitType = FloatModeKind::Float128;
DestWidth = Str[1] == 'I' ? 0 : 128;
break;
case 'T':
- ExplicitIEEE = false;
+ ExplicitType = FloatModeKind::LongDouble;
DestWidth = 128;
break;
}
@@ -4290,7 +4291,7 @@ void Sema::AddModeAttr(Decl *D, const AttributeCommonInfo &CI,
unsigned DestWidth = 0;
bool IntegerMode = true;
bool ComplexMode = false;
- bool ExplicitIEEE = false;
+ FloatModeKind ExplicitType = FloatModeKind::NoFloat;
llvm::APInt VectorSize(64, 0);
if (Str.size() >= 4 && Str[0] == 'V') {
// Minimal length of vector mode is 4: 'V' + NUMBER(>=1) + TYPE(>=2).
@@ -4303,7 +4304,7 @@ void Sema::AddModeAttr(Decl *D, const AttributeCommonInfo &CI,
!Str.substr(1, VectorStringLength).getAsInteger(10, VectorSize) &&
VectorSize.isPowerOf2()) {
parseModeAttrArg(*this, Str.substr(VectorStringLength + 1), DestWidth,
- IntegerMode, ComplexMode, ExplicitIEEE);
+ IntegerMode, ComplexMode, ExplicitType);
// Avoid duplicate warning from template instantiation.
if (!InInstantiation)
Diag(AttrLoc, diag::warn_vector_mode_deprecated);
@@ -4314,7 +4315,7 @@ void Sema::AddModeAttr(Decl *D, const AttributeCommonInfo &CI,
if (!VectorSize)
parseModeAttrArg(*this, Str, DestWidth, IntegerMode, ComplexMode,
- ExplicitIEEE);
+ ExplicitType);
// FIXME: Sync this with InitializePredefinedMacros; we need to match int8_t
// and friends, at least with glibc.
@@ -4380,7 +4381,7 @@ void Sema::AddModeAttr(Decl *D, const AttributeCommonInfo &CI,
NewElemTy = Context.getIntTypeForBitwidth(DestWidth,
OldElemTy->isSignedIntegerType());
else
- NewElemTy = Context.getRealTypeForBitwidth(DestWidth, ExplicitIEEE);
+ NewElemTy = Context.getRealTypeForBitwidth(DestWidth, ExplicitType);
if (NewElemTy.isNull()) {
Diag(AttrLoc, diag::err_machine_mode) << 1 /*Unsupported*/ << Name;
More information about the cfe-commits
mailing list