1 /* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef ECMASCRIPT_COMPILER_PROFILER_STUB_BUILDER_H 17 #define ECMASCRIPT_COMPILER_PROFILER_STUB_BUILDER_H 18 19 #include "ecmascript/compiler/profiler_operation.h" 20 #include "ecmascript/compiler/stub_builder.h" 21 22 namespace panda::ecmascript::kungfu { 23 class ProfilerStubBuilder : public StubBuilder { 24 public: ProfilerStubBuilder(StubBuilder * parent)25 explicit ProfilerStubBuilder(StubBuilder *parent) : StubBuilder(parent) {} ProfilerStubBuilder(Environment * env)26 explicit ProfilerStubBuilder(Environment *env) : StubBuilder(env) {} 27 ~ProfilerStubBuilder() override = default; 28 NO_MOVE_SEMANTIC(ProfilerStubBuilder); 29 NO_COPY_SEMANTIC(ProfilerStubBuilder); GenerateCircuit()30 void GenerateCircuit() override {} 31 32 void PGOProfiler(GateRef glue, GateRef pc, GateRef func, GateRef profileTypeInfo, 33 const std::vector<GateRef> &values, SlotIDFormat format, OperationType type); 34 35 void TryDump(GateRef glue, GateRef func, GateRef profileTypeInfo); 36 void TryPreDump(GateRef glue, GateRef func, GateRef profileTypeInfo); 37 38 void ProfileCall( 39 GateRef glue, GateRef pc, GateRef func, GateRef target, GateRef profileTypeInfo, SlotIDFormat format); 40 void ProfileNativeCall( 41 GateRef glue, GateRef pc, GateRef func, GateRef target, GateRef profileTypeInfo, SlotIDFormat format); 42 void ProfileOpType( 43 GateRef glue, GateRef pc, GateRef func, GateRef profileTypeInfo, GateRef type, SlotIDFormat format); 44 void ProfileDefineClass( 45 GateRef glue, GateRef pc, GateRef func, GateRef constructor, GateRef profileTypeInfo, SlotIDFormat format); 46 void ProfileCreateObject( 47 GateRef glue, GateRef pc, GateRef func, GateRef newObj, GateRef profileTypeInfo, SlotIDFormat format); 48 void ProfileBranch(GateRef glue, GateRef pc, GateRef func, GateRef profileTypeInfo, bool isTrue); 49 void ProfileGetIterator( 50 GateRef glue, GateRef pc, GateRef func, GateRef iterator, GateRef profileTypeInfo, SlotIDFormat format); 51 52 GateRef UpdateTrackTypeInPropAttr(GateRef attr, GateRef value, ProfileOperation callback); 53 void UpdatePropAttrIC(GateRef glue, GateRef receiver, GateRef value, GateRef handler, ProfileOperation callback); 54 void UpdatePropAttrWithValue(GateRef glue, GateRef jsType, GateRef layout, GateRef attr, GateRef attrIndex, 55 GateRef value, ProfileOperation callback); 56 57 GateRef IsProfileTypeInfoDumped(GateRef profileTypeInfo, ProfileOperation callback); 58 59 void TryJitCompile(GateRef glue, GateRef func, GateRef profileTypeInfo); 60 GateRef IsHotForJitCompiling(GateRef profileTypeInfo, ProfileOperation callback); 61 GateRef IsHotForJitCompiling(GateRef profileTypeInfo); 62 63 private: 64 static constexpr size_t MAX_PROFILE_CALL_COUNT = 10000; 65 static constexpr size_t MIN_PROFILE_CALL_INTERVAL = 5; 66 static constexpr size_t BITS_OF_WORD = 8; 67 static constexpr size_t HIGH_WORD_OFFSET = 2; 68 static constexpr size_t LOW_WORD_OFFSET = 1; 69 70 void TryPreDumpInner(GateRef glue, GateRef func, GateRef profileTypeInfo); 71 72 GateRef GetSlotID(GateRef pc, SlotIDFormat format); 73 GateRef GetBitFieldOffsetFromProfileTypeInfo(GateRef profileTypeInfo); 74 GateRef IsProfileTypeInfoDumped(GateRef profileTypeInfo); 75 GateRef IsProfileTypeInfoPreDumped(GateRef profileTypeInfo); 76 void SetDumpPeriodIndex(GateRef glue, GateRef profileTypeInfo); 77 void SetPreDumpPeriodIndex(GateRef glue, GateRef profileTypeInfo); 78 GateRef TaggedToTrackType(GateRef value); 79 GateRef GetIterationFunctionId(GateRef glue, GateRef iterator); 80 GateRef TryGetBuiltinFunctionId(GateRef target); 81 GateRef GetJitHotnessCnt(GateRef profileTypeInfo); 82 GateRef GetJitHotnessThreshold(GateRef profileTypeInfo); 83 GateRef GetJitHotnessThresholdOffset(GateRef profileTypeInfo); 84 GateRef GetJitHotnessCntOffset(GateRef profileTypeInfo); 85 }; 86 } // namespace panda::ecmascript::kungfu 87 #endif // ECMASCRIPT_COMPILER_PROFILER_STUB_BUILDER_H 88