• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2021-2024 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 COMPILER_OPTIMIZER_OPTIMIZATIONS_SIMPLIFY_STRING_BUILDER_H
17 #define COMPILER_OPTIMIZER_OPTIMIZATIONS_SIMPLIFY_STRING_BUILDER_H
18 
19 #include "optimizer/ir/basicblock.h"
20 #include "optimizer/ir/graph.h"
21 #include "optimizer/pass.h"
22 
23 namespace panda::compiler {
24 class SimplifyStringBuilder : public Optimization {
25 public:
26     explicit SimplifyStringBuilder(Graph *graph);
27 
28     NO_MOVE_SEMANTIC(SimplifyStringBuilder);
29     NO_COPY_SEMANTIC(SimplifyStringBuilder);
30     ~SimplifyStringBuilder() override = default;
31 
32     bool RunImpl() override;
33 
IsEnable()34     bool IsEnable() const override
35     {
36         return g_options.IsCompilerSimplifyStringBuilder();
37     }
38 
GetPassName()39     const char *GetPassName() const override
40     {
41         return "SimplifyStringBuilder";
42     }
43     void InvalidateAnalyses() override;
44 
45 private:
46     bool IsMethodStringBuilderConstructorWithStringArg(Inst *inst);
47     bool IsMethodStringBuilderToString(Inst *inst);
48     InstIter SkipToStringBuilderConstructor(InstIter begin, InstIter end);
49     void VisitBlock(BasicBlock *block);
50 
51 private:
52     constexpr static size_t CONSTRUCTOR_WITH_STRING_ARG_TOTAL_ARGS_NUM = 3U;
53     bool isApplied_ {false};
54 };
55 
56 }  // namespace panda::compiler
57 
58 #endif  // COMPILER_OPTIMIZER_OPTIMIZATIONS_SIMPLIFY_STRING_BUILDER_H
59