This is an archive of the discontinued LLVM Phabricator instance.

[TableGen] Make DAGInstruction own Pattern to avoid leaking it.
ClosedPublic

Authored by fhahn on May 30 2018, 2:43 AM.

Diff Detail

Repository
rL LLVM

Event Timeline

nhaehnle added inline comments.May 30 2018, 4:08 AM
utils/TableGen/CodeGenDAGPatterns.h
924–925 ↗(On Diff #149069)

Why do you need a non-const overload here? The pointer itself should never be changed.

Actually, it would arguably be nicer to just return a reference here, since the fact that the TreePattern is stored in a unique_ptr seems like an implementation detail that callers should not have to worry about.

fhahn updated this revision to Diff 149086.May 30 2018, 4:38 AM

Thanks for having a look. Dropped the non-const accessor.

fhahn added inline comments.May 30 2018, 4:42 AM
utils/TableGen/CodeGenDAGPatterns.h
924–925 ↗(On Diff #149069)

Actually, it would arguably be nicer to just return a reference here, since the fact that the TreePattern is stored in a unique_ptr seems like an implementation detail that callers should not have to worry about.

There are some places that check that the pattern is not null, before accessing the value. Having a unique_ptr there seemed just easier. But I suppose we could have something like hasPattern, if you think that would be better?

dsanders added inline comments.May 30 2018, 9:24 AM
utils/TableGen/CodeGenDAGPatterns.h
924 ↗(On Diff #149086)

This code looks like it's either making a copy of pattern or giving ownership of DAGInstruction::Pattern to the caller. Shouldn't it be returning a raw pointer?

fhahn updated this revision to Diff 149156.May 30 2018, 10:18 AM

Thanks, updated to return TreePattern*.

fhahn marked an inline comment as done.May 30 2018, 10:19 AM
craig.topper added inline comments.Jun 7 2018, 2:14 PM
utils/TableGen/CodeGenDAGPatterns.cpp
3575 ↗(On Diff #149156)

Why doesn't insert work? There should be an rvalue pair version.

fhahn updated this revision to Diff 150420.Jun 7 2018, 3:37 PM

Do not create pair explicitly with emplace.

utils/TableGen/CodeGenDAGPatterns.cpp
3575 ↗(On Diff #149156)

Thanks. With emplace we do not have to use make_pair.

This revision is now accepted and ready to land.Jun 7 2018, 3:43 PM
This revision was automatically updated to reflect the committed changes.