!10316 Some Aot Modification

Merge pull request !10316 from 许杰/Some_Aot_Optimize
This commit is contained in:
openharmony_ci 2024-11-22 06:43:58 +00:00 committed by Gitee
commit 9682ba8b45
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
8 changed files with 711 additions and 368 deletions

File diff suppressed because it is too large Load Diff

View File

@ -247,6 +247,34 @@ private:
explicit BytecodeMetaData(uint64_t value) : value_(value) {}
static BytecodeMetaData InitBytecodeMetaData(const uint8_t *pc);
static void InitBytecodeFlags(EcmaOpcode &opcode, uint32_t &flags);
static void InitBytecodeKind(EcmaOpcode &opcode, BytecodeKind &kind);
static void InitNoSideEffectFlag(EcmaOpcode &opcode, uint32_t &flags);
static void InitNoGCFlag(EcmaOpcode &opcode, uint32_t &flags);
static void InitNoThrowFlag(EcmaOpcode &opcode, uint32_t &flags);
static void InitReadThisObjectFlag(EcmaOpcode &opcode, uint32_t &flags);
static void InitSupportDeoptFlag(EcmaOpcode &opcode, uint32_t &flags);
static void InitReadACCFlag(EcmaOpcode &opcode, uint32_t &flags);
static void InitDebuggerFlag(EcmaOpcode &opcode, uint32_t &flags);
static void InitReadFuncFlag(EcmaOpcode &opcode, uint32_t &flags);
static void InitWriteEnvFlag(EcmaOpcode &opcode, uint32_t &flags);
static void InitReadEnvFlag(EcmaOpcode &opcode, uint32_t &flags);
static void InitReadNewTargetFlag(EcmaOpcode &opcode, uint32_t &flags);
static void InitReadArgcFlag(EcmaOpcode &opcode, uint32_t &flags);
static bool InitMovKind(EcmaOpcode &opcode, BytecodeKind &kind);
static bool InitSetConstantKind(EcmaOpcode &opcode, BytecodeKind &kind);
static bool InitCallBCKind(EcmaOpcode &opcode, BytecodeKind &kind);
static bool InitRetrunKind(EcmaOpcode &opcode, BytecodeKind &kind);
static bool InitSuspendKind(EcmaOpcode &opcode, BytecodeKind &kind);
static bool InitResumeKind(EcmaOpcode &opcode, BytecodeKind &kind);
static bool InitDiscardedKind(EcmaOpcode &opcode, BytecodeKind &kind);
static bool InitThrowKind(EcmaOpcode &opcode, BytecodeKind &kind);
static bool InitConditionJumpKind(EcmaOpcode &opcode, BytecodeKind &kind);
static bool InitJumpIMMKind(EcmaOpcode &opcode, BytecodeKind &kind);
static bool InitGeneratorResolveKind(EcmaOpcode &opcode, BytecodeKind &kind);
static bool InitAccessorKind(EcmaOpcode &opcode, BytecodeKind &kind);
static size_t GetVRegCount(const BytecodeInstruction &inst);

View File

