[llvm] r221928 - Use unique_ptr to handle ownership of TreePatterns in CodeGenDAGPatterns::PatternFragments
David Blaikie
dblaikie at gmail.com
Thu Nov 13 13:40:03 PST 2014
Author: dblaikie
Date: Thu Nov 13 15:40:02 2014
New Revision: 221928
URL: http://llvm.org/viewvc/llvm-project?rev=221928&view=rev
Log:
Use unique_ptr to handle ownership of TreePatterns in CodeGenDAGPatterns::PatternFragments
We might be able to use unique_ptr to handle ownership of the
TreePatternNodes too - looking into that next.
Modified:
llvm/trunk/utils/TableGen/CodeGenDAGPatterns.cpp
llvm/trunk/utils/TableGen/CodeGenDAGPatterns.h
llvm/trunk/utils/TableGen/DAGISelMatcherEmitter.cpp
Modified: llvm/trunk/utils/TableGen/CodeGenDAGPatterns.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/CodeGenDAGPatterns.cpp?rev=221928&r1=221927&r2=221928&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/CodeGenDAGPatterns.cpp (original)
+++ llvm/trunk/utils/TableGen/CodeGenDAGPatterns.cpp Thu Nov 13 15:40:02 2014
@@ -2263,13 +2263,6 @@ CodeGenDAGPatterns::CodeGenDAGPatterns(R
VerifyInstructionFlags();
}
-CodeGenDAGPatterns::~CodeGenDAGPatterns() {
- for (pf_iterator I = PatternFragments.begin(),
- E = PatternFragments.end(); I != E; ++I)
- delete I->second;
-}
-
-
Record *CodeGenDAGPatterns::getSDNodeNamed(const std::string &Name) const {
Record *N = Records.getDef(Name);
if (!N || !N->isSubClassOf("SDNode")) {
@@ -2331,9 +2324,9 @@ void CodeGenDAGPatterns::ParsePatternFra
DagInit *Tree = Fragments[i]->getValueAsDag("Fragment");
TreePattern *P =
- new TreePattern(Fragments[i], Tree,
- !Fragments[i]->isSubClassOf("OutPatFrag"), *this);
- PatternFragments[Fragments[i]] = P;
+ (PatternFragments[Fragments[i]] = llvm::make_unique<TreePattern>(
+ Fragments[i], Tree, !Fragments[i]->isSubClassOf("OutPatFrag"),
+ *this)).get();
// Validate the argument list, converting it to set, to discard duplicates.
std::vector<std::string> &Args = P->getArgList();
@@ -2391,16 +2384,16 @@ void CodeGenDAGPatterns::ParsePatternFra
if (OutFrags != Fragments[i]->isSubClassOf("OutPatFrag"))
continue;
- TreePattern *ThePat = PatternFragments[Fragments[i]];
- ThePat->InlinePatternFragments();
+ TreePattern &ThePat = *PatternFragments[Fragments[i]];
+ ThePat.InlinePatternFragments();
// Infer as many types as possible. Don't worry about it if we don't infer
// all of them, some may depend on the inputs of the pattern.
- ThePat->InferAllTypes();
- ThePat->resetError();
+ ThePat.InferAllTypes();
+ ThePat.resetError();
// If debugging, print out the pattern fragment result.
- DEBUG(ThePat->dump());
+ DEBUG(ThePat.dump());
}
}
Modified: llvm/trunk/utils/TableGen/CodeGenDAGPatterns.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/CodeGenDAGPatterns.h?rev=221928&r1=221927&r2=221928&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/CodeGenDAGPatterns.h (original)
+++ llvm/trunk/utils/TableGen/CodeGenDAGPatterns.h Thu Nov 13 15:40:02 2014
@@ -702,7 +702,8 @@ class CodeGenDAGPatterns {
std::map<Record*, SDNodeInfo, LessRecordByID> SDNodes;
std::map<Record*, std::pair<Record*, std::string>, LessRecordByID> SDNodeXForms;
std::map<Record*, ComplexPattern, LessRecordByID> ComplexPatterns;
- std::map<Record*, TreePattern*, LessRecordByID> PatternFragments;
+ std::map<Record *, std::unique_ptr<TreePattern>, LessRecordByID>
+ PatternFragments;
std::map<Record*, DAGDefaultOperand, LessRecordByID> DefaultOperands;
std::map<Record*, DAGInstruction, LessRecordByID> Instructions;
@@ -716,7 +717,6 @@ class CodeGenDAGPatterns {
std::vector<PatternToMatch> PatternsToMatch;
public:
CodeGenDAGPatterns(RecordKeeper &R);
- ~CodeGenDAGPatterns();
CodeGenTarget &getTargetInfo() { return Target; }
const CodeGenTarget &getTargetInfo() const { return Target; }
@@ -778,15 +778,15 @@ public:
// Pattern Fragment information.
TreePattern *getPatternFragment(Record *R) const {
assert(PatternFragments.count(R) && "Invalid pattern fragment request!");
- return PatternFragments.find(R)->second;
+ return PatternFragments.find(R)->second.get();
}
TreePattern *getPatternFragmentIfRead(Record *R) const {
- if (!PatternFragments.count(R)) return nullptr;
- return PatternFragments.find(R)->second;
+ if (!PatternFragments.count(R))
+ return nullptr;
+ return PatternFragments.find(R)->second.get();
}
- typedef std::map<Record*, TreePattern*, LessRecordByID>::const_iterator
- pf_iterator;
+ typedef decltype(PatternFragments)::const_iterator pf_iterator;
pf_iterator pf_begin() const { return PatternFragments.begin(); }
pf_iterator pf_end() const { return PatternFragments.end(); }
Modified: llvm/trunk/utils/TableGen/DAGISelMatcherEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/DAGISelMatcherEmitter.cpp?rev=221928&r1=221927&r2=221928&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/DAGISelMatcherEmitter.cpp (original)
+++ llvm/trunk/utils/TableGen/DAGISelMatcherEmitter.cpp Thu Nov 13 15:40:02 2014
@@ -630,7 +630,7 @@ void MatcherTableEmitter::EmitPredicateF
for (CodeGenDAGPatterns::pf_iterator I = CGP.pf_begin(), E = CGP.pf_end();
I != E; ++I)
- PFsByName[I->first->getName()] = I->second;
+ PFsByName[I->first->getName()] = I->second.get();
if (!NodePredicates.empty()) {
OS << "bool CheckNodePredicate(SDNode *Node,\n";
More information about the llvm-commits
mailing list