llvm opt -always-inline pass 不内联

llvm opt -always-inline pass doesn't inline

我在(人类可读的)LLVM 位码文件 Input.ll 中有 SyS_sendto 的以下函数定义:

; 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_sendto 的调用, 应该被内联 在 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 not 改变了,我在 InputInlined.ll 中也看到了对 SyS_sendto 的调用......它 not 内联:

; 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
}

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

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

你可以关注the discussion on the mailing list (2015) or check in the source code.