[llvm] 42358b6 - [llvm-ocaml] Add and use opaque pointer compatible bindings

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 2 02:42:31 PDT 2022


Author: Nikita Popov
Date: 2022-06-02T11:42:24+02:00
New Revision: 42358b686cfd7394a453cc9c86680376adc7f208

URL: https://github.com/llvm/llvm-project/commit/42358b686cfd7394a453cc9c86680376adc7f208
DIFF: https://github.com/llvm/llvm-project/commit/42358b686cfd7394a453cc9c86680376adc7f208.diff

LOG: [llvm-ocaml] Add and use opaque pointer compatible bindings

Add bindings for LLVMConstGEP2, LLVMAddAlias2, LLVMBuildLoad2,
LLVMBuildInvoke2, LLVMBuildGEP2, LLVMBuildInBoundsGEP2,
LLVMBuildStructGEP2, LLVMBuildPtrDiff2 and use these in tests.

Added: 
    

Modified: 
    llvm/bindings/ocaml/llvm/llvm.ml
    llvm/bindings/ocaml/llvm/llvm.mli
    llvm/bindings/ocaml/llvm/llvm_ocaml.c
    llvm/test/Bindings/OCaml/core.ml

Removed: 
    


################################################################################
diff  --git a/llvm/bindings/ocaml/llvm/llvm.ml b/llvm/bindings/ocaml/llvm/llvm.ml
index 9c79035167b9..b20c113ef32e 100644
--- a/llvm/bindings/ocaml/llvm/llvm.ml
+++ b/llvm/bindings/ocaml/llvm/llvm.ml
@@ -669,6 +669,8 @@ external const_shl : llvalue -> llvalue -> llvalue = "LLVMConstShl"
 external const_lshr : llvalue -> llvalue -> llvalue = "LLVMConstLShr"
 external const_ashr : llvalue -> llvalue -> llvalue = "LLVMConstAShr"
 external const_gep : llvalue -> llvalue array -> llvalue = "llvm_const_gep"
+external const_gep2 : lltype -> llvalue -> llvalue array -> llvalue
+                    = "llvm_const_gep2"
 external const_in_bounds_gep : llvalue -> llvalue array -> llvalue
                             = "llvm_const_in_bounds_gep"
 external const_trunc : llvalue -> lltype -> llvalue = "LLVMConstTrunc"
@@ -812,6 +814,9 @@ let fold_right_globals f m init =
 external add_alias : llmodule -> lltype -> llvalue -> string -> llvalue
                    = "llvm_add_alias"
 
+external add_alias2 : llmodule -> lltype -> int -> llvalue -> string -> llvalue
+                    = "llvm_add_alias2"
+
 (*--... Operations on functions ............................................--*)
 external declare_function : string -> lltype -> llmodule -> llvalue
                           = "llvm_declare_function"
@@ -1223,6 +1228,9 @@ external add_destination : llvalue -> llbasicblock -> unit
 external build_invoke : llvalue -> llvalue array -> llbasicblock ->
                         llbasicblock -> string -> llbuilder -> llvalue
                       = "llvm_build_invoke_bc" "llvm_build_invoke_nat"
+external build_invoke2 : lltype -> llvalue -> llvalue array -> llbasicblock ->
+                         llbasicblock -> string -> llbuilder -> llvalue
+                      = "llvm_build_invoke2_bc" "llvm_build_invoke2_nat"
 external build_landingpad : lltype -> llvalue -> int -> string -> llbuilder ->
                             llvalue = "llvm_build_landingpad"
 external is_cleanup : llvalue -> bool = "llvm_is_cleanup"
@@ -1300,6 +1308,8 @@ external build_array_alloca : lltype -> llvalue -> string -> llbuilder ->
                               llvalue = "llvm_build_array_alloca"
 external build_load : llvalue -> string -> llbuilder -> llvalue
                     = "llvm_build_load"
+external build_load2 : lltype -> llvalue -> string -> llbuilder -> llvalue
+                     = "llvm_build_load2"
 external build_store : llvalue -> llvalue -> llbuilder -> llvalue
                      = "llvm_build_store"
 external build_atomicrmw : AtomicRMWBinOp.t -> llvalue -> llvalue ->
