[Fixed Point Arithmetic] Rename `-fsame-fbits` flag

- Rename the `-fsame-fbits` flag to `-fpadding-on-unsigned-fixed-point`
- Move the flag from a driver option to a cc1 option
- Rename the `SameFBits` member in TargetInfo to `PaddingOnUnsignedFixedPoint`
- Updated descriptions

Differential Revision: https://reviews.llvm.org/D48727

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@335993 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Leonard Chan 2018-06-29 17:08:19 +00:00
parent 4c16104f94
commit aaf4d11cdd
9 changed files with 33 additions and 31 deletions

View File

@ -306,8 +306,8 @@ ENUM_LANGOPT(ClangABICompat, ClangABI, 4, ClangABI::Latest,
COMPATIBLE_VALUE_LANGOPT(FunctionAlignment, 5, 0, "Default alignment for functions")
LANGOPT(FixedPoint, 1, 0, "fixed point types")
LANGOPT(SameFBits, 1, 0,
"unsigned and signed fixed point type having the same number of fractional bits")
LANGOPT(PaddingOnUnsignedFixedPoint, 1, 0,
"unsigned fixed point types having one extra padding bit")
#undef LANGOPT
#undef COMPATIBLE_LANGOPT

View File

@ -84,10 +84,11 @@ protected:
unsigned char LongFractWidth, LongFractAlign;
// If true, unsigned fixed point types have the same number of fractional bits
// as their signed counterparts. Otherwise, unsigned fixed point types have
// as their signed counterparts, forcing the unsigned types to have one extra
// bit of padding. Otherwise, unsigned fixed point types have
// one more fractional bit than its corresponding signed type. This is false
// by default.
bool SameFBits;
bool PaddingOnUnsignedFixedPoint;
// Fixed point integral and fractional bit sizes
// Saturated types share the same integral/fractional bits as their
@ -95,7 +96,7 @@ protected:
// For simplicity, the fractional bits in a _Fract type will be one less the
// width of that _Fract type. This leaves all signed _Fract types having no
// padding and unsigned _Fract types will only have 1 bit of padding after the
// sign if SameFBits is set.
// sign if PaddingOnUnsignedFixedPoint is set.
unsigned char ShortAccumScale;
unsigned char AccumScale;
unsigned char LongAccumScale;
@ -436,30 +437,33 @@ public:
/// getUnsignedShortAccumScale/IBits - Return the number of
/// fractional/integral bits in a 'unsigned short _Accum' type.
unsigned getUnsignedShortAccumScale() const {
return SameFBits ? ShortAccumScale : ShortAccumScale + 1;
return PaddingOnUnsignedFixedPoint ? ShortAccumScale : ShortAccumScale + 1;
}
unsigned getUnsignedShortAccumIBits() const {
return SameFBits ? getShortAccumIBits()
: ShortAccumWidth - getUnsignedShortAccumScale();
return PaddingOnUnsignedFixedPoint
? getShortAccumIBits()
: ShortAccumWidth - getUnsignedShortAccumScale();
}
/// getUnsignedAccumScale/IBits - Return the number of fractional/integral
/// bits in a 'unsigned _Accum' type.
unsigned getUnsignedAccumScale() const {
return SameFBits ? AccumScale : AccumScale + 1;
return PaddingOnUnsignedFixedPoint ? AccumScale : AccumScale + 1;
}
unsigned getUnsignedAccumIBits() const {
return SameFBits ? getAccumIBits() : AccumWidth - getUnsignedAccumScale();
return PaddingOnUnsignedFixedPoint ? getAccumIBits()
: AccumWidth - getUnsignedAccumScale();
}
/// getUnsignedLongAccumScale/IBits - Return the number of fractional/integral
/// bits in a 'unsigned long _Accum' type.
unsigned getUnsignedLongAccumScale() const {
return SameFBits ? LongAccumScale : LongAccumScale + 1;
return PaddingOnUnsignedFixedPoint ? LongAccumScale : LongAccumScale + 1;
}
unsigned getUnsignedLongAccumIBits() const {
return SameFBits ? getLongAccumIBits()
: LongAccumWidth - getUnsignedLongAccumScale();
return PaddingOnUnsignedFixedPoint
? getLongAccumIBits()
: LongAccumWidth - getUnsignedLongAccumScale();
}
/// getShortFractScale - Return the number of fractional bits
@ -477,19 +481,21 @@ public:
/// getUnsignedShortFractScale - Return the number of fractional bits
/// in a 'unsigned short _Fract' type.
unsigned getUnsignedShortFractScale() const {
return SameFBits ? getShortFractScale() : getShortFractScale() + 1;
return PaddingOnUnsignedFixedPoint ? getShortFractScale()
: getShortFractScale() + 1;
}
/// getUnsignedFractScale - Return the number of fractional bits
/// in a 'unsigned _Fract' type.
unsigned getUnsignedFractScale() const {
return SameFBits ? getFractScale() : getFractScale() + 1;
return PaddingOnUnsignedFixedPoint ? getFractScale() : getFractScale() + 1;
}
/// getUnsignedLongFractScale - Return the number of fractional bits
/// in a 'unsigned long _Fract' type.
unsigned getUnsignedLongFractScale() const {
return SameFBits ? getLongFractScale() : getLongFractScale() + 1;
return PaddingOnUnsignedFixedPoint ? getLongFractScale()
: getLongFractScale() + 1;
}
/// Determine whether the __int128 type is supported on this target.

View File

@ -36,6 +36,10 @@ def triple_EQ : Joined<["-"], "triple=">, Alias<triple>;
def mfpmath : Separate<["-"], "mfpmath">,
HelpText<"Which unit to use for fp math">;
def fpadding_on_unsigned_fixed_point : Flag<["-"], "fpadding-on-unsigned-fixed-point">,
HelpText<"Force each unsigned fixed point type to have an extra bit of padding to align their scales with those of signed fixed point types">;
def fno_padding_on_unsigned_fixed_point : Flag<["-"], "fno-padding-on-unsigned-fixed-point">;
//===----------------------------------------------------------------------===//
// Analyzer Options
//===----------------------------------------------------------------------===//

View File

@ -893,10 +893,6 @@ def ffixed_point : Flag<["-"], "ffixed-point">, Group<f_Group>,
Flags<[CC1Option]>, HelpText<"Enable fixed point types">;
def fno_fixed_point : Flag<["-"], "fno-fixed-point">, Group<f_Group>,
HelpText<"Disable fixed point types">;
def fsame_fbits : Flag<["-"], "fsame-fbits">, Group<f_Group>,
Flags<[CC1Option]>,
HelpText<"Force each unsigned fixed point type to have the same number of fractional bits as its corresponding signed type">;
def fno_same_fbits : Flag<["-"], "fno-same-fbits">, Group<f_Group>;
// Begin sanitizer flags. These should all be core options exposed in all driver
// modes.

View File

@ -53,7 +53,7 @@ TargetInfo::TargetInfo(const llvm::Triple &T) : TargetOpts(), Triple(T) {
// We give the _Accum 1 fewer fractional bits than their corresponding _Fract
// types by default to have the same number of fractional bits between _Accum
// and _Fract types.
SameFBits = false;
PaddingOnUnsignedFixedPoint = false;
ShortAccumScale = 7;
AccumScale = 15;
LongAccumScale = 31;
@ -377,7 +377,7 @@ void TargetInfo::adjust(LangOptions &Opts) {
// Each unsigned fixed point type has the same number of fractional bits as
// its corresponding signed type.
SameFBits |= Opts.SameFBits;
PaddingOnUnsignedFixedPoint |= Opts.PaddingOnUnsignedFixedPoint;
CheckFixedPointBits();
}

View File

@ -3765,11 +3765,6 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
/*Default=*/false))
Args.AddLastArg(CmdArgs, options::OPT_ffixed_point);
if (Args.hasFlag(options::OPT_fsame_fbits,
options::OPT_fno_same_fbits,
/*Default=*/false))
Args.AddLastArg(CmdArgs, options::OPT_fsame_fbits);
// Handle -{std, ansi, trigraphs} -- take the last of -{std, ansi}
// (-ansi is equivalent to -std=c89 or -std=c++98).
//

