[llvm] [OCaml] Add missing bindings for x86_amx, token, and metadata types (PR #120638)

via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 19 14:56:11 PST 2024


https://github.com/alan-j-hu updated https://github.com/llvm/llvm-project/pull/120638

>From 4f88a3eb3158c23fb8ebb63a48f7390de4142f16 Mon Sep 17 00:00:00 2001
From: Alan Hu <ahulambda at gmail.com>
Date: Thu, 19 Dec 2024 15:56:52 -0500
Subject: [PATCH] [OCaml] Add missing bindings for x86_amx, token, and metadata
 types

---
 llvm/bindings/ocaml/llvm/llvm.ml      |  3 +++
 llvm/bindings/ocaml/llvm/llvm.mli     | 12 ++++++++++++
 llvm/bindings/ocaml/llvm/llvm_ocaml.c | 15 +++++++++++++++
 llvm/test/Bindings/OCaml/core.ml      | 12 ++++++++++++
 4 files changed, 42 insertions(+)

diff --git a/llvm/bindings/ocaml/llvm/llvm.ml b/llvm/bindings/ocaml/llvm/llvm.ml
index 74ba31389b378e..35bc16a60bcfcd 100644
--- a/llvm/bindings/ocaml/llvm/llvm.ml
+++ b/llvm/bindings/ocaml/llvm/llvm.ml
@@ -525,6 +525,9 @@ external vector_size : lltype -> int = "llvm_vector_size"
 (*--... Operations on other types ..........................................--*)
 external void_type : llcontext -> lltype = "llvm_void_type"
 external label_type : llcontext -> lltype = "llvm_label_type"
+external x86_amx_type : llcontext -> lltype = "llvm_x86_amx_type"
+external token_type : llcontext -> lltype = "llvm_token_type"
+external metadata_type : llcontext -> lltype = "llvm_metadata_type"
 external type_by_name : llmodule -> string -> lltype option = "llvm_type_by_name"
 
 external classify_value : llvalue -> ValueKind.t = "llvm_classify_value"
diff --git a/llvm/bindings/ocaml/llvm/llvm.mli b/llvm/bindings/ocaml/llvm/llvm.mli
index 17cad1f43888be..da52ae6033b90e 100644
--- a/llvm/bindings/ocaml/llvm/llvm.mli
+++ b/llvm/bindings/ocaml/llvm/llvm.mli
@@ -766,6 +766,18 @@ val void_type : llcontext -> lltype
     [llvm::Type::LabelTy]. *)
 val label_type : llcontext -> lltype
 
+(** [x86_amx_type c] creates an X86 AMX type in the context [c]. See
+    [llvm::Type::getX86_AMXTy]. *)
+val x86_amx_type : llcontext -> lltype
+
+(** [token_type c] creates a token type in the context [c]. See
+    [llvm::Type::getTokenTy]. *)
+val token_type : llcontext -> lltype
+
+(** [metadata_type c] creates a metadata type in the context [c]. See
+    [llvm::Type::getMetadataTy]. *)
+val metadata_type : llcontext -> lltype
+
 (** [type_by_name m name] returns the specified type from the current module
     if it exists.
     See the method [llvm::Module::getTypeByName] *)
diff --git a/llvm/bindings/ocaml/llvm/llvm_ocaml.c b/llvm/bindings/ocaml/llvm/llvm_ocaml.c
index 5906f427e69072..019e731172a986 100644
--- a/llvm/bindings/ocaml/llvm/llvm_ocaml.c
+++ b/llvm/bindings/ocaml/llvm/llvm_ocaml.c
@@ -686,6 +686,21 @@ value llvm_label_type(value Context) {
   return to_val(LLVMLabelTypeInContext(Context_val(Context)));
 }
 
+/* llcontext -> lltype */
+value llvm_x86_amx_type(value Context) {
+  return to_val(LLVMX86AMXTypeInContext(Context_val(Context)));
+}
+
+/* llcontext -> lltype */
+value llvm_token_type(value Context) {
+  return to_val(LLVMTokenTypeInContext(Context_val(Context)));
+}
+
+/* llcontext -> lltype */
+value llvm_metadata_type(value Context) {
+  return to_val(LLVMMetadataTypeInContext(Context_val(Context)));
+}
+
 /* llmodule -> string -> lltype option */
 value llvm_type_by_name(value M, value Name) {
   return ptr_to_option(LLVMGetTypeByName(Module_val(M), String_val(Name)));
diff --git a/llvm/test/Bindings/OCaml/core.ml b/llvm/test/Bindings/OCaml/core.ml
index 923a3541e239c3..9d42107aff2ab0 100644
--- a/llvm/test/Bindings/OCaml/core.ml
+++ b/llvm/test/Bindings/OCaml/core.ml
@@ -48,11 +48,22 @@ let test_contained_types () =
   insist ([| i32_type; i8_type |] = struct_element_types ar)
 
 (*===-- Pointer types  ----------------------------------------------------===*)
+
 let test_pointer_types () =
+  insist (TypeKind.Pointer = classify_type (pointer_type context));
   insist (0 = address_space (pointer_type context));
   insist (0 = address_space (qualified_pointer_type context 0));
   insist (1 = address_space (qualified_pointer_type context 1))
 
+(*===-- Other types  ------------------------------------------------------===*)
+
+let test_other_types () =
+  insist (TypeKind.Void = classify_type void_type);
+  insist (TypeKind.Label = classify_type (label_type context));
+  insist (TypeKind.X86_amx = classify_type (x86_amx_type context));
+  insist (TypeKind.Token = classify_type (token_type context));
+  insist (TypeKind.Metadata = classify_type (metadata_type context))
+
 (*===-- Conversion --------------------------------------------------------===*)
 
 let test_conversion () =
@@ -1461,6 +1472,7 @@ let _ =
   suite "modules"          test_modules;
   suite "contained types"  test_contained_types;
   suite "pointer types"    test_pointer_types;
+  suite "other types"      test_other_types;
   suite "conversion"       test_conversion;
   suite "target"           test_target;
   suite "constants"        test_constants;



More information about the llvm-commits mailing list