[PATCH] D67980: [WIP][CLANG][BPF] implement clang __builtin_bitfield_info() intrinsic

Yonghong Song via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 24 14:17:44 PDT 2019


yonghong-song updated this revision to Diff 221598.
yonghong-song edited the summary of this revision.
yonghong-song added a comment.

builtin return u32 instead of u64.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D67980/new/

https://reviews.llvm.org/D67980

Files:
  clang/include/clang/Basic/Builtins.def
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/Sema/SemaChecking.cpp


Index: clang/lib/Sema/SemaChecking.cpp
===================================================================
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -1429,6 +1429,19 @@
     if (SemaBuiltinPreserveAI(*this, TheCall))
       return ExprError();
     break;
+  case Builtin::BI__builtin_bitfield_info: {
+    if (checkArgCount(*this, TheCall, 1))
+      return ExprError();
+
+    Expr *Arg = TheCall->getArg(0);
+    if (Arg->getType()->getAsPlaceholderType())
+      return ExprError();
+    if (Arg->IgnoreParens()->getObjectKind() != OK_BitField)
+      return ExprError();
+
+    TheCall->setType(Context.UnsignedIntTy);
+    break;
+  }
   case Builtin::BI__builtin_call_with_static_chain:
     if (SemaBuiltinCallWithStaticChain(*this, TheCall))
       return ExprError();
Index: clang/lib/CodeGen/CGBuiltin.cpp
===================================================================
--- clang/lib/CodeGen/CGBuiltin.cpp
+++ clang/lib/CodeGen/CGBuiltin.cpp
@@ -1882,6 +1882,13 @@
     IsInPreservedAIRegion = false;
     return RValue::get(Res);
   }
+  case Builtin::BI__builtin_bitfield_info: {
+    const CGBitFieldInfo &Info = EmitLValue(E->getArg(0)).getBitFieldInfo();
+    uint32_t Val = ((Info.StorageOffset.getQuantity() * 8 + Info.Offset) << 8) |
+                   (Info.IsSigned << 7) |
+                   Info.Size;
+    return RValue::get(ConstantInt::get(Int32Ty, Val));
+  }
 
   case Builtin::BI__builtin_cimag:
   case Builtin::BI__builtin_cimagf:
Index: clang/include/clang/Basic/Builtins.def
===================================================================
--- clang/include/clang/Basic/Builtins.def
+++ clang/include/clang/Basic/Builtins.def
@@ -1469,6 +1469,7 @@
 BUILTIN(__builtin_char_memchr, "c*cC*iz", "n")
 BUILTIN(__builtin_dump_struct, "ivC*v*", "tn")
 BUILTIN(__builtin_preserve_access_index, "v.", "t")
+BUILTIN(__builtin_bitfield_info, "Ui.", "t")
 
 // Safestack builtins
 BUILTIN(__builtin___get_unsafe_stack_start, "v*", "Fn")


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D67980.221598.patch
Type: text/x-patch
Size: 2000 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190924/34a400e1/attachment-0001.bin>


More information about the cfe-commits mailing list