使用clang生成llvm ir时如何保存变量名? [英] How to save the variable name when use clang to generate llvm ir?
本文介绍了使用clang生成llvm ir时如何保存变量名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用'clang -S -emit-llvm test.c'生成ir.
I generate ir by use 'clang -S -emit-llvm test.c'.
int main(int argc, char **argv)
{
int* a=0;
a=(int *)malloc(sizeof(int));
printf("hello world\n");
return 0;
}
这是红外线:
define i32 @main(i32, i8**) #0 {
%3 = alloca i32, align 4
%4 = alloca i32, align 4
%5 = alloca i8**, align 8
%6 = alloca i32*, align 8
store i32 0, i32* %3, align 4
store i32 %0, i32* %4, align 4
store i8** %1, i8*** %5, align 8
store i32* null, i32** %6, align 8
%7 = call noalias i8* @malloc(i64 4) #3
%8 = bitcast i8* %7 to i32*
store i32* %8, i32** %6, align 8
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i32 0, i32 0))
ret i32 0
}
如何使变量名保持不变,例如仍然是%a而不是%3?
how can I make the variable name remain unchanged,like a still %a ,not %3?
推荐答案
实际上,删除变量名是一项功能,需要使用-discard-value-names
激活.发布版本中的Clang会自己执行此操作(不是在调试模式下使用自编译的Clang).
Actually dropping of variable names is a feature and needs to be activated with -discard-value-names
. Clang in a release build does this by its own (a self compiled clang in debug mode not).
您可以使用
clang <your-command-line> -###
然后复制输出并删除-discard-value-names
.
较新的clang版本(从7开始)将标志公开给普通命令行:
Newer clang version (since 7) expose the flag to the normal command line:
clang -fno-discard-value-names <your-command-line>
这篇关于使用clang生成llvm ir时如何保存变量名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文