Tidy up a bit. Trailing whitespace, hard tabs and 80-columns.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122337 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Jim Grosbach 2010-12-21 16:16:00 +00:00
parent e95cc25a22
commit fbadcd0826
4 changed files with 536 additions and 536 deletions

File diff suppressed because it is too large Load Diff

View File

@ -35,7 +35,7 @@ void Matcher::printOne(raw_ostream &OS) const {
Matcher *Matcher::unlinkNode(Matcher *Other) { Matcher *Matcher::unlinkNode(Matcher *Other) {
if (this == Other) if (this == Other)
return takeNext(); return takeNext();
// Scan until we find the predecessor of Other. // Scan until we find the predecessor of Other.
Matcher *Cur = this; Matcher *Cur = this;
for (; Cur && Cur->getNext() != Other; Cur = Cur->getNext()) for (; Cur && Cur->getNext() != Other; Cur = Cur->getNext())
@ -67,11 +67,11 @@ bool Matcher::canMoveBeforeNode(const Matcher *Other) const {
// We can move simple predicates before record nodes. // We can move simple predicates before record nodes.
if (isSimplePredicateNode()) if (isSimplePredicateNode())
return Other->isSimplePredicateOrRecordNode(); return Other->isSimplePredicateOrRecordNode();
// We can move record nodes across simple predicates. // We can move record nodes across simple predicates.
if (isSimplePredicateOrRecordNode()) if (isSimplePredicateOrRecordNode())
return isSimplePredicateNode(); return isSimplePredicateNode();
// We can't move record nodes across each other etc. // We can't move record nodes across each other etc.
return false; return false;
} }
@ -296,7 +296,7 @@ unsigned EmitMergeInputChainsMatcher::getHashImpl() const {
bool CheckOpcodeMatcher::isEqualImpl(const Matcher *M) const { bool CheckOpcodeMatcher::isEqualImpl(const Matcher *M) const {
// Note: pointer equality isn't enough here, we have to check the enum names // Note: pointer equality isn't enough here, we have to check the enum names
// to ensure that the nodes are for the same opcode. // to ensure that the nodes are for the same opcode.
return cast<CheckOpcodeMatcher>(M)->Opcode.getEnumName() == return cast<CheckOpcodeMatcher>(M)->Opcode.getEnumName() ==
Opcode.getEnumName(); Opcode.getEnumName();
} }
@ -321,7 +321,7 @@ unsigned MarkFlagResultsMatcher::getHashImpl() const {
} }
unsigned CompleteMatchMatcher::getHashImpl() const { unsigned CompleteMatchMatcher::getHashImpl() const {
return HashUnsigneds(Results.begin(), Results.end()) ^ return HashUnsigneds(Results.begin(), Results.end()) ^
((unsigned)(intptr_t)&Pattern << 8); ((unsigned)(intptr_t)&Pattern << 8);
} }
@ -332,15 +332,15 @@ static bool TypesAreContradictory(MVT::SimpleValueType T1,
// If the two types are the same, then they are the same, so they don't // If the two types are the same, then they are the same, so they don't
// contradict. // contradict.
if (T1 == T2) return false; if (T1 == T2) return false;
// If either type is about iPtr, then they don't conflict unless the other // If either type is about iPtr, then they don't conflict unless the other
// one is not a scalar integer type. // one is not a scalar integer type.
if (T1 == MVT::iPTR) if (T1 == MVT::iPTR)
return !MVT(T2).isInteger() || MVT(T2).isVector(); return !MVT(T2).isInteger() || MVT(T2).isVector();
if (T2 == MVT::iPTR) if (T2 == MVT::iPTR)
return !MVT(T1).isInteger() || MVT(T1).isVector(); return !MVT(T1).isInteger() || MVT(T1).isVector();
// Otherwise, they are two different non-iPTR types, they conflict. // Otherwise, they are two different non-iPTR types, they conflict.
return true; return true;
} }
@ -349,10 +349,10 @@ bool CheckOpcodeMatcher::isContradictoryImpl(const Matcher *M) const {
if (const CheckOpcodeMatcher *COM = dyn_cast<CheckOpcodeMatcher>(M)) { if (const CheckOpcodeMatcher *COM = dyn_cast<CheckOpcodeMatcher>(M)) {
// One node can't have two different opcodes! // One node can't have two different opcodes!
// Note: pointer equality isn't enough here, we have to check the enum names // Note: pointer equality isn't enough here, we have to check the enum names
// to ensure that the nodes are for the same opcode. // to ensure that the nodes are for the same opcode.
return COM->getOpcode().getEnumName() != getOpcode().getEnumName(); return COM->getOpcode().getEnumName() != getOpcode().getEnumName();
} }
// If the node has a known type, and if the type we're checking for is // If the node has a known type, and if the type we're checking for is
// different, then we know they contradict. For example, a check for // different, then we know they contradict. For example, a check for
// ISD::STORE will never be true at the same time a check for Type i32 is. // ISD::STORE will never be true at the same time a check for Type i32 is.
@ -360,12 +360,12 @@ bool CheckOpcodeMatcher::isContradictoryImpl(const Matcher *M) const {
// If checking for a result the opcode doesn't have, it can't match. // If checking for a result the opcode doesn't have, it can't match.
if (CT->getResNo() >= getOpcode().getNumResults()) if (CT->getResNo() >= getOpcode().getNumResults())
return true; return true;
MVT::SimpleValueType NodeType = getOpcode().getKnownType(CT->getResNo()); MVT::SimpleValueType NodeType = getOpcode().getKnownType(CT->getResNo());
if (NodeType != MVT::Other) if (NodeType != MVT::Other)
return TypesAreContradictory(NodeType, CT->getType()); return TypesAreContradictory(NodeType, CT->getType());
} }
return false; return false;
} }
@ -381,12 +381,12 @@ bool CheckChildTypeMatcher::isContradictoryImpl(const Matcher *M) const {
// conflict! // conflict!
if (CC->getChildNo() != getChildNo()) if (CC->getChildNo() != getChildNo())
return false; return false;
return TypesAreContradictory(getType(), CC->getType()); return TypesAreContradictory(getType(), CC->getType());
} }
return false; return false;
} }
bool CheckIntegerMatcher::isContradictoryImpl(const Matcher *M) const { bool CheckIntegerMatcher::isContradictoryImpl(const Matcher *M) const {
if (const CheckIntegerMatcher *CIM = dyn_cast<CheckIntegerMatcher>(M)) if (const CheckIntegerMatcher *CIM = dyn_cast<CheckIntegerMatcher>(M))
return CIM->getValue() != getValue(); return CIM->getValue() != getValue();

View File

@ -31,7 +31,7 @@ Matcher *OptimizeMatcher(Matcher *Matcher, const CodeGenDAGPatterns &CGP);
void EmitMatcherTable(const Matcher *Matcher, const CodeGenDAGPatterns &CGP, void EmitMatcherTable(const Matcher *Matcher, const CodeGenDAGPatterns &CGP,
raw_ostream &OS); raw_ostream &OS);
/// Matcher - Base class for all the the DAG ISel Matcher representation /// Matcher - Base class for all the the DAG ISel Matcher representation
/// nodes. /// nodes.
class Matcher { class Matcher {
@ -48,7 +48,7 @@ public:
CaptureFlagInput, // If the current node has an input flag, save it. CaptureFlagInput, // If the current node has an input flag, save it.
MoveChild, // Move current node to specified child. MoveChild, // Move current node to specified child.
MoveParent, // Move current node to parent. MoveParent, // Move current node to parent.
// Predicate checking. // Predicate checking.
CheckSame, // Fail if not same as prev match. CheckSame, // Fail if not same as prev match.
CheckPatternPredicate, CheckPatternPredicate,
@ -65,7 +65,7 @@ public:
CheckAndImm, CheckAndImm,
CheckOrImm, CheckOrImm,
CheckFoldableChainNode, CheckFoldableChainNode,
// Node creation/emisssion. // Node creation/emisssion.
EmitInteger, // Create a TargetConstant EmitInteger, // Create a TargetConstant
EmitStringInteger, // Create a TargetConstant from a string. EmitStringInteger, // Create a TargetConstant from a string.
@ -85,7 +85,7 @@ protected:
Matcher(KindTy K) : Kind(K) {} Matcher(KindTy K) : Kind(K) {}
public: public:
virtual ~Matcher() {} virtual ~Matcher() {}
KindTy getKind() const { return Kind; } KindTy getKind() const { return Kind; }
Matcher *getNext() { return Next.get(); } Matcher *getNext() { return Next.get(); }
@ -94,25 +94,25 @@ public:
Matcher *takeNext() { return Next.take(); } Matcher *takeNext() { return Next.take(); }
OwningPtr<Matcher> &getNextPtr() { return Next; } OwningPtr<Matcher> &getNextPtr() { return Next; }
static inline bool classof(const Matcher *) { return true; } static inline bool classof(const Matcher *) { return true; }
bool isEqual(const Matcher *M) const { bool isEqual(const Matcher *M) const {
if (getKind() != M->getKind()) return false; if (getKind() != M->getKind()) return false;
return isEqualImpl(M); return isEqualImpl(M);
} }
unsigned getHash() const { unsigned getHash() const {
// Clear the high bit so we don't conflict with tombstones etc. // Clear the high bit so we don't conflict with tombstones etc.
return ((getHashImpl() << 4) ^ getKind()) & (~0U>>1); return ((getHashImpl() << 4) ^ getKind()) & (~0U>>1);
} }
/// isSafeToReorderWithPatternPredicate - Return true if it is safe to sink a /// isSafeToReorderWithPatternPredicate - Return true if it is safe to sink a
/// PatternPredicate node past this one. /// PatternPredicate node past this one.
virtual bool isSafeToReorderWithPatternPredicate() const { virtual bool isSafeToReorderWithPatternPredicate() const {
return false; return false;
} }
/// isSimplePredicateNode - Return true if this is a simple predicate that /// isSimplePredicateNode - Return true if this is a simple predicate that
/// operates on the node or its children without potential side effects or a /// operates on the node or its children without potential side effects or a
/// change of the current node. /// change of the current node.
@ -134,28 +134,28 @@ public:
return true; return true;
} }
} }
/// isSimplePredicateOrRecordNode - Return true if this is a record node or /// isSimplePredicateOrRecordNode - Return true if this is a record node or
/// a simple predicate. /// a simple predicate.
bool isSimplePredicateOrRecordNode() const { bool isSimplePredicateOrRecordNode() const {
return isSimplePredicateNode() || return isSimplePredicateNode() ||
getKind() == RecordNode || getKind() == RecordChild; getKind() == RecordNode || getKind() == RecordChild;
} }
/// unlinkNode - Unlink the specified node from this chain. If Other == this, /// unlinkNode - Unlink the specified node from this chain. If Other == this,
/// we unlink the next pointer and return it. Otherwise we unlink Other from /// we unlink the next pointer and return it. Otherwise we unlink Other from
/// the list and return this. /// the list and return this.
Matcher *unlinkNode(Matcher *Other); Matcher *unlinkNode(Matcher *Other);
/// canMoveBefore - Return true if this matcher is the same as Other, or if /// canMoveBefore - Return true if this matcher is the same as Other, or if
/// we can move this matcher past all of the nodes in-between Other and this /// we can move this matcher past all of the nodes in-between Other and this
/// node. Other must be equal to or before this. /// node. Other must be equal to or before this.
bool canMoveBefore(const Matcher *Other) const; bool canMoveBefore(const Matcher *Other) const;
/// canMoveBefore - Return true if it is safe to move the current matcher /// canMoveBefore - Return true if it is safe to move the current matcher
/// across the specified one. /// across the specified one.
bool canMoveBeforeNode(const Matcher *Other) const; bool canMoveBeforeNode(const Matcher *Other) const;
/// isContradictory - Return true of these two matchers could never match on /// isContradictory - Return true of these two matchers could never match on
/// the same node. /// the same node.
bool isContradictory(const Matcher *Other) const { bool isContradictory(const Matcher *Other) const {
@ -167,7 +167,7 @@ public:
return isContradictoryImpl(Other); return isContradictoryImpl(Other);
return Other->isContradictoryImpl(this); return Other->isContradictoryImpl(this);
} }
void print(raw_ostream &OS, unsigned indent = 0) const; void print(raw_ostream &OS, unsigned indent = 0) const;
void printOne(raw_ostream &OS) const; void printOne(raw_ostream &OS) const;
void dump() const; void dump() const;
@ -177,7 +177,7 @@ protected:
virtual unsigned getHashImpl() const = 0; virtual unsigned getHashImpl() const = 0;
virtual bool isContradictoryImpl(const Matcher *M) const { return false; } virtual bool isContradictoryImpl(const Matcher *M) const { return false; }
}; };
/// ScopeMatcher - This attempts to match each of its children to find the first /// ScopeMatcher - This attempts to match each of its children to find the first
/// one that successfully matches. If one child fails, it tries the next child. /// one that successfully matches. If one child fails, it tries the next child.
/// If none of the children match then this check fails. It never has a 'next'. /// If none of the children match then this check fails. It never has a 'next'.
@ -188,12 +188,12 @@ public:
: Matcher(Scope), Children(children, children+numchildren) { : Matcher(Scope), Children(children, children+numchildren) {
} }
virtual ~ScopeMatcher(); virtual ~ScopeMatcher();
unsigned getNumChildren() const { return Children.size(); } unsigned getNumChildren() const { return Children.size(); }
Matcher *getChild(unsigned i) { return Children[i]; } Matcher *getChild(unsigned i) { return Children[i]; }
const Matcher *getChild(unsigned i) const { return Children[i]; } const Matcher *getChild(unsigned i) const { return Children[i]; }
void resetChild(unsigned i, Matcher *N) { void resetChild(unsigned i, Matcher *N) {
delete Children[i]; delete Children[i];
Children[i] = N; Children[i] = N;
@ -204,7 +204,7 @@ public:
Children[i] = 0; Children[i] = 0;
return Res; return Res;
} }
void setNumChildren(unsigned NC) { void setNumChildren(unsigned NC) {
if (NC < Children.size()) { if (NC < Children.size()) {
// delete any children we're about to lose pointers to. // delete any children we're about to lose pointers to.
@ -217,7 +217,7 @@ public:
static inline bool classof(const Matcher *N) { static inline bool classof(const Matcher *N) {
return N->getKind() == Scope; return N->getKind() == Scope;
} }
private: private:
virtual void printImpl(raw_ostream &OS, unsigned indent) const; virtual void printImpl(raw_ostream &OS, unsigned indent) const;
virtual bool isEqualImpl(const Matcher *M) const { return false; } virtual bool isEqualImpl(const Matcher *M) const { return false; }
@ -229,38 +229,38 @@ class RecordMatcher : public Matcher {
/// 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;
/// ResultNo - The slot number in the RecordedNodes vector that this will be, /// ResultNo - The slot number in the RecordedNodes vector that this will be,
/// just printed as a comment. /// just printed as a comment.
unsigned ResultNo; unsigned ResultNo;
public: public:
RecordMatcher(const std::string &whatfor, unsigned resultNo) RecordMatcher(const std::string &whatfor, unsigned resultNo)
: Matcher(RecordNode), WhatFor(whatfor), ResultNo(resultNo) {} : Matcher(RecordNode), WhatFor(whatfor), ResultNo(resultNo) {}
const std::string &getWhatFor() const { return WhatFor; } const std::string &getWhatFor() const { return WhatFor; }
unsigned getResultNo() const { return ResultNo; } unsigned getResultNo() const { return ResultNo; }
static inline bool classof(const Matcher *N) { static inline bool classof(const Matcher *N) {
return N->getKind() == RecordNode; return N->getKind() == RecordNode;
} }
virtual bool isSafeToReorderWithPatternPredicate() const { return true; } virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
private: private:
virtual void printImpl(raw_ostream &OS, unsigned indent) const; virtual void printImpl(raw_ostream &OS, unsigned indent) const;
virtual bool isEqualImpl(const Matcher *M) const { return true; } virtual bool isEqualImpl(const Matcher *M) const { return true; }
virtual unsigned getHashImpl() const { return 0; } virtual unsigned getHashImpl() const { return 0; }
}; };
/// RecordChildMatcher - Save a numbered child of the current node, or fail /// RecordChildMatcher - Save a numbered child of the current node, or fail
/// the match if it doesn't exist. This is logically equivalent to: /// the match if it doesn't exist. This is logically equivalent to:
/// MoveChild N + RecordNode + MoveParent. /// MoveChild N + RecordNode + MoveParent.
class RecordChildMatcher : public Matcher { class RecordChildMatcher : public Matcher {
unsigned ChildNo; unsigned ChildNo;
/// 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;
/// ResultNo - The slot number in the RecordedNodes vector that this will be, /// ResultNo - The slot number in the RecordedNodes vector that this will be,
/// just printed as a comment. /// just printed as a comment.
unsigned ResultNo; unsigned ResultNo;
@ -269,7 +269,7 @@ public:
unsigned resultNo) unsigned resultNo)
: Matcher(RecordChild), ChildNo(childno), WhatFor(whatfor), : Matcher(RecordChild), ChildNo(childno), WhatFor(whatfor),
ResultNo(resultNo) {} ResultNo(resultNo) {}
unsigned getChildNo() const { return ChildNo; } unsigned getChildNo() const { return ChildNo; }
const std::string &getWhatFor() const { return WhatFor; } const std::string &getWhatFor() const { return WhatFor; }
unsigned getResultNo() const { return ResultNo; } unsigned getResultNo() const { return ResultNo; }
@ -277,7 +277,7 @@ public:
static inline bool classof(const Matcher *N) { static inline bool classof(const Matcher *N) {
return N->getKind() == RecordChild; return N->getKind() == RecordChild;
} }
virtual bool isSafeToReorderWithPatternPredicate() const { return true; } virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
private: private:
@ -287,16 +287,16 @@ private:
} }
virtual unsigned getHashImpl() const { return getChildNo(); } virtual unsigned getHashImpl() const { return getChildNo(); }
}; };
/// RecordMemRefMatcher - Save the current node's memref. /// RecordMemRefMatcher - Save the current node's memref.
class RecordMemRefMatcher : public Matcher { class RecordMemRefMatcher : public Matcher {
public: public:
RecordMemRefMatcher() : Matcher(RecordMemRef) {} RecordMemRefMatcher() : Matcher(RecordMemRef) {}
static inline bool classof(const Matcher *N) { static inline bool classof(const Matcher *N) {
return N->getKind() == RecordMemRef; return N->getKind() == RecordMemRef;
} }
virtual bool isSafeToReorderWithPatternPredicate() const { return true; } virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
private: private:
@ -305,17 +305,17 @@ private:
virtual unsigned getHashImpl() const { return 0; } virtual unsigned getHashImpl() const { return 0; }
}; };
/// CaptureFlagInputMatcher - If the current record has a flag input, record /// CaptureFlagInputMatcher - If the current record has a flag input, record
/// it so that it is used as an input to the generated code. /// it so that it is used as an input to the generated code.
class CaptureFlagInputMatcher : public Matcher { class CaptureFlagInputMatcher : public Matcher {
public: public:
CaptureFlagInputMatcher() : Matcher(CaptureFlagInput) {} CaptureFlagInputMatcher() : Matcher(CaptureFlagInput) {}
static inline bool classof(const Matcher *N) { static inline bool classof(const Matcher *N) {
return N->getKind() == CaptureFlagInput; return N->getKind() == CaptureFlagInput;
} }
virtual bool isSafeToReorderWithPatternPredicate() const { return true; } virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
private: private:
@ -323,20 +323,20 @@ private:
virtual bool isEqualImpl(const Matcher *M) const { return true; } virtual bool isEqualImpl(const Matcher *M) const { return true; }
virtual unsigned getHashImpl() const { return 0; } virtual unsigned getHashImpl() const { return 0; }
}; };
/// MoveChildMatcher - This tells the interpreter to move into the /// MoveChildMatcher - This tells the interpreter to move into the
/// specified child node. /// specified child node.
class MoveChildMatcher : public Matcher { class MoveChildMatcher : public Matcher {
unsigned ChildNo; unsigned ChildNo;
public: public:
MoveChildMatcher(unsigned childNo) : Matcher(MoveChild), ChildNo(childNo) {} MoveChildMatcher(unsigned childNo) : Matcher(MoveChild), ChildNo(childNo) {}
unsigned getChildNo() const { return ChildNo; } unsigned getChildNo() const { return ChildNo; }
static inline bool classof(const Matcher *N) { static inline bool classof(const Matcher *N) {
return N->getKind() == MoveChild; return N->getKind() == MoveChild;
} }
virtual bool isSafeToReorderWithPatternPredicate() const { return true; } virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
private: private:
@ -346,17 +346,17 @@ private:
} }
virtual unsigned getHashImpl() const { return getChildNo(); } virtual unsigned getHashImpl() const { return getChildNo(); }
}; };
/// MoveParentMatcher - This tells the interpreter to move to the parent /// MoveParentMatcher - This tells the interpreter to move to the parent
/// of the current node. /// of the current node.
class MoveParentMatcher : public Matcher { class MoveParentMatcher : public Matcher {
public: public:
MoveParentMatcher() : Matcher(MoveParent) {} MoveParentMatcher() : Matcher(MoveParent) {}
static inline bool classof(const Matcher *N) { static inline bool classof(const Matcher *N) {
return N->getKind() == MoveParent; return N->getKind() == MoveParent;
} }
virtual bool isSafeToReorderWithPatternPredicate() const { return true; } virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
private: private:
@ -373,13 +373,13 @@ class CheckSameMatcher : public Matcher {
public: public:
CheckSameMatcher(unsigned matchnumber) CheckSameMatcher(unsigned matchnumber)
: Matcher(CheckSame), MatchNumber(matchnumber) {} : Matcher(CheckSame), MatchNumber(matchnumber) {}
unsigned getMatchNumber() const { return MatchNumber; } unsigned getMatchNumber() const { return MatchNumber; }
static inline bool classof(const Matcher *N) { static inline bool classof(const Matcher *N) {
return N->getKind() == CheckSame; return N->getKind() == CheckSame;
} }
virtual bool isSafeToReorderWithPatternPredicate() const { return true; } virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
private: private:
@ -389,7 +389,7 @@ private:
} }
virtual unsigned getHashImpl() const { return getMatchNumber(); } virtual unsigned getHashImpl() const { return getMatchNumber(); }
}; };
/// CheckPatternPredicateMatcher - This checks the target-specific predicate /// CheckPatternPredicateMatcher - 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.
@ -398,13 +398,13 @@ class CheckPatternPredicateMatcher : public Matcher {
public: public:
CheckPatternPredicateMatcher(StringRef predicate) CheckPatternPredicateMatcher(StringRef predicate)
: Matcher(CheckPatternPredicate), Predicate(predicate) {} : Matcher(CheckPatternPredicate), Predicate(predicate) {}
StringRef getPredicate() const { return Predicate; } StringRef getPredicate() const { return Predicate; }
static inline bool classof(const Matcher *N) { static inline bool classof(const Matcher *N) {
return N->getKind() == CheckPatternPredicate; return N->getKind() == CheckPatternPredicate;
} }
virtual bool isSafeToReorderWithPatternPredicate() const { return true; } virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
private: private:
@ -414,7 +414,7 @@ private:
} }
virtual unsigned getHashImpl() const; virtual unsigned getHashImpl() const;
}; };
/// CheckPredicateMatcher - This checks the target-specific predicate to /// CheckPredicateMatcher - This checks the target-specific predicate to
/// see if the node is acceptable. /// see if the node is acceptable.
class CheckPredicateMatcher : public Matcher { class CheckPredicateMatcher : public Matcher {
@ -422,13 +422,13 @@ class CheckPredicateMatcher : public Matcher {
public: public:
CheckPredicateMatcher(StringRef predname) CheckPredicateMatcher(StringRef predname)
: Matcher(CheckPredicate), PredName(predname) {} : Matcher(CheckPredicate), PredName(predname) {}
StringRef getPredicateName() const { return PredName; } StringRef getPredicateName() const { return PredName; }
static inline bool classof(const Matcher *N) { static inline bool classof(const Matcher *N) {
return N->getKind() == CheckPredicate; return N->getKind() == CheckPredicate;
} }
// TODO: Ok? // TODO: Ok?
//virtual bool isSafeToReorderWithPatternPredicate() const { return true; } //virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
@ -439,8 +439,8 @@ private:
} }
virtual unsigned getHashImpl() const; virtual unsigned getHashImpl() const;
}; };
/// CheckOpcodeMatcher - This checks to see if the current node has the /// CheckOpcodeMatcher - 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 CheckOpcodeMatcher : public Matcher { class CheckOpcodeMatcher : public Matcher {
@ -448,13 +448,13 @@ class CheckOpcodeMatcher : public Matcher {
public: public:
CheckOpcodeMatcher(const SDNodeInfo &opcode) CheckOpcodeMatcher(const SDNodeInfo &opcode)
: Matcher(CheckOpcode), Opcode(opcode) {} : Matcher(CheckOpcode), Opcode(opcode) {}
const SDNodeInfo &getOpcode() const { return Opcode; } const SDNodeInfo &getOpcode() const { return Opcode; }
static inline bool classof(const Matcher *N) { static inline bool classof(const Matcher *N) {
return N->getKind() == CheckOpcode; return N->getKind() == CheckOpcode;
} }
virtual bool isSafeToReorderWithPatternPredicate() const { return true; } virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
private: private:
@ -478,19 +478,19 @@ public:
static inline bool classof(const Matcher *N) { static inline bool classof(const Matcher *N) {
return N->getKind() == SwitchOpcode; return N->getKind() == SwitchOpcode;
} }
unsigned getNumCases() const { return Cases.size(); } unsigned getNumCases() const { return Cases.size(); }
const SDNodeInfo &getCaseOpcode(unsigned i) const { return *Cases[i].first; } const SDNodeInfo &getCaseOpcode(unsigned i) const { return *Cases[i].first; }
Matcher *getCaseMatcher(unsigned i) { return Cases[i].second; } Matcher *getCaseMatcher(unsigned i) { return Cases[i].second; }
const Matcher *getCaseMatcher(unsigned i) const { return Cases[i].second; } const Matcher *getCaseMatcher(unsigned i) const { return Cases[i].second; }
private: private:
virtual void printImpl(raw_ostream &OS, unsigned indent) const; virtual void printImpl(raw_ostream &OS, unsigned indent) const;
virtual bool isEqualImpl(const Matcher *M) const { return false; } virtual bool isEqualImpl(const Matcher *M) const { return false; }
virtual unsigned getHashImpl() const { return 4123; } virtual unsigned getHashImpl() const { return 4123; }
}; };
/// CheckTypeMatcher - This checks to see if the current node has the /// CheckTypeMatcher - This checks to see if the current node has the
/// specified type at the specified result, if not it fails to match. /// specified type at the specified result, if not it fails to match.
class CheckTypeMatcher : public Matcher { class CheckTypeMatcher : public Matcher {
@ -499,14 +499,14 @@ class CheckTypeMatcher : public Matcher {
public: public:
CheckTypeMatcher(MVT::SimpleValueType type, unsigned resno) CheckTypeMatcher(MVT::SimpleValueType type, unsigned resno)
: Matcher(CheckType), Type(type), ResNo(resno) {} : Matcher(CheckType), Type(type), ResNo(resno) {}
MVT::SimpleValueType getType() const { return Type; } MVT::SimpleValueType getType() const { return Type; }
unsigned getResNo() const { return ResNo; } unsigned getResNo() const { return ResNo; }
static inline bool classof(const Matcher *N) { static inline bool classof(const Matcher *N) {
return N->getKind() == CheckType; return N->getKind() == CheckType;
} }
virtual bool isSafeToReorderWithPatternPredicate() const { return true; } virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
private: private:
@ -517,7 +517,7 @@ private:
virtual unsigned getHashImpl() const { return Type; } virtual unsigned getHashImpl() const { return Type; }
virtual bool isContradictoryImpl(const Matcher *M) const; virtual bool isContradictoryImpl(const Matcher *M) const;
}; };
/// SwitchTypeMatcher - Switch based on the current node's type, dispatching /// SwitchTypeMatcher - Switch based on the current node's type, dispatching
/// to one matcher per case. If the type doesn't match any of the cases, /// to one matcher per case. If the type doesn't match any of the cases,
/// then the match fails. This is semantically equivalent to a Scope node where /// then the match fails. This is semantically equivalent to a Scope node where
@ -528,24 +528,24 @@ public:
SwitchTypeMatcher(const std::pair<MVT::SimpleValueType, Matcher*> *cases, SwitchTypeMatcher(const std::pair<MVT::SimpleValueType, Matcher*> *cases,
unsigned numcases) unsigned numcases)
: Matcher(SwitchType), Cases(cases, cases+numcases) {} : 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;
} }
unsigned getNumCases() const { return Cases.size(); } unsigned getNumCases() const { return Cases.size(); }
MVT::SimpleValueType getCaseType(unsigned i) const { return Cases[i].first; } MVT::SimpleValueType getCaseType(unsigned i) const { return Cases[i].first; }
Matcher *getCaseMatcher(unsigned i) { return Cases[i].second; } Matcher *getCaseMatcher(unsigned i) { return Cases[i].second; }
const Matcher *getCaseMatcher(unsigned i) const { return Cases[i].second; } const Matcher *getCaseMatcher(unsigned i) const { return Cases[i].second; }
private: private:
virtual void printImpl(raw_ostream &OS, unsigned indent) const; virtual void printImpl(raw_ostream &OS, unsigned indent) const;
virtual bool isEqualImpl(const Matcher *M) const { return false; } virtual bool isEqualImpl(const Matcher *M) const { return false; }
virtual unsigned getHashImpl() const { return 4123; } virtual unsigned getHashImpl() const { return 4123; }
}; };
/// CheckChildTypeMatcher - This checks to see if a child node has the /// CheckChildTypeMatcher - This checks to see if a child node has the
/// specified type, if not it fails to match. /// specified type, if not it fails to match.
class CheckChildTypeMatcher : public Matcher { class CheckChildTypeMatcher : public Matcher {
@ -554,14 +554,14 @@ class CheckChildTypeMatcher : public Matcher {
public: public:
CheckChildTypeMatcher(unsigned childno, MVT::SimpleValueType type) CheckChildTypeMatcher(unsigned childno, MVT::SimpleValueType type)
: Matcher(CheckChildType), ChildNo(childno), Type(type) {} : Matcher(CheckChildType), ChildNo(childno), Type(type) {}
unsigned getChildNo() const { return ChildNo; } unsigned getChildNo() const { return ChildNo; }
MVT::SimpleValueType getType() const { return Type; } MVT::SimpleValueType getType() const { return Type; }
static inline bool classof(const Matcher *N) { static inline bool classof(const Matcher *N) {
return N->getKind() == CheckChildType; return N->getKind() == CheckChildType;
} }
virtual bool isSafeToReorderWithPatternPredicate() const { return true; } virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
private: private:
@ -573,7 +573,7 @@ private:
virtual unsigned getHashImpl() const { return (Type << 3) | ChildNo; } virtual unsigned getHashImpl() const { return (Type << 3) | ChildNo; }
virtual bool isContradictoryImpl(const Matcher *M) const; virtual bool isContradictoryImpl(const Matcher *M) const;
}; };
/// CheckIntegerMatcher - This checks to see if the current node is a /// CheckIntegerMatcher - 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.
@ -582,13 +582,13 @@ class CheckIntegerMatcher : public Matcher {
public: public:
CheckIntegerMatcher(int64_t value) CheckIntegerMatcher(int64_t value)
: Matcher(CheckInteger), Value(value) {} : Matcher(CheckInteger), Value(value) {}
int64_t getValue() const { return Value; } int64_t getValue() const { return Value; }
static inline bool classof(const Matcher *N) { static inline bool classof(const Matcher *N) {
return N->getKind() == CheckInteger; return N->getKind() == CheckInteger;
} }
virtual bool isSafeToReorderWithPatternPredicate() const { return true; } virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
private: private:
@ -599,7 +599,7 @@ private:
virtual unsigned getHashImpl() const { return Value; } virtual unsigned getHashImpl() const { return Value; }
virtual bool isContradictoryImpl(const Matcher *M) const; virtual bool isContradictoryImpl(const Matcher *M) const;
}; };
/// CheckCondCodeMatcher - This checks to see if the current node is a /// CheckCondCodeMatcher - 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 CheckCondCodeMatcher : public Matcher { class CheckCondCodeMatcher : public Matcher {
@ -607,13 +607,13 @@ class CheckCondCodeMatcher : public Matcher {
public: public:
CheckCondCodeMatcher(StringRef condcodename) CheckCondCodeMatcher(StringRef condcodename)
: Matcher(CheckCondCode), CondCodeName(condcodename) {} : Matcher(CheckCondCode), CondCodeName(condcodename) {}
StringRef getCondCodeName() const { return CondCodeName; } StringRef getCondCodeName() const { return CondCodeName; }
static inline bool classof(const Matcher *N) { static inline bool classof(const Matcher *N) {
return N->getKind() == CheckCondCode; return N->getKind() == CheckCondCode;
} }
virtual bool isSafeToReorderWithPatternPredicate() const { return true; } virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
private: private:
@ -623,7 +623,7 @@ private:
} }
virtual unsigned getHashImpl() const; virtual unsigned getHashImpl() const;
}; };
/// CheckValueTypeMatcher - This checks to see if the current node is a /// CheckValueTypeMatcher - 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 CheckValueTypeMatcher : public Matcher { class CheckValueTypeMatcher : public Matcher {
@ -631,13 +631,13 @@ class CheckValueTypeMatcher : public Matcher {
public: public:
CheckValueTypeMatcher(StringRef type_name) CheckValueTypeMatcher(StringRef type_name)
: Matcher(CheckValueType), TypeName(type_name) {} : Matcher(CheckValueType), TypeName(type_name) {}
StringRef getTypeName() const { return TypeName; } StringRef getTypeName() const { return TypeName; }
static inline bool classof(const Matcher *N) { static inline bool classof(const Matcher *N) {
return N->getKind() == CheckValueType; return N->getKind() == CheckValueType;
} }
virtual bool isSafeToReorderWithPatternPredicate() const { return true; } virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
private: private:
@ -648,21 +648,21 @@ private:
virtual unsigned getHashImpl() const; virtual unsigned getHashImpl() const;
bool isContradictoryImpl(const Matcher *M) const; bool isContradictoryImpl(const Matcher *M) const;
}; };
/// CheckComplexPatMatcher - This node runs the specified ComplexPattern on /// CheckComplexPatMatcher - This node runs the specified ComplexPattern on
/// the current node. /// the current node.
class CheckComplexPatMatcher : public Matcher { class CheckComplexPatMatcher : public Matcher {
const ComplexPattern &Pattern; const ComplexPattern &Pattern;
/// MatchNumber - This is the recorded nodes slot that contains the node we want to /// MatchNumber - This is the recorded nodes slot that contains the node we
/// match against. /// want to match against.
unsigned MatchNumber; unsigned MatchNumber;
/// Name - The name of the node we're matching, for comment emission. /// Name - The name of the node we're matching, for comment emission.
std::string Name; std::string Name;
/// FirstResult - This is the first slot in the RecordedNodes list that the /// FirstResult - This is the first slot in the RecordedNodes list that the
/// result of the match populates. /// result of the match populates.
unsigned FirstResult; unsigned FirstResult;
@ -671,17 +671,17 @@ public:
const std::string &name, unsigned firstresult) const std::string &name, unsigned firstresult)
: Matcher(CheckComplexPat), Pattern(pattern), MatchNumber(matchnumber), : Matcher(CheckComplexPat), Pattern(pattern), MatchNumber(matchnumber),
Name(name), FirstResult(firstresult) {} Name(name), FirstResult(firstresult) {}
const ComplexPattern &getPattern() const { return Pattern; } const ComplexPattern &getPattern() const { return Pattern; }
unsigned getMatchNumber() const { return MatchNumber; } unsigned getMatchNumber() const { return MatchNumber; }
const std::string getName() const { return Name; } const std::string getName() const { return Name; }
unsigned getFirstResult() const { return FirstResult; } unsigned getFirstResult() const { return FirstResult; }
static inline bool classof(const Matcher *N) { static inline bool classof(const Matcher *N) {
return N->getKind() == CheckComplexPat; return N->getKind() == CheckComplexPat;
} }
// Not safe to move a pattern predicate past a complex pattern. // Not safe to move a pattern predicate past a complex pattern.
virtual bool isSafeToReorderWithPatternPredicate() const { return false; } virtual bool isSafeToReorderWithPatternPredicate() const { return false; }
@ -695,7 +695,7 @@ private:
return (unsigned)(intptr_t)&Pattern ^ MatchNumber; return (unsigned)(intptr_t)&Pattern ^ MatchNumber;
} }
}; };
/// CheckAndImmMatcher - This checks to see if the current node is an 'and' /// CheckAndImmMatcher - 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 CheckAndImmMatcher : public Matcher { class CheckAndImmMatcher : public Matcher {
@ -703,13 +703,13 @@ class CheckAndImmMatcher : public Matcher {
public: public:
CheckAndImmMatcher(int64_t value) CheckAndImmMatcher(int64_t value)
: Matcher(CheckAndImm), Value(value) {} : Matcher(CheckAndImm), Value(value) {}
int64_t getValue() const { return Value; } int64_t getValue() const { return Value; }
static inline bool classof(const Matcher *N) { static inline bool classof(const Matcher *N) {
return N->getKind() == CheckAndImm; return N->getKind() == CheckAndImm;
} }
virtual bool isSafeToReorderWithPatternPredicate() const { return true; } virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
private: private:
@ -727,13 +727,13 @@ class CheckOrImmMatcher : public Matcher {
public: public:
CheckOrImmMatcher(int64_t value) CheckOrImmMatcher(int64_t value)
: Matcher(CheckOrImm), Value(value) {} : Matcher(CheckOrImm), Value(value) {}
int64_t getValue() const { return Value; } int64_t getValue() const { return Value; }
static inline bool classof(const Matcher *N) { static inline bool classof(const Matcher *N) {
return N->getKind() == CheckOrImm; return N->getKind() == CheckOrImm;
} }
virtual bool isSafeToReorderWithPatternPredicate() const { return true; } virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
private: private:
@ -750,11 +750,11 @@ class CheckFoldableChainNodeMatcher : public Matcher {
public: public:
CheckFoldableChainNodeMatcher() CheckFoldableChainNodeMatcher()
: Matcher(CheckFoldableChainNode) {} : Matcher(CheckFoldableChainNode) {}
static inline bool classof(const Matcher *N) { static inline bool classof(const Matcher *N) {
return N->getKind() == CheckFoldableChainNode; return N->getKind() == CheckFoldableChainNode;
} }
virtual bool isSafeToReorderWithPatternPredicate() const { return true; } virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
private: private:
@ -770,14 +770,14 @@ class EmitIntegerMatcher : public Matcher {
public: public:
EmitIntegerMatcher(int64_t val, MVT::SimpleValueType vt) EmitIntegerMatcher(int64_t val, MVT::SimpleValueType vt)
: Matcher(EmitInteger), Val(val), VT(vt) {} : Matcher(EmitInteger), Val(val), VT(vt) {}
int64_t getValue() const { return Val; } int64_t getValue() const { return Val; }
MVT::SimpleValueType getVT() const { return VT; } MVT::SimpleValueType getVT() const { return VT; }
static inline bool classof(const Matcher *N) { static inline bool classof(const Matcher *N) {
return N->getKind() == EmitInteger; return N->getKind() == EmitInteger;
} }
private: private:
virtual void printImpl(raw_ostream &OS, unsigned indent) const; virtual void printImpl(raw_ostream &OS, unsigned indent) const;
virtual bool isEqualImpl(const Matcher *M) const { virtual bool isEqualImpl(const Matcher *M) const {
@ -795,14 +795,14 @@ class EmitStringIntegerMatcher : public Matcher {
public: public:
EmitStringIntegerMatcher(const std::string &val, MVT::SimpleValueType vt) EmitStringIntegerMatcher(const std::string &val, MVT::SimpleValueType vt)
: Matcher(EmitStringInteger), Val(val), VT(vt) {} : Matcher(EmitStringInteger), Val(val), VT(vt) {}
const std::string &getValue() const { return Val; } const std::string &getValue() const { return Val; }
MVT::SimpleValueType getVT() const { return VT; } MVT::SimpleValueType getVT() const { return VT; }
static inline bool classof(const Matcher *N) { static inline bool classof(const Matcher *N) {
return N->getKind() == EmitStringInteger; return N->getKind() == EmitStringInteger;
} }
private: private:
virtual void printImpl(raw_ostream &OS, unsigned indent) const; virtual void printImpl(raw_ostream &OS, unsigned indent) const;
virtual bool isEqualImpl(const Matcher *M) const { virtual bool isEqualImpl(const Matcher *M) const {
@ -811,7 +811,7 @@ private:
} }
virtual unsigned getHashImpl() const; virtual unsigned getHashImpl() const;
}; };
/// EmitRegisterMatcher - This creates a new TargetConstant. /// EmitRegisterMatcher - This creates a new TargetConstant.
class EmitRegisterMatcher : public Matcher { class EmitRegisterMatcher : public Matcher {
/// Reg - The def for the register that we're emitting. If this is null, then /// Reg - The def for the register that we're emitting. If this is null, then
@ -821,14 +821,14 @@ class EmitRegisterMatcher : public Matcher {
public: public:
EmitRegisterMatcher(Record *reg, MVT::SimpleValueType vt) EmitRegisterMatcher(Record *reg, MVT::SimpleValueType vt)
: Matcher(EmitRegister), Reg(reg), VT(vt) {} : Matcher(EmitRegister), Reg(reg), VT(vt) {}
Record *getReg() const { return Reg; } Record *getReg() const { return Reg; }
MVT::SimpleValueType getVT() const { return VT; } MVT::SimpleValueType getVT() const { return VT; }
static inline bool classof(const Matcher *N) { static inline bool classof(const Matcher *N) {
return N->getKind() == EmitRegister; return N->getKind() == EmitRegister;
} }
private: private:
virtual void printImpl(raw_ostream &OS, unsigned indent) const; virtual void printImpl(raw_ostream &OS, unsigned indent) const;
virtual bool isEqualImpl(const Matcher *M) const { virtual bool isEqualImpl(const Matcher *M) const {
@ -848,13 +848,13 @@ class EmitConvertToTargetMatcher : public Matcher {
public: public:
EmitConvertToTargetMatcher(unsigned slot) EmitConvertToTargetMatcher(unsigned slot)
: Matcher(EmitConvertToTarget), Slot(slot) {} : Matcher(EmitConvertToTarget), Slot(slot) {}
unsigned getSlot() const { return Slot; } unsigned getSlot() const { return Slot; }
static inline bool classof(const Matcher *N) { static inline bool classof(const Matcher *N) {
return N->getKind() == EmitConvertToTarget; return N->getKind() == EmitConvertToTarget;
} }
private: private:
virtual void printImpl(raw_ostream &OS, unsigned indent) const; virtual void printImpl(raw_ostream &OS, unsigned indent) const;
virtual bool isEqualImpl(const Matcher *M) const { virtual bool isEqualImpl(const Matcher *M) const {
@ -862,7 +862,7 @@ private:
} }
virtual unsigned getHashImpl() const { return Slot; } virtual unsigned getHashImpl() const { return Slot; }
}; };
/// EmitMergeInputChainsMatcher - Emit a node that merges a list of input /// EmitMergeInputChainsMatcher - Emit a node that merges a list of input
/// chains together with a token factor. The list of nodes are the nodes in the /// chains together with a token factor. The list of nodes are the nodes in the
/// matched pattern that have chain input/outputs. This node adds all input /// matched pattern that have chain input/outputs. This node adds all input
@ -872,18 +872,18 @@ class EmitMergeInputChainsMatcher : public Matcher {
public: public:
EmitMergeInputChainsMatcher(const unsigned *nodes, unsigned NumNodes) EmitMergeInputChainsMatcher(const unsigned *nodes, unsigned NumNodes)
: Matcher(EmitMergeInputChains), ChainNodes(nodes, nodes+NumNodes) {} : Matcher(EmitMergeInputChains), ChainNodes(nodes, nodes+NumNodes) {}
unsigned getNumNodes() const { return ChainNodes.size(); } unsigned getNumNodes() const { return ChainNodes.size(); }
unsigned getNode(unsigned i) const { unsigned getNode(unsigned i) const {
assert(i < ChainNodes.size()); assert(i < ChainNodes.size());
return ChainNodes[i]; return ChainNodes[i];
} }
static inline bool classof(const Matcher *N) { static inline bool classof(const Matcher *N) {
return N->getKind() == EmitMergeInputChains; return N->getKind() == EmitMergeInputChains;
} }
private: private:
virtual void printImpl(raw_ostream &OS, unsigned indent) const; virtual void printImpl(raw_ostream &OS, unsigned indent) const;
virtual bool isEqualImpl(const Matcher *M) const { virtual bool isEqualImpl(const Matcher *M) const {
@ -891,7 +891,7 @@ private:
} }
virtual unsigned getHashImpl() const; virtual unsigned getHashImpl() const;
}; };
/// EmitCopyToRegMatcher - Emit a CopyToReg node from a value to a physreg, /// EmitCopyToRegMatcher - Emit a CopyToReg node from a value to a physreg,
/// pushing the chain and flag results. /// pushing the chain and flag results.
/// ///
@ -901,27 +901,27 @@ class EmitCopyToRegMatcher : public Matcher {
public: public:
EmitCopyToRegMatcher(unsigned srcSlot, Record *destPhysReg) EmitCopyToRegMatcher(unsigned srcSlot, Record *destPhysReg)
: Matcher(EmitCopyToReg), SrcSlot(srcSlot), DestPhysReg(destPhysReg) {} : Matcher(EmitCopyToReg), SrcSlot(srcSlot), DestPhysReg(destPhysReg) {}
unsigned getSrcSlot() const { return SrcSlot; } unsigned getSrcSlot() const { return SrcSlot; }
Record *getDestPhysReg() const { return DestPhysReg; } Record *getDestPhysReg() const { return DestPhysReg; }
static inline bool classof(const Matcher *N) { static inline bool classof(const Matcher *N) {
return N->getKind() == EmitCopyToReg; return N->getKind() == EmitCopyToReg;
} }
private: private:
virtual void printImpl(raw_ostream &OS, unsigned indent) const; virtual void printImpl(raw_ostream &OS, unsigned indent) const;
virtual bool isEqualImpl(const Matcher *M) const { virtual bool isEqualImpl(const Matcher *M) const {
return cast<EmitCopyToRegMatcher>(M)->SrcSlot == SrcSlot && return cast<EmitCopyToRegMatcher>(M)->SrcSlot == SrcSlot &&
cast<EmitCopyToRegMatcher>(M)->DestPhysReg == DestPhysReg; cast<EmitCopyToRegMatcher>(M)->DestPhysReg == DestPhysReg;
} }
virtual unsigned getHashImpl() const { virtual unsigned getHashImpl() const {
return SrcSlot ^ ((unsigned)(intptr_t)DestPhysReg << 4); return SrcSlot ^ ((unsigned)(intptr_t)DestPhysReg << 4);
} }
}; };
/// EmitNodeXFormMatcher - Emit an operation that runs an SDNodeXForm on a /// EmitNodeXFormMatcher - Emit an operation that runs an SDNodeXForm on a
/// recorded node and records the result. /// recorded node and records the result.
class EmitNodeXFormMatcher : public Matcher { class EmitNodeXFormMatcher : public Matcher {
@ -930,25 +930,25 @@ class EmitNodeXFormMatcher : public Matcher {
public: public:
EmitNodeXFormMatcher(unsigned slot, Record *nodeXForm) EmitNodeXFormMatcher(unsigned slot, Record *nodeXForm)
: Matcher(EmitNodeXForm), Slot(slot), NodeXForm(nodeXForm) {} : Matcher(EmitNodeXForm), Slot(slot), NodeXForm(nodeXForm) {}
unsigned getSlot() const { return Slot; } unsigned getSlot() const { return Slot; }
Record *getNodeXForm() const { return NodeXForm; } Record *getNodeXForm() const { return NodeXForm; }
static inline bool classof(const Matcher *N) { static inline bool classof(const Matcher *N) {
return N->getKind() == EmitNodeXForm; return N->getKind() == EmitNodeXForm;
} }
private: private:
virtual void printImpl(raw_ostream &OS, unsigned indent) const; virtual void printImpl(raw_ostream &OS, unsigned indent) const;
virtual bool isEqualImpl(const Matcher *M) const { virtual bool isEqualImpl(const Matcher *M) const {
return cast<EmitNodeXFormMatcher>(M)->Slot == Slot && return cast<EmitNodeXFormMatcher>(M)->Slot == Slot &&
cast<EmitNodeXFormMatcher>(M)->NodeXForm == NodeXForm; cast<EmitNodeXFormMatcher>(M)->NodeXForm == NodeXForm;
} }
virtual unsigned getHashImpl() const { virtual unsigned getHashImpl() const {
return Slot ^ ((unsigned)(intptr_t)NodeXForm << 4); return Slot ^ ((unsigned)(intptr_t)NodeXForm << 4);
} }
}; };
/// EmitNodeMatcherCommon - Common class shared between EmitNode and /// EmitNodeMatcherCommon - Common class shared between EmitNode and
/// MorphNodeTo. /// MorphNodeTo.
class EmitNodeMatcherCommon : public Matcher { class EmitNodeMatcherCommon : public Matcher {
@ -956,7 +956,7 @@ class EmitNodeMatcherCommon : public Matcher {
const SmallVector<MVT::SimpleValueType, 3> VTs; const SmallVector<MVT::SimpleValueType, 3> VTs;
const SmallVector<unsigned, 6> Operands; const SmallVector<unsigned, 6> Operands;
bool HasChain, HasInFlag, HasOutFlag, HasMemRefs; bool HasChain, HasInFlag, HasOutFlag, HasMemRefs;
/// NumFixedArityOperands - If this is a fixed arity node, this is set to -1. /// NumFixedArityOperands - If this is a fixed arity node, this is set to -1.
/// If this is a varidic node, this is set to the number of fixed arity /// If this is a varidic node, this is set to the number of fixed arity
/// operands in the root of the pattern. The rest are appended to this node. /// operands in the root of the pattern. The rest are appended to this node.
@ -972,9 +972,9 @@ public:
VTs(vts, vts+numvts), Operands(operands, operands+numops), VTs(vts, vts+numvts), Operands(operands, operands+numops),
HasChain(hasChain), HasInFlag(hasInFlag), HasOutFlag(hasOutFlag), HasChain(hasChain), HasInFlag(hasInFlag), HasOutFlag(hasOutFlag),
HasMemRefs(hasmemrefs), NumFixedArityOperands(numfixedarityoperands) {} HasMemRefs(hasmemrefs), NumFixedArityOperands(numfixedarityoperands) {}
const std::string &getOpcodeName() const { return OpcodeName; } const std::string &getOpcodeName() const { return OpcodeName; }
unsigned getNumVTs() const { return VTs.size(); } unsigned getNumVTs() const { return VTs.size(); }
MVT::SimpleValueType getVT(unsigned i) const { MVT::SimpleValueType getVT(unsigned i) const {
assert(i < VTs.size()); assert(i < VTs.size());
@ -986,27 +986,27 @@ public:
assert(i < Operands.size()); assert(i < Operands.size());
return Operands[i]; return Operands[i];
} }
const SmallVectorImpl<MVT::SimpleValueType> &getVTList() const { return VTs; } const SmallVectorImpl<MVT::SimpleValueType> &getVTList() const { return VTs; }
const SmallVectorImpl<unsigned> &getOperandList() const { return Operands; } const SmallVectorImpl<unsigned> &getOperandList() const { return Operands; }
bool hasChain() const { return HasChain; } bool hasChain() const { return HasChain; }
bool hasInFlag() const { return HasInFlag; } bool hasInFlag() const { return HasInFlag; }
bool hasOutFlag() const { return HasOutFlag; } bool hasOutFlag() const { return HasOutFlag; }
bool hasMemRefs() const { return HasMemRefs; } bool hasMemRefs() const { return HasMemRefs; }
int getNumFixedArityOperands() const { return NumFixedArityOperands; } int getNumFixedArityOperands() const { return NumFixedArityOperands; }
static inline bool classof(const Matcher *N) { static inline bool classof(const Matcher *N) {
return N->getKind() == EmitNode || N->getKind() == MorphNodeTo; return N->getKind() == EmitNode || N->getKind() == MorphNodeTo;
} }
private: private:
virtual void printImpl(raw_ostream &OS, unsigned indent) const; virtual void printImpl(raw_ostream &OS, unsigned indent) const;
virtual bool isEqualImpl(const Matcher *M) const; virtual bool isEqualImpl(const Matcher *M) const;
virtual unsigned getHashImpl() const; virtual unsigned getHashImpl() const;
}; };
/// EmitNodeMatcher - This signals a successful match and generates a node. /// EmitNodeMatcher - This signals a successful match and generates a node.
class EmitNodeMatcher : public EmitNodeMatcherCommon { class EmitNodeMatcher : public EmitNodeMatcherCommon {
unsigned FirstResultSlot; unsigned FirstResultSlot;
@ -1021,15 +1021,15 @@ public:
hasInFlag, hasOutFlag, hasmemrefs, hasInFlag, hasOutFlag, hasmemrefs,
numfixedarityoperands, false), numfixedarityoperands, false),
FirstResultSlot(firstresultslot) {} FirstResultSlot(firstresultslot) {}
unsigned getFirstResultSlot() const { return FirstResultSlot; } unsigned getFirstResultSlot() const { return FirstResultSlot; }
static inline bool classof(const Matcher *N) { static inline bool classof(const Matcher *N) {
return N->getKind() == EmitNode; return N->getKind() == EmitNode;
} }
}; };
class MorphNodeToMatcher : public EmitNodeMatcherCommon { class MorphNodeToMatcher : public EmitNodeMatcherCommon {
const PatternToMatch &Pattern; const PatternToMatch &Pattern;
public: public:
@ -1044,14 +1044,14 @@ public:
numfixedarityoperands, true), numfixedarityoperands, true),
Pattern(pattern) { Pattern(pattern) {
} }
const PatternToMatch &getPattern() const { return Pattern; } const PatternToMatch &getPattern() const { return Pattern; }
static inline bool classof(const Matcher *N) { static inline bool classof(const Matcher *N) {
return N->getKind() == MorphNodeTo; return N->getKind() == MorphNodeTo;
} }
}; };
/// MarkFlagResultsMatcher - This node indicates which non-root nodes in the /// MarkFlagResultsMatcher - This node indicates which non-root nodes in the
/// pattern produce flags. This allows CompleteMatchMatcher to update them /// pattern produce flags. This allows CompleteMatchMatcher to update them
/// with the output flag of the resultant code. /// with the output flag of the resultant code.
@ -1060,18 +1060,18 @@ class MarkFlagResultsMatcher : public Matcher {
public: public:
MarkFlagResultsMatcher(const unsigned *nodes, unsigned NumNodes) MarkFlagResultsMatcher(const unsigned *nodes, unsigned NumNodes)
: Matcher(MarkFlagResults), FlagResultNodes(nodes, nodes+NumNodes) {} : Matcher(MarkFlagResults), FlagResultNodes(nodes, nodes+NumNodes) {}
unsigned getNumNodes() const { return FlagResultNodes.size(); } unsigned getNumNodes() const { return FlagResultNodes.size(); }
unsigned getNode(unsigned i) const { unsigned getNode(unsigned i) const {
assert(i < FlagResultNodes.size()); assert(i < FlagResultNodes.size());
return FlagResultNodes[i]; return FlagResultNodes[i];
} }
static inline bool classof(const Matcher *N) { static inline bool classof(const Matcher *N) {
return N->getKind() == MarkFlagResults; return N->getKind() == MarkFlagResults;
} }
private: private:
virtual void printImpl(raw_ostream &OS, unsigned indent) const; virtual void printImpl(raw_ostream &OS, unsigned indent) const;
virtual bool isEqualImpl(const Matcher *M) const { virtual bool isEqualImpl(const Matcher *M) const {
@ -1095,11 +1095,11 @@ public:
unsigned getNumResults() const { return Results.size(); } unsigned getNumResults() const { return Results.size(); }
unsigned getResult(unsigned R) const { return Results[R]; } unsigned getResult(unsigned R) const { return Results[R]; }
const PatternToMatch &getPattern() const { return Pattern; } const PatternToMatch &getPattern() const { return Pattern; }
static inline bool classof(const Matcher *N) { static inline bool classof(const Matcher *N) {
return N->getKind() == CompleteMatch; return N->getKind() == CompleteMatch;
} }
private: private:
virtual void printImpl(raw_ostream &OS, unsigned indent) const; virtual void printImpl(raw_ostream &OS, unsigned indent) const;
virtual bool isEqualImpl(const Matcher *M) const { virtual bool isEqualImpl(const Matcher *M) const {
@ -1108,7 +1108,7 @@ private:
} }
virtual unsigned getHashImpl() const; virtual unsigned getHashImpl() const;
}; };
} // end namespace llvm } // end namespace llvm
#endif #endif

View File

@ -25,12 +25,12 @@ static MVT::SimpleValueType getRegisterValueType(Record *R,
MVT::SimpleValueType VT = MVT::Other; MVT::SimpleValueType VT = MVT::Other;
const std::vector<CodeGenRegisterClass> &RCs = T.getRegisterClasses(); const std::vector<CodeGenRegisterClass> &RCs = T.getRegisterClasses();
std::vector<Record*>::const_iterator Element; std::vector<Record*>::const_iterator Element;
for (unsigned rc = 0, e = RCs.size(); rc != e; ++rc) { for (unsigned rc = 0, e = RCs.size(); rc != e; ++rc) {
const CodeGenRegisterClass &RC = RCs[rc]; const CodeGenRegisterClass &RC = RCs[rc];
if (!std::count(RC.Elements.begin(), RC.Elements.end(), R)) if (!std::count(RC.Elements.begin(), RC.Elements.end(), R))
continue; continue;
if (!FoundRC) { if (!FoundRC) {
FoundRC = true; FoundRC = true;
VT = RC.getValueTypeNum(0); VT = RC.getValueTypeNum(0);
@ -48,22 +48,22 @@ namespace {
class MatcherGen { class MatcherGen {
const PatternToMatch &Pattern; const PatternToMatch &Pattern;
const CodeGenDAGPatterns &CGP; const CodeGenDAGPatterns &CGP;
/// PatWithNoTypes - This is a clone of Pattern.getSrcPattern() that starts /// PatWithNoTypes - This is a clone of Pattern.getSrcPattern() that starts
/// out with all of the types removed. This allows us to insert type checks /// out with all of the types removed. This allows us to insert type checks
/// as we scan the tree. /// as we scan the tree.
TreePatternNode *PatWithNoTypes; TreePatternNode *PatWithNoTypes;
/// VariableMap - A map from variable names ('$dst') to the recorded operand /// VariableMap - A map from variable names ('$dst') to the recorded operand
/// number that they were captured as. These are biased by 1 to make /// number that they were captured as. These are biased by 1 to make
/// insertion easier. /// insertion easier.
StringMap<unsigned> VariableMap; StringMap<unsigned> VariableMap;
/// NextRecordedOperandNo - As we emit opcodes to record matched values in /// NextRecordedOperandNo - As we emit opcodes to record matched values in
/// the RecordedNodes array, this keeps track of which slot will be next to /// the RecordedNodes array, this keeps track of which slot will be next to
/// record into. /// record into.
unsigned NextRecordedOperandNo; unsigned NextRecordedOperandNo;
/// MatchedChainNodes - This maintains the position in the recorded nodes /// MatchedChainNodes - This maintains the position in the recorded nodes
/// array of all of the recorded input nodes that have chains. /// array of all of the recorded input nodes that have chains.
SmallVector<unsigned, 2> MatchedChainNodes; SmallVector<unsigned, 2> MatchedChainNodes;
@ -71,7 +71,7 @@ namespace {
/// MatchedFlagResultNodes - This maintains the position in the recorded /// MatchedFlagResultNodes - This maintains the position in the recorded
/// nodes array of all of the recorded input nodes that have flag results. /// nodes array of all of the recorded input nodes that have flag results.
SmallVector<unsigned, 2> MatchedFlagResultNodes; SmallVector<unsigned, 2> MatchedFlagResultNodes;
/// MatchedComplexPatterns - This maintains a list of all of the /// MatchedComplexPatterns - This maintains a list of all of the
/// ComplexPatterns that we need to check. The patterns are known to have /// ComplexPatterns that we need to check. The patterns are known to have
/// names which were recorded. The second element of each pair is the first /// names which were recorded. The second element of each pair is the first
@ -79,39 +79,39 @@ namespace {
/// results into. /// results into.
SmallVector<std::pair<const TreePatternNode*, SmallVector<std::pair<const TreePatternNode*,
unsigned>, 2> MatchedComplexPatterns; unsigned>, 2> MatchedComplexPatterns;
/// PhysRegInputs - List list has an entry for each explicitly specified /// PhysRegInputs - List list has an entry for each explicitly specified
/// physreg input to the pattern. The first elt is the Register node, the /// physreg input to the pattern. The first elt is the Register node, the
/// second is the recorded slot number the input pattern match saved it in. /// second is the recorded slot number the input pattern match saved it in.
SmallVector<std::pair<Record*, unsigned>, 2> PhysRegInputs; SmallVector<std::pair<Record*, unsigned>, 2> PhysRegInputs;
/// Matcher - This is the top level of the generated matcher, the result. /// Matcher - This is the top level of the generated matcher, the result.
Matcher *TheMatcher; Matcher *TheMatcher;
/// 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 Next position. /// which should have future checks stuck into its Next position.
Matcher *CurPredicate; Matcher *CurPredicate;
public: public:
MatcherGen(const PatternToMatch &pattern, const CodeGenDAGPatterns &cgp); MatcherGen(const PatternToMatch &pattern, const CodeGenDAGPatterns &cgp);
~MatcherGen() { ~MatcherGen() {
delete PatWithNoTypes; delete PatWithNoTypes;
} }
bool EmitMatcherCode(unsigned Variant); bool EmitMatcherCode(unsigned Variant);
void EmitResultCode(); void EmitResultCode();
Matcher *GetMatcher() const { return TheMatcher; } Matcher *GetMatcher() const { return TheMatcher; }
private: private:
void AddMatcher(Matcher *NewNode); void AddMatcher(Matcher *NewNode);
void InferPossibleTypes(); void InferPossibleTypes();
// Matcher Generation. // Matcher Generation.
void EmitMatchCode(const TreePatternNode *N, TreePatternNode *NodeNoTypes); void EmitMatchCode(const TreePatternNode *N, TreePatternNode *NodeNoTypes);
void EmitLeafMatchCode(const TreePatternNode *N); void EmitLeafMatchCode(const TreePatternNode *N);
void EmitOperatorMatchCode(const TreePatternNode *N, void EmitOperatorMatchCode(const TreePatternNode *N,
TreePatternNode *NodeNoTypes); TreePatternNode *NodeNoTypes);
// Result Code Generation. // Result Code Generation.
unsigned getNamedArgumentSlot(StringRef Name) { unsigned getNamedArgumentSlot(StringRef Name) {
unsigned VarMapEntry = VariableMap[Name]; unsigned VarMapEntry = VariableMap[Name];
@ -123,7 +123,7 @@ namespace {
/// GetInstPatternNode - Get the pattern for an instruction. /// GetInstPatternNode - Get the pattern for an instruction.
const TreePatternNode *GetInstPatternNode(const DAGInstruction &Ins, const TreePatternNode *GetInstPatternNode(const DAGInstruction &Ins,
const TreePatternNode *N); const TreePatternNode *N);
void EmitResultOperand(const TreePatternNode *N, void EmitResultOperand(const TreePatternNode *N,
SmallVectorImpl<unsigned> &ResultOps); SmallVectorImpl<unsigned> &ResultOps);
void EmitResultOfNamedOperand(const TreePatternNode *N, void EmitResultOfNamedOperand(const TreePatternNode *N,
@ -135,7 +135,7 @@ namespace {
void EmitResultSDNodeXFormAsOperand(const TreePatternNode *N, void EmitResultSDNodeXFormAsOperand(const TreePatternNode *N,
SmallVectorImpl<unsigned> &ResultOps); SmallVectorImpl<unsigned> &ResultOps);
}; };
} // end anon namespace. } // end anon namespace.
MatcherGen::MatcherGen(const PatternToMatch &pattern, MatcherGen::MatcherGen(const PatternToMatch &pattern,
@ -156,7 +156,7 @@ MatcherGen::MatcherGen(const PatternToMatch &pattern,
// //
PatWithNoTypes = Pattern.getSrcPattern()->clone(); PatWithNoTypes = Pattern.getSrcPattern()->clone();
PatWithNoTypes->RemoveAllTypes(); PatWithNoTypes->RemoveAllTypes();
// If there are types that are manifestly known, infer them. // If there are types that are manifestly known, infer them.
InferPossibleTypes(); InferPossibleTypes();
} }
@ -169,7 +169,7 @@ void MatcherGen::InferPossibleTypes() {
// TP - Get *SOME* tree pattern, we don't care which. It is only used for // TP - Get *SOME* tree pattern, we don't care which. It is only used for
// diagnostics, which we know are impossible at this point. // diagnostics, which we know are impossible at this point.
TreePattern &TP = *CGP.pf_begin()->second; TreePattern &TP = *CGP.pf_begin()->second;
try { try {
bool MadeChange = true; bool MadeChange = true;
while (MadeChange) while (MadeChange)
@ -182,7 +182,7 @@ void MatcherGen::InferPossibleTypes() {
} }
/// AddMatcher - Add a matcher node to the current graph we're building. /// AddMatcher - Add a matcher node to the current graph we're building.
void MatcherGen::AddMatcher(Matcher *NewNode) { void MatcherGen::AddMatcher(Matcher *NewNode) {
if (CurPredicate != 0) if (CurPredicate != 0)
CurPredicate->setNext(NewNode); CurPredicate->setNext(NewNode);
@ -199,7 +199,7 @@ void MatcherGen::AddMatcher(Matcher *NewNode) {
/// EmitLeafMatchCode - Generate matching code for leaf nodes. /// EmitLeafMatchCode - Generate matching code for leaf nodes.
void MatcherGen::EmitLeafMatchCode(const TreePatternNode *N) { void MatcherGen::EmitLeafMatchCode(const TreePatternNode *N) {
assert(N->isLeaf() && "Not a leaf?"); assert(N->isLeaf() && "Not a leaf?");
// Direct match against an integer constant. // Direct match against an integer constant.
if (IntInit *II = dynamic_cast<IntInit*>(N->getLeafValue())) { if (IntInit *II = dynamic_cast<IntInit*>(N->getLeafValue())) {
// If this is the root of the dag we're matching, we emit a redundant opcode // If this is the root of the dag we're matching, we emit a redundant opcode
@ -212,16 +212,16 @@ void MatcherGen::EmitLeafMatchCode(const TreePatternNode *N) {
return AddMatcher(new CheckIntegerMatcher(II->getValue())); return AddMatcher(new CheckIntegerMatcher(II->getValue()));
} }
DefInit *DI = dynamic_cast<DefInit*>(N->getLeafValue()); DefInit *DI = dynamic_cast<DefInit*>(N->getLeafValue());
if (DI == 0) { if (DI == 0) {
errs() << "Unknown leaf kind: " << *DI << "\n"; errs() << "Unknown leaf kind: " << *DI << "\n";
abort(); abort();
} }
Record *LeafRec = DI->getDef(); Record *LeafRec = DI->getDef();
if (// Handle register references. Nothing to do here, they always match. if (// Handle register references. Nothing to do here, they always match.
LeafRec->isSubClassOf("RegisterClass") || LeafRec->isSubClassOf("RegisterClass") ||
LeafRec->isSubClassOf("PointerLikeRegClass") || LeafRec->isSubClassOf("PointerLikeRegClass") ||
LeafRec->isSubClassOf("SubRegIndex") || LeafRec->isSubClassOf("SubRegIndex") ||
// Place holder for SRCVALUE nodes. Nothing to do here. // Place holder for SRCVALUE nodes. Nothing to do here.
@ -229,20 +229,20 @@ void MatcherGen::EmitLeafMatchCode(const TreePatternNode *N) {
return; return;
// If we have a physreg reference like (mul gpr:$src, EAX) then we need to // If we have a physreg reference like (mul gpr:$src, EAX) then we need to
// record the register // record the register
if (LeafRec->isSubClassOf("Register")) { if (LeafRec->isSubClassOf("Register")) {
AddMatcher(new RecordMatcher("physreg input "+LeafRec->getName(), AddMatcher(new RecordMatcher("physreg input "+LeafRec->getName(),
NextRecordedOperandNo)); NextRecordedOperandNo));
PhysRegInputs.push_back(std::make_pair(LeafRec, NextRecordedOperandNo++)); PhysRegInputs.push_back(std::make_pair(LeafRec, NextRecordedOperandNo++));
return; return;
} }
if (LeafRec->isSubClassOf("ValueType")) if (LeafRec->isSubClassOf("ValueType"))
return AddMatcher(new CheckValueTypeMatcher(LeafRec->getName())); return AddMatcher(new CheckValueTypeMatcher(LeafRec->getName()));
if (LeafRec->isSubClassOf("CondCode")) if (LeafRec->isSubClassOf("CondCode"))
return AddMatcher(new CheckCondCodeMatcher(LeafRec->getName())); return AddMatcher(new CheckCondCodeMatcher(LeafRec->getName()));
if (LeafRec->isSubClassOf("ComplexPattern")) { if (LeafRec->isSubClassOf("ComplexPattern")) {
// We can't model ComplexPattern uses that don't have their name taken yet. // We can't model ComplexPattern uses that don't have their name taken yet.
// The OPC_CheckComplexPattern operation implicitly records the results. // The OPC_CheckComplexPattern operation implicitly records the results.
@ -256,7 +256,7 @@ void MatcherGen::EmitLeafMatchCode(const TreePatternNode *N) {
MatchedComplexPatterns.push_back(std::make_pair(N, 0)); MatchedComplexPatterns.push_back(std::make_pair(N, 0));
return; return;
} }
errs() << "Unknown leaf kind: " << *N << "\n"; errs() << "Unknown leaf kind: " << *N << "\n";
abort(); abort();
} }
@ -265,7 +265,7 @@ void MatcherGen::EmitOperatorMatchCode(const TreePatternNode *N,
TreePatternNode *NodeNoTypes) { TreePatternNode *NodeNoTypes) {
assert(!N->isLeaf() && "Not an operator?"); assert(!N->isLeaf() && "Not an operator?");
const SDNodeInfo &CInfo = CGP.getSDNodeInfo(N->getOperator()); const SDNodeInfo &CInfo = CGP.getSDNodeInfo(N->getOperator());
// If this is an 'and R, 1234' where the operation is AND/OR and the RHS is // If this is an 'and R, 1234' where the operation is AND/OR and the RHS is
// a constant without a predicate fn that has more that one bit set, handle // a constant without a predicate fn that has more that one bit set, handle
// this as a special case. This is usually for targets that have special // this as a special case. This is usually for targets that have special
@ -276,7 +276,7 @@ void MatcherGen::EmitOperatorMatchCode(const TreePatternNode *N,
// them from the mask in the dag. For example, it might turn 'AND X, 255' // them from the mask in the dag. For example, it might turn 'AND X, 255'
// into 'AND X, 254' if it knows the low bit is set. Emit code that checks // into 'AND X, 254' if it knows the low bit is set. Emit code that checks
// to handle this. // to handle this.
if ((N->getOperator()->getName() == "and" || if ((N->getOperator()->getName() == "and" ||
N->getOperator()->getName() == "or") && N->getOperator()->getName() == "or") &&
N->getChild(1)->isLeaf() && N->getChild(1)->getPredicateFns().empty() && N->getChild(1)->isLeaf() && N->getChild(1)->getPredicateFns().empty() &&
N->getPredicateFns().empty()) { N->getPredicateFns().empty()) {
@ -302,15 +302,15 @@ void MatcherGen::EmitOperatorMatchCode(const TreePatternNode *N,
} }
} }
} }
// Check that the current opcode lines up. // Check that the current opcode lines up.
AddMatcher(new CheckOpcodeMatcher(CInfo)); AddMatcher(new CheckOpcodeMatcher(CInfo));
// If this node has memory references (i.e. is a load or store), tell the // If this node has memory references (i.e. is a load or store), tell the
// interpreter to capture them in the memref array. // interpreter to capture them in the memref array.
if (N->NodeHasProperty(SDNPMemOperand, CGP)) if (N->NodeHasProperty(SDNPMemOperand, CGP))
AddMatcher(new RecordMemRefMatcher()); AddMatcher(new RecordMemRefMatcher());
// If this node has a chain, then the chain is operand #0 is the SDNode, and // If this node has a chain, then the chain is operand #0 is the SDNode, and
// the child numbers of the node are all offset by one. // the child numbers of the node are all offset by one.
unsigned OpNo = 0; unsigned OpNo = 0;
@ -321,7 +321,7 @@ void MatcherGen::EmitOperatorMatchCode(const TreePatternNode *N,
NextRecordedOperandNo)); NextRecordedOperandNo));
// Remember all of the input chains our pattern will match. // Remember all of the input chains our pattern will match.
MatchedChainNodes.push_back(NextRecordedOperandNo++); MatchedChainNodes.push_back(NextRecordedOperandNo++);
// Don't look at the input chain when matching the tree pattern to the // Don't look at the input chain when matching the tree pattern to the
// SDNode. // SDNode.
OpNo = 1; OpNo = 1;
@ -352,7 +352,7 @@ void MatcherGen::EmitOperatorMatchCode(const TreePatternNode *N,
// If there is a node between the root and this node, then we definitely // If there is a node between the root and this node, then we definitely
// need to emit the check. // need to emit the check.
bool NeedCheck = !Root->hasChild(N); bool NeedCheck = !Root->hasChild(N);
// If it *is* an immediate child of the root, we can still need a check if // If it *is* an immediate child of the root, we can still need a check if
// the root SDNode has multiple inputs. For us, this means that it is an // the root SDNode has multiple inputs. For us, this means that it is an
// intrinsic, has multiple operands, or has other inputs like chain or // intrinsic, has multiple operands, or has other inputs like chain or
@ -368,17 +368,17 @@ void MatcherGen::EmitOperatorMatchCode(const TreePatternNode *N,
PInfo.hasProperty(SDNPInFlag) || PInfo.hasProperty(SDNPInFlag) ||
PInfo.hasProperty(SDNPOptInFlag); PInfo.hasProperty(SDNPOptInFlag);
} }
if (NeedCheck) if (NeedCheck)
AddMatcher(new CheckFoldableChainNodeMatcher()); AddMatcher(new CheckFoldableChainNodeMatcher());
} }
} }
// If this node has an output flag and isn't the root, remember it. // If this node has an output flag and isn't the root, remember it.
if (N->NodeHasProperty(SDNPOutFlag, CGP) && if (N->NodeHasProperty(SDNPOutFlag, CGP) &&
N != Pattern.getSrcPattern()) { N != Pattern.getSrcPattern()) {
// TODO: This redundantly records nodes with both flags and chains. // TODO: This redundantly records nodes with both flags and chains.
// Record the node and remember it in our chained nodes list. // Record the node and remember it in our chained nodes list.
AddMatcher(new RecordMatcher("'" + N->getOperator()->getName() + AddMatcher(new RecordMatcher("'" + N->getOperator()->getName() +
"' flag output node", "' flag output node",
@ -386,13 +386,13 @@ void MatcherGen::EmitOperatorMatchCode(const TreePatternNode *N,
// Remember all of the nodes with output flags our pattern will match. // Remember all of the nodes with output flags our pattern will match.
MatchedFlagResultNodes.push_back(NextRecordedOperandNo++); MatchedFlagResultNodes.push_back(NextRecordedOperandNo++);
} }
// If this node is known to have an input flag or if it *might* have an input // If this node is known to have an input flag or if it *might* have an input
// flag, capture it as the flag input of the pattern. // flag, capture it as the flag input of the pattern.
if (N->NodeHasProperty(SDNPOptInFlag, CGP) || if (N->NodeHasProperty(SDNPOptInFlag, CGP) ||
N->NodeHasProperty(SDNPInFlag, CGP)) N->NodeHasProperty(SDNPInFlag, CGP))
AddMatcher(new CaptureFlagInputMatcher()); AddMatcher(new CaptureFlagInputMatcher());
for (unsigned i = 0, e = N->getNumChildren(); i != e; ++i, ++OpNo) { for (unsigned i = 0, e = N->getNumChildren(); i != e; ++i, ++OpNo) {
// Get the code suitable for matching this child. Move to the child, check // Get the code suitable for matching this child. Move to the child, check
// it then move back to the parent. // it then move back to the parent.
@ -409,14 +409,14 @@ void MatcherGen::EmitMatchCode(const TreePatternNode *N,
// need to do a type check. Emit the check, apply the tyep to NodeNoTypes and // need to do a type check. Emit the check, apply the tyep to NodeNoTypes and
// reinfer any correlated types. // reinfer any correlated types.
SmallVector<unsigned, 2> ResultsToTypeCheck; SmallVector<unsigned, 2> ResultsToTypeCheck;
for (unsigned i = 0, e = NodeNoTypes->getNumTypes(); i != e; ++i) { for (unsigned i = 0, e = NodeNoTypes->getNumTypes(); i != e; ++i) {
if (NodeNoTypes->getExtType(i) == N->getExtType(i)) continue; if (NodeNoTypes->getExtType(i) == N->getExtType(i)) continue;
NodeNoTypes->setType(i, N->getExtType(i)); NodeNoTypes->setType(i, N->getExtType(i));
InferPossibleTypes(); InferPossibleTypes();
ResultsToTypeCheck.push_back(i); ResultsToTypeCheck.push_back(i);
} }
// If this node has a name associated with it, capture it in VariableMap. If // If this node has a name associated with it, capture it in VariableMap. If
// we already saw this in the pattern, emit code to verify dagness. // we already saw this in the pattern, emit code to verify dagness.
if (!N->getName().empty()) { if (!N->getName().empty()) {
@ -434,16 +434,16 @@ void MatcherGen::EmitMatchCode(const TreePatternNode *N,
return; return;
} }
} }
if (N->isLeaf()) if (N->isLeaf())
EmitLeafMatchCode(N); EmitLeafMatchCode(N);
else else
EmitOperatorMatchCode(N, NodeNoTypes); EmitOperatorMatchCode(N, NodeNoTypes);
// If there are node predicates for this node, generate their checks. // If there are node predicates for this node, generate their checks.
for (unsigned i = 0, e = N->getPredicateFns().size(); i != e; ++i) for (unsigned i = 0, e = N->getPredicateFns().size(); i != e; ++i)
AddMatcher(new CheckPredicateMatcher(N->getPredicateFns()[i])); AddMatcher(new CheckPredicateMatcher(N->getPredicateFns()[i]));
for (unsigned i = 0, e = ResultsToTypeCheck.size(); i != e; ++i) for (unsigned i = 0, e = ResultsToTypeCheck.size(); i != e; ++i)
AddMatcher(new CheckTypeMatcher(N->getType(ResultsToTypeCheck[i]), AddMatcher(new CheckTypeMatcher(N->getType(ResultsToTypeCheck[i]),
ResultsToTypeCheck[i])); ResultsToTypeCheck[i]));
@ -462,27 +462,27 @@ bool MatcherGen::EmitMatcherCode(unsigned Variant) {
const std::vector<Record*> &OpNodes = CP->getRootNodes(); const std::vector<Record*> &OpNodes = CP->getRootNodes();
assert(!OpNodes.empty() &&"Complex Pattern must specify what it can match"); assert(!OpNodes.empty() &&"Complex Pattern must specify what it can match");
if (Variant >= OpNodes.size()) return true; if (Variant >= OpNodes.size()) return true;
AddMatcher(new CheckOpcodeMatcher(CGP.getSDNodeInfo(OpNodes[Variant]))); AddMatcher(new CheckOpcodeMatcher(CGP.getSDNodeInfo(OpNodes[Variant])));
} else { } else {
if (Variant != 0) return true; if (Variant != 0) return true;
} }
// Emit the matcher for the pattern structure and types. // Emit the matcher for the pattern structure and types.
EmitMatchCode(Pattern.getSrcPattern(), PatWithNoTypes); EmitMatchCode(Pattern.getSrcPattern(), PatWithNoTypes);
// If the pattern has a predicate on it (e.g. only enabled when a subtarget // If the pattern has a predicate on it (e.g. only enabled when a subtarget
// feature is around, do the check). // feature is around, do the check).
if (!Pattern.getPredicateCheck().empty()) if (!Pattern.getPredicateCheck().empty())
AddMatcher(new CheckPatternPredicateMatcher(Pattern.getPredicateCheck())); AddMatcher(new CheckPatternPredicateMatcher(Pattern.getPredicateCheck()));
// Now that we've completed the structural type match, emit any ComplexPattern // Now that we've completed the structural type match, emit any ComplexPattern
// checks (e.g. addrmode matches). We emit this after the structural match // checks (e.g. addrmode matches). We emit this after the structural match
// because they are generally more expensive to evaluate and more difficult to // because they are generally more expensive to evaluate and more difficult to
// factor. // factor.
for (unsigned i = 0, e = MatchedComplexPatterns.size(); i != e; ++i) { for (unsigned i = 0, e = MatchedComplexPatterns.size(); i != e; ++i) {
const TreePatternNode *N = MatchedComplexPatterns[i].first; const TreePatternNode *N = MatchedComplexPatterns[i].first;
// Remember where the results of this match get stuck. // Remember where the results of this match get stuck.
MatchedComplexPatterns[i].second = NextRecordedOperandNo; MatchedComplexPatterns[i].second = NextRecordedOperandNo;
@ -491,15 +491,15 @@ bool MatcherGen::EmitMatcherCode(unsigned Variant) {
assert(!N->getName().empty() && RecNodeEntry && assert(!N->getName().empty() && RecNodeEntry &&
"Complex pattern should have a name and slot"); "Complex pattern should have a name and slot");
--RecNodeEntry; // Entries in VariableMap are biased. --RecNodeEntry; // Entries in VariableMap are biased.
const ComplexPattern &CP = const ComplexPattern &CP =
CGP.getComplexPattern(((DefInit*)N->getLeafValue())->getDef()); CGP.getComplexPattern(((DefInit*)N->getLeafValue())->getDef());
// Emit a CheckComplexPat operation, which does the match (aborting if it // Emit a CheckComplexPat operation, which does the match (aborting if it
// fails) and pushes the matched operands onto the recorded nodes list. // fails) and pushes the matched operands onto the recorded nodes list.
AddMatcher(new CheckComplexPatMatcher(CP, RecNodeEntry, AddMatcher(new CheckComplexPatMatcher(CP, RecNodeEntry,
N->getName(), NextRecordedOperandNo)); N->getName(), NextRecordedOperandNo));
// Record the right number of operands. // Record the right number of operands.
NextRecordedOperandNo += CP.getNumOperands(); NextRecordedOperandNo += CP.getNumOperands();
if (CP.hasProperty(SDNPHasChain)) { if (CP.hasProperty(SDNPHasChain)) {
@ -507,17 +507,17 @@ bool MatcherGen::EmitMatcherCode(unsigned Variant) {
// fact that we just recorded a chain input. The chain input will be // fact that we just recorded a chain input. The chain input will be
// matched as the last operand of the predicate if it was successful. // matched as the last operand of the predicate if it was successful.
++NextRecordedOperandNo; // Chained node operand. ++NextRecordedOperandNo; // Chained node operand.
// It is the last operand recorded. // It is the last operand recorded.
assert(NextRecordedOperandNo > 1 && assert(NextRecordedOperandNo > 1 &&
"Should have recorded input/result chains at least!"); "Should have recorded input/result chains at least!");
MatchedChainNodes.push_back(NextRecordedOperandNo-1); MatchedChainNodes.push_back(NextRecordedOperandNo-1);
} }
// TODO: Complex patterns can't have output flags, if they did, we'd want // TODO: Complex patterns can't have output flags, if they did, we'd want
// to record them. // to record them.
} }
return false; return false;
} }
@ -529,7 +529,7 @@ bool MatcherGen::EmitMatcherCode(unsigned Variant) {
void MatcherGen::EmitResultOfNamedOperand(const TreePatternNode *N, void MatcherGen::EmitResultOfNamedOperand(const TreePatternNode *N,
SmallVectorImpl<unsigned> &ResultOps){ SmallVectorImpl<unsigned> &ResultOps){
assert(!N->getName().empty() && "Operand not named!"); assert(!N->getName().empty() && "Operand not named!");
// A reference to a complex pattern gets all of the results of the complex // A reference to a complex pattern gets all of the results of the complex
// pattern's match. // pattern's match.
if (const ComplexPattern *CP = N->getComplexPatternInfo(CGP)) { if (const ComplexPattern *CP = N->getComplexPatternInfo(CGP)) {
@ -540,7 +540,7 @@ void MatcherGen::EmitResultOfNamedOperand(const TreePatternNode *N,
break; break;
} }
assert(SlotNo != 0 && "Didn't get a slot number assigned?"); assert(SlotNo != 0 && "Didn't get a slot number assigned?");
// The first slot entry is the node itself, the subsequent entries are the // The first slot entry is the node itself, the subsequent entries are the
// matched values. // matched values.
for (unsigned i = 0, e = CP->getNumOperands(); i != e; ++i) for (unsigned i = 0, e = CP->getNumOperands(); i != e; ++i)
@ -561,20 +561,20 @@ void MatcherGen::EmitResultOfNamedOperand(const TreePatternNode *N,
return; return;
} }
} }
ResultOps.push_back(SlotNo); ResultOps.push_back(SlotNo);
} }
void MatcherGen::EmitResultLeafAsOperand(const TreePatternNode *N, void MatcherGen::EmitResultLeafAsOperand(const TreePatternNode *N,
SmallVectorImpl<unsigned> &ResultOps) { SmallVectorImpl<unsigned> &ResultOps) {
assert(N->isLeaf() && "Must be a leaf"); assert(N->isLeaf() && "Must be a leaf");
if (IntInit *II = dynamic_cast<IntInit*>(N->getLeafValue())) { if (IntInit *II = dynamic_cast<IntInit*>(N->getLeafValue())) {
AddMatcher(new EmitIntegerMatcher(II->getValue(), N->getType(0))); AddMatcher(new EmitIntegerMatcher(II->getValue(), N->getType(0)));
ResultOps.push_back(NextRecordedOperandNo++); ResultOps.push_back(NextRecordedOperandNo++);
return; return;
} }
// If this is an explicit register reference, handle it. // If this is an explicit register reference, handle it.
if (DefInit *DI = dynamic_cast<DefInit*>(N->getLeafValue())) { if (DefInit *DI = dynamic_cast<DefInit*>(N->getLeafValue())) {
if (DI->getDef()->isSubClassOf("Register")) { if (DI->getDef()->isSubClassOf("Register")) {
@ -582,13 +582,13 @@ void MatcherGen::EmitResultLeafAsOperand(const TreePatternNode *N,
ResultOps.push_back(NextRecordedOperandNo++); ResultOps.push_back(NextRecordedOperandNo++);
return; return;
} }
if (DI->getDef()->getName() == "zero_reg") { if (DI->getDef()->getName() == "zero_reg") {
AddMatcher(new EmitRegisterMatcher(0, N->getType(0))); AddMatcher(new EmitRegisterMatcher(0, N->getType(0)));
ResultOps.push_back(NextRecordedOperandNo++); ResultOps.push_back(NextRecordedOperandNo++);
return; return;
} }
// Handle a reference to a register class. This is used // Handle a reference to a register class. This is used
// in COPY_TO_SUBREG instructions. // in COPY_TO_SUBREG instructions.
if (DI->getDef()->isSubClassOf("RegisterClass")) { if (DI->getDef()->isSubClassOf("RegisterClass")) {
@ -606,17 +606,17 @@ void MatcherGen::EmitResultLeafAsOperand(const TreePatternNode *N,
return; return;
} }
} }
errs() << "unhandled leaf node: \n"; errs() << "unhandled leaf node: \n";
N->dump(); N->dump();
} }
/// GetInstPatternNode - Get the pattern for an instruction. /// GetInstPatternNode - Get the pattern for an instruction.
/// ///
const TreePatternNode *MatcherGen:: const TreePatternNode *MatcherGen::
GetInstPatternNode(const DAGInstruction &Inst, const TreePatternNode *N) { GetInstPatternNode(const DAGInstruction &Inst, const TreePatternNode *N) {
const TreePattern *InstPat = Inst.getPattern(); const TreePattern *InstPat = Inst.getPattern();
// FIXME2?: Assume actual pattern comes before "implicit". // FIXME2?: Assume actual pattern comes before "implicit".
TreePatternNode *InstPatNode; TreePatternNode *InstPatNode;
if (InstPat) if (InstPat)
@ -625,11 +625,11 @@ GetInstPatternNode(const DAGInstruction &Inst, const TreePatternNode *N) {
InstPatNode = Pattern.getSrcPattern(); InstPatNode = Pattern.getSrcPattern();
else else
return 0; return 0;
if (InstPatNode && !InstPatNode->isLeaf() && if (InstPatNode && !InstPatNode->isLeaf() &&
InstPatNode->getOperator()->getName() == "set") InstPatNode->getOperator()->getName() == "set")
InstPatNode = InstPatNode->getChild(InstPatNode->getNumChildren()-1); InstPatNode = InstPatNode->getChild(InstPatNode->getNumChildren()-1);
return InstPatNode; return InstPatNode;
} }
@ -640,7 +640,7 @@ EmitResultInstructionAsOperand(const TreePatternNode *N,
const CodeGenTarget &CGT = CGP.getTargetInfo(); const CodeGenTarget &CGT = CGP.getTargetInfo();
CodeGenInstruction &II = CGT.getInstruction(Op); CodeGenInstruction &II = CGT.getInstruction(Op);
const DAGInstruction &Inst = CGP.getInstruction(Op); const DAGInstruction &Inst = CGP.getInstruction(Op);
// If we can, get the pattern for the instruction we're generating. We derive // If we can, get the pattern for the instruction we're generating. We derive
// a variety of information from this pattern, such as whether it has a chain. // a variety of information from this pattern, such as whether it has a chain.
// //
@ -649,10 +649,10 @@ EmitResultInstructionAsOperand(const TreePatternNode *N,
// nodes can't duplicate. // nodes can't duplicate.
const TreePatternNode *InstPatNode = GetInstPatternNode(Inst, N); const TreePatternNode *InstPatNode = GetInstPatternNode(Inst, N);
// NodeHasChain - Whether the instruction node we're creating takes chains. // NodeHasChain - Whether the instruction node we're creating takes chains.
bool NodeHasChain = InstPatNode && bool NodeHasChain = InstPatNode &&
InstPatNode->TreeHasProperty(SDNPHasChain, CGP); InstPatNode->TreeHasProperty(SDNPHasChain, CGP);
bool isRoot = N == Pattern.getDstPattern(); bool isRoot = N == Pattern.getDstPattern();
// TreeHasOutFlag - True if this tree has a flag. // TreeHasOutFlag - True if this tree has a flag.
@ -661,7 +661,7 @@ EmitResultInstructionAsOperand(const TreePatternNode *N,
const TreePatternNode *SrcPat = Pattern.getSrcPattern(); const TreePatternNode *SrcPat = Pattern.getSrcPattern();
TreeHasInFlag = SrcPat->TreeHasProperty(SDNPOptInFlag, CGP) || TreeHasInFlag = SrcPat->TreeHasProperty(SDNPOptInFlag, CGP) ||
SrcPat->TreeHasProperty(SDNPInFlag, CGP); SrcPat->TreeHasProperty(SDNPInFlag, CGP);
// FIXME2: this is checking the entire pattern, not just the node in // FIXME2: this is checking the entire pattern, not just the node in
// question, doing this just for the root seems like a total hack. // question, doing this just for the root seems like a total hack.
TreeHasOutFlag = SrcPat->TreeHasProperty(SDNPOutFlag, CGP); TreeHasOutFlag = SrcPat->TreeHasProperty(SDNPOutFlag, CGP);
@ -669,7 +669,7 @@ EmitResultInstructionAsOperand(const TreePatternNode *N,
// NumResults - This is the number of results produced by the instruction in // NumResults - This is the number of results produced by the instruction in
// the "outs" list. // the "outs" list.
unsigned NumResults = Inst.getNumResults(); unsigned NumResults = Inst.getNumResults();
// Loop over all of the operands of the instruction pattern, emitting code // Loop over all of the operands of the instruction pattern, emitting code
// to fill them all in. The node 'N' usually has number children equal to // to fill them all in. The node 'N' usually has number children equal to
@ -680,7 +680,7 @@ EmitResultInstructionAsOperand(const TreePatternNode *N,
SmallVector<unsigned, 8> InstOps; SmallVector<unsigned, 8> InstOps;
for (unsigned ChildNo = 0, InstOpNo = NumResults, e = II.Operands.size(); for (unsigned ChildNo = 0, InstOpNo = NumResults, e = II.Operands.size();
InstOpNo != e; ++InstOpNo) { InstOpNo != e; ++InstOpNo) {
// Determine what to emit for this operand. // Determine what to emit for this operand.
Record *OperandNode = II.Operands[InstOpNo].Rec; Record *OperandNode = II.Operands[InstOpNo].Rec;
if ((OperandNode->isSubClassOf("PredicateOperand") || if ((OperandNode->isSubClassOf("PredicateOperand") ||
@ -689,28 +689,28 @@ EmitResultInstructionAsOperand(const TreePatternNode *N,
// This is a predicate or optional def operand; emit the // This is a predicate or optional def operand; emit the
// 'default ops' operands. // 'default ops' operands.
const DAGDefaultOperand &DefaultOp const DAGDefaultOperand &DefaultOp
= CGP.getDefaultOperand(OperandNode); = CGP.getDefaultOperand(OperandNode);
for (unsigned i = 0, e = DefaultOp.DefaultOps.size(); i != e; ++i) for (unsigned i = 0, e = DefaultOp.DefaultOps.size(); i != e; ++i)
EmitResultOperand(DefaultOp.DefaultOps[i], InstOps); EmitResultOperand(DefaultOp.DefaultOps[i], InstOps);
continue; continue;
} }
const TreePatternNode *Child = N->getChild(ChildNo); const TreePatternNode *Child = N->getChild(ChildNo);
// Otherwise this is a normal operand or a predicate operand without // Otherwise this is a normal operand or a predicate operand without
// 'execute always'; emit it. // 'execute always'; emit it.
unsigned BeforeAddingNumOps = InstOps.size(); unsigned BeforeAddingNumOps = InstOps.size();
EmitResultOperand(Child, InstOps); EmitResultOperand(Child, InstOps);
assert(InstOps.size() > BeforeAddingNumOps && "Didn't add any operands"); assert(InstOps.size() > BeforeAddingNumOps && "Didn't add any operands");
// If the operand is an instruction and it produced multiple results, just // If the operand is an instruction and it produced multiple results, just
// take the first one. // take the first one.
if (!Child->isLeaf() && Child->getOperator()->isSubClassOf("Instruction")) if (!Child->isLeaf() && Child->getOperator()->isSubClassOf("Instruction"))
InstOps.resize(BeforeAddingNumOps+1); InstOps.resize(BeforeAddingNumOps+1);
++ChildNo; ++ChildNo;
} }
// If this node has an input flag or explicitly specified input physregs, we // If this node has an input flag or explicitly specified input physregs, we
// need to add chained and flagged copyfromreg nodes and materialize the flag // need to add chained and flagged copyfromreg nodes and materialize the flag
// input. // input.
@ -724,14 +724,14 @@ EmitResultInstructionAsOperand(const TreePatternNode *N,
// flagged to the CopyFromReg nodes we just generated. // flagged to the CopyFromReg nodes we just generated.
TreeHasInFlag = true; TreeHasInFlag = true;
} }
// Result order: node results, chain, flags // Result order: node results, chain, flags
// Determine the result types. // Determine the result types.
SmallVector<MVT::SimpleValueType, 4> ResultVTs; SmallVector<MVT::SimpleValueType, 4> ResultVTs;
for (unsigned i = 0, e = N->getNumTypes(); i != e; ++i) for (unsigned i = 0, e = N->getNumTypes(); i != e; ++i)
ResultVTs.push_back(N->getType(i)); ResultVTs.push_back(N->getType(i));
// If this is the root instruction of a pattern that has physical registers in // If this is the root instruction of a pattern that has physical registers in
// its result pattern, add output VTs for them. For example, X86 has: // its result pattern, add output VTs for them. For example, X86 has:
// (set AL, (mul ...)) // (set AL, (mul ...))
@ -743,7 +743,7 @@ EmitResultInstructionAsOperand(const TreePatternNode *N,
Record *HandledReg = 0; Record *HandledReg = 0;
if (II.HasOneImplicitDefWithKnownVT(CGT) != MVT::Other) if (II.HasOneImplicitDefWithKnownVT(CGT) != MVT::Other)
HandledReg = II.ImplicitDefs[0]; HandledReg = II.ImplicitDefs[0];
for (unsigned i = 0; i != Pattern.getDstRegs().size(); ++i) { for (unsigned i = 0; i != Pattern.getDstRegs().size(); ++i) {
Record *Reg = Pattern.getDstRegs()[i]; Record *Reg = Pattern.getDstRegs()[i];
if (!Reg->isSubClassOf("Register") || Reg == HandledReg) continue; if (!Reg->isSubClassOf("Register") || Reg == HandledReg) continue;
@ -758,7 +758,7 @@ EmitResultInstructionAsOperand(const TreePatternNode *N,
if (isRoot && if (isRoot &&
(Pattern.getSrcPattern()->NodeHasProperty(SDNPVariadic, CGP))) (Pattern.getSrcPattern()->NodeHasProperty(SDNPVariadic, CGP)))
NumFixedArityOperands = Pattern.getSrcPattern()->getNumChildren(); NumFixedArityOperands = Pattern.getSrcPattern()->getNumChildren();
// If this is the root node and any of the nodes matched nodes in the input // If this is the root node and any of the nodes matched nodes in the input
// pattern have MemRefs in them, have the interpreter collect them and plop // pattern have MemRefs in them, have the interpreter collect them and plop
// them onto this node. // them onto this node.
@ -777,14 +777,14 @@ EmitResultInstructionAsOperand(const TreePatternNode *N,
assert((!ResultVTs.empty() || TreeHasOutFlag || NodeHasChain) && assert((!ResultVTs.empty() || TreeHasOutFlag || NodeHasChain) &&
"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.data(), ResultVTs.size(),
InstOps.data(), InstOps.size(), InstOps.data(), InstOps.size(),
NodeHasChain, TreeHasInFlag, TreeHasOutFlag, NodeHasChain, TreeHasInFlag, TreeHasOutFlag,
NodeHasMemRefs, NumFixedArityOperands, NodeHasMemRefs, NumFixedArityOperands,
NextRecordedOperandNo)); NextRecordedOperandNo));
// The non-chain and non-flag results of the newly emitted node get recorded. // The non-chain and non-flag results of the newly emitted node get recorded.
for (unsigned i = 0, e = ResultVTs.size(); i != e; ++i) { for (unsigned i = 0, e = ResultVTs.size(); i != e; ++i) {
if (ResultVTs[i] == MVT::Other || ResultVTs[i] == MVT::Glue) break; if (ResultVTs[i] == MVT::Other || ResultVTs[i] == MVT::Glue) break;
@ -799,7 +799,7 @@ EmitResultSDNodeXFormAsOperand(const TreePatternNode *N,
// Emit the operand. // Emit the operand.
SmallVector<unsigned, 8> InputOps; SmallVector<unsigned, 8> InputOps;
// FIXME2: Could easily generalize this to support multiple inputs and outputs // FIXME2: Could easily generalize this to support multiple inputs and outputs
// to the SDNodeXForm. For now we just support one input and one output like // to the SDNodeXForm. For now we just support one input and one output like
// the old instruction selector. // the old instruction selector.
@ -838,7 +838,7 @@ void MatcherGen::EmitResultCode() {
if (!MatchedChainNodes.empty()) if (!MatchedChainNodes.empty())
AddMatcher(new EmitMergeInputChainsMatcher AddMatcher(new EmitMergeInputChainsMatcher
(MatchedChainNodes.data(), MatchedChainNodes.size())); (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;
EmitResultOperand(Pattern.getDstPattern(), Ops); EmitResultOperand(Pattern.getDstPattern(), Ops);
@ -850,7 +850,7 @@ void MatcherGen::EmitResultCode() {
// explicit results. // explicit results.
// //
unsigned NumSrcResults = Pattern.getSrcPattern()->getNumTypes(); unsigned NumSrcResults = Pattern.getSrcPattern()->getNumTypes();
// If the pattern also has (implicit) results, count them as well. // If the pattern also has (implicit) results, count them as well.
if (!Pattern.getDstRegs().empty()) { if (!Pattern.getDstRegs().empty()) {
// If the root came from an implicit def in the instruction handling stuff, // If the root came from an implicit def in the instruction handling stuff,
@ -864,14 +864,14 @@ void MatcherGen::EmitResultCode() {
if (II.HasOneImplicitDefWithKnownVT(CGT) != MVT::Other) if (II.HasOneImplicitDefWithKnownVT(CGT) != MVT::Other)
HandledReg = II.ImplicitDefs[0]; HandledReg = II.ImplicitDefs[0];
} }
for (unsigned i = 0; i != Pattern.getDstRegs().size(); ++i) { for (unsigned i = 0; i != Pattern.getDstRegs().size(); ++i) {
Record *Reg = Pattern.getDstRegs()[i]; Record *Reg = Pattern.getDstRegs()[i];
if (!Reg->isSubClassOf("Register") || Reg == HandledReg) continue; if (!Reg->isSubClassOf("Register") || Reg == HandledReg) continue;
++NumSrcResults; ++NumSrcResults;
} }
} }
assert(Ops.size() >= NumSrcResults && "Didn't provide enough results"); assert(Ops.size() >= NumSrcResults && "Didn't provide enough results");
Ops.resize(NumSrcResults); Ops.resize(NumSrcResults);
@ -880,7 +880,7 @@ void MatcherGen::EmitResultCode() {
if (!MatchedFlagResultNodes.empty()) if (!MatchedFlagResultNodes.empty())
AddMatcher(new MarkFlagResultsMatcher(MatchedFlagResultNodes.data(), AddMatcher(new MarkFlagResultsMatcher(MatchedFlagResultNodes.data(),
MatchedFlagResultNodes.size())); MatchedFlagResultNodes.size()));
AddMatcher(new CompleteMatchMatcher(Ops.data(), Ops.size(), Pattern)); AddMatcher(new CompleteMatchMatcher(Ops.data(), Ops.size(), Pattern));
} }
@ -895,12 +895,12 @@ Matcher *llvm::ConvertPatternToMatcher(const PatternToMatch &Pattern,
// Generate the code for the matcher. // Generate the code for the matcher.
if (Gen.EmitMatcherCode(Variant)) if (Gen.EmitMatcherCode(Variant))
return 0; return 0;
// FIXME2: Kill extra MoveParent commands at the end of the matcher sequence. // FIXME2: Kill extra MoveParent commands at the end of the matcher sequence.
// FIXME2: Split result code out to another table, and make the matcher end // FIXME2: Split result code out to another table, and make the matcher end
// with an "Emit <index>" command. This allows result generation stuff to be // with an "Emit <index>" command. This allows result generation stuff to be
// shared and factored? // shared and factored?
// If the match succeeds, then we generate Pattern. // If the match succeeds, then we generate Pattern.
Gen.EmitResultCode(); Gen.EmitResultCode();