clang 和 llvm opt 中可用的优化列表

问题描述 投票:0回答:2

可以使用

gcc --help=optimizers
获取 GCC/G++ 中可用的优化器列表。合法值和参数范围也在
params.def
中定义。 有这样的命令和
params.def
文件也可用于 clang 吗?

gcc g++ clang llvm
2个回答
5
投票

1- 对于

Clang
使用:

clang -OX -mllvm -debug-pass=Arguments foo.c

clang -OX -mllvm -debug-pass=Structure foo.c

其中

X
可以是
Os,O1,O2,O3 and O4
(-O4 等同于 -O3,除了当从源文件编译的目标文件发出
LLVM IR
而不是目标代码时,它执行 LTO(链接时间优化))

您将拥有两组

Pass Arguments
,其中第一组是
global kernel
通行证,第二组是
function pass

2- 对于

Opt
使用:

llvm-as < /dev/null | opt -OX -disable-output -debug-pass=Arguments

其中

X
可以是
Os,O1,O2 and O3

Update as of LLVM-15x

由于新的通行证管理器被设置为默认通行证管理器,因此上面的答案仅打印

legacy pass manager
通行证。为了查看新的 pass manager 通过 opt,请尝试:

opt --print-passes   "Print available passes that can be specified in -passes=foo and exit"

1
投票

根据Amir的回答,看看

-O1
-O2
之间的差异:

# echo 'main(){}' > foo.c
# diff -uw <(clang -O0 -mllvm -debug-pass=Arguments foo.c 2>&1 | tr ' ' '\n' | sort) <(clang -O2 -mllvm -debug-pass=Arguments foo.c 2>&1 | tr ' ' '\n' | sort)

产生差异:

--- /dev/fd/63  2023-12-03 14:02:18.393064827 -0800
+++ /dev/fd/62  2023-12-03 14:02:18.394064877 -0800
@@ -1,22 +1,47 @@
 
 ^
 1
+-aa
+-aa
+-aa
 -amdgpu-isel
 and
 Arguments:
 -assumption-cache-tracker
 -atomic-expand
+-basic-aa
+-basic-aa
+-basic-aa
+-basic-aa
+-block-freq
... and many more

您可能还想添加

| grep '^[+-]'
以忽略输出上下文。

奇怪的是,

-O1
-O2
之间没有区别,所以我不确定这意味着什么,因为从
-O0
到-
O2

有相当多的输出
© www.soinside.com 2019 - 2024. All rights reserved.