llvm.org GIT mirror llvm / 8f74ea3
Use ArrayRef to simplify some code. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@199712 91177308-0d34-0410-b5e6-96231b3b80d8 Craig Topper 6 years ago
4 changed file(s) with 33 addition(s) and 39 deletion(s). Raw diff Collapse all Expand all
154154 }
155155 }
156156
157 Matcher *TheMatcher = new ScopeMatcher(&PatternMatchers[0],
158 PatternMatchers.size());
157 Matcher *TheMatcher = new ScopeMatcher(PatternMatchers);
159158
160159 TheMatcher = OptimizeMatcher(TheMatcher, CGP);
161160 //Matcher->dump();
99 #ifndef TBLGEN_DAGISELMATCHER_H
1010 #define TBLGEN_DAGISELMATCHER_H
1111
12 #include "llvm/ADT/ArrayRef.h"
1213 #include "llvm/ADT/OwningPtr.h"
1314 #include "llvm/ADT/SmallVector.h"
1415 #include "llvm/ADT/StringRef.h"
187188 class ScopeMatcher : public Matcher {
188189 SmallVector Children;
189190 public:
190 ScopeMatcher(Matcher *const *children, unsigned numchildren)
191 : Matcher(Scope), Children(children, children+numchildren) {
191 ScopeMatcher(ArrayRef children)
192 : Matcher(Scope), Children(children.begin(), children.end()) {
192193 }
193194 virtual ~ScopeMatcher();
194195
501502 class SwitchOpcodeMatcher : public Matcher {
502503 SmallVector, 8> Cases;
503504 public:
504 SwitchOpcodeMatcher(const std::pair *cases,
505 unsigned numcases)
506 : Matcher(SwitchOpcode), Cases(cases, cases+numcases) {}
505 SwitchOpcodeMatcher(ArrayRef > cases)
506 : Matcher(SwitchOpcode), Cases(cases.begin(), cases.end()) {}
507507
508508 static inline bool classof(const Matcher *N) {
509509 return N->getKind() == SwitchOpcode;
555555 class SwitchTypeMatcher : public Matcher {
556556 SmallVector, 8> Cases;
557557 public:
558 SwitchTypeMatcher(const std::pair *cases,
559 unsigned numcases)
560 : Matcher(SwitchType), Cases(cases, cases+numcases) {}
558 SwitchTypeMatcher(ArrayRef > cases)
559 : Matcher(SwitchType), Cases(cases.begin(), cases.end()) {}
561560
562561 static inline bool classof(const Matcher *N) {
563562 return N->getKind() == SwitchType;
900899 class EmitMergeInputChainsMatcher : public Matcher {
901900 SmallVector ChainNodes;
902901 public:
903 EmitMergeInputChainsMatcher(const unsigned *nodes, unsigned NumNodes)
904 : Matcher(EmitMergeInputChains), ChainNodes(nodes, nodes+NumNodes) {}
902 EmitMergeInputChainsMatcher(ArrayRef nodes)
903 : Matcher(EmitMergeInputChains), ChainNodes(nodes.begin(), nodes.end()) {}
905904
906905 unsigned getNumNodes() const { return ChainNodes.size(); }
907906
993992 int NumFixedArityOperands;
994993 public:
995994 EmitNodeMatcherCommon(const std::string &opcodeName,
996 const MVT::SimpleValueType *vts, unsigned numvts,
997 const unsigned *operands, unsigned numops,
995 ArrayRef vts,
996 ArrayRef operands,
998997 bool hasChain, bool hasInGlue, bool hasOutGlue,
999998 bool hasmemrefs,
1000999 int numfixedarityoperands, bool isMorphNodeTo)
10011000 : Matcher(isMorphNodeTo ? MorphNodeTo : EmitNode), OpcodeName(opcodeName),
1002 VTs(vts, vts+numvts), Operands(operands, operands+numops),
1001 VTs(vts.begin(), vts.end()), Operands(operands.begin(), operands.end()),
10031002 HasChain(hasChain), HasInGlue(hasInGlue), HasOutGlue(hasOutGlue),
10041003 HasMemRefs(hasmemrefs), NumFixedArityOperands(numfixedarityoperands) {}
10051004
10431042 unsigned FirstResultSlot;
10441043 public:
10451044 EmitNodeMatcher(const std::string &opcodeName,
1046 const MVT::SimpleValueType *vts, unsigned numvts,
1047 const unsigned *operands, unsigned numops,
1045 ArrayRef vts,
1046 ArrayRef operands,
10481047 bool hasChain, bool hasInFlag, bool hasOutFlag,
10491048 bool hasmemrefs,
10501049 int numfixedarityoperands, unsigned firstresultslot)
1051 : EmitNodeMatcherCommon(opcodeName, vts, numvts, operands, numops, hasChain,
1050 : EmitNodeMatcherCommon(opcodeName, vts, operands, hasChain,
10521051 hasInFlag, hasOutFlag, hasmemrefs,
10531052 numfixedarityoperands, false),
10541053 FirstResultSlot(firstresultslot) {}
10661065 const PatternToMatch &Pattern;
10671066 public:
10681067 MorphNodeToMatcher(const std::string &opcodeName,
1069 const MVT::SimpleValueType *vts, unsigned numvts,
1070 const unsigned *operands, unsigned numops,
1068 ArrayRef vts,
1069 ArrayRef operands,
10711070 bool hasChain, bool hasInFlag, bool hasOutFlag,
10721071 bool hasmemrefs,
10731072 int numfixedarityoperands, const PatternToMatch &pattern)
1074 : EmitNodeMatcherCommon(opcodeName, vts, numvts, operands, numops, hasChain,
1073 : EmitNodeMatcherCommon(opcodeName, vts, operands, hasChain,
10751074 hasInFlag, hasOutFlag, hasmemrefs,
10761075 numfixedarityoperands, true),
10771076 Pattern(pattern) {
10901089 class MarkGlueResultsMatcher : public Matcher {
10911090 SmallVector GlueResultNodes;
10921091 public:
1093 MarkGlueResultsMatcher(const unsigned *nodes, unsigned NumNodes)
1094 : Matcher(MarkGlueResults), GlueResultNodes(nodes, nodes+NumNodes) {}
1092 MarkGlueResultsMatcher(ArrayRef nodes)
1093 : Matcher(MarkGlueResults), GlueResultNodes(nodes.begin(), nodes.end()) {}
10951094
10961095 unsigned getNumNodes() const { return GlueResultNodes.size(); }
10971096
11191118 SmallVector Results;
11201119 const PatternToMatch &Pattern;
11211120 public:
1122 CompleteMatchMatcher(const unsigned *results, unsigned numresults,
1121 CompleteMatchMatcher(ArrayRef results,
11231122 const PatternToMatch &pattern)
1124 : Matcher(CompleteMatch), Results(results, results+numresults),
1123 : Matcher(CompleteMatch), Results(results.begin(), results.end()),
11251124 Pattern(pattern) {}
11261125
11271126 unsigned getNumResults() const { return Results.size(); }
849849 "Node has no result");
850850
851851 AddMatcher(new EmitNodeMatcher(II.Namespace+"::"+II.TheDef->getName(),
852 ResultVTs.data(), ResultVTs.size(),
853 InstOps.data(), InstOps.size(),
852 ResultVTs, InstOps,
854853 NodeHasChain, TreeHasInGlue, TreeHasOutGlue,
855854 NodeHasMemRefs, NumFixedArityOperands,
856855 NextRecordedOperandNo));
906905 // merge them together into a token factor. This informs the generated code
907906 // what all the chained nodes are.
908907 if (!MatchedChainNodes.empty())
909 AddMatcher(new EmitMergeInputChainsMatcher
910 (MatchedChainNodes.data(), MatchedChainNodes.size()));
908 AddMatcher(new EmitMergeInputChainsMatcher(MatchedChainNodes));
911909
912910 // Codegen the root of the result pattern, capturing the resulting values.
913911 SmallVector Ops;
948946 // If the matched pattern covers nodes which define a glue result, emit a node
949947 // that tells the matcher about them so that it can update their results.
950948 if (!MatchedGlueResultNodes.empty())
951 AddMatcher(new MarkGlueResultsMatcher(MatchedGlueResultNodes.data(),
952 MatchedGlueResultNodes.size()));
953
954 AddMatcher(new CompleteMatchMatcher(Ops.data(), Ops.size(), Pattern));
949 AddMatcher(new MarkGlueResultsMatcher(MatchedGlueResultNodes));
950
951 AddMatcher(new CompleteMatchMatcher(Ops, Pattern));
955952 }
956953
957954
135135 const SmallVectorImpl &VTs = EN->getVTList();
136136 const SmallVectorImpl &Operands = EN->getOperandList();
137137 MatcherPtr.reset(new MorphNodeToMatcher(EN->getOpcodeName(),
138 VTs.data(), VTs.size(),
139 Operands.data(),Operands.size(),
138 VTs, Operands,
140139 EN->hasChain(), EN->hasInFlag(),
141140 EN->hasOutFlag(),
142141 EN->hasMemRefs(),
379378 EqualMatchers[i] = Tmp;
380379 }
381380
382 Shared->setNext(new ScopeMatcher(&EqualMatchers[0], EqualMatchers.size()));
381 Shared->setNext(new ScopeMatcher(EqualMatchers));
383382
384383 // Recursively factor the newly created node.
385384 FactorNodes(Shared->getNextPtr());
454453 Cases.push_back(std::make_pair(&COM->getOpcode(), COM->getNext()));
455454 }
456455
457 MatcherPtr.reset(new SwitchOpcodeMatcher(&Cases[0], Cases.size()));
456 MatcherPtr.reset(new SwitchOpcodeMatcher(Cases));
458457 return;
459458 }
460459
481480 }
482481
483482 Matcher *Entries[2] = { PrevMatcher, MatcherWithoutCTM };
484 Cases[Entry-1].second = new ScopeMatcher(Entries, 2);
483 Cases[Entry-1].second = new ScopeMatcher(Entries);
485484 continue;
486485 }
487486
490489 }
491490
492491 if (Cases.size() != 1) {
493 MatcherPtr.reset(new SwitchTypeMatcher(&Cases[0], Cases.size()));
492 MatcherPtr.reset(new SwitchTypeMatcher(Cases));
494493 } else {
495494 // If we factored and ended up with one case, create it now.
496495 MatcherPtr.reset(new CheckTypeMatcher(Cases[0].first, 0));