| Jia Liu | b22310f | 2012-02-18 12:03:15 +0000 | [diff] [blame] | 1 | //===-- ARMBaseInstrInfo.h - ARM Base Instruction Information ---*- C++ -*-===// |
| David Goodwin | af7451b | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file contains the Base ARM implementation of the TargetInstrInfo class. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| Benjamin Kramer | a7c40ef | 2014-08-13 16:26:38 +0000 | [diff] [blame] | 14 | #ifndef LLVM_LIB_TARGET_ARM_ARMBASEINSTRINFO_H |
| 15 | #define LLVM_LIB_TARGET_ARM_ARMBASEINSTRINFO_H |
| David Goodwin | af7451b | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 16 | |
| Craig Topper | a925326 | 2014-03-22 23:51:00 +0000 | [diff] [blame] | 17 | #include "MCTargetDesc/ARMBaseInfo.h" |
| Evan Cheng | 62c7b5b | 2010-12-05 22:04:16 +0000 | [diff] [blame] | 18 | #include "llvm/ADT/DenseMap.h" |
| 19 | #include "llvm/ADT/SmallSet.h" |
| Eugene Zelenko | 342257e | 2017-01-31 00:56:17 +0000 | [diff] [blame] | 20 | #include "llvm/CodeGen/MachineBasicBlock.h" |
| 21 | #include "llvm/CodeGen/MachineInstr.h" |
| Chandler Carruth | 802d755 | 2012-12-04 07:12:27 +0000 | [diff] [blame] | 22 | #include "llvm/CodeGen/MachineInstrBuilder.h" |
| Eugene Zelenko | 342257e | 2017-01-31 00:56:17 +0000 | [diff] [blame] | 23 | #include "llvm/CodeGen/MachineOperand.h" |
| David Blaikie | 3f833ed | 2017-11-08 01:01:31 +0000 | [diff] [blame] | 24 | #include "llvm/CodeGen/TargetInstrInfo.h" |
| Eugene Zelenko | 342257e | 2017-01-31 00:56:17 +0000 | [diff] [blame] | 25 | #include <array> |
| 26 | #include <cstdint> |
| David Goodwin | af7451b | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 27 | |
| Evan Cheng | 703a0fb | 2011-07-01 17:57:27 +0000 | [diff] [blame] | 28 | #define GET_INSTRINFO_HEADER |
| 29 | #include "ARMGenInstrInfo.inc" |
| 30 | |
| David Goodwin | af7451b | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 31 | namespace llvm { |
| Eugene Zelenko | 342257e | 2017-01-31 00:56:17 +0000 | [diff] [blame] | 32 | |
| 33 | class ARMBaseRegisterInfo; |
| 34 | class ARMSubtarget; |
| David Goodwin | af7451b | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 35 | |
| Evan Cheng | 703a0fb | 2011-07-01 17:57:27 +0000 | [diff] [blame] | 36 | class ARMBaseInstrInfo : public ARMGenInstrInfo { |
| Chris Lattner | cbe9856 | 2010-07-20 21:17:29 +0000 | [diff] [blame] | 37 | const ARMSubtarget &Subtarget; |
| Evan Cheng | 62c7b5b | 2010-12-05 22:04:16 +0000 | [diff] [blame] | 38 | |
| David Goodwin | af7451b | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 39 | protected: |
| 40 | // Can be only subclassed. |
| Anton Korobeynikov | 14635da | 2009-11-02 00:10:38 +0000 | [diff] [blame] | 41 | explicit ARMBaseInstrInfo(const ARMSubtarget &STI); |
| Evan Cheng | 62c7b5b | 2010-12-05 22:04:16 +0000 | [diff] [blame] | 42 | |
| Akira Hatanaka | e5b6e0d | 2014-07-25 19:31:34 +0000 | [diff] [blame] | 43 | void expandLoadStackGuardBase(MachineBasicBlock::iterator MI, |
| Rafael Espindola | 82f4631 | 2016-06-28 15:18:26 +0000 | [diff] [blame] | 44 | unsigned LoadImmOpc, unsigned LoadOpc) const; |
| Akira Hatanaka | e5b6e0d | 2014-07-25 19:31:34 +0000 | [diff] [blame] | 45 | |
| Quentin Colombet | d358e84 | 2014-08-22 18:05:22 +0000 | [diff] [blame] | 46 | /// Build the equivalent inputs of a REG_SEQUENCE for the given \p MI |
| 47 | /// and \p DefIdx. |
| 48 | /// \p [out] InputRegs of the equivalent REG_SEQUENCE. Each element of |
| 49 | /// the list is modeled as <Reg:SubReg, SubIdx>. |
| Francis Visoiu Mistrih | 93ef145 | 2017-11-30 12:12:19 +0000 | [diff] [blame] | 50 | /// E.g., REG_SEQUENCE %1:sub1, sub0, %2, sub1 would produce |
| Quentin Colombet | d358e84 | 2014-08-22 18:05:22 +0000 | [diff] [blame] | 51 | /// two elements: |
| Francis Visoiu Mistrih | 93ef145 | 2017-11-30 12:12:19 +0000 | [diff] [blame] | 52 | /// - %1:sub1, sub0 |
| 53 | /// - %2<:0>, sub1 |
| Quentin Colombet | d358e84 | 2014-08-22 18:05:22 +0000 | [diff] [blame] | 54 | /// |
| 55 | /// \returns true if it is possible to build such an input sequence |
| 56 | /// with the pair \p MI, \p DefIdx. False otherwise. |
| 57 | /// |
| 58 | /// \pre MI.isRegSequenceLike(). |
| 59 | bool getRegSequenceLikeInputs( |
| 60 | const MachineInstr &MI, unsigned DefIdx, |
| 61 | SmallVectorImpl<RegSubRegPairAndIdx> &InputRegs) const override; |
| 62 | |
| 63 | /// Build the equivalent inputs of a EXTRACT_SUBREG for the given \p MI |
| 64 | /// and \p DefIdx. |
| 65 | /// \p [out] InputReg of the equivalent EXTRACT_SUBREG. |
| Francis Visoiu Mistrih | 93ef145 | 2017-11-30 12:12:19 +0000 | [diff] [blame] | 66 | /// E.g., EXTRACT_SUBREG %1:sub1, sub0, sub1 would produce: |
| 67 | /// - %1:sub1, sub0 |
| Quentin Colombet | d358e84 | 2014-08-22 18:05:22 +0000 | [diff] [blame] | 68 | /// |
| 69 | /// \returns true if it is possible to build such an input sequence |
| 70 | /// with the pair \p MI, \p DefIdx. False otherwise. |
| 71 | /// |
| 72 | /// \pre MI.isExtractSubregLike(). |
| 73 | bool getExtractSubregLikeInputs(const MachineInstr &MI, unsigned DefIdx, |
| 74 | RegSubRegPairAndIdx &InputReg) const override; |
| 75 | |
| 76 | /// Build the equivalent inputs of a INSERT_SUBREG for the given \p MI |
| 77 | /// and \p DefIdx. |
| 78 | /// \p [out] BaseReg and \p [out] InsertedReg contain |
| 79 | /// the equivalent inputs of INSERT_SUBREG. |
| Francis Visoiu Mistrih | 93ef145 | 2017-11-30 12:12:19 +0000 | [diff] [blame] | 80 | /// E.g., INSERT_SUBREG %0:sub0, %1:sub1, sub3 would produce: |
| 81 | /// - BaseReg: %0:sub0 |
| 82 | /// - InsertedReg: %1:sub1, sub3 |
| Quentin Colombet | d358e84 | 2014-08-22 18:05:22 +0000 | [diff] [blame] | 83 | /// |
| 84 | /// \returns true if it is possible to build such an input sequence |
| 85 | /// with the pair \p MI, \p DefIdx. False otherwise. |
| 86 | /// |
| 87 | /// \pre MI.isInsertSubregLike(). |
| 88 | bool |
| 89 | getInsertSubregLikeInputs(const MachineInstr &MI, unsigned DefIdx, |
| 90 | RegSubRegPair &BaseReg, |
| 91 | RegSubRegPairAndIdx &InsertedReg) const override; |
| 92 | |
| Andrew Kaylor | 16c4da0 | 2015-09-28 20:33:22 +0000 | [diff] [blame] | 93 | /// Commutes the operands in the given instruction. |
| 94 | /// The commutable operands are specified by their indices OpIdx1 and OpIdx2. |
| 95 | /// |
| 96 | /// Do not call this method for a non-commutable instruction or for |
| 97 | /// non-commutable pair of operand indices OpIdx1 and OpIdx2. |
| 98 | /// Even though the instruction is commutable, the method may still |
| 99 | /// fail to commute the operands, null pointer is returned in such cases. |
| Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 100 | MachineInstr *commuteInstructionImpl(MachineInstr &MI, bool NewMI, |
| Andrew Kaylor | 16c4da0 | 2015-09-28 20:33:22 +0000 | [diff] [blame] | 101 | unsigned OpIdx1, |
| 102 | unsigned OpIdx2) const override; |
| 103 | |
| David Goodwin | af7451b | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 104 | public: |
| Jim Grosbach | 617f84dd | 2012-02-28 23:53:30 +0000 | [diff] [blame] | 105 | // Return whether the target has an explicit NOP encoding. |
| 106 | bool hasNOP() const; |
| 107 | |
| David Goodwin | af7451b | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 108 | // Return the non-pre/post incrementing version of 'Opc'. Return 0 |
| 109 | // if there is not such an opcode. |
| Eugene Zelenko | 342257e | 2017-01-31 00:56:17 +0000 | [diff] [blame] | 110 | virtual unsigned getUnindexedOpcode(unsigned Opc) const = 0; |
| David Goodwin | af7451b | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 111 | |
| Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 112 | MachineInstr *convertToThreeAddress(MachineFunction::iterator &MFI, |
| Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 113 | MachineInstr &MI, |
| Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 114 | LiveVariables *LV) const override; |
| David Goodwin | af7451b | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 115 | |
| Bill Wendling | f95178e | 2013-06-07 05:54:19 +0000 | [diff] [blame] | 116 | virtual const ARMBaseRegisterInfo &getRegisterInfo() const = 0; |
| Anton Korobeynikov | 14635da | 2009-11-02 00:10:38 +0000 | [diff] [blame] | 117 | const ARMSubtarget &getSubtarget() const { return Subtarget; } |
| David Goodwin | af7451b | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 118 | |
| Evan Cheng | 62c7b5b | 2010-12-05 22:04:16 +0000 | [diff] [blame] | 119 | ScheduleHazardRecognizer * |
| Eric Christopher | f047bfd | 2014-06-13 22:38:52 +0000 | [diff] [blame] | 120 | CreateTargetHazardRecognizer(const TargetSubtargetInfo *STI, |
| Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 121 | const ScheduleDAG *DAG) const override; |
| Andrew Trick | 10ffc2b | 2010-12-24 05:03:26 +0000 | [diff] [blame] | 122 | |
| 123 | ScheduleHazardRecognizer * |
| 124 | CreateTargetPostRAHazardRecognizer(const InstrItineraryData *II, |
| Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 125 | const ScheduleDAG *DAG) const override; |
| Evan Cheng | 62c7b5b | 2010-12-05 22:04:16 +0000 | [diff] [blame] | 126 | |
| David Goodwin | af7451b | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 127 | // Branch analysis. |
| Jacques Pienaar | 71c30a1 | 2016-07-15 14:41:04 +0000 | [diff] [blame] | 128 | bool analyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB, |
| Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 129 | MachineBasicBlock *&FBB, |
| 130 | SmallVectorImpl<MachineOperand> &Cond, |
| 131 | bool AllowModify = false) const override; |
| Matt Arsenault | 1b9fc8e | 2016-09-14 20:43:16 +0000 | [diff] [blame] | 132 | unsigned removeBranch(MachineBasicBlock &MBB, |
| Matt Arsenault | a2b036e | 2016-09-14 17:23:48 +0000 | [diff] [blame] | 133 | int *BytesRemoved = nullptr) const override; |
| Matt Arsenault | e8e0f5c | 2016-09-14 17:24:15 +0000 | [diff] [blame] | 134 | unsigned insertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB, |
| Ahmed Bougacha | c88bf54 | 2015-06-11 19:30:37 +0000 | [diff] [blame] | 135 | MachineBasicBlock *FBB, ArrayRef<MachineOperand> Cond, |
| Matt Arsenault | a2b036e | 2016-09-14 17:23:48 +0000 | [diff] [blame] | 136 | const DebugLoc &DL, |
| 137 | int *BytesAdded = nullptr) const override; |
| David Goodwin | af7451b | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 138 | |
| Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 139 | bool |
| Matt Arsenault | 1b9fc8e | 2016-09-14 20:43:16 +0000 | [diff] [blame] | 140 | reverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const override; |
| David Goodwin | af7451b | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 141 | |
| 142 | // Predication support. |
| Duncan P. N. Exon Smith | 6307eb5 | 2016-02-23 02:46:52 +0000 | [diff] [blame] | 143 | bool isPredicated(const MachineInstr &MI) const override; |
| David Goodwin | af7451b | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 144 | |
| Duncan P. N. Exon Smith | 6307eb5 | 2016-02-23 02:46:52 +0000 | [diff] [blame] | 145 | ARMCC::CondCodes getPredicate(const MachineInstr &MI) const { |
| 146 | int PIdx = MI.findFirstPredOperandIdx(); |
| 147 | return PIdx != -1 ? (ARMCC::CondCodes)MI.getOperand(PIdx).getImm() |
| David Goodwin | af7451b | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 148 | : ARMCC::AL; |
| 149 | } |
| 150 | |
| Duncan P. N. Exon Smith | 6307eb5 | 2016-02-23 02:46:52 +0000 | [diff] [blame] | 151 | bool PredicateInstruction(MachineInstr &MI, |
| 152 | ArrayRef<MachineOperand> Pred) const override; |
| David Goodwin | af7451b | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 153 | |
| Ahmed Bougacha | c88bf54 | 2015-06-11 19:30:37 +0000 | [diff] [blame] | 154 | bool SubsumesPredicate(ArrayRef<MachineOperand> Pred1, |
| 155 | ArrayRef<MachineOperand> Pred2) const override; |
| David Goodwin | af7451b | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 156 | |
| Duncan P. N. Exon Smith | 6307eb5 | 2016-02-23 02:46:52 +0000 | [diff] [blame] | 157 | bool DefinesPredicate(MachineInstr &MI, |
| Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 158 | std::vector<MachineOperand> &Pred) const override; |
| David Goodwin | af7451b | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 159 | |
| Krzysztof Parzyszek | cc31871 | 2017-03-03 18:30:54 +0000 | [diff] [blame] | 160 | bool isPredicable(const MachineInstr &MI) const override; |
| Evan Cheng | a33fc86 | 2009-11-21 06:21:52 +0000 | [diff] [blame] | 161 | |
| Javed Absar | 4ae7e812 | 2017-06-02 08:53:19 +0000 | [diff] [blame] | 162 | // CPSR defined in instruction |
| 163 | static bool isCPSRDefined(const MachineInstr &MI); |
| 164 | bool isAddrMode3OpImm(const MachineInstr &MI, unsigned Op) const; |
| 165 | bool isAddrMode3OpMinusReg(const MachineInstr &MI, unsigned Op) const; |
| 166 | |
| 167 | // Load, scaled register offset |
| 168 | bool isLdstScaledReg(const MachineInstr &MI, unsigned Op) const; |
| 169 | // Load, scaled register offset, not plus LSL2 |
| 170 | bool isLdstScaledRegNotPlusLsl2(const MachineInstr &MI, unsigned Op) const; |
| 171 | // Minus reg for ldstso addr mode |
| 172 | bool isLdstSoMinusReg(const MachineInstr &MI, unsigned Op) const; |
| 173 | // Scaled register offset in address mode 2 |
| 174 | bool isAm2ScaledReg(const MachineInstr &MI, unsigned Op) const; |
| 175 | // Load multiple, base reg in list |
| 176 | bool isLDMBaseRegInList(const MachineInstr &MI) const; |
| 177 | // get LDM variable defs size |
| 178 | unsigned getLDMVariableDefsSize(const MachineInstr &MI) const; |
| 179 | |
| David Goodwin | af7451b | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 180 | /// GetInstSize - Returns the size of the specified MachineInstr. |
| 181 | /// |
| Sjoerd Meijer | a3de126 | 2016-07-29 09:57:37 +0000 | [diff] [blame] | 182 | unsigned getInstSizeInBytes(const MachineInstr &MI) const override; |
| David Goodwin | af7451b | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 183 | |
| Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 184 | unsigned isLoadFromStackSlot(const MachineInstr &MI, |
| Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 185 | int &FrameIndex) const override; |
| Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 186 | unsigned isStoreToStackSlot(const MachineInstr &MI, |
| Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 187 | int &FrameIndex) const override; |
| Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 188 | unsigned isLoadFromStackSlotPostFE(const MachineInstr &MI, |
| Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 189 | int &FrameIndex) const override; |
| Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 190 | unsigned isStoreToStackSlotPostFE(const MachineInstr &MI, |
| Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 191 | int &FrameIndex) const override; |
| David Goodwin | af7451b | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 192 | |
| Tim Northover | 5d72c5d | 2014-10-01 19:21:03 +0000 | [diff] [blame] | 193 | void copyToCPSR(MachineBasicBlock &MBB, MachineBasicBlock::iterator I, |
| 194 | unsigned SrcReg, bool KillSrc, |
| 195 | const ARMSubtarget &Subtarget) const; |
| 196 | void copyFromCPSR(MachineBasicBlock &MBB, MachineBasicBlock::iterator I, |
| 197 | unsigned DestReg, bool KillSrc, |
| 198 | const ARMSubtarget &Subtarget) const; |
| 199 | |
| Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 200 | void copyPhysReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator I, |
| Benjamin Kramer | bdc4956 | 2016-06-12 15:39:02 +0000 | [diff] [blame] | 201 | const DebugLoc &DL, unsigned DestReg, unsigned SrcReg, |
| Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 202 | bool KillSrc) const override; |
| Evan Cheng | c47e109 | 2009-07-27 03:14:20 +0000 | [diff] [blame] | 203 | |
| Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 204 | void storeRegToStackSlot(MachineBasicBlock &MBB, |
| 205 | MachineBasicBlock::iterator MBBI, |
| 206 | unsigned SrcReg, bool isKill, int FrameIndex, |
| 207 | const TargetRegisterClass *RC, |
| 208 | const TargetRegisterInfo *TRI) const override; |
| David Goodwin | af7451b | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 209 | |
| Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 210 | void loadRegFromStackSlot(MachineBasicBlock &MBB, |
| 211 | MachineBasicBlock::iterator MBBI, |
| 212 | unsigned DestReg, int FrameIndex, |
| 213 | const TargetRegisterClass *RC, |
| 214 | const TargetRegisterInfo *TRI) const override; |
| David Goodwin | af7451b | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 215 | |
| Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 216 | bool expandPostRAPseudo(MachineInstr &MI) const override; |
| Jakob Stoklund Olesen | da7c0f8 | 2011-10-11 00:59:06 +0000 | [diff] [blame] | 217 | |
| Joel Galenson | fe7fa40 | 2018-01-17 19:19:05 +0000 | [diff] [blame] | 218 | bool shouldSink(const MachineInstr &MI) const override; |
| 219 | |
| Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 220 | void reMaterialize(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, |
| 221 | unsigned DestReg, unsigned SubIdx, |
| Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 222 | const MachineInstr &Orig, |
| Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 223 | const TargetRegisterInfo &TRI) const override; |
| Evan Cheng | fe86442 | 2009-11-08 00:15:23 +0000 | [diff] [blame] | 224 | |
| Matthias Braun | 55bc9b3 | 2017-08-22 23:56:30 +0000 | [diff] [blame] | 225 | MachineInstr & |
| 226 | duplicate(MachineBasicBlock &MBB, MachineBasicBlock::iterator InsertBefore, |
| 227 | const MachineInstr &Orig) const override; |
| Jakob Stoklund Olesen | 29a64c9 | 2010-01-06 23:47:07 +0000 | [diff] [blame] | 228 | |
| Tim Northover | 798697d | 2013-04-21 11:57:07 +0000 | [diff] [blame] | 229 | const MachineInstrBuilder &AddDReg(MachineInstrBuilder &MIB, unsigned Reg, |
| 230 | unsigned SubIdx, unsigned State, |
| 231 | const TargetRegisterInfo *TRI) const; |
| 232 | |
| Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 233 | bool produceSameValue(const MachineInstr &MI0, const MachineInstr &MI1, |
| Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 234 | const MachineRegisterInfo *MRI) const override; |
| Evan Cheng | 2d51c7c | 2010-06-18 23:09:54 +0000 | [diff] [blame] | 235 | |
| Bill Wendling | f470747 | 2010-06-23 23:00:16 +0000 | [diff] [blame] | 236 | /// areLoadsFromSameBasePtr - This is used by the pre-regalloc scheduler to |
| 237 | /// determine if two loads are loading from the same base address. It should |
| 238 | /// only return true if the base pointers are the same and the only |
| 239 | /// differences between the two addresses is the offset. It also returns the |
| 240 | /// offsets by reference. |
| Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 241 | bool areLoadsFromSameBasePtr(SDNode *Load1, SDNode *Load2, int64_t &Offset1, |
| 242 | int64_t &Offset2) const override; |
| Bill Wendling | f470747 | 2010-06-23 23:00:16 +0000 | [diff] [blame] | 243 | |
| 244 | /// shouldScheduleLoadsNear - This is a used by the pre-regalloc scheduler to |
| Jim Grosbach | 7ef7ddd | 2011-06-13 22:54:22 +0000 | [diff] [blame] | 245 | /// determine (in conjunction with areLoadsFromSameBasePtr) if two loads |
| 246 | /// should be scheduled togther. On some targets if two loads are loading from |
| Bill Wendling | f470747 | 2010-06-23 23:00:16 +0000 | [diff] [blame] | 247 | /// addresses in the same cache line, it's better if they are scheduled |
| 248 | /// together. This function takes two integers that represent the load offsets |
| 249 | /// from the common base address. It returns true if it decides it's desirable |
| 250 | /// to schedule the two loads together. "NumLoads" is the number of loads that |
| 251 | /// have already been scheduled after Load1. |
| Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 252 | bool shouldScheduleLoadsNear(SDNode *Load1, SDNode *Load2, |
| 253 | int64_t Offset1, int64_t Offset2, |
| 254 | unsigned NumLoads) const override; |
| Bill Wendling | f470747 | 2010-06-23 23:00:16 +0000 | [diff] [blame] | 255 | |
| Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 256 | bool isSchedulingBoundary(const MachineInstr &MI, |
| Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 257 | const MachineBasicBlock *MBB, |
| 258 | const MachineFunction &MF) const override; |
| Evan Cheng | 02b184d | 2010-06-25 22:42:03 +0000 | [diff] [blame] | 259 | |
| Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 260 | bool isProfitableToIfCvt(MachineBasicBlock &MBB, |
| 261 | unsigned NumCycles, unsigned ExtraPredCycles, |
| Cong Hou | c536bd9 | 2015-09-10 23:10:42 +0000 | [diff] [blame] | 262 | BranchProbability Probability) const override; |
| Evan Cheng | 02b184d | 2010-06-25 22:42:03 +0000 | [diff] [blame] | 263 | |
| Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 264 | bool isProfitableToIfCvt(MachineBasicBlock &TMBB, unsigned NumT, |
| 265 | unsigned ExtraT, MachineBasicBlock &FMBB, |
| 266 | unsigned NumF, unsigned ExtraF, |
| Cong Hou | c536bd9 | 2015-09-10 23:10:42 +0000 | [diff] [blame] | 267 | BranchProbability Probability) const override; |
| Evan Cheng | 02b184d | 2010-06-25 22:42:03 +0000 | [diff] [blame] | 268 | |
| Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 269 | bool isProfitableToDupForIfCvt(MachineBasicBlock &MBB, unsigned NumCycles, |
| Cong Hou | c536bd9 | 2015-09-10 23:10:42 +0000 | [diff] [blame] | 270 | BranchProbability Probability) const override { |
| Cameron Zwarich | 8001850 | 2011-04-13 06:39:16 +0000 | [diff] [blame] | 271 | return NumCycles == 1; |
| Evan Cheng | 02b184d | 2010-06-25 22:42:03 +0000 | [diff] [blame] | 272 | } |
| Bill Wendling | 7de9d52 | 2010-08-06 01:32:48 +0000 | [diff] [blame] | 273 | |
| Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 274 | bool isProfitableToUnpredicate(MachineBasicBlock &TMBB, |
| 275 | MachineBasicBlock &FMBB) const override; |
| Bob Wilson | e8a549c | 2012-09-29 21:43:49 +0000 | [diff] [blame] | 276 | |
| Manman Ren | 6fa76dc | 2012-06-29 21:33:59 +0000 | [diff] [blame] | 277 | /// analyzeCompare - For a comparison instruction, return the source registers |
| 278 | /// in SrcReg and SrcReg2 if having two register operands, and the value it |
| 279 | /// compares against in CmpValue. Return true if the comparison instruction |
| 280 | /// can be analyzed. |
| Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 281 | bool analyzeCompare(const MachineInstr &MI, unsigned &SrcReg, |
| Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 282 | unsigned &SrcReg2, int &CmpMask, |
| 283 | int &CmpValue) const override; |
| Bill Wendling | 7de9d52 | 2010-08-06 01:32:48 +0000 | [diff] [blame] | 284 | |
| Manman Ren | 6fa76dc | 2012-06-29 21:33:59 +0000 | [diff] [blame] | 285 | /// optimizeCompareInstr - Convert the instruction to set the zero flag so |
| 286 | /// that we can remove a "comparison with zero"; Remove a redundant CMP |
| 287 | /// instruction if the flags can be updated in the same way by an earlier |
| 288 | /// instruction such as SUB. |
| Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 289 | bool optimizeCompareInstr(MachineInstr &CmpInstr, unsigned SrcReg, |
| Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 290 | unsigned SrcReg2, int CmpMask, int CmpValue, |
| 291 | const MachineRegisterInfo *MRI) const override; |
| Evan Cheng | 367a5df | 2010-09-09 18:18:55 +0000 | [diff] [blame] | 292 | |
| Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 293 | bool analyzeSelect(const MachineInstr &MI, |
| 294 | SmallVectorImpl<MachineOperand> &Cond, unsigned &TrueOp, |
| 295 | unsigned &FalseOp, bool &Optimizable) const override; |
| Jakob Stoklund Olesen | c19bf02 | 2012-08-16 23:14:20 +0000 | [diff] [blame] | 296 | |
| Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 297 | MachineInstr *optimizeSelect(MachineInstr &MI, |
| Mehdi Amini | 22e5974 | 2015-01-13 07:07:13 +0000 | [diff] [blame] | 298 | SmallPtrSetImpl<MachineInstr *> &SeenMIs, |
| 299 | bool) const override; |
| Jakob Stoklund Olesen | c19bf02 | 2012-08-16 23:14:20 +0000 | [diff] [blame] | 300 | |
| Evan Cheng | 7f8ab6e | 2010-11-17 20:13:28 +0000 | [diff] [blame] | 301 | /// FoldImmediate - 'Reg' is known to be defined by a move immediate |
| 302 | /// instruction, try to fold the immediate into the use instruction. |
| Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 303 | bool FoldImmediate(MachineInstr &UseMI, MachineInstr &DefMI, unsigned Reg, |
| 304 | MachineRegisterInfo *MRI) const override; |
| Evan Cheng | 7f8ab6e | 2010-11-17 20:13:28 +0000 | [diff] [blame] | 305 | |
| Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 306 | unsigned getNumMicroOps(const InstrItineraryData *ItinData, |
| Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 307 | const MachineInstr &MI) const override; |
| Evan Cheng | 49d4c0b | 2010-10-06 06:27:31 +0000 | [diff] [blame] | 308 | |
| Evan Cheng | 49d4c0b | 2010-10-06 06:27:31 +0000 | [diff] [blame] | 309 | int getOperandLatency(const InstrItineraryData *ItinData, |
| Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 310 | const MachineInstr &DefMI, unsigned DefIdx, |
| 311 | const MachineInstr &UseMI, |
| Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 312 | unsigned UseIdx) const override; |
| Evan Cheng | 49d4c0b | 2010-10-06 06:27:31 +0000 | [diff] [blame] | 313 | int getOperandLatency(const InstrItineraryData *ItinData, |
| 314 | SDNode *DefNode, unsigned DefIdx, |
| Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 315 | SDNode *UseNode, unsigned UseIdx) const override; |
| Jakob Stoklund Olesen | f9b71a2 | 2011-09-27 22:57:21 +0000 | [diff] [blame] | 316 | |
| 317 | /// VFP/NEON execution domains. |
| 318 | std::pair<uint16_t, uint16_t> |
| Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 319 | getExecutionDomain(const MachineInstr &MI) const override; |
| 320 | void setExecutionDomain(MachineInstr &MI, unsigned Domain) const override; |
| Jakob Stoklund Olesen | f9b71a2 | 2011-09-27 22:57:21 +0000 | [diff] [blame] | 321 | |
| Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 322 | unsigned |
| 323 | getPartialRegUpdateClearance(const MachineInstr &, unsigned, |
| 324 | const TargetRegisterInfo *) const override; |
| 325 | void breakPartialRegDependency(MachineInstr &, unsigned, |
| Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 326 | const TargetRegisterInfo *TRI) const override; |
| Tom Roeder | 44cb65f | 2014-06-05 19:29:43 +0000 | [diff] [blame] | 327 | |
| Andrew Trick | 2ac6f7d | 2012-09-14 18:48:46 +0000 | [diff] [blame] | 328 | /// Get the number of addresses by LDM or VLDM or zero for unknown. |
| Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 329 | unsigned getNumLDMAddresses(const MachineInstr &MI) const; |
| Andrew Trick | 2ac6f7d | 2012-09-14 18:48:46 +0000 | [diff] [blame] | 330 | |
| Evan Cheng | 49d4c0b | 2010-10-06 06:27:31 +0000 | [diff] [blame] | 331 | private: |
| Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 332 | unsigned getInstBundleLength(const MachineInstr &MI) const; |
| Evan Cheng | 7fae11b | 2011-12-14 02:11:42 +0000 | [diff] [blame] | 333 | |
| Evan Cheng | 412e37b | 2010-10-07 23:12:15 +0000 | [diff] [blame] | 334 | int getVLDMDefCycle(const InstrItineraryData *ItinData, |
| Evan Cheng | 6cc775f | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 335 | const MCInstrDesc &DefMCID, |
| Evan Cheng | 412e37b | 2010-10-07 23:12:15 +0000 | [diff] [blame] | 336 | unsigned DefClass, |
| 337 | unsigned DefIdx, unsigned DefAlign) const; |
| 338 | int getLDMDefCycle(const InstrItineraryData *ItinData, |
| Evan Cheng | 6cc775f | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 339 | const MCInstrDesc &DefMCID, |
| Evan Cheng | 412e37b | 2010-10-07 23:12:15 +0000 | [diff] [blame] | 340 | unsigned DefClass, |
| 341 | unsigned DefIdx, unsigned DefAlign) const; |
| 342 | int getVSTMUseCycle(const InstrItineraryData *ItinData, |
| Evan Cheng | 6cc775f | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 343 | const MCInstrDesc &UseMCID, |
| Evan Cheng | 412e37b | 2010-10-07 23:12:15 +0000 | [diff] [blame] | 344 | unsigned UseClass, |
| 345 | unsigned UseIdx, unsigned UseAlign) const; |
| 346 | int getSTMUseCycle(const InstrItineraryData *ItinData, |
| Evan Cheng | 6cc775f | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 347 | const MCInstrDesc &UseMCID, |
| Evan Cheng | 412e37b | 2010-10-07 23:12:15 +0000 | [diff] [blame] | 348 | unsigned UseClass, |
| 349 | unsigned UseIdx, unsigned UseAlign) const; |
| Evan Cheng | 49d4c0b | 2010-10-06 06:27:31 +0000 | [diff] [blame] | 350 | int getOperandLatency(const InstrItineraryData *ItinData, |
| Evan Cheng | 6cc775f | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 351 | const MCInstrDesc &DefMCID, |
| Evan Cheng | 49d4c0b | 2010-10-06 06:27:31 +0000 | [diff] [blame] | 352 | unsigned DefIdx, unsigned DefAlign, |
| Evan Cheng | 6cc775f | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 353 | const MCInstrDesc &UseMCID, |
| Evan Cheng | 49d4c0b | 2010-10-06 06:27:31 +0000 | [diff] [blame] | 354 | unsigned UseIdx, unsigned UseAlign) const; |
| Evan Cheng | 63c7608 | 2010-10-19 18:58:51 +0000 | [diff] [blame] | 355 | |
| Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 356 | int getOperandLatencyImpl(const InstrItineraryData *ItinData, |
| 357 | const MachineInstr &DefMI, unsigned DefIdx, |
| 358 | const MCInstrDesc &DefMCID, unsigned DefAdj, |
| 359 | const MachineOperand &DefMO, unsigned Reg, |
| 360 | const MachineInstr &UseMI, unsigned UseIdx, |
| 361 | const MCInstrDesc &UseMCID, unsigned UseAdj) const; |
| 362 | |
| Duncan P. N. Exon Smith | 6307eb5 | 2016-02-23 02:46:52 +0000 | [diff] [blame] | 363 | unsigned getPredicationCost(const MachineInstr &MI) const override; |
| Arnold Schwaighofer | d2f96b9 | 2013-09-30 15:28:56 +0000 | [diff] [blame] | 364 | |
| Andrew Trick | 4544606 | 2012-06-05 21:11:27 +0000 | [diff] [blame] | 365 | unsigned getInstrLatency(const InstrItineraryData *ItinData, |
| Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 366 | const MachineInstr &MI, |
| Craig Topper | e73658d | 2014-04-28 04:05:08 +0000 | [diff] [blame] | 367 | unsigned *PredCost = nullptr) const override; |
| Evan Cheng | debf9c5 | 2010-11-03 00:45:17 +0000 | [diff] [blame] | 368 | |
| 369 | int getInstrLatency(const InstrItineraryData *ItinData, |
| Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 370 | SDNode *Node) const override; |
| Evan Cheng | debf9c5 | 2010-11-03 00:45:17 +0000 | [diff] [blame] | 371 | |
| Matthias Braun | 88e2131 | 2015-06-13 03:42:11 +0000 | [diff] [blame] | 372 | bool hasHighOperandLatency(const TargetSchedModel &SchedModel, |
| Evan Cheng | 63c7608 | 2010-10-19 18:58:51 +0000 | [diff] [blame] | 373 | const MachineRegisterInfo *MRI, |
| Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 374 | const MachineInstr &DefMI, unsigned DefIdx, |
| 375 | const MachineInstr &UseMI, |
| Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 376 | unsigned UseIdx) const override; |
| Matthias Braun | 88e2131 | 2015-06-13 03:42:11 +0000 | [diff] [blame] | 377 | bool hasLowDefLatency(const TargetSchedModel &SchedModel, |
| Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 378 | const MachineInstr &DefMI, |
| Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 379 | unsigned DefIdx) const override; |
| Evan Cheng | 62c7b5b | 2010-12-05 22:04:16 +0000 | [diff] [blame] | 380 | |
| Andrew Trick | 924123a | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 381 | /// verifyInstruction - Perform target specific instruction verification. |
| Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 382 | bool verifyInstruction(const MachineInstr &MI, |
| Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 383 | StringRef &ErrInfo) const override; |
| Andrew Trick | 924123a | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 384 | |
| Rafael Espindola | 82f4631 | 2016-06-28 15:18:26 +0000 | [diff] [blame] | 385 | virtual void expandLoadStackGuard(MachineBasicBlock::iterator MI) const = 0; |
| Akira Hatanaka | e5b6e0d | 2014-07-25 19:31:34 +0000 | [diff] [blame] | 386 | |
| Scott Douglass | 953f908 | 2015-10-05 14:49:54 +0000 | [diff] [blame] | 387 | void expandMEMCPY(MachineBasicBlock::iterator) const; |
| 388 | |
| Evan Cheng | 62c7b5b | 2010-12-05 22:04:16 +0000 | [diff] [blame] | 389 | private: |
| 390 | /// Modeling special VFP / NEON fp MLA / MLS hazards. |
| 391 | |
| 392 | /// MLxEntryMap - Map fp MLA / MLS to the corresponding entry in the internal |
| 393 | /// MLx table. |
| 394 | DenseMap<unsigned, unsigned> MLxEntryMap; |
| 395 | |
| 396 | /// MLxHazardOpcodes - Set of add / sub and multiply opcodes that would cause |
| 397 | /// stalls when scheduled together with fp MLA / MLS opcodes. |
| 398 | SmallSet<unsigned, 16> MLxHazardOpcodes; |
| 399 | |
| 400 | public: |
| 401 | /// isFpMLxInstruction - Return true if the specified opcode is a fp MLA / MLS |
| 402 | /// instruction. |
| 403 | bool isFpMLxInstruction(unsigned Opcode) const { |
| 404 | return MLxEntryMap.count(Opcode); |
| 405 | } |
| 406 | |
| 407 | /// isFpMLxInstruction - This version also returns the multiply opcode and the |
| 408 | /// addition / subtraction opcode to expand to. Return true for 'HasLane' for |
| 409 | /// the MLX instructions with an extra lane operand. |
| 410 | bool isFpMLxInstruction(unsigned Opcode, unsigned &MulOpc, |
| 411 | unsigned &AddSubOpc, bool &NegAcc, |
| 412 | bool &HasLane) const; |
| 413 | |
| 414 | /// canCauseFpMLxStall - Return true if an instruction of the specified opcode |
| 415 | /// will cause stalls when scheduled after (within 4-cycle window) a fp |
| 416 | /// MLA / MLS instruction. |
| 417 | bool canCauseFpMLxStall(unsigned Opcode) const { |
| 418 | return MLxHazardOpcodes.count(Opcode); |
| 419 | } |
| Arnold Schwaighofer | 5dde1f3 | 2013-04-05 04:42:00 +0000 | [diff] [blame] | 420 | |
| 421 | /// Returns true if the instruction has a shift by immediate that can be |
| 422 | /// executed in one cycle less. |
| 423 | bool isSwiftFastImmShift(const MachineInstr *MI) const; |
| Serge Pavlov | 5943a96 | 2017-04-19 03:12:05 +0000 | [diff] [blame] | 424 | |
| 425 | /// Returns predicate register associated with the given frame instruction. |
| 426 | unsigned getFramePred(const MachineInstr &MI) const { |
| 427 | assert(isFrameInstr(MI)); |
| Serge Pavlov | d526b13 | 2017-05-09 13:35:13 +0000 | [diff] [blame] | 428 | // Operands of ADJCALLSTACKDOWN/ADJCALLSTACKUP: |
| 429 | // - argument declared in the pattern: |
| Serge Pavlov | 5943a96 | 2017-04-19 03:12:05 +0000 | [diff] [blame] | 430 | // 0 - frame size |
| Serge Pavlov | d526b13 | 2017-05-09 13:35:13 +0000 | [diff] [blame] | 431 | // 1 - arg of CALLSEQ_START/CALLSEQ_END |
| 432 | // 2 - predicate code (like ARMCC::AL) |
| Serge Pavlov | 5943a96 | 2017-04-19 03:12:05 +0000 | [diff] [blame] | 433 | // - added by predOps: |
| 434 | // 3 - predicate reg |
| 435 | return MI.getOperand(3).getReg(); |
| 436 | } |
| David Goodwin | af7451b | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 437 | }; |
| Evan Cheng | 780748d | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 438 | |
| Diana Picus | 4f8c3e1 | 2017-01-13 09:37:56 +0000 | [diff] [blame] | 439 | /// Get the operands corresponding to the given \p Pred value. By default, the |
| 440 | /// predicate register is assumed to be 0 (no register), but you can pass in a |
| 441 | /// \p PredReg if that is not the case. |
| 442 | static inline std::array<MachineOperand, 2> predOps(ARMCC::CondCodes Pred, |
| 443 | unsigned PredReg = 0) { |
| 444 | return {{MachineOperand::CreateImm(static_cast<int64_t>(Pred)), |
| Eugene Zelenko | 342257e | 2017-01-31 00:56:17 +0000 | [diff] [blame] | 445 | MachineOperand::CreateReg(PredReg, false)}}; |
| David Goodwin | af7451b | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 446 | } |
| 447 | |
| Diana Picus | 8a73f55 | 2017-01-13 10:18:01 +0000 | [diff] [blame] | 448 | /// Get the operand corresponding to the conditional code result. By default, |
| 449 | /// this is 0 (no register). |
| 450 | static inline MachineOperand condCodeOp(unsigned CCReg = 0) { |
| Eugene Zelenko | 342257e | 2017-01-31 00:56:17 +0000 | [diff] [blame] | 451 | return MachineOperand::CreateReg(CCReg, false); |
| Evan Cheng | 780748d | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 452 | } |
| 453 | |
| Diana Picus | a2c5914 | 2017-01-13 10:37:37 +0000 | [diff] [blame] | 454 | /// Get the operand corresponding to the conditional code result for Thumb1. |
| 455 | /// This operand will always refer to CPSR and it will have the Define flag set. |
| 456 | /// You can optionally set the Dead flag by means of \p isDead. |
| 457 | static inline MachineOperand t1CondCodeOp(bool isDead = false) { |
| 458 | return MachineOperand::CreateReg(ARM::CPSR, |
| 459 | /*Define*/ true, /*Implicit*/ false, |
| 460 | /*Kill*/ false, isDead); |
| Evan Cheng | 6ddd7bc | 2009-08-15 07:59:10 +0000 | [diff] [blame] | 461 | } |
| 462 | |
| 463 | static inline |
| Evan Cheng | 780748d | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 464 | bool isUncondBranchOpcode(int Opc) { |
| 465 | return Opc == ARM::B || Opc == ARM::tB || Opc == ARM::t2B; |
| 466 | } |
| 467 | |
| 468 | static inline |
| 469 | bool isCondBranchOpcode(int Opc) { |
| 470 | return Opc == ARM::Bcc || Opc == ARM::tBcc || Opc == ARM::t2Bcc; |
| 471 | } |
| 472 | |
| Momchil Velikov | 4a91fb9 | 2017-11-15 12:02:55 +0000 | [diff] [blame] | 473 | static inline bool isJumpTableBranchOpcode(int Opc) { |
| 474 | return Opc == ARM::BR_JTr || Opc == ARM::BR_JTm_i12 || |
| 475 | Opc == ARM::BR_JTm_rs || Opc == ARM::BR_JTadd || Opc == ARM::tBR_JTr || |
| 476 | Opc == ARM::t2BR_JT; |
| Evan Cheng | 780748d | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 477 | } |
| 478 | |
| Bob Wilson | 73789b8 | 2009-10-28 18:26:41 +0000 | [diff] [blame] | 479 | static inline |
| 480 | bool isIndirectBranchOpcode(int Opc) { |
| Bill Wendling | 8294a30 | 2010-11-30 00:48:15 +0000 | [diff] [blame] | 481 | return Opc == ARM::BX || Opc == ARM::MOVPCRX || Opc == ARM::tBRIND; |
| Bob Wilson | 73789b8 | 2009-10-28 18:26:41 +0000 | [diff] [blame] | 482 | } |
| 483 | |
| Tim Northover | 93bcc66 | 2013-11-08 17:18:07 +0000 | [diff] [blame] | 484 | static inline bool isPopOpcode(int Opc) { |
| 485 | return Opc == ARM::tPOP_RET || Opc == ARM::LDMIA_RET || |
| 486 | Opc == ARM::t2LDMIA_RET || Opc == ARM::tPOP || Opc == ARM::LDMIA_UPD || |
| 487 | Opc == ARM::t2LDMIA_UPD || Opc == ARM::VLDMDIA_UPD; |
| 488 | } |
| 489 | |
| 490 | static inline bool isPushOpcode(int Opc) { |
| 491 | return Opc == ARM::tPUSH || Opc == ARM::t2STMDB_UPD || |
| 492 | Opc == ARM::STMDB_UPD || Opc == ARM::VSTMDDB_UPD; |
| 493 | } |
| 494 | |
| Evan Cheng | 2aa91cc | 2009-08-08 03:20:32 +0000 | [diff] [blame] | 495 | /// getInstrPredicate - If instruction is predicated, returns its predicate |
| 496 | /// condition, otherwise returns AL. It also returns the condition code |
| 497 | /// register by reference. |
| Duncan P. N. Exon Smith | 6307eb5 | 2016-02-23 02:46:52 +0000 | [diff] [blame] | 498 | ARMCC::CondCodes getInstrPredicate(const MachineInstr &MI, unsigned &PredReg); |
| Evan Cheng | 2aa91cc | 2009-08-08 03:20:32 +0000 | [diff] [blame] | 499 | |
| Matthias Braun | fa3872e | 2015-05-18 20:27:55 +0000 | [diff] [blame] | 500 | unsigned getMatchingCondBranchOpcode(unsigned Opc); |
| Evan Cheng | 780748d | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 501 | |
| Jakob Stoklund Olesen | 6cb9612 | 2012-08-15 22:16:39 +0000 | [diff] [blame] | 502 | /// Determine if MI can be folded into an ARM MOVCC instruction, and return the |
| 503 | /// opcode of the SSA instruction representing the conditional MI. |
| 504 | unsigned canFoldARMInstrIntoMOVCC(unsigned Reg, |
| 505 | MachineInstr *&MI, |
| 506 | const MachineRegisterInfo &MRI); |
| Andrew Trick | 924123a | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 507 | |
| 508 | /// Map pseudo instructions that imply an 'S' bit onto real opcodes. Whether |
| 509 | /// the instruction is encoded with an 'S' bit is determined by the optional |
| 510 | /// CPSR def operand. |
| 511 | unsigned convertAddSubFlagsOpcode(unsigned OldOpc); |
| 512 | |
| Evan Cheng | 780748d | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 513 | /// emitARMRegPlusImmediate / emitT2RegPlusImmediate - Emits a series of |
| 514 | /// instructions to materializea destreg = basereg + immediate in ARM / Thumb2 |
| 515 | /// code. |
| 516 | void emitARMRegPlusImmediate(MachineBasicBlock &MBB, |
| Benjamin Kramer | bdc4956 | 2016-06-12 15:39:02 +0000 | [diff] [blame] | 517 | MachineBasicBlock::iterator &MBBI, |
| 518 | const DebugLoc &dl, unsigned DestReg, |
| 519 | unsigned BaseReg, int NumBytes, |
| Evan Cheng | 780748d | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 520 | ARMCC::CondCodes Pred, unsigned PredReg, |
| Anton Korobeynikov | e7410dd | 2011-03-05 18:43:32 +0000 | [diff] [blame] | 521 | const ARMBaseInstrInfo &TII, unsigned MIFlags = 0); |
| Evan Cheng | 780748d | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 522 | |
| 523 | void emitT2RegPlusImmediate(MachineBasicBlock &MBB, |
| Benjamin Kramer | bdc4956 | 2016-06-12 15:39:02 +0000 | [diff] [blame] | 524 | MachineBasicBlock::iterator &MBBI, |
| 525 | const DebugLoc &dl, unsigned DestReg, |
| 526 | unsigned BaseReg, int NumBytes, |
| Evan Cheng | 780748d | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 527 | ARMCC::CondCodes Pred, unsigned PredReg, |
| Anton Korobeynikov | e7410dd | 2011-03-05 18:43:32 +0000 | [diff] [blame] | 528 | const ARMBaseInstrInfo &TII, unsigned MIFlags = 0); |
| Jim Grosbach | bbdc5d2 | 2010-10-19 23:27:08 +0000 | [diff] [blame] | 529 | void emitThumbRegPlusImmediate(MachineBasicBlock &MBB, |
| Benjamin Kramer | bdc4956 | 2016-06-12 15:39:02 +0000 | [diff] [blame] | 530 | MachineBasicBlock::iterator &MBBI, |
| 531 | const DebugLoc &dl, unsigned DestReg, |
| 532 | unsigned BaseReg, int NumBytes, |
| 533 | const TargetInstrInfo &TII, |
| 534 | const ARMBaseRegisterInfo &MRI, |
| Anton Korobeynikov | e7410dd | 2011-03-05 18:43:32 +0000 | [diff] [blame] | 535 | unsigned MIFlags = 0); |
| Evan Cheng | 780748d | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 536 | |
| Tim Northover | 93bcc66 | 2013-11-08 17:18:07 +0000 | [diff] [blame] | 537 | /// Tries to add registers to the reglist of a given base-updating |
| 538 | /// push/pop instruction to adjust the stack by an additional |
| 539 | /// NumBytes. This can save a few bytes per function in code-size, but |
| 540 | /// obviously generates more memory traffic. As such, it only takes |
| 541 | /// effect in functions being optimised for size. |
| Tim Northover | dee8604 | 2013-12-02 14:46:26 +0000 | [diff] [blame] | 542 | bool tryFoldSPUpdateIntoPushPop(const ARMSubtarget &Subtarget, |
| 543 | MachineFunction &MF, MachineInstr *MI, |
| Tim Northover | 93bcc66 | 2013-11-08 17:18:07 +0000 | [diff] [blame] | 544 | unsigned NumBytes); |
| Evan Cheng | 780748d | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 545 | |
| Jim Grosbach | f24f9d9 | 2009-08-11 15:33:49 +0000 | [diff] [blame] | 546 | /// rewriteARMFrameIndex / rewriteT2FrameIndex - |
| Evan Cheng | 7a37b1a | 2009-08-27 01:23:50 +0000 | [diff] [blame] | 547 | /// Rewrite MI to access 'Offset' bytes from the FP. Return false if the |
| 548 | /// offset could not be handled directly in MI, and return the left-over |
| 549 | /// portion by reference. |
| 550 | bool rewriteARMFrameIndex(MachineInstr &MI, unsigned FrameRegIdx, |
| 551 | unsigned FrameReg, int &Offset, |
| 552 | const ARMBaseInstrInfo &TII); |
| Evan Cheng | 780748d | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 553 | |
| Evan Cheng | 7a37b1a | 2009-08-27 01:23:50 +0000 | [diff] [blame] | 554 | bool rewriteT2FrameIndex(MachineInstr &MI, unsigned FrameRegIdx, |
| 555 | unsigned FrameReg, int &Offset, |
| 556 | const ARMBaseInstrInfo &TII); |
| Evan Cheng | 780748d | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 557 | |
| Eugene Zelenko | 342257e | 2017-01-31 00:56:17 +0000 | [diff] [blame] | 558 | } // end namespace llvm |
| Evan Cheng | 780748d | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 559 | |
| Eugene Zelenko | 342257e | 2017-01-31 00:56:17 +0000 | [diff] [blame] | 560 | #endif // LLVM_LIB_TARGET_ARM_ARMBASEINSTRINFO_H |