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 #ifndef ECMASCRIPT_LITECG_STACKMAP_TYPE_H 16 #define ECMASCRIPT_LITECG_STACKMAP_TYPE_H 17 18 #include <cstdint> 19 #include <map> 20 #include <vector> 21 #include "ecmascript/stackmap/cg_stackmap.h" 22 #include "ecmascript/stackmap/llvm_stackmap_type.h" 23 24 namespace panda::ecmascript::kungfu { 25 class LiteCGStackMapType { 26 public: 27 using Pc2CallSiteInfo = std::unordered_map<uint64_t, std::vector<uint64_t>>; 28 using Pc2Deopt = std::map<uint64_t, std::vector<uint64_t>>; 29 }; 30 31 class LiteCGStackMapInfo : public CGStackMapInfo { 32 public: LiteCGStackMapInfo()33 LiteCGStackMapInfo() : CGStackMapInfo() {} 34 ~LiteCGStackMapInfo() = default; 35 GetCallSiteInfoVec()36 const std::vector<LiteCGStackMapType::Pc2CallSiteInfo> &GetCallSiteInfoVec() const 37 { 38 return pc2CallSiteInfoVec_; 39 } 40 GetDeoptInfoVec()41 const std::vector<LiteCGStackMapType::Pc2Deopt> &GetDeoptInfoVec() const 42 { 43 return pc2DeoptVec_; 44 } 45 AppendCallSiteInfo(const LiteCGStackMapType::Pc2CallSiteInfo & callSiteInfo)46 void AppendCallSiteInfo(const LiteCGStackMapType::Pc2CallSiteInfo &callSiteInfo) 47 { 48 pc2CallSiteInfoVec_.push_back(callSiteInfo); 49 } 50 AppendDeoptInfo(const LiteCGStackMapType::Pc2Deopt & deoptInfo)51 void AppendDeoptInfo(const LiteCGStackMapType::Pc2Deopt &deoptInfo) 52 { 53 pc2DeoptVec_.push_back(deoptInfo); 54 } 55 GetStackMapKind()56 CGStackMapKind GetStackMapKind() const override 57 { 58 return kLiteCGStackMapInfo; 59 } 60 61 void ConvertToLLVMStackMapInfo( 62 std::vector<LLVMStackMapType::Pc2CallSiteInfo> &pc2StackMapsVec, 63 std::vector<LLVMStackMapType::Pc2Deopt> &pc2DeoptInfoVec, Triple triple) const; 64 private: 65 std::vector<LiteCGStackMapType::Pc2CallSiteInfo> pc2CallSiteInfoVec_; 66 std::vector<LiteCGStackMapType::Pc2Deopt> pc2DeoptVec_; 67 }; 68 } // namespace panda::ecmascript::kungfu 69 #endif // ECMASCRIPT_LITECG_STACKMAP_TYPE_H