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)
commit4fb46cb818f43805205cf05d7064cb443e04f69c
tree643c0073cbfd71d13ab494d920f838fb5c1bd7fa
parent14e67e43a759538e6ab00624c2e50034fea4d015
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.

llvm-svn: 243883
llvm/include/llvm/Transforms/Utils/ValueMapper.h
llvm/lib/Linker/LinkModules.cpp
llvm/lib/Transforms/Utils/ValueMapper.cpp
llvm/unittests/Linker/LinkModulesTest.cpp
llvm/unittests/Transforms/Utils/ValueMapperTest.cpp