!5393 Create Object With BC Info

Merge pull request !5393 from ChunyangWang/create_obj_with_bc_info
This commit is contained in:
openharmony_ci 2023-12-01 10:20:50 +00:00 committed by Gitee
commit 8d1283a06c
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
12 changed files with 106 additions and 20 deletions

View File

@ -524,7 +524,7 @@ public:
GateRef CheckNullAndConvertToBool(GateRef gate); GateRef CheckNullAndConvertToBool(GateRef gate);
GateRef CheckUndefinedAndConvertToInt32(GateRef gate); GateRef CheckUndefinedAndConvertToInt32(GateRef gate);
GateRef StartAllocate(); GateRef StartAllocate();
GateRef FinishAllocate(); GateRef FinishAllocate(GateRef value);
inline GateRef PrimitiveToNumber(GateRef x, VariableType type); inline GateRef PrimitiveToNumber(GateRef x, VariableType type);
inline GateRef GetValueFromTaggedArray(GateRef array, GateRef index); inline GateRef GetValueFromTaggedArray(GateRef array, GateRef index);

View File

@ -102,7 +102,8 @@ enum class CallExceptionKind : bool {
V(MulWithOverflow, (GateRef gate, GateRef e1, GateRef e2)) \ V(MulWithOverflow, (GateRef gate, GateRef e1, GateRef e2)) \
V(ExtractValue, (GateRef gate, GateRef e1, GateRef e2)) \ V(ExtractValue, (GateRef gate, GateRef e1, GateRef e2)) \
V(Sqrt, (GateRef gate, GateRef e1)) \ V(Sqrt, (GateRef gate, GateRef e1)) \
V(ReadSp, (GateRef gate)) V(ReadSp, (GateRef gate)) \
V(FinishAllocate, (GateRef gate, GateRef e1))
bool IsAddIntergerType(MachineType machineType); bool IsAddIntergerType(MachineType machineType);
bool IsMulIntergerType(MachineType machineType); bool IsMulIntergerType(MachineType machineType);

View File

@ -204,6 +204,7 @@ void LLVMIRBuilder::InitializeHandlers()
{OpCode::EXTRACT_VALUE, &LLVMIRBuilder::HandleExtractValue}, {OpCode::EXTRACT_VALUE, &LLVMIRBuilder::HandleExtractValue},
{OpCode::SQRT, &LLVMIRBuilder::HandleSqrt}, {OpCode::SQRT, &LLVMIRBuilder::HandleSqrt},
{OpCode::READSP, &LLVMIRBuilder::HandleReadSp}, {OpCode::READSP, &LLVMIRBuilder::HandleReadSp},
{OpCode::FINISH_ALLOCATE, &LLVMIRBuilder::HandleFinishAllocate},
}; };
illegalOpHandlers_ = { illegalOpHandlers_ = {
OpCode::NOP, OpCode::CIRCUIT_ROOT, OpCode::DEPEND_ENTRY, OpCode::NOP, OpCode::CIRCUIT_ROOT, OpCode::DEPEND_ENTRY,
@ -212,7 +213,7 @@ void LLVMIRBuilder::InitializeHandlers()
OpCode::DEPEND_SELECTOR, OpCode::DEPEND_RELAY, OpCode::DEPEND_SELECTOR, OpCode::DEPEND_RELAY,
OpCode::FRAME_STATE, OpCode::STATE_SPLIT, OpCode::FRAME_ARGS, OpCode::FRAME_STATE, OpCode::STATE_SPLIT, OpCode::FRAME_ARGS,
OpCode::LOOP_EXIT_DEPEND, OpCode::LOOP_EXIT, OpCode::LOOP_EXIT_DEPEND, OpCode::LOOP_EXIT,
OpCode::START_ALLOCATE, OpCode::FINISH_ALLOCATE, OpCode::FRAME_VALUES OpCode::START_ALLOCATE, OpCode::FRAME_VALUES
}; };
} }
@ -1349,6 +1350,21 @@ void LLVMIRBuilder::VisitMod(GateRef gate, GateRef e1, GateRef e2)
} }
} }
void LLVMIRBuilder::HandleFinishAllocate(GateRef gate)
{
auto g0 = acc_.GetValueIn(gate, 0);
VisitFinishAllocate(gate, g0);
}
void LLVMIRBuilder::VisitFinishAllocate(GateRef gate, GateRef e1)
{
LLVMValueRef result = GetLValue(e1);
Bind(gate, result);
if (IsLogEnabled()) {
SetDebugInfo(gate, result);
}
}
void LLVMIRBuilder::VisitBranch(GateRef gate, GateRef cmp, int btrue, int bfalse) void LLVMIRBuilder::VisitBranch(GateRef gate, GateRef cmp, int btrue, int bfalse)
{ {
if (gate2LValue_.count(cmp) == 0) { if (gate2LValue_.count(cmp) == 0) {

View File

@ -854,12 +854,12 @@ GateRef CircuitBuilder::StartAllocate()
return newGate; return newGate;
} }
GateRef CircuitBuilder::FinishAllocate() GateRef CircuitBuilder::FinishAllocate(GateRef value)
{ {
auto currentLabel = env_->GetCurrentLabel(); auto currentLabel = env_->GetCurrentLabel();
auto currentDepend = currentLabel->GetDepend(); auto currentDepend = currentLabel->GetDepend();
GateRef newGate = GetCircuit()->NewGate(circuit_->FinishAllocate(), MachineType::I64, GateRef newGate = GetCircuit()->NewGate(circuit_->FinishAllocate(), MachineType::I64,
{ currentDepend }, GateType::NJSValue()); { currentDepend, value }, acc_.GetGateType(value));
currentLabel->SetDepend(newGate); currentLabel->SetDepend(newGate);
return newGate; return newGate;
} }
@ -869,7 +869,7 @@ GateRef CircuitBuilder::HeapAlloc(GateRef size, GateType type, RegionSpaceFlag f
auto currentLabel = env_->GetCurrentLabel(); auto currentLabel = env_->GetCurrentLabel();
auto currentControl = currentLabel->GetControl(); auto currentControl = currentLabel->GetControl();
auto currentDepend = currentLabel->GetDepend(); auto currentDepend = currentLabel->GetDepend();
auto ret = GetCircuit()->NewGate(circuit_->HeapAlloc(flag), MachineType::ANYVALUE, auto ret = GetCircuit()->NewGate(circuit_->HeapAlloc(flag), MachineType::I64,
{ currentControl, currentDepend, size }, type); { currentControl, currentDepend, size }, type);
currentLabel->SetControl(ret); currentLabel->SetControl(ret);
currentLabel->SetDepend(ret); currentLabel->SetDepend(ret);

View File

@ -36,7 +36,7 @@ namespace panda::ecmascript::kungfu {
V(COWArrayCheck, COW_ARRAY_CHECK, GateFlags::CHECKABLE, 1, 1, 1) \ V(COWArrayCheck, COW_ARRAY_CHECK, GateFlags::CHECKABLE, 1, 1, 1) \
V(ConvertHoleAsUndefined, CONVERT_HOLE_AS_UNDEFINED, GateFlags::NO_WRITE, 1, 1, 1) \ V(ConvertHoleAsUndefined, CONVERT_HOLE_AS_UNDEFINED, GateFlags::NO_WRITE, 1, 1, 1) \
V(EcmaStringCheck, ECMA_STRING_CHECK, GateFlags::CHECKABLE, 1, 1, 1) \ V(EcmaStringCheck, ECMA_STRING_CHECK, GateFlags::CHECKABLE, 1, 1, 1) \
V(FinishAllocate, FINISH_ALLOCATE, GateFlags::NONE_FLAG, 0, 1, 0) \ V(FinishAllocate, FINISH_ALLOCATE, GateFlags::NONE_FLAG, 0, 1, 1) \
V(FlattenTreeStringCheck, FLATTEN_TREE_STRING_CHECK, GateFlags::CHECKABLE, 1, 1, 1) \ V(FlattenTreeStringCheck, FLATTEN_TREE_STRING_CHECK, GateFlags::CHECKABLE, 1, 1, 1) \
V(HeapObjectCheck, HEAP_OBJECT_CHECK, GateFlags::CHECKABLE, 1, 1, 1) \ V(HeapObjectCheck, HEAP_OBJECT_CHECK, GateFlags::CHECKABLE, 1, 1, 1) \
V(ProtoChangeMarkerCheck, PROTO_CHANGE_MARKER_CHECK, GateFlags::CHECKABLE, 1, 1, 1) \ V(ProtoChangeMarkerCheck, PROTO_CHANGE_MARKER_CHECK, GateFlags::CHECKABLE, 1, 1, 1) \

View File

@ -175,8 +175,7 @@ GateRef NTypeHCRLowering::NewJSArrayLiteral(GateRef gate, GateRef elements, Gate
builder_.StoreConstOffset(VariableType::INT64(), array, JSArray::TRACK_INFO_OFFSET, builder_.Undefined()); builder_.StoreConstOffset(VariableType::INT64(), array, JSArray::TRACK_INFO_OFFSET, builder_.Undefined());
} }
builder_.StoreConstOffset(VariableType::JS_POINTER(), array, lengthAccessorOffset, accessor); builder_.StoreConstOffset(VariableType::JS_POINTER(), array, lengthAccessorOffset, accessor);
builder_.FinishAllocate(); return builder_.FinishAllocate(array);
return array;
} }
GateRef NTypeHCRLowering::NewTaggedArray(size_t length) GateRef NTypeHCRLowering::NewTaggedArray(size_t length)
@ -194,9 +193,7 @@ GateRef NTypeHCRLowering::NewTaggedArray(size_t length)
for (size_t offset = TaggedArray::DATA_OFFSET; offset < endOffset; offset += JSTaggedValue::TaggedTypeSize()) { for (size_t offset = TaggedArray::DATA_OFFSET; offset < endOffset; offset += JSTaggedValue::TaggedTypeSize()) {
builder_.StoreConstOffset(VariableType::INT64(), elements, offset, builder_.Hole()); builder_.StoreConstOffset(VariableType::INT64(), elements, offset, builder_.Hole());
} }
builder_.FinishAllocate(); return builder_.FinishAllocate(elements);
return elements;
} }
GateRef NTypeHCRLowering::LowerCallRuntime(GateRef glue, GateRef hirGate, int index, const std::vector<GateRef> &args, GateRef NTypeHCRLowering::LowerCallRuntime(GateRef glue, GateRef hirGate, int index, const std::vector<GateRef> &args,
@ -289,8 +286,7 @@ GateRef NTypeHCRLowering::NewTaggedArray(GateRef length)
builder_.Bind(&loopEnd); builder_.Bind(&loopEnd);
builder_.LoopEnd(&loopHead); builder_.LoopEnd(&loopHead);
builder_.Bind(&exit); builder_.Bind(&exit);
builder_.FinishAllocate(); auto ret = builder_.FinishAllocate(*array);
auto ret = *array;
builder_.SubCfgExit(); builder_.SubCfgExit();
return ret; return ret;
} }

