Skip to content

Commit

Permalink
[TableGen] ShouldIgnore Pattern bit to disable DAG pattern imports du…
Browse files Browse the repository at this point in the history
…ring GISel (llvm#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.
  • Loading branch information
jofrn authored Apr 25, 2024
1 parent 933f492 commit eae7554
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 12 deletions.
1 change: 1 addition & 0 deletions llvm/include/llvm/Target/TargetSelectionDAG.td
Original file line number Diff line number Diff line change
Expand Up @@ -1979,6 +1979,7 @@ class Pattern<dag patternToMatch, list<dag> resultInstrs> {
list<dag> ResultInstrs = resultInstrs;
list<Predicate> Predicates = []; // See class Instruction in Target.td.
int AddedComplexity = 0; // See class Instruction in Target.td.
bit GISelShouldIgnore = 0;
}

// Pat - A simple (but common) form of a pattern, which produces a simple result
Expand Down
6 changes: 6 additions & 0 deletions llvm/test/TableGen/GlobalISelEmitterSkippedPatterns.td
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// RUN: llvm-tblgen -warn-on-skipped-patterns -gen-global-isel -I %p/../../include %s -I %p/Common -o /dev/null 2>&1 | FileCheck %s
// 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

include "llvm/Target/Target.td"
include "GlobalISelEmitterCommon.td"

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

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

#ifdef IGNORE
let GISelShouldIgnore = 1 in
#endif
// IGNORED-NOT: warning: Skipped pattern: Error: {{.*}}
// CHECK: warning: Skipped pattern: Error: Complex suboperand x referenced by different operands: complex_rr:x:y and complex_rr:x:z.
def : Pat<(add (complex_rr GPR32:$x, GPR32:$y),
(complex_rr GPR32:$x, GPR32:$z)),
Expand Down
5 changes: 5 additions & 0 deletions llvm/test/TableGen/simplify-patfrag.td
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// RUN: llvm-tblgen -gen-dag-isel -I %p/../../include %s 2>&1 | FileCheck %s
// RUN: llvm-tblgen -gen-dag-isel -I %p/../../include -DIGNORE %s 2>&1 | FileCheck %s

include "llvm/Target/Target.td"

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

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

Expand Down
16 changes: 9 additions & 7 deletions llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4246,7 +4246,7 @@ static TreePatternNodePtr PromoteXForms(TreePatternNodePtr N) {

void CodeGenDAGPatterns::ParseOnePattern(
Record *TheDef, TreePattern &Pattern, TreePattern &Result,
const std::vector<Record *> &InstImpResults) {
const std::vector<Record *> &InstImpResults, bool ShouldIgnore) {

// Inline pattern fragments and expand multiple alternatives.
Pattern.InlinePatternFragments();
Expand Down Expand Up @@ -4332,7 +4332,7 @@ void CodeGenDAGPatterns::ParseOnePattern(
AddPatternToMatch(&Pattern,
PatternToMatch(TheDef, Preds, T, Temp.getOnlyTree(),
InstImpResults, Complexity,
TheDef->getID()));
TheDef->getID(), ShouldIgnore));
}
} else {
// Show a message about a dropped pattern with some info to make it
Expand Down Expand Up @@ -4378,7 +4378,8 @@ void CodeGenDAGPatterns::ParsePatterns() {
FindPatternInputsAndOutputs(Pattern, Pattern.getTree(j), InstInputs,
InstResults, InstImpResults);

ParseOnePattern(CurPattern, Pattern, Result, InstImpResults);
ParseOnePattern(CurPattern, Pattern, Result, InstImpResults,
CurPattern->getValueAsBit("GISelShouldIgnore"));
}
}

Expand Down Expand Up @@ -4407,10 +4408,10 @@ void CodeGenDAGPatterns::ExpandHwModeBasedTypes() {
return;
}

PatternsToMatch.emplace_back(P.getSrcRecord(), P.getPredicates(),
std::move(NewSrc), std::move(NewDst),
P.getDstRegs(), P.getAddedComplexity(),
Record::getNewUID(Records), Check);
PatternsToMatch.emplace_back(
P.getSrcRecord(), P.getPredicates(), std::move(NewSrc),
std::move(NewDst), P.getDstRegs(), P.getAddedComplexity(),
Record::getNewUID(Records), P.getGISelShouldIgnore(), Check);
};

for (PatternToMatch &P : Copy) {
Expand Down Expand Up @@ -4781,6 +4782,7 @@ void CodeGenDAGPatterns::GenerateVariants() {
Variant, PatternsToMatch[i].getDstPatternShared(),
PatternsToMatch[i].getDstRegs(),
PatternsToMatch[i].getAddedComplexity(), Record::getNewUID(Records),
PatternsToMatch[i].getGISelShouldIgnore(),
PatternsToMatch[i].getHwModeFeatures());
}

Expand Down
14 changes: 9 additions & 5 deletions llvm/utils/TableGen/Common/CodeGenDAGPatterns.h
Original file line number Diff line number Diff line change
Expand Up @@ -1057,17 +1057,19 @@ class PatternToMatch {
TreePatternNodePtr DstPattern; // Resulting pattern.
std::vector<Record *> Dstregs; // Physical register defs being matched.
std::string HwModeFeatures;
int AddedComplexity; // Add to matching pattern complexity.
unsigned ID; // Unique ID for the record.
int AddedComplexity; // Add to matching pattern complexity.
bool GISelShouldIgnore; // Should GlobalISel ignore importing this pattern.
unsigned ID; // Unique ID for the record.

public:
PatternToMatch(Record *srcrecord, ListInit *preds, TreePatternNodePtr src,
TreePatternNodePtr dst, std::vector<Record *> dstregs,
int complexity, unsigned uid, const Twine &hwmodefeatures = "")
int complexity, unsigned uid, bool ignore,
const Twine &hwmodefeatures = "")
: SrcRecord(srcrecord), Predicates(preds), SrcPattern(src),
DstPattern(dst), Dstregs(std::move(dstregs)),
HwModeFeatures(hwmodefeatures.str()), AddedComplexity(complexity),
ID(uid) {}
GISelShouldIgnore(ignore), ID(uid) {}

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

std::string getPredicateCheck() const;
Expand Down Expand Up @@ -1240,7 +1243,8 @@ class CodeGenDAGPatterns {

void ParseOnePattern(Record *TheDef, TreePattern &Pattern,
TreePattern &Result,
const std::vector<Record *> &InstImpResults);
const std::vector<Record *> &InstImpResults,
bool ShouldIgnore = false);
void AddPatternToMatch(TreePattern *Pattern, PatternToMatch &&PTM);
void FindPatternInputsAndOutputs(
TreePattern &I, TreePatternNodePtr Pat,
Expand Down
2 changes: 2 additions & 0 deletions llvm/utils/TableGen/GlobalISelEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2411,6 +2411,8 @@ void GlobalISelEmitter::run(raw_ostream &OS) {
for (const PatternToMatch &Pat : CGP.ptms()) {
++NumPatternTotal;

if (Pat.getGISelShouldIgnore())
continue; // skip without warning
auto MatcherOrErr = runOnPattern(Pat);

// The pattern analysis can fail, indicating an unsupported pattern.
Expand Down

0 comments on commit eae7554

Please sign in to comment.