DebugInfo: Rewrite atSameLineAs() as MDLocation::canDiscriminate()
[oota-llvm.git] / include / llvm / IR / DebugInfo.h
index b193ee013a7cb5099babb803bf455f9b4097e493..9237377e2a3b66423cc795361af81a2882b544be 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.
   ///
@@ -77,26 +73,12 @@ public:
     FlagAccessibility = DebugNode::FlagAccessibility
   };
 
-  static unsigned getFlag(StringRef Flag);
-  static const char *getFlagString(unsigned Flag);
-
-  /// \brief Split up a flags bitfield.
-  ///
-  /// Split \c Flags into \c SplitFlags, a vector of its components.  Returns
-  /// any remaining (unrecognized) bits.
-  static unsigned splitFlags(unsigned Flags,
-                             SmallVectorImpl<unsigned> &SplitFlags);
-
 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(); }
@@ -159,6 +141,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:
@@ -175,25 +160,10 @@ public:
     return *get();
   }
 
-  int64_t getLo() const { return get()->getLo(); }
+  int64_t getLo() const { return get()->getLowerBound(); }
   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
@@ -221,7 +191,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.
 ///
@@ -253,8 +222,8 @@ public:
   ///
   /// If the scope node has a name, return that, else return an empty string.
   StringRef getName() const;
-  StringRef getFilename() const;
-  StringRef getDirectory() const;
+  StringRef getFilename() const { return get()->getFilename(); }
+  StringRef getDirectory() const { return get()->getDirectory(); }
 
   /// \brief Generate a reference to this DIScope.
   ///
@@ -267,17 +236,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>
@@ -288,8 +250,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 <>
@@ -298,22 +258,6 @@ 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);
-
 /// \brief This is a wrapper for a type.
 ///
 /// FIXME: Types should be factored much better so that CV qualifiers and
@@ -331,7 +275,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(); }
@@ -340,36 +284,22 @@ public:
   // carry this is just plain insane.
   uint64_t getOffsetInBits() const { return get()->getOffsetInBits(); }
   unsigned getFlags() const { return get()->getFlags(); }
-  bool isPrivate() const {
-    return (getFlags() & FlagAccessibility) == FlagPrivate;
-  }
-  bool isProtected() const {
-    return (getFlags() & FlagAccessibility) == FlagProtected;
-  }
-  bool isPublic() const {
-    return (getFlags() & FlagAccessibility) == FlagPublic;
-  }
-  bool isForwardDecl() const { return (getFlags() & FlagFwdDecl) != 0; }
-  bool isAppleBlockExtension() const {
-    return (getFlags() & FlagAppleBlock) != 0;
-  }
-  bool isBlockByrefStruct() const {
-    return (getFlags() & FlagBlockByrefStruct) != 0;
-  }
-  bool isVirtual() const { return (getFlags() & FlagVirtual) != 0; }
-  bool isArtificial() const { return (getFlags() & FlagArtificial) != 0; }
-  bool isObjectPointer() const { return (getFlags() & FlagObjectPointer) != 0; }
-  bool isObjcClassComplete() const {
-    return (getFlags() & FlagObjcClassComplete) != 0;
-  }
-  bool isVector() const { return (getFlags() & FlagVector) != 0; }
-  bool isStaticMember() const { return (getFlags() & FlagStaticMember) != 0; }
-  bool isLValueReference() const {
-    return (getFlags() & FlagLValueReference) != 0;
-  }
-  bool isRValueReference() const {
-    return (getFlags() & FlagRValueReference) != 0;
-  }
+
+  bool isPrivate() const { return get()->isPrivate(); }
+  bool isProtected() const { return get()->isProtected(); }
+  bool isPublic() const { return get()->isPublic(); }
+  bool isForwardDecl() const { return get()->isForwardDecl(); }
+  bool isAppleBlockExtension() const { return get()->isAppleBlockExtension(); }
+  bool isBlockByrefStruct() const { return get()->isBlockByrefStruct(); }
+  bool isVirtual() const { return get()->isVirtual(); }
+  bool isArtificial() const { return get()->isArtificial(); }
+  bool isObjectPointer() const { return get()->isObjectPointer(); }
+  bool isObjcClassComplete() const { return get()->isObjcClassComplete(); }
+  bool isVector() const { return get()->isVector(); }
+  bool isStaticMember() const { return get()->isStaticMember(); }
+  bool isLValueReference() const { return get()->isLValueReference(); }
+  bool isRValueReference() const { return get()->isRValueReference(); }
+
   bool isValid() const { return DbgNode && isa<MDType>(*this); }
 };
 
@@ -411,9 +341,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 {
@@ -425,8 +353,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 {
@@ -451,9 +379,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) {}
@@ -473,30 +398,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(); }
 };
 
@@ -515,9 +420,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.
@@ -618,14 +521,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);
@@ -642,42 +543,16 @@ public:
   DISubprogram getFunctionDeclaration() const {
     return DISubprogram(get()->getDeclaration());
   }
-  MDNode *getVariablesNodes() const { return getVariables(); }
   DIArray getVariables() const { return DIArray(get()->getVariables()); }
 
