diff --git a/ecmascript/compiler/builtins_lowering.cpp b/ecmascript/compiler/builtins_lowering.cpp index 292ba356b405e54d599a6f5ca9512d79c0f0d1c8..af78d36185b21b4c54ca674b6e9605fcc202612a 100644 --- a/ecmascript/compiler/builtins_lowering.cpp +++ b/ecmascript/compiler/builtins_lowering.cpp @@ -253,7 +253,7 @@ GateRef BuiltinLowering::LowerCallTargetCheck(Environment *env, GateRef gate) GateRef BuiltinLowering::LowerCallTargetCheckDefault(GateRef gate, BuiltinsStubCSigns::ID id) { GateRef globalEnvFunction = - builder_.GetGlobalEnvValue(VariableType::JS_ANY(), acc_.GetGlueFromArgList(), builder_.GetGlobalEnv(), + builder_.GetGlobalEnvValue(VariableType::JS_ANY(), acc_.GetGlueFromArgList(), circuit_->GetGlobalEnvCache(), static_cast(GET_TYPED_ENV_FIELD_INEDX(id))); GateRef function = acc_.GetValueIn(gate, 0); // 0: function return builder_.Equal(function, globalEnvFunction); @@ -261,7 +261,7 @@ GateRef BuiltinLowering::LowerCallTargetCheckDefault(GateRef gate, BuiltinsStubC GateRef BuiltinLowering::LowerCallTargetCheckWithGlobalEnv(GateRef gate, BuiltinsStubCSigns::ID id) { - GateRef globalEnv = builder_.GetGlobalEnv(); + GateRef globalEnv = circuit_->GetGlobalEnvCache(); GateRef globalFunction = builder_.GetGlobalEnvObj(globalEnv, GET_TYPED_GLOBAL_ENV_INDEX(id)); GateRef target = acc_.GetValueIn(gate, 0); // 0:target @@ -275,27 +275,27 @@ GateRef BuiltinLowering::LowerCallTargetCheckWithDetector(GateRef gate, Builtins switch (id) { case BuiltinsStubCSigns::ID::MapProtoIterator: { expectType = JSType::JS_MAP; - detectorValue = builder_.BoolNot(builder_.GetMapIteratorDetector(builder_.GetGlobalEnv())); + detectorValue = builder_.BoolNot(builder_.GetMapIteratorDetector(circuit_->GetGlobalEnvCache())); break; } case BuiltinsStubCSigns::ID::SetProtoIterator: { expectType = JSType::JS_SET; - detectorValue = builder_.BoolNot(builder_.GetSetIteratorDetector(builder_.GetGlobalEnv())); + detectorValue = builder_.BoolNot(builder_.GetSetIteratorDetector(circuit_->GetGlobalEnvCache())); break; } case BuiltinsStubCSigns::ID::StringProtoIterator: { expectType = JSType::STRING_FIRST; - detectorValue = builder_.BoolNot(builder_.GetStringIteratorDetector(builder_.GetGlobalEnv())); + detectorValue = builder_.BoolNot(builder_.GetStringIteratorDetector(circuit_->GetGlobalEnvCache())); break; } case BuiltinsStubCSigns::ID::ArrayProtoIterator: { expectType = JSType::JS_ARRAY; - detectorValue = builder_.BoolNot(builder_.GetArrayIteratorDetector(builder_.GetGlobalEnv())); + detectorValue = builder_.BoolNot(builder_.GetArrayIteratorDetector(circuit_->GetGlobalEnvCache())); break; } case BuiltinsStubCSigns::ID::TypedArrayProtoIterator: { expectType = JSType::JS_TYPED_ARRAY_FIRST; - detectorValue = builder_.BoolNot(builder_.GetTypedArrayIteratorDetector(builder_.GetGlobalEnv())); + detectorValue = builder_.BoolNot(builder_.GetTypedArrayIteratorDetector(circuit_->GetGlobalEnvCache())); break; } default: { @@ -501,7 +501,7 @@ void BuiltinLowering::LowerNumberConstructor(GateRef gate) BRANCH_CIR(builder_.Equal(length, builder_.Int32(0)), &exit, &nonZeroLength); builder_.Bind(&nonZeroLength); Label isInteger(env); - BuiltinsStringStubBuilder stringStub(builder_.GetCurrentEnvironment(), builder_.GetGlobalEnv(glue)); + BuiltinsStringStubBuilder stringStub(builder_.GetCurrentEnvironment(), circuit_->GetGlobalEnvCache()); GateRef dataUtf8 = builder_.PtrAdd(param, builder_.IntPtr(LineString::DATA_OFFSET)); GateRef res = stringStub.StringDataToUint(dataUtf8, length, std::numeric_limits::max()); BRANCH_CIR(builder_.Int64NotEqual(res, builder_.Int64(-1)), &isInteger, ¬LineUtf8String); @@ -534,7 +534,7 @@ void BuiltinLowering::LowerCallBuiltinStub(GateRef gate, BuiltinsStubCSigns::ID Environment env(gate, circuit_, &builder_); size_t numIn = acc_.GetNumValueIn(gate); GateRef glue = acc_.GetGlueFromArgList(); - GateRef function = builder_.GetGlobalEnvValue(VariableType::JS_ANY(), glue, builder_.GetGlobalEnv(), + GateRef function = builder_.GetGlobalEnvValue(VariableType::JS_ANY(), glue, circuit_->GetGlobalEnvCache(), static_cast(GET_TYPED_ENV_FIELD_INEDX(id))); GateRef nativeCode = builder_.LoadWithoutBarrier(VariableType::NATIVE_POINTER(), function, builder_.IntPtr(JSFunction::CODE_ENTRY_OFFSET)); diff --git a/ecmascript/compiler/bytecode_circuit_builder.cpp b/ecmascript/compiler/bytecode_circuit_builder.cpp index 5b0b8718ccf6db7a12f3afad84400c1c07b61d28..4ebcde644ad790f7044c339adb6c99b253d30ed5 100644 --- a/ecmascript/compiler/bytecode_circuit_builder.cpp +++ b/ecmascript/compiler/bytecode_circuit_builder.cpp @@ -731,6 +731,7 @@ void BytecodeCircuitBuilder::BuildFrameArgs() args[idx++] = unSharedConstpool; args[idx++] = GetPreFrameArgs(); GateRef frameArgs = circuit_->NewGate(metaData, args); + argAcc_.SetFrameArgs(frameArgs); } @@ -1325,6 +1326,8 @@ void BytecodeCircuitBuilder::BuildCircuit() // build states sub-circuit of each block BuildSubCircuit(); } + InitGlobalEnv(); + if (IsLogEnabled()) { PrintGraph(std::string("Bytecode2Gate [" + methodName_ + "]").c_str()); LOG_COMPILER(INFO) << "\033[34m" << "============= " @@ -1336,6 +1339,17 @@ void BytecodeCircuitBuilder::BuildCircuit() } } +void BytecodeCircuitBuilder::InitGlobalEnv() +{ + if (circuit_->GetGlobalEnvCache() != Circuit::NullGate()) { + return; + } + UInt32PairAccessor accessor(0, 0); + auto envMeta = circuit_->GetGlobalEnvByFunc(accessor.ToValue()); + GateRef globalEnv = circuit_->NewGate(envMeta, {argAcc_.GetCommonArgGate(CommonArgIdx::FUNC)}); + circuit_->SetGlobalEnvCache(globalEnv); +} + void BytecodeCircuitBuilder::PrintGraph(const char* title) { LOG_COMPILER(INFO) << "======================== " << title << " ========================"; diff --git a/ecmascript/compiler/bytecode_circuit_builder.h b/ecmascript/compiler/bytecode_circuit_builder.h index 1f89290364b77d1f9b7181269cfd7fc02813221d..4f0fcff67e2bad415c64b0d5522e425a476d5c4f 100644 --- a/ecmascript/compiler/bytecode_circuit_builder.h +++ b/ecmascript/compiler/bytecode_circuit_builder.h @@ -677,6 +677,7 @@ private: void ClearUnreachableRegion(ChunkVector& pendingList, bool skipInsufficientProfile = false); void RemoveUnusedPredsInfo(BytecodeRegion& bb, bool skipInsufficientProfile); void BuildCircuit(); + void InitGlobalEnv(); void PrintGraph(); void PrintBBInfo(); void PrintGraph(const char* title); diff --git a/ecmascript/compiler/circuit.h b/ecmascript/compiler/circuit.h index ab784a76c4a9a967cfdd26e4237020407c374eac..6df97172056b7031f663fc3cea9a770acea270b5 100644 --- a/ecmascript/compiler/circuit.h +++ b/ecmascript/compiler/circuit.h @@ -92,6 +92,15 @@ public: root_ = root; } + GateRef GetGlobalEnvCache() const + { + return globalEnv_; + } + void SetGlobalEnvCache(GateRef globalEnv) + { + globalEnv_ = globalEnv; + } + Chunk* chunk() { return &chunk_; @@ -336,7 +345,8 @@ private: Chunk chunk_; GateRef root_ { NullGate() }; GateRef dead_ { NullGate() }; - GateRef replaceable_ { NullGate() }; + GateRef globalEnv_ {NullGate()}; + GateRef replaceable_ {NullGate()}; GateMetaBuilder metaBuilder_; ChunkMap gateToDInfo_; DebugInfo* debugInfo_ {nullptr}; diff --git a/ecmascript/compiler/mcr_circuit_builder.h b/ecmascript/compiler/mcr_circuit_builder.h index 44be09d9df40b69ae7cf5f3aad95d2b1312de3c1..2bec865d47a0df2988164a9e044c931e75a0660a 100644 --- a/ecmascript/compiler/mcr_circuit_builder.h +++ b/ecmascript/compiler/mcr_circuit_builder.h @@ -248,7 +248,7 @@ GateRef CircuitBuilder::TaggedIsStableArray(GateRef glue, GateRef obj) BRANCH(IsStableArray(jsHclass), &targetIsStableArray, &exit); Bind(&targetIsStableArray); { - GateRef globalEnv = GetGlobalEnv(glue); + GateRef globalEnv = circuit_->GetGlobalEnvCache(); result = GetArrayElementsGuardians(globalEnv); Jump(&exit); } diff --git a/ecmascript/compiler/mcr_lowering.cpp b/ecmascript/compiler/mcr_lowering.cpp index 23766becfab7b17857d2f48d5d5437e1e959538b..64f73425ac903eb0bd53f995b1dc1df43bcd5b3b 100644 --- a/ecmascript/compiler/mcr_lowering.cpp +++ b/ecmascript/compiler/mcr_lowering.cpp @@ -276,7 +276,7 @@ void MCRLowering::LowerArrayGuardianCheck(GateRef gate) Environment env(gate, circuit_, &builder_); GateRef frameState = acc_.GetFrameState(gate); - GateRef check = builder_.GetArrayElementsGuardians(builder_.GetGlobalEnv()); + GateRef check = builder_.GetArrayElementsGuardians(circuit_->GetGlobalEnvCache()); builder_.DeoptCheck(check, frameState, DeoptType::NOTSARRAY1); acc_.ReplaceGate(gate, builder_.GetState(), builder_.GetDepend(), Circuit::NullGate()); @@ -300,8 +300,8 @@ void MCRLowering::LowerMathHClassConsistencyCheck(GateRef gate) GateRef receiver = acc_.GetValueIn(gate, 0); GateRef receiverHClass = builder_.LoadHClassByConstOffset(glue_, receiver); - GateRef cond = builder_.Equal(receiverHClass, - builder_.GetGlobalEnvObj(builder_.GetGlobalEnv(), GlobalEnv::MATH_FUNCTION_CLASS_INDEX)); + GateRef cond = builder_.Equal( + receiverHClass, builder_.GetGlobalEnvObj(circuit_->GetGlobalEnvCache(), GlobalEnv::MATH_FUNCTION_CLASS_INDEX)); builder_.DeoptCheck(cond, acc_.GetFrameState(gate), DeoptType::INCONSISTENTHCLASS14); @@ -368,7 +368,7 @@ StateDepend MCRLowering::LowerConvert(StateDepend stateDepend, GateRef gate) if (env_->IsJitCompiler()) { result = builder_.CallStub(glue, gate, CommonStubCSigns::ConvertCharToString, {glue, value }); } else { - BuiltinsStringStubBuilder builder(&env, builder_.GetGlobalEnv(glue)); + BuiltinsStringStubBuilder builder(&env, circuit_->GetGlobalEnvCache()); result = builder.CreateStringBySingleCharCode(glue, value); } } else if (dstType == ValueType::INT32) { diff --git a/ecmascript/compiler/native_inline_lowering.cpp b/ecmascript/compiler/native_inline_lowering.cpp index 6b21aa134bd83d4f8d2d52255c9f500265e0044d..6ef2cd3a0c347187a266007461526a68cd31a1d4 100644 --- a/ecmascript/compiler/native_inline_lowering.cpp +++ b/ecmascript/compiler/native_inline_lowering.cpp @@ -1499,9 +1499,9 @@ void NativeInlineLowering::TryInlineIndexOfIncludes(GateRef gate, size_t argc, B GateRef fromIndexHandler = acc_.GetValueIn(gate, 2); builder_.DeoptCheck(builder_.TaggedIsNumber(fromIndexHandler), acc_.GetFrameState(gate), DeoptType::INDEXNOTINT); - GateRef fromIndex = BuiltinsArrayStubBuilder(&env, builder_.GetGlobalEnv(glue_)).MakeFromIndex( - fromIndexHandler, thisLen, - (id == BuiltinsStubCSigns::ID::ArrayLastIndexOf)); + GateRef fromIndex = + BuiltinsArrayStubBuilder(&env, circuit_->GetGlobalEnvCache()) + .MakeFromIndex(fromIndexHandler, thisLen, (id == BuiltinsStubCSigns::ID::ArrayLastIndexOf)); ret = builder_.ArrayIncludesIndexOf(elements, targetElement, fromIndex, thisLen, callID, arrayKind); } if (EnableTrace()) { diff --git a/ecmascript/compiler/ntype_hcr_lowering.cpp b/ecmascript/compiler/ntype_hcr_lowering.cpp index ca51979388cad218e8acbbe6c89cc2a7bd607d8f..dd5161c3536959e6a258bd37848de4163436ac1e 100644 --- a/ecmascript/compiler/ntype_hcr_lowering.cpp +++ b/ecmascript/compiler/ntype_hcr_lowering.cpp @@ -219,7 +219,7 @@ GateRef NTypeHCRLowering::NewJSArrayLiteral(GateRef glue, GateRef gate, GateRef GateRef hclass = Circuit::NullGate(); // At define point, we use initial array class without IsPrototype set. auto hclassIndex = compilationEnv_->GetArrayHClassIndex(kind, false); - GateRef globalEnv = builder_.GetGlobalEnv(glue); + GateRef globalEnv = circuit_->GetGlobalEnvCache(); hclass = builder_.GetGlobalEnvValue(VariableType::JS_POINTER(), glue, globalEnv, static_cast(hclassIndex)); JSHandle arrayFunc(compilationEnv_->GetGlobalEnv()->GetArrayFunction()); diff --git a/ecmascript/compiler/share_opcodes.h b/ecmascript/compiler/share_opcodes.h index a20ae6bacb8c5415f85219f6d64d23c16d2b3260..17f10d3688a2934cc1621a6bebb30f45b52a514b 100644 --- a/ecmascript/compiler/share_opcodes.h +++ b/ecmascript/compiler/share_opcodes.h @@ -75,7 +75,8 @@ namespace panda::ecmascript::kungfu { V(RelocatableData, RELOCATABLE_DATA, GateFlags::NONE_FLAG, 0, 0, 0) \ V(SwitchBranch, SWITCH_BRANCH, GateFlags::CONTROL, 1, 0, 1) \ V(SwitchCase, SWITCH_CASE, GateFlags::CONTROL, 1, 0, 0) \ - V(GetSharedConstPool, GET_SHARED_CONSTPOOL, GateFlags::NO_WRITE, 0, 0, 1) + V(GetSharedConstPool, GET_SHARED_CONSTPOOL, GateFlags::NO_WRITE, 0, 0, 1) \ + V(GetGlobalEnvByFunc, GET_GLOBAL_ENV_BY_FUNC, GateFlags::NO_WRITE, 0, 0, 1) \ #define SHARE_GATE_OPCODE_LIST(V) \ V(CONSTSTRING) diff --git a/ecmascript/compiler/slowpath_lowering.cpp b/ecmascript/compiler/slowpath_lowering.cpp index 8de6466e63711986db439df3b55e45d5348fa188..6f6afcb74465874f0cfdb88e7cf5a7baa818c0ee 100644 --- a/ecmascript/compiler/slowpath_lowering.cpp +++ b/ecmascript/compiler/slowpath_lowering.cpp @@ -44,7 +44,7 @@ void SlowPathLowering::CallRuntimeLowering() { std::vector gateList; circuit_->GetAllGates(gateList); - + GateRef test = Circuit::NullGate(); for (const auto &gate : gateList) { auto op = acc_.GetOpCode(gate); [[maybe_unused]] auto scopedGate = circuit_->VisitGateBegin(gate); @@ -88,6 +88,9 @@ void SlowPathLowering::CallRuntimeLowering() case OpCode::GET_UNSHARED_CONSTPOOL: unsharedCP_.emplace_back(gate); break; + case OpCode::GET_GLOBAL_ENV_BY_FUNC: + test = gate; + break; default: break; } @@ -102,6 +105,8 @@ void SlowPathLowering::CallRuntimeLowering() LowerGetSharedConstPool(sharedConstPool); } + LowerGetGlobalEnvbyFunc(test); + if (IsLogEnabled()) { LOG_COMPILER(INFO) << " "; LOG_COMPILER(INFO) << "\033[34m" << "=================" @@ -1303,7 +1308,7 @@ void SlowPathLowering::LowerLdSymbol(GateRef gate) void SlowPathLowering::LowerLdGlobal(GateRef gate) { - GateRef globalEnv = builder_.GetGlobalEnv(glue_); + GateRef globalEnv = circuit_->GetGlobalEnvCache(); GateRef newGate = builder_.GetGlobalEnvValue(VariableType::JS_ANY(), glue_, globalEnv, GlobalEnv::JS_GLOBAL_OBJECT_INDEX); ReplaceHirWithValue(gate, newGate); @@ -1619,7 +1624,7 @@ GateRef SlowPathLowering::LowerUpdateArrayHClassAtDefine(GateRef gate, GateRef a { ElementsKind kind = acc_.TryGetElementsKind(gate); if (!Elements::IsGeneric(kind)) { - GateRef globalEnv = builder_.GetGlobalEnv(glue_); + GateRef globalEnv = circuit_->GetGlobalEnvCache(); size_t elementIndex = static_cast(compilationEnv_->GetArrayHClassIndex(kind, false)); GateRef hclass = builder_.GetGlobalEnvValue(VariableType::JS_ANY(), glue_, globalEnv, elementIndex); builder_.Store(VariableType::JS_POINTER(), glue_, array, builder_.IntPtr(0), hclass); @@ -3802,6 +3807,18 @@ void SlowPathLowering::LowerGetSharedConstPool(GateRef gate) acc_.DeleteGate(gate); } +void SlowPathLowering::LowerGetGlobalEnvbyFunc(GateRef gate) +{ + ASSERT(acc_.GetNumValueIn(gate) == 1); + GateRef jsFunc = acc_.GetValueIn(gate, 0); + GateRef lexicalEnv = builder_.Load(VariableType::JS_ANY(), glue_, jsFunc, + builder_.IntPtr(JSFunction::LEXICAL_ENV_OFFSET), acc_.GetDependRoot()); + GateRef globalEnv = + builder_.Load(VariableType::JS_ANY(), glue_, lexicalEnv, builder_.IntPtr(TaggedArray::DATA_OFFSET), lexicalEnv); + acc_.UpdateAllUses(gate, globalEnv); + acc_.DeleteGate(gate); +} + void SlowPathLowering::LowerGetUnsharedConstPool(GateRef gate) { bool useConstPool = false; diff --git a/ecmascript/compiler/slowpath_lowering.h b/ecmascript/compiler/slowpath_lowering.h index f55662459e1a8ecc09f6a026d22b6815fb41b037..1f0ac5873b34e6aab8a527d44c85046484039484 100644 --- a/ecmascript/compiler/slowpath_lowering.h +++ b/ecmascript/compiler/slowpath_lowering.h @@ -342,6 +342,7 @@ private: void LowerLdStr(GateRef gate); void LowerGetSharedConstPool(GateRef gate); void LowerGetUnsharedConstPool(GateRef gate); + void LowerGetGlobalEnvbyFunc(GateRef gate); void LowerLdLazyExternalModuleVar(GateRef gate); void LowerLdLazySendableExternalModuleVar(GateRef gate); GateRef GetStringFromConstPool(GateRef gate, GateRef stringId, uint32_t stringIdIdx); diff --git a/ecmascript/compiler/state_split_linearizer.cpp b/ecmascript/compiler/state_split_linearizer.cpp index 0239ade1b358272315dd65ae667c578b61701aca..160cd13ee8ddef8c5ae0c39e1d8319e1cf7babe5 100644 --- a/ecmascript/compiler/state_split_linearizer.cpp +++ b/ecmascript/compiler/state_split_linearizer.cpp @@ -117,9 +117,8 @@ public: circuit->GetAllGates(gateList); for (const auto &gate : gateList) { - if (acc_.GetMark(gate) == MarkCode::NO_MARK && - !acc_.IsProlog(gate) && !acc_.IsRoot(gate) && - acc_.GetId(gate) <= maxGateId_) { + if (acc_.GetMark(gate) == MarkCode::NO_MARK && !acc_.IsProlog(gate) && !acc_.IsRoot(gate) && + !(acc_.GetOpCode(gate) == OpCode::GET_GLOBAL_ENV_BY_FUNC) && acc_.GetId(gate) <= maxGateId_) { acc_.DeleteGate(gate); } } diff --git a/ecmascript/compiler/typed_bytecode_lowering.cpp b/ecmascript/compiler/typed_bytecode_lowering.cpp index 4fb199fc9282c9b76ba7854af2ce9ff31a6fbe19..a41857179079b130bf415cfc602f3e10a1f1f83a 100644 --- a/ecmascript/compiler/typed_bytecode_lowering.cpp +++ b/ecmascript/compiler/typed_bytecode_lowering.cpp @@ -593,7 +593,7 @@ GateRef TypedBytecodeLowering::GetPrimitiveTypeProto(PrimitiveType primitiveType UNREACHABLE(); } ASSERT(index != static_cast(-1)); - return builder_.GetGlobalEnvValue(VariableType::JS_ANY(), glue_, builder_.GetGlobalEnv(), index); + return builder_.GetGlobalEnvValue(VariableType::JS_ANY(), glue_, circuit_->GetGlobalEnvCache(), index); } void TypedBytecodeLowering::PolyPrimitiveTypeCheckAndLoad(LoadObjByNameDataInfo &info, @@ -1299,7 +1299,7 @@ bool TypedBytecodeLowering::TryLowerTypedLdObjByNameForGlobalsId(const LoadBulit // 1. check hclass builder_.HeapObjectCheck(receiver, frameState); GateRef receiverHClass = builder_.LoadHClassByConstOffset(glue_, receiver); - GateRef globalEnvObj = builder_.GetGlobalEnvObj(builder_.GetGlobalEnv(), static_cast(index)); + GateRef globalEnvObj = builder_.GetGlobalEnvObj(circuit_->GetGlobalEnvCache(), static_cast(index)); builder_.DeoptCheck(builder_.Equal(receiverHClass, globalEnvObj), frameState, DeoptType::INCONSISTENTHCLASS12); // 2. load property @@ -1449,7 +1449,7 @@ bool TypedBytecodeLowering::TryLowerTypedLdObjByNameForBuiltinMethod(const LoadB } // Successfully goes to typed path GateRef plrGate = builder_.Int32(plr.GetData()); - GateRef prototype = builder_.GetGlobalEnvObj(builder_.GetGlobalEnv(), static_cast(*protoField)); + GateRef prototype = builder_.GetGlobalEnvObj(circuit_->GetGlobalEnvCache(), static_cast(*protoField)); GateRef result = builder_.LoadProperty(prototype, plrGate, plr.IsFunction()); acc_.ReplaceHirAndDeleteIfException(gate, builder_.GetStateDepend(), result); return true; @@ -2746,7 +2746,7 @@ void TypedBytecodeLowering::LowerInstanceOf(GateRef gate) void TypedBytecodeLowering::LowerCreateEmptyObject(GateRef gate) { AddProfiling(gate); - GateRef globalEnv = builder_.GetGlobalEnv(); + GateRef globalEnv = circuit_->GetGlobalEnvCache(); GateRef hclass = builder_.GetGlobalEnvObjHClass(globalEnv, GlobalEnv::OBJECT_FUNCTION_INDEX); JSHandle objectFunc(compilationEnv_->GetGlobalEnv()->GetObjectFunction()); diff --git a/ecmascript/compiler/typed_hcr_lowering.cpp b/ecmascript/compiler/typed_hcr_lowering.cpp index 1a6e8627c547a9b538fa235537a8e1e1da705a69..1a971f8518ab07a03f7748d87ea6fd339dd3930c 100644 --- a/ecmascript/compiler/typed_hcr_lowering.cpp +++ b/ecmascript/compiler/typed_hcr_lowering.cpp @@ -425,7 +425,7 @@ void TypedHCRLowering::LowerTypedArrayCheck(GateRef glue, GateRef gate) SetDeoptTypeInfo(builtinType, deoptType, typedArrayRootHclassIndex, typedArrayRootHclassOnHeapIndex); GateRef frameState = GetFrameState(gate); - GateRef globalEnv = builder_.GetGlobalEnv(); + GateRef globalEnv = circuit_->GetGlobalEnvCache(); GateRef receiver = acc_.GetValueIn(gate, 0); builder_.HeapObjectCheck(receiver, frameState); GateRef receiverHClass = builder_.LoadHClassByConstOffset(glue, receiver); @@ -512,7 +512,7 @@ void TypedHCRLowering::LowerEcmaMapCheck(GateRef glue, GateRef gate) GateRef hclass = builder_.LoadHClassByConstOffset(glue, receiver); size_t mapHclassIndex = GlobalEnv::MAP_CLASS_INDEX; - GateRef globalEnv = builder_.GetGlobalEnv(); + GateRef globalEnv = circuit_->GetGlobalEnvCache(); GateRef mapHclass = builder_.GetGlobalEnvObj(globalEnv, mapHclassIndex); GateRef isMap = builder_.Equal(hclass, mapHclass, "Check HClass"); @@ -713,7 +713,7 @@ void TypedHCRLowering::BuiltinInstanceHClassCheck(Environment *env, GateRef gate GateRef receiverHClass = builder_.LoadHClassByConstOffset(glue, receiver); // If the Elements kind is Generic, hclass comparison is required. Other kinds can ensure that hclass has // not been modified. - GateRef globalEnv = builder_.GetGlobalEnv(glue); + GateRef globalEnv = circuit_->GetGlobalEnvCache(); ihcMatches = LogicOrBuilder(env) .Or(builder_.Equal(receiverHClass, builder_.GetGlobalEnvValue(VariableType::JS_ANY(), glue, globalEnv, @@ -1354,7 +1354,7 @@ void TypedHCRLowering::LowerStringLoadElement(GateRef gate, GateRef glue) result = builder_.CallStub(glue, gate, CommonStubCSigns::StringLoadElement, { glue, receiver, index }, "StringLoadElement stub"); } else { - BuiltinsStringStubBuilder builder(&env, builder_.GetGlobalEnv(glue)); + BuiltinsStringStubBuilder builder(&env, circuit_->GetGlobalEnvCache()); result = builder.GetSingleCharCodeByIndex(glue, receiver, index); } @@ -2114,7 +2114,7 @@ void TypedHCRLowering::LowerArrayConstructorCheck(GateRef gate, GateRef glue) builder_.Bind(&isJSFunction); { Label getHclass(&builder_); - GateRef globalEnv = builder_.GetGlobalEnv(glue); + GateRef globalEnv = circuit_->GetGlobalEnvCache(); GateRef arrayFunc = builder_.GetGlobalEnvValue(VariableType::JS_ANY(), glue, globalEnv, GlobalEnv::ARRAY_FUNCTION_INDEX); check = builder_.Equal(arrayFunc, newTarget); @@ -2194,7 +2194,7 @@ void TypedHCRLowering::LowerArrayConstructor(GateRef gate, GateRef glue) builder_.Int64GreaterThan(*arrayLength, builder_.Int64(JSObject::MAX_GAP)), &slowPath, &lengthValid); builder_.Bind(&lengthValid); { - NewObjectStubBuilder newBuilder(builder_.GetCurrentEnvironment(), builder_.GetGlobalEnv(glue)); + NewObjectStubBuilder newBuilder(builder_.GetCurrentEnvironment(), circuit_->GetGlobalEnvCache()); newBuilder.SetParameters(glue, 0); res = newBuilder.NewJSArrayWithSize(intialHClass, *arrayLength); GateRef lengthOffset = builder_.IntPtr(JSArray::LENGTH_OFFSET); @@ -2225,7 +2225,7 @@ void TypedHCRLowering::LowerFloat32ArrayConstructorCheck(GateRef gate, GateRef g Environment env(gate, circuit_, &builder_); GateRef frameState = GetFrameState(gate); GateRef newTarget = acc_.GetValueIn(gate, 0); - GateRef globalEnv = builder_.GetGlobalEnv(glue); + GateRef globalEnv = circuit_->GetGlobalEnvCache(); GateRef arrayFunc = builder_.GetGlobalEnvValue(VariableType::JS_ANY(), glue, globalEnv, GlobalEnv::FLOAT32_ARRAY_FUNCTION_INDEX); GateRef check = builder_.Equal(arrayFunc, newTarget); @@ -2235,7 +2235,7 @@ void TypedHCRLowering::LowerFloat32ArrayConstructorCheck(GateRef gate, GateRef g void TypedHCRLowering::NewFloat32ArrayConstructorWithNoArgs(GateRef gate, GateRef glue) { - NewObjectStubBuilder newBuilder(builder_.GetCurrentEnvironment(), builder_.GetGlobalEnv(glue)); + NewObjectStubBuilder newBuilder(builder_.GetCurrentEnvironment(), circuit_->GetGlobalEnvCache()); newBuilder.SetParameters(glue, 0); GateRef res = newBuilder.NewFloat32ArrayWithSize(glue, builder_.Int32(0)); acc_.ReplaceGate(gate, builder_.GetState(), builder_.GetDepend(), res); @@ -2316,7 +2316,7 @@ void TypedHCRLowering::LowerFloat32ArrayConstructor(GateRef gate, GateRef glue) ConvertFloat32ArrayConstructorLength(arg0, &arrayLength, &arrayCreateByLength, &arrayCreate); builder_.Bind(&arrayCreateByLength); { - NewObjectStubBuilder newBuilder(builder_.GetCurrentEnvironment(), builder_.GetGlobalEnv(glue)); + NewObjectStubBuilder newBuilder(builder_.GetCurrentEnvironment(), circuit_->GetGlobalEnvCache()); newBuilder.SetParameters(glue, 0); GateRef truncedLength = builder_.TruncInt64ToInt32(*arrayLength); res = newBuilder.NewFloat32ArrayWithSize(glue, truncedLength); @@ -2324,7 +2324,7 @@ void TypedHCRLowering::LowerFloat32ArrayConstructor(GateRef gate, GateRef glue) } builder_.Bind(&arrayCreate); { - NewObjectStubBuilder newBuilder(builder_.GetCurrentEnvironment(), builder_.GetGlobalEnv(glue)); + NewObjectStubBuilder newBuilder(builder_.GetCurrentEnvironment(), circuit_->GetGlobalEnvCache()); newBuilder.SetParameters(glue, 0); GateRef thisObj = newBuilder.NewFloat32ArrayObj(glue); GateRef argc = builder_.Int64(4); // 4: means func newtarget thisObj arg0 @@ -2343,7 +2343,7 @@ void TypedHCRLowering::NewArrayConstructorWithNoArgs(GateRef gate, GateRef glue) GateRef intialHClass = builder_.Load(VariableType::JS_ANY(), glue, newTarget, builder_.IntPtr(JSFunction::PROTO_OR_DYNCLASS_OFFSET)); GateRef arrayLength = builder_.Int64(0); - NewObjectStubBuilder newBuilder(builder_.GetCurrentEnvironment(), builder_.GetGlobalEnv(glue)); + NewObjectStubBuilder newBuilder(builder_.GetCurrentEnvironment(), circuit_->GetGlobalEnvCache()); newBuilder.SetParameters(glue, 0); GateRef res = newBuilder.NewJSArrayWithSize(intialHClass, arrayLength); GateRef lengthOffset = builder_.IntPtr(JSArray::LENGTH_OFFSET); @@ -2373,7 +2373,7 @@ void TypedHCRLowering::LowerObjectConstructorCheck(GateRef gate, GateRef glue) builder_.Bind(&isJSFunction); { Label getHclass(&builder_); - GateRef globalEnv = builder_.GetGlobalEnv(glue); + GateRef globalEnv = circuit_->GetGlobalEnvCache(); GateRef targetFunc = builder_.GetGlobalEnvValue(VariableType::JS_ANY(), glue, globalEnv, GlobalEnv::OBJECT_FUNCTION_INDEX); check = builder_.Equal(targetFunc, newTarget); @@ -2465,7 +2465,7 @@ void TypedHCRLowering::LowerObjectConstructor(GateRef gate, GateRef glue) BRANCH_CIR(builder_.TaggedIsUndefinedOrNull(value), &isNullOrUndefined, &slowPath); builder_.Bind(&isNullOrUndefined); { - GateRef globalEnv = builder_.GetGlobalEnv(glue); + GateRef globalEnv = circuit_->GetGlobalEnvCache(); GateRef objectFunctionPrototype = builder_.GetGlobalEnvValue(VariableType::JS_ANY(), glue, globalEnv, GlobalEnv::OBJECT_FUNCTION_PROTOTYPE_INDEX); res = builder_.OrdinaryNewJSObjectCreate(glue, objectFunctionPrototype); @@ -2506,7 +2506,7 @@ void TypedHCRLowering::LowerBooleanConstructorCheck(GateRef gate, GateRef glue) builder_.Bind(&isJSFunction); { Label getHclass(&builder_); - GateRef globalEnv = builder_.GetGlobalEnv(glue); + GateRef globalEnv = circuit_->GetGlobalEnvCache(); GateRef booleanFunc = builder_.GetGlobalEnvValue(VariableType::JS_ANY(), glue, globalEnv, GlobalEnv::BOOLEAN_FUNCTION_INDEX); check = builder_.Equal(booleanFunc, newTarget); @@ -2559,7 +2559,7 @@ void TypedHCRLowering::LowerBooleanConstructor(GateRef gate, GateRef glue) GateRef TypedHCRLowering::NewJSPrimitiveRef(PrimitiveType type, GateRef glue, GateRef value) { - GateRef globalEnv = builder_.GetGlobalEnv(glue); + GateRef globalEnv = circuit_->GetGlobalEnvCache(); GateRef ctor = Circuit::NullGate(); switch (type) { case PrimitiveType::PRIMITIVE_NUMBER: { diff --git a/ecmascript/compiler/typed_native_inline_lowering.cpp b/ecmascript/compiler/typed_native_inline_lowering.cpp index 8d94161479954277cd1e4b5382290118771dfc8c..a038cd39d5561ad3fe0487149fb51c3dbf2a1376 100644 --- a/ecmascript/compiler/typed_native_inline_lowering.cpp +++ b/ecmascript/compiler/typed_native_inline_lowering.cpp @@ -450,7 +450,7 @@ void TypedNativeInlineLowering::LowerTypedArrayIterator(GateRef gate, CommonStub BRANCH_CIR(hasNoConstructor, &selfValidLabel, &selfInvalidLabel); builder_.Bind(&selfValidLabel); { - GateRef globalEnv = builder_.GetGlobalEnv(glue); + GateRef globalEnv = circuit_->GetGlobalEnvCache(); GateRef prototype = builder_.GetGlobalEnvValue(VariableType::JS_POINTER(), glue, globalEnv, GlobalEnv::ARRAY_ITERATOR_PROTOTYPE_INDEX); @@ -1152,8 +1152,8 @@ void TypedNativeInlineLowering::LowerNewNumber(GateRef gate) GateRef numberFunction = acc_.GetValueIn(gate, 0); GateRef param = acc_.GetValueIn(gate, 1); - GateRef globalEnvNumberFunction = builder_.GetGlobalEnvValue(VariableType::JS_ANY(), glue, builder_.GetGlobalEnv(), - GlobalEnv::NUMBER_FUNCTION_INDEX); + GateRef globalEnvNumberFunction = builder_.GetGlobalEnvValue( + VariableType::JS_ANY(), glue, circuit_->GetGlobalEnvCache(), GlobalEnv::NUMBER_FUNCTION_INDEX); auto builtinIsNumber = builder_.Equal(numberFunction, globalEnvNumberFunction); builder_.DeoptCheck(builtinIsNumber, FindFrameState(gate), DeoptType::NEWBUILTINCTORFAIL1); @@ -1173,7 +1173,7 @@ void TypedNativeInlineLowering::LowerNewNumber(GateRef gate) builder_.DeoptCheck(builder_.TaggedIsLineUtf8String(glue, param), FindFrameState(gate), DeoptType::NOTSTRING1); auto length = builder_.GetLengthFromString(param); builder_.DeoptCheck(builder_.NotEqual(length, builder_.Int32(0)), FindFrameState(gate), DeoptType::NOTINT1); - BuiltinsStringStubBuilder stringStub(builder_.GetCurrentEnvironment(), builder_.GetGlobalEnv(glue)); + BuiltinsStringStubBuilder stringStub(builder_.GetCurrentEnvironment(), circuit_->GetGlobalEnvCache()); GateRef dataUtf8 = builder_.PtrAdd(param, builder_.IntPtr(LineString::DATA_OFFSET)); GateRef res = stringStub.StringDataToUint(dataUtf8, length, std::numeric_limits::max()); builder_.DeoptCheck(builder_.NotEqual(res, builder_.Int64(-1)), FindFrameState(gate), DeoptType::NOTINT1); @@ -1999,7 +1999,7 @@ GateRef TypedNativeInlineLowering::CheckAndConvertToUInt(GateRef glue, GateRef m auto length = builder_.GetLengthFromString(msg); BRANCH_CIR(builder_.Equal(length, builder_.Int32(0)), notIntegerStr, nonZeroLength); builder_.Bind(nonZeroLength); - BuiltinsStringStubBuilder stringStub(builder_.GetCurrentEnvironment(), builder_.GetGlobalEnv(glue)); + BuiltinsStringStubBuilder stringStub(builder_.GetCurrentEnvironment(), circuit_->GetGlobalEnvCache()); GateRef dataUtf8 = builder_.PtrAdd(msg, builder_.IntPtr(LineString::DATA_OFFSET)); return stringStub.StringDataToUint(dataUtf8, length, std::numeric_limits::max()); } @@ -2152,7 +2152,7 @@ void TypedNativeInlineLowering::LowerStringCharCodeAt(GateRef gate) BRANCH_CIR(builder_.Int32UnsignedLessThan(pos, strLen), &posIsValid, &posNotValid); builder_.Bind(&posIsValid); { - BuiltinsStringStubBuilder stringBuilder(builder_.GetCurrentEnvironment(), builder_.GetGlobalEnv(glue)); + BuiltinsStringStubBuilder stringBuilder(builder_.GetCurrentEnvironment(), circuit_->GetGlobalEnvCache()); result = stringBuilder.FastStringCharCodeAt(glue, thisValue, pos); builder_.Jump(&exit); } @@ -2230,7 +2230,7 @@ void TypedNativeInlineLowering::LowerStringSubstring(GateRef gate) from = BuildIntMinMax(finalStart, finalEnd); to = BuildIntMinMax(finalStart, finalEnd); const CallSignature *cs = BuiltinsStubCSigns::Get(BuiltinsStubCSigns::ID::StringSubstring); - BuiltinsStringStubBuilder stringBuilder(const_cast(cs), &env, builder_.GetGlobalEnv(glue)); + BuiltinsStringStubBuilder stringBuilder(const_cast(cs), &env, circuit_->GetGlobalEnvCache()); GateRef len = builder_.Int32Sub(*to, *from); result = stringBuilder.GetSubString(glue, thisValue, *from, len); acc_.ReplaceGate(gate, builder_.GetStateDepend(), *result); @@ -2319,7 +2319,8 @@ void TypedNativeInlineLowering::LowerStringSubStr(GateRef gate) builder_.Bind(&resLenNotLessOrEqualZero); { const CallSignature *cs = BuiltinsStubCSigns::Get(BuiltinsStubCSigns::ID::StringSubStr); - BuiltinsStringStubBuilder stringBuilder(const_cast(cs), &env, builder_.GetGlobalEnv(glue)); + BuiltinsStringStubBuilder stringBuilder(const_cast(cs), &env, + circuit_->GetGlobalEnvCache()); result = stringBuilder.GetFastSubString(glue, thisValue, *start, *resultLength); builder_.Jump(&exit); } @@ -2425,8 +2426,8 @@ void TypedNativeInlineLowering::LowerStringSlice(GateRef gate) builder_.Bind(&fromLessThanTo); { const CallSignature *cs = BuiltinsStubCSigns::Get(BuiltinsStubCSigns::ID::StringSlice); - BuiltinsStringStubBuilder stringBuilder(const_cast(cs), &env, - builder_.GetGlobalEnv(glue)); + BuiltinsStringStubBuilder stringBuilder(const_cast(cs), &env, + circuit_->GetGlobalEnvCache()); GateRef len = builder_.Int32Sub(*to, *from); result = stringBuilder.GetSubString(glue, thisValue, *from, len); builder_.Jump(&exit); @@ -2493,7 +2494,7 @@ void TypedNativeInlineLowering::LowerObjectGetPrototypeOf(GateRef gate) // fast handle some primitive types if (TypeInfoAccessor::IsTrustedBooleanOrNumberOrStringType(compilationEnv_, circuit_, chunk_, acc_, value)) { - GateRef globalEnv = builder_.GetGlobalEnv(glue); + GateRef globalEnv = circuit_->GetGlobalEnvCache(); size_t index = -1; if (TypeInfoAccessor::IsTrustedBooleanType(acc_, value)) { index = GlobalEnv::BOOLEAN_PROTOTYPE_INDEX; diff --git a/ecmascript/compiler/useless_gate_elimination.cpp b/ecmascript/compiler/useless_gate_elimination.cpp index f673255eb4b26661016987fc95f97c9fc13a810c..381e006ff34e80c8891ff4bf1e7d25883108eaa7 100644 --- a/ecmascript/compiler/useless_gate_elimination.cpp +++ b/ecmascript/compiler/useless_gate_elimination.cpp @@ -35,7 +35,7 @@ void UselessGateElimination::InitList() for (auto gate : gateList_) { if (acc_.GetOpCode(gate) == OpCode::LOOP_BEGIN) { PushGate(gate); - } else if (acc_.IsProlog(gate) || acc_.IsRoot(gate)) { + } else if (acc_.IsProlog(gate) || acc_.IsRoot(gate) || acc_.GetOpCode(gate) == OpCode::GET_GLOBAL_ENV_BY_FUNC) { acc_.SetMark(gate, MarkCode::VISITED); } }