[cfe-commits] r165362 - in /cfe/trunk: include/clang/Basic/Builtins.def lib/AST/ExprConstant.cpp lib/CodeGen/CGBuiltin.cpp test/CodeGen/builtins.c test/Sema/constant-builtins-2.c test/Sema/constant-builtins.c

Benjamin Kramer benny.kra at googlemail.com
Sat Oct 6 07:42:22 PDT 2012


Author: d0k
Date: Sat Oct  6 09:42:22 2012
New Revision: 165362

URL: http://llvm.org/viewvc/llvm-project?rev=165362&view=rev
Log:
Expose __builtin_bswap16.

GCC has always supported this on PowerPC and 4.8 supports it on all platforms,
so it's a good idea to expose it in clang too. LLVM supports this on all targets.

Modified:
    cfe/trunk/include/clang/Basic/Builtins.def
    cfe/trunk/lib/AST/ExprConstant.cpp
    cfe/trunk/lib/CodeGen/CGBuiltin.cpp
    cfe/trunk/test/CodeGen/builtins.c
    cfe/trunk/test/Sema/constant-builtins-2.c
    cfe/trunk/test/Sema/constant-builtins.c

Modified: cfe/trunk/include/clang/Basic/Builtins.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Builtins.def?rev=165362&r1=165361&r2=165362&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/Builtins.def (original)
+++ cfe/trunk/include/clang/Basic/Builtins.def Sat Oct  6 09:42:22 2012
@@ -388,6 +388,7 @@
 
 // FIXME: These type signatures are not correct for targets with int != 32-bits
 // or with ULL != 64-bits.
+BUILTIN(__builtin_bswap16, "UsUs", "nc")
 BUILTIN(__builtin_bswap32, "UiUi", "nc")
 BUILTIN(__builtin_bswap64, "ULLiULLi", "nc")
 

Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=165362&r1=165361&r2=165362&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Sat Oct  6 09:42:22 2012
@@ -4296,6 +4296,7 @@
     return Error(E);
   }
 
+  case Builtin::BI__builtin_bswap16:
   case Builtin::BI__builtin_bswap32:
   case Builtin::BI__builtin_bswap64: {
     APSInt Val;

Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=165362&r1=165361&r2=165362&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Sat Oct  6 09:42:22 2012
@@ -356,6 +356,7 @@
                                         "expval");
     return RValue::get(Result);
   }
+  case Builtin::BI__builtin_bswap16:
   case Builtin::BI__builtin_bswap32:
   case Builtin::BI__builtin_bswap64: {
     Value *ArgValue = EmitScalarExpr(E->getArg(0));

Modified: cfe/trunk/test/CodeGen/builtins.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/builtins.c?rev=165362&r1=165361&r2=165362&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/builtins.c (original)
+++ cfe/trunk/test/CodeGen/builtins.c Sat Oct  6 09:42:22 2012
@@ -113,6 +113,7 @@
 
   // Whatever
 
+  P(bswap16, (N));
   P(bswap32, (N));
   P(bswap64, (N));
   // FIXME

Modified: cfe/trunk/test/Sema/constant-builtins-2.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/constant-builtins-2.c?rev=165362&r1=165361&r2=165362&view=diff
==============================================================================
--- cfe/trunk/test/Sema/constant-builtins-2.c (original)
+++ cfe/trunk/test/Sema/constant-builtins-2.c Sat Oct  6 09:42:22 2012
@@ -48,8 +48,9 @@
 int h0 = __builtin_types_compatible_p(int, float);
 //int h1 = __builtin_choose_expr(1, 10, f());
 //int h2 = __builtin_expect(0, 0);
-int h3 = __builtin_bswap32(0x1234) == 0x34120000 ? 1 : f();
-int h4 = __builtin_bswap64(0x1234) == 0x3412000000000000 ? 1 : f();
+int h3 = __builtin_bswap16(0x1234) == 0x3412 ? 1 : f();
+int h4 = __builtin_bswap32(0x1234) == 0x34120000 ? 1 : f();
+int h5 = __builtin_bswap64(0x1234) == 0x3412000000000000 ? 1 : f();
 extern long int bi0;
 extern __typeof__(__builtin_expect(0, 0)) bi0;
 

Modified: cfe/trunk/test/Sema/constant-builtins.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/constant-builtins.c?rev=165362&r1=165361&r2=165362&view=diff
==============================================================================
--- cfe/trunk/test/Sema/constant-builtins.c (original)
+++ cfe/trunk/test/Sema/constant-builtins.c Sat Oct  6 09:42:22 2012
@@ -16,8 +16,9 @@
 int h0 = __builtin_types_compatible_p(int,float);
 //int h1 = __builtin_choose_expr(1, 10, f());
 //int h2 = __builtin_expect(0, 0);
-int h3 = __builtin_bswap32(0x1234) == 0x34120000 ? 1 : f();
-int h4 = __builtin_bswap64(0x1234) == 0x3412000000000000 ? 1 : f();
+int h3 = __builtin_bswap16(0x1234) == 0x3412 ? 1 : f();
+int h4 = __builtin_bswap32(0x1234) == 0x34120000 ? 1 : f();
+int h5 = __builtin_bswap64(0x1234) == 0x3412000000000000 ? 1 : f();
 
 short somefunc();
 





More information about the cfe-commits mailing list