Skip to content

Commit c1fc189

Browse files
[llvm-mca] Add -skip-unsupported-instructions option
Prior to this patch, if llvm-mca encountered an instruction which parses but has no scheduler info, the instruction is always reported as unsupported, and llvm-mca halts with an error. However, it would still be useful to allow MCA to continue even in the case of instructions lacking scheduling information. Obviously if scheduling information is lacking, it's not possible to give an accurate analysis for those instructions, and therefore a warning is emitted. A user could previously have worked around such unsupported instructions manually by deleting such instructions from the input, but this provides them a way of doing this for bulk inputs where they may not have a list of such unsupported instructions to drop up front. Note that this behaviour of instructions with no scheduling information under -skip-unsupported-instructions is analagous to current instructions which fail to parse: those are currently dropped from the input with a message printed, after which the analysis continues.
1 parent f89f670 commit c1fc189

File tree

4 files changed

+48
-7
lines changed

4 files changed

+48
-7
lines changed

llvm/lib/MCA/InstrBuilder.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -542,8 +542,7 @@ InstrBuilder::createInstrDescImpl(const MCInst &MCI,
542542
const MCSchedClassDesc &SCDesc = *SM.getSchedClassDesc(SchedClassID);
543543
if (SCDesc.NumMicroOps == MCSchedClassDesc::InvalidNumMicroOps) {
544544
return make_error<InstructionError<MCInst>>(
545-
"found an unsupported instruction in the input assembly sequence.",
546-
MCI);
545+
"found an unsupported instruction in the input assembly sequence", MCI);
547546
}
548547

549548
LLVM_DEBUG(dbgs() << "\n\t\tOpcode Name= " << MCII.getName(Opcode) << '\n');
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# RUN: llvm-mca -march=aarch64 -mcpu=neoverse-v2 -skip-unsupported-instructions %s |& FileCheck --check-prefix=CHECK-SKIP %s
2+
# RUN: not llvm-mca -march=aarch64 -mcpu=neoverse-v2 %s |& FileCheck --check-prefix=CHECK-ERROR %s
3+
4+
# CHECK-SKIP: warning: found an unsupported instruction in the input assembly sequence, skipping with -skip-unsupported-instructions, note accuracy will be impacted:
5+
# CHECK-ERROR: error: found an unsupported instruction in the input assembly sequence, use -skip-unsupported-instructions to ignore.
6+
7+
# Currently lacks scheduling information and is therefore reported as unsupported by llvm-mca.
8+
# This may change some day in which case an alternative unsupported input would need to be found or the test removed.
9+
steor x0, [x1]

llvm/tools/llvm-mca/CodeRegion.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
#define LLVM_TOOLS_LLVM_MCA_CODEREGION_H
6060

6161
#include "llvm/ADT/ArrayRef.h"
62+
#include "llvm/ADT/SmallPtrSet.h"
6263
#include "llvm/ADT/SmallVector.h"
6364
#include "llvm/ADT/StringMap.h"
6465
#include "llvm/ADT/StringRef.h"
@@ -97,6 +98,20 @@ class CodeRegion {
9798
Instructions.emplace_back(Instruction);
9899
}
99100

101+
// Remove the given instructions from the set, for unsupported instructions
102+
// being skipped. Returns an ArrayRef for the updated vector of Instructions.
103+
[[nodiscard]] llvm::ArrayRef<llvm::MCInst>
104+
dropInstructions(const llvm::SmallPtrSetImpl<const llvm::MCInst *> &Insts) {
105+
if (Insts.empty())
106+
return Instructions;
107+
Instructions.erase(std::remove_if(Instructions.begin(), Instructions.end(),
108+
[&Insts](const llvm::MCInst &Inst) {
109+
return Insts.contains(&Inst);
110+
}),
111+
Instructions.end());
112+
return Instructions;
113+
}
114+
100115
llvm::SMLoc startLoc() const { return RangeStart; }
101116
llvm::SMLoc endLoc() const { return RangeEnd; }
102117

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

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,11 @@ static cl::opt<bool> DisableInstrumentManager(
237237
"ignores instruments.)."),
238238
cl::cat(ViewOptions), cl::init(false));
239239

240+
static cl::opt<bool> SkipUnsupportedInstructions(
241+
"skip-unsupported-instructions",
242+
cl::desc("Make unsupported instruction errors into warnings."),
243+
cl::cat(ViewOptions), cl::init(false));
244+
240245
namespace {
241246

242247
const Target *getTarget(const char *ProgName) {
@@ -571,14 +576,13 @@ int main(int argc, char **argv) {
571576

572577
IPP->resetState();
573578

574-
DenseMap<const MCInst *, SmallVector<mca::Instrument *>>
575-
InstToInstruments;
579+
DenseMap<const MCInst *, SmallVector<mca::Instrument *>> InstToInstruments;
576580
SmallVector<std::unique_ptr<mca::Instruction>> LoweredSequence;
581+
SmallPtrSet<const MCInst *, 16> DroppedInsts;
577582
for (const MCInst &MCI : Insts) {
578583
SMLoc Loc = MCI.getLoc();
579584
const SmallVector<mca::Instrument *> Instruments =
580585
InstrumentRegions.getActiveInstruments(Loc);
581-
InstToInstruments.insert({&MCI, Instruments});
582586

583587
Expected<std::unique_ptr<mca::Instruction>> Inst =
584588
IB.createInstruction(MCI, Instruments);
@@ -588,7 +592,15 @@ int main(int argc, char **argv) {
588592
[&IP, &STI](const mca::InstructionError<MCInst> &IE) {
589593
std::string InstructionStr;
590594
raw_string_ostream SS(InstructionStr);
591-
WithColor::error() << IE.Message << '\n';
595+
if (SkipUnsupportedInstructions)
596+
WithColor::warning()
597+
<< IE.Message
598+
<< ", skipping with -skip-unsupported-instructions, "
599+
"note accuracy will be impacted:\n";
600+
else
601+
WithColor::error()
602+
<< IE.Message
603+
<< ", use -skip-unsupported-instructions to ignore.";
592604
IP->printInst(&IE.Inst, 0, "", *STI, SS);
593605
SS.flush();
594606
WithColor::note()
@@ -597,14 +609,20 @@ int main(int argc, char **argv) {
597609
// Default case.
598610
WithColor::error() << toString(std::move(NewE));
599611
}
612+
if (SkipUnsupportedInstructions) {
613+
DroppedInsts.insert(&MCI);
614+
continue;
615+
}
600616
return 1;
601617
}
602618

603619
IPP->postProcessInstruction(Inst.get(), MCI);
604-
620+
InstToInstruments.insert({&MCI, Instruments});
605621
LoweredSequence.emplace_back(std::move(Inst.get()));
606622
}
607623

624+
Insts = Region->dropInstructions(DroppedInsts);
625+
608626
mca::CircularSourceMgr S(LoweredSequence,
609627
PrintInstructionTables ? 1 : Iterations);
610628

0 commit comments

Comments
 (0)