Index: utils/TableGen/CodeGenDAGPatterns.h =================================================================== --- utils/TableGen/CodeGenDAGPatterns.h +++ utils/TableGen/CodeGenDAGPatterns.h @@ -907,21 +907,21 @@ }; class DAGInstruction { - TreePattern *Pattern; + std::unique_ptr Pattern; std::vector Results; std::vector Operands; std::vector ImpResults; TreePatternNodePtr ResultPattern; public: - DAGInstruction(TreePattern *TP, + DAGInstruction(std::unique_ptr &&TP, const std::vector &results, const std::vector &operands, const std::vector &impresults) - : Pattern(TP), Results(results), Operands(operands), + : Pattern(std::move(TP)), Results(results), Operands(operands), ImpResults(impresults), ResultPattern(nullptr) {} - TreePattern *getPattern() const { return Pattern; } + const std::unique_ptr &getPattern() const { return Pattern; } unsigned getNumResults() const { return Results.size(); } unsigned getNumOperands() const { return Operands.size(); } unsigned getNumImpResults() const { return ImpResults.size(); } Index: utils/TableGen/CodeGenDAGPatterns.cpp =================================================================== --- utils/TableGen/CodeGenDAGPatterns.cpp +++ utils/TableGen/CodeGenDAGPatterns.cpp @@ -3218,7 +3218,7 @@ : CDP(cdp), hasSideEffects(false), mayStore(false), mayLoad(false), isBitcast(false), isVariadic(false) {} - void Analyze(const TreePattern *Pat) { + void Analyze(const std::unique_ptr &Pat) { // Assume only the first tree is the pattern. The others are clobber nodes. AnalyzeNode(Pat->getTree(0).get()); } @@ -3421,7 +3421,7 @@ assert(!DAGInsts.count(CGI.TheDef) && "Instruction already parsed!"); // Parse the instruction. - TreePattern *I = new TreePattern(CGI.TheDef, Pat, true, *this); + auto I = llvm::make_unique(CGI.TheDef, Pat, true, *this); // Inline pattern fragments into it. I->InlinePatternFragments(); @@ -3459,7 +3459,7 @@ } // Find inputs and outputs, and verify the structure of the uses/defs. - FindPatternInputsAndOutputs(I, Pat, InstInputs, InstResults, + FindPatternInputsAndOutputs(I.get(), Pat, InstInputs, InstResults, InstImpResults); } @@ -3570,16 +3570,19 @@ // Create and insert the instruction. // FIXME: InstImpResults should not be part of DAGInstruction. - DAGInstruction TheInst(I, Results, Operands, InstImpResults); - DAGInsts.insert(std::make_pair(I->getRecord(), TheInst)); + TreePattern *InstPattern = I.get(); + DAGInstruction TheInst(std::move(I), Results, Operands, InstImpResults); + DAGInsts.emplace( + std::make_pair(InstPattern->getRecord(), std::move(TheInst))); // Use a temporary tree pattern to infer all types and make sure that the // constructed result is correct. This depends on the instruction already // being inserted into the DAGInsts map. - TreePattern Temp(I->getRecord(), ResultPattern, false, *this); - Temp.InferAllTypes(&I->getNamedNodesMap()); + TreePattern Temp(InstPattern->getRecord(), ResultPattern, false, *this); + Temp.InferAllTypes(&InstPattern->getNamedNodesMap()); - DAGInstruction &TheInsertedInst = DAGInsts.find(I->getRecord())->second; + DAGInstruction &TheInsertedInst = + DAGInsts.find(InstPattern->getRecord())->second; TheInsertedInst.setResultPattern(Temp.getOnlyTree()); return TheInsertedInst; @@ -3636,11 +3639,11 @@ // If we can, convert the instructions to be patterns that are matched! for (auto &Entry : Instructions) { DAGInstruction &TheInst = Entry.second; - TreePattern *I = TheInst.getPattern(); + const std::unique_ptr &I = TheInst.getPattern(); if (!I) continue; // No pattern. if (PatternRewriter) - PatternRewriter(I); + PatternRewriter(I.get()); // FIXME: Assume only the first tree is the pattern. The others are clobber // nodes. TreePatternNodePtr Pattern = I->getTree(0); @@ -3656,7 +3659,7 @@ ListInit *Preds = Instr->getValueAsListInit("Predicates"); int Complexity = Instr->getValueAsInt("AddedComplexity"); AddPatternToMatch( - I, + I.get(), PatternToMatch(Instr, makePredList(Preds), SrcPattern, TheInst.getResultPattern(), TheInst.getImpResults(), Complexity, Instr->getID())); @@ -3753,7 +3756,8 @@ const_cast(*Instructions[i]); // Get the primary instruction pattern. - const TreePattern *Pattern = getInstruction(InstInfo.TheDef).getPattern(); + const std::unique_ptr &Pattern = + getInstruction(InstInfo.TheDef).getPattern(); if (!Pattern) { if (InstInfo.hasUndefFlags()) Revisit.push_back(&InstInfo); Index: utils/TableGen/DAGISelMatcherGen.cpp =================================================================== --- utils/TableGen/DAGISelMatcherGen.cpp +++ utils/TableGen/DAGISelMatcherGen.cpp @@ -665,7 +665,7 @@ /// const TreePatternNode *MatcherGen:: GetInstPatternNode(const DAGInstruction &Inst, const TreePatternNode *N) { - const TreePattern *InstPat = Inst.getPattern(); + const std::unique_ptr &InstPat = Inst.getPattern(); // FIXME2?: Assume actual pattern comes before "implicit". TreePatternNode *InstPatNode;