Commit f884e2fa authored by Jakob Gruber's avatar Jakob Gruber Committed by Commit Bot

[compiler] Pass the max frame size to CodeGenerator

The maximal unoptimized frame size is calculated during instruction
selection and will be needed during code generation (it will be
applied as an offset to the stack check). Pass the information along
to the code generator through PipelineData.

Bug: v8:9534
Change-Id: Ia72cd70d57c3de2db9fe43d91b9378d8e2ab8a0a
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1762302
Commit-Queue: Jakob Gruber <jgruber@chromium.org>
Reviewed-by: 's avatarGeorg Neis <neis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#63451}
parent af31c024
......@@ -47,7 +47,8 @@ CodeGenerator::CodeGenerator(
Isolate* isolate, base::Optional<OsrHelper> osr_helper,
int start_source_position, JumpOptimizationInfo* jump_opt,
PoisoningMitigationLevel poisoning_level, const AssemblerOptions& options,
int32_t builtin_index, std::unique_ptr<AssemblerBuffer> buffer)
int32_t builtin_index, size_t max_unoptimized_frame_height,
std::unique_ptr<AssemblerBuffer> buffer)
: zone_(codegen_zone),
isolate_(isolate),
frame_access_state_(nullptr),
......@@ -66,6 +67,7 @@ CodeGenerator::CodeGenerator(
deoptimization_exits_(zone()),
deoptimization_literals_(zone()),
translations_(zone()),
max_unoptimized_frame_height_(max_unoptimized_frame_height),
caller_registers_saved_(false),
jump_tables_(nullptr),
ools_(nullptr),
......
......@@ -115,6 +115,7 @@ class V8_EXPORT_PRIVATE CodeGenerator final : public GapResolver::Assembler {
JumpOptimizationInfo* jump_opt,
PoisoningMitigationLevel poisoning_level,
const AssemblerOptions& options, int32_t builtin_index,
size_t max_unoptimized_frame_height,
std::unique_ptr<AssemblerBuffer> = {});
// Generate native code. After calling AssembleCode, call FinalizeCode to
......@@ -422,6 +423,10 @@ class V8_EXPORT_PRIVATE CodeGenerator final : public GapResolver::Assembler {
int handler_table_offset_ = 0;
int last_lazy_deopt_pc_ = 0;
// The maximal combined height of all frames produced upon deoptimization.
// Applied as an offset to the first stack check of an optimized function.
const size_t max_unoptimized_frame_height_;
// kArchCallCFunction could be reached either:
// kArchCallCFunction;
// or:
......
......@@ -26,6 +26,7 @@ InstructionSelector::InstructionSelector(
InstructionSequence* sequence, Schedule* schedule,
SourcePositionTable* source_positions, Frame* frame,
EnableSwitchJumpTable enable_switch_jump_table, TickCounter* tick_counter,
size_t* max_unoptimized_frame_height,
SourcePositionMode source_position_mode, Features features,
EnableScheduling enable_scheduling,
EnableRootsRelativeAddressing enable_roots_relative_addressing,
......@@ -56,7 +57,10 @@ InstructionSelector::InstructionSelector(
instruction_selection_failed_(false),
instr_origins_(sequence->zone()),
trace_turbo_(trace_turbo),
tick_counter_(tick_counter) {
tick_counter_(tick_counter),
max_unoptimized_frame_height_(max_unoptimized_frame_height) {
DCHECK_EQ(*max_unoptimized_frame_height, 0); // Caller-initialized.
instructions_.reserve(node_count);
continuation_inputs_.reserve(5);
continuation_outputs_.reserve(2);
......@@ -3073,8 +3077,8 @@ FrameStateDescriptor* GetFrameStateDescriptorInternal(Zone* zone, Node* state) {
FrameStateDescriptor* InstructionSelector::GetFrameStateDescriptor(
Node* state) {
auto* desc = GetFrameStateDescriptorInternal(instruction_zone(), state);
max_unoptimized_frame_height_ =
std::max(max_unoptimized_frame_height_,
*max_unoptimized_frame_height_ =
std::max(*max_unoptimized_frame_height_,
desc->total_conservative_frame_size_in_bytes());
return desc;
}
......
......@@ -271,6 +271,7 @@ class V8_EXPORT_PRIVATE InstructionSelector final {
InstructionSequence* sequence, Schedule* schedule,
SourcePositionTable* source_positions, Frame* frame,
EnableSwitchJumpTable enable_switch_jump_table, TickCounter* tick_counter,
size_t* max_unoptimized_frame_height,
SourcePositionMode source_position_mode = kCallSourcePositions,
Features features = SupportedFeatures(),
EnableScheduling enable_scheduling = FLAG_turbo_instruction_scheduling
......@@ -787,7 +788,7 @@ class V8_EXPORT_PRIVATE InstructionSelector final {
// Store the maximal unoptimized frame height. Later used to apply an offset
// to stack checks.
size_t max_unoptimized_frame_height_ = 0;
size_t* max_unoptimized_frame_height_;
};
} // namespace compiler
......
......@@ -323,6 +323,13 @@ class PipelineData {
return assembler_options_;
}
size_t* address_of_max_unoptimized_frame_height() {
return &max_unoptimized_frame_height_;
}
size_t max_unoptimized_frame_height() const {
return max_unoptimized_frame_height_;
}
CodeTracer* GetCodeTracer() const {
return wasm_engine_ == nullptr ? isolate_->GetCodeTracer()
: wasm_engine_->GetCodeTracer();
......@@ -437,7 +444,8 @@ class PipelineData {
codegen_zone(), frame(), linkage, sequence(), info(), isolate(),
osr_helper_, start_source_position_, jump_optimization_info_,
info()->GetPoisoningMitigationLevel(), assembler_options_,
info_->builtin_index(), std::move(buffer));
info_->builtin_index(), max_unoptimized_frame_height(),
std::move(buffer));
}
void BeginPhaseKind(const char* phase_kind_name) {
......@@ -524,6 +532,11 @@ class PipelineData {
JumpOptimizationInfo* jump_optimization_info_ = nullptr;
AssemblerOptions assembler_options_;
// The maximal combined height of all inlined frames in their unoptimized
// state. Calculated during instruction selection, applied during code
// generation.
size_t max_unoptimized_frame_height_ = 0;
DISALLOW_COPY_AND_ASSIGN(PipelineData);
};
......@@ -1873,6 +1886,7 @@ struct InstructionSelectionPhase {
? InstructionSelector::kEnableSwitchJumpTable
: InstructionSelector::kDisableSwitchJumpTable,
&data->info()->tick_counter(),
data->address_of_max_unoptimized_frame_height(),
data->info()->is_source_positions_enabled()
? InstructionSelector::kAllSourcePositions
: InstructionSelector::kCallSourcePositions,
......
......@@ -990,13 +990,14 @@ class CodeGeneratorTester {
i++;
}
static constexpr size_t kMaxUnoptimizedFrameHeight = 0;
generator_ = new CodeGenerator(
environment->main_zone(), &frame_, &linkage_,
environment->instructions(), &info_, environment->main_isolate(),
base::Optional<OsrHelper>(), kNoSourcePosition, nullptr,
PoisoningMitigationLevel::kDontPoison,
AssemblerOptions::Default(environment->main_isolate()),
Builtins::kNoBuiltinId);
Builtins::kNoBuiltinId, kMaxUnoptimizedFrameHeight);
// Force a frame to be created.
generator_->frame_access_state()->MarkHasFrame(true);
......
......@@ -40,11 +40,13 @@ InstructionSelectorTest::Stream InstructionSelectorTest::StreamBuilder::Build(
instruction_blocks);
SourcePositionTable source_position_table(graph());
TickCounter tick_counter;
size_t max_unoptimized_frame_height = 0;
InstructionSelector selector(
test_->zone(), node_count, &linkage, &sequence, schedule,
&source_position_table, nullptr,
InstructionSelector::kEnableSwitchJumpTable, &tick_counter,
source_position_mode, features, InstructionSelector::kDisableScheduling,
&max_unoptimized_frame_height, source_position_mode, features,
InstructionSelector::kDisableScheduling,
InstructionSelector::kEnableRootsRelativeAddressing,
PoisoningMitigationLevel::kPoisonAll);
selector.SelectInstructions();
......
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