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.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@221928 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
David Blaikie 2014-11-13 21:40:02 +00:00
parent 365df40768
commit bea87dad5e
3 changed files with 16 additions and 23 deletions

View File

@ -2263,13 +2263,6 @@ CodeGenDAGPatterns::CodeGenDAGPatterns(RecordKeeper &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::ParsePatternFragments(bool OutFrags) {
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::ParsePatternFragments(bool OutFrags) {
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());
}
}

View File

@ -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(); }

View File

@ -630,7 +630,7 @@ void MatcherTableEmitter::EmitPredicateFunctions(formatted_raw_ostream &OS) {
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";