aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/MachineInstr.cpp
diff options
context:
space:
mode:
authorMatt Arsenault <Matthew.Arsenault@amd.com>2024-12-11 17:16:07 +0900
committerGitHub <noreply@github.com>2024-12-11 17:16:07 +0900
commit884f2ad6f9e269407366622ac80e65a1bb1b4b2e (patch)
tree1ac61fda4cde4d2f52b624039e4197cd53ab5a7a /llvm/lib/CodeGen/MachineInstr.cpp
parent2fe30bc6693c60d76c7e44d9fd6323c39125c19e (diff)
downloadllvm-884f2ad6f9e269407366622ac80e65a1bb1b4b2e.zip
llvm-884f2ad6f9e269407366622ac80e65a1bb1b4b2e.tar.gz
llvm-884f2ad6f9e269407366622ac80e65a1bb1b4b2e.tar.bz2
DiagnosticInfo: Clean up usage of DiagnosticInfoInlineAsm (#119485)
Currently LLVMContext::emitError emits any error as an "inline asm" error which does not make any sense. InlineAsm appears to be special, in that it uses a "LocCookie" from srcloc metadata, which looks like a parallel mechanism to ordinary source line locations. This meant that other types of failures had degraded source information reported when available. Introduce some new generic error types, and only use inline asm in the appropriate contexts. The DiagnosticInfo types are still a bit of a mess, and I'm not sure why DiagnosticInfoWithLocationBase exists instead of just having an optional DiagnosticLocation in the base class. DK_Generic is for any error that derives from an IR level instruction, and thus can pull debug locations directly from it. DK_GenericWithLoc is functionally the generic codegen error, since it does not depend on the IR and instead can construct a DiagnosticLocation from the MI debug location.
Diffstat (limited to 'llvm/lib/CodeGen/MachineInstr.cpp')
-rw-r--r--llvm/lib/CodeGen/MachineInstr.cpp32
1 files changed, 21 insertions, 11 deletions
diff --git a/llvm/lib/CodeGen/MachineInstr.cpp b/llvm/lib/CodeGen/MachineInstr.cpp
index 941861d..958efa7 100644
--- a/llvm/lib/CodeGen/MachineInstr.cpp
+++ b/llvm/lib/CodeGen/MachineInstr.cpp
@@ -2219,26 +2219,36 @@ MachineInstrExpressionTrait::getHashValue(const MachineInstr* const &MI) {
return hash_combine_range(HashComponents.begin(), HashComponents.end());
}
-void MachineInstr::emitError(StringRef Msg) const {
+const MDNode *MachineInstr::getLocCookieMD() const {
// Find the source location cookie.
- uint64_t LocCookie = 0;
const MDNode *LocMD = nullptr;
for (unsigned i = getNumOperands(); i != 0; --i) {
if (getOperand(i-1).isMetadata() &&
(LocMD = getOperand(i-1).getMetadata()) &&
LocMD->getNumOperands() != 0) {
- if (const ConstantInt *CI =
- mdconst::dyn_extract<ConstantInt>(LocMD->getOperand(0))) {
- LocCookie = CI->getZExtValue();
- break;
- }
+ if (mdconst::hasa<ConstantInt>(LocMD->getOperand(0)))
+ return LocMD;
}
}
- if (const MachineBasicBlock *MBB = getParent())
- if (const MachineFunction *MF = MBB->getParent())
- return MF->getFunction().getContext().emitError(LocCookie, Msg);
- report_fatal_error(Msg);
+ return nullptr;
+}
+
+void MachineInstr::emitInlineAsmError(const Twine &Msg) const {
+ assert(isInlineAsm());
+ const MDNode *LocMD = getLocCookieMD();
+ uint64_t LocCookie =
+ LocMD
+ ? mdconst::extract<ConstantInt>(LocMD->getOperand(0))->getZExtValue()
+ : 0;
+ LLVMContext &Ctx = getMF()->getFunction().getContext();
+ Ctx.diagnose(DiagnosticInfoInlineAsm(LocCookie, Msg));
+}
+
+void MachineInstr::emitGenericError(const Twine &Msg) const {
+ const Function &Fn = getMF()->getFunction();
+ Fn.getContext().diagnose(
+ DiagnosticInfoGenericWithLoc(Msg, Fn, getDebugLoc()));
}
MachineInstrBuilder llvm::BuildMI(MachineFunction &MF, const DebugLoc &DL,