diff options
author | Jessica Paquette <jpaquette@apple.com> | 2019-02-09 00:29:13 +0000 |
---|---|---|
committer | Jessica Paquette <jpaquette@apple.com> | 2019-02-09 00:29:13 +0000 |
commit | 1ed1dd6d9548ba18ef0e73dfbb9714000c74c1ab (patch) | |
tree | e09ca6c47c83a4526487cecff169e963fc88faa4 /llvm/utils/TableGen/GlobalISelEmitter.cpp | |
parent | 760fee27fe1a95640477e7da98d03fbd80319b84 (diff) | |
download | bcm5719-llvm-1ed1dd6d9548ba18ef0e73dfbb9714000c74c1ab.tar.gz bcm5719-llvm-1ed1dd6d9548ba18ef0e73dfbb9714000c74c1ab.zip |
[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
Diffstat (limited to 'llvm/utils/TableGen/GlobalISelEmitter.cpp')
-rw-r--r-- | llvm/utils/TableGen/GlobalISelEmitter.cpp | 22 |
1 files changed, 16 insertions, 6 deletions
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<DefinedComplexPatternSubOperand> 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(); |