From f58c34d5315a35d489c5c203ae45430ccb53f973 Mon Sep 17 00:00:00 2001 From: Victor Hernandez Date: Wed, 20 Jan 2010 05:49:59 +0000 Subject: Map operands of all function-local metadata, not just metadata passed to llvm.dbg.declare intrinsics git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@93979 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Utils/ValueMapper.cpp | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-) (limited to 'lib/Transforms/Utils/ValueMapper.cpp') diff --git a/lib/Transforms/Utils/ValueMapper.cpp b/lib/Transforms/Utils/ValueMapper.cpp index b5b0d2e2de..2fba938324 100644 --- a/lib/Transforms/Utils/ValueMapper.cpp +++ b/lib/Transforms/Utils/ValueMapper.cpp @@ -29,11 +29,21 @@ Value *llvm::MapValue(const Value *V, ValueMapTy &VM) { // NOTE: VMSlot can be invalidated by any reference to VM, which can grow the // DenseMap. This includes any recursive calls to MapValue. - // Global values and metadata do not need to be seeded into the ValueMap if - // they are using the identity mapping. - if (isa(V) || isa(V) || isa(V)) + // Global values and non-function-local metadata do not need to be seeded into + // the ValueMap if they are using the identity mapping. + if (isa(V) || isa(V) || isa(V) || + (isa(V) && !dyn_cast(V)->isFunctionLocal())) return VMSlot = const_cast(V); + if (isa(V)) { + const MDNode *MD = dyn_cast(V); + std::vector Elts; + Elts.reserve(MD->getNumOperands()); + for (unsigned i = 0; i != MD->getNumOperands(); i++) + Elts.push_back(MapValue(MD->getOperand(i), VM)); + return VM[V] = MDNode::get(V->getContext(), Elts.data(), Elts.size()); + } + Constant *C = const_cast(dyn_cast(V)); if (C == 0) return 0; @@ -131,21 +141,5 @@ void llvm::RemapInstruction(Instruction *I, ValueMapTy &ValueMap) { assert(V && "Referenced value not in value map!"); *op = V; } - - // Map llvm.dbg.declare instruction's first operand, which points to - // alloca instruction through MDNode. Since MDNodes are not counted as normal - // uses, this will fall through cracks otherwise. - const DbgDeclareInst *DDI = dyn_cast(I); - if (!DDI) return; - - Value *AddrInsn = DDI->getAddress(); - if (!AddrInsn) return; - - ValueMapTy::iterator VMI = ValueMap.find(AddrInsn); - if (VMI == ValueMap.end()) return; - - Value *Elts[] = { VMI->second }; - MDNode *NewAddr = MDNode::get(AddrInsn->getContext(), Elts, 1); - I->setOperand(1, NewAddr); } -- cgit v1.2.3