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_VALUE_NUMBERING_H 17 #define ECMASCRIPT_COMPILER_VALUE_NUMBERING_H 18 19 #include "ecmascript/compiler/circuit_builder.h" 20 #include "ecmascript/compiler/combined_pass_visitor.h" 21 #include "ecmascript/compiler/gate_accessor.h" 22 #include "ecmascript/mem/chunk_containers.h" 23 24 namespace panda::ecmascript::kungfu { 25 class ValueNumbering : public PassVisitor { 26 public: ValueNumbering(Circuit * circuit,RPOVisitor * visitor,Chunk * chunk,bool useNewGVN,bool enableLog)27 ValueNumbering(Circuit *circuit, RPOVisitor *visitor, Chunk* chunk, bool useNewGVN, bool enableLog) 28 : PassVisitor(circuit, chunk, visitor), entries_(nullptr), useNewGVN_(useNewGVN), 29 enableLog_(enableLog) {} 30 31 ~ValueNumbering() = default; 32 33 GateRef VisitGate(GateRef gate) override; 34 bool CheckReplacement(GateRef lhs, GateRef rhs); GetoptimizedGateCount()35 int GetoptimizedGateCount() 36 { 37 return optimizedGateCount; 38 } 39 40 private: 41 void Grow(); 42 void EnsureCapacity(); 43 void InitEntries(size_t initSize); 44 size_t HashCode(GateRef gate); SetEntry(size_t hash,GateRef gate)45 void SetEntry(size_t hash, GateRef gate) 46 { 47 entries_[hash & (entriesLength_ - 1)] = gate; 48 } 49 static const uint32_t CACHE_LENGTH_BIT = 8; 50 static const uint32_t CACHE_LENGTH = (1U << CACHE_LENGTH_BIT); 51 const uint8_t LOAD_FACTOR_THRESHOLD = 4; 52 uint32_t entriesLength_ = (1U << CACHE_LENGTH_BIT); 53 uint32_t entriesSize_ = 0; 54 GateRef* entries_; 55 bool useNewGVN_; 56 int optimizedGateCount = 0; 57 bool enableLog_ = false; 58 }; 59 } // panda::ecmascript::kungfu 60 #endif // ECMASCRIPT_COMPILER_VALUE_NUMBERING_H