mirror of
https://gitee.com/openharmony/arkcompiler_ets_runtime
synced 2024-11-27 12:10:47 +00:00
!3415 Remove unnecessary IfException gate
Merge pull request !3415 from 孙哲/master
This commit is contained in:
commit
959677e02c
@ -65,8 +65,11 @@ void AsyncFunctionLowering::ProcessJumpTable()
|
||||
void AsyncFunctionLowering::RebuildGeneratorCfg(GateRef resumeGate, GateRef restoreOffsetGate, GateRef ifFalseCondition,
|
||||
GateRef newTarget, GateRef &firstState)
|
||||
{
|
||||
GateRef ifSuccess = accessor_.GetState(resumeGate);
|
||||
GateRef suspendGate = accessor_.GetState(ifSuccess);
|
||||
GateRef stateGate = accessor_.GetState(resumeGate);
|
||||
GateRef suspendGate = stateGate;
|
||||
if (accessor_.GetOpCode(suspendGate) == OpCode::IF_SUCCESS) {
|
||||
suspendGate = accessor_.GetState(suspendGate);
|
||||
}
|
||||
GateRef restoreRegGate = accessor_.GetDep(resumeGate);
|
||||
GateRef offsetConstantGate = accessor_.GetValueIn(suspendGate);
|
||||
offsetConstantGate = builder_.TruncInt64ToInt32(offsetConstantGate);
|
||||
@ -89,7 +92,7 @@ void AsyncFunctionLowering::RebuildGeneratorCfg(GateRef resumeGate, GateRef rest
|
||||
accessor_.ReplaceValueIn(resumeGate, newTarget);
|
||||
accessor_.ReplaceDependIn(restoreRegGate, ifTrueDepend);
|
||||
circuit_->NewGate(circuit_->Return(), MachineType::NOVALUE,
|
||||
{ ifSuccess, suspendGate, suspendGate, circuit_->GetReturnRoot() },
|
||||
{ stateGate, suspendGate, suspendGate, circuit_->GetReturnRoot() },
|
||||
GateType::AnyType());
|
||||
} else {
|
||||
loopBeginStateIn = ifTrue;
|
||||
@ -127,7 +130,7 @@ void AsyncFunctionLowering::RebuildGeneratorCfg(GateRef resumeGate, GateRef rest
|
||||
accessor_.ReplaceValueIn(resumeGate, newTarget);
|
||||
accessor_.ReplaceDependIn(restoreRegGate, bcOffsetPhiGate);
|
||||
circuit_->NewGate(circuit_->Return(), MachineType::NOVALUE,
|
||||
{ ifSuccess, suspendGate, suspendGate, circuit_->GetReturnRoot() },
|
||||
{ stateGate, suspendGate, suspendGate, circuit_->GetReturnRoot() },
|
||||
GateType::AnyType());
|
||||
} else {
|
||||
// Handling multi-layer for loops
|
||||
|
@ -799,9 +799,11 @@ void BytecodeCircuitBuilder::NewJSGate(BytecodeRegion &bb, GateRef &state, GateR
|
||||
}
|
||||
gateAcc_.NewIn(gate, 0, state);
|
||||
gateAcc_.NewIn(gate, 1, depend);
|
||||
auto ifSuccess = circuit_->NewGate(circuit_->IfSuccess(), {gate});
|
||||
auto ifException = circuit_->NewGate(circuit_->IfException(), {gate});
|
||||
state = gate;
|
||||
if (!bb.catchs.empty()) {
|
||||
auto ifSuccess = circuit_->NewGate(circuit_->IfSuccess(), {gate});
|
||||
auto ifException = circuit_->NewGate(circuit_->IfException(), {gate});
|
||||
|
||||
auto &bbNext = bb.catchs.at(0);
|
||||
auto isLoopBack = bbNext->loopbackBlocks.count(bb.id);
|
||||
SetBlockPred(*bbNext, ifException, gate, isLoopBack);
|
||||
@ -810,12 +812,7 @@ void BytecodeCircuitBuilder::NewJSGate(BytecodeRegion &bb, GateRef &state, GateR
|
||||
} else {
|
||||
bbNext->expandedPreds.push_back({bb.id, iterator.Index(), true});
|
||||
}
|
||||
} else {
|
||||
auto constant = circuit_->GetConstantGate(MachineType::I64,
|
||||
JSTaggedValue::VALUE_EXCEPTION,
|
||||
GateType::TaggedValue());
|
||||
circuit_->NewGate(circuit_->Return(),
|
||||
{ ifException, gate, constant, circuit_->GetReturnRoot() });
|
||||
state = ifSuccess;
|
||||
}
|
||||
byteCodeToJSGate_[iterator.Index()] = gate;
|
||||
if (bytecodeInfo.IsGeneratorRelative()) {
|
||||
@ -838,16 +835,15 @@ void BytecodeCircuitBuilder::NewJSGate(BytecodeRegion &bb, GateRef &state, GateR
|
||||
}
|
||||
suspendAndResumeGates_.emplace_back(gate);
|
||||
}
|
||||
depend = gate;
|
||||
if (bytecodeInfo.IsThrow()) {
|
||||
auto constant = circuit_->GetConstantGate(MachineType::I64,
|
||||
JSTaggedValue::VALUE_EXCEPTION,
|
||||
GateType::TaggedValue());
|
||||
circuit_->NewGate(circuit_->Return(),
|
||||
{ ifSuccess, gate, constant, circuit_->GetReturnRoot() });
|
||||
{ state, depend, constant, circuit_->GetReturnRoot() });
|
||||
return;
|
||||
}
|
||||
state = ifSuccess;
|
||||
depend = gate;
|
||||
if (iterator.Index() == bb.end) {
|
||||
auto &bbNext = graph_[bb.id + 1];
|
||||
auto isLoopBack = bbNext.loopbackBlocks.count(bb.id);
|
||||
|
@ -93,6 +93,12 @@ UseIterator SlowPathLowering::ReplaceHirControlGate(const UseIterator &useIt, Ga
|
||||
return next;
|
||||
}
|
||||
|
||||
void SlowPathLowering::ExceptionReturn(GateRef state, GateRef depend)
|
||||
{
|
||||
auto constant = builder_.ExceptionConstant();
|
||||
builder_.Return(state, depend, constant);
|
||||
}
|
||||
|
||||
void SlowPathLowering::ReplaceHirToSubCfg(GateRef hir, GateRef outir,
|
||||
const std::vector<GateRef> &successControl,
|
||||
const std::vector<GateRef> &exceptionControl,
|
||||
@ -107,10 +113,17 @@ void SlowPathLowering::ReplaceHirToSubCfg(GateRef hir, GateRef outir,
|
||||
auto uses = acc_.Uses(hir);
|
||||
for (auto useIt = uses.begin(); useIt != uses.end();) {
|
||||
const OpCode op = acc_.GetOpCode(*useIt);
|
||||
if (op == OpCode::IF_SUCCESS) {
|
||||
useIt = ReplaceHirControlGate(useIt, successControl[0]);
|
||||
} else if (op == OpCode::IF_EXCEPTION) {
|
||||
useIt = ReplaceHirControlGate(useIt, exceptionControl[0], noThrow);
|
||||
if (acc_.IsStateIn(useIt)) {
|
||||
if (op == OpCode::IF_SUCCESS) {
|
||||
useIt = ReplaceHirControlGate(useIt, successControl[0]);
|
||||
} else if (op == OpCode::IF_EXCEPTION) {
|
||||
useIt = ReplaceHirControlGate(useIt, exceptionControl[0], noThrow);
|
||||
} else {
|
||||
if (!noThrow) {
|
||||
ExceptionReturn(exceptionControl[0], exceptionControl[1]);
|
||||
}
|
||||
useIt = acc_.ReplaceIn(useIt, successControl[0]);
|
||||
}
|
||||
} else if (acc_.IsValueIn(useIt)) {
|
||||
useIt = acc_.ReplaceIn(useIt, outir);
|
||||
} else if (acc_.IsDependIn(useIt)) {
|
||||
@ -130,6 +143,33 @@ void SlowPathLowering::ReplaceHirToSubCfg(GateRef hir, GateRef outir,
|
||||
acc_.DeleteGate(hir);
|
||||
}
|
||||
|
||||
void SlowPathLowering::ReplaceHirWithIfBranch(GateRef hirGate, GateRef callGate, GateRef ifBranch)
|
||||
{
|
||||
auto uses = acc_.Uses(hirGate);
|
||||
for (auto it = uses.begin(); it != uses.end();) {
|
||||
if (acc_.IsStateIn(it)) {
|
||||
const OpCode op = acc_.GetOpCode(*it);
|
||||
if (op == OpCode::IF_SUCCESS) {
|
||||
acc_.SetMetaData(*it, circuit_->IfFalse());
|
||||
it = acc_.ReplaceIn(it, ifBranch);
|
||||
} else if (op == OpCode::IF_EXCEPTION) {
|
||||
acc_.SetMetaData(*it, circuit_->IfTrue());
|
||||
it = acc_.ReplaceIn(it, ifBranch);
|
||||
} else {
|
||||
GateRef ifTrue = builder_.IfTrue(ifBranch);
|
||||
GateRef ifFalse = builder_.IfFalse(ifBranch);
|
||||
ExceptionReturn(ifTrue, callGate);
|
||||
it = acc_.ReplaceIn(it, ifFalse);
|
||||
}
|
||||
} else {
|
||||
it = acc_.ReplaceIn(it, callGate);
|
||||
}
|
||||
}
|
||||
|
||||
// delete old gate
|
||||
acc_.DeleteGate(hirGate);
|
||||
}
|
||||
|
||||
void SlowPathLowering::ReplaceHirToJSCall(GateRef hirGate, GateRef callGate)
|
||||
{
|
||||
GateRef stateInGate = acc_.GetState(hirGate);
|
||||
@ -142,24 +182,7 @@ void SlowPathLowering::ReplaceHirToJSCall(GateRef hirGate, GateRef callGate)
|
||||
acc_.SetDep(exception, callGate);
|
||||
GateRef equal = builder_.NotEqual(exception, builder_.HoleConstant());
|
||||
GateRef ifBranch = builder_.Branch(stateInGate, equal);
|
||||
|
||||
auto uses = acc_.Uses(hirGate);
|
||||
for (auto it = uses.begin(); it != uses.end();) {
|
||||
if (acc_.GetOpCode(*it) == OpCode::IF_SUCCESS) {
|
||||
acc_.SetMetaData(*it, circuit_->IfFalse());
|
||||
it = acc_.ReplaceIn(it, ifBranch);
|
||||
} else {
|
||||
if (acc_.GetOpCode(*it) == OpCode::IF_EXCEPTION) {
|
||||
acc_.SetMetaData(*it, circuit_->IfTrue());
|
||||
it = acc_.ReplaceIn(it, ifBranch);
|
||||
} else {
|
||||
it = acc_.ReplaceIn(it, callGate);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// delete old gate
|
||||
acc_.DeleteGate(hirGate);
|
||||
ReplaceHirWithIfBranch(hirGate, callGate, ifBranch);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -192,24 +215,7 @@ void SlowPathLowering::ReplaceHirToCall(GateRef hirGate, GateRef callGate, bool
|
||||
} else {
|
||||
ifBranch = builder_.Branch(stateInGate, builder_.Boolean(false));
|
||||
}
|
||||
|
||||
auto uses = acc_.Uses(hirGate);
|
||||
for (auto it = uses.begin(); it != uses.end();) {
|
||||
if (acc_.GetOpCode(*it) == OpCode::IF_SUCCESS) {
|
||||
acc_.SetMetaData(*it, circuit_->IfFalse());
|
||||
it = acc_.ReplaceIn(it, ifBranch);
|
||||
} else {
|
||||
if (acc_.GetOpCode(*it) == OpCode::IF_EXCEPTION) {
|
||||
acc_.SetMetaData(*it, circuit_->IfTrue());
|
||||
it = acc_.ReplaceIn(it, ifBranch);
|
||||
} else {
|
||||
it = acc_.ReplaceIn(it, callGate);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// delete old gate
|
||||
acc_.DeleteGate(hirGate);
|
||||
ReplaceHirWithIfBranch(hirGate, callGate, ifBranch);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -225,21 +231,7 @@ void SlowPathLowering::ReplaceHirToThrowCall(GateRef hirGate, GateRef callGate)
|
||||
acc_.SetDep(callGate, dependInGate);
|
||||
|
||||
GateRef ifBranch = builder_.Branch(stateInGate, builder_.Boolean(true));
|
||||
auto uses = acc_.Uses(hirGate);
|
||||
for (auto it = uses.begin(); it != uses.end();) {
|
||||
if (acc_.GetOpCode(*it) == OpCode::IF_SUCCESS) {
|
||||
acc_.SetMetaData(*it, circuit_->IfFalse());
|
||||
it = acc_.ReplaceIn(it, ifBranch);
|
||||
} else {
|
||||
if (acc_.GetOpCode(*it) == OpCode::IF_EXCEPTION) {
|
||||
acc_.SetMetaData(*it, circuit_->IfTrue());
|
||||
it = acc_.ReplaceIn(it, ifBranch);
|
||||
} else {
|
||||
it = acc_.ReplaceIn(it, callGate);
|
||||
}
|
||||
}
|
||||
}
|
||||
acc_.DeleteGate(hirGate);
|
||||
ReplaceHirWithIfBranch(hirGate, callGate, ifBranch);
|
||||
}
|
||||
|
||||
// labelmanager must be initialized
|
||||
@ -829,9 +821,7 @@ void SlowPathLowering::SaveFrameToContext(GateRef gate, GateRef jsFunc)
|
||||
const int arrayId = RTSTUB_ID(NewTaggedArray);
|
||||
GateRef taggedArray = LowerCallRuntime(arrayId, {taggedLength});
|
||||
// setRegsArrays
|
||||
auto hole = circuit_->GetConstantGate(MachineType::I64,
|
||||
JSTaggedValue::VALUE_HOLE,
|
||||
GateType::TaggedValue());
|
||||
auto hole = builder_.HoleConstant();
|
||||
size_t numVreg = acc_.GetNumValueIn(saveRegister);
|
||||
for (size_t idx = 0; idx < numVreg; idx++) {
|
||||
GateRef tmpGate = acc_.GetValueIn(saveRegister, idx);
|
||||
|
@ -152,6 +152,8 @@ private:
|
||||
const std::vector<GateRef> &successControl,
|
||||
const std::vector<GateRef> &exceptionControl,
|
||||
bool noThrow = false);
|
||||
void ExceptionReturn(GateRef state, GateRef depend);
|
||||
void ReplaceHirWithIfBranch(GateRef hirGate, GateRef callGate, GateRef ifBranch);
|
||||
void ReplaceHirToCall(GateRef hirGate, GateRef callGate, bool noThrow = false);
|
||||
void ReplaceHirToJSCall(GateRef hirGate, GateRef callGate);
|
||||
void ReplaceHirToThrowCall(GateRef hirGate, GateRef callGate);
|
||||
|
@ -219,10 +219,7 @@ GateRef TSInlineLowering::MergeAllReturn(const std::vector<GateRef> &returnVecto
|
||||
vaueList[0] = state;
|
||||
for (size_t i = 0; i < returnVector.size(); i++) {
|
||||
GateRef returnGate = returnVector.at(i);
|
||||
GateRef returnState = acc_.GetState(returnGate);
|
||||
if (acc_.GetOpCode(returnState) == OpCode::IF_EXCEPTION) {
|
||||
continue;
|
||||
}
|
||||
ASSERT(acc_.GetOpCode(acc_.GetState(returnGate)) != OpCode::IF_EXCEPTION);
|
||||
stateList[i] = acc_.GetState(returnGate);
|
||||
dependList[i + 1] = acc_.GetDep(returnGate);
|
||||
vaueList[i + 1] = acc_.GetValueIn(returnGate, 0);
|
||||
|
@ -306,15 +306,6 @@ void TSTypeLowering::ReplaceHIRGate(GateRef hir, GateRef outir, GateRef state, G
|
||||
unusedGate.emplace_back(*exceptionUseIt);
|
||||
}
|
||||
++useIt;
|
||||
} else if (op == OpCode::RETURN) {
|
||||
// replace return valueIn and dependIn
|
||||
if (acc_.IsValueIn(useIt)) {
|
||||
useIt = acc_.ReplaceIn(useIt, outir);
|
||||
} else if (acc_.IsDependIn(useIt)) {
|
||||
useIt = acc_.ReplaceIn(useIt, depend);
|
||||
} else {
|
||||
++useIt;
|
||||
}
|
||||
} else if (op == OpCode::DEPEND_SELECTOR) {
|
||||
if (acc_.GetOpCode(acc_.GetIn(acc_.GetIn(*useIt, 0), useIt.GetIndex() - 1)) == OpCode::IF_EXCEPTION) {
|
||||
++useIt;
|
||||
|
Loading…
Reference in New Issue
Block a user