Skip to content

Commit 983565a

Browse files
committed
[ADT] Move DenseMapInfo for ArrayRef/StringRef into respective headers (NFC)
This is a followup to D103422. The DenseMapInfo implementations for ArrayRef and StringRef are moved into the ArrayRef.h and StringRef.h headers, which means that these two headers no longer need to be included by DenseMapInfo.h. This required adding a few additional includes, as many files were relying on various things pulled in by ArrayRef.h. Differential Revision: https://reviews.llvm.org/D103491
1 parent fd3a526 commit 983565a

File tree

16 files changed

+77
-60
lines changed

16 files changed

+77
-60
lines changed

clang/include/clang/AST/ComparisonCategories.h

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "llvm/ADT/DenseMap.h"
2020
#include <array>
2121
#include <cassert>
22+
#include <vector>
2223

2324
namespace llvm {
2425
class StringRef;

llvm/include/llvm/ADT/ArrayRef.h

+31
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626

2727
namespace llvm {
2828

29+
template<typename T> struct DenseMapInfo;
30+
2931
/// ArrayRef - Represent a constant reference to an array (0 or more elements
3032
/// consecutively in memory), i.e. a start pointer and a length. It allows
3133
/// various APIs to take consecutive elements easily and conveniently.
@@ -569,6 +571,35 @@ namespace llvm {
569571
return hash_combine_range(S.begin(), S.end());
570572
}
571573

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+
572603
} // end namespace llvm
573604

574605
#endif // LLVM_ADT_ARRAYREF_H

llvm/include/llvm/ADT/DenseMapInfo.h

-58
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313
#ifndef LLVM_ADT_DENSEMAPINFO_H
1414
#define LLVM_ADT_DENSEMAPINFO_H
1515

16-
#include "llvm/ADT/ArrayRef.h"
1716
#include "llvm/ADT/Hashing.h"
18-
#include "llvm/ADT/StringRef.h"
1917
#include <cassert>
2018
#include <cstddef>
2119
#include <cstdint>
@@ -284,62 +282,6 @@ template <typename... Ts> struct DenseMapInfo<std::tuple<Ts...>> {
284282
}
285283
};
286284

