DebugInfo: Move DILocation::computeNewDiscriminators()
[oota-llvm.git] / include / llvm / IR / DebugInfo.h
index f4f6bd3ecde561a48135218c8ae4ade5fd9164ef..6fcf1ee65cd3943b7e6585e571ed61ef2109a680 100644 (file)
@@ -83,10 +83,7 @@ public:
   MDNode *get() const { return const_cast<MDNode *>(DbgNode); }
   operator MDNode *() const { return get(); }
   MDNode *operator->() const { return get(); }
-  MDNode &operator*() const {
-    assert(get() && "Expected valid pointer");
-    return *get();
-  }
+  MDNode &operator*() const { return *get(); }
 
   // An explicit operator bool so that we can do testing of DI values
   // easily.
@@ -151,10 +148,7 @@ public:
   }
   operator MDSubrange *() const { return get(); }
   MDSubrange *operator->() const { return get(); }
-  MDSubrange &operator*() const {
-    assert(get() && "Expected valid pointer");
-    return *get();
-  }
+  MDSubrange &operator*() const { return *get(); }
 
   int64_t getLo() const { return get()->getLowerBound(); }
   int64_t getCount() const { return get()->getCount(); }
@@ -174,10 +168,7 @@ public:
   }
   operator MDEnumerator *() const { return get(); }
   MDEnumerator *operator->() const { return get(); }
-  MDEnumerator &operator*() const {
-    assert(get() && "Expected valid pointer");
-    return *get();
-  }
+  MDEnumerator &operator*() const { return *get(); }
 
   StringRef getName() const { return get()->getName(); }
   int64_t getEnumValue() const { return get()->getValue(); }
@@ -204,10 +195,7 @@ public:
   MDScope *get() const { return cast_or_null<MDScope>(DIDescriptor::get()); }
   operator MDScope *() const { return get(); }
   MDScope *operator->() const { return get(); }
-  MDScope &operator*() const {
-    assert(get() && "Expected valid pointer");
-    return *get();
-  }
+  MDScope &operator*() const { return *get(); }
 
   inline DIScopeRef getContext() const;
   StringRef getName() const { return get()->getName(); }
@@ -261,10 +249,7 @@ public:
   MDType *get() const { return cast_or_null<MDType>(DIDescriptor::get()); }
   operator MDType *() const { return get(); }
   MDType *operator->() const { return get(); }
-  MDType &operator*() const {
-    assert(get() && "Expected valid pointer");
-    return *get();
-  }
+  MDType &operator*() const { return *get(); }
 
   DIScopeRef getContext() const { return get()->getScope(); }
   StringRef getName() const { return get()->getName(); }
@@ -305,10 +290,7 @@ public:
   }
   operator MDBasicType *() const { return get(); }
   MDBasicType *operator->() const { return get(); }
-  MDBasicType &operator*() const {
-    assert(get() && "Expected valid pointer");
-    return *get();
-  }
+  MDBasicType &operator*() const { return *get(); }
 
   unsigned getEncoding() const { return get()->getEncoding(); }
 };
@@ -327,34 +309,21 @@ public:
   }
   operator MDDerivedTypeBase *() const { return get(); }
   MDDerivedTypeBase *operator->() const { return get(); }
-  MDDerivedTypeBase &operator*() const {
-    assert(get() && "Expected valid pointer");
-    return *get();
-  }
+  MDDerivedTypeBase &operator*() const { return *get(); }
 
   DITypeRef getTypeDerivedFrom() const { return get()->getBaseType(); }
 
   /// \brief Return property node, if this ivar is associated with one.
