aboutsummaryrefslogtreecommitdiff
path: root/llvm/tools/llvm-mca/llvm-mca.cpp
diff options
context:
space:
mode:
authorPeter Waller <peter.waller@arm.com>2024-05-07 09:13:44 +0100
committerGitHub <noreply@github.com>2024-05-07 09:13:44 +0100
commit1de0535e84f03941badc8021bbc87a8c674a379f (patch)
treef808c6fe778fb77c759a3ba6a2c91806993e2e3c /llvm/tools/llvm-mca/llvm-mca.cpp
parentf3fbd21fa4e25496725c22d987e4e47e4c39c8b0 (diff)
downloadllvm-1de0535e84f03941badc8021bbc87a8c674a379f.zip
llvm-1de0535e84f03941badc8021bbc87a8c674a379f.tar.gz
llvm-1de0535e84f03941badc8021bbc87a8c674a379f.tar.bz2
[llvm-mca] Abort on parse error without -skip-unsupported-instructions (#90474)
[llvm-mca] Abort on parse error without -skip-unsupported-instructions Prior to this patch, llvm-mca would continue executing after parse errors. These errors can lead to some confusion since some analysis results are printed on the standard output, and they're printed after the errors, which could otherwise be easy to miss. However it is still useful to be able to continue analysis after errors; so extend the recently added -skip-unsupported-instructions to support this. Two tests which have parse errors for some of the 'RUN' branches are updated to use -skip-unsupported-instructions so they can remain as-is. Add a description of -skip-unsupported-instructions to the llvm-mca command guide, and add it to the llvm-mca --help output: ``` --skip-unsupported-instructions=<value> - Force analysis to continue in the presence of unsupported instructions =none - Exit with an error when an instruction is unsupported for any reason (default) =lack-sched - Skip instructions on input which lack scheduling information =parse-failure - Skip lines on the input which fail to parse for any reason =any - Skip instructions or lines on input which are unsupported for any reason ``` Tests within this patch are intended to cover each of the cases. Reason | Flag | Comment --------------|------|------- none | none | Usual case, existing test suite lack-sched | none | Advises user to use -skip-unsupported-instructions=lack-sched, tested in llvm/test/tools/llvm-mca/X86/BtVer2/unsupported-instruction.s parse-failure | none | Advises user to use -skip-unsupported-instructions=parse-failure, tested in llvm/test/tools/llvm-mca/bad-input.s any | none | (N/A, covered above) lack-sched | any | Continues, prints warnings, tested in llvm/test/tools/llvm-mca/X86/BtVer2/unsupported-instruction.s parse-failure | any | Continues, prints errors, tested in llvm/test/tools/llvm-mca/bad-input.s lack-sched | parse-failure | Advises user to use -skip-unsupported-instructions=lack-sched, tested in llvm/test/tools/llvm-mca/X86/BtVer2/unsupported-instruction.s parse-failure | lack-sched | Advises user to use -skip-unsupported-instructions=parse-failure, tested in llvm/test/tools/llvm-mca/bad-input.s none | * | This would be any test case with skip-unsupported-instructions, coverage added in llvm/test/tools/llvm-mca/X86/BtVer2/simple-test.s any | * | (Logically covered by the other cases)
Diffstat (limited to 'llvm/tools/llvm-mca/llvm-mca.cpp')
-rw-r--r--llvm/tools/llvm-mca/llvm-mca.cpp47
1 files changed, 37 insertions, 10 deletions
diff --git a/llvm/tools/llvm-mca/llvm-mca.cpp b/llvm/tools/llvm-mca/llvm-mca.cpp
index e037c06..03d7d79 100644
--- a/llvm/tools/llvm-mca/llvm-mca.cpp
+++ b/llvm/tools/llvm-mca/llvm-mca.cpp
@@ -135,6 +135,35 @@ static cl::opt<unsigned>
"(instructions per cycle)"),
cl::cat(ToolOptions), cl::init(0));
+enum class SkipType { NONE, LACK_SCHED, PARSE_FAILURE, ANY_FAILURE };
+
+static cl::opt<enum SkipType> SkipUnsupportedInstructions(
+ "skip-unsupported-instructions",
+ cl::desc("Force analysis to continue in the presence of unsupported "
+ "instructions"),
+ cl::values(
+ clEnumValN(SkipType::NONE, "none",
+ "Exit with an error when an instruction is unsupported for "
+ "any reason (default)"),
+ clEnumValN(
+ SkipType::LACK_SCHED, "lack-sched",
+ "Skip instructions on input which lack scheduling information"),
+ clEnumValN(
+ SkipType::PARSE_FAILURE, "parse-failure",
+ "Skip lines on the input which fail to parse for any reason"),
+ clEnumValN(SkipType::ANY_FAILURE, "any",
+ "Skip instructions or lines on input which are unsupported "
+ "for any reason")),
+ cl::init(SkipType::NONE), cl::cat(ViewOptions));
+
+bool shouldSkip(enum SkipType skipType) {
+ if (SkipUnsupportedInstructions == SkipType::NONE)
+ return false;
+ if (SkipUnsupportedInstructions == SkipType::ANY_FAILURE)
+ return true;
+ return skipType == SkipUnsupportedInstructions;
+}
+
static cl::opt<bool>
PrintRegisterFileStats("register-file-stats",
cl::desc("Print register file statistics"),
@@ -237,11 +266,6 @@ static cl::opt<bool> DisableInstrumentManager(
"ignores instruments.)."),
cl::cat(ViewOptions), cl::init(false));
-static cl::opt<bool> SkipUnsupportedInstructions(
- "skip-unsupported-instructions",
- cl::desc("Make unsupported instruction errors into warnings."),
- cl::cat(ViewOptions), cl::init(false));
-
namespace {
const Target *getTarget(const char *ProgName) {
@@ -440,7 +464,8 @@ int main(int argc, char **argv) {
mca::AsmAnalysisRegionGenerator CRG(*TheTarget, SrcMgr, ACtx, *MAI, *STI,
*MCII);
Expected<const mca::AnalysisRegions &> RegionsOrErr =
- CRG.parseAnalysisRegions(std::move(IPtemp));
+ CRG.parseAnalysisRegions(std::move(IPtemp),
+ shouldSkip(SkipType::PARSE_FAILURE));
if (!RegionsOrErr) {
if (auto Err =
handleErrors(RegionsOrErr.takeError(), [](const StringError &E) {
@@ -482,7 +507,8 @@ int main(int argc, char **argv) {
mca::AsmInstrumentRegionGenerator IRG(*TheTarget, SrcMgr, ICtx, *MAI, *STI,
*MCII, *IM);
Expected<const mca::InstrumentRegions &> InstrumentRegionsOrErr =
- IRG.parseInstrumentRegions(std::move(IPtemp));
+ IRG.parseInstrumentRegions(std::move(IPtemp),
+ shouldSkip(SkipType::PARSE_FAILURE));
if (!InstrumentRegionsOrErr) {
if (auto Err = handleErrors(InstrumentRegionsOrErr.takeError(),
[](const StringError &E) {
@@ -593,7 +619,7 @@ int main(int argc, char **argv) {
[&IP, &STI](const mca::InstructionError<MCInst> &IE) {
std::string InstructionStr;
raw_string_ostream SS(InstructionStr);
- if (SkipUnsupportedInstructions)
+ if (shouldSkip(SkipType::LACK_SCHED))
WithColor::warning()
<< IE.Message
<< ", skipping with -skip-unsupported-instructions, "
@@ -601,7 +627,8 @@ int main(int argc, char **argv) {
else
WithColor::error()
<< IE.Message
- << ", use -skip-unsupported-instructions to ignore.\n";
+ << ", use -skip-unsupported-instructions=lack-sched to "
+ "ignore these on the input.\n";
IP->printInst(&IE.Inst, 0, "", *STI, SS);
SS.flush();
WithColor::note()
@@ -610,7 +637,7 @@ int main(int argc, char **argv) {
// Default case.
WithColor::error() << toString(std::move(NewE));
}
- if (SkipUnsupportedInstructions) {
+ if (shouldSkip(SkipType::LACK_SCHED)) {
DroppedInsts.insert(&MCI);
continue;
}