Reject patterns that use a name multiple times in the src or result

of a pattern and where the uses have different types.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@96904 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2010-02-23 07:22:28 +00:00
parent c6c161265e
commit a27234e290

View File

@ -2091,20 +2091,21 @@ void CodeGenDAGPatterns::ParseInstructions() {
typedef std::pair<const TreePatternNode*, unsigned> NameRecord; typedef std::pair<const TreePatternNode*, unsigned> NameRecord;
static void FindNames(const TreePatternNode *P, static void FindNames(const TreePatternNode *P,
std::map<std::string, NameRecord> &Names) { std::map<std::string, NameRecord> &Names,
const TreePattern *PatternTop) {
if (!P->getName().empty()) { if (!P->getName().empty()) {
NameRecord &Rec = Names[P->getName()]; NameRecord &Rec = Names[P->getName()];
// If this is the first instance of the name, remember the node. // If this is the first instance of the name, remember the node.
if (Rec.second++ == 0) if (Rec.second++ == 0)
Rec.first = P; Rec.first = P;
// else else if (Rec.first->getExtTypes() != P->getExtTypes())
// assert(Rec.first->getExtTypes() == P->getExtTypes() && PatternTop->error("repetition of value: $" + P->getName() +
// "Type mismatch on name repetition"); " where different uses have different types!");
} }
if (!P->isLeaf()) { if (!P->isLeaf()) {
for (unsigned i = 0, e = P->getNumChildren(); i != e; ++i) for (unsigned i = 0, e = P->getNumChildren(); i != e; ++i)
FindNames(P->getChild(i), Names); FindNames(P->getChild(i), Names, PatternTop);
} }
} }
@ -2118,8 +2119,8 @@ void CodeGenDAGPatterns::AddPatternToMatch(const TreePattern *Pattern,
// Find all of the named values in the input and output, ensure they have the // Find all of the named values in the input and output, ensure they have the
// same type. // same type.
std::map<std::string, NameRecord> SrcNames, DstNames; std::map<std::string, NameRecord> SrcNames, DstNames;
FindNames(PTM.getSrcPattern(), SrcNames); FindNames(PTM.getSrcPattern(), SrcNames, Pattern);
FindNames(PTM.getDstPattern(), DstNames); FindNames(PTM.getDstPattern(), DstNames, Pattern);
// Scan all of the named values in the destination pattern, rejecting them if // Scan all of the named values in the destination pattern, rejecting them if
// they don't exist in the input pattern. // they don't exist in the input pattern.