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,
for (auto& offset_and_info : bytecode_analysis().GetLoopInfos()) {
int offset = offset_and_info.first;
const compiler::LoopInfo& loop_info = offset_and_info.second;
const compiler::BytecodeLivenessState* liveness = GetInLivenessFor(offset);
merge_states_[offset] = zone()->New<MergePointInterpreterFrameState>(
merge_states_[offset] = MergePointInterpreterFrameState::NewForLoop(
*compilation_unit_, offset, NumPredecessors(offset), liveness,
&loop_info);
}
......@@ -90,7 +88,7 @@ MaglevGraphBuilder::MaglevGraphBuilder(LocalIsolate* local_isolate,
const compiler::BytecodeLivenessState* liveness =
GetInLivenessFor(offset);
DCHECK_EQ(NumPredecessors(offset), 0);
merge_states_[offset] = zone()->New<MergePointInterpreterFrameState>(
merge_states_[offset] = MergePointInterpreterFrameState::NewForCatchBlock(
*compilation_unit_, liveness, offset);
}
}
......@@ -1750,10 +1748,9 @@ void MaglevGraphBuilder::InlineCallFromRegisters(
// 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
// have already been processed on entry to this visitor.
current_block_ =
zone()->New<BasicBlock>(zone()->New<MergePointInterpreterFrameState>(
*compilation_unit_, current_interpreter_frame_,
iterator_.current_offset(), 1, block, GetInLiveness()));
current_block_ = zone()->New<BasicBlock>(MergePointInterpreterFrameState::New(
*compilation_unit_, current_interpreter_frame_,
iterator_.current_offset(), 1, block, GetInLiveness()));
block_offset_ = iterator_.current_offset();
// Set the exit JumpFromInlined to jump to this resume block.
// TODO(leszeks): Passing start_ref to JumpFromInlined creates a two-element
......@@ -2507,7 +2504,7 @@ void MaglevGraphBuilder::MergeIntoFrameState(BasicBlock* predecessor,
DCHECK(!bytecode_analysis().IsLoopHeader(target));
const compiler::BytecodeLivenessState* liveness = GetInLivenessFor(target);
// 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,
NumPredecessors(target), predecessor, liveness);
} else {
......@@ -2553,7 +2550,7 @@ void MaglevGraphBuilder::MergeIntoInlinedReturnFrameState(
DCHECK_EQ(liveness->live_value_count(), 1);
// 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,
NumPredecessors(target), predecessor, liveness);
} else {
......
......@@ -429,75 +429,85 @@ class MergePointInterpreterFrameState {
#endif
}
MergePointInterpreterFrameState(
static MergePointInterpreterFrameState* New(
const MaglevCompilationUnit& info, const InterpreterFrameState& state,
int merge_offset, int predecessor_count, BasicBlock* predecessor,
const compiler::BytecodeLivenessState* liveness)
: predecessor_count_(predecessor_count),
predecessors_so_far_(1),
basic_block_type_(BasicBlockType::kDefault),
predecessors_(info.zone()->NewArray<BasicBlock*>(predecessor_count)),
frame_state_(info, liveness, state),
known_node_aspects_(state.known_node_aspects().Clone(info.zone())) {
predecessors_[0] = predecessor;
const compiler::BytecodeLivenessState* liveness) {
MergePointInterpreterFrameState* merge_state =
info.zone()->New<MergePointInterpreterFrameState>(
info, predecessor_count, 1,
info.zone()->NewArray<BasicBlock*>(predecessor_count),
BasicBlockType::kDefault, liveness);
merge_state->frame_state_.ForEachValue(
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,
int predecessor_count, const compiler::BytecodeLivenessState* liveness,
const compiler::LoopInfo* loop_info)
: predecessor_count_(predecessor_count),
predecessors_so_far_(0),
basic_block_type_(BasicBlockType::kLoopHeader),
predecessors_(info.zone()->NewArray<BasicBlock*>(predecessor_count)),
frame_state_(info, liveness) {
const compiler::LoopInfo* loop_info) {
MergePointInterpreterFrameState* state =
info.zone()->New<MergePointInterpreterFrameState>(
info, predecessor_count, 0,
info.zone()->NewArray<BasicBlock*>(predecessor_count),
BasicBlockType::kLoopHeader, liveness);
auto& assignments = loop_info->assignments();
frame_state_.ForEachParameter(
auto& frame_state = state->frame_state_;
frame_state.ForEachParameter(
info, [&](ValueNode*& entry, interpreter::Register reg) {
entry = nullptr;
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_.ForEachLocal(
frame_state.context(info) = nullptr;
frame_state.ForEachLocal(
info, [&](ValueNode*& entry, interpreter::Register reg) {
entry = nullptr;
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 compiler::BytecodeLivenessState* liveness, int handler_offset)
: predecessor_count_(0),
predecessors_so_far_(0),
basic_block_type_(BasicBlockType::kExceptionHandlerStart),
predecessors_(nullptr),
frame_state_(info, liveness),
known_node_aspects_(info.zone()->New<KnownNodeAspects>(info.zone())) {
const compiler::BytecodeLivenessState* liveness, int handler_offset) {
MergePointInterpreterFrameState* state =
info.zone()->New<MergePointInterpreterFrameState>(
info, 0, 0, nullptr, BasicBlockType::kExceptionHandlerStart,
liveness);
auto& frame_state = state->frame_state_;
// If the accumulator is live, the ExceptionPhi associated to it is the
// first one in the block. That ensures it gets kReturnValue0 in the
// register allocator. See
// StraightForwardRegisterAllocator::AllocateRegisters.
if (frame_state_.liveness()->AccumulatorIsLive()) {
frame_state_.accumulator(info) = NewExceptionPhi(
if (frame_state.liveness()->AccumulatorIsLive()) {
frame_state.accumulator(info) = state->NewExceptionPhi(
info.zone(), interpreter::Register::virtual_accumulator(),
handler_offset);
}
frame_state_.ForEachParameter(
frame_state.ForEachParameter(
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);
frame_state_.ForEachLocal(
frame_state.ForEachLocal(
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|
......@@ -659,6 +669,19 @@ class MergePointInterpreterFrameState {
const MaglevCompilationUnit& info,
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* value) {
DCHECK_EQ(value->properties().value_representation(),
......@@ -846,9 +869,10 @@ class MergePointInterpreterFrameState {
int predecessor_count_;
int predecessors_so_far_;
BasicBlock** predecessors_;
BasicBlockType basic_block_type_;
Phi::List phis_;
BasicBlock** predecessors_;
CompactInterpreterFrameState frame_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