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

Side by Side Diff: courgette/assembly_program.h

Issue 1935203002: [Courgette] Using LabelManager to reduce Courgette-apply peak RAM by 25%. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Sync. Created 4 years, 7 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
« no previous file with comments | « courgette/adjustment_method_unittest.cc ('k') | courgette/assembly_program.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef COURGETTE_ASSEMBLY_PROGRAM_H_ 5 #ifndef COURGETTE_ASSEMBLY_PROGRAM_H_
6 #define COURGETTE_ASSEMBLY_PROGRAM_H_ 6 #define COURGETTE_ASSEMBLY_PROGRAM_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 Label* label, 116 Label* label,
117 const uint8_t* arm_op, 117 const uint8_t* arm_op,
118 uint16_t op_size) WARN_UNUSED_RESULT; 118 uint16_t op_size) WARN_UNUSED_RESULT;
119 119
120 // Generates 4-byte absolute reference to address of 'label'. 120 // Generates 4-byte absolute reference to address of 'label'.
121 CheckBool EmitAbs32(Label* label) WARN_UNUSED_RESULT; 121 CheckBool EmitAbs32(Label* label) WARN_UNUSED_RESULT;
122 122
123 // Generates 8-byte absolute reference to address of 'label'. 123 // Generates 8-byte absolute reference to address of 'label'.
124 CheckBool EmitAbs64(Label* label) WARN_UNUSED_RESULT; 124 CheckBool EmitAbs64(Label* label) WARN_UNUSED_RESULT;
125 125
126 // Looks up a label or creates a new one. Might return NULL. 126 // Traverses RVAs in |abs32_visitor| and |rel32_visitor| to precompute Labels.
127 Label* FindOrMakeAbs32Label(RVA rva); 127 void PrecomputeLabels(RvaVisitor* abs32_visitor, RvaVisitor* rel32_visitor);
128 128
129 // Looks up a label or creates a new one. Might return NULL. 129 // Removes underused Labels. Thresholds used (0 = no trimming) is
130 Label* FindOrMakeRel32Label(RVA rva); 130 // architecture-dependent.
131 void TrimLabels();
131 132
133 void UnassignIndexes();
132 void DefaultAssignIndexes(); 134 void DefaultAssignIndexes();
133 void UnassignIndexes();
134 void AssignRemainingIndexes(); 135 void AssignRemainingIndexes();
135 136
137 // Looks up abs32 label. Returns null if none found.
138 Label* FindAbs32Label(RVA rva);
139
140 // Looks up rel32 label. Returns null if none found.
141 Label* FindRel32Label(RVA rva);
142
136 std::unique_ptr<EncodedProgram> Encode() const; 143 std::unique_ptr<EncodedProgram> Encode() const;
137 144
138 // Accessor for instruction list. 145 // Accessor for instruction list.
139 const InstructionVector& instructions() const { 146 const InstructionVector& instructions() const {
140 return instructions_; 147 return instructions_;
141 } 148 }
142 149
143 // Returns the label if the instruction contains an absolute 32-bit address, 150 // Returns the label if the instruction contains an absolute 32-bit address,
144 // otherwise returns NULL. 151 // otherwise returns NULL.
145 Label* InstructionAbs32Label(const Instruction* instruction) const; 152 Label* InstructionAbs32Label(const Instruction* instruction) const;
146 153
147 // Returns the label if the instruction contains an absolute 64-bit address, 154 // Returns the label if the instruction contains an absolute 64-bit address,
148 // otherwise returns NULL. 155 // otherwise returns NULL.
149 Label* InstructionAbs64Label(const Instruction* instruction) const; 156 Label* InstructionAbs64Label(const Instruction* instruction) const;
150 157
151 // Returns the label if the instruction contains a rel32 offset, 158 // Returns the label if the instruction contains a rel32 offset,
152 // otherwise returns NULL. 159 // otherwise returns NULL.
153 Label* InstructionRel32Label(const Instruction* instruction) const; 160 Label* InstructionRel32Label(const Instruction* instruction) const;
154 161
155 // Removes underused Labels. Thresholds used (may be 0, i.e., no trimming) is
156 // dependent on architecture. Returns true on success, and false otherwise.
157 CheckBool TrimLabels();
158
159 private: 162 private:
160 using ScopedInstruction = 163 using ScopedInstruction =
161 std::unique_ptr<Instruction, UncheckedDeleter<Instruction>>; 164 std::unique_ptr<Instruction, UncheckedDeleter<Instruction>>;
162 165
163 ExecutableType kind_; 166 ExecutableType kind_;
164 167
165 CheckBool Emit(ScopedInstruction instruction) WARN_UNUSED_RESULT; 168 CheckBool Emit(ScopedInstruction instruction) WARN_UNUSED_RESULT;
166 CheckBool EmitShared(Instruction* instruction) WARN_UNUSED_RESULT; 169 CheckBool EmitShared(Instruction* instruction) WARN_UNUSED_RESULT;
167 170
168 static const int kLabelLowerLimit; 171 static const int kLabelLowerLimit;
169 172
170 // Looks up a label or creates a new one. Might return NULL. 173 // Looks up a label or creates a new one. Might return NULL.
171 Label* FindLabel(RVA rva, RVAToLabel* labels); 174 Label* FindLabel(RVA rva, RVAToLabel* labels);
172 175
173 // Helper methods for the public versions. 176 // Helper methods for the public versions.
174 static void UnassignIndexes(RVAToLabel* labels); 177 static void UnassignIndexes(RVAToLabel* labels);
175 static void DefaultAssignIndexes(RVAToLabel* labels); 178 static void DefaultAssignIndexes(RVAToLabel* labels);
176 static void AssignRemainingIndexes(RVAToLabel* labels); 179 static void AssignRemainingIndexes(RVAToLabel* labels);
177 180
178 // Sharing instructions that emit a single byte saves a lot of space. 181 // Sharing instructions that emit a single byte saves a lot of space.
179 Instruction* GetByteInstruction(uint8_t byte); 182 Instruction* GetByteInstruction(uint8_t byte);
180 std::unique_ptr<Instruction* [], base::FreeDeleter> byte_instruction_cache_; 183 std::unique_ptr<Instruction* [], base::FreeDeleter> byte_instruction_cache_;
181 184
182 uint64_t image_base_; // Desired or mandated base address of image. 185 uint64_t image_base_; // Desired or mandated base address of image.
183 186
184 InstructionVector instructions_; // All the instructions in program. 187 InstructionVector instructions_; // All the instructions in program.
185 188
186 // These are lookup maps to find the label associated with a given address. 189 // Storage and lookup of Labels associated with target addresses. We use
187 // We have separate label spaces for addresses referenced by rel32 labels and 190 // separate abs32 and rel32 labels.
188 // abs32 labels. This is somewhat arbitrary. 191 LabelManager abs32_label_manager_;
189 RVAToLabel rel32_labels_; 192 LabelManager rel32_label_manager_;
190 RVAToLabel abs32_labels_;
191 193
192 DISALLOW_COPY_AND_ASSIGN(AssemblyProgram); 194 DISALLOW_COPY_AND_ASSIGN(AssemblyProgram);
193 }; 195 };
194 196
195 // Converts |program| into encoded form, returning it as |*output|. 197 // Converts |program| into encoded form, returning it as |*output|.
196 // Returns C_OK if succeeded, otherwise returns an error status and sets 198 // Returns C_OK if succeeded, otherwise returns an error status and sets
197 // |*output| to null. 199 // |*output| to null.
198 Status Encode(const AssemblyProgram& program, 200 Status Encode(const AssemblyProgram& program,
199 std::unique_ptr<EncodedProgram>* output); 201 std::unique_ptr<EncodedProgram>* output);
200 202
201 } // namespace courgette 203 } // namespace courgette
202 204
203 #endif // COURGETTE_ASSEMBLY_PROGRAM_H_ 205 #endif // COURGETTE_ASSEMBLY_PROGRAM_H_
OLDNEW
« no previous file with comments | « courgette/adjustment_method_unittest.cc ('k') | courgette/assembly_program.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698