1 /** 2 * Copyright (c) 2021-2022 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_LOWERING_H 17 #define COMPILER_OPTIMIZER_OPTIMIZATIONS_LOWERING_H 18 19 #include "compiler_logger.h" 20 #include "compiler_options.h" 21 #include "optimizer/ir/graph.h" 22 #include "optimizer/ir/graph_visitor.h" 23 24 namespace panda::compiler { 25 // NOLINTNEXTLINE(fuchsia-multiple-inheritance) 26 class Lowering : public Optimization, public GraphVisitor { 27 using Optimization::Optimization; 28 29 public: Lowering(Graph * graph)30 explicit Lowering(Graph *graph) : Optimization(graph) {} 31 32 bool RunImpl() override; 33 IsEnable()34 bool IsEnable() const override 35 { 36 return options.IsCompilerLowering(); 37 } 38 GetPassName()39 const char *GetPassName() const override 40 { 41 return "Lowering"; 42 } 43 44 void InvalidateAnalyses() override; 45 static constexpr uint8_t HALF_SIZE = 32; 46 static constexpr uint8_t WORD_SIZE = 64; 47 48 private: GetBlocksToVisit()49 const ArenaVector<BasicBlock *> &GetBlocksToVisit() const override 50 { 51 return GetGraph()->GetBlocksRPO(); 52 } 53 static void VisitIfImm([[maybe_unused]] GraphVisitor *v, Inst *inst); 54 55 #include "optimizer/ir/visitor.inc" 56 57 static bool ConstantFitsCompareImm(Inst *cst, uint32_t size, ConditionCode cc); 58 // We'd like to swap only to make second operand immediate 59 static bool BetterToSwapCompareInputs(Inst *cmp); 60 // Optimize order of input arguments for decreasing using accumulator (Bytecodeoptimizer only). 61 static void OptimizeIfInput(compiler::Inst *if_inst); 62 static void LowerIf(IfImmInst *inst); 63 static void InPlaceLowerIfImm(IfImmInst *inst, Inst *input, Inst *cst, ConditionCode cc); 64 }; 65 } // namespace panda::compiler 66 67 #endif // COMPILER_OPTIMIZER_OPTIMIZATIONS_LOWERING_H 68