From b2187ede9e234c5abd264fca1bfc18882d8f0d85 Mon Sep 17 00:00:00 2001 From: "Duncan P. N. Exon Smith" Date: Sat, 1 Nov 2014 00:26:42 +0000 Subject: [PATCH] IR: MDNode => Value: Instruction::getAllMetadata() Change `Instruction::getAllMetadata()` to modify a vector of `Value` instead of `MDNode` and update call sites. This is part of PR21433. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@221027 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/IR/Instruction.h | 6 ++++-- lib/IR/AsmWriter.cpp | 10 +++++----- lib/IR/Metadata.cpp | 4 ++-- .../InstCombine/InstCombineLoadStoreAlloca.cpp | 4 ++-- lib/Transforms/Utils/ValueMapper.cpp | 9 ++++----- 5 files changed, 17 insertions(+), 16 deletions(-) diff --git a/include/llvm/IR/Instruction.h b/include/llvm/IR/Instruction.h index 8030b2b1498..e7d1d25c933 100644 --- a/include/llvm/IR/Instruction.h +++ b/include/llvm/IR/Instruction.h @@ -174,7 +174,8 @@ public: /// getAllMetadata - Get all metadata attached to this Instruction. The first /// element of each pair returned is the KindID, the second element is the /// metadata value. This list is returned sorted by the KindID. - void getAllMetadata(SmallVectorImpl > &MDs)const{ + void + getAllMetadata(SmallVectorImpl> &MDs) const { if (hasMetadata()) getAllMetadataImpl(MDs); } @@ -293,7 +294,8 @@ private: Value *getMetadataImpl(StringRef Kind) const; MDNode *getMDNodeImpl(unsigned KindID) const; MDNode *getMDNodeImpl(StringRef Kind) const; - void getAllMetadataImpl(SmallVectorImpl > &)const; + void + getAllMetadataImpl(SmallVectorImpl> &) const; void getAllMetadataOtherThanDebugLocImpl(SmallVectorImpl > &) const; void clearMetadataHashEntries(); diff --git a/lib/IR/AsmWriter.cpp b/lib/IR/AsmWriter.cpp index 449225ae8c3..2dab6a44bc9 100644 --- a/lib/IR/AsmWriter.cpp +++ b/lib/IR/AsmWriter.cpp @@ -718,7 +718,7 @@ void SlotTracker::processFunction() { ST_DEBUG("Inserting Instructions:\n"); - SmallVector, 4> MDForInst; + SmallVector, 4> MDForInst; // Add all of the basic blocks and instructions with no names. for (Function::const_iterator BB = TheFunction->begin(), @@ -755,7 +755,7 @@ void SlotTracker::processFunction() { // Process metadata attached with this instruction. I->getAllMetadata(MDForInst); for (unsigned i = 0, e = MDForInst.size(); i != e; ++i) - CreateMetadataSlot(MDForInst[i].second); + CreateMetadataSlot(cast(MDForInst[i].second)); MDForInst.clear(); } } @@ -2315,7 +2315,7 @@ void AssemblyWriter::printInstruction(const Instruction &I) { } // Print Metadata info. - SmallVector, 4> InstMD; + SmallVector, 4> InstMD; I.getAllMetadata(InstMD); if (!InstMD.empty()) { SmallVector MDNames; @@ -2328,8 +2328,8 @@ void AssemblyWriter::printInstruction(const Instruction &I) { Out << ", !"; } Out << ' '; - WriteAsOperandInternal(Out, InstMD[i].second, &TypePrinter, &Machine, - TheModule); + WriteAsOperandInternal(Out, cast(InstMD[i].second), &TypePrinter, + &Machine, TheModule); } } printInfoComment(I); diff --git a/lib/IR/Metadata.cpp b/lib/IR/Metadata.cpp index 6c335c78729..ba86e9e6085 100644 --- a/lib/IR/Metadata.cpp +++ b/lib/IR/Metadata.cpp @@ -745,8 +745,8 @@ Value *Instruction::getMetadataImpl(unsigned KindID) const { return nullptr; } -void Instruction::getAllMetadataImpl(SmallVectorImpl > &Result) const { +void Instruction::getAllMetadataImpl( + SmallVectorImpl> &Result) const { Result.clear(); // Handle 'dbg' as a special case since it is not stored in the hash table. diff --git a/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp b/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp index f3ac44cbd6b..ebbb9ec08c5 100644 --- a/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp +++ b/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp @@ -304,7 +304,7 @@ Instruction *InstCombiner::visitAllocaInst(AllocaInst &AI) { static LoadInst *combineLoadToNewType(InstCombiner &IC, LoadInst &LI, Type *NewTy) { Value *Ptr = LI.getPointerOperand(); unsigned AS = LI.getPointerAddressSpace(); - SmallVector, 8> MD; + SmallVector, 8> MD; LI.getAllMetadata(MD); LoadInst *NewLoad = IC.Builder->CreateAlignedLoad( @@ -312,7 +312,7 @@ static LoadInst *combineLoadToNewType(InstCombiner &IC, LoadInst &LI, Type *NewT LI.getAlignment(), LI.getName()); for (const auto &MDPair : MD) { unsigned ID = MDPair.first; - MDNode *N = MDPair.second; + Value *N = MDPair.second; // Note, essentially every kind of metadata should be preserved here! This // routine is supposed to clone a load instruction changing *only its type*. // The only metadata it makes sense to drop is metadata which is invalidated diff --git a/lib/Transforms/Utils/ValueMapper.cpp b/lib/Transforms/Utils/ValueMapper.cpp index 0f20e6df6c9..31755427d77 100644 --- a/lib/Transforms/Utils/ValueMapper.cpp +++ b/lib/Transforms/Utils/ValueMapper.cpp @@ -208,12 +208,11 @@ void llvm::RemapInstruction(Instruction *I, ValueToValueMapTy &VMap, } // Remap attached metadata. - SmallVector, 4> MDs; + SmallVector, 4> MDs; I->getAllMetadata(MDs); - for (SmallVectorImpl >::iterator - MI = MDs.begin(), ME = MDs.end(); MI != ME; ++MI) { - MDNode *Old = MI->second; - MDNode *New = MapValue(Old, VMap, Flags, TypeMapper, Materializer); + for (auto MI = MDs.begin(), ME = MDs.end(); MI != ME; ++MI) { + Value *Old = MI->second; + Value *New = MapValue(Old, VMap, Flags, TypeMapper, Materializer); if (New != Old) I->setMetadata(MI->first, New); } -- 2.34.1