!3810 抽取MIR LoadConstOffset

Merge pull request !3810 from yingguofeng/master
This commit is contained in:
openharmony_ci 2023-03-31 15:30:27 +00:00 committed by Gitee
commit 4e3d3b35da
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
10 changed files with 122 additions and 6 deletions

View File

@ -842,6 +842,19 @@ GateRef CircuitBuilder::LoadArrayLength(GateRef array)
return ret;
}
GateRef CircuitBuilder::LoadConstOffset(VariableType type, GateRef receiver, size_t offset)
{
auto currentLabel = env_->GetCurrentLabel();
auto currentControl = currentLabel->GetControl();
auto currentDepend = currentLabel->GetDepend();
auto ret = GetCircuit()->NewGate(circuit_->LoadConstOffset(offset), type.GetMachineType(),
{ currentControl, currentDepend, receiver }, type.GetGateType());
currentLabel->SetControl(ret);
currentLabel->SetDepend(ret);
return ret;
}
GateRef CircuitBuilder::Construct(GateRef hirGate, std::vector<GateRef> args)
{
ASSERT(acc_.GetOpCode(hirGate) == OpCode::JS_BYTECODE);

View File

@ -468,6 +468,7 @@ public:
GateRef CallGetter(GateRef hirGate, GateRef receiver, GateRef propertyLookupResult);
GateRef CallSetter(GateRef hirGate, GateRef receiver, GateRef propertyLookupResult, GateRef value);
GateRef GetConstPool(GateRef jsFunc);
GateRef LoadConstOffset(VariableType type, GateRef receiver, size_t offset);
// Object Operations
inline GateRef LoadHClass(GateRef object);

View File

@ -47,6 +47,15 @@ GateRef DependChainInfo::LookUpArrayLength(ArrayLengthInfo info) const
}
}
GateRef DependChainInfo::LookUpLoadConstOffset(LoadConstInfo info) const
{
if ((loadConstMap_ != nullptr) && (loadConstMap_->count(info) > 0)) {
return loadConstMap_->at(info);
} else {
return Circuit::NullGate();
}
}
bool DependChainInfo::LookUpGateTypeCheck(GateTypeCheckInfo info) const
{
return (gateTypeCheckSet_ != nullptr) && (gateTypeCheckSet_->count(info) > 0);
@ -134,6 +143,18 @@ DependChainInfo* DependChainInfo::UpdateArrayLength(ArrayLengthInfo info, GateRe
return that;
}
DependChainInfo* DependChainInfo::UpdateLoadConstOffset(LoadConstInfo info, GateRef gate)
{
DependChainInfo* that = new (chunk_) DependChainInfo(*this);
if (loadConstMap_ != nullptr) {
that->loadConstMap_ = new ChunkMap<LoadConstInfo, GateRef>(*loadConstMap_);
} else {
that->loadConstMap_ = new ChunkMap<LoadConstInfo, GateRef>(chunk_);
}
that->loadConstMap_->insert(std::make_pair(info, gate));
return that;
}
DependChainInfo* DependChainInfo::UpdateGateTypeCheck(GateTypeCheckInfo info)
{
DependChainInfo* that = new (chunk_) DependChainInfo(*this);
@ -226,6 +247,7 @@ bool DependChainInfo::Empty() const {
return (elementMap_ == nullptr) &&
(propertyMap_ == nullptr) &&
(arrayLengthMap_ == nullptr) &&
(loadConstMap_ == nullptr) &&
(gateTypeCheckSet_ == nullptr) &&
(int32OverflowCheckSet_ == nullptr) &&
(stableArrayCheckSet_ == nullptr) &&
@ -275,6 +297,9 @@ bool DependChainInfo::Equals(DependChainInfo* that)
if (!EqualsMap<ArrayLengthInfo, GateRef>(arrayLengthMap_, that->arrayLengthMap_)) {
return false;
}
if (!EqualsMap<LoadConstInfo, GateRef>(loadConstMap_, that->loadConstMap_)) {
return false;
}
if (!EqualsSet<GateTypeCheckInfo>(gateTypeCheckSet_, that->gateTypeCheckSet_)) {
return false;
}
@ -343,6 +368,7 @@ DependChainInfo* DependChainInfo::Merge(DependChainInfo* that)
newInfo->elementMap_ = MergeMap<ElementInfo, GateRef>(elementMap_, that->elementMap_);
newInfo->propertyMap_ = MergeMap<PropertyInfo, GateRef>(propertyMap_, that->propertyMap_);
newInfo->arrayLengthMap_ = MergeMap<ArrayLengthInfo, GateRef>(arrayLengthMap_, that->arrayLengthMap_);
newInfo->loadConstMap_ = MergeMap<LoadConstInfo, GateRef>(loadConstMap_, that->loadConstMap_);
newInfo->gateTypeCheckSet_ =
MergeSet<GateTypeCheckInfo>(gateTypeCheckSet_, that->gateTypeCheckSet_);
newInfo->int32OverflowCheckSet_ =
@ -421,6 +447,13 @@ ArrayLengthInfo EarlyElimination::GetArrayLengthInfo(GateRef gate) const
return ArrayLengthInfo(v0);
}
LoadConstInfo EarlyElimination::GetLoadConstInfo(GateRef gate) const
{
auto receiver = acc_.GetValueIn(gate, 0);
auto offset = acc_.GetOffset(gate);
return LoadConstInfo(receiver, offset);
}
Int32OverflowCheckInfo EarlyElimination::GetInt32OverflowCheckInfo(GateRef gate) const
{
TypedUnaryAccessor accessor(acc_.TryGetValue(gate));
@ -461,6 +494,8 @@ GateRef EarlyElimination::VisitGate(GateRef gate)
return TryEliminateElement(gate);
case OpCode::LOAD_ARRAY_LENGTH:
return TryEliminateArrayLength(gate);
case OpCode::LOAD_CONST_OFFSET:
return TryEliminateLoadConstOffset(gate);
case OpCode::TYPED_ARRAY_CHECK:
case OpCode::OBJECT_TYPE_CHECK:
return TryEliminateObjectTypeCheck(gate);
@ -591,6 +626,23 @@ GateRef EarlyElimination::TryEliminateArrayLength(GateRef gate)
return UpdateDependInfo(gate, dependInfo);
}
GateRef EarlyElimination::TryEliminateLoadConstOffset(GateRef gate)
{
auto depIn = acc_.GetDep(gate);
auto dependInfo = dependInfos_[acc_.GetId(depIn)];
if (dependInfo == nullptr) {
return Circuit::NullGate();
}
auto info = GetLoadConstInfo(gate);
auto preGate = dependInfo->LookUpLoadConstOffset(info);
if (preGate != Circuit::NullGate()) {
return preGate;
}
dependInfo = dependInfo->UpdateLoadConstOffset(info, gate);
return UpdateDependInfo(gate, dependInfo);
}
GateRef EarlyElimination::TryEliminateObjectTypeCheck(GateRef gate)
{
auto depIn = acc_.GetDep(gate);
@ -807,4 +859,4 @@ GateRef EarlyElimination::UpdateDependInfo(GateRef gate, DependChainInfo* depend
return gate;
}
} // namespace panda::ecmascript::kungfu
} // namespace panda::ecmascript::kungfu

View File

@ -100,6 +100,29 @@ private:
GateRef receiver_ {Circuit::NullGate()};
};
class LoadConstInfo {
public:
LoadConstInfo(GateRef receiver, size_t offset) : receiver_(receiver), offset_(offset) {}
~LoadConstInfo() = default;
bool operator < (const LoadConstInfo& rhs) const
{
if (receiver_ != rhs.receiver_) {
return receiver_ < rhs.receiver_;
} else {
return offset_ < rhs.offset_;
}
}
bool operator == (const LoadConstInfo& rhs) const
{
return receiver_ == rhs.receiver_ && offset_ == rhs.offset_;
}
private:
GateRef receiver_ {Circuit::NullGate()};
size_t offset_;
};
class GateTypeCheckInfo {
public:
GateTypeCheckInfo(GateRef value, GateType type) : value_(value), type_(type) {}
@ -290,6 +313,7 @@ public:
GateRef LookUpElement(ElementInfo info) const;
GateRef LookUpProperty(PropertyInfo info) const;
GateRef LookUpArrayLength(ArrayLengthInfo info) const;
GateRef LookUpLoadConstOffset(LoadConstInfo info) const;
bool LookUpGateTypeCheck(GateTypeCheckInfo info) const;
GateTypeCheckInfo LookUpGateTypeCheck(GateRef gate) const;
bool LookUpInt32OverflowCheck(Int32OverflowCheckInfo info) const;
@ -302,6 +326,7 @@ public:
DependChainInfo* UpdateElement(ElementInfo info, GateRef gate);
DependChainInfo* UpdateProperty(PropertyInfo info, GateRef gate);
DependChainInfo* UpdateArrayLength(ArrayLengthInfo info, GateRef gate);
DependChainInfo* UpdateLoadConstOffset(LoadConstInfo info, GateRef gate);
DependChainInfo* UpdateGateTypeCheck(GateTypeCheckInfo info);
DependChainInfo* UpdateInt32OverflowCheck(Int32OverflowCheckInfo info);
DependChainInfo* UpdateStableArrayCheck(StableArrayCheckInfo info);
@ -327,6 +352,7 @@ private:
ChunkMap<ElementInfo, GateRef>* elementMap_ {nullptr};
ChunkMap<PropertyInfo, GateRef>* propertyMap_ {nullptr};
ChunkMap<ArrayLengthInfo, GateRef>* arrayLengthMap_ {nullptr};
ChunkMap<LoadConstInfo, GateRef>* loadConstMap_ {nullptr};
ChunkSet<GateTypeCheckInfo>* gateTypeCheckSet_ {nullptr};
ChunkSet<Int32OverflowCheckInfo>* int32OverflowCheckSet_ {nullptr};
ChunkSet<StableArrayCheckInfo>* stableArrayCheckSet_ {nullptr};
@ -362,6 +388,7 @@ private:
ElementInfo GetElementInfo(GateRef gate) const;
PropertyInfo GetPropertyInfo(GateRef gate) const;
ArrayLengthInfo GetArrayLengthInfo(GateRef gate) const;
LoadConstInfo GetLoadConstInfo(GateRef gate) const;
Int32OverflowCheckInfo GetInt32OverflowCheckInfo(GateRef gate) const;
StableArrayCheckInfo GetStableArrayCheckInfo(GateRef gate) const;
IndexCheckInfo GetIndexCheckInfo(GateRef gate) const;
@ -371,6 +398,7 @@ private:
GateRef TryEliminateElement(GateRef gate);
GateRef TryEliminateProperty(GateRef gate);
GateRef TryEliminateArrayLength(GateRef gate);
GateRef TryEliminateLoadConstOffset(GateRef gate);
GateRef TryEliminateGateTypeCheck(GateRef gate);
GateRef TryEliminateInt32OverflowCheck(GateRef gate);
GateRef TryEliminateStableArrayCheck(GateRef gate);
@ -393,4 +421,4 @@ private:
ChunkVector<DependChainInfo*> dependInfos_;
};
} // panda::ecmascript::kungfu
#endif // ECMASCRIPT_COMPILER_EARLY_ELIMINATION_H
#endif // ECMASCRIPT_COMPILER_EARLY_ELIMINATION_H

