From d044f9c9a76edb566feb2a6618f652f79780a3ad Mon Sep 17 00:00:00 2001 From: Simon Pilgrim Date: Sun, 25 Mar 2018 19:20:08 +0000 Subject: [PATCH] [SchedModel] Remove instregex entries that don't match any instructions This patch throws a fatal error if an instregex entry doesn't actually match any instructions. This is part of the work to reduce the compile time impact of increased instregex usage (PR35955), although the x86 models seem to be relatively clean. All the cases I encountered have now been fixed in trunk and this will ensure they don't get reintroduced. Differential Revision: https://reviews.llvm.org/D44687 llvm-svn: 328459 --- llvm/utils/TableGen/CodeGenSchedule.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/llvm/utils/TableGen/CodeGenSchedule.cpp b/llvm/utils/TableGen/CodeGenSchedule.cpp index 9f9b32b..7791f4a 100644 --- a/llvm/utils/TableGen/CodeGenSchedule.cpp +++ b/llvm/utils/TableGen/CodeGenSchedule.cpp @@ -106,6 +106,8 @@ struct InstRegexOp : public SetTheory::Operator { Regexpr = Regex(pat); } + int NumMatches = 0; + unsigned NumGeneric = Target.getNumFixedInstructions(); ArrayRef Generics = Target.getInstructionsByEnumValue().slice(0, NumGeneric + 1); @@ -114,8 +116,10 @@ struct InstRegexOp : public SetTheory::Operator { for (auto *Inst : Generics) { StringRef InstName = Inst->TheDef->getName(); if (InstName.startswith(Prefix) && - (!Regexpr || Regexpr->match(InstName.substr(Prefix.size())))) + (!Regexpr || Regexpr->match(InstName.substr(Prefix.size())))) { Elts.insert(Inst->TheDef); + NumMatches++; + } } ArrayRef Instructions = @@ -139,9 +143,14 @@ struct InstRegexOp : public SetTheory::Operator { // a regex that needs to be checked. for (auto *Inst : make_range(Range)) { StringRef InstName = Inst->TheDef->getName(); - if (!Regexpr || Regexpr->match(InstName.substr(Prefix.size()))) + if (!Regexpr || Regexpr->match(InstName.substr(Prefix.size()))) { Elts.insert(Inst->TheDef); + NumMatches++; + } } + + if (0 == NumMatches) + PrintFatalError(Loc, "instregex has no matches: " + Original); } } }; -- 2.7.4