/* * Copyright (c) 2021-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef ECMASCRIPT_COMPILER_CIRCUIT_BUILDER_HELPER_H #define ECMASCRIPT_COMPILER_CIRCUIT_BUILDER_HELPER_H #include "ecmascript/compiler/circuit_builder.h" namespace panda::ecmascript { class JSRuntimeOptions; } // namespace panda::ecmascript namespace panda::ecmascript::kungfu { class CompilationConfig { public: explicit CompilationConfig(const std::string &triple, const JSRuntimeOptions *options = nullptr); ~CompilationConfig() = default; inline bool Is32Bit() const { return triple_ == Triple::TRIPLE_ARM32; } inline bool IsAArch64() const { return triple_ == Triple::TRIPLE_AARCH64; } inline bool IsAmd64() const { return triple_ == Triple::TRIPLE_AMD64; } inline bool Is64Bit() const { return IsAArch64() || IsAmd64(); } Triple GetTriple() const { return triple_; } std::string GetTripleStr() const { return tripleStr_; } bool IsTraceBC() const { return isTraceBc_; } bool IsProfiling() const { return profiling_; } bool IsStressDeopt() const { return stressDeopt_; } bool IsVerifyVTbale() const { return verifyVTable_; } bool IsTypedOpProfiling() const { return typedOpProfiling_; } private: inline Triple GetTripleFromString(const std::string &triple) { if (triple.compare(TARGET_X64) == 0) { return Triple::TRIPLE_AMD64; } if (triple.compare(TARGET_AARCH64) == 0) { return Triple::TRIPLE_AARCH64; } if (triple.compare(TARGET_ARM32) == 0) { return Triple::TRIPLE_ARM32; } LOG_ECMA(FATAL) << "this branch is unreachable"; UNREACHABLE(); } std::string tripleStr_; Triple triple_; bool isTraceBc_ {false}; bool profiling_ {false}; bool stressDeopt_ {false}; bool verifyVTable_ {false}; bool typedOpProfiling_ {false}; }; class Label { public: Label() = default; explicit Label(Environment *env); explicit Label(CircuitBuilder *cirBuilder); ~Label() = default; Label(Label const &label) = default; Label &operator=(Label const &label) = default; Label(Label &&label) = default; Label &operator=(Label &&label) = default; inline void Seal() { return impl_->Seal(); } inline void WriteVariable(Variable *var, GateRef value) { impl_->WriteVariable(var, value); } inline GateRef ReadVariable(Variable *var) { return impl_->ReadVariable(var); } inline void Bind() { impl_->Bind(); } inline void MergeAllControl() { impl_->MergeAllControl(); } inline void MergeAllDepend() { impl_->MergeAllDepend(); } inline void AppendPredecessor(const Label *predecessor) { impl_->AppendPredecessor(predecessor->GetRawLabel()); } inline std::vector