本文整理汇总了C++中Pattern::getTree方法的典型用法代码示例。如果您正苦于以下问题:C++ Pattern::getTree方法的具体用法?C++ Pattern::getTree怎么用?C++ Pattern::getTree使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Pattern
的用法示例。
在下文中一共展示了Pattern::getTree方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CalculateComputableValues
// CalculateComputableValues - Fill in the ComputableValues map through
// analysis of the patterns we are playing with.
void InstrSelectorEmitter::CalculateComputableValues() {
// Loop over all of the patterns, adding them to the ComputableValues map
for (std::map<Record*, Pattern*>::iterator I = Patterns.begin(),
E = Patterns.end(); I != E; ++I)
if (I->second->isResolved()) {
// We don't want to add patterns like R32 = R32. This is a hack working
// around a special case of a general problem, but for now we explicitly
// forbid these patterns. They can never match anyway.
Pattern *P = I->second;
if (!P->getResult() || !P->getTree()->isLeaf() ||
P->getResult() != P->getTree()->getValueRecord())
ComputableValues.addPattern(P);
}
}
示例2: assert
/// InstantiateNonterminal - This method takes the nonterminal specified by
/// NT, which should not be completely resolved, clones it, applies ResultTy
/// to its root, then runs the type inference stuff on it. This should
/// produce a newly resolved nonterminal, which we make a record for and
/// return. To be extra fancy and efficient, this only makes one clone for
/// each type it is instantiated with.
Record *InstrSelectorEmitter::InstantiateNonterminal(Pattern *NT,
MVT::ValueType ResultTy) {
assert(!NT->isResolved() && "Nonterminal is already resolved!");
// Check to see if we have already instantiated this pair...
Record* &Slot = InstantiatedNTs[std::make_pair(NT, ResultTy)];
if (Slot) return Slot;
Record *New = new Record(NT->getRecord()->getName()+"_"+getName(ResultTy));
// Copy over the superclasses...
const std::vector<Record*> &SCs = NT->getRecord()->getSuperClasses();
for (unsigned i = 0, e = SCs.size(); i != e; ++i)
New->addSuperClass(SCs[i]);
DEBUG(std::cerr << " Nonterminal '" << NT->getRecord()->getName()
<< "' for type '" << getName(ResultTy) << "', producing '"
<< New->getName() << "'\n");
// Copy the pattern...
Pattern *NewPat = NT->clone(New);
// Apply the type to the root...
NewPat->getTree()->updateNodeType(ResultTy, New->getName());
// Infer types...
NewPat->InferAllTypes();
// Make sure everything is good to go now...
if (!NewPat->isResolved())
NewPat->error("Instantiating nonterminal did not resolve all types!");
// Add the pattern to the patterns map, add the record to the RecordKeeper,
// return the new record.
Patterns[New] = NewPat;
Records.addDef(New);
return Slot = New;
}
示例3: run
//.........这里部分代码省略.........
OS << " ReducedValue_" << I->first << " *Reduce_" << I->first
<< "(SelectionDAGNode *N,\n" << std::string(27+2*I->first.size(), ' ')
<< "MachineBasicBlock *MBB);\n";
OS << " };\n}\n\n";
// Emit the generateCode entry-point...
OS << "void " << Target.getName () << "ISel::generateCode() {\n"
<< " SelectionDAGNode *Root = DAG.getRoot();\n"
<< " assert(Root->getValueType() == MVT::isVoid && "
"\"Root of DAG produces value??\");\n\n"
<< " std::cerr << \"\\n\";\n"
<< " unsigned Cost = Match_Void_void(Root);\n"
<< " if (Cost >= ~0U >> 1) {\n"
<< " std::cerr << \"Match failed!\\n\";\n"
<< " Root->dump();\n"
<< " abort();\n"
<< " }\n\n"
<< " std::cerr << \"Total DAG Cost: \" << Cost << \"\\n\\n\";\n\n"
<< " Reduce_Void_void(Root, 0);\n"
<< "}\n\n"
<< "//===" << std::string(70, '-') << "===//\n"
<< "// Matching methods...\n"
<< "//\n\n";
//===--------------------------------------------------------------------===//
// Emit all of the matcher methods...
//
for (PatternOrganizer::iterator I = ComputableValues.begin(),
E = ComputableValues.end(); I != E; ++I) {
const std::string &SlotName = I->first;
OS << "unsigned " << Target.getName() << "ISel::Match_" << SlotName
<< "(SelectionDAGNode *N) {\n"
<< " assert(N->getValueType() == MVT::"
<< getEnumName((*I->second.begin()).second[0]->getTree()->getType())
<< ");\n" << " // If we already have a cost available for " << SlotName
<< " use it!\n"
<< " if (N->getPatternFor(" << SlotName << "_Slot))\n"
<< " return N->getCostFor(" << SlotName << "_Slot);\n\n"
<< " unsigned Cost;\n"
<< " switch (N->getNodeType()) {\n"
<< " default: Cost = ~0U >> 1; // Match failed\n"
<< " N->setPatternCostFor(" << SlotName << "_Slot, NoMatchPattern, Cost, NumSlots);\n"
<< " break;\n";
for (PatternOrganizer::NodesForSlot::iterator J = I->second.begin(),
E = I->second.end(); J != E; ++J)
if (!J->first->isSubClassOf("Nonterminal"))
OS << " case ISD::" << getNodeName(J->first) << ":\tCost = Match_"
<< SlotName << "_" << getNodeName(J->first) << "(N); break;\n";
OS << " }\n"; // End of the switch statement
// Emit any patterns which have a nonterminal leaf as the RHS. These may
// match multiple root nodes, so they cannot be handled with the switch...
for (PatternOrganizer::NodesForSlot::iterator J = I->second.begin(),
E = I->second.end(); J != E; ++J)
if (J->first->isSubClassOf("Nonterminal")) {
OS << " unsigned " << J->first->getName() << "_Cost = Match_"
<< getNodeName(J->first) << "(N);\n"
<< " if (" << getNodeName(J->first) << "_Cost < Cost) Cost = "
<< getNodeName(J->first) << "_Cost;\n";
}
OS << " return Cost;\n}\n\n";
for (PatternOrganizer::NodesForSlot::iterator J = I->second.begin(),
E = I->second.end(); J != E; ++J) {
示例4: EmitMatchCosters
//.........这里部分代码省略.........
OS << Indent << "{ // ";
if (Group.size() != 1) {
OS << Group.size() << " size group...\n";
OS << Indent << " unsigned " << VarPrefix << "_Pattern = NoMatch;\n";
} else {
OS << *Group[0].first << "\n";
OS << Indent << " unsigned " << VarPrefix << "_Pattern = "
<< Group[0].first->getRecord()->getName() << "_Pattern;\n";
}
OS << Indent << " unsigned " << LocCostName << " = ";
if (Group.size() == 1)
OS << "1;\n"; // Add inst cost if at individual rec
else
OS << "0;\n";
// Loop over all of the operands, adding in their costs...
TreePatternNode *N = Group[0].second;
const std::vector<TreePatternNode*> &Children = N->getChildren();
// If necessary, emit conditionals to check for the appropriate tree
// structure here...
for (unsigned i = 0, e = Children.size(); i != e; ++i) {
TreePatternNode *C = Children[i];
if (C->isLeaf()) {
// We already calculated the cost for this leaf, add it in now...
OS << Indent << " " << LocCostName << " += "
<< VarPrefix << "_Op" << utostr(i) << "_"
<< C->getValueRecord()->getName() << "_Cost;\n";
} else {
// If it's not a leaf, we have to check to make sure that the current
// node has the appropriate structure, then recurse into it...
OS << Indent << " if (" << VarPrefix << "_Op" << i
<< "->getNodeType() == ISD::" << getNodeName(C->getOperator())
<< ") {\n";
std::vector<std::pair<Pattern*, TreePatternNode*> > SubPatterns;
for (unsigned n = 0, e = Group.size(); n != e; ++n)
SubPatterns.push_back(std::make_pair(Group[n].first,
Group[n].second->getChild(i)));
EmitMatchCosters(OS, SubPatterns, VarPrefix+"_Op"+utostr(i),
IndentAmt + 4);
OS << Indent << " }\n";
}
}
// If the cost for this match is less than the minimum computed cost so far,
// update the minimum cost and selected pattern.
OS << Indent << " if (" << LocCostName << " < " << LocCostName << "Min) { "
<< LocCostName << "Min = " << LocCostName << "; " << VarPrefix
<< "_PatternMin = " << VarPrefix << "_Pattern; }\n";
OS << Indent << "}\n";
}
#endif
for (unsigned i = 0, e = Patterns.size(); i != e; ++i) {
Pattern *P = Patterns[i].first;
TreePatternNode *PTree = P->getTree();
unsigned PatternCost = 1;
// Check to see if there are any non-leaf elements in the pattern. If so,
// we need to emit a predicate for this match.
bool AnyNonLeaf = false;
for (unsigned c = 0, e = PTree->getNumChildren(); c != e; ++c)
if (!PTree->getChild(c)->isLeaf()) {
AnyNonLeaf = true;
break;
}
if (!AnyNonLeaf) { // No predicate necessary, just output a scope...
OS << " {// " << *P << "\n";
} else {
// We need to emit a predicate to make sure the tree pattern matches, do
// so now...
OS << " if (1";
for (unsigned c = 0, e = PTree->getNumChildren(); c != e; ++c)
if (!PTree->getChild(c)->isLeaf())
EmitPatternPredicates(PTree->getChild(c),
VarPrefix + "_Op" + utostr(c), OS);
OS << ") {\n // " << *P << "\n";
}
OS << " unsigned PatCost = " << PatternCost;
for (unsigned c = 0, e = PTree->getNumChildren(); c != e; ++c)
if (PTree->getChild(c)->isLeaf()) {
OS << " + " << VarPrefix << "_Op" << c << "_"
<< PTree->getChild(c)->getValueRecord()->getName() << "_Cost";
} else {
EmitPatternCosts(PTree->getChild(c), VarPrefix + "_Op" + utostr(c), OS);
}
OS << ";\n";
OS << " if (PatCost < MinCost) { MinCost = PatCost; Pattern = "
<< P->getRecord()->getName() << "_Pattern; }\n"
<< " }\n";
}
}