LLVM开发常见调试方法
一、llvm_unreachable
用来描述某个不支持的特性,会比assert(0) 更优雅,dump出来的信息也会友好一些
官方注释,llvm-project/llvm/include/llvm/Support/ErrorHandling.h:125
复制/// Marks that the current location is not supposed to be reachable.
/// In !NDEBUG builds, prints the message and location info to stderr.
/// In NDEBUG builds, if the platform does not support a builtin unreachable
/// then we call an internal LLVM runtime function. Otherwise the behavior is
/// controlled by the CMake flag
/// -DLLVM_UNREACHABLE_OPTIMIZE
/// * When "ON" (default) llvm_unreachable() becomes an optimizer hint
/// that the current location is not supposed to be reachable: the hint
/// turns such code path into undefined behavior. On compilers that don't
/// support such hints, prints a reduced message instead and aborts the
/// program.
/// * When "OFF", a builtin_trap is emitted instead of an
// optimizer hint or printing a reduced message.
///
/// Use this instead of assert(0). It conveys intent more clearly, suppresses
/// diagnostics for unreachable code paths, and allows compilers to omit
/// unnecessary code.
二、 LLVM_DEBUG
LLVM Debug信息输出,需要使用-g选项的Debug版本,可以使用--debug
输出所有LLVM_DEBUG内容,也可以使用--debug-only
控制输出某个DEBUG_TYPE的输出
三、dump
基本所有的LLVM数据都有dump方法,是一个调试非常好用的东西
四、官方提供的debug方法
比如MLIR的debug文档,就有--mlir-print-ir-after-failure
,可以在MLIR
报错时把整个module
dump出来。
附、测试
测试的话会使用llvm-lit和FileCheck,其中还有一些他的单元测试
LLVM Testing官方文档
lit官方文档
LLVM中FileCheck开发者工具–2--入门教程
CFG可视化
本文来自博客园,作者:暴力都不会的蒟蒻,转载请注明原文链接:https://www.cnblogs.com/BobHuang/p/17804596.html
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架
2021-11-02 高中信息技术(Python)重难点1:数制