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 #ifndef COMPILER_OPTIMIZER_CODEGEN_SPILL_FILL_ENCODER_H 16 #define COMPILER_OPTIMIZER_CODEGEN_SPILL_FILL_ENCODER_H 17 18 #include "optimizer/ir/inst.h" 19 #include "optimizer/ir/graph_visitor.h" 20 #include "utils/cframe_layout.h" 21 22 namespace ark::compiler { 23 24 class Graph; 25 class Codegen; 26 class Encoder; 27 28 // Helper class for SpillFill encoding 29 class SpillFillEncoder { 30 public: 31 PANDA_PUBLIC_API SpillFillEncoder(Codegen *codegen, Inst *inst); 32 ~SpillFillEncoder() = default; 33 NO_COPY_SEMANTIC(SpillFillEncoder); 34 NO_MOVE_SEMANTIC(SpillFillEncoder); 35 36 PANDA_PUBLIC_API void EncodeSpillFill(); 37 static bool CanCombineSpillFills(SpillFillData pred, SpillFillData succ, const Graph *graph); 38 static void SortSpillFillData(ArenaVector<SpillFillData> *spillFills); 39 IsCombiningEnabled(const Graph * graph)40 static bool IsCombiningEnabled(const Graph *graph) 41 { 42 return graph->GetArch() == Arch::AARCH64 && g_options.IsCompilerSpillFillPair(); 43 } 44 GetDstReg(Location dst,TypeInfo type)45 inline Reg GetDstReg(Location dst, TypeInfo type) 46 { 47 if (graph_->GetArch() == Arch::AARCH32) { 48 // ARM32 ABI SOFT calling convention 49 if (type.IsFloat() && dst.IsRegister()) { 50 type = type.GetSize() < DOUBLE_WORD_SIZE ? INT32_TYPE : INT64_TYPE; 51 } else if (type.IsScalar() && dst.IsFpRegister()) { 52 type = type.GetSize() < DOUBLE_WORD_SIZE ? FLOAT32_TYPE : FLOAT64_TYPE; 53 } 54 } 55 return Reg(dst.GetValue(), type); 56 } 57 58 private: 59 size_t EncodeImmToX(const SpillFillData &sf); 60 size_t EncodeRegisterToX(const SpillFillData &sf, const SpillFillData *next, int consecutiveOpsHint = 0); 61 size_t EncodeStackToX(const SpillFillData &sf, const SpillFillData *next, int consecutiveOpsHint = 0); 62 static bool AreConsecutiveOps(const SpillFillData &pred, const SpillFillData &succ); 63 void EncodeImmWithCorrectType(DataType::Type sfType, MemRef dstMem, ConstantInst *constInst); 64 65 SpillFillInst *inst_; 66 Graph *graph_; 67 Codegen *codegen_; 68 Encoder *encoder_; 69 CFrameLayout fl_; 70 Reg spReg_; 71 }; 72 } // namespace ark::compiler 73 #endif // COMPILER_OPTIMIZER_CODEGEN_SPILL_FILL_ENCODER_H 74