[PATCH] D47525: [TableGen] Make DAGInstruction own Pattern to avoid leaking it.

Florian Hahn via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 8 02:58:35 PDT 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rL334275: [TableGen] Make DAGInstruction own Pattern to avoid leaking it. (authored by fhahn, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D47525?vs=150420&id=150471#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D47525

Files:
  llvm/trunk/utils/TableGen/CodeGenDAGPatterns.cpp
  llvm/trunk/utils/TableGen/CodeGenDAGPatterns.h


Index: llvm/trunk/utils/TableGen/CodeGenDAGPatterns.cpp
===================================================================
--- llvm/trunk/utils/TableGen/CodeGenDAGPatterns.cpp
+++ llvm/trunk/utils/TableGen/CodeGenDAGPatterns.cpp
@@ -3423,7 +3423,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<TreePattern>(CGI.TheDef, Pat, true, *this);
   // Inline pattern fragments into it.
   I->InlinePatternFragments();
 
@@ -3461,7 +3461,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);
   }
 
@@ -3572,16 +3572,18 @@
 
   // 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(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;
Index: llvm/trunk/utils/TableGen/CodeGenDAGPatterns.h
===================================================================
--- llvm/trunk/utils/TableGen/CodeGenDAGPatterns.h
+++ llvm/trunk/utils/TableGen/CodeGenDAGPatterns.h
@@ -907,21 +907,21 @@
 };
 
 class DAGInstruction {
-  TreePattern *Pattern;
+  std::unique_ptr<TreePattern> Pattern;
   std::vector<Record*> Results;
   std::vector<Record*> Operands;
   std::vector<Record*> ImpResults;
   TreePatternNodePtr ResultPattern;
 
 public:
-  DAGInstruction(TreePattern *TP,
+  DAGInstruction(std::unique_ptr<TreePattern> &&TP,
                  const std::vector<Record*> &results,
                  const std::vector<Record*> &operands,
                  const std::vector<Record*> &impresults)
-    : Pattern(TP), Results(results), Operands(operands),
+    : Pattern(std::move(TP)), Results(results), Operands(operands),
       ImpResults(impresults), ResultPattern(nullptr) {}
 
-  TreePattern *getPattern() const { return Pattern; }
+  TreePattern *getPattern() const { return Pattern.get(); }
   unsigned getNumResults() const { return Results.size(); }
   unsigned getNumOperands() const { return Operands.size(); }
   unsigned getNumImpResults() const { return ImpResults.size(); }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D47525.150471.patch
Type: text/x-patch
Size: 3261 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180608/d8810226/attachment.bin>


More information about the llvm-commits mailing list