llvm.org GIT mirror llvm / 67a202b
now that we have control over emission of the code, emit the code using nested "if" statements (indenting it appropriately, of course) instead of using goto's. This inverts the logic for all of the if statements, which makes things simpler to understand in addition to making the generated code easier to read. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25757 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 13 years ago
1 changed file(s) with 29 addition(s) and 28 deletion(s). Raw diff Collapse all Expand all
18791879 assert(0 && "Unknown predicate type!");
18801880 }
18811881 if (!PredicateCheck.empty())
1882 PredicateCheck += " && ";
1883 PredicateCheck += "!(" + Def->getValueAsString("CondString") + ")";
1882 PredicateCheck += " || ";
1883 PredicateCheck += "(" + Def->getValueAsString("CondString") + ")";
18841884 }
18851885 }
18861886
18901890 if (N->isLeaf()) {
18911891 if (IntInit *II = dynamic_cast(N->getLeafValue())) {
18921892 emitCheck("cast(" + RootName +
1893 ")->getSignExtended() != " + itostr(II->getValue()));
1893 ")->getSignExtended() == " + itostr(II->getValue()));
18941894 return;
18951895 } else if (!NodeIsComplexPattern(N)) {
18961896 assert(0 && "Cannot match this as a leaf value!");
19091909 // we already have checked that the first reference is valid, we don't
19101910 // have to recursively match it, just check that it's the same as the
19111911 // previously named thing.
1912 emitCheck(VarMapEntry + " != " + RootName);
1912 emitCheck(VarMapEntry + " == " + RootName);
19131913 return;
19141914 }
19151915
19301930 if (!isRoot) {
19311931 const SDNodeInfo &CInfo = ISE.getSDNodeInfo(N->getOperator());
19321932 // Multiple uses of actual result?
1933 emitCheck("!" + RootName + ".hasOneUse()");
1933 emitCheck(RootName + ".hasOneUse()");
19341934 EmittedUseCheck = true;
19351935 // hasOneUse() check is not strong enough. If the original node has
19361936 // already been selected, it may have been replaced with another.
19371937 for (unsigned j = 0; j != CInfo.getNumResults(); j++)
1938 emitCheck("CodeGenMap.count(" + RootName + ".getValue(" + utostr(j) +
1938 emitCheck("!CodeGenMap.count(" + RootName + ".getValue(" + utostr(j) +
19391939 "))");
19401940
19411941 EmittedSlctedCheck = true;
19421942 if (NodeHasChain)
1943 emitCheck("CodeGenMap.count(" + RootName + ".getValue(" +
1943 emitCheck("!CodeGenMap.count(" + RootName + ".getValue(" +
19441944 utostr(CInfo.getNumResults()) + "))");
19451945 }
19461946 if (NodeHasChain) {
19481948 emitCode("SDOperand Chain = " + RootName + ".getOperand(0);");
19491949 FoundChain = true;
19501950 } else {
1951 emitCheck("Chain.Val != " + RootName + ".Val");
1951 emitCheck("Chain.Val == " + RootName + ".Val");
19521952 emitCode("Chain = " + RootName + ".getOperand(0);");
19531953 }
19541954 }
19651965 const SDNodeInfo &CInfo = ISE.getSDNodeInfo(N->getOperator());
19661966 if (!EmittedUseCheck) {
19671967 // Multiple uses of actual result?
1968 emitCheck("!" + RootName + ".hasOneUse()");
1968 emitCheck(RootName + ".hasOneUse()");
19691969 }
19701970 if (!EmittedSlctedCheck)
19711971 // hasOneUse() check is not strong enough. If the original node has
19721972 // already been selected, it may have been replaced with another.
19731973 for (unsigned j = 0; j < CInfo.getNumResults(); j++)
1974 emitCheck("CodeGenMap.count(" + RootName + ".getValue(" + utostr(j) +
1974 emitCheck("!CodeGenMap.count(" + RootName + ".getValue(" + utostr(j) +
19751975 "))");
19761976 }
19771977
19831983 if (!Child->isLeaf()) {
19841984 // If it's not a leaf, recursively match.
19851985 const SDNodeInfo &CInfo = ISE.getSDNodeInfo(Child->getOperator());
1986 emitCheck(RootName + utostr(OpNo) + ".getOpcode() != " +
1986 emitCheck(RootName + utostr(OpNo) + ".getOpcode() == " +
19871987 CInfo.getEnumName());
19881988 EmitMatchCode(Child, RootName + utostr(OpNo), FoundChain);
19891989 if (NodeHasProperty(Child, SDNodeInfo::SDNPHasChain, ISE))
20012001 // Since we already have checked that the first reference is valid,
20022002 // we don't have to recursively match it, just check that it's the
20032003 // same as the previously named thing.
2004 emitCheck(VarMapEntry + " != " + RootName + utostr(OpNo));
2004 emitCheck(VarMapEntry + " == " + RootName + utostr(OpNo));
20052005 Duplicates.insert(RootName + utostr(OpNo));
20062006 continue;
20072007 }
20212021 } else if (LeafRec->isSubClassOf("ValueType")) {
20222022 // Make sure this is the specified value type.
20232023 emitCheck("cast(" + RootName + utostr(OpNo) +
2024 ")->getVT() != MVT::" + LeafRec->getName());
2024 ")->getVT() == MVT::" + LeafRec->getName());
20252025 } else if (LeafRec->isSubClassOf("CondCode")) {
20262026 // Make sure this is the specified cond code.
20272027 emitCheck("cast(" + RootName + utostr(OpNo) +
2028 ")->get() != ISD::" + LeafRec->getName());
2028 ")->get() == ISD::" + LeafRec->getName());
20292029 } else {
20302030 Child->dump();
20312031 std::cerr << " ";
20332033 }
20342034 } else if (IntInit *II =
20352035 dynamic_cast(Child->getLeafValue())) {
2036 emitCheck("!isa(" + RootName + utostr(OpNo) +
2037 ") || cast(" + RootName + utostr(OpNo) +
2038 ")->getSignExtended() != " + itostr(II->getValue()));
2036 emitCheck("isa(" + RootName + utostr(OpNo) +
2037 ") && cast(" + RootName + utostr(OpNo) +
2038 ")->getSignExtended() == " + itostr(II->getValue()));
20392039 } else {
20402040 Child->dump();
20412041 assert(0 && "Unknown leaf type!");
20452045
20462046 // If there is a node predicate for this, emit the call.
20472047 if (!N->getPredicateFn().empty())
2048 emitCheck("!" + N->getPredicateFn() + "(" + RootName + ".Val)");
2048 emitCheck(N->getPredicateFn() + "(" + RootName + ".Val)");
20492049 }
20502050
20512051 /// EmitResultCode - Emit the action for a pattern. Now that it has matched
21162116 Code += "Tmp" + utostr(i+ResNo) + ", ";
21172117 emitCode(Code + "Tmp" + utostr(NumRes - 1 + ResNo) + ";");
21182118
2119 Code = "!" + Fn + "(" + Val;
2119 Code = Fn + "(" + Val;
21202120 for (unsigned i = 0; i < NumRes; i++)
21212121 Code += ", Tmp" + utostr(i + ResNo);
21222122 emitCheck(Code + ")");
24162416 if (!Pat->hasTypeSet()) {
24172417 // Move a type over from 'other' to 'pat'.
24182418 Pat->setTypes(Other->getExtTypes());
2419 emitCheck(Prefix + ".Val->getValueType(0) != MVT::" +
2419 emitCheck(Prefix + ".Val->getValueType(0) == MVT::" +
24202420 getName(Pat->getTypeNum(0)));
24212421 return true;
24222422 }
26002600
26012601 // Actually output the generated code now.
26022602 bool CanFail = false;
2603 unsigned Indent = 4;
26032604 for (unsigned i = 0, e = GeneratedCode.size(); i != e; ++i) {
26042605 if (!GeneratedCode[i].first) {
26052606 // Normal code.
2606 OS << " " << GeneratedCode[i].second << "\n";
2607 OS << std::string(Indent, ' ') << GeneratedCode[i].second << "\n";
26072608 } else {
2608 OS << " if (" << GeneratedCode[i].second << ") goto P"
2609 << PatternNo << "Fail;\n";
26102609 CanFail = true;
2611 }
2612 }
2610 OS << std::string(Indent, ' ')
2611 << "if (" << GeneratedCode[i].second << ") {\n";
2612 Indent += 2;
2613 }
2614 }
2615 for (; Indent != 4; Indent -= 2)
2616 OS << std::string(Indent-2, ' ') << "}\n";
26132617
26142618 OS << " }\n";
2615 if (CanFail)
2616 OS << "P" << PatternNo << "Fail:\n";
2617
26182619 return CanFail;
26192620 }
26202621