Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
LLVM:将alloca作为函数参数传递_Llvm_Llvm Ir - Fatal编程技术网

LLVM:将alloca作为函数参数传递

LLVM:将alloca作为函数参数传递,llvm,llvm-ir,Llvm,Llvm Ir,我想要一个LLVM IR代码,相当于 double x = 4.93; printf("hello world: %f", x); 在我的LLVM IR代码中,我从中获得,整理代码后,它将变成 %x = alloca double, align 8 store double 4.930000e+00, double* %x, align 8 %1 = load double, double* %x, align 8 %2 = call i32 (i8*, ...) @pri

我想要一个LLVM IR代码,相当于

double x = 4.93;
printf("hello world: %f", x);
在我的LLVM IR代码中,我从中获得,整理代码后,它将变成

%x = alloca double, align 8
store double 4.930000e+00, double* %x, align 8
%1 = load double, double* %x, align 8
%2 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i32 0, i32 0), double %1)
没有错误。到目前为止没有问题


但对我来说,
%1
看起来多余。但是,看起来我无法删除此介质。下面的代码

%x = alloca double, align 8
store double 4.930000e+00, double* %x, align 8
%2 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i32 0, i32 0), double %x)
导致错误

llvm-as-9: test.ll:26:113: error: '%x' defined with type 'double*' but expected 'double'
%2 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i32 0, i32 0), double %x)
                                                                                                                ^

现在我想知道我所做的删除
%1
的操作是否真的可行?

alloca指令返回一个指针,因此在您的代码中
%x
双*
类型。您必须从
double*
加载
,才能获得
double

在您的情况下,应该可以使用
4.930000e+00
值创建一个
double
常量,并直接将该值用作
printf
参数

通过对第一个代码段运行优化过程,也可以达到同样的效果