LLVM: include/llvm/ADT/PointerEmbeddedInt.h Source File (original) (raw)

1

2

3

4

5

6

7

8

9#ifndef LLVM_ADT_POINTEREMBEDDEDINT_H

10#define LLVM_ADT_POINTEREMBEDDEDINT_H

11

15#include

16#include

17#include

18#include <type_traits>

19

20namespace llvm {

21

22

23

24

25

26

27

28

29

30

31

32template <typename IntT, int Bits = sizeof(IntT) * CHAR_BIT>

33class PointerEmbeddedInt {

34 uintptr_t Value = 0;

35

36

37

38 static_assert(Bits < sizeof(uintptr_t) * CHAR_BIT,

39 "Cannot embed more bits than we have in a pointer!");

40

41 enum : uintptr_t {

42

43

44 Shift = sizeof(uintptr_t) * CHAR_BIT - Bits,

45 };

46

47 struct RawValueTag {

48 explicit RawValueTag() = default;

49 };

50

52

53 explicit PointerEmbeddedInt(uintptr_t Value, RawValueTag) : Value(Value) {}

54

55public:

57

59

62 "Integer has bits outside those preserved!");

63 Value = static_cast<uintptr_t>(I) << Shift;

64 return *this;

65 }

66

67

68

69 operator IntT() const {

70 if (std::is_signed::value)

71 return static_cast<IntT>(static_cast<intptr_t>(Value) >> Shift);

72 return static_cast<IntT>(Value >> Shift);

73 }

74};

75

76

77

78template <typename IntT, int Bits>

81

83 return reinterpret_cast<void *>(P.Value);

84 }

85

87 return T(reinterpret_cast<uintptr_t>(P), typename T::RawValueTag());

88 }

89

91 return T(reinterpret_cast<uintptr_t>(P), typename T::RawValueTag());

92 }

93

95};

96

97

98

99template <typename IntT, int Bits>

103

104 static inline T getEmptyKey() { return IntInfo::getEmptyKey(); }

106

108 return IntInfo::getHashValue(Arg);

109 }

110

112};

113

114}

115

116#endif

assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")

This file defines DenseMapInfo traits for DenseMap.

Utility to embed an integer into a pointer-like type.

Definition PointerEmbeddedInt.h:33

PointerEmbeddedInt & operator=(IntT I)

Definition PointerEmbeddedInt.h:60

PointerEmbeddedInt(IntT I)

Definition PointerEmbeddedInt.h:58

PointerEmbeddedInt()=default

This is an optimization pass for GlobalISel generic memory operations.

constexpr bool isInt(int64_t x)

Checks if an integer fits into the given bit width.

constexpr bool isUInt(uint64_t x)

Checks if an unsigned integer fits into the given bit width.

static unsigned getHashValue(const T &Arg)

Definition PointerEmbeddedInt.h:107

static T getEmptyKey()

Definition PointerEmbeddedInt.h:104

static bool isEqual(const T &LHS, const T &RHS)

Definition PointerEmbeddedInt.h:111

PointerEmbeddedInt< IntT, Bits > T

Definition PointerEmbeddedInt.h:101

DenseMapInfo< IntT > IntInfo

Definition PointerEmbeddedInt.h:102

static T getTombstoneKey()

Definition PointerEmbeddedInt.h:105

An information struct used to provide DenseMap with the various necessary components for a given valu...

static T getFromVoidPointer(const void *P)

Definition PointerEmbeddedInt.h:90

PointerEmbeddedInt< IntT, Bits > T

Definition PointerEmbeddedInt.h:80

static void * getAsVoidPointer(const T &P)

Definition PointerEmbeddedInt.h:82

static T getFromVoidPointer(void *P)

Definition PointerEmbeddedInt.h:86

static constexpr int NumLowBitsAvailable

Definition PointerEmbeddedInt.h:94

A traits type that is used to handle pointer types and things that are just wrappers for pointers as ...