IR: MDNode => Value: Instruction::getAllMetadataOtherThanDebugLoc()
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>
Mon, 3 Nov 2014 18:13:57 +0000 (18:13 +0000)
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>
Mon, 3 Nov 2014 18:13:57 +0000 (18:13 +0000)
Change `Instruction::getAllMetadataOtherThanDebugLoc()` from a vector of
`MDNode` to one of `Value`.  Part of PR21433.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@221167 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/IR/Instruction.h
lib/Bitcode/Writer/BitcodeWriter.cpp
lib/Bitcode/Writer/ValueEnumerator.cpp
lib/IR/Instruction.cpp
lib/IR/Metadata.cpp
lib/IR/TypeFinder.cpp
lib/Target/R600/SITypeRewriter.cpp
lib/Transforms/Scalar/Scalarizer.cpp
lib/Transforms/Utils/Local.cpp
lib/Transforms/Vectorize/LoopVectorize.cpp
lib/Transforms/Vectorize/SLPVectorizer.cpp

index e7d1d25c933a16861565e9e24f39ec2245c2e0ed..a46485d83cec110bb8f6cfdfe0da80c16fa1ed88 100644 (file)
@@ -182,8 +182,8 @@ public:
 
   /// getAllMetadataOtherThanDebugLoc - This does the same thing as
   /// getAllMetadata, except that it filters out the debug location.
