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 void ScopeMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
29 OS.indent(indent) << "Scope\n";
30 Check->print(OS, indent+2);
33 void RecordMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
34 OS.indent(indent) << "Record\n";
37 void RecordChildMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
38 OS.indent(indent) << "RecordChild: " << ChildNo << '\n';
41 void RecordMemRefMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
42 OS.indent(indent) << "RecordMemRef\n";
45 void CaptureFlagInputMatcher::printImpl(raw_ostream &OS, unsigned indent) const{
46 OS.indent(indent) << "CaptureFlagInput\n";
49 void MoveChildMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
50 OS.indent(indent) << "MoveChild " << ChildNo << '\n';
53 void MoveParentMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
54 OS.indent(indent) << "MoveParent\n";
57 void CheckSameMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
58 OS.indent(indent) << "CheckSame " << MatchNumber << '\n';
61 void CheckPatternPredicateMatcher::
62 printImpl(raw_ostream &OS, unsigned indent) const {
63 OS.indent(indent) << "CheckPatternPredicate " << Predicate << '\n';
66 void CheckPredicateMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
67 OS.indent(indent) << "CheckPredicate " << PredName << '\n';
70 void CheckOpcodeMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
71 OS.indent(indent) << "CheckOpcode " << OpcodeName << '\n';
74 void CheckMultiOpcodeMatcher::printImpl(raw_ostream &OS, unsigned indent) const{
75 OS.indent(indent) << "CheckMultiOpcode <todo args>\n";
78 void CheckTypeMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
79 OS.indent(indent) << "CheckType " << getEnumName(Type) << '\n';
82 void CheckChildTypeMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
83 OS.indent(indent) << "CheckChildType " << ChildNo << " "
84 << getEnumName(Type) << '\n';
88 void CheckIntegerMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
89 OS.indent(indent) << "CheckInteger " << Value << '\n';
92 void CheckCondCodeMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
93 OS.indent(indent) << "CheckCondCode ISD::" << CondCodeName << '\n';
96 void CheckValueTypeMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
97 OS.indent(indent) << "CheckValueType MVT::" << TypeName << '\n';
100 void CheckComplexPatMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
101 OS.indent(indent) << "CheckComplexPat " << Pattern.getSelectFunc() << '\n';
104 void CheckAndImmMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
105 OS.indent(indent) << "CheckAndImm " << Value << '\n';
108 void CheckOrImmMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
109 OS.indent(indent) << "CheckOrImm " << Value << '\n';
112 void CheckFoldableChainNodeMatcher::printImpl(raw_ostream &OS,
113 unsigned indent) const {
114 OS.indent(indent) << "CheckFoldableChainNode\n";
117 void CheckChainCompatibleMatcher::printImpl(raw_ostream &OS,
118 unsigned indent) const {
119 OS.indent(indent) << "CheckChainCompatible " << PreviousOp << "\n";
122 void EmitIntegerMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
123 OS.indent(indent) << "EmitInteger " << Val << " VT=" << VT << '\n';
126 void EmitStringIntegerMatcher::
127 printImpl(raw_ostream &OS, unsigned indent) const {
128 OS.indent(indent) << "EmitStringInteger " << Val << " VT=" << VT << '\n';
131 void EmitRegisterMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
132 OS.indent(indent) << "EmitRegister ";
134 OS << Reg->getName();
137 OS << " VT=" << VT << '\n';
140 void EmitConvertToTargetMatcher::
141 printImpl(raw_ostream &OS, unsigned indent) const {
142 OS.indent(indent) << "EmitConvertToTarget " << Slot << '\n';
145 void EmitMergeInputChainsMatcher::
146 printImpl(raw_ostream &OS, unsigned indent) const {
147 OS.indent(indent) << "EmitMergeInputChains <todo: args>\n";
150 void EmitCopyToRegMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
151 OS.indent(indent) << "EmitCopyToReg <todo: args>\n";
154 void EmitNodeXFormMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
155 OS.indent(indent) << "EmitNodeXForm " << NodeXForm->getName()
156 << " Slot=" << Slot << '\n';
160 void EmitNodeMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
161 OS.indent(indent) << "EmitNode: " << OpcodeName << ": <todo flags> ";
163 for (unsigned i = 0, e = VTs.size(); i != e; ++i)
164 OS << ' ' << getEnumName(VTs[i]);
166 for (unsigned i = 0, e = Operands.size(); i != e; ++i)
167 OS << Operands[i] << ' ';
171 void MarkFlagResultsMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
172 OS.indent(indent) << "MarkFlagResults <todo: args>\n";
175 void CompleteMatchMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
176 OS.indent(indent) << "CompleteMatch <todo args>\n";
177 OS.indent(indent) << "Src = " << *Pattern.getSrcPattern() << "\n";
178 OS.indent(indent) << "Dst = " << *Pattern.getDstPattern() << "\n";
181 // getHashImpl Implementation.
183 unsigned CheckPatternPredicateMatcher::getHashImpl() const {
184 return HashString(Predicate);
187 unsigned CheckPredicateMatcher::getHashImpl() const {
188 return HashString(PredName);
191 unsigned CheckOpcodeMatcher::getHashImpl() const {
192 return HashString(OpcodeName);
195 unsigned CheckMultiOpcodeMatcher::getHashImpl() const {
197 for (unsigned i = 0, e = OpcodeNames.size(); i != e; ++i)
198 Result |= HashString(OpcodeNames[i]);
202 unsigned CheckCondCodeMatcher::getHashImpl() const {
203 return HashString(CondCodeName);
206 unsigned CheckValueTypeMatcher::getHashImpl() const {
207 return HashString(TypeName);
210 unsigned EmitStringIntegerMatcher::getHashImpl() const {
211 return HashString(Val) ^ VT;
214 template<typename It>
215 static unsigned HashUnsigneds(It I, It E) {
218 Result = (Result<<3) ^ *I;
222 unsigned EmitMergeInputChainsMatcher::getHashImpl() const {
223 return HashUnsigneds(ChainNodes.begin(), ChainNodes.end());
226 bool EmitNodeMatcher::isEqualImpl(const Matcher *m) const {
227 const EmitNodeMatcher *M = cast<EmitNodeMatcher>(m);
228 return M->OpcodeName == OpcodeName && M->VTs == VTs &&
229 M->Operands == Operands && M->HasChain == HasChain &&
230 M->HasFlag == HasFlag && M->HasMemRefs == HasMemRefs &&
231 M->NumFixedArityOperands == NumFixedArityOperands;
234 unsigned EmitNodeMatcher::getHashImpl() const {
235 return (HashString(OpcodeName) << 4) | Operands.size();
239 unsigned MarkFlagResultsMatcher::getHashImpl() const {
240 return HashUnsigneds(FlagResultNodes.begin(), FlagResultNodes.end());
243 unsigned CompleteMatchMatcher::getHashImpl() const {
244 return HashUnsigneds(Results.begin(), Results.end()) ^
245 ((unsigned)(intptr_t)&Pattern << 8);