[PATCH] D87063: [BitcodeReader] Fix O(N^2) in placeholder replacement algorithm.

Eli Friedman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 29 16:41:57 PDT 2020


efriedma added a comment.

There are basically three steps here:

1. We find all the relevant constants, and do a topological sort of them.  Think of all the Constants as a DAG, where the edges go from a Constant to its uses.  We treat placeholders as if they're uses of the corresponding constant in the ResolveConstants mapping.  The roots are placeholders that don't refer to another placeholder.  The result is saved in RewrittenConstants.
2. We go through the constants in order, and compute the rewritten version of every constant.
3. We go through the constants in reverse order, and RAUW every constant to its rewritten version.

The key here is ensuring the RAUW operations in step 3 never rewrite a Constant.

Looking at this again, it's maybe a little trickier to follow than it needs to be. The topological sort and the forward iteration step are mixed together; I could separate them.  And maybe there's a better way to write the topological sort.

> (so I guess they're not all using placeholders - some are already resolved?)

We only use a placeholder in constants that refer to another constant that hasn't been constructed yet.  (If the bitcode writer wrote out all the constants in sorted order, we wouldn't need placeholders at all.)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87063/new/

https://reviews.llvm.org/D87063



More information about the llvm-commits mailing list