Skip to content

Commit

Permalink
fibers
Browse files Browse the repository at this point in the history
  • Loading branch information
antonbashir committed Sep 1, 2024
1 parent 64fd60f commit 7b19ae5
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 202 deletions.
6 changes: 3 additions & 3 deletions runtime/vm/compiler/backend/constant_propagator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1565,13 +1565,13 @@ void ConstantPropagator::VisitCall1ArgStub(Call1ArgStubInstr* instr) {
SetValue(instr, non_constant_);
}

void ConstantPropagator::VisitCoroutineInitializeStub(CoroutineInitializeStubInstr* instr) {
void ConstantPropagator::VisitCoroutineInitialize(CoroutineInitializeInstr* instr) {
}

void ConstantPropagator::VisitCoroutineTransferStub(CoroutineTransferStubInstr* instr) {
void ConstantPropagator::VisitCoroutineTransfer(CoroutineTransferInstr* instr) {
}

void ConstantPropagator::VisitCoroutineForkStub(CoroutineForkStubInstr* instr) {
void ConstantPropagator::VisitCoroutineFork(CoroutineForkInstr* instr) {
}

void ConstantPropagator::VisitSuspend(SuspendInstr* instr) {
Expand Down
36 changes: 18 additions & 18 deletions runtime/vm/compiler/backend/il.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8551,18 +8551,18 @@ void Call1ArgStubInstr::EmitNativeCode(FlowGraphCompiler* compiler) {
locs(), deopt_id(), env());
}

LocationSummary* CoroutineInitializeStubInstr::MakeLocationSummary(
LocationSummary* CoroutineInitializeInstr::MakeLocationSummary(
Zone* zone,
bool opt) const {
const intptr_t kNumInputs = 1;
const intptr_t kNumTemps = 0;
LocationSummary* locs = new (zone) LocationSummary(zone, kNumInputs, kNumTemps, LocationSummary::kCall);
locs->set_in(0, Location::RegisterLocation(CoroutineInitializeStubABI::kCoroutineReg));
locs->set_in(0, Location::RegisterLocation(CoroutineInitializeABI::kCoroutineReg));
return locs;
}

void CoroutineInitializeStubInstr::EmitNativeCode(FlowGraphCompiler* compiler) {
const Register kCoroutine = CoroutineInitializeStubABI::kCoroutineReg;
void CoroutineInitializeInstr::EmitNativeCode(FlowGraphCompiler* compiler) {
const Register kCoroutine = CoroutineInitializeABI::kCoroutineReg;

#if defined(TARGET_ARCH_ARM) || defined(TARGET_ARCH_ARM64)
SPILLS_LR_TO_FRAME({});
Expand Down Expand Up @@ -8606,21 +8606,21 @@ void CoroutineInitializeStubInstr::EmitNativeCode(FlowGraphCompiler* compiler) {
__ LeaveFrame();
}

LocationSummary* CoroutineTransferStubInstr::MakeLocationSummary(
LocationSummary* CoroutineTransferInstr::MakeLocationSummary(
Zone* zone,
bool opt) const {
const intptr_t kNumInputs = 2;
const intptr_t kNumTemps = 0;
LocationSummary* locs = new (zone) LocationSummary(zone, kNumInputs, kNumTemps, LocationSummary::kCall);
locs->set_in(0, Location::RegisterLocation(CoroutineTransferStubABI::kFromCoroutineReg));
locs->set_in(1, Location::RegisterLocation(CoroutineTransferStubABI::kToCoroutineReg));
locs->set_in(0, Location::RegisterLocation(CoroutineTransferABI::kFromCoroutineReg));
locs->set_in(1, Location::RegisterLocation(CoroutineTransferABI::kToCoroutineReg));
return locs;
}

void CoroutineTransferStubInstr::EmitNativeCode(FlowGraphCompiler* compiler) {
const Register kFromCoroutine = CoroutineTransferStubABI::kFromCoroutineReg;
const Register kToCoroutine = CoroutineTransferStubABI::kToCoroutineReg;
const Register kToStackLimit = CoroutineTransferStubABI::kToStackLimitReg;
void CoroutineTransferInstr::EmitNativeCode(FlowGraphCompiler* compiler) {
const Register kFromCoroutine = CoroutineTransferABI::kFromCoroutineReg;
const Register kToCoroutine = CoroutineTransferABI::kToCoroutineReg;
const Register kToStackLimit = CoroutineTransferABI::kToStackLimitReg;

#if defined(TARGET_ARCH_ARM) || defined(TARGET_ARCH_ARM64)
SPILLS_LR_TO_FRAME({});
Expand All @@ -8644,21 +8644,21 @@ void CoroutineTransferStubInstr::EmitNativeCode(FlowGraphCompiler* compiler) {
__ StoreFieldToOffset(kFromCoroutine, kToCoroutine, Coroutine::caller_offset());
}

LocationSummary* CoroutineForkStubInstr::MakeLocationSummary(
LocationSummary* CoroutineForkInstr::MakeLocationSummary(
Zone* zone,
bool opt) const {
const intptr_t kNumInputs = 2;
const intptr_t kNumTemps = 0;
LocationSummary* locs = new (zone) LocationSummary(zone, kNumInputs, kNumTemps, LocationSummary::kCall);
locs->set_in(0, Location::RegisterLocation(CoroutineForkStubABI::kCallerCoroutineReg));
locs->set_in(1, Location::RegisterLocation(CoroutineForkStubABI::kForkedCoroutineReg));
locs->set_in(0, Location::RegisterLocation(CoroutineForkABI::kCallerCoroutineReg));
locs->set_in(1, Location::RegisterLocation(CoroutineForkABI::kForkedCoroutineReg));
return locs;
}

void CoroutineForkStubInstr::EmitNativeCode(FlowGraphCompiler* compiler) {
const Register kCallerCoroutine = CoroutineForkStubABI::kCallerCoroutineReg;
const Register kForkedCoroutine = CoroutineForkStubABI::kForkedCoroutineReg;
const Register kStackLimit = CoroutineForkStubABI::kStackLimitReg;
void CoroutineForkInstr::EmitNativeCode(FlowGraphCompiler* compiler) {
const Register kCallerCoroutine = CoroutineForkABI::kCallerCoroutineReg;
const Register kForkedCoroutine = CoroutineForkABI::kForkedCoroutineReg;
const Register kStackLimit = CoroutineForkABI::kStackLimitReg;

#if defined(TARGET_ARCH_ARM) || defined(TARGET_ARCH_ARM64)
SPILLS_LR_TO_FRAME({});
Expand Down
42 changes: 21 additions & 21 deletions runtime/vm/compiler/backend/il.h
Original file line number Diff line number Diff line change
Expand Up @@ -545,9 +545,9 @@ struct InstrAttrs {
M(IntConverter, kNoGC) \
M(BitCast, kNoGC) \
M(Call1ArgStub, _) \
M(CoroutineInitializeStub, _) \
M(CoroutineTransferStub, _) \
M(CoroutineForkStub, _) \
M(CoroutineInitialize, _) \
M(CoroutineTransfer, _) \
M(CoroutineFork, _) \
M(LoadThread, kNoGC) \
M(Deoptimize, kNoGC) \
M(SimdOp, kNoGC) \
Expand Down Expand Up @@ -11476,11 +11476,11 @@ class Call1ArgStubInstr : public TemplateDefinition<1, Throws> {
DISALLOW_COPY_AND_ASSIGN(Call1ArgStubInstr);
};

class CoroutineInitializeStubInstr : public TemplateInstruction<1, NoThrow> {
class CoroutineInitializeInstr : public TemplateInstruction<1, NoThrow> {
public:
CoroutineInitializeStubInstr(Value* root, intptr_t deopt_id)
CoroutineInitializeInstr(Value* root, intptr_t deopt_id)
: TemplateInstruction(InstructionSource(TokenPosition::kNoSource),
deopt_id) {
deopt_id) {
SetInputAt(0, root);
}

Expand All @@ -11493,19 +11493,19 @@ class CoroutineInitializeStubInstr : public TemplateInstruction<1, NoThrow> {
return InputCount();
}

DECLARE_INSTRUCTION(CoroutineInitializeStub);
DECLARE_INSTRUCTION(CoroutineInitialize);
PRINT_OPERANDS_TO_SUPPORT
DECLARE_EMPTY_SERIALIZATION(CoroutineInitializeStubInstr, TemplateInstruction)
DECLARE_EMPTY_SERIALIZATION(CoroutineInitializeInstr, TemplateInstruction)

private:
DISALLOW_COPY_AND_ASSIGN(CoroutineInitializeStubInstr);
DISALLOW_COPY_AND_ASSIGN(CoroutineInitializeInstr);
};

class CoroutineTransferStubInstr : public TemplateInstruction<2, NoThrow> {
class CoroutineTransferInstr : public TemplateInstruction<2, NoThrow> {
public:
CoroutineTransferStubInstr(Value* from, Value* to, intptr_t deopt_id)
CoroutineTransferInstr(Value* from, Value* to, intptr_t deopt_id)
: TemplateInstruction(InstructionSource(TokenPosition::kNoSource),
deopt_id) {
deopt_id) {
SetInputAt(0, from);
SetInputAt(1, to);
}
Expand All @@ -11521,19 +11521,19 @@ class CoroutineTransferStubInstr : public TemplateInstruction<2, NoThrow> {
return InputCount();
}

DECLARE_INSTRUCTION(CoroutineTransferStub);
DECLARE_INSTRUCTION(CoroutineTransfer);
PRINT_OPERANDS_TO_SUPPORT
DECLARE_EMPTY_SERIALIZATION(CoroutineTransferStubInstr, TemplateInstruction)
DECLARE_EMPTY_SERIALIZATION(CoroutineTransferInstr, TemplateInstruction)

private:
DISALLOW_COPY_AND_ASSIGN(CoroutineTransferStubInstr);
DISALLOW_COPY_AND_ASSIGN(CoroutineTransferInstr);
};

class CoroutineForkStubInstr : public TemplateInstruction<2, NoThrow> {
class CoroutineForkInstr : public TemplateInstruction<2, NoThrow> {
public:
CoroutineForkStubInstr(Value* from, Value* to, intptr_t deopt_id)
CoroutineForkInstr(Value* from, Value* to, intptr_t deopt_id)
: TemplateInstruction(InstructionSource(TokenPosition::kNoSource),
deopt_id) {
deopt_id) {
SetInputAt(0, from);
SetInputAt(1, to);
}
Expand All @@ -11549,13 +11549,13 @@ class CoroutineForkStubInstr : public TemplateInstruction<2, NoThrow> {
return InputCount();
}

DECLARE_INSTRUCTION(CoroutineForkStub);
DECLARE_INSTRUCTION(CoroutineFork);
PRINT_OPERANDS_TO_SUPPORT

DECLARE_EMPTY_SERIALIZATION(CoroutineForkStubInstr, TemplateInstruction)
DECLARE_EMPTY_SERIALIZATION(CoroutineForkInstr, TemplateInstruction)

private:
DISALLOW_COPY_AND_ASSIGN(CoroutineForkStubInstr);
DISALLOW_COPY_AND_ASSIGN(CoroutineForkInstr);
};

// Suspends execution using the suspend stub specified using [StubId].
Expand Down
6 changes: 3 additions & 3 deletions runtime/vm/compiler/backend/il_printer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1576,22 +1576,22 @@ void Call1ArgStubInstr::PrintOperandsTo(BaseTextBuffer* f) const {
f->AddString(")");
}

void CoroutineInitializeStubInstr::PrintOperandsTo(BaseTextBuffer* f) const {
void CoroutineInitializeInstr::PrintOperandsTo(BaseTextBuffer* f) const {
const char* name = "CoroutineInitialize";
f->Printf("%s(", name);
root()->PrintTo(f);
f->AddString(")");
}

void CoroutineTransferStubInstr::PrintOperandsTo(BaseTextBuffer* f) const {
void CoroutineTransferInstr::PrintOperandsTo(BaseTextBuffer* f) const {
const char* name = "CoroutineTransfer";
f->Printf("%s(", name);
from()->PrintTo(f);
to()->PrintTo(f);
f->AddString(")");
}

void CoroutineForkStubInstr::PrintOperandsTo(BaseTextBuffer* f) const {
void CoroutineForkInstr::PrintOperandsTo(BaseTextBuffer* f) const {
const char* name = "CoroutineFork";
f->Printf("%s(", name);
from()->PrintTo(f);
Expand Down
12 changes: 6 additions & 6 deletions runtime/vm/compiler/frontend/kernel_to_il.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4766,20 +4766,20 @@ Fragment FlowGraphBuilder::Call1ArgStub(TokenPosition position,
}

Fragment FlowGraphBuilder::CoroutineInitialize() {
CoroutineInitializeStubInstr* instr =
new (Z) CoroutineInitializeStubInstr(Pop(), GetNextDeoptId());
CoroutineInitializeInstr* instr =
new (Z) CoroutineInitializeInstr(Pop(), GetNextDeoptId());
return Fragment(instr);
}

Fragment FlowGraphBuilder::CoroutineTransfer() {
CoroutineTransferStubInstr* instr =
new (Z) CoroutineTransferStubInstr(Pop(), Pop(), GetNextDeoptId());
CoroutineTransferInstr* instr =
new (Z) CoroutineTransferInstr(Pop(), Pop(), GetNextDeoptId());
return Fragment(instr);
}

Fragment FlowGraphBuilder::CoroutineFork() {
CoroutineForkStubInstr* instr =
new (Z) CoroutineForkStubInstr(Pop(), Pop(), GetNextDeoptId());
CoroutineForkInstr* instr =
new (Z) CoroutineForkInstr(Pop(), Pop(), GetNextDeoptId());
return Fragment(instr);
}

Expand Down
139 changes: 0 additions & 139 deletions runtime/vm/compiler/stub_code_compiler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2209,145 +2209,6 @@ void StubCodeCompiler::GenerateInitSyncStarStub() {
target::ObjectStore::suspend_state_init_sync_star_offset());
}

void StubCodeCompiler::GenerateCoroutineInitializeStub() {
const Register kCoroutine = CoroutineInitializeStubABI::kCoroutineReg;

#if defined(TARGET_ARCH_ARM) || defined(TARGET_ARCH_ARM64)
SPILLS_LR_TO_FRAME({});
#endif
__ EnterStubFrame();
__ PushObject(NullObject());
__ PushRegister(kCoroutine);
__ CallRuntime(kEnterCoroutineRuntimeEntry, 1);
__ PopRegister(kCoroutine);
__ Drop(1);
__ LeaveStubFrame();

__ PushRegister(FPREG);
__ PushRegister(PP);
__ PushRegister(CODE_REG);
__ PushRegister(FUNCTION_REG);

__ EnterFrame(0);
__ LoadFieldFromOffset(SPREG, kCoroutine,
target::Coroutine::stack_base_offset());
__ PushRegister(FPREG);

__ LoadCompressedFieldFromOffset(FUNCTION_REG, kCoroutine,
target::Coroutine::entry_offset());
if (!FLAG_precompiled_mode) {
__ LoadCompressedFieldFromOffset(CODE_REG, FUNCTION_REG,
target::Function::code_offset());
__ LoadImmediate(ARGS_DESC_REG, 0);
}
__ Call(FieldAddress(FUNCTION_REG, target::Function::entry_point_offset()));

__ PopRegister(FPREG);
__ LeaveFrame();

__ PopRegister(FUNCTION_REG);
__ PopRegister(CODE_REG);
__ PopRegister(PP);
__ PopRegister(FPREG);

__ EnterStubFrame();
__ PushObject(NullObject());
__ CallRuntime(kExitCoroutineRuntimeEntry, 0);
__ Drop(1);
__ LeaveStubFrame();

__ Ret();
}

void StubCodeCompiler::GenerateCoroutineTransferStub() {
const Register kFromCoroutine = CoroutineTransferStubABI::kFromCoroutineReg;
const Register kToCoroutine = CoroutineTransferStubABI::kToCoroutineReg;
const Register kToStackLimit = CoroutineTransferStubABI::kToStackLimitReg;

#if defined(TARGET_ARCH_ARM) || defined(TARGET_ARCH_ARM64)
SPILLS_LR_TO_FRAME({});
#endif

__ PushRegister(FPREG);
__ PushRegister(PP);
__ PushRegister(CODE_REG);
__ PushRegister(FUNCTION_REG);
__ StoreFieldToOffset(SPREG, kFromCoroutine,
target::Coroutine::stack_base_offset());

__ LoadFieldFromOffset(SPREG, kToCoroutine,
target::Coroutine::stack_base_offset());
__ PopRegister(FUNCTION_REG);
__ PopRegister(CODE_REG);
__ PopRegister(PP);
__ PopRegister(FPREG);

__ LoadFieldFromOffset(kToStackLimit, kToCoroutine,
target::Coroutine::stack_limit_offset());
__ StoreToOffset(kToStackLimit, THR, Thread::stack_limit_offset());
__ StoreToOffset(kToCoroutine, THR, Thread::coroutine_offset());

__ StoreFieldToOffset(kFromCoroutine, kToCoroutine,
target::Coroutine::caller_offset());

__ Ret();
}

void StubCodeCompiler::GenerateCoroutineForkStub() {
const Register kCallerCoroutine = CoroutineForkStubABI::kCallerCoroutineReg;
const Register kForkedCoroutine = CoroutineForkStubABI::kForkedCoroutineReg;
const Register kStackLimit = CoroutineForkStubABI::kStackLimitReg;

#if defined(TARGET_ARCH_ARM) || defined(TARGET_ARCH_ARM64)
SPILLS_LR_TO_FRAME({});
#endif

__ PushRegister(FPREG);
__ PushRegister(PP);
__ PushRegister(CODE_REG);
__ PushRegister(FUNCTION_REG);
__ StoreFieldToOffset(SPREG, kCallerCoroutine,
target::Coroutine::stack_base_offset());

__ StoreFieldToOffset(kCallerCoroutine, kForkedCoroutine,
target::Coroutine::caller_offset());

__ LoadFieldFromOffset(kStackLimit, kForkedCoroutine,
target::Coroutine::stack_limit_offset());
__ StoreToOffset(kStackLimit, THR, Thread::stack_limit_offset());
__ StoreToOffset(kForkedCoroutine, THR, Thread::coroutine_offset());

__ LoadFieldFromOffset(SPREG, kForkedCoroutine,
target::Coroutine::stack_base_offset());
__ PushRegister(kForkedCoroutine);

__ LoadCompressedFieldFromOffset(FUNCTION_REG, kForkedCoroutine,
target::Coroutine::entry_offset());
if (!FLAG_precompiled_mode) {
__ LoadCompressedFieldFromOffset(CODE_REG, FUNCTION_REG,
target::Function::code_offset());
__ LoadImmediate(ARGS_DESC_REG, 0);
}
__ Call(FieldAddress(FUNCTION_REG, target::Function::entry_point_offset()));

__ PopRegister(kForkedCoroutine);
__ LoadFieldFromOffset(kCallerCoroutine, kForkedCoroutine,
target::Coroutine::caller_offset());
__ LoadFieldFromOffset(SPREG, kCallerCoroutine,
target::Coroutine::stack_base_offset());
__ PopRegister(FUNCTION_REG);
__ PopRegister(CODE_REG);
__ PopRegister(PP);
__ PopRegister(FPREG);

__ LoadFieldFromOffset(kStackLimit, kCallerCoroutine,
target::Coroutine::stack_limit_offset());
__ StoreToOffset(kStackLimit, THR, Thread::stack_limit_offset());
__ StoreToOffset(kCallerCoroutine, THR, Thread::coroutine_offset());

__ Ret();
}

void StubCodeCompiler::GenerateResumeStub() {
const Register kSuspendState = ResumeStubABI::kSuspendStateReg;
const Register kTemp = ResumeStubABI::kTempReg;
Expand Down
Loading

0 comments on commit 7b19ae5

Please sign in to comment.