DebugInfo: Remove dead DIDescriptor::replaceAllUsesWith()
[oota-llvm.git] / include / llvm / IR / DebugInfo.h
index bfb725f65bcbce413083a60b3e13ca40259dc995..33bb225db19fef3812d07282027486a44697689a 100644 (file)
@@ -63,10 +63,6 @@ typedef DenseMap<const MDString *, MDNode *> DITypeIdentifierMap;
 /// This should not be stored in a container, because the underlying MDNode may
 /// change in certain situations.
 class DIDescriptor {
-  // Befriends DIRef so DIRef can befriend the protected member
-  // function: getFieldAs<DIRef>.
-  template <typename T> friend class DIRef;
-
 public:
   /// \brief Duplicated debug info flags.
   ///
@@ -80,13 +76,9 @@ public:
 protected:
   const MDNode *DbgNode;
 
-  DIDescriptor getDescriptorField(unsigned Elt) const;
-  template <typename DescTy> DescTy getFieldAs(unsigned Elt) const {
-    return DescTy(getDescriptorField(Elt));
-  }
-
 public:
   explicit DIDescriptor(const MDNode *N = nullptr) : DbgNode(N) {}
+  DIDescriptor(const DebugNode *N) : DbgNode(N) {}
 
   MDNode *get() const { return const_cast<MDNode *>(DbgNode); }
   operator MDNode *() const { return get(); }
@@ -114,10 +106,6 @@ public:
 
   void print(raw_ostream &OS) const;
   void dump() const;
-
-  /// \brief Replace all uses of debug info referenced by this descriptor.
-  void replaceAllUsesWith(LLVMContext &VMContext, DIDescriptor D);
-  void replaceAllUsesWith(MDNode *D);
 };
 
 #define DECLARE_SIMPLIFY_DESCRIPTOR(DESC)                                      \
@@ -149,6 +137,9 @@ DECLARE_SIMPLIFY_DESCRIPTOR(DIObjCProperty)
 DECLARE_SIMPLIFY_DESCRIPTOR(DIImportedEntity)
 #undef DECLARE_SIMPLIFY_DESCRIPTOR
 
+typedef DebugNodeArray DIArray;
+typedef MDTypeRefArray DITypeArray;
+
 /// \brief This is used to represent ranges, for array bounds.
 class DISubrange : public DIDescriptor {
 public:
@@ -169,21 +160,6 @@ public:
   int64_t getCount() const { return get()->getCount(); }
 };
 
-/// \brief This descriptor holds an array of nodes with type T.
-template <typename T> class DITypedArray : public DIDescriptor {
-public:
-  explicit DITypedArray(const MDNode *N = nullptr) : DIDescriptor(N) {}
-  operator MDTuple *() const {
-    return const_cast<MDTuple *>(cast_or_null<MDTuple>(DbgNode));
-  }
-  unsigned getNumElements() const {
-    return DbgNode ? DbgNode->getNumOperands() : 0;
-  }
-  T getElement(unsigned Idx) const { return getFieldAs<T>(Idx); }
-};
-
-typedef DITypedArray<DIDescriptor> DIArray;
-
 /// \brief A wrapper for an enumerator (e.g. X and Y in 'enum {X,Y}').
 ///
 /// FIXME: it seems strange that this doesn't have either a reference to the
@@ -211,7 +187,6 @@ template <typename T> class DIRef;
 typedef DIRef<DIDescriptor> DIDescriptorRef;
 typedef DIRef<DIScope> DIScopeRef;
 typedef DIRef<DIType> DITypeRef;
-typedef DITypedArray<DITypeRef> DITypeArray;
 
 /// \brief A base class for various scopes.
 ///
@@ -234,17 +209,10 @@ public:
     return *get();
   }
 
-  /// \brief Get the parent scope.
-  ///
-  /// Gets the parent scope for this scope node or returns a default
-  /// constructed scope.
-  DIScopeRef getContext() const;
-  /// \brief Get the scope name.
-  ///
-  /// If the scope node has a name, return that, else return an empty string.
-  StringRef getName() const;
-  StringRef getFilename() const;
-  StringRef getDirectory() const;
+  inline DIScopeRef getContext() const;
+  StringRef getName() const { return get()->getName(); }
+  StringRef getFilename() const { return get()->getFilename(); }
+  StringRef getDirectory() const { return get()->getDirectory(); }
 
   /// \brief Generate a reference to this DIScope.
   ///