View File

@ -96,6 +96,13 @@ ConstDataId GateAccessor::GetConstDataId(GateRef gate) const
return ConstDataId(gatePtr->GetOneParameterMetaData()->GetValue());
}
size_t GateAccessor::GetOffset(GateRef gate) const
{
ASSERT(GetOpCode(gate) == OpCode::LOAD_CONST_OFFSET);
Gate *gatePtr = circuit_->LoadGatePtr(gate);
return gatePtr->GetOneParameterMetaData()->GetValue();
}
TypedUnaryAccessor GateAccessor::GetTypedUnOp(GateRef gate) const
{
ASSERT(GetOpCode(gate) == OpCode::TYPED_UNARY_OP);

View File

@ -374,6 +374,7 @@ public:
ICmpCondition GetICmpCondition(GateRef gate) const;
FCmpCondition GetFCmpCondition(GateRef gate) const;
ConstDataId GetConstDataId(GateRef gate) const;
size_t GetOffset(GateRef gate) const;
size_t GetVirtualRegisterIndex(GateRef gate) const;
TypedLoadOp GetTypedLoadOp(GateRef gate) const;
TypedStoreOp GetTypedStoreOp(GateRef gate) const;

View File

@ -269,6 +269,7 @@ std::string MachineTypeToStr(MachineType machineType);
V(SwitchBranch, SWITCH_BRANCH, GateFlags::CONTROL, 1, 0, 1) \
V(SwitchCase, SWITCH_CASE, GateFlags::CONTROL, 1, 0, 0) \
V(HeapAlloc, HEAP_ALLOC, GateFlags::NONE_FLAG, 1, 1, 1) \
V(LoadConstOffset, LOAD_CONST_OFFSET, GateFlags::NO_WRITE, 1, 1, 1) \
V(LoadElement, LOAD_ELEMENT, GateFlags::NO_WRITE, 1, 1, 2) \
V(StoreElement, STORE_ELEMENT, GateFlags::NONE_FLAG, 1, 1, 3) \
V(RestoreRegister, RESTORE_REGISTER, GateFlags::NONE_FLAG, 0, 1, 0) \

View File

@ -762,7 +762,8 @@ void TSTypeLowering::LowerTypedLdObjByValue(GateRef gate, bool isThis)
GateRef length = builder_.LoadArrayLength(receiver);
builder_.IndexCheck(receiverType, length, propKey);
ASSERT(acc_.GetOpCode(acc_.GetDep(gate)) == OpCode::STATE_SPLIT);
GateRef result = builder_.LoadElement<TypedLoadOp::ARRAY_LOAD_ELEMENT>(receiver, propKey);
GateRef element = builder_.LoadConstOffset(VariableType::JS_POINTER(), receiver, JSObject::ELEMENTS_OFFSET);
GateRef result = builder_.LoadElement<TypedLoadOp::ARRAY_LOAD_ELEMENT>(element, propKey);
acc_.ReplaceHirAndDeleteIfException(gate, builder_.GetStateDepend(), result);
}