-  MDNode *getObjCProperty() const {
-    if (auto *N = dyn_cast<MDDerivedType>(get()))
-      return dyn_cast_or_null<MDNode>(N->getExtraData());
-    return nullptr;
+  MDObjCProperty *getObjCProperty() const {
+    return cast<MDDerivedType>(get())->getObjCProperty();
   }
 
   DITypeRef getClassType() const {
-    assert(getTag() == dwarf::DW_TAG_ptr_to_member_type);
-    if (auto *N = dyn_cast<MDDerivedType>(get()))
-      return MDTypeRef(N->getExtraData());
-    return MDTypeRef();
+    return cast<MDDerivedType>(get())->getClassType();
   }
 
   Constant *getConstant() const {
-    assert((getTag() == dwarf::DW_TAG_member) && isStaticMember());
-    if (auto *N = dyn_cast<MDDerivedType>(get()))
-      if (auto *C = dyn_cast_or_null<ConstantAsMetadata>(N->getExtraData()))
-        return C->getValue();
-
-    return nullptr;
+    return cast<MDDerivedType>(get())->getConstant();
   }
 };
 
@@ -379,10 +348,7 @@ public:
   }
   operator MDCompositeTypeBase *() const { return get(); }
   MDCompositeTypeBase *operator->() const { return get(); }
-  MDCompositeTypeBase &operator*() const {
-    assert(get() && "Expected valid pointer");
-    return *get();
-  }
+  MDCompositeTypeBase &operator*() const { return *get(); }
 
   DIArray getElements() const {
     assert(!isa<MDSubroutineType>(*this) && "no elements for DISubroutineType");
@@ -406,10 +372,7 @@ public:
   }
   operator MDSubroutineType *() const { return get(); }
   MDSubroutineType *operator->() const { return get(); }
-  MDSubroutineType &operator*() const {
-    assert(get() && "Expected valid pointer");
-    return *get();
-  }
+  MDSubroutineType &operator*() const { return *get(); }
 
   MDTypeRefArray getTypeArray() const { return get()->getTypeArray(); }
 };
@@ -423,10 +386,7 @@ public:
   MDFile *get() const { return cast_or_null<MDFile>(DIDescriptor::get()); }
   operator MDFile *() const { return get(); }
   MDFile *operator->() const { return get(); }
-  MDFile &operator*() const {
-    assert(get() && "Expected valid pointer");
-    return *get();
-  }
+  MDFile &operator*() const { return *get(); }
 
   /// \brief Retrieve the MDNode for the directory/file pair.
   MDNode *getFileNode() const { return get(); }
@@ -443,10 +403,7 @@ public:
   }
   operator MDCompileUnit *() const { return get(); }
   MDCompileUnit *operator->() const { return get(); }
-  MDCompileUnit &operator*() const {
-    assert(get() && "Expected valid pointer");
-    return *get();
-  }
+  MDCompileUnit &operator*() const { return *get(); }
 
   dwarf::SourceLanguage getLanguage() const {
     return static_cast<dwarf::SourceLanguage>(get()->getSourceLanguage());
@@ -456,17 +413,11 @@ public:
   StringRef getFlags() const { return get()->getFlags(); }
   unsigned getRunTimeVersion() const { return get()->getRuntimeVersion(); }
 
-  DIArray getEnumTypes() const { return DIArray(get()->getEnumTypes()); }
-  DIArray getRetainedTypes() const {
-    return DIArray(get()->getRetainedTypes());
-  }
-  DIArray getSubprograms() const { return DIArray(get()->getSubprograms()); }
-  DIArray getGlobalVariables() const {
-    return DIArray(get()->getGlobalVariables());
-  }
-  DIArray getImportedEntities() const {
-    return DIArray(get()->getImportedEntities());
-  }
+  DIArray getEnumTypes() const { return get()->getEnumTypes(); }
+  DIArray getRetainedTypes() const { return get()->getRetainedTypes(); }
+  DIArray getSubprograms() const { return get()->getSubprograms(); }
+  DIArray getGlobalVariables() const { return get()->getGlobalVariables(); }
+  DIArray getImportedEntities() const { return get()->getImportedEntities(); }
 
   void replaceSubprograms(DIArray Subprograms);
   void replaceGlobalVariables(DIArray GlobalVariables);
@@ -488,10 +439,7 @@ public:
   }
   operator MDSubprogram *() const { return get(); }
   MDSubprogram *operator->() const { return get(); }
