diff options
author | Matt Arsenault <Matthew.Arsenault@amd.com> | 2024-12-12 09:01:48 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-12-11 16:01:48 -0800 |
commit | ea632e1b34e1878b977f8adc406a89e91aa98b7e (patch) | |
tree | a6e50bd5fe024ea74d97be89c9180f5e4afa0a94 /llvm/lib/CodeGen/MachineInstr.cpp | |
parent | dd647e3e608ed0b2bac7c588d5859b80ef4a5976 (diff) | |
download | llvm-ea632e1b34e1878b977f8adc406a89e91aa98b7e.zip llvm-ea632e1b34e1878b977f8adc406a89e91aa98b7e.tar.gz llvm-ea632e1b34e1878b977f8adc406a89e91aa98b7e.tar.bz2 |
Reapply "DiagnosticInfo: Clean up usage of DiagnosticInfoInlineAsm" (#119575) (#119634)
This reverts commit 40986feda8b1437ed475b144d5b9a208b008782a.
Reapply with fix to prevent temporary Twine from going out of scope.
Diffstat (limited to 'llvm/lib/CodeGen/MachineInstr.cpp')
-rw-r--r-- | llvm/lib/CodeGen/MachineInstr.cpp | 32 |
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, |