Add a comment to describe why vector shuffles are legalized to custom DAG nodes.
[oota-llvm.git] / lib / VMCore / LLVMContext.cpp
index 22882711a06dcea21e11a77bbd09cdff4729a8ad..aa9dc3671a089b10ff15c43a8847949c197b4905 100644 (file)
@@ -8,18 +8,16 @@
 //===----------------------------------------------------------------------===//
 //
 //  This file implements LLVMContext, as a wrapper around the opaque
-// struct LLVMContextImpl.
+//  class LLVMContextImpl.
 //
 //===----------------------------------------------------------------------===//
 
 #include "llvm/LLVMContext.h"
 #include "llvm/Constants.h"
-#include "llvm/DerivedTypes.h"
 #include "llvm/Instruction.h"
-#include "llvm/Metadata.h"
 #include "llvm/Support/ManagedStatic.h"
 #include "LLVMContextImpl.h"
-#include <cstdarg>
+#include <set>
 
 using namespace llvm;
 
@@ -44,3 +42,27 @@ GetElementPtrConstantExpr::GetElementPtrConstantExpr
   for (unsigned i = 0, E = IdxList.size(); i != E; ++i)
     OperandList[i+1] = IdxList[i];
 }
+
+bool LLVMContext::RemoveDeadMetadata() {
+  std::vector<const MDNode *> DeadMDNodes;
+  bool Changed = false;
+  while (1) {
+
+    for (LLVMContextImpl::MDNodeMapTy::MapTy::iterator
+           I = pImpl->MDNodes.map_begin(),
+           E = pImpl->MDNodes.map_end(); I != E; ++I) {
+      const MDNode *N = cast<MDNode>(I->second);
+      if (N->use_empty()) 
+        DeadMDNodes.push_back(N);
+    }
+    
+    if (DeadMDNodes.empty())
+      return Changed;
+
+    while (!DeadMDNodes.empty()) {
+      const MDNode *N = DeadMDNodes.back(); DeadMDNodes.pop_back();
+      delete N;
+    }
+  }
+  return Changed;
+}