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_TS_HCR_OPT_PASS_H 17 #define ECMASCRIPT_COMPILER_TS_HCR_OPT_PASS_H 18 19 #include "ecmascript/compiler/combined_pass_visitor.h" 20 #include "ecmascript/compiler/pass_manager.h" 21 #include "ecmascript/compiler/pgo_type/pgo_type_manager.h" 22 #include "ecmascript/ecma_string-inl.h" 23 24 namespace panda::ecmascript::kungfu { 25 class TSHCROptPass : public PassVisitor { 26 public: TSHCROptPass(Circuit * circuit,RPOVisitor * visitor,Chunk * chunk,PassContext * ctx,bool enableLog,const std::string & name)27 TSHCROptPass(Circuit* circuit, 28 RPOVisitor *visitor, 29 Chunk* chunk, 30 PassContext *ctx, 31 bool enableLog, 32 const std::string &name) 33 : PassVisitor(circuit, chunk, visitor), 34 builder_(circuit, ctx->GetCompilerConfig()), 35 compilationEnv_(ctx->GetCompilationEnv()), 36 enableLog_(enableLog), 37 methodName_(name), 38 glue_(acc_.GetGlueFromArgList()) 39 { 40 if (ctx->GetCompilerConfig() != nullptr) { 41 typedOpProfiling_ = ctx->GetCompilerConfig()->IsTypedOpProfiling(); 42 } 43 } 44 45 ~TSHCROptPass() = default; 46 47 GateRef VisitGate(GateRef gate) override; 48 49 private: 50 void AddProfiling(GateRef gate); 51 IsTypedOpProfiling()52 bool IsTypedOpProfiling() const 53 { 54 return typedOpProfiling_; 55 } 56 IsLogEnabled()57 bool IsLogEnabled() const 58 { 59 return enableLog_; 60 } 61 GetMethodName()62 const std::string& GetMethodName() const 63 { 64 return methodName_; 65 } 66 GetStringFromConstantPool(uint32_t methodOffset,uint32_t cpIdx)67 JSTaggedValue GetStringFromConstantPool(uint32_t methodOffset, uint32_t cpIdx) const 68 { 69 return compilationEnv_->GetStringFromConstantPool(methodOffset, cpIdx); 70 } 71 72 GateRef VisitTypedBinaryOp(GateRef gate); 73 74 GateRef VisitStringBinOp(GateRef gate); 75 GateRef VisitStringEqual(GateRef gate); 76 bool IsSingleCharString(GateRef gate); 77 bool IsNotLoadStrOrStringLoadElement(GateRef gate); 78 GateRef ConvertStringEqualToConst(GateRef left, GateRef right); 79 GateRef ConvertConstSingleCharToInt32(GateRef gate); 80 GateRef ConvertToSingleCharComparison(GateRef left, GateRef right); 81 82 CircuitBuilder builder_; 83 const CompilationEnv *compilationEnv_ {nullptr}; 84 bool enableLog_ {false}; 85 std::string methodName_; 86 bool typedOpProfiling_ {false}; 87 GateRef glue_ {Circuit::NullGate()}; 88 }; 89 } // panda::ecmascript::kungfu 90 #endif // ECMASCRIPT_COMPILER_TS_HCR_OPT_PASS_H 91