• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/ecma_string-inl.h"
22 
23 namespace panda::ecmascript::kungfu {
24 class TSHCROptPass : public PassVisitor {
25 public:
TSHCROptPass(Circuit * circuit,RPOVisitor * visitor,Chunk * chunk,PassContext * ctx,bool enableLog,const std::string & name)26     TSHCROptPass(Circuit* circuit, RPOVisitor *visitor, Chunk* chunk,
27                  PassContext *ctx, bool enableLog, const std::string &name)
28         : PassVisitor(circuit, chunk, visitor),
29           builder_(circuit, ctx->GetCompilerConfig()),
30           tsManager_(ctx->GetTSManager()),
31           thread_(ctx->GetEcmaVM()->GetJSThread()),
32           enableLog_(enableLog),
33           methodName_(name) {}
34 
35     ~TSHCROptPass() = default;
36 
37     GateRef VisitGate(GateRef gate) override;
38 
39 private:
IsLogEnabled()40     bool IsLogEnabled() const
41     {
42         return enableLog_;
43     }
44 
GetMethodName()45     const std::string& GetMethodName() const
46     {
47         return methodName_;
48     }
49 
GetStringFromCP(uint32_t methodOffset,uint32_t cpIdx)50     JSTaggedValue GetStringFromCP(uint32_t methodOffset, uint32_t cpIdx) const
51     {
52         return tsManager_->GetStringFromConstantPool(methodOffset, cpIdx);
53     }
54 
55     GateRef VisitTypedBinaryOp(GateRef gate);
56 
57     GateRef VisitStringBinOp(GateRef gate);
58     GateRef VisitStringEqual(GateRef gate);
59     bool IsSingleCharString(GateRef gate);
60     bool IsNotLoadStrOrStringLoadElement(GateRef gate);
61     GateRef ConvertStringEqualToConst(GateRef left, GateRef right);
62     GateRef ConvertConstSingleCharToInt32(GateRef gate);
63     GateRef ConvertToSingleCharComparison(GateRef left, GateRef right);
64 
65     CircuitBuilder builder_;
66     TSManager *tsManager_ {nullptr};
67     const JSThread *thread_ {nullptr};
68     bool enableLog_ {false};
69     std::string methodName_;
70 };
71 }  // panda::ecmascript::kungfu
72 #endif  // ECMASCRIPT_COMPILER_TS_HCR_OPT_PASS_H
73