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

Side by Side Diff: courgette/adjustment_method.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 | « no previous file | courgette/adjustment_method_2.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 #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 <list> 11 #include <list>
12 #include <map> 12 #include <map>
13 #include <set> 13 #include <set>
14 #include <string> 14 #include <string>
15 #include <vector> 15 #include <vector>
16 16
17 #include "base/bind.h"
17 #include "base/logging.h" 18 #include "base/logging.h"
18 #include "base/macros.h" 19 #include "base/macros.h"
19 #include "base/strings/string_number_conversions.h" 20 #include "base/strings/string_number_conversions.h"
20 #include "base/strings/stringprintf.h" 21 #include "base/strings/stringprintf.h"
21 #include "courgette/assembly_program.h" 22 #include "courgette/assembly_program.h"
22 #include "courgette/courgette.h" 23 #include "courgette/courgette.h"
23 #include "courgette/encoded_program.h" 24 #include "courgette/encoded_program.h"
24 25
25 namespace courgette { 26 namespace courgette {
26 27
(...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after
585 prog_->UnassignIndexes(); 586 prog_->UnassignIndexes();
586 CollectTraces(model_, &model_abs32_, &model_rel32_, true); 587 CollectTraces(model_, &model_abs32_, &model_rel32_, true);
587 CollectTraces(prog_, &prog_abs32_, &prog_rel32_, false); 588 CollectTraces(prog_, &prog_abs32_, &prog_rel32_, false);
588 Solve(model_abs32_, prog_abs32_); 589 Solve(model_abs32_, prog_abs32_);
589 Solve(model_rel32_, prog_rel32_); 590 Solve(model_rel32_, prog_rel32_);
590 prog_->AssignRemainingIndexes(); 591 prog_->AssignRemainingIndexes();
591 return true; 592 return true;
592 } 593 }
593 594
594 private: 595 private:
595
596 void CollectTraces(const AssemblyProgram* program, Trace* abs32, Trace* rel32, 596 void CollectTraces(const AssemblyProgram* program, Trace* abs32, Trace* rel32,
597 bool is_model) { 597 bool is_model) {
598 const InstructionVector& instructions = program->instructions(); 598 AssemblyProgram::LabelHandler abs32_handler =
599 for (size_t i = 0; i < instructions.size(); ++i) { 599 base::Bind(&GraphAdjuster::ReferenceLabel, base::Unretained(this),
600 Instruction* instruction = instructions[i]; 600 abs32, is_model);
601 if (Label* label = program->InstructionAbs32Label(instruction)) 601 AssemblyProgram::LabelHandler rel32_handler =
602 ReferenceLabel(abs32, label, is_model); 602 base::Bind(&GraphAdjuster::ReferenceLabel, base::Unretained(this),
603 if (Label* label = program->InstructionRel32Label(instruction)) 603 rel32, is_model);
604 ReferenceLabel(rel32, label, is_model); 604
605 } 605 program->HandleInstructionLabels({{ABS32, abs32_handler},
606 {REL32, rel32_handler},
607 {REL32ARM, rel32_handler}});
608
606 // TODO(sra): we could simply append all the labels in index order to 609 // TODO(sra): we could simply append all the labels in index order to
607 // incorporate some costing for entropy (bigger deltas) that will be 610 // incorporate some costing for entropy (bigger deltas) that will be
608 // introduced into the label address table by non-monotonic ordering. This 611 // introduced into the label address table by non-monotonic ordering. This
609 // would have some knock-on effects to parts of the algorithm that work on 612 // would have some knock-on effects to parts of the algorithm that work on
610 // single-occurrence labels. 613 // single-occurrence labels.
611 } 614 }
612 615
613 void Solve(const Trace& model, const Trace& problem) { 616 void Solve(const Trace& model, const Trace& problem) {
614 LinkLabelInfos(model); 617 LinkLabelInfos(model);
615 LinkLabelInfos(problem); 618 LinkLabelInfos(problem);
(...skipping 11 matching lines...) Expand all
627 LabelInfo* curr = *p; 630 LabelInfo* curr = *p;
628 if (prev) prev->next_addr_ = curr; 631 if (prev) prev->next_addr_ = curr;
629 curr->prev_addr_ = prev; 632 curr->prev_addr_ = prev;
630 prev = curr; 633 prev = curr;
631 634
632 if (curr->positions_.size() != curr->refs_) 635 if (curr->positions_.size() != curr->refs_)
633 NOTREACHED(); 636 NOTREACHED();
634 } 637 }
635 } 638 }
636 639
637 void ReferenceLabel(Trace* trace, Label* label, bool is_model) { 640 void ReferenceLabel(Trace* trace, bool is_model, Label* label) {
638 trace->push_back( 641 trace->push_back(
639 MakeLabelInfo(label, is_model, static_cast<uint32_t>(trace->size()))); 642 MakeLabelInfo(label, is_model, static_cast<uint32_t>(trace->size())));
640 } 643 }
641 644
642 LabelInfo* MakeLabelInfo(Label* label, bool is_model, uint32_t position) { 645 LabelInfo* MakeLabelInfo(Label* label, bool is_model, uint32_t position) {
643 LabelInfo& slot = label_infos_[label]; 646 LabelInfo& slot = label_infos_[label];
644 if (slot.label_ == NULL) { 647 if (slot.label_ == NULL) {
645 slot.label_ = label; 648 slot.label_ = label;
646 slot.is_model_ = is_model; 649 slot.is_model_ = is_model;
647 slot.debug_index_ = ++debug_label_index_gen_; 650 slot.debug_index_ = ++debug_label_index_gen_;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
686 AdjustmentMethod* method = AdjustmentMethod::MakeProductionAdjustmentMethod(); 689 AdjustmentMethod* method = AdjustmentMethod::MakeProductionAdjustmentMethod();
687 bool ok = method->Adjust(model, program); 690 bool ok = method->Adjust(model, program);
688 method->Destroy(); 691 method->Destroy();
689 if (ok) 692 if (ok)
690 return C_OK; 693 return C_OK;
691 else 694 else
692 return C_ADJUSTMENT_FAILED; 695 return C_ADJUSTMENT_FAILED;
693 } 696 }
694 697
695 } // namespace courgette 698 } // namespace courgette
OLDNEW
« no previous file with comments | « no previous file | courgette/adjustment_method_2.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698