From 8f49c8202f3ce1fd77ca07cc56b5acf05a49dad3 Mon Sep 17 00:00:00 2001 From: "Duncan P. N. Exon Smith" Date: Mon, 3 Nov 2014 18:13:57 +0000 Subject: [PATCH] IR: MDNode => Value: Instruction::getAllMetadataOtherThanDebugLoc() Change `Instruction::getAllMetadataOtherThanDebugLoc()` from a vector of `MDNode` to one of `Value`. Part of PR21433. llvm-svn: 221167 --- include/llvm/IR/Instruction.h | 8 ++++---- lib/Bitcode/Writer/BitcodeWriter.cpp | 2 +- lib/Bitcode/Writer/ValueEnumerator.cpp | 8 ++++---- lib/IR/Instruction.cpp | 2 +- lib/IR/Metadata.cpp | 5 ++--- lib/IR/TypeFinder.cpp | 4 ++-- lib/Target/R600/SITypeRewriter.cpp | 3 ++- lib/Transforms/Scalar/Scalarizer.cpp | 5 ++--- lib/Transforms/Utils/Local.cpp | 4 ++-- lib/Transforms/Vectorize/LoopVectorize.cpp | 2 +- lib/Transforms/Vectorize/SLPVectorizer.cpp | 4 ++-- 11 files changed, 23 insertions(+), 24 deletions(-) diff --git a/include/llvm/IR/Instruction.h b/include/llvm/IR/Instruction.h index e7d1d25c933..a46485d83ce 100644 --- a/include/llvm/IR/Instruction.h +++ b/include/llvm/IR/Instruction.h @@ -182,8 +182,8 @@ public: /// getAllMetadataOtherThanDebugLoc - This does the same thing as /// getAllMetadata, except that it filters out the debug location. - void getAllMetadataOtherThanDebugLoc(SmallVectorImpl > &MDs) const { + void getAllMetadataOtherThanDebugLoc( + SmallVectorImpl> &MDs) const { if (hasMetadataOtherThanDebugLoc()) getAllMetadataOtherThanDebugLocImpl(MDs); } @@ -296,8 +296,8 @@ private: MDNode *getMDNodeImpl(StringRef Kind) const; void getAllMetadataImpl(SmallVectorImpl> &) const; - void getAllMetadataOtherThanDebugLocImpl(SmallVectorImpl > &) const; + void getAllMetadataOtherThanDebugLocImpl( + SmallVectorImpl> &) const; void clearMetadataHashEntries(); public: //===--------------------------------------------------------------------===// diff --git a/lib/Bitcode/Writer/BitcodeWriter.cpp b/lib/Bitcode/Writer/BitcodeWriter.cpp index 191fdc9efdc..ef7a456a35c 100644 --- a/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -848,7 +848,7 @@ static void WriteMetadataAttachment(const Function &F, // Write metadata attachments // METADATA_ATTACHMENT - [m x [value, [n x [id, mdnode]]] - SmallVector, 4> MDs; + SmallVector, 4> MDs; for (Function::const_iterator BB = F.begin(), E = F.end(); BB != E; ++BB) for (BasicBlock::const_iterator I = BB->begin(), E = BB->end(); diff --git a/lib/Bitcode/Writer/ValueEnumerator.cpp b/lib/Bitcode/Writer/ValueEnumerator.cpp index c14591acc8a..902bb27c1e9 100644 --- a/lib/Bitcode/Writer/ValueEnumerator.cpp +++ b/lib/Bitcode/Writer/ValueEnumerator.cpp @@ -321,7 +321,7 @@ ValueEnumerator::ValueEnumerator(const Module *M) { EnumerateValueSymbolTable(M->getValueSymbolTable()); EnumerateNamedMetadata(M); - SmallVector, 8> MDs; + SmallVector, 8> MDs; // Enumerate types used by function bodies and argument lists. for (const Function &F : *M) { @@ -347,7 +347,7 @@ ValueEnumerator::ValueEnumerator(const Module *M) { MDs.clear(); I.getAllMetadataOtherThanDebugLoc(MDs); for (unsigned i = 0, e = MDs.size(); i != e; ++i) - EnumerateMetadata(MDs[i].second); + EnumerateMetadata(cast(MDs[i].second)); if (!I.getDebugLoc().isUnknown()) { MDNode *Scope, *IA; @@ -741,10 +741,10 @@ void ValueEnumerator::incorporateFunction(const Function &F) { FnLocalMDVector.push_back(MD); } - SmallVector, 8> MDs; + SmallVector, 8> MDs; I->getAllMetadataOtherThanDebugLoc(MDs); for (unsigned i = 0, e = MDs.size(); i != e; ++i) { - MDNode *N = MDs[i].second; + auto *N = cast(MDs[i].second); if (N->isFunctionLocal() && N->getFunction()) FnLocalMDVector.push_back(N); } diff --git a/lib/IR/Instruction.cpp b/lib/IR/Instruction.cpp index bf375c976df..a2bbb563db4 100644 --- a/lib/IR/Instruction.cpp +++ b/lib/IR/Instruction.cpp @@ -548,7 +548,7 @@ Instruction *Instruction::clone() const { // Otherwise, enumerate and copy over metadata from the old instruction to the // new one. - SmallVector, 4> TheMDs; + SmallVector, 4> TheMDs; getAllMetadataOtherThanDebugLoc(TheMDs); for (const auto &MD : TheMDs) New->setMetadata(MD.first, MD.second); diff --git a/lib/IR/Metadata.cpp b/lib/IR/Metadata.cpp index ba86e9e6085..34c85004bc2 100644 --- a/lib/IR/Metadata.cpp +++ b/lib/IR/Metadata.cpp @@ -770,9 +770,8 @@ void Instruction::getAllMetadataImpl( array_pod_sort(Result.begin(), Result.end()); } -void Instruction:: -getAllMetadataOtherThanDebugLocImpl(SmallVectorImpl > &Result) const { +void Instruction::getAllMetadataOtherThanDebugLocImpl( + SmallVectorImpl> &Result) const { Result.clear(); assert(hasMetadataHashEntry() && getContext().pImpl->MetadataStore.count(this) && diff --git a/lib/IR/TypeFinder.cpp b/lib/IR/TypeFinder.cpp index 689b9038913..d1d8e1381be 100644 --- a/lib/IR/TypeFinder.cpp +++ b/lib/IR/TypeFinder.cpp @@ -40,7 +40,7 @@ void TypeFinder::run(const Module &M, bool onlyNamed) { } // Get types from functions. - SmallVector, 4> MDForInst; + SmallVector, 4> MDForInst; for (Module::const_iterator FI = M.begin(), E = M.end(); FI != E; ++FI) { incorporateType(FI->getType()); @@ -71,7 +71,7 @@ void TypeFinder::run(const Module &M, bool onlyNamed) { // Incorporate types hiding in metadata. I.getAllMetadataOtherThanDebugLoc(MDForInst); for (unsigned i = 0, e = MDForInst.size(); i != e; ++i) - incorporateMDNode(MDForInst[i].second); + incorporateMDNode(cast(MDForInst[i].second)); MDForInst.clear(); } diff --git a/lib/Target/R600/SITypeRewriter.cpp b/lib/Target/R600/SITypeRewriter.cpp index 367963aebb0..f32b1e4ef7b 100644 --- a/lib/Target/R600/SITypeRewriter.cpp +++ b/lib/Target/R600/SITypeRewriter.cpp @@ -87,7 +87,8 @@ void SITypeRewriter::visitLoadInst(LoadInst &I) { Value *BitCast = Builder.CreateBitCast(Ptr, PointerType::get(v4i32,PtrTy->getPointerAddressSpace())); LoadInst *Load = Builder.CreateLoad(BitCast); - SmallVector , 8> MD; + // FIXME: Should the DebugLoc really get dropped here? + SmallVector, 8> MD; I.getAllMetadataOtherThanDebugLoc(MD); for (unsigned i = 0, e = MD.size(); i != e; ++i) { Load->setMetadata(MD[i].first, MD[i].second); diff --git a/lib/Transforms/Scalar/Scalarizer.cpp b/lib/Transforms/Scalar/Scalarizer.cpp index 64e12d45bb3..0ad7cea6392 100644 --- a/lib/Transforms/Scalar/Scalarizer.cpp +++ b/lib/Transforms/Scalar/Scalarizer.cpp @@ -327,12 +327,11 @@ bool Scalarizer::canTransferMetadata(unsigned Tag) { // Transfer metadata from Op to the instructions in CV if it is known // to be safe to do so. void Scalarizer::transferMetadata(Instruction *Op, const ValueVector &CV) { - SmallVector, 4> MDs; + SmallVector, 4> MDs; Op->getAllMetadataOtherThanDebugLoc(MDs); for (unsigned I = 0, E = CV.size(); I != E; ++I) { if (Instruction *New = dyn_cast(CV[I])) { - for (SmallVectorImpl >::iterator - MI = MDs.begin(), ME = MDs.end(); MI != ME; ++MI) + for (auto MI = MDs.begin(), ME = MDs.end(); MI != ME; ++MI) if (canTransferMetadata(MI->first)) New->setMetadata(MI->first, MI->second); New->setDebugLoc(Op->getDebugLoc()); diff --git a/lib/Transforms/Utils/Local.cpp b/lib/Transforms/Utils/Local.cpp index 7c0e4c7f214..c6229b1028c 100644 --- a/lib/Transforms/Utils/Local.cpp +++ b/lib/Transforms/Utils/Local.cpp @@ -1308,13 +1308,13 @@ bool llvm::removeUnreachableBlocks(Function &F) { } void llvm::combineMetadata(Instruction *K, const Instruction *J, ArrayRef KnownIDs) { - SmallVector, 4> Metadata; + SmallVector, 4> Metadata; K->dropUnknownMetadata(KnownIDs); K->getAllMetadataOtherThanDebugLoc(Metadata); for (unsigned i = 0, n = Metadata.size(); i < n; ++i) { unsigned Kind = Metadata[i].first; MDNode *JMD = J->getMDNode(Kind); - MDNode *KMD = Metadata[i].second; + MDNode *KMD = cast(Metadata[i].second); switch (Kind) { default: diff --git a/lib/Transforms/Vectorize/LoopVectorize.cpp b/lib/Transforms/Vectorize/LoopVectorize.cpp index 17e11724183..f02cf0a55bd 100644 --- a/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -531,7 +531,7 @@ static std::string getDebugLocString(const Loop *L) { /// \brief Propagate known metadata from one instruction to another. static void propagateMetadata(Instruction *To, const Instruction *From) { - SmallVector, 4> Metadata; + SmallVector, 4> Metadata; From->getAllMetadataOtherThanDebugLoc(Metadata); for (auto M : Metadata) { diff --git a/lib/Transforms/Vectorize/SLPVectorizer.cpp b/lib/Transforms/Vectorize/SLPVectorizer.cpp index 73767b46a36..5771582896d 100644 --- a/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -188,12 +188,12 @@ static void propagateIRFlags(Value *I, ArrayRef VL) { /// \returns \p I after propagating metadata from \p VL. static Instruction *propagateMetadata(Instruction *I, ArrayRef VL) { Instruction *I0 = cast(VL[0]); - SmallVector, 4> Metadata; + SmallVector, 4> Metadata; I0->getAllMetadataOtherThanDebugLoc(Metadata); for (unsigned i = 0, n = Metadata.size(); i != n; ++i) { unsigned Kind = Metadata[i].first; - MDNode *MD = Metadata[i].second; + MDNode *MD = cast_or_null(Metadata[i].second); for (int i = 1, e = VL.size(); MD && i != e; i++) { Instruction *I = cast(VL[i]);