ValueMapper: Avoid recursion in mapSimplifiedMetadata, NFC
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>
Sun, 3 Apr 2016 20:17:45 +0000 (20:17 +0000)
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>
Sun, 3 Apr 2016 20:17:45 +0000 (20:17 +0000)
commitc6065e3a25560e683ed0e752181e167f96576a1a
tree47b254d168c2fcb54915b1bd81f9ac63d7db66ba
parent151ae32dba245f1052e99a7f40757bdb867f24dd
ValueMapper: Avoid recursion in mapSimplifiedMetadata, NFC

The main change is to delay materializing GlobalValue initializers from
Mapper::mapValue until Mapper::~Mapper.  This effectively removes all
recursion from mapSimplifiedMetadata, as promised in r265270.
mapSimplifiedMetadata calls mapValue for ConstantAsMetadata nodes to
find the mapped constant, and now it shouldn't be possible for mapValue
to indirectly re-invoke mapMetadata.  I'll add an assertion to that
effect in a follow-up (separated so that the assertion can easily be
reverted independently, if it comes to that).

This a step toward a broader goal: converting Mapper::mapMetadataImpl
from a recursive to an iterative algorithm.

When a BlockAddress points at a BasicBlock inside an unmaterialized
function body, we need to delay it until the function body is
materialized in Mapper::~Mapper.  This commit creates a temporary
BasicBlock and returns a new BlockAddress, then RAUWs the BasicBlock
once it is known.  This situation should be extremely rare since a
BlockAddress is usually used from within the function it's referencing
(and BlockAddress itself is rare).

There should be no observable functionality change.

llvm-svn: 265273
llvm/lib/Transforms/Utils/ValueMapper.cpp