summaryrefslogtreecommitdiff
path: root/compiler/optimizing/scheduler.cc
diff options
context:
space:
mode:
author Vladimir Marko <vmarko@google.com> 2024-01-30 16:31:03 +0100
committer VladimĂ­r Marko <vmarko@google.com> 2024-01-31 11:34:16 +0000
commit5b9e42854c513d2f73466024b397634397a25ad6 (patch)
tree3369b0f315993ca92070c3db3462a5340bac60a0 /compiler/optimizing/scheduler.cc
parent6f337cb466e05eb51373a3f7b4e7d6dd95256ed8 (diff)
Do not create random scheduling selector if not needed.
Test: m test-art-host-gtest Test: testrunner.py --host --optimizing Bug: 181943478 Change-Id: I1fc3234243315ee1133d5a12c52d7f42ea8273bc
Diffstat (limited to 'compiler/optimizing/scheduler.cc')
-rw-r--r--compiler/optimizing/scheduler.cc12
1 files changed, 8 insertions, 4 deletions
diff --git a/compiler/optimizing/scheduler.cc b/compiler/optimizing/scheduler.cc
index 4c68844dbb..9b5091a81a 100644
--- a/compiler/optimizing/scheduler.cc
+++ b/compiler/optimizing/scheduler.cc
@@ -793,10 +793,14 @@ bool HInstructionScheduling::Run(bool only_optimize_loop_blocks,
// Phase-local allocator that allocates scheduler internal data structures like
// scheduling nodes, internel nodes map, dependencies, etc.
CriticalPathSchedulingNodeSelector critical_path_selector;
- RandomSchedulingNodeSelector random_selector;
- SchedulingNodeSelector* selector = schedule_randomly
- ? static_cast<SchedulingNodeSelector*>(&random_selector)
- : static_cast<SchedulingNodeSelector*>(&critical_path_selector);
+ // Do not create the `RandomSchedulingNodeSelector` if not requested.
+ // The construction is expensive, including a call to `srand()`.
+ std::optional<RandomSchedulingNodeSelector> random_selector;
+ SchedulingNodeSelector* selector = &critical_path_selector;
+ if (schedule_randomly) {
+ random_selector.emplace();
+ selector = &random_selector.value();
+ }
#else
// Avoid compilation error when compiling for unsupported instruction set.
UNUSED(only_optimize_loop_blocks);