diff --git a/lib/Transforms/Utils/InlineFunction.cpp b/lib/Transforms/Utils/InlineFunction.cpp index 22377b759c8..01ffb253e4b 100644 --- a/lib/Transforms/Utils/InlineFunction.cpp +++ b/lib/Transforms/Utils/InlineFunction.cpp @@ -124,14 +124,6 @@ bool InlineFunction(CallSite CS) { // Make a vector to capture the return instructions in the cloned function... std::vector Returns; - // Populate the value map with all of the globals in the program. - // FIXME: This should be the default for CloneFunctionInto! - Module &M = *Caller->getParent(); - for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) - ValueMap[I] = I; - for (Module::giterator I = M.gbegin(), E = M.gend(); I != E; ++I) - ValueMap[I] = I; - // Do all of the hard part of cloning the callee into the caller... CloneFunctionInto(Caller, CalledFunc, ValueMap, Returns, ".i"); diff --git a/lib/Transforms/Utils/ValueMapper.cpp b/lib/Transforms/Utils/ValueMapper.cpp index 484765a7e25..d79c21f474e 100644 --- a/lib/Transforms/Utils/ValueMapper.cpp +++ b/lib/Transforms/Utils/ValueMapper.cpp @@ -13,6 +13,11 @@ Value *MapValue(const Value *V, std::map &VM) { Value *&VMSlot = VM[V]; if (VMSlot) return VMSlot; // Does it exist in the map yet? + // Global values do not need to be seeded into the ValueMap if they are using + // the identity mapping. + if (isa(V)) + return VMSlot = const_cast(V); + if (Constant *C = const_cast(dyn_cast(V))) { if (isa(C) || isa(C) || isa(C))