Skip to content

Commit e788a4b

Browse files
[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.
1 parent 86b9a4f commit e788a4b

File tree

6 files changed

+45
-18
lines changed

6 files changed

+45
-18
lines changed

llvm/test/tools/llvm-mca/AArch64/Exynos/float-divide-multiply.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# NOTE: Assertions have been autogenerated by utils/update_mca_test_checks.py
2-
# RUN: llvm-mca -march=aarch64 -mcpu=exynos-m3 -resource-pressure=false < %s | FileCheck %s -check-prefixes=ALL,EM3
2+
# RUN: llvm-mca -march=aarch64 -mcpu=exynos-m3 -resource-pressure=false -skip-unsupported-instructions < %s | FileCheck %s -check-prefixes=ALL,EM3
33
# RUN: llvm-mca -march=aarch64 -mcpu=exynos-m4 -resource-pressure=false < %s | FileCheck %s -check-prefixes=ALL,EM4
44
# RUN: llvm-mca -march=aarch64 -mcpu=exynos-m5 -resource-pressure=false < %s | FileCheck %s -check-prefixes=ALL,EM5
55

llvm/test/tools/llvm-mca/AArch64/Exynos/float-integer.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# NOTE: Assertions have been autogenerated by utils/update_mca_test_checks.py
2-
# RUN: llvm-mca -mtriple=aarch64-linux-gnu -mcpu=exynos-m3 -resource-pressure=false < %s | FileCheck %s -check-prefixes=ALL,EM3
2+
# RUN: llvm-mca -mtriple=aarch64-linux-gnu -mcpu=exynos-m3 -resource-pressure=false -skip-unsupported-instructions < %s | FileCheck %s -check-prefixes=ALL,EM3
33
# RUN: llvm-mca -mtriple=aarch64-linux-gnu -mcpu=exynos-m4 -resource-pressure=false < %s | FileCheck %s -check-prefixes=ALL,EM4
44
# RUN: llvm-mca -mtriple=aarch64-linux-gnu -mcpu=exynos-m5 -resource-pressure=false < %s | FileCheck %s -check-prefixes=ALL,EM5
55

llvm/test/tools/llvm-mca/bad-input.s

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# RUN: not llvm-mca %s -o /dev/null 2>&1 | FileCheck --check-prefixes=CHECK-ALL,CHECK %s
2+
# RUN: not llvm-mca -skip-unsupported-instructions %s -o /dev/null 2>&1 | FileCheck --check-prefixes=CHECK-ALL,CHECK-SKIP %s
3+
4+
# Test checks that MCA does not produce a total cycles estimate if it encounters parse errors.
5+
6+
# CHECK-ALL-NOT: Total Cycles:
7+
8+
# CHECK: error: Assembly input parsing had errors.
9+
# CHECK-SKIP: error: no assembly instructions found.
10+
11+
This is not a valid assembly file for any architecture (by virtue of this text.)

llvm/tools/llvm-mca/CodeRegionGenerator.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ namespace mca {
2929
CodeRegionGenerator::~CodeRegionGenerator() {}
3030

3131
Expected<const CodeRegions &> AsmCodeRegionGenerator::parseCodeRegions(
32-
const std::unique_ptr<MCInstPrinter> &IP) {
32+
const std::unique_ptr<MCInstPrinter> &IP,
33+
bool SkipUnsupportedInstructions) {
3334
MCTargetOptions Opts;
3435
Opts.PreserveAsmComments = false;
3536
CodeRegions &Regions = getRegions();
@@ -61,7 +62,9 @@ Expected<const CodeRegions &> AsmCodeRegionGenerator::parseCodeRegions(
6162
"This target does not support assembly parsing.",
6263
inconvertibleErrorCode());
6364
Parser->setTargetParser(*TAP);
64-
Parser->Run(false);
65+
if (Parser->Run(false) && !SkipUnsupportedInstructions)
66+
return make_error<StringError>("Assembly input parsing had errors.",
67+
inconvertibleErrorCode());
6568

6669
if (CCP->hadErr())
6770
return make_error<StringError>("There was an error parsing comments.",

llvm/tools/llvm-mca/CodeRegionGenerator.h

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,8 @@ class CodeRegionGenerator {
148148
CodeRegionGenerator(const CodeRegionGenerator &) = delete;
149149
CodeRegionGenerator &operator=(const CodeRegionGenerator &) = delete;
150150
virtual Expected<const CodeRegions &>
151-
parseCodeRegions(const std::unique_ptr<MCInstPrinter> &IP) = 0;
151+
parseCodeRegions(const std::unique_ptr<MCInstPrinter> &IP,
152+
bool SkipUnsupportedInstructions) = 0;
152153

153154
public:
154155
CodeRegionGenerator() {}
@@ -164,7 +165,8 @@ class AnalysisRegionGenerator : public virtual CodeRegionGenerator {
164165
AnalysisRegionGenerator(llvm::SourceMgr &SM) : Regions(SM) {}
165166

166167
virtual Expected<const AnalysisRegions &>
167-
parseAnalysisRegions(const std::unique_ptr<MCInstPrinter> &IP) = 0;
168+
parseAnalysisRegions(const std::unique_ptr<MCInstPrinter> &IP,
169+
bool SkipUnsupportedInstructions) = 0;
168170
};
169171

170172
/// Abstract CodeRegionGenerator with InstrumentRegionsRegions member
@@ -176,7 +178,8 @@ class InstrumentRegionGenerator : public virtual CodeRegionGenerator {
176178
InstrumentRegionGenerator(llvm::SourceMgr &SM) : Regions(SM) {}
177179

178180
virtual Expected<const InstrumentRegions &>
179-
parseInstrumentRegions(const std::unique_ptr<MCInstPrinter> &IP) = 0;
181+
parseInstrumentRegions(const std::unique_ptr<MCInstPrinter> &IP,
182+
bool SkipUnsupportedInstructions) = 0;
180183
};
181184

182185
/// This abstract class is responsible for parsing input ASM and
@@ -202,7 +205,8 @@ class AsmCodeRegionGenerator : public virtual CodeRegionGenerator {
202205

203206
unsigned getAssemblerDialect() const { return AssemblerDialect; }
204207
Expected<const CodeRegions &>
205-
parseCodeRegions(const std::unique_ptr<MCInstPrinter> &IP) override;
208+
parseCodeRegions(const std::unique_ptr<MCInstPrinter> &IP,
209+
bool SkipUnsupportedInstructions) override;
206210
};
207211

208212
class AsmAnalysisRegionGenerator final : public AnalysisRegionGenerator,
@@ -222,17 +226,21 @@ class AsmAnalysisRegionGenerator final : public AnalysisRegionGenerator,
222226
MCStreamerWrapper *getMCStreamer() override { return &Streamer; }
223227

224228
Expected<const AnalysisRegions &>
225-
parseAnalysisRegions(const std::unique_ptr<MCInstPrinter> &IP) override {
226-
Expected<const CodeRegions &> RegionsOrErr = parseCodeRegions(IP);
229+
parseAnalysisRegions(const std::unique_ptr<MCInstPrinter> &IP,
230+
bool SkipUnsupportedInstructions) override {
231+
Expected<const CodeRegions &> RegionsOrErr =
232+
parseCodeRegions(IP, SkipUnsupportedInstructions);
227233
if (!RegionsOrErr)
228234
return RegionsOrErr.takeError();
229235
else
230236
return static_cast<const AnalysisRegions &>(*RegionsOrErr);
231237
}
232238

233239
Expected<const CodeRegions &>
234-
parseCodeRegions(const std::unique_ptr<MCInstPrinter> &IP) override {
235-
return AsmCodeRegionGenerator::parseCodeRegions(IP);
240+
parseCodeRegions(const std::unique_ptr<MCInstPrinter> &IP,
241+
bool SkipUnsupportedInstructions) override {
242+
return AsmCodeRegionGenerator::parseCodeRegions(
243+
IP, SkipUnsupportedInstructions);
236244
}
237245
};
238246

@@ -254,17 +262,21 @@ class AsmInstrumentRegionGenerator final : public InstrumentRegionGenerator,
254262
MCStreamerWrapper *getMCStreamer() override { return &Streamer; }
255263

256264
Expected<const InstrumentRegions &>
257-
parseInstrumentRegions(const std::unique_ptr<MCInstPrinter> &IP) override {
258-
Expected<const CodeRegions &> RegionsOrErr = parseCodeRegions(IP);
265+
parseInstrumentRegions(const std::unique_ptr<MCInstPrinter> &IP,
266+
bool SkipUnsupportedInstructions) override {
267+
Expected<const CodeRegions &> RegionsOrErr =
268+
parseCodeRegions(IP, SkipUnsupportedInstructions);
259269
if (!RegionsOrErr)
260270
return RegionsOrErr.takeError();
261271
else
262272
return static_cast<const InstrumentRegions &>(*RegionsOrErr);
263273
}
264274

265275
Expected<const CodeRegions &>
266-
parseCodeRegions(const std::unique_ptr<MCInstPrinter> &IP) override {
267-
return AsmCodeRegionGenerator::parseCodeRegions(IP);
276+
parseCodeRegions(const std::unique_ptr<MCInstPrinter> &IP,
277+
bool SkipUnsupportedInstructions) override {
278+
return AsmCodeRegionGenerator::parseCodeRegions(
279+
IP, SkipUnsupportedInstructions);
268280
}
269281
};
270282

llvm/tools/llvm-mca/llvm-mca.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ int main(int argc, char **argv) {
440440
mca::AsmAnalysisRegionGenerator CRG(*TheTarget, SrcMgr, ACtx, *MAI, *STI,
441441
*MCII);
442442
Expected<const mca::AnalysisRegions &> RegionsOrErr =
443-
CRG.parseAnalysisRegions(std::move(IPtemp));
443+
CRG.parseAnalysisRegions(std::move(IPtemp), SkipUnsupportedInstructions);
444444
if (!RegionsOrErr) {
445445
if (auto Err =
446446
handleErrors(RegionsOrErr.takeError(), [](const StringError &E) {
@@ -482,7 +482,8 @@ int main(int argc, char **argv) {
482482
mca::AsmInstrumentRegionGenerator IRG(*TheTarget, SrcMgr, ICtx, *MAI, *STI,
483483
*MCII, *IM);
484484
Expected<const mca::InstrumentRegions &> InstrumentRegionsOrErr =
485-
IRG.parseInstrumentRegions(std::move(IPtemp));
485+
IRG.parseInstrumentRegions(std::move(IPtemp),
486+
SkipUnsupportedInstructions);
486487
if (!InstrumentRegionsOrErr) {
487488
if (auto Err = handleErrors(InstrumentRegionsOrErr.takeError(),
488489
[](const StringError &E) {

0 commit comments

Comments
 (0)