From 5f79f7506a495872be431a4607a33fa717fda2eb Mon Sep 17 00:00:00 2001 From: Peter Waller Date: Mon, 29 Apr 2024 08:39:15 +0100 Subject: [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. --- llvm/tools/llvm-mca/llvm-mca.cpp | 39 ++++++++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 5 deletions(-) (limited to 'llvm/tools/llvm-mca/llvm-mca.cpp') 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 DisableInstrumentManager( "ignores instruments.)."), cl::cat(ViewOptions), cl::init(false)); +static cl::opt 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 &Region : Regions) { // Skip empty code regions. if (Region->empty()) @@ -571,14 +577,13 @@ int main(int argc, char **argv) { IPP->resetState(); - DenseMap> - InstToInstruments; + DenseMap> InstToInstruments; SmallVector> LoweredSequence; + SmallPtrSet DroppedInsts; for (const MCInst &MCI : Insts) { SMLoc Loc = MCI.getLoc(); const SmallVector Instruments = InstrumentRegions.getActiveInstruments(Loc); - InstToInstruments.insert({&MCI, Instruments}); Expected> Inst = IB.createInstruction(MCI, Instruments); @@ -588,7 +593,15 @@ int main(int argc, char **argv) { [&IP, &STI](const mca::InstructionError &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"; -- cgit v1.1