diff --git a/llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp b/llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp index 31bf9a98943e5..193d29717d2c9 100644 --- a/llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp +++ b/llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp @@ -3007,13 +3007,12 @@ TreePatternNodePtr TreePattern::ParseTreePattern(const Init *TheInit, // and "(MY_PAT $b, $a)" should not be allowed in the same pattern; // neither should "(MY_PAT_1 $a, $b)" and "(MY_PAT_2 $a, $b)". auto OperandId = std::make_pair(Operator, i); - auto PrevOp = ComplexPatternOperands.find(Child->getName()); - if (PrevOp != ComplexPatternOperands.end()) { - if (PrevOp->getValue() != OperandId) - error("All ComplexPattern operands must appear consistently: " - "in the same order in just one ComplexPattern instance."); - } else - ComplexPatternOperands[Child->getName()] = OperandId; + auto [PrevOp, Inserted] = + ComplexPatternOperands.try_emplace(Child->getName(), OperandId); + if (!Inserted && PrevOp->getValue() != OperandId) { + error("All ComplexPattern operands must appear consistently: " + "in the same order in just one ComplexPattern instance."); + } } } @@ -3095,14 +3094,14 @@ bool TreePattern::InferAllTypes( // If we have input named node types, propagate their types to the named // values here. if (InNamedTypes) { - if (!InNamedTypes->count(Entry.getKey())) { + auto InIter = InNamedTypes->find(Entry.getKey()); + if (InIter == InNamedTypes->end()) { error("Node '" + std::string(Entry.getKey()) + "' in output pattern but not input pattern"); return true; } - const SmallVectorImpl &InNodes = - InNamedTypes->find(Entry.getKey())->second; + const SmallVectorImpl &InNodes = InIter->second; // The input types should be fully resolved by now. for (TreePatternNode *Node : Nodes) { @@ -3855,7 +3854,8 @@ void CodeGenDAGPatterns::parseInstructionPattern(CodeGenInstruction &CGI, continue; } - if (!InstInputs.count(OpName)) { + auto InIter = InstInputs.find(OpName); + if (InIter == InstInputs.end()) { // If this is an operand with a DefaultOps set filled in, we can ignore // this. When we codegen it, we will do so as always executed. if (Op.Rec->isSubClassOf("OperandWithDefaultOps")) { @@ -3868,8 +3868,8 @@ void CodeGenDAGPatterns::parseInstructionPattern(CodeGenInstruction &CGI, " does not appear in the instruction pattern"); continue; } - TreePatternNodePtr InVal = InstInputs[OpName]; - InstInputs.erase(OpName); // It occurred, remove from map. + TreePatternNodePtr InVal = InIter->second; + InstInputs.erase(InIter); // It occurred, remove from map. if (InVal->isLeaf() && isa(InVal->getLeafValue())) { const Record *InRec = cast(InVal->getLeafValue())->getDef();