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_JIT_COMPILER_H 17 #define ECMASCRIPT_COMPILER_JIT_COMPILER_H 18 19 #include "ecmascript/compiler/pass_manager.h" 20 #include "ecmascript/ecma_vm.h" 21 #include "ecmascript/jit/jit_task.h" 22 23 namespace panda::ecmascript::kungfu { 24 extern "C" { 25 PUBLIC_API void *CreateJitCompiler(EcmaVM *vm, JitTask *jitTask); 26 PUBLIC_API bool JitCompile(void *compiler, JitTask *jitTask); 27 PUBLIC_API bool JitFinalize(void *compiler, JitTask *jitTask); 28 PUBLIC_API void DeleteJitCompile(void *handle); 29 }; 30 31 struct JitCompilationOptions { 32 JitCompilationOptions(JSRuntimeOptions &runtimeOptions, EcmaVM *vm); 33 JitCompilationOptions() = default; 34 35 std::string triple_; 36 std::string outputFileName_; 37 size_t optLevel_; 38 size_t relocMode_; 39 std::string logOption_; 40 std::string logMethodsList_; 41 bool compilerLogTime_; 42 size_t maxAotMethodSize_; 43 size_t maxMethodsInModule_; 44 uint32_t hotnessThreshold_; 45 std::string profilerIn_; 46 bool isEnableArrayBoundsCheckElimination_; 47 bool isEnableTypeLowering_; 48 bool isEnableEarlyElimination_; 49 bool isEnableLaterElimination_; 50 bool isEnableValueNumbering_; 51 bool isEnableOptInlining_; 52 bool isEnableOptString_; 53 bool isEnableTypeInfer_; 54 bool isEnableOptPGOType_; 55 bool isEnableOptTrackField_; 56 bool isEnableOptLoopPeeling_; 57 bool isEnableOptOnHeapCheck_; 58 bool isEnableOptLoopInvariantCodeMotion_; 59 bool isEnableCollectLiteralInfo_; 60 bool isEnableOptConstantFolding_; 61 bool isEnableLexenvSpecialization_; 62 bool isEnableNativeInline_; 63 bool isEnableLoweringBuiltin_; 64 }; 65 66 class JitCompiler { 67 public: 68 static JitCompiler *Create(EcmaVM *vm, JitTask *jitTask); JitCompiler(EcmaVM * vm,JSHandle<JSFunction> jsFunction)69 explicit JitCompiler(EcmaVM *vm, JSHandle<JSFunction> jsFunction) 70 : vm_(vm), 71 jsFunction_(jsFunction), 72 jitOptions_(vm->GetJSOptions(), vm), 73 log_(jitOptions_.logOption_), 74 logList_(jitOptions_.logMethodsList_), 75 profilerDecoder_(jitOptions_.profilerIn_, jitOptions_.hotnessThreshold_) 76 { 77 Init(); 78 } 79 ~JitCompiler(); 80 void Init(); 81 82 bool Compile(); 83 bool Finalize(JitTask *jitTask); 84 85 private: 86 EcmaVM *vm_; 87 JSHandle<JSFunction> jsFunction_; 88 JitCompilationOptions jitOptions_; 89 CompilerLog log_; 90 AotMethodLogList logList_; 91 PGOProfilerDecoder profilerDecoder_; 92 PassOptions passOptions_; 93 JitPassManager *passManager_; 94 AOTFileGenerator *aotFileGenerator_; 95 }; 96 } // namespace panda::ecmascript::kungfu 97 #endif // ECMASCRIPT_COMPILER_JIT_COMPILER_H 98