This is an archive of the discontinued LLVM Phabricator instance.

[TableGen] Use SmallMapVector to simplify some code that was trying to keep a vector unique
ClosedPublic

Authored by craig.topper on Mar 20 2018, 3:14 PM.

Details

Summary

This code previously had a SmallVector of std::pairs containing an unsigned and another SmallVector. The outer vector was using the unsigned effectively as a key to decide which SmallVector to add into. So each time something new needed to be added the out vector needed to be scanned. If it wasn't found a new entry needed to be added to be added. This sounds very much like a map, but the next loop iterates over the outer vector to get a deterministic order.

We can simplify this code greatly if use SmallMapVector instead. This uses more stack space since we now have a vector and a map, but the searching and creating new entries all happens behind the scenes. It should also make the search more efficient though usually there are only a few entries so that doesn't matter much.

We could probably get determinism by just using std::map which would iterate over the unsigned key, but that would generate different output from what we get with the current implementation.

Diff Detail

Repository
rL LLVM

Event Timeline

craig.topper created this revision.Mar 20 2018, 3:14 PM
dblaikie accepted this revision.Mar 20 2018, 4:08 PM

Sounds good to me

This revision is now accepted and ready to land.Mar 20 2018, 4:08 PM
This revision was automatically updated to reflect the committed changes.