summaryrefslogtreecommitdiff
path: root/utils/TableGen/DAGISelEmitter.cpp
diff options
context:
space:
mode:
authorEvan Cheng <evan.cheng@apple.com>2006-02-03 06:22:41 +0000
committerEvan Cheng <evan.cheng@apple.com>2006-02-03 06:22:41 +0000
commite4a8a6e645b82e8fb5863ae78717cf99cd295f89 (patch)
treeabe026c3760f8db4961ee7e7b12380a891d0d160 /utils/TableGen/DAGISelEmitter.cpp
parent33c1dab0bdb2f1a1a75405aa82b9dd9d01d76cd1 (diff)
downloadllvm-e4a8a6e645b82e8fb5863ae78717cf99cd295f89.tar.gz
llvm-e4a8a6e645b82e8fb5863ae78717cf99cd295f89.tar.bz2
llvm-e4a8a6e645b82e8fb5863ae78717cf99cd295f89.tar.xz
(store (op (load ...))) folding problem. In the generated matching code,
Chain is initially set to the chain operand of store node, when it reaches load, if it matches the load then Chain is set to the chain operand of the load. However, if the matching code that follows this fails, isel moves on to the next pattern but it does not restore Chain to the chain operand of the store. So when it tries to match the next store / op / load pattern it would fail on the Chain == load.getOperand(0) test. The solution is for each chain operand to get a unique name. e.g. Chain10. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25931 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'utils/TableGen/DAGISelEmitter.cpp')
-rw-r--r--utils/TableGen/DAGISelEmitter.cpp53
1 files changed, 30 insertions, 23 deletions
diff --git a/utils/TableGen/DAGISelEmitter.cpp b/utils/TableGen/DAGISelEmitter.cpp
index f0ecd66fb2..b9a398f6b4 100644
--- a/utils/TableGen/DAGISelEmitter.cpp
+++ b/utils/TableGen/DAGISelEmitter.cpp
@@ -1848,6 +1848,7 @@ private:
/// [when false].
std::vector<std::pair<bool, std::string> > &GeneratedCode;
+ std::string ChainName;
unsigned TmpNo;
void emitCheck(const std::string &S) {
@@ -1869,7 +1870,8 @@ public:
/// if the match fails. At this point, we already know that the opcode for N
/// matches, and the SDNode for the result has the RootName specified name.
void EmitMatchCode(TreePatternNode *N, const std::string &RootName,
- bool &FoundChain, bool isRoot = false) {
+ const std::string &ChainSuffix, bool &FoundChain,
+ bool isRoot = false) {
// Emit instruction predicates. Each predicate is just a string for now.
if (isRoot) {
@@ -1947,13 +1949,13 @@ public:
utostr(CInfo.getNumResults()) + "))");
}
if (NodeHasChain) {
- if (!FoundChain) {
- emitCode("SDOperand Chain = " + RootName + ".getOperand(0);");
- FoundChain = true;
- } else {
+ if (FoundChain)
emitCheck("Chain.Val == " + RootName + ".Val");
- emitCode("Chain = " + RootName + ".getOperand(0);");
- }
+ else
+ FoundChain = true;
+ ChainName = "Chain" + ChainSuffix;
+ emitCode("SDOperand " + ChainName + " = " + RootName +
+ ".getOperand(0);");
}
}
@@ -1988,7 +1990,8 @@ public:
const SDNodeInfo &CInfo = ISE.getSDNodeInfo(Child->getOperator());
emitCheck(RootName + utostr(OpNo) + ".getOpcode() == " +
CInfo.getEnumName());
- EmitMatchCode(Child, RootName + utostr(OpNo), FoundChain);
+ EmitMatchCode(Child, RootName + utostr(OpNo), ChainSuffix + utostr(OpNo),
+ FoundChain);
if (NodeHasProperty(Child, SDNodeInfo::SDNPHasChain, ISE))
FoldedChains.push_back(std::make_pair(RootName + utostr(OpNo),
CInfo.getNumResults()));
@@ -2225,7 +2228,7 @@ public:
// Emit all the chain and CopyToReg stuff.
bool ChainEmitted = HasChain;
if (HasChain)
- emitCode("Chain = Select(Chain);");
+ emitCode(ChainName + " = Select(" + ChainName + ");");
if (HasInFlag || HasOptInFlag || HasImpInputs)
EmitInFlagSelectCode(Pattern, "N", ChainEmitted, true);
@@ -2248,7 +2251,7 @@ public:
emitCode(Code + ");");
if (HasChain) {
// Must have at least one result
- emitCode("Chain = Tmp" + utostr(LastOp) + ".getValue(" +
+ emitCode(ChainName + " = Tmp" + utostr(LastOp) + ".getValue(" +
utostr(NumResults) + ");");
}
} else if (HasChain || NodeHasOutFlag) {
@@ -2273,7 +2276,7 @@ public:
// Inputs.
for (unsigned i = 0, e = Ops.size(); i != e; ++i)
Code += ", Tmp" + utostr(Ops[i]);
- if (HasChain) Code += ", Chain";
+ if (HasChain) Code += ", " + ChainName;
emitCode(Code + ", InFlag);");
emitCode("else");
@@ -2292,7 +2295,7 @@ public:
// Inputs.
for (unsigned i = 0, e = Ops.size(); i != e; ++i)
Code += ", Tmp" + utostr(Ops[i]);
- if (HasChain) Code += ", Chain);";
+ if (HasChain) Code += ", " + ChainName + ");";
emitCode(Code);
} else {
std::string Code = "SDOperand Result = CurDAG->getTargetNode(" +
@@ -2310,7 +2313,7 @@ public:
// Inputs.
for (unsigned i = 0, e = Ops.size(); i != e; ++i)
Code += ", Tmp" + utostr(Ops[i]);
- if (HasChain) Code += ", Chain";
+ if (HasChain) Code += ", " + ChainName;
if (HasInFlag || HasImpInputs) Code += ", InFlag";
emitCode(Code + ");");
}
@@ -2323,7 +2326,7 @@ public:
}
if (HasChain)
- emitCode("Chain = Result.getValue(" + utostr(ValNo) + ");");
+ emitCode(ChainName + " = Result.getValue(" + utostr(ValNo) + ");");
if (NodeHasOutFlag)
emitCode("InFlag = Result.getValue(" +
@@ -2338,14 +2341,15 @@ public:
// User does not expect that the instruction produces a chain!
bool AddedChain = HasChain && !NodeHasChain;
if (NodeHasChain)
- emitCode("CodeGenMap[N.getValue(" + utostr(ValNo++) + ")] = Chain;");
+ emitCode("CodeGenMap[N.getValue(" + utostr(ValNo++) + ")] = " +
+ ChainName + ";");
if (FoldedChains.size() > 0) {
std::string Code;
for (unsigned j = 0, e = FoldedChains.size(); j < e; j++)
Code += "CodeGenMap[" + FoldedChains[j].first + ".getValue(" +
utostr(FoldedChains[j].second) + ")] = ";
- emitCode(Code + "Chain;");
+ emitCode(Code + ChainName + ";");
}
if (NodeHasOutFlag)
@@ -2467,14 +2471,16 @@ private:
} else {
if (!ChainEmitted) {
emitCode("SDOperand Chain = CurDAG->getEntryNode();");
+ ChainName = "Chain";
ChainEmitted = true;
}
emitCode("SDOperand " + RootName + "CR" + utostr(i) + ";");
emitCode(RootName + "CR" + utostr(i) +
- " = CurDAG->getCopyToReg(Chain, CurDAG->getRegister(" +
- ISE.getQualifiedName(RR) + ", MVT::" + getEnumName(RVT) +
- "), Select(" + RootName + utostr(OpNo) + "), InFlag);");
- emitCode("Chain = " + RootName + "CR" + utostr(i) +
+ " = CurDAG->getCopyToReg(" + ChainName +
+ ", CurDAG->getRegister(" + ISE.getQualifiedName(RR) +
+ ", MVT::" + getEnumName(RVT) + "), Select(" + RootName +
+ utostr(OpNo) + "), InFlag);");
+ emitCode(ChainName + " = " + RootName + "CR" + utostr(i) +
".getValue(0);");
emitCode("InFlag = " + RootName + "CR" + utostr(i) +
".getValue(1);");
@@ -2519,11 +2525,12 @@ private:
if (!ChainEmitted) {
emitCode("SDOperand Chain = CurDAG->getEntryNode();");
ChainEmitted = true;
+ ChainName = "Chain";
}
- emitCode("Result = CurDAG->getCopyFromReg(Chain, " +
+ emitCode("Result = CurDAG->getCopyFromReg(" + ChainName + ", " +
ISE.getQualifiedName(RR) + ", MVT::" + getEnumName(RVT) +
", InFlag);");
- emitCode("Chain = Result.getValue(1);");
+ emitCode(ChainName + " = Result.getValue(1);");
emitCode("InFlag = Result.getValue(2);");
RetVal = true;
}
@@ -2545,7 +2552,7 @@ void DAGISelEmitter::GenerateCodeForPattern(PatternToMatch &Pattern,
// Emit the matcher, capturing named arguments in VariableMap.
bool FoundChain = false;
- Emitter.EmitMatchCode(Pattern.getSrcPattern(), "N", FoundChain,
+ Emitter.EmitMatchCode(Pattern.getSrcPattern(), "N", "", FoundChain,
true /*the root*/);
// TP - Get *SOME* tree pattern, we don't care which.