From 5213039bde44f548441e7b12b67e4a597a1b08e9 Mon Sep 17 00:00:00 2001 From: Krzysztof Parzyszek Date: Mon, 1 May 2017 20:06:01 +0000 Subject: [PATCH] [Hexagon] Give better error messages for solo instruction errors Patch by Colin LeMahieu. llvm-svn: 301827 --- .../Hexagon/MCTargetDesc/HexagonMCChecker.cpp | 16 ++++++++++------ .../Hexagon/MCTargetDesc/HexagonMCChecker.h | 2 +- test/MC/Hexagon/PacketRules/solo.s | 5 +++++ test/MC/Hexagon/multiple_errs.s | 10 ++++++++++ 4 files changed, 26 insertions(+), 7 deletions(-) create mode 100644 test/MC/Hexagon/PacketRules/solo.s create mode 100644 test/MC/Hexagon/multiple_errs.s diff --git a/lib/Target/Hexagon/MCTargetDesc/HexagonMCChecker.cpp b/lib/Target/Hexagon/MCTargetDesc/HexagonMCChecker.cpp index 43f75819683..36e0aee630e 100644 --- a/lib/Target/Hexagon/MCTargetDesc/HexagonMCChecker.cpp +++ b/lib/Target/Hexagon/MCTargetDesc/HexagonMCChecker.cpp @@ -484,16 +484,16 @@ bool HexagonMCChecker::checkRegisters() { // Check for legal use of solo insns. bool HexagonMCChecker::checkSolo() { - if (HexagonMCInstrInfo::isBundle(MCB) && - HexagonMCInstrInfo::bundleSize(MCB) > 1) { + if (HexagonMCInstrInfo::bundleSize(MCB) > 1) for (auto const &I : HexagonMCInstrInfo::bundleInstructions(MCB)) { if (llvm::HexagonMCInstrInfo::isSolo(MCII, *I.getInst())) { - reportError( - "instruction cannot appear in packet with other instructions"); + SMLoc Loc = I.getInst()->getLoc(); + reportError(Loc, "Instruction is marked `isSolo' and " + "cannot have other instructions in " + "the same packet"); return false; } } - } return true; } @@ -575,8 +575,12 @@ void HexagonMCChecker::reportErrorNewValue(unsigned Register) { } void HexagonMCChecker::reportError(llvm::Twine const &Msg) { + reportError(MCB.getLoc(), Msg); +} + +void HexagonMCChecker::reportError(SMLoc Loc, llvm::Twine const &Msg) { if (ReportErrors) - Context.reportError(MCB.getLoc(), Msg); + Context.reportError(Loc, Msg); } void HexagonMCChecker::reportWarning(llvm::Twine const &Msg) { diff --git a/lib/Target/Hexagon/MCTargetDesc/HexagonMCChecker.h b/lib/Target/Hexagon/MCTargetDesc/HexagonMCChecker.h index c1a29ea6596..69c0ef28c4d 100644 --- a/lib/Target/Hexagon/MCTargetDesc/HexagonMCChecker.h +++ b/lib/Target/Hexagon/MCTargetDesc/HexagonMCChecker.h @@ -118,7 +118,6 @@ class HexagonMCChecker { bool checkSolo(); bool checkShuffle(); bool checkSlots(); - bool checkSize(); static void compoundRegisterMap(unsigned &); @@ -141,6 +140,7 @@ public: bool check(bool FullCheck = true); void reportErrorRegisters(unsigned Register); void reportErrorNewValue(unsigned Register); + void reportError(SMLoc Loc, llvm::Twine const &Msg); void reportError(llvm::Twine const &Msg); void reportWarning(llvm::Twine const &Msg); }; diff --git a/test/MC/Hexagon/PacketRules/solo.s b/test/MC/Hexagon/PacketRules/solo.s new file mode 100644 index 00000000000..86107d52f1f --- /dev/null +++ b/test/MC/Hexagon/PacketRules/solo.s @@ -0,0 +1,5 @@ +# RUN: not llvm-mc -arch=hexagon -filetype=asm %s 2>%t; FileCheck %s <%t + +{ brkpt + r0 = r0 } +# CHECK: 3:3: error: Instruction is marked `isSolo' and cannot have other instructions in the same packet diff --git a/test/MC/Hexagon/multiple_errs.s b/test/MC/Hexagon/multiple_errs.s new file mode 100644 index 00000000000..cd04c0efbd3 --- /dev/null +++ b/test/MC/Hexagon/multiple_errs.s @@ -0,0 +1,10 @@ +# RUN: not llvm-mc -arch=hexagon -filetype=asm %s 2> %t; FileCheck %s < %t +# + +{ + if (!p0) r0=r1; + if (!p0) r0=r2; + trap0(#15); +} +# CHECK: error: register `R0' modified more than once +# CHECK: error: Instruction is marked `isSolo' and cannot have other instructions in the same packet