fixed for CONST_DATA lowering

Signed-off-by: getingke <getingke@huawei.com>
Change-Id: I5873cb8a8bd3325e6ac51829f82447082a383dac
This commit is contained in:
getingke 2022-10-17 19:41:53 +08:00
parent 70f342a545
commit af750f011e
12 changed files with 298 additions and 203 deletions

View File

@ -581,7 +581,7 @@ BytecodeInfo BytecodeCircuitBuilder::GetBytecodeInfo(const uint8_t *pc)
}
case EcmaOpcode::LDA_STR_ID16: {
uint16_t stringId = READ_INST_16_0();
info.inputs.emplace_back(StringId(stringId));
info.inputs.emplace_back(ConstDataId(ConstDataIDType::StringIDType, stringId));
break;
}
case EcmaOpcode::LDA_V8: {
@ -860,28 +860,28 @@ BytecodeInfo BytecodeCircuitBuilder::GetBytecodeInfo(const uint8_t *pc)
case EcmaOpcode::DEFINEFUNC_IMM8_ID16_IMM8: {
uint16_t methodId = READ_INST_16_1();
uint16_t length = READ_INST_8_3();
info.inputs.emplace_back(MethodId(methodId));
info.inputs.emplace_back(Immediate(methodId));
info.inputs.emplace_back(Immediate(length));
break;
}
case EcmaOpcode::DEFINEFUNC_IMM16_ID16_IMM8: {
uint16_t methodId = READ_INST_16_2();
uint16_t length = READ_INST_8_4();
info.inputs.emplace_back(MethodId(methodId));
info.inputs.emplace_back(Immediate(methodId));
info.inputs.emplace_back(Immediate(length));
break;
}
case EcmaOpcode::DEFINEMETHOD_IMM8_ID16_IMM8: {
uint16_t methodId = READ_INST_16_1();
uint16_t length = READ_INST_8_3();
info.inputs.emplace_back(MethodId(methodId));
info.inputs.emplace_back(Immediate(methodId));
info.inputs.emplace_back(Immediate(length));
break;
}
case EcmaOpcode::DEFINEMETHOD_IMM16_ID16_IMM8: {
uint16_t methodId = READ_INST_16_2();
uint16_t length = READ_INST_8_4();
info.inputs.emplace_back(MethodId(methodId));
info.inputs.emplace_back(Immediate(methodId));
info.inputs.emplace_back(Immediate(length));
break;
}
@ -1022,28 +1022,28 @@ BytecodeInfo BytecodeCircuitBuilder::GetBytecodeInfo(const uint8_t *pc)
case EcmaOpcode::STOWNBYNAME_IMM8_ID16_V8: {
uint16_t stringId = READ_INST_16_1();
uint32_t v0 = READ_INST_8_3();
info.inputs.emplace_back(StringId(stringId));
info.inputs.emplace_back(ConstDataId(ConstDataIDType::StringIDType, stringId));
info.inputs.emplace_back(VirtualRegister(v0));
break;
}
case EcmaOpcode::STOWNBYNAME_IMM16_ID16_V8: {
uint16_t stringId = READ_INST_16_2();
uint32_t v0 = READ_INST_8_4();
info.inputs.emplace_back(StringId(stringId));
info.inputs.emplace_back(ConstDataId(ConstDataIDType::StringIDType, stringId));
info.inputs.emplace_back(VirtualRegister(v0));
break;
}
case EcmaOpcode::CREATEREGEXPWITHLITERAL_IMM8_ID16_IMM8: {
uint16_t stringId = READ_INST_16_1();
uint8_t flags = READ_INST_8_3();
info.inputs.emplace_back(StringId(stringId));
info.inputs.emplace_back(ConstDataId(ConstDataIDType::StringIDType, stringId));
info.inputs.emplace_back(Immediate(flags));
break;
}
case EcmaOpcode::CREATEREGEXPWITHLITERAL_IMM16_ID16_IMM8: {
uint16_t stringId = READ_INST_16_2();
uint8_t flags = READ_INST_8_4();
info.inputs.emplace_back(StringId(stringId));
info.inputs.emplace_back(ConstDataId(ConstDataIDType::StringIDType, stringId));
info.inputs.emplace_back(Immediate(flags));
break;
}
@ -1124,7 +1124,7 @@ BytecodeInfo BytecodeCircuitBuilder::GetBytecodeInfo(const uint8_t *pc)
}
case EcmaOpcode::STCONSTTOGLOBALRECORD_IMM16_ID16: {
uint16_t stringId = READ_INST_16_2();
info.inputs.emplace_back(StringId(stringId));
info.inputs.emplace_back(ConstDataId(ConstDataIDType::StringIDType, stringId));
break;
}
case EcmaOpcode::GETTEMPLATEOBJECT_IMM8:
@ -1295,27 +1295,27 @@ BytecodeInfo BytecodeCircuitBuilder::GetBytecodeInfo(const uint8_t *pc)
}
case EcmaOpcode::TRYLDGLOBALBYNAME_IMM8_ID16: {
uint16_t stringId = READ_INST_16_1();
info.inputs.emplace_back(StringId(stringId));
info.inputs.emplace_back(ConstDataId(ConstDataIDType::StringIDType, stringId));
break;
}
case EcmaOpcode::TRYLDGLOBALBYNAME_IMM16_ID16: {
uint16_t stringId = READ_INST_16_2();
info.inputs.emplace_back(StringId(stringId));
info.inputs.emplace_back(ConstDataId(ConstDataIDType::StringIDType, stringId));
break;
}
case EcmaOpcode::TRYSTGLOBALBYNAME_IMM8_ID16: {
uint16_t stringId = READ_INST_16_1();
info.inputs.emplace_back(StringId(stringId));
info.inputs.emplace_back(ConstDataId(ConstDataIDType::StringIDType, stringId));
break;
}
case EcmaOpcode::TRYSTGLOBALBYNAME_IMM16_ID16: {
uint16_t stringId = READ_INST_16_2();
info.inputs.emplace_back(StringId(stringId));
info.inputs.emplace_back(ConstDataId(ConstDataIDType::StringIDType, stringId));
break;
}
case EcmaOpcode::STTOGLOBALRECORD_IMM16_ID16: {
uint16_t stringId = READ_INST_16_2();
info.inputs.emplace_back(StringId(stringId));
info.inputs.emplace_back(ConstDataId(ConstDataIDType::StringIDType, stringId));
break;
}
case EcmaOpcode::STOWNBYVALUEWITHNAMESET_IMM8_V8_V8: {
@ -1335,14 +1335,14 @@ BytecodeInfo BytecodeCircuitBuilder::GetBytecodeInfo(const uint8_t *pc)
case EcmaOpcode::STOWNBYNAMEWITHNAMESET_IMM8_ID16_V8: {
uint16_t stringId = READ_INST_16_1();
uint32_t v0 = READ_INST_8_3();
info.inputs.emplace_back(StringId(stringId));
info.inputs.emplace_back(ConstDataId(ConstDataIDType::StringIDType, stringId));
info.inputs.emplace_back(VirtualRegister(v0));
break;
}
case EcmaOpcode::STOWNBYNAMEWITHNAMESET_IMM16_ID16_V8: {
uint16_t stringId = READ_INST_16_2();
uint32_t v0 = READ_INST_8_4();
info.inputs.emplace_back(StringId(stringId));
info.inputs.emplace_back(ConstDataId(ConstDataIDType::StringIDType, stringId));
info.inputs.emplace_back(VirtualRegister(v0));
break;
}
@ -1390,71 +1390,71 @@ BytecodeInfo BytecodeCircuitBuilder::GetBytecodeInfo(const uint8_t *pc)
case EcmaOpcode::LDTHISBYNAME_IMM8_ID16:
case EcmaOpcode::LDTHISBYNAME_IMM16_ID16: {
uint16_t stringId = READ_INST_16_2();
info.inputs.emplace_back(StringId(stringId));
info.inputs.emplace_back(ConstDataId(ConstDataIDType::StringIDType, stringId));
break;
}
case EcmaOpcode::STTHISBYNAME_IMM8_ID16:
case EcmaOpcode::STTHISBYNAME_IMM16_ID16: {
uint16_t stringId = READ_INST_16_2();
info.inputs.emplace_back(StringId(stringId));
info.inputs.emplace_back(ConstDataId(ConstDataIDType::StringIDType, stringId));
break;
}
case EcmaOpcode::LDGLOBALVAR_IMM16_ID16: {
uint16_t stringId = READ_INST_16_2();
info.inputs.emplace_back(StringId(stringId));
info.inputs.emplace_back(ConstDataId(ConstDataIDType::StringIDType, stringId));
break;
}
case EcmaOpcode::LDOBJBYNAME_IMM8_ID16: {
uint16_t stringId = READ_INST_16_1();
info.inputs.emplace_back(StringId(stringId));
info.inputs.emplace_back(ConstDataId(ConstDataIDType::StringIDType, stringId));
break;
}
case EcmaOpcode::LDOBJBYNAME_IMM16_ID16: {
uint16_t stringId = READ_INST_16_2();
info.inputs.emplace_back(StringId(stringId));
info.inputs.emplace_back(ConstDataId(ConstDataIDType::StringIDType, stringId));
break;
}
case EcmaOpcode::STOBJBYNAME_IMM8_ID16_V8: {
uint16_t stringId = READ_INST_16_1();
uint32_t v0 = READ_INST_8_3();
info.inputs.emplace_back(StringId(stringId));
info.inputs.emplace_back(ConstDataId(ConstDataIDType::StringIDType, stringId));
info.inputs.emplace_back(VirtualRegister(v0));
break;
}
case EcmaOpcode::STOBJBYNAME_IMM16_ID16_V8: {
uint16_t stringId = READ_INST_16_2();
uint32_t v0 = READ_INST_8_4();
info.inputs.emplace_back(StringId(stringId));
info.inputs.emplace_back(ConstDataId(ConstDataIDType::StringIDType, stringId));
info.inputs.emplace_back(VirtualRegister(v0));
break;
}
case EcmaOpcode::LDSUPERBYNAME_IMM8_ID16: {
uint16_t stringId = READ_INST_16_1();
info.inputs.emplace_back(StringId(stringId));
info.inputs.emplace_back(ConstDataId(ConstDataIDType::StringIDType, stringId));
break;
}
case EcmaOpcode::LDSUPERBYNAME_IMM16_ID16: {
uint16_t stringId = READ_INST_16_2();
info.inputs.emplace_back(StringId(stringId));
info.inputs.emplace_back(ConstDataId(ConstDataIDType::StringIDType, stringId));
break;
}
case EcmaOpcode::STSUPERBYNAME_IMM8_ID16_V8: {
uint16_t stringId = READ_INST_16_1();
uint32_t v0 = READ_INST_8_3();
info.inputs.emplace_back(StringId(stringId));
info.inputs.emplace_back(ConstDataId(ConstDataIDType::StringIDType, stringId));
info.inputs.emplace_back(VirtualRegister(v0));
break;
}
case EcmaOpcode::STSUPERBYNAME_IMM16_ID16_V8: {
uint16_t stringId = READ_INST_16_2();
uint32_t v0 = READ_INST_8_4();
info.inputs.emplace_back(StringId(stringId));
info.inputs.emplace_back(ConstDataId(ConstDataIDType::StringIDType, stringId));
info.inputs.emplace_back(VirtualRegister(v0));
break;
}
case EcmaOpcode::STGLOBALVAR_IMM16_ID16: {
uint32_t stringId = READ_INST_16_2();
info.inputs.emplace_back(StringId(stringId));
info.inputs.emplace_back(ConstDataId(ConstDataIDType::StringIDType, stringId));
break;
}
case EcmaOpcode::CREATEGENERATOROBJ_V8: {
@ -1493,7 +1493,7 @@ BytecodeInfo BytecodeCircuitBuilder::GetBytecodeInfo(const uint8_t *pc)
uint16_t literaId = READ_INST_16_3();
uint16_t length = READ_INST_16_5();
uint16_t v0 = READ_INST_8_7();
info.inputs.emplace_back(MethodId(methodId));
info.inputs.emplace_back(Immediate(methodId));
info.inputs.emplace_back(Immediate(literaId));
info.inputs.emplace_back(Immediate(length));
info.inputs.emplace_back(VirtualRegister(v0));
@ -1504,7 +1504,7 @@ BytecodeInfo BytecodeCircuitBuilder::GetBytecodeInfo(const uint8_t *pc)
uint16_t literaId = READ_INST_16_4();
uint16_t length = READ_INST_16_6();
uint16_t v0 = READ_INST_8_8();
info.inputs.emplace_back(MethodId(methodId));
info.inputs.emplace_back(Immediate(methodId));
info.inputs.emplace_back(Immediate(literaId));
info.inputs.emplace_back(Immediate(length));
info.inputs.emplace_back(VirtualRegister(v0));
@ -1515,7 +1515,7 @@ BytecodeInfo BytecodeCircuitBuilder::GetBytecodeInfo(const uint8_t *pc)
}
case EcmaOpcode::LDBIGINT_ID16: {
uint32_t stringId = READ_INST_16_0();
info.inputs.emplace_back(StringId(stringId));
info.inputs.emplace_back(ConstDataId(ConstDataIDType::StringIDType, stringId));
break;
}
case EcmaOpcode::DYNAMICIMPORT: {
@ -1898,15 +1898,12 @@ std::vector<GateRef> BytecodeCircuitBuilder::CreateGateInList(const BytecodeInfo
std::vector<GateRef> inList(length + numValueInputs + numBCOffsetInput, Circuit::NullGate());
for (size_t i = 0; i < info.inputs.size(); i++) {
const auto &input = info.inputs[i];
if (std::holds_alternative<MethodId>(input)) {
inList[i + length] = circuit_.GetConstantGate(MachineType::I16,
std::get<MethodId>(input).GetId(),
GateType::NJSValue());
} else if (std::holds_alternative<StringId>(input)) {
tsManager_->AddStringIndex(std::get<StringId>(input).GetId());
inList[i + length] = circuit_.GetConstantGate(MachineType::I16,
std::get<StringId>(input).GetId(),
GateType::NJSValue());
if (std::holds_alternative<ConstDataId>(input)) {
if (std::get<ConstDataId>(input).IsStringId()) {
tsManager_->AddStringIndex(std::get<ConstDataId>(input).GetId());
}
inList[i + length] = circuit_.GetConstantDataGate(std::get<ConstDataId>(input).CaculateBitField(),
GateType::StringType());
} else if (std::holds_alternative<Immediate>(input)) {
inList[i + length] = circuit_.GetConstantGate(MachineType::I64,
std::get<Immediate>(input).GetValue(),
@ -2001,6 +1998,14 @@ GateRef BytecodeCircuitBuilder::NewConst(const BytecodeInfo &info)
case EcmaOpcode::LDTHIS:
gate = argAcc_.GetCommonArgGate(CommonArgIdx::THIS_OBJECT);
break;
case EcmaOpcode::LDA_STR_ID16: {
auto input = std::get<ConstDataId>(info.inputs.at(0));
if (input.IsStringId()) {
tsManager_->AddStringIndex(input.GetId());
}
gate = circuit_.GetConstantDataGate(input.CaculateBitField(), GateType::StringType());
break;
}
default:
UNREACHABLE();
}
@ -2517,7 +2522,7 @@ void BytecodeCircuitBuilder::BuildCircuit()
if (it == jsgateToBytecode_.cend()) {
continue;
}
if (gateAcc_.GetOpCode(gate) == OpCode::CONSTANT) {
if (gateAcc_.GetOpCode(gate) == OpCode::CONSTANT || gateAcc_.GetOpCode(gate) == OpCode::CONST_DATA) {
continue;
}
const auto &[id, pc] = it->second;

View File

@ -35,10 +35,16 @@
namespace panda::ecmascript::kungfu {
using VRegIDType = uint32_t;
using ImmValueType = uint64_t;
using StringIdType = uint16_t;
using MethodIdType = uint16_t;
using EcmaOpcode = BytecodeInstruction::Opcode;
enum class ConstDataIDType : uint8_t {
StringIDType,
MethodIDType,
ArrayLiteralIDType,
ObjectLiteralIDType,
ClassLiteralIDType,
};
class VirtualRegister {
public:
explicit VirtualRegister(VRegIDType id) : id_(id)
@ -91,46 +97,65 @@ private:
ImmValueType value_;
};
class StringId {
class ConstDataId {
public:
explicit StringId(StringIdType id) : id_(id)
explicit ConstDataId(ConstDataIDType type, uint16_t id)
:type_(type), id_(id)
{
}
~StringId() = default;
void SetId(StringIdType id)
explicit ConstDataId(BitField bitfield)
{
type_ = ConstDataIDType(bitfield >> TYPE_SHIFT);
id_ = bitfield & ((1 << TYPE_SHIFT) - 1);
}
~ConstDataId() = default;
void SetId(uint16_t id)
{
id_ = id;
}
StringIdType GetId() const
uint16_t GetId() const
{
return id_;
}
private:
StringIdType id_;
};
class MethodId {
public:
explicit MethodId(MethodIdType id) : id_(id)
void SetType(ConstDataIDType type)
{
}
~MethodId() = default;
void SetId(MethodIdType id)
{
id_ = id;
type_ = type;
}
MethodIdType GetId() const
ConstDataIDType GetType() const
{
return id_;
return type_;
}
bool IsStringId() const
{
return type_ == ConstDataIDType::StringIDType;
}
bool IsMethodId() const
{
return type_ == ConstDataIDType::MethodIDType;
}
bool IsClassLiteraId() const
{
return type_ == ConstDataIDType::ClassLiteralIDType;
}
BitField CaculateBitField() const
{
return (static_cast<uint8_t>(type_) << TYPE_SHIFT) | id_;
}
private:
MethodIdType id_;
static constexpr int TYPE_SHIFT = 16;
ConstDataIDType type_;
uint16_t id_;
};
enum class SplitKind : uint8_t {
@ -255,7 +280,7 @@ using BytecodeGraph = std::vector<BytecodeRegion>;
struct BytecodeInfo {
// set of id, immediate and read register
std::vector<std::variant<StringId, MethodId, Immediate, VirtualRegister>> inputs {};
std::vector<std::variant<ConstDataId, Immediate, VirtualRegister>> inputs {};
std::vector<VRegIDType> vregOut {}; // write register
bool accIn {false}; // read acc
bool accOut {false}; // write acc
@ -375,6 +400,7 @@ struct BytecodeInfo {
case EcmaOpcode::LDAI_IMM32:
case EcmaOpcode::FLDAI_IMM64:
case EcmaOpcode::LDFUNCTION:
case EcmaOpcode::LDA_STR_ID16:
return true;
default:
return false;

View File

@ -456,6 +456,18 @@ GateRef Circuit::GetConstantGate(MachineType bitValue, BitField bitfield,
return gate;
}
GateRef Circuit::GetConstantDataGate(BitField bitfield, GateType type)
{
auto search = constantDataCache_.find(bitfield);
if (search != constantDataCache_.end()) {
return constantDataCache_.at(bitfield);
}
auto gate = NewGate(OpCode(OpCode::CONST_DATA), bitfield,
{GetCircuitRoot(OpCode(OpCode::CONSTANT_LIST))}, type);
constantDataCache_[bitfield] = gate;
return gate;
}
size_t Circuit::GetGateCount() const
{
return gateCount_;

View File

@ -56,6 +56,7 @@ public:
panda::ecmascript::FrameType GetFrameType() const;
void SetFrameType(panda::ecmascript::FrameType type);
GateRef GetConstantGate(MachineType bitValue, BitField bitfield, GateType type);
GateRef GetConstantDataGate(BitField index, GateType type);
size_t GetGateCount() const;
TimeStamp GetTime() const;
void AdvanceTime() const;
@ -116,6 +117,7 @@ private:
TimeStamp time_;
std::vector<uint8_t> dataSection_ {};
std::map<std::tuple<MachineType, BitField, GateType>, GateRef> constantCache_ {};
std::map<BitField, GateRef> constantDataCache_ {};
panda::ecmascript::FrameType frameType_ {panda::ecmascript::FrameType::OPTIMIZED_FRAME};
bool isArch64_ {false};

View File

@ -45,6 +45,8 @@ void SlowPathLowering::CallRuntimeLowering()
// initialize label manager
Environment env(gate, circuit_, &builder_);
LowerExceptionHandler(gate);
} else if (op == OpCode::CONST_DATA) {
LowerConstPoolData(gate);
}
}
@ -243,6 +245,12 @@ GateRef SlowPathLowering::GetConstPool(GateRef jsFunc)
}
// labelmanager must be initialized
GateRef SlowPathLowering::LoadObjectFromConstPool(GateRef jsFunc, GateRef index)
{
GateRef constPool = GetConstPool(jsFunc);
return GetValueFromTaggedArray(constPool, index);
}
GateRef SlowPathLowering::GetObjectFromConstPool(GateRef jsFunc, GateRef index)
{
GateRef constPool = GetConstPool(jsFunc);
@ -308,7 +316,7 @@ void SlowPathLowering::Lower(GateRef gate)
Environment env(gate, circuit_, &builder_);
switch (op) {
case EcmaOpcode::LDA_STR_ID16:
LowerLoadStr(gate, glue, jsFunc);
// LowerLoadStr(gate, glue, jsFunc);
break;
case EcmaOpcode::CALLARG0_IMM8:
LowerCallArg0(gate, glue);
@ -424,10 +432,10 @@ void SlowPathLowering::Lower(GateRef gate)
break;
case EcmaOpcode::TRYLDGLOBALBYNAME_IMM8_ID16:
case EcmaOpcode::TRYLDGLOBALBYNAME_IMM16_ID16:
LowerTryLdGlobalByName(gate, glue, jsFunc);
LowerTryLdGlobalByName(gate, glue);
break;
case EcmaOpcode::STGLOBALVAR_IMM16_ID16:
LowerStGlobalVar(gate, glue, jsFunc);
LowerStGlobalVar(gate, glue);
break;
case EcmaOpcode::GETITERATOR_IMM8:
case EcmaOpcode::GETITERATOR_IMM16:
@ -549,7 +557,7 @@ void SlowPathLowering::Lower(GateRef gate)
LowerSetObjectWithProto(gate, glue);
break;
case EcmaOpcode::LDBIGINT_ID16:
LowerLdBigInt(gate, glue, jsFunc);
LowerLdBigInt(gate, glue);
break;
case EcmaOpcode::TONUMERIC_IMM8:
LowerToNumeric(gate, glue);
@ -609,7 +617,7 @@ void SlowPathLowering::Lower(GateRef gate)
break;
case EcmaOpcode::CREATEREGEXPWITHLITERAL_IMM8_ID16_IMM8:
case EcmaOpcode::CREATEREGEXPWITHLITERAL_IMM16_ID16_IMM8:
LowerCreateRegExpWithLiteral(gate, glue, jsFunc);
LowerCreateRegExpWithLiteral(gate, glue);
break;
case EcmaOpcode::STOWNBYVALUE_IMM8_V8_V8:
case EcmaOpcode::STOWNBYVALUE_IMM16_V8_V8:
@ -622,7 +630,7 @@ void SlowPathLowering::Lower(GateRef gate)
break;
case EcmaOpcode::STOWNBYNAME_IMM8_ID16_V8:
case EcmaOpcode::STOWNBYNAME_IMM16_ID16_V8:
LowerStOwnByName(gate, glue, jsFunc);
LowerStOwnByName(gate, glue);
break;
case EcmaOpcode::NEWLEXENV_IMM8:
case EcmaOpcode::WIDE_NEWLEXENV_PREF_IMM16:
@ -644,13 +652,13 @@ void SlowPathLowering::Lower(GateRef gate)
break;
case EcmaOpcode::TRYSTGLOBALBYNAME_IMM8_ID16:
case EcmaOpcode::TRYSTGLOBALBYNAME_IMM16_ID16:
LowerTryStGlobalByName(gate, glue, jsFunc);
LowerTryStGlobalByName(gate, glue);
break;
case EcmaOpcode::STCONSTTOGLOBALRECORD_IMM16_ID16:
LowerStConstToGlobalRecord(gate, glue, jsFunc, true);
LowerStConstToGlobalRecord(gate, glue, true);
break;
case EcmaOpcode::STTOGLOBALRECORD_IMM16_ID16:
LowerStConstToGlobalRecord(gate, glue, jsFunc, false);
LowerStConstToGlobalRecord(gate, glue, false);
break;
case EcmaOpcode::STOWNBYVALUEWITHNAMESET_IMM8_V8_V8:
case EcmaOpcode::STOWNBYVALUEWITHNAMESET_IMM16_V8_V8:
@ -658,18 +666,18 @@ void SlowPathLowering::Lower(GateRef gate)
break;
case EcmaOpcode::STOWNBYNAMEWITHNAMESET_IMM8_ID16_V8:
case EcmaOpcode::STOWNBYNAMEWITHNAMESET_IMM16_ID16_V8:
LowerStOwnByNameWithNameSet(gate, glue, jsFunc);
LowerStOwnByNameWithNameSet(gate, glue);
break;
case EcmaOpcode::LDGLOBALVAR_IMM16_ID16:
LowerLdGlobalVar(gate, glue, jsFunc);
LowerLdGlobalVar(gate, glue);
break;
case EcmaOpcode::LDOBJBYNAME_IMM8_ID16:
case EcmaOpcode::LDOBJBYNAME_IMM16_ID16:
LowerLdObjByName(gate, glue, jsFunc);
LowerLdObjByName(gate, glue);
break;
case EcmaOpcode::STOBJBYNAME_IMM8_ID16_V8:
case EcmaOpcode::STOBJBYNAME_IMM16_ID16_V8:
LowerStObjByName(gate, glue, jsFunc, thisObj);
LowerStObjByName(gate, glue, thisObj);
break;
case EcmaOpcode::DEFINEGETTERSETTERBYVALUE_V8_V8_V8_V8:
LowerDefineGetterSetterByValue(gate, glue);
@ -787,11 +795,11 @@ void SlowPathLowering::Lower(GateRef gate)
break;
case EcmaOpcode::LDTHISBYNAME_IMM8_ID16:
case EcmaOpcode::LDTHISBYNAME_IMM16_ID16:
LowerLdThisByName(gate, glue, jsFunc, thisObj);
LowerLdThisByName(gate, glue, thisObj);
break;
case EcmaOpcode::STTHISBYNAME_IMM8_ID16:
case EcmaOpcode::STTHISBYNAME_IMM16_ID16:
LowerStObjByName(gate, glue, jsFunc, thisObj, true);
LowerStObjByName(gate, glue, thisObj, true);
break;
default:
break;
@ -964,12 +972,11 @@ void SlowPathLowering::LowerLoadStr(GateRef gate, GateRef glue, GateRef jsFunc)
ReplaceHirToSubCfg(gate, newGate, successControl, failControl);
}
void SlowPathLowering::LowerTryLdGlobalByName(GateRef gate, GateRef glue, GateRef jsFunc)
void SlowPathLowering::LowerTryLdGlobalByName(GateRef gate, GateRef glue)
{
DebugPrintBC(gate, glue);
DEFVAlUE(result, (&builder_), VariableType::JS_ANY(), acc_.GetValueIn(gate, 0));
GateRef prop = GetObjectFromConstPool(glue, jsFunc, builder_.ZExtInt16ToInt32(acc_.GetValueIn(gate, 0)),
ConstPoolType::STRING);
DEFVAlUE(result, (&builder_), VariableType::JS_ANY(), builder_.Undefined());
GateRef prop = acc_.GetValueIn(gate, 0);
GateRef recordResult = LowerCallRuntime(glue, RTSTUB_ID(LdGlobalRecord), {prop}, true);
Label isFound(&builder_);
Label isNotFound(&builder_);
@ -1003,13 +1010,12 @@ void SlowPathLowering::LowerTryLdGlobalByName(GateRef gate, GateRef glue, GateRe
ReplaceHirToSubCfg(gate, value, successControl, failControl);
}
void SlowPathLowering::LowerStGlobalVar(GateRef gate, GateRef glue, GateRef jsFunc)
void SlowPathLowering::LowerStGlobalVar(GateRef gate, GateRef glue)
{
DebugPrintBC(gate, glue);
Label successExit(&builder_);
Label exceptionExit(&builder_);
GateRef prop = GetObjectFromConstPool(glue, jsFunc, builder_.ZExtInt16ToInt32(acc_.GetValueIn(gate, 0)),
ConstPoolType::STRING);
GateRef prop = acc_.GetValueIn(gate, 0);
const int id = RTSTUB_ID(StGlobalVar);
ASSERT(acc_.GetNumValueIn(gate) == 2); // 2: number of value inputs
GateRef newGate = LowerCallRuntime(glue, id, {prop, acc_.GetValueIn(gate, 1)}, true);
@ -1863,15 +1869,14 @@ void SlowPathLowering::LowerSetObjectWithProto(GateRef gate, GateRef glue)
ReplaceHirToCall(gate, newGate);
}
void SlowPathLowering::LowerLdBigInt(GateRef gate, GateRef glue, GateRef jsFunc)
void SlowPathLowering::LowerLdBigInt(GateRef gate, GateRef glue)
{
DebugPrintBC(gate, glue);
Label successExit(&builder_);
Label exceptionExit(&builder_);
// 1: number of value inputs
ASSERT(acc_.GetNumValueIn(gate) == 1);
GateRef numberBigInt = GetObjectFromConstPool(glue, jsFunc, builder_.ZExtInt16ToInt32(acc_.GetValueIn(gate, 0)),
ConstPoolType::STRING);
GateRef numberBigInt = acc_.GetValueIn(gate, 0);
GateRef result = LowerCallRuntime(glue, RTSTUB_ID(LdBigInt), {numberBigInt}, true);
builder_.Branch(builder_.IsSpecial(result, JSTaggedValue::VALUE_EXCEPTION),
&exceptionExit, &successExit);
@ -2133,7 +2138,7 @@ void SlowPathLowering::LowerCreateObjectWithExcludedKeys(GateRef gate, GateRef g
ReplaceHirToCall(gate, newGate);
}
void SlowPathLowering::LowerCreateRegExpWithLiteral(GateRef gate, GateRef glue, GateRef jsFunc)
void SlowPathLowering::LowerCreateRegExpWithLiteral(GateRef gate, GateRef glue)
{
DebugPrintBC(gate, glue);
Label successExit(&builder_);
@ -2141,8 +2146,7 @@ void SlowPathLowering::LowerCreateRegExpWithLiteral(GateRef gate, GateRef glue,
const int id = RTSTUB_ID(CreateRegExpWithLiteral);
// 2: number of value inputs
ASSERT(acc_.GetNumValueIn(gate) == 2);
GateRef pattern = GetObjectFromConstPool(glue, jsFunc, builder_.ZExtInt16ToInt32(acc_.GetValueIn(gate, 0)),
ConstPoolType::STRING);
GateRef pattern = acc_.GetValueIn(gate, 0);
GateRef flags = acc_.GetValueIn(gate, 1);
GateRef newGate = LowerCallRuntime(glue, id, { pattern, builder_.ToTaggedInt(flags) }, true);
builder_.Branch(builder_.IsSpecial(newGate, JSTaggedValue::VALUE_EXCEPTION), &exceptionExit, &successExit);
@ -2235,13 +2239,12 @@ void SlowPathLowering::LowerStOwnByIndex(GateRef gate, GateRef glue)
ReplaceHirToSubCfg(gate, Circuit::NullGate(), successControl, failControl);
}
void SlowPathLowering::LowerStOwnByName(GateRef gate, GateRef glue, GateRef jsFunc)
void SlowPathLowering::LowerStOwnByName(GateRef gate, GateRef glue)
{
DebugPrintBC(gate, glue);
// 3: number of value inputs
ASSERT(acc_.GetNumValueIn(gate) == 3);
GateRef propKey = GetObjectFromConstPool(glue, jsFunc, builder_.ZExtInt16ToInt32(acc_.GetValueIn(gate, 0)),
ConstPoolType::STRING);
GateRef propKey = acc_.GetValueIn(gate, 0);
GateRef receiver = acc_.GetValueIn(gate, 1);
GateRef accValue = acc_.GetValueIn(gate, 2);
// we do not need to merge outValueGate, so using GateRef directly instead of using Variable
@ -2351,15 +2354,14 @@ void SlowPathLowering::LowerStSuperByValue(GateRef gate, GateRef glue, GateRef j
ReplaceHirToCall(gate, newGate);
}
void SlowPathLowering::LowerTryStGlobalByName(GateRef gate, GateRef glue, GateRef jsFunc)
void SlowPathLowering::LowerTryStGlobalByName(GateRef gate, GateRef glue)
{
DebugPrintBC(gate, glue);
// order: 1. global record 2. global object
DEFVAlUE(res, (&builder_), VariableType::JS_ANY(), builder_.HoleConstant());
// 2 : number of value inputs
ASSERT(acc_.GetNumValueIn(gate) == 2);
GateRef propKey = GetObjectFromConstPool(glue, jsFunc, builder_.ZExtInt16ToInt32(acc_.GetValueIn(gate, 0)),
ConstPoolType::STRING);
GateRef propKey = acc_.GetValueIn(gate, 0);
Label isUndefined(&builder_);
Label notUndefined(&builder_);
Label successExit(&builder_);
@ -2399,13 +2401,12 @@ void SlowPathLowering::LowerTryStGlobalByName(GateRef gate, GateRef glue, GateRe
ReplaceHirToSubCfg(gate, Circuit::NullGate(), successControl, failControl);
}
void SlowPathLowering::LowerStConstToGlobalRecord(GateRef gate, GateRef glue, GateRef jsFunc, bool isConst)
void SlowPathLowering::LowerStConstToGlobalRecord(GateRef gate, GateRef glue, bool isConst)
{
DebugPrintBC(gate, glue);
Label successExit(&builder_);
Label exceptionExit(&builder_);
GateRef propKey = GetObjectFromConstPool(glue, jsFunc, builder_.SExtInt16ToInt32(acc_.GetValueIn(gate, 0)),
ConstPoolType::STRING);
GateRef propKey = acc_.GetValueIn(gate, 0);
acc_.SetDep(gate, propKey);
// 2 : number of value inputs
ASSERT(acc_.GetNumValueIn(gate) == 2);
@ -2469,13 +2470,12 @@ void SlowPathLowering::LowerStOwnByValueWithNameSet(GateRef gate, GateRef glue)
ReplaceHirToSubCfg(gate, Circuit::NullGate(), successControl, failControl);
}
void SlowPathLowering::LowerStOwnByNameWithNameSet(GateRef gate, GateRef glue, GateRef jsFunc)
void SlowPathLowering::LowerStOwnByNameWithNameSet(GateRef gate, GateRef glue)
{
DebugPrintBC(gate, glue);
// 3: number of value inputs
ASSERT(acc_.GetNumValueIn(gate) == 3);
GateRef propKey = GetObjectFromConstPool(glue, jsFunc, builder_.ZExtInt16ToInt32(acc_.GetValueIn(gate, 0)),
ConstPoolType::STRING);
GateRef propKey = acc_.GetValueIn(gate, 0);
GateRef receiver = acc_.GetValueIn(gate, 1);
GateRef accValue = acc_.GetValueIn(gate, 2);
GateRef result;
@ -2521,7 +2521,7 @@ void SlowPathLowering::LowerStOwnByNameWithNameSet(GateRef gate, GateRef glue, G
ReplaceHirToSubCfg(gate, Circuit::NullGate(), successControl, failControl);
}
void SlowPathLowering::LowerLdGlobalVar(GateRef gate, GateRef glue, GateRef jsFunc)
void SlowPathLowering::LowerLdGlobalVar(GateRef gate, GateRef glue)
{
DebugPrintBC(gate, glue);
std::vector<GateRef> successControl;
@ -2532,8 +2532,7 @@ void SlowPathLowering::LowerLdGlobalVar(GateRef gate, GateRef glue, GateRef jsFu
GateRef ret;
DEFVAlUE(result, (&builder_), VariableType::JS_ANY(), builder_.Undefined());
ASSERT(acc_.GetNumValueIn(gate) == 1);
GateRef propKey = GetObjectFromConstPool(glue, jsFunc, builder_.ZExtInt16ToInt32(acc_.GetValueIn(gate, 0)),
ConstPoolType::STRING);
GateRef propKey = acc_.GetValueIn(gate, 0);
GateRef globalObject = builder_.GetGlobalObject(glue);
result = LowerCallRuntime(glue, RTSTUB_ID(GetGlobalOwnProperty), { propKey }, true);
builder_.Branch(builder_.IsSpecial(*result, JSTaggedValue::VALUE_HOLE),
@ -2558,7 +2557,7 @@ void SlowPathLowering::LowerLdGlobalVar(GateRef gate, GateRef glue, GateRef jsFu
ReplaceHirToSubCfg(gate, ret, successControl, failControl);
}
void SlowPathLowering::LowerLdObjByName(GateRef gate, GateRef glue, GateRef jsFunc)
void SlowPathLowering::LowerLdObjByName(GateRef gate, GateRef glue)
{
DebugPrintBC(gate, glue);
std::vector<GateRef> successControl;
@ -2573,8 +2572,7 @@ void SlowPathLowering::LowerLdObjByName(GateRef gate, GateRef glue, GateRef jsFu
// 2: number of value inputs
ASSERT(acc_.GetNumValueIn(gate) == 2);
GateRef receiver = acc_.GetValueIn(gate, 1);
GateRef prop = GetObjectFromConstPool(glue, jsFunc, builder_.ZExtInt16ToInt32(acc_.GetValueIn(gate, 0)),
ConstPoolType::STRING);
GateRef prop = acc_.GetValueIn(gate, 0);
builder_.Branch(builder_.TaggedIsHeapObject(receiver), &receiverIsHeapObject, &slowPath);
builder_.Bind(&receiverIsHeapObject);
{
@ -2608,15 +2606,14 @@ void SlowPathLowering::LowerLdObjByName(GateRef gate, GateRef glue, GateRef jsFu
ReplaceHirToSubCfg(gate, result, successControl, failControl);
}
void SlowPathLowering::LowerStObjByName(GateRef gate, GateRef glue, GateRef jsFunc, GateRef thisObj, bool isThis)
void SlowPathLowering::LowerStObjByName(GateRef gate, GateRef glue, GateRef thisObj, bool isThis)
{
DebugPrintBC(gate, glue);
Label receiverIsHeapObject(&builder_);
Label slowPath(&builder_);
Label successExit(&builder_);
Label exceptionExit(&builder_);
GateRef prop = GetObjectFromConstPool(glue, jsFunc, builder_.ZExtInt16ToInt32(acc_.GetValueIn(gate, 0)),
ConstPoolType::STRING);
GateRef prop = acc_.GetValueIn(gate, 0);
GateRef receiver;
GateRef value;
if (isThis) {
@ -2868,8 +2865,7 @@ void SlowPathLowering::LowerLdSuperByName(GateRef gate, GateRef glue, GateRef js
Label exceptionExit(&builder_);
// 2: number of value inputs
ASSERT(acc_.GetNumValueIn(gate) == 2);
GateRef prop = GetObjectFromConstPool(glue, jsFunc, builder_.ZExtInt16ToInt32(acc_.GetValueIn(gate, 0)),
ConstPoolType::STRING);
GateRef prop = acc_.GetValueIn(gate, 0);
GateRef result =
LowerCallRuntime(glue, RTSTUB_ID(OptLdSuperByValue), {acc_.GetValueIn(gate, 1), prop, jsFunc}, true);
builder_.Branch(builder_.IsSpecial(result, JSTaggedValue::VALUE_EXCEPTION),
@ -2885,8 +2881,7 @@ void SlowPathLowering::LowerStSuperByName(GateRef gate, GateRef glue, GateRef js
Label exceptionExit(&builder_);
// 3: number of value inputs
ASSERT(acc_.GetNumValueIn(gate) == 3);
GateRef prop = GetObjectFromConstPool(glue, jsFunc, builder_.ZExtInt16ToInt32(acc_.GetValueIn(gate, 0)),
ConstPoolType::STRING);
GateRef prop = acc_.GetValueIn(gate, 0);
auto args2 = { acc_.GetValueIn(gate, 1), prop, acc_.GetValueIn(gate, 2), jsFunc };
GateRef result = LowerCallRuntime(glue, RTSTUB_ID(OptStSuperByValue), args2, true);
builder_.Branch(builder_.IsSpecial(result, JSTaggedValue::VALUE_EXCEPTION),
@ -3027,7 +3022,7 @@ void SlowPathLowering::LowerDefineClassWithBuffer(GateRef gate, GateRef glue, Ga
// 4: number of value inputs
ASSERT(acc_.GetNumValueIn(gate) == 4);
GateRef methodId = builder_.SExtInt16ToInt64(acc_.GetValueIn(gate, 0));
GateRef methodId = acc_.GetValueIn(gate, 0);
GateRef proto = acc_.GetValueIn(gate, 3);
GateRef literalId = acc_.GetValueIn(gate, 1);
GateRef length = acc_.GetValueIn(gate, 2); // 2: second arg
@ -3080,10 +3075,10 @@ void SlowPathLowering::LowerDefineClassWithBuffer(GateRef gate, GateRef glue, Ga
void SlowPathLowering::LowerDefineFunc(GateRef gate, GateRef glue, GateRef jsFunc)
{
DebugPrintBC(gate, glue);
GateRef methodId = acc_.GetValueIn(gate, 0);
GateRef methodId = builder_.TruncInt64ToInt32(acc_.GetValueIn(gate, 0));
GateRef length = acc_.GetValueIn(gate, 1);
DEFVAlUE(result, (&builder_), VariableType::JS_POINTER(),
GetObjectFromConstPool(glue, jsFunc, builder_.ZExtInt16ToInt32(methodId), ConstPoolType::METHOD));
auto method = GetObjectFromConstPool(glue, jsFunc, methodId, ConstPoolType::METHOD);
DEFVAlUE(result, (&builder_), VariableType::JS_POINTER(), builder_.ExceptionConstant());
Label defaultLabel(&builder_);
Label successExit(&builder_);
Label exceptionExit(&builder_);
@ -3091,8 +3086,6 @@ void SlowPathLowering::LowerDefineFunc(GateRef gate, GateRef glue, GateRef jsFun
std::vector<GateRef> successControl;
std::vector<GateRef> failControl;
{
GateRef method = GetObjectFromConstPool(glue, jsFunc, builder_.ZExtInt16ToInt32(methodId),
ConstPoolType::METHOD);
result = LowerCallRuntime(glue, RTSTUB_ID(DefineFunc), { method });
Label isException(&builder_);
Label notException(&builder_);
@ -3412,19 +3405,19 @@ void SlowPathLowering::LowerDefineMethod(GateRef gate, GateRef glue, GateRef jsF
DebugPrintBC(gate, glue);
// 3: number of value inputs
ASSERT(acc_.GetNumValueIn(gate) == 3);
GateRef methodId = acc_.GetValueIn(gate, 0);
GateRef methodId = builder_.TruncInt64ToInt32(acc_.GetValueIn(gate, 0));
auto method = GetObjectFromConstPool(glue, jsFunc, methodId, ConstPoolType::METHOD);
GateRef length = acc_.GetValueIn(gate, 1);
GateRef homeObject = acc_.GetValueIn(gate, 2); // 2: second arg
GateRef result;
DEFVAlUE(method, (&builder_), VariableType::JS_POINTER(),
GetObjectFromConstPool(glue, jsFunc, builder_.ZExtInt16ToInt32(methodId), ConstPoolType::METHOD));
DEFVAlUE(result, (&builder_), VariableType::JS_POINTER(), builder_.ExceptionConstant());
GateRef newGate;
Label defaultLabel(&builder_);
Label successExit(&builder_);
Label exceptionExit(&builder_);
{
method = LowerCallRuntime(glue, RTSTUB_ID(DefineMethod), {*method, homeObject}, true);
result = LowerCallRuntime(glue, RTSTUB_ID(DefineMethod), {method, homeObject}, true);
Label notException(&builder_);
builder_.Branch(builder_.IsSpecial(*method, JSTaggedValue::VALUE_EXCEPTION),
builder_.Branch(builder_.IsSpecial(*result, JSTaggedValue::VALUE_EXCEPTION),
&exceptionExit, &notException);
builder_.Bind(&notException);
{
@ -3433,17 +3426,17 @@ void SlowPathLowering::LowerDefineMethod(GateRef gate, GateRef glue, GateRef jsF
}
builder_.Bind(&defaultLabel);
{
GateRef hclass = builder_.LoadHClass(*method);
builder_.SetPropertyInlinedProps(glue, *method, hclass, builder_.ToTaggedInt(length),
GateRef hclass = builder_.LoadHClass(*result);
builder_.SetPropertyInlinedProps(glue, *result, hclass, builder_.ToTaggedInt(length),
builder_.Int32(JSFunction::LENGTH_INLINE_PROPERTY_INDEX), VariableType::INT64());
GateRef env = LowerCallRuntime(glue, RTSTUB_ID(OptGetLexicalEnv), {}, true);
builder_.SetLexicalEnvToFunction(glue, *method, env);
builder_.SetModuleToFunction(glue, *method, builder_.GetModuleFromFunction(jsFunc));
result = *method;
builder_.SetLexicalEnvToFunction(glue, *result, env);
builder_.SetModuleToFunction(glue, *result, builder_.GetModuleFromFunction(jsFunc));
newGate = *result;
builder_.Jump(&successExit);
}
CREATE_DOUBLE_EXIT(successExit, exceptionExit)
ReplaceHirToSubCfg(gate, result, successControl, failControl);
ReplaceHirToSubCfg(gate, newGate, successControl, failControl);
}
void SlowPathLowering::LowerGetUnmappedArgs(GateRef gate, GateRef glue, GateRef actualArgc)
@ -3647,12 +3640,11 @@ void SlowPathLowering::LowerCallthis3Imm8V8V8V8V8(GateRef gate, GateRef glue)
a1Value, a2Value, bcOffset});
}
void SlowPathLowering::LowerLdThisByName(GateRef gate, GateRef glue, GateRef jsFunc, GateRef thisObj)
void SlowPathLowering::LowerLdThisByName(GateRef gate, GateRef glue, GateRef thisObj)
{
DebugPrintBC(gate, glue);
ASSERT(acc_.GetNumValueIn(gate) == 1);
GateRef stringId = acc_.GetValueIn(gate, 0);
GateRef propKey = GetObjectFromConstPool(glue, jsFunc, builder_.ZExtInt16ToInt32(stringId), ConstPoolType::STRING);
GateRef propKey = acc_.GetValueIn(gate, 0);
DEFVAlUE(result, (&builder_), VariableType::JS_ANY(), builder_.Undefined());
Label fastPath(&builder_);
Label slowPath(&builder_);
@ -3694,4 +3686,20 @@ void SlowPathLowering::LowerLdThisByName(GateRef gate, GateRef glue, GateRef jsF
}
ReplaceHirToSubCfg(gate, ret, successControl, failControl);
}
void SlowPathLowering::LowerConstPoolData(GateRef gate)
{
Environment env(0, &builder_);
GateRef jsFunc = argAcc_.GetCommonArgGate(CommonArgIdx::FUNC);
ConstDataId dataId(acc_.GetBitField(gate));
auto newGate = LoadObjectFromConstPool(jsFunc, builder_.Int32(dataId.GetId()));
// replace newGate
auto uses = acc_.Uses(gate);
for (auto it = uses.begin(); it != uses.end();) {
it = acc_.ReplaceIn(it, newGate);
}
// delete old gate
acc_.DeleteGate(gate);
}
} // namespace panda::ecmascript

View File

@ -150,6 +150,7 @@ private:
void LowerExceptionHandler(GateRef hirGate);
// environment must be initialized
GateRef GetConstPool(GateRef jsFunc);
GateRef LoadObjectFromConstPool(GateRef jsFunc, GateRef index);
GateRef GetObjectFromConstPool(GateRef jsFunc, GateRef index);
// environment must be initialized
GateRef GetObjectFromConstPool(GateRef glue, GateRef jsFunc, GateRef index, ConstPoolType type);
@ -164,8 +165,8 @@ private:
void LowerAsyncFunctionResolve(GateRef gate, GateRef glue);
void LowerAsyncFunctionReject(GateRef gate, GateRef glue);
void LowerLoadStr(GateRef gate, GateRef glue, GateRef jsFunc);
void LowerStGlobalVar(GateRef gate, GateRef glue, GateRef jsFunc);
void LowerTryLdGlobalByName(GateRef gate, GateRef glue, GateRef jsFunc);
void LowerStGlobalVar(GateRef gate, GateRef glue);
void LowerTryLdGlobalByName(GateRef gate, GateRef glue);
void LowerGetIterator(GateRef gate, GateRef glue);
void LowerToJSCall(GateRef gate, GateRef glue, const std::vector<GateRef> &args);
void LowerCallArg0(GateRef gate, GateRef glue);
@ -228,7 +229,7 @@ private:
void LowerStModuleVar(GateRef gate, GateRef glue, GateRef jsFunc);
void LowerGetTemplateObject(GateRef gate, GateRef glue);
void LowerSetObjectWithProto(GateRef gate, GateRef glue);
void LowerLdBigInt(GateRef gate, GateRef glue, GateRef jsFunc);
void LowerLdBigInt(GateRef gate, GateRef glue);
void LowerToNumeric(GateRef gate, GateRef glue);
void LowerDynamicImport(GateRef gate, GateRef glue, GateRef jsFunc);
void LowerLdLocalModuleVarByIndex(GateRef gate, GateRef glue, GateRef jsFunc);
@ -243,23 +244,23 @@ private:
void LowerGetNextPropName(GateRef gate, GateRef glue);
void LowerCopyDataProperties(GateRef gate, GateRef glue);
void LowerCreateObjectWithExcludedKeys(GateRef gate, GateRef glue);
void LowerCreateRegExpWithLiteral(GateRef gate, GateRef glue, GateRef jsFunc);
void LowerCreateRegExpWithLiteral(GateRef gate, GateRef glue);
void LowerStOwnByValue(GateRef gate, GateRef glue);
void LowerStOwnByIndex(GateRef gate, GateRef glue);
void LowerStOwnByName(GateRef gate, GateRef glue, GateRef jsFunc);
void LowerStOwnByName(GateRef gate, GateRef glue);
void LowerDefineFunc(GateRef gate, GateRef glue, GateRef jsFunc);
void LowerNewLexicalEnv(GateRef gate, GateRef glue);
void LowerNewLexicalEnvWithName(GateRef gate, GateRef glue, GateRef jsFunc);
void LowerPopLexicalEnv(GateRef gate, GateRef glue);
void LowerLdSuperByValue(GateRef gate, GateRef glue, GateRef jsFunc);
void LowerStSuperByValue(GateRef gate, GateRef glue, GateRef jsFunc);
void LowerTryStGlobalByName(GateRef gate, GateRef glue, GateRef jsFunc);
void LowerStConstToGlobalRecord(GateRef gate, GateRef glue, GateRef jsFunc, bool isConst);
void LowerTryStGlobalByName(GateRef gate, GateRef glue);
void LowerStConstToGlobalRecord(GateRef gate, GateRef glue,bool isConst);
void LowerStOwnByValueWithNameSet(GateRef gate, GateRef glue);
void LowerStOwnByNameWithNameSet(GateRef gate, GateRef glue, GateRef jsFunc);
void LowerLdGlobalVar(GateRef gate, GateRef glue, GateRef jsFunc);
void LowerLdObjByName(GateRef gate, GateRef glue, GateRef jsFunc);
void LowerStObjByName(GateRef gate, GateRef glue, GateRef jsFunc, GateRef thisObj, bool isThis = false);
void LowerStOwnByNameWithNameSet(GateRef gate, GateRef glue);
void LowerLdGlobalVar(GateRef gate, GateRef glue);
void LowerLdObjByName(GateRef gate, GateRef glue);
void LowerStObjByName(GateRef gate, GateRef glue, GateRef thisObj, bool isThis = false);
void LowerLdSuperByName(GateRef gate, GateRef glue, GateRef jsFunc);
void LowerStSuperByName(GateRef gate, GateRef glue, GateRef jsFunc);
void LowerDefineGetterSetterByValue(GateRef gate, GateRef glue);
@ -289,7 +290,8 @@ private:
GateRef FastStrictEqual(GateRef glue, GateRef left, GateRef right);
void LowerWideLdPatchVar(GateRef gate, GateRef glue);
void LowerWideStPatchVar(GateRef gate, GateRef glue);
void LowerLdThisByName(GateRef gate, GateRef glue, GateRef jsFunc, GateRef thisObj);
void LowerLdThisByName(GateRef gate, GateRef glue, GateRef thisObj);
void LowerConstPoolData(GateRef gate);
TSManager *tsManager_ {nullptr};
BytecodeCircuitBuilder *bcBuilder_;

View File

@ -152,6 +152,25 @@ void TSTypeLowering::Lower(GateRef gate)
case EcmaOpcode::JEQZ_IMM32:
LowerConditionJump(gate);
break;
case EcmaOpcode::LDOBJBYNAME_IMM8_ID16:
case EcmaOpcode::LDOBJBYNAME_IMM16_ID16:
// lower LD_OBJ
// LowerTypedLoadObjByName(gate);
break;
case EcmaOpcode::STOBJBYNAME_IMM8_ID16_V8:
case EcmaOpcode::STOBJBYNAME_IMM16_ID16_V8:
// LowerTypedStoreObjByName(gate);
break;
case EcmaOpcode::LDOBJBYINDEX_IMM8_IMM16:
case EcmaOpcode::LDOBJBYINDEX_IMM16_IMM16:
case EcmaOpcode::WIDE_LDOBJBYINDEX_PREF_IMM32:
// LowerTypedLoadObjByIndex(gate);
break;
case EcmaOpcode::STOBJBYINDEX_IMM8_V8_IMM16:
case EcmaOpcode::STOBJBYINDEX_IMM16_V8_IMM16:
case EcmaOpcode::WIDE_STOBJBYINDEX_PREF_V8_IMM32:
// LowerTypedStoreObjByIndex(gate);
break;
default:
break;
}

View File

@ -506,7 +506,7 @@ bool TypeInfer::SetStGlobalBcType(GateRef gate)
{
auto byteCodeInfo = builder_->GetByteCodeInfo(gate);
ASSERT(byteCodeInfo.inputs.size() == 1);
auto stringId = std::get<StringId>(byteCodeInfo.inputs[0]).GetId();
auto stringId = std::get<ConstDataId>(byteCodeInfo.inputs[0]).GetId();
// 2: number of value inputs
ASSERT(gateAccessor_.GetNumValueIn(gate) == 2);
auto inValueType = gateAccessor_.GetGateType(gateAccessor_.GetValueIn(gate, 1));
@ -522,7 +522,7 @@ bool TypeInfer::InferLdGlobalVar(GateRef gate)
{
auto byteCodeInfo = builder_->GetByteCodeInfo(gate);
ASSERT(byteCodeInfo.inputs.size() == 1);
auto stringId = std::get<StringId>(byteCodeInfo.inputs[0]).GetId();
auto stringId = std::get<ConstDataId>(byteCodeInfo.inputs[0]).GetId();
auto iter = stringIdToGateType_.find(stringId);
if (iter != stringIdToGateType_.end()) {
return UpdateType(gate, iter->second);
@ -651,7 +651,7 @@ bool TypeInfer::InferTryLdGlobalByName(GateRef gate)
// todo by hongtao, should consider function of .d.ts
auto byteCodeInfo = builder_->GetByteCodeInfo(gate);
ASSERT(byteCodeInfo.inputs.size() == 1);
auto stringId = std::get<StringId>(byteCodeInfo.inputs[0]).GetId();
auto stringId = std::get<ConstDataId>(byteCodeInfo.inputs[0]).GetId();
auto iter = stringIdToGateType_.find(stringId);
if (iter != stringIdToGateType_.end()) {
return UpdateType(gate, iter->second);
@ -751,9 +751,9 @@ void TypeInfer::TypeCheck(GateRef gate) const
ConstantPool::GetStringFromCache(thread, constantPool_.GetTaggedValue(), gateAccessor_.GetBitField(funcName));
auto funcNameString = constantPool_->GetStdStringByIdx(gateAccessor_.GetBitField(funcName));
if (funcNameString == "AssertType") {
GateRef expectedGate = gateAccessor_.GetValueIn(gateAccessor_.GetValueIn(gate, 1), 0);
GateRef expectedGate = gateAccessor_.GetValueIn(gate, 1);
ConstantPool::GetStringFromCache(thread, constantPool_.GetTaggedValue(),
gateAccessor_.GetBitField(expectedGate));
ConstDataId(gateAccessor_.GetBitField(expectedGate)).GetId());
auto expectedTypeStr = constantPool_->GetStdStringByIdx(gateAccessor_.GetBitField(expectedGate));
GateRef valueGate = gateAccessor_.GetValueIn(gate, 0);
auto type = gateAccessor_.GetGateType(valueGate);

View File

@ -454,6 +454,7 @@ Expected<JSTaggedValue, bool> EcmaVM::InvokeEcmaEntrypoint(const JSPandaFile *js
if (jsPandaFile->IsLoadedAOT()) {
thread_->SetPrintBCOffset(true);
EcmaRuntimeStatScope runtimeStatScope(this);
result = InvokeEcmaAotEntrypoint(func, global, jsPandaFile);
} else {
if (jsPandaFile->IsCjs(entryPoint.data())) {

View File

@ -756,10 +756,10 @@ JSTaggedValue RuntimeStubs::RuntimeCreateClassWithBuffer(JSThread *thread,
auto methodObj = ConstantPool::GetClassMethodFromCache(thread, constantPool, methodId);
JSHandle<JSTaggedValue> method(thread, methodObj);
auto literalObj = ConstantPool::GetClassLiteralFromCache(thread, constantPool, literalId, entry);
JSHandle<TaggedArray> literal(thread, literalObj);
JSHandle<TaggedArray> literalHandle(thread, literalObj);
JSHandle<ClassInfoExtractor> extractor = factory->NewClassInfoExtractor(method);
ClassInfoExtractor::BuildClassInfoExtractorFromLiteral(thread, extractor, literal);
ClassInfoExtractor::BuildClassInfoExtractorFromLiteral(thread, extractor, literalHandle);
JSHandle<JSFunction> cls = ClassHelper::DefineClassFromExtractor(thread, base, extractor, constpool, lexenv);
RuntimeSetClassInheritanceRelationship(thread, JSHandle<JSTaggedValue>(cls), base);
@ -788,10 +788,10 @@ JSTaggedValue RuntimeStubs::RuntimeCreateClassWithIHClass(JSThread *thread,
auto methodObj = ConstantPool::GetClassMethodFromCache(thread, constantPool, methodId);
JSHandle<JSTaggedValue> method(thread, methodObj);
auto literalObj = ConstantPool::GetClassLiteralFromCache(thread, constantPool, literalId, entry);
JSHandle<TaggedArray> literal(thread, literalObj);
JSHandle<TaggedArray> literalHandle(thread, literalObj);
JSHandle<ClassInfoExtractor> extractor = factory->NewClassInfoExtractor(method);
ClassInfoExtractor::BuildClassInfoExtractorFromLiteral(thread, extractor, literal);
ClassInfoExtractor::BuildClassInfoExtractorFromLiteral(thread, extractor, literalHandle);
JSHandle<JSFunction> cls = ClassHelper::DefineClassWithIHClass(thread, base, extractor, constpool, lexenv, ihclass);
RuntimeSetClassInheritanceRelationship(thread, JSHandle<JSTaggedValue>(cls), base);

View File

@ -566,27 +566,35 @@ JSTaggedValue TSManager::GenerateConstantPoolInfo(const JSPandaFile* jsPandaFile
JSHandle<ConstantPool> constantPool(thread, vm_->FindConstpool(jsPandaFile, 0));
JSHandle<TaggedArray> constantPoolInfo = factory->NewTaggedArray(ComputeSizeOfConstantPoolInfo());
constantPoolInfo->Set(thread, NUM_OF_ORIGINAL_CONSTANTPOOL_DATA_INDEX,
JSTaggedValue(GetStringCacheSize() * ORIGINAL_CONSTANTPOOL_DATA_SIZE));
JSTaggedValue(GetConstDataCacheSize() * ORIGINAL_CONSTANTPOOL_DATA_SIZE));
constantPoolInfo->Set(thread, NUM_OF_HCLASS_INDEX, JSTaggedValue(GetHClassCacheSize()));
uint32_t index = CONSTANTPOOL_INFO_DATA_OFFSET;
const panda_file::File *pfile = jsPandaFile->GetPandaFile();
panda_file::File::IndexHeader *indexHeader = constantPool->GetIndexHeader();
Span<const panda_file::File::EntityId> indexs = pfile->GetMethodIndex(indexHeader);
IterateCaches(CacheKind::STRING_INDEX, [this, pfile ,&indexs, &index, constantPoolInfo] (uint32_t stringIndex) {
ObjectFactory *factory = vm_->GetFactory();
JSThread *thread = vm_->GetJSThread();
panda_file::File::EntityId id = indexs[stringIndex];
auto foundStr = pfile->GetStringData(id);
auto string = factory->GetRawStringFromStringTable(foundStr.data, foundStr.utf16_length, foundStr.is_ascii,
MemSpaceType::OLD_SPACE);
constantPoolInfo->Set(thread, index++, JSTaggedValue(stringIndex));
constantPoolInfo->Set(thread, index++, JSTaggedValue(string));
IterateConstDataCaches([thread, constantPool, &index, constantPoolInfo] (ConstPoolType type, uint32_t constIndex) {
switch (type) {
case ConstPoolType::STRING: {
auto string = ConstantPool::GetStringFromCache(thread, constantPool.GetTaggedValue(), constIndex);
constantPoolInfo->Set(thread, index++, JSTaggedValue(constIndex));
constantPoolInfo->Set(thread, index++, string);
break;
}
case ConstPoolType::METHOD: {
auto method = ConstantPool::GetMethodFromCache(thread, constantPool.GetTaggedValue(), constIndex);
constantPoolInfo->Set(thread, index++, JSTaggedValue(constIndex));
constantPoolInfo->Set(thread, index++, method);
break;
}
case ConstPoolType::CLASS_LITERAL: {
auto litera = ConstantPool::GetClassLiteralFromCache(thread, constantPool, constIndex);
constantPoolInfo->Set(thread, index++, JSTaggedValue(constIndex));
constantPoolInfo->Set(thread, index++, litera);
break;
}
default:
UNREACHABLE();
}
});
IterateCaches(CacheKind::HCLASS, [thread, &index, &constantPoolInfo]
IterateHClassCaches([thread, &index, &constantPoolInfo]
(JSTaggedType hclass) {
constantPoolInfo->Set(thread, index++, JSTaggedValue(hclass));
});

View File

@ -18,6 +18,7 @@
#include "ecmascript/mem/c_string.h"
#include "ecmascript/js_handle.h"
#include "ecmascript/jspandafile/constpool_value.h"
#include "ecmascript/js_tagged_value-inl.h"
#include "ecmascript/ts_types/global_ts_type_ref.h"
@ -30,7 +31,7 @@ enum class MTableIdx : uint8_t {
};
enum class CacheKind: uint8_t {
STRING_INDEX = 0,
CONST_DATA_INDEX = 0,
HCLASS,
};
@ -253,16 +254,32 @@ public:
void ClearCaches()
{
stringIndexCache_.clear();
constIndexCache_.clear();
hclassCache_.clear();
}
void AddStringIndex(uint32_t index)
{
if (stringIndexCache_.find(index) != stringIndexCache_.end()) {
if (constIndexCache_.find({ConstPoolType::STRING, index}) != constIndexCache_.end()) {
return;
}
stringIndexCache_.insert(index);
constIndexCache_.insert({ConstPoolType::STRING, index});
}
void AddMethodIndex(uint32_t index)
{
if (constIndexCache_.find({ConstPoolType::METHOD, index}) != constIndexCache_.end()) {
return;
}
constIndexCache_.insert({ConstPoolType::METHOD, index});
}
void AddClassLiteraIndex(uint32_t index)
{
if (constIndexCache_.find({ConstPoolType::CLASS_LITERAL, index}) != constIndexCache_.end()) {
return;
}
constIndexCache_.insert({ConstPoolType::CLASS_LITERAL, index});
}
EcmaVM *GetEcmaVM() const
@ -363,7 +380,7 @@ private:
uint32_t ComputeSizeOfConstantPoolInfo() const
{
return CONSTANTPOOL_INFO_DATA_OFFSET + ORIGINAL_CONSTANTPOOL_DATA_SIZE *
GetStringCacheSize() + GetHClassCacheSize();
GetConstDataCacheSize() + GetHClassCacheSize();
}
uint32_t GetHClassCacheSize() const
@ -371,9 +388,9 @@ private:
return hclassCache_.size();
}
uint32_t GetStringCacheSize() const
uint32_t GetConstDataCacheSize() const
{
return stringIndexCache_.size();
return constIndexCache_.size();
}
void AddHClassInCompilePhase(GlobalTSTypeRef gt, JSTaggedValue hclass, uint32_t constantPoolLen)
@ -383,24 +400,19 @@ private:
}
template <class Callback>
void IterateCaches(CacheKind kind, const Callback &cb)
void IterateConstDataCaches(const Callback &cb)
{
switch (kind) {
case CacheKind::STRING_INDEX: {
for (uint32_t item: stringIndexCache_) {
cb(item);
}
break;
}
case CacheKind::HCLASS: {
for (JSTaggedType item: hclassCache_) {
cb(item);
}
break;
}
default:
UNREACHABLE();
};
for (auto item: constIndexCache_) {
cb(std::get<0>(item), std::get<1>(item));
}
}
template <class Callback>
void IterateHClassCaches(const Callback &cb)
{
for (JSTaggedType item: hclassCache_) {
cb(item);
}
}
EcmaVM *vm_ {nullptr};
@ -416,7 +428,7 @@ private:
friend class EcmaVM;
// recode the index of String in each constpool
std::set<uint32_t> stringIndexCache_ {};
std::set<std::tuple<ConstPoolType, int>>constIndexCache_ {};
// store hclass of each abc which produced from static type info
CVector<JSTaggedType> hclassCache_ {};