@@ -1440,24 +1440,50 @@ getPatternComplexity(const CodeGenDAGPatterns &CGP) const {
1440
1440
return getPatternSize (getSrcPattern (), CGP) + getAddedComplexity ();
1441
1441
}
1442
1442
1443
+ void PatternToMatch::getPredicateRecords (
1444
+ SmallVectorImpl<Record *> &PredicateRecs) const {
1445
+ for (Init *I : Predicates->getValues ()) {
1446
+ if (DefInit *Pred = dyn_cast<DefInit>(I)) {
1447
+ Record *Def = Pred->getDef ();
1448
+ if (!Def->isSubClassOf (" Predicate" )) {
1449
+ #ifndef NDEBUG
1450
+ Def->dump ();
1451
+ #endif
1452
+ llvm_unreachable (" Unknown predicate type!" );
1453
+ }
1454
+ PredicateRecs.push_back (Def);
1455
+ }
1456
+ }
1457
+ // Sort so that different orders get canonicalized to the same string.
1458
+ llvm::sort (PredicateRecs, LessRecord ());
1459
+ }
1460
+
1443
1461
// / getPredicateCheck - Return a single string containing all of this
1444
1462
// / pattern's predicates concatenated with "&&" operators.
1445
1463
// /
1446
1464
std::string PatternToMatch::getPredicateCheck () const {
1447
- SmallVector<const Predicate*,4 > PredList;
1448
- for (const Predicate &P : Predicates) {
1449
- if (!P.getCondString ().empty ())
1450
- PredList.push_back (&P);
1465
+ SmallVector<Record *, 4 > PredicateRecs;
1466
+ getPredicateRecords (PredicateRecs);
1467
+
1468
+ SmallString<128 > PredicateCheck;
1469
+ for (Record *Pred : PredicateRecs) {
1470
+ StringRef CondString = Pred->getValueAsString (" CondString" );
1471
+ if (CondString.empty ())
1472
+ continue ;
1473
+ if (!PredicateCheck.empty ())
1474
+ PredicateCheck += " && " ;
1475
+ PredicateCheck += " (" ;
1476
+ PredicateCheck += CondString;
1477
+ PredicateCheck += " )" ;
1451
1478
}
1452
- llvm::sort (PredList, deref<std::less<>>());
1453
1479
1454
- std::string Check;
1455
- for (unsigned i = 0 , e = PredList.size (); i != e; ++i) {
1456
- if (i != 0 )
1457
- Check += " && " ;
1458
- Check += ' (' + PredList[i]->getCondString () + ' )' ;
1480
+ if (!HwModeFeatures.empty ()) {
1481
+ if (!PredicateCheck.empty ())
1482
+ PredicateCheck += " && " ;
1483
+ PredicateCheck += HwModeFeatures;
1459
1484
}
1460
- return Check;
1485
+
1486
+ return std::string (PredicateCheck);
1461
1487
}
1462
1488
1463
1489
// ===----------------------------------------------------------------------===//
@@ -3930,20 +3956,6 @@ static void FindNames(TreePatternNode *P,
3930
3956
}
3931
3957
}
3932
3958
3933
- std::vector<Predicate> CodeGenDAGPatterns::makePredList (ListInit *L) {
3934
- std::vector<Predicate> Preds;
3935
- for (Init *I : L->getValues ()) {
3936
- if (DefInit *Pred = dyn_cast<DefInit>(I))
3937
- Preds.push_back (Pred->getDef ());
3938
- else
3939
- llvm_unreachable (" Non-def on the list" );
3940
- }
3941
-
3942
- // Sort so that different orders get canonicalized to the same string.
3943
- llvm::sort (Preds);
3944
- return Preds;
3945
- }
3946
-
3947
3959
void CodeGenDAGPatterns::AddPatternToMatch (TreePattern *Pattern,
3948
3960
PatternToMatch &&PTM) {
3949
3961
// Do some sanity checking on the pattern we're about to match.
@@ -4254,8 +4266,7 @@ void CodeGenDAGPatterns::ParseOnePattern(Record *TheDef,
4254
4266
for (const auto &T : Pattern.getTrees ())
4255
4267
if (T->hasPossibleType ())
4256
4268
AddPatternToMatch (&Pattern,
4257
- PatternToMatch (TheDef, makePredList (Preds),
4258
- T, Temp.getOnlyTree (),
4269
+ PatternToMatch (TheDef, Preds, T, Temp.getOnlyTree (),
4259
4270
InstImpResults, Complexity,
4260
4271
TheDef->getID ()));
4261
4272
}
@@ -4310,20 +4321,17 @@ void CodeGenDAGPatterns::ExpandHwModeBasedTypes() {
4310
4321
PatternsToMatch.swap (Copy);
4311
4322
4312
4323
auto AppendPattern = [this ](PatternToMatch &P, unsigned Mode,
4313
- ArrayRef<Predicate> Check) {
4324
+ StringRef Check) {
4314
4325
TreePatternNodePtr NewSrc = P.getSrcPattern ()->clone ();
4315
4326
TreePatternNodePtr NewDst = P.getDstPattern ()->clone ();
4316
4327
if (!NewSrc->setDefaultMode (Mode) || !NewDst->setDefaultMode (Mode)) {
4317
4328
return ;
4318
4329
}
4319
4330
4320
- std::vector<Predicate> Preds = P.getPredicates ();
4321
- llvm::append_range (Preds, Check);
4322
- PatternsToMatch.emplace_back (P.getSrcRecord (), std::move (Preds),
4331
+ PatternsToMatch.emplace_back (P.getSrcRecord (), P.getPredicates (),
4323
4332
std::move (NewSrc), std::move (NewDst),
4324
- P.getDstRegs (),
4325
- P.getAddedComplexity (), Record::getNewUID (),
4326
- Mode);
4333
+ P.getDstRegs (), P.getAddedComplexity (),
4334
+ Record::getNewUID (), Mode, Check);
4327
4335
};
4328
4336
4329
4337
for (PatternToMatch &P : Copy) {
@@ -4354,18 +4362,22 @@ void CodeGenDAGPatterns::ExpandHwModeBasedTypes() {
4354
4362
// duplicated patterns with different predicate checks, construct the
4355
4363
// default check as a negation of all predicates that are actually present
4356
4364
// in the source/destination patterns.
4357
- SmallVector<Predicate, 2 > DefaultCheck;
4365
+ SmallString< 128 > DefaultCheck;
4358
4366
4359
4367
for (unsigned M : Modes) {
4360
4368
if (M == DefaultMode)
4361
4369
continue ;
4362
4370
4363
4371
// Fill the map entry for this mode.
4364
4372
const HwMode &HM = CGH.getMode (M);
4365
- AppendPattern (P, M, Predicate ( HM.Features , true ) );
4373
+ AppendPattern (P, M, " (MF->getSubtarget().checkFeatures( \" " + HM.Features + " \" )) " );
4366
4374
4367
4375
// Add negations of the HM's predicates to the default predicate.
4368
- DefaultCheck.push_back (Predicate (HM.Features , false ));
4376
+ if (!DefaultCheck.empty ())
4377
+ DefaultCheck += " && " ;
4378
+ DefaultCheck += " (!(MF->getSubtarget().checkFeatures(\" " ;
4379
+ DefaultCheck += HM.Features ;
4380
+ DefaultCheck += " \" )))" ;
4369
4381
}
4370
4382
4371
4383
bool HasDefault = Modes.count (DefaultMode);
@@ -4685,8 +4697,8 @@ void CodeGenDAGPatterns::GenerateVariants() {
4685
4697
if (MatchedPatterns[i])
4686
4698
continue ;
4687
4699
4688
- const std::vector<Predicate> & Predicates =
4689
- PatternsToMatch[i].getPredicates ();
4700
+ ListInit * Predicates = PatternsToMatch[i]. getPredicates ();
4701
+ StringRef HwModeFeatures = PatternsToMatch[i].getHwModeFeatures ();
4690
4702
4691
4703
BitVector &Matches = MatchedPredicates[i];
4692
4704
MatchedPatterns.set (i);
@@ -4695,7 +4707,8 @@ void CodeGenDAGPatterns::GenerateVariants() {
4695
4707
// Don't test patterns that have already been cached - it won't match.
4696
4708
for (unsigned p = 0 ; p != NumOriginalPatterns; ++p)
4697
4709
if (!MatchedPatterns[p])
4698
- Matches[p] = (Predicates == PatternsToMatch[p].getPredicates ());
4710
+ Matches[p] = (Predicates == PatternsToMatch[p].getPredicates ()) &&
4711
+ (HwModeFeatures == PatternsToMatch[p].getHwModeFeatures ());
4699
4712
4700
4713
// Copy this to all the matching patterns.
4701
4714
for (int p = Matches.find_first (); p != -1 ; p = Matches.find_next (p))
@@ -4739,7 +4752,9 @@ void CodeGenDAGPatterns::GenerateVariants() {
4739
4752
PatternsToMatch[i].getSrcRecord (), PatternsToMatch[i].getPredicates (),
4740
4753
Variant, PatternsToMatch[i].getDstPatternShared (),
4741
4754
PatternsToMatch[i].getDstRegs (),
4742
- PatternsToMatch[i].getAddedComplexity (), Record::getNewUID ());
4755
+ PatternsToMatch[i].getAddedComplexity (), Record::getNewUID (),
4756
+ PatternsToMatch[i].getForceMode (),
4757
+ PatternsToMatch[i].getHwModeFeatures ().str ());
4743
4758
MatchedPredicates.push_back (Matches);
4744
4759
4745
4760
// Add a new match the same as this pattern.
0 commit comments