llvm.org GIT mirror llvm / c72cf87
Add an OutPatFrag TableGen class Unfortunately, it is currently impossible to use a PatFrag as part of an output pattern (the part of the pattern that has instructions in it) in TableGen. Looking at the current implementation, this was clearly intended to work (there is already code in place to expand patterns in the output DAG), but is currently broken by the baked-in type-checking assumption and the order in which the pattern fragments are processed (output pattern fragments need to be processed after the instruction definitions are processed). Fixing this is fairly simple, but requires some way of differentiating output patterns from the existing input patterns. The simplest way to handle this seems to be to create a subclass of PatFrag, and so that's what I've done here. As a simple example, this allows us to write: def crnot : OutPatFrag<(ops node:$in), (CRNOR $in, $in)>; def : Pat<(not i1:$in), (crnot $in)>; which captures the core use case: handling of repeated subexpressions inside of complicated output patterns. This will be used by an upcoming commit to the PowerPC backend. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@202450 91177308-0d34-0410-b5e6-96231b3b80d8 Hal Finkel 5 years ago
3 changed file(s) with 22 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
558558 code ImmediateCode = [{}];
559559 SDNodeXForm OperandTransform = xform;
560560 }
561
562 // OutPatFrag is a pattern fragment that is used as part of an output pattern
563 // (not an input pattern). These do not have predicates or transforms, but are
564 // used to avoid repeated subexpressions in output patterns.
565 class OutPatFrag
566 : PatFrag;
561567
562568 // PatLeaf's are pattern fragments that have no operands. This is just a helper
563569 // to define immediates and other common things concisely.
12311231 TreePatternNode *Child = getChild(i);
12321232 if (Child->isLeaf()) {
12331233 Init *Val = Child->getLeafValue();
1234 if (isa(Val) &&
1235 cast(Val)->getDef()->getName() == "node") {
1234 // Note that, when substituting into an output pattern, Val might be an
1235 // UnsetInit.
1236 if (isa(Val) || (isa(Val) &&
1237 cast(Val)->getDef()->getName() == "node")) {
12361238 // We found a use of a formal argument, replace it with its value.
12371239 TreePatternNode *NewChild = ArgMap[Child->getName()];
12381240 assert(NewChild && "Couldn't find formal argument!");
21342136 ParsePatternFragments();
21352137 ParseDefaultOperands();
21362138 ParseInstructions();
2139 ParsePatternFragments(/*OutFrags*/true);
21372140 ParsePatterns();
21382141
21392142 // Generate variants. For example, commutative patterns can match
22072210 /// inline fragments together as necessary, so that there are no references left
22082211 /// inside a pattern fragment to a pattern fragment.
22092212 ///
2210 void CodeGenDAGPatterns::ParsePatternFragments() {
2213 void CodeGenDAGPatterns::ParsePatternFragments(bool OutFrags) {
22112214 std::vector Fragments = Records.getAllDerivedDefinitions("PatFrag");
22122215
22132216 // First step, parse all of the fragments.
22142217 for (unsigned i = 0, e = Fragments.size(); i != e; ++i) {
2218 if (OutFrags != Fragments[i]->isSubClassOf("OutPatFrag"))
2219 continue;
2220
22152221 DagInit *Tree = Fragments[i]->getValueAsDag("Fragment");
2216 TreePattern *P = new TreePattern(Fragments[i], Tree, true, *this);
2222 TreePattern *P =
2223 new TreePattern(Fragments[i], Tree,
2224 !Fragments[i]->isSubClassOf("OutPatFrag"), *this);
22172225 PatternFragments[Fragments[i]] = P;
22182226
22192227 // Validate the argument list, converting it to set, to discard duplicates.
22692277 // Now that we've parsed all of the tree fragments, do a closure on them so
22702278 // that there are not references to PatFrags left inside of them.
22712279 for (unsigned i = 0, e = Fragments.size(); i != e; ++i) {
2280 if (OutFrags != Fragments[i]->isSubClassOf("OutPatFrag"))
2281 continue;
2282
22722283 TreePattern *ThePat = PatternFragments[Fragments[i]];
22732284 ThePat->InlinePatternFragments();
22742285
808808 void ParseNodeInfo();
809809 void ParseNodeTransforms();
810810 void ParseComplexPatterns();
811 void ParsePatternFragments();
811 void ParsePatternFragments(bool OutFrags = false);
812812 void ParseDefaultOperands();
813813 void ParseInstructions();
814814 void ParsePatterns();