LLVM 的 -globalopt 传递不优化全局变量
LLVM's -globalopt pass does not optimize global variables
我有以下 LLVM IR 程序:
@test1 = global i32 3, align 4
@test2 = common global i32 0, align 4
; Function Attrs: nounwind uwtable
define i32 @main() #0 {
store i32 4, i32* @test2, align 4
%1 = load i32* @test1, align 4
ret i32 %1
}
当我使用 opt(版本 3.3)到 运行 和 -globalopt
传递时,位码保持不变。但是,我希望 @test1
被标记为 constant 并且 @test2
被删除,因为程序只存储到 @test2
.
我是否必须运行选择之前的一些分析传递或者为什么传递没有按我预期的那样执行?
来自 linkage section of the langref(强调我的):
common
“common
” linkage is most similar to “weak
” linkage, but they are used for tentative definitions in C, such as “int X;
” at global scope. Symbols with “common
” linkage are merged in the same way as weak
symbols, and they may not be deleted if unreferenced. common
symbols may not have an explicit section, must have a zero initializer, and may not be marked ‘constant
‘. Functions and aliases may not have common linkage.
...
external
If none of the above identifiers are used, the global is externally visible, meaning that it participates in linkage and can be used to resolve external symbol references.
所以 @test1
是外部可见的,这意味着它不能保证是一个常量(可以从外部更改),并且 @test2
是一个链接类型,明确表示它可能不是即使未被引用也会被删除。
我有以下 LLVM IR 程序:
@test1 = global i32 3, align 4
@test2 = common global i32 0, align 4
; Function Attrs: nounwind uwtable
define i32 @main() #0 {
store i32 4, i32* @test2, align 4
%1 = load i32* @test1, align 4
ret i32 %1
}
当我使用 opt(版本 3.3)到 运行 和 -globalopt
传递时,位码保持不变。但是,我希望 @test1
被标记为 constant 并且 @test2
被删除,因为程序只存储到 @test2
.
我是否必须运行选择之前的一些分析传递或者为什么传递没有按我预期的那样执行?
来自 linkage section of the langref(强调我的):
common
“common
” linkage is most similar to “weak
” linkage, but they are used for tentative definitions in C, such as “int X;
” at global scope. Symbols with “common
” linkage are merged in the same way asweak
symbols, and they may not be deleted if unreferenced.common
symbols may not have an explicit section, must have a zero initializer, and may not be marked ‘constant
‘. Functions and aliases may not have common linkage.
...
external
If none of the above identifiers are used, the global is externally visible, meaning that it participates in linkage and can be used to resolve external symbol references.
所以 @test1
是外部可见的,这意味着它不能保证是一个常量(可以从外部更改),并且 @test2
是一个链接类型,明确表示它可能不是即使未被引用也会被删除。