287-
// Provide DenseMapInfo for StringRefs.
288-
template <> struct DenseMapInfo<StringRef> {
289-
static inline StringRef getEmptyKey() {
290-
return StringRef(reinterpret_cast<const char *>(~static_cast<uintptr_t>(0)),
291-
0);
292-
}
293-
294-
static inline StringRef getTombstoneKey() {
295-
return StringRef(reinterpret_cast<const char *>(~static_cast<uintptr_t>(1)),
296-
0);
297-
}
298-
299-
static unsigned getHashValue(StringRef Val) {
300-
assert(Val.data() != getEmptyKey().data() && "Cannot hash the empty key!");
301-
assert(Val.data() != getTombstoneKey().data() &&
302-
"Cannot hash the tombstone key!");
303-
return (unsigned)(hash_value(Val));
304-
}
305-
306-
static bool isEqual(StringRef LHS, StringRef RHS) {
307-
if (RHS.data() == getEmptyKey().data())
308-
return LHS.data() == getEmptyKey().data();
309-
if (RHS.data() == getTombstoneKey().data())
310-
return LHS.data() == getTombstoneKey().data();
311-
return LHS == RHS;
312-
}
313-
};
314-
315-
// Provide DenseMapInfo for ArrayRefs.
316-
template <typename T> struct DenseMapInfo<ArrayRef<T>> {
317-
static inline ArrayRef<T> getEmptyKey() {
318-
return ArrayRef<T>(reinterpret_cast<const T *>(~static_cast<uintptr_t>(0)),
319-
size_t(0));
320-
}
321-
322-
static inline ArrayRef<T> getTombstoneKey() {
323-
return ArrayRef<T>(reinterpret_cast<const T *>(~static_cast<uintptr_t>(1)),
324-
size_t(0));
325-
}
326-
327-
static unsigned getHashValue(ArrayRef<T> Val) {
328-
assert(Val.data() != getEmptyKey().data() && "Cannot hash the empty key!");
329-
assert(Val.data() != getTombstoneKey().data() &&
330-
"Cannot hash the tombstone key!");
331-
return (unsigned)(hash_value(Val));
332-
}
333-
334-
static bool isEqual(ArrayRef<T> LHS, ArrayRef<T> RHS) {
335-
if (RHS.data() == getEmptyKey().data())
336-
return LHS.data() == getEmptyKey().data();
337-
if (RHS.data() == getTombstoneKey().data())
338-
return LHS.data() == getTombstoneKey().data();
339-
return LHS == RHS;
340-
}
341-
};
342-
343285
template <> struct DenseMapInfo<hash_code> {
344286
static inline hash_code getEmptyKey() { return hash_code(-1); }
345287
static inline hash_code getTombstoneKey() { return hash_code(-2); }

llvm/include/llvm/ADT/StringRef.h

+30
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ namespace llvm {
3535
class APInt;
3636
class hash_code;
3737
template <typename T> class SmallVectorImpl;
38+
template <typename T> struct DenseMapInfo;
3839
class StringRef;
3940

4041
/// Helper functions for StringRef::getAsInteger.
@@ -925,6 +926,35 @@ namespace llvm {
925926
LLVM_NODISCARD
926927
hash_code hash_value(StringRef S);
927928

929+
// Provide DenseMapInfo for StringRefs.
930+
template <> struct DenseMapInfo<StringRef> {
931+
static inline StringRef getEmptyKey() {
932+
return StringRef(
933+
reinterpret_cast<const char *>(~static_cast<uintptr_t>(0)), 0);
934+
}
935+
936+
static inline StringRef getTombstoneKey() {
937+
return StringRef(
938+
reinterpret_cast<const char *>(~static_cast<uintptr_t>(1)), 0);
939+
}
940+
941+
static unsigned getHashValue(StringRef Val) {
942+
assert(Val.data() != getEmptyKey().data() &&
943+
"Cannot hash the empty key!");
944+
assert(Val.data() != getTombstoneKey().data() &&
945+
"Cannot hash the tombstone key!");
946+
return (unsigned)(hash_value(Val));
947+
}
948+
949+
static bool isEqual(StringRef LHS, StringRef RHS) {
950+
if (RHS.data() == getEmptyKey().data())
951+
return LHS.data() == getEmptyKey().data();
952+
if (RHS.data() == getTombstoneKey().data())
953+
return LHS.data() == getTombstoneKey().data();
954+
return LHS == RHS;
955+
}
956+
};
957+
928958
} // end namespace llvm
929959

930960
#endif // LLVM_ADT_STRINGREF_H

llvm/include/llvm/IR/PassInstrumentation.h

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
#include "llvm/ADT/SmallVector.h"
5555
#include "llvm/ADT/StringMap.h"
5656
#include <type_traits>
57+
#include <vector>
5758

5859
namespace llvm {
5960

llvm/include/llvm/Support/Threading.h

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "llvm/ADT/BitVector.h"
1818
#include "llvm/ADT/FunctionExtras.h"
1919
#include "llvm/ADT/SmallVector.h"
20+
#include "llvm/ADT/StringRef.h"
2021
#include "llvm/Config/llvm-config.h" // for LLVM_ON_UNIX
2122
#include "llvm/Support/Compiler.h"
2223
#include <ciso646> // So we can check the C++ standard lib macros.

llvm/lib/CodeGen/AsmPrinter/WinException.h

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#define LLVM_LIB_CODEGEN_ASMPRINTER_WIN64EXCEPTION_H
1515

1616
#include "EHStreamer.h"
17+
#include <vector>
1718

1819
namespace llvm {
1920
class GlobalValue;

llvm/lib/CodeGen/MBFIWrapper.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@
1111
//
1212
//===----------------------------------------------------------------------===//
1313

14-
#include "llvm/CodeGen/MBFIWrapper.h"
14+
#include "llvm/ADT/Optional.h"
1515
#include "llvm/CodeGen/MachineBlockFrequencyInfo.h"
16+
#include "llvm/CodeGen/MBFIWrapper.h"
1617

1718
using namespace llvm;
1819

llvm/lib/MC/StringTableBuilder.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "llvm/MC/StringTableBuilder.h"
10+
#include "llvm/ADT/ArrayRef.h"
1011
#include "llvm/ADT/CachedHashString.h"
1112
#include "llvm/ADT/SmallString.h"
1213
#include "llvm/ADT/StringRef.h"

llvm/lib/Support/SmallPtrSet.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@
1313

1414
#include "llvm/ADT/SmallPtrSet.h"
1515
#include "llvm/ADT/DenseMapInfo.h"
16-
#include "llvm/Support/MathExtras.h"
1716
#include "llvm/Support/ErrorHandling.h"
17+
#include "llvm/Support/MathExtras.h"
18+
#include "llvm/Support/MemAlloc.h"
1819
#include <algorithm>
1920
#include <cassert>
2021
#include <cstdlib>

llvm/lib/Target/AMDGPU/AMDGPUGlobalISelUtils.h

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#ifndef LLVM_LIB_TARGET_AMDGPU_AMDGPUGLOBALISELUTILS_H
1010
#define LLVM_LIB_TARGET_AMDGPU_AMDGPUGLOBALISELUTILS_H
1111

12+
#include "llvm/ADT/ArrayRef.h"
1213
#include "llvm/CodeGen/Register.h"
1314
#include <utility>
1415

llvm/tools/llvm-c-test/echo.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "llvm-c/DebugInfo.h"
1919
#include "llvm-c/Target.h"
2020
#include "llvm/ADT/DenseMap.h"
21+
#include "llvm/ADT/SmallVector.h"
2122
#include "llvm/Support/ErrorHandling.h"
2223

2324
#include <stdio.h>

mlir/include/mlir/IR/AffineExpr.h

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "mlir/Support/LLVM.h"
1818
#include "llvm/ADT/DenseMapInfo.h"
1919
#include "llvm/Support/Casting.h"
20+
#include <functional>
2021
#include <type_traits>
2122

2223
namespace mlir {

mlir/include/mlir/IR/DialectInterface.h

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include "mlir/Support/TypeID.h"
1313
#include "llvm/ADT/DenseSet.h"
14+
#include "llvm/ADT/STLExtras.h"
1415

1516
namespace mlir {
1617
class Dialect;

mlir/include/mlir/Support/InterfaceSupport.h

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#define MLIR_SUPPORT_INTERFACESUPPORT_H
1515

1616
#include "mlir/Support/TypeID.h"
17+
#include "llvm/ADT/ArrayRef.h"
1718
#include "llvm/ADT/DenseMap.h"
1819
#include "llvm/Support/TypeName.h"
1920

mlir/include/mlir/Support/StorageUniquer.h

+2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
#include "mlir/Support/LLVM.h"
1313
#include "mlir/Support/LogicalResult.h"
1414
#include "mlir/Support/TypeID.h"
15+
#include "llvm/ADT/ArrayRef.h"
1516
#include "llvm/ADT/DenseSet.h"
17+
#include "llvm/ADT/StringRef.h"
1618
#include "llvm/Support/Allocator.h"
1719

1820
namespace mlir {

0 commit comments

Comments
 (0)