Skip to content

Commit eae7554

Browse files
authored
[TableGen] ShouldIgnore Pattern bit to disable DAG pattern imports during GISel (#88382)
Added GISelShouldIgnore property to class Pattern in TargetSelectionDAG.td; it's similar to FastISelShouldIgnore. This bit can be put on a record to avoid its pattern import within GlobalISelEmitter. This allows one to avoid the record's GISel .td implementation, .inc generation, and any skipped pattern warnings from -warn-on-skipped-patterns.
1 parent 933f492 commit eae7554

File tree

6 files changed

+32
-12
lines changed

6 files changed

+32
-12
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 GISelShouldIgnore = 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=IGNORED %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 GISelShouldIgnore = 1 in
30+
#endif
31+
// IGNORED-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/test/TableGen/simplify-patfrag.td

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// RUN: llvm-tblgen -gen-dag-isel -I %p/../../include %s 2>&1 | FileCheck %s
2+
// RUN: llvm-tblgen -gen-dag-isel -I %p/../../include -DIGNORE %s 2>&1 | FileCheck %s
23

34
include "llvm/Target/Target.td"
45

@@ -29,6 +30,10 @@ def anyconvert : PatFrags<(ops node:$src),
2930
[(bitconvert node:$src),
3031
(specialconvert node:$src)]>;
3132

33+
#ifdef IGNORE
34+
// Ensure ShouldIgnore does not disable records in dag isel emitter
35+
let GISelShouldIgnore = 1 in
36+
#endif
3237
// And a rule that matches that PatFrag and turns it into i2f
3338
def : Pat<(f32 (anyconvert (i32 GPR:$val))), (i2f GPR:$val)>;
3439

llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp

Lines changed: 9 additions & 7 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("GISelShouldIgnore"));
43824383
}
43834384
}
43844385

@@ -4407,10 +4408,10 @@ void CodeGenDAGPatterns::ExpandHwModeBasedTypes() {
44074408
return;
44084409
}
44094410

4410-
PatternsToMatch.emplace_back(P.getSrcRecord(), P.getPredicates(),
4411-
std::move(NewSrc), std::move(NewDst),
4412-
P.getDstRegs(), P.getAddedComplexity(),
4413-
Record::getNewUID(Records), Check);
4411+
PatternsToMatch.emplace_back(
4412+
P.getSrcRecord(), P.getPredicates(), std::move(NewSrc),
4413+
std::move(NewDst), P.getDstRegs(), P.getAddedComplexity(),
4414+
Record::getNewUID(Records), P.getGISelShouldIgnore(), 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].getGISelShouldIgnore(),
47844786
PatternsToMatch[i].getHwModeFeatures());
47854787
}
47864788

llvm/utils/TableGen/Common/CodeGenDAGPatterns.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,17 +1057,19 @@ 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 GISelShouldIgnore; // Should GlobalISel ignore importing 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,
1068+
const Twine &hwmodefeatures = "")
10671069
: SrcRecord(srcrecord), Predicates(preds), SrcPattern(src),
10681070
DstPattern(dst), Dstregs(std::move(dstregs)),
10691071
HwModeFeatures(hwmodefeatures.str()), AddedComplexity(complexity),
1070-
ID(uid) {}
1072+
GISelShouldIgnore(ignore), ID(uid) {}
10711073

10721074
Record *getSrcRecord() const { return SrcRecord; }
10731075
ListInit *getPredicates() const { return Predicates; }
@@ -1078,6 +1080,7 @@ class PatternToMatch {
10781080
const std::vector<Record *> &getDstRegs() const { return Dstregs; }
10791081
StringRef getHwModeFeatures() const { return HwModeFeatures; }
10801082
int getAddedComplexity() const { return AddedComplexity; }
1083+
bool getGISelShouldIgnore() const { return GISelShouldIgnore; }
10811084
unsigned getID() const { return ID; }
10821085

10831086
std::string getPredicateCheck() const;
@@ -1240,7 +1243,8 @@ class CodeGenDAGPatterns {
12401243

12411244
void ParseOnePattern(Record *TheDef, TreePattern &Pattern,
12421245
TreePattern &Result,
1243-
const std::vector<Record *> &InstImpResults);
1246+
const std::vector<Record *> &InstImpResults,
1247+
bool ShouldIgnore = false);
12441248
void AddPatternToMatch(TreePattern *Pattern, PatternToMatch &&PTM);
12451249
void FindPatternInputsAndOutputs(
12461250
TreePattern &I, TreePatternNodePtr Pat,

llvm/utils/TableGen/GlobalISelEmitter.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2411,6 +2411,8 @@ void GlobalISelEmitter::run(raw_ostream &OS) {
24112411
for (const PatternToMatch &Pat : CGP.ptms()) {
24122412
++NumPatternTotal;
24132413

2414+
if (Pat.getGISelShouldIgnore())
2415+
continue; // skip without warning
24142416
auto MatcherOrErr = runOnPattern(Pat);
24152417

24162418
// The pattern analysis can fail, indicating an unsupported pattern.

0 commit comments

Comments
 (0)