函数传递为struct数组的首地址时,需要记录数组的index,

遇到的问题:
H264中写C程序为:
其中PINGPONGbuffer,Pic,Pic_info都是三个结构体类型变量,其中Pic,Pic_info为数组,当传递时值传递了首地址,此时指针无法知道指向哪个memory。

StorablePicture Pic[MAX_REFERENCE_PICTURES];
StorablePictureInfo Pic_info[MAX_REFERENCE_PICTURES];
NALU_t PINGPONGbuffer;
decode_main(&PINGPONGbuffer,Pic,Pic_info);

解决思路:
将传递结构体数组的首地址传给函数时,需传递的是整个结构体数组,%struct.StorablePicture* getelementptr inbounds ([3 x %struct.StorablePicture], [3 x %struct.StorablePicture]* @Pic, i32 0, i32 0),此时的语句不能分解,提取第一个memory空间,而是将第二个index i32 0作为index,与结构体数组一同传入函数,
需要从%struct.StorablePicture* getelementptr inbounds ([3 x %struct.StorablePicture], [3 x %struct.StorablePicture]* @Pic, i32 0, i32 0)入手,拿到GEP_src和index 0,传递给了decode_main函数,需要传递数组Get_src_x、数组GEP_stc_y和index i32 0 。后期Get_src_x使用要的地方都需要给其加上index i32 0
判断是否含有index,有的话,添加个offset,其实应该是0+传进来的index数组。

if (isStructType(GEP_src->getType()) && src_children.size() > getStructTypeNumElement(GEP_src->getType())) {IdxList.push_back(ConstantInt::get(Type::getInt64Ty(module_->getContext()), 0));
        }

对应的IR 源码:

  call void @decode_main(
  %struct.NALU_t* @PINGPONGbuffer, 
  %struct.StorablePicture* getelementptr inbounds ([3 x %struct.StorablePicture], [3 x %struct.StorablePicture]* @Pic, i32 0, i32 0), 
  %struct.StorablePictureInfo* getelementptr inbounds ([3 x %struct.StorablePictureInfo], [3 x %struct.StorablePictureInfo]* @Pic_info, i32 0, i32 0))
  ……
define void @decode_main(%struct.NALU_t.2* %nalu, %struct.StorablePicture.3* %pic, %struct.StorablePictureInfo.4* %pic_info) {
……
  call fastcc void @init_listB(%struct.StorablePicture.3* %PicBuff, i32* getelementptr inbounds (%struct.ImageParameters.7, %struct.ImageParameters.7* @img_inst, i64 0, i32 12, i64 0), i32* getelementptr inbounds (%struct.ImageParameters.7, %struct.ImageParameters.7* @img_inst, i64 0, i32 13, i64 0))
……
}

define internal fastcc void @init_listB(%struct.StorablePicture.3* %PicBff, i32* %list0, i32* %list1) #0 {
  %PicBff.addr = getelementptr inbounds %struct.StorablePicture.3, %struct.StorablePicture.3* %PicBff, i64 0, i32 0
  %PicBff.load = load i32, i32* %PicBff.addr, align 4
  %PicBff.addr.5 = getelementptr inbounds %struct.StorablePicture.3, %struct.StorablePicture.3* %PicBff, i64 1, i32 0
  %PicBff.load.5 = load i32, i32* %PicBff.addr.5, align 4
  %icmp.ln71 = icmp sgt i32 %PicBff.load, %PicBff.load.5
  br i1 %icmp.ln71, label %1, label %2
……
}
//此时%PicBff, i64 1, i32 0,指针发生的偏移,指向下一块memory,需要将传进来的index变量加‘1’

我代码修改后的IR为:
之前

Function main's instructions:
    %1 = getelementptr inbounds [3 x %struct.StorablePicture.3], [3 x %struct.StorablePicture.3]* @Pic, i32 0, i32 0
    %2 = getelementptr inbounds [3 x %struct.StorablePictureInfo.4], [3 x %struct.StorablePictureInfo.4]* @Pic_info, i32 0, i32 0
    call void @decode_main(%struct.NALU_t.2* @PINGPONGbuffer, %struct.StorablePicture.3* %1, %struct.StorablePictureInfo.4* %2)
    ret i32 0

之后

Function decode_main_old's argument Type:
  0   %struct.NALU_t.2*
  1   %struct.StorablePicture.3*
  2   %struct.StorablePictureInfo.4*
  
Current processing mid function is : decode_main_mid
Function decode_main_mid's argument Type:
  0   %struct.NALU_t.2*
  1   i32*
  2   i32*
  3   i32*
  4   i32*
  5   i32*
  6   i64*
  7   i64*
  8   [200000 x i8]*
  9   %struct.StorablePicture.3*
  10   [3 x i32]*
  11   [3 x i8]*
  12   [3 x i8]*
  13   [3 x i8]*
  14   [3 x i8]*
  15   [3 x [640 x [480 x i8]]]*
  16   [3 x [320 x [240 x i8]]]*
  17   [3 x [320 x [240 x i8]]]*
  18   i32
  19   %struct.StorablePictureInfo.4*
  20   [3 x [80 x [60 x i8]]]*
  21   [3 x [80 x [60 x i8]]]*
  22   [3 x [160 x [120 x [2 x i32]]]]*
  23   [3 x [160 x [120 x [2 x i32]]]]*
  24   i32

