1 /* 2 * Copyright (c) 2021 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_VERIFIER_H 17 #define ECMASCRIPT_COMPILER_VERIFIER_H 18 19 #include <algorithm> 20 #include <deque> 21 #include <functional> 22 #include <numeric> 23 #include <unordered_map> 24 25 #include "ecmascript/compiler/circuit.h" 26 27 namespace panda::ecmascript::kungfu { 28 class Verifier { 29 public: 30 static bool RunDataIntegrityCheck(const Circuit *circuit); 31 32 static bool RunStateGatesCheck(const Circuit *circuit, const std::vector<GateRef> &bbGatesList); 33 34 static bool RunCFGSoundnessCheck(const Circuit *circuit, const std::vector<GateRef> &bbGatesList, 35 const std::unordered_map<GateRef, size_t> &bbGatesAddrToIdx); 36 37 static bool RunCFGIsDAGCheck(const Circuit *circuit); 38 39 static bool RunCFGReducibilityCheck(const Circuit *circuit, const std::vector<GateRef> &bbGatesList, 40 const std::unordered_map<GateRef, size_t> &bbGatesAddrToIdx, 41 const std::function<bool(size_t, size_t)> &isAncestor); 42 43 static bool RunFixedGatesCheck(const Circuit *circuit, const std::vector<GateRef> &fixedGatesList); 44 45 static bool RunFixedGatesRelationsCheck(const Circuit *circuit, const std::vector<GateRef> &fixedGatesList, 46 const std::unordered_map<GateRef, size_t> &bbGatesAddrToIdx, 47 const std::function<bool(size_t, size_t)> &isAncestor); 48 49 static bool RunFlowCyclesFind(const Circuit *circuit, std::vector<GateRef> *schedulableGatesListPtr, 50 const std::vector<GateRef> &bbGatesList, 51 const std::vector<GateRef> &fixedGatesList); 52 53 static bool RunSchedulableGatesCheck(const Circuit *circuit, const std::vector<GateRef> &schedulableGatesList); 54 55 static bool RunPrologGatesCheck(const Circuit *circuit, const std::vector<GateRef> &schedulableGatesList); 56 57 static bool RunSchedulingBoundsCheck(const Circuit *circuit, const std::vector<GateRef> &schedulableGatesList, 58 const std::unordered_map<GateRef, size_t> &bbGatesAddrToIdx, 59 const std::function<bool(size_t, size_t)> &isAncestor, 60 const std::function<size_t(size_t, size_t)> &lowestCommonAncestor); 61 62 static void FindFixedGates(const Circuit *circuit, const std::vector<GateRef> &bbGatesList, 63 std::vector<GateRef> &fixedGatesList); 64 65 static bool Run(const Circuit *circuit, const std::string& methodName = "", bool enableLog = false); 66 }; 67 } // namespace panda::ecmascript::kungfu 68 69 #endif // ECMASCRIPT_COMPILER_VERIFIER_H 70