This is an archive of the discontinued LLVM Phabricator instance.

[CodeView] Speed up type merging by about 20%
ClosedPublic

Authored by zturner on Jan 25 2018, 3:06 PM.

Details

Summary

The critical loop in type merging is (unsurprisingly) the one that iterates over every type record and remaps indices.

The patch here mostly focuses on improving inlining behavior and saving unnecessary memcpys. The way the algorithm works is that for every record, it tries to insert it into a hash table, and if it succeeded (because it was new), it then calls into a callback to serialize the record and save it off. There were multiple levels of outlined functions in this tight loop. This brings my test case down from 40 seconds to ~35 seconds when built with clang with optimizations.

Diff Detail

Repository
rL LLVM

Event Timeline

zturner created this revision.Jan 25 2018, 3:06 PM
rnk added inline comments.Jan 25 2018, 3:30 PM
llvm/lib/DebugInfo/CodeView/TypeStreamMerger.cpp
376–377 ↗(On Diff #131517)

Maybe the next step is to templatize this so we don't have to build a vector of offsets to iterate? Maybe it doesn't matter, though. It'd save the branch on the TiRefKind inside the loop, though.

I think the ideal code for type index remapping would basically be a giant switch on record kind followed by inlined code that implements the remappings inline in each case block.

393 ↗(On Diff #131517)

Looks like we lost error handling here.

zturner added inline comments.Jan 25 2018, 3:45 PM
llvm/lib/DebugInfo/CodeView/TypeStreamMerger.cpp
393 ↗(On Diff #131517)

It turns out nothing actually depended on or used the error handling. It seems like if we decide we need it in the future, we could just go back and re-add it. For now, I was just trying to make the code as fast as possible. If you think we should put it back though, I can. The current behavior is actually the same as the original behavior though.

zturner added inline comments.Jan 25 2018, 3:46 PM
llvm/lib/DebugInfo/CodeView/TypeStreamMerger.cpp
376–377 ↗(On Diff #131517)

Yea, I basically had the same idea. Just like we have ForEachCodeViewRecord we could have ForEachTypeIndex that works the same way. That can be later though.

rnk added inline comments.Jan 25 2018, 4:17 PM
llvm/lib/DebugInfo/CodeView/TypeStreamMerger.cpp
393 ↗(On Diff #131517)

No, we were returning an empty record in the case where remapping failed. I mean, I'm sure we don't have tests for this case, but it would be nice to keep this NFC.

zturner updated this revision to Diff 131608.Jan 26 2018, 9:34 AM

Return an empty record when remapping fails.

This revision was not accepted when it landed; it landed in state Needs Review.Jan 30 2018, 9:16 AM
This revision was automatically updated to reflect the committed changes.