Commit 8b9c543c authored by Victor Gomes's avatar Victor Gomes Committed by V8 LUCI CQ

[maglev][cleanup] Create MergePointIFS::NewForLoop and NewForCatchBlock

This makes it clear that the constructors are to be used for a basic block that starts a loop or a basic block that starts an exception handler.

Bug: v8:7700
Change-Id: Ic58dd80f223e45b4e5cf5da6e78e989ba18d55a3
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3870916
Auto-Submit: Victor Gomes <victorgomes@chromium.org>
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Reviewed-by: 's avatarLeszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/main@{#82944}
parent 14ec87e2
...@@ -75,10 +75,8 @@ MaglevGraphBuilder::MaglevGraphBuilder(LocalIsolate* local_isolate, ...@@ -75,10 +75,8 @@ MaglevGraphBuilder::MaglevGraphBuilder(LocalIsolate* local_isolate,
for (auto& offset_and_info : bytecode_analysis().GetLoopInfos()) { for (auto& offset_and_info : bytecode_analysis().GetLoopInfos()) {
int offset = offset_and_info.first; int offset = offset_and_info.first;
const compiler::LoopInfo& loop_info = offset_and_info.second; const compiler::LoopInfo& loop_info = offset_and_info.second;
const compiler::BytecodeLivenessState* liveness = GetInLivenessFor(offset); const compiler::BytecodeLivenessState* liveness = GetInLivenessFor(offset);
merge_states_[offset] = MergePointInterpreterFrameState::NewForLoop(
merge_states_[offset] = zone()->New<MergePointInterpreterFrameState>(
*compilation_unit_, offset, NumPredecessors(offset), liveness, *compilation_unit_, offset, NumPredecessors(offset), liveness,
&loop_info); &loop_info);
} }
...@@ -90,7 +88,7 @@ MaglevGraphBuilder::MaglevGraphBuilder(LocalIsolate* local_isolate, ...@@ -90,7 +88,7 @@ MaglevGraphBuilder::MaglevGraphBuilder(LocalIsolate* local_isolate,
const compiler::BytecodeLivenessState* liveness = const compiler::BytecodeLivenessState* liveness =
GetInLivenessFor(offset); GetInLivenessFor(offset);
DCHECK_EQ(NumPredecessors(offset), 0); DCHECK_EQ(NumPredecessors(offset), 0);
merge_states_[offset] = zone()->New<MergePointInterpreterFrameState>( merge_states_[offset] = MergePointInterpreterFrameState::NewForCatchBlock(
*compilation_unit_, liveness, offset); *compilation_unit_, liveness, offset);
} }
} }
...@@ -1750,10 +1748,9 @@ void MaglevGraphBuilder::InlineCallFromRegisters( ...@@ -1750,10 +1748,9 @@ void MaglevGraphBuilder::InlineCallFromRegisters(
// Create a new block at our current offset, and resume execution. Do this // Create a new block at our current offset, and resume execution. Do this
// manually to avoid trying to resolve any merges to this offset, which will // manually to avoid trying to resolve any merges to this offset, which will
// have already been processed on entry to this visitor. // have already been processed on entry to this visitor.
current_block_ = current_block_ = zone()->New<BasicBlock>(MergePointInterpreterFrameState::New(
zone()->New<BasicBlock>(zone()->New<MergePointInterpreterFrameState>( *compilation_unit_, current_interpreter_frame_,
*compilation_unit_, current_interpreter_frame_, iterator_.current_offset(), 1, block, GetInLiveness()));
iterator_.current_offset(), 1, block, GetInLiveness()));
block_offset_ = iterator_.current_offset(); block_offset_ = iterator_.current_offset();
// Set the exit JumpFromInlined to jump to this resume block. // Set the exit JumpFromInlined to jump to this resume block.
// TODO(leszeks): Passing start_ref to JumpFromInlined creates a two-element // TODO(leszeks): Passing start_ref to JumpFromInlined creates a two-element
...@@ -2507,7 +2504,7 @@ void MaglevGraphBuilder::MergeIntoFrameState(BasicBlock* predecessor, ...@@ -2507,7 +2504,7 @@ void MaglevGraphBuilder::MergeIntoFrameState(BasicBlock* predecessor,
DCHECK(!bytecode_analysis().IsLoopHeader(target)); DCHECK(!bytecode_analysis().IsLoopHeader(target));
const compiler::BytecodeLivenessState* liveness = GetInLivenessFor(target); const compiler::BytecodeLivenessState* liveness = GetInLivenessFor(target);
// If there's no target frame state, allocate a new one. // If there's no target frame state, allocate a new one.
merge_states_[target] = zone()->New<MergePointInterpreterFrameState>( merge_states_[target] = MergePointInterpreterFrameState::New(
*compilation_unit_, current_interpreter_frame_, target, *compilation_unit_, current_interpreter_frame_, target,
NumPredecessors(target), predecessor, liveness); NumPredecessors(target), predecessor, liveness);
} else { } else {
...@@ -2553,7 +2550,7 @@ void MaglevGraphBuilder::MergeIntoInlinedReturnFrameState( ...@@ -2553,7 +2550,7 @@ void MaglevGraphBuilder::MergeIntoInlinedReturnFrameState(
DCHECK_EQ(liveness->live_value_count(), 1); DCHECK_EQ(liveness->live_value_count(), 1);
// If there's no target frame state, allocate a new one. // If there's no target frame state, allocate a new one.
merge_states_[target] = zone()->New<MergePointInterpreterFrameState>( merge_states_[target] = MergePointInterpreterFrameState::New(
*compilation_unit_, current_interpreter_frame_, target, *compilation_unit_, current_interpreter_frame_, target,
NumPredecessors(target), predecessor, liveness); NumPredecessors(target), predecessor, liveness);
} else { } else {
......
...@@ -429,75 +429,85 @@ class MergePointInterpreterFrameState { ...@@ -429,75 +429,85 @@ class MergePointInterpreterFrameState {
#endif #endif
} }
MergePointInterpreterFrameState( static MergePointInterpreterFrameState* New(
const MaglevCompilationUnit& info, const InterpreterFrameState& state, const MaglevCompilationUnit& info, const InterpreterFrameState& state,
int merge_offset, int predecessor_count, BasicBlock* predecessor, int merge_offset, int predecessor_count, BasicBlock* predecessor,
const compiler::BytecodeLivenessState* liveness) const compiler::BytecodeLivenessState* liveness) {
: predecessor_count_(predecessor_count), MergePointInterpreterFrameState* merge_state =
predecessors_so_far_(1), info.zone()->New<MergePointInterpreterFrameState>(
basic_block_type_(BasicBlockType::kDefault), info, predecessor_count, 1,
predecessors_(info.zone()->NewArray<BasicBlock*>(predecessor_count)), info.zone()->NewArray<BasicBlock*>(predecessor_count),
frame_state_(info, liveness, state), BasicBlockType::kDefault, liveness);
known_node_aspects_(state.known_node_aspects().Clone(info.zone())) { merge_state->frame_state_.ForEachValue(
predecessors_[0] = predecessor; info, [&](ValueNode*& entry, interpreter::Register reg) {
entry = state.get(reg);
});
merge_state->predecessors_[0] = predecessor;
merge_state->known_node_aspects_ =
info.zone()->New<KnownNodeAspects>(info.zone());
return merge_state;
} }
MergePointInterpreterFrameState( static MergePointInterpreterFrameState* NewForLoop(
const MaglevCompilationUnit& info, int merge_offset, const MaglevCompilationUnit& info, int merge_offset,
int predecessor_count, const compiler::BytecodeLivenessState* liveness, int predecessor_count, const compiler::BytecodeLivenessState* liveness,
const compiler::LoopInfo* loop_info) const compiler::LoopInfo* loop_info) {
: predecessor_count_(predecessor_count), MergePointInterpreterFrameState* state =
predecessors_so_far_(0), info.zone()->New<MergePointInterpreterFrameState>(
basic_block_type_(BasicBlockType::kLoopHeader), info, predecessor_count, 0,
predecessors_(info.zone()->NewArray<BasicBlock*>(predecessor_count)), info.zone()->NewArray<BasicBlock*>(predecessor_count),
frame_state_(info, liveness) { BasicBlockType::kLoopHeader, liveness);
auto& assignments = loop_info->assignments(); auto& assignments = loop_info->assignments();
frame_state_.ForEachParameter( auto& frame_state = state->frame_state_;
frame_state.ForEachParameter(
info, [&](ValueNode*& entry, interpreter::Register reg) { info, [&](ValueNode*& entry, interpreter::Register reg) {
entry = nullptr; entry = nullptr;
if (assignments.ContainsParameter(reg.ToParameterIndex())) { if (assignments.ContainsParameter(reg.ToParameterIndex())) {
entry = NewLoopPhi(info.zone(), reg, merge_offset); entry = state->NewLoopPhi(info.zone(), reg, merge_offset);
} }
}); });
frame_state_.context(info) = nullptr; frame_state.context(info) = nullptr;
frame_state_.ForEachLocal( frame_state.ForEachLocal(
info, [&](ValueNode*& entry, interpreter::Register reg) { info, [&](ValueNode*& entry, interpreter::Register reg) {
entry = nullptr; entry = nullptr;
if (assignments.ContainsLocal(reg.index())) { if (assignments.ContainsLocal(reg.index())) {
entry = NewLoopPhi(info.zone(), reg, merge_offset); entry = state->NewLoopPhi(info.zone(), reg, merge_offset);
} }
}); });
DCHECK(!frame_state_.liveness()->AccumulatorIsLive()); DCHECK(!frame_state.liveness()->AccumulatorIsLive());
return state;
} }
MergePointInterpreterFrameState( static MergePointInterpreterFrameState* NewForCatchBlock(
const MaglevCompilationUnit& info, const MaglevCompilationUnit& info,
const compiler::BytecodeLivenessState* liveness, int handler_offset) const compiler::BytecodeLivenessState* liveness, int handler_offset) {
: predecessor_count_(0), MergePointInterpreterFrameState* state =
predecessors_so_far_(0), info.zone()->New<MergePointInterpreterFrameState>(
basic_block_type_(BasicBlockType::kExceptionHandlerStart), info, 0, 0, nullptr, BasicBlockType::kExceptionHandlerStart,
predecessors_(nullptr), liveness);
frame_state_(info, liveness), auto& frame_state = state->frame_state_;
known_node_aspects_(info.zone()->New<KnownNodeAspects>(info.zone())) {
// If the accumulator is live, the ExceptionPhi associated to it is the // If the accumulator is live, the ExceptionPhi associated to it is the
// first one in the block. That ensures it gets kReturnValue0 in the // first one in the block. That ensures it gets kReturnValue0 in the
// register allocator. See // register allocator. See
// StraightForwardRegisterAllocator::AllocateRegisters. // StraightForwardRegisterAllocator::AllocateRegisters.
if (frame_state_.liveness()->AccumulatorIsLive()) { if (frame_state.liveness()->AccumulatorIsLive()) {
frame_state_.accumulator(info) = NewExceptionPhi( frame_state.accumulator(info) = state->NewExceptionPhi(
info.zone(), interpreter::Register::virtual_accumulator(), info.zone(), interpreter::Register::virtual_accumulator(),
handler_offset); handler_offset);
} }
frame_state_.ForEachParameter( frame_state.ForEachParameter(
info, [&](ValueNode*& entry, interpreter::Register reg) { info, [&](ValueNode*& entry, interpreter::Register reg) {
entry = NewExceptionPhi(info.zone(), reg, handler_offset); entry = state->NewExceptionPhi(info.zone(), reg, handler_offset);
}); });
frame_state_.context(info) = NewExceptionPhi( frame_state.context(info) = state->NewExceptionPhi(
info.zone(), interpreter::Register::current_context(), handler_offset); info.zone(), interpreter::Register::current_context(), handler_offset);
frame_state_.ForEachLocal( frame_state.ForEachLocal(
info, [&](ValueNode*& entry, interpreter::Register reg) { info, [&](ValueNode*& entry, interpreter::Register reg) {
entry = NewExceptionPhi(info.zone(), reg, handler_offset); entry = state->NewExceptionPhi(info.zone(), reg, handler_offset);
}); });
state->known_node_aspects_ =
info.zone()->New<KnownNodeAspects>(info.zone());
return state;
} }
// Merges an unmerged framestate with a possibly merged framestate into |this| // Merges an unmerged framestate with a possibly merged framestate into |this|
...@@ -659,6 +669,19 @@ class MergePointInterpreterFrameState { ...@@ -659,6 +669,19 @@ class MergePointInterpreterFrameState {
const MaglevCompilationUnit& info, const MaglevCompilationUnit& info,
const MergePointInterpreterFrameState& state); const MergePointInterpreterFrameState& state);
template <typename T, typename... Args>
friend T* Zone::New(Args&&... args);
MergePointInterpreterFrameState(
const MaglevCompilationUnit& info, int predecessor_count,
int predecessors_so_far, BasicBlock** predecessors, BasicBlockType type,
const compiler::BytecodeLivenessState* liveness)
: predecessor_count_(predecessor_count),
predecessors_so_far_(predecessors_so_far),
predecessors_(predecessors),
basic_block_type_(type),
frame_state_(info, liveness) {}
ValueNode* FromInt32ToTagged(MaglevCompilationUnit& compilation_unit, ValueNode* FromInt32ToTagged(MaglevCompilationUnit& compilation_unit,
ValueNode* value) { ValueNode* value) {
DCHECK_EQ(value->properties().value_representation(), DCHECK_EQ(value->properties().value_representation(),
...@@ -846,9 +869,10 @@ class MergePointInterpreterFrameState { ...@@ -846,9 +869,10 @@ class MergePointInterpreterFrameState {
int predecessor_count_; int predecessor_count_;
int predecessors_so_far_; int predecessors_so_far_;
BasicBlock** predecessors_;
BasicBlockType basic_block_type_; BasicBlockType basic_block_type_;
Phi::List phis_; Phi::List phis_;
BasicBlock** predecessors_;
CompactInterpreterFrameState frame_state_; CompactInterpreterFrameState frame_state_;
MergePointRegisterState register_state_; MergePointRegisterState register_state_;
......
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