Skip to content

Commit 5193a76

Browse files
committed
[LLVMSupport] Re-import LLVMSupport .cpp and .h files from 9ff3a9759b7c2f146e7f46e4aebc60453c577c5a from apple/llvm-project
Done via the following commands, while having llvm-project checked out at 9ff3a9759b7c2f146e7f46e4aebc60453c577c5a, a commit on the stable/20210726 branch of apple/llvm-project, <swiftlang/llvm-project@9ff3a97>: for i in swift/stdlib/public/LLVMSupport/*.cpp ; do cp llvm-project/llvm/lib/Support/$(basename $i) $i ; done for i in swift/stdlib/include/llvm/ADT/*.h; do cp llvm-project/llvm/include/llvm/ADT/$(basename $i) $i ; done for i in swift/stdlib/include/llvm/Support/*.h; do cp llvm-project/llvm/include/llvm/Support/$(basename $i) $i ; done cp llvm-project/llvm/include/llvm/ADT/ScopeExit.h swift/stdlib/include/llvm/ADT/ScopeExit.h cp llvm-project/llvm/include/llvm/ADT/Twine.h swift/stdlib/include/llvm/ADT/Twine.h cp llvm-project/llvm/include/llvm/Support/raw_ostream.h swift/stdlib/include/llvm/Support/raw_ostream.h
1 parent 46ffc22 commit 5193a76

38 files changed

+3326
-875
lines changed

stdlib/include/llvm/ADT/ArrayRef.h

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@
2424
#include <type_traits>
2525
#include <vector>
2626

27-
inline namespace __swift { inline namespace __runtime {
2827
namespace llvm {
2928

29+
template<typename T> struct DenseMapInfo;
30+
3031
/// ArrayRef - Represent a constant reference to an array (0 or more elements
3132
/// consecutively in memory), i.e. a start pointer and a length. It allows
3233
/// various APIs to take consecutive elements easily and conveniently.
@@ -41,10 +42,17 @@ namespace llvm {
4142
template<typename T>
4243
class LLVM_GSL_POINTER LLVM_NODISCARD ArrayRef {
4344
public:
44-
using iterator = const T *;
45-
using const_iterator = const T *;
46-
using size_type = size_t;
45+
using value_type = T;
46+
using pointer = value_type *;
47+
using const_pointer = const value_type *;
48+
using reference = value_type &;
49+
using const_reference = const value_type &;
50+
using iterator = const_pointer;
51+
using const_iterator = const_pointer;
4752
using reverse_iterator = std::reverse_iterator<iterator>;
53+
using const_reverse_iterator = std::reverse_iterator<const_iterator>;
54+
using size_type = size_t;
55+
using difference_type = ptrdiff_t;
4856

4957
private:
5058
/// The start of the array, in an external buffer.
@@ -298,8 +306,17 @@ namespace llvm {
298306
template<typename T>
299307
class LLVM_NODISCARD MutableArrayRef : public ArrayRef<T> {
300308
public:
301-
using iterator = T *;
309+
using value_type = T;
310+
using pointer = value_type *;
311+
using const_pointer = const value_type *;
312+
using reference = value_type &;
313+
using const_reference = const value_type &;
314+
using iterator = pointer;
315+
using const_iterator = const_pointer;
302316
using reverse_iterator = std::reverse_iterator<iterator>;
317+
using const_reverse_iterator = std::reverse_iterator<const_iterator>;
318+
using size_type = size_t;
319+
using difference_type = ptrdiff_t;
303320

304321
/// Construct an empty MutableArrayRef.
305322
/*implicit*/ MutableArrayRef() = default;
@@ -554,7 +571,35 @@ namespace llvm {
554571
return hash_combine_range(S.begin(), S.end());
555572
}
556573

574+
// Provide DenseMapInfo for ArrayRefs.
575+
template <typename T> struct DenseMapInfo<ArrayRef<T>> {
576+
static inline ArrayRef<T> getEmptyKey() {
577+
return ArrayRef<T>(
578+
reinterpret_cast<const T *>(~static_cast<uintptr_t>(0)), size_t(0));
579+
}
580+
581+
static inline ArrayRef<T> getTombstoneKey() {
582+
return ArrayRef<T>(
583+
reinterpret_cast<const T *>(~static_cast<uintptr_t>(1)), size_t(0));
584+
}
585+
586+
static unsigned getHashValue(ArrayRef<T> Val) {
587+
assert(Val.data() != getEmptyKey().data() &&
588+
"Cannot hash the empty key!");
589+
assert(Val.data() != getTombstoneKey().data() &&
590+
"Cannot hash the tombstone key!");
591+
return (unsigned)(hash_value(Val));
592+
}
593+
594+
static bool isEqual(ArrayRef<T> LHS, ArrayRef<T> RHS) {
595+
if (RHS.data() == getEmptyKey().data())
596+
return LHS.data() == getEmptyKey().data();
597+
if (RHS.data() == getTombstoneKey().data())
598+
return LHS.data() == getTombstoneKey().data();
599+
return LHS == RHS;
600+
}
601+
};
602+
557603
} // end namespace llvm
558-
}} // namespace swift::runtime
559604

560605
#endif // LLVM_ADT_ARRAYREF_H

0 commit comments

Comments
 (0)