[PATCH] D120781: [IRLinker] materialize Functions before moving any

Nick Desaulniers via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 23 17:12:01 PDT 2022


nickdesaulniers added a comment.
Herald added a subscriber: StephenFan.

In D120781#3376069 <https://reviews.llvm.org/D120781#3376069>, @dexonsmith wrote:

> Here's what I suggest:
>
> - Add to bitcode a way to say that materializing a function requires materializing another one. Maybe this could be a new record in the `FUNCTION_BLOCK` that's arbitrary size, only emitted if there are non-zero of them, which lists the functions that need to be materialized when this one is.
> - Use this feature to add edges in both directions every time one function has a `blockaddress` to another one. Probably not too hard; during value enumeration of function bodies, create a map of which functions need to be materialized with each other (based on observed `blockaddress`es), then use that to generate the records during bitcode emission.
> - Change the lazy materializer to use this information somehow (maybe this is the hard part).
>
> WDYT?

So I think when BitcodeWriter is serializing a function, it can check whether each of the function's basicblocks has its address taken.  If so, it can build the set of GlobalValues that are Users of that BlockAddress.  I'm curious if this should be part of the record or an Abbreviation? (Not sure I fully understand what an abbreviation is, despite just reading https://llvm.org/docs/BitCodeFormat.html#abbreviations). It seems like adding a record is unconditional though? So not sure about making it optional/only emitted if necessary?

Then, when BitcodeReader is parsing function records (`parseFunctionRecord`), it can read back these sub-records (or abbreviations). When parsing a function body (lazily), it can check these sub-records and call `DeferredFunctionInfo.find`, `findFunctionInStream`, `Stream.JumpToBit`, `parseFunctionBody` (basically the steps of `BitcodeReader::materialize`).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120781



More information about the llvm-commits mailing list