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 | |
| 14 | #ifndef ARMBASEINSTRUCTIONINFO_H |
| 15 | #define ARMBASEINSTRUCTIONINFO_H |
| 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" |
Chandler Carruth | 802d755 | 2012-12-04 07:12:27 +0000 | [diff] [blame] | 20 | #include "llvm/CodeGen/MachineInstrBuilder.h" |
| 21 | #include "llvm/Target/TargetInstrInfo.h" |
David Goodwin | af7451b | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 22 | |
Evan Cheng | 703a0fb | 2011-07-01 17:57:27 +0000 | [diff] [blame] | 23 | #define GET_INSTRINFO_HEADER |
| 24 | #include "ARMGenInstrInfo.inc" |
| 25 | |
David Goodwin | af7451b | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 26 | namespace llvm { |
Chris Lattner | cbe9856 | 2010-07-20 21:17:29 +0000 | [diff] [blame] | 27 | class ARMSubtarget; |
| 28 | class ARMBaseRegisterInfo; |
David Goodwin | af7451b | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 29 | |
Evan Cheng | 703a0fb | 2011-07-01 17:57:27 +0000 | [diff] [blame] | 30 | class ARMBaseInstrInfo : public ARMGenInstrInfo { |
Chris Lattner | cbe9856 | 2010-07-20 21:17:29 +0000 | [diff] [blame] | 31 | const ARMSubtarget &Subtarget; |
Evan Cheng | 62c7b5b | 2010-12-05 22:04:16 +0000 | [diff] [blame] | 32 | |
David Goodwin | af7451b | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 33 | protected: |
| 34 | // Can be only subclassed. |
Anton Korobeynikov | 14635da | 2009-11-02 00:10:38 +0000 | [diff] [blame] | 35 | explicit ARMBaseInstrInfo(const ARMSubtarget &STI); |
Evan Cheng | 62c7b5b | 2010-12-05 22:04:16 +0000 | [diff] [blame] | 36 | |
David Goodwin | af7451b | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 37 | public: |
Jim Grosbach | 617f84dd | 2012-02-28 23:53:30 +0000 | [diff] [blame] | 38 | // Return whether the target has an explicit NOP encoding. |
| 39 | bool hasNOP() const; |
| 40 | |
David Goodwin | af7451b | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 41 | // Return the non-pre/post incrementing version of 'Opc'. Return 0 |
| 42 | // if there is not such an opcode. |
| 43 | virtual unsigned getUnindexedOpcode(unsigned Opc) const =0; |
| 44 | |
Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 45 | MachineInstr *convertToThreeAddress(MachineFunction::iterator &MFI, |
| 46 | MachineBasicBlock::iterator &MBBI, |
| 47 | LiveVariables *LV) const override; |
David Goodwin | af7451b | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 48 | |
Bill Wendling | f95178e | 2013-06-07 05:54:19 +0000 | [diff] [blame] | 49 | virtual const ARMBaseRegisterInfo &getRegisterInfo() const = 0; |
Anton Korobeynikov | 14635da | 2009-11-02 00:10:38 +0000 | [diff] [blame] | 50 | const ARMSubtarget &getSubtarget() const { return Subtarget; } |
David Goodwin | af7451b | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 51 | |
Evan Cheng | 62c7b5b | 2010-12-05 22:04:16 +0000 | [diff] [blame] | 52 | ScheduleHazardRecognizer * |
Eric Christopher | f047bfd | 2014-06-13 22:38:52 +0000 | [diff] [blame^] | 53 | CreateTargetHazardRecognizer(const TargetSubtargetInfo *STI, |
Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 54 | const ScheduleDAG *DAG) const override; |
Andrew Trick | 10ffc2b | 2010-12-24 05:03:26 +0000 | [diff] [blame] | 55 | |
| 56 | ScheduleHazardRecognizer * |
| 57 | CreateTargetPostRAHazardRecognizer(const InstrItineraryData *II, |
Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 58 | const ScheduleDAG *DAG) const override; |
Evan Cheng | 62c7b5b | 2010-12-05 22:04:16 +0000 | [diff] [blame] | 59 | |
David Goodwin | af7451b | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 60 | // Branch analysis. |
Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 61 | bool AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB, |
| 62 | MachineBasicBlock *&FBB, |
| 63 | SmallVectorImpl<MachineOperand> &Cond, |
| 64 | bool AllowModify = false) const override; |
| 65 | unsigned RemoveBranch(MachineBasicBlock &MBB) const override; |
| 66 | unsigned InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB, |
| 67 | MachineBasicBlock *FBB, |
| 68 | const SmallVectorImpl<MachineOperand> &Cond, |
| 69 | DebugLoc DL) const override; |
David Goodwin | af7451b | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 70 | |
Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 71 | bool |
| 72 | ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const override; |
David Goodwin | af7451b | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 73 | |
| 74 | // Predication support. |
Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 75 | bool isPredicated(const MachineInstr *MI) const override; |
David Goodwin | af7451b | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 76 | |
| 77 | ARMCC::CondCodes getPredicate(const MachineInstr *MI) const { |
| 78 | int PIdx = MI->findFirstPredOperandIdx(); |
| 79 | return PIdx != -1 ? (ARMCC::CondCodes)MI->getOperand(PIdx).getImm() |
| 80 | : ARMCC::AL; |
| 81 | } |
| 82 | |
David Goodwin | af7451b | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 83 | bool PredicateInstruction(MachineInstr *MI, |
Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 84 | const SmallVectorImpl<MachineOperand> &Pred) const override; |
David Goodwin | af7451b | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 85 | |
David Goodwin | af7451b | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 86 | bool SubsumesPredicate(const SmallVectorImpl<MachineOperand> &Pred1, |
Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 87 | const SmallVectorImpl<MachineOperand> &Pred2) const override; |
David Goodwin | af7451b | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 88 | |
Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 89 | bool DefinesPredicate(MachineInstr *MI, |
| 90 | std::vector<MachineOperand> &Pred) const override; |
David Goodwin | af7451b | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 91 | |
Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 92 | bool isPredicable(MachineInstr *MI) const override; |
Evan Cheng | a33fc86 | 2009-11-21 06:21:52 +0000 | [diff] [blame] | 93 | |
David Goodwin | af7451b | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 94 | /// GetInstSize - Returns the size of the specified MachineInstr. |
| 95 | /// |
| 96 | virtual unsigned GetInstSizeInBytes(const MachineInstr* MI) const; |
| 97 | |
Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 98 | unsigned isLoadFromStackSlot(const MachineInstr *MI, |
| 99 | int &FrameIndex) const override; |
| 100 | unsigned isStoreToStackSlot(const MachineInstr *MI, |
| 101 | int &FrameIndex) const override; |
| 102 | unsigned isLoadFromStackSlotPostFE(const MachineInstr *MI, |
| 103 | int &FrameIndex) const override; |
| 104 | unsigned isStoreToStackSlotPostFE(const MachineInstr *MI, |
| 105 | int &FrameIndex) const override; |
David Goodwin | af7451b | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 106 | |
Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 107 | void copyPhysReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator I, |
| 108 | DebugLoc DL, unsigned DestReg, unsigned SrcReg, |
| 109 | bool KillSrc) const override; |
Evan Cheng | c47e109 | 2009-07-27 03:14:20 +0000 | [diff] [blame] | 110 | |
Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 111 | void storeRegToStackSlot(MachineBasicBlock &MBB, |
| 112 | MachineBasicBlock::iterator MBBI, |
| 113 | unsigned SrcReg, bool isKill, int FrameIndex, |
| 114 | const TargetRegisterClass *RC, |
| 115 | const TargetRegisterInfo *TRI) const override; |
David Goodwin | af7451b | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 116 | |
Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 117 | void loadRegFromStackSlot(MachineBasicBlock &MBB, |
| 118 | MachineBasicBlock::iterator MBBI, |
| 119 | unsigned DestReg, int FrameIndex, |
| 120 | const TargetRegisterClass *RC, |
| 121 | const TargetRegisterInfo *TRI) const override; |
David Goodwin | af7451b | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 122 | |
Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 123 | bool expandPostRAPseudo(MachineBasicBlock::iterator MI) const override; |
Jakob Stoklund Olesen | da7c0f8 | 2011-10-11 00:59:06 +0000 | [diff] [blame] | 124 | |
Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 125 | void reMaterialize(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, |
| 126 | unsigned DestReg, unsigned SubIdx, |
| 127 | const MachineInstr *Orig, |
| 128 | const TargetRegisterInfo &TRI) const override; |
Evan Cheng | fe86442 | 2009-11-08 00:15:23 +0000 | [diff] [blame] | 129 | |
Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 130 | MachineInstr *duplicate(MachineInstr *Orig, |
| 131 | MachineFunction &MF) const override; |
Jakob Stoklund Olesen | 29a64c9 | 2010-01-06 23:47:07 +0000 | [diff] [blame] | 132 | |
Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 133 | MachineInstr *commuteInstruction(MachineInstr*, |
| 134 | bool=false) const override; |
Jakob Stoklund Olesen | 0a5b72f | 2012-04-04 18:23:42 +0000 | [diff] [blame] | 135 | |
Tim Northover | 798697d | 2013-04-21 11:57:07 +0000 | [diff] [blame] | 136 | const MachineInstrBuilder &AddDReg(MachineInstrBuilder &MIB, unsigned Reg, |
| 137 | unsigned SubIdx, unsigned State, |
| 138 | const TargetRegisterInfo *TRI) const; |
| 139 | |
Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 140 | bool produceSameValue(const MachineInstr *MI0, const MachineInstr *MI1, |
| 141 | const MachineRegisterInfo *MRI) const override; |
Evan Cheng | 2d51c7c | 2010-06-18 23:09:54 +0000 | [diff] [blame] | 142 | |
Bill Wendling | f470747 | 2010-06-23 23:00:16 +0000 | [diff] [blame] | 143 | /// areLoadsFromSameBasePtr - This is used by the pre-regalloc scheduler to |
| 144 | /// determine if two loads are loading from the same base address. It should |
| 145 | /// only return true if the base pointers are the same and the only |
| 146 | /// differences between the two addresses is the offset. It also returns the |
| 147 | /// offsets by reference. |
Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 148 | bool areLoadsFromSameBasePtr(SDNode *Load1, SDNode *Load2, int64_t &Offset1, |
| 149 | int64_t &Offset2) const override; |
Bill Wendling | f470747 | 2010-06-23 23:00:16 +0000 | [diff] [blame] | 150 | |
| 151 | /// shouldScheduleLoadsNear - This is a used by the pre-regalloc scheduler to |
Jim Grosbach | 7ef7ddd | 2011-06-13 22:54:22 +0000 | [diff] [blame] | 152 | /// determine (in conjunction with areLoadsFromSameBasePtr) if two loads |
| 153 | /// 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] | 154 | /// addresses in the same cache line, it's better if they are scheduled |
| 155 | /// together. This function takes two integers that represent the load offsets |
| 156 | /// from the common base address. It returns true if it decides it's desirable |
| 157 | /// to schedule the two loads together. "NumLoads" is the number of loads that |
| 158 | /// have already been scheduled after Load1. |
Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 159 | bool shouldScheduleLoadsNear(SDNode *Load1, SDNode *Load2, |
| 160 | int64_t Offset1, int64_t Offset2, |
| 161 | unsigned NumLoads) const override; |
Bill Wendling | f470747 | 2010-06-23 23:00:16 +0000 | [diff] [blame] | 162 | |
Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 163 | bool isSchedulingBoundary(const MachineInstr *MI, |
| 164 | const MachineBasicBlock *MBB, |
| 165 | const MachineFunction &MF) const override; |
Evan Cheng | 02b184d | 2010-06-25 22:42:03 +0000 | [diff] [blame] | 166 | |
Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 167 | bool isProfitableToIfCvt(MachineBasicBlock &MBB, |
| 168 | unsigned NumCycles, unsigned ExtraPredCycles, |
| 169 | const BranchProbability &Probability) const override; |
Evan Cheng | 02b184d | 2010-06-25 22:42:03 +0000 | [diff] [blame] | 170 | |
Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 171 | bool isProfitableToIfCvt(MachineBasicBlock &TMBB, unsigned NumT, |
| 172 | unsigned ExtraT, MachineBasicBlock &FMBB, |
| 173 | unsigned NumF, unsigned ExtraF, |
| 174 | const BranchProbability &Probability) const override; |
Evan Cheng | 02b184d | 2010-06-25 22:42:03 +0000 | [diff] [blame] | 175 | |
Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 176 | bool isProfitableToDupForIfCvt(MachineBasicBlock &MBB, unsigned NumCycles, |
| 177 | const BranchProbability &Probability) const override { |
Cameron Zwarich | 8001850 | 2011-04-13 06:39:16 +0000 | [diff] [blame] | 178 | return NumCycles == 1; |
Evan Cheng | 02b184d | 2010-06-25 22:42:03 +0000 | [diff] [blame] | 179 | } |
Bill Wendling | 7de9d52 | 2010-08-06 01:32:48 +0000 | [diff] [blame] | 180 | |
Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 181 | bool isProfitableToUnpredicate(MachineBasicBlock &TMBB, |
| 182 | MachineBasicBlock &FMBB) const override; |
Bob Wilson | e8a549c | 2012-09-29 21:43:49 +0000 | [diff] [blame] | 183 | |
Manman Ren | 6fa76dc | 2012-06-29 21:33:59 +0000 | [diff] [blame] | 184 | /// analyzeCompare - For a comparison instruction, return the source registers |
| 185 | /// in SrcReg and SrcReg2 if having two register operands, and the value it |
| 186 | /// compares against in CmpValue. Return true if the comparison instruction |
| 187 | /// can be analyzed. |
Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 188 | bool analyzeCompare(const MachineInstr *MI, unsigned &SrcReg, |
| 189 | unsigned &SrcReg2, int &CmpMask, |
| 190 | int &CmpValue) const override; |
Bill Wendling | 7de9d52 | 2010-08-06 01:32:48 +0000 | [diff] [blame] | 191 | |
Manman Ren | 6fa76dc | 2012-06-29 21:33:59 +0000 | [diff] [blame] | 192 | /// optimizeCompareInstr - Convert the instruction to set the zero flag so |
| 193 | /// that we can remove a "comparison with zero"; Remove a redundant CMP |
| 194 | /// instruction if the flags can be updated in the same way by an earlier |
| 195 | /// instruction such as SUB. |
Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 196 | bool optimizeCompareInstr(MachineInstr *CmpInstr, unsigned SrcReg, |
| 197 | unsigned SrcReg2, int CmpMask, int CmpValue, |
| 198 | const MachineRegisterInfo *MRI) const override; |
Evan Cheng | 367a5df | 2010-09-09 18:18:55 +0000 | [diff] [blame] | 199 | |
Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 200 | bool analyzeSelect(const MachineInstr *MI, |
| 201 | SmallVectorImpl<MachineOperand> &Cond, |
| 202 | unsigned &TrueOp, unsigned &FalseOp, |
| 203 | bool &Optimizable) const override; |
Jakob Stoklund Olesen | c19bf02 | 2012-08-16 23:14:20 +0000 | [diff] [blame] | 204 | |
Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 205 | MachineInstr *optimizeSelect(MachineInstr *MI, bool) const override; |
Jakob Stoklund Olesen | c19bf02 | 2012-08-16 23:14:20 +0000 | [diff] [blame] | 206 | |
Evan Cheng | 7f8ab6e | 2010-11-17 20:13:28 +0000 | [diff] [blame] | 207 | /// FoldImmediate - 'Reg' is known to be defined by a move immediate |
| 208 | /// instruction, try to fold the immediate into the use instruction. |
Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 209 | bool FoldImmediate(MachineInstr *UseMI, MachineInstr *DefMI, |
| 210 | unsigned Reg, MachineRegisterInfo *MRI) const override; |
Evan Cheng | 7f8ab6e | 2010-11-17 20:13:28 +0000 | [diff] [blame] | 211 | |
Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 212 | unsigned getNumMicroOps(const InstrItineraryData *ItinData, |
| 213 | const MachineInstr *MI) const override; |
Evan Cheng | 49d4c0b | 2010-10-06 06:27:31 +0000 | [diff] [blame] | 214 | |
Evan Cheng | 49d4c0b | 2010-10-06 06:27:31 +0000 | [diff] [blame] | 215 | int getOperandLatency(const InstrItineraryData *ItinData, |
| 216 | const MachineInstr *DefMI, unsigned DefIdx, |
Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 217 | const MachineInstr *UseMI, |
| 218 | unsigned UseIdx) const override; |
Evan Cheng | 49d4c0b | 2010-10-06 06:27:31 +0000 | [diff] [blame] | 219 | int getOperandLatency(const InstrItineraryData *ItinData, |
| 220 | SDNode *DefNode, unsigned DefIdx, |
Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 221 | SDNode *UseNode, unsigned UseIdx) const override; |
Jakob Stoklund Olesen | f9b71a2 | 2011-09-27 22:57:21 +0000 | [diff] [blame] | 222 | |
| 223 | /// VFP/NEON execution domains. |
| 224 | std::pair<uint16_t, uint16_t> |
Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 225 | getExecutionDomain(const MachineInstr *MI) const override; |
| 226 | void setExecutionDomain(MachineInstr *MI, unsigned Domain) const override; |
Jakob Stoklund Olesen | f9b71a2 | 2011-09-27 22:57:21 +0000 | [diff] [blame] | 227 | |
Bob Wilson | e8a549c | 2012-09-29 21:43:49 +0000 | [diff] [blame] | 228 | unsigned getPartialRegUpdateClearance(const MachineInstr*, unsigned, |
Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 229 | const TargetRegisterInfo*) const override; |
Bob Wilson | e8a549c | 2012-09-29 21:43:49 +0000 | [diff] [blame] | 230 | void breakPartialRegDependency(MachineBasicBlock::iterator, unsigned, |
Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 231 | const TargetRegisterInfo *TRI) const override; |
Tom Roeder | 44cb65f | 2014-06-05 19:29:43 +0000 | [diff] [blame] | 232 | |
| 233 | void |
| 234 | getUnconditionalBranch(MCInst &Branch, |
| 235 | const MCSymbolRefExpr *BranchTarget) const override; |
| 236 | |
| 237 | void getTrap(MCInst &MI) const override; |
| 238 | |
Andrew Trick | 2ac6f7d | 2012-09-14 18:48:46 +0000 | [diff] [blame] | 239 | /// Get the number of addresses by LDM or VLDM or zero for unknown. |
| 240 | unsigned getNumLDMAddresses(const MachineInstr *MI) const; |
| 241 | |
Evan Cheng | 49d4c0b | 2010-10-06 06:27:31 +0000 | [diff] [blame] | 242 | private: |
Evan Cheng | 7fae11b | 2011-12-14 02:11:42 +0000 | [diff] [blame] | 243 | unsigned getInstBundleLength(const MachineInstr *MI) const; |
| 244 | |
Evan Cheng | 412e37b | 2010-10-07 23:12:15 +0000 | [diff] [blame] | 245 | int getVLDMDefCycle(const InstrItineraryData *ItinData, |
Evan Cheng | 6cc775f | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 246 | const MCInstrDesc &DefMCID, |
Evan Cheng | 412e37b | 2010-10-07 23:12:15 +0000 | [diff] [blame] | 247 | unsigned DefClass, |
| 248 | unsigned DefIdx, unsigned DefAlign) const; |
| 249 | int getLDMDefCycle(const InstrItineraryData *ItinData, |
Evan Cheng | 6cc775f | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 250 | const MCInstrDesc &DefMCID, |
Evan Cheng | 412e37b | 2010-10-07 23:12:15 +0000 | [diff] [blame] | 251 | unsigned DefClass, |
| 252 | unsigned DefIdx, unsigned DefAlign) const; |
| 253 | int getVSTMUseCycle(const InstrItineraryData *ItinData, |
Evan Cheng | 6cc775f | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 254 | const MCInstrDesc &UseMCID, |
Evan Cheng | 412e37b | 2010-10-07 23:12:15 +0000 | [diff] [blame] | 255 | unsigned UseClass, |
| 256 | unsigned UseIdx, unsigned UseAlign) const; |
| 257 | int getSTMUseCycle(const InstrItineraryData *ItinData, |
Evan Cheng | 6cc775f | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 258 | const MCInstrDesc &UseMCID, |
Evan Cheng | 412e37b | 2010-10-07 23:12:15 +0000 | [diff] [blame] | 259 | unsigned UseClass, |
| 260 | unsigned UseIdx, unsigned UseAlign) const; |
Evan Cheng | 49d4c0b | 2010-10-06 06:27:31 +0000 | [diff] [blame] | 261 | int getOperandLatency(const InstrItineraryData *ItinData, |
Evan Cheng | 6cc775f | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 262 | const MCInstrDesc &DefMCID, |
Evan Cheng | 49d4c0b | 2010-10-06 06:27:31 +0000 | [diff] [blame] | 263 | unsigned DefIdx, unsigned DefAlign, |
Evan Cheng | 6cc775f | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 264 | const MCInstrDesc &UseMCID, |
Evan Cheng | 49d4c0b | 2010-10-06 06:27:31 +0000 | [diff] [blame] | 265 | unsigned UseIdx, unsigned UseAlign) const; |
Evan Cheng | 63c7608 | 2010-10-19 18:58:51 +0000 | [diff] [blame] | 266 | |
Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 267 | unsigned getPredicationCost(const MachineInstr *MI) const override; |
Arnold Schwaighofer | d2f96b9 | 2013-09-30 15:28:56 +0000 | [diff] [blame] | 268 | |
Andrew Trick | 4544606 | 2012-06-05 21:11:27 +0000 | [diff] [blame] | 269 | unsigned getInstrLatency(const InstrItineraryData *ItinData, |
| 270 | const MachineInstr *MI, |
Craig Topper | e73658d | 2014-04-28 04:05:08 +0000 | [diff] [blame] | 271 | unsigned *PredCost = nullptr) const override; |
Evan Cheng | debf9c5 | 2010-11-03 00:45:17 +0000 | [diff] [blame] | 272 | |
| 273 | int getInstrLatency(const InstrItineraryData *ItinData, |
Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 274 | SDNode *Node) const override; |
Evan Cheng | debf9c5 | 2010-11-03 00:45:17 +0000 | [diff] [blame] | 275 | |
Evan Cheng | 63c7608 | 2010-10-19 18:58:51 +0000 | [diff] [blame] | 276 | bool hasHighOperandLatency(const InstrItineraryData *ItinData, |
| 277 | const MachineRegisterInfo *MRI, |
| 278 | const MachineInstr *DefMI, unsigned DefIdx, |
Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 279 | const MachineInstr *UseMI, |
| 280 | unsigned UseIdx) const override; |
Evan Cheng | e96b8d7 | 2010-10-26 02:08:50 +0000 | [diff] [blame] | 281 | bool hasLowDefLatency(const InstrItineraryData *ItinData, |
Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 282 | const MachineInstr *DefMI, |
| 283 | unsigned DefIdx) const override; |
Evan Cheng | 62c7b5b | 2010-12-05 22:04:16 +0000 | [diff] [blame] | 284 | |
Andrew Trick | 924123a | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 285 | /// verifyInstruction - Perform target specific instruction verification. |
Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 286 | bool verifyInstruction(const MachineInstr *MI, |
| 287 | StringRef &ErrInfo) const override; |
Andrew Trick | 924123a | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 288 | |
Evan Cheng | 62c7b5b | 2010-12-05 22:04:16 +0000 | [diff] [blame] | 289 | private: |
| 290 | /// Modeling special VFP / NEON fp MLA / MLS hazards. |
| 291 | |
| 292 | /// MLxEntryMap - Map fp MLA / MLS to the corresponding entry in the internal |
| 293 | /// MLx table. |
| 294 | DenseMap<unsigned, unsigned> MLxEntryMap; |
| 295 | |
| 296 | /// MLxHazardOpcodes - Set of add / sub and multiply opcodes that would cause |
| 297 | /// stalls when scheduled together with fp MLA / MLS opcodes. |
| 298 | SmallSet<unsigned, 16> MLxHazardOpcodes; |
| 299 | |
| 300 | public: |
| 301 | /// isFpMLxInstruction - Return true if the specified opcode is a fp MLA / MLS |
| 302 | /// instruction. |
| 303 | bool isFpMLxInstruction(unsigned Opcode) const { |
| 304 | return MLxEntryMap.count(Opcode); |
| 305 | } |
| 306 | |
| 307 | /// isFpMLxInstruction - This version also returns the multiply opcode and the |
| 308 | /// addition / subtraction opcode to expand to. Return true for 'HasLane' for |
| 309 | /// the MLX instructions with an extra lane operand. |
| 310 | bool isFpMLxInstruction(unsigned Opcode, unsigned &MulOpc, |
| 311 | unsigned &AddSubOpc, bool &NegAcc, |
| 312 | bool &HasLane) const; |
| 313 | |
| 314 | /// canCauseFpMLxStall - Return true if an instruction of the specified opcode |
| 315 | /// will cause stalls when scheduled after (within 4-cycle window) a fp |
| 316 | /// MLA / MLS instruction. |
| 317 | bool canCauseFpMLxStall(unsigned Opcode) const { |
| 318 | return MLxHazardOpcodes.count(Opcode); |
| 319 | } |
Arnold Schwaighofer | 5dde1f3 | 2013-04-05 04:42:00 +0000 | [diff] [blame] | 320 | |
| 321 | /// Returns true if the instruction has a shift by immediate that can be |
| 322 | /// executed in one cycle less. |
| 323 | bool isSwiftFastImmShift(const MachineInstr *MI) const; |
David Goodwin | af7451b | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 324 | }; |
Evan Cheng | 780748d | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 325 | |
| 326 | static inline |
| 327 | const MachineInstrBuilder &AddDefaultPred(const MachineInstrBuilder &MIB) { |
| 328 | return MIB.addImm((int64_t)ARMCC::AL).addReg(0); |
David Goodwin | af7451b | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 329 | } |
| 330 | |
Evan Cheng | 780748d | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 331 | static inline |
| 332 | const MachineInstrBuilder &AddDefaultCC(const MachineInstrBuilder &MIB) { |
| 333 | return MIB.addReg(0); |
| 334 | } |
| 335 | |
| 336 | static inline |
Evan Cheng | 51cbd2d | 2009-08-10 02:37:24 +0000 | [diff] [blame] | 337 | const MachineInstrBuilder &AddDefaultT1CC(const MachineInstrBuilder &MIB, |
| 338 | bool isDead = false) { |
| 339 | return MIB.addReg(ARM::CPSR, getDefRegState(true) | getDeadRegState(isDead)); |
Evan Cheng | 780748d | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 340 | } |
| 341 | |
| 342 | static inline |
Evan Cheng | 6ddd7bc | 2009-08-15 07:59:10 +0000 | [diff] [blame] | 343 | const MachineInstrBuilder &AddNoT1CC(const MachineInstrBuilder &MIB) { |
| 344 | return MIB.addReg(0); |
| 345 | } |
| 346 | |
| 347 | static inline |
Evan Cheng | 780748d | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 348 | bool isUncondBranchOpcode(int Opc) { |
| 349 | return Opc == ARM::B || Opc == ARM::tB || Opc == ARM::t2B; |
| 350 | } |
| 351 | |
| 352 | static inline |
| 353 | bool isCondBranchOpcode(int Opc) { |
| 354 | return Opc == ARM::Bcc || Opc == ARM::tBcc || Opc == ARM::t2Bcc; |
| 355 | } |
| 356 | |
| 357 | static inline |
| 358 | bool isJumpTableBranchOpcode(int Opc) { |
| 359 | return Opc == ARM::BR_JTr || Opc == ARM::BR_JTm || Opc == ARM::BR_JTadd || |
| 360 | Opc == ARM::tBR_JTr || Opc == ARM::t2BR_JT; |
| 361 | } |
| 362 | |
Bob Wilson | 73789b8 | 2009-10-28 18:26:41 +0000 | [diff] [blame] | 363 | static inline |
| 364 | bool isIndirectBranchOpcode(int Opc) { |
Bill Wendling | 8294a30 | 2010-11-30 00:48:15 +0000 | [diff] [blame] | 365 | return Opc == ARM::BX || Opc == ARM::MOVPCRX || Opc == ARM::tBRIND; |
Bob Wilson | 73789b8 | 2009-10-28 18:26:41 +0000 | [diff] [blame] | 366 | } |
| 367 | |
Tim Northover | 93bcc66 | 2013-11-08 17:18:07 +0000 | [diff] [blame] | 368 | static inline bool isPopOpcode(int Opc) { |
| 369 | return Opc == ARM::tPOP_RET || Opc == ARM::LDMIA_RET || |
| 370 | Opc == ARM::t2LDMIA_RET || Opc == ARM::tPOP || Opc == ARM::LDMIA_UPD || |
| 371 | Opc == ARM::t2LDMIA_UPD || Opc == ARM::VLDMDIA_UPD; |
| 372 | } |
| 373 | |
| 374 | static inline bool isPushOpcode(int Opc) { |
| 375 | return Opc == ARM::tPUSH || Opc == ARM::t2STMDB_UPD || |
| 376 | Opc == ARM::STMDB_UPD || Opc == ARM::VSTMDDB_UPD; |
| 377 | } |
| 378 | |
Evan Cheng | 2aa91cc | 2009-08-08 03:20:32 +0000 | [diff] [blame] | 379 | /// getInstrPredicate - If instruction is predicated, returns its predicate |
| 380 | /// condition, otherwise returns AL. It also returns the condition code |
| 381 | /// register by reference. |
Evan Cheng | 83e0d48 | 2009-09-28 09:14:39 +0000 | [diff] [blame] | 382 | ARMCC::CondCodes getInstrPredicate(const MachineInstr *MI, unsigned &PredReg); |
Evan Cheng | 2aa91cc | 2009-08-08 03:20:32 +0000 | [diff] [blame] | 383 | |
Evan Cheng | 780748d | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 384 | int getMatchingCondBranchOpcode(int Opc); |
| 385 | |
Jakob Stoklund Olesen | 6cb9612 | 2012-08-15 22:16:39 +0000 | [diff] [blame] | 386 | /// Determine if MI can be folded into an ARM MOVCC instruction, and return the |
| 387 | /// opcode of the SSA instruction representing the conditional MI. |
| 388 | unsigned canFoldARMInstrIntoMOVCC(unsigned Reg, |
| 389 | MachineInstr *&MI, |
| 390 | const MachineRegisterInfo &MRI); |
Andrew Trick | 924123a | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 391 | |
| 392 | /// Map pseudo instructions that imply an 'S' bit onto real opcodes. Whether |
| 393 | /// the instruction is encoded with an 'S' bit is determined by the optional |
| 394 | /// CPSR def operand. |
| 395 | unsigned convertAddSubFlagsOpcode(unsigned OldOpc); |
| 396 | |
Evan Cheng | 780748d | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 397 | /// emitARMRegPlusImmediate / emitT2RegPlusImmediate - Emits a series of |
| 398 | /// instructions to materializea destreg = basereg + immediate in ARM / Thumb2 |
| 399 | /// code. |
| 400 | void emitARMRegPlusImmediate(MachineBasicBlock &MBB, |
| 401 | MachineBasicBlock::iterator &MBBI, DebugLoc dl, |
| 402 | unsigned DestReg, unsigned BaseReg, int NumBytes, |
| 403 | ARMCC::CondCodes Pred, unsigned PredReg, |
Anton Korobeynikov | e7410dd | 2011-03-05 18:43:32 +0000 | [diff] [blame] | 404 | const ARMBaseInstrInfo &TII, unsigned MIFlags = 0); |
Evan Cheng | 780748d | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 405 | |
| 406 | void emitT2RegPlusImmediate(MachineBasicBlock &MBB, |
| 407 | MachineBasicBlock::iterator &MBBI, DebugLoc dl, |
| 408 | unsigned DestReg, unsigned BaseReg, int NumBytes, |
| 409 | ARMCC::CondCodes Pred, unsigned PredReg, |
Anton Korobeynikov | e7410dd | 2011-03-05 18:43:32 +0000 | [diff] [blame] | 410 | const ARMBaseInstrInfo &TII, unsigned MIFlags = 0); |
Jim Grosbach | bbdc5d2 | 2010-10-19 23:27:08 +0000 | [diff] [blame] | 411 | void emitThumbRegPlusImmediate(MachineBasicBlock &MBB, |
Anton Korobeynikov | e7410dd | 2011-03-05 18:43:32 +0000 | [diff] [blame] | 412 | MachineBasicBlock::iterator &MBBI, DebugLoc dl, |
Jim Grosbach | bbdc5d2 | 2010-10-19 23:27:08 +0000 | [diff] [blame] | 413 | unsigned DestReg, unsigned BaseReg, |
| 414 | int NumBytes, const TargetInstrInfo &TII, |
| 415 | const ARMBaseRegisterInfo& MRI, |
Anton Korobeynikov | e7410dd | 2011-03-05 18:43:32 +0000 | [diff] [blame] | 416 | unsigned MIFlags = 0); |
Evan Cheng | 780748d | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 417 | |
Tim Northover | 93bcc66 | 2013-11-08 17:18:07 +0000 | [diff] [blame] | 418 | /// Tries to add registers to the reglist of a given base-updating |
| 419 | /// push/pop instruction to adjust the stack by an additional |
| 420 | /// NumBytes. This can save a few bytes per function in code-size, but |
| 421 | /// obviously generates more memory traffic. As such, it only takes |
| 422 | /// effect in functions being optimised for size. |
Tim Northover | dee8604 | 2013-12-02 14:46:26 +0000 | [diff] [blame] | 423 | bool tryFoldSPUpdateIntoPushPop(const ARMSubtarget &Subtarget, |
| 424 | MachineFunction &MF, MachineInstr *MI, |
Tim Northover | 93bcc66 | 2013-11-08 17:18:07 +0000 | [diff] [blame] | 425 | unsigned NumBytes); |
Evan Cheng | 780748d | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 426 | |
Jim Grosbach | f24f9d9 | 2009-08-11 15:33:49 +0000 | [diff] [blame] | 427 | /// rewriteARMFrameIndex / rewriteT2FrameIndex - |
Evan Cheng | 7a37b1a | 2009-08-27 01:23:50 +0000 | [diff] [blame] | 428 | /// Rewrite MI to access 'Offset' bytes from the FP. Return false if the |
| 429 | /// offset could not be handled directly in MI, and return the left-over |
| 430 | /// portion by reference. |
| 431 | bool rewriteARMFrameIndex(MachineInstr &MI, unsigned FrameRegIdx, |
| 432 | unsigned FrameReg, int &Offset, |
| 433 | const ARMBaseInstrInfo &TII); |
Evan Cheng | 780748d | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 434 | |
Evan Cheng | 7a37b1a | 2009-08-27 01:23:50 +0000 | [diff] [blame] | 435 | bool rewriteT2FrameIndex(MachineInstr &MI, unsigned FrameRegIdx, |
| 436 | unsigned FrameReg, int &Offset, |
| 437 | const ARMBaseInstrInfo &TII); |
Evan Cheng | 780748d | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 438 | |
| 439 | } // End llvm namespace |
| 440 | |
David Goodwin | af7451b | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 441 | #endif |