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_STRLDR_H 17 #define MAPLEBE_INCLUDE_CG_AARCH64_AARCH64_STRLDR_H 18 19 #include "strldr.h" 20 #include "aarch64_reaching.h" 21 #include "aarch64_operand.h" 22 23 namespace maplebe { 24 using namespace maple; 25 enum MemPropMode : uint8 { kUndef, kPropBase, kPropOffset, kPropSignedExtend, kPropUnsignedExtend, kPropShift }; 26 27 class AArch64StoreLoadOpt : public StoreLoadOpt { 28 public: AArch64StoreLoadOpt(CGFunc & func,MemPool & memPool)29 AArch64StoreLoadOpt(CGFunc &func, MemPool &memPool) 30 : StoreLoadOpt(func, memPool), localAlloc(&memPool), str2MovMap(localAlloc.Adapter()) 31 { 32 } 33 ~AArch64StoreLoadOpt() override = default; 34 void Run() final; 35 void DoStoreLoadOpt(); 36 void DoLoadZeroToMoveTransfer(const Insn &strInsn, short strSrcIdx, const InsnSet &memUseInsnSet) const; 37 void DoLoadToMoveTransfer(Insn &strInsn, short strSrcIdx, short memSeq, const InsnSet &memUseInsnSet); 38 bool CheckStoreOpCode(MOperator opCode) const; 39 static bool CheckNewAmount(const Insn &insn, uint32 newAmount); 40 41 private: 42 void StrLdrIndexModeOpt(Insn &currInsn); 43 bool CheckReplaceReg(Insn &defInsn, Insn &currInsn, InsnSet &replaceRegDefSet, regno_t replaceRegNo); 44 bool CheckDefInsn(Insn &defInsn, Insn &currInsn); 45 bool CheckNewMemOffset(const Insn &insn, MemOperand *newMemOpnd, uint32 opndIdx); 46 MemOperand *HandleArithImmDef(RegOperand &replace, Operand *oldOffset, int64 defVal); 47 MemOperand *SelectReplaceMem(Insn &defInsn, Insn &curInsn, RegOperand &base, Operand *offset); 48 MemOperand *SelectReplaceExt(const Insn &defInsn, RegOperand &base, bool isSigned); 49 bool CanDoMemProp(const Insn *insn); 50 bool CanDoIndexOpt(const MemOperand &MemOpnd); 51 void MemPropInit(); 52 void SelectPropMode(const MemOperand &currMemOpnd); 53 int64 GetOffsetForNewIndex(Insn &defInsn, Insn &insn, regno_t baseRegNO, uint32 memOpndSize); 54 MemOperand *SelectIndexOptMode(Insn &insn, const MemOperand &curMemOpnd); 55 bool ReplaceMemOpnd(Insn &insn, regno_t regNo, RegOperand &base, Operand *offset); 56 void MemProp(Insn &insn); 57 void ProcessStrPair(Insn &insn); 58 void ProcessStr(Insn &insn); 59 void GenerateMoveLiveInsn(RegOperand &resRegOpnd, RegOperand &srcRegOpnd, Insn &ldrInsn, Insn &strInsn, 60 short memSeq); 61 void GenerateMoveDeadInsn(RegOperand &resRegOpnd, RegOperand &srcRegOpnd, Insn &ldrInsn, Insn &strInsn, 62 short memSeq); 63 bool HasMemBarrier(const Insn &ldrInsn, const Insn &strInsn) const; 64 bool IsAdjacentBB(Insn &defInsn, Insn &curInsn) const; 65 MapleAllocator localAlloc; 66 /* the max number of mov insn to optimize. */ 67 static constexpr uint8 kMaxMovNum = 2; 68 MapleMap<Insn *, Insn *[kMaxMovNum]> str2MovMap; 69 MemPropMode propMode = kUndef; 70 uint32 amount = 0; 71 bool removeDefInsn = false; 72 }; 73 } /* namespace maplebe */ 74 75 #endif /* MAPLEBE_INCLUDE_CG_AARCH64_AARCH64_STRLDR_H */ 76