[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 13:01:20 PST 2024
https://github.com/alan-j-hu created https://github.com/llvm/llvm-project/pull/120638
None
>From 5d8a6c0121556062f9f39eefd2faaeab39bc2102 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 | 9 +++++++++
4 files changed, 39 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..b8ce9fb524c709 100644
--- a/llvm/test/Bindings/OCaml/core.ml
+++ b/llvm/test/Bindings/OCaml/core.ml
@@ -53,6 +53,14 @@ let test_pointer_types () =
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 +1469,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