LLVM: lib/CGData/OutlinedHashTreeRecord.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

20

21#define DEBUG_TYPE "outlined-hash-tree"

22

23using namespace llvm;

25

26namespace llvm {

27namespace yaml {

28

36

41 unsigned Id;

42 if (Key.getAsInteger(0, Id)) {

43 io.setError("Id not an integer");

44 return;

45 }

46 V.insert({Id, NodeStable});

47 }

48

50 for (auto Iter = V.begin(); Iter != V.end(); ++Iter)

52 }

53};

54

55}

56}

57

60 convertToStableData(IdNodeStableMap);

63

64 for (const auto &[Id, NodeStable] : IdNodeStableMap) {

68 Writer.write<uint32_t>(NodeStable.SuccessorIds.size());

69 for (auto SuccessorId : NodeStable.SuccessorIds)

71 }

72}

73

76 auto NumIdNodeStableMap =

78

79 for (unsigned I = 0; I < NumIdNodeStableMap; ++I) {

82 NodeStable.Hash =

86 auto NumSuccessorIds =

88 for (unsigned J = 0; J < NumSuccessorIds; ++J)

91

92 IdNodeStableMap[Id] = std::move(NodeStable);

93 }

94

95 convertFromStableData(IdNodeStableMap);

96}

97

100 convertToStableData(IdNodeStableMap);

101

102 YOS << IdNodeStableMap;

103}

104

107

108 YIS >> IdNodeStableMap;

110

111 convertFromStableData(IdNodeStableMap);

112}

113

114void OutlinedHashTreeRecord::convertToStableData(

116

119 [&NodeIdMap](const HashNode *Current) {

120 size_t Index = NodeIdMap.size();

121 NodeIdMap[Current] = Index;

122 assert((Index + 1 == NodeIdMap.size()) &&

123 "Duplicate key in NodeIdMap: 'Current' should be unique.");

124 },

125 nullptr, true);

126

127

128 for (auto &P : NodeIdMap) {

129 auto *Node = P.first;

130 auto Id = P.second;

132 NodeStable.Hash = Node->Hash;

133 NodeStable.Terminals = Node->Terminals.value_or(0);

134 for (auto &P : Node->Successors)

135 NodeStable.SuccessorIds.push_back(NodeIdMap[P.second.get()]);

136 IdNodeStableMap[Id] = NodeStable;

137 }

138

139

140 for (auto &P : IdNodeStableMap)

142}

143

144void OutlinedHashTreeRecord::convertFromStableData(

147

148 IdNodeMap[0] = HashTree->getRoot();

149 assert(IdNodeMap[0]->Successors.empty());

150

151 for (auto &P : IdNodeStableMap) {

152 auto Id = P.first;

153 const HashNodeStable &NodeStable = P.second;

155 HashNode *Curr = IdNodeMap[Id];

156 Curr->Hash = NodeStable.Hash;

160 assert(Successors.empty());

161 for (auto SuccessorId : NodeStable.SuccessorIds) {

162 auto Sucessor = std::make_unique();

163 IdNodeMap[SuccessorId] = Sucessor.get();

164 auto Hash = IdNodeStableMap.at(SuccessorId).Hash;

165 Successors[Hash] = std::move(Sucessor);

166 }

167 }

168}

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

ValueT & at(const_arg_type_t< KeyT > Val)

at - Return the entry for the specified key, or abort if no such entry exists.

size_type count(const_arg_type_t< KeyT > Val) const

Return 1 if the specified key is in the map, 0 otherwise.

StringRef - Represent a constant reference to a string, i.e.

This class implements an extremely fast bulk output stream that can only output to a stream.

virtual void setError(const Twine &)=0

void mapRequired(StringRef Key, T &Val)

The Input class is used to parse a yaml document into in-memory structs and vectors.

The Output class is used to generate a yaml document from in-memory structs and vectors.

value_type readNext(const CharT *&memory, endianness endian)

Read a value of a particular endianness from a buffer, and increment the buffer past that value.

This is an optimization pass for GlobalISel generic memory operations.

std::string utostr(uint64_t X, bool isNeg=false)

void sort(IteratorTy Start, IteratorTy End)

LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key

DenseMap< unsigned, HashNode * > IdHashNodeMapTy

std::map< unsigned, HashNodeStable > IdHashNodeStableMapTy

DenseMap< const HashNode *, unsigned > HashNodeIdMapTy

HashNodeStable is the serialized, stable, and compact representation of a HashNode.

std::vector< unsigned > SuccessorIds

A HashNode is an entry in an OutlinedHashTree, holding a hash value and a collection of Successors (o...

std::unordered_map< stable_hash, std::unique_ptr< HashNode > > Successors

The successors of this node.

std::optional< unsigned > Terminals

The number of terminals in the sequence ending at this node.

stable_hash Hash

The hash value of the node.

LLVM_ABI void serializeYAML(yaml::Output &YOS) const

Serialize the outlined hash tree to a YAML stream.

Definition OutlinedHashTreeRecord.cpp:98

LLVM_ABI void deserializeYAML(yaml::Input &YIS)

Deserialize the outlined hash tree from a YAML stream.

Definition OutlinedHashTreeRecord.cpp:105

LLVM_ABI void deserialize(const unsigned char *&Ptr)

Deserialize the outlined hash tree from a raw_ostream.

Definition OutlinedHashTreeRecord.cpp:74

LLVM_ABI void serialize(raw_ostream &OS) const

Serialize the outlined hash tree to a raw_ostream.

Definition OutlinedHashTreeRecord.cpp:58

std::unique_ptr< OutlinedHashTree > HashTree

Adapter to write values to a stream in a particular byte order.

void write(ArrayRef< value_type > Val)

static void output(IO &io, IdHashNodeStableMapTy &V)

Definition OutlinedHashTreeRecord.cpp:49

static void inputOne(IO &io, StringRef Key, IdHashNodeStableMapTy &V)

Definition OutlinedHashTreeRecord.cpp:38

This class should be specialized by any type that needs to be converted to/from a YAML mapping in the...

static void mapping(IO &io, HashNodeStable &res)

Definition OutlinedHashTreeRecord.cpp:30

This class should be specialized by any type that needs to be converted to/from a YAML mapping.