-  void getAllMetadataOtherThanDebugLoc(SmallVectorImpl<std::pair<unsigned,
-                                       MDNode*> > &MDs) const {
+  void getAllMetadataOtherThanDebugLoc(
+      SmallVectorImpl<std::pair<unsigned, Value *>> &MDs) const {
     if (hasMetadataOtherThanDebugLoc())
       getAllMetadataOtherThanDebugLocImpl(MDs);
   }
@@ -296,8 +296,8 @@ private:
   MDNode *getMDNodeImpl(StringRef Kind) const;
   void
   getAllMetadataImpl(SmallVectorImpl<std::pair<unsigned, Value *>> &) const;
-  void getAllMetadataOtherThanDebugLocImpl(SmallVectorImpl<std::pair<unsigned,
-                                           MDNode*> > &) const;
+  void getAllMetadataOtherThanDebugLocImpl(
+      SmallVectorImpl<std::pair<unsigned, Value *>> &) const;
   void clearMetadataHashEntries();
 public:
   //===--------------------------------------------------------------------===//
index 191fdc9efdc32867faea41de1492108d1be1557d..ef7a456a35ca0244db60589d91730848231c6810 100644 (file)
@@ -848,7 +848,7 @@ static void WriteMetadataAttachment(const Function &F,
 
   // Write metadata attachments
   // METADATA_ATTACHMENT - [m x [value, [n x [id, mdnode]]]
-  SmallVector<std::pair<unsigned, MDNode*>, 4> MDs;
+  SmallVector<std::pair<unsigned, Value *>, 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();
index c14591acc8adc3c03bd670a1569bef2e0a36e412..902bb27c1e9805974f80d05b613e3baac9390172 100644 (file)
@@ -321,7 +321,7 @@ ValueEnumerator::ValueEnumerator(const Module *M) {
   EnumerateValueSymbolTable(M->getValueSymbolTable());
   EnumerateNamedMetadata(M);
 
-  SmallVector<std::pair<unsigned, MDNode*>, 8> MDs;
+  SmallVector<std::pair<unsigned, Value *>, 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<MDNode>(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<std::pair<unsigned, MDNode*>, 8> MDs;
+      SmallVector<std::pair<unsigned, Value *>, 8> MDs;
       I->getAllMetadataOtherThanDebugLoc(MDs);
       for (unsigned i = 0, e = MDs.size(); i != e; ++i) {
-        MDNode *N = MDs[i].second;
+        auto *N = cast<MDNode>(MDs[i].second);
         if (N->isFunctionLocal() && N->getFunction())
           FnLocalMDVector.push_back(N);
       }
index bf375c976df5f29578347fc65b8ee8584998e50e..a2bbb563db43842e296610ed51bf32c0bde97a8e 100644 (file)
@@ -548,7 +548,7 @@ Instruction *Instruction::clone() const {
 
   // Otherwise, enumerate and copy over metadata from the old instruction to the
   // new one.
-  SmallVector<std::pair<unsigned, MDNode*>, 4> TheMDs;
+  SmallVector<std::pair<unsigned, Value *>, 4> TheMDs;
   getAllMetadataOtherThanDebugLoc(TheMDs);
   for (const auto &MD : TheMDs)
     New->setMetadata(MD.first, MD.second);
index ba86e9e60855c7c3bbcd327079c948c66e39875f..34c85004bc219a75b3177701f8380160065f65a7 100644 (file)
@@ -770,9 +770,8 @@ void Instruction::getAllMetadataImpl(
     array_pod_sort(Result.begin(), Result.end());
 }
 
-void Instruction::
-getAllMetadataOtherThanDebugLocImpl(SmallVectorImpl<std::pair<unsigned,
-                                    MDNode*> > &Result) const {
+void Instruction::getAllMetadataOtherThanDebugLocImpl(
+    SmallVectorImpl<std::pair<unsigned, Value *>> &Result) const {
   Result.clear();
   assert(hasMetadataHashEntry() &&
          getContext().pImpl->MetadataStore.count(this) &&
index 689b90389130ba1ab457efd13310d5a0fe99e9f3..d1d8e1381bebc15a4167eadd9aeeb649d3938279 100644 (file)
@@ -40,7 +40,7 @@ void TypeFinder::run(const Module &M, bool onlyNamed) {
   }
 
   // Get types from functions.
-  SmallVector<std::pair<unsigned, MDNode*>, 4> MDForInst;
+  SmallVector<std::pair<unsigned, Value *>, 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<MDNode>(MDForInst[i].second));
 
         MDForInst.clear();
       }
index 367963aebb002d466094bf75a3214c39cd9b748d..f32b1e4ef7b3f1c6cad0a8767865aa3331e20013 100644 (file)
@@ -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 <std::pair<unsigned, MDNode*>, 8> MD;
+    // FIXME: Should the DebugLoc really get dropped here?
+    SmallVector<std::pair<unsigned, Value *>, 8> MD;
     I.getAllMetadataOtherThanDebugLoc(MD);
     for (unsigned i = 0, e = MD.size(); i != e; ++i) {
       Load->setMetadata(MD[i].first, MD[i].second);
index 64e12d45bb333527a211e054e3d6a767cc077a63..0ad7cea63922eef1f075ac65fb2fa34b02ba159b 100644 (file)
@@ -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<std::pair<unsigned, MDNode *>, 4> MDs;
+  SmallVector<std::pair<unsigned, Value *>, 4> MDs;
   Op->getAllMetadataOtherThanDebugLoc(MDs);
   for (unsigned I = 0, E = CV.size(); I != E; ++I) {
     if (Instruction *New = dyn_cast<Instruction>(CV[I])) {
-      for (SmallVectorImpl<std::pair<unsigned, MDNode *> >::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());
index 7c0e4c7f214e29916de1ddaf9ac14220362389d0..c6229b1028cdebbe366bc2acef5a143488e68e0e 100644 (file)
@@ -1308,13 +1308,13 @@ bool llvm::removeUnreachableBlocks(Function &F) {
 }
 
 void llvm::combineMetadata(Instruction *K, const Instruction *J, ArrayRef<unsigned> KnownIDs) {
-  SmallVector<std::pair<unsigned, MDNode*>, 4> Metadata;
+  SmallVector<std::pair<unsigned, Value *>, 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<MDNode>(Metadata[i].second);
 
     switch (Kind) {
       default:
index 17e11724183c697a8b7e1e7c8beeb33fc1d7432d..f02cf0a55bdb3309da1dfe6560a8f675b64d3c34 100644 (file)
@@ -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<std::pair<unsigned, MDNode *>, 4> Metadata;
+  SmallVector<std::pair<unsigned, Value *>, 4> Metadata;
   From->getAllMetadataOtherThanDebugLoc(Metadata);
 
   for (auto M : Metadata) {
index 73767b46a36a8b45f92a53d54c9fff09d932ca67..5771582896dde49cf132ad141b23b14c7575d23f 100644 (file)
@@ -188,12 +188,12 @@ static void propagateIRFlags(Value *I, ArrayRef<Value *> VL) {
 /// \returns \p I after propagating metadata from \p VL.
 static Instruction *propagateMetadata(Instruction *I, ArrayRef<Value *> VL) {
   Instruction *I0 = cast<Instruction>(VL[0]);
-  SmallVector<std::pair<unsigned, MDNode *>, 4> Metadata;
+  SmallVector<std::pair<unsigned, Value *>, 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<MDNode>(Metadata[i].second);
 
     for (int i = 1, e = VL.size(); MD && i != e; i++) {
       Instruction *I = cast<Instruction>(VL[i]);