-  MDSubprogram &operator*() const {
-    assert(get() && "Expected valid pointer");
-    return *get();
-  }
+  MDSubprogram &operator*() const { return *get(); }
 
   StringRef getName() const { return get()->getName(); }
   StringRef getDisplayName() const { return get()->getDisplayName(); }
@@ -513,9 +461,7 @@ public:
   unsigned getScopeLineNumber() const { return get()->getScopeLine(); }
 
   DIScopeRef getContext() const { return get()->getScope(); }
-  DISubroutineType getType() const {
-    return DISubroutineType(get()->getType());
-  }
+  DISubroutineType getType() const { return get()->getType(); }
 
   DITypeRef getContainingType() const { return get()->getContainingType(); }
 
@@ -524,15 +470,10 @@ public:
 
   Function *getFunction() const { return get()->getFunction(); }
 
-  void replaceFunction(Function *F) {
-    if (auto *N = get())
-      N->replaceFunction(F);
-  }
-  DIArray getTemplateParams() const {
-    return DIArray(get()->getTemplateParams());
-  }
+  void replaceFunction(Function *F) { get()->replaceFunction(F); }
+  DIArray getTemplateParams() const { return get()->getTemplateParams(); }
   DISubprogram getFunctionDeclaration() const {
-    return DISubprogram(get()->getDeclaration());
+    return get()->getDeclaration();
   }
   DIArray getVariables() const { return DIArray(get()->getVariables()); }
 
@@ -557,10 +498,7 @@ public:
   }
   operator MDLexicalBlockBase *() const { return get(); }
   MDLexicalBlockBase *operator->() const { return get(); }
-  MDLexicalBlockBase &operator*() const {
-    assert(get() && "Expected valid pointer");
-    return *get();
-  }
+  MDLexicalBlockBase &operator*() const { return *get(); }
 
   DIScope getContext() const { return DIScope(get()->getScope()); }
   unsigned getLineNumber() const {
@@ -586,10 +524,7 @@ public:
   }
   operator MDLexicalBlockFile *() const { return get(); }
   MDLexicalBlockFile *operator->() const { return get(); }
-  MDLexicalBlockFile &operator*() const {
-    assert(get() && "Expected valid pointer");
-    return *get();
-  }
+  MDLexicalBlockFile &operator*() const { return *get(); }
 
   DIScope getContext() const { return get()->getScope(); }
   unsigned getDiscriminator() const { return get()->getDiscriminator(); }
@@ -606,10 +541,7 @@ public:
   }
   operator MDNamespace *() const { return get(); }
   MDNamespace *operator->() const { return get(); }
-  MDNamespace &operator*() const {
-    assert(get() && "Expected valid pointer");
-    return *get();
-  }
+  MDNamespace &operator*() const { return *get(); }
 
   StringRef getName() const { return get()->getName(); }
   unsigned getLineNumber() const { return get()->getLine(); }
@@ -627,10 +559,7 @@ public:
   }
   operator MDTemplateTypeParameter *() const { return get(); }
   MDTemplateTypeParameter *operator->() const { return get(); }
-  MDTemplateTypeParameter &operator*() const {
-    assert(get() && "Expected valid pointer");
-    return *get();
-  }
+  MDTemplateTypeParameter &operator*() const { return *get(); }
 
   StringRef getName() const { return get()->getName(); }
   DITypeRef getType() const { return get()->getType(); }
@@ -648,10 +577,7 @@ public:
   }
   operator MDTemplateValueParameter *() const { return get(); }
   MDTemplateValueParameter *operator->() const { return get(); }
-  MDTemplateValueParameter &operator*() const {
-    assert(get() && "Expected valid pointer");
-    return *get();
-  }
+  MDTemplateValueParameter &operator*() const { return *get(); }
 
   StringRef getName() const { return get()->getName(); }
   DITypeRef getType() const { return get()->getType(); }
