diff options
author | Peter Waller <peter.waller@arm.com> | 2024-04-29 08:39:15 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-29 08:39:15 +0100 |
commit | 5f79f7506a495872be431a4607a33fa717fda2eb (patch) | |
tree | dbe953518df1ff4ae7b9b53d37ff9a210135918b /llvm/tools/llvm-mca/llvm-mca.cpp | |
parent | e1622e189e8c0ef457bfac528f90a7a930d9aad2 (diff) | |
download | llvm-5f79f7506a495872be431a4607a33fa717fda2eb.zip llvm-5f79f7506a495872be431a4607a33fa717fda2eb.tar.gz llvm-5f79f7506a495872be431a4607a33fa717fda2eb.tar.bz2 |
[llvm-mca] Add -skip-unsupported-instructions option (#89733)
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.
~Testing the feature is a little awkward currently, it relies on an
instruction
which is currently marked as unsupported, which may not remain so;
should the
situation change it would be necessary to find an alternative
unsupported
instruction or drop the test.~
A test is added to check that analysis still reports an error if all
instructions are removed from the input, to mirror the current behaviour
of giving an error if no instructions are supplied.
Diffstat (limited to 'llvm/tools/llvm-mca/llvm-mca.cpp')
-rw-r--r-- | llvm/tools/llvm-mca/llvm-mca.cpp | 39 |
1 files changed, 34 insertions, 5 deletions
diff --git a/llvm/tools/llvm-mca/llvm-mca.cpp b/llvm/tools/llvm-mca/llvm-mca.cpp index eb71cff..e037c06 100644 --- a/llvm/tools/llvm-mca/llvm-mca.cpp +++ b/llvm/tools/llvm-mca/llvm-mca.cpp @@ -237,6 +237,11 @@ 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) { @@ -558,6 +563,7 @@ int main(int argc, char **argv) { assert(MAB && "Unable to create asm backend!"); json::Object JSONOutput; + int NonEmptyRegions = 0; for (const std::unique_ptr<mca::AnalysisRegion> &Region : Regions) { // Skip empty code regions. if (Region->empty()) @@ -571,14 +577,13 @@ int main(int argc, char **argv) { IPP->resetState(); - DenseMap<const MCInst *, SmallVector<mca::Instrument *>> - InstToInstruments; + DenseMap<const MCInst *, SmallVector<mca::Instrument *>> InstToInstruments; SmallVector<std::unique_ptr<mca::Instruction>> LoweredSequence; + SmallPtrSet<const MCInst *, 16> DroppedInsts; for (const MCInst &MCI : Insts) { SMLoc Loc = MCI.getLoc(); const SmallVector<mca::Instrument *> Instruments = InstrumentRegions.getActiveInstruments(Loc); - InstToInstruments.insert({&MCI, Instruments}); Expected<std::unique_ptr<mca::Instruction>> Inst = IB.createInstruction(MCI, Instruments); @@ -588,7 +593,15 @@ int main(int argc, char **argv) { [&IP, &STI](const mca::InstructionError<MCInst> &IE) { std::string InstructionStr; raw_string_ostream SS(InstructionStr); - WithColor::error() << IE.Message << '\n'; + if (SkipUnsupportedInstructions) + WithColor::warning() + << IE.Message + << ", skipping with -skip-unsupported-instructions, " + "note accuracy will be impacted:\n"; + else + WithColor::error() + << IE.Message + << ", use -skip-unsupported-instructions to ignore.\n"; IP->printInst(&IE.Inst, 0, "", *STI, SS); SS.flush(); WithColor::note() @@ -597,14 +610,25 @@ int main(int argc, char **argv) { // Default case. WithColor::error() << toString(std::move(NewE)); } + if (SkipUnsupportedInstructions) { + DroppedInsts.insert(&MCI); + continue; + } return 1; } IPP->postProcessInstruction(Inst.get(), MCI); - + InstToInstruments.insert({&MCI, Instruments}); LoweredSequence.emplace_back(std::move(Inst.get())); } + Insts = Region->dropInstructions(DroppedInsts); + + // Skip empty regions. + if (Insts.empty()) + continue; + NonEmptyRegions++; + mca::CircularSourceMgr S(LoweredSequence, PrintInstructionTables ? 1 : Iterations); @@ -759,6 +783,11 @@ int main(int argc, char **argv) { ++RegionIdx; } + if (NonEmptyRegions == 0) { + WithColor::error() << "no assembly instructions found.\n"; + return 1; + } + if (PrintJson) TOF->os() << formatv("{0:2}", json::Value(std::move(JSONOutput))) << "\n"; |