View File

@ -100,6 +100,9 @@ void TypeLowering::LowerType(GateRef gate)
case OpCode::LOAD_ARRAY_LENGTH:
LowerLoadArrayLength(gate);
break;
case OpCode::LOAD_CONST_OFFSET:
LowerLoadConstOffset(gate);
break;
case OpCode::LOAD_ELEMENT:
LowerLoadElement(gate);
break;
@ -615,6 +618,16 @@ void TypeLowering::LowerLoadArrayLength(GateRef gate)
acc_.ReplaceGate(gate, builder_.GetState(), builder_.GetDepend(), result);
}
void TypeLowering::LowerLoadConstOffset(GateRef gate)
{
Environment env(gate, circuit_, &builder_);
GateRef receiver = acc_.GetValueIn(gate, 0);
GateRef offset = builder_.IntPtr(acc_.GetOffset(gate));
GateRef result = builder_.Load(
VariableType(acc_.GetMachineType(gate), acc_.GetGateType(gate)), receiver, offset);
acc_.ReplaceGate(gate, builder_.GetState(), builder_.GetDepend(), result);
}
void TypeLowering::LowerLoadElement(GateRef gate)
{
Environment env(gate, circuit_, &builder_);
@ -636,9 +649,7 @@ void TypeLowering::LowerLoadElement(GateRef gate)
void TypeLowering::LowerArrayLoadElement(GateRef gate)
{
Environment env(gate, circuit_, &builder_);
GateRef receiver = acc_.GetValueIn(gate, 0);
GateRef element =
builder_.Load(VariableType::JS_POINTER(), receiver, builder_.IntPtr(JSObject::ELEMENTS_OFFSET));
GateRef element = acc_.GetValueIn(gate, 0);
GateRef index = acc_.GetValueIn(gate, 1);
GateRef res = builder_.GetValueFromTaggedArray(element, index);
DEFVAlUE(result, (&builder_), VariableType::JS_ANY(), res);

View File

@ -191,6 +191,7 @@ private:
void LowerStoreProperty(GateRef gate, GateRef glue);
void LowerCallSetter(GateRef gate, GateRef glue);
void LowerLoadArrayLength(GateRef gate);
void LowerLoadConstOffset(GateRef gate);
void LowerStoreElement(GateRef gate, GateRef glue);
void LowerLoadElement(GateRef gate);
void LowerLoadFromTaggedArray(GateRef gate);