r204164 - Creating a printing policy for "half":

Richard Smith richard at metafoo.co.uk
Tue Mar 18 15:34:45 PDT 2014


On Tue, Mar 18, 2014 at 10:55 AM, Yunzhong Gao <
Yunzhong_Gao at playstation.sony.com> wrote:

> Author: ygao
> Date: Tue Mar 18 12:55:18 2014
> New Revision: 204164
>
> URL: http://llvm.org/viewvc/llvm-project?rev=204164&view=rev
> Log:
> Creating a printing policy for "half":
> Since "half" is an OpenCL keyword and clang accepts __fp16 as an extension
> for
> other languages, error messages and metadata (and hence debug info) should
> refer
> to the half-precision floating point as "__fp16" instead of "half" when
> compiling for non-OpenCL languages. This patch creates a new printing
> policy for
> half in a similar manner to what is done for bool and wchar_t.
>
> Differential Revision: http://llvm-reviews.chandlerc.com/D2952
>
>
> Modified:
>     cfe/trunk/include/clang/AST/PrettyPrinter.h
>     cfe/trunk/include/clang/Basic/LangOptions.def
>     cfe/trunk/include/clang/Basic/TokenKinds.def
>     cfe/trunk/lib/AST/Type.cpp
>     cfe/trunk/lib/Basic/IdentifierTable.cpp
>     cfe/trunk/lib/Frontend/CompilerInvocation.cpp
>     cfe/trunk/test/CXX/expr/expr.const/p2-0x.cpp
>     cfe/trunk/test/Sema/variadic-promotion.c
>
> Modified: cfe/trunk/include/clang/AST/PrettyPrinter.h
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/PrettyPrinter.h?rev=204164&r1=204163&r2=204164&view=diff
>
> ==============================================================================
> --- cfe/trunk/include/clang/AST/PrettyPrinter.h (original)
> +++ cfe/trunk/include/clang/AST/PrettyPrinter.h Tue Mar 18 12:55:18 2014
> @@ -41,7 +41,7 @@ struct PrintingPolicy {
>        ConstantArraySizeAsWritten(false), AnonymousTagLocations(true),
>        SuppressStrongLifetime(false), SuppressLifetimeQualifiers(false),
>        Bool(LO.Bool), TerseOutput(false), PolishForDeclaration(false),
> -      MSWChar(LO.MicrosoftExt && !LO.WChar),
> +      Half(LO.Half), MSWChar(LO.MicrosoftExt && !LO.WChar),
>        IncludeNewlines(true) { }
>
>    /// \brief What language we're printing.
> @@ -153,6 +153,10 @@ struct PrintingPolicy {
>    ///
>    unsigned PolishForDeclaration : 1;
>
> +  /// \brief When true, print the half-precision floating-point type as
> 'half'
> +  /// instead of '__fp16'
> +  unsigned Half : 1;
> +
>    /// \brief When true, print the built-in wchar_t type as __wchar_t. For
> use in
>    /// Microsoft mode when wchar_t is not available.
>    unsigned MSWChar : 1;
>
> Modified: cfe/trunk/include/clang/Basic/LangOptions.def
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/LangOptions.def?rev=204164&r1=204163&r2=204164&view=diff
>
> ==============================================================================
> --- cfe/trunk/include/clang/Basic/LangOptions.def (original)
> +++ cfe/trunk/include/clang/Basic/LangOptions.def Tue Mar 18 12:55:18 2014
> @@ -61,6 +61,7 @@ BENIGN_LANGOPT(ObjCInferRelatedResultTyp
>  LANGOPT(Trigraphs         , 1, 0,"trigraphs")
>  LANGOPT(LineComment       , 1, 0, "'//' comments")
>  LANGOPT(Bool              , 1, 0, "bool, true, and false keywords")
> +LANGOPT(Half              , 1, 0, "half keyword")
>  LANGOPT(WChar             , 1, CPlusPlus, "wchar_t keyword")
>  BENIGN_LANGOPT(DollarIdents   , 1, 1, "'$' in identifiers")
>  BENIGN_LANGOPT(AsmPreprocessor, 1, 0, "preprocessor in asm mode")
>
> Modified: cfe/trunk/include/clang/Basic/TokenKinds.def
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TokenKinds.def?rev=204164&r1=204163&r2=204164&view=diff
>
> ==============================================================================
> --- cfe/trunk/include/clang/Basic/TokenKinds.def (original)
> +++ cfe/trunk/include/clang/Basic/TokenKinds.def Tue Mar 18 12:55:18 2014
> @@ -229,6 +229,7 @@ PUNCTUATOR(greatergreatergreater, ">>>")
>  //   KEYALTIVEC - This is a keyword in AltiVec
>  //   KEYBORLAND - This is a keyword if Borland extensions are enabled
>  //   BOOLSUPPORT - This is a keyword if 'bool' is a built-in type
> +//   HALFSUPPORT - This is a keyword if 'half' is a built-in type
>  //   WCHARSUPPORT - This is a keyword if 'wchar_t' is a built-in type
>  //
>  KEYWORD(auto                        , KEYALL)
> @@ -492,7 +493,7 @@ KEYWORD(__pixel                     , KE
>  ALIAS("__fp16", half                , KEYALL)
>
>  // OpenCL Extension.
> -KEYWORD(half                        , KEYOPENCL)
> +KEYWORD(half                        , HALFSUPPORT)
>
>  // Objective-C ARC keywords.
>  KEYWORD(__bridge                     , KEYARC)
>
> Modified: cfe/trunk/lib/AST/Type.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Type.cpp?rev=204164&r1=204163&r2=204164&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/AST/Type.cpp (original)
> +++ cfe/trunk/lib/AST/Type.cpp Tue Mar 18 12:55:18 2014
> @@ -1523,7 +1523,7 @@ StringRef BuiltinType::getName(const Pri
>    case ULong:             return "unsigned long";
>    case ULongLong:         return "unsigned long long";
>    case UInt128:           return "unsigned __int128";
> -  case Half:              return "half";
> +  case Half:              return Policy.Half ? "half" : "__fp16";
>    case Float:             return "float";
>    case Double:            return "double";
>    case LongDouble:        return "long double";
>
> Modified: cfe/trunk/lib/Basic/IdentifierTable.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/IdentifierTable.cpp?rev=204164&r1=204163&r2=204164&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/Basic/IdentifierTable.cpp (original)
> +++ cfe/trunk/lib/Basic/IdentifierTable.cpp Tue Mar 18 12:55:18 2014
> @@ -105,6 +105,7 @@ namespace {
>      KEYARC = 0x800,
>      KEYNOMS = 0x01000,
>      WCHARSUPPORT = 0x02000,
> +    HALFSUPPORT = 0x04000,
>      KEYALL = (0xffff & ~KEYNOMS) // Because KEYNOMS is used to exclude.
>    };
>  }
> @@ -129,6 +130,7 @@ static void AddKeyword(StringRef Keyword
>    else if (LangOpts.MicrosoftExt && (Flags & KEYMS)) AddResult = 1;
>    else if (LangOpts.Borland && (Flags & KEYBORLAND)) AddResult = 1;
>    else if (LangOpts.Bool && (Flags & BOOLSUPPORT)) AddResult = 2;
> +  else if (LangOpts.Half && (Flags && HALFSUPPORT)) AddResult = 2;
>

There's a && here that should be &.


>    else if (LangOpts.WChar && (Flags & WCHARSUPPORT)) AddResult = 2;
>    else if (LangOpts.AltiVec && (Flags & KEYALTIVEC)) AddResult = 2;
>    else if (LangOpts.OpenCL && (Flags & KEYOPENCL)) AddResult = 2;
>
> Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=204164&r1=204163&r2=204164&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original)
> +++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Tue Mar 18 12:55:18 2014
> @@ -1116,6 +1116,9 @@ void CompilerInvocation::setLangDefaults
>    // OpenCL and C++ both have bool, true, false keywords.
>    Opts.Bool = Opts.OpenCL || Opts.CPlusPlus;
>
> +  // OpenCL has half keyword
> +  Opts.Half = Opts.OpenCL;
> +
>    // C++ has wchar_t keyword.
>    Opts.WChar = Opts.CPlusPlus;
>
>
> Modified: cfe/trunk/test/CXX/expr/expr.const/p2-0x.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/expr/expr.const/p2-0x.cpp?rev=204164&r1=204163&r2=204164&view=diff
>
> ==============================================================================
> --- cfe/trunk/test/CXX/expr/expr.const/p2-0x.cpp (original)
> +++ cfe/trunk/test/CXX/expr/expr.const/p2-0x.cpp Tue Mar 18 12:55:18 2014
> @@ -138,7 +138,7 @@ namespace UndefinedBehavior {
>      case (int)(unsigned)(long long)4.4e9: // ok
>      case (int)(float)1e300: // expected-error {{constant expression}}
> expected-note {{value 1.0E+300 is outside the range of representable values
> of type 'float'}} expected-error {{duplicate case value '2147483647'}}
> expected-note {{previous case defined here}}
>      case (int)((float)1e37 / 1e30): // ok
> -    case (int)(__fp16)65536: // expected-error {{constant expression}}
> expected-note {{value 65536 is outside the range of representable values of
> type 'half'}} expected-error {{duplicate case value '2147483647'}}
> +    case (int)(__fp16)65536: // expected-error {{constant expression}}
> expected-note {{value 65536 is outside the range of representable values of
> type '__fp16'}} expected-error {{duplicate case value '2147483647'}}
>        break;
>      }
>    }
>
> Modified: cfe/trunk/test/Sema/variadic-promotion.c
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/variadic-promotion.c?rev=204164&r1=204163&r2=204164&view=diff
>
> ==============================================================================
> --- cfe/trunk/test/Sema/variadic-promotion.c (original)
> +++ cfe/trunk/test/Sema/variadic-promotion.c Tue Mar 18 12:55:18 2014
> @@ -6,7 +6,7 @@ void test_floating_promotion(__fp16 *f16
>    variadic(3, *f16, f32, f64);
>
>  // CHECK: ImplicitCastExpr {{.*}} 'double' <FloatingCast>
> -// CHECK-NEXT: 'half'
> +// CHECK-NEXT: '__fp16'
>
>  // CHECK: ImplicitCastExpr {{.*}} 'double' <FloatingCast>
>  // CHECK-NEXT: 'float'
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140318/0fdcfc40/attachment.html>


More information about the cfe-commits mailing list