From 9d975faeb6b014a13ec2d6b33b198982be48ee34 Mon Sep 17 00:00:00 2001 From: songzhengchao Date: Sat, 30 Oct 2021 10:04:58 +0800 Subject: [PATCH 1/2] enum MachineType replace with enum class MachineType GetInteger32Constant replace with GetInt32Constant Signed-off-by: songzhengchao --- ecmascript/compiler/circuit_builder.cpp | 124 +++++++++--------- ecmascript/compiler/fast_stub.cpp | 90 +++++++------ ecmascript/compiler/llvm_ir_builder.cpp | 26 ++-- ecmascript/compiler/machine_type.h | 2 +- ecmascript/compiler/stub.cpp | 137 +++++++++---------- ecmascript/compiler/stub.h | 160 ++++++++++++----------- ecmascript/compiler/stub_descriptor.cpp | 103 ++++++++++----- ecmascript/compiler/tests/stub_tests.cpp | 51 ++++---- 8 files changed, 368 insertions(+), 325 deletions(-) diff --git a/ecmascript/compiler/circuit_builder.cpp b/ecmascript/compiler/circuit_builder.cpp index ba3c833a0c..d0bcab1f91 100644 --- a/ecmascript/compiler/circuit_builder.cpp +++ b/ecmascript/compiler/circuit_builder.cpp @@ -155,30 +155,30 @@ AddrShift CircuitBuilder::NewDefaultCase(AddrShift switchBranch) OpCode CircuitBuilder::GetStoreOpCodeFromMachineType(MachineType type) { switch (type) { - case INT8_TYPE: + case MachineType::INT8_TYPE: return OpCode(OpCode::INT8_STORE); - case INT16_TYPE: + case MachineType::INT16_TYPE: return OpCode(OpCode::INT16_STORE); - case INT32_TYPE: + case MachineType::INT32_TYPE: return OpCode(OpCode::INT32_STORE); - case INT64_TYPE: + case MachineType::INT64_TYPE: return OpCode(OpCode::INT64_STORE); - case BOOL_TYPE: + case MachineType::BOOL_TYPE: return OpCode(OpCode::INT32_STORE); - case UINT8_TYPE: + case MachineType::UINT8_TYPE: return OpCode(OpCode::INT8_STORE); - case UINT16_TYPE: + case MachineType::UINT16_TYPE: return OpCode(OpCode::INT16_STORE); - case UINT32_TYPE: + case MachineType::UINT32_TYPE: return OpCode(OpCode::INT32_STORE); - case UINT64_TYPE: - case POINTER_TYPE: - case TAGGED_TYPE: - case TAGGED_POINTER_TYPE: + case MachineType::UINT64_TYPE: + case MachineType::POINTER_TYPE: + case MachineType::TAGGED_TYPE: + case MachineType::TAGGED_POINTER_TYPE: return OpCode(OpCode::INT64_STORE); - case FLOAT32_TYPE: + case MachineType::FLOAT32_TYPE: return OpCode(OpCode::FLOAT32_STORE); - case FLOAT64_TYPE: + case MachineType::FLOAT64_TYPE: return OpCode(OpCode::FLOAT64_STORE); default: UNREACHABLE(); @@ -188,30 +188,30 @@ OpCode CircuitBuilder::GetStoreOpCodeFromMachineType(MachineType type) OpCode CircuitBuilder::GetLoadOpCodeFromMachineType(MachineType type) { switch (type) { - case INT8_TYPE: + case MachineType::INT8_TYPE: return OpCode(OpCode::INT8_LOAD); - case INT16_TYPE: + case MachineType::INT16_TYPE: return OpCode(OpCode::INT16_LOAD); - case INT32_TYPE: + case MachineType::INT32_TYPE: return OpCode(OpCode::INT32_LOAD); - case INT64_TYPE: + case MachineType::INT64_TYPE: return OpCode(OpCode::INT64_LOAD); - case BOOL_TYPE: + case MachineType::BOOL_TYPE: return OpCode(OpCode::INT32_LOAD); - case UINT8_TYPE: + case MachineType::UINT8_TYPE: return OpCode(OpCode::INT8_LOAD); - case UINT16_TYPE: + case MachineType::UINT16_TYPE: return OpCode(OpCode::INT16_LOAD); - case UINT32_TYPE: + case MachineType::UINT32_TYPE: return OpCode(OpCode::INT32_LOAD); - case UINT64_TYPE: - case POINTER_TYPE: - case TAGGED_TYPE: - case TAGGED_POINTER_TYPE: + case MachineType::UINT64_TYPE: + case MachineType::POINTER_TYPE: + case MachineType::TAGGED_TYPE: + case MachineType::TAGGED_POINTER_TYPE: return OpCode(OpCode::INT64_LOAD); - case FLOAT32_TYPE: + case MachineType::FLOAT32_TYPE: return OpCode(OpCode::FLOAT32_LOAD); - case FLOAT64_TYPE: + case MachineType::FLOAT64_TYPE: return OpCode(OpCode::FLOAT64_LOAD); default: UNREACHABLE(); @@ -221,32 +221,32 @@ OpCode CircuitBuilder::GetLoadOpCodeFromMachineType(MachineType type) OpCode CircuitBuilder::GetSelectOpCodeFromMachineType(MachineType type) { switch (type) { - case NONE_TYPE: + case MachineType::NONE_TYPE: return OpCode(OpCode::DEPEND_SELECTOR); - case INT8_TYPE: + case MachineType::INT8_TYPE: return OpCode(OpCode::VALUE_SELECTOR_INT8); - case INT16_TYPE: + case MachineType::INT16_TYPE: return OpCode(OpCode::VALUE_SELECTOR_INT16); - case INT32_TYPE: + case MachineType::INT32_TYPE: return OpCode(OpCode::VALUE_SELECTOR_INT32); - case INT64_TYPE: + case MachineType::INT64_TYPE: return OpCode(OpCode::VALUE_SELECTOR_INT64); - case BOOL_TYPE: + case MachineType::BOOL_TYPE: return OpCode(OpCode::VALUE_SELECTOR_INT1); - case UINT8_TYPE: + case MachineType::UINT8_TYPE: return OpCode(OpCode::VALUE_SELECTOR_INT8); - case UINT16_TYPE: + case MachineType::UINT16_TYPE: return OpCode(OpCode::VALUE_SELECTOR_INT16); - case UINT32_TYPE: + case MachineType::UINT32_TYPE: return OpCode(OpCode::VALUE_SELECTOR_INT32); - case UINT64_TYPE: - case POINTER_TYPE: - case TAGGED_TYPE: - case TAGGED_POINTER_TYPE: + case MachineType::UINT64_TYPE: + case MachineType::POINTER_TYPE: + case MachineType::TAGGED_TYPE: + case MachineType::TAGGED_POINTER_TYPE: return OpCode(OpCode::VALUE_SELECTOR_INT64); - case FLOAT32_TYPE: + case MachineType::FLOAT32_TYPE: return OpCode(OpCode::VALUE_SELECTOR_FLOAT32); - case FLOAT64_TYPE: + case MachineType::FLOAT64_TYPE: return OpCode(OpCode::VALUE_SELECTOR_FLOAT64); default: UNREACHABLE(); @@ -270,13 +270,13 @@ AddrShift CircuitBuilder::NewDependAnd(std::initializer_list args) AddrShift CircuitBuilder::NewLoadGate(MachineType type, AddrShift val, AddrShift depend) { OpCode op = GetLoadOpCodeFromMachineType(type); - return circuit_->NewGate(op, type, {depend, val}, TypeCode::NOTYPE); + return circuit_->NewGate(op, static_cast(type), {depend, val}, TypeCode::NOTYPE); } AddrShift CircuitBuilder::NewStoreGate(MachineType type, AddrShift ptr, AddrShift val, AddrShift depend) { OpCode op = GetStoreOpCodeFromMachineType(type); - return circuit_->NewGate(op, type, {depend, val, ptr}, TypeCode::NOTYPE); + return circuit_->NewGate(op, static_cast(type), {depend, val, ptr}, TypeCode::NOTYPE); } AddrShift CircuitBuilder::NewArithMeticGate(OpCode opcode, AddrShift left, AddrShift right) @@ -291,43 +291,43 @@ AddrShift CircuitBuilder::NewArithMeticGate(OpCode opcode, AddrShift value) AddrShift CircuitBuilder::NewLogicGate(OpCode opcode, AddrShift left, AddrShift right) { - return circuit_->NewGate(opcode, MachineType::BOOL_TYPE, {left, right}, TypeCode::NOTYPE); + return circuit_->NewGate(opcode, static_cast(MachineType::BOOL_TYPE), {left, right}, TypeCode::NOTYPE); } AddrShift CircuitBuilder::NewLogicGate(OpCode opcode, AddrShift value) { - return circuit_->NewGate(opcode, MachineType::BOOL_TYPE, {value}, TypeCode::NOTYPE); + return circuit_->NewGate(opcode, static_cast(MachineType::BOOL_TYPE), {value}, TypeCode::NOTYPE); } OpCode CircuitBuilder::GetCallOpCodeFromMachineType(MachineType type) { switch (type) { - case NONE_TYPE: + case MachineType::NONE_TYPE: return OpCode(OpCode::CALL); - case INT8_TYPE: + case MachineType::INT8_TYPE: return OpCode(OpCode::INT8_CALL); - case INT16_TYPE: + case MachineType::INT16_TYPE: return OpCode(OpCode::INT16_CALL); - case INT32_TYPE: + case MachineType::INT32_TYPE: return OpCode(OpCode::INT32_CALL); - case INT64_TYPE: + case MachineType::INT64_TYPE: return OpCode(OpCode::INT64_CALL); - case BOOL_TYPE: + case MachineType::BOOL_TYPE: return OpCode(OpCode::INT1_CALL); - case UINT8_TYPE: + case MachineType::UINT8_TYPE: return OpCode(OpCode::INT8_CALL); - case UINT16_TYPE: + case MachineType::UINT16_TYPE: return OpCode(OpCode::INT16_CALL); - case UINT32_TYPE: + case MachineType::UINT32_TYPE: return OpCode(OpCode::INT32_CALL); - case UINT64_TYPE: - case POINTER_TYPE: - case TAGGED_TYPE: - case TAGGED_POINTER_TYPE: + case MachineType::UINT64_TYPE: + case MachineType::POINTER_TYPE: + case MachineType::TAGGED_TYPE: + case MachineType::TAGGED_POINTER_TYPE: return OpCode(OpCode::INT64_CALL); - case FLOAT32_TYPE: + case MachineType::FLOAT32_TYPE: return OpCode(OpCode::FLOAT32_CALL); - case FLOAT64_TYPE: + case MachineType::FLOAT64_TYPE: return OpCode(OpCode::FLOAT64_CALL); default: UNREACHABLE(); diff --git a/ecmascript/compiler/fast_stub.cpp b/ecmascript/compiler/fast_stub.cpp index 19c87b3b5f..395127709b 100644 --- a/ecmascript/compiler/fast_stub.cpp +++ b/ecmascript/compiler/fast_stub.cpp @@ -29,7 +29,7 @@ void FastArrayLoadElementStub::GenerateCircuit() AddrShift indexVal = Int32Argument(1); // load a.length - AddrShift lengthOffset = GetInteger32Constant(JSArray::GetArrayLengthOffset()); + AddrShift lengthOffset = GetInt32Constant(JSArray::GetArrayLengthOffset()); if (PtrValueCode() == ValueCode::INT64) { lengthOffset = SExtInt32ToInt64(lengthOffset); } else if (PtrValueCode() == ValueCode::INT32) { @@ -349,19 +349,18 @@ void FindOwnElementStub::GenerateCircuit() AddrShift thread = PtrArgument(0); AddrShift obj = PtrArgument(1); AddrShift index = Int32Argument(2); // 2: 3rd parameter - index - Label notDict(env); Label isDict(env); Label invalidValue(env); Label end(env); - AddrShift elements = Load(POINTER_TYPE, obj, GetPtrConstant(JSObject::ELEMENTS_OFFSET)); - + AddrShift elements = Load(MachineType::POINTER_TYPE, obj, GetPtrConstant(JSObject::ELEMENTS_OFFSET)); Branch(IsDictionaryMode(elements), &isDict, ¬Dict); Bind(¬Dict); { Label outOfArray(env); Label notOutOfArray(env); - AddrShift arrayLength = Load(UINT32_TYPE, elements, GetPtrConstant(panda::coretypes::Array::GetLengthOffset())); + AddrShift arrayLength = Load(MachineType::UINT32_TYPE, elements, + GetPtrConstant(panda::coretypes::Array::GetLengthOffset())); Branch(Int32LessThanOrEqual(arrayLength, index), &outOfArray, ¬OutOfArray); Bind(&outOfArray); Jump(&invalidValue); @@ -369,7 +368,7 @@ void FindOwnElementStub::GenerateCircuit() { AddrShift offset = PtrMul(ChangeInt32ToPointer(index), GetPtrConstant(JSTaggedValue::TaggedTypeSize())); AddrShift dataIndex = PtrAdd(offset, GetPtrConstant(panda::coretypes::Array::GetDataOffset())); - AddrShift value = Load(TAGGED_TYPE, elements, dataIndex); + AddrShift value = Load(MachineType::TAGGED_TYPE, elements, dataIndex); Label isHole1(env); Label notHole1(env); Branch(TaggedIsHole(value), &isHole1, ¬Hole1); @@ -388,7 +387,7 @@ void FindOwnElementStub::GenerateCircuit() AddrShift entry = FindElementFromNumberDictionary(thread, elements, taggedIndex); Label notNegtiveOne(env); Label negtiveOne(env); - Branch(Word32NotEqual(entry, GetInteger32Constant(-1)), ¬NegtiveOne, &negtiveOne); + Branch(Word32NotEqual(entry, GetInt32Constant(-1)), ¬NegtiveOne, &negtiveOne); Bind(¬NegtiveOne); { Return(GetValueFromDictionary(elements, entry)); @@ -424,7 +423,7 @@ void GetElementStub::GenerateCircuit() Bind(¬Hole); Return(callFindOwnElementVal); Bind(&isHole); - receiver = Load(TAGGED_TYPE, LoadHClass(objPtr), GetPtrConstant(JSHClass::PROTOTYPE_OFFSET)); + receiver = Load(MachineType::TAGGED_TYPE, LoadHClass(objPtr), GetPtrConstant(JSHClass::PROTOTYPE_OFFSET)); Branch(TaggedIsHeapObject(receiver), &loopEnd, ¬HeapObj); Bind(¬HeapObj); Return(GetUndefinedConstant()); @@ -445,11 +444,11 @@ void FindOwnElement2Stub::GenerateCircuit() Label notDictionary(env); Label isDictionary(env); Label end(env); - Branch(Word32Equal(isDict, GetInteger32Constant(0)), ¬Dictionary, &isDictionary); + Branch(Word32Equal(isDict, GetInt32Constant(0)), ¬Dictionary, &isDictionary); Bind(¬Dictionary); { AddrShift elementsLength = - Load(UINT32_TYPE, elements, GetPtrConstant(panda::coretypes::Array::GetLengthOffset())); + Load(MachineType::UINT32_TYPE, elements, GetPtrConstant(panda::coretypes::Array::GetLengthOffset())); Label outOfElements(env); Label notOutOfElements(env); Branch(Int32LessThanOrEqual(elementsLength, index), &outOfElements, ¬OutOfElements); @@ -467,9 +466,9 @@ void FindOwnElement2Stub::GenerateCircuit() Jump(&end); Bind(¬Hole); { - Store(UINT32_TYPE, attr, GetPtrConstant(0), - GetInteger32Constant(PropertyAttributes::GetDefaultAttributes())); - Store(UINT32_TYPE, indexOrEntry, GetPtrConstant(0), index); + Store(MachineType::UINT32_TYPE, attr, GetPtrConstant(0), + GetInt32Constant(PropertyAttributes::GetDefaultAttributes())); + Store(MachineType::UINT32_TYPE, indexOrEntry, GetPtrConstant(0), index); Return(value); } } @@ -479,11 +478,11 @@ void FindOwnElement2Stub::GenerateCircuit() AddrShift entry = FindElementFromNumberDictionary(thread, elements, IntBuildTagged(index)); Label notNegtiveOne(env); Label negtiveOne(env); - Branch(Word32NotEqual(entry, GetInteger32Constant(-1)), ¬NegtiveOne, &negtiveOne); + Branch(Word32NotEqual(entry, GetInt32Constant(-1)), ¬NegtiveOne, &negtiveOne); Bind(¬NegtiveOne); { - Store(UINT32_TYPE, attr, GetPtrConstant(0), GetAttributesFromDictionary(elements, entry)); - Store(UINT32_TYPE, indexOrEntry, GetPtrConstant(0), entry); + Store(MachineType::UINT32_TYPE, attr, GetPtrConstant(0), GetAttributesFromDictionary(elements, entry)); + Store(MachineType::UINT32_TYPE, indexOrEntry, GetPtrConstant(0), entry); Return(GetValueFromDictionary(elements, entry)); } Bind(&negtiveOne); @@ -539,7 +538,7 @@ void SetElementStub::GenerateCircuit() { Label isThrow(env); Label notThrow(env); - Branch(Word32NotEqual(mayThrow, GetInteger32Constant(0)), &isThrow, ¬Throw); + Branch(Word32NotEqual(mayThrow, GetInt32Constant(0)), &isThrow, ¬Throw); Bind(&isThrow); ThrowTypeAndReturn(thread, GET_MESSAGE_STRING_ID(SetPropertyWhenNotExtensible), FalseConstant()); Bind(¬Throw); @@ -549,11 +548,11 @@ void SetElementStub::GenerateCircuit() StubDescriptor *addElementInternal = GET_STUBDESCRIPTOR(AddElementInternal); Return(CallRuntime(addElementInternal, thread, GetWord64Constant(FAST_STUB_ID(AddElementInternal)), {thread, receiver, index, value, - GetInteger32Constant(PropertyAttributes::GetDefaultAttributes())})); + GetInt32Constant(PropertyAttributes::GetDefaultAttributes())})); } Bind(&afterOnProtoType); { - AddrShift attr = Load(INT32_TYPE, pattr); + AddrShift attr = Load(MachineType::INT32_TYPE, pattr); Label isAccessor(env); Label notAccessor(env); Branch(IsAccessor(attr), &isAccessor, ¬Accessor); @@ -567,7 +566,7 @@ void SetElementStub::GenerateCircuit() AddrShift elements = GetElements(receiver); Label isDict(env); Label notDict(env); - AddrShift indexOrEntry = Load(INT32_TYPE, pindexOrEntry); + AddrShift indexOrEntry = Load(MachineType::INT32_TYPE, pindexOrEntry); Branch(isDictionary, &isDict, ¬Dict); Bind(¬Dict); { @@ -585,7 +584,7 @@ void SetElementStub::GenerateCircuit() { Label isThrow(env); Label notThrow(env); - Branch(Word32NotEqual(mayThrow, GetInteger32Constant(0)), &isThrow, ¬Throw); + Branch(Word32NotEqual(mayThrow, GetInt32Constant(0)), &isThrow, ¬Throw); Bind(&isThrow); ThrowTypeAndReturn(thread, GET_MESSAGE_STRING_ID(SetReadOnlyProperty), FalseConstant()); Bind(¬Throw); @@ -620,7 +619,7 @@ void SetElementStub::GenerateCircuit() { Label isThrow(env); Label notThrow(env); - Branch(Word32NotEqual(mayThrow, GetInteger32Constant(0)), &isThrow, ¬Throw); + Branch(Word32NotEqual(mayThrow, GetInt32Constant(0)), &isThrow, ¬Throw); Bind(&isThrow); ThrowTypeAndReturn(thread, GET_MESSAGE_STRING_ID(SetPropertyWhenNotExtensible), FalseConstant()); Bind(¬Throw); @@ -631,7 +630,7 @@ void SetElementStub::GenerateCircuit() StubDescriptor *addElementInternal = GET_STUBDESCRIPTOR(AddElementInternal); Return(CallRuntime(addElementInternal, thread, GetWord64Constant(FAST_STUB_ID(AddElementInternal)), {thread, receiver, index, value, - GetInteger32Constant(PropertyAttributes::GetDefaultAttributes())})); + GetInt32Constant(PropertyAttributes::GetDefaultAttributes())})); } } Bind(&isHeapObj); @@ -718,7 +717,7 @@ void GetPropertyByIndexStub::GenerateCircuit() FindElementFromNumberDictionary(thread, elements, IntBuildTagged(index)); Label notNegtiveOne(env); Label negtiveOne(env); - Branch(Word32NotEqual(entry, GetInteger32Constant(-1)), ¬NegtiveOne, &negtiveOne); + Branch(Word32NotEqual(entry, GetInt32Constant(-1)), ¬NegtiveOne, &negtiveOne); Bind(¬NegtiveOne); { AddrShift attr = GetAttributesFromDictionary(elements, entry); @@ -844,7 +843,7 @@ void SetPropertyByIndexStub::GenerateCircuit() AddrShift result = CallRuntime(addElementInternal, thread, GetWord64Constant(FAST_STUB_ID(AddElementInternal)), {thread, receiver, index, value, - GetInteger32Constant(PropertyAttributes::GetDefaultAttributes())}); + GetInt32Constant(PropertyAttributes::GetDefaultAttributes())}); Label success(env); Label failed(env); Branch(result, &success, &failed); @@ -907,7 +906,7 @@ void GetPropertyByNameStub::GenerateCircuit() Label hasEntry(env); Label noEntry(env); // if branch condition : entry != -1 - Branch(Word32NotEqual(entry, GetInteger32Constant(-1)), &hasEntry, &noEntry); + Branch(Word32NotEqual(entry, GetInt32Constant(-1)), &hasEntry, &noEntry); Bind(&hasEntry); { // PropertyAttributes attr(layoutInfo->GetAttr(entry)) @@ -956,7 +955,7 @@ void GetPropertyByNameStub::GenerateCircuit() Label notNegtiveOne(env); Label negtiveOne(env); // if branch condition : entry != -1 - Branch(Word32NotEqual(entry, GetInteger32Constant(-1)), ¬NegtiveOne, &negtiveOne); + Branch(Word32NotEqual(entry, GetInt32Constant(-1)), ¬NegtiveOne, &negtiveOne); Bind(¬NegtiveOne); { // auto value = dict->GetValue(entry) @@ -1040,10 +1039,10 @@ void FastModStub::GenerateCircuit() { Label xGtZero(env); Label xGtZeroAndyGtZero(env); - Branch(Int32GreaterThan(*intX, GetInteger32Constant(0)), &xGtZero, &xNotIntOryNotInt); + Branch(Int32GreaterThan(*intX, GetInt32Constant(0)), &xGtZero, &xNotIntOryNotInt); Bind(&xGtZero); { - Branch(Int32GreaterThan(*intY, GetInteger32Constant(0)), &xGtZeroAndyGtZero, &xNotIntOryNotInt); + Branch(Int32GreaterThan(*intY, GetInt32Constant(0)), &xGtZeroAndyGtZero, &xNotIntOryNotInt); Bind(&xGtZeroAndyGtZero); { intX = Int32Mod(*intX, *intY); @@ -1173,14 +1172,14 @@ void FastTypeOfStub::GenerateCircuit() DEFVARIABLE(holder, MachineType::TAGGED_POINTER_TYPE, obj); AddrShift gConstOffset = PtrAdd(thread, GetPtrConstant(panda::ecmascript::JSThread::GetGlobalConstantOffset())); AddrShift booleanIndex = GetGlobalConstantString(ConstantIndex::UNDEFINED_STRING_INDEX); - AddrShift gConstUndefindStr = Load(TAGGED_TYPE, gConstOffset, booleanIndex); + AddrShift gConstUndefindStr = Load(MachineType::TAGGED_TYPE, gConstOffset, booleanIndex); DEFVARIABLE(resultRep, MachineType::TAGGED_TYPE, gConstUndefindStr); Label objIsTrue(env); Label objNotTrue(env); Label exit(env); Label defaultLabel(env); AddrShift gConstBooleanStr = Load( - TAGGED_TYPE, gConstOffset, GetGlobalConstantString(ConstantIndex::BOOLEAN_STRING_INDEX)); + MachineType::TAGGED_TYPE, gConstOffset, GetGlobalConstantString(ConstantIndex::BOOLEAN_STRING_INDEX)); Branch(Word64Equal(obj, GetWord64Constant(JSTaggedValue::VALUE_TRUE)), &objIsTrue, &objNotTrue); Bind(&objIsTrue); { @@ -1205,7 +1204,8 @@ void FastTypeOfStub::GenerateCircuit() Bind(&objIsNull); { resultRep = Load( - TAGGED_TYPE, gConstOffset, GetGlobalConstantString(ConstantIndex::OBJECT_STRING_INDEX)); + MachineType::TAGGED_TYPE, gConstOffset, + GetGlobalConstantString(ConstantIndex::OBJECT_STRING_INDEX)); Jump(&exit); } Bind(&objNotNull); @@ -1216,7 +1216,7 @@ void FastTypeOfStub::GenerateCircuit() &objNotUndefined); Bind(&objIsUndefined); { - resultRep = Load(TAGGED_TYPE, gConstOffset, + resultRep = Load(MachineType::TAGGED_TYPE, gConstOffset, GetGlobalConstantString(ConstantIndex::UNDEFINED_STRING_INDEX)); Jump(&exit); } @@ -1238,7 +1238,8 @@ void FastTypeOfStub::GenerateCircuit() Bind(&objIsString); { resultRep = Load( - TAGGED_TYPE, gConstOffset, GetGlobalConstantString(ConstantIndex::STRING_STRING_INDEX)); + MachineType::TAGGED_TYPE, gConstOffset, + GetGlobalConstantString(ConstantIndex::STRING_STRING_INDEX)); Jump(&exit); } Bind(&objNotString); @@ -1248,7 +1249,7 @@ void FastTypeOfStub::GenerateCircuit() Branch(IsSymbol(obj), &objIsSymbol, &objNotSymbol); Bind(&objIsSymbol); { - resultRep = Load(TAGGED_TYPE, gConstOffset, + resultRep = Load(MachineType::TAGGED_TYPE, gConstOffset, GetGlobalConstantString(ConstantIndex::SYMBOL_STRING_INDEX)); Jump(&exit); } @@ -1260,13 +1261,15 @@ void FastTypeOfStub::GenerateCircuit() Bind(&objIsCallable); { resultRep = Load( - TAGGED_TYPE, gConstOffset, GetGlobalConstantString(ConstantIndex::FUNCTION_STRING_INDEX)); + MachineType::TAGGED_TYPE, gConstOffset, + GetGlobalConstantString(ConstantIndex::FUNCTION_STRING_INDEX)); Jump(&exit); } Bind(&objNotCallable); { resultRep = Load( - TAGGED_TYPE, gConstOffset, GetGlobalConstantString(ConstantIndex::OBJECT_STRING_INDEX)); + MachineType::TAGGED_TYPE, gConstOffset, + GetGlobalConstantString(ConstantIndex::OBJECT_STRING_INDEX)); Jump(&exit); } } @@ -1280,7 +1283,8 @@ void FastTypeOfStub::GenerateCircuit() Bind(&objIsNum); { resultRep = Load( - TAGGED_TYPE, gConstOffset, GetGlobalConstantString(ConstantIndex::NUMBER_STRING_INDEX)); + MachineType::TAGGED_TYPE, gConstOffset, + GetGlobalConstantString(ConstantIndex::NUMBER_STRING_INDEX)); Jump(&exit); } Bind(&objNotNum); @@ -1321,7 +1325,7 @@ void GetPropertyByValueStub::GenerateCircuit() auto env = GetEnvironment(); AddrShift thread = PtrArgument(0); AddrShift receiver = PtrArgument(1); - DEFVARIABLE(key, TAGGED_TYPE, PtrArgument(2)); /* 2 : 3rd parameter is key */ + DEFVARIABLE(key, MachineType::TAGGED_TYPE, PtrArgument(2)); /* 2 : 3rd parameter is key */ Label isNumberOrStringSymbol(env); Label notNumber(env); @@ -1343,7 +1347,7 @@ void GetPropertyByValueStub::GenerateCircuit() AddrShift index = TryToElementsIndex(*key); Label validIndex(env); Label notValidIndex(env); - Branch(Int32GreaterThanOrEqual(index, GetInteger32Constant(0)), &validIndex, ¬ValidIndex); + Branch(Int32GreaterThanOrEqual(index, GetInt32Constant(0)), &validIndex, ¬ValidIndex); Bind(&validIndex); { auto getPropertyByIndex = GET_STUBDESCRIPTOR(GetPropertyByIndex); @@ -1398,7 +1402,7 @@ void SetPropertyByValueStub::GenerateCircuit() auto env = GetEnvironment(); AddrShift thread = PtrArgument(0); AddrShift receiver = PtrArgument(1); - DEFVARIABLE(key, TAGGED_TYPE, PtrArgument(2)); /* 2 : 3rd parameter is key */ + DEFVARIABLE(key, MachineType::TAGGED_TYPE, PtrArgument(2)); /* 2 : 3rd parameter is key */ AddrShift value = Int64Argument(3); /* 3 : 4th parameter is value */ Label isNumberOrStringSymbol(env); @@ -1421,7 +1425,7 @@ void SetPropertyByValueStub::GenerateCircuit() AddrShift index = TryToElementsIndex(*key); Label validIndex(env); Label notValidIndex(env); - Branch(Int32GreaterThanOrEqual(index, GetInteger32Constant(0)), &validIndex, ¬ValidIndex); + Branch(Int32GreaterThanOrEqual(index, GetInt32Constant(0)), &validIndex, ¬ValidIndex); Bind(&validIndex); { auto setPropertyByIndex = GET_STUBDESCRIPTOR(SetPropertyByIndex); @@ -1470,4 +1474,4 @@ void SetPropertyByValueStub::GenerateCircuit() Bind(&exit); Return(GetHoleConstant()); } -} // namespace kungfu \ No newline at end of file +} // namespace kungfu diff --git a/ecmascript/compiler/llvm_ir_builder.cpp b/ecmascript/compiler/llvm_ir_builder.cpp index 373550d8e0..13de635722 100644 --- a/ecmascript/compiler/llvm_ir_builder.cpp +++ b/ecmascript/compiler/llvm_ir_builder.cpp @@ -1393,19 +1393,19 @@ LLVMTypeRef LLVMStubModule::GetLLVMFunctionTypeStubDescriptor(StubDescriptor *st LLVMTypeRef LLVMStubModule::ConvertLLVMTypeFromMachineType(MachineType type) { static std::map machineTypeMap = { - {MachineType::NONE_TYPE, LLVMVoidType()}, - {MachineType::BOOL_TYPE, LLVMInt1Type()}, - {MachineType::INT8_TYPE, LLVMInt8Type()}, - {MachineType::INT16_TYPE, LLVMInt16Type()}, - {MachineType::INT32_TYPE, LLVMInt32Type()}, - {MachineType::INT64_TYPE, LLVMInt64Type()}, - {MachineType::UINT8_TYPE, LLVMInt8Type()}, - {MachineType::UINT16_TYPE, LLVMInt16Type()}, - {MachineType::UINT32_TYPE, LLVMInt32Type()}, - {MachineType::UINT64_TYPE, LLVMInt64Type()}, - {MachineType::FLOAT32_TYPE, LLVMFloatType()}, - {MachineType::FLOAT64_TYPE, LLVMDoubleType()}, - {MachineType::TAGGED_TYPE, LLVMInt64Type()}, + {MachineType::NONE_TYPE, LLVMVoidType()}, + {MachineType::BOOL_TYPE, LLVMInt1Type()}, + {MachineType::INT8_TYPE, LLVMInt8Type()}, + {MachineType::INT16_TYPE, LLVMInt16Type()}, + {MachineType::INT32_TYPE, LLVMInt32Type()}, + {MachineType::INT64_TYPE, LLVMInt64Type()}, + {MachineType::UINT8_TYPE, LLVMInt8Type()}, + {MachineType::UINT16_TYPE, LLVMInt16Type()}, + {MachineType::UINT32_TYPE, LLVMInt32Type()}, + {MachineType::UINT64_TYPE, LLVMInt64Type()}, + {MachineType::FLOAT32_TYPE, LLVMFloatType()}, + {MachineType::FLOAT64_TYPE, LLVMDoubleType()}, + {MachineType::TAGGED_TYPE, LLVMInt64Type()}, }; return machineTypeMap[type]; } diff --git a/ecmascript/compiler/machine_type.h b/ecmascript/compiler/machine_type.h index 3530cd14dd..f17f60808d 100644 --- a/ecmascript/compiler/machine_type.h +++ b/ecmascript/compiler/machine_type.h @@ -17,7 +17,7 @@ #define ECMASCRIPT_COMPILER_MACHINE_TYPE_H namespace kungfu { -enum MachineType { +enum class MachineType { NONE_TYPE, BOOL_TYPE, INT8_TYPE, diff --git a/ecmascript/compiler/stub.cpp b/ecmascript/compiler/stub.cpp index 2da08e6e43..004977d4ee 100644 --- a/ecmascript/compiler/stub.cpp +++ b/ecmascript/compiler/stub.cpp @@ -366,7 +366,7 @@ AddrShift Stub::FixLoadType(AddrShift x) AddrShift Stub::LoadFromObject(MachineType type, AddrShift object, AddrShift offset) { - AddrShift elementsOffset = GetInteger32Constant(panda::ecmascript::JSObject::ELEMENTS_OFFSET); + AddrShift elementsOffset = GetInt32Constant(panda::ecmascript::JSObject::ELEMENTS_OFFSET); if (PtrValueCode() == ValueCode::INT64) { elementsOffset = SExtInt32ToInt64(elementsOffset); } @@ -374,8 +374,8 @@ AddrShift Stub::LoadFromObject(MachineType type, AddrShift object, AddrShift off AddrShift elements = Load(MachineType::UINT64_TYPE, object, elementsOffset); // load index in tagged array AddrShift dataOffset = - Int32Add(GetInteger32Constant(panda::coretypes::Array::GetDataOffset()), - Int32Mul(offset, GetInteger32Constant(panda::ecmascript::JSTaggedValue::TaggedTypeSize()))); + Int32Add(GetInt32Constant(panda::coretypes::Array::GetDataOffset()), + Int32Mul(offset, GetInt32Constant(panda::ecmascript::JSTaggedValue::TaggedTypeSize()))); if (PtrValueCode() == ValueCode::INT64) { dataOffset = SExtInt32ToInt64(dataOffset); } @@ -387,22 +387,22 @@ AddrShift Stub::FindElementFromNumberDictionary(AddrShift thread, AddrShift elem auto env = GetEnvironment(); Label subentry(env); env->PushCurrentLabel(&subentry); - DEFVARIABLE(result, INT32_TYPE, GetInteger32Constant(-1)); + DEFVARIABLE(result, MachineType::INT32_TYPE, GetInt32Constant(-1)); Label exit(env); AddrShift capcityoffset = PtrMul(GetPtrConstant(panda::ecmascript::JSTaggedValue::TaggedTypeSize()), GetPtrConstant(panda::ecmascript::TaggedHashTable::SIZE_INDEX)); AddrShift dataoffset = GetPtrConstant(panda::coretypes::Array::GetDataOffset()); - AddrShift capacity = TaggedCastToInt32(Load(TAGGED_TYPE, elements, PtrAdd(dataoffset, capcityoffset))); - DEFVARIABLE(count, INT32_TYPE, GetInteger32Constant(1)); + AddrShift capacity = TaggedCastToInt32(Load(MachineType::TAGGED_TYPE, elements, PtrAdd(dataoffset, capcityoffset))); + DEFVARIABLE(count, MachineType::INT32_TYPE, GetInt32Constant(1)); AddrShift pKey = Alloca(static_cast(MachineRep::K_WORD32)); - AddrShift keyStore = Store(INT32_TYPE, pKey, GetPtrConstant(0), TaggedCastToInt32(key)); + AddrShift keyStore = Store(MachineType::INT32_TYPE, pKey, GetPtrConstant(0), TaggedCastToInt32(key)); StubDescriptor *getHash32Descriptor = GET_STUBDESCRIPTOR(GetHash32); - AddrShift len = GetInteger32Constant(sizeof(int) / sizeof(uint8_t)); + AddrShift len = GetInt32Constant(sizeof(int) / sizeof(uint8_t)); AddrShift hash = CallRuntime(getHash32Descriptor, thread, GetWord64Constant(FAST_STUB_ID(GetHash32)), keyStore, {pKey, len}); - DEFVARIABLE(entry, INT32_TYPE, Word32And(hash, Int32Sub(capacity, GetInteger32Constant(1)))); + DEFVARIABLE(entry, MachineType::INT32_TYPE, Word32And(hash, Int32Sub(capacity, GetInt32Constant(1)))); Label loopHead(env); Label loopEnd(env); Label afterLoop(env); @@ -419,7 +419,7 @@ AddrShift Stub::FindElementFromNumberDictionary(AddrShift thread, AddrShift elem Label notUndefined(env); Branch(TaggedIsUndefined(element), &isUndefined, ¬Undefined); Bind(&isUndefined); - result = GetInteger32Constant(-1); + result = GetInt32Constant(-1); Jump(&exit); Bind(¬Undefined); Label isMatch(env); @@ -432,7 +432,7 @@ AddrShift Stub::FindElementFromNumberDictionary(AddrShift thread, AddrShift elem Jump(&loopEnd); Bind(&loopEnd); entry = GetNextPositionForHash(*entry, *count, capacity); - count = Int32Add(*count, GetInteger32Constant(1)); + count = Int32Add(*count, GetInt32Constant(1)); LoopEnd(&loopHead); Bind(&exit); auto ret = *result; @@ -446,7 +446,7 @@ AddrShift Stub::IsMatchInNumberDictionary(AddrShift key, AddrShift other) Label entry(env); env->PushCurrentLabel(&entry); Label exit(env); - DEFVARIABLE(result, BOOL_TYPE, FalseConstant()); + DEFVARIABLE(result, MachineType::BOOL_TYPE, FalseConstant()); Label isHole(env); Label notHole(env); Label isUndefined(env); @@ -485,16 +485,17 @@ AddrShift Stub::GetKeyFromNumberDictionary(AddrShift elements, AddrShift entry) Label subentry(env); env->PushCurrentLabel(&subentry); Label exit(env); - DEFVARIABLE(result, TAGGED_TYPE, GetUndefinedConstant()); + DEFVARIABLE(result, MachineType::TAGGED_TYPE, GetUndefinedConstant()); Label ltZero(env); Label notLtZero(env); Label gtLength(env); Label notGtLength(env); - AddrShift dictionaryLength = Load(INT32_TYPE, elements, GetPtrConstant(panda::coretypes::Array::GetLengthOffset())); + AddrShift dictionaryLength = + Load(MachineType::INT32_TYPE, elements, GetPtrConstant(panda::coretypes::Array::GetLengthOffset())); AddrShift arrayIndex = - Int32Add(GetInteger32Constant(panda::ecmascript::NumberDictionary::TABLE_HEADER_SIZE), - Int32Mul(entry, GetInteger32Constant(panda::ecmascript::NumberDictionary::ENTRY_SIZE))); - Branch(Int32LessThan(arrayIndex, GetInteger32Constant(0)), <Zero, ¬LtZero); + Int32Add(GetInt32Constant(panda::ecmascript::NumberDictionary::TABLE_HEADER_SIZE), + Int32Mul(entry, GetInt32Constant(panda::ecmascript::NumberDictionary::ENTRY_SIZE))); + Branch(Int32LessThan(arrayIndex, GetInt32Constant(0)), <Zero, ¬LtZero); Bind(<Zero); Jump(&exit); Bind(¬LtZero); @@ -517,14 +518,14 @@ AddrShift Stub::FindEntryFromNameDictionary(AddrShift thread, AddrShift elements Label funcEntry(env); env->PushCurrentLabel(&funcEntry); Label exit(env); - DEFVARIABLE(result, INT32_TYPE, GetInteger32Constant(-1)); + DEFVARIABLE(result, MachineType::INT32_TYPE, GetInt32Constant(-1)); AddrShift capcityoffset = PtrMul(GetPtrConstant(panda::ecmascript::JSTaggedValue::TaggedTypeSize()), GetPtrConstant(panda::ecmascript::TaggedHashTable::SIZE_INDEX)); AddrShift dataoffset = GetPtrConstant(panda::coretypes::Array::GetDataOffset()); - AddrShift capacity = TaggedCastToInt32(Load(TAGGED_TYPE, elements, PtrAdd(dataoffset, capcityoffset))); - DEFVARIABLE(count, INT32_TYPE, GetInteger32Constant(1)); - DEFVARIABLE(hash, INT32_TYPE, GetInteger32Constant(0)); + AddrShift capacity = TaggedCastToInt32(Load(MachineType::TAGGED_TYPE, elements, PtrAdd(dataoffset, capcityoffset))); + DEFVARIABLE(count, MachineType::INT32_TYPE, GetInt32Constant(1)); + DEFVARIABLE(hash, MachineType::INT32_TYPE, GetInt32Constant(0)); // NameDictionary::hash Label isSymbol(env); Label notSymbol(env); @@ -535,7 +536,8 @@ AddrShift Stub::FindEntryFromNameDictionary(AddrShift thread, AddrShift elements Branch(IsSymbol(key), &isSymbol, ¬Symbol); Bind(&isSymbol); { - hash = TaggedCastToInt32(Load(TAGGED_TYPE, key, GetPtrConstant(panda::ecmascript::JSSymbol::HASHFIELD_OFFSET))); + hash = TaggedCastToInt32(Load(MachineType::TAGGED_TYPE, key, + GetPtrConstant(panda::ecmascript::JSSymbol::HASHFIELD_OFFSET))); Jump(&beforeDefineHash); } Bind(¬Symbol); @@ -556,7 +558,7 @@ AddrShift Stub::FindEntryFromNameDictionary(AddrShift thread, AddrShift elements } Bind(&beforeDefineHash); // GetFirstPosition(hash, size) - DEFVARIABLE(entry, INT32_TYPE, Word32And(*hash, Int32Sub(capacity, GetInteger32Constant(1)))); + DEFVARIABLE(entry, MachineType::INT32_TYPE, Word32And(*hash, Int32Sub(capacity, GetInt32Constant(1)))); Jump(&loopHead); LoopBegin(&loopHead); { @@ -577,7 +579,7 @@ AddrShift Stub::FindEntryFromNameDictionary(AddrShift thread, AddrShift elements { Bind(&isUndefined); { - result = GetInteger32Constant(-1); + result = GetInt32Constant(-1); Jump(&exit); } Bind(¬Undefined); @@ -603,7 +605,7 @@ AddrShift Stub::FindEntryFromNameDictionary(AddrShift thread, AddrShift elements Bind(&loopEnd); { entry = GetNextPositionForHash(*entry, *count, capacity); - count = Int32Add(*count, GetInteger32Constant(1)); + count = Int32Add(*count, GetInt32Constant(1)); LoopEnd(&loopHead); } } @@ -619,7 +621,7 @@ AddrShift Stub::JSObjectGetProperty(AddrShift obj, AddrShift hClass, AddrShift a Label entry(env); env->PushCurrentLabel(&entry); Label exit(env); - DEFVARIABLE(result, TAGGED_TYPE, GetUndefinedConstant()); + DEFVARIABLE(result, MachineType::TAGGED_TYPE, GetUndefinedConstant()); Label inlinedProp(env); Label notInlinedProp(env); AddrShift attrOffset = PropAttrGetOffset(attr); @@ -632,17 +634,18 @@ AddrShift Stub::JSObjectGetProperty(AddrShift obj, AddrShift hClass, AddrShift a AddrShift propOffset = Int32Sub( ChangeInt64ToInt32(hClassObjectSize), Int32Mul(Int32Sub( - GetInteger32Constant(panda::ecmascript::JSHClass::DEFAULT_CAPACITY_OF_IN_OBJECTS), attrOffset), - GetInteger32Constant(panda::ecmascript::JSTaggedValue::TaggedTypeSize()))); - result = Load(UINT64_TYPE, obj, ZExtInt32ToInt64(propOffset)); + GetInt32Constant(panda::ecmascript::JSHClass::DEFAULT_CAPACITY_OF_IN_OBJECTS), attrOffset), + GetInt32Constant(panda::ecmascript::JSTaggedValue::TaggedTypeSize()))); + result = Load(MachineType::UINT64_TYPE, obj, ZExtInt32ToInt64(propOffset)); Jump(&exit); } Bind(¬InlinedProp); { // compute outOfLineProp offset, get it and return - AddrShift array = Load(UINT64_TYPE, obj, GetPtrConstant(panda::ecmascript::JSObject::PROPERTIES_OFFSET)); + AddrShift array = + Load(MachineType::UINT64_TYPE, obj, GetPtrConstant(panda::ecmascript::JSObject::PROPERTIES_OFFSET)); result = GetValueFromTaggedArray(array, Int32Sub(attrOffset, - GetInteger32Constant(panda::ecmascript::JSHClass::DEFAULT_CAPACITY_OF_IN_OBJECTS))); + GetInt32Constant(panda::ecmascript::JSHClass::DEFAULT_CAPACITY_OF_IN_OBJECTS))); Jump(&exit); } } @@ -655,7 +658,7 @@ AddrShift Stub::JSObjectGetProperty(AddrShift obj, AddrShift hClass, AddrShift a void Stub::ThrowTypeAndReturn(AddrShift thread, int messageId, AddrShift val) { StubDescriptor *throwTypeError = GET_STUBDESCRIPTOR(ThrowTypeError); - AddrShift msgIntId = GetInteger32Constant(messageId); + AddrShift msgIntId = GetInt32Constant(messageId); CallRuntime(throwTypeError, thread, GetWord64Constant(FAST_STUB_ID(ThrowTypeError)), {thread, msgIntId}); Return(val); } @@ -666,7 +669,7 @@ AddrShift Stub::TaggedToRepresentation(AddrShift value) Label entry(env); env->PushCurrentLabel(&entry); Label exit(env); - DEFVARIABLE(resultRep, INT64_TYPE, + DEFVARIABLE(resultRep, MachineType::INT64_TYPE, GetWord64Constant(static_cast(panda::ecmascript::Representation::OBJECT))); Label isInt(env); Label notInt(env); @@ -705,7 +708,7 @@ AddrShift Stub::UpdateRepresention(AddrShift oldRep, AddrShift value) Label entry(env); env->PushCurrentLabel(&entry); Label exit(env); - DEFVARIABLE(resultRep, INT64_TYPE, oldRep); + DEFVARIABLE(resultRep, MachineType::INT64_TYPE, oldRep); Label isMixedRep(env); Label notMiexedRep(env); Branch(Word64Equal(oldRep, GetWord64Constant(static_cast(panda::ecmascript::Representation::MIXED))), @@ -807,13 +810,13 @@ AddrShift Stub::TaggedIsString(AddrShift obj) Label entry(env); env->PushCurrentLabel(&entry); Label exit(env); - DEFVARIABLE(result, BOOL_TYPE, FalseConstant()); + DEFVARIABLE(result, MachineType::BOOL_TYPE, FalseConstant()); Label isHeapObject(env); Branch(TaggedIsHeapObject(obj), &isHeapObject, &exit); Bind(&isHeapObject); { result = Word32Equal(GetObjectType(LoadHClass(obj)), - GetInteger32Constant(static_cast(panda::ecmascript::JSType::STRING))); + GetInt32Constant(static_cast(panda::ecmascript::JSType::STRING))); Jump(&exit); } Bind(&exit); @@ -828,21 +831,21 @@ AddrShift Stub::TaggedIsStringOrSymbol(AddrShift obj) Label entry(env); env->PushCurrentLabel(&entry); Label exit(env); - DEFVARIABLE(result, BOOL_TYPE, FalseConstant()); + DEFVARIABLE(result, MachineType::BOOL_TYPE, FalseConstant()); Label isHeapObject(env); Branch(TaggedIsHeapObject(obj), &isHeapObject, &exit); Bind(&isHeapObject); { AddrShift objType = GetObjectType(LoadHClass(obj)); result = Word32Equal(objType, - GetInteger32Constant(static_cast(panda::ecmascript::JSType::STRING))); + GetInt32Constant(static_cast(panda::ecmascript::JSType::STRING))); Label isString(env); Label notString(env); Branch(*result, &exit, ¬String); Bind(¬String); { result = Word32Equal(objType, - GetInteger32Constant(static_cast(panda::ecmascript::JSType::SYMBOL))); + GetInt32Constant(static_cast(panda::ecmascript::JSType::SYMBOL))); Jump(&exit); } } @@ -858,8 +861,8 @@ AddrShift Stub::IsUtf16String(AddrShift string) AddrShift len = Load(MachineType::UINT32_TYPE, string, GetPtrConstant(panda::ecmascript::EcmaString::GetLengthOffset())); return Word32Equal( - Word32And(len, GetInteger32Constant(panda::ecmascript::EcmaString::STRING_COMPRESSED_BIT)), - GetInteger32Constant(panda::ecmascript::EcmaString::STRING_UNCOMPRESSED)); + Word32And(len, GetInt32Constant(panda::ecmascript::EcmaString::STRING_COMPRESSED_BIT)), + GetInt32Constant(panda::ecmascript::EcmaString::STRING_UNCOMPRESSED)); } AddrShift Stub::IsUtf8String(AddrShift string) @@ -868,8 +871,8 @@ AddrShift Stub::IsUtf8String(AddrShift string) AddrShift len = Load(MachineType::UINT32_TYPE, string, GetPtrConstant(panda::ecmascript::EcmaString::GetLengthOffset())); return Word32Equal( - Word32And(len, GetInteger32Constant(panda::ecmascript::EcmaString::STRING_COMPRESSED_BIT)), - GetInteger32Constant(panda::ecmascript::EcmaString::STRING_COMPRESSED)); + Word32And(len, GetInt32Constant(panda::ecmascript::EcmaString::STRING_COMPRESSED_BIT)), + GetInt32Constant(panda::ecmascript::EcmaString::STRING_COMPRESSED)); } AddrShift Stub::IsInternalString(AddrShift string) @@ -878,15 +881,15 @@ AddrShift Stub::IsInternalString(AddrShift string) AddrShift len = Load(MachineType::UINT32_TYPE, string, GetPtrConstant(panda::ecmascript::EcmaString::GetLengthOffset())); return Word32NotEqual( - Word32And(len, GetInteger32Constant(panda::ecmascript::EcmaString::STRING_INTERN_BIT)), - GetInteger32Constant(0)); + Word32And(len, GetInt32Constant(panda::ecmascript::EcmaString::STRING_INTERN_BIT)), + GetInt32Constant(0)); } AddrShift Stub::IsDigit(AddrShift ch) { return TruncInt32ToInt1( - Word32And(SExtInt1ToInt32(Int32LessThanOrEqual(ch, GetInteger32Constant('9'))), - SExtInt1ToInt32(Int32GreaterThanOrEqual(ch, GetInteger32Constant('0'))))); + Word32And(SExtInt1ToInt32(Int32LessThanOrEqual(ch, GetInt32Constant('9'))), + SExtInt1ToInt32(Int32GreaterThanOrEqual(ch, GetInt32Constant('0'))))); } AddrShift Stub::StringToElementIndex(AddrShift string) @@ -895,19 +898,19 @@ AddrShift Stub::StringToElementIndex(AddrShift string) Label entry(env); env->PushCurrentLabel(&entry); Label exit(env); - DEFVARIABLE(result, INT32_TYPE, GetInteger32Constant(-1)); + DEFVARIABLE(result, MachineType::INT32_TYPE, GetInt32Constant(-1)); Label greatThanZero(env); Label inRange(env); AddrShift len = Load(MachineType::UINT32_TYPE, string, GetPtrConstant(panda::ecmascript::EcmaString::GetLengthOffset())); - len = Word32LSR(len, GetInteger32Constant(2)); // 2 : 2 means len must be right shift 2 bits - Branch(Word32Equal(len, GetInteger32Constant(0)), &exit, &greatThanZero); + len = Word32LSR(len, GetInt32Constant(2)); // 2 : 2 means len must be right shift 2 bits + Branch(Word32Equal(len, GetInt32Constant(0)), &exit, &greatThanZero); Bind(&greatThanZero); - Branch(Int32GreaterThan(len, GetInteger32Constant(panda::ecmascript::MAX_INDEX_LEN)), &exit, &inRange); + Branch(Int32GreaterThan(len, GetInt32Constant(panda::ecmascript::MAX_INDEX_LEN)), &exit, &inRange); Bind(&inRange); { AddrShift dataUtf16 = PtrAdd(string, GetPtrConstant(panda::ecmascript::EcmaString::GetDataOffset())); - DEFVARIABLE(c, UINT32_TYPE, GetInteger32Constant(0)); + DEFVARIABLE(c, MachineType::UINT32_TYPE, GetInt32Constant(0)); Label isUtf16(env); Label isUtf8(env); Label getChar1(env); @@ -915,34 +918,34 @@ AddrShift Stub::StringToElementIndex(AddrShift string) Branch(isUtf16String, &isUtf16, &isUtf8); Bind(&isUtf16); { - c = ZExtInt16ToInt32(Load(INT16_TYPE, dataUtf16)); + c = ZExtInt16ToInt32(Load(MachineType::INT16_TYPE, dataUtf16)); Jump(&getChar1); } Bind(&isUtf8); { - c = ZExtInt8ToInt32(Load(INT8_TYPE, dataUtf16)); + c = ZExtInt8ToInt32(Load(MachineType::INT8_TYPE, dataUtf16)); Jump(&getChar1); } Bind(&getChar1); { Label isDigitZero(env); Label notDigitZero(env); - Branch(Word32Equal(*c, GetInteger32Constant('0')), &isDigitZero, ¬DigitZero); + Branch(Word32Equal(*c, GetInt32Constant('0')), &isDigitZero, ¬DigitZero); Bind(&isDigitZero); { Label lengthIsOne(env); - Branch(Word32Equal(len, GetInteger32Constant(1)), &lengthIsOne, &exit); + Branch(Word32Equal(len, GetInt32Constant(1)), &lengthIsOne, &exit); Bind(&lengthIsOne); { - result = GetInteger32Constant(0); + result = GetInt32Constant(0); Jump(&exit); } } Bind(¬DigitZero); { Label isDigit(env); - DEFVARIABLE(i, UINT32_TYPE, GetInteger32Constant(1)); - DEFVARIABLE(n, UINT32_TYPE, Int32Sub(*c, GetInteger32Constant('0'))); + DEFVARIABLE(i, MachineType::UINT32_TYPE, GetInt32Constant(1)); + DEFVARIABLE(n, MachineType::UINT32_TYPE, Int32Sub(*c, GetInt32Constant('0'))); Branch(IsDigit(*c), &isDigit, &exit); Label loopHead(env); Label loopEnd(env); @@ -959,12 +962,12 @@ AddrShift Stub::StringToElementIndex(AddrShift string) { // 2 : 2 means utf16 char width is two bytes auto charOffset = PtrMul(ChangeInt32ToPointer(*i), GetPtrConstant(2)); - c = ZExtInt16ToInt32(Load(INT16_TYPE, dataUtf16, charOffset)); + c = ZExtInt16ToInt32(Load(MachineType::INT16_TYPE, dataUtf16, charOffset)); Jump(&getChar2); } Bind(¬Utf16); { - c = ZExtInt8ToInt32(Load(INT8_TYPE, dataUtf16, ChangeInt32ToPointer(*i))); + c = ZExtInt8ToInt32(Load(MachineType::INT8_TYPE, dataUtf16, ChangeInt32ToPointer(*i))); Jump(&getChar2); } Bind(&getChar2); @@ -975,9 +978,9 @@ AddrShift Stub::StringToElementIndex(AddrShift string) Bind(&isDigit2); { // 10 means the base of digit is 10. - n = Int32Add(Int32Mul(*n, GetInteger32Constant(10)), - Int32Sub(*c, GetInteger32Constant('0'))); - i = Int32Add(*i, GetInteger32Constant(1)); + n = Int32Add(Int32Mul(*n, GetInt32Constant(10)), + Int32Sub(*c, GetInt32Constant('0'))); + i = Int32Add(*i, GetInt32Constant(1)); Branch(Int32LessThan(*i, len), &loopEnd, &afterLoop); } Bind(¬Digit2); @@ -989,7 +992,7 @@ AddrShift Stub::StringToElementIndex(AddrShift string) Bind(&afterLoop); { Label lessThanMaxIndex(env); - Branch(Word32LessThan(*n, GetInteger32Constant(panda::ecmascript::JSObject::MAX_ELEMENT_INDEX)), + Branch(Word32LessThan(*n, GetInt32Constant(panda::ecmascript::JSObject::MAX_ELEMENT_INDEX)), &lessThanMaxIndex, &exit); Bind(&lessThanMaxIndex); { @@ -1015,7 +1018,7 @@ AddrShift Stub::TryToElementsIndex(AddrShift key) Label isKeyInt(env); Label notKeyInt(env); - DEFVARIABLE(resultKey, INT32_TYPE, GetInteger32Constant(-1)); + DEFVARIABLE(resultKey, MachineType::INT32_TYPE, GetInt32Constant(-1)); Branch(TaggedIsInt(key), &isKeyInt, ¬KeyInt); Bind(&isKeyInt); { @@ -1055,4 +1058,4 @@ AddrShift Stub::TryToElementsIndex(AddrShift key) env->PopCurrentLabel(); return ret; } -} // namespace kungfu \ No newline at end of file +} // namespace kungfu diff --git a/ecmascript/compiler/stub.h b/ecmascript/compiler/stub.h index 3a12f0bab7..a4ae1826dc 100644 --- a/ecmascript/compiler/stub.h +++ b/ecmascript/compiler/stub.h @@ -21,11 +21,13 @@ #include "ecmascript/compiler/circuit.h" #include "ecmascript/compiler/circuit_builder.h" #include "ecmascript/compiler/gate.h" +#include "ecmascript/compiler/machine_type.h" #include "ecmascript/compiler/stub_descriptor.h" #include "ecmascript/js_function.h" #include "ecmascript/js_object.h" #include "ecmascript/js_tagged_value.h" #include "ecmascript/layout_info.h" +#include "ecmascript/message_string.h" #include "ecmascript/tagged_dictionary.h" namespace kungfu { @@ -394,7 +396,7 @@ public: return &env_; } // constant - AddrShift GetInteger32Constant(int32_t value) + AddrShift GetInt32Constant(int32_t value) { return env_.GetCircuitBuilder().NewIntegerConstant(value); }; @@ -409,13 +411,13 @@ public: return GetWord64Constant(value); #endif #ifdef PANDA_TARGET_X86 - return GetInteger32Constant(value); + return GetInt32Constant(value); #endif #ifdef PANDA_TARGET_ARM64 return GetWord64Constant(value); #endif #ifdef PANDA_TARGET_ARM32 - return GetInteger32Constant(value); + return GetInt32Constant(value); #endif } @@ -437,12 +439,12 @@ public: AddrShift TrueConstant() { - return TruncInt32ToInt1(GetInteger32Constant(1)); + return TruncInt32ToInt1(GetInt32Constant(1)); } AddrShift FalseConstant() { - return TruncInt32ToInt1(GetInteger32Constant(0)); + return TruncInt32ToInt1(GetInt32Constant(0)); } AddrShift GetBooleanConstant(bool value) @@ -788,7 +790,7 @@ public: AddrShift TaggedIsDouble(AddrShift x) { return Word32Equal(Word32Or(SExtInt1ToInt32(TaggedIsInt(x)), SExtInt1ToInt32(TaggedIsObject(x))), - GetInteger32Constant(0)); + GetInt32Constant(0)); } AddrShift TaggedIsObject(AddrShift x) @@ -832,7 +834,7 @@ public: { return TruncInt32ToInt1( Word32And(SExtInt1ToInt32(TaggedIsObject(x)), - SExtInt1ToInt32(Word32Equal(SExtInt1ToInt32(TaggedIsSpecial(x)), GetInteger32Constant(0))))); + SExtInt1ToInt32(Word32Equal(SExtInt1ToInt32(TaggedIsSpecial(x)), GetInt32Constant(0))))); } AddrShift TaggedIsString(AddrShift obj); @@ -841,15 +843,15 @@ public: AddrShift GetNextPositionForHash(AddrShift last, AddrShift count, AddrShift size) { - auto nextOffset = Word32LSR(Int32Mul(count, Int32Add(count, GetInteger32Constant(1))), - GetInteger32Constant(1)); - return Word32And(Int32Add(last, nextOffset), Int32Sub(size, GetInteger32Constant(1))); + auto nextOffset = Word32LSR(Int32Mul(count, Int32Add(count, GetInt32Constant(1))), + GetInt32Constant(1)); + return Word32And(Int32Add(last, nextOffset), Int32Sub(size, GetInt32Constant(1))); } AddrShift DoubleIsNAN(AddrShift x) { AddrShift diff = DoubleEqual(x, x); - return Word32Equal(SExtInt1ToInt32(diff), GetInteger32Constant(0)); + return Word32Equal(SExtInt1ToInt32(diff), GetInt32Constant(0)); } AddrShift DoubleIsINF(AddrShift x) @@ -858,8 +860,8 @@ public: AddrShift negativeInfinity = GetDoubleConstant(-base::POSITIVE_INFINITY); AddrShift diff1 = DoubleEqual(x, infinity); AddrShift diff2 = DoubleEqual(x, negativeInfinity); - return TruncInt32ToInt1(Word32Or(Word32Equal(SExtInt1ToInt32(diff1), GetInteger32Constant(1)), - Word32Equal(SExtInt1ToInt32(diff2), GetInteger32Constant(1)))); + return TruncInt32ToInt1(Word32Or(Word32Equal(SExtInt1ToInt32(diff1), GetInt32Constant(1)), + Word32Equal(SExtInt1ToInt32(diff2), GetInt32Constant(1)))); } AddrShift IntBuildTagged(AddrShift x) @@ -1023,7 +1025,7 @@ public: AddrShift GetElements(AddrShift object) { - AddrShift elementsOffset = GetInteger32Constant(panda::ecmascript::JSObject::ELEMENTS_OFFSET); + AddrShift elementsOffset = GetInt32Constant(panda::ecmascript::JSObject::ELEMENTS_OFFSET); if (PtrValueCode() == ValueCode::INT64) { elementsOffset = SExtInt32ToInt64(elementsOffset); } @@ -1033,7 +1035,7 @@ public: AddrShift GetProperties(AddrShift object) { - AddrShift propertiesOffset = GetInteger32Constant(panda::ecmascript::JSObject::PROPERTIES_OFFSET); + AddrShift propertiesOffset = GetInt32Constant(panda::ecmascript::JSObject::PROPERTIES_OFFSET); if (PtrValueCode() == ValueCode::INT64) { propertiesOffset = SExtInt32ToInt64(propertiesOffset); } @@ -1043,36 +1045,34 @@ public: AddrShift GetLengthofElements(AddrShift elements) { - return Load(UINT32_TYPE, elements, GetPtrConstant(panda::coretypes::Array::GetLengthOffset())); + return Load(MachineType::UINT32_TYPE, elements, GetPtrConstant(panda::coretypes::Array::GetLengthOffset())); } // object operation AddrShift LoadHClass(AddrShift object) { - return ChangeInt32ToPointer(Load(UINT32_TYPE, object)); + return ChangeInt32ToPointer(Load(MachineType::UINT32_TYPE, object)); } - AddrShift GetObjectType(AddrShift hclass) + AddrShift GetObjectType(AddrShift hClass) { AddrShift bitfieldOffset = GetPtrConstant(panda::ecmascript::JSHClass::BIT_FIELD_OFFSET); - - AddrShift bitfield = Load(INT64_TYPE, hclass, bitfieldOffset); - + AddrShift bitfield = Load(MachineType::UINT64_TYPE, hClass, bitfieldOffset); return ChangeInt64ToInt32( Word64And(bitfield, GetWord64Constant((1LLU << panda::ecmascript::JSHClass::ObjectTypeBits::SIZE) - 1))); } AddrShift IsDictionaryMode(AddrShift object) { - return Word32NotEqual(Word32And(Load(UINT32_TYPE, LoadHClass(object), GetPtrConstant(0)), - GetInteger32Constant(panda::HClass::IS_DICTIONARY_ARRAY)), - GetInteger32Constant(0)); + return Word32NotEqual(Word32And(Load(MachineType::UINT32_TYPE, LoadHClass(object), GetPtrConstant(0)), + GetInt32Constant(panda::HClass::IS_DICTIONARY_ARRAY)), + GetInt32Constant(0)); } AddrShift IsDictionaryModeByHClass(AddrShift hClass) { AddrShift bitfieldOffset = GetPtrConstant(panda::ecmascript::JSHClass::BIT_FIELD_OFFSET); - AddrShift bitfield = Load(INT64_TYPE, hClass, bitfieldOffset); + AddrShift bitfield = Load(MachineType::INT64_TYPE, hClass, bitfieldOffset); return Word64NotEqual( Word64And( Word64LSR(bitfield, GetWord64Constant(panda::ecmascript::JSHClass::IsDictionaryBit::START_BIT)), @@ -1080,11 +1080,10 @@ public: GetWord64Constant(0)); } - AddrShift IsDictionaryElement(AddrShift hclass) + AddrShift IsDictionaryElement(AddrShift hClass) { AddrShift bitfieldOffset = GetPtrConstant(panda::ecmascript::JSHClass::BIT_FIELD_OFFSET); - - AddrShift bitfield = Load(INT64_TYPE, hclass, bitfieldOffset); + AddrShift bitfield = Load(MachineType::INT64_TYPE, hClass, bitfieldOffset); // decode return Word64NotEqual( Word64And( @@ -1098,7 +1097,7 @@ public: AddrShift hclass = LoadHClass(object); AddrShift bitfieldOffset = GetPtrConstant(panda::ecmascript::JSHClass::BIT_FIELD_OFFSET); - AddrShift bitfield = Load(INT64_TYPE, hclass, bitfieldOffset); + AddrShift bitfield = Load(MachineType::INT64_TYPE, hclass, bitfieldOffset); // decode return Word64Equal( Word64And( @@ -1124,10 +1123,10 @@ public: AddrShift IsExtensible(AddrShift object) { - AddrShift hclass = LoadHClass(object); + AddrShift hClass = LoadHClass(object); AddrShift bitfieldOffset = GetPtrConstant(panda::ecmascript::JSHClass::BIT_FIELD_OFFSET); - AddrShift bitfield = Load(INT64_TYPE, hclass, bitfieldOffset); + AddrShift bitfield = Load(MachineType::INT64_TYPE, hClass, bitfieldOffset); // decode return Word64NotEqual( Word64And(Word64LSR(bitfield, GetWord64Constant(panda::ecmascript::JSHClass::ExtensibleBit::START_BIT)), @@ -1138,70 +1137,77 @@ public: AddrShift IsSymbol(AddrShift obj) { AddrShift objectType = GetObjectType(LoadHClass(obj)); - return Word32Equal(objectType, GetInteger32Constant(static_cast(panda::ecmascript::JSType::SYMBOL))); + return Word32Equal(objectType, GetInt32Constant(static_cast(panda::ecmascript::JSType::SYMBOL))); } AddrShift IsString(AddrShift obj) { AddrShift objectType = GetObjectType(LoadHClass(obj)); - return Word32Equal(objectType, GetInteger32Constant(static_cast(panda::ecmascript::JSType::STRING))); + return Word32Equal(objectType, GetInt32Constant(static_cast(panda::ecmascript::JSType::STRING))); } AddrShift IsJsProxy(AddrShift obj) { AddrShift objectType = GetObjectType(LoadHClass(obj)); - return Word32Equal(objectType, GetInteger32Constant(static_cast(panda::ecmascript::JSType::JS_PROXY))); + return Word32Equal(objectType, GetInt32Constant(static_cast(panda::ecmascript::JSType::JS_PROXY))); + } + + AddrShift IsJsArray(AddrShift obj) + { + AddrShift objectType = GetObjectType(LoadHClass(obj)); + return Word32Equal(objectType, GetInt32Constant(static_cast(panda::ecmascript::JSType::JS_ARRAY))); } AddrShift IsWritable(AddrShift attr) { return Word32NotEqual( Word32And( - Word32LSR(attr, GetInteger32Constant(panda::ecmascript::PropertyAttributes::WritableField::START_BIT)), - GetInteger32Constant((1LLU << panda::ecmascript::PropertyAttributes::WritableField::SIZE) - 1)), - GetInteger32Constant(0)); + Word32LSR(attr, GetInt32Constant(panda::ecmascript::PropertyAttributes::WritableField::START_BIT)), + GetInt32Constant((1LLU << panda::ecmascript::PropertyAttributes::WritableField::SIZE) - 1)), + GetInt32Constant(0)); } AddrShift IsAccessor(AddrShift attr) { return Word32NotEqual( Word32And(Word32LSR(attr, - GetInteger32Constant(panda::ecmascript::PropertyAttributes::IsAccessorField::START_BIT)), - GetInteger32Constant((1LLU << panda::ecmascript::PropertyAttributes::IsAccessorField::SIZE) - 1)), - GetInteger32Constant(0)); + GetInt32Constant(panda::ecmascript::PropertyAttributes::IsAccessorField::START_BIT)), + GetInt32Constant((1LLU << panda::ecmascript::PropertyAttributes::IsAccessorField::SIZE) - 1)), + GetInt32Constant(0)); } AddrShift IsInlinedProperty(AddrShift attr) { return Word32NotEqual( Word32And(Word32LSR(attr, - GetInteger32Constant(panda::ecmascript::PropertyAttributes::IsInlinedPropsField::START_BIT)), - GetInteger32Constant((1LLU << panda::ecmascript::PropertyAttributes::IsInlinedPropsField::SIZE) - 1)), - GetInteger32Constant(0)); + GetInt32Constant(panda::ecmascript::PropertyAttributes::IsInlinedPropsField::START_BIT)), + GetInt32Constant((1LLU << panda::ecmascript::PropertyAttributes::IsInlinedPropsField::SIZE) - 1)), + GetInt32Constant(0)); } AddrShift PropAttrGetOffset(AddrShift attr) { return Word32And( - Word32LSR(attr, GetInteger32Constant(panda::ecmascript::PropertyAttributes::OffsetField::START_BIT)), - GetInteger32Constant((1LLU << panda::ecmascript::PropertyAttributes::OffsetField::SIZE) - 1)); + Word32LSR(attr, GetInt32Constant(panda::ecmascript::PropertyAttributes::OffsetField::START_BIT)), + GetInt32Constant((1LLU << panda::ecmascript::PropertyAttributes::OffsetField::SIZE) - 1)); } - AddrShift GetPrototypeFromHClass(AddrShift hclass) + AddrShift GetPrototypeFromHClass(AddrShift hClass) { AddrShift protoOffset = GetPtrConstant(panda::ecmascript::JSHClass::PROTOTYPE_OFFSET); - return Load(TAGGED_TYPE, hclass, protoOffset); + return Load(MachineType::TAGGED_TYPE, hClass, protoOffset); } - AddrShift GetAttributesFromHclass(AddrShift hclass) + AddrShift GetAttributesFromHclass(AddrShift hClass) { AddrShift attrOffset = GetPtrConstant(panda::ecmascript::JSHClass::ATTRIBUTES_OFFSET); - return Load(TAGGED_TYPE, hclass, attrOffset); + return Load(MachineType::TAGGED_TYPE, hClass, attrOffset); } - AddrShift GetPropertiesNumberFromHClass(AddrShift hclass) + AddrShift GetPropertiesNumberFromHClass(AddrShift hClass) { - AddrShift bitfield = Load(INT64_TYPE, hclass, GetPtrConstant(panda::ecmascript::JSHClass::BIT_FIELD_OFFSET)); + AddrShift bitfield = Load(MachineType::INT64_TYPE, hClass, + GetPtrConstant(panda::ecmascript::JSHClass::BIT_FIELD_OFFSET)); AddrShift unusedNonInlinedProps = Word64And(Word64LSR(bitfield, GetWord64Constant(panda::ecmascript::JSHClass::NumberOfUnusedNonInlinedPropsBits::START_BIT)), GetWord64Constant((1LLU << panda::ecmascript::JSHClass::NumberOfUnusedNonInlinedPropsBits::SIZE) - 1)); @@ -1214,9 +1220,9 @@ public: unusedInlinedProps); } - AddrShift GetObjectSizeFromHClass(AddrShift hclass) // NOTE: need to add special case for string and TAGGED_ARRAY + AddrShift GetObjectSizeFromHClass(AddrShift hClass) // NOTE: need to add special case for string and TAGGED_ARRAY { - return Load(UINT64_TYPE, hclass, GetPtrConstant(panda::ecmascript::JSHClass::OBJECT_SIZE_OFFSET)); + return Load(MachineType::UINT64_TYPE, hClass, GetPtrConstant(panda::ecmascript::JSHClass::OBJECT_SIZE_OFFSET)); } void StoreElement(AddrShift elements, AddrShift index, AddrShift value) @@ -1224,7 +1230,7 @@ public: AddrShift offset = PtrMul(ChangeInt32ToPointer(index), GetPtrConstant(panda::ecmascript::JSTaggedValue::TaggedTypeSize())); AddrShift dataOffset = PtrAdd(offset, GetPtrConstant(panda::coretypes::Array::GetDataOffset())); - Store(TAGGED_TYPE, elements, dataOffset, value); + Store(MachineType::TAGGED_TYPE, elements, dataOffset, value); } void ThrowTypeAndReturn(AddrShift thread, int messageId, AddrShift val); @@ -1234,40 +1240,40 @@ public: AddrShift offset = PtrMul(ChangeInt32ToPointer(index), GetPtrConstant(panda::ecmascript::JSTaggedValue::TaggedTypeSize())); AddrShift dataOffset = PtrAdd(offset, GetPtrConstant(panda::coretypes::Array::GetDataOffset())); - return Load(TAGGED_TYPE, elements, dataOffset); + return Load(MachineType::TAGGED_TYPE, elements, dataOffset); } AddrShift TaggedToRepresentation(AddrShift value); - AddrShift GetElementRepresentation(AddrShift hclass) + AddrShift GetElementRepresentation(AddrShift hClass) { AddrShift bitfieldOffset = GetPtrConstant(panda::ecmascript::JSHClass::BIT_FIELD_OFFSET); - AddrShift bitfield = Load(INT64_TYPE, hclass, bitfieldOffset); + AddrShift bitfield = Load(MachineType::INT64_TYPE, hClass, bitfieldOffset); return Word64And( Word64LSR(bitfield, GetWord64Constant(panda::ecmascript::JSHClass::ElementRepresentationBits::START_BIT)), GetWord64Constant(((1LLU << panda::ecmascript::JSHClass::ElementRepresentationBits::SIZE) - 1))); } - void SetElementRepresentation(AddrShift hclass, AddrShift value) + void SetElementRepresentation(AddrShift hClass, AddrShift value) { AddrShift bitfieldOffset = GetPtrConstant(panda::ecmascript::JSHClass::BIT_FIELD_OFFSET); - AddrShift oldValue = Load(INT64_TYPE, hclass, bitfieldOffset); + AddrShift oldValue = Load(MachineType::INT64_TYPE, hClass, bitfieldOffset); AddrShift oldWithMask = Word64And(oldValue, GetWord64Constant(~panda::ecmascript::JSHClass::ElementRepresentationBits::Mask())); AddrShift newValue = Word64LSR(value, GetWord64Constant( panda::ecmascript::JSHClass::ElementRepresentationBits::START_BIT)); - Store(INT64_TYPE, hclass, bitfieldOffset, Word64Or(oldWithMask, newValue)); + Store(MachineType::INT64_TYPE, hClass, bitfieldOffset, Word64Or(oldWithMask, newValue)); } void UpdateValueAndAttributes(AddrShift elements, AddrShift index, AddrShift value, AddrShift attr) { AddrShift arrayIndex = - Int32Add(GetInteger32Constant(panda::ecmascript::NameDictionary::TABLE_HEADER_SIZE), - Int32Mul(index, GetInteger32Constant(panda::ecmascript::NameDictionary::ENTRY_SIZE))); + Int32Add(GetInt32Constant(panda::ecmascript::NameDictionary::TABLE_HEADER_SIZE), + Int32Mul(index, GetInt32Constant(panda::ecmascript::NameDictionary::ENTRY_SIZE))); AddrShift valueIndex = - Int32Add(arrayIndex, GetInteger32Constant(panda::ecmascript::NameDictionary::ENTRY_VALUE_INDEX)); + Int32Add(arrayIndex, GetInt32Constant(panda::ecmascript::NameDictionary::ENTRY_VALUE_INDEX)); AddrShift attributesIndex = - Int32Add(arrayIndex, GetInteger32Constant(panda::ecmascript::NameDictionary::ENTRY_DETAILS_INDEX)); + Int32Add(arrayIndex, GetInt32Constant(panda::ecmascript::NameDictionary::ENTRY_DETAILS_INDEX)); StoreElement(elements, valueIndex, value); StoreElement(elements, attributesIndex, IntBuildTagged(attr)); } @@ -1275,36 +1281,36 @@ public: AddrShift IsSpecialIndexedObj(AddrShift jsType) { return Int32GreaterThan(jsType, - GetInteger32Constant(static_cast(panda::ecmascript::JSType::JS_ARRAY))); + GetInt32Constant(static_cast(panda::ecmascript::JSType::JS_ARRAY))); } AddrShift IsAccessorInternal(AddrShift value) { return Word32Equal(GetObjectType(LoadHClass(value)), - GetInteger32Constant(static_cast(panda::ecmascript::JSType::INTERNAL_ACCESSOR))); + GetInt32Constant(static_cast(panda::ecmascript::JSType::INTERNAL_ACCESSOR))); } - void UpdateAndStoreRepresention(AddrShift hclass, AddrShift value); + void UpdateAndStoreRepresention(AddrShift hClass, AddrShift value); AddrShift UpdateRepresention(AddrShift oldRep, AddrShift value); AddrShift GetAttributesFromDictionary(AddrShift elements, AddrShift entry) { AddrShift arrayIndex = - Int32Add(GetInteger32Constant(panda::ecmascript::NumberDictionary::TABLE_HEADER_SIZE), - Int32Mul(entry, GetInteger32Constant(panda::ecmascript::NumberDictionary::ENTRY_SIZE))); + Int32Add(GetInt32Constant(panda::ecmascript::NumberDictionary::TABLE_HEADER_SIZE), + Int32Mul(entry, GetInt32Constant(panda::ecmascript::NumberDictionary::ENTRY_SIZE))); AddrShift attributesIndex = - Int32Add(arrayIndex, GetInteger32Constant(panda::ecmascript::NameDictionary::ENTRY_DETAILS_INDEX)); + Int32Add(arrayIndex, GetInt32Constant(panda::ecmascript::NameDictionary::ENTRY_DETAILS_INDEX)); return TaggedCastToInt32(GetValueFromTaggedArray(elements, attributesIndex)); } AddrShift GetValueFromDictionary(AddrShift elements, AddrShift entry) { AddrShift arrayIndex = - Int32Add(GetInteger32Constant(panda::ecmascript::NumberDictionary::TABLE_HEADER_SIZE), - Int32Mul(entry, GetInteger32Constant(panda::ecmascript::NumberDictionary::ENTRY_SIZE))); + Int32Add(GetInt32Constant(panda::ecmascript::NumberDictionary::TABLE_HEADER_SIZE), + Int32Mul(entry, GetInt32Constant(panda::ecmascript::NumberDictionary::ENTRY_SIZE))); AddrShift valueIndex = - Int32Add(arrayIndex, GetInteger32Constant(panda::ecmascript::NameDictionary::ENTRY_VALUE_INDEX)); + Int32Add(arrayIndex, GetInt32Constant(panda::ecmascript::NameDictionary::ENTRY_VALUE_INDEX)); return GetValueFromTaggedArray(elements, valueIndex); } @@ -1313,9 +1319,9 @@ public: AddrShift GetPropAttrFromLayoutInfo(AddrShift layout, AddrShift entry) { AddrShift index = Int32Add( - Int32Add(GetInteger32Constant(panda::ecmascript::LayoutInfo::ELEMENTS_START_INDEX), - Word32LSL(entry, GetInteger32Constant(1))), - GetInteger32Constant(1)); + Int32Add(GetInt32Constant(panda::ecmascript::LayoutInfo::ELEMENTS_START_INDEX), + Word32LSL(entry, GetInt32Constant(1))), + GetInt32Constant(1)); return GetValueFromTaggedArray(layout, index); } @@ -1450,7 +1456,7 @@ public: AddrShift hclass = LoadHClass(obj); AddrShift bitfieldOffset = GetPtrConstant(panda::ecmascript::JSHClass::BIT_FIELD_OFFSET); - AddrShift bitfield = Load(INT64_TYPE, hclass, bitfieldOffset); + AddrShift bitfield = Load(MachineType::INT64_TYPE, hclass, bitfieldOffset); // decode return Word64NotEqual( Word64And(Word64LSR(bitfield, GetWord64Constant(panda::ecmascript::JSHClass::CallableBit::START_BIT)), diff --git a/ecmascript/compiler/stub_descriptor.cpp b/ecmascript/compiler/stub_descriptor.cpp index c979661e34..7e04dee06e 100644 --- a/ecmascript/compiler/stub_descriptor.cpp +++ b/ecmascript/compiler/stub_descriptor.cpp @@ -26,11 +26,10 @@ namespace kungfu { static void Initialize(StubDescriptor *descriptor); \ }; \ void Stub##name##InterfaceDescriptor::Initialize(StubDescriptor *descriptor) - CALL_STUB_INIT_DESCRIPTOR(FastAdd) { // 2 : 2 input parameters - StubDescriptor fastAdd("FastAdd", 0, 2, ArgumentsOrder::DEFAULT_ORDER, UINT64_TYPE); + StubDescriptor fastAdd("FastAdd", 0, 2, ArgumentsOrder::DEFAULT_ORDER, MachineType::UINT64_TYPE); *descriptor = fastAdd; // 2 : 2 input parameters std::array params = { @@ -43,7 +42,7 @@ CALL_STUB_INIT_DESCRIPTOR(FastAdd) CALL_STUB_INIT_DESCRIPTOR(FastSub) { // 2 : 2 input parameters - StubDescriptor fastSub("FastSub", 0, 2, ArgumentsOrder::DEFAULT_ORDER, UINT64_TYPE); + StubDescriptor fastSub("FastSub", 0, 2, ArgumentsOrder::DEFAULT_ORDER, MachineType::UINT64_TYPE); *descriptor = fastSub; // 2 : 2 input parameters std::array params = { @@ -56,7 +55,7 @@ CALL_STUB_INIT_DESCRIPTOR(FastSub) CALL_STUB_INIT_DESCRIPTOR(FastMul) { // 2 : 2 input parameters - StubDescriptor fastMul("FastMul", 0, 2, ArgumentsOrder::DEFAULT_ORDER, UINT64_TYPE); + StubDescriptor fastMul("FastMul", 0, 2, ArgumentsOrder::DEFAULT_ORDER, MachineType::UINT64_TYPE); *descriptor = fastMul; // 2 : 2 input parameters std::array params = { @@ -69,7 +68,7 @@ CALL_STUB_INIT_DESCRIPTOR(FastMul) CALL_STUB_INIT_DESCRIPTOR(FastDiv) { // 2 : 2 input parameters - StubDescriptor fastDiv("FastDiv", 0, 2, ArgumentsOrder::DEFAULT_ORDER, UINT64_TYPE); + StubDescriptor fastDiv("FastDiv", 0, 2, ArgumentsOrder::DEFAULT_ORDER, MachineType::UINT64_TYPE); *descriptor = fastDiv; // 2 : 2 input parameters std::array params = { @@ -82,7 +81,7 @@ CALL_STUB_INIT_DESCRIPTOR(FastDiv) CALL_STUB_INIT_DESCRIPTOR(FastMod) { // 3 : 3 input parameters - StubDescriptor fastMod("FastMod", 0, 3, ArgumentsOrder::DEFAULT_ORDER, UINT64_TYPE); + StubDescriptor fastMod("FastMod", 0, 3, ArgumentsOrder::DEFAULT_ORDER, MachineType::UINT64_TYPE); *descriptor = fastMod; // 3 : 3 input parameters std::array params = { @@ -96,7 +95,7 @@ CALL_STUB_INIT_DESCRIPTOR(FastMod) CALL_STUB_INIT_DESCRIPTOR(FloatMod) { // 2 : 2 input parameters - StubDescriptor floatMod("FloatMod", 0, 2, ArgumentsOrder::DEFAULT_ORDER, FLOAT64_TYPE); + StubDescriptor floatMod("FloatMod", 0, 2, ArgumentsOrder::DEFAULT_ORDER, MachineType::FLOAT64_TYPE); *descriptor = floatMod; // 2 : 2 input parameters std::array params = { @@ -112,7 +111,7 @@ CALL_STUB_INIT_DESCRIPTOR(FastEqual) {} CALL_STUB_INIT_DESCRIPTOR(FastTypeOf) { // 2 input parameters - StubDescriptor fastTypeOf("FastTypeOf", 0, 2, ArgumentsOrder::DEFAULT_ORDER, UINT64_TYPE); + StubDescriptor fastTypeOf("FastTypeOf", 0, 2, ArgumentsOrder::DEFAULT_ORDER, MachineType::UINT64_TYPE); *descriptor = fastTypeOf; // 2 input parameters std::array params = { @@ -131,7 +130,7 @@ CALL_STUB_INIT_DESCRIPTOR(IsSpecialIndexedObjForGet) {} CALL_STUB_INIT_DESCRIPTOR(GetElement) { // 3 : 3 input parameters - StubDescriptor getElement("GetElement", 0, 3, ArgumentsOrder::DEFAULT_ORDER, UINT64_TYPE); + StubDescriptor getElement("GetElement", 0, 3, ArgumentsOrder::DEFAULT_ORDER, MachineType::UINT64_TYPE); *descriptor = getElement; // 3 : 3 input parameters std::array params = { @@ -145,7 +144,7 @@ CALL_STUB_INIT_DESCRIPTOR(GetElement) CALL_STUB_INIT_DESCRIPTOR(SetElement) { // 5 : 5 input parameters - StubDescriptor setElement("SetElement", 0, 5, ArgumentsOrder::DEFAULT_ORDER, BOOL_TYPE); + StubDescriptor setElement("SetElement", 0, 5, ArgumentsOrder::DEFAULT_ORDER, MachineType::BOOL_TYPE); *descriptor = setElement; // 5 : 5 input parameters std::array params = { @@ -160,13 +159,12 @@ CALL_STUB_INIT_DESCRIPTOR(SetPropertyByName) {} CALL_STUB_INIT_DESCRIPTOR(GetPropertyByName) { // 3 : 3 input parameters - StubDescriptor getPropertyByName("GetPropertyByName", 0, 3, ArgumentsOrder::DEFAULT_ORDER, UINT64_TYPE); + StubDescriptor getPropertyByName("GetPropertyByName", 0, 3, ArgumentsOrder::DEFAULT_ORDER, + MachineType::UINT64_TYPE); *descriptor = getPropertyByName; // 3 : 3 input parameters std::array params = { - MachineType::UINT64_TYPE, - MachineType::UINT64_TYPE, - MachineType::UINT64_TYPE, + MachineType::UINT64_TYPE, MachineType::UINT64_TYPE, MachineType::UINT64_TYPE, }; descriptor->SetParameters(params.data()); } @@ -188,7 +186,7 @@ CALL_STUB_INIT_DESCRIPTOR(FindOwnProperty) {} CALL_STUB_INIT_DESCRIPTOR(FindOwnElement) { // 3 : 3 input parameters - StubDescriptor findOwnElement("FindOwnElement", 0, 3, ArgumentsOrder::DEFAULT_ORDER, UINT64_TYPE); + StubDescriptor findOwnElement("FindOwnElement", 0, 3, ArgumentsOrder::DEFAULT_ORDER, MachineType::UINT64_TYPE); *descriptor = findOwnElement; // 3 : 3 input parameters std::array params = { @@ -206,7 +204,7 @@ CALL_STUB_INIT_DESCRIPTOR(FindOwnProperty2) {} CALL_STUB_INIT_DESCRIPTOR(FindOwnElement2) { // 6 : 6 input parameters - StubDescriptor findOwnElement2("FindOwnElement2", 0, 6, ArgumentsOrder::DEFAULT_ORDER, UINT64_TYPE); + StubDescriptor findOwnElement2("FindOwnElement2", 0, 6, ArgumentsOrder::DEFAULT_ORDER, MachineType::UINT64_TYPE); *descriptor = findOwnElement2; // 6 : 6 input parameters std::array params = { @@ -219,7 +217,8 @@ CALL_STUB_INIT_DESCRIPTOR(FindOwnElement2) CALL_STUB_INIT_DESCRIPTOR(GetPropertyByIndex) { // 3 : 3 input parameters - StubDescriptor getPropertyByIndex("GetPropertyByIndex", 0, 3, ArgumentsOrder::DEFAULT_ORDER, UINT64_TYPE); + StubDescriptor getPropertyByIndex("GetPropertyByIndex", 0, 3, ArgumentsOrder::DEFAULT_ORDER, + MachineType::UINT64_TYPE); *descriptor = getPropertyByIndex; // 3 : 3 input parameters std::array params = { @@ -233,7 +232,8 @@ CALL_STUB_INIT_DESCRIPTOR(GetPropertyByIndex) CALL_STUB_INIT_DESCRIPTOR(SetPropertyByIndex) { // 4 : 4 input parameters - StubDescriptor setPropertyByIndex("SetPropertyByIndex", 0, 4, ArgumentsOrder::DEFAULT_ORDER, UINT64_TYPE); + StubDescriptor setPropertyByIndex("SetPropertyByIndex", 0, 4, ArgumentsOrder::DEFAULT_ORDER, + MachineType::UINT64_TYPE); *descriptor = setPropertyByIndex; // 4 : 4 input parameters std::array params = { @@ -248,7 +248,7 @@ CALL_STUB_INIT_DESCRIPTOR(SetPropertyByIndex) CALL_STUB_INIT_DESCRIPTOR(GetPropertyByValue) { // 3 : 3 input parameters - StubDescriptor getPropertyByValue("GetPropertyByValue", 0, 3, ArgumentsOrder::DEFAULT_ORDER, UINT64_TYPE); + StubDescriptor getPropertyByValue("GetPropertyByValue", 0, 3, ArgumentsOrder::DEFAULT_ORDER, MachineType::UINT64_TYPE); *descriptor = getPropertyByValue; // 3 : 3 input parameters std::array params = { @@ -267,7 +267,8 @@ CALL_STUB_INIT_DESCRIPTOR(SetPropertyByValue) CALL_STUB_INIT_DESCRIPTOR(AddElementInternal) { // 5 : 5 input parameters - StubDescriptor addElementInternal("AddElementInternal", 0, 5, ArgumentsOrder::DEFAULT_ORDER, BOOL_TYPE); + StubDescriptor addElementInternal("AddElementInternal", 0, 5, ArgumentsOrder::DEFAULT_ORDER, + MachineType::BOOL_TYPE); *descriptor = addElementInternal; // 5 : 5 input parameters std::array params = { @@ -278,10 +279,22 @@ CALL_STUB_INIT_DESCRIPTOR(AddElementInternal) descriptor->SetStubKind(StubDescriptor::CallStubKind::RUNTIME_STUB); } +CALL_STUB_INIT_DESCRIPTOR(GetTaggedArrayPtr) +{ + static StubDescriptor getTaggedArrayPtr("GetTaggedArrayPtr", 0, 1, ArgumentsOrder::DEFAULT_ORDER, + MachineType::TAGGED_POINTER_TYPE); + *descriptor = getTaggedArrayPtr; + std::array params = { + MachineType::UINT64_TYPE, + }; + descriptor->SetParameters(params.data()); + descriptor->SetStubKind(StubDescriptor::CallStubKind::RUNTIME_STUB); +} + CALL_STUB_INIT_DESCRIPTOR(CallSetter) { // 5 : 5 input parameters - StubDescriptor callSetter("CallSetter", 0, 5, ArgumentsOrder::DEFAULT_ORDER, BOOL_TYPE); + StubDescriptor callSetter("CallSetter", 0, 5, ArgumentsOrder::DEFAULT_ORDER, MachineType::BOOL_TYPE); *descriptor = callSetter; // 5 : 5 input parameters std::array params = { @@ -295,7 +308,7 @@ CALL_STUB_INIT_DESCRIPTOR(CallSetter) CALL_STUB_INIT_DESCRIPTOR(CallGetter) { // 3 : 3 input parameters - StubDescriptor callGetter("CallGetter", 0, 3, ArgumentsOrder::DEFAULT_ORDER, UINT64_TYPE); + StubDescriptor callGetter("CallGetter", 0, 3, ArgumentsOrder::DEFAULT_ORDER, MachineType::UINT64_TYPE); *descriptor = callGetter; // 3 : 3 input parameters std::array params = { @@ -310,7 +323,7 @@ CALL_STUB_INIT_DESCRIPTOR(CallGetter) CALL_STUB_INIT_DESCRIPTOR(AccessorGetter) { // 3 : 3 input parameters - StubDescriptor accessorGetter("AccessorGetter", 0, 3, ArgumentsOrder::DEFAULT_ORDER, UINT64_TYPE); + StubDescriptor accessorGetter("AccessorGetter", 0, 3, ArgumentsOrder::DEFAULT_ORDER, MachineType::UINT64_TYPE); *descriptor = accessorGetter; // 3 : 3 input parameters std::array params = { @@ -325,7 +338,7 @@ CALL_STUB_INIT_DESCRIPTOR(AccessorGetter) CALL_STUB_INIT_DESCRIPTOR(ThrowTypeError) { // 2 : 2 input parameters - StubDescriptor throwTypeError("ThrowTypeError", 0, 2, ArgumentsOrder::DEFAULT_ORDER, NONE_TYPE); + StubDescriptor throwTypeError("ThrowTypeError", 0, 2, ArgumentsOrder::DEFAULT_ORDER, MachineType::BOOL_TYPE); *descriptor = throwTypeError; // 2 : 2 input parameters std::array params = { @@ -339,7 +352,8 @@ CALL_STUB_INIT_DESCRIPTOR(ThrowTypeError) CALL_STUB_INIT_DESCRIPTOR(JSProxySetProperty) { // 6 : 6 input parameters - StubDescriptor jsproxySetproperty("JSProxySetProperty", 0, 6, ArgumentsOrder::DEFAULT_ORDER, BOOL_TYPE); + StubDescriptor jsproxySetproperty("JSProxySetProperty", 0, 6, + ArgumentsOrder::DEFAULT_ORDER, MachineType::BOOL_TYPE); *descriptor = jsproxySetproperty; // 6 : 6 input parameters std::array params = { @@ -353,7 +367,7 @@ CALL_STUB_INIT_DESCRIPTOR(JSProxySetProperty) CALL_STUB_INIT_DESCRIPTOR(GetHash32) { // 2 : 2 input parameters - StubDescriptor getHash32("GetHash32", 0, 2, ArgumentsOrder::DEFAULT_ORDER, UINT32_TYPE); + StubDescriptor getHash32("GetHash32", 0, 2, ArgumentsOrder::DEFAULT_ORDER, MachineType::UINT32_TYPE); *descriptor = getHash32; // 2 : 2 input parameters std::array params = { @@ -367,7 +381,8 @@ CALL_STUB_INIT_DESCRIPTOR(GetHash32) CALL_STUB_INIT_DESCRIPTOR(FindElementWithCache) { // 4 : 4 input parameters - StubDescriptor findElementWithCache("FindElementWithCache", 0, 4, ArgumentsOrder::DEFAULT_ORDER, INT32_TYPE); + StubDescriptor findElementWithCache("FindElementWithCache", 0, 4, + ArgumentsOrder::DEFAULT_ORDER, MachineType::INT32_TYPE); *descriptor = findElementWithCache; std::array params = { // 4 : 4 input parameters MachineType::UINT64_TYPE, @@ -382,7 +397,7 @@ CALL_STUB_INIT_DESCRIPTOR(FindElementWithCache) CALL_STUB_INIT_DESCRIPTOR(Execute) { // 5 : 5 input parameters - StubDescriptor execute("Execute", 0, 5, ArgumentsOrder::DEFAULT_ORDER, UINT64_TYPE); + StubDescriptor execute("Execute", 0, 5, ArgumentsOrder::DEFAULT_ORDER, MachineType::UINT64_TYPE); *descriptor = execute; std::array params = { // 5 : 5 input parameters MachineType::UINT64_TYPE, @@ -399,7 +414,7 @@ CALL_STUB_INIT_DESCRIPTOR(FunctionCallInternal) { // 5 : 5 input parameters StubDescriptor functionCallInternal("FunctionCallInternal", 0, 5, - ArgumentsOrder::DEFAULT_ORDER, UINT64_TYPE); + ArgumentsOrder::DEFAULT_ORDER, MachineType::UINT64_TYPE); *descriptor = functionCallInternal; std::array params = { // 5 : 5 input parameters MachineType::UINT64_TYPE, @@ -414,7 +429,8 @@ CALL_STUB_INIT_DESCRIPTOR(FunctionCallInternal) CALL_STUB_INIT_DESCRIPTOR(StringGetHashCode) { - StubDescriptor stringGetHashCode("StringGetHashCode", 0, 1, ArgumentsOrder::DEFAULT_ORDER, UINT32_TYPE); + StubDescriptor stringGetHashCode("StringGetHashCode", 0, 1, + ArgumentsOrder::DEFAULT_ORDER, MachineType::UINT32_TYPE); *descriptor = stringGetHashCode; std::array params = { MachineType::UINT64_TYPE, @@ -423,10 +439,27 @@ CALL_STUB_INIT_DESCRIPTOR(StringGetHashCode) descriptor->SetStubKind(StubDescriptor::CallStubKind::RUNTIME_STUB); } +CALL_STUB_INIT_DESCRIPTOR(SetValueWithBarrier) +{ + // 4 : 4 input parameters + static StubDescriptor SetValueWithBarrier("SetValueWithBarrier", 0, 4, + ArgumentsOrder::DEFAULT_ORDER, MachineType::NONE_TYPE); + *descriptor = SetValueWithBarrier; + // 4 : 4 input parameters + std::array params = { + MachineType::UINT64_TYPE, + MachineType::UINT64_TYPE, + MachineType::UINT64_TYPE, + MachineType::UINT64_TYPE, + }; + descriptor->SetParameters(params.data()); + descriptor->SetStubKind(StubDescriptor::CallStubKind::RUNTIME_STUB); +} + CALL_STUB_INIT_DESCRIPTOR(NewInternalString) { // 2 : 2 input parameters - StubDescriptor stringGetHashCode("NewInternalString", 0, 2, ArgumentsOrder::DEFAULT_ORDER, UINT64_TYPE); + StubDescriptor stringGetHashCode("NewInternalString", 0, 2, ArgumentsOrder::DEFAULT_ORDER, MachineType::UINT64_TYPE); *descriptor = stringGetHashCode; // 2 : 2 input parameters std::array params = { @@ -440,7 +473,7 @@ CALL_STUB_INIT_DESCRIPTOR(NewInternalString) CALL_STUB_INIT_DESCRIPTOR(FastLoadElement) { // 2 : 2 input parameters - StubDescriptor fastLoadElement("FastLoadElement", 0, 2, ArgumentsOrder::DEFAULT_ORDER, TAGGED_TYPE); + StubDescriptor fastLoadElement("FastLoadElement", 0, 2, ArgumentsOrder::DEFAULT_ORDER, MachineType::TAGGED_TYPE); *descriptor = fastLoadElement; std::array params = { // 2 : 2 input parameters MachineType::UINT64_TYPE, @@ -452,7 +485,7 @@ CALL_STUB_INIT_DESCRIPTOR(FastLoadElement) CALL_STUB_INIT_DESCRIPTOR(PhiGateTest) { - StubDescriptor phiGateTest("PhiGateTest", 0, 1, ArgumentsOrder::DEFAULT_ORDER, UINT32_TYPE); + StubDescriptor phiGateTest("PhiGateTest", 0, 1, ArgumentsOrder::DEFAULT_ORDER, MachineType::UINT32_TYPE); *descriptor = phiGateTest; std::array params = { MachineType::UINT32_TYPE, @@ -463,7 +496,7 @@ CALL_STUB_INIT_DESCRIPTOR(PhiGateTest) CALL_STUB_INIT_DESCRIPTOR(LoopTest) { - StubDescriptor loopTest("LoopTest", 0, 1, ArgumentsOrder::DEFAULT_ORDER, UINT32_TYPE); + StubDescriptor loopTest("LoopTest", 0, 1, ArgumentsOrder::DEFAULT_ORDER, MachineType::UINT32_TYPE); *descriptor = loopTest; std::array params = { MachineType::UINT32_TYPE, @@ -474,7 +507,7 @@ CALL_STUB_INIT_DESCRIPTOR(LoopTest) CALL_STUB_INIT_DESCRIPTOR(LoopTest1) { - StubDescriptor loopTest1("LoopTest1", 0, 1, ArgumentsOrder::DEFAULT_ORDER, UINT32_TYPE); + StubDescriptor loopTest1("LoopTest1", 0, 1, ArgumentsOrder::DEFAULT_ORDER, MachineType::UINT32_TYPE); *descriptor = loopTest1; std::array params = { MachineType::UINT32_TYPE, diff --git a/ecmascript/compiler/tests/stub_tests.cpp b/ecmascript/compiler/tests/stub_tests.cpp index 3999065046..ffa7d7c885 100644 --- a/ecmascript/compiler/tests/stub_tests.cpp +++ b/ecmascript/compiler/tests/stub_tests.cpp @@ -114,22 +114,19 @@ public: void GenerateCircuit() override { auto env = GetEnvironment(); - DEFVARIABLE(z, MachineType::INT32_TYPE, GetInteger32Constant(0)); + DEFVARIABLE(z, MachineType::INT32_TYPE, GetInt32Constant(0)); DEFVARIABLE(x, MachineType::INT32_TYPE, Int32Argument(0)); Label ifTrue(env); Label ifFalse(env); Label next(env); - Branch(Word32Equal(*x, GetInteger32Constant(10)), &ifTrue, &ifFalse); // 10 : size of entry + + Branch(Word32Equal(*x, GetInt32Constant(10)), &ifTrue, &ifFalse); // 10 : size of entry Bind(&ifTrue); - { - z = Int32Add(*x, GetInteger32Constant(10)); // 10 : size of entry - Jump(&next); - } + z = Int32Add(*x, GetInt32Constant(10)); // 10 : size of entry + Jump(&next); Bind(&ifFalse); - { - z = Int32Add(*x, GetInteger32Constant(100)); // 100 : size of entry - Jump(&next); - } + z = Int32Add(*x, GetInt32Constant(100)); // 100 : size of entry + Jump(&next); Bind(&next); Return(*z); } @@ -166,27 +163,27 @@ public: void GenerateCircuit() override { auto env = GetEnvironment(); - DEFVARIABLE(z, MachineType::INT32_TYPE, GetInteger32Constant(0)); + DEFVARIABLE(z, MachineType::INT32_TYPE, GetInt32Constant(0)); DEFVARIABLE(y, MachineType::INT32_TYPE, Int32Argument(0)); Label loopHead(env); Label loopEnd(env); Label afterLoop(env); - Branch(Int32LessThan(*y, GetInteger32Constant(10)), &loopHead, &afterLoop); // 10 : size of entry + Branch(Int32LessThan(*y, GetInt32Constant(10)), &loopHead, &afterLoop); // 10 : size of entry LoopBegin(&loopHead); Label ifTrue(env); Label ifFalse(env); Label next(env); - Branch(Word32Equal(Int32Argument(0), GetInteger32Constant(9)), &ifTrue, &ifFalse); // 9 : size of entry + Branch(Word32Equal(Int32Argument(0), GetInt32Constant(9)), &ifTrue, &ifFalse); // 9 : size of entry Bind(&ifTrue); - z = Int32Add(*y, GetInteger32Constant(10)); // 10 : size of entry - y = Int32Add(*z, GetInteger32Constant(1)); + z = Int32Add(*y, GetInt32Constant(10)); // 10 : size of entry + y = Int32Add(*z, GetInt32Constant(1)); Jump(&next); Bind(&ifFalse); - z = Int32Add(*y, GetInteger32Constant(100)); // 100 : size of entry + z = Int32Add(*y, GetInt32Constant(100)); // 100 : size of entry Jump(&next); Bind(&next); - y = Int32Add(*y, GetInteger32Constant(1)); - Branch(Int32LessThan(*y, GetInteger32Constant(10)), &loopEnd, &afterLoop); // 10 : size of entry + y = Int32Add(*y, GetInt32Constant(1)); + Branch(Int32LessThan(*y, GetInt32Constant(10)), &loopEnd, &afterLoop); // 10 : size of entry Bind(&loopEnd); LoopEnd(&loopHead); Bind(&afterLoop); @@ -204,7 +201,7 @@ HWTEST_F_L0(StubTest, LoopTest) netOfGates.PrintAllGates(); auto cfg = Scheduler::Run(&netOfGates); PrintCircuitByBasicBlock(cfg, netOfGates); - LLVMIRBuilder llvmBuilder(&cfg, &netOfGates, module, function); + LLVMIRBuilder llvmBuilder(&cfg, &netOfGates, &stubModule, function); llvmBuilder.Build(); LLVMAssembler assembler(module, "x86_64-unknown-linux-gnu"); assembler.Run(); @@ -233,18 +230,18 @@ public: Label loopHead(env); Label loopEnd(env); Label afterLoop(env); - Branch(Int32LessThan(*y, GetInteger32Constant(10)), &loopHead, &afterLoop); // 10 : size of entry + Branch(Int32LessThan(*y, GetInt32Constant(10)), &loopHead, &afterLoop); // 10 : size of entry LoopBegin(&loopHead); - x = Int32Add(*z, GetInteger32Constant(3)); // 3 : size of entry + x = Int32Add(*z, GetInt32Constant(3)); // 3 : size of entry Label ifTrue(env); Label next(env); - Branch(Word32Equal(*x, GetInteger32Constant(9)), &ifTrue, &next); // 9 : size of entry + Branch(Word32Equal(*x, GetInt32Constant(9)), &ifTrue, &next); // 9 : size of entry Bind(&ifTrue); y = Int32Add(*z, *x); Jump(&next); Bind(&next); - y = Int32Add(*y, GetInteger32Constant(1)); - Branch(Int32LessThan(*y, GetInteger32Constant(10)), &loopEnd, &afterLoop); // 10 : size of entry + y = Int32Add(*y, GetInt32Constant(1)); + Branch(Int32LessThan(*y, GetInt32Constant(10)), &loopEnd, &afterLoop); // 10 : size of entry Bind(&loopEnd); LoopEnd(&loopHead); Bind(&afterLoop); @@ -255,8 +252,7 @@ public: HWTEST_F_L0(StubTest, LoopTest1) { - LLVMModuleRef module = LLVMModuleCreateWithName("simple_module"); - LLVMSetTarget(module, "x86_64-unknown-linux-gnu"); + auto module = stubModule.GetModule(); LLVMTypeRef paramTys[] = { LLVMInt32Type(), }; @@ -267,7 +263,7 @@ HWTEST_F_L0(StubTest, LoopTest1) netOfGates.PrintAllGates(); auto cfg = Scheduler::Run(&netOfGates); PrintCircuitByBasicBlock(cfg, netOfGates); - LLVMIRBuilder llvmBuilder(&cfg, &netOfGates, module, function); + LLVMIRBuilder llvmBuilder(&cfg, &netOfGates, &stubModule, function); llvmBuilder.Build(); LLVMAssembler assembler(module, "x86_64-unknown-linux-gnu"); assembler.Run(); @@ -1033,6 +1029,7 @@ HWTEST_F_L0(StubTest, LoadGCIRTest) std::unique_ptr rawModule = parseIRFile(inputFilename, err, context); if (!rawModule) { std::cout << "parseIRFile :" << inputFilename.data() << " failed !" << std::endl; + err.print("parseIRFile ", llvm::errs()); return; } LLVMModuleRef module = LLVMCloneModule(wrap(rawModule.get())); -- Gitee From 0f0321fac300525cf0ef8c2d84c80b26f5c4f5a7 Mon Sep 17 00:00:00 2001 From: songzhengchao Date: Sat, 30 Oct 2021 10:40:31 +0800 Subject: [PATCH 2/2] code review Signed-off-by: songzhengchao --- ecmascript/compiler/fast_stub.cpp | 11 +++++------ ecmascript/compiler/stub_descriptor.cpp | 18 ++++-------------- 2 files changed, 9 insertions(+), 20 deletions(-) diff --git a/ecmascript/compiler/fast_stub.cpp b/ecmascript/compiler/fast_stub.cpp index 395127709b..7c1aaa3d48 100644 --- a/ecmascript/compiler/fast_stub.cpp +++ b/ecmascript/compiler/fast_stub.cpp @@ -380,7 +380,6 @@ void FindOwnElementStub::GenerateCircuit() Bind(&invalidValue); Return(GetHoleConstant()); } - // IsDictionary Bind(&isDict); { AddrShift taggedIndex = IntBuildTagged(index); @@ -1205,7 +1204,7 @@ void FastTypeOfStub::GenerateCircuit() { resultRep = Load( MachineType::TAGGED_TYPE, gConstOffset, - GetGlobalConstantString(ConstantIndex::OBJECT_STRING_INDEX)); + GetGlobalConstantString(ConstantIndex::OBJECT_STRING_INDEX)); Jump(&exit); } Bind(&objNotNull); @@ -1239,7 +1238,7 @@ void FastTypeOfStub::GenerateCircuit() { resultRep = Load( MachineType::TAGGED_TYPE, gConstOffset, - GetGlobalConstantString(ConstantIndex::STRING_STRING_INDEX)); + GetGlobalConstantString(ConstantIndex::STRING_STRING_INDEX)); Jump(&exit); } Bind(&objNotString); @@ -1262,14 +1261,14 @@ void FastTypeOfStub::GenerateCircuit() { resultRep = Load( MachineType::TAGGED_TYPE, gConstOffset, - GetGlobalConstantString(ConstantIndex::FUNCTION_STRING_INDEX)); + GetGlobalConstantString(ConstantIndex::FUNCTION_STRING_INDEX)); Jump(&exit); } Bind(&objNotCallable); { resultRep = Load( MachineType::TAGGED_TYPE, gConstOffset, - GetGlobalConstantString(ConstantIndex::OBJECT_STRING_INDEX)); + GetGlobalConstantString(ConstantIndex::OBJECT_STRING_INDEX)); Jump(&exit); } } @@ -1284,7 +1283,7 @@ void FastTypeOfStub::GenerateCircuit() { resultRep = Load( MachineType::TAGGED_TYPE, gConstOffset, - GetGlobalConstantString(ConstantIndex::NUMBER_STRING_INDEX)); + GetGlobalConstantString(ConstantIndex::NUMBER_STRING_INDEX)); Jump(&exit); } Bind(&objNotNum); diff --git a/ecmascript/compiler/stub_descriptor.cpp b/ecmascript/compiler/stub_descriptor.cpp index 7e04dee06e..cda345c4a6 100644 --- a/ecmascript/compiler/stub_descriptor.cpp +++ b/ecmascript/compiler/stub_descriptor.cpp @@ -248,7 +248,8 @@ CALL_STUB_INIT_DESCRIPTOR(SetPropertyByIndex) CALL_STUB_INIT_DESCRIPTOR(GetPropertyByValue) { // 3 : 3 input parameters - StubDescriptor getPropertyByValue("GetPropertyByValue", 0, 3, ArgumentsOrder::DEFAULT_ORDER, MachineType::UINT64_TYPE); + StubDescriptor getPropertyByValue("GetPropertyByValue", 0, 3, + ArgumentsOrder::DEFAULT_ORDER, MachineType::UINT64_TYPE); *descriptor = getPropertyByValue; // 3 : 3 input parameters std::array params = { @@ -279,18 +280,6 @@ CALL_STUB_INIT_DESCRIPTOR(AddElementInternal) descriptor->SetStubKind(StubDescriptor::CallStubKind::RUNTIME_STUB); } -CALL_STUB_INIT_DESCRIPTOR(GetTaggedArrayPtr) -{ - static StubDescriptor getTaggedArrayPtr("GetTaggedArrayPtr", 0, 1, ArgumentsOrder::DEFAULT_ORDER, - MachineType::TAGGED_POINTER_TYPE); - *descriptor = getTaggedArrayPtr; - std::array params = { - MachineType::UINT64_TYPE, - }; - descriptor->SetParameters(params.data()); - descriptor->SetStubKind(StubDescriptor::CallStubKind::RUNTIME_STUB); -} - CALL_STUB_INIT_DESCRIPTOR(CallSetter) { // 5 : 5 input parameters @@ -459,7 +448,8 @@ CALL_STUB_INIT_DESCRIPTOR(SetValueWithBarrier) CALL_STUB_INIT_DESCRIPTOR(NewInternalString) { // 2 : 2 input parameters - StubDescriptor stringGetHashCode("NewInternalString", 0, 2, ArgumentsOrder::DEFAULT_ORDER, MachineType::UINT64_TYPE); + StubDescriptor stringGetHashCode("NewInternalString", 0, 2, + ArgumentsOrder::DEFAULT_ORDER, MachineType::UINT64_TYPE); *descriptor = stringGetHashCode; // 2 : 2 input parameters std::array params = { -- Gitee