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 16 #ifndef MAPLEBE_INCLUDE_CG_AARCH64_AARCH64_OFFSET_ADJUST_H 17 #define MAPLEBE_INCLUDE_CG_AARCH64_AARCH64_OFFSET_ADJUST_H 18 19 #include "offset_adjust.h" 20 #include "aarch64_cgfunc.h" 21 22 namespace maplebe { 23 using namespace maple; 24 25 class AArch64FPLROffsetAdjustment : public FrameFinalize { 26 public: AArch64FPLROffsetAdjustment(CGFunc & func)27 explicit AArch64FPLROffsetAdjustment(CGFunc &func) 28 : FrameFinalize(func), 29 aarchCGFunc(static_cast<AArch64CGFunc *>(&func)), 30 isLmbc(aarchCGFunc->GetMirModule().GetFlavor() == MIRFlavor::kFlavorLmbc), 31 stackBaseReg((isLmbc || aarchCGFunc->UseFP()) ? R29 : RSP) 32 { 33 } 34 ~AArch64FPLROffsetAdjustment()35 ~AArch64FPLROffsetAdjustment() override 36 { 37 aarchCGFunc = nullptr; 38 } 39 40 void Run() override; 41 42 private: 43 void AdjustmentOffsetForOpnd(Insn &insn) const; 44 void AdjustmentOffsetForImmOpnd(Insn &insn, uint32 index) const; 45 /* frame pointer(x29) is available as a general-purpose register if useFP is set as false */ 46 void AdjustmentStackPointer(Insn &insn) const; 47 void AdjustMemBaseReg(Insn &insn, uint32 i, bool &replaceFP) const; 48 void AdjustMemOfstVary(Insn &insn, uint32 i) const; 49 AArch64CGFunc *aarchCGFunc; 50 bool isLmbc; 51 AArch64reg stackBaseReg; 52 }; 53 } /* namespace maplebe */ 54 55 #endif /* MAPLEBE_INCLUDE_CG_AARCH64_AARCH64_OFFSET_ADJUST_H */ 56