%“分配点”的目的是什么? llvm 代码中出现的行?
我最近一直在查看 llvm-gcc 生成的一些 LLVM 程序集,并且注意到一个反复出现的语句,我不确定其目的。
例如,以下 C 程序:
int main(void)
{
void (*f)(void) = (0x21332);
f();
}
当使用“llvm-gcc -emit-llvm -S”编译时,将生成以下代码(删除了不相关的部分):
define i32 @main() nounwind {
entry:
%retval = alloca i32 ; <i32*> [#uses=1]
%f = alloca void ()* ; <void ()**> [#uses=2]
%"alloca point" = bitcast i32 0 to i32 ; <i32> [#uses=0]
store void ()* inttoptr (i64 135986 to void ()*), void ()** %f, align 4
%0 = load void ()** %f, align 4 ; <void ()*> [#uses=1]
call void %0() nounwind
br label %return
我对该行的目的感兴趣:
%"alloca point" = bitcast i32 0 to i32 ; <i32> [#uses=0]
似乎没有任何东西作为它分配给的变量都不会再被使用,并且位广播本身是毫无意义的。我能想到的是,它实际上是作为 nop 插入的,用于以后的代码生成/分析目的,指示代码中有趣的部分。
I've been looking at some LLVM assembly produced by llvm-gcc lately and I've noticed a recurring statement of which I'm not sure its purpose.
For example, the following C program:
int main(void)
{
void (*f)(void) = (0x21332);
f();
}
When compiled with "llvm-gcc -emit-llvm -S" will produce the following code (irrelevant parts removed):
define i32 @main() nounwind {
entry:
%retval = alloca i32 ; <i32*> [#uses=1]
%f = alloca void ()* ; <void ()**> [#uses=2]
%"alloca point" = bitcast i32 0 to i32 ; <i32> [#uses=0]
store void ()* inttoptr (i64 135986 to void ()*), void ()** %f, align 4
%0 = load void ()** %f, align 4 ; <void ()*> [#uses=1]
call void %0() nounwind
br label %return
I'm interested in the purpose of the line:
%"alloca point" = bitcast i32 0 to i32 ; <i32> [#uses=0]
Doesn't seem to do anything as the variable it assigns to is never used again and the bitcast itself is pointless. All I can think of is that its inserted really as a nop for later code generation / analysis purposes, indicating interesting parts of the code.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
来自 llvm-gcc 源: gcc/ llvm-convert.cpp,它只是用作辅助值*,它将被死指令消除过程删除。
From the llvm-gcc source: gcc/llvm-convert.cpp, it's just used as a helper Value* and it will be removed by a dead instruction elimination pass.
在互联网上找到了这个:
其大小可以在编译时确定的分配器将在计算堆栈帧大小时在堆栈上分配空间。对于可变大小的分配,目标特定代码必须调整堆栈大小,根据需要调整帧指针和堆栈指针,并将传出参数的位置调整到堆栈顶部。
听起来它的存在是为了使一些堆栈空间正确工作。
Found this on the internets:
Allocas whose size can be determined at compile time will be allocated space on the stack when the stack frame size is calculated. For variable sized allocas the target specific code will have to resize the stack, adjusting the frame pointer and stack pointer as needed, and adjust the locations for the outgoing parameters to the top of the stack.
sounds like its there to make some stack space work out correctly.