@@ -671,10 +597,7 @@ public:
   }
   operator MDGlobalVariable *() const { return get(); }
   MDGlobalVariable *operator->() const { return get(); }
-  MDGlobalVariable &operator*() const {
-    assert(get() && "Expected valid pointer");
-    return *get();
-  }
+  MDGlobalVariable &operator*() const { return *get(); }
 
   StringRef getName() const { return get()->getName(); }
   StringRef getDisplayName() const { return get()->getDisplayName(); }
@@ -683,15 +606,14 @@ public:
   unsigned isLocalToUnit() const { return get()->isLocalToUnit(); }
   unsigned isDefinition() const { return get()->isDefinition(); }
 
-  DIScope getContext() const { return DIScope(get()->getScope()); }
+  DIScope getContext() const { return get()->getScope(); }
   StringRef getFilename() const { return get()->getFilename(); }
   StringRef getDirectory() const { return get()->getDirectory(); }
   DITypeRef getType() const { return get()->getType(); }
 
-  GlobalVariable *getGlobal() const;
   Constant *getConstant() const { return get()->getVariable(); }
   DIDerivedType getStaticDataMemberDeclaration() const {
-    return DIDerivedType(get()->getStaticDataMemberDeclaration());
+    return get()->getStaticDataMemberDeclaration();
   }
 };
 
@@ -708,33 +630,27 @@ public:
   }
   operator MDLocalVariable *() const { return get(); }
   MDLocalVariable *operator->() const { return get(); }
-  MDLocalVariable &operator*() const {
-    assert(get() && "Expected valid pointer");
-    return *get();
-  }
+  MDLocalVariable &operator*() const { return *get(); }
 
   StringRef getName() const { return get()->getName(); }
   unsigned getLineNumber() const { return get()->getLine(); }
   unsigned getArgNumber() const { return get()->getArg(); }
 
-  DIScope getContext() const { return DIScope(get()->getScope()); }
-  DIFile getFile() const { return DIFile(get()->getFile()); }
+  DIScope getContext() const { return get()->getScope(); }
+  DIFile getFile() const { return get()->getFile(); }
   DITypeRef getType() const { return get()->getType(); }
 
   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()); }
+  MDNode *getInlinedAt() const { return get()->getInlinedAt(); }
 
   /// \brief Check if this is a "__block" variable (Apple Blocks).
   bool isBlockByrefVariable(const DITypeIdentifierMap &Map) const {
     return (getType().resolve(Map)).isBlockByrefStruct();
   }
 
-  /// \brief Check if this is an inlined function argument.
-  bool isInlinedFnArgument(const Function *CurFn);
-
   void printExtendedName(raw_ostream &OS) const;
 };
 
@@ -755,10 +671,7 @@ public:
   }
   operator MDExpression *() const { return get(); }
   MDExpression *operator->() const { return get(); }
-  MDExpression &operator*() const {
-    assert(get() && "Expected valid pointer");
-    return *get();
-  }
+  MDExpression &operator*() const { return *get(); }
 
   unsigned getNumElements() const { return get()->getNumElements(); }
   uint64_t getElement(unsigned I) const { return get()->getElement(I); }
@@ -780,42 +693,15 @@ public:
   }
   operator MDLocation *() const { return get(); }
   MDLocation *operator->() const { return get(); }
-  MDLocation &operator*() const {
-    assert(get() && "Expected valid pointer");
-    return *get();
-  }
+  MDLocation &operator*() const { return *get(); }
 
   unsigned getLineNumber() const { return get()->getLine(); }
   unsigned getColumnNumber() const { return get()->getColumn(); }
   DIScope getScope() const { return DIScope(get()->getScope()); }
-  DILocation getOrigLocation() const {
-    return DILocation(get()->getInlinedAt());
-  }
+  DILocation getOrigLocation() const { return get()->getInlinedAt(); }
   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
