1 //===- DAGISelMatcher.cpp - Representation of DAG pattern matcher ---------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "DAGISelMatcher.h"
11 #include "CodeGenDAGPatterns.h"
12 #include "CodeGenTarget.h"
14 #include "llvm/Support/raw_ostream.h"
15 #include "llvm/ADT/StringExtras.h"
18 void Matcher::dump() const {
22 void Matcher::print(raw_ostream &OS, unsigned indent) const {
23 printImpl(OS, indent);
25 return Next->print(OS, indent);
28 ScopeMatcher::~ScopeMatcher() {
29 for (unsigned i = 0, e = Children.size(); i != e; ++i)
36 void ScopeMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
37 OS.indent(indent) << "Scope\n";
38 for (unsigned i = 0, e = getNumChildren(); i != e; ++i)
39 getChild(i)->print(OS, indent+2);
42 void RecordMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
43 OS.indent(indent) << "Record\n";
46 void RecordChildMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
47 OS.indent(indent) << "RecordChild: " << ChildNo << '\n';
50 void RecordMemRefMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
51 OS.indent(indent) << "RecordMemRef\n";
54 void CaptureFlagInputMatcher::printImpl(raw_ostream &OS, unsigned indent) const{
55 OS.indent(indent) << "CaptureFlagInput\n";
58 void MoveChildMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
59 OS.indent(indent) << "MoveChild " << ChildNo << '\n';
62 void MoveParentMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
63 OS.indent(indent) << "MoveParent\n";
66 void CheckSameMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
67 OS.indent(indent) << "CheckSame " << MatchNumber << '\n';
70 void CheckPatternPredicateMatcher::
71 printImpl(raw_ostream &OS, unsigned indent) const {
72 OS.indent(indent) << "CheckPatternPredicate " << Predicate << '\n';
75 void CheckPredicateMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
76 OS.indent(indent) << "CheckPredicate " << PredName << '\n';
79 void CheckOpcodeMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
80 OS.indent(indent) << "CheckOpcode " << OpcodeName << '\n';
83 void CheckMultiOpcodeMatcher::printImpl(raw_ostream &OS, unsigned indent) const{
84 OS.indent(indent) << "CheckMultiOpcode <todo args>\n";
87 void CheckTypeMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
88 OS.indent(indent) << "CheckType " << getEnumName(Type) << '\n';
91 void CheckChildTypeMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
92 OS.indent(indent) << "CheckChildType " << ChildNo << " "
93 << getEnumName(Type) << '\n';
97 void CheckIntegerMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
98 OS.indent(indent) << "CheckInteger " << Value << '\n';
101 void CheckCondCodeMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
102 OS.indent(indent) << "CheckCondCode ISD::" << CondCodeName << '\n';
105 void CheckValueTypeMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
106 OS.indent(indent) << "CheckValueType MVT::" << TypeName << '\n';
109 void CheckComplexPatMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
110 OS.indent(indent) << "CheckComplexPat " << Pattern.getSelectFunc() << '\n';
113 void CheckAndImmMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
114 OS.indent(indent) << "CheckAndImm " << Value << '\n';
117 void CheckOrImmMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
118 OS.indent(indent) << "CheckOrImm " << Value << '\n';
121 void CheckFoldableChainNodeMatcher::printImpl(raw_ostream &OS,
122 unsigned indent) const {
123 OS.indent(indent) << "CheckFoldableChainNode\n";
126 void CheckChainCompatibleMatcher::printImpl(raw_ostream &OS,
127 unsigned indent) const {
128 OS.indent(indent) << "CheckChainCompatible " << PreviousOp << "\n";
131 void EmitIntegerMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
132 OS.indent(indent) << "EmitInteger " << Val << " VT=" << VT << '\n';
135 void EmitStringIntegerMatcher::
136 printImpl(raw_ostream &OS, unsigned indent) const {
137 OS.indent(indent) << "EmitStringInteger " << Val << " VT=" << VT << '\n';
140 void EmitRegisterMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
141 OS.indent(indent) << "EmitRegister ";
143 OS << Reg->getName();
146 OS << " VT=" << VT << '\n';
149 void EmitConvertToTargetMatcher::
150 printImpl(raw_ostream &OS, unsigned indent) const {
151 OS.indent(indent) << "EmitConvertToTarget " << Slot << '\n';
154 void EmitMergeInputChainsMatcher::
155 printImpl(raw_ostream &OS, unsigned indent) const {
156 OS.indent(indent) << "EmitMergeInputChains <todo: args>\n";
159 void EmitCopyToRegMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
160 OS.indent(indent) << "EmitCopyToReg <todo: args>\n";
163 void EmitNodeXFormMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
164 OS.indent(indent) << "EmitNodeXForm " << NodeXForm->getName()
165 << " Slot=" << Slot << '\n';
169 void EmitNodeMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
170 OS.indent(indent) << "EmitNode: " << OpcodeName << ": <todo flags> ";
172 for (unsigned i = 0, e = VTs.size(); i != e; ++i)
173 OS << ' ' << getEnumName(VTs[i]);
175 for (unsigned i = 0, e = Operands.size(); i != e; ++i)
176 OS << Operands[i] << ' ';
180 void MarkFlagResultsMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
181 OS.indent(indent) << "MarkFlagResults <todo: args>\n";
184 void CompleteMatchMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
185 OS.indent(indent) << "CompleteMatch <todo args>\n";
186 OS.indent(indent) << "Src = " << *Pattern.getSrcPattern() << "\n";
187 OS.indent(indent) << "Dst = " << *Pattern.getDstPattern() << "\n";
190 // getHashImpl Implementation.
192 unsigned CheckPatternPredicateMatcher::getHashImpl() const {
193 return HashString(Predicate);
196 unsigned CheckPredicateMatcher::getHashImpl() const {
197 return HashString(PredName);
200 unsigned CheckOpcodeMatcher::getHashImpl() const {
201 return HashString(OpcodeName);
204 unsigned CheckMultiOpcodeMatcher::getHashImpl() const {
206 for (unsigned i = 0, e = OpcodeNames.size(); i != e; ++i)
207 Result |= HashString(OpcodeNames[i]);
211 unsigned CheckCondCodeMatcher::getHashImpl() const {
212 return HashString(CondCodeName);
215 unsigned CheckValueTypeMatcher::getHashImpl() const {
216 return HashString(TypeName);
219 unsigned EmitStringIntegerMatcher::getHashImpl() const {
220 return HashString(Val) ^ VT;
223 template<typename It>
224 static unsigned HashUnsigneds(It I, It E) {
227 Result = (Result<<3) ^ *I;
231 unsigned EmitMergeInputChainsMatcher::getHashImpl() const {
232 return HashUnsigneds(ChainNodes.begin(), ChainNodes.end());
235 bool EmitNodeMatcher::isEqualImpl(const Matcher *m) const {
236 const EmitNodeMatcher *M = cast<EmitNodeMatcher>(m);
237 return M->OpcodeName == OpcodeName && M->VTs == VTs &&
238 M->Operands == Operands && M->HasChain == HasChain &&
239 M->HasFlag == HasFlag && M->HasMemRefs == HasMemRefs &&
240 M->NumFixedArityOperands == NumFixedArityOperands;
243 unsigned EmitNodeMatcher::getHashImpl() const {
244 return (HashString(OpcodeName) << 4) | Operands.size();
248 unsigned MarkFlagResultsMatcher::getHashImpl() const {
249 return HashUnsigneds(FlagResultNodes.begin(), FlagResultNodes.end());
252 unsigned CompleteMatchMatcher::getHashImpl() const {
253 return HashUnsigneds(Results.begin(), Results.end()) ^
254 ((unsigned)(intptr_t)&Pattern << 8);