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

Leonard Chan via cfe-commits cfe-commits at lists.llvm.org
Fri Jun 29 10:08:20 PDT 2018


Author: leonardchan
Date: Fri Jun 29 10:08:19 2018
New Revision: 335993

URL: http://llvm.org/viewvc/llvm-project?rev=335993&view=rev
Log:
[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

Modified:
    cfe/trunk/include/clang/Basic/LangOptions.def
    cfe/trunk/include/clang/Basic/TargetInfo.h
    cfe/trunk/include/clang/Driver/CC1Options.td
    cfe/trunk/include/clang/Driver/Options.td
    cfe/trunk/lib/Basic/TargetInfo.cpp
    cfe/trunk/lib/Driver/ToolChains/Clang.cpp
    cfe/trunk/lib/Frontend/CompilerInvocation.cpp
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/test/Frontend/fixed_point_same_fbits.c

Modified: cfe/trunk/include/clang/Basic/LangOptions.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/LangOptions.def?rev=335993&r1=335992&r2=335993&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/LangOptions.def (original)
+++ cfe/trunk/include/clang/Basic/LangOptions.def Fri Jun 29 10:08:19 2018
@@ -306,8 +306,8 @@ ENUM_LANGOPT(ClangABICompat, ClangABI, 4
 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

Modified: cfe/trunk/include/clang/Basic/TargetInfo.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TargetInfo.h?rev=335993&r1=335992&r2=335993&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/TargetInfo.h (original)
+++ cfe/trunk/include/clang/Basic/TargetInfo.h Fri Jun 29 10:08:19 2018
@@ -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.

Modified: cfe/trunk/include/clang/Driver/CC1Options.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/CC1Options.td?rev=335993&r1=335992&r2=335993&view=diff
==============================================================================
--- cfe/trunk/include/clang/Driver/CC1Options.td (original)
+++ cfe/trunk/include/clang/Driver/CC1Options.td Fri Jun 29 10:08:19 2018
@@ -36,6 +36,10 @@ def triple_EQ : Joined<["-"], "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
 //===----------------------------------------------------------------------===//

Modified: cfe/trunk/include/clang/Driver/Options.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=335993&r1=335992&r2=335993&view=diff
==============================================================================
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Fri Jun 29 10:08:19 2018
@@ -893,10 +893,6 @@ def ffixed_point : Flag<["-"], "ffixed-p
                    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.

Modified: cfe/trunk/lib/Basic/TargetInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/TargetInfo.cpp?rev=335993&r1=335992&r2=335993&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/TargetInfo.cpp (original)
+++ cfe/trunk/lib/Basic/TargetInfo.cpp Fri Jun 29 10:08:19 2018
@@ -53,7 +53,7 @@ TargetInfo::TargetInfo(const llvm::Tripl
   // 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 &Opt
 
   // Each unsigned fixed point type has the same number of fractional bits as
   // its corresponding signed type.
-  SameFBits |= Opts.SameFBits;
+  PaddingOnUnsignedFixedPoint |= Opts.PaddingOnUnsignedFixedPoint;
   CheckFixedPointBits();
 }
 

Modified: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Clang.cpp?rev=335993&r1=335992&r2=335993&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp Fri Jun 29 10:08:19 2018
@@ -3765,11 +3765,6 @@ void Clang::ConstructJob(Compilation &C,
                    /*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).
   //

Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=335993&r1=335992&r2=335993&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Fri Jun 29 10:08:19 2018
@@ -2338,8 +2338,9 @@ static void ParseLangArgs(LangOptions &O
   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;
 

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=335993&r1=335992&r2=335993&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Fri Jun 29 10:08:19 2018
@@ -3358,7 +3358,7 @@ ExprResult Sema::ActOnNumericConstant(co
     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

Modified: cfe/trunk/test/Frontend/fixed_point_same_fbits.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Frontend/fixed_point_same_fbits.c?rev=335993&r1=335992&r2=335993&view=diff
==============================================================================
--- cfe/trunk/test/Frontend/fixed_point_same_fbits.c (original)
+++ cfe/trunk/test/Frontend/fixed_point_same_fbits.c Fri Jun 29 10:08:19 2018
@@ -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. */




More information about the cfe-commits mailing list