函數傳參struct算法流程

目標:替換call指令和其對應define函數中struct參數
1、遍歷struct value userlist,struct value作爲call指令參數,將call define Function 存入set中。
2、處理set中Function,目標創建new Function
(1) Function(str)創建Mid Function(str, x, y) P.S. x、y爲str的subvalue
(2) Mid Function(str, x, y)中str和其subvalue存入DAG圖中,將str相關語句進行替換,替換後Mid Function 參數含有str,Body 無 str。下一步將參數中的str刪除。
(3)通過Mid Function(str, x, y)創建new Function(x,y)
(4)刪除Mid Function(str, x, y)
3、創建實參爲subvalue的new call指令,與new Function約定匹配
4、刪除old Function & old call

問題:
1、無法對old Function添加新參數,只能新建new Function
2、 struct參數的諸多屬性不可直接丟棄,分解的x需要繼承其哪些屬性 (已解決,所有屬性直接全部繼承)
3、Function中有嵌套定義Function,最底層or最上層的Function進行修改
(選擇從最上層處理,依次處理到最底層,按照DAG的處理順序)
4、當返回值爲struct時(str= F(A) --》 F(A,str))
5、F(A,B)進行替換時,先換A,在換B,重複clone Function,複雜度上升
6、多餘的參數未刪除,
7、當struct爲{i8,i8}時,函數參數爲i16
8、struct、array作爲函數參數傳遞時,一定爲指針。

處理face-detection問題:

  // %64 = bitcast %struct.MyPoint* %23 to i64*
  // %65 = load i64, i64* %64, align 4
  // %66 = call i32 @cascadeClassifier([320 x i32]* %62, [320 x i32]* %63, i64 %65)
 @cascadeClassifier函數內的IR:
  // %36 = bitcast %struct.MySize* %12 to i64*
  // store i64 %10, i64* %36, align 4

應該選擇替換的分解的方案,由於其過於複雜,繁瑣易錯,暫時不選用:

  // %64 = bitcast %struct.MyPoint* %23 to i64*
  // %65 = load i64, i64* %64, align 4
  // %66 = call i32 @cascadeClassifier([320 x i32]* %62, [320 x i32]* %63, i64 %65)
  //@cascadeClassifier(%10 is %65)
  // %36 = bitcast %struct.MySize* %12 to i64*
  // store i64 %10, i64* %36, align 4

  //-->> %66 = call i32 @cascadeClassifier([320 x i32]* %62, [320 x i32]* %63, %struct.MyPoint* %23)
  //-->> @cascadeClassifier([320 x i32]*, [320 x i32]*, %struct.MyPoint*)
  // %3 = getelementptr inbounds %struct.MySize, %struct.MySize* %2, i32 0, i32 0
  // %4 = load i32, i32* %3
  // %5 = getelementptr inbounds %struct.MySize, %struct.MySize* %2, i32 0, i32 1
  // %6 = load i32, i32* %5
  // %13 = getelementptr inbounds %struct.MySize, %struct.MySize* %12, i32 0, i32 0
  // %14 = getelementptr inbounds %struct.MySize, %struct.MySize* %12, i32 0, i32 1
  // store i32 %4, i32* %13
  // store i32 %6, i32* %14

目前用拼接的方案解決:

  //->->->->->
  // %62 = load i32, i32* %_01
  // %63 = zext i32 %62 to i64
  // %64 = load i32, i32* %_12
  // %65 = zext i32 %64 to i64
  // %66 = shl i64 %65, 32
  // %67 = xor i64 %66, %63
  //@cascadeClassifier(x,x,%67)
  // %3 = get %struct.MySize* %23 first children value by DAG
  // %5 = get %struct.MySize* %23 second children value by DAG
  // %19 = lshr i64 %2, 0
  // %20 = trunc i64 %19 to i32
  // store i32 %20, i32* %3
  // %21 = lshr i64 %2, 32
  // %22 = trunc i64 %21 to i32
  // store i32 %22, i32* %5
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章