| OLD | NEW |
| 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 561 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 |
| 596 void CollectTraces(const AssemblyProgram* program, Trace* abs32, Trace* rel32, | 597 void CollectTraces(const AssemblyProgram* program, Trace* abs32, Trace* rel32, |
| 597 bool is_model) { | 598 bool is_model) { |
| 598 const InstructionVector& instructions = program->instructions(); | 599 AssemblyProgram::LabelHandler abs32_handler = |
| 599 for (size_t i = 0; i < instructions.size(); ++i) { | 600 base::Bind(&GraphAdjuster::ReferenceLabel, base::Unretained(this), |
| 600 Instruction* instruction = instructions[i]; | 601 abs32, is_model); |
| 601 if (Label* label = program->InstructionAbs32Label(instruction)) | 602 AssemblyProgram::LabelHandler rel32_handler = |
| 602 ReferenceLabel(abs32, label, is_model); | 603 base::Bind(&GraphAdjuster::ReferenceLabel, base::Unretained(this), |
| 603 if (Label* label = program->InstructionRel32Label(instruction)) | 604 rel32, is_model); |
| 604 ReferenceLabel(rel32, label, is_model); | 605 |
| 605 } | 606 program->DispatchInstructionLabels({{ABS32, abs32_handler}, |
| 607 {REL32, rel32_handler}, |
| 608 {REL32ARM, rel32_handler}}); |
| 609 |
| 606 // TODO(sra): we could simply append all the labels in index order to | 610 // TODO(sra): we could simply append all the labels in index order to |
| 607 // incorporate some costing for entropy (bigger deltas) that will be | 611 // incorporate some costing for entropy (bigger deltas) that will be |
| 608 // introduced into the label address table by non-monotonic ordering. This | 612 // 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 | 613 // would have some knock-on effects to parts of the algorithm that work on |
| 610 // single-occurrence labels. | 614 // single-occurrence labels. |
| 611 } | 615 } |
| 612 | 616 |
| 613 void Solve(const Trace& model, const Trace& problem) { | 617 void Solve(const Trace& model, const Trace& problem) { |
| 614 LinkLabelInfos(model); | 618 LinkLabelInfos(model); |
| 615 LinkLabelInfos(problem); | 619 LinkLabelInfos(problem); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 627 LabelInfo* curr = *p; | 631 LabelInfo* curr = *p; |
| 628 if (prev) prev->next_addr_ = curr; | 632 if (prev) prev->next_addr_ = curr; |
| 629 curr->prev_addr_ = prev; | 633 curr->prev_addr_ = prev; |
| 630 prev = curr; | 634 prev = curr; |
| 631 | 635 |
| 632 if (curr->positions_.size() != curr->refs_) | 636 if (curr->positions_.size() != curr->refs_) |
| 633 NOTREACHED(); | 637 NOTREACHED(); |
| 634 } | 638 } |
| 635 } | 639 } |
| 636 | 640 |
| 637 void ReferenceLabel(Trace* trace, Label* label, bool is_model) { | 641 void ReferenceLabel(Trace* trace, bool is_model, Label* label) { |
| 638 trace->push_back( | 642 trace->push_back( |
| 639 MakeLabelInfo(label, is_model, static_cast<uint32_t>(trace->size()))); | 643 MakeLabelInfo(label, is_model, static_cast<uint32_t>(trace->size()))); |
| 640 } | 644 } |
| 641 | 645 |
| 642 LabelInfo* MakeLabelInfo(Label* label, bool is_model, uint32_t position) { | 646 LabelInfo* MakeLabelInfo(Label* label, bool is_model, uint32_t position) { |
| 643 LabelInfo& slot = label_infos_[label]; | 647 LabelInfo& slot = label_infos_[label]; |
| 644 if (slot.label_ == NULL) { | 648 if (slot.label_ == NULL) { |
| 645 slot.label_ = label; | 649 slot.label_ = label; |
| 646 slot.is_model_ = is_model; | 650 slot.is_model_ = is_model; |
| 647 slot.debug_index_ = ++debug_label_index_gen_; | 651 slot.debug_index_ = ++debug_label_index_gen_; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 686 AdjustmentMethod* method = AdjustmentMethod::MakeProductionAdjustmentMethod(); | 690 AdjustmentMethod* method = AdjustmentMethod::MakeProductionAdjustmentMethod(); |
| 687 bool ok = method->Adjust(model, program); | 691 bool ok = method->Adjust(model, program); |
| 688 method->Destroy(); | 692 method->Destroy(); |
| 689 if (ok) | 693 if (ok) |
| 690 return C_OK; | 694 return C_OK; |
| 691 else | 695 else |
| 692 return C_ADJUSTMENT_FAILED; | 696 return C_ADJUSTMENT_FAILED; |
| 693 } | 697 } |
| 694 | 698 |
| 695 } // namespace courgette | 699 } // namespace courgette |
| OLD | NEW |