修改过程:

Start to insert the new Insturctions : 
insert inst :   <badref> = getelementptr inbounds [3 x i32], [3 x i32]* @Pic_0, i32 0
before inst :   call void @decode_main_old(%struct.NALU_t.2* @PINGPONGbuffer, %struct.StorablePicture.3* %1, %struct.StorablePictureInfo.4* %2)
insert inst :   <badref> = getelementptr inbounds [3 x i8], [3 x i8]* @Pic_1, i32 0
before inst :   call void @decode_main_old(%struct.NALU_t.2* @PINGPONGbuffer, %struct.StorablePicture.3* %1, %struct.StorablePictureInfo.4* %2)
insert inst :   <badref> = getelementptr inbounds [3 x i8], [3 x i8]* @Pic_2, i32 0
before inst :   call void @decode_main_old(%struct.NALU_t.2* @PINGPONGbuffer, %struct.StorablePicture.3* %1, %struct.StorablePictureInfo.4* %2)
insert inst :   <badref> = getelementptr inbounds [3 x i8], [3 x i8]* @Pic_3, i32 0
before inst :   call void @decode_main_old(%struct.NALU_t.2* @PINGPONGbuffer, %struct.StorablePicture.3* %1, %struct.StorablePictureInfo.4* %2)
insert inst :   <badref> = getelementptr inbounds [3 x i8], [3 x i8]* @Pic_4, i32 0
before inst :   call void @decode_main_old(%struct.NALU_t.2* @PINGPONGbuffer, %struct.StorablePicture.3* %1, %struct.StorablePictureInfo.4* %2)
insert inst :   <badref> = getelementptr inbounds [3 x [640 x [480 x i8]]], [3 x [640 x [480 x i8]]]* @Pic_5, i32 0
before inst :   call void @decode_main_old(%struct.NALU_t.2* @PINGPONGbuffer, %struct.StorablePicture.3* %1, %struct.StorablePictureInfo.4* %2)
insert inst :   <badref> = getelementptr inbounds [3 x [320 x [240 x i8]]], [3 x [320 x [240 x i8]]]* @Pic_6, i32 0
before inst :   call void @decode_main_old(%struct.NALU_t.2* @PINGPONGbuffer, %struct.StorablePicture.3* %1, %struct.StorablePictureInfo.4* %2)
insert inst :   <badref> = getelementptr inbounds [3 x [320 x [240 x i8]]], [3 x [320 x [240 x i8]]]* @Pic_7, i32 0
before inst :   call void @decode_main_old(%struct.NALU_t.2* @PINGPONGbuffer, %struct.StorablePicture.3* %1, %struct.StorablePictureInfo.4* %2)
insert inst :   <badref> = getelementptr inbounds [3 x [80 x [60 x i8]]], [3 x [80 x [60 x i8]]]* @Pic_info_0, i32 0
before inst :   call void @decode_main_old(%struct.NALU_t.2* @PINGPONGbuffer, %struct.StorablePicture.3* %1, %struct.StorablePictureInfo.4* %2)
insert inst :   <badref> = getelementptr inbounds [3 x [80 x [60 x i8]]], [3 x [80 x [60 x i8]]]* @Pic_info_1, i32 0
before inst :   call void @decode_main_old(%struct.NALU_t.2* @PINGPONGbuffer, %struct.StorablePicture.3* %1, %struct.StorablePictureInfo.4* %2)
insert inst :   <badref> = getelementptr inbounds [3 x [160 x [120 x [2 x i32]]]], [3 x [160 x [120 x [2 x i32]]]]* @Pic_info_2, i32 0
before inst :   call void @decode_main_old(%struct.NALU_t.2* @PINGPONGbuffer, %struct.StorablePicture.3* %1, %struct.StorablePictureInfo.4* %2)
insert inst :   <badref> = getelementptr inbounds [3 x [160 x [120 x [2 x i32]]]], [3 x [160 x [120 x [2 x i32]]]]* @Pic_info_3, i32 0
before inst :   call void @decode_main_old(%struct.NALU_t.2* @PINGPONGbuffer, %struct.StorablePicture.3* %1, %struct.StorablePictureInfo.4* %2)
insert inst :   call void @decode_main(i32* @PINGPONGbuffer_0, i32* @PINGPONGbuffer_1, i32* @PINGPONGbuffer_2, i32* @PINGPONGbuffer_3, i32* @PINGPONGbuffer_4, i64* @PINGPONGbuffer_5, i64* @PINGPONGbuffer_6, [200000 x i8]* @PINGPONGbuffer_7, [3 x i32]* %3, [3 x i8]* %4, [3 x i8]* %5, [3 x i8]* %6, [3 x i8]* %7, [3 x [640 x [480 x i8]]]* %8, [3 x [320 x [240 x i8]]]* %9, [3 x [320 x [240 x i8]]]* %10, i32 0, [3 x [80 x [60 x i8]]]* %11, [3 x [80 x [60 x i8]]]* %12, [3 x [160 x [120 x [2 x i32]]]]* %13, [3 x [160 x [120 x [2 x i32]]]]* %14, i32 0)
before inst :   call void @decode_main_old(%struct.NALU_t.2* @PINGPONGbuffer, %struct.StorablePicture.3* %1, %struct.StorablePictureInfo.4* %2)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值