Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(233)

Side by Side Diff: include/llvm/Bitcode/NaCl/NaClBitcodeValueDist.h

Issue 939073008: Rebased PNaCl localmods in LLVM to 223109 (Closed)
Patch Set: undo localmod Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 //===-- NaClBitcodeValueDist.h ---------------------------------------------===/ /
2 // Defines distribution maps to separate out values at each index
3 // in a bitcode record.
4 //
5 // The LLVM Compiler Infrastructure
6 //
7 // This file is distributed under the University of Illinois Open Source
8 // License. See LICENSE.TXT for details.
9 //
10 //===----------------------------------------------------------------------===//
11
12 #ifndef LLVM_BITCODE_NACL_NACLBITCODEVALUEDIST_H
13 #define LLVM_BITCODE_NACL_NACLBITCODEVALUEDIST_H
14
15 #include "llvm/Bitcode/NaCl/NaClBitcodeDist.h"
16
17 namespace llvm {
18
19 /// Defines the value index cutoff where we no longer track values associated
20 /// with specific value indices of bitcode records.
21 static const unsigned NaClValueIndexCutoff = 6;
22
23 /// Defines an (inclusive) range of values in a bitcode record,
24 /// defined by the given pair of values. Note that values are stored
25 /// as ranges. For small values, each value is in a separate range, so
26 /// that potential constants for abbreviations can be found. For
27 /// larger values, values are coalesced together into multiple element
28 /// ranges, since we don't look for constants and are only interested
29 /// in the overall distribution of values.
30 typedef std::pair<NaClBitcodeDistValue,
31 NaClBitcodeDistValue> NaClValueRangeType;
32
33 /// Models a range index. Ranges are encoded as a consecutive sequence
34 /// of indices, starting at zero. The actual ranges chosen to
35 /// represent bitcode records are internal, and is defined by function
36 /// GetValueRange index below.
37 typedef NaClBitcodeDistValue NaClValueRangeIndexType;
38
39 /// Converts a bitcode record value to the corresponding range index that
40 /// contains the value.
41 NaClValueRangeIndexType GetNaClValueRangeIndex(NaClBitcodeDistValue Value);
42
43 /// Converts a range index into the corresponding range of values.
44 NaClValueRangeType GetNaClValueRange(NaClValueRangeIndexType RangeIndex);
45
46 /// Defines the distribution of range indices.
47 class NaClBitcodeValueDistElement : public NaClBitcodeDistElement {
48 NaClBitcodeValueDistElement(const NaClBitcodeValueDistElement&)
49 LLVM_DELETED_FUNCTION;
50 void operator=(const NaClBitcodeValueDistElement&) LLVM_DELETED_FUNCTION;
51
52 public:
53 static bool classof(const NaClBitcodeDistElement *Element) {
54 return Element->getKind() >= RDE_ValueDist &&
55 Element->getKind() < RDE_ValueDistLast;
56 }
57
58 NaClBitcodeValueDistElement()
59 : NaClBitcodeDistElement(RDE_ValueDist)
60 {}
61
62 static NaClBitcodeValueDistElement Sentinel;
63
64 virtual ~NaClBitcodeValueDistElement();
65
66 virtual NaClBitcodeDistElement *CreateElement(
67 NaClBitcodeDistValue Value) const;
68
69 /// Returns the number of instances, normalized over the
70 /// range of values, using a uniform distribution.
71 virtual double GetImportance(NaClBitcodeDistValue Value) const;
72
73 virtual const char *GetTitle() const;
74
75 virtual const char *GetValueHeader() const;
76
77 virtual void PrintRowValue(raw_ostream &Stream,
78 NaClBitcodeDistValue Value,
79 const NaClBitcodeDist *Distribution) const;
80 };
81
82 /// Defines the distribution of values for a set of value indices for
83 /// bitcode records.
84 class NaClBitcodeValueDist : public NaClBitcodeDist {
85 NaClBitcodeValueDist(const NaClBitcodeValueDist&) LLVM_DELETED_FUNCTION;
86 void operator=(const NaClBitcodeValueDist&) LLVM_DELETED_FUNCTION;
87
88 public:
89 static bool classof(const NaClBitcodeDist *Dist) {
90 return Dist->getKind() >= RD_ValueDist &&
91 Dist->getKind() < RD_ValueDistLast;
92 }
93
94 /// Builds a value distribution for the given set of value indices.
95 /// If AllRemainingIndices is false, only value Index is considered.
96 /// Otherwise, builds a value distribution for all values stored in
97 /// record value indices >= Index.
98 explicit NaClBitcodeValueDist(unsigned Index,
99 bool AllRemainingIndices=false);
100
101 virtual ~NaClBitcodeValueDist();
102
103 unsigned GetIndex() const {
104 return Index;
105 }
106
107 bool HoldsAllRemainingIndices() const {
108 return AllRemainingIndices;
109 }
110
111 virtual void GetValueList(const NaClBitcodeRecord &Record,
112 ValueListType &ValueList) const;
113
114 private:
115 // The range index being tracked.
116 unsigned Index;
117
118 // If true, then tracks all indices >= Index. Otherwise only Index.
119 bool AllRemainingIndices;
120 };
121
122 /// Defines the value distribution for each value index in corresponding
123 /// bitcode records. This is a helper class used to separate each element
124 /// in the bitcode record, so that we can determine the proper abbreviation
125 /// for each element.
126 class NaClBitcodeValueIndexDistElement : public NaClBitcodeDistElement {
127 NaClBitcodeValueIndexDistElement(
128 const NaClBitcodeValueIndexDistElement&) LLVM_DELETED_FUNCTION;
129 void operator=(
130 const NaClBitcodeValueIndexDistElement&) LLVM_DELETED_FUNCTION;
131
132 public:
133 static bool classof(const NaClBitcodeDistElement *Element) {
134 return Element->getKind() <= RDE_ValueIndexDist &&
135 Element->getKind() < RDE_ValueIndexDistLast;
136 }
137
138 explicit NaClBitcodeValueIndexDistElement(unsigned Index=0)
139 : NaClBitcodeDistElement(RDE_ValueIndexDist),
140 ValueDist(Index) {
141 NestedDists.push_back(&ValueDist);
142 }
143
144 static NaClBitcodeValueIndexDistElement Sentinel;
145
146 virtual ~NaClBitcodeValueIndexDistElement();
147
148 virtual NaClBitcodeDistElement *CreateElement(
149 NaClBitcodeDistValue Value) const;
150
151 virtual void GetValueList(const NaClBitcodeRecord &Record,
152 ValueListType &ValueList) const;
153
154 virtual double GetImportance(NaClBitcodeDistValue Value) const;
155
156 virtual void AddRecord(const NaClBitcodeRecord &Record);
157
158 virtual const char *GetTitle() const;
159
160 virtual const char *GetValueHeader() const;
161
162 virtual void PrintRowValue(raw_ostream &Stream,
163 NaClBitcodeDistValue Value,
164 const NaClBitcodeDist *Distribution) const;
165
166 virtual const SmallVectorImpl<NaClBitcodeDist*> *
167 GetNestedDistributions() const;
168
169 NaClBitcodeValueDist &GetValueDist() {
170 return ValueDist;
171 }
172
173 private:
174 // Nested blocks used by GetNestedDistributions.
175 SmallVector<NaClBitcodeDist*, 1> NestedDists;
176
177 // The value distribution associated with the given index.
178 NaClBitcodeValueDist ValueDist;
179 };
180
181 }
182
183 #endif
OLDNEW
« no previous file with comments | « include/llvm/Bitcode/NaCl/NaClBitcodeSubblockDist.h ('k') | include/llvm/Bitcode/NaCl/NaClBitcodeWriterPass.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698