Skip to content

Commit c206eb6

Browse files
committed
[TableGen] Added tblgen ISelShouldIgnore bit to class Pattern to disable pattern imports in GISel
Via `let ISelShouldIgnore = 1`, a Pattern record can be disabled to skip pattern warnings in GlobalISel.
1 parent ad38450 commit c206eb6

File tree

5 files changed

+31
-14
lines changed

5 files changed

+31
-14
lines changed

llvm/include/llvm/Target/TargetSelectionDAG.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1979,6 +1979,7 @@ class Pattern<dag patternToMatch, list<dag> resultInstrs> {
19791979
list<dag> ResultInstrs = resultInstrs;
19801980
list<Predicate> Predicates = []; // See class Instruction in Target.td.
19811981
int AddedComplexity = 0; // See class Instruction in Target.td.
1982+
bit ISelShouldIgnore = 0;
19821983
}
19831984

19841985
// Pat - A simple (but common) form of a pattern, which produces a simple result

llvm/test/TableGen/GlobalISelEmitterSkippedPatterns.td

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
// RUN: llvm-tblgen -warn-on-skipped-patterns -gen-global-isel -I %p/../../include %s -I %p/Common -o /dev/null 2>&1 | FileCheck %s
2+
// RUN: llvm-tblgen -warn-on-skipped-patterns -gen-global-isel -I %p/../../include %s -I %p/Common -o /dev/null -DIGNORE 2>&1 | FileCheck --allow-empty --check-prefix=CHECK0 %s
3+
24
include "llvm/Target/Target.td"
35
include "GlobalISelEmitterCommon.td"
46

@@ -23,6 +25,10 @@ def INSN : I<(outs GPR32:$dst), (ins GPR32:$src1, complex:$src2), []>;
2325

2426
//===- Bail out when we define a variable twice wrt complex suboperands. -===//
2527

28+
#ifdef IGNORE
29+
let ISelShouldIgnore = 1 in
30+
#endif
31+
// CHECK0-NOT: warning: Skipped pattern: Error: {{.*}}
2632
// CHECK: warning: Skipped pattern: Error: Complex suboperand x referenced by different operands: complex_rr:x:y and complex_rr:x:z.
2733
def : Pat<(add (complex_rr GPR32:$x, GPR32:$y),
2834
(complex_rr GPR32:$x, GPR32:$z)),

llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4246,7 +4246,7 @@ static TreePatternNodePtr PromoteXForms(TreePatternNodePtr N) {
42464246

42474247
void CodeGenDAGPatterns::ParseOnePattern(
42484248
Record *TheDef, TreePattern &Pattern, TreePattern &Result,
4249-
const std::vector<Record *> &InstImpResults) {
4249+
const std::vector<Record *> &InstImpResults, bool ShouldIgnore) {
42504250

42514251
// Inline pattern fragments and expand multiple alternatives.
42524252
Pattern.InlinePatternFragments();
@@ -4332,7 +4332,7 @@ void CodeGenDAGPatterns::ParseOnePattern(
43324332
AddPatternToMatch(&Pattern,
43334333
PatternToMatch(TheDef, Preds, T, Temp.getOnlyTree(),
43344334
InstImpResults, Complexity,
4335-
TheDef->getID()));
4335+
TheDef->getID(), ShouldIgnore));
43364336
}
43374337
} else {
43384338
// Show a message about a dropped pattern with some info to make it
@@ -4378,7 +4378,8 @@ void CodeGenDAGPatterns::ParsePatterns() {
43784378
FindPatternInputsAndOutputs(Pattern, Pattern.getTree(j), InstInputs,
43794379
InstResults, InstImpResults);
43804380

4381-
ParseOnePattern(CurPattern, Pattern, Result, InstImpResults);
4381+
ParseOnePattern(CurPattern, Pattern, Result, InstImpResults,
4382+
CurPattern->getValueAsBit("ISelShouldIgnore"));
43824383
}
43834384
}
43844385

@@ -4410,7 +4411,7 @@ void CodeGenDAGPatterns::ExpandHwModeBasedTypes() {
44104411
PatternsToMatch.emplace_back(P.getSrcRecord(), P.getPredicates(),
44114412
std::move(NewSrc), std::move(NewDst),
44124413
P.getDstRegs(), P.getAddedComplexity(),
4413-
Record::getNewUID(Records), Check);
4414+
Record::getNewUID(Records), P.getISelShouldIgnore(), Check);
44144415
};
44154416

44164417
for (PatternToMatch &P : Copy) {
@@ -4781,6 +4782,7 @@ void CodeGenDAGPatterns::GenerateVariants() {
47814782
Variant, PatternsToMatch[i].getDstPatternShared(),
47824783
PatternsToMatch[i].getDstRegs(),
47834784
PatternsToMatch[i].getAddedComplexity(), Record::getNewUID(Records),
4785+
PatternsToMatch[i].getISelShouldIgnore(),
47844786
PatternsToMatch[i].getHwModeFeatures());
47854787
}
47864788