View File

@ -2253,9 +2253,6 @@ void TypeBytecodeLowering::LowerCreateObjectWithBuffer(GateRef gate)
PGOTypeManager *ptManager = thread_->GetCurrentEcmaContext()->GetPTManager(); PGOTypeManager *ptManager = thread_->GetCurrentEcmaContext()->GetPTManager();
int hclassIndex = static_cast<int>(ptManager->GetHClassIndexByProfileType(type)); int hclassIndex = static_cast<int>(ptManager->GetHClassIndexByProfileType(type));
if (hclassIndex == -1) {
return;
}
ASSERT(acc_.GetNumValueIn(gate) == 2); // 2: number of value ins ASSERT(acc_.GetNumValueIn(gate) == 2); // 2: number of value ins
GateRef index = acc_.GetValueIn(gate, 0); GateRef index = acc_.GetValueIn(gate, 0);
auto imm = acc_.GetConstantValue(index); auto imm = acc_.GetConstantValue(index);
@ -2271,8 +2268,9 @@ void TypeBytecodeLowering::LowerCreateObjectWithBuffer(GateRef gate)
return; return;
} }
std::vector<uint64_t> inlinedProps; std::vector<uint64_t> inlinedProps;
JSHandle<JSHClass> newClass = JSHandle<JSHClass>(thread_, ptManager->QueryHClass(type.first, type.second));
JSHandle<JSHClass> oldClass = JSHandle<JSHClass>(thread_, objhandle->GetClass()); JSHandle<JSHClass> oldClass = JSHandle<JSHClass>(thread_, objhandle->GetClass());
JSHandle<JSHClass> newClass = hclassIndex == -1 ? oldClass :
JSHandle<JSHClass>(thread_, ptManager->QueryHClass(type.first, type.second));
if (oldClass->GetInlinedProperties() != newClass->GetInlinedProperties()) { if (oldClass->GetInlinedProperties() != newClass->GetInlinedProperties()) {
return; return;
} }
@ -2292,6 +2290,7 @@ void TypeBytecodeLowering::LowerCreateObjectWithBuffer(GateRef gate)
} }
} }
AddProfiling(gate);
GateRef jsFunc = argAcc_.GetFrameArgsIn(gate, FrameArgIdx::FUNC); GateRef jsFunc = argAcc_.GetFrameArgsIn(gate, FrameArgIdx::FUNC);
GateRef oldObj = builder_.GetObjectFromConstPool(glue_, gate, jsFunc, GateRef oldObj = builder_.GetObjectFromConstPool(glue_, gate, jsFunc,
builder_.TruncInt64ToInt32(index), ConstPoolType::OBJECT_LITERAL); builder_.TruncInt64ToInt32(index), ConstPoolType::OBJECT_LITERAL);
@ -2310,7 +2309,7 @@ void TypeBytecodeLowering::LowerCreateObjectWithBuffer(GateRef gate)
builder_.StoreConstOffset(VariableType::INT64(), newObj, newClass->GetInlinedPropertiesOffset(i), builder_.StoreConstOffset(VariableType::INT64(), newObj, newClass->GetInlinedPropertiesOffset(i),
builder_.Int64(inlinedProps.at(i))); builder_.Int64(inlinedProps.at(i)));
} }
builder_.FinishAllocate(); GateRef ret = builder_.FinishAllocate(newObj);
acc_.ReplaceHirAndDeleteIfException(gate, builder_.GetStateDepend(), newObj); acc_.ReplaceHirAndDeleteIfException(gate, builder_.GetStateDepend(), ret);
} }
} // namespace panda::ecmascript } // namespace panda::ecmascript

View File

@ -123,6 +123,7 @@ group("ark_aot_ts_test") {
"forin_non_empty_prototype", "forin_non_empty_prototype",
"forin_special_object", "forin_special_object",
"forloop", "forloop",
"framestatesalloc",
"framestatesasync", "framestatesasync",
"framestatesphi", "framestatesphi",
"generatormerge", "generatormerge",

View File

@ -0,0 +1,18 @@
# 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("framestatesalloc") {
deps = []
}

View File

@ -0,0 +1,13 @@
# 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.

View File

@ -0,0 +1,27 @@
/*
* 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.
*/
function foo() {
// framevalues should't handle object of unfinished allocation
return {
value: -0,
writable: false,
configurable: false
}
}
let obj = {}
Object.defineProperty(obj, "foo", foo());

View File

@ -1,3 +1,18 @@
/*
* 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.
*/
declare function print(arg:any):string; declare function print(arg:any):string;
class A { class A {
constructor() { constructor() {