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,LoopAnalysis & loop)29 AArch64StoreLoadOpt(CGFunc &func, MemPool &memPool, LoopAnalysis &loop) 30 : StoreLoadOpt(func, memPool), localAlloc(&memPool), loopInfo(loop), 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 bool CheckStoreOpCode(MOperator opCode) const; 38 static bool CheckNewAmount(const Insn &insn, uint32 newAmount); 39 40 private: 41 void StrLdrIndexModeOpt(Insn &currInsn); 42 bool CheckReplaceReg(Insn &defInsn, Insn &currInsn, InsnSet &replaceRegDefSet, regno_t replaceRegNo); 43 bool CheckDefInsn(Insn &defInsn, Insn &currInsn); 44 bool CheckNewMemOffset(const Insn &insn, MemOperand *newMemOpnd, uint32 opndIdx); 45 MemOperand *HandleArithImmDef(RegOperand &replace, Operand *oldOffset, int64 defVal); 46 MemOperand *SelectReplaceExt(const Insn &defInsn, RegOperand &base, bool isSigned); 47 bool CanDoMemProp(const Insn *insn); 48 bool CanDoIndexOpt(const MemOperand &MemOpnd); 49 void MemPropInit(); 50 void SelectPropMode(const MemOperand &currMemOpnd); 51 int64 GetOffsetForNewIndex(Insn &defInsn, Insn &insn, regno_t baseRegNO, uint32 memOpndSize); 52 MemOperand *SelectIndexOptMode(Insn &insn, const MemOperand &curMemOpnd); 53 void MemProp(Insn &insn); 54 void ProcessStrPair(Insn &insn); 55 void ProcessStr(Insn &insn); 56 void GenerateMoveLiveInsn(RegOperand &resRegOpnd, RegOperand &srcRegOpnd, Insn &ldrInsn, Insn &strInsn, 57 short memSeq); 58 void GenerateMoveDeadInsn(RegOperand &resRegOpnd, RegOperand &srcRegOpnd, Insn &ldrInsn, Insn &strInsn, 59 short memSeq); 60 bool HasMemBarrier(const Insn &ldrInsn, const Insn &strInsn) const; 61 bool IsAdjacentBB(Insn &defInsn, Insn &curInsn) const; 62 MapleAllocator localAlloc; 63 LoopAnalysis &loopInfo; 64 /* the max number of mov insn to optimize. */ 65 static constexpr uint8 kMaxMovNum = 2; 66 MapleMap<Insn *, Insn *[kMaxMovNum]> str2MovMap; 67 MemPropMode propMode = kUndef; 68 uint32 amount = 0; 69 bool removeDefInsn = false; 70 }; 71 } /* namespace maplebe */ 72 73 #endif /* MAPLEBE_INCLUDE_CG_AARCH64_AARCH64_STRLDR_H */ 74