-  /// instructions that are on different basic blocks. If two instructions are
-  /// inside the same lexical block and are in different basic blocks, we
-  /// create a new lexical block with identical location as the original but
-  /// with a different discriminator value
-  /// (lib/Transforms/Util/AddDiscriminators.cpp for details).
-  unsigned getDiscriminator() const {
-    // Since discriminators are associated with lexical blocks, make
-    // sure this location is a lexical block before retrieving its
-    // value.
-    if (auto *F = dyn_cast<MDLexicalBlockFile>(get()->getScope()))
-      return F->getDiscriminator();
-    return 0;
-  }
-
-  /// \brief Generate a new discriminator value for this location.
-  unsigned computeNewDiscriminator(LLVMContext &Ctx);
-
-  /// \brief Return a copy of this location with a different scope.
-  DILocation copyWithNewScope(LLVMContext &Ctx, DILexicalBlockFile NewScope);
+  unsigned getDiscriminator() const { return get()->getDiscriminator(); }
 };
 
 class DIObjCProperty : public DIDescriptor {
@@ -828,42 +714,21 @@ public:
   }
   operator MDObjCProperty *() const { return get(); }
   MDObjCProperty *operator->() const { return get(); }
-  MDObjCProperty &operator*() const {
-    assert(get() && "Expected valid pointer");
-    return *get();
-  }
+  MDObjCProperty &operator*() const { return *get(); }
 
   StringRef getObjCPropertyName() const { return get()->getName(); }
-  DIFile getFile() const { return DIFile(get()->getFile()); }
+  DIFile getFile() const { return get()->getFile(); }
   unsigned getLineNumber() const { return get()->getLine(); }
 
   StringRef getObjCPropertyGetterName() const { return get()->getGetterName(); }
   StringRef getObjCPropertySetterName() const { return get()->getSetterName(); }
   unsigned getAttributes() const { return get()->getAttributes(); }
-  bool isReadOnlyObjCProperty() const {
-    return (getAttributes() & dwarf::DW_APPLE_PROPERTY_readonly) != 0;
-  }
-  bool isReadWriteObjCProperty() const {
-    return (getAttributes() & dwarf::DW_APPLE_PROPERTY_readwrite) != 0;
-  }
-  bool isAssignObjCProperty() const {
-    return (getAttributes() & dwarf::DW_APPLE_PROPERTY_assign) != 0;
-  }
-  bool isRetainObjCProperty() const {
-    return (getAttributes() & dwarf::DW_APPLE_PROPERTY_retain) != 0;
-  }
-  bool isCopyObjCProperty() const {
-    return (getAttributes() & dwarf::DW_APPLE_PROPERTY_copy) != 0;
-  }
-  bool isNonAtomicObjCProperty() const {
-    return (getAttributes() & dwarf::DW_APPLE_PROPERTY_nonatomic) != 0;
-  }
 
   /// \brief Get the type.
   ///
   /// \note Objective-C doesn't have an ODR, so there is no benefit in storing
   /// the type as a DITypeRef here.
-  DIType getType() const { return DIType(get()->getType()); }
+  DIType getType() const { return get()->getType(); }
 };
 
 /// \brief An imported module (C++ using directive or similar).
@@ -877,12 +742,9 @@ public:
   }
   operator MDImportedEntity *() const { return get(); }
   MDImportedEntity *operator->() const { return get(); }
-  MDImportedEntity &operator*() const {
-    assert(get() && "Expected valid pointer");
-    return *get();
-  }
+  MDImportedEntity &operator*() const { return *get(); }
 
-  DIScope getContext() const { return DIScope(get()->getScope()); }
+  DIScope getContext() const { return get()->getScope(); }
   DIDescriptorRef getEntity() const { return get()->getEntity(); }
   unsigned getLineNumber() const { return get()->getLine(); }
   StringRef getName() const { return get()->getName(); }