What is the effect of "--debug-pass=Structure" option on opt tool?

本文详细解释了LLVM优化与分析工具opt中'--debug-pass=Structure'选项的作用。通过此选项,可以查看在特定优化级别下运行的pass列表,包括目标库信息、目标转换信息等。并通过一个C源代码示例,展示了如何使用此选项来观察模块级和函数级的pass运行情况。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

What is the effect of “–debug-pass=Structure” option on opt tool?

opt is the LLVM optimizer and analyzer tool that is run on LLVM IR to optimize the IR or produce an analysis about it.

We can direct the opt tool to run a specific pass that we require. These passes can be one of the already defined passes listed at http://llvm.org/docs/Passes.html or one of the passes we have written ourselves. The passes listed in the above link are also run in the optimization levels of -O1, -O2, -O3.

To view which pass is being run at a certain optimization level, use the --debug-pass=Structure command-line option along with the opt tool. let’s take an example.

A small piece of C source code, as follow:

// file: /tmp/1.c
int foo(int aa, int bb, int cc) {
  int sum = aa + bb;
  return sum / cc;
}

int main(){
    foo(1,2,3);
    return 0;
}

Execute command:

clang -S -emit-llvm /tmp/1.c -o /tmp/1.ll
opt --debug-pass=Structure /tmp/1.ll

Outputs:

Pass Arguments:  -targetlibinfo -tti -verify
Target Library Information
Target Transform Information
  ModulePass Manager
    FunctionPass Manager
      Module Verifier

In the output, the Pass arguments gives us the passes that are run and the following list is the structure used to run each pass. The Passes just after ModulePass Manager will show the passes run per module(here, it is empty). The passes in hierarchy of FunctionPass Manager show that the pass was run per function(Module Verifier).

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值