@@ -1309,10 +1319,16 @@ external build_atomicrmw : AtomicRMWBinOp.t -> llvalue -> llvalue ->
                            "llvm_build_atomicrmw_native"
 external build_gep : llvalue -> llvalue array -> string -> llbuilder -> llvalue
                    = "llvm_build_gep"
+external build_gep2 : lltype -> llvalue -> llvalue array -> string -> llbuilder
+                    -> llvalue = "llvm_build_gep2"
 external build_in_bounds_gep : llvalue -> llvalue array -> string ->
                              llbuilder -> llvalue = "llvm_build_in_bounds_gep"
+external build_in_bounds_gep2 : lltype -> llvalue -> llvalue array -> string ->
+                              llbuilder -> llvalue = "llvm_build_in_bounds_gep2"
 external build_struct_gep : llvalue -> int -> string -> llbuilder -> llvalue
                          = "llvm_build_struct_gep"
+external build_struct_gep2 : lltype -> llvalue -> int -> string -> llbuilder ->
+                           llvalue = "llvm_build_struct_gep2"
 
 external build_global_string : string -> string -> llbuilder -> llvalue
                              = "llvm_build_global_string"
@@ -1393,6 +1409,8 @@ external build_is_not_null : llvalue -> string -> llbuilder -> llvalue
                            = "llvm_build_is_not_null"
 external build_ptr
diff  : llvalue -> llvalue -> string -> llbuilder -> llvalue
                        = "llvm_build_ptr
diff "
+external build_ptr
diff 2 : lltype -> llvalue -> llvalue -> string -> llbuilder ->
+                          llvalue = "llvm_build_ptr
diff 2"
 external build_freeze : llvalue -> string -> llbuilder -> llvalue
                       = "llvm_build_freeze"
 

diff  --git a/llvm/bindings/ocaml/llvm/llvm.mli b/llvm/bindings/ocaml/llvm/llvm.mli
index c8f0f14cdf79..af303774e0b9 100644
--- a/llvm/bindings/ocaml/llvm/llvm.mli
+++ b/llvm/bindings/ocaml/llvm/llvm.mli
@@ -1219,6 +1219,12 @@ val const_ashr : llvalue -> llvalue -> llvalue
     See the method [llvm::ConstantExpr::getGetElementPtr]. *)
 val const_gep : llvalue -> llvalue array -> llvalue
 
+(** [const_gep2 srcty pc indices] returns the constant [getElementPtr] of [pc]
+    with source element type [srcty] and the constant integers indices from the
+    array [indices].
+    See the method [llvm::ConstantExpr::getGetElementPtr]. *)
+val const_gep2 : lltype -> llvalue -> llvalue array -> llvalue
+
 (** [const_in_bounds_gep pc indices] returns the constant [getElementPtr] of [pc]
     with the constant integers indices from the array [indices].
     See the method [llvm::ConstantExpr::getInBoundsGetElementPtr]. *)
@@ -1564,6 +1570,10 @@ val set_externally_initialized : bool -> llvalue -> unit
     See the constructor for [llvm::GlobalAlias]. *)
 val add_alias : llmodule -> lltype -> llvalue -> string -> llvalue
 
+(** [add_alias m vt as a n] inserts an alias in the module [m] with the value
+    type [vt] the address space [as] the aliasee [a] with the name [n].
+    See the constructor for [llvm::GlobalAlias]. *)
+val add_alias2 : llmodule -> lltype -> int -> llvalue -> string -> llvalue
 
 (** {7 Operations on functions} *)
 
@@ -2150,6 +2160,13 @@ val add_destination : llvalue -> llbasicblock -> unit
 val build_invoke : llvalue -> llvalue array -> llbasicblock ->
                         llbasicblock -> string -> llbuilder -> llvalue
 
+(** [build_invoke2 fnty fn args tobb unwindbb name b] creates an
+    [%name = invoke %fn(args) to %tobb unwind %unwindbb]
+    instruction at the position specified by the instruction builder [b].
+    See the method [llvm::LLVMBuilder::CreateInvoke]. *)
+val build_invoke2 : lltype -> llvalue -> llvalue array -> llbasicblock ->
+                        llbasicblock -> string -> llbuilder -> llvalue
+
 (** [build_landingpad ty persfn numclauses name b] creates an
     [landingpad]
     instruction at the position specified by the instruction builder [b].
@@ -2390,6 +2407,12 @@ val build_array_alloca : lltype -> llvalue -> string -> llbuilder ->
     See the method [llvm::LLVMBuilder::CreateLoad]. *)
 val build_load : llvalue -> string -> llbuilder -> llvalue
 
