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

Side by Side Diff: lib/Bitcode/NaCl/Writer/NaClValueEnumerator.h

Issue 939073008: Rebased PNaCl localmods in LLVM to 223109 (Closed)
Patch Set: undo localmod Created 5 years, 10 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 //===-- Bitcode/NaCl/Writer/NaClValueEnumerator.h - ----------*- C++ -*-===//
2 // Number values.
3 //
4 // The LLVM Compiler Infrastructure
5 //
6 // This file is distributed under the University of Illinois Open Source
7 // License. See LICENSE.TXT for details.
8 //
9 //===----------------------------------------------------------------------===//
10 //
11 // This class gives values and types Unique ID's.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #ifndef NACL_VALUE_ENUMERATOR_H
16 #define NACL_VALUE_ENUMERATOR_H
17
18 #include "llvm/ADT/DenseMap.h"
19 #include "llvm/ADT/SmallSet.h"
20 #include "llvm/ADT/SmallVector.h"
21 #include "llvm/Bitcode/NaCl/NaClReaderWriter.h"
22 #include <vector>
23
24 namespace llvm {
25
26 class Type;
27 class Value;
28 class Instruction;
29 class BasicBlock;
30 class Function;
31 class Module;
32 class ValueSymbolTable;
33 class raw_ostream;
34
35 class NaClValueEnumerator {
36 public:
37 typedef std::vector<Type*> TypeList;
38
39 // For each value, we remember its Value* and occurrence frequency.
40 typedef std::vector<std::pair<const Value*, unsigned> > ValueList;
41 private:
42 // Defines unique ID's for each type.
43 typedef DenseMap<Type*, unsigned> TypeMapType;
44 TypeMapType TypeMap;
45 // Defines the number of references to each type. If defined,
46 // we are in the first pass of collecting types, and reference counts
47 // should be added to the map. If undefined, we are in the second pass
48 // that actually assigns type IDs, based on frequency counts found in
49 // the first pass.
50 typedef TypeMapType TypeCountMapType;
51 TypeCountMapType* TypeCountMap;
52
53 TypeList Types;
54
55 typedef DenseMap<const Value*, unsigned> ValueMapType;
56 ValueMapType ValueMap;
57 ValueList Values;
58
59 typedef DenseMap<const Instruction*, unsigned> InstructionMapType;
60 InstructionMapType InstructionMap;
61 unsigned InstructionCount;
62
63 /// BasicBlocks - This contains all the basic blocks for the currently
64 /// incorporated function. Their reverse mapping is stored in ValueMap.
65 std::vector<const BasicBlock*> BasicBlocks;
66
67 /// When a function is incorporated, this is the size of the Values list
68 /// before incorporation.
69 unsigned NumModuleValues;
70
71 unsigned FirstFuncConstantID;
72 unsigned FirstInstID;
73
74 /// Holds values that have been forward referenced within a function.
75 /// Used to make sure we don't generate more forward reference declarations
76 /// than necessary.
77 SmallSet<unsigned, 32> FnForwardTypeRefs;
78
79 // The index of the first global variable ID in the bitcode file.
80 unsigned FirstGlobalVarID;
81 // The number of global variable IDs defined in the bitcode file.
82 unsigned NumGlobalVarIDs;
83
84 /// \brief Integer type use for PNaCl conversion of pointers.
85 Type *IntPtrType;
86
87 NaClValueEnumerator(const NaClValueEnumerator &) LLVM_DELETED_FUNCTION;
88 void operator=(const NaClValueEnumerator &) LLVM_DELETED_FUNCTION;
89 public:
90 NaClValueEnumerator(const Module *M);
91
92 void dump() const;
93 void print(raw_ostream &OS, const ValueMapType &Map, const char *Name) const;
94
95 unsigned getFirstGlobalVarID() const {
96 return FirstGlobalVarID;
97 }
98
99 unsigned getNumGlobalVarIDs() const {
100 return NumGlobalVarIDs;
101 }
102
103 unsigned getValueID(const Value *V) const;
104
105 unsigned getTypeID(Type *T) const {
106 TypeMapType::const_iterator I = TypeMap.find(NormalizeType(T));
107 assert(I != TypeMap.end() && "Type not in NaClValueEnumerator!");
108 return I->second-1;
109 }
110
111 unsigned getInstructionID(const Instruction *I) const;
112 void setInstructionID(const Instruction *I);
113
114 /// getFunctionConstantRange - Return the range of values that corresponds to
115 /// function-local constants.
116 void getFunctionConstantRange(unsigned &Start, unsigned &End) const {
117 Start = FirstFuncConstantID;
118 End = FirstInstID;
119 }
120
121 /// \brief Inserts the give value into the set of known function forward
122 /// value type refs. Returns true if the value id is added to the set.
123 bool InsertFnForwardTypeRef(unsigned ValID) {
124 return FnForwardTypeRefs.insert(ValID).second;
125 }
126
127 const ValueList &getValues() const { return Values; }
128 const TypeList &getTypes() const { return Types; }
129 const std::vector<const BasicBlock*> &getBasicBlocks() const {
130 return BasicBlocks;
131 }
132
133 /// incorporateFunction/purgeFunction - If you'd like to deal with a function,
134 /// use these two methods to get its data into the NaClValueEnumerator!
135 ///
136 void incorporateFunction(const Function &F);
137 void purgeFunction();
138
139 /// \brief Returns the value after elided (cast) operations have been
140 /// removed. Returns V if unable to elide the cast.
141 const Value *ElideCasts(const Value *V) const;
142
143 /// \brief Returns true if value V is an elided (cast) operation.
144 bool IsElidedCast(const Value *V) const {
145 return V != ElideCasts(V);
146 }
147
148 /// \brief Returns true if the type of V is the integer used to
149 /// model pointers in PNaCl.
150 bool IsIntPtrType(Type *T) const {
151 return T == IntPtrType;
152 }
153
154 Type *NormalizeType(Type *Ty) const;
155
156 private:
157 void OptimizeTypes(const Module *M);
158 void OptimizeConstants(unsigned CstStart, unsigned CstEnd);
159
160 void EnumerateValue(const Value *V);
161 void EnumerateType(Type *T, bool InsideOptimizeTypes=false);
162 void EnumerateOperandType(const Value *V);
163
164 void EnumerateValueSymbolTable(const ValueSymbolTable &ST);
165 };
166
167 } // End llvm namespace
168
169 #endif
OLDNEW
« no previous file with comments | « lib/Bitcode/NaCl/Writer/NaClBitcodeWriterPass.cpp ('k') | lib/Bitcode/NaCl/Writer/NaClValueEnumerator.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698