@ -363,8 +363,23 @@ bool EarlyElimination::CheckReplacement(GateRef lhs, GateRef rhs)
case OpCode::TYPED_ARRAY_CHECK: {
TypedArrayMetaDataAccessor lhsAccessor = acc_.GetTypedArrayMetaDataAccessor(lhs);
TypedArrayMetaDataAccessor rhsAccessor = acc_.GetTypedArrayMetaDataAccessor(rhs);
if ((lhsAccessor.GetParamType() != rhsAccessor.GetParamType()) ||
(lhsAccessor.GetOnHeapMode() != rhsAccessor.GetOnHeapMode())) {
if ((lhsAccessor.GetParamType() != rhsAccessor.GetParamType())) {
return false;
}
OnHeapMode lMode = lhsAccessor.GetOnHeapMode();
OnHeapMode rMode = rhsAccessor.GetOnHeapMode();
// When the onheapmode types of the two checks are inconsistent and one type is none, the none type will be
// updated to another type. Because there is no side effect between the two checks, the onheapmode types are
// also consistent.
if (lMode != rMode) {
if (OnHeap::IsNone(lMode)) {
acc_.UpdateOnHeapMode(lhs, rMode);
return true;
} else if (OnHeap::IsNone(rMode)) {
acc_.UpdateOnHeapMode(rhs, lMode);
return true;
}
return false;
}
break;

View File

@ -325,6 +325,15 @@ TypedArrayMetaDataAccessor GateAccessor::GetTypedArrayMetaDataAccessor(GateRef g
return TypedArrayMetaDataAccessor(gatePtr->GetOneParameterMetaData()->GetValue());
}
void GateAccessor::UpdateOnHeapMode(GateRef gate, OnHeapMode onHeapMode)
{
ASSERT(GetOpCode(gate) == OpCode::TYPED_ARRAY_CHECK);
Gate *gatePtr = circuit_->LoadGatePtr(gate);
TypedArrayMetaDataAccessor accessor = GetTypedArrayMetaDataAccessor(gate);
uint64_t value = accessor.UpdateOnHeapMode(onHeapMode);
const_cast<OneParameterMetaData *>(gatePtr->GetOneParameterMetaData())->SetValue(value);
}
LoadElementAccessor GateAccessor::GetLoadElementAccessor(GateRef gate) const
{
ASSERT(GetOpCode(gate) == OpCode::LOAD_ELEMENT);

View File

@ -624,6 +624,7 @@ public:
TypedBinOp GetRevCompareOpForTypedBinOp(TypedBinOp op);
TypedBinOp GetSwapCompareOpForTypedBinOp(TypedBinOp op);
void UpdateOnHeapMode(GateRef gate, OnHeapMode onHeapMode);
private:
const GateMetaData *GetMetaData(GateRef gate) const;

View File

@ -690,6 +690,11 @@ public:
return OnHeapModeBits::Get(bitField_);
}
uint64_t UpdateOnHeapMode(OnHeapMode mode)
{
return OnHeapModeBits::Update(bitField_, mode);
}
bool IsAccessElement() const
{
return ModeBits::Get(bitField_) == Mode::ACCESS_ELEMENT;

View File

@ -418,21 +418,24 @@ void TypedHCRLowering::LowerTypedArrayCheck(GateRef gate)
GateRef glueGlobalEnv = builder_.GetGlobalEnv();
GateRef receiver = acc_.GetValueIn(gate, 0);
builder_.HeapObjectCheck(receiver, frameState);
GateRef receiverHClass = builder_.LoadHClass(receiver);
GateRef rootHclass = builder_.GetGlobalEnvObj(glueGlobalEnv, typedArrayRootHclassIndex);
GateRef rootOnHeapHclass = builder_.GetGlobalEnvObj(glueGlobalEnv, typedArrayRootHclassOnHeapIndex);
GateRef check1 = builder_.Equal(receiverHClass, rootHclass);
GateRef check2 = builder_.Equal(receiverHClass, rootOnHeapHclass);
builder_.DeoptCheck(builder_.BitOr(check1, check2), frameState, deoptType);
GateRef receiverHClass = builder_.LoadHClassByConstOffset(receiver);
OnHeapMode onHeapMode = accessor.GetOnHeapMode();
if (accessor.IsAccessElement() && !OnHeap::IsNone(onHeapMode)) {
GateRef profilingOnHeap = builder_.Boolean(OnHeap::ToBoolean(onHeapMode));
GateRef runtimeOnHeap = builder_.IsOnHeap(receiverHClass);
GateRef onHeapCheck = builder_.Equal(profilingOnHeap, runtimeOnHeap);
builder_.DeoptCheck(onHeapCheck, frameState, DeoptType::INCONSISTENTONHEAP1);
if (OnHeap::IsOnHeap(onHeapMode)) {
GateRef rootOnHeapHclass = builder_.GetGlobalEnvObj(glueGlobalEnv, typedArrayRootHclassOnHeapIndex);
GateRef check = builder_.Equal(receiverHClass, rootOnHeapHclass);
builder_.DeoptCheck(check, frameState, deoptType);
} else if (OnHeap::IsNotOnHeap(onHeapMode)) {
GateRef rootHclass = builder_.GetGlobalEnvObj(glueGlobalEnv, typedArrayRootHclassIndex);
GateRef check = builder_.Equal(receiverHClass, rootHclass);
builder_.DeoptCheck(check, frameState, deoptType);
} else {
GateRef rootHclass = builder_.GetGlobalEnvObj(glueGlobalEnv, typedArrayRootHclassIndex);
GateRef rootOnHeapHclass = builder_.GetGlobalEnvObj(glueGlobalEnv, typedArrayRootHclassOnHeapIndex);
GateRef check1 = builder_.Equal(receiverHClass, rootHclass);
GateRef check2 = builder_.Equal(receiverHClass, rootOnHeapHclass);
builder_.DeoptCheck(builder_.BitOr(check1, check2), frameState, deoptType);
}
acc_.ReplaceGate(gate, builder_.GetState(), builder_.GetDepend(), Circuit::NullGate());
}
@ -468,7 +471,7 @@ void TypedHCRLowering::LowerEcmaMapCheck(GateRef gate)
GateRef receiver = acc_.GetValueIn(gate, 0);
builder_.HeapObjectCheck(receiver, frameState);
GateRef hclass = builder_.LoadHClass(receiver);
GateRef hclass = builder_.LoadHClassByConstOffset(receiver);
size_t mapHclassIndex = GlobalEnv::MAP_CLASS_INDEX;
GateRef glueGlobalEnv = builder_.GetGlobalEnv();
@ -623,10 +626,17 @@ void TypedHCRLowering::BuiltinInstanceHClassCheck(Environment *env, GateRef gate
auto iter = arrayHClassIndexMap.find(kind);
ASSERT(iter != arrayHClassIndexMap.end());
GateRef receiverHClass = builder_.LoadHClassByConstOffset(receiver);
// If the Elements kind is Generic, hclass comparison is required. Other kinds can ensure that hclass has
// not been modified.
ihcMatches = LogicOrBuilder(env)
.Or(builder_.Equal(receiverHClass, builder_.GetGlobalConstantValue(iter->second.first)))
.Or(builder_.Equal(receiverHClass, builder_.GetGlobalConstantValue(iter->second.second)))
.Done();
GateRef elementsKind = builder_.GetElementsKindByHClass(receiverHClass);
ihcMatches = LogicOrBuilder(env)
.Or(ihcMatches)
.Or(builder_.NotEqual(elementsKind, builder_.Int32(static_cast<size_t>(ElementsKind::GENERIC))))
.Done();
} else {
GateRef receiverHClass = builder_.LoadHClassByConstOffset(receiver);
GateRef elementsKind = builder_.GetElementsKindByHClass(receiverHClass);
@ -1212,7 +1222,7 @@ GateRef TypedHCRLowering::BuildTypedArrayLoadElement(GateRef receiver, GateRef o
DEFVALUE(data, (&builder_), VariableType::JS_ANY(), builder_.Undefined());
DEFVALUE(result, (&builder_), type, builder_.Double(0));
GateRef isOnHeap = builder_.IsOnHeap(builder_.LoadHClass(receiver));
GateRef isOnHeap = builder_.IsOnHeap(builder_.LoadHClassByConstOffset(receiver));
BRANCH_CIR(isOnHeap, isByteArray, isArrayBuffer);
builder_.Bind(isByteArray);
{
@ -1394,7 +1404,7 @@ void TypedHCRLowering::BuildTypedArrayStoreElement(GateRef receiver, GateRef off
{
GateRef byteArrayOrArrayBuffer = builder_.LoadConstOffset(VariableType::JS_POINTER(), receiver,
JSTypedArray::VIEWED_ARRAY_BUFFER_OFFSET);
GateRef isOnHeap = builder_.IsOnHeap(builder_.LoadHClass(receiver));
GateRef isOnHeap = builder_.IsOnHeap(builder_.LoadHClassByConstOffset(receiver));
DEFVALUE(data, (&builder_), VariableType::JS_ANY(), builder_.Undefined());
BRANCH_CIR(isOnHeap, isByteArray, isArrayBuffer);
builder_.Bind(isByteArray);
@ -1596,10 +1606,9 @@ void TypedHCRLowering::LowerJSInlineTargetTypeCheck(GateRef gate)
GateRef frameState = GetFrameState(gate);
auto func = acc_.GetValueIn(gate, 0);
builder_.HeapObjectCheck(func, frameState);
GateRef check = LogicAndBuilder(&env)
.And(builder_.IsJSFunction(func))
.And(builder_.Equal(builder_.GetMethodId(func), acc_.GetValueIn(gate, 1)))
.Done();
GateRef isFunction = builder_.IsJSFunction(func);
builder_.DeoptCheck(isFunction, frameState, DeoptType::NOTJSFUNCTION);
GateRef check = builder_.Equal(builder_.GetMethodId(func), acc_.GetValueIn(gate, 1));
builder_.DeoptCheck(check, frameState, DeoptType::INLINEFAIL1);
acc_.ReplaceGate(gate, builder_.GetState(), builder_.GetDepend(), Circuit::NullGate());
}
@ -1648,7 +1657,7 @@ void TypedHCRLowering::LowerGetSuperConstructor(GateRef gate)
{
Environment env(gate, circuit_, &builder_);
GateRef ctor = acc_.GetValueIn(gate, 0);
GateRef hclass = builder_.LoadHClass(ctor);
GateRef hclass = builder_.LoadHClassByConstOffset(ctor);
GateRef superCtor = builder_.LoadConstOffset(VariableType::JS_ANY(), hclass, JSHClass::PROTOTYPE_OFFSET);
acc_.ReplaceGate(gate, builder_.GetState(), builder_.GetDepend(), superCtor);
}
@ -1724,7 +1733,7 @@ void TypedHCRLowering::LowerLookupHolder(GateRef gate)
builder_.LoopBegin(&loopHead);
builder_.DeoptCheck(builder_.TaggedIsNotNull(*holder), frameState, DeoptType::INCONSISTENTHCLASS13);
auto curHC = builder_.LoadHClass(*holder);
auto curHC = builder_.LoadHClassByConstOffset(*holder);
BRANCH_CIR(builder_.Equal(curHC, holderHC), &exit, &lookUpProto);
builder_.Bind(&lookUpProto);
@ -1787,7 +1796,7 @@ void TypedHCRLowering::LowerPrototypeCheck(GateRef gate)
auto expectedReceiverHC = builder_.LoadHClassFromConstpool(unsharedConstPool, hclassIndex);
auto prototype = builder_.LoadConstOffset(VariableType::JS_ANY(), expectedReceiverHC, JSHClass::PROTOTYPE_OFFSET);
auto protoHClass = builder_.LoadHClass(prototype);
auto protoHClass = builder_.LoadHClassByConstOffset(prototype);
auto marker = builder_.LoadConstOffset(VariableType::JS_ANY(), protoHClass, JSHClass::PROTO_CHANGE_MARKER_OFFSET);
builder_.DeoptCheck(builder_.TaggedIsNotNull(marker), frameState, DeoptType::PROTOTYPECHANGED1);
auto check = LogicAndBuilder(&env)
@ -2568,7 +2577,7 @@ void TypedHCRLowering::LowerOrdinaryHasInstance(GateRef gate, GateRef glue)
}
builder_.Bind(&objectNotIsJsProxy);
{
GateRef objHClass = builder_.LoadHClass(*object);
GateRef objHClass = builder_.LoadHClassByConstOffset(*object);
object = builder_.LoadPrototype(objHClass);
builder_.Jump(&shouldContinue);
}

View File

@ -32,6 +32,16 @@ public:
return !(mode == OnHeapMode::ON_HEAP || mode == OnHeapMode::NOT_ON_HEAP);
}
static bool IsOnHeap(OnHeapMode mode)
{
return mode == OnHeapMode::ON_HEAP;
}
static bool IsNotOnHeap(OnHeapMode mode)
{
return mode == OnHeapMode::NOT_ON_HEAP;
}
static OnHeapMode Merge(OnHeapMode first, OnHeapMode second)
{
if (IsNone(first) || IsNone(second) || (first != second)) {