[PATCH] D50566: [Tablegen][SubtargetEmitter] Improve expansion of predicates of a variant scheduling class.
Phabricator via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 13 04:09:55 PDT 2018
This revision was automatically updated to reflect the committed changes.
Closed by commit rL339552: [Tablegen][SubtargetEmitter] Improve expansion of predicates of a variant… (authored by adibiagio, committed by ).
Changed prior to commit:
https://reviews.llvm.org/D50566?vs=160126&id=160326#toc
Repository:
rL LLVM
https://reviews.llvm.org/D50566
Files:
llvm/trunk/include/llvm/Target/TargetSchedule.td
llvm/trunk/utils/TableGen/SubtargetEmitter.cpp
Index: llvm/trunk/utils/TableGen/SubtargetEmitter.cpp
===================================================================
--- llvm/trunk/utils/TableGen/SubtargetEmitter.cpp
+++ llvm/trunk/utils/TableGen/SubtargetEmitter.cpp
@@ -1480,30 +1480,54 @@
}
static void emitPredicates(const CodeGenSchedTransition &T,
- const CodeGenSchedClass &SC,
- PredicateExpander &PE,
+ const CodeGenSchedClass &SC, PredicateExpander &PE,
raw_ostream &OS) {
std::string Buffer;
raw_string_ostream StringStream(Buffer);
formatted_raw_ostream FOS(StringStream);
FOS.PadToColumn(6);
- FOS << "if (";
- for (RecIter RI = T.PredTerm.begin(), RE = T.PredTerm.end(); RI != RE; ++RI) {
- if (RI != T.PredTerm.begin()) {
- FOS << "\n";
- FOS.PadToColumn(8);
- FOS << "&& ";
- }
- const Record *Rec = *RI;
- if (Rec->isSubClassOf("MCSchedPredicate"))
- PE.expandPredicate(FOS, Rec->getValueAsDef("Pred"));
- else
- FOS << "(" << Rec->getValueAsString("Predicate") << ")";
+
+ auto IsTruePredicate = [](const Record *Rec) {
+ return Rec->isSubClassOf("MCSchedPredicate") &&
+ Rec->getValueAsDef("Pred")->isSubClassOf("MCTrue");
+ };
+
+ // If not all predicates are MCTrue, then we need an if-stmt.
+ unsigned NumNonTruePreds =
+ T.PredTerm.size() - count_if(T.PredTerm, IsTruePredicate);
+ if (NumNonTruePreds) {
+ bool FirstNonTruePredicate = true;
+ for (const Record *Rec : T.PredTerm) {
+ // Skip predicates that evaluate to "true".
+ if (IsTruePredicate(Rec))
+ continue;
+
+ if (FirstNonTruePredicate) {
+ FOS << "if (";
+ FirstNonTruePredicate = false;
+ } else {
+ FOS << "\n";
+ FOS.PadToColumn(8);
+ FOS << "&& ";
+ }
+
+ if (Rec->isSubClassOf("MCSchedPredicate")) {
+ PE.expandPredicate(FOS, Rec->getValueAsDef("Pred"));
+ continue;
+ }
+
+ // Expand this legacy predicate and wrap it around braces if there is more
+ // than one predicate to expand.
+ FOS << ((NumNonTruePreds > 1) ? "(" : "")
+ << Rec->getValueAsString("Predicate")
+ << ((NumNonTruePreds > 1) ? ")" : "");
+ }
+
+ FOS << ")\n"; // end of if-stmt
+ FOS.PadToColumn(8);
}
- FOS << ")\n";
- FOS.PadToColumn(8);
FOS << "return " << T.ToClassIdx << "; // " << SC.Name << '\n';
FOS.flush();
OS << Buffer;
Index: llvm/trunk/include/llvm/Target/TargetSchedule.td
===================================================================
--- llvm/trunk/include/llvm/Target/TargetSchedule.td
+++ llvm/trunk/include/llvm/Target/TargetSchedule.td
@@ -373,7 +373,7 @@
SchedMachineModel SchedModel = ?;
code Predicate = pred;
}
-def NoSchedPred : SchedPredicate<[{true}]>;
+def NoSchedPred : MCSchedPredicate<TruePred>;
// Associate a predicate with a list of SchedReadWrites. By default,
// the selected SchedReadWrites are still associated with a single
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D50566.160326.patch
Type: text/x-patch
Size: 3043 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180813/56a0224d/attachment.bin>
More information about the llvm-commits
mailing list