diff --git a/llvm/include/llvm/ADT/DenseMap.h b/llvm/include/llvm/ADT/DenseMap.h --- a/llvm/include/llvm/ADT/DenseMap.h +++ b/llvm/include/llvm/ADT/DenseMap.h @@ -96,7 +96,7 @@ LLVM_NODISCARD bool empty() const { return getNumEntries() == 0; } - unsigned size() const { return getNumEntries(); } + LLVM_USED_FOR_DEBUG unsigned size() const { return getNumEntries(); } /// Grow the densemap so that it can contain at least \p NumEntries items /// before resizing again. @@ -141,18 +141,18 @@ } /// Return 1 if the specified key is in the map, 0 otherwise. - size_type count(const_arg_type_t Val) const { + LLVM_USED_FOR_DEBUG size_type count(const_arg_type_t Val) const { const BucketT *TheBucket; return LookupBucketFor(Val, TheBucket) ? 1 : 0; } - iterator find(const_arg_type_t Val) { + LLVM_USED_FOR_DEBUG iterator find(const_arg_type_t Val) { BucketT *TheBucket; if (LookupBucketFor(Val, TheBucket)) return makeIterator(TheBucket, getBucketsEnd(), *this, true); return end(); } - const_iterator find(const_arg_type_t Val) const { + LLVM_USED_FOR_DEBUG const_iterator find(const_arg_type_t Val) const { const BucketT *TheBucket; if (LookupBucketFor(Val, TheBucket)) return makeConstIterator(TheBucket, getBucketsEnd(), *this, true); @@ -181,7 +181,7 @@ /// lookup - Return the entry for the specified key, or a default /// constructed value if no such entry exists. - ValueT lookup(const_arg_type_t Val) const { + LLVM_USED_FOR_DEBUG ValueT lookup(const_arg_type_t Val) const { const BucketT *TheBucket; if (LookupBucketFor(Val, TheBucket)) return TheBucket->getSecond(); @@ -1198,14 +1198,14 @@ const DenseMapIterator &I) : DebugEpochBase::HandleBase(I), Ptr(I.Ptr), End(I.End) {} - reference operator*() const { + LLVM_USED_FOR_DEBUG reference operator*() const { assert(isHandleInSync() && "invalid iterator access!"); assert(Ptr != End && "dereferencing end() iterator"); if (shouldReverseIterate()) return Ptr[-1]; return *Ptr; } - pointer operator->() const { + LLVM_USED_FOR_DEBUG pointer operator->() const { assert(isHandleInSync() && "invalid iterator access!"); assert(Ptr != End && "dereferencing end() iterator"); if (shouldReverseIterate()) @@ -1213,14 +1213,14 @@ return Ptr; } - bool operator==(const ConstIterator &RHS) const { + LLVM_USED_FOR_DEBUG bool operator==(const ConstIterator &RHS) const { assert((!Ptr || isHandleInSync()) && "handle not in sync!"); assert((!RHS.Ptr || RHS.isHandleInSync()) && "handle not in sync!"); assert(getEpochAddress() == RHS.getEpochAddress() && "comparing incomparable iterators!"); return Ptr == RHS.Ptr; } - bool operator!=(const ConstIterator &RHS) const { + LLVM_USED_FOR_DEBUG bool operator!=(const ConstIterator &RHS) const { assert((!Ptr || isHandleInSync()) && "handle not in sync!"); assert((!RHS.Ptr || RHS.isHandleInSync()) && "handle not in sync!"); assert(getEpochAddress() == RHS.getEpochAddress() && diff --git a/llvm/include/llvm/ADT/PointerIntPair.h b/llvm/include/llvm/ADT/PointerIntPair.h --- a/llvm/include/llvm/ADT/PointerIntPair.h +++ b/llvm/include/llvm/ADT/PointerIntPair.h @@ -56,9 +56,13 @@ explicit PointerIntPair(PointerTy PtrVal) { initWithPointer(PtrVal); } - PointerTy getPointer() const { return Info::getPointer(Value); } + LLVM_USED_FOR_DEBUG PointerTy getPointer() const { + return Info::getPointer(Value); + } - IntType getInt() const { return (IntType)Info::getInt(Value); } + LLVM_USED_FOR_DEBUG IntType getInt() const { + return (IntType)Info::getInt(Value); + } void setPointer(PointerTy PtrVal) LLVM_LVALUE_FUNCTION { Value = Info::updatePointer(Value, PtrVal); diff --git a/llvm/include/llvm/ADT/SmallVector.h b/llvm/include/llvm/ADT/SmallVector.h --- a/llvm/include/llvm/ADT/SmallVector.h +++ b/llvm/include/llvm/ADT/SmallVector.h @@ -49,7 +49,7 @@ void grow_pod(void *FirstEl, size_t MinCapacity, size_t TSize); public: - size_t size() const { return Size; } + LLVM_USED_FOR_DEBUG size_t size() const { return Size; } size_t capacity() const { return Capacity; } LLVM_NODISCARD bool empty() const { return !Size; } @@ -145,11 +145,11 @@ /// Return a pointer to the vector's buffer, even if empty(). const_pointer data() const { return const_pointer(begin()); } - reference operator[](size_type idx) { + LLVM_USED_FOR_DEBUG reference operator[](size_type idx) { assert(idx < size()); return begin()[idx]; } - const_reference operator[](size_type idx) const { + LLVM_USED_FOR_DEBUG const_reference operator[](size_type idx) const { assert(idx < size()); return begin()[idx]; } diff --git a/llvm/include/llvm/Support/Compiler.h b/llvm/include/llvm/Support/Compiler.h --- a/llvm/include/llvm/Support/Compiler.h +++ b/llvm/include/llvm/Support/Compiler.h @@ -503,6 +503,20 @@ #define LLVM_DUMP_METHOD LLVM_ATTRIBUTE_NOINLINE #endif +/// This macro will mark the function as used if the host compiler supports it +/// and the build has asserts enabled. Functions marked with this macro can be +/// called from the debugger during debugging. This macro should be used on +/// function that are useful for debugging and wouldn't be emitted unless they +/// are used, usually getter-like member function of template classes. Example: +/// SmallVectors's operator[] is usefull for debugging, doesn't change the state +/// of the SmallVector and will not be generated it is used because it is +/// templated. +#if !defined(NDEBUG) +#define LLVM_USED_FOR_DEBUG LLVM_ATTRIBUTE_USED +#else +#define LLVM_USED_FOR_DEBUG +#endif + /// \macro LLVM_PRETTY_FUNCTION /// Gets a user-friendly looking function signature for the current scope /// using the best available method on each platform. The exact format of the