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/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<uint8_t>>; 28 using Pc2Deopt = std::map<uint64_t, std::vector<uint8_t>>; 29 }; 30 31 class LiteCGStackMapInfo : public CGStackMapInfo { 32 public: 33 using LLVMPc2CallSiteInfo = LLVMStackMapType::Pc2CallSiteInfo; 34 using LLVMCallSiteInfo = LLVMStackMapType::CallSiteInfo; 35 using LLVMPc2Deopt = LLVMStackMapType::Pc2Deopt; 36 using LLVMDwarfRegAndOffsetType = LLVMStackMapType::DwarfRegAndOffsetType; 37 using LLVMDeoptInfoType = LLVMStackMapType::DeoptInfoType; 38 using LLVMLargeInt = LLVMStackMapType::LargeInt; 39 using LLVMIntType = LLVMStackMapType::IntType; 40 using LLVMOffsetType = LLVMStackMapType::OffsetType; 41 using LLVMDwarfRegType = LLVMStackMapType::DwarfRegType; 42 43 using LiteCGPc2CallSiteInfo = LiteCGStackMapType::Pc2CallSiteInfo; 44 using LiteCGPc2Deopt = LiteCGStackMapType::Pc2Deopt; 45 LiteCGStackMapInfo()46 LiteCGStackMapInfo() : CGStackMapInfo() {} 47 ~LiteCGStackMapInfo() = default; 48 AppendCallSiteInfo(const LiteCGPc2CallSiteInfo & callSiteInfo)49 void AppendCallSiteInfo(const LiteCGPc2CallSiteInfo &callSiteInfo) 50 { 51 pc2CallSiteInfoVec_.push_back(callSiteInfo); 52 } 53 AppendDeoptInfo(const LiteCGPc2Deopt & deoptInfo)54 void AppendDeoptInfo(const LiteCGPc2Deopt &deoptInfo) 55 { 56 pc2DeoptVec_.push_back(deoptInfo); 57 } 58 GetStackMapKind()59 CGStackMapKind GetStackMapKind() const override 60 { 61 return kLiteCGStackMapInfo; 62 } 63 64 void ConvertToLLVMStackMapInfo(std::vector<LLVMPc2CallSiteInfo> &pc2StackMapsVec, 65 std::vector<LLVMPc2Deopt> &pc2DeoptInfoVec, Triple triple) const; 66 private: 67 std::vector<LiteCGPc2CallSiteInfo> pc2CallSiteInfoVec_; 68 std::vector<LiteCGPc2Deopt> pc2DeoptVec_; 69 70 void ConvertToLLVMPc2CallSiteInfo(LLVMPc2CallSiteInfo &pc2CallSiteInfo, 71 const LiteCGPc2CallSiteInfo &liteCGPc2CallSiteInfo, int fpReg) const; 72 void ConvertToLLVMPv2Deopt(LLVMPc2Deopt &pc2DeoptInfo, const LiteCGPc2Deopt &liteCGPc2DeoptInfo, int fpReg) const; 73 }; 74 } // namespace panda::ecmascript::kungfu 75 #endif // ECMASCRIPT_LITECG_STACKMAP_TYPE_H