You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

LLVM新Pass管理器:如何获取-analyze -loops输出

使用LLVM新Pass管理器获取循环分析信息

旧Pass管理器的工作方式

之前我通过以下命令获取循环分析信息:

$ opt -analyze -loops app2/app2.ll

输出结果:

Printing analysis 'Natural Loop Information' for function 'rotf':
Loop at depth 1 containing: %4<header><exiting>,%7,%10,%27,%31<latch>,%14,%24
    Loop at depth 2 containing: %10<header><exiting>,%14,%24<latch>
Printing analysis 'Natural Loop Information' for function 'rotf2':
Loop at depth 1 containing: %4<header><exiting>,%7,%10,%27,%31<latch>,%14,%24
    Loop at depth 2 containing: %10<header><exiting>,%14,%24<latch>
Printing analysis 'Natural Loop Information' for function 'main':
Loop at depth 1 containing: %4<header><exiting>,%7,%15,%11,%19,%24,%28,%29<latch>

尝试新Pass管理器遇到的问题

我尝试了以下命令,但均报错:

$ opt -p print-loops app2/app2.ll

报错信息:

WARNING: You're attempting to print out a bitcode file.
This is inadvisable as it may cause display problems. If
you REALLY want to taste LLVM bitcode first-hand, you
can force output with the `-f' option.

opt: unknown pass name 'print-loops'
$ opt -p print-analyze-loops app2/app2.ll

报错信息:

WARNING: You're attempting to print out a bitcode file.
This is inadvisable as it may cause display problems. If
you REALLY want to taste LLVM bitcode first-hand, you
can force output with the `-f' option.

opt: unknown pass name 'print-analyze-loops'

正确解决方案

要在新Pass管理器中获取等价的循环分析信息,需注意两个核心点:

  1. 禁用输出:旧Pass管理器的-analyze参数,在新管理器中对应-disable-output,可避免输出bitcode的警告。
  2. 使用正确的Pass名称:根据LLVM版本差异,选择对应Pass:

正确命令示例

方式一(适配LLVM 14及以上版本)

$ opt -disable-output -passes="print-loops" app2/app2.ll

方式二(适配部分旧版本新Pass管理器)

若上述命令提示未知Pass,尝试完整的分析打印语法:

$ opt -disable-output -passes="print<LoopInfo>" app2/app2.ll

兼容旧版本方案

如果你的LLVM版本较旧(如LLVM 13及之前),新Pass管理器可能未完全支持print-loops,可强制切换回旧模式:

$ opt -enable-new-pm=0 -analyze -loops app2/app2.ll

内容的提问来源于stack exchange,提问作者dtkerns

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.03 17:25:22