1、拋出error信息并終止程序
使用DiagnosticInfoUnsupported可以向用戶拋出error信息并且終止程序,效果如同report_fatal_error、Error。后端用法如下:
void xxxx::reportErrorMsg(const MachineFunction &MF)const {
const Function &F = MF.getFunction();
// Diagnostic information for unsupported feature in backend.
F.getContext().diagnose(DiagnosticInfoUnsupported{F, "report msg."});
}
2、優(yōu)化pass中拋出警告信息之OptimizationRemark
使用時(shí)clang得加上-Rpass=name,llc得加上–pass-remarks=name才行,后端用法如下:
#include "llvm/Analysis/OptimizationRemarkEmitter.h"
void getAnalysisUsage(AnalysisUsage &AU) const override {
AU.addRequired<OptimizationRemarkEmitterWrapperPass>();
MachineFunctionPass::getAnalysisUsage(AU);
}
void xxx::reportWarningMsg(const MachineFunction &MF)const {
auto *ORE = &getAnalysis<OptimizationRemarkEmitterWrapperPass>().getORE();
const Function &F = MF.getFunction();
// Diagnostic information for applied optimization remarks
OptimizationRemark R(DEBUG_TYPE, "replace-spill-register", &F);
R << "report msg";
ORE->emit(R);
}
3、machine ir拋信息之DiagnosticInfoMIRParser
該接口同樣支持DS_Error,DS_Warning,DS_Remark和DS_Note 4種方式,后端用法如下:
#include "llvm/IR/DiagnosticInfo.h"
#include "llvm/Support/SourceMgr.h"
void xxx::reportWarningMsg(const MachineFunction &MF)const {
const Function &F = MF.getFunction();
// Diagnostic information for machine IR parser.
F.getContext().diagnose(DiagnosticInfoMIRParser(
DS_Warning,
SMDiagnostic(
DEBUG_TYPE, SourceMgr::DK_Warning, "report msg")));
}
4、AsmParser之Warning
基本用法如下:
XXXAsmParser &Parser;
void Warning(SMLoc L, const Twine &Msg) { Parser.Warning(L, Msg); }
5、MCContext之reportWarning
基本用法如下:文章來源:http://www.zghlxwxcb.cn/news/detail-612627.html
MCContext &Context;
void MCContext::reportWarning(SMLoc Loc, const Twine &Msg)
Context.reportWarning(MCxxx.getLoc(), Msg);
6、其它類型的信息
包括DiagnosticInfoInlineAsm,DiagnosticInfoResourceLimit,DiagnosticInfoStackSize,DiagnosticInfoOptimizationBase,DiagnosticInfoIROptimization以及debug,Profileing,remarks等。文章來源地址http://www.zghlxwxcb.cn/news/detail-612627.html
- 其中l(wèi)lvm_unreachable為開發(fā)者使用,發(fā)布時(shí)用戶不可見,所看到的信息為segment fatal。
- assert由于存在判斷開銷,一般也不在發(fā)布中開啟。
7、用例如何檢查report_fatal_error
- RUN命令需要使用not,用法如下:
// RUN: not %clang --target=xx -mcpu=xxx -O3 -c %s -o - 2>&1 | FileCheck %s --check-prefix=expected-error
....
// expected-error: xxxx
- 使用-fsyntax-only -verify,用法如下:
// RUN: %clang_cc1 -triple xxx -target-feature xx -fsyntax-only -verify %s
// expected-warning{{xxxxxxxx}} expected-error{{xxxxxxxxxxxxxxx}}
到了這里,關(guān)于llvm向用戶拋出warning、error信息的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!