edward-jones created this revision.

This makes it possible to specify a bit width after the 'i' integer type 
specifier when defining builtins. The bswap and bitreverse builtins have been 
updated so that their definitions use fixed-width types instead of short, int 
and long, so that they work on targets where int != 32-bits and long != 64 bits.


https://reviews.llvm.org/D34103

Files:
  include/clang/Basic/Builtins.def
  lib/AST/ASTContext.cpp
  test/CodeGen/builtins.c

Index: test/CodeGen/builtins.c
===================================================================
--- test/CodeGen/builtins.c
+++ test/CodeGen/builtins.c
@@ -111,8 +111,9 @@
   P(object_size, (s0, 2));
   P(object_size, (s0, 3));
 
-  // Whatever
-
+  // CHECK: @llvm.bswap.i16
+  // CHECK: @llvm.bswap.i32
+  // CHECK: @llvm.bswap.i64
   P(bswap16, (N));
   P(bswap32, (N));
   P(bswap64, (N));
@@ -603,4 +604,4 @@
   __builtin_os_log_format(buf, "%s %% %s", data1, data2);
 }
 
-#endif
\ No newline at end of file
+#endif
Index: lib/AST/ASTContext.cpp
===================================================================
--- lib/AST/ASTContext.cpp
+++ lib/AST/ASTContext.cpp
@@ -8585,16 +8585,26 @@
     else
       Type = Context.ShortTy;
     break;
-  case 'i':
-    if (HowLong == 3)
-      Type = Unsigned ? Context.UnsignedInt128Ty : Context.Int128Ty;
-    else if (HowLong == 2)
-      Type = Unsigned ? Context.UnsignedLongLongTy : Context.LongLongTy;
-    else if (HowLong == 1)
-      Type = Unsigned ? Context.UnsignedLongTy : Context.LongTy;
-    else
-      Type = Unsigned ? Context.UnsignedIntTy : Context.IntTy;
+  case 'i': {
+    char *End;
+    unsigned BitWidth = strtoul(Str, &End, 10);
+    if (End != Str) {
+      // Optional fixed width modifier
+      Str = End;
+      assert(HowLong == 0 && "Bad modifiers used with fixed-width integer");
+      Type = Context.getIntTypeForBitwidth(BitWidth, !Unsigned);
+    } else {
+      if (HowLong == 3)
+        Type = Unsigned ? Context.UnsignedInt128Ty : Context.Int128Ty;
+      else if (HowLong == 2)
+        Type = Unsigned ? Context.UnsignedLongLongTy : Context.LongLongTy;
+      else if (HowLong == 1)
+        Type = Unsigned ? Context.UnsignedLongTy : Context.LongTy;
+      else
+        Type = Unsigned ? Context.UnsignedIntTy : Context.IntTy;
+    }
     break;
+  }
   case 'c':
     assert(HowLong == 0 && "Bad modifiers used with 'c'!");
     if (Signed)
Index: include/clang/Basic/Builtins.def
===================================================================
--- include/clang/Basic/Builtins.def
+++ include/clang/Basic/Builtins.def
@@ -24,7 +24,7 @@
 //  b -> boolean
 //  c -> char
 //  s -> short
-//  i -> int
+//  i -> int, optionally followed by the bit width of the integer type
 //  h -> half
 //  f -> float
 //  d -> double
@@ -47,7 +47,9 @@
 //  p -> pid_t
 //  . -> "...".  This may only occur at the end of the function list.
 //
-// Types may be prefixed with the following modifiers:
+// Types may be prefixed with a number of modifiers. Modifiers which affect
+// the width of the integer type cannot be used if the integer is specified
+// as a fixed-width type.
 //  L   -> long (e.g. Li for 'long int')
 //  LL  -> long long
 //  LLL -> __int128_t (e.g. LLLi)
@@ -406,16 +408,14 @@
 BUILTIN(__builtin_popcountl , "iULi" , "nc")
 BUILTIN(__builtin_popcountll, "iULLi", "nc")
 
-// 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")
+BUILTIN(__builtin_bswap16, "Ui16Ui16", "nc")
+BUILTIN(__builtin_bswap32, "Ui32Ui32", "nc")
+BUILTIN(__builtin_bswap64, "Ui64Ui64", "nc")
 
-BUILTIN(__builtin_bitreverse8, "UcUc", "nc")
-BUILTIN(__builtin_bitreverse16, "UsUs", "nc")
-BUILTIN(__builtin_bitreverse32, "UiUi", "nc")
-BUILTIN(__builtin_bitreverse64, "ULLiULLi", "nc")
+BUILTIN(__builtin_bitreverse8,  "Ui8Ui8", "nc")
+BUILTIN(__builtin_bitreverse16, "Ui16Ui16", "nc")
+BUILTIN(__builtin_bitreverse32, "Ui32Ui32", "nc")
+BUILTIN(__builtin_bitreverse64, "Ui64Ui64", "nc")
 
 // Random GCC builtins
 BUILTIN(__builtin_constant_p, "i.", "nctu")
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to