mirror of
https://gitee.com/openharmony/arkcompiler_ets_runtime
synced 2024-10-07 08:03:29 +00:00
!3952 Fix the compilation bug in the process of bytecode to circuit
Merge pull request !3952 from weng-xi/phi
This commit is contained in:
commit
4f13a75bd6
@ -1209,6 +1209,7 @@ void BytecodeCircuitBuilder::NewPhi(BytecodeRegion &bb, uint16_t reg, bool acc,
|
||||
gateAcc_.NewIn(currentPhi, 1, forwardValue); // 1: index of forward value input
|
||||
gateAcc_.NewIn(currentPhi, 2, loopBackValue); // 2: index of loop-back value input
|
||||
}
|
||||
bb.phiGate.insert(currentPhi);
|
||||
}
|
||||
|
||||
// recursive variables renaming algorithm
|
||||
@ -1289,10 +1290,10 @@ GateRef BytecodeCircuitBuilder::ResolveDef(const size_t bbId, int32_t bcId, cons
|
||||
}
|
||||
// find def-site in value selectors of vregs
|
||||
if (ans == Circuit::NullGate() && !tmpAcc && bb.phi.count(tmpReg)) {
|
||||
if (!bb.vregToValSelectorGate.count(tmpReg)) {
|
||||
NewPhi(bb, tmpReg, tmpAcc, bb.vregToValSelectorGate[tmpReg]);
|
||||
if (!bb.vregToValueGate.count(tmpReg)) {
|
||||
NewPhi(bb, tmpReg, tmpAcc, bb.vregToValueGate[tmpReg]);
|
||||
}
|
||||
ans = bb.vregToValSelectorGate.at(tmpReg);
|
||||
ans = bb.vregToValueGate.at(tmpReg);
|
||||
}
|
||||
// find def-site in value selectors of acc
|
||||
if (ans == Circuit::NullGate() && tmpAcc && bb.phiAcc) {
|
||||
|
@ -174,6 +174,7 @@ struct BytecodeRegion {
|
||||
bool isLoopBody {false};
|
||||
size_t loopHead {0};
|
||||
std::set<uint16_t> phi {}; // phi node
|
||||
std::set<GateRef> phiGate {}; // phi gate
|
||||
size_t numOfStatePreds {0};
|
||||
size_t numOfLoopBacks {0};
|
||||
size_t statePredIndex {0};
|
||||
@ -188,7 +189,7 @@ struct BytecodeRegion {
|
||||
GateRef dependMerge {Circuit::NullGate()};
|
||||
GateRef loopBackStateMerge {Circuit::NullGate()};
|
||||
GateRef loopBackDependMerge {Circuit::NullGate()};
|
||||
std::unordered_map<uint16_t, GateRef> vregToValSelectorGate {}; // corresponding ValueSelector gates of vregs
|
||||
std::unordered_map<uint16_t, GateRef> vregToValueGate {}; // corresponding value gates of vregs
|
||||
GateRef valueSelectorAccGate {Circuit::NullGate()};
|
||||
BytecodeIterator bytecodeIterator_ {};
|
||||
|
||||
|
@ -153,9 +153,22 @@ bool FrameStateBuilder::MergeIntoPredBC(uint32_t predPc)
|
||||
return changed;
|
||||
}
|
||||
|
||||
GateRef FrameStateBuilder::GetPreBBInput(BytecodeRegion *bb, BytecodeRegion *predBb, GateRef gate)
|
||||
{
|
||||
if (gateAcc_.GetOpCode(gate) == OpCode::VALUE_SELECTOR) {
|
||||
return GetPhiComponent(bb, predBb, gate);
|
||||
}
|
||||
return gate;
|
||||
}
|
||||
|
||||
GateRef FrameStateBuilder::GetPhiComponent(BytecodeRegion *bb, BytecodeRegion *predBb, GateRef phi)
|
||||
{
|
||||
ASSERT(gateAcc_.GetOpCode(phi) == OpCode::VALUE_SELECTOR);
|
||||
|
||||
if (bb->phiGate.find(phi) == bb->phiGate.end()) {
|
||||
return Circuit::NullGate();
|
||||
}
|
||||
|
||||
if (bb->numOfLoopBacks != 0) {
|
||||
ASSERT(bb->loopbackBlocks.size() != 0);
|
||||
auto forwardValue = gateAcc_.GetValueIn(phi, 0); // 0: fowward
|
||||
@ -209,18 +222,21 @@ bool FrameStateBuilder::MergeIntoPredBB(BytecodeRegion *bb, BytecodeRegion *pred
|
||||
auto phi = bb->valueSelectorAccGate;
|
||||
auto value = predLiveout->ValuesAt(accumulatorIndex_);
|
||||
if (value == phi) {
|
||||
auto target = GetPhiComponent(bb, predBb, phi);
|
||||
ASSERT(target != Circuit::NullGate());
|
||||
predLiveout->SetValuesAt(accumulatorIndex_, target);
|
||||
auto target = GetPreBBInput(bb, predBb, phi);
|
||||
if (target != Circuit::NullGate()) {
|
||||
predLiveout->SetValuesAt(accumulatorIndex_, target);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (auto &it : bb->vregToValSelectorGate) {
|
||||
for (auto &it : bb->vregToValueGate) {
|
||||
auto reg = it.first;
|
||||
auto phi = it.second;
|
||||
auto gate = it.second;
|
||||
auto value = predLiveout->ValuesAt(reg);
|
||||
if (value == phi) {
|
||||
auto target = GetPhiComponent(bb, predBb, phi);
|
||||
ASSERT(target != Circuit::NullGate());
|
||||
if (value == gate) {
|
||||
auto target = GetPreBBInput(bb, predBb, gate);
|
||||
if (target == Circuit::NullGate()) {
|
||||
continue;
|
||||
}
|
||||
predLiveout->SetValuesAt(reg, target);
|
||||
}
|
||||
}
|
||||
@ -252,7 +268,7 @@ bool FrameStateBuilder::ComputeLiveOut(size_t bbId)
|
||||
SaveBBBeginStateInfo(bbId);
|
||||
|
||||
bool defPhi = bb.valueSelectorAccGate != Circuit::NullGate() ||
|
||||
bb.vregToValSelectorGate.size() != 0;
|
||||
bb.vregToValueGate.size() != 0;
|
||||
// merge current into pred bb
|
||||
for (auto bbPred : bb.preds) {
|
||||
if (bbPred->isDead) {
|
||||
@ -426,4 +442,4 @@ void FrameStateBuilder::UpdateVirtualRegistersOfResume(GateRef gate)
|
||||
restoreGate = gateAcc_.GetDep(restoreGate);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -129,6 +129,7 @@ private:
|
||||
void UpdateVirtualRegistersOfResume(GateRef gate);
|
||||
void SaveBBBeginStateInfo(size_t bbId);
|
||||
FrameStateInfo *GetCurrentFrameInfo(BytecodeRegion &bb, uint32_t bcId);
|
||||
GateRef GetPreBBInput(BytecodeRegion *bb, BytecodeRegion *predBb, GateRef gate);
|
||||
GateRef GetPhiComponent(BytecodeRegion *bb, BytecodeRegion *predBb, GateRef phi);
|
||||
|
||||
BytecodeCircuitBuilder *builder_{nullptr};
|
||||
@ -143,4 +144,4 @@ private:
|
||||
std::vector<size_t> postOrderList_;
|
||||
};
|
||||
} // panda::ecmascript::kungfu
|
||||
#endif // ECMASCRIPT_COMPILER_FRAME_STATE_H
|
||||
#endif // ECMASCRIPT_COMPILER_FRAME_STATE_H
|
||||
|
6
ecmascript/ts_types/lib_ark_builtins.d.ts
vendored
6
ecmascript/ts_types/lib_ark_builtins.d.ts
vendored
@ -36,7 +36,7 @@ interface IteratorReturnResult {
|
||||
value: any;
|
||||
}
|
||||
|
||||
interface Iterator {
|
||||
declare class Iterator {
|
||||
next(...args: [] | [any]): IteratorYieldResult | IteratorReturnResult;
|
||||
return?(value?: any): IteratorYieldResult | IteratorReturnResult;
|
||||
throw?(e?: any): IteratorYieldResult | IteratorReturnResult;
|
||||
@ -71,7 +71,7 @@ declare class RegExpMatchArray extends Array {
|
||||
input?: string;
|
||||
}
|
||||
|
||||
interface RegExp {
|
||||
declare class RegExp {
|
||||
readonly flags: string;
|
||||
|
||||
readonly sticky: boolean;
|
||||
@ -1852,4 +1852,4 @@ declare function encodeURIComponent(uriComponent: string | number | boolean): st
|
||||
|
||||
// globalThis, ArkPrivate
|
||||
// namespace, undefined
|
||||
// Intl, Reflect, TypedArray, Proxy
|
||||
// Intl, Reflect, TypedArray, Proxy
|
||||
|
Loading…
Reference in New Issue
Block a user