llvm.org GIT mirror llvm / e945f4d
Added support for variable_ops. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@28788 91177308-0d34-0410-b5e6-96231b3b80d8 Evan Cheng 13 years ago
1 changed file(s) with 85 addition(s) and 92 deletion(s). Raw diff Collapse all Expand all
24992499 if (InstPatNode && InstPatNode->getOperator()->getName() == "set") {
25002500 InstPatNode = InstPatNode->getChild(1);
25012501 }
2502 bool HasVarOps = isRoot && II.hasVariableNumberOfOperands;
25022503 bool HasImpInputs = isRoot && Inst.getNumImpOperands() > 0;
25032504 bool HasImpResults = isRoot && Inst.getNumImpResults() > 0;
25042505 bool NodeHasOptInFlag = isRoot &&
25142515
25152516 if (NodeHasInFlag || NodeHasOutFlag || NodeHasOptInFlag || HasImpInputs)
25162517 emitDecl("InFlag");
2517 if (NodeHasOptInFlag) {
2518 emitCode("bool HasOptInFlag = "
2518 if (NodeHasOptInFlag)
2519 emitCode("bool HasInFlag = "
25192520 "N.getOperand(N.getNumOperands()-1).getValueType() == MVT::Flag;");
2520 }
2521 if (HasVarOps)
2522 emitCode("std::vector Ops;");
25212523
25222524 // How many results is this pattern expected to produce?
25232525 unsigned PatResults = 0;
25802582 if (NodeHasInFlag || HasImpInputs)
25812583 EmitInFlagSelectCode(Pattern, "N", ChainEmitted, true);
25822584 if (NodeHasOptInFlag) {
2583 emitCode("if (HasOptInFlag)");
2585 emitCode("if (HasInFlag)");
25842586 emitCode(" Select(InFlag, N.getOperand(N.getNumOperands()-1));");
25852587 }
25862588
25952597 unsigned ResNo = TmpNo++;
25962598 if (!isRoot || InputHasChain || NodeHasChain || NodeHasOutFlag ||
25972599 NodeHasOptInFlag) {
2598 if (NodeHasOptInFlag) {
2599 unsigned FlagNo = (unsigned) NodeHasChain + Pattern->getNumChildren();
2600 emitDecl("ResNode", true);
2601 emitCode("if (HasOptInFlag)");
2602 std::string Code = " ResNode = CurDAG->getTargetNode(" +
2603 II.Namespace + "::" + II.TheDef->getName();
2604
2605 // Output order: results, chain, flags
2606 // Result types.
2607 if (PatResults > 0) {
2608 if (N->getTypeNum(0) != MVT::isVoid)
2609 Code += ", " + getEnumName(N->getTypeNum(0));
2610 }
2611 if (NodeHasChain)
2612 Code += ", MVT::Other";
2613 if (NodeHasOutFlag)
2614 Code += ", MVT::Flag";
2615
2616 // Inputs.
2617 for (unsigned i = 0, e = Ops.size(); i != e; ++i)
2600 std::string Code;
2601 std::string Code2;
2602 std::string NodeName;
2603 if (!isRoot) {
2604 NodeName = "Tmp" + utostr(ResNo);
2605 emitDecl(NodeName);
2606 Code2 = NodeName + " = SDOperand(";
2607 } else {
2608 NodeName = "ResNode";
2609 emitDecl(NodeName, true);
2610 Code2 = NodeName + " = ";
2611 }
2612 Code = "CurDAG->getTargetNode(" +
2613 II.Namespace + "::" + II.TheDef->getName();
2614
2615 // Output order: results, chain, flags
2616 // Result types.
2617 if (NumResults > 0 && N->getTypeNum(0) != MVT::isVoid)
2618 Code += ", " + getEnumName(N->getTypeNum(0));
2619 if (NodeHasChain)
2620 Code += ", MVT::Other";
2621 if (NodeHasOutFlag)
2622 Code += ", MVT::Flag";
2623
2624 // Inputs.
2625 for (unsigned i = 0, e = Ops.size(); i != e; ++i) {
2626 if (HasVarOps)
2627 emitCode("Ops.push_back(Tmp" + utostr(Ops[i]) + ");");
2628 else
26182629 Code += ", Tmp" + utostr(Ops[i]);
2619 if (NodeHasChain) Code += ", " + ChainName;
2620 emitCode(Code + ", InFlag);");
2621
2622 emitCode("else");
2623 Code = " ResNode = CurDAG->getTargetNode(" + II.Namespace + "::" +
2624 II.TheDef->getName();
2625
2626 // Output order: results, chain, flags
2627 // Result types.
2628 if (PatResults > 0 && N->getTypeNum(0) != MVT::isVoid)
2629 Code += ", " + getEnumName(N->getTypeNum(0));
2630 if (NodeHasChain)
2631 Code += ", MVT::Other";
2632 if (NodeHasOutFlag)
2633 Code += ", MVT::Flag";
2634
2635 // Inputs.
2636 for (unsigned i = 0, e = Ops.size(); i != e; ++i)
2637 Code += ", Tmp" + utostr(Ops[i]);
2638 if (NodeHasChain) Code += ", " + ChainName + ");";
2639 emitCode(Code);
2640
2641 if (NodeHasChain)
2642 // Remember which op produces the chain.
2643 emitCode(ChainName + " = SDOperand(ResNode" +
2630 }
2631
2632 if (HasVarOps) {
2633 if (NodeHasInFlag || HasImpInputs)
2634 emitCode("for (unsigned i = 2, e = N.getNumOperands()-1; "
2635 "i != e; ++i) {");
2636 else if (NodeHasOptInFlag)
2637 emitCode("for (unsigned i = 2, e = N.getNumOperands()-HasInFlag; "
2638 "i != e; ++i) {");
2639 else
2640 emitCode("for (unsigned i = 2, e = N.getNumOperands(); "
2641 "i != e; ++i) {");
2642 emitCode(" SDOperand VarOp(0, 0);");
2643 emitCode(" Select(VarOp, N.getOperand(i));");
2644 emitCode(" Ops.push_back(VarOp);");
2645 emitCode("}");
2646 }
2647
2648 if (NodeHasChain) {
2649 if (HasVarOps)
2650 emitCode("Ops.push_back(" + ChainName + ");");
2651 else
2652 Code += ", " + ChainName;
2653 }
2654 if (NodeHasInFlag || HasImpInputs) {
2655 if (HasVarOps)
2656 emitCode("Ops.push_back(InFlag);");
2657 else
2658 Code += ", InFlag";
2659 } else if (NodeHasOptInFlag && HasVarOps) {
2660 emitCode("if (HasInFlag)");
2661 emitCode(" Ops.push_back(InFlag);");
2662 }
2663
2664 if (HasVarOps)
2665 Code += ", Ops";
2666 else if (NodeHasOptInFlag)
2667 Code = "HasInFlag ? " + Code + ", InFlag) : " + Code;
2668
2669 if (!isRoot)
2670 Code += "), 0";
2671 emitCode(Code2 + Code + ");");
2672
2673 if (NodeHasChain)
2674 // Remember which op produces the chain.
2675 if (!isRoot)
2676 emitCode(ChainName + " = SDOperand(" + NodeName +
2677 ".Val, " + utostr(PatResults) + ");");
2678 else
2679 emitCode(ChainName + " = SDOperand(" + NodeName +
26442680 ", " + utostr(PatResults) + ");");
2645 } else {
2646 std::string Code;
2647 std::string NodeName;
2648 if (!isRoot) {
2649 NodeName = "Tmp" + utostr(ResNo);
2650 emitDecl(NodeName);
2651 Code = NodeName + " = SDOperand(";
2652 } else {
2653 NodeName = "ResNode";
2654 emitDecl(NodeName, true);
2655 Code = NodeName + " = ";
2656 }
2657 Code += "CurDAG->getTargetNode(" +
2658 II.Namespace + "::" + II.TheDef->getName();
2659
2660 // Output order: results, chain, flags
2661 // Result types.
2662 if (NumResults > 0 && N->getTypeNum(0) != MVT::isVoid)
2663 Code += ", " + getEnumName(N->getTypeNum(0));
2664 if (NodeHasChain)
2665 Code += ", MVT::Other";
2666 if (NodeHasOutFlag)
2667 Code += ", MVT::Flag";
2668
2669 // Inputs.
2670 for (unsigned i = 0, e = Ops.size(); i != e; ++i)
2671 Code += ", Tmp" + utostr(Ops[i]);
2672 if (NodeHasChain) Code += ", " + ChainName;
2673 if (NodeHasInFlag || HasImpInputs) Code += ", InFlag";
2674 if (!isRoot)
2675 emitCode(Code + "), 0);");
2676 else
2677 emitCode(Code + ");");
2678
2679 if (NodeHasChain)
2680 // Remember which op produces the chain.
2681 if (!isRoot)
2682 emitCode(ChainName + " = SDOperand(" + NodeName +
2683 ".Val, " + utostr(PatResults) + ");");
2684 else
2685 emitCode(ChainName + " = SDOperand(" + NodeName +
2686 ", " + utostr(PatResults) + ");");
2687 }
26882681
26892682 if (!isRoot)
26902683 return std::make_pair(1, ResNo);