Llvm 如何生成内联GetElementPtr指令?

Llvm 如何生成内联GetElementPtr指令?,llvm,llvm-c++-api,Llvm,Llvm C++ Api,我有一些这样的代码(systemFun定义为i32@system(i8*)): 但是,当我使用Clang编译此C代码时: system("echo haha"); 生成以下LLVM IR: call i32 @system(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @cmd, i32 0, i32 0)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

我有一些这样的代码(
systemFun
定义为
i32@system(i8*)
):

但是,当我使用Clang编译此C代码时:

system("echo haha");
生成以下LLVM IR:

call i32 @system(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @cmd, i32 0, i32 0))
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
我想生成后一个代码,其中
getelementptr
的结果直接用于函数调用,而不分配给临时变量
%1

我试图省略
NameStr
insertaden
returnBB
是一个基本块),但它生成的代码如下

call i32 @system(i8* <badref>)
调用i32@system(i8*)
请告诉我如何实现我的目标。

内联版本是一个ConstantExpr,使用生成

ConstantExpr
类是全局变量使用的最佳格式,因为它在运行时不需要CPU时间,但指令适用于所有类型的指针,即使不是常量。(指向全局变量的指针是常量。)

call i32 @system(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @cmd, i32 0, i32 0))
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
call i32 @system(i8* <badref>)