| 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 | |
| David Goodwin | af7451b | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 17 | #include "ARM.h" |
| Anton Korobeynikov | c5df7e2 | 2009-07-16 23:26:06 +0000 | [diff] [blame] | 18 | #include "llvm/CodeGen/MachineInstrBuilder.h" |
| 19 | #include "llvm/Target/TargetInstrInfo.h" |
| Evan Cheng | 62c7b5b | 2010-12-05 22:04:16 +0000 | [diff] [blame] | 20 | #include "llvm/ADT/DenseMap.h" |
| 21 | #include "llvm/ADT/SmallSet.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 | |
| David Goodwin | af7451b | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 45 | virtual MachineInstr *convertToThreeAddress(MachineFunction::iterator &MFI, |
| 46 | MachineBasicBlock::iterator &MBBI, |
| 47 | LiveVariables *LV) const; |
| 48 | |
| 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 * |
| Andrew Trick | 10ffc2b | 2010-12-24 05:03:26 +0000 | [diff] [blame] | 53 | CreateTargetHazardRecognizer(const TargetMachine *TM, |
| 54 | const ScheduleDAG *DAG) const; |
| 55 | |
| 56 | ScheduleHazardRecognizer * |
| 57 | CreateTargetPostRAHazardRecognizer(const InstrItineraryData *II, |
| 58 | const ScheduleDAG *DAG) const; |
| 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. |
| 61 | virtual bool AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB, |
| 62 | MachineBasicBlock *&FBB, |
| 63 | SmallVectorImpl<MachineOperand> &Cond, |
| Chris Lattner | 749ca32 | 2010-07-22 21:27:00 +0000 | [diff] [blame] | 64 | bool AllowModify = false) const; |
| David Goodwin | af7451b | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 65 | virtual unsigned RemoveBranch(MachineBasicBlock &MBB) const; |
| 66 | virtual unsigned InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB, |
| 67 | MachineBasicBlock *FBB, |
| Stuart Hastings | 0125b64 | 2010-06-17 22:43:56 +0000 | [diff] [blame] | 68 | const SmallVectorImpl<MachineOperand> &Cond, |
| 69 | DebugLoc DL) const; |
| David Goodwin | af7451b | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 70 | |
| 71 | virtual |
| 72 | bool ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const; |
| 73 | |
| 74 | // Predication support. |
| Evan Cheng | 7fae11b | 2011-12-14 02:11:42 +0000 | [diff] [blame] | 75 | bool isPredicated(const MachineInstr *MI) const; |
| 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 | |
| 83 | virtual |
| 84 | bool PredicateInstruction(MachineInstr *MI, |
| 85 | const SmallVectorImpl<MachineOperand> &Pred) const; |
| 86 | |
| 87 | virtual |
| 88 | bool SubsumesPredicate(const SmallVectorImpl<MachineOperand> &Pred1, |
| 89 | const SmallVectorImpl<MachineOperand> &Pred2) const; |
| 90 | |
| 91 | virtual bool DefinesPredicate(MachineInstr *MI, |
| 92 | std::vector<MachineOperand> &Pred) const; |
| 93 | |
| Evan Cheng | a33fc86 | 2009-11-21 06:21:52 +0000 | [diff] [blame] | 94 | virtual bool isPredicable(MachineInstr *MI) const; |
| 95 | |
| David Goodwin | af7451b | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 96 | /// GetInstSize - Returns the size of the specified MachineInstr. |
| 97 | /// |
| 98 | virtual unsigned GetInstSizeInBytes(const MachineInstr* MI) const; |
| 99 | |
| David Goodwin | af7451b | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 100 | virtual unsigned isLoadFromStackSlot(const MachineInstr *MI, |
| 101 | int &FrameIndex) const; |
| 102 | virtual unsigned isStoreToStackSlot(const MachineInstr *MI, |
| 103 | int &FrameIndex) const; |
| Jakob Stoklund Olesen | c04a66b | 2011-08-08 21:45:32 +0000 | [diff] [blame] | 104 | virtual unsigned isLoadFromStackSlotPostFE(const MachineInstr *MI, |
| 105 | int &FrameIndex) const; |
| 106 | virtual unsigned isStoreToStackSlotPostFE(const MachineInstr *MI, |
| 107 | int &FrameIndex) const; |
| David Goodwin | af7451b | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 108 | |
| Jakob Stoklund Olesen | d7b3300 | 2010-07-11 06:33:54 +0000 | [diff] [blame] | 109 | virtual void copyPhysReg(MachineBasicBlock &MBB, |
| 110 | MachineBasicBlock::iterator I, DebugLoc DL, |
| 111 | unsigned DestReg, unsigned SrcReg, |
| 112 | bool KillSrc) const; |
| Evan Cheng | c47e109 | 2009-07-27 03:14:20 +0000 | [diff] [blame] | 113 | |
| David Goodwin | af7451b | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 114 | virtual void storeRegToStackSlot(MachineBasicBlock &MBB, |
| 115 | MachineBasicBlock::iterator MBBI, |
| 116 | unsigned SrcReg, bool isKill, int FrameIndex, |
| Evan Cheng | efb126a | 2010-05-06 19:06:44 +0000 | [diff] [blame] | 117 | const TargetRegisterClass *RC, |
| 118 | const TargetRegisterInfo *TRI) const; |
| David Goodwin | af7451b | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 119 | |
| David Goodwin | af7451b | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 120 | virtual void loadRegFromStackSlot(MachineBasicBlock &MBB, |
| 121 | MachineBasicBlock::iterator MBBI, |
| 122 | unsigned DestReg, int FrameIndex, |
| Evan Cheng | efb126a | 2010-05-06 19:06:44 +0000 | [diff] [blame] | 123 | const TargetRegisterClass *RC, |
| 124 | const TargetRegisterInfo *TRI) const; |
| David Goodwin | af7451b | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 125 | |
| Jakob Stoklund Olesen | da7c0f8 | 2011-10-11 00:59:06 +0000 | [diff] [blame] | 126 | virtual bool expandPostRAPseudo(MachineBasicBlock::iterator MI) const; |
| 127 | |
| Evan Cheng | bcb99ecc | 2010-04-26 07:39:25 +0000 | [diff] [blame] | 128 | virtual MachineInstr *emitFrameIndexDebugValue(MachineFunction &MF, |
| Evan Cheng | 250e917 | 2010-04-29 01:13:30 +0000 | [diff] [blame] | 129 | int FrameIx, |
| Evan Cheng | bcb99ecc | 2010-04-26 07:39:25 +0000 | [diff] [blame] | 130 | uint64_t Offset, |
| 131 | const MDNode *MDPtr, |
| 132 | DebugLoc DL) const; |
| 133 | |
| Evan Cheng | fe86442 | 2009-11-08 00:15:23 +0000 | [diff] [blame] | 134 | virtual void reMaterialize(MachineBasicBlock &MBB, |
| 135 | MachineBasicBlock::iterator MI, |
| 136 | unsigned DestReg, unsigned SubIdx, |
| Evan Cheng | 6ad7da9 | 2009-11-14 02:55:43 +0000 | [diff] [blame] | 137 | const MachineInstr *Orig, |
| Jakob Stoklund Olesen | a8ad977 | 2010-06-02 22:47:25 +0000 | [diff] [blame] | 138 | const TargetRegisterInfo &TRI) const; |
| Evan Cheng | fe86442 | 2009-11-08 00:15:23 +0000 | [diff] [blame] | 139 | |
| Jakob Stoklund Olesen | 29a64c9 | 2010-01-06 23:47:07 +0000 | [diff] [blame] | 140 | MachineInstr *duplicate(MachineInstr *Orig, MachineFunction &MF) const; |
| 141 | |
| Jakob Stoklund Olesen | 0a5b72f | 2012-04-04 18:23:42 +0000 | [diff] [blame^] | 142 | MachineInstr *commuteInstruction(MachineInstr*, bool=false) const; |
| 143 | |
| Evan Cheng | e9c46c2 | 2010-03-03 01:44:33 +0000 | [diff] [blame] | 144 | virtual bool produceSameValue(const MachineInstr *MI0, |
| Evan Cheng | b8b0ad8 | 2011-01-20 08:34:58 +0000 | [diff] [blame] | 145 | const MachineInstr *MI1, |
| 146 | const MachineRegisterInfo *MRI) const; |
| Evan Cheng | 2d51c7c | 2010-06-18 23:09:54 +0000 | [diff] [blame] | 147 | |
| Bill Wendling | f470747 | 2010-06-23 23:00:16 +0000 | [diff] [blame] | 148 | /// areLoadsFromSameBasePtr - This is used by the pre-regalloc scheduler to |
| 149 | /// determine if two loads are loading from the same base address. It should |
| 150 | /// only return true if the base pointers are the same and the only |
| 151 | /// differences between the two addresses is the offset. It also returns the |
| 152 | /// offsets by reference. |
| 153 | virtual bool areLoadsFromSameBasePtr(SDNode *Load1, SDNode *Load2, |
| 154 | int64_t &Offset1, int64_t &Offset2)const; |
| 155 | |
| 156 | /// shouldScheduleLoadsNear - This is a used by the pre-regalloc scheduler to |
| Jim Grosbach | 7ef7ddd | 2011-06-13 22:54:22 +0000 | [diff] [blame] | 157 | /// determine (in conjunction with areLoadsFromSameBasePtr) if two loads |
| 158 | /// 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] | 159 | /// addresses in the same cache line, it's better if they are scheduled |
| 160 | /// together. This function takes two integers that represent the load offsets |
| 161 | /// from the common base address. It returns true if it decides it's desirable |
| 162 | /// to schedule the two loads together. "NumLoads" is the number of loads that |
| 163 | /// have already been scheduled after Load1. |
| 164 | virtual bool shouldScheduleLoadsNear(SDNode *Load1, SDNode *Load2, |
| 165 | int64_t Offset1, int64_t Offset2, |
| 166 | unsigned NumLoads) const; |
| 167 | |
| Evan Cheng | 2d51c7c | 2010-06-18 23:09:54 +0000 | [diff] [blame] | 168 | virtual bool isSchedulingBoundary(const MachineInstr *MI, |
| 169 | const MachineBasicBlock *MBB, |
| 170 | const MachineFunction &MF) const; |
| Evan Cheng | 02b184d | 2010-06-25 22:42:03 +0000 | [diff] [blame] | 171 | |
| 172 | virtual bool isProfitableToIfCvt(MachineBasicBlock &MBB, |
| Cameron Zwarich | 8001850 | 2011-04-13 06:39:16 +0000 | [diff] [blame] | 173 | unsigned NumCycles, unsigned ExtraPredCycles, |
| Jakub Staszak | 9b07c0a | 2011-07-10 02:58:07 +0000 | [diff] [blame] | 174 | const BranchProbability &Probability) const; |
| Evan Cheng | 02b184d | 2010-06-25 22:42:03 +0000 | [diff] [blame] | 175 | |
| Evan Cheng | debf9c5 | 2010-11-03 00:45:17 +0000 | [diff] [blame] | 176 | virtual bool isProfitableToIfCvt(MachineBasicBlock &TMBB, |
| 177 | unsigned NumT, unsigned ExtraT, |
| 178 | MachineBasicBlock &FMBB, |
| 179 | unsigned NumF, unsigned ExtraF, |
| Jakub Staszak | 9b07c0a | 2011-07-10 02:58:07 +0000 | [diff] [blame] | 180 | const BranchProbability &Probability) const; |
| Evan Cheng | 02b184d | 2010-06-25 22:42:03 +0000 | [diff] [blame] | 181 | |
| 182 | virtual bool isProfitableToDupForIfCvt(MachineBasicBlock &MBB, |
| Cameron Zwarich | 8001850 | 2011-04-13 06:39:16 +0000 | [diff] [blame] | 183 | unsigned NumCycles, |
| Jakub Staszak | 9b07c0a | 2011-07-10 02:58:07 +0000 | [diff] [blame] | 184 | const BranchProbability |
| 185 | &Probability) const { |
| Cameron Zwarich | 8001850 | 2011-04-13 06:39:16 +0000 | [diff] [blame] | 186 | return NumCycles == 1; |
| Evan Cheng | 02b184d | 2010-06-25 22:42:03 +0000 | [diff] [blame] | 187 | } |
| Bill Wendling | 7de9d52 | 2010-08-06 01:32:48 +0000 | [diff] [blame] | 188 | |
| Bill Wendling | 798617b | 2010-08-08 05:04:59 +0000 | [diff] [blame] | 189 | /// AnalyzeCompare - For a comparison instruction, return the source register |
| 190 | /// in SrcReg and the value it compares against in CmpValue. Return true if |
| 191 | /// the comparison instruction can be analyzed. |
| 192 | virtual bool AnalyzeCompare(const MachineInstr *MI, unsigned &SrcReg, |
| Gabor Greif | adbbb93 | 2010-09-21 12:01:15 +0000 | [diff] [blame] | 193 | int &CmpMask, int &CmpValue) const; |
| Bill Wendling | 7de9d52 | 2010-08-06 01:32:48 +0000 | [diff] [blame] | 194 | |
| Bill Wendling | 27dddd1 | 2010-09-11 00:13:50 +0000 | [diff] [blame] | 195 | /// OptimizeCompareInstr - Convert the instruction to set the zero flag so |
| Bill Wendling | 7de9d52 | 2010-08-06 01:32:48 +0000 | [diff] [blame] | 196 | /// that we can remove a "comparison with zero". |
| Bill Wendling | 27dddd1 | 2010-09-11 00:13:50 +0000 | [diff] [blame] | 197 | virtual bool OptimizeCompareInstr(MachineInstr *CmpInstr, unsigned SrcReg, |
| Gabor Greif | adbbb93 | 2010-09-21 12:01:15 +0000 | [diff] [blame] | 198 | int CmpMask, int CmpValue, |
| Evan Cheng | 2ce016c | 2010-11-15 21:20:45 +0000 | [diff] [blame] | 199 | const MachineRegisterInfo *MRI) const; |
| Evan Cheng | 367a5df | 2010-09-09 18:18:55 +0000 | [diff] [blame] | 200 | |
| Evan Cheng | 7f8ab6e | 2010-11-17 20:13:28 +0000 | [diff] [blame] | 201 | /// FoldImmediate - 'Reg' is known to be defined by a move immediate |
| 202 | /// instruction, try to fold the immediate into the use instruction. |
| 203 | virtual bool FoldImmediate(MachineInstr *UseMI, MachineInstr *DefMI, |
| 204 | unsigned Reg, MachineRegisterInfo *MRI) const; |
| 205 | |
| Evan Cheng | debf9c5 | 2010-11-03 00:45:17 +0000 | [diff] [blame] | 206 | virtual unsigned getNumMicroOps(const InstrItineraryData *ItinData, |
| 207 | const MachineInstr *MI) const; |
| Evan Cheng | 49d4c0b | 2010-10-06 06:27:31 +0000 | [diff] [blame] | 208 | |
| 209 | virtual |
| 210 | int getOperandLatency(const InstrItineraryData *ItinData, |
| 211 | const MachineInstr *DefMI, unsigned DefIdx, |
| 212 | const MachineInstr *UseMI, unsigned UseIdx) const; |
| 213 | virtual |
| 214 | int getOperandLatency(const InstrItineraryData *ItinData, |
| 215 | SDNode *DefNode, unsigned DefIdx, |
| 216 | SDNode *UseNode, unsigned UseIdx) const; |
| Jakob Stoklund Olesen | f9b71a2 | 2011-09-27 22:57:21 +0000 | [diff] [blame] | 217 | |
| Evan Cheng | da103bf | 2011-12-14 20:00:08 +0000 | [diff] [blame] | 218 | virtual unsigned getOutputLatency(const InstrItineraryData *ItinData, |
| 219 | const MachineInstr *DefMI, unsigned DefIdx, |
| 220 | const MachineInstr *DepMI) const; |
| 221 | |
| Jakob Stoklund Olesen | f9b71a2 | 2011-09-27 22:57:21 +0000 | [diff] [blame] | 222 | /// VFP/NEON execution domains. |
| 223 | std::pair<uint16_t, uint16_t> |
| 224 | getExecutionDomain(const MachineInstr *MI) const; |
| 225 | void setExecutionDomain(MachineInstr *MI, unsigned Domain) const; |
| 226 | |
| Evan Cheng | 49d4c0b | 2010-10-06 06:27:31 +0000 | [diff] [blame] | 227 | private: |
| Evan Cheng | 7fae11b | 2011-12-14 02:11:42 +0000 | [diff] [blame] | 228 | unsigned getInstBundleLength(const MachineInstr *MI) const; |
| 229 | |
| Evan Cheng | 412e37b | 2010-10-07 23:12:15 +0000 | [diff] [blame] | 230 | int getVLDMDefCycle(const InstrItineraryData *ItinData, |
| Evan Cheng | 6cc775f | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 231 | const MCInstrDesc &DefMCID, |
| Evan Cheng | 412e37b | 2010-10-07 23:12:15 +0000 | [diff] [blame] | 232 | unsigned DefClass, |
| 233 | unsigned DefIdx, unsigned DefAlign) const; |
| 234 | int getLDMDefCycle(const InstrItineraryData *ItinData, |
| Evan Cheng | 6cc775f | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 235 | const MCInstrDesc &DefMCID, |
| Evan Cheng | 412e37b | 2010-10-07 23:12:15 +0000 | [diff] [blame] | 236 | unsigned DefClass, |
| 237 | unsigned DefIdx, unsigned DefAlign) const; |
| 238 | int getVSTMUseCycle(const InstrItineraryData *ItinData, |
| Evan Cheng | 6cc775f | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 239 | const MCInstrDesc &UseMCID, |
| Evan Cheng | 412e37b | 2010-10-07 23:12:15 +0000 | [diff] [blame] | 240 | unsigned UseClass, |
| 241 | unsigned UseIdx, unsigned UseAlign) const; |
| 242 | int getSTMUseCycle(const InstrItineraryData *ItinData, |
| Evan Cheng | 6cc775f | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 243 | const MCInstrDesc &UseMCID, |
| Evan Cheng | 412e37b | 2010-10-07 23:12:15 +0000 | [diff] [blame] | 244 | unsigned UseClass, |
| 245 | unsigned UseIdx, unsigned UseAlign) const; |
| Evan Cheng | 49d4c0b | 2010-10-06 06:27:31 +0000 | [diff] [blame] | 246 | int getOperandLatency(const InstrItineraryData *ItinData, |
| Evan Cheng | 6cc775f | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 247 | const MCInstrDesc &DefMCID, |
| Evan Cheng | 49d4c0b | 2010-10-06 06:27:31 +0000 | [diff] [blame] | 248 | unsigned DefIdx, unsigned DefAlign, |
| Evan Cheng | 6cc775f | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 249 | const MCInstrDesc &UseMCID, |
| Evan Cheng | 49d4c0b | 2010-10-06 06:27:31 +0000 | [diff] [blame] | 250 | unsigned UseIdx, unsigned UseAlign) const; |
| Evan Cheng | 63c7608 | 2010-10-19 18:58:51 +0000 | [diff] [blame] | 251 | |
| Evan Cheng | debf9c5 | 2010-11-03 00:45:17 +0000 | [diff] [blame] | 252 | int getInstrLatency(const InstrItineraryData *ItinData, |
| 253 | const MachineInstr *MI, unsigned *PredCost = 0) const; |
| 254 | |
| 255 | int getInstrLatency(const InstrItineraryData *ItinData, |
| 256 | SDNode *Node) const; |
| 257 | |
| Evan Cheng | 63c7608 | 2010-10-19 18:58:51 +0000 | [diff] [blame] | 258 | bool hasHighOperandLatency(const InstrItineraryData *ItinData, |
| 259 | const MachineRegisterInfo *MRI, |
| 260 | const MachineInstr *DefMI, unsigned DefIdx, |
| 261 | const MachineInstr *UseMI, unsigned UseIdx) const; |
| Evan Cheng | e96b8d7 | 2010-10-26 02:08:50 +0000 | [diff] [blame] | 262 | bool hasLowDefLatency(const InstrItineraryData *ItinData, |
| 263 | const MachineInstr *DefMI, unsigned DefIdx) const; |
| Evan Cheng | 62c7b5b | 2010-12-05 22:04:16 +0000 | [diff] [blame] | 264 | |
| Andrew Trick | 924123a | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 265 | /// verifyInstruction - Perform target specific instruction verification. |
| 266 | bool verifyInstruction(const MachineInstr *MI, StringRef &ErrInfo) const; |
| 267 | |
| Evan Cheng | 62c7b5b | 2010-12-05 22:04:16 +0000 | [diff] [blame] | 268 | private: |
| 269 | /// Modeling special VFP / NEON fp MLA / MLS hazards. |
| 270 | |
| 271 | /// MLxEntryMap - Map fp MLA / MLS to the corresponding entry in the internal |
| 272 | /// MLx table. |
| 273 | DenseMap<unsigned, unsigned> MLxEntryMap; |
| 274 | |
| 275 | /// MLxHazardOpcodes - Set of add / sub and multiply opcodes that would cause |
| 276 | /// stalls when scheduled together with fp MLA / MLS opcodes. |
| 277 | SmallSet<unsigned, 16> MLxHazardOpcodes; |
| 278 | |
| 279 | public: |
| 280 | /// isFpMLxInstruction - Return true if the specified opcode is a fp MLA / MLS |
| 281 | /// instruction. |
| 282 | bool isFpMLxInstruction(unsigned Opcode) const { |
| 283 | return MLxEntryMap.count(Opcode); |
| 284 | } |
| 285 | |
| 286 | /// isFpMLxInstruction - This version also returns the multiply opcode and the |
| 287 | /// addition / subtraction opcode to expand to. Return true for 'HasLane' for |
| 288 | /// the MLX instructions with an extra lane operand. |
| 289 | bool isFpMLxInstruction(unsigned Opcode, unsigned &MulOpc, |
| 290 | unsigned &AddSubOpc, bool &NegAcc, |
| 291 | bool &HasLane) const; |
| 292 | |
| 293 | /// canCauseFpMLxStall - Return true if an instruction of the specified opcode |
| 294 | /// will cause stalls when scheduled after (within 4-cycle window) a fp |
| 295 | /// MLA / MLS instruction. |
| 296 | bool canCauseFpMLxStall(unsigned Opcode) const { |
| 297 | return MLxHazardOpcodes.count(Opcode); |
| 298 | } |
| David Goodwin | af7451b | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 299 | }; |
| Evan Cheng | 780748d | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 300 | |
| 301 | static inline |
| 302 | const MachineInstrBuilder &AddDefaultPred(const MachineInstrBuilder &MIB) { |
| 303 | return MIB.addImm((int64_t)ARMCC::AL).addReg(0); |
| David Goodwin | af7451b | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 304 | } |
| 305 | |
| Evan Cheng | 780748d | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 306 | static inline |
| 307 | const MachineInstrBuilder &AddDefaultCC(const MachineInstrBuilder &MIB) { |
| 308 | return MIB.addReg(0); |
| 309 | } |
| 310 | |
| 311 | static inline |
| Evan Cheng | 51cbd2d | 2009-08-10 02:37:24 +0000 | [diff] [blame] | 312 | const MachineInstrBuilder &AddDefaultT1CC(const MachineInstrBuilder &MIB, |
| 313 | bool isDead = false) { |
| 314 | return MIB.addReg(ARM::CPSR, getDefRegState(true) | getDeadRegState(isDead)); |
| Evan Cheng | 780748d | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 315 | } |
| 316 | |
| 317 | static inline |
| Evan Cheng | 6ddd7bc | 2009-08-15 07:59:10 +0000 | [diff] [blame] | 318 | const MachineInstrBuilder &AddNoT1CC(const MachineInstrBuilder &MIB) { |
| 319 | return MIB.addReg(0); |
| 320 | } |
| 321 | |
| 322 | static inline |
| Evan Cheng | 780748d | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 323 | bool isUncondBranchOpcode(int Opc) { |
| 324 | return Opc == ARM::B || Opc == ARM::tB || Opc == ARM::t2B; |
| 325 | } |
| 326 | |
| 327 | static inline |
| 328 | bool isCondBranchOpcode(int Opc) { |
| 329 | return Opc == ARM::Bcc || Opc == ARM::tBcc || Opc == ARM::t2Bcc; |
| 330 | } |
| 331 | |
| 332 | static inline |
| 333 | bool isJumpTableBranchOpcode(int Opc) { |
| 334 | return Opc == ARM::BR_JTr || Opc == ARM::BR_JTm || Opc == ARM::BR_JTadd || |
| 335 | Opc == ARM::tBR_JTr || Opc == ARM::t2BR_JT; |
| 336 | } |
| 337 | |
| Bob Wilson | 73789b8 | 2009-10-28 18:26:41 +0000 | [diff] [blame] | 338 | static inline |
| 339 | bool isIndirectBranchOpcode(int Opc) { |
| Bill Wendling | 8294a30 | 2010-11-30 00:48:15 +0000 | [diff] [blame] | 340 | return Opc == ARM::BX || Opc == ARM::MOVPCRX || Opc == ARM::tBRIND; |
| Bob Wilson | 73789b8 | 2009-10-28 18:26:41 +0000 | [diff] [blame] | 341 | } |
| 342 | |
| Evan Cheng | 2aa91cc | 2009-08-08 03:20:32 +0000 | [diff] [blame] | 343 | /// getInstrPredicate - If instruction is predicated, returns its predicate |
| 344 | /// condition, otherwise returns AL. It also returns the condition code |
| 345 | /// register by reference. |
| Evan Cheng | 83e0d48 | 2009-09-28 09:14:39 +0000 | [diff] [blame] | 346 | ARMCC::CondCodes getInstrPredicate(const MachineInstr *MI, unsigned &PredReg); |
| Evan Cheng | 2aa91cc | 2009-08-08 03:20:32 +0000 | [diff] [blame] | 347 | |
| Evan Cheng | 780748d | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 348 | int getMatchingCondBranchOpcode(int Opc); |
| 349 | |
| Andrew Trick | 924123a | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 350 | |
| 351 | /// Map pseudo instructions that imply an 'S' bit onto real opcodes. Whether |
| 352 | /// the instruction is encoded with an 'S' bit is determined by the optional |
| 353 | /// CPSR def operand. |
| 354 | unsigned convertAddSubFlagsOpcode(unsigned OldOpc); |
| 355 | |
| Evan Cheng | 780748d | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 356 | /// emitARMRegPlusImmediate / emitT2RegPlusImmediate - Emits a series of |
| 357 | /// instructions to materializea destreg = basereg + immediate in ARM / Thumb2 |
| 358 | /// code. |
| 359 | void emitARMRegPlusImmediate(MachineBasicBlock &MBB, |
| 360 | MachineBasicBlock::iterator &MBBI, DebugLoc dl, |
| 361 | unsigned DestReg, unsigned BaseReg, int NumBytes, |
| 362 | ARMCC::CondCodes Pred, unsigned PredReg, |
| Anton Korobeynikov | e7410dd | 2011-03-05 18:43:32 +0000 | [diff] [blame] | 363 | const ARMBaseInstrInfo &TII, unsigned MIFlags = 0); |
| Evan Cheng | 780748d | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 364 | |
| 365 | void emitT2RegPlusImmediate(MachineBasicBlock &MBB, |
| 366 | MachineBasicBlock::iterator &MBBI, DebugLoc dl, |
| 367 | unsigned DestReg, unsigned BaseReg, int NumBytes, |
| 368 | ARMCC::CondCodes Pred, unsigned PredReg, |
| Anton Korobeynikov | e7410dd | 2011-03-05 18:43:32 +0000 | [diff] [blame] | 369 | const ARMBaseInstrInfo &TII, unsigned MIFlags = 0); |
| Jim Grosbach | bbdc5d2 | 2010-10-19 23:27:08 +0000 | [diff] [blame] | 370 | void emitThumbRegPlusImmediate(MachineBasicBlock &MBB, |
| Anton Korobeynikov | e7410dd | 2011-03-05 18:43:32 +0000 | [diff] [blame] | 371 | MachineBasicBlock::iterator &MBBI, DebugLoc dl, |
| Jim Grosbach | bbdc5d2 | 2010-10-19 23:27:08 +0000 | [diff] [blame] | 372 | unsigned DestReg, unsigned BaseReg, |
| 373 | int NumBytes, const TargetInstrInfo &TII, |
| 374 | const ARMBaseRegisterInfo& MRI, |
| Anton Korobeynikov | e7410dd | 2011-03-05 18:43:32 +0000 | [diff] [blame] | 375 | unsigned MIFlags = 0); |
| Evan Cheng | 780748d | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 376 | |
| 377 | |
| Jim Grosbach | f24f9d9 | 2009-08-11 15:33:49 +0000 | [diff] [blame] | 378 | /// rewriteARMFrameIndex / rewriteT2FrameIndex - |
| Evan Cheng | 7a37b1a | 2009-08-27 01:23:50 +0000 | [diff] [blame] | 379 | /// Rewrite MI to access 'Offset' bytes from the FP. Return false if the |
| 380 | /// offset could not be handled directly in MI, and return the left-over |
| 381 | /// portion by reference. |
| 382 | bool rewriteARMFrameIndex(MachineInstr &MI, unsigned FrameRegIdx, |
| 383 | unsigned FrameReg, int &Offset, |
| 384 | const ARMBaseInstrInfo &TII); |
| Evan Cheng | 780748d | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 385 | |
| Evan Cheng | 7a37b1a | 2009-08-27 01:23:50 +0000 | [diff] [blame] | 386 | bool rewriteT2FrameIndex(MachineInstr &MI, unsigned FrameRegIdx, |
| 387 | unsigned FrameReg, int &Offset, |
| 388 | const ARMBaseInstrInfo &TII); |
| Evan Cheng | 780748d | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 389 | |
| 390 | } // End llvm namespace |
| 391 | |
| David Goodwin | af7451b | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 392 | #endif |