View File

@ -2338,8 +2338,9 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK,
Opts.FixedPoint =
Args.hasFlag(OPT_ffixed_point, OPT_fno_fixed_point, /*Default=*/false) &&
!Opts.CPlusPlus;
Opts.SameFBits =
Args.hasFlag(OPT_fsame_fbits, OPT_fno_same_fbits,
Opts.PaddingOnUnsignedFixedPoint =
Args.hasFlag(OPT_fpadding_on_unsigned_fixed_point,
OPT_fno_padding_on_unsigned_fixed_point,
/*Default=*/false) &&
Opts.FixedPoint;

View File

@ -3358,7 +3358,7 @@ ExprResult Sema::ActOnNumericConstant(const Token &Tok, Scope *UDLScope) {
bool Overflowed = Literal.GetFixedPointValue(Val, scale);
// Do not use bit_width since some types may have padding like _Fract or
// unsigned _Accums if SameFBits is set.
// unsigned _Accums if PaddingOnUnsignedFixedPoint is set.
auto MaxVal = llvm::APInt::getMaxValue(ibits + scale).zextOrSelf(bit_width);
if (Literal.isFract && Val == MaxVal + 1)
// Clause 6.4.4 - The value of a constant shall be in the range of

View File

@ -1,5 +1,5 @@
// RUN: %clang -ffixed-point -S -emit-llvm -o - %s | FileCheck %s -check-prefix=DEFAULT
// RUN: %clang -ffixed-point -fsame-fbits -S -emit-llvm -o - %s | FileCheck %s -check-prefix=SAME
// RUN: %clang_cc1 -ffixed-point -fpadding-on-unsigned-fixed-point -S -emit-llvm -o - %s | FileCheck %s -check-prefix=SAME
/* The scale for unsigned fixed point types should be the same as that of signed
* fixed point types when -fsame-fbits is enabled. */