From: Daniel Dunbar Date: Thu, 26 Aug 2010 03:48:08 +0000 (+0000) Subject: Revert r112091, "Remap metadata attached to instructions when remapping X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=fd406f1ee2d94bafcb4943e4b21c2f4ea4bd8f3a;p=oota-llvm.git Revert r112091, "Remap metadata attached to instructions when remapping individual ...", which depends on r111922, which I am reverting. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@112157 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Linker/LinkModules.cpp b/lib/Linker/LinkModules.cpp index 07089f7feec..89f4cdc2296 100644 --- a/lib/Linker/LinkModules.cpp +++ b/lib/Linker/LinkModules.cpp @@ -1005,31 +1005,13 @@ static bool LinkFunctionBody(Function *Dest, Function *Src, // the Source function as operands. Loop through all of the operands of the // functions and patch them up to point to the local versions... // - // This is the same as RemapInstruction, except that it avoids remapping - // instruction and basic block operands. - // for (Function::iterator BB = Dest->begin(), BE = Dest->end(); BB != BE; ++BB) - for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ++I) { - // Remap operands. + for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ++I) for (Instruction::op_iterator OI = I->op_begin(), OE = I->op_end(); OI != OE; ++OI) if (!isa(*OI) && !isa(*OI)) *OI = MapValue(*OI, ValueMap); - // Remap attached metadata. - SmallVector, 4> MDs; - I->getAllMetadata(MDs); - for (SmallVectorImpl >::iterator - MI = MDs.begin(), ME = MDs.end(); MI != ME; ++MI) { - Value *Old = MI->second; - if (!isa(Old) && !isa(Old)) { - Value *New = MapValue(Old, ValueMap); - if (New != Old) - I->setMetadata(MI->first, cast(New)); - } - } - } - // There is no need to map the arguments anymore. for (Function::arg_iterator I = Src->arg_begin(), E = Src->arg_end(); I != E; ++I) diff --git a/lib/Transforms/Utils/CloneModule.cpp b/lib/Transforms/Utils/CloneModule.cpp index c54edf63171..25083adb7ce 100644 --- a/lib/Transforms/Utils/CloneModule.cpp +++ b/lib/Transforms/Utils/CloneModule.cpp @@ -132,5 +132,20 @@ Module *llvm::CloneModule(const Module *M, NewNMD->addOperand(cast(MapValue(NMD.getOperand(i), VMap))); } + // Update metadata attach with instructions. + for (Module::iterator MI = New->begin(), ME = New->end(); MI != ME; ++MI) + for (Function::iterator FI = MI->begin(), FE = MI->end(); + FI != FE; ++FI) + for (BasicBlock::iterator BI = FI->begin(), BE = FI->end(); + BI != BE; ++BI) { + SmallVector, 4 > MDs; + BI->getAllMetadata(MDs); + for (SmallVector, 4>::iterator + MDI = MDs.begin(), MDE = MDs.end(); MDI != MDE; ++MDI) { + Value *MappedValue = MapValue(MDI->second, VMap); + if (MDI->second != MappedValue && MappedValue) + BI->setMetadata(MDI->first, cast(MappedValue)); + } + } return New; } diff --git a/lib/Transforms/Utils/ValueMapper.cpp b/lib/Transforms/Utils/ValueMapper.cpp index 8b5ddb08621..df11cbbcb27 100644 --- a/lib/Transforms/Utils/ValueMapper.cpp +++ b/lib/Transforms/Utils/ValueMapper.cpp @@ -147,21 +147,10 @@ Value *llvm::MapValue(const Value *V, ValueToValueMapTy &VM) { /// current values into those specified by VMap. /// void llvm::RemapInstruction(Instruction *I, ValueToValueMapTy &VMap) { - // Remap operands. for (User::op_iterator op = I->op_begin(), E = I->op_end(); op != E; ++op) { Value *V = MapValue(*op, VMap); assert(V && "Referenced value not in value map!"); *op = V; } - - // Remap attached metadata. - SmallVector, 4> MDs; - I->getAllMetadata(MDs); - for (SmallVectorImpl >::iterator - MI = MDs.begin(), ME = MDs.end(); MI != ME; ++MI) { - Value *Old = MI->second; - Value *New = MapValue(Old, VMap); - if (New != Old) - I->setMetadata(MI->first, cast(New)); - } } + diff --git a/test/Linker/metadata-a.ll b/test/Linker/metadata-a.ll deleted file mode 100644 index 5a9d2e40b94..00000000000 --- a/test/Linker/metadata-a.ll +++ /dev/null @@ -1,15 +0,0 @@ -; RUN: llvm-link %s %p/metadata-b.ll -S -o - | FileCheck %s - -; CHECK: define void @foo(i32 %a) -; CHECK: ret void, !attach !0, !also !{i32 %a} -; CHECK: define void @goo(i32 %b) -; CHECK: ret void, !attach !1, !and !{i32 %b} -; CHECK: !0 = metadata !{i32 524334, void (i32)* @foo} -; CHECK: !1 = metadata !{i32 524334, void (i32)* @goo} - -define void @foo(i32 %a) nounwind { -entry: - ret void, !attach !0, !also !{ i32 %a } -} - -!0 = metadata !{i32 524334, void (i32)* @foo} diff --git a/test/Linker/metadata-b.ll b/test/Linker/metadata-b.ll deleted file mode 100644 index ef0270af075..00000000000 --- a/test/Linker/metadata-b.ll +++ /dev/null @@ -1,9 +0,0 @@ -; This file is for use with metadata-a.ll -; RUN: true - -define void @goo(i32 %b) nounwind { -entry: - ret void, !attach !0, !and !{ i32 %b } -} - -!0 = metadata !{i32 524334, void (i32)* @goo}