!3987 Fix FrameState ComputeLiveOut

Merge pull request !3987 from dingding/fix_compute_live_out
This commit is contained in:
openharmony_ci 2023-04-27 14:02:56 +00:00 committed by Gitee
commit a1b7168e4d
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
11 changed files with 97 additions and 7 deletions

View File

@ -1390,7 +1390,8 @@ void BytecodeCircuitBuilder::BuildCircuit()
auto valueCount = gateAcc_.GetInValueCount(gate);
[[maybe_unused]] size_t numValueInputs = bytecodeInfo.ComputeValueInputCount();
[[maybe_unused]] size_t numValueOutputs = bytecodeInfo.ComputeOutCount();
ASSERT(numValueInputs == valueCount);
// RETURNUNDEFINED has value input, but not from acc
ASSERT(numValueInputs == valueCount || bytecodeInfo.GetOpcode() == EcmaOpcode::RETURNUNDEFINED);
ASSERT(numValueOutputs <= 1 + (bytecodeInfo.EnvOut() ? 1 : 0));
auto valueStarts = gateAcc_.GetInValueStarts(gate);
for (size_t valueIdx = 0; valueIdx < valueCount; valueIdx++) {

View File

@ -284,6 +284,7 @@ public:
void PUBLIC_API BytecodeToCircuit();
int32_t GetJumpOffset(uint32_t bcIndex) const;
void CollectRegionInfo(uint32_t bcIndex);
GateRef ResolveDef(const size_t bbId, int32_t bcId, const uint16_t reg, const bool acc);
[[nodiscard]] Circuit* GetCircuit() const
{
@ -465,7 +466,6 @@ private:
void NewPhi(BytecodeRegion &bb, uint16_t reg, bool acc, GateRef &currentPhi);
GateRef NewLoopBackPhi(BytecodeRegion &bb, uint16_t reg, bool acc);
GateRef NewLoopForwardPhi(BytecodeRegion &bb, uint16_t reg, bool acc);
GateRef ResolveDef(const size_t bbId, int32_t bcId, const uint16_t reg, const bool acc);
void BuildCircuit();
GateRef GetExistingRestore(GateRef resumeGate, uint16_t tmpReg) const;
void SetExistingRestore(GateRef resumeGate, uint16_t tmpReg, GateRef restoreGate);

View File

@ -179,10 +179,10 @@ BytecodeMetaData BytecodeMetaData::InitBytecodeMetaData(const uint8_t *pc)
case EcmaOpcode::CALLTHISRANGE_IMM8_IMM8_V8:
flags |= BytecodeFlags::SUPPORT_DEOPT;
break;
case EcmaOpcode::RETURNUNDEFINED:
case EcmaOpcode::RETURN:
flags |= BytecodeFlags::READ_ACC;
[[fallthrough]];
case EcmaOpcode::RETURN:
case EcmaOpcode::RETURNUNDEFINED:
kind = BytecodeKind::RETURN_BC;
break;
case EcmaOpcode::SUSPENDGENERATOR_V8:

View File

@ -257,7 +257,7 @@ bool FrameStateBuilder::ComputeLiveOut(size_t bbId)
liveOutResult_->CopyFrom(liveout);
while (true) {
auto &bytecodeInfo = iterator.GetBytecodeInfo();
ComputeLiveOutBC(iterator.Index(), bytecodeInfo);
ComputeLiveOutBC(iterator.Index(), bytecodeInfo, bbId);
--iterator;
if (iterator.Done()) {
break;
@ -324,7 +324,7 @@ void FrameStateBuilder::BuildFrameState(GateRef frameArgs)
BindStateSplit(size);
}
void FrameStateBuilder::ComputeLiveOutBC(uint32_t index, const BytecodeInfo &bytecodeInfo)
void FrameStateBuilder::ComputeLiveOutBC(uint32_t index, const BytecodeInfo &bytecodeInfo, size_t bbId)
{
if (bytecodeInfo.IsMov()) {
auto gate = Circuit::NullGate();
@ -338,10 +338,17 @@ void FrameStateBuilder::ComputeLiveOutBC(uint32_t index, const BytecodeInfo &byt
UpdateVirtualRegister(out, Circuit::NullGate());
}
// variable use
// when alive gate is null, find def
if (bytecodeInfo.AccIn()) {
if (gate == Circuit::NullGate()) {
gate = builder_->ResolveDef(bbId, index, 0, true);
}
UpdateAccumulator(gate);
} else if (bytecodeInfo.inputs.size() != 0) {
auto vreg = std::get<VirtualRegister>(bytecodeInfo.inputs.at(0)).GetId();
if (gate == Circuit::NullGate()) {
gate = builder_->ResolveDef(bbId, index, vreg, false);
}
UpdateVirtualRegister(vreg, gate);
}
return;

View File

@ -108,7 +108,7 @@ private:
void BuildPostOrderList(size_t size);
bool ComputeLiveOut(size_t bbId);
void ComputeLiveState();
void ComputeLiveOutBC(uint32_t index, const BytecodeInfo &bytecodeInfo);
void ComputeLiveOutBC(uint32_t index, const BytecodeInfo &bytecodeInfo, size_t bbId);
bool IsAsyncResolveOrSusp(const BytecodeInfo &bytecodeInfo);
bool MergeIntoPredBC(uint32_t predPc);
bool MergeIntoPredBB(BytecodeRegion *bb, BytecodeRegion *predBb);

View File

@ -401,6 +401,10 @@ void NumberSpeculativeLowering::VisitPhi(GateRef gate)
acc_.SetMachineType(gate, MachineType::F64);
break;
}
case TypeInfo::NONE: { // retype not visit it, it's unused
acc_.DeleteGate(gate);
break;
}
default:
break;
}

View File

@ -20,6 +20,7 @@ group("ark_deopt_test") {
"dec",
"div",
"inc",
"live_out",
"mod",
"newobjrange",
"restore_vregs",

View File

@ -0,0 +1,19 @@
# Copyright (c) 2023 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//arkcompiler/ets_runtime/test/test_helper.gni")
host_aot_test_action("live_out") {
deps = []
is_debug_abc = true
}

View File

@ -0,0 +1,14 @@
# Copyright (c) 2023 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
2

View File

@ -0,0 +1,36 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// @ts-nocheck
declare function print(a:any, b?:any):string;
class C {
x:number = 1;
y:number = 2;
z:number = 3;
public update(d:number) {
const x = this.x; // occur deopt
const {
y
} = this;
print(y);
}
}
let c = new C();
C.prototype.foo = 123;
c.update(123);

View File

@ -517,6 +517,10 @@ template("host_aot_test_action") {
src_js = rebase_path(_test_ts_path_)
}
if (defined(invoker.is_debug_abc) && invoker.is_debug_abc) {
extra_args += [ "--debug" ]
}
in_puts = [
_test_ts_path_,
_test_expect_path_,
@ -542,6 +546,10 @@ template("host_aot_test_action") {
"--type-extractor",
]
if (defined(invoker.is_debug_abc) && invoker.is_debug_abc) {
extra_args += [ "--debug" ]
}
in_puts = [
_test_ts_path_,
_test_expect_path_,