@@ -257,17 +225,10 @@ public:
 ///
 /// Abstracts over direct and identifier-based metadata references.
 template <typename T> class DIRef {
-  template <typename DescTy>
-  friend DescTy DIDescriptor::getFieldAs(unsigned Elt) const;
-  friend DIScopeRef DIScope::getContext() const;
-  friend DIScopeRef DIScope::getRef() const;
-  friend class DIType;
-
   /// \brief Val can be either a MDNode or a MDString.
   ///
   /// In the latter, MDString specifies the type identifier.
   const Metadata *Val;
-  explicit DIRef(const Metadata *V);
 
 public:
   template <class U>
@@ -278,8 +239,6 @@ public:
 
   T resolve(const DITypeIdentifierMap &Map) const;
   operator Metadata *() const { return const_cast<Metadata *>(Val); }
-
-  static DIRef get(const Metadata *MD) { return DIRef(MD); }
 };
 
 template <>
@@ -288,21 +247,7 @@ template <>
 DIScope DIRef<DIScope>::resolve(const DITypeIdentifierMap &Map) const;
 template <> DIType DIRef<DIType>::resolve(const DITypeIdentifierMap &Map) const;
 
-/// \brief Handle fields that are references to DIDescriptors.
-template <>
-DIDescriptorRef DIDescriptor::getFieldAs<DIDescriptorRef>(unsigned Elt) const;
-/// \brief Specialize DIRef constructor for DIDescriptorRef.
-template <> DIRef<DIDescriptor>::DIRef(const Metadata *V);
-
-/// \brief Handle fields that are references to DIScopes.
-template <> DIScopeRef DIDescriptor::getFieldAs<DIScopeRef>(unsigned Elt) const;
-/// \brief Specialize DIRef constructor for DIScopeRef.
-template <> DIRef<DIScope>::DIRef(const Metadata *V);
-
-/// \brief Handle fields that are references to DITypes.
-template <> DITypeRef DIDescriptor::getFieldAs<DITypeRef>(unsigned Elt) const;
-/// \brief Specialize DIRef constructor for DITypeRef.
-template <> DIRef<DIType>::DIRef(const Metadata *V);
+DIScopeRef DIScope::getContext() const { return get()->getScope(); }
 
 /// \brief This is a wrapper for a type.
 ///
@@ -321,7 +266,7 @@ public:
     return *get();
   }
 
-  DIScopeRef getContext() const { return DIScopeRef::get(get()->getScope()); }
+  DIScopeRef getContext() const { return get()->getScope(); }
   StringRef getName() const { return get()->getName(); }
   unsigned getLineNumber() const { return get()->getLine(); }
   uint64_t getSizeInBits() const { return get()->getSizeInBits(); }
@@ -387,9 +332,7 @@ public:
     return *get();
   }
 
-  DITypeRef getTypeDerivedFrom() const {
-    return DITypeRef::get(get()->getBaseType());
-  }
+  DITypeRef getTypeDerivedFrom() const { return get()->getBaseType(); }
 
   /// \brief Return property node, if this ivar is associated with one.
   MDNode *getObjCProperty() const {
@@ -401,8 +344,8 @@ public:
   DITypeRef getClassType() const {
     assert(getTag() == dwarf::DW_TAG_ptr_to_member_type);
     if (auto *N = dyn_cast<MDDerivedType>(get()))
-      return DITypeRef::get(N->getExtraData());
-    return DITypeRef::get(nullptr);
+      return MDTypeRef(N->getExtraData());
+    return MDTypeRef();
   }
 
   Constant *getConstant() const {
@@ -427,9 +370,6 @@ public:
 class DICompositeType : public DIDerivedType {
   friend class DIBuilder;
 
-  /// \brief Set the array of member DITypes.
-  void setArraysHelper(MDNode *Elements, MDNode *TParams);
-
 public:
   DICompositeType() = default;
   DICompositeType(const MDCompositeTypeBase *N) : DIDerivedType(N) {}
@@ -449,30 +389,10 @@ public:
     return DIArray(get()->getElements());
   }
 
-private:
-  template <typename T>
-  void setArrays(DITypedArray<T> Elements, DIArray TParams = DIArray()) {
-    assert(
-        (!TParams || DbgNode->getNumOperands() == 8) &&
-        "If you're setting the template parameters this should include a slot "
-        "for that!");
-    setArraysHelper(Elements, TParams);
-  }
-
-public:
   unsigned getRunTimeLang() const { return get()->getRuntimeLang(); }
-  DITypeRef getContainingType() const {
-    return DITypeRef::get(get()->getVTableHolder());
-  }
-
-private:
-  /// \brief Set the containing type.
-  void setContainingType(DICompositeType ContainingType);
+  DITypeRef getContainingType() const { return get()->getVTableHolder(); }
 
-public:
-  DIArray getTemplateParams() const {
-    return DIArray(get()->getTemplateParams());
-  }
+  DIArray getTemplateParams() const { return get()->getTemplateParams(); }
   MDString *getIdentifier() const { return get()->getRawIdentifier(); }
 };
 
@@ -491,9 +411,7 @@ public:
     return *get();
   }
 
