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 #ifndef MAPLEBE_INCLUDE_CG_CFI_GENERATOR_H 16 #define MAPLEBE_INCLUDE_CG_CFI_GENERATOR_H 17 #include "cg_phase.h" 18 #include "cfi.h" 19 #include "cgfunc.h" 20 #include "insn.h" 21 #include "aarch64_insn.h" 22 #include "aarch64_operand.h" 23 24 namespace maplebe { 25 class GenCfi { 26 public: GenCfi(CGFunc & func)27 explicit GenCfi(CGFunc &func) : cg(*func.GetCG()), cgFunc(func) {} 28 virtual ~GenCfi() = default; 29 30 void Run(); 31 32 protected: 33 Insn *InsertCFIDefCfaOffset(BB &bb, Insn &insn, int32 &cfiOffset); /* cfiOffset in-out */ 34 35 Insn *FindStackDefInsn(BB &bb) const; 36 Insn *FinsStackRevertInsn(BB &bb) const; 37 38 /* CFI related routines */ GetOffsetFromCFA()39 int64 GetOffsetFromCFA() const 40 { 41 return offsetFromCfa; 42 } 43 44 /* add increment (can be negative) and return the new value */ AddtoOffsetFromCFA(int64 delta)45 int64 AddtoOffsetFromCFA(int64 delta) 46 { 47 offsetFromCfa += delta; 48 return offsetFromCfa; 49 } 50 51 CG &cg; 52 CGFunc &cgFunc; 53 /* SP offset from Call Frame Address */ 54 int64 offsetFromCfa = 0; 55 bool useFP = true; 56 57 static constexpr const int32 kOffset8MemPos = 8; 58 59 private: 60 void GenerateStartDirective(BB &bb); 61 void GenerateEndDirective(BB &bb); 62 void GenerateRegisterStateDirective(BB &bb); GenerateRegisterSaveDirective(BB & bb,Insn & stackDefInsn)63 virtual void GenerateRegisterSaveDirective(BB &bb, Insn &stackDefInsn) {} GenerateRegisterRestoreDirective(BB & bb,Insn & stackRevertInsn)64 virtual void GenerateRegisterRestoreDirective(BB &bb, Insn &stackRevertInsn) {} 65 }; 66 } /* namespace maplebe */ 67 #endif /* MAPLEBE_INCLUDE_CG_CFI_GENERATOR_H */ 68