@@ -15,7 +15,7 @@ use melior::{
1515
1616use crate :: {
1717 error:: { Error , Result } ,
18- utils:: { BlockExt , GepIndex } ,
18+ utils:: BlockExt ,
1919} ;
2020
2121#[ derive( Clone , Copy , Debug , Hash , PartialEq , Eq ) ]
@@ -142,7 +142,7 @@ impl LibfuncCounterMeta {
142142 module : & Module ,
143143 block : & ' a Block < ' c > ,
144144 location : Location ,
145- libfunc_amount : u32
145+ libfunc_amount : u32 ,
146146 ) -> Result < ( ) > {
147147 let array_ty = llvm:: r#type:: array ( IntegerType :: new ( context, 32 ) . into ( ) , libfunc_amount) ;
148148
@@ -166,12 +166,10 @@ impl LibfuncCounterMeta {
166166 . into ( ) ,
167167 ) ?;
168168
169- let array_counter_ptr = block. load ( context, location, global_address, array_ty) ?;
170-
171169 block. append_operation (
172170 OperationBuilder :: new ( "llvm.call" , location)
173171 . add_operands ( & [ function_ptr] )
174- . add_operands ( & [ counter_id, array_counter_ptr , lifuncs_amount] )
172+ . add_operands ( & [ counter_id, global_address , lifuncs_amount] )
175173 . build ( ) ?,
176174 ) ;
177175
@@ -212,15 +210,6 @@ impl LibfuncCounterMeta {
212210 . into ( ) ,
213211 ) ?;
214212
215- let array_counter_ptr = block. load ( context, location, global_address, array_ty) ?;
216-
217- block. insert_values (
218- context,
219- location,
220- array_counter_ptr,
221- & vec ! [ k0; libfunc_amount as usize ] ,
222- ) ?;
223-
224213 Ok ( ( ) )
225214 }
226215
@@ -241,7 +230,7 @@ impl LibfuncCounterMeta {
241230 let array_ty = llvm:: r#type:: array ( u32_ty, libfuncs_amount) ;
242231 let k1 = block. const_int ( context, location, 1 , 32 ) ?;
243232
244- let global_address = block. append_op_result (
233+ let array_counter_ptr = block. append_op_result (
245234 ods:: llvm:: mlir_addressof (
246235 context,
247236 llvm:: r#type:: pointer ( context, 0 ) ,
@@ -251,25 +240,21 @@ impl LibfuncCounterMeta {
251240 . into ( ) ,
252241 ) ?;
253242
254- let array_counter_ptr = block. load ( context, location, global_address , array_ty) ?;
243+ let array_counter = block. load ( context, location, array_counter_ptr , array_ty) ?;
255244
256- let value_counter = block. gep (
257- context,
258- location,
259- array_counter_ptr,
260- & [ GepIndex :: Const ( libfunc_idx as i32 ) ] ,
261- u32_ty,
262- ) ?;
245+ let value_counter = block. extract_value ( context, location, array_counter, u32_ty, libfunc_idx) ?;
263246 let value_incremented = block. addi ( value_counter, k1, location) ?;
264-
265- block. insert_value (
247+
248+ let array_counter = block. insert_value (
266249 context,
267250 location,
268- array_counter_ptr ,
251+ array_counter ,
269252 value_incremented,
270253 libfunc_idx,
271254 ) ?;
272255
256+ block. store ( context, location, array_counter_ptr, array_counter) ?;
257+
273258 Ok ( ( ) )
274259 }
275260}
@@ -328,11 +313,12 @@ pub mod libfunc_counter_runtime {
328313
329314 pub unsafe extern "C" fn store_array_counter (
330315 counter_id : u64 ,
331- array_counter : & [ u32 ] ,
316+ array_counter : * const u32 ,
332317 libfuncs_amount : u32 ,
333318 ) {
334319 let mut libfunc_counter = LIBFUNC_COUNTER . lock ( ) . unwrap ( ) ;
335-
336- libfunc_counter. insert ( counter_id, array_counter. to_vec ( ) ) ;
320+ let vec = ( 0 ..libfuncs_amount) . map ( |i| dbg ! ( * array_counter. add( i as usize ) ) ) . collect_vec ( ) ;
321+
322+ libfunc_counter. insert ( counter_id, vec) ;
337323 }
338324}
0 commit comments