Skip to content

Commit

Permalink
[VM] Make all of our compilation pipeline use a [FrameLayout] to gene…
Browse files Browse the repository at this point in the history
…rate code

This will allow us to have configurable frame layouts during
gen_snapshot/dart_bootstrap.

Issue #33274

Change-Id: I18945189034be1a585c1e2edcf53a4b7537204c2
Reviewed-on: https://dart-review.googlesource.com/59880
Commit-Queue: Martin Kustermann <[email protected]>
Reviewed-by: Vyacheslav Egorov <[email protected]>
  • Loading branch information
mkustermann authored and [email protected] committed Aug 21, 2018
1 parent 2a36502 commit b7790e3
Show file tree
Hide file tree
Showing 30 changed files with 351 additions and 187 deletions.
5 changes: 3 additions & 2 deletions runtime/vm/compiler/assembler/assembler_arm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1433,7 +1433,7 @@ void Assembler::CheckCodePointer() {
}

void Assembler::RestoreCodePointer() {
ldr(CODE_REG, Address(FP, kPcMarkerSlotFromFp * kWordSize));
ldr(CODE_REG, Address(FP, compiler_frame_layout.code_from_fp * kWordSize));
CheckCodePointer();
}

Expand Down Expand Up @@ -3124,7 +3124,8 @@ void Assembler::EnterOsrFrame(intptr_t extra_size) {

void Assembler::LeaveDartFrame(RestorePP restore_pp) {
if (restore_pp == kRestoreCallerPP) {
ldr(PP, Address(FP, kSavedCallerPpSlotFromFp * kWordSize));
ldr(PP,
Address(FP, compiler_frame_layout.saved_caller_pp_from_fp * kWordSize));
set_constant_pool_allowed(false);
}

Expand Down
5 changes: 3 additions & 2 deletions runtime/vm/compiler/assembler/assembler_arm64.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1077,7 +1077,7 @@ void Assembler::ReserveAlignedFrameSpace(intptr_t frame_space) {
}

void Assembler::RestoreCodePointer() {
ldr(CODE_REG, Address(FP, kPcMarkerSlotFromFp * kWordSize));
ldr(CODE_REG, Address(FP, compiler_frame_layout.code_from_fp * kWordSize));
CheckCodePointer();
}

Expand Down Expand Up @@ -1184,7 +1184,8 @@ void Assembler::LeaveDartFrame(RestorePP restore_pp) {
if (restore_pp == kRestoreCallerPP) {
set_constant_pool_allowed(false);
// Restore and untag PP.
LoadFromOffset(PP, FP, kSavedCallerPpSlotFromFp * kWordSize);
LoadFromOffset(PP, FP,
compiler_frame_layout.saved_caller_pp_from_fp * kWordSize);
sub(PP, PP, Operand(kHeapObjectTag));
}
LeaveFrame();
Expand Down
5 changes: 3 additions & 2 deletions runtime/vm/compiler/assembler/assembler_x64.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1486,7 +1486,7 @@ void Assembler::CallRuntime(const RuntimeEntry& entry,
}

void Assembler::RestoreCodePointer() {
movq(CODE_REG, Address(RBP, kPcMarkerSlotFromFp * kWordSize));
movq(CODE_REG, Address(RBP, compiler_frame_layout.code_from_fp * kWordSize));
}

void Assembler::LoadPoolPointer(Register pp) {
Expand Down Expand Up @@ -1515,7 +1515,8 @@ void Assembler::EnterDartFrame(intptr_t frame_size, Register new_pp) {
void Assembler::LeaveDartFrame(RestorePP restore_pp) {
// Restore caller's PP register that was pushed in EnterDartFrame.
if (restore_pp == kRestoreCallerPP) {
movq(PP, Address(RBP, (kSavedCallerPpSlotFromFp * kWordSize)));
movq(PP, Address(RBP, (compiler_frame_layout.saved_caller_pp_from_fp *
kWordSize)));
set_constant_pool_allowed(false);
}
LeaveFrame();
Expand Down
17 changes: 10 additions & 7 deletions runtime/vm/compiler/backend/flow_graph_compiler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ void CompilerDeoptInfo::AllocateIncomingParametersRecursive(
for (Environment::ShallowIterator it(env); !it.Done(); it.Advance()) {
if (it.CurrentLocation().IsInvalid() &&
it.CurrentValue()->definition()->IsPushArgument()) {
it.SetCurrentLocation(
Location::StackSlot(FrameSlotForVariableIndex(-*stack_height)));
it.SetCurrentLocation(Location::StackSlot(
compiler_frame_layout.FrameSlotForVariableIndex(-*stack_height)));
(*stack_height)++;
}
}
Expand Down Expand Up @@ -376,7 +376,8 @@ void FlowGraphCompiler::EmitCatchEntryState(Environment* env,
catch_entry_state_maps_builder_->AppendConstant(id, dest_index);
continue;
}
const intptr_t src_index = -VariableIndexForFrameSlot(src.stack_index());
const intptr_t src_index =
-compiler_frame_layout.VariableIndexForFrameSlot(src.stack_index());
if (src_index != dest_index) {
catch_entry_state_maps_builder_->AppendMove(src_index, dest_index);
}
Expand Down Expand Up @@ -406,7 +407,8 @@ void FlowGraphCompiler::EmitCatchEntryState(Environment* env,
catch_entry_state_maps_builder_->AppendConstant(id, dest_index);
continue;
}
const intptr_t src_index = -VariableIndexForFrameSlot(src.stack_index());
const intptr_t src_index =
-compiler_frame_layout.VariableIndexForFrameSlot(src.stack_index());
if (src_index != dest_index) {
catch_entry_state_maps_builder_->AppendMove(src_index, dest_index);
}
Expand Down Expand Up @@ -1010,8 +1012,8 @@ void FlowGraphCompiler::FinalizeVarDescriptors(const Code& code) {
info.scope_id = 0;
info.begin_pos = TokenPosition::kMinSource;
info.end_pos = TokenPosition::kMinSource;
info.set_index(
FrameSlotForVariable(parsed_function().current_context_var()));
info.set_index(compiler_frame_layout.FrameSlotForVariable(
parsed_function().current_context_var()));
var_descs.SetVar(0, Symbols::CurrentContextVar(), &info);
}
code.set_var_descriptors(var_descs);
Expand Down Expand Up @@ -1323,7 +1325,8 @@ static Register AllocateFreeRegister(bool* blocked_registers) {

void FlowGraphCompiler::AllocateRegistersLocally(Instruction* instr) {
ASSERT(!is_optimizing());
instr->InitializeLocationSummary(zone(), false); // Not optimizing.
instr->InitializeLocationSummary(zone(),
false); // Not optimizing.

// No need to allocate registers based on LocationSummary on DBC as in
// unoptimized mode it's a stack based bytecode just like IR itself.
Expand Down
6 changes: 4 additions & 2 deletions runtime/vm/compiler/backend/flow_graph_compiler_arm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -862,15 +862,17 @@ void FlowGraphCompiler::EmitPrologue() {

intptr_t args_desc_slot = -1;
if (parsed_function().has_arg_desc_var()) {
args_desc_slot = FrameSlotForVariable(parsed_function().arg_desc_var());
args_desc_slot = compiler_frame_layout.FrameSlotForVariable(
parsed_function().arg_desc_var());
}

__ Comment("Initialize spill slots");
if (num_locals > 1 || (num_locals == 1 && args_desc_slot == -1)) {
__ LoadObject(R0, Object::null_object());
}
for (intptr_t i = 0; i < num_locals; ++i) {
const intptr_t slot_index = FrameSlotForVariableIndex(-i);
const intptr_t slot_index =
compiler_frame_layout.FrameSlotForVariableIndex(-i);
Register value_reg = slot_index == args_desc_slot ? ARGS_DESC_REG : R0;
__ StoreToOffset(kWord, value_reg, FP, slot_index * kWordSize);
}
Expand Down
6 changes: 4 additions & 2 deletions runtime/vm/compiler/backend/flow_graph_compiler_arm64.cc
Original file line number Diff line number Diff line change
Expand Up @@ -863,15 +863,17 @@ void FlowGraphCompiler::CompileGraph() {

intptr_t args_desc_slot = -1;
if (parsed_function().has_arg_desc_var()) {
args_desc_slot = FrameSlotForVariable(parsed_function().arg_desc_var());
args_desc_slot = compiler_frame_layout.FrameSlotForVariable(
parsed_function().arg_desc_var());
}

__ Comment("Initialize spill slots");
if (num_locals > 1 || (num_locals == 1 && args_desc_slot == -1)) {
__ LoadObject(R0, Object::null_object());
}
for (intptr_t i = 0; i < num_locals; ++i) {
const intptr_t slot_index = FrameSlotForVariableIndex(-i);
const intptr_t slot_index =
compiler_frame_layout.FrameSlotForVariableIndex(-i);
Register value_reg = slot_index == args_desc_slot ? ARGS_DESC_REG : R0;
__ StoreToOffset(value_reg, FP, slot_index * kWordSize);
}
Expand Down
16 changes: 9 additions & 7 deletions runtime/vm/compiler/backend/flow_graph_compiler_dbc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ RawTypedData* CompilerDeoptInfo::CreateDeoptInfo(FlowGraphCompiler* compiler,
if (lazy_deopt_with_result_) {
ASSERT(reason() == ICData::kDeoptAtCall);
builder->AddCopy(
NULL, Location::StackSlot(FrameSlotForVariableIndex(-stack_height)),
NULL,
Location::StackSlot(
compiler_frame_layout.FrameSlotForVariableIndex(-stack_height)),
slot_ix++);
}

Expand Down Expand Up @@ -283,7 +285,7 @@ void FlowGraphCompiler::EmitInstructionEpilogue(Instruction* instr) {
}

void FlowGraphCompiler::GenerateInlinedGetter(intptr_t offset) {
__ Move(0, -(1 + kParamEndSlotFromFp));
__ Move(0, -(1 + compiler_frame_layout.param_end_from_fp));
ASSERT(offset % kWordSize == 0);
if (Utils::IsInt(8, offset / kWordSize)) {
__ LoadField(0, 0, offset / kWordSize);
Expand All @@ -295,8 +297,8 @@ void FlowGraphCompiler::GenerateInlinedGetter(intptr_t offset) {
}

void FlowGraphCompiler::GenerateInlinedSetter(intptr_t offset) {
__ Move(0, -(2 + kParamEndSlotFromFp));
__ Move(1, -(1 + kParamEndSlotFromFp));
__ Move(0, -(2 + compiler_frame_layout.param_end_from_fp));
__ Move(1, -(1 + compiler_frame_layout.param_end_from_fp));
ASSERT(offset % kWordSize == 0);
if (Utils::IsInt(8, offset / kWordSize)) {
__ StoreField(0, offset / kWordSize, 1);
Expand Down Expand Up @@ -329,8 +331,8 @@ void FlowGraphCompiler::EmitFrameEntry() {
if (parsed_function().has_arg_desc_var()) {
// TODO(kustermann): If dbc simulator put the args_desc_ into the
// _special_regs, we could replace these 3 with the MoveSpecial bytecode.
const intptr_t slot_index =
FrameSlotForVariable(parsed_function().arg_desc_var());
const intptr_t slot_index = compiler_frame_layout.FrameSlotForVariable(
parsed_function().arg_desc_var());
__ LoadArgDescriptor();
__ StoreLocal(LocalVarIndex(0, slot_index));
__ Drop(1);
Expand Down Expand Up @@ -370,7 +372,7 @@ void ParallelMoveResolver::EmitMove(int index) {
// Only allow access to the arguments (which have in the non-inverted stack
// positive indices).
ASSERT(source.base_reg() == FPREG);
ASSERT(source.stack_index() > kParamEndSlotFromFp);
ASSERT(source.stack_index() > compiler_frame_layout.param_end_from_fp);
__ Move(destination.reg(), -source.stack_index());
} else if (source.IsRegister() && destination.IsRegister()) {
__ Move(destination.reg(), source.reg());
Expand Down
6 changes: 4 additions & 2 deletions runtime/vm/compiler/backend/flow_graph_compiler_ia32.cc
Original file line number Diff line number Diff line change
Expand Up @@ -820,7 +820,8 @@ void FlowGraphCompiler::CompileGraph() {

intptr_t args_desc_slot = -1;
if (parsed_function().has_arg_desc_var()) {
args_desc_slot = FrameSlotForVariable(parsed_function().arg_desc_var());
args_desc_slot = compiler_frame_layout.FrameSlotForVariable(
parsed_function().arg_desc_var());
}

__ Comment("Initialize spill slots");
Expand All @@ -830,7 +831,8 @@ void FlowGraphCompiler::CompileGraph() {
__ movl(EAX, raw_null);
}
for (intptr_t i = 0; i < num_locals; ++i) {
const intptr_t slot_index = FrameSlotForVariableIndex(-i);
const intptr_t slot_index =
compiler_frame_layout.FrameSlotForVariableIndex(-i);
Register value_reg = slot_index == args_desc_slot ? ARGS_DESC_REG : EAX;
__ movl(Address(EBP, slot_index * kWordSize), value_reg);
}
Expand Down
14 changes: 8 additions & 6 deletions runtime/vm/compiler/backend/flow_graph_compiler_x64.cc
Original file line number Diff line number Diff line change
Expand Up @@ -859,15 +859,17 @@ void FlowGraphCompiler::EmitPrologue() {

intptr_t args_desc_slot = -1;
if (parsed_function().has_arg_desc_var()) {
args_desc_slot = FrameSlotForVariable(parsed_function().arg_desc_var());
args_desc_slot = compiler_frame_layout.FrameSlotForVariable(
parsed_function().arg_desc_var());
}

__ Comment("Initialize spill slots");
if (num_locals > 1 || (num_locals == 1 && args_desc_slot == -1)) {
__ LoadObject(RAX, Object::null_object());
}
for (intptr_t i = 0; i < num_locals; ++i) {
const intptr_t slot_index = FrameSlotForVariableIndex(-i);
const intptr_t slot_index =
compiler_frame_layout.FrameSlotForVariableIndex(-i);
Register value_reg = slot_index == args_desc_slot ? ARGS_DESC_REG : RAX;
__ movq(Address(RBP, slot_index * kWordSize), value_reg);
}
Expand Down Expand Up @@ -1240,14 +1242,14 @@ void ParallelMoveResolver::EmitMove(int index) {
} else {
ASSERT(destination.IsStackSlot());
ASSERT((destination.base_reg() != FPREG) ||
((-VariableIndexForFrameSlot(destination.stack_index())) <
compiler_->StackSize()));
((-compiler_frame_layout.VariableIndexForFrameSlot(
destination.stack_index())) < compiler_->StackSize()));
__ movq(destination.ToStackSlotAddress(), source.reg());
}
} else if (source.IsStackSlot()) {
ASSERT((source.base_reg() != FPREG) ||
((-VariableIndexForFrameSlot(source.stack_index())) <
compiler_->StackSize()));
((-compiler_frame_layout.VariableIndexForFrameSlot(
source.stack_index())) < compiler_->StackSize()));
if (destination.IsRegister()) {
__ movq(destination.reg(), source.ToStackSlotAddress());
} else {
Expand Down
20 changes: 14 additions & 6 deletions runtime/vm/compiler/backend/il_arm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ void ReturnInstr::EmitNativeCode(FlowGraphCompiler* compiler) {
Label stack_ok;
__ Comment("Stack Check");
const intptr_t fp_sp_dist =
(kFirstLocalSlotFromFp + 1 - compiler->StackSize()) * kWordSize;
(compiler_frame_layout.first_local_from_fp + 1 - compiler->StackSize()) *
kWordSize;
ASSERT(fp_sp_dist <= 0);
__ sub(R2, SP, Operand(FP));
__ CompareImmediate(R2, fp_sp_dist);
Expand Down Expand Up @@ -294,7 +295,9 @@ LocationSummary* LoadLocalInstr::MakeLocationSummary(Zone* zone,

void LoadLocalInstr::EmitNativeCode(FlowGraphCompiler* compiler) {
const Register result = locs()->out(0).reg();
__ LoadFromOffset(kWord, result, FP, FrameOffsetInBytesForVariable(&local()));
__ LoadFromOffset(
kWord, result, FP,
compiler_frame_layout.FrameOffsetInBytesForVariable(&local()));
}

LocationSummary* StoreLocalInstr::MakeLocationSummary(Zone* zone,
Expand All @@ -307,7 +310,9 @@ void StoreLocalInstr::EmitNativeCode(FlowGraphCompiler* compiler) {
const Register value = locs()->in(0).reg();
const Register result = locs()->out(0).reg();
ASSERT(result == value); // Assert that register assignment is correct.
__ StoreToOffset(kWord, value, FP, FrameOffsetInBytesForVariable(&local()));
__ StoreToOffset(
kWord, value, FP,
compiler_frame_layout.FrameOffsetInBytesForVariable(&local()));
}

LocationSummary* ConstantInstr::MakeLocationSummary(Zone* zone,
Expand Down Expand Up @@ -2990,18 +2995,21 @@ void CatchBlockEntryInstr::EmitNativeCode(FlowGraphCompiler* compiler) {
// Restore SP from FP as we are coming from a throw and the code for
// popping arguments has not been run.
const intptr_t fp_sp_dist =
(kFirstLocalSlotFromFp + 1 - compiler->StackSize()) * kWordSize;
(compiler_frame_layout.first_local_from_fp + 1 - compiler->StackSize()) *
kWordSize;
ASSERT(fp_sp_dist <= 0);
__ AddImmediate(SP, FP, fp_sp_dist);

if (!compiler->is_optimizing()) {
if (raw_exception_var_ != nullptr) {
__ StoreToOffset(kWord, kExceptionObjectReg, FP,
FrameOffsetInBytesForVariable(raw_exception_var_));
compiler_frame_layout.FrameOffsetInBytesForVariable(
raw_exception_var_));
}
if (raw_stacktrace_var_ != nullptr) {
__ StoreToOffset(kWord, kStackTraceObjectReg, FP,
FrameOffsetInBytesForVariable(raw_stacktrace_var_));
compiler_frame_layout.FrameOffsetInBytesForVariable(
raw_stacktrace_var_));
}
}
}
Expand Down
19 changes: 13 additions & 6 deletions runtime/vm/compiler/backend/il_arm64.cc
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ void ReturnInstr::EmitNativeCode(FlowGraphCompiler* compiler) {
Label stack_ok;
__ Comment("Stack Check");
const intptr_t fp_sp_dist =
(kFirstLocalSlotFromFp + 1 - compiler->StackSize()) * kWordSize;
(compiler_frame_layout.first_local_from_fp + 1 - compiler->StackSize()) *
kWordSize;
ASSERT(fp_sp_dist <= 0);
__ sub(R2, SP, Operand(FP));
__ CompareImmediate(R2, fp_sp_dist);
Expand Down Expand Up @@ -291,7 +292,9 @@ LocationSummary* LoadLocalInstr::MakeLocationSummary(Zone* zone,

void LoadLocalInstr::EmitNativeCode(FlowGraphCompiler* compiler) {
const Register result = locs()->out(0).reg();
__ LoadFromOffset(result, FP, FrameOffsetInBytesForVariable(&local()));
__ LoadFromOffset(
result, FP,
compiler_frame_layout.FrameOffsetInBytesForVariable(&local()));
}

LocationSummary* StoreLocalInstr::MakeLocationSummary(Zone* zone,
Expand All @@ -304,7 +307,8 @@ void StoreLocalInstr::EmitNativeCode(FlowGraphCompiler* compiler) {
const Register value = locs()->in(0).reg();
const Register result = locs()->out(0).reg();
ASSERT(result == value); // Assert that register assignment is correct.
__ StoreToOffset(value, FP, FrameOffsetInBytesForVariable(&local()));
__ StoreToOffset(
value, FP, compiler_frame_layout.FrameOffsetInBytesForVariable(&local()));
}

LocationSummary* ConstantInstr::MakeLocationSummary(Zone* zone,
Expand Down Expand Up @@ -2685,18 +2689,21 @@ void CatchBlockEntryInstr::EmitNativeCode(FlowGraphCompiler* compiler) {
// Restore SP from FP as we are coming from a throw and the code for
// popping arguments has not been run.
const intptr_t fp_sp_dist =
(kFirstLocalSlotFromFp + 1 - compiler->StackSize()) * kWordSize;
(compiler_frame_layout.first_local_from_fp + 1 - compiler->StackSize()) *
kWordSize;
ASSERT(fp_sp_dist <= 0);
__ AddImmediate(SP, FP, fp_sp_dist);

if (!compiler->is_optimizing()) {
if (raw_exception_var_ != nullptr) {
__ StoreToOffset(kExceptionObjectReg, FP,
FrameOffsetInBytesForVariable(raw_exception_var_));
compiler_frame_layout.FrameOffsetInBytesForVariable(
raw_exception_var_));
}
if (raw_stacktrace_var_ != nullptr) {
__ StoreToOffset(kStackTraceObjectReg, FP,
FrameOffsetInBytesForVariable(raw_stacktrace_var_));
compiler_frame_layout.FrameOffsetInBytesForVariable(
raw_stacktrace_var_));
}
}
}
Expand Down
Loading

0 comments on commit b7790e3

Please sign in to comment.