[PATCH] D97763: Add type attributes to LLVM C API

Christoffer Lerno via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 2 04:51:05 PST 2021


lerno created this revision.
lerno added reviewers: arsenm, t.p.northover, deadalnix.
Herald added subscribers: dexonsmith, hiraditya.
lerno requested review of this revision.
Herald added subscribers: llvm-commits, wdng.
Herald added a project: LLVM.

The LLVM C API is missing type attributes as is needed by attributes such as sret and byval. This patch adds three missing wrapper functions.

Bugzilla: https://bugs.llvm.org/show_bug.cgi?id=48249


https://reviews.llvm.org/D97763

Files:
  llvm/include/llvm-c/Core.h
  llvm/lib/IR/Core.cpp


Index: llvm/lib/IR/Core.cpp
===================================================================
--- llvm/lib/IR/Core.cpp
+++ llvm/lib/IR/Core.cpp
@@ -164,6 +164,18 @@
   return Attr.getValueAsInt();
 }
 
+LLVMAttributeRef LLVMCreateTypeAttribute(LLVMContextRef C, unsigned KindID,
+                                         LLVMTypeRef type_ref) {
+  auto &Ctx = *unwrap(C);
+  auto AttrKind = (Attribute::AttrKind)KindID;
+  return wrap(Attribute::get(Ctx, AttrKind, unwrap(type_ref)));
+}
+
+LLVMTypeRef LLVMGetTypeAttributeValue(LLVMAttributeRef A) {
+  auto Attr = unwrap(A);
+  return wrap(Attr.getValueAsType());
+}
+
 LLVMAttributeRef LLVMCreateStringAttribute(LLVMContextRef C,
                                            const char *K, unsigned KLength,
                                            const char *V, unsigned VLength) {
@@ -194,6 +206,10 @@
   return unwrap(A).isStringAttribute();
 }
 
+LLVMBool LLVMIsTypeAttribute(LLVMAttributeRef A) {
+  return unwrap(A).isTypeAttribute();
+}
+
 char *LLVMGetDiagInfoDescription(LLVMDiagnosticInfoRef DI) {
   std::string MsgStorage;
   raw_string_ostream Stream(MsgStorage);
Index: llvm/include/llvm-c/Core.h
===================================================================
--- llvm/include/llvm-c/Core.h
+++ llvm/include/llvm-c/Core.h
@@ -604,6 +604,17 @@
  */
 uint64_t LLVMGetEnumAttributeValue(LLVMAttributeRef A);
 
+/**
+ * Create a type attribute
+ */
+LLVMAttributeRef LLVMCreateTypeAttribute(LLVMContextRef C, unsigned KindID,
+                                         LLVMTypeRef type_ref);
+
+/**
+ * Get the type attribute's value.
+ */
+LLVMTypeRef LLVMGetTypeAttributeValue(LLVMAttributeRef A);
+
 /**
  * Create a string attribute.
  */
@@ -626,6 +637,7 @@
  */
 LLVMBool LLVMIsEnumAttribute(LLVMAttributeRef A);
 LLVMBool LLVMIsStringAttribute(LLVMAttributeRef A);
+LLVMBool LLVMIsTypeAttribute(LLVMAttributeRef A);
 
 /**
  * Obtain a Type from a context by its registered name.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D97763.327410.patch
Type: text/x-patch
Size: 1959 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210302/03f6f2fe/attachment.bin>


More information about the llvm-commits mailing list