This is an archive of the discontinued LLVM Phabricator instance.

[codeview] Cope with unsorted streams in type merging
ClosedPublic

Authored by rnk on Apr 3 2017, 3:32 PM.

Details

Summary

MASM can produce type streams that are not topologically sorted. It can
even produce type streams with circular references, but those are not
common in practice.

Diff Detail

Repository
rL LLVM

Event Timeline

rnk created this revision.Apr 3 2017, 3:32 PM
ruiu edited edge metadata.Apr 3 2017, 4:14 PM

Do you need multiple scans? I wonder if you can keep type records that were not resolved in the first pass in a map or something and backfill them once we visit all type records.

rnk added a comment.Apr 3 2017, 4:28 PM
In D31629#717372, @ruiu wrote:

Do you need multiple scans? I wonder if you can keep type records that were not resolved in the first pass in a map or something and backfill them once we visit all type records.

You can avoid the traversal if you copy the unresolved records to temporary storage and topologically sort them. You can't backpatch the type records because inserting them into the destination stream requires hashing them, and the hash includes the type index references we'd need to backpatch.

In general, if the type stream is badly unsorted, this algorithm is O(n^2). Topo sort is O(n), but it requires extra storage. It seemed better to optimize for the common case of a large, sorted type stream, and hope that unsorted streams are rare and/or small.

ruiu accepted this revision.Apr 3 2017, 4:41 PM

LGTM

This revision is now accepted and ready to land.Apr 3 2017, 4:41 PM
This revision was automatically updated to reflect the committed changes.