LLVM结构返回优化 [英] LLVM Struct Return Optimization
问题描述
我想知道为什么LLVM无法优化以下IR代码(使用PassManagerBuilder(优化设置为"3",还使用LLVM的"opt"工具):
I'm wondering why LLVM fails to optimize the following IR code (using the PassManagerBuilder with optimisation set to '3', and also using LLVM's 'opt' tool):
%GenericStruct = type { i32 }
define void @makeGenericStructOuter(%GenericStruct* noalias nocapture sret) {
entry:
%1 = alloca %GenericStruct
call void @makeGenericStructInner(%GenericStruct* %1)
%2 = load %GenericStruct* %1
store %GenericStruct %2, %GenericStruct* %0
ret void
}
declare void @makeGenericStructInner(%GenericStruct* noalias nocapture sret)
期望的代码是:
%GenericStruct = type { i32 }
define void @makeGenericStructOuter(%GenericStruct* noalias nocapture sret) {
entry:
call void @makeGenericStructInner(%GenericStruct* %0)
ret void
}
declare void @makeGenericStructInner(%GenericStruct* noalias nocapture sret)
目前是否没有优化可用于处理这种情况?还是我无法生成(该代码是从我正在开发的前端生成的)正确的IR(允许进行优化)?
Are there simply no optimizations currently available to handle this case? Or am I failing to produce (this code is generated from a front-end I'm developing) the right IR that would allow optimization?
在建议之前,我无法生成按值返回的代码,因为这些函数必须可以从其他不知道'GenericStruct'大小或内容的模块/库中调用(它们将在本地声明'TestClass'为结构不透明").
Before it's suggested, I can't produce code that returns by value since these functions must be callable from other modules/libraries that don't know the size or contents of 'GenericStruct' (and they would locally declare 'TestClass' as 'struct opaque').
推荐答案
If you belive that optimization should take place, report a bug in LLVM Bug Tracker. LLVM developers are usually very happy and interested when reporting optimization opportunities missed.
这篇关于LLVM结构返回优化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!