Commit 2635521f authored by Samuel Huang's avatar Samuel Huang Committed by Commit Bot

[Courgette] Remove label trimming feature, which was used by ARM only.

Courgette's algorithm allow removal for underused labels. However, this
was only used by ARM, whose support is recently removed. This CL is a
follow-up to remove more dead code.

* Remove AssemblyProgram::TrimLabels()
* Remove LabelManager::RemoveUnderusedLabels() and usage in test.

Bug: 1012592
Change-Id: Ia50ee2ec9f90e35ce123463e06edc9bfb5a868af
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1987863Reviewed-by: default avatarEtienne Pierre-Doray <etiennep@chromium.org>
Commit-Queue: Samuel Huang <huangs@chromium.org>
Cr-Commit-Position: refs/heads/master@{#728682}
parent 30b19ef9
...@@ -67,20 +67,6 @@ void AssemblyProgram::PrecomputeLabels(RvaVisitor* abs32_visitor, ...@@ -67,20 +67,6 @@ void AssemblyProgram::PrecomputeLabels(RvaVisitor* abs32_visitor,
RvaVisitor* rel32_visitor) { RvaVisitor* rel32_visitor) {
abs32_label_manager_.Read(abs32_visitor); abs32_label_manager_.Read(abs32_visitor);
rel32_label_manager_.Read(rel32_visitor); rel32_label_manager_.Read(rel32_visitor);
// TrimLabels() should be called here if used. Previously this was used only
// for ARM binaries, but ARM support has been deprecated.
}
// Chosen empirically to give the best reduction in payload size for
// an update from daisy_3701.98.0 to daisy_4206.0.0.
const int AssemblyProgram::kLabelLowerLimit = 5;
void AssemblyProgram::TrimLabels() {
int lower_limit = kLabelLowerLimit;
VLOG(1) << "TrimLabels: threshold " << lower_limit;
rel32_label_manager_.RemoveUnderusedLabels(lower_limit);
} }
void AssemblyProgram::UnassignIndexes() { void AssemblyProgram::UnassignIndexes() {
......
...@@ -55,10 +55,6 @@ class AssemblyProgram { ...@@ -55,10 +55,6 @@ class AssemblyProgram {
// Traverses RVAs in |abs32_visitor| and |rel32_visitor| to precompute Labels. // Traverses RVAs in |abs32_visitor| and |rel32_visitor| to precompute Labels.
void PrecomputeLabels(RvaVisitor* abs32_visitor, RvaVisitor* rel32_visitor); void PrecomputeLabels(RvaVisitor* abs32_visitor, RvaVisitor* rel32_visitor);
// Removes underused Labels. Thresholds used (0 = no trimming) is
// architecture-dependent.
void TrimLabels();
void UnassignIndexes(); void UnassignIndexes();
void DefaultAssignIndexes(); void DefaultAssignIndexes();
void AssignRemainingIndexes(); void AssignRemainingIndexes();
......
...@@ -113,17 +113,6 @@ Label* LabelManager::Find(RVA rva) { ...@@ -113,17 +113,6 @@ Label* LabelManager::Find(RVA rva) {
return it == labels_.end() || it->rva_ != rva ? nullptr : &(*it); return it == labels_.end() || it->rva_ != rva ? nullptr : &(*it);
} }
void LabelManager::RemoveUnderusedLabels(int32_t count_threshold) {
if (count_threshold <= 0)
return;
labels_.erase(std::remove_if(labels_.begin(), labels_.end(),
[count_threshold](const Label& label) {
return label.count_ < count_threshold;
}),
labels_.end());
// Not shrinking |labels_|, since this may cause reallocation.
}
void LabelManager::UnassignIndexes() { void LabelManager::UnassignIndexes() {
for (Label& label : labels_) for (Label& label : labels_)
label.index_ = Label::kNoIndex; label.index_ = Label::kNoIndex;
......
...@@ -155,14 +155,6 @@ TEST(LabelManagerTest, Basic) { ...@@ -155,14 +155,6 @@ TEST(LabelManagerTest, Basic) {
EXPECT_EQ(nullptr, label_manager.Find(RVA(0x5F3759DF))); EXPECT_EQ(nullptr, label_manager.Find(RVA(0x5F3759DF)));
EXPECT_EQ(nullptr, label_manager.Find(RVA(0xFEEDFFF0))); EXPECT_EQ(nullptr, label_manager.Find(RVA(0xFEEDFFF0)));
EXPECT_EQ(nullptr, label_manager.Find(RVA(0xFFFFFFFF))); EXPECT_EQ(nullptr, label_manager.Find(RVA(0xFFFFFFFF)));
// Remove Labels with |count_| < 2.
label_manager.RemoveUnderusedLabels(2);
static const std::pair<RVA, int32_t> kExpected2Raw[] = {
{0x04000010, 3}, {0x04000030, 2}, {0xFEEDF00D, 2}};
std::map<RVA, int32_t> expected2(std::begin(kExpected2Raw),
std::end(kExpected2Raw));
CheckLabelManagerContent(&label_manager, expected2);
} }
TEST(LabelManagerTest, Single) { TEST(LabelManagerTest, Single) {
...@@ -324,8 +316,8 @@ TEST(LabelManagerTest, AssignRemainingIndexes) { ...@@ -324,8 +316,8 @@ TEST(LabelManagerTest, AssignRemainingIndexes) {
{"....AC", "BDEFAC"}, {"....AC", "BDEFAC"},
{"ED...C...B....A", "EDFGHCIJKBLMNOA"}, {"ED...C...B....A", "EDFGHCIJKBLMNOA"},
// Forward fill and infill. // Forward fill and infill.
{"E..", "EBA"}, // Forward: "A"; in: "B". {"E..", "EBA"}, // Forward: "A"; in: "B".
{"Z....", "ZDABC"}, // Forward: "ABC"; in: "D". {"Z....", "ZDABC"}, // Forward: "ABC"; in: "D".
{".E.....", "AEFGBCD"}, // Forward: "A", "FG"; in: "BCD". {".E.....", "AEFGBCD"}, // Forward: "A", "FG"; in: "BCD".
{"....C..", "ABFGCDE"}, // Forward: "AB", "DE"; in: "FG". {"....C..", "ABFGCDE"}, // Forward: "AB", "DE"; in: "FG".
{"...Z...", "ABCZDEF"}, // Forward: "ABC"; in: "DEF". {"...Z...", "ABCZDEF"}, // Forward: "ABC"; in: "DEF".
...@@ -337,7 +329,7 @@ TEST(LabelManagerTest, AssignRemainingIndexes) { ...@@ -337,7 +329,7 @@ TEST(LabelManagerTest, AssignRemainingIndexes) {
{"ANM..Z....L...T", "ANMXYZHIJKLQRST"}, {"ANM..Z....L...T", "ANMXYZHIJKLQRST"},
{"....G..Z...LAH", "CDEFGXYZIJKLAH"}, {"....G..Z...LAH", "CDEFGXYZIJKLAH"},
// Forward fill and backward fill. // Forward fill and backward fill.
{"..ZA..", "XYZABC"}, // Forward: "BC"; backward: "XY". {"..ZA..", "XYZABC"}, // Forward: "BC"; backward: "XY".
{".....ZD", "ABCXYZD"}, // Forward: "ABC"; backward: "XY". {".....ZD", "ABCXYZD"}, // Forward: "ABC"; backward: "XY".
{"DA.....", "DABCEFG"}, // Forward: "BC"; backward: "EFG". {"DA.....", "DABCEFG"}, // Forward: "BC"; backward: "EFG".
// Backward fill and infill. // Backward fill and infill.
...@@ -346,7 +338,7 @@ TEST(LabelManagerTest, AssignRemainingIndexes) { ...@@ -346,7 +338,7 @@ TEST(LabelManagerTest, AssignRemainingIndexes) {
// All. // All.
{".....ZED.", "ABCXYZEDF"}, // Forward: "ABC"; backward: "XY"; in: "F". {".....ZED.", "ABCXYZEDF"}, // Forward: "ABC"; backward: "XY"; in: "F".
{".....GD.", "ABCHFGDE"}, // Forward: "ABC", "E"; backward: "F"; in: "H". {".....GD.", "ABCHFGDE"}, // Forward: "ABC", "E"; backward: "F"; in: "H".
{"..FE..GD..", "ABFECHGDIJ"}, // Forward: "AB"; backward: "IJ"; in: "CH". {"..FE..GD..", "ABFECHGDIJ"}, // Forward: "AB"; backward: "IJ"; in: "CH".
}; };
for (const auto& test_case : kTestCases) { for (const auto& test_case : kTestCases) {
TestLabelManager label_manager; TestLabelManager label_manager;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment