1b1994897Sopenharmony_ci/**
2b1994897Sopenharmony_ci * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3b1994897Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4b1994897Sopenharmony_ci * you may not use this file except in compliance with the License.
5b1994897Sopenharmony_ci * You may obtain a copy of the License at
6b1994897Sopenharmony_ci *
7b1994897Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0
8b1994897Sopenharmony_ci *
9b1994897Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10b1994897Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11b1994897Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12b1994897Sopenharmony_ci * See the License for the specific language governing permissions and
13b1994897Sopenharmony_ci * limitations under the License.
14b1994897Sopenharmony_ci */
15b1994897Sopenharmony_ci
16b1994897Sopenharmony_ci#ifndef COMPILER_OPTIMIZER_OPTIMIZATIONS_LOWERING_H
17b1994897Sopenharmony_ci#define COMPILER_OPTIMIZER_OPTIMIZATIONS_LOWERING_H
18b1994897Sopenharmony_ci
19b1994897Sopenharmony_ci#include "compiler_logger.h"
20b1994897Sopenharmony_ci#include "compiler_options.h"
21b1994897Sopenharmony_ci#include "optimizer/ir/graph.h"
22b1994897Sopenharmony_ci#include "optimizer/ir/graph_visitor.h"
23b1994897Sopenharmony_ci
24b1994897Sopenharmony_cinamespace panda::compiler {
25b1994897Sopenharmony_ci// NOLINTNEXTLINE(fuchsia-multiple-inheritance)
26b1994897Sopenharmony_ciclass Lowering : public Optimization, public GraphVisitor {
27b1994897Sopenharmony_ci    using Optimization::Optimization;
28b1994897Sopenharmony_ci
29b1994897Sopenharmony_cipublic:
30b1994897Sopenharmony_ci    explicit Lowering(Graph *graph) : Optimization(graph) {}
31b1994897Sopenharmony_ci
32b1994897Sopenharmony_ci    bool RunImpl() override;
33b1994897Sopenharmony_ci
34b1994897Sopenharmony_ci    bool IsEnable() const override
35b1994897Sopenharmony_ci    {
36b1994897Sopenharmony_ci        return options.IsCompilerLowering();
37b1994897Sopenharmony_ci    }
38b1994897Sopenharmony_ci
39b1994897Sopenharmony_ci    const char *GetPassName() const override
40b1994897Sopenharmony_ci    {
41b1994897Sopenharmony_ci        return "Lowering";
42b1994897Sopenharmony_ci    }
43b1994897Sopenharmony_ci
44b1994897Sopenharmony_ci    void InvalidateAnalyses() override;
45b1994897Sopenharmony_ci    static constexpr uint8_t HALF_SIZE = 32;
46b1994897Sopenharmony_ci    static constexpr uint8_t WORD_SIZE = 64;
47b1994897Sopenharmony_ci
48b1994897Sopenharmony_ciprivate:
49b1994897Sopenharmony_ci    const ArenaVector<BasicBlock *> &GetBlocksToVisit() const override
50b1994897Sopenharmony_ci    {
51b1994897Sopenharmony_ci        return GetGraph()->GetBlocksRPO();
52b1994897Sopenharmony_ci    }
53b1994897Sopenharmony_ci    static void VisitIfImm([[maybe_unused]] GraphVisitor *v, Inst *inst);
54b1994897Sopenharmony_ci
55b1994897Sopenharmony_ci#include "optimizer/ir/visitor.inc"
56b1994897Sopenharmony_ci
57b1994897Sopenharmony_ci    static bool ConstantFitsCompareImm(Inst *cst, uint32_t size, ConditionCode cc);
58b1994897Sopenharmony_ci    // We'd like to swap only to make second operand immediate
59b1994897Sopenharmony_ci    static bool BetterToSwapCompareInputs(Inst *cmp);
60b1994897Sopenharmony_ci    // Optimize order of input arguments for decreasing using accumulator (Bytecodeoptimizer only).
61b1994897Sopenharmony_ci    static void OptimizeIfInput(compiler::Inst *if_inst);
62b1994897Sopenharmony_ci    static void LowerIf(IfImmInst *inst);
63b1994897Sopenharmony_ci    static void InPlaceLowerIfImm(IfImmInst *inst, Inst *input, Inst *cst, ConditionCode cc);
64b1994897Sopenharmony_ci};
65b1994897Sopenharmony_ci}  // namespace panda::compiler
66b1994897Sopenharmony_ci
67b1994897Sopenharmony_ci#endif  // COMPILER_OPTIMIZER_OPTIMIZATIONS_LOWERING_H
68