From 1ed1dd6d9548ba18ef0e73dfbb9714000c74c1ab Mon Sep 17 00:00:00 2001 From: Jessica Paquette Date: Sat, 9 Feb 2019 00:29:13 +0000 Subject: [GlobalISel] Skip patterns that define complex suboperands twice instead of dying If we run into a pattern that looks like this: add (complex $x, $y) (complex $x, $z) We should skip the pattern instead of asserting/doing something unpredictable. This makes us return an Error in that case, and adds a testcase for skipped patterns. Differential Revision: https://reviews.llvm.org/D57980 llvm-svn: 353586 --- llvm/utils/TableGen/GlobalISelEmitter.cpp | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'llvm/utils/TableGen/GlobalISelEmitter.cpp') diff --git a/llvm/utils/TableGen/GlobalISelEmitter.cpp b/llvm/utils/TableGen/GlobalISelEmitter.cpp index 2e52c8e6fc9..8079e2989b6 100644 --- a/llvm/utils/TableGen/GlobalISelEmitter.cpp +++ b/llvm/utils/TableGen/GlobalISelEmitter.cpp @@ -881,12 +881,19 @@ public: void defineOperand(StringRef SymbolicName, OperandMatcher &OM); - void defineComplexSubOperand(StringRef SymbolicName, Record *ComplexPattern, - unsigned RendererID, unsigned SubOperandID) { - assert(ComplexSubOperands.count(SymbolicName) == 0 && "Already defined"); + Error defineComplexSubOperand(StringRef SymbolicName, Record *ComplexPattern, + unsigned RendererID, unsigned SubOperandID) { + if (ComplexSubOperands.count(SymbolicName)) + return failedImport( + "Complex suboperand referenced more than once (Operand: " + + SymbolicName + ")"); + ComplexSubOperands[SymbolicName] = std::make_tuple(ComplexPattern, RendererID, SubOperandID); + + return Error::success(); } + Optional getComplexSubOperand(StringRef SymbolicName) const { const auto &I = ComplexSubOperands.find(SymbolicName); @@ -3421,9 +3428,12 @@ Error GlobalISelEmitter::importChildMatcher(RuleMatcher &Rule, for (unsigned i = 0, e = SrcChild->getNumChildren(); i != e; ++i) { auto *SubOperand = SrcChild->getChild(i); - if (!SubOperand->getName().empty()) - Rule.defineComplexSubOperand(SubOperand->getName(), - SrcChild->getOperator(), RendererID, i); + if (!SubOperand->getName().empty()) { + if (auto Error = Rule.defineComplexSubOperand(SubOperand->getName(), + SrcChild->getOperator(), + RendererID, i)) + return Error; + } } return Error::success(); -- cgit v1.2.3