Commit 6be9ac9d authored by Georgia Kouveli's avatar Georgia Kouveli Committed by Commit Bot

[instruction-scheduler] Add a RandomNumberGenerator to InstructionScheduler

When running the tests with --turbo-stress-instruction-scheduling, there are
crashes in the cases where there is no isolate, since we used the random
generator from the isolate. This change introduces a RandomNumberGenerator to
the instruction scheduler instead.

We use the value from --random-seed for seeding the random number generator.
We don't treat a zero value specially, as the feature is meant to be used with
the test system which always sets a random seed and doesn't rely on default
behaviour. This also means that the instruction scheduler will always produce
the same result for the same input within the same run, which fixes another
issue with the x64 jump optimisation: when that optimisation is enabled, the
backend is ran twice, and previously it was producing a different schedule
each time, thus collecting incorrect jump information.

Bug: v8:9884
Change-Id: I00394a7e50d0c502254b18490ebaf28a38d8f819
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1895555Reviewed-by: 's avatarGeorg Neis <neis@chromium.org>
Commit-Queue: Georgia Kouveli <georgia.kouveli@arm.com>
Cr-Commit-Position: refs/heads/master@{#64769}
parent 7cceb727
......@@ -5,8 +5,8 @@
#include "src/compiler/backend/instruction-scheduler.h"
#include "src/base/iterator.h"
#include "src/base/optional.h"
#include "src/base/utils/random-number-generator.h"
#include "src/execution/isolate.h"
namespace v8 {
namespace internal {
......@@ -50,7 +50,7 @@ InstructionScheduler::StressSchedulerQueue::PopBestCandidate(int cycle) {
DCHECK(!IsEmpty());
// Choose a random element from the ready list.
auto candidate = nodes_.begin();
std::advance(candidate, isolate()->random_number_generator()->NextInt(
std::advance(candidate, random_number_generator()->NextInt(
static_cast<int>(nodes_.size())));
ScheduleGraphNode* result = *candidate;
nodes_.erase(candidate);
......@@ -81,7 +81,12 @@ InstructionScheduler::InstructionScheduler(Zone* zone,
pending_loads_(zone),
last_live_in_reg_marker_(nullptr),
last_deopt_or_trap_(nullptr),
operands_map_(zone) {}
operands_map_(zone) {
if (FLAG_turbo_stress_instruction_scheduling) {
random_number_generator_ =
base::Optional<base::RandomNumberGenerator>(FLAG_random_seed);
}
}
void InstructionScheduler::StartBlock(RpoNumber rpo) {
DCHECK(graph_.empty());
......
......@@ -5,10 +5,16 @@
#ifndef V8_COMPILER_BACKEND_INSTRUCTION_SCHEDULER_H_
#define V8_COMPILER_BACKEND_INSTRUCTION_SCHEDULER_H_
#include "src/base/optional.h"
#include "src/compiler/backend/instruction.h"
#include "src/zone/zone-containers.h"
namespace v8 {
namespace base {
class RandomNumberGenerator;
}
namespace internal {
namespace compiler {
......@@ -138,7 +144,9 @@ class InstructionScheduler final : public ZoneObject {
ScheduleGraphNode* PopBestCandidate(int cycle);
private:
Isolate* isolate() { return scheduler_->isolate(); }
base::RandomNumberGenerator* random_number_generator() {
return scheduler_->random_number_generator();
}
};
// Perform scheduling for the current block specifying the queue type to
......@@ -200,7 +208,9 @@ class InstructionScheduler final : public ZoneObject {
Zone* zone() { return zone_; }
InstructionSequence* sequence() { return sequence_; }
Isolate* isolate() { return sequence()->isolate(); }
base::RandomNumberGenerator* random_number_generator() {
return &random_number_generator_.value();
}
Zone* zone_;
InstructionSequence* sequence_;
......@@ -230,6 +240,8 @@ class InstructionScheduler final : public ZoneObject {
// Keep track of definition points for virtual registers. This is used to
// record operand dependencies in the scheduling graph.
ZoneMap<int32_t, ScheduleGraphNode*> operands_map_;
base::Optional<base::RandomNumberGenerator> random_number_generator_;
};
} // namespace compiler
......
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