1 //===- InstrInfoEmitter.cpp - Generate a Instruction Set Desc. ------------===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This tablegen backend is responsible for emitting a description of the target
11 // instruction set for the code generator.
13 //===----------------------------------------------------------------------===//
15 #include "InstrSelectorEmitter.h"
16 #include "CodeGenWrappers.h"
18 #include "Support/Debug.h"
19 #include "Support/StringExtras.h"
24 NodeType::ArgResultTypes NodeType::Translate(Record *R) {
25 const std::string &Name = R->getName();
26 if (Name == "DNVT_any") return Any;
27 if (Name == "DNVT_void") return Void;
28 if (Name == "DNVT_val" ) return Val;
29 if (Name == "DNVT_arg0") return Arg0;
30 if (Name == "DNVT_arg1") return Arg1;
31 if (Name == "DNVT_ptr" ) return Ptr;
32 if (Name == "DNVT_i8" ) return I8;
33 throw "Unknown DagNodeValType '" + Name + "'!";
37 //===----------------------------------------------------------------------===//
38 // TreePatternNode implementation
41 /// getValueRecord - Returns the value of this tree node as a record. For now
42 /// we only allow DefInit's as our leaf values, so this is used.
43 Record *TreePatternNode::getValueRecord() const {
44 DefInit *DI = dynamic_cast<DefInit*>(getValue());
45 assert(DI && "Instruction Selector does not yet support non-def leaves!");
50 // updateNodeType - Set the node type of N to VT if VT contains information. If
51 // N already contains a conflicting type, then throw an exception
53 bool TreePatternNode::updateNodeType(MVT::ValueType VT,
54 const std::string &RecName) {
55 if (VT == MVT::Other || getType() == VT) return false;
56 if (getType() == MVT::Other) {
61 throw "Type inference contradiction found for pattern " + RecName;
64 /// InstantiateNonterminals - If this pattern refers to any nonterminals which
65 /// are not themselves completely resolved, clone the nonterminal and resolve it
66 /// with the using context we provide.
68 void TreePatternNode::InstantiateNonterminals(InstrSelectorEmitter &ISE) {
70 for (unsigned i = 0, e = getNumChildren(); i != e; ++i)
71 getChild(i)->InstantiateNonterminals(ISE);
75 // If this is a leaf, it might be a reference to a nonterminal! Check now.
76 Record *R = getValueRecord();
77 if (R->isSubClassOf("Nonterminal")) {
78 Pattern *NT = ISE.getPattern(R);
79 if (!NT->isResolved()) {
80 // We found an unresolved nonterminal reference. Ask the ISE to clone
81 // it for us, then update our reference to the fresh, new, resolved,
84 Value = new DefInit(ISE.InstantiateNonterminal(NT, getType()));
90 /// clone - Make a copy of this tree and all of its children.
92 TreePatternNode *TreePatternNode::clone() const {
95 New = new TreePatternNode(Value);
97 std::vector<std::pair<TreePatternNode*, std::string> > CChildren;
98 CChildren.reserve(Children.size());
99 for (unsigned i = 0, e = getNumChildren(); i != e; ++i)
100 CChildren.push_back(std::make_pair(getChild(i)->clone(),getChildName(i)));
101 New = new TreePatternNode(Operator, CChildren);
107 std::ostream &operator<<(std::ostream &OS, const TreePatternNode &N) {
109 return OS << N.getType() << ":" << *N.getValue();
110 OS << "(" << N.getType() << ":";
111 OS << N.getOperator()->getName();
113 if (N.getNumChildren() != 0) {
114 OS << " " << *N.getChild(0);
115 for (unsigned i = 1, e = N.getNumChildren(); i != e; ++i)
116 OS << ", " << *N.getChild(i);
121 void TreePatternNode::dump() const { std::cerr << *this; }
123 //===----------------------------------------------------------------------===//
124 // Pattern implementation
127 // Parse the specified DagInit into a TreePattern which we can use.
129 Pattern::Pattern(PatternType pty, DagInit *RawPat, Record *TheRec,
130 InstrSelectorEmitter &ise)
131 : PTy(pty), ResultNode(0), TheRecord(TheRec), ISE(ise) {
133 // First, parse the pattern...
134 Tree = ParseTreePattern(RawPat);
136 // Run the type-inference engine...
139 if (PTy == Instruction || PTy == Expander) {
140 // Check to make sure there is not any unset types in the tree pattern...
142 std::cerr << "In pattern: " << *Tree << "\n";
143 error("Could not infer all types!");
146 // Check to see if we have a top-level (set) of a register.
147 if (Tree->getOperator()->getName() == "set") {
148 assert(Tree->getNumChildren() == 2 && "Set with != 2 arguments?");
149 if (!Tree->getChild(0)->isLeaf())
150 error("Arg #0 of set should be a register or register class!");
151 ResultNode = Tree->getChild(0);
152 ResultName = Tree->getChildName(0);
153 Tree = Tree->getChild(1);
157 calculateArgs(Tree, "");
160 void Pattern::error(const std::string &Msg) const {
161 std::string M = "In ";
163 case Nonterminal: M += "nonterminal "; break;
164 case Instruction: M += "instruction "; break;
165 case Expander : M += "expander "; break;
167 throw M + TheRecord->getName() + ": " + Msg;
170 /// calculateArgs - Compute the list of all of the arguments to this pattern,
171 /// which are the non-void leaf nodes in this pattern.
173 void Pattern::calculateArgs(TreePatternNode *N, const std::string &Name) {
174 if (N->isLeaf() || N->getNumChildren() == 0) {
175 if (N->getType() != MVT::isVoid)
176 Args.push_back(std::make_pair(N, Name));
178 for (unsigned i = 0, e = N->getNumChildren(); i != e; ++i)
179 calculateArgs(N->getChild(i), N->getChildName(i));
183 /// getIntrinsicType - Check to see if the specified record has an intrinsic
184 /// type which should be applied to it. This infer the type of register
185 /// references from the register file information, for example.
187 MVT::ValueType Pattern::getIntrinsicType(Record *R) const {
188 // Check to see if this is a register or a register class...
189 if (R->isSubClassOf("RegisterClass"))
190 return getValueType(R->getValueAsDef("RegType"));
191 else if (R->isSubClassOf("Nonterminal"))
192 return ISE.ReadNonterminal(R)->getTree()->getType();
193 else if (R->isSubClassOf("Register")) {
194 std::cerr << "WARNING: Explicit registers not handled yet!\n";
198 error("Unknown value used: " + R->getName());
202 TreePatternNode *Pattern::ParseTreePattern(DagInit *Dag) {
203 Record *Operator = Dag->getNodeType();
205 if (Operator->isSubClassOf("ValueType")) {
206 // If the operator is a ValueType, then this must be "type cast" of a leaf
208 if (Dag->getNumArgs() != 1)
209 error("Type cast only valid for a leaf node!");
211 Init *Arg = Dag->getArg(0);
212 TreePatternNode *New;
213 if (DefInit *DI = dynamic_cast<DefInit*>(Arg)) {
214 New = new TreePatternNode(DI);
215 // If it's a regclass or something else known, set the type.
216 New->setType(getIntrinsicType(DI->getDef()));
217 } else if (DagInit *DI = dynamic_cast<DagInit*>(Arg)) {
218 New = ParseTreePattern(DI);
221 error("Unknown leaf value for tree pattern!");
225 // Apply the type cast...
226 New->updateNodeType(getValueType(Operator), TheRecord->getName());
230 if (!ISE.getNodeTypes().count(Operator))
231 error("Unrecognized node '" + Operator->getName() + "'!");
233 std::vector<std::pair<TreePatternNode*, std::string> > Children;
235 for (unsigned i = 0, e = Dag->getNumArgs(); i != e; ++i) {
236 Init *Arg = Dag->getArg(i);
237 if (DagInit *DI = dynamic_cast<DagInit*>(Arg)) {
238 Children.push_back(std::make_pair(ParseTreePattern(DI),
239 Dag->getArgName(i)));
240 } else if (DefInit *DefI = dynamic_cast<DefInit*>(Arg)) {
241 Record *R = DefI->getDef();
242 // Direct reference to a leaf DagNode? Turn it into a DagNode if its own.
243 if (R->isSubClassOf("DagNode")) {
244 Dag->setArg(i, new DagInit(R,
245 std::vector<std::pair<Init*, std::string> >()));
246 --i; // Revisit this node...
248 Children.push_back(std::make_pair(new TreePatternNode(DefI),
249 Dag->getArgName(i)));
250 // If it's a regclass or something else known, set the type.
251 Children.back().first->setType(getIntrinsicType(R));
255 error("Unknown leaf value for tree pattern!");
259 return new TreePatternNode(Operator, Children);
262 void Pattern::InferAllTypes() {
263 bool MadeChange, AnyUnset;
266 AnyUnset = InferTypes(Tree, MadeChange);
267 } while ((AnyUnset || MadeChange) && !(AnyUnset && !MadeChange));
268 Resolved = !AnyUnset;
272 // InferTypes - Perform type inference on the tree, returning true if there
273 // are any remaining untyped nodes and setting MadeChange if any changes were
275 bool Pattern::InferTypes(TreePatternNode *N, bool &MadeChange) {
276 if (N->isLeaf()) return N->getType() == MVT::Other;
278 bool AnyUnset = false;
279 Record *Operator = N->getOperator();
280 const NodeType &NT = ISE.getNodeType(Operator);
282 // Check to see if we can infer anything about the argument types from the
284 if (N->getNumChildren() != NT.ArgTypes.size())
285 error("Incorrect number of children for " + Operator->getName() + " node!");
287 for (unsigned i = 0, e = N->getNumChildren(); i != e; ++i) {
288 TreePatternNode *Child = N->getChild(i);
289 AnyUnset |= InferTypes(Child, MadeChange);
291 switch (NT.ArgTypes[i]) {
292 case NodeType::Any: break;
294 MadeChange |= Child->updateNodeType(MVT::i1, TheRecord->getName());
297 MadeChange |= Child->updateNodeType(N->getChild(0)->getType(),
298 TheRecord->getName());
301 MadeChange |= Child->updateNodeType(N->getChild(1)->getType(),
302 TheRecord->getName());
305 if (Child->getType() == MVT::isVoid)
306 error("Inferred a void node in an illegal place!");
309 MadeChange |= Child->updateNodeType(ISE.getTarget().getPointerType(),
310 TheRecord->getName());
313 MadeChange |= Child->updateNodeType(MVT::isVoid, TheRecord->getName());
315 default: assert(0 && "Invalid argument ArgType!");
319 // See if we can infer anything about the return type now...
320 switch (NT.ResultType) {
321 case NodeType::Any: break;
323 MadeChange |= N->updateNodeType(MVT::isVoid, TheRecord->getName());
326 MadeChange |= N->updateNodeType(MVT::i1, TheRecord->getName());
329 MadeChange |= N->updateNodeType(N->getChild(0)->getType(),
330 TheRecord->getName());
333 MadeChange |= N->updateNodeType(N->getChild(1)->getType(),
334 TheRecord->getName());
337 MadeChange |= N->updateNodeType(ISE.getTarget().getPointerType(),
338 TheRecord->getName());
341 if (N->getType() == MVT::isVoid)
342 error("Inferred a void node in an illegal place!");
345 assert(0 && "Unhandled type constraint!");
349 return AnyUnset | N->getType() == MVT::Other;
352 /// clone - This method is used to make an exact copy of the current pattern,
353 /// then change the "TheRecord" instance variable to the specified record.
355 Pattern *Pattern::clone(Record *R) const {
356 assert(PTy == Nonterminal && "Can only clone nonterminals");
357 return new Pattern(Tree->clone(), R, Resolved, ISE);
362 std::ostream &operator<<(std::ostream &OS, const Pattern &P) {
363 switch (P.getPatternType()) {
364 case Pattern::Nonterminal: OS << "Nonterminal pattern "; break;
365 case Pattern::Instruction: OS << "Instruction pattern "; break;
366 case Pattern::Expander: OS << "Expander pattern "; break;
369 OS << P.getRecord()->getName() << ":\t";
371 if (Record *Result = P.getResult())
372 OS << Result->getName() << " = ";
376 OS << " [not completely resolved]";
380 void Pattern::dump() const { std::cerr << *this; }
384 /// getSlotName - If this is a leaf node, return the slot name that the operand
386 std::string Pattern::getSlotName() const {
387 if (getPatternType() == Pattern::Nonterminal) {
388 // Just use the nonterminal name, which will already include the type if
389 // it has been cloned.
390 return getRecord()->getName();
392 std::string SlotName;
394 SlotName = getResult()->getName()+"_";
397 return SlotName + getName(getTree()->getType());
401 /// getSlotName - If this is a leaf node, return the slot name that the
402 /// operand will update.
403 std::string Pattern::getSlotName(Record *R) {
404 if (R->isSubClassOf("Nonterminal")) {
405 // Just use the nonterminal name, which will already include the type if
406 // it has been cloned.
408 } else if (R->isSubClassOf("RegisterClass")) {
409 MVT::ValueType Ty = getValueType(R->getValueAsDef("RegType"));
410 return R->getName() + "_" + getName(Ty);
412 assert(0 && "Don't know how to get a slot name for this!");
417 //===----------------------------------------------------------------------===//
418 // PatternOrganizer implementation
421 /// addPattern - Add the specified pattern to the appropriate location in the
423 void PatternOrganizer::addPattern(Pattern *P) {
424 NodesForSlot &Nodes = AllPatterns[P->getSlotName()];
425 if (!P->getTree()->isLeaf())
426 Nodes[P->getTree()->getOperator()].push_back(P);
428 // Right now we only support DefInit's with node types...
429 Nodes[P->getTree()->getValueRecord()].push_back(P);
435 //===----------------------------------------------------------------------===//
436 // InstrSelectorEmitter implementation
439 /// ReadNodeTypes - Read in all of the node types in the current RecordKeeper,
440 /// turning them into the more accessible NodeTypes data structure.
442 void InstrSelectorEmitter::ReadNodeTypes() {
443 std::vector<Record*> Nodes = Records.getAllDerivedDefinitions("DagNode");
444 DEBUG(std::cerr << "Getting node types: ");
445 for (unsigned i = 0, e = Nodes.size(); i != e; ++i) {
446 Record *Node = Nodes[i];
448 // Translate the return type...
449 NodeType::ArgResultTypes RetTy =
450 NodeType::Translate(Node->getValueAsDef("RetType"));
452 // Translate the arguments...
453 ListInit *Args = Node->getValueAsListInit("ArgTypes");
454 std::vector<NodeType::ArgResultTypes> ArgTypes;
456 for (unsigned a = 0, e = Args->getSize(); a != e; ++a) {
457 if (DefInit *DI = dynamic_cast<DefInit*>(Args->getElement(a)))
458 ArgTypes.push_back(NodeType::Translate(DI->getDef()));
460 throw "In node " + Node->getName() + ", argument is not a Def!";
462 if (a == 0 && ArgTypes.back() == NodeType::Arg0)
463 throw "In node " + Node->getName() + ", arg 0 cannot have type 'arg0'!";
464 if (a == 1 && ArgTypes.back() == NodeType::Arg1)
465 throw "In node " + Node->getName() + ", arg 1 cannot have type 'arg1'!";
467 if ((RetTy == NodeType::Arg0 && Args->getSize() == 0) ||
468 (RetTy == NodeType::Arg1 && Args->getSize() < 2))
469 throw "In node " + Node->getName() +
470 ", invalid return type for node with this many operands!";
472 // Add the node type mapping now...
473 NodeTypes[Node] = NodeType(RetTy, ArgTypes);
474 DEBUG(std::cerr << Node->getName() << ", ");
476 DEBUG(std::cerr << "DONE!\n");
479 Pattern *InstrSelectorEmitter::ReadNonterminal(Record *R) {
480 Pattern *&P = Patterns[R];
481 if (P) return P; // Don't reread it!
483 DagInit *DI = R->getValueAsDag("Pattern");
484 P = new Pattern(Pattern::Nonterminal, DI, R, *this);
485 DEBUG(std::cerr << "Parsed " << *P << "\n");
490 // ReadNonTerminals - Read in all nonterminals and incorporate them into our
492 void InstrSelectorEmitter::ReadNonterminals() {
493 std::vector<Record*> NTs = Records.getAllDerivedDefinitions("Nonterminal");
494 for (unsigned i = 0, e = NTs.size(); i != e; ++i)
495 ReadNonterminal(NTs[i]);
499 /// ReadInstructionPatterns - Read in all subclasses of Instruction, and process
500 /// those with a useful Pattern field.
502 void InstrSelectorEmitter::ReadInstructionPatterns() {
503 std::vector<Record*> Insts = Records.getAllDerivedDefinitions("Instruction");
504 for (unsigned i = 0, e = Insts.size(); i != e; ++i) {
505 Record *Inst = Insts[i];
506 if (DagInit *DI = dynamic_cast<DagInit*>(Inst->getValueInit("Pattern"))) {
507 Patterns[Inst] = new Pattern(Pattern::Instruction, DI, Inst, *this);
508 DEBUG(std::cerr << "Parsed " << *Patterns[Inst] << "\n");
513 /// ReadExpanderPatterns - Read in all expander patterns...
515 void InstrSelectorEmitter::ReadExpanderPatterns() {
516 std::vector<Record*> Expanders = Records.getAllDerivedDefinitions("Expander");
517 for (unsigned i = 0, e = Expanders.size(); i != e; ++i) {
518 Record *Expander = Expanders[i];
519 DagInit *DI = Expander->getValueAsDag("Pattern");
520 Patterns[Expander] = new Pattern(Pattern::Expander, DI, Expander, *this);
521 DEBUG(std::cerr << "Parsed " << *Patterns[Expander] << "\n");
526 // InstantiateNonterminals - Instantiate any unresolved nonterminals with
527 // information from the context that they are used in.
529 void InstrSelectorEmitter::InstantiateNonterminals() {
530 DEBUG(std::cerr << "Instantiating nonterminals:\n");
531 for (std::map<Record*, Pattern*>::iterator I = Patterns.begin(),
532 E = Patterns.end(); I != E; ++I)
533 if (I->second->isResolved())
534 I->second->InstantiateNonterminals();
537 /// InstantiateNonterminal - This method takes the nonterminal specified by
538 /// NT, which should not be completely resolved, clones it, applies ResultTy
539 /// to its root, then runs the type inference stuff on it. This should
540 /// produce a newly resolved nonterminal, which we make a record for and
541 /// return. To be extra fancy and efficient, this only makes one clone for
542 /// each type it is instantiated with.
543 Record *InstrSelectorEmitter::InstantiateNonterminal(Pattern *NT,
544 MVT::ValueType ResultTy) {
545 assert(!NT->isResolved() && "Nonterminal is already resolved!");
547 // Check to see if we have already instantiated this pair...
548 Record* &Slot = InstantiatedNTs[std::make_pair(NT, ResultTy)];
549 if (Slot) return Slot;
551 Record *New = new Record(NT->getRecord()->getName()+"_"+getName(ResultTy));
553 // Copy over the superclasses...
554 const std::vector<Record*> &SCs = NT->getRecord()->getSuperClasses();
555 for (unsigned i = 0, e = SCs.size(); i != e; ++i)
556 New->addSuperClass(SCs[i]);
558 DEBUG(std::cerr << " Nonterminal '" << NT->getRecord()->getName()
559 << "' for type '" << getName(ResultTy) << "', producing '"
560 << New->getName() << "'\n");
562 // Copy the pattern...
563 Pattern *NewPat = NT->clone(New);
565 // Apply the type to the root...
566 NewPat->getTree()->updateNodeType(ResultTy, New->getName());
569 NewPat->InferAllTypes();
571 // Make sure everything is good to go now...
572 if (!NewPat->isResolved())
573 NewPat->error("Instantiating nonterminal did not resolve all types!");
575 // Add the pattern to the patterns map, add the record to the RecordKeeper,
576 // return the new record.
577 Patterns[New] = NewPat;
582 // CalculateComputableValues - Fill in the ComputableValues map through
583 // analysis of the patterns we are playing with.
584 void InstrSelectorEmitter::CalculateComputableValues() {
585 // Loop over all of the patterns, adding them to the ComputableValues map
586 for (std::map<Record*, Pattern*>::iterator I = Patterns.begin(),
587 E = Patterns.end(); I != E; ++I)
588 if (I->second->isResolved()) {
589 // We don't want to add patterns like R32 = R32. This is a hack working
590 // around a special case of a general problem, but for now we explicitly
591 // forbid these patterns. They can never match anyway.
592 Pattern *P = I->second;
593 if (!P->getResult() || !P->getTree()->isLeaf() ||
594 P->getResult() != P->getTree()->getValueRecord())
595 ComputableValues.addPattern(P);
600 // MoveIdenticalPatterns - Given a tree pattern 'P', move all of the tree
601 // patterns which have the same top-level structure as P from the 'From' list to
603 static void MoveIdenticalPatterns(TreePatternNode *P,
604 std::vector<std::pair<Pattern*, TreePatternNode*> > &From,
605 std::vector<std::pair<Pattern*, TreePatternNode*> > &To) {
606 assert(!P->isLeaf() && "All leaves are identical!");
608 const std::vector<TreePatternNode*> &PChildren = P->getChildren();
609 for (unsigned i = 0; i != From.size(); ++i) {
610 TreePatternNode *N = From[i].second;
611 assert(P->getOperator() == N->getOperator() &&"Differing operators?");
612 assert(PChildren.size() == N->getChildren().size() &&
613 "Nodes with different arity??");
614 bool isDifferent = false;
615 for (unsigned c = 0, e = PChildren.size(); c != e; ++c) {
616 TreePatternNode *PC = PChildren[c];
617 TreePatternNode *NC = N->getChild(c);
618 if (PC->isLeaf() != NC->isLeaf()) {
624 if (PC->getOperator() != NC->getOperator()) {
628 } else { // It's a leaf!
629 if (PC->getValueRecord() != NC->getValueRecord()) {
635 // If it's the same as the reference one, move it over now...
637 To.push_back(std::make_pair(From[i].first, N));
638 From.erase(From.begin()+i);
639 --i; // Don't skip an entry...
645 static std::string getNodeName(Record *R) {
646 RecordVal *RV = R->getValue("EnumName");
648 if (Init *I = RV->getValue())
649 if (StringInit *SI = dynamic_cast<StringInit*>(I))
650 return SI->getValue();
655 static void EmitPatternPredicates(TreePatternNode *Tree,
656 const std::string &VarName, std::ostream &OS){
657 OS << " && " << VarName << "->getNodeType() == ISD::"
658 << getNodeName(Tree->getOperator());
660 for (unsigned c = 0, e = Tree->getNumChildren(); c != e; ++c)
661 if (!Tree->getChild(c)->isLeaf())
662 EmitPatternPredicates(Tree->getChild(c),
663 VarName + "->getUse(" + utostr(c)+")", OS);
666 static void EmitPatternCosts(TreePatternNode *Tree, const std::string &VarName,
668 for (unsigned c = 0, e = Tree->getNumChildren(); c != e; ++c)
669 if (Tree->getChild(c)->isLeaf()) {
671 << Pattern::getSlotName(Tree->getChild(c)->getValueRecord()) << "("
672 << VarName << "->getUse(" << c << "))";
674 EmitPatternCosts(Tree->getChild(c),
675 VarName + "->getUse(" + utostr(c) + ")", OS);
680 // EmitMatchCosters - Given a list of patterns, which all have the same root
681 // pattern operator, emit an efficient decision tree to decide which one to
682 // pick. This is structured this way to avoid reevaluations of non-obvious
684 void InstrSelectorEmitter::EmitMatchCosters(std::ostream &OS,
685 const std::vector<std::pair<Pattern*, TreePatternNode*> > &Patterns,
686 const std::string &VarPrefix,
687 unsigned IndentAmt) {
688 assert(!Patterns.empty() && "No patterns to emit matchers for!");
689 std::string Indent(IndentAmt, ' ');
691 // Load all of the operands of the root node into scalars for fast access
692 const NodeType &ONT = getNodeType(Patterns[0].second->getOperator());
693 for (unsigned i = 0, e = ONT.ArgTypes.size(); i != e; ++i)
694 OS << Indent << "SelectionDAGNode *" << VarPrefix << "_Op" << i
695 << " = N->getUse(" << i << ");\n";
697 // Compute the costs of computing the various nonterminals/registers, which
698 // are directly used at this level.
699 OS << "\n" << Indent << "// Operand matching costs...\n";
700 std::set<std::string> ComputedValues; // Avoid duplicate computations...
701 for (unsigned i = 0, e = Patterns.size(); i != e; ++i) {
702 TreePatternNode *NParent = Patterns[i].second;
703 for (unsigned c = 0, e = NParent->getNumChildren(); c != e; ++c) {
704 TreePatternNode *N = NParent->getChild(c);
706 Record *VR = N->getValueRecord();
707 const std::string &LeafName = VR->getName();
708 std::string OpName = VarPrefix + "_Op" + utostr(c);
709 std::string ValName = OpName + "_" + LeafName + "_Cost";
710 if (!ComputedValues.count(ValName)) {
711 OS << Indent << "unsigned " << ValName << " = Match_"
712 << Pattern::getSlotName(VR) << "(" << OpName << ");\n";
713 ComputedValues.insert(ValName);
721 std::string LocCostName = VarPrefix + "_Cost";
722 OS << Indent << "unsigned " << LocCostName << "Min = ~0U >> 1;\n"
723 << Indent << "unsigned " << VarPrefix << "_PatternMin = NoMatchPattern;\n";
726 // Separate out all of the patterns into groups based on what their top-level
727 // signature looks like...
728 std::vector<std::pair<Pattern*, TreePatternNode*> > PatternsLeft(Patterns);
729 while (!PatternsLeft.empty()) {
730 // Process all of the patterns that have the same signature as the last
732 std::vector<std::pair<Pattern*, TreePatternNode*> > Group;
733 MoveIdenticalPatterns(PatternsLeft.back().second, PatternsLeft, Group);
734 assert(!Group.empty() && "Didn't at least pick the source pattern?");
737 OS << "PROCESSING GROUP:\n";
738 for (unsigned i = 0, e = Group.size(); i != e; ++i)
739 OS << " " << *Group[i].first << "\n";
743 OS << Indent << "{ // ";
745 if (Group.size() != 1) {
746 OS << Group.size() << " size group...\n";
747 OS << Indent << " unsigned " << VarPrefix << "_Pattern = NoMatch;\n";
749 OS << *Group[0].first << "\n";
750 OS << Indent << " unsigned " << VarPrefix << "_Pattern = "
751 << Group[0].first->getRecord()->getName() << "_Pattern;\n";
754 OS << Indent << " unsigned " << LocCostName << " = ";
755 if (Group.size() == 1)
756 OS << "1;\n"; // Add inst cost if at individual rec
760 // Loop over all of the operands, adding in their costs...
761 TreePatternNode *N = Group[0].second;
762 const std::vector<TreePatternNode*> &Children = N->getChildren();
764 // If necessary, emit conditionals to check for the appropriate tree
766 for (unsigned i = 0, e = Children.size(); i != e; ++i) {
767 TreePatternNode *C = Children[i];
769 // We already calculated the cost for this leaf, add it in now...
770 OS << Indent << " " << LocCostName << " += "
771 << VarPrefix << "_Op" << utostr(i) << "_"
772 << C->getValueRecord()->getName() << "_Cost;\n";
774 // If it's not a leaf, we have to check to make sure that the current
775 // node has the appropriate structure, then recurse into it...
776 OS << Indent << " if (" << VarPrefix << "_Op" << i
777 << "->getNodeType() == ISD::" << getNodeName(C->getOperator())
779 std::vector<std::pair<Pattern*, TreePatternNode*> > SubPatterns;
780 for (unsigned n = 0, e = Group.size(); n != e; ++n)
781 SubPatterns.push_back(std::make_pair(Group[n].first,
782 Group[n].second->getChild(i)));
783 EmitMatchCosters(OS, SubPatterns, VarPrefix+"_Op"+utostr(i),
785 OS << Indent << " }\n";
789 // If the cost for this match is less than the minimum computed cost so far,
790 // update the minimum cost and selected pattern.
791 OS << Indent << " if (" << LocCostName << " < " << LocCostName << "Min) { "
792 << LocCostName << "Min = " << LocCostName << "; " << VarPrefix
793 << "_PatternMin = " << VarPrefix << "_Pattern; }\n";
795 OS << Indent << "}\n";
799 for (unsigned i = 0, e = Patterns.size(); i != e; ++i) {
800 Pattern *P = Patterns[i].first;
801 TreePatternNode *PTree = P->getTree();
802 unsigned PatternCost = 1;
804 // Check to see if there are any non-leaf elements in the pattern. If so,
805 // we need to emit a predicate for this match.
806 bool AnyNonLeaf = false;
807 for (unsigned c = 0, e = PTree->getNumChildren(); c != e; ++c)
808 if (!PTree->getChild(c)->isLeaf()) {
813 if (!AnyNonLeaf) { // No predicate necessary, just output a scope...
814 OS << " {// " << *P << "\n";
816 // We need to emit a predicate to make sure the tree pattern matches, do
819 for (unsigned c = 0, e = PTree->getNumChildren(); c != e; ++c)
820 if (!PTree->getChild(c)->isLeaf())
821 EmitPatternPredicates(PTree->getChild(c),
822 VarPrefix + "_Op" + utostr(c), OS);
824 OS << ") {\n // " << *P << "\n";
827 OS << " unsigned PatCost = " << PatternCost;
829 for (unsigned c = 0, e = PTree->getNumChildren(); c != e; ++c)
830 if (PTree->getChild(c)->isLeaf()) {
831 OS << " + " << VarPrefix << "_Op" << c << "_"
832 << PTree->getChild(c)->getValueRecord()->getName() << "_Cost";
834 EmitPatternCosts(PTree->getChild(c), VarPrefix + "_Op" + utostr(c), OS);
837 OS << " if (PatCost < MinCost) { MinCost = PatCost; Pattern = "
838 << P->getRecord()->getName() << "_Pattern; }\n"
843 static void ReduceAllOperands(TreePatternNode *N, const std::string &Name,
844 std::vector<std::pair<TreePatternNode*, std::string> > &Operands,
847 // If this is a leaf, register or nonterminal reference...
848 std::string SlotName = Pattern::getSlotName(N->getValueRecord());
849 OS << " ReducedValue_" << SlotName << " *" << Name << "Val = Reduce_"
850 << SlotName << "(" << Name << ", MBB);\n";
851 Operands.push_back(std::make_pair(N, Name+"Val"));
852 } else if (N->getNumChildren() == 0) {
853 // This is a reference to a leaf tree node, like an immediate or frame
855 if (N->getType() != MVT::isVoid) {
856 std::string SlotName =
857 getNodeName(N->getOperator()) + "_" + getName(N->getType());
858 OS << " ReducedValue_" << SlotName << " *" << Name << "Val = "
859 << Name << "->getValue<ReducedValue_" << SlotName << ">(ISD::"
860 << SlotName << "_Slot);\n";
861 Operands.push_back(std::make_pair(N, Name+"Val"));
864 // Otherwise this is an interior node...
865 for (unsigned i = 0, e = N->getNumChildren(); i != e; ++i) {
866 std::string ChildName = Name + "_Op" + utostr(i);
867 OS << " SelectionDAGNode *" << ChildName << " = " << Name
868 << "->getUse(" << i << ");\n";
869 ReduceAllOperands(N->getChild(i), ChildName, Operands, OS);
874 /// PrintExpanderOperand - Print out Arg as part of the instruction emission
875 /// process for the expander pattern P. This argument may be referencing some
876 /// values defined in P, or may just be physical register references or
877 /// something like that. If PrintArg is true, we are printing out arguments to
878 /// the BuildMI call. If it is false, we are printing the result register
880 void InstrSelectorEmitter::PrintExpanderOperand(Init *Arg,
881 const std::string &NameVar,
882 TreePatternNode *ArgDeclNode,
883 Pattern *P, bool PrintArg,
885 if (DefInit *DI = dynamic_cast<DefInit*>(Arg)) {
886 Record *Arg = DI->getDef();
887 if (!ArgDeclNode->isLeaf() && ArgDeclNode->getNumChildren() != 0)
888 P->error("Expected leaf node as argument!");
889 Record *ArgDecl = ArgDeclNode->isLeaf() ? ArgDeclNode->getValueRecord() :
890 ArgDeclNode->getOperator();
891 if (Arg->isSubClassOf("Register")) {
892 // This is a physical register reference... make sure that the instruction
893 // requested a register!
894 if (!ArgDecl->isSubClassOf("RegisterClass"))
895 P->error("Argument mismatch for instruction pattern!");
897 // FIXME: This should check to see if the register is in the specified
899 if (PrintArg) OS << ".addReg(";
900 OS << getQualifiedName(Arg);
901 if (PrintArg) OS << ")";
903 } else if (Arg->isSubClassOf("RegisterClass")) {
904 // If this is a symbolic register class reference, we must be using a
906 if (NameVar.empty()) P->error("Did not specify WHICH register to pass!");
907 if (Arg != ArgDecl) P->error("Instruction pattern mismatch!");
909 if (PrintArg) OS << ".addReg(";
911 if (PrintArg) OS << ")";
913 } else if (Arg->getName() == "frameidx") {
914 if (!PrintArg) P->error("Cannot define a new frameidx value!");
915 OS << ".addFrameIndex(" << NameVar << ")";
917 } else if (Arg->getName() == "basicblock") {
918 if (!PrintArg) P->error("Cannot define a new basicblock value!");
919 OS << ".addMBB(" << NameVar << ")";
922 P->error("Unknown operand type '" + Arg->getName() + "' to expander!");
923 } else if (IntInit *II = dynamic_cast<IntInit*>(Arg)) {
924 if (!NameVar.empty())
925 P->error("Illegal to specify a name for a constant initializer arg!");
927 // Hack this check to allow R32 values with 0 as the initializer for memory
928 // references... FIXME!
929 if (ArgDeclNode->isLeaf() && II->getValue() == 0 &&
930 ArgDeclNode->getValueRecord()->getName() == "R32") {
933 if (ArgDeclNode->isLeaf() || ArgDeclNode->getOperator()->getName()!="imm")
934 P->error("Illegal immediate int value '" + itostr(II->getValue()) +
936 OS << ".addZImm(" << II->getValue() << ")";
940 P->error("Unknown operand type to expander!");
943 static std::string getArgName(Pattern *P, const std::string &ArgName,
944 const std::vector<std::pair<TreePatternNode*, std::string> > &Operands) {
945 assert(P->getNumArgs() == Operands.size() &&"Argument computation mismatch!");
946 if (ArgName.empty()) return "";
948 for (unsigned i = 0, e = P->getNumArgs(); i != e; ++i)
949 if (P->getArgName(i) == ArgName)
950 return Operands[i].second + "->Val";
952 if (ArgName == P->getResultName())
954 P->error("Pattern does not define a value named $" + ArgName + "!");
959 void InstrSelectorEmitter::run(std::ostream &OS) {
960 // Type-check all of the node types to ensure we "understand" them.
963 // Read in all of the nonterminals, instructions, and expanders...
965 ReadInstructionPatterns();
966 ReadExpanderPatterns();
968 // Instantiate any unresolved nonterminals with information from the context
969 // that they are used in.
970 InstantiateNonterminals();
972 // Clear InstantiatedNTs, we don't need it anymore...
973 InstantiatedNTs.clear();
975 DEBUG(std::cerr << "Patterns acquired:\n");
976 for (std::map<Record*, Pattern*>::iterator I = Patterns.begin(),
977 E = Patterns.end(); I != E; ++I)
978 if (I->second->isResolved())
979 DEBUG(std::cerr << " " << *I->second << "\n");
981 CalculateComputableValues();
983 OS << "#include \"llvm/CodeGen/MachineInstrBuilder.h\"\n";
985 EmitSourceFileHeader("Instruction Selector for the " + Target.getName() +
988 // Output the slot number enums...
989 OS << "\nenum { // Slot numbers...\n"
990 << " LastBuiltinSlot = ISD::NumBuiltinSlots-1, // Start numbering here\n";
991 for (PatternOrganizer::iterator I = ComputableValues.begin(),
992 E = ComputableValues.end(); I != E; ++I)
993 OS << " " << I->first << "_Slot,\n";
994 OS << " NumSlots\n};\n\n// Reduction value typedefs...\n";
996 // Output the reduction value typedefs...
997 for (PatternOrganizer::iterator I = ComputableValues.begin(),
998 E = ComputableValues.end(); I != E; ++I) {
1000 OS << "typedef ReducedValue<unsigned, " << I->first
1001 << "_Slot> ReducedValue_" << I->first << ";\n";
1004 // Output the pattern enums...
1006 << "enum { // Patterns...\n"
1007 << " NotComputed = 0,\n"
1008 << " NoMatchPattern, \n";
1009 for (PatternOrganizer::iterator I = ComputableValues.begin(),
1010 E = ComputableValues.end(); I != E; ++I) {
1011 OS << " // " << I->first << " patterns...\n";
1012 for (PatternOrganizer::NodesForSlot::iterator J = I->second.begin(),
1013 E = I->second.end(); J != E; ++J)
1014 for (unsigned i = 0, e = J->second.size(); i != e; ++i)
1015 OS << " " << J->second[i]->getRecord()->getName() << "_Pattern,\n";
1019 //===--------------------------------------------------------------------===//
1020 // Emit the class definition...
1022 OS << "namespace {\n"
1023 << " class " << Target.getName() << "ISel {\n"
1024 << " SelectionDAG &DAG;\n"
1026 << " " << Target.getName () << "ISel(SelectionDAG &D) : DAG(D) {}\n"
1027 << " void generateCode();\n"
1029 << " unsigned makeAnotherReg(const TargetRegisterClass *RC) {\n"
1030 << " return DAG.getMachineFunction().getSSARegMap()->createVirt"
1031 "ualRegister(RC);\n"
1033 << " // DAG matching methods for classes... all of these methods"
1034 " return the cost\n"
1035 << " // of producing a value of the specified class and type, which"
1037 << " // added to the DAG node.\n";
1039 // Output all of the matching prototypes for slots...
1040 for (PatternOrganizer::iterator I = ComputableValues.begin(),
1041 E = ComputableValues.end(); I != E; ++I)
1042 OS << " unsigned Match_" << I->first << "(SelectionDAGNode *N);\n";
1043 OS << "\n // DAG matching methods for DAG nodes...\n";
1045 // Output all of the matching prototypes for slot/node pairs
1046 for (PatternOrganizer::iterator I = ComputableValues.begin(),
1047 E = ComputableValues.end(); I != E; ++I)
1048 for (PatternOrganizer::NodesForSlot::iterator J = I->second.begin(),
1049 E = I->second.end(); J != E; ++J)
1050 OS << " unsigned Match_" << I->first << "_" << getNodeName(J->first)
1051 << "(SelectionDAGNode *N);\n";
1053 // Output all of the dag reduction methods prototypes...
1054 OS << "\n // DAG reduction methods...\n";
1055 for (PatternOrganizer::iterator I = ComputableValues.begin(),
1056 E = ComputableValues.end(); I != E; ++I)
1057 OS << " ReducedValue_" << I->first << " *Reduce_" << I->first
1058 << "(SelectionDAGNode *N,\n" << std::string(27+2*I->first.size(), ' ')
1059 << "MachineBasicBlock *MBB);\n";
1062 // Emit the generateCode entry-point...
1063 OS << "void " << Target.getName () << "ISel::generateCode() {\n"
1064 << " SelectionDAGNode *Root = DAG.getRoot();\n"
1065 << " assert(Root->getValueType() == MVT::isVoid && "
1066 "\"Root of DAG produces value??\");\n\n"
1067 << " std::cerr << \"\\n\";\n"
1068 << " unsigned Cost = Match_Void_void(Root);\n"
1069 << " if (Cost >= ~0U >> 1) {\n"
1070 << " std::cerr << \"Match failed!\\n\";\n"
1071 << " Root->dump();\n"
1074 << " std::cerr << \"Total DAG Cost: \" << Cost << \"\\n\\n\";\n\n"
1075 << " Reduce_Void_void(Root, 0);\n"
1077 << "//===" << std::string(70, '-') << "===//\n"
1078 << "// Matching methods...\n"
1081 //===--------------------------------------------------------------------===//
1082 // Emit all of the matcher methods...
1084 for (PatternOrganizer::iterator I = ComputableValues.begin(),
1085 E = ComputableValues.end(); I != E; ++I) {
1086 const std::string &SlotName = I->first;
1087 OS << "unsigned " << Target.getName() << "ISel::Match_" << SlotName
1088 << "(SelectionDAGNode *N) {\n"
1089 << " assert(N->getValueType() == MVT::"
1090 << getEnumName((*I->second.begin()).second[0]->getTree()->getType())
1091 << ");\n" << " // If we already have a cost available for " << SlotName
1093 << " if (N->getPatternFor(" << SlotName << "_Slot))\n"
1094 << " return N->getCostFor(" << SlotName << "_Slot);\n\n"
1095 << " unsigned Cost;\n"
1096 << " switch (N->getNodeType()) {\n"
1097 << " default: Cost = ~0U >> 1; // Match failed\n"
1098 << " N->setPatternCostFor(" << SlotName << "_Slot, NoMatchPattern, Cost, NumSlots);\n"
1101 for (PatternOrganizer::NodesForSlot::iterator J = I->second.begin(),
1102 E = I->second.end(); J != E; ++J)
1103 if (!J->first->isSubClassOf("Nonterminal"))
1104 OS << " case ISD::" << getNodeName(J->first) << ":\tCost = Match_"
1105 << SlotName << "_" << getNodeName(J->first) << "(N); break;\n";
1106 OS << " }\n"; // End of the switch statement
1108 // Emit any patterns which have a nonterminal leaf as the RHS. These may
1109 // match multiple root nodes, so they cannot be handled with the switch...
1110 for (PatternOrganizer::NodesForSlot::iterator J = I->second.begin(),
1111 E = I->second.end(); J != E; ++J)
1112 if (J->first->isSubClassOf("Nonterminal")) {
1113 OS << " unsigned " << J->first->getName() << "_Cost = Match_"
1114 << getNodeName(J->first) << "(N);\n"
1115 << " if (" << getNodeName(J->first) << "_Cost < Cost) Cost = "
1116 << getNodeName(J->first) << "_Cost;\n";
1119 OS << " return Cost;\n}\n\n";
1121 for (PatternOrganizer::NodesForSlot::iterator J = I->second.begin(),
1122 E = I->second.end(); J != E; ++J) {
1123 Record *Operator = J->first;
1124 bool isNonterm = Operator->isSubClassOf("Nonterminal");
1126 OS << "unsigned " << Target.getName() << "ISel::Match_";
1127 if (!isNonterm) OS << SlotName << "_";
1128 OS << getNodeName(Operator) << "(SelectionDAGNode *N) {\n"
1129 << " unsigned Pattern = NoMatchPattern;\n"
1130 << " unsigned MinCost = ~0U >> 1;\n";
1132 std::vector<std::pair<Pattern*, TreePatternNode*> > Patterns;
1133 for (unsigned i = 0, e = J->second.size(); i != e; ++i)
1134 Patterns.push_back(std::make_pair(J->second[i],
1135 J->second[i]->getTree()));
1136 EmitMatchCosters(OS, Patterns, "N", 2);
1138 OS << "\n N->setPatternCostFor(" << SlotName
1139 << "_Slot, Pattern, MinCost, NumSlots);\n"
1140 << " return MinCost;\n"
1146 //===--------------------------------------------------------------------===//
1147 // Emit all of the reducer methods...
1149 OS << "\n\n//===" << std::string(70, '-') << "===//\n"
1150 << "// Reducer methods...\n"
1153 for (PatternOrganizer::iterator I = ComputableValues.begin(),
1154 E = ComputableValues.end(); I != E; ++I) {
1155 const std::string &SlotName = I->first;
1156 OS << "ReducedValue_" << SlotName << " *" << Target.getName()
1157 << "ISel::Reduce_" << SlotName
1158 << "(SelectionDAGNode *N, MachineBasicBlock *MBB) {\n"
1159 << " ReducedValue_" << SlotName << " *Val = N->hasValue<ReducedValue_"
1160 << SlotName << ">(" << SlotName << "_Slot);\n"
1161 << " if (Val) return Val;\n"
1162 << " if (N->getBB()) MBB = N->getBB();\n\n"
1163 << " switch (N->getPatternFor(" << SlotName << "_Slot)) {\n";
1165 // Loop over all of the patterns that can produce a value for this slot...
1166 PatternOrganizer::NodesForSlot &NodesForSlot = I->second;
1167 for (PatternOrganizer::NodesForSlot::iterator J = NodesForSlot.begin(),
1168 E = NodesForSlot.end(); J != E; ++J)
1169 for (unsigned i = 0, e = J->second.size(); i != e; ++i) {
1170 Pattern *P = J->second[i];
1171 OS << " case " << P->getRecord()->getName() << "_Pattern: {\n"
1172 << " // " << *P << "\n";
1173 // Loop over the operands, reducing them...
1174 std::vector<std::pair<TreePatternNode*, std::string> > Operands;
1175 ReduceAllOperands(P->getTree(), "N", Operands, OS);
1177 // Now that we have reduced all of our operands, and have the values
1178 // that reduction produces, perform the reduction action for this
1182 // If the pattern produces a register result, generate a new register
1184 if (Record *R = P->getResult()) {
1185 assert(R->isSubClassOf("RegisterClass") &&
1186 "Only handle register class results so far!");
1187 OS << " unsigned NewReg = makeAnotherReg(" << Target.getName()
1188 << "::" << R->getName() << "RegisterClass);\n";
1190 DEBUG(OS << " std::cerr << \"%reg\" << NewReg << \" =\t\";\n");
1192 DEBUG(OS << " std::cerr << \"\t\t\";\n");
1196 // Print out the pattern that matched...
1197 DEBUG(OS << " std::cerr << \" " << P->getRecord()->getName() <<'"');
1198 DEBUG(for (unsigned i = 0, e = Operands.size(); i != e; ++i)
1199 if (Operands[i].first->isLeaf()) {
1200 Record *RV = Operands[i].first->getValueRecord();
1201 assert(RV->isSubClassOf("RegisterClass") &&
1202 "Only handles registers here so far!");
1203 OS << " << \" %reg\" << " << Operands[i].second
1206 OS << " << ' ' << " << Operands[i].second
1209 DEBUG(OS << " << \"\\n\";\n");
1211 // Generate the reduction code appropriate to the particular type of
1212 // pattern that this is...
1213 switch (P->getPatternType()) {
1214 case Pattern::Instruction:
1215 // Instruction patterns just emit a single MachineInstr, using BuildMI
1216 OS << " BuildMI(MBB, " << Target.getName() << "::"
1217 << P->getRecord()->getName() << ", " << Operands.size();
1218 if (P->getResult()) OS << ", NewReg";
1221 for (unsigned i = 0, e = Operands.size(); i != e; ++i) {
1222 TreePatternNode *Op = Operands[i].first;
1224 Record *RV = Op->getValueRecord();
1225 assert(RV->isSubClassOf("RegisterClass") &&
1226 "Only handles registers here so far!");
1227 OS << ".addReg(" << Operands[i].second << "->Val)";
1228 } else if (Op->getOperator()->getName() == "imm") {
1229 OS << ".addZImm(" << Operands[i].second << "->Val)";
1230 } else if (Op->getOperator()->getName() == "basicblock") {
1231 OS << ".addMBB(" << Operands[i].second << "->Val)";
1233 assert(0 && "Unknown value type!");
1238 case Pattern::Expander: {
1239 // Expander patterns emit one machine instr for each instruction in
1240 // the list of instructions expanded to.
1241 ListInit *Insts = P->getRecord()->getValueAsListInit("Result");
1242 for (unsigned IN = 0, e = Insts->getSize(); IN != e; ++IN) {
1243 DagInit *DIInst = dynamic_cast<DagInit*>(Insts->getElement(IN));
1244 if (!DIInst) P->error("Result list must contain instructions!");
1245 Record *InstRec = DIInst->getNodeType();
1246 Pattern *InstPat = getPattern(InstRec);
1247 if (!InstPat || InstPat->getPatternType() != Pattern::Instruction)
1248 P->error("Instruction list must contain Instruction patterns!");
1250 bool hasResult = InstPat->getResult() != 0;
1251 if (InstPat->getNumArgs() != DIInst->getNumArgs()-hasResult) {
1252 P->error("Incorrect number of arguments specified for inst '" +
1253 InstPat->getRecord()->getName() + "' in result list!");
1256 // Start emission of the instruction...
1257 OS << " BuildMI(MBB, " << Target.getName() << "::"
1258 << InstRec->getName() << ", "
1259 << DIInst->getNumArgs()-hasResult;
1260 // Emit register result if necessary..
1262 std::string ArgNameVal =
1263 getArgName(P, DIInst->getArgName(0), Operands);
1264 PrintExpanderOperand(DIInst->getArg(0), ArgNameVal,
1265 InstPat->getResultNode(), P, false,
1270 for (unsigned i = hasResult, e = DIInst->getNumArgs(); i != e; ++i){
1271 std::string ArgNameVal =
1272 getArgName(P, DIInst->getArgName(i), Operands);
1274 PrintExpanderOperand(DIInst->getArg(i), ArgNameVal,
1275 InstPat->getArg(i-hasResult), P, true, OS);
1283 assert(0 && "Reduction of this type of pattern not implemented!");
1286 OS << " Val = new ReducedValue_" << SlotName << "(" << Result<<");\n"
1292 OS << " default: assert(0 && \"Unknown " << SlotName << " pattern!\");\n"
1293 << " }\n\n N->addValue(Val); // Do not ever recalculate this\n"
1294 << " return Val;\n}\n\n";
1296 EmitSourceFileTail(OS);
1299 } // End llvm namespace