-  unsigned isArtificial() const { return (getFlags() & FlagArtificial) != 0; }
-  /// \brief Check for the "private" access specifier.
-  bool isPrivate() const {
-    return (getFlags() & FlagAccessibility) == FlagPrivate;
-  }
-  /// \brief Check for the "protected" access specifier.
-  bool isProtected() const {
-    return (getFlags() & FlagAccessibility) == FlagProtected;
-  }
-  /// \brief Check for the "public" access specifier.
-  bool isPublic() const {
-    return (getFlags() & FlagAccessibility) == FlagPublic;
-  }
-  /// \brief Check for "explicit".
-  bool isExplicit() const { return (getFlags() & FlagExplicit) != 0; }
-  /// \brief Check if this is prototyped.
-  bool isPrototyped() const { return (getFlags() & FlagPrototyped) != 0; }
-
-  /// \brief Check if this is reference-qualified.
-  ///
-  /// Return true if this subprogram is a C++11 reference-qualified non-static
-  /// member function (void foo() &).
-  unsigned isLValueReference() const {
-    return (getFlags() & FlagLValueReference) != 0;
-  }
-
-  /// \brief Check if this is rvalue-reference-qualified.
-  ///
-  /// Return true if this subprogram is a C++11 rvalue-reference-qualified
-  /// non-static member function (void foo() &&).
-  unsigned isRValueReference() const {
-    return (getFlags() & FlagRValueReference) != 0;
-  }
+  unsigned isArtificial() const { return get()->isArtificial(); }
+  bool isPrivate() const { return get()->isPrivate(); }
+  bool isProtected() const { return get()->isProtected(); }
+  bool isPublic() const { return get()->isPublic(); }
+  bool isExplicit() const { return get()->isExplicit(); }
+  bool isPrototyped() const { return get()->isPrototyped(); }
+  unsigned isLValueReference() const { return get()->isLValueReference(); }
+  unsigned isRValueReference() const { return get()->isRValueReference(); }
 };
 
 /// \brief This is a wrapper for a lexical block.
@@ -767,8 +642,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.
@@ -789,7 +663,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(); }
 };
 
@@ -819,9 +693,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 {
@@ -859,16 +733,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()); }
@@ -909,78 +777,11 @@ public:
     return *get();
   }
 
-  /// \brief Return the number of elements in the complex expression.
   unsigned getNumElements() const { return get()->getNumElements(); }
-
-  /// \brief return the Idx'th complex address element.
   uint64_t getElement(unsigned I) const { return get()->getElement(I); }
-
-  /// \brief Return whether this is a piece of an aggregate variable.
-  bool isBitPiece() const;
-  /// \brief Return the offset of this piece in bits.
-  uint64_t getBitPieceOffset() const;
-  /// \brief Return the size of this piece in bits.
-  uint64_t getBitPieceSize() const;
-
-  class iterator;
-  /// \brief A lightweight wrapper around an element of a DIExpression.
-  class Operand {
-    friend class iterator;
-    MDExpression::element_iterator I;
-    Operand() {}
-    Operand(MDExpression::element_iterator I) : I(I) {}
-  public:
-    /// \brief Operands such as DW_OP_piece have explicit (non-stack) arguments.
-    /// Argument 0 is the operand itself.
-    uint64_t getArg(unsigned N) const {
-      MDExpression::element_iterator In = I;
-      std::advance(In, N);
-      return *In;
-    }
-    operator uint64_t () const { return *I; }
-    /// \brief Returns underlying MDExpression::element_iterator.
-    const MDExpression::element_iterator &getBase() const { return I; }
-    /// \brief Returns the next operand.
-    iterator getNext() const;
-  };
-
-  /// \brief An iterator for DIExpression elements.
-  class iterator : public std::iterator<std::input_iterator_tag, StringRef,
-                                        unsigned, const Operand*, Operand> {
-    friend class Operand;
-    MDExpression::element_iterator I;
-    Operand Tmp;
-
-  public:
-    iterator(MDExpression::element_iterator I) : I(I) {}
-    const Operand &operator*() { return Tmp = Operand(I); }
-    const Operand *operator->() { return &(Tmp = Operand(I)); }
-    iterator &operator++() {
-      increment();
-      return *this;
-    }
-    iterator operator++(int) {
-      iterator X(*this);
-      increment();
-      return X;
-    }
-    bool operator==(const iterator &X) const { return I == X.I; }
-    bool operator!=(const iterator &X) const { return !(*this == X); }
-
-  private:
-    void increment() {
-      switch (**this) {
-      case dwarf::DW_OP_bit_piece: std::advance(I, 3); break;
-      case dwarf::DW_OP_plus:      std::advance(I, 2); break;
-      case dwarf::DW_OP_deref:     std::advance(I, 1); break;
-      default:
-        llvm_unreachable("unsupported operand");
-      }
-    }
-  };
-
-  iterator begin() const { return get()->elements_begin(); }
-  iterator end() const { return get()->elements_end(); }
+  bool isBitPiece() const { return get()->isBitPiece(); }
+  uint64_t getBitPieceOffset() const { return get()->getBitPieceOffset(); }
+  uint64_t getBitPieceSize() const { return get()->getBitPieceSize(); }
 };
 
 /// \brief This object holds location information.
@@ -1007,12 +808,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
@@ -1102,9 +900,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(); }
 };