-  DITypedArray<DITypeRef> getTypeArray() const {
-    return DITypedArray<DITypeRef>(get()->getTypeArray());
-  }
+  MDTypeRefArray getTypeArray() const { return get()->getTypeArray(); }
 };
 
 /// \brief This is a wrapper for a file.
@@ -594,14 +512,12 @@ public:
   /// \brief Get the beginning of the scope of the function (not the name).
   unsigned getScopeLineNumber() const { return get()->getScopeLine(); }
 
-  DIScopeRef getContext() const { return DIScopeRef::get(get()->getScope()); }
+  DIScopeRef getContext() const { return get()->getScope(); }
   DISubroutineType getType() const {
     return DISubroutineType(get()->getType());
   }
 
-  DITypeRef getContainingType() const {
-    return DITypeRef::get(get()->getContainingType());
-  }
+  DITypeRef getContainingType() const { return get()->getContainingType(); }
 
   /// \brief Check if this provides debugging information for the function F.
   bool describes(const Function *F);
@@ -618,7 +534,6 @@ public:
   DISubprogram getFunctionDeclaration() const {
     return DISubprogram(get()->getDeclaration());
   }
-  MDNode *getVariablesNodes() const { return getVariables(); }
   DIArray getVariables() const { return DIArray(get()->getVariables()); }
 
   unsigned isArtificial() const { return get()->isArtificial(); }
@@ -718,8 +633,7 @@ public:
   }
 
   StringRef getName() const { return get()->getName(); }
-
-  DITypeRef getType() const { return DITypeRef::get(get()->getType()); }
+  DITypeRef getType() const { return get()->getType(); }
 };
 
 /// \brief This is a wrapper for template value parameter.
@@ -740,7 +654,7 @@ public:
   }
 
   StringRef getName() const { return get()->getName(); }
-  DITypeRef getType() const { return DITypeRef::get(get()->getType()); }
+  DITypeRef getType() const { return get()->getType(); }
   Metadata *getValue() const { return get()->getValue(); }
 };
 
@@ -770,9 +684,9 @@ public:
   unsigned isDefinition() const { return get()->isDefinition(); }
 
   DIScope getContext() const { return DIScope(get()->getScope()); }
-  StringRef getFilename() const { return getFile().getFilename(); }
-  StringRef getDirectory() const { return getFile().getDirectory(); }
-  DITypeRef getType() const { return DITypeRef::get(get()->getType()); }
+  StringRef getFilename() const { return get()->getFilename(); }
+  StringRef getDirectory() const { return get()->getDirectory(); }
+  DITypeRef getType() const { return get()->getType(); }
 
   GlobalVariable *getGlobal() const;
   Constant *getConstant() const {
@@ -810,16 +724,10 @@ public:
 
   DIScope getContext() const { return DIScope(get()->getScope()); }
   DIFile getFile() const { return DIFile(get()->getFile()); }
-  DITypeRef getType() const { return DITypeRef::get(get()->getType()); }
+  DITypeRef getType() const { return get()->getType(); }
 
-  /// \brief Return true if this variable is marked as "artificial".
-  bool isArtificial() const {
-    return (getFlags() & FlagArtificial) != 0;
-  }
-
-  bool isObjectPointer() const {
-    return (getFlags() & FlagObjectPointer) != 0;
-  }
+  bool isArtificial() const { return get()->isArtificial(); }
+  bool isObjectPointer() const { return get()->isObjectPointer(); }
 
   /// \brief If this variable is inlined then return inline location.
   MDNode *getInlinedAt() const { return DIDescriptor(get()->getInlinedAt()); }
@@ -891,12 +799,9 @@ public:
   DILocation getOrigLocation() const {
     return DILocation(get()->getInlinedAt());
   }
-  StringRef getFilename() const { return getScope().getFilename(); }
-  StringRef getDirectory() const { return getScope().getDirectory(); }
-  bool atSameLineAs(const DILocation &Other) const {
-    return (getLineNumber() == Other.getLineNumber() &&
-            getFilename() == Other.getFilename());
-  }
+  StringRef getFilename() const { return get()->getFilename(); }
+  StringRef getDirectory() const { return get()->getDirectory(); }
+
   /// \brief Get the DWAF discriminator.
   ///
   /// DWARF discriminators are used to distinguish identical file locations for
@@ -986,9 +891,7 @@ public:
   }
 
   DIScope getContext() const { return DIScope(get()->getScope()); }
-  DIDescriptorRef getEntity() const {
-    return DIDescriptorRef::get(get()->getEntity());
-  }
+  DIDescriptorRef getEntity() const { return get()->getEntity(); }
   unsigned getLineNumber() const { return get()->getLine(); }
   StringRef getName() const { return get()->getName(); }
 };