+(** [build_load2 ty v name b] creates a
+    [%name = load %ty, %v]
+    instruction at the position specified by the instruction builder [b].
+    See the method [llvm::LLVMBuilder::CreateLoad]. *)
+val build_load2 : lltype -> llvalue -> string -> llbuilder -> llvalue
+
 (** [build_store v p b] creates a
     [store %v, %p]
     instruction at the position specified by the instruction builder [b].
@@ -2410,6 +2433,13 @@ val build_atomicrmw : AtomicRMWBinOp.t -> llvalue -> llvalue ->
     See the method [llvm::LLVMBuilder::CreateGetElementPtr]. *)
 val build_gep : llvalue -> llvalue array -> string -> llbuilder -> llvalue
 
+(** [build_gep2 srcty p indices name b] creates a
+    [%name = getelementptr srcty, %p, indices...]
+    instruction at the position specified by the instruction builder [b].
+    See the method [llvm::LLVMBuilder::CreateGetElementPtr]. *)
+val build_gep2 : lltype -> llvalue -> llvalue array -> string -> llbuilder ->
+                       llvalue
+
 (** [build_in_bounds_gep p indices name b] creates a
     [%name = gelementptr inbounds %p, indices...]
     instruction at the position specified by the instruction builder [b].
@@ -2417,6 +2447,13 @@ val build_gep : llvalue -> llvalue array -> string -> llbuilder -> llvalue
 val build_in_bounds_gep : llvalue -> llvalue array -> string -> llbuilder ->
                                llvalue
 
+(** [build_in_bounds_gep2 srcty p indices name b] creates a
+    [%name = gelementptr inbounds srcty, %p, indices...]
+    instruction at the position specified by the instruction builder [b].
+    See the method [llvm::LLVMBuilder::CreateInBoundsGetElementPtr]. *)
+val build_in_bounds_gep2 : lltype -> llvalue -> llvalue array -> string ->
+                                llbuilder -> llvalue
+
 (** [build_struct_gep p idx name b] creates a
     [%name = getelementptr %p, 0, idx]
     instruction at the position specified by the instruction builder [b].
@@ -2424,6 +2461,13 @@ val build_in_bounds_gep : llvalue -> llvalue array -> string -> llbuilder ->
 val build_struct_gep : llvalue -> int -> string -> llbuilder ->
                             llvalue
 
+(** [build_struct_gep2 srcty p idx name b] creates a
+    [%name = getelementptr srcty, %p, 0, idx]
+    instruction at the position specified by the instruction builder [b].
+    See the method [llvm::LLVMBuilder::CreateStructGetElementPtr]. *)
+val build_struct_gep2 : lltype -> llvalue -> int -> string -> llbuilder ->
+                            llvalue
+
 (** [build_global_string str name b] creates a series of instructions that adds
     a global string at the position specified by the instruction builder [b].
     See the method [llvm::LLVMBuilder::CreateGlobalString]. *)
@@ -2656,6 +2700,13 @@ val build_is_not_null : llvalue -> string -> llbuilder -> llvalue
     See the method [llvm::LLVMBuilder::CreatePtrDiff]. *)
 val build_ptr
diff  : llvalue -> llvalue -> string -> llbuilder -> llvalue
 
+(** [build_ptr
diff 2 elemty lhs rhs name b] creates a series of instructions
+    that measure the 
diff erence between two pointer values in multiples of
+    [elemty] at the position specified by the instruction builder [b].
+    See the method [llvm::LLVMBuilder::CreatePtrDiff]. *)
+val build_ptr
diff 2 : lltype -> llvalue -> llvalue -> string -> llbuilder ->
+                     llvalue
+
 (** [build_freeze x name b] creates a
     [%name = freeze %x]
     instruction at the position specified by the instruction builder [b].

diff  --git a/llvm/bindings/ocaml/llvm/llvm_ocaml.c b/llvm/bindings/ocaml/llvm/llvm_ocaml.c
index fe819d9f92c9..8a1b63aa8bf9 100644
--- a/llvm/bindings/ocaml/llvm/llvm_ocaml.c
+++ b/llvm/bindings/ocaml/llvm/llvm_ocaml.c
@@ -994,6 +994,13 @@ LLVMValueRef llvm_const_gep(LLVMValueRef ConstantVal, value Indices) {
                       Wosize_val(Indices));
 }
 
+/* lltype -> llvalue -> llvalue array -> llvalue */
+LLVMValueRef llvm_const_gep2(LLVMTypeRef Ty, LLVMValueRef ConstantVal,
+                            value Indices) {
+  return LLVMConstGEP2(Ty, ConstantVal, (LLVMValueRef *)Op_val(Indices),
+                       Wosize_val(Indices));
+}
+
 /* llvalue -> llvalue array -> llvalue */
 LLVMValueRef llvm_const_in_bounds_gep(LLVMValueRef ConstantVal, value Indices) {
   return LLVMConstInBoundsGEP(ConstantVal, (LLVMValueRef *)Op_val(Indices),
@@ -1162,7 +1169,7 @@ DEFINE_ITERATORS(global, Global, LLVMModuleRef, LLVMValueRef,
 LLVMValueRef llvm_declare_global(LLVMTypeRef Ty, value Name, LLVMModuleRef M) {
   LLVMValueRef GlobalVar;
   if ((GlobalVar = LLVMGetNamedGlobal(M, String_val(Name)))) {
-    if (LLVMGetElementType(LLVMTypeOf(GlobalVar)) != Ty)
+    if (LLVMGlobalGetValueType(GlobalVar) != Ty)
       return LLVMConstBitCast(GlobalVar, LLVMPointerType(Ty, 0));
     return GlobalVar;
   }
@@ -1175,7 +1182,7 @@ LLVMValueRef llvm_declare_qualified_global(LLVMTypeRef Ty, value Name,
                                            LLVMModuleRef M) {
   LLVMValueRef GlobalVar;
   if ((GlobalVar = LLVMGetNamedGlobal(M, String_val(Name)))) {
-    if (LLVMGetElementType(LLVMTypeOf(GlobalVar)) != Ty)
+    if (LLVMGlobalGetValueType(GlobalVar) != Ty)
       return LLVMConstBitCast(GlobalVar,
                               LLVMPointerType(Ty, Int_val(AddressSpace)));
     return GlobalVar;
@@ -1283,6 +1290,12 @@ LLVMValueRef llvm_add_alias(LLVMModuleRef M, LLVMTypeRef Ty,
   return LLVMAddAlias(M, Ty, Aliasee, String_val(Name));
 }
 
+LLVMValueRef llvm_add_alias2(LLVMModuleRef M, LLVMTypeRef ValueTy,
+                            value AddrSpace, LLVMValueRef Aliasee, value Name) {
+  return LLVMAddAlias2(M, ValueTy, Int_val(AddrSpace), Aliasee,
+                       String_val(Name));
+}
+
 /*--... Operations on functions ............................................--*/
 
 DEFINE_ITERATORS(function, Function, LLVMModuleRef, LLVMValueRef,
@@ -1293,7 +1306,7 @@ LLVMValueRef llvm_declare_function(value Name, LLVMTypeRef Ty,
                                    LLVMModuleRef M) {
   LLVMValueRef Fn;
   if ((Fn = LLVMGetNamedFunction(M, String_val(Name)))) {
-    if (LLVMGetElementType(LLVMTypeOf(Fn)) != Ty)
+    if (LLVMGlobalGetValueType(Fn) != Ty)
       return LLVMConstBitCast(Fn, LLVMPointerType(Ty, 0));
     return Fn;
   }
@@ -1797,6 +1810,25 @@ LLVMValueRef llvm_build_invoke_bc(value Args[], int NumArgs) {
                                (LLVMBasicBlockRef)Args[3], Args[4], Args[5]);
 }
 
+/* lltype -> llvalue -> llvalue array -> llbasicblock -> llbasicblock ->
+   string -> llbuilder -> llvalue */
+LLVMValueRef llvm_build_invoke2_nat(LLVMTypeRef FnTy, LLVMValueRef Fn,
+                                    value Args, LLVMBasicBlockRef Then,
+                                    LLVMBasicBlockRef Catch, value Name,
+                                    value B) {
+  return LLVMBuildInvoke2(Builder_val(B), FnTy, Fn,
+                          (LLVMValueRef *)Op_val(Args), Wosize_val(Args),
+                          Then, Catch, String_val(Name));
+}
+
+/* lltype -> llvalue -> llvalue array -> llbasicblock -> llbasicblock ->
+   string -> llbuilder -> llvalue */
+LLVMValueRef llvm_build_invoke2_bc(value Args[], int NumArgs) {
+  return llvm_build_invoke2_nat((LLVMTypeRef)Args[0], (LLVMValueRef)Args[1],
+                                Args[2], (LLVMBasicBlockRef)Args[3],
+                               (LLVMBasicBlockRef)Args[4], Args[5], Args[6]);
+}
+
 /* lltype -> llvalue -> int -> string -> llbuilder -> llvalue */
 LLVMValueRef llvm_build_landingpad(LLVMTypeRef Ty, LLVMValueRef PersFn,
                                    value NumClauses, value Name, value B) {
@@ -2026,6 +2058,12 @@ LLVMValueRef llvm_build_load(LLVMValueRef Pointer, value Name, value B) {
   return LLVMBuildLoad(Builder_val(B), Pointer, String_val(Name));
 }
 
+/* lltype -> llvalue -> string -> llbuilder -> llvalue */
+LLVMValueRef llvm_build_load2(LLVMTypeRef Ty, LLVMValueRef Pointer, value Name,
+                              value B) {
+  return LLVMBuildLoad2(Builder_val(B), Ty, Pointer, String_val(Name));
+}
+
 /* llvalue -> llvalue -> llbuilder -> llvalue */
 LLVMValueRef llvm_build_store(LLVMValueRef Value, LLVMValueRef Pointer,
                               value B) {
@@ -2057,6 +2095,14 @@ LLVMValueRef llvm_build_gep(LLVMValueRef Pointer, value Indices, value Name,
                       Wosize_val(Indices), String_val(Name));
 }
 
+/* lltype -> llvalue -> llvalue array -> string -> llbuilder -> llvalue */
+LLVMValueRef llvm_build_gep2(LLVMTypeRef Ty, LLVMValueRef Pointer,
+                             value Indices, value Name, value B) {
+  return LLVMBuildGEP2(Builder_val(B), Ty, Pointer,
+                       (LLVMValueRef *)Op_val(Indices), Wosize_val(Indices),
+                       String_val(Name));
+}
+
 /* llvalue -> llvalue array -> string -> llbuilder -> llvalue */
 LLVMValueRef llvm_build_in_bounds_gep(LLVMValueRef Pointer, value Indices,
                                       value Name, value B) {
@@ -2065,6 +2111,14 @@ LLVMValueRef llvm_build_in_bounds_gep(LLVMValueRef Pointer, value Indices,
                               Wosize_val(Indices), String_val(Name));
 }
 
+/* lltype -> llvalue -> llvalue array -> string -> llbuilder -> llvalue */
+LLVMValueRef llvm_build_in_bounds_gep2(LLVMTypeRef Ty, LLVMValueRef Pointer,
+                                       value Indices, value Name, value B) {
+  return LLVMBuildInBoundsGEP2(Builder_val(B), Ty, Pointer,
+                               (LLVMValueRef *)Op_val(Indices),
+                               Wosize_val(Indices), String_val(Name));
+}
+
 /* llvalue -> int -> string -> llbuilder -> llvalue */
 LLVMValueRef llvm_build_struct_gep(LLVMValueRef Pointer, value Index,
                                    value Name, value B) {
@@ -2072,6 +2126,13 @@ LLVMValueRef llvm_build_struct_gep(LLVMValueRef Pointer, value Index,
                             String_val(Name));
 }
 
+/* lltype -> llvalue -> int -> string -> llbuilder -> llvalue */
+LLVMValueRef llvm_build_struct_gep2(LLVMTypeRef Ty, LLVMValueRef Pointer,
+                                    value Index, value Name, value B) {
+  return LLVMBuildStructGEP2(Builder_val(B), Ty, Pointer, Int_val(Index),
+                             String_val(Name));
+}
+
 /* string -> string -> llbuilder -> llvalue */
 LLVMValueRef llvm_build_global_string(value Str, value Name, value B) {
   return LLVMBuildGlobalString(Builder_val(B), String_val(Str),
@@ -2314,6 +2375,12 @@ LLVMValueRef llvm_build_ptr
diff (LLVMValueRef LHS, LLVMValueRef RHS, value Name,
   return LLVMBuildPtrDiff(Builder_val(B), LHS, RHS, String_val(Name));
 }
 
+/* llvalue -> llvalue -> string -> llbuilder -> llvalue */
+LLVMValueRef llvm_build_ptr
diff 2(LLVMTypeRef ElemTy, LLVMValueRef LHS,
+                                 LLVMValueRef RHS, value Name, value B) {
+  return LLVMBuildPtrDiff2(Builder_val(B), ElemTy, LHS, RHS, String_val(Name));
+}
+
 /* llvalue -> string -> llbuilder -> llvalue */
 LLVMValueRef llvm_build_freeze(LLVMValueRef X, value Name, value B) {
   return LLVMBuildFreeze(Builder_val(B), X, String_val(Name));

diff  --git a/llvm/test/Bindings/OCaml/core.ml b/llvm/test/Bindings/OCaml/core.ml
index 5eeb27155dd7..41200cad4996 100644
--- a/llvm/test/Bindings/OCaml/core.ml
+++ b/llvm/test/Bindings/OCaml/core.ml
@@ -213,7 +213,7 @@ let test_constants () =
   ignore (define_global "const_all_ones" c m);
 
   group "pointer null"; begin
-    (* CHECK: const_pointer_null = global i64* null
+    (* CHECK: const_pointer_null = global ptr null
      *)
     let c = const_pointer_null (pointer_type i64_type) in
     ignore (define_global "const_pointer_null" c m);
@@ -329,8 +329,8 @@ let test_constants () =
   ignore (define_global "const_fptoui" (const_fptoui ffoldbomb i32_type) m);
   ignore (define_global "const_fptosi" (const_fptosi ffoldbomb i32_type) m);
   ignore (define_global "const_ptrtoint" (const_ptrtoint
-    (const_gep (const_null (pointer_type i8_type))
-               [| const_int i32_type 1 |])
+    (const_gep2 i8_type (const_null (pointer_type i8_type))
+                [| const_int i32_type 1 |])
     i32_type) m);
   ignore (define_global "const_inttoptr" (const_inttoptr (const_add foldbomb five)
                                                   void_ptr) m);
@@ -347,7 +347,8 @@ let test_constants () =
    * CHECK: const_shufflevector = global <4 x i32> <i32 0, i32 1, i32 1, i32 0>
    *)
   ignore (define_global "const_size_of" (size_of (pointer_type i8_type)) m);
-  ignore (define_global "const_gep" (const_gep foldbomb_gv [| five |]) m);
+  ignore (define_global "const_gep" (const_gep2 i8_type foldbomb_gv [| five |])
+          m);
   ignore (define_global "const_select" (const_select
     (const_icmp Icmp.Sle foldbomb five)
     (const_int i8_type (-1))
@@ -630,7 +631,7 @@ let test_users () =
   let p1 = param fn 0 in
   let p2 = param fn 1 in
   let a3 = build_alloca i32_type "user_alloca" b in
-  let p3 = build_load a3 "user_load" b in
+  let p3 = build_load2 i32_type a3 "user_load" b in
   let i = build_add p1 p2 "sum" b in
 
   insist ((num_operands i) = 2);
@@ -647,11 +648,11 @@ let test_users () =
 (*===-- Aliases -----------------------------------------------------------===*)
 
 let test_aliases () =
-  (* CHECK: @alias = alias i32, i32* @aliasee
+  (* CHECK: @alias = alias i32, ptr @aliasee
    *)
   let forty_two32 = const_int i32_type 42 in
   let v = define_global "aliasee" forty_two32 m in
-  ignore (add_alias m (pointer_type i32_type) v "alias")
+  ignore (add_alias2 m i32_type 0 v "alias")
 
 
 (*===-- Functions ---------------------------------------------------------===*)
@@ -1017,14 +1018,13 @@ let test_builder () =
      * CHECK-DAG: %build_fptrunc2 = fptrunc double %build_sitofp to float
      * CHECK-DAG: %build_fpext = fpext float %build_fptrunc to double
      * CHECK-DAG: %build_fpext2 = fpext float %build_fptrunc to double
-     * CHECK-DAG: %build_inttoptr = inttoptr i32 %P1 to i8*
-     * CHECK-DAG: %build_ptrtoint = ptrtoint i8* %build_inttoptr to i64
-     * CHECK-DAG: %build_ptrtoint2 = ptrtoint i8* %build_inttoptr to i64
+     * CHECK-DAG: %build_inttoptr = inttoptr i32 %P1 to ptr
+     * CHECK-DAG: %build_ptrtoint = ptrtoint ptr %build_inttoptr to i64
+     * CHECK-DAG: %build_ptrtoint2 = ptrtoint ptr %build_inttoptr to i64
      * CHECK-DAG: %build_bitcast = bitcast i64 %build_ptrtoint to double
      * CHECK-DAG: %build_bitcast2 = bitcast i64 %build_ptrtoint to double
      * CHECK-DAG: %build_bitcast3 = bitcast i64 %build_ptrtoint to double
      * CHECK-DAG: %build_bitcast4 = bitcast i64 %build_ptrtoint to double
-     * CHECK-DAG: %build_pointercast = bitcast i8* %build_inttoptr to i16*
      *)
     let inst28 = build_trunc p1 i8_type "build_trunc" atentry in
     let inst29 = build_zext inst28 i32_type "build_zext" atentry in
@@ -1059,7 +1059,7 @@ let test_builder () =
      * CHECK: %build_fcmp_false = fcmp false float %F1, %F2
      * CHECK: %build_fcmp_true = fcmp true float %F2, %F1
      * CHECK: %build_is_null{{.*}}= icmp eq{{.*}}%X0,{{.*}}null
-     * CHECK: %build_is_not_null = icmp ne i8* %X1, null
+     * CHECK: %build_is_not_null = icmp ne ptr %X1, null
      * CHECK: %build_ptr
diff 
      *)
     let c = build_icmp Icmp.Ne    p1 p2 "build_icmp_ne" atentry in
@@ -1080,17 +1080,17 @@ let test_builder () =
 
     let g0 = declare_global (pointer_type i8_type) "g0" m in
     let g1 = declare_global (pointer_type i8_type) "g1" m in
-    let p0 = build_load g0 "X0" atentry in
-    let p1 = build_load g1 "X1" atentry in
+    let p0 = build_load2 (pointer_type i8_type) g0 "X0" atentry in
+    let p1 = build_load2 (pointer_type i8_type) g1 "X1" atentry in
     ignore (build_is_null p0 "build_is_null" atentry);
     ignore (build_is_not_null p1 "build_is_not_null" atentry);
-    ignore (build_ptr
diff  p1 p0 "build_ptr
diff " atentry);
+    ignore (build_ptr
diff 2 i8_type p1 p0 "build_ptr
diff " atentry);
   end;
 
   group "miscellaneous"; begin
     (* CHECK: %build_call = tail call cc63 zeroext i32 @{{.*}}(i32 signext %P2, i32 %P1)
      * CHECK: %build_select = select i1 %build_icmp, i32 %P1, i32 %P2
-     * CHECK: %build_va_arg = va_arg i8** null, i32
+     * CHECK: %build_va_arg = va_arg ptr null, i32
      * CHECK: %build_extractelement = extractelement <4 x i32> %Vec1, i32 %P2
      * CHECK: %build_insertelement = insertelement <4 x i32> %Vec1, i32 %P1, i32 %P2
      * CHECK: %build_shufflevector = shufflevector <4 x i32> %Vec1, <4 x i32> %Vec2, <4 x i32> <i32 1, i32 1, i32 0, i32 0>
@@ -1143,7 +1143,7 @@ let test_builder () =
     ignore (build_shufflevector vec1 vec2 t3 "build_shufflevector" atentry);
 
     let p = build_alloca sty "ba" atentry in
-    let agg = build_load p "bl" atentry in
+    let agg = build_load2 sty p "bl" atentry in
     let agg0 = build_insertvalue agg (const_int i32_type 1) 0
                  "build_insertvalue0" atentry in
     let agg1 = build_insertvalue agg0 (const_int i8_type 2) 1
@@ -1218,7 +1218,7 @@ let test_builder () =
       end;
       (* CHECK: landingpad
        * CHECK: cleanup
-       * CHECK: catch{{.*}}i8**{{.*}}@_ZTIc
+       * CHECK: catch{{.*}}ptr{{.*}}@_ZTIc
        * CHECK: filter{{.*}}@_ZTIPKc{{.*}}@_ZTId
        * CHECK: resume
        * *)
@@ -1268,7 +1268,7 @@ let test_builder () =
 
   group "malloc/free"; begin
       (* CHECK: call{{.*}}@malloc(i32 ptrtoint
-       * CHECK: call{{.*}}@free(i8*
+       * CHECK: call{{.*}}@free(ptr
        * CHECK: call{{.*}}@malloc(i32 %
        *)
       let bb1 = append_block context "MallocBlock1" fn in
@@ -1280,7 +1280,7 @@ let test_builder () =
   end;
 
   group "indirectbr"; begin
-    (* CHECK: indirectbr i8* blockaddress(@X7, %IBRBlock2), [label %IBRBlock2, label %IBRBlock3]
+    (* CHECK: indirectbr ptr blockaddress(@X7, %IBRBlock2), [label %IBRBlock2, label %IBRBlock3]
      *)
     let bb1 = append_block context "IBRBlock1" fn in
 
@@ -1302,7 +1302,7 @@ let test_builder () =
      *)
     let bb04 = append_block context "Bb04" fn in
     let b = builder_at_end context bb04 in
-    ignore (build_invoke fn [| p1; p2 |] bb04 bblpad "build_invoke" b)
+    ignore (build_invoke2 fty fn [| p1; p2 |] bb04 bblpad "build_invoke" b)
   end;
 
   group "unreachable"; begin
@@ -1389,17 +1389,17 @@ let test_builder () =
 
     (* CHECK: %build_alloca = alloca i32
      * CHECK: %build_array_alloca = alloca i32, i32 %P2
-     * CHECK: %build_load = load volatile i32, i32* %build_array_alloca, align 4
-     * CHECK: store volatile i32 %P2, i32* %build_alloca, align 4
-     * CHECK: %build_gep = getelementptr i32, i32* %build_array_alloca, i32 %P2
-     * CHECK: %build_in_bounds_gep = getelementptr inbounds i32, i32* %build_array_alloca, i32 %P2
+     * CHECK: %build_load = load volatile i32, ptr %build_array_alloca, align 4
+     * CHECK: store volatile i32 %P2, ptr %build_alloca, align 4
+     * CHECK: %build_gep = getelementptr i32, ptr %build_array_alloca, i32 %P2
+     * CHECK: %build_in_bounds_gep = getelementptr inbounds i32, ptr %build_array_alloca, i32 %P2
      * CHECK: %build_struct_gep = getelementptr inbounds{{.*}}%build_alloca2, i32 0, i32 1
-     * CHECK: %build_atomicrmw = atomicrmw xchg i8* %p, i8 42 seq_cst
+     * CHECK: %build_atomicrmw = atomicrmw xchg ptr %p, i8 42 seq_cst
      *)
     let alloca = build_alloca i32_type "build_alloca" b in
     let array_alloca = build_array_alloca i32_type p2 "build_array_alloca" b in
 
-    let load = build_load array_alloca "build_load" b in
+    let load = build_load2 i32_type array_alloca "build_load" b in
     ignore(set_alignment 4 load);
     ignore(set_volatile true load);
     insist(true = is_volatile load);
@@ -1410,12 +1410,13 @@ let test_builder () =
     ignore(set_alignment 4 store);
     insist(true = is_volatile store);
     insist(4 = alignment store);
-    ignore(build_gep array_alloca [| p2 |] "build_gep" b);
-    ignore(build_in_bounds_gep array_alloca [| p2 |] "build_in_bounds_gep" b);
+    ignore(build_gep2 i32_type array_alloca [| p2 |] "build_gep" b);
+    ignore(build_in_bounds_gep2 i32_type array_alloca [| p2 |]
+           "build_in_bounds_gep" b);
 
     let sty = struct_type context [| i32_type; i8_type |] in
     let alloca2 = build_alloca sty "build_alloca2" b in
-    ignore(build_struct_gep alloca2 1 "build_struct_gep" b);
+    ignore(build_struct_gep2 sty alloca2 1 "build_struct_gep" b);
 
     let p = build_alloca i8_type "p" b in
     ignore(build_atomicrmw AtomicRMWBinOp.Xchg p (const_int i8_type 42)


        


More information about the llvm-commits mailing list