DebugInfo: Remove dead DIDescriptor::getDescriptorField()
[oota-llvm.git] / lib / IR / DebugInfo.cpp
index 42537d0fa98fffb2e5daa6632980f9b5e6bca145..70a6722568591129b69b732595f2ea3baa994c3a 100644 (file)
 using namespace llvm;
 using namespace llvm::dwarf;
 
-//===----------------------------------------------------------------------===//
-// DIDescriptor
-//===----------------------------------------------------------------------===//
-
-static Metadata *getField(const MDNode *DbgNode, unsigned Elt) {
-  if (!DbgNode || Elt >= DbgNode->getNumOperands())
-    return nullptr;
-  return DbgNode->getOperand(Elt);
-}
-
-static MDNode *getNodeField(const MDNode *DbgNode, unsigned Elt) {
-  return dyn_cast_or_null<MDNode>(getField(DbgNode, Elt));
-}
-
-DIDescriptor DIDescriptor::getDescriptorField(unsigned Elt) const {
-  MDNode *Field = getNodeField(DbgNode, Elt);
-  return DIDescriptor(Field);
-}
-
 /// \brief Return the size reported by the variable's type.
 unsigned DIVariable::getSizeInBits(const DITypeIdentifierMap &Map) {
   DIType Ty = getType().resolve(Map);
@@ -96,35 +77,6 @@ void DIDescriptor::replaceAllUsesWith(MDNode *D) {
   Node->replaceAllUsesWith(D);
 }
 
-#ifndef NDEBUG
-/// \brief Check if a value can be a reference to a type.
-static bool isTypeRef(const Metadata *MD) {
-  if (!MD)
-    return true;
-  if (auto *S = dyn_cast<MDString>(MD))
-    return !S->getString().empty();
-  return isa<MDType>(MD);
-}
-
-/// \brief Check if a value can be a ScopeRef.
-static bool isScopeRef(const Metadata *MD) {
-  if (!MD)
-    return true;
-  if (auto *S = dyn_cast<MDString>(MD))
-    return !S->getString().empty();
-  return isa<MDScope>(MD);
-}
-
-/// \brief Check if a value can be a DescriptorRef.
-static bool isDescriptorRef(const Metadata *MD) {
-  if (!MD)
-    return true;
-  if (auto *S = dyn_cast<MDString>(MD))
-    return !S->getString().empty();
-  return isa<MDNode>(MD);
-}
-#endif
-
 DIScopeRef DIScope::getRef() const { return MDScopeRef::get(get()); }
 
 bool DIVariable::isInlinedFnArgument(const Function *CurFn) {
@@ -165,17 +117,17 @@ DIScopeRef DIScope::getContext() const {
     return T.getContext();
 
   if (DISubprogram SP = dyn_cast<MDSubprogram>(*this))
-    return DIScopeRef(SP.getContext());
+    return MDScopeRef(SP.getContext());
 
   if (DILexicalBlock LB = dyn_cast<MDLexicalBlockBase>(*this))
-    return DIScopeRef(LB.getContext());
+    return MDScopeRef(LB.getContext());
 
   if (DINameSpace NS = dyn_cast<MDNamespace>(*this))
-    return DIScopeRef(NS.getContext());
+    return MDScopeRef(NS.getContext());
 
   assert((isa<MDFile>(*this) || isa<MDCompileUnit>(*this)) &&
          "Unhandled type of scope.");
-  return DIScopeRef(nullptr);
+  return MDScopeRef();
 }
 
 StringRef DIScope::getName() const {
@@ -206,11 +158,11 @@ StringRef DIScope::getDirectory() const {
 }
 
 void DICompileUnit::replaceSubprograms(DIArray Subprograms) {
-  get()->replaceSubprograms(Subprograms);
+  get()->replaceSubprograms(MDSubprogramArray(Subprograms));
 }
 
 void DICompileUnit::replaceGlobalVariables(DIArray GlobalVariables) {
-  get()->replaceGlobalVariables(GlobalVariables);
+  get()->replaceGlobalVariables(MDGlobalVariableArray(GlobalVariables));
 }
 
 DILocation DILocation::copyWithNewScope(LLVMContext &Ctx,
@@ -564,29 +516,6 @@ void DIVariable::printExtendedName(raw_ostream &OS) const {
   }
 }
 
-template <> DIRef<DIDescriptor>::DIRef(const Metadata *V) : Val(V) {
-  assert(isDescriptorRef(V) &&
-         "DIDescriptorRef should be a MDString or MDNode");
-}
-template <> DIRef<DIScope>::DIRef(const Metadata *V) : Val(V) {
-  assert(isScopeRef(V) && "DIScopeRef should be a MDString or MDNode");
-}
-template <> DIRef<DIType>::DIRef(const Metadata *V) : Val(V) {
-  assert(isTypeRef(V) && "DITypeRef should be a MDString or MDNode");
-}
-
-template <>
-DIDescriptorRef DIDescriptor::getFieldAs<DIDescriptorRef>(unsigned Elt) const {
-  return DIDescriptorRef(cast_or_null<Metadata>(getField(DbgNode, Elt)));
-}
-template <>
-DIScopeRef DIDescriptor::getFieldAs<DIScopeRef>(unsigned Elt) const {
-  return DIScopeRef(cast_or_null<Metadata>(getField(DbgNode, Elt)));
-}
-template <> DITypeRef DIDescriptor::getFieldAs<DITypeRef>(unsigned Elt) const {
-  return DITypeRef(cast_or_null<Metadata>(getField(DbgNode, Elt)));
-}
-
 template <>
 DIDescriptor
 DIRef<DIDescriptor>::resolve(const DITypeIdentifierMap &Map) const {