Use ArrayRef to simplify some code.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@199712 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Craig Topper 2014-01-21 07:20:05 +00:00
parent bb70b577e3
commit 8f74ea3fa1
4 changed files with 32 additions and 38 deletions

View File

@ -155,8 +155,7 @@ void DAGISelEmitter::run(raw_ostream &OS) {
} }
} }
Matcher *TheMatcher = new ScopeMatcher(&PatternMatchers[0], Matcher *TheMatcher = new ScopeMatcher(PatternMatchers);
PatternMatchers.size());
TheMatcher = OptimizeMatcher(TheMatcher, CGP); TheMatcher = OptimizeMatcher(TheMatcher, CGP);
//Matcher->dump(); //Matcher->dump();

View File

@ -10,6 +10,7 @@
#ifndef TBLGEN_DAGISELMATCHER_H #ifndef TBLGEN_DAGISELMATCHER_H
#define TBLGEN_DAGISELMATCHER_H #define TBLGEN_DAGISELMATCHER_H
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/OwningPtr.h" #include "llvm/ADT/OwningPtr.h"
#include "llvm/ADT/SmallVector.h" #include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h" #include "llvm/ADT/StringRef.h"
@ -188,8 +189,8 @@ protected:
class ScopeMatcher : public Matcher { class ScopeMatcher : public Matcher {
SmallVector<Matcher*, 4> Children; SmallVector<Matcher*, 4> Children;
public: public:
ScopeMatcher(Matcher *const *children, unsigned numchildren) ScopeMatcher(ArrayRef<Matcher *> children)
: Matcher(Scope), Children(children, children+numchildren) { : Matcher(Scope), Children(children.begin(), children.end()) {
} }
virtual ~ScopeMatcher(); virtual ~ScopeMatcher();
@ -502,9 +503,8 @@ private:
class SwitchOpcodeMatcher : public Matcher { class SwitchOpcodeMatcher : public Matcher {
SmallVector<std::pair<const SDNodeInfo*, Matcher*>, 8> Cases; SmallVector<std::pair<const SDNodeInfo*, Matcher*>, 8> Cases;
public: public:
SwitchOpcodeMatcher(const std::pair<const SDNodeInfo*, Matcher*> *cases, SwitchOpcodeMatcher(ArrayRef<std::pair<const SDNodeInfo*, Matcher*> > cases)
unsigned numcases) : Matcher(SwitchOpcode), Cases(cases.begin(), cases.end()) {}
: Matcher(SwitchOpcode), Cases(cases, cases+numcases) {}
static inline bool classof(const Matcher *N) { static inline bool classof(const Matcher *N) {
return N->getKind() == SwitchOpcode; return N->getKind() == SwitchOpcode;
@ -556,9 +556,8 @@ private:
class SwitchTypeMatcher : public Matcher { class SwitchTypeMatcher : public Matcher {
SmallVector<std::pair<MVT::SimpleValueType, Matcher*>, 8> Cases; SmallVector<std::pair<MVT::SimpleValueType, Matcher*>, 8> Cases;
public: public:
SwitchTypeMatcher(const std::pair<MVT::SimpleValueType, Matcher*> *cases, SwitchTypeMatcher(ArrayRef<std::pair<MVT::SimpleValueType, Matcher*> > cases)
unsigned numcases) : Matcher(SwitchType), Cases(cases.begin(), cases.end()) {}
: Matcher(SwitchType), Cases(cases, cases+numcases) {}
static inline bool classof(const Matcher *N) { static inline bool classof(const Matcher *N) {
return N->getKind() == SwitchType; return N->getKind() == SwitchType;
@ -901,8 +900,8 @@ private:
class EmitMergeInputChainsMatcher : public Matcher { class EmitMergeInputChainsMatcher : public Matcher {
SmallVector<unsigned, 3> ChainNodes; SmallVector<unsigned, 3> ChainNodes;
public: public:
EmitMergeInputChainsMatcher(const unsigned *nodes, unsigned NumNodes) EmitMergeInputChainsMatcher(ArrayRef<unsigned> nodes)
: Matcher(EmitMergeInputChains), ChainNodes(nodes, nodes+NumNodes) {} : Matcher(EmitMergeInputChains), ChainNodes(nodes.begin(), nodes.end()) {}
unsigned getNumNodes() const { return ChainNodes.size(); } unsigned getNumNodes() const { return ChainNodes.size(); }
@ -994,13 +993,13 @@ class EmitNodeMatcherCommon : public Matcher {
int NumFixedArityOperands; int NumFixedArityOperands;
public: public:
EmitNodeMatcherCommon(const std::string &opcodeName, EmitNodeMatcherCommon(const std::string &opcodeName,
const MVT::SimpleValueType *vts, unsigned numvts, ArrayRef<MVT::SimpleValueType> vts,
const unsigned *operands, unsigned numops, ArrayRef<unsigned> operands,
bool hasChain, bool hasInGlue, bool hasOutGlue, bool hasChain, bool hasInGlue, bool hasOutGlue,
bool hasmemrefs, bool hasmemrefs,
int numfixedarityoperands, bool isMorphNodeTo) int numfixedarityoperands, bool isMorphNodeTo)
: Matcher(isMorphNodeTo ? MorphNodeTo : EmitNode), OpcodeName(opcodeName), : Matcher(isMorphNodeTo ? MorphNodeTo : EmitNode), OpcodeName(opcodeName),
VTs(vts, vts+numvts), Operands(operands, operands+numops), VTs(vts.begin(), vts.end()), Operands(operands.begin(), operands.end()),
HasChain(hasChain), HasInGlue(hasInGlue), HasOutGlue(hasOutGlue), HasChain(hasChain), HasInGlue(hasInGlue), HasOutGlue(hasOutGlue),
HasMemRefs(hasmemrefs), NumFixedArityOperands(numfixedarityoperands) {} HasMemRefs(hasmemrefs), NumFixedArityOperands(numfixedarityoperands) {}
@ -1044,12 +1043,12 @@ class EmitNodeMatcher : public EmitNodeMatcherCommon {
unsigned FirstResultSlot; unsigned FirstResultSlot;
public: public:
EmitNodeMatcher(const std::string &opcodeName, EmitNodeMatcher(const std::string &opcodeName,
const MVT::SimpleValueType *vts, unsigned numvts, ArrayRef<MVT::SimpleValueType> vts,
const unsigned *operands, unsigned numops, ArrayRef<unsigned> operands,
bool hasChain, bool hasInFlag, bool hasOutFlag, bool hasChain, bool hasInFlag, bool hasOutFlag,
bool hasmemrefs, bool hasmemrefs,
int numfixedarityoperands, unsigned firstresultslot) int numfixedarityoperands, unsigned firstresultslot)
: EmitNodeMatcherCommon(opcodeName, vts, numvts, operands, numops, hasChain, : EmitNodeMatcherCommon(opcodeName, vts, operands, hasChain,
hasInFlag, hasOutFlag, hasmemrefs, hasInFlag, hasOutFlag, hasmemrefs,
numfixedarityoperands, false), numfixedarityoperands, false),
FirstResultSlot(firstresultslot) {} FirstResultSlot(firstresultslot) {}
@ -1067,12 +1066,12 @@ class MorphNodeToMatcher : public EmitNodeMatcherCommon {
const PatternToMatch &Pattern; const PatternToMatch &Pattern;
public: public:
MorphNodeToMatcher(const std::string &opcodeName, MorphNodeToMatcher(const std::string &opcodeName,
const MVT::SimpleValueType *vts, unsigned numvts, ArrayRef<MVT::SimpleValueType> vts,
const unsigned *operands, unsigned numops, ArrayRef<unsigned> operands,
bool hasChain, bool hasInFlag, bool hasOutFlag, bool hasChain, bool hasInFlag, bool hasOutFlag,
bool hasmemrefs, bool hasmemrefs,
int numfixedarityoperands, const PatternToMatch &pattern) int numfixedarityoperands, const PatternToMatch &pattern)
: EmitNodeMatcherCommon(opcodeName, vts, numvts, operands, numops, hasChain, : EmitNodeMatcherCommon(opcodeName, vts, operands, hasChain,
hasInFlag, hasOutFlag, hasmemrefs, hasInFlag, hasOutFlag, hasmemrefs,
numfixedarityoperands, true), numfixedarityoperands, true),
Pattern(pattern) { Pattern(pattern) {
@ -1091,8 +1090,8 @@ public:
class MarkGlueResultsMatcher : public Matcher { class MarkGlueResultsMatcher : public Matcher {
SmallVector<unsigned, 3> GlueResultNodes; SmallVector<unsigned, 3> GlueResultNodes;
public: public:
MarkGlueResultsMatcher(const unsigned *nodes, unsigned NumNodes) MarkGlueResultsMatcher(ArrayRef<unsigned> nodes)
: Matcher(MarkGlueResults), GlueResultNodes(nodes, nodes+NumNodes) {} : Matcher(MarkGlueResults), GlueResultNodes(nodes.begin(), nodes.end()) {}
unsigned getNumNodes() const { return GlueResultNodes.size(); } unsigned getNumNodes() const { return GlueResultNodes.size(); }
@ -1120,9 +1119,9 @@ class CompleteMatchMatcher : public Matcher {
SmallVector<unsigned, 2> Results; SmallVector<unsigned, 2> Results;
const PatternToMatch &Pattern; const PatternToMatch &Pattern;
public: public:
CompleteMatchMatcher(const unsigned *results, unsigned numresults, CompleteMatchMatcher(ArrayRef<unsigned> results,
const PatternToMatch &pattern) const PatternToMatch &pattern)
: Matcher(CompleteMatch), Results(results, results+numresults), : Matcher(CompleteMatch), Results(results.begin(), results.end()),
Pattern(pattern) {} Pattern(pattern) {}
unsigned getNumResults() const { return Results.size(); } unsigned getNumResults() const { return Results.size(); }

View File

@ -850,8 +850,7 @@ EmitResultInstructionAsOperand(const TreePatternNode *N,
"Node has no result"); "Node has no result");
AddMatcher(new EmitNodeMatcher(II.Namespace+"::"+II.TheDef->getName(), AddMatcher(new EmitNodeMatcher(II.Namespace+"::"+II.TheDef->getName(),
ResultVTs.data(), ResultVTs.size(), ResultVTs, InstOps,
InstOps.data(), InstOps.size(),
NodeHasChain, TreeHasInGlue, TreeHasOutGlue, NodeHasChain, TreeHasInGlue, TreeHasOutGlue,
NodeHasMemRefs, NumFixedArityOperands, NodeHasMemRefs, NumFixedArityOperands,
NextRecordedOperandNo)); NextRecordedOperandNo));
@ -907,8 +906,7 @@ void MatcherGen::EmitResultCode() {
// merge them together into a token factor. This informs the generated code // merge them together into a token factor. This informs the generated code
// what all the chained nodes are. // what all the chained nodes are.
if (!MatchedChainNodes.empty()) if (!MatchedChainNodes.empty())
AddMatcher(new EmitMergeInputChainsMatcher AddMatcher(new EmitMergeInputChainsMatcher(MatchedChainNodes));
(MatchedChainNodes.data(), MatchedChainNodes.size()));
// Codegen the root of the result pattern, capturing the resulting values. // Codegen the root of the result pattern, capturing the resulting values.
SmallVector<unsigned, 8> Ops; SmallVector<unsigned, 8> Ops;
@ -949,10 +947,9 @@ void MatcherGen::EmitResultCode() {
// If the matched pattern covers nodes which define a glue result, emit a node // If the matched pattern covers nodes which define a glue result, emit a node
// that tells the matcher about them so that it can update their results. // that tells the matcher about them so that it can update their results.
if (!MatchedGlueResultNodes.empty()) if (!MatchedGlueResultNodes.empty())
AddMatcher(new MarkGlueResultsMatcher(MatchedGlueResultNodes.data(), AddMatcher(new MarkGlueResultsMatcher(MatchedGlueResultNodes));
MatchedGlueResultNodes.size()));
AddMatcher(new CompleteMatchMatcher(Ops.data(), Ops.size(), Pattern)); AddMatcher(new CompleteMatchMatcher(Ops, Pattern));
} }

View File

@ -136,8 +136,7 @@ static void ContractNodes(OwningPtr<Matcher> &MatcherPtr,
const SmallVectorImpl<MVT::SimpleValueType> &VTs = EN->getVTList(); const SmallVectorImpl<MVT::SimpleValueType> &VTs = EN->getVTList();
const SmallVectorImpl<unsigned> &Operands = EN->getOperandList(); const SmallVectorImpl<unsigned> &Operands = EN->getOperandList();
MatcherPtr.reset(new MorphNodeToMatcher(EN->getOpcodeName(), MatcherPtr.reset(new MorphNodeToMatcher(EN->getOpcodeName(),
VTs.data(), VTs.size(), VTs, Operands,
Operands.data(),Operands.size(),
EN->hasChain(), EN->hasInFlag(), EN->hasChain(), EN->hasInFlag(),
EN->hasOutFlag(), EN->hasOutFlag(),
EN->hasMemRefs(), EN->hasMemRefs(),
@ -380,7 +379,7 @@ static void FactorNodes(OwningPtr<Matcher> &MatcherPtr) {
EqualMatchers[i] = Tmp; EqualMatchers[i] = Tmp;
} }
Shared->setNext(new ScopeMatcher(&EqualMatchers[0], EqualMatchers.size())); Shared->setNext(new ScopeMatcher(EqualMatchers));
// Recursively factor the newly created node. // Recursively factor the newly created node.
FactorNodes(Shared->getNextPtr()); FactorNodes(Shared->getNextPtr());
@ -455,7 +454,7 @@ static void FactorNodes(OwningPtr<Matcher> &MatcherPtr) {
Cases.push_back(std::make_pair(&COM->getOpcode(), COM->getNext())); Cases.push_back(std::make_pair(&COM->getOpcode(), COM->getNext()));
} }
MatcherPtr.reset(new SwitchOpcodeMatcher(&Cases[0], Cases.size())); MatcherPtr.reset(new SwitchOpcodeMatcher(Cases));
return; return;
} }
@ -482,7 +481,7 @@ static void FactorNodes(OwningPtr<Matcher> &MatcherPtr) {
} }
Matcher *Entries[2] = { PrevMatcher, MatcherWithoutCTM }; Matcher *Entries[2] = { PrevMatcher, MatcherWithoutCTM };
Cases[Entry-1].second = new ScopeMatcher(Entries, 2); Cases[Entry-1].second = new ScopeMatcher(Entries);
continue; continue;
} }
@ -491,7 +490,7 @@ static void FactorNodes(OwningPtr<Matcher> &MatcherPtr) {
} }
if (Cases.size() != 1) { if (Cases.size() != 1) {
MatcherPtr.reset(new SwitchTypeMatcher(&Cases[0], Cases.size())); MatcherPtr.reset(new SwitchTypeMatcher(Cases));
} else { } else {
// If we factored and ended up with one case, create it now. // If we factored and ended up with one case, create it now.
MatcherPtr.reset(new CheckTypeMatcher(Cases[0].first, 0)); MatcherPtr.reset(new CheckTypeMatcher(Cases[0].first, 0));