eliminate the MatcherNodeWithChild class, give the 'child'

field to MatcherNode.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@96560 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2010-02-18 02:49:24 +00:00
parent f6afae2f49
commit 8ef9c7958a
4 changed files with 53 additions and 67 deletions

View File

@ -22,7 +22,7 @@ void EmitNodeMatcherNode::print(raw_ostream &OS, unsigned indent) const {
OS.indent(indent) << "EmitNode: Dst = " << *Pattern.getDstPattern() << "\n"; OS.indent(indent) << "EmitNode: Dst = " << *Pattern.getDstPattern() << "\n";
} }
void MatcherNodeWithChild::printChild(raw_ostream &OS, unsigned indent) const { void MatcherNode::printChild(raw_ostream &OS, unsigned indent) const {
if (Child) if (Child)
return Child->print(OS, indent); return Child->print(OS, indent);
OS.indent(indent) << "<null child>\n"; OS.indent(indent) << "<null child>\n";

View File

@ -31,6 +31,7 @@ void EmitMatcherTable(const MatcherNode *Matcher, raw_ostream &OS);
/// MatcherNode - Base class for all the the DAG ISel Matcher representation /// MatcherNode - Base class for all the the DAG ISel Matcher representation
/// nodes. /// nodes.
class MatcherNode { class MatcherNode {
OwningPtr<MatcherNode> Child;
public: public:
enum KindTy { enum KindTy {
EmitNode, EmitNode,
@ -54,19 +55,24 @@ public:
CheckChainCompatible CheckChainCompatible
}; };
const KindTy Kind; const KindTy Kind;
protected: protected:
MatcherNode(KindTy K) : Kind(K) {} MatcherNode(KindTy K) : Kind(K) {}
public: public:
virtual ~MatcherNode() {} virtual ~MatcherNode() {}
KindTy getKind() const { return Kind; } KindTy getKind() const { return Kind; }
MatcherNode *getChild() { return Child.get(); }
const MatcherNode *getChild() const { return Child.get(); }
void setChild(MatcherNode *C) { Child.reset(C); }
static inline bool classof(const MatcherNode *) { return true; } static inline bool classof(const MatcherNode *) { return true; }
virtual void print(raw_ostream &OS, unsigned indent = 0) const = 0; virtual void print(raw_ostream &OS, unsigned indent = 0) const = 0;
void dump() const; void dump() const;
protected:
void printChild(raw_ostream &OS, unsigned indent) const;
}; };
/// EmitNodeMatcherNode - This signals a successful match and generates a node. /// EmitNodeMatcherNode - This signals a successful match and generates a node.
@ -85,33 +91,15 @@ public:
virtual void print(raw_ostream &OS, unsigned indent = 0) const; virtual void print(raw_ostream &OS, unsigned indent = 0) const;
}; };
/// MatcherNodeWithChild - Every node accept the final accept state has a child
/// that is executed after the node runs. This class captures this commonality.
class MatcherNodeWithChild : public MatcherNode {
OwningPtr<MatcherNode> Child;
public:
MatcherNodeWithChild(KindTy K) : MatcherNode(K) {}
MatcherNode *getChild() { return Child.get(); }
const MatcherNode *getChild() const { return Child.get(); }
void setChild(MatcherNode *C) { Child.reset(C); }
static inline bool classof(const MatcherNode *N) {
return N->getKind() != EmitNode;
}
protected:
void printChild(raw_ostream &OS, unsigned indent) const;
};
/// PushMatcherNode - This pushes a failure scope on the stack and evaluates /// PushMatcherNode - This pushes a failure scope on the stack and evaluates
/// 'child'. If 'child' fails to match, it pops its scope and attempts to /// 'child'. If 'child' fails to match, it pops its scope and attempts to
/// match 'Failure'. /// match 'Failure'.
class PushMatcherNode : public MatcherNodeWithChild { class PushMatcherNode : public MatcherNode {
OwningPtr<MatcherNode> Failure; OwningPtr<MatcherNode> Failure;
public: public:
PushMatcherNode(MatcherNode *child = 0, MatcherNode *failure = 0) PushMatcherNode(MatcherNode *child = 0, MatcherNode *failure = 0)
: MatcherNodeWithChild(Push), Failure(failure) { : MatcherNode(Push), Failure(failure) {
setChild(child); setChild(child);
} }
@ -127,13 +115,13 @@ public:
}; };
/// RecordMatcherNode - Save the current node in the operand list. /// RecordMatcherNode - Save the current node in the operand list.
class RecordMatcherNode : public MatcherNodeWithChild { class RecordMatcherNode : public MatcherNode {
/// WhatFor - This is a string indicating why we're recording this. This /// WhatFor - This is a string indicating why we're recording this. This
/// should only be used for comment generation not anything semantic. /// should only be used for comment generation not anything semantic.
std::string WhatFor; std::string WhatFor;
public: public:
RecordMatcherNode(const std::string &whatfor) RecordMatcherNode(const std::string &whatfor)
: MatcherNodeWithChild(Record), WhatFor(whatfor) {} : MatcherNode(Record), WhatFor(whatfor) {}
const std::string &getWhatFor() const { return WhatFor; } const std::string &getWhatFor() const { return WhatFor; }
@ -146,11 +134,11 @@ public:
/// MoveChildMatcherNode - This tells the interpreter to move into the /// MoveChildMatcherNode - This tells the interpreter to move into the
/// specified child node. /// specified child node.
class MoveChildMatcherNode : public MatcherNodeWithChild { class MoveChildMatcherNode : public MatcherNode {
unsigned ChildNo; unsigned ChildNo;
public: public:
MoveChildMatcherNode(unsigned childNo) MoveChildMatcherNode(unsigned childNo)
: MatcherNodeWithChild(MoveChild), ChildNo(childNo) {} : MatcherNode(MoveChild), ChildNo(childNo) {}
unsigned getChildNo() const { return ChildNo; } unsigned getChildNo() const { return ChildNo; }
@ -163,10 +151,10 @@ public:
/// MoveParentMatcherNode - This tells the interpreter to move to the parent /// MoveParentMatcherNode - This tells the interpreter to move to the parent
/// of the current node. /// of the current node.
class MoveParentMatcherNode : public MatcherNodeWithChild { class MoveParentMatcherNode : public MatcherNode {
public: public:
MoveParentMatcherNode() MoveParentMatcherNode()
: MatcherNodeWithChild(MoveParent) {} : MatcherNode(MoveParent) {}
static inline bool classof(const MatcherNode *N) { static inline bool classof(const MatcherNode *N) {
return N->getKind() == MoveParent; return N->getKind() == MoveParent;
@ -178,11 +166,11 @@ public:
/// CheckSameMatcherNode - This checks to see if this node is exactly the same /// CheckSameMatcherNode - This checks to see if this node is exactly the same
/// node as the specified match that was recorded with 'Record'. This is used /// node as the specified match that was recorded with 'Record'. This is used
/// when patterns have the same name in them, like '(mul GPR:$in, GPR:$in)'. /// when patterns have the same name in them, like '(mul GPR:$in, GPR:$in)'.
class CheckSameMatcherNode : public MatcherNodeWithChild { class CheckSameMatcherNode : public MatcherNode {
unsigned MatchNumber; unsigned MatchNumber;
public: public:
CheckSameMatcherNode(unsigned matchnumber) CheckSameMatcherNode(unsigned matchnumber)
: MatcherNodeWithChild(CheckSame), MatchNumber(matchnumber) {} : MatcherNode(CheckSame), MatchNumber(matchnumber) {}
unsigned getMatchNumber() const { return MatchNumber; } unsigned getMatchNumber() const { return MatchNumber; }
@ -196,11 +184,11 @@ public:
/// CheckPatternPredicateMatcherNode - This checks the target-specific predicate /// CheckPatternPredicateMatcherNode - This checks the target-specific predicate
/// to see if the entire pattern is capable of matching. This predicate does /// to see if the entire pattern is capable of matching. This predicate does
/// not take a node as input. This is used for subtarget feature checks etc. /// not take a node as input. This is used for subtarget feature checks etc.
class CheckPatternPredicateMatcherNode : public MatcherNodeWithChild { class CheckPatternPredicateMatcherNode : public MatcherNode {
std::string Predicate; std::string Predicate;
public: public:
CheckPatternPredicateMatcherNode(StringRef predicate) CheckPatternPredicateMatcherNode(StringRef predicate)
: MatcherNodeWithChild(CheckPatternPredicate), Predicate(predicate) {} : MatcherNode(CheckPatternPredicate), Predicate(predicate) {}
StringRef getPredicate() const { return Predicate; } StringRef getPredicate() const { return Predicate; }
@ -213,11 +201,11 @@ public:
/// CheckPredicateMatcherNode - This checks the target-specific predicate to /// CheckPredicateMatcherNode - This checks the target-specific predicate to
/// see if the node is acceptable. /// see if the node is acceptable.
class CheckPredicateMatcherNode : public MatcherNodeWithChild { class CheckPredicateMatcherNode : public MatcherNode {
StringRef PredName; StringRef PredName;
public: public:
CheckPredicateMatcherNode(StringRef predname) CheckPredicateMatcherNode(StringRef predname)
: MatcherNodeWithChild(CheckPredicate), PredName(predname) {} : MatcherNode(CheckPredicate), PredName(predname) {}
StringRef getPredicateName() const { return PredName; } StringRef getPredicateName() const { return PredName; }
@ -231,11 +219,11 @@ public:
/// CheckOpcodeMatcherNode - This checks to see if the current node has the /// CheckOpcodeMatcherNode - This checks to see if the current node has the
/// specified opcode, if not it fails to match. /// specified opcode, if not it fails to match.
class CheckOpcodeMatcherNode : public MatcherNodeWithChild { class CheckOpcodeMatcherNode : public MatcherNode {
StringRef OpcodeName; StringRef OpcodeName;
public: public:
CheckOpcodeMatcherNode(StringRef opcodename) CheckOpcodeMatcherNode(StringRef opcodename)
: MatcherNodeWithChild(CheckOpcode), OpcodeName(opcodename) {} : MatcherNode(CheckOpcode), OpcodeName(opcodename) {}
StringRef getOpcodeName() const { return OpcodeName; } StringRef getOpcodeName() const { return OpcodeName; }
@ -248,11 +236,11 @@ public:
/// CheckTypeMatcherNode - This checks to see if the current node has the /// CheckTypeMatcherNode - This checks to see if the current node has the
/// specified type, if not it fails to match. /// specified type, if not it fails to match.
class CheckTypeMatcherNode : public MatcherNodeWithChild { class CheckTypeMatcherNode : public MatcherNode {
MVT::SimpleValueType Type; MVT::SimpleValueType Type;
public: public:
CheckTypeMatcherNode(MVT::SimpleValueType type) CheckTypeMatcherNode(MVT::SimpleValueType type)
: MatcherNodeWithChild(CheckType), Type(type) {} : MatcherNode(CheckType), Type(type) {}
MVT::SimpleValueType getType() const { return Type; } MVT::SimpleValueType getType() const { return Type; }
@ -265,11 +253,11 @@ public:
/// CheckIntegerMatcherNode - This checks to see if the current node is a /// CheckIntegerMatcherNode - This checks to see if the current node is a
/// ConstantSDNode with the specified integer value, if not it fails to match. /// ConstantSDNode with the specified integer value, if not it fails to match.
class CheckIntegerMatcherNode : public MatcherNodeWithChild { class CheckIntegerMatcherNode : public MatcherNode {
int64_t Value; int64_t Value;
public: public:
CheckIntegerMatcherNode(int64_t value) CheckIntegerMatcherNode(int64_t value)
: MatcherNodeWithChild(CheckInteger), Value(value) {} : MatcherNode(CheckInteger), Value(value) {}
int64_t getValue() const { return Value; } int64_t getValue() const { return Value; }
@ -282,11 +270,11 @@ public:
/// CheckCondCodeMatcherNode - This checks to see if the current node is a /// CheckCondCodeMatcherNode - This checks to see if the current node is a
/// CondCodeSDNode with the specified condition, if not it fails to match. /// CondCodeSDNode with the specified condition, if not it fails to match.
class CheckCondCodeMatcherNode : public MatcherNodeWithChild { class CheckCondCodeMatcherNode : public MatcherNode {
StringRef CondCodeName; StringRef CondCodeName;
public: public:
CheckCondCodeMatcherNode(StringRef condcodename) CheckCondCodeMatcherNode(StringRef condcodename)
: MatcherNodeWithChild(CheckCondCode), CondCodeName(condcodename) {} : MatcherNode(CheckCondCode), CondCodeName(condcodename) {}
StringRef getCondCodeName() const { return CondCodeName; } StringRef getCondCodeName() const { return CondCodeName; }
@ -299,11 +287,11 @@ public:
/// CheckValueTypeMatcherNode - This checks to see if the current node is a /// CheckValueTypeMatcherNode - This checks to see if the current node is a
/// VTSDNode with the specified type, if not it fails to match. /// VTSDNode with the specified type, if not it fails to match.
class CheckValueTypeMatcherNode : public MatcherNodeWithChild { class CheckValueTypeMatcherNode : public MatcherNode {
StringRef TypeName; StringRef TypeName;
public: public:
CheckValueTypeMatcherNode(StringRef type_name) CheckValueTypeMatcherNode(StringRef type_name)
: MatcherNodeWithChild(CheckValueType), TypeName(type_name) {} : MatcherNode(CheckValueType), TypeName(type_name) {}
StringRef getTypeName() const { return TypeName; } StringRef getTypeName() const { return TypeName; }
@ -318,11 +306,11 @@ public:
/// CheckComplexPatMatcherNode - This node runs the specified ComplexPattern on /// CheckComplexPatMatcherNode - This node runs the specified ComplexPattern on
/// the current node. /// the current node.
class CheckComplexPatMatcherNode : public MatcherNodeWithChild { class CheckComplexPatMatcherNode : public MatcherNode {
const ComplexPattern &Pattern; const ComplexPattern &Pattern;
public: public:
CheckComplexPatMatcherNode(const ComplexPattern &pattern) CheckComplexPatMatcherNode(const ComplexPattern &pattern)
: MatcherNodeWithChild(CheckComplexPat), Pattern(pattern) {} : MatcherNode(CheckComplexPat), Pattern(pattern) {}
const ComplexPattern &getPattern() const { return Pattern; } const ComplexPattern &getPattern() const { return Pattern; }
@ -335,11 +323,11 @@ public:
/// CheckAndImmMatcherNode - This checks to see if the current node is an 'and' /// CheckAndImmMatcherNode - This checks to see if the current node is an 'and'
/// with something equivalent to the specified immediate. /// with something equivalent to the specified immediate.
class CheckAndImmMatcherNode : public MatcherNodeWithChild { class CheckAndImmMatcherNode : public MatcherNode {
int64_t Value; int64_t Value;
public: public:
CheckAndImmMatcherNode(int64_t value) CheckAndImmMatcherNode(int64_t value)
: MatcherNodeWithChild(CheckAndImm), Value(value) {} : MatcherNode(CheckAndImm), Value(value) {}
int64_t getValue() const { return Value; } int64_t getValue() const { return Value; }
@ -352,11 +340,11 @@ public:
/// CheckOrImmMatcherNode - This checks to see if the current node is an 'and' /// CheckOrImmMatcherNode - This checks to see if the current node is an 'and'
/// with something equivalent to the specified immediate. /// with something equivalent to the specified immediate.
class CheckOrImmMatcherNode : public MatcherNodeWithChild { class CheckOrImmMatcherNode : public MatcherNode {
int64_t Value; int64_t Value;
public: public:
CheckOrImmMatcherNode(int64_t value) CheckOrImmMatcherNode(int64_t value)
: MatcherNodeWithChild(CheckOrImm), Value(value) {} : MatcherNode(CheckOrImm), Value(value) {}
int64_t getValue() const { return Value; } int64_t getValue() const { return Value; }
@ -369,10 +357,10 @@ public:
/// CheckFoldableChainNodeMatcherNode - This checks to see if the current node /// CheckFoldableChainNodeMatcherNode - This checks to see if the current node
/// (which defines a chain operand) is safe to fold into a larger pattern. /// (which defines a chain operand) is safe to fold into a larger pattern.
class CheckFoldableChainNodeMatcherNode : public MatcherNodeWithChild { class CheckFoldableChainNodeMatcherNode : public MatcherNode {
public: public:
CheckFoldableChainNodeMatcherNode() CheckFoldableChainNodeMatcherNode()
: MatcherNodeWithChild(CheckFoldableChainNode) {} : MatcherNode(CheckFoldableChainNode) {}
static inline bool classof(const MatcherNode *N) { static inline bool classof(const MatcherNode *N) {
return N->getKind() == CheckFoldableChainNode; return N->getKind() == CheckFoldableChainNode;
@ -383,11 +371,11 @@ public:
/// CheckChainCompatibleMatcherNode - Verify that the current node's chain /// CheckChainCompatibleMatcherNode - Verify that the current node's chain
/// operand is 'compatible' with the specified recorded node's. /// operand is 'compatible' with the specified recorded node's.
class CheckChainCompatibleMatcherNode : public MatcherNodeWithChild { class CheckChainCompatibleMatcherNode : public MatcherNode {
unsigned PreviousOp; unsigned PreviousOp;
public: public:
CheckChainCompatibleMatcherNode(unsigned previousop) CheckChainCompatibleMatcherNode(unsigned previousop)
: MatcherNodeWithChild(CheckChainCompatible), PreviousOp(previousop) {} : MatcherNode(CheckChainCompatible), PreviousOp(previousop) {}
unsigned getPreviousOp() const { return PreviousOp; } unsigned getPreviousOp() const { return PreviousOp; }

View File

@ -221,7 +221,7 @@ EmitMatcher(const MatcherNode *N, unsigned Indent) {
unsigned MatcherTableEmitter:: unsigned MatcherTableEmitter::
EmitMatcherAndChildren(const MatcherNode *N, unsigned Indent) { EmitMatcherAndChildren(const MatcherNode *N, unsigned Indent) {
unsigned Size = 0; unsigned Size = 0;
while (1) { while (N) {
// Push is a special case since it is binary. // Push is a special case since it is binary.
if (const PushMatcherNode *PMN = dyn_cast<PushMatcherNode>(N)) { if (const PushMatcherNode *PMN = dyn_cast<PushMatcherNode>(N)) {
// We need to encode the child and the offset of the failure code before // We need to encode the child and the offset of the failure code before
@ -256,11 +256,9 @@ EmitMatcherAndChildren(const MatcherNode *N, unsigned Indent) {
// If there are children of this node, iterate to them, otherwise we're // If there are children of this node, iterate to them, otherwise we're
// done. // done.
if (const MatcherNodeWithChild *MNWC = dyn_cast<MatcherNodeWithChild>(N)) N = N->getChild();
N = MNWC->getChild();
else
return Size;
} }
return Size;
} }
void MatcherTableEmitter::EmitPredicateFunctions() { void MatcherTableEmitter::EmitPredicateFunctions() {

View File

@ -35,11 +35,11 @@ namespace {
SmallVector<unsigned, 2> InputChains; SmallVector<unsigned, 2> InputChains;
/// Matcher - This is the top level of the generated matcher, the result. /// Matcher - This is the top level of the generated matcher, the result.
MatcherNodeWithChild *Matcher; MatcherNode *Matcher;
/// CurPredicate - As we emit matcher nodes, this points to the latest check /// CurPredicate - As we emit matcher nodes, this points to the latest check
/// which should have future checks stuck into its child position. /// which should have future checks stuck into its child position.
MatcherNodeWithChild *CurPredicate; MatcherNode *CurPredicate;
public: public:
MatcherGen(const PatternToMatch &pattern, const CodeGenDAGPatterns &cgp); MatcherGen(const PatternToMatch &pattern, const CodeGenDAGPatterns &cgp);
@ -49,10 +49,10 @@ namespace {
void EmitMatcherCode(); void EmitMatcherCode();
MatcherNodeWithChild *GetMatcher() const { return Matcher; } MatcherNode *GetMatcher() const { return Matcher; }
MatcherNodeWithChild *GetCurPredicate() const { return CurPredicate; } MatcherNode *GetCurPredicate() const { return CurPredicate; }
private: private:
void AddMatcherNode(MatcherNodeWithChild *NewNode); void AddMatcherNode(MatcherNode *NewNode);
void InferPossibleTypes(); void InferPossibleTypes();
void EmitMatchCode(const TreePatternNode *N, TreePatternNode *NodeNoTypes); void EmitMatchCode(const TreePatternNode *N, TreePatternNode *NodeNoTypes);
void EmitLeafMatchCode(const TreePatternNode *N); void EmitLeafMatchCode(const TreePatternNode *N);
@ -107,7 +107,7 @@ void MatcherGen::InferPossibleTypes() {
/// AddMatcherNode - Add a matcher node to the current graph we're building. /// AddMatcherNode - Add a matcher node to the current graph we're building.
void MatcherGen::AddMatcherNode(MatcherNodeWithChild *NewNode) { void MatcherGen::AddMatcherNode(MatcherNode *NewNode) {
if (CurPredicate != 0) if (CurPredicate != 0)
CurPredicate->setChild(NewNode); CurPredicate->setChild(NewNode);
else else
@ -388,7 +388,7 @@ MatcherNode *llvm::ConvertPatternToMatcher(const PatternToMatch &Pattern,
EmitNodeMatcherNode *Result = new EmitNodeMatcherNode(Pattern); EmitNodeMatcherNode *Result = new EmitNodeMatcherNode(Pattern);
// Link it into the pattern. // Link it into the pattern.
if (MatcherNodeWithChild *Pred = Gen.GetCurPredicate()) { if (MatcherNode *Pred = Gen.GetCurPredicate()) {
Pred->setChild(Result); Pred->setChild(Result);
return Gen.GetMatcher(); return Gen.GetMatcher();
} }