llvm opt -always-inline pass并不是内联的

时间:2017-05-14 07:07:25

标签: llvm inline

我在(人类可读)LLVM bitcode文件Input.ll中有以下函数定义SyS_send:

; Function Attrs: alwaysinline noredzone nounwind
define i64 @SyS_sendto(
i64 %fd, i64 %buff, i64 %len, i64 %flags, i64 %addr, i64 %addr_len) #0 {

在此文件的末尾,属性#0 包含单词alwaysinline

attributes #0 = { alwaysinline noredzone nounwind "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }

在Input.ll的某处,有一个对SyS_send的调用,应该内联 在opt pass -always-inline中

; Function Attrs: noredzone nounwind
define i64 @GO(i64 %fd, i64 %buff, i64 %len, i64 %flags) #0 {
  %1 = trunc i64 %fd to i32
  %2 = inttoptr i64 %buff to i8*
  %3 = trunc i64 %flags to i32
  %4 = tail call i64 bitcast
  (i64 (i64, i64, i64, i64, i64, i64)*
      @SyS_sendto to i64
          (i32, i8*, i64, i32, %struct.sockaddr*, i32)*)
          (i32 %1,
           i8* %2,
           i64 %len,
           i32 %3,
           %struct.sockaddr* null,
           i32 0) #0
  ret i64 %4
}

我跑:

llvm-as -o=Input.bc Input.ll
opt -always-inline Input.bc -o InlinedInput.bc
llvm-dis -o=InlinedInput.ll InlinedInput.bc

但GO已经更改了,我在InputInlined.ll中也看到了对SyS_sendto的调用......它是内联:

; Function Attrs: noredzone nounwind
define i64 @GO(i64 %fd, i64 %buff, i64 %len, i64 %flags) #0 {
  %1 = trunc i64 %fd to i32
  %2 = inttoptr i64 %buff to i8*
  %3 = trunc i64 %flags to i32
  %4 = tail call i64 bitcast
  (i64 (i64, i64, i64, i64, i64, i64)*
      @SyS_sendto to i64
          (i32, i8*, i64, i32, %struct.sockaddr*, i32)*)
          (i32 %1,
           i8* %2,
           i64 %len,
           i32 %3,
           %struct.sockaddr* null,
           i32 0) #0
  ret i64 %4
}

非常感谢任何帮助!谢谢!

1 个答案:

答案 0 :(得分:4)

在您的示例中对@SyS_sendto的调用是间接调用的实例(由于bitcast表达式),而LLVM当前does not support内联这些内容。

您可以关注the discussion on the mailing list(2015)或签入the source code