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

Side by Side Diff: courgette/adjustment_method_2.cc

Issue 2457133002: [Courgette] Refactor: Add AssemblyProgram::DispatchInstructionLabels() to hide InstructionVector us… (Closed)
Patch Set: Rename 'Dispatch' to 'Handle'. Created 4 years, 1 month 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.cc ('k') | courgette/assembly_program.h » ('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 #include "courgette/adjustment_method.h" 5 #include "courgette/adjustment_method.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
11 #include <limits> 11 #include <limits>
12 #include <list> 12 #include <list>
13 #include <map> 13 #include <map>
14 #include <set> 14 #include <set>
15 #include <string> 15 #include <string>
16 #include <vector> 16 #include <vector>
17 17
18 #include "base/bind.h"
18 #include "base/format_macros.h" 19 #include "base/format_macros.h"
19 #include "base/logging.h" 20 #include "base/logging.h"
20 #include "base/macros.h" 21 #include "base/macros.h"
21 #include "base/strings/stringprintf.h" 22 #include "base/strings/stringprintf.h"
22 #include "base/time/time.h" 23 #include "base/time/time.h"
23 #include "courgette/assembly_program.h" 24 #include "courgette/assembly_program.h"
24 #include "courgette/courgette.h" 25 #include "courgette/courgette.h"
25 #include "courgette/encoded_program.h" 26 #include "courgette/encoded_program.h"
26 27
27 /* 28 /*
(...skipping 1217 matching lines...) Expand 10 before | Expand all | Expand 10 after
1245 Solve(abs32_trace_, abs32_model_end); 1246 Solve(abs32_trace_, abs32_model_end);
1246 Solve(rel32_trace_, rel32_model_end); 1247 Solve(rel32_trace_, rel32_model_end);
1247 prog_->AssignRemainingIndexes(); 1248 prog_->AssignRemainingIndexes();
1248 return true; 1249 return true;
1249 } 1250 }
1250 1251
1251 private: 1252 private:
1252 void CollectTraces(const AssemblyProgram* program, Trace* abs32, Trace* rel32, 1253 void CollectTraces(const AssemblyProgram* program, Trace* abs32, Trace* rel32,
1253 bool is_model) { 1254 bool is_model) {
1254 label_info_maker_.ResetDebugLabel(); 1255 label_info_maker_.ResetDebugLabel();
1255 const InstructionVector& instructions = program->instructions(); 1256
1256 for (size_t i = 0; i < instructions.size(); ++i) { 1257 AssemblyProgram::LabelHandler abs32_handler = base::Bind(
1257 Instruction* instruction = instructions[i]; 1258 &Adjuster::ReferenceLabel, base::Unretained(this), abs32, is_model);
1258 if (Label* label = program->InstructionAbs32Label(instruction)) 1259 AssemblyProgram::LabelHandler rel32_handler = base::Bind(
1259 ReferenceLabel(abs32, label, is_model); 1260 &Adjuster::ReferenceLabel, base::Unretained(this), rel32, is_model);
1260 if (Label* label = program->InstructionAbs64Label(instruction)) 1261
1261 ReferenceLabel(abs32, label, is_model); 1262 program->HandleInstructionLabels({{ABS32, abs32_handler},
1262 if (Label* label = program->InstructionRel32Label(instruction)) 1263 {ABS64, abs32_handler},
1263 ReferenceLabel(rel32, label, is_model); 1264 {REL32, rel32_handler},
1264 } 1265 {REL32ARM, rel32_handler}});
1266
1265 // TODO(sra): we could simply append all the labels in index order to 1267 // TODO(sra): we could simply append all the labels in index order to
1266 // incorporate some costing for entropy (bigger deltas) that will be 1268 // incorporate some costing for entropy (bigger deltas) that will be
1267 // introduced into the label address table by non-monotonic ordering. This 1269 // introduced into the label address table by non-monotonic ordering. This
1268 // would have some knock-on effects to parts of the algorithm that work on 1270 // would have some knock-on effects to parts of the algorithm that work on
1269 // single-occurrence labels. 1271 // single-occurrence labels.
1270 } 1272 }
1271 1273
1272 void Solve(const Trace& model, size_t model_end) { 1274 void Solve(const Trace& model, size_t model_end) {
1273 base::Time start_time = base::Time::Now(); 1275 base::Time start_time = base::Time::Now();
1274 AssignmentProblem a(model, model_end); 1276 AssignmentProblem a(model, model_end);
1275 a.Solve(); 1277 a.Solve();
1276 VLOG(1) << " Adjuster::Solve " 1278 VLOG(1) << " Adjuster::Solve "
1277 << (base::Time::Now() - start_time).InSecondsF(); 1279 << (base::Time::Now() - start_time).InSecondsF();
1278 } 1280 }
1279 1281
1280 void ReferenceLabel(Trace* trace, Label* label, bool is_model) { 1282 void ReferenceLabel(Trace* trace, bool is_model, Label* label) {
1281 trace->push_back(label_info_maker_.MakeLabelInfo( 1283 trace->push_back(label_info_maker_.MakeLabelInfo(
1282 label, is_model, static_cast<uint32_t>(trace->size()))); 1284 label, is_model, static_cast<uint32_t>(trace->size())));
1283 } 1285 }
1284 1286
1285 AssemblyProgram* prog_; // Program to be adjusted, owned by caller. 1287 AssemblyProgram* prog_; // Program to be adjusted, owned by caller.
1286 const AssemblyProgram* model_; // Program to be mimicked, owned by caller. 1288 const AssemblyProgram* model_; // Program to be mimicked, owned by caller.
1287 1289
1288 LabelInfoMaker label_info_maker_; 1290 LabelInfoMaker label_info_maker_;
1289 1291
1290 private: 1292 private:
1291 DISALLOW_COPY_AND_ASSIGN(Adjuster); 1293 DISALLOW_COPY_AND_ASSIGN(Adjuster);
1292 }; 1294 };
1293 1295
1294 //////////////////////////////////////////////////////////////////////////////// 1296 ////////////////////////////////////////////////////////////////////////////////
1295 1297
1296 } // namespace adjustment_method_2 1298 } // namespace adjustment_method_2
1297 1299
1298 AdjustmentMethod* AdjustmentMethod::MakeShingleAdjustmentMethod() { 1300 AdjustmentMethod* AdjustmentMethod::MakeShingleAdjustmentMethod() {
1299 return new adjustment_method_2::Adjuster(); 1301 return new adjustment_method_2::Adjuster();
1300 } 1302 }
1301 1303
1302 } // namespace courgette 1304 } // namespace courgette
OLDNEW
« no previous file with comments | « courgette/adjustment_method.cc ('k') | courgette/assembly_program.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698