Linker: Move distinct MDNodes instead of cloning
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>
Mon, 3 Aug 2015 17:09:38 +0000 (17:09 +0000)
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>
Mon, 3 Aug 2015 17:09:38 +0000 (17:09 +0000)
commit268a7555856b12015465c2b5c2e513529f4fb32c
tree0eb1b2fb368b7abce3f7c8c16027e40371aed26e
parent1c12df14a6b168f01790abcc41a8e9d0f2f12de4
Linker: Move distinct MDNodes instead of cloning

Instead of cloning distinct `MDNode`s when linking in a module, just
move them over.  The module linker destroys the source module, so the
old node would otherwise just be leaked on the context.  Create the new
node in place.  This also reduces the number of cloned uniqued nodes
(since it's less likely their operands have changed).

This mapping strategy is only correct when we're discarding the source,
so the linker turns it on via a ValueMapper flag, `RF_MoveDistinctMDs`.

There's nothing observable in terms of `llvm-link` output here: the
linked module should be semantically identical.

I'll be adding more 'distinct' nodes to the debug info metadata graph in
order to break uniquing cycles, so the benefits of this will partly come
in future commits.  However, we should get some gains immediately, since
we have a fair number of 'distinct' `DILocation`s being linked in.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@243883 91177308-0d34-0410-b5e6-96231b3b80d8
include/llvm/Transforms/Utils/ValueMapper.h
lib/Linker/LinkModules.cpp
lib/Transforms/Utils/ValueMapper.cpp
unittests/Linker/LinkModulesTest.cpp
unittests/Transforms/Utils/ValueMapperTest.cpp