Jia Liu | 31d157a | 2012-02-18 12:03:15 +0000 | [diff] [blame^] | 1 | //===-- ARMBaseInstrInfo.h - ARM Base Instruction Information ---*- C++ -*-===// |
David Goodwin | 334c264 | 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 | |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 17 | #include "ARM.h" |
Anton Korobeynikov | b8e9ac8 | 2009-07-16 23:26:06 +0000 | [diff] [blame] | 18 | #include "llvm/CodeGen/MachineInstrBuilder.h" |
| 19 | #include "llvm/Target/TargetInstrInfo.h" |
Evan Cheng | 48575f6 | 2010-12-05 22:04:16 +0000 | [diff] [blame] | 20 | #include "llvm/ADT/DenseMap.h" |
| 21 | #include "llvm/ADT/SmallSet.h" |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 22 | |
Evan Cheng | 4db3cff | 2011-07-01 17:57:27 +0000 | [diff] [blame] | 23 | #define GET_INSTRINFO_HEADER |
| 24 | #include "ARMGenInstrInfo.inc" |
| 25 | |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 26 | namespace llvm { |
Chris Lattner | 4dbbe34 | 2010-07-20 21:17:29 +0000 | [diff] [blame] | 27 | class ARMSubtarget; |
| 28 | class ARMBaseRegisterInfo; |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 29 | |
Evan Cheng | 4db3cff | 2011-07-01 17:57:27 +0000 | [diff] [blame] | 30 | class ARMBaseInstrInfo : public ARMGenInstrInfo { |
Chris Lattner | 4dbbe34 | 2010-07-20 21:17:29 +0000 | [diff] [blame] | 31 | const ARMSubtarget &Subtarget; |
Evan Cheng | 48575f6 | 2010-12-05 22:04:16 +0000 | [diff] [blame] | 32 | |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 33 | protected: |
| 34 | // Can be only subclassed. |
Anton Korobeynikov | f95215f | 2009-11-02 00:10:38 +0000 | [diff] [blame] | 35 | explicit ARMBaseInstrInfo(const ARMSubtarget &STI); |
Evan Cheng | 48575f6 | 2010-12-05 22:04:16 +0000 | [diff] [blame] | 36 | |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 37 | public: |
| 38 | // Return the non-pre/post incrementing version of 'Opc'. Return 0 |
| 39 | // if there is not such an opcode. |
| 40 | virtual unsigned getUnindexedOpcode(unsigned Opc) const =0; |
| 41 | |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 42 | virtual MachineInstr *convertToThreeAddress(MachineFunction::iterator &MFI, |
| 43 | MachineBasicBlock::iterator &MBBI, |
| 44 | LiveVariables *LV) const; |
| 45 | |
| 46 | virtual const ARMBaseRegisterInfo &getRegisterInfo() const =0; |
Anton Korobeynikov | f95215f | 2009-11-02 00:10:38 +0000 | [diff] [blame] | 47 | const ARMSubtarget &getSubtarget() const { return Subtarget; } |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 48 | |
Evan Cheng | 48575f6 | 2010-12-05 22:04:16 +0000 | [diff] [blame] | 49 | ScheduleHazardRecognizer * |
Andrew Trick | 2da8bc8 | 2010-12-24 05:03:26 +0000 | [diff] [blame] | 50 | CreateTargetHazardRecognizer(const TargetMachine *TM, |
| 51 | const ScheduleDAG *DAG) const; |
| 52 | |
| 53 | ScheduleHazardRecognizer * |
| 54 | CreateTargetPostRAHazardRecognizer(const InstrItineraryData *II, |
| 55 | const ScheduleDAG *DAG) const; |
Evan Cheng | 48575f6 | 2010-12-05 22:04:16 +0000 | [diff] [blame] | 56 | |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 57 | // Branch analysis. |
| 58 | virtual bool AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB, |
| 59 | MachineBasicBlock *&FBB, |
| 60 | SmallVectorImpl<MachineOperand> &Cond, |
Chris Lattner | 2062875 | 2010-07-22 21:27:00 +0000 | [diff] [blame] | 61 | bool AllowModify = false) const; |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 62 | virtual unsigned RemoveBranch(MachineBasicBlock &MBB) const; |
| 63 | virtual unsigned InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB, |
| 64 | MachineBasicBlock *FBB, |
Stuart Hastings | 3bf9125 | 2010-06-17 22:43:56 +0000 | [diff] [blame] | 65 | const SmallVectorImpl<MachineOperand> &Cond, |
| 66 | DebugLoc DL) const; |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 67 | |
| 68 | virtual |
| 69 | bool ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const; |
| 70 | |
| 71 | // Predication support. |
Evan Cheng | ddfd137 | 2011-12-14 02:11:42 +0000 | [diff] [blame] | 72 | bool isPredicated(const MachineInstr *MI) const; |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 73 | |
| 74 | ARMCC::CondCodes getPredicate(const MachineInstr *MI) const { |
| 75 | int PIdx = MI->findFirstPredOperandIdx(); |
| 76 | return PIdx != -1 ? (ARMCC::CondCodes)MI->getOperand(PIdx).getImm() |
| 77 | : ARMCC::AL; |
| 78 | } |
| 79 | |
| 80 | virtual |
| 81 | bool PredicateInstruction(MachineInstr *MI, |
| 82 | const SmallVectorImpl<MachineOperand> &Pred) const; |
| 83 | |
| 84 | virtual |
| 85 | bool SubsumesPredicate(const SmallVectorImpl<MachineOperand> &Pred1, |
| 86 | const SmallVectorImpl<MachineOperand> &Pred2) const; |
| 87 | |
| 88 | virtual bool DefinesPredicate(MachineInstr *MI, |
| 89 | std::vector<MachineOperand> &Pred) const; |
| 90 | |
Evan Cheng | ac0869d | 2009-11-21 06:21:52 +0000 | [diff] [blame] | 91 | virtual bool isPredicable(MachineInstr *MI) const; |
| 92 | |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 93 | /// GetInstSize - Returns the size of the specified MachineInstr. |
| 94 | /// |
| 95 | virtual unsigned GetInstSizeInBytes(const MachineInstr* MI) const; |
| 96 | |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 97 | virtual unsigned isLoadFromStackSlot(const MachineInstr *MI, |
| 98 | int &FrameIndex) const; |
| 99 | virtual unsigned isStoreToStackSlot(const MachineInstr *MI, |
| 100 | int &FrameIndex) const; |
Jakob Stoklund Olesen | 36ee0e6 | 2011-08-08 21:45:32 +0000 | [diff] [blame] | 101 | virtual unsigned isLoadFromStackSlotPostFE(const MachineInstr *MI, |
| 102 | int &FrameIndex) const; |
| 103 | virtual unsigned isStoreToStackSlotPostFE(const MachineInstr *MI, |
| 104 | int &FrameIndex) const; |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 105 | |
Jakob Stoklund Olesen | ac27366 | 2010-07-11 06:33:54 +0000 | [diff] [blame] | 106 | virtual void copyPhysReg(MachineBasicBlock &MBB, |
| 107 | MachineBasicBlock::iterator I, DebugLoc DL, |
| 108 | unsigned DestReg, unsigned SrcReg, |
| 109 | bool KillSrc) const; |
Evan Cheng | 5732ca0 | 2009-07-27 03:14:20 +0000 | [diff] [blame] | 110 | |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 111 | virtual void storeRegToStackSlot(MachineBasicBlock &MBB, |
| 112 | MachineBasicBlock::iterator MBBI, |
| 113 | unsigned SrcReg, bool isKill, int FrameIndex, |
Evan Cheng | 746ad69 | 2010-05-06 19:06:44 +0000 | [diff] [blame] | 114 | const TargetRegisterClass *RC, |
| 115 | const TargetRegisterInfo *TRI) const; |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 116 | |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 117 | virtual void loadRegFromStackSlot(MachineBasicBlock &MBB, |
| 118 | MachineBasicBlock::iterator MBBI, |
| 119 | unsigned DestReg, int FrameIndex, |
Evan Cheng | 746ad69 | 2010-05-06 19:06:44 +0000 | [diff] [blame] | 120 | const TargetRegisterClass *RC, |
| 121 | const TargetRegisterInfo *TRI) const; |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 122 | |
Jakob Stoklund Olesen | 142bd1a | 2011-10-11 00:59:06 +0000 | [diff] [blame] | 123 | virtual bool expandPostRAPseudo(MachineBasicBlock::iterator MI) const; |
| 124 | |
Evan Cheng | 62b5065 | 2010-04-26 07:39:25 +0000 | [diff] [blame] | 125 | virtual MachineInstr *emitFrameIndexDebugValue(MachineFunction &MF, |
Evan Cheng | 8601a3d | 2010-04-29 01:13:30 +0000 | [diff] [blame] | 126 | int FrameIx, |
Evan Cheng | 62b5065 | 2010-04-26 07:39:25 +0000 | [diff] [blame] | 127 | uint64_t Offset, |
| 128 | const MDNode *MDPtr, |
| 129 | DebugLoc DL) const; |
| 130 | |
Evan Cheng | fdc8340 | 2009-11-08 00:15:23 +0000 | [diff] [blame] | 131 | virtual void reMaterialize(MachineBasicBlock &MBB, |
| 132 | MachineBasicBlock::iterator MI, |
| 133 | unsigned DestReg, unsigned SubIdx, |
Evan Cheng | d57cdd5 | 2009-11-14 02:55:43 +0000 | [diff] [blame] | 134 | const MachineInstr *Orig, |
Jakob Stoklund Olesen | 9edf7de | 2010-06-02 22:47:25 +0000 | [diff] [blame] | 135 | const TargetRegisterInfo &TRI) const; |
Evan Cheng | fdc8340 | 2009-11-08 00:15:23 +0000 | [diff] [blame] | 136 | |
Jakob Stoklund Olesen | 30ac046 | 2010-01-06 23:47:07 +0000 | [diff] [blame] | 137 | MachineInstr *duplicate(MachineInstr *Orig, MachineFunction &MF) const; |
| 138 | |
Evan Cheng | 506049f | 2010-03-03 01:44:33 +0000 | [diff] [blame] | 139 | virtual bool produceSameValue(const MachineInstr *MI0, |
Evan Cheng | 9fe2009 | 2011-01-20 08:34:58 +0000 | [diff] [blame] | 140 | const MachineInstr *MI1, |
| 141 | const MachineRegisterInfo *MRI) const; |
Evan Cheng | 86050dc | 2010-06-18 23:09:54 +0000 | [diff] [blame] | 142 | |
Bill Wendling | 4b72210 | 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. |
| 148 | virtual bool areLoadsFromSameBasePtr(SDNode *Load1, SDNode *Load2, |
| 149 | int64_t &Offset1, int64_t &Offset2)const; |
| 150 | |
| 151 | /// shouldScheduleLoadsNear - This is a used by the pre-regalloc scheduler to |
Jim Grosbach | f921c0fe | 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 | 4b72210 | 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. |
| 159 | virtual bool shouldScheduleLoadsNear(SDNode *Load1, SDNode *Load2, |
| 160 | int64_t Offset1, int64_t Offset2, |
| 161 | unsigned NumLoads) const; |
| 162 | |
Evan Cheng | 86050dc | 2010-06-18 23:09:54 +0000 | [diff] [blame] | 163 | virtual bool isSchedulingBoundary(const MachineInstr *MI, |
| 164 | const MachineBasicBlock *MBB, |
| 165 | const MachineFunction &MF) const; |
Evan Cheng | 1315143 | 2010-06-25 22:42:03 +0000 | [diff] [blame] | 166 | |
| 167 | virtual bool isProfitableToIfCvt(MachineBasicBlock &MBB, |
Cameron Zwarich | 5876db7 | 2011-04-13 06:39:16 +0000 | [diff] [blame] | 168 | unsigned NumCycles, unsigned ExtraPredCycles, |
Jakub Staszak | f81b7f6 | 2011-07-10 02:58:07 +0000 | [diff] [blame] | 169 | const BranchProbability &Probability) const; |
Evan Cheng | 1315143 | 2010-06-25 22:42:03 +0000 | [diff] [blame] | 170 | |
Evan Cheng | 8239daf | 2010-11-03 00:45:17 +0000 | [diff] [blame] | 171 | virtual bool isProfitableToIfCvt(MachineBasicBlock &TMBB, |
| 172 | unsigned NumT, unsigned ExtraT, |
| 173 | MachineBasicBlock &FMBB, |
| 174 | unsigned NumF, unsigned ExtraF, |
Jakub Staszak | f81b7f6 | 2011-07-10 02:58:07 +0000 | [diff] [blame] | 175 | const BranchProbability &Probability) const; |
Evan Cheng | 1315143 | 2010-06-25 22:42:03 +0000 | [diff] [blame] | 176 | |
| 177 | virtual bool isProfitableToDupForIfCvt(MachineBasicBlock &MBB, |
Cameron Zwarich | 5876db7 | 2011-04-13 06:39:16 +0000 | [diff] [blame] | 178 | unsigned NumCycles, |
Jakub Staszak | f81b7f6 | 2011-07-10 02:58:07 +0000 | [diff] [blame] | 179 | const BranchProbability |
| 180 | &Probability) const { |
Cameron Zwarich | 5876db7 | 2011-04-13 06:39:16 +0000 | [diff] [blame] | 181 | return NumCycles == 1; |
Evan Cheng | 1315143 | 2010-06-25 22:42:03 +0000 | [diff] [blame] | 182 | } |
Bill Wendling | e4ddbdf | 2010-08-06 01:32:48 +0000 | [diff] [blame] | 183 | |
Bill Wendling | c98af33 | 2010-08-08 05:04:59 +0000 | [diff] [blame] | 184 | /// AnalyzeCompare - For a comparison instruction, return the source register |
| 185 | /// in SrcReg and the value it compares against in CmpValue. Return true if |
| 186 | /// the comparison instruction can be analyzed. |
| 187 | virtual bool AnalyzeCompare(const MachineInstr *MI, unsigned &SrcReg, |
Gabor Greif | 04ac81d | 2010-09-21 12:01:15 +0000 | [diff] [blame] | 188 | int &CmpMask, int &CmpValue) const; |
Bill Wendling | e4ddbdf | 2010-08-06 01:32:48 +0000 | [diff] [blame] | 189 | |
Bill Wendling | a655686 | 2010-09-11 00:13:50 +0000 | [diff] [blame] | 190 | /// OptimizeCompareInstr - Convert the instruction to set the zero flag so |
Bill Wendling | e4ddbdf | 2010-08-06 01:32:48 +0000 | [diff] [blame] | 191 | /// that we can remove a "comparison with zero". |
Bill Wendling | a655686 | 2010-09-11 00:13:50 +0000 | [diff] [blame] | 192 | virtual bool OptimizeCompareInstr(MachineInstr *CmpInstr, unsigned SrcReg, |
Gabor Greif | 04ac81d | 2010-09-21 12:01:15 +0000 | [diff] [blame] | 193 | int CmpMask, int CmpValue, |
Evan Cheng | eb96a2f | 2010-11-15 21:20:45 +0000 | [diff] [blame] | 194 | const MachineRegisterInfo *MRI) const; |
Evan Cheng | 5f54ce3 | 2010-09-09 18:18:55 +0000 | [diff] [blame] | 195 | |
Evan Cheng | c4af463 | 2010-11-17 20:13:28 +0000 | [diff] [blame] | 196 | /// FoldImmediate - 'Reg' is known to be defined by a move immediate |
| 197 | /// instruction, try to fold the immediate into the use instruction. |
| 198 | virtual bool FoldImmediate(MachineInstr *UseMI, MachineInstr *DefMI, |
| 199 | unsigned Reg, MachineRegisterInfo *MRI) const; |
| 200 | |
Evan Cheng | 8239daf | 2010-11-03 00:45:17 +0000 | [diff] [blame] | 201 | virtual unsigned getNumMicroOps(const InstrItineraryData *ItinData, |
| 202 | const MachineInstr *MI) const; |
Evan Cheng | a0792de | 2010-10-06 06:27:31 +0000 | [diff] [blame] | 203 | |
| 204 | virtual |
| 205 | int getOperandLatency(const InstrItineraryData *ItinData, |
| 206 | const MachineInstr *DefMI, unsigned DefIdx, |
| 207 | const MachineInstr *UseMI, unsigned UseIdx) const; |
| 208 | virtual |
| 209 | int getOperandLatency(const InstrItineraryData *ItinData, |
| 210 | SDNode *DefNode, unsigned DefIdx, |
| 211 | SDNode *UseNode, unsigned UseIdx) const; |
Jakob Stoklund Olesen | 13fd601 | 2011-09-27 22:57:21 +0000 | [diff] [blame] | 212 | |
Evan Cheng | 020f410 | 2011-12-14 20:00:08 +0000 | [diff] [blame] | 213 | virtual unsigned getOutputLatency(const InstrItineraryData *ItinData, |
| 214 | const MachineInstr *DefMI, unsigned DefIdx, |
| 215 | const MachineInstr *DepMI) const; |
| 216 | |
Jakob Stoklund Olesen | 13fd601 | 2011-09-27 22:57:21 +0000 | [diff] [blame] | 217 | /// VFP/NEON execution domains. |
| 218 | std::pair<uint16_t, uint16_t> |
| 219 | getExecutionDomain(const MachineInstr *MI) const; |
| 220 | void setExecutionDomain(MachineInstr *MI, unsigned Domain) const; |
| 221 | |
Evan Cheng | a0792de | 2010-10-06 06:27:31 +0000 | [diff] [blame] | 222 | private: |
Evan Cheng | ddfd137 | 2011-12-14 02:11:42 +0000 | [diff] [blame] | 223 | unsigned getInstBundleLength(const MachineInstr *MI) const; |
| 224 | |
Evan Cheng | 344d9db | 2010-10-07 23:12:15 +0000 | [diff] [blame] | 225 | int getVLDMDefCycle(const InstrItineraryData *ItinData, |
Evan Cheng | e837dea | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 226 | const MCInstrDesc &DefMCID, |
Evan Cheng | 344d9db | 2010-10-07 23:12:15 +0000 | [diff] [blame] | 227 | unsigned DefClass, |
| 228 | unsigned DefIdx, unsigned DefAlign) const; |
| 229 | int getLDMDefCycle(const InstrItineraryData *ItinData, |
Evan Cheng | e837dea | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 230 | const MCInstrDesc &DefMCID, |
Evan Cheng | 344d9db | 2010-10-07 23:12:15 +0000 | [diff] [blame] | 231 | unsigned DefClass, |
| 232 | unsigned DefIdx, unsigned DefAlign) const; |
| 233 | int getVSTMUseCycle(const InstrItineraryData *ItinData, |
Evan Cheng | e837dea | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 234 | const MCInstrDesc &UseMCID, |
Evan Cheng | 344d9db | 2010-10-07 23:12:15 +0000 | [diff] [blame] | 235 | unsigned UseClass, |
| 236 | unsigned UseIdx, unsigned UseAlign) const; |
| 237 | int getSTMUseCycle(const InstrItineraryData *ItinData, |
Evan Cheng | e837dea | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 238 | const MCInstrDesc &UseMCID, |
Evan Cheng | 344d9db | 2010-10-07 23:12:15 +0000 | [diff] [blame] | 239 | unsigned UseClass, |
| 240 | unsigned UseIdx, unsigned UseAlign) const; |
Evan Cheng | a0792de | 2010-10-06 06:27:31 +0000 | [diff] [blame] | 241 | int getOperandLatency(const InstrItineraryData *ItinData, |
Evan Cheng | e837dea | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 242 | const MCInstrDesc &DefMCID, |
Evan Cheng | a0792de | 2010-10-06 06:27:31 +0000 | [diff] [blame] | 243 | unsigned DefIdx, unsigned DefAlign, |
Evan Cheng | e837dea | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 244 | const MCInstrDesc &UseMCID, |
Evan Cheng | a0792de | 2010-10-06 06:27:31 +0000 | [diff] [blame] | 245 | unsigned UseIdx, unsigned UseAlign) const; |
Evan Cheng | 2312842 | 2010-10-19 18:58:51 +0000 | [diff] [blame] | 246 | |
Evan Cheng | 8239daf | 2010-11-03 00:45:17 +0000 | [diff] [blame] | 247 | int getInstrLatency(const InstrItineraryData *ItinData, |
| 248 | const MachineInstr *MI, unsigned *PredCost = 0) const; |
| 249 | |
| 250 | int getInstrLatency(const InstrItineraryData *ItinData, |
| 251 | SDNode *Node) const; |
| 252 | |
Evan Cheng | 2312842 | 2010-10-19 18:58:51 +0000 | [diff] [blame] | 253 | bool hasHighOperandLatency(const InstrItineraryData *ItinData, |
| 254 | const MachineRegisterInfo *MRI, |
| 255 | const MachineInstr *DefMI, unsigned DefIdx, |
| 256 | const MachineInstr *UseMI, unsigned UseIdx) const; |
Evan Cheng | c8141df | 2010-10-26 02:08:50 +0000 | [diff] [blame] | 257 | bool hasLowDefLatency(const InstrItineraryData *ItinData, |
| 258 | const MachineInstr *DefMI, unsigned DefIdx) const; |
Evan Cheng | 48575f6 | 2010-12-05 22:04:16 +0000 | [diff] [blame] | 259 | |
Andrew Trick | 3be654f | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 260 | /// verifyInstruction - Perform target specific instruction verification. |
| 261 | bool verifyInstruction(const MachineInstr *MI, StringRef &ErrInfo) const; |
| 262 | |
Evan Cheng | 48575f6 | 2010-12-05 22:04:16 +0000 | [diff] [blame] | 263 | private: |
| 264 | /// Modeling special VFP / NEON fp MLA / MLS hazards. |
| 265 | |
| 266 | /// MLxEntryMap - Map fp MLA / MLS to the corresponding entry in the internal |
| 267 | /// MLx table. |
| 268 | DenseMap<unsigned, unsigned> MLxEntryMap; |
| 269 | |
| 270 | /// MLxHazardOpcodes - Set of add / sub and multiply opcodes that would cause |
| 271 | /// stalls when scheduled together with fp MLA / MLS opcodes. |
| 272 | SmallSet<unsigned, 16> MLxHazardOpcodes; |
| 273 | |
| 274 | public: |
| 275 | /// isFpMLxInstruction - Return true if the specified opcode is a fp MLA / MLS |
| 276 | /// instruction. |
| 277 | bool isFpMLxInstruction(unsigned Opcode) const { |
| 278 | return MLxEntryMap.count(Opcode); |
| 279 | } |
| 280 | |
| 281 | /// isFpMLxInstruction - This version also returns the multiply opcode and the |
| 282 | /// addition / subtraction opcode to expand to. Return true for 'HasLane' for |
| 283 | /// the MLX instructions with an extra lane operand. |
| 284 | bool isFpMLxInstruction(unsigned Opcode, unsigned &MulOpc, |
| 285 | unsigned &AddSubOpc, bool &NegAcc, |
| 286 | bool &HasLane) const; |
| 287 | |
| 288 | /// canCauseFpMLxStall - Return true if an instruction of the specified opcode |
| 289 | /// will cause stalls when scheduled after (within 4-cycle window) a fp |
| 290 | /// MLA / MLS instruction. |
| 291 | bool canCauseFpMLxStall(unsigned Opcode) const { |
| 292 | return MLxHazardOpcodes.count(Opcode); |
| 293 | } |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 294 | }; |
Evan Cheng | 6495f63 | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 295 | |
| 296 | static inline |
| 297 | const MachineInstrBuilder &AddDefaultPred(const MachineInstrBuilder &MIB) { |
| 298 | return MIB.addImm((int64_t)ARMCC::AL).addReg(0); |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 299 | } |
| 300 | |
Evan Cheng | 6495f63 | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 301 | static inline |
| 302 | const MachineInstrBuilder &AddDefaultCC(const MachineInstrBuilder &MIB) { |
| 303 | return MIB.addReg(0); |
| 304 | } |
| 305 | |
| 306 | static inline |
Evan Cheng | e8af1f9 | 2009-08-10 02:37:24 +0000 | [diff] [blame] | 307 | const MachineInstrBuilder &AddDefaultT1CC(const MachineInstrBuilder &MIB, |
| 308 | bool isDead = false) { |
| 309 | return MIB.addReg(ARM::CPSR, getDefRegState(true) | getDeadRegState(isDead)); |
Evan Cheng | 6495f63 | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 310 | } |
| 311 | |
| 312 | static inline |
Evan Cheng | bc9b754 | 2009-08-15 07:59:10 +0000 | [diff] [blame] | 313 | const MachineInstrBuilder &AddNoT1CC(const MachineInstrBuilder &MIB) { |
| 314 | return MIB.addReg(0); |
| 315 | } |
| 316 | |
| 317 | static inline |
Evan Cheng | 6495f63 | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 318 | bool isUncondBranchOpcode(int Opc) { |
| 319 | return Opc == ARM::B || Opc == ARM::tB || Opc == ARM::t2B; |
| 320 | } |
| 321 | |
| 322 | static inline |
| 323 | bool isCondBranchOpcode(int Opc) { |
| 324 | return Opc == ARM::Bcc || Opc == ARM::tBcc || Opc == ARM::t2Bcc; |
| 325 | } |
| 326 | |
| 327 | static inline |
| 328 | bool isJumpTableBranchOpcode(int Opc) { |
| 329 | return Opc == ARM::BR_JTr || Opc == ARM::BR_JTm || Opc == ARM::BR_JTadd || |
| 330 | Opc == ARM::tBR_JTr || Opc == ARM::t2BR_JT; |
| 331 | } |
| 332 | |
Bob Wilson | 8d4de5a | 2009-10-28 18:26:41 +0000 | [diff] [blame] | 333 | static inline |
| 334 | bool isIndirectBranchOpcode(int Opc) { |
Bill Wendling | 6e46d84 | 2010-11-30 00:48:15 +0000 | [diff] [blame] | 335 | return Opc == ARM::BX || Opc == ARM::MOVPCRX || Opc == ARM::tBRIND; |
Bob Wilson | 8d4de5a | 2009-10-28 18:26:41 +0000 | [diff] [blame] | 336 | } |
| 337 | |
Evan Cheng | 8fb9036 | 2009-08-08 03:20:32 +0000 | [diff] [blame] | 338 | /// getInstrPredicate - If instruction is predicated, returns its predicate |
| 339 | /// condition, otherwise returns AL. It also returns the condition code |
| 340 | /// register by reference. |
Evan Cheng | 5adb66a | 2009-09-28 09:14:39 +0000 | [diff] [blame] | 341 | ARMCC::CondCodes getInstrPredicate(const MachineInstr *MI, unsigned &PredReg); |
Evan Cheng | 8fb9036 | 2009-08-08 03:20:32 +0000 | [diff] [blame] | 342 | |
Evan Cheng | 6495f63 | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 343 | int getMatchingCondBranchOpcode(int Opc); |
| 344 | |
Andrew Trick | 3be654f | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 345 | |
| 346 | /// Map pseudo instructions that imply an 'S' bit onto real opcodes. Whether |
| 347 | /// the instruction is encoded with an 'S' bit is determined by the optional |
| 348 | /// CPSR def operand. |
| 349 | unsigned convertAddSubFlagsOpcode(unsigned OldOpc); |
| 350 | |
Evan Cheng | 6495f63 | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 351 | /// emitARMRegPlusImmediate / emitT2RegPlusImmediate - Emits a series of |
| 352 | /// instructions to materializea destreg = basereg + immediate in ARM / Thumb2 |
| 353 | /// code. |
| 354 | void emitARMRegPlusImmediate(MachineBasicBlock &MBB, |
| 355 | MachineBasicBlock::iterator &MBBI, DebugLoc dl, |
| 356 | unsigned DestReg, unsigned BaseReg, int NumBytes, |
| 357 | ARMCC::CondCodes Pred, unsigned PredReg, |
Anton Korobeynikov | 57caad7 | 2011-03-05 18:43:32 +0000 | [diff] [blame] | 358 | const ARMBaseInstrInfo &TII, unsigned MIFlags = 0); |
Evan Cheng | 6495f63 | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 359 | |
| 360 | void emitT2RegPlusImmediate(MachineBasicBlock &MBB, |
| 361 | MachineBasicBlock::iterator &MBBI, DebugLoc dl, |
| 362 | unsigned DestReg, unsigned BaseReg, int NumBytes, |
| 363 | ARMCC::CondCodes Pred, unsigned PredReg, |
Anton Korobeynikov | 57caad7 | 2011-03-05 18:43:32 +0000 | [diff] [blame] | 364 | const ARMBaseInstrInfo &TII, unsigned MIFlags = 0); |
Jim Grosbach | e4ad387 | 2010-10-19 23:27:08 +0000 | [diff] [blame] | 365 | void emitThumbRegPlusImmediate(MachineBasicBlock &MBB, |
Anton Korobeynikov | 57caad7 | 2011-03-05 18:43:32 +0000 | [diff] [blame] | 366 | MachineBasicBlock::iterator &MBBI, DebugLoc dl, |
Jim Grosbach | e4ad387 | 2010-10-19 23:27:08 +0000 | [diff] [blame] | 367 | unsigned DestReg, unsigned BaseReg, |
| 368 | int NumBytes, const TargetInstrInfo &TII, |
| 369 | const ARMBaseRegisterInfo& MRI, |
Anton Korobeynikov | 57caad7 | 2011-03-05 18:43:32 +0000 | [diff] [blame] | 370 | unsigned MIFlags = 0); |
Evan Cheng | 6495f63 | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 371 | |
| 372 | |
Jim Grosbach | 764ab52 | 2009-08-11 15:33:49 +0000 | [diff] [blame] | 373 | /// rewriteARMFrameIndex / rewriteT2FrameIndex - |
Evan Cheng | cdbb3f5 | 2009-08-27 01:23:50 +0000 | [diff] [blame] | 374 | /// Rewrite MI to access 'Offset' bytes from the FP. Return false if the |
| 375 | /// offset could not be handled directly in MI, and return the left-over |
| 376 | /// portion by reference. |
| 377 | bool rewriteARMFrameIndex(MachineInstr &MI, unsigned FrameRegIdx, |
| 378 | unsigned FrameReg, int &Offset, |
| 379 | const ARMBaseInstrInfo &TII); |
Evan Cheng | 6495f63 | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 380 | |
Evan Cheng | cdbb3f5 | 2009-08-27 01:23:50 +0000 | [diff] [blame] | 381 | bool rewriteT2FrameIndex(MachineInstr &MI, unsigned FrameRegIdx, |
| 382 | unsigned FrameReg, int &Offset, |
| 383 | const ARMBaseInstrInfo &TII); |
Evan Cheng | 6495f63 | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 384 | |
| 385 | } // End llvm namespace |
| 386 | |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 387 | #endif |