ValueMapper: Eliminate cross-file co-recursion, NFC
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>
Sat, 16 Apr 2016 01:29:08 +0000 (01:29 +0000)
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>
Sat, 16 Apr 2016 01:29:08 +0000 (01:29 +0000)
commitf0d73f95c15f909c6034f1735632695248bb75a8
treeb7f244a7c9f762457852998500c4e62a014516c2
parent2db6f2e508126d237435a4d43af8076bf74f641d
ValueMapper: Eliminate cross-file co-recursion, NFC

Eliminate co-recursion of Mapper::mapValue through
ValueMaterializer::materializeInitFor, through a major redesign of the
ValueMapper.cpp interface.

  - Expose a ValueMapper class that controls the entry points to the
    mapping algorithms.
  - Change IRLinker to use ValueMapper directly, rather than
    llvm::RemapInstruction, llvm::MapValue, etc.
  - Use (e.g.) ValueMapper::scheduleMapGlobalInit to add mapping work to
    a worklist in ValueMapper instead of recursing.

There were two fairly major complications.

Firstly, IRLinker::linkAppendingVarProto incorporates an on-the-fly IR
ugprade that I had to split apart.  Long-term, this upgrade should be
done in the bitcode reader (and we should only accept the "new" form),
but for now I've just made it work and added a FIXME.  The hold-op is
that we need to deprecate C API that relies on this.

Secondly, IRLinker has special logic to correctly implement aliases with
comdats, and uses two ValueToValueMapTy instances and two
ValueMaterializers.  I supported this by allowing clients to register an
alternate mapping context, whose MCID can be passed in when scheduling
new work.

While out of scope for this commit, it should now be straightforward to
remove recursion from Mapper::mapValue.

llvm-svn: 266503
llvm/include/llvm/Transforms/Utils/ValueMapper.h
llvm/lib/Linker/IRMover.cpp
llvm/lib/Transforms/Utils/ValueMapper.cpp