diff --git a/src/compiler/instruction.cc b/src/compiler/instruction.cc index e53414bdb1..c4560b6e76 100644 --- a/src/compiler/instruction.cc +++ b/src/compiler/instruction.cc @@ -12,7 +12,8 @@ namespace v8 { namespace internal { namespace compiler { -const auto GetRegConfig = RegisterConfiguration::Turbofan; +const RegisterConfiguration* (*GetRegConfig)() = + RegisterConfiguration::Turbofan; FlagsCondition CommuteFlagsCondition(FlagsCondition condition) { switch (condition) { @@ -985,6 +986,21 @@ void InstructionSequence::PrintBlock(int block_id) const { PrintBlock(GetRegConfig(), block_id); } +const RegisterConfiguration* + InstructionSequence::registerConfigurationForTesting_ = nullptr; + +const RegisterConfiguration* +InstructionSequence::RegisterConfigurationForTesting() { + DCHECK(registerConfigurationForTesting_ != nullptr); + return registerConfigurationForTesting_; +} + +void InstructionSequence::SetRegisterConfigurationForTesting( + const RegisterConfiguration* regConfig) { + registerConfigurationForTesting_ = regConfig; + GetRegConfig = InstructionSequence::RegisterConfigurationForTesting; +} + FrameStateDescriptor::FrameStateDescriptor( Zone* zone, FrameStateType type, BailoutId bailout_id, OutputFrameStateCombine state_combine, size_t parameters_count, diff --git a/src/compiler/instruction.h b/src/compiler/instruction.h index 872d664f25..e63ceda148 100644 --- a/src/compiler/instruction.h +++ b/src/compiler/instruction.h @@ -1570,12 +1570,19 @@ class V8_EXPORT_PRIVATE InstructionSequence final void ValidateDeferredBlockEntryPaths() const; void ValidateSSA() const; + static void SetRegisterConfigurationForTesting( + const RegisterConfiguration* regConfig); + static void ClearRegisterConfigurationForTesting(); + private: friend V8_EXPORT_PRIVATE std::ostream& operator<<( std::ostream& os, const PrintableInstructionSequence& code); typedef ZoneMap SourcePositionMap; + static const RegisterConfiguration* RegisterConfigurationForTesting(); + static const RegisterConfiguration* registerConfigurationForTesting_; + Isolate* isolate_; Zone* const zone_; InstructionBlocks* const instruction_blocks_; diff --git a/test/unittests/compiler/instruction-sequence-unittest.cc b/test/unittests/compiler/instruction-sequence-unittest.cc index e61f690b4e..ee9f7914a6 100644 --- a/test/unittests/compiler/instruction-sequence-unittest.cc +++ b/test/unittests/compiler/instruction-sequence-unittest.cc @@ -85,7 +85,7 @@ int InstructionSequenceTest::GetAllocatableCode(int index, } } -RegisterConfiguration* InstructionSequenceTest::config() { +const RegisterConfiguration* InstructionSequenceTest::config() { if (!config_) { config_.reset(new RegisterConfiguration( num_general_registers_, num_double_registers_, num_general_registers_, @@ -105,6 +105,8 @@ InstructionSequence* InstructionSequenceTest::sequence() { if (sequence_ == nullptr) { sequence_ = new (zone()) InstructionSequence(isolate(), zone(), &instruction_blocks_); + sequence_->SetRegisterConfigurationForTesting( + InstructionSequenceTest::config()); } return sequence_; } diff --git a/test/unittests/compiler/instruction-sequence-unittest.h b/test/unittests/compiler/instruction-sequence-unittest.h index 8424834816..2c4df038fb 100644 --- a/test/unittests/compiler/instruction-sequence-unittest.h +++ b/test/unittests/compiler/instruction-sequence-unittest.h @@ -158,7 +158,7 @@ class InstructionSequenceTest : public TestWithIsolateAndZone { void SetNumRegs(int num_general_registers, int num_double_registers); int GetNumRegs(MachineRepresentation rep); int GetAllocatableCode(int index, MachineRepresentation rep = kNoRep); - RegisterConfiguration* config(); + const RegisterConfiguration* config(); InstructionSequence* sequence(); void StartLoop(int loop_blocks);