llvm/utils/TableGen/Common/CodeGenDAGPatterns.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,16 +1057,17 @@ class PatternToMatch {
10571057
TreePatternNodePtr DstPattern; // Resulting pattern.
10581058
std::vector<Record *> Dstregs; // Physical register defs being matched.
10591059
std::string HwModeFeatures;
1060-
int AddedComplexity; // Add to matching pattern complexity.
1061-
unsigned ID; // Unique ID for the record.
1060+
int AddedComplexity; // Add to matching pattern complexity.
1061+
bool ISelShouldIgnore; // Should ISel ignore this pattern.
1062+
unsigned ID; // Unique ID for the record.
10621063

10631064
public:
10641065
PatternToMatch(Record *srcrecord, ListInit *preds, TreePatternNodePtr src,
10651066
TreePatternNodePtr dst, std::vector<Record *> dstregs,
1066-
int complexity, unsigned uid, const Twine &hwmodefeatures = "")
1067+
int complexity, unsigned uid, bool ignore, const Twine &hwmodefeatures = "")
10671068
: SrcRecord(srcrecord), Predicates(preds), SrcPattern(src),
10681069
DstPattern(dst), Dstregs(std::move(dstregs)),
1069-
HwModeFeatures(hwmodefeatures.str()), AddedComplexity(complexity),
1070+
HwModeFeatures(hwmodefeatures.str()), AddedComplexity(complexity), ISelShouldIgnore(ignore),
10701071
ID(uid) {}
10711072

10721073
Record *getSrcRecord() const { return SrcRecord; }
@@ -1078,6 +1079,7 @@ class PatternToMatch {
10781079
const std::vector<Record *> &getDstRegs() const { return Dstregs; }
10791080
StringRef getHwModeFeatures() const { return HwModeFeatures; }
10801081
int getAddedComplexity() const { return AddedComplexity; }
1082+
bool getISelShouldIgnore() const { return ISelShouldIgnore; }
10811083
unsigned getID() const { return ID; }
10821084

10831085
std::string getPredicateCheck() const;
@@ -1240,7 +1242,8 @@ class CodeGenDAGPatterns {
12401242

12411243
void ParseOnePattern(Record *TheDef, TreePattern &Pattern,
12421244
TreePattern &Result,
1243-
const std::vector<Record *> &InstImpResults);
1245+
const std::vector<Record *> &InstImpResults,
1246+
bool ShouldIgnore = false);
12441247
void AddPatternToMatch(TreePattern *Pattern, PatternToMatch &&PTM);
12451248
void FindPatternInputsAndOutputs(
12461249
TreePattern &I, TreePatternNodePtr Pat,

llvm/utils/TableGen/GlobalISelEmitter.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ class GlobalISelEmitter final : public GlobalISelMatchTableExecutorEmitter {
428428

429429
/// Analyze pattern \p P, returning a matcher for it if possible.
430430
/// Otherwise, return an Error explaining why we don't support it.
431-
Expected<RuleMatcher> runOnPattern(const PatternToMatch &P);
431+
std::optional<Expected<RuleMatcher>> runOnPattern(const PatternToMatch &P);
432432

433433
void declareSubtargetFeature(Record *Predicate);
434434

@@ -1901,7 +1901,11 @@ std::optional<CodeGenSubRegIndex *> GlobalISelEmitter::inferSubRegIndexForNode(
19011901
return CGRegs.getSubRegIdx(SubRegInit->getDef());
19021902
}
19031903

1904-
Expected<RuleMatcher> GlobalISelEmitter::runOnPattern(const PatternToMatch &P) {
1904+
std::optional<Expected<RuleMatcher>> GlobalISelEmitter::runOnPattern(const PatternToMatch &P) {
1905+
if (P.getISelShouldIgnore()) {
1906+
return {};
1907+
}
1908+
19051909
// Keep track of the matchers and actions to emit.
19061910
int Score = P.getPatternComplexity(CGP);
19071911
RuleMatcher M(P.getSrcRecord()->getLoc());
@@ -2412,10 +2416,11 @@ void GlobalISelEmitter::run(raw_ostream &OS) {
24122416
++NumPatternTotal;
24132417

24142418
auto MatcherOrErr = runOnPattern(Pat);
2419+
if (!MatcherOrErr) continue; // skip without warning
24152420

24162421
// The pattern analysis can fail, indicating an unsupported pattern.
24172422
// Report that if we've been asked to do so.
2418-
if (auto Err = MatcherOrErr.takeError()) {
2423+
if (auto Err = MatcherOrErr->takeError()) {
24192424
if (WarnOnSkippedPatterns) {
24202425
PrintWarning(Pat.getSrcRecord()->getLoc(),
24212426
"Skipped pattern: " + toString(std::move(Err)));
@@ -2427,13 +2432,13 @@ void GlobalISelEmitter::run(raw_ostream &OS) {
24272432
}
24282433

24292434
if (RuleCoverage) {
2430-
if (RuleCoverage->isCovered(MatcherOrErr->getRuleID()))
2435+
if (RuleCoverage->isCovered((*MatcherOrErr)->getRuleID()))
24312436
++NumPatternsTested;
24322437
else
24332438
PrintWarning(Pat.getSrcRecord()->getLoc(),
24342439
"Pattern is not covered by a test");
24352440
}
2436-
Rules.push_back(std::move(MatcherOrErr.get()));
2441+
Rules.push_back(std::move(MatcherOrErr->get()));
24372442
postProcessRule(Rules.back());
24382443
}
24392444

0 commit comments

Comments
 (0)