Jim Grosbach | 31c24bf | 2009-11-07 22:00:39 +0000 | [diff] [blame] | 1 | //===- ARMBaseInstrInfo.cpp - ARM 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 | #include "ARMBaseInstrInfo.h" |
| 15 | #include "ARM.h" |
| 16 | #include "ARMAddressingModes.h" |
Evan Cheng | d457e6e | 2009-11-07 04:04:34 +0000 | [diff] [blame] | 17 | #include "ARMConstantPoolValue.h" |
Evan Cheng | 48575f6 | 2010-12-05 22:04:16 +0000 | [diff] [blame] | 18 | #include "ARMHazardRecognizer.h" |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 19 | #include "ARMMachineFunctionInfo.h" |
Anton Korobeynikov | f95215f | 2009-11-02 00:10:38 +0000 | [diff] [blame] | 20 | #include "ARMRegisterInfo.h" |
Chris Lattner | 4dbbe34 | 2010-07-20 21:17:29 +0000 | [diff] [blame] | 21 | #include "ARMGenInstrInfo.inc" |
Evan Cheng | fdc8340 | 2009-11-08 00:15:23 +0000 | [diff] [blame] | 22 | #include "llvm/Constants.h" |
| 23 | #include "llvm/Function.h" |
| 24 | #include "llvm/GlobalValue.h" |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 25 | #include "llvm/CodeGen/LiveVariables.h" |
Evan Cheng | d457e6e | 2009-11-07 04:04:34 +0000 | [diff] [blame] | 26 | #include "llvm/CodeGen/MachineConstantPool.h" |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 27 | #include "llvm/CodeGen/MachineFrameInfo.h" |
| 28 | #include "llvm/CodeGen/MachineInstrBuilder.h" |
| 29 | #include "llvm/CodeGen/MachineJumpTableInfo.h" |
Anton Korobeynikov | 249fb33 | 2009-10-07 00:06:35 +0000 | [diff] [blame] | 30 | #include "llvm/CodeGen/MachineMemOperand.h" |
Evan Cheng | 2457f2c | 2010-05-22 01:47:14 +0000 | [diff] [blame] | 31 | #include "llvm/CodeGen/MachineRegisterInfo.h" |
Anton Korobeynikov | 249fb33 | 2009-10-07 00:06:35 +0000 | [diff] [blame] | 32 | #include "llvm/CodeGen/PseudoSourceValue.h" |
Chris Lattner | af76e59 | 2009-08-22 20:48:53 +0000 | [diff] [blame] | 33 | #include "llvm/MC/MCAsmInfo.h" |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 34 | #include "llvm/Support/CommandLine.h" |
Anton Korobeynikov | f95215f | 2009-11-02 00:10:38 +0000 | [diff] [blame] | 35 | #include "llvm/Support/Debug.h" |
Torok Edwin | c25e758 | 2009-07-11 20:10:48 +0000 | [diff] [blame] | 36 | #include "llvm/Support/ErrorHandling.h" |
Bill Wendling | 40a5eb1 | 2010-11-01 20:41:43 +0000 | [diff] [blame] | 37 | #include "llvm/ADT/STLExtras.h" |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 38 | using namespace llvm; |
| 39 | |
| 40 | static cl::opt<bool> |
| 41 | EnableARM3Addr("enable-arm-3-addr-conv", cl::Hidden, |
| 42 | cl::desc("Enable ARM 2-addr to 3-addr conv")); |
| 43 | |
Andrew Trick | 2da8bc8 | 2010-12-24 05:03:26 +0000 | [diff] [blame] | 44 | // Other targets already have a hazard recognizer enabled by default, so this |
| 45 | // flag currently only affects ARM. It will be generalized when it becomes a |
| 46 | // disabled flag. |
| 47 | static cl::opt<bool> EnableHazardRecognizer( |
| 48 | "enable-sched-hazard", cl::Hidden, |
| 49 | cl::desc("Enable hazard detection during preRA scheduling"), |
| 50 | cl::init(false)); |
Evan Cheng | 48575f6 | 2010-12-05 22:04:16 +0000 | [diff] [blame] | 51 | |
| 52 | /// ARM_MLxEntry - Record information about MLA / MLS instructions. |
| 53 | struct ARM_MLxEntry { |
| 54 | unsigned MLxOpc; // MLA / MLS opcode |
| 55 | unsigned MulOpc; // Expanded multiplication opcode |
| 56 | unsigned AddSubOpc; // Expanded add / sub opcode |
| 57 | bool NegAcc; // True if the acc is negated before the add / sub. |
| 58 | bool HasLane; // True if instruction has an extra "lane" operand. |
| 59 | }; |
| 60 | |
| 61 | static const ARM_MLxEntry ARM_MLxTable[] = { |
| 62 | // MLxOpc, MulOpc, AddSubOpc, NegAcc, HasLane |
| 63 | // fp scalar ops |
| 64 | { ARM::VMLAS, ARM::VMULS, ARM::VADDS, false, false }, |
| 65 | { ARM::VMLSS, ARM::VMULS, ARM::VSUBS, false, false }, |
| 66 | { ARM::VMLAD, ARM::VMULD, ARM::VADDD, false, false }, |
| 67 | { ARM::VMLSD, ARM::VMULD, ARM::VSUBD, false, false }, |
Evan Cheng | 48575f6 | 2010-12-05 22:04:16 +0000 | [diff] [blame] | 68 | { ARM::VNMLAS, ARM::VNMULS, ARM::VSUBS, true, false }, |
| 69 | { ARM::VNMLSS, ARM::VMULS, ARM::VSUBS, true, false }, |
| 70 | { ARM::VNMLAD, ARM::VNMULD, ARM::VSUBD, true, false }, |
| 71 | { ARM::VNMLSD, ARM::VMULD, ARM::VSUBD, true, false }, |
| 72 | |
| 73 | // fp SIMD ops |
| 74 | { ARM::VMLAfd, ARM::VMULfd, ARM::VADDfd, false, false }, |
| 75 | { ARM::VMLSfd, ARM::VMULfd, ARM::VSUBfd, false, false }, |
| 76 | { ARM::VMLAfq, ARM::VMULfq, ARM::VADDfq, false, false }, |
| 77 | { ARM::VMLSfq, ARM::VMULfq, ARM::VSUBfq, false, false }, |
| 78 | { ARM::VMLAslfd, ARM::VMULslfd, ARM::VADDfd, false, true }, |
| 79 | { ARM::VMLSslfd, ARM::VMULslfd, ARM::VSUBfd, false, true }, |
| 80 | { ARM::VMLAslfq, ARM::VMULslfq, ARM::VADDfq, false, true }, |
| 81 | { ARM::VMLSslfq, ARM::VMULslfq, ARM::VSUBfq, false, true }, |
| 82 | }; |
| 83 | |
Anton Korobeynikov | f95215f | 2009-11-02 00:10:38 +0000 | [diff] [blame] | 84 | ARMBaseInstrInfo::ARMBaseInstrInfo(const ARMSubtarget& STI) |
| 85 | : TargetInstrInfoImpl(ARMInsts, array_lengthof(ARMInsts)), |
| 86 | Subtarget(STI) { |
Evan Cheng | 48575f6 | 2010-12-05 22:04:16 +0000 | [diff] [blame] | 87 | for (unsigned i = 0, e = array_lengthof(ARM_MLxTable); i != e; ++i) { |
| 88 | if (!MLxEntryMap.insert(std::make_pair(ARM_MLxTable[i].MLxOpc, i)).second) |
| 89 | assert(false && "Duplicated entries?"); |
| 90 | MLxHazardOpcodes.insert(ARM_MLxTable[i].AddSubOpc); |
| 91 | MLxHazardOpcodes.insert(ARM_MLxTable[i].MulOpc); |
| 92 | } |
| 93 | } |
| 94 | |
Andrew Trick | 2da8bc8 | 2010-12-24 05:03:26 +0000 | [diff] [blame] | 95 | // Use a ScoreboardHazardRecognizer for prepass ARM scheduling. TargetInstrImpl |
| 96 | // currently defaults to no prepass hazard recognizer. |
Evan Cheng | 48575f6 | 2010-12-05 22:04:16 +0000 | [diff] [blame] | 97 | ScheduleHazardRecognizer *ARMBaseInstrInfo:: |
Andrew Trick | 2da8bc8 | 2010-12-24 05:03:26 +0000 | [diff] [blame] | 98 | CreateTargetHazardRecognizer(const TargetMachine *TM, |
| 99 | const ScheduleDAG *DAG) const { |
| 100 | if (EnableHazardRecognizer) { |
| 101 | const InstrItineraryData *II = TM->getInstrItineraryData(); |
| 102 | return new ScoreboardHazardRecognizer(II, DAG, "pre-RA-sched"); |
| 103 | } |
| 104 | return TargetInstrInfoImpl::CreateTargetHazardRecognizer(TM, DAG); |
| 105 | } |
| 106 | |
| 107 | ScheduleHazardRecognizer *ARMBaseInstrInfo:: |
| 108 | CreateTargetPostRAHazardRecognizer(const InstrItineraryData *II, |
| 109 | const ScheduleDAG *DAG) const { |
Evan Cheng | 48575f6 | 2010-12-05 22:04:16 +0000 | [diff] [blame] | 110 | if (Subtarget.isThumb2() || Subtarget.hasVFP2()) |
| 111 | return (ScheduleHazardRecognizer *) |
Andrew Trick | 2da8bc8 | 2010-12-24 05:03:26 +0000 | [diff] [blame] | 112 | new ARMHazardRecognizer(II, *this, getRegisterInfo(), Subtarget, DAG); |
| 113 | return TargetInstrInfoImpl::CreateTargetPostRAHazardRecognizer(II, DAG); |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | MachineInstr * |
| 117 | ARMBaseInstrInfo::convertToThreeAddress(MachineFunction::iterator &MFI, |
| 118 | MachineBasicBlock::iterator &MBBI, |
| 119 | LiveVariables *LV) const { |
Evan Cheng | 78703dd | 2009-07-27 18:44:00 +0000 | [diff] [blame] | 120 | // FIXME: Thumb2 support. |
| 121 | |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 122 | if (!EnableARM3Addr) |
| 123 | return NULL; |
| 124 | |
| 125 | MachineInstr *MI = MBBI; |
| 126 | MachineFunction &MF = *MI->getParent()->getParent(); |
Bruno Cardoso Lopes | 99405df | 2010-06-08 22:51:23 +0000 | [diff] [blame] | 127 | uint64_t TSFlags = MI->getDesc().TSFlags; |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 128 | bool isPre = false; |
| 129 | switch ((TSFlags & ARMII::IndexModeMask) >> ARMII::IndexModeShift) { |
| 130 | default: return NULL; |
| 131 | case ARMII::IndexModePre: |
| 132 | isPre = true; |
| 133 | break; |
| 134 | case ARMII::IndexModePost: |
| 135 | break; |
| 136 | } |
| 137 | |
| 138 | // Try splitting an indexed load/store to an un-indexed one plus an add/sub |
| 139 | // operation. |
| 140 | unsigned MemOpc = getUnindexedOpcode(MI->getOpcode()); |
| 141 | if (MemOpc == 0) |
| 142 | return NULL; |
| 143 | |
| 144 | MachineInstr *UpdateMI = NULL; |
| 145 | MachineInstr *MemMI = NULL; |
| 146 | unsigned AddrMode = (TSFlags & ARMII::AddrModeMask); |
| 147 | const TargetInstrDesc &TID = MI->getDesc(); |
| 148 | unsigned NumOps = TID.getNumOperands(); |
| 149 | bool isLoad = !TID.mayStore(); |
| 150 | const MachineOperand &WB = isLoad ? MI->getOperand(1) : MI->getOperand(0); |
| 151 | const MachineOperand &Base = MI->getOperand(2); |
| 152 | const MachineOperand &Offset = MI->getOperand(NumOps-3); |
| 153 | unsigned WBReg = WB.getReg(); |
| 154 | unsigned BaseReg = Base.getReg(); |
| 155 | unsigned OffReg = Offset.getReg(); |
| 156 | unsigned OffImm = MI->getOperand(NumOps-2).getImm(); |
| 157 | ARMCC::CondCodes Pred = (ARMCC::CondCodes)MI->getOperand(NumOps-1).getImm(); |
| 158 | switch (AddrMode) { |
| 159 | default: |
| 160 | assert(false && "Unknown indexed op!"); |
| 161 | return NULL; |
| 162 | case ARMII::AddrMode2: { |
| 163 | bool isSub = ARM_AM::getAM2Op(OffImm) == ARM_AM::sub; |
| 164 | unsigned Amt = ARM_AM::getAM2Offset(OffImm); |
| 165 | if (OffReg == 0) { |
Evan Cheng | e7cbe41 | 2009-07-08 21:03:57 +0000 | [diff] [blame] | 166 | if (ARM_AM::getSOImmVal(Amt) == -1) |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 167 | // Can't encode it in a so_imm operand. This transformation will |
| 168 | // add more than 1 instruction. Abandon! |
| 169 | return NULL; |
| 170 | UpdateMI = BuildMI(MF, MI->getDebugLoc(), |
Evan Cheng | 78703dd | 2009-07-27 18:44:00 +0000 | [diff] [blame] | 171 | get(isSub ? ARM::SUBri : ARM::ADDri), WBReg) |
Evan Cheng | e7cbe41 | 2009-07-08 21:03:57 +0000 | [diff] [blame] | 172 | .addReg(BaseReg).addImm(Amt) |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 173 | .addImm(Pred).addReg(0).addReg(0); |
| 174 | } else if (Amt != 0) { |
| 175 | ARM_AM::ShiftOpc ShOpc = ARM_AM::getAM2ShiftOpc(OffImm); |
| 176 | unsigned SOOpc = ARM_AM::getSORegOpc(ShOpc, Amt); |
| 177 | UpdateMI = BuildMI(MF, MI->getDebugLoc(), |
Evan Cheng | 78703dd | 2009-07-27 18:44:00 +0000 | [diff] [blame] | 178 | get(isSub ? ARM::SUBrs : ARM::ADDrs), WBReg) |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 179 | .addReg(BaseReg).addReg(OffReg).addReg(0).addImm(SOOpc) |
| 180 | .addImm(Pred).addReg(0).addReg(0); |
| 181 | } else |
| 182 | UpdateMI = BuildMI(MF, MI->getDebugLoc(), |
Evan Cheng | 78703dd | 2009-07-27 18:44:00 +0000 | [diff] [blame] | 183 | get(isSub ? ARM::SUBrr : ARM::ADDrr), WBReg) |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 184 | .addReg(BaseReg).addReg(OffReg) |
| 185 | .addImm(Pred).addReg(0).addReg(0); |
| 186 | break; |
| 187 | } |
| 188 | case ARMII::AddrMode3 : { |
| 189 | bool isSub = ARM_AM::getAM3Op(OffImm) == ARM_AM::sub; |
| 190 | unsigned Amt = ARM_AM::getAM3Offset(OffImm); |
| 191 | if (OffReg == 0) |
| 192 | // Immediate is 8-bits. It's guaranteed to fit in a so_imm operand. |
| 193 | UpdateMI = BuildMI(MF, MI->getDebugLoc(), |
Evan Cheng | 78703dd | 2009-07-27 18:44:00 +0000 | [diff] [blame] | 194 | get(isSub ? ARM::SUBri : ARM::ADDri), WBReg) |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 195 | .addReg(BaseReg).addImm(Amt) |
| 196 | .addImm(Pred).addReg(0).addReg(0); |
| 197 | else |
| 198 | UpdateMI = BuildMI(MF, MI->getDebugLoc(), |
Evan Cheng | 78703dd | 2009-07-27 18:44:00 +0000 | [diff] [blame] | 199 | get(isSub ? ARM::SUBrr : ARM::ADDrr), WBReg) |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 200 | .addReg(BaseReg).addReg(OffReg) |
| 201 | .addImm(Pred).addReg(0).addReg(0); |
| 202 | break; |
| 203 | } |
| 204 | } |
| 205 | |
| 206 | std::vector<MachineInstr*> NewMIs; |
| 207 | if (isPre) { |
| 208 | if (isLoad) |
| 209 | MemMI = BuildMI(MF, MI->getDebugLoc(), |
| 210 | get(MemOpc), MI->getOperand(0).getReg()) |
Jim Grosbach | 3e55612 | 2010-10-26 22:37:02 +0000 | [diff] [blame] | 211 | .addReg(WBReg).addImm(0).addImm(Pred); |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 212 | else |
| 213 | MemMI = BuildMI(MF, MI->getDebugLoc(), |
| 214 | get(MemOpc)).addReg(MI->getOperand(1).getReg()) |
| 215 | .addReg(WBReg).addReg(0).addImm(0).addImm(Pred); |
| 216 | NewMIs.push_back(MemMI); |
| 217 | NewMIs.push_back(UpdateMI); |
| 218 | } else { |
| 219 | if (isLoad) |
| 220 | MemMI = BuildMI(MF, MI->getDebugLoc(), |
| 221 | get(MemOpc), MI->getOperand(0).getReg()) |
Jim Grosbach | 3e55612 | 2010-10-26 22:37:02 +0000 | [diff] [blame] | 222 | .addReg(BaseReg).addImm(0).addImm(Pred); |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 223 | else |
| 224 | MemMI = BuildMI(MF, MI->getDebugLoc(), |
| 225 | get(MemOpc)).addReg(MI->getOperand(1).getReg()) |
| 226 | .addReg(BaseReg).addReg(0).addImm(0).addImm(Pred); |
| 227 | if (WB.isDead()) |
| 228 | UpdateMI->getOperand(0).setIsDead(); |
| 229 | NewMIs.push_back(UpdateMI); |
| 230 | NewMIs.push_back(MemMI); |
| 231 | } |
| 232 | |
| 233 | // Transfer LiveVariables states, kill / dead info. |
| 234 | if (LV) { |
| 235 | for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) { |
| 236 | MachineOperand &MO = MI->getOperand(i); |
Jakob Stoklund Olesen | c9df025 | 2011-01-10 02:58:51 +0000 | [diff] [blame^] | 237 | if (MO.isReg() && TargetRegisterInfo::isVirtualRegister(MO.getReg())) { |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 238 | unsigned Reg = MO.getReg(); |
| 239 | |
| 240 | LiveVariables::VarInfo &VI = LV->getVarInfo(Reg); |
| 241 | if (MO.isDef()) { |
| 242 | MachineInstr *NewMI = (Reg == WBReg) ? UpdateMI : MemMI; |
| 243 | if (MO.isDead()) |
| 244 | LV->addVirtualRegisterDead(Reg, NewMI); |
| 245 | } |
| 246 | if (MO.isUse() && MO.isKill()) { |
| 247 | for (unsigned j = 0; j < 2; ++j) { |
| 248 | // Look at the two new MI's in reverse order. |
| 249 | MachineInstr *NewMI = NewMIs[j]; |
| 250 | if (!NewMI->readsRegister(Reg)) |
| 251 | continue; |
| 252 | LV->addVirtualRegisterKilled(Reg, NewMI); |
| 253 | if (VI.removeKill(MI)) |
| 254 | VI.Kills.push_back(NewMI); |
| 255 | break; |
| 256 | } |
| 257 | } |
| 258 | } |
| 259 | } |
| 260 | } |
| 261 | |
| 262 | MFI->insert(MBBI, NewMIs[1]); |
| 263 | MFI->insert(MBBI, NewMIs[0]); |
| 264 | return NewMIs[0]; |
| 265 | } |
| 266 | |
| 267 | // Branch analysis. |
| 268 | bool |
| 269 | ARMBaseInstrInfo::AnalyzeBranch(MachineBasicBlock &MBB,MachineBasicBlock *&TBB, |
| 270 | MachineBasicBlock *&FBB, |
| 271 | SmallVectorImpl<MachineOperand> &Cond, |
| 272 | bool AllowModify) const { |
| 273 | // If the block has no terminators, it just falls into the block after it. |
| 274 | MachineBasicBlock::iterator I = MBB.end(); |
Dale Johannesen | 93d6a7e | 2010-04-02 01:38:09 +0000 | [diff] [blame] | 275 | if (I == MBB.begin()) |
| 276 | return false; |
| 277 | --I; |
| 278 | while (I->isDebugValue()) { |
| 279 | if (I == MBB.begin()) |
| 280 | return false; |
| 281 | --I; |
| 282 | } |
| 283 | if (!isUnpredicatedTerminator(I)) |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 284 | return false; |
| 285 | |
| 286 | // Get the last instruction in the block. |
| 287 | MachineInstr *LastInst = I; |
| 288 | |
| 289 | // If there is only one terminator instruction, process it. |
| 290 | unsigned LastOpc = LastInst->getOpcode(); |
| 291 | if (I == MBB.begin() || !isUnpredicatedTerminator(--I)) { |
Evan Cheng | 5ca53a7 | 2009-07-27 18:20:05 +0000 | [diff] [blame] | 292 | if (isUncondBranchOpcode(LastOpc)) { |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 293 | TBB = LastInst->getOperand(0).getMBB(); |
| 294 | return false; |
| 295 | } |
Evan Cheng | 5ca53a7 | 2009-07-27 18:20:05 +0000 | [diff] [blame] | 296 | if (isCondBranchOpcode(LastOpc)) { |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 297 | // Block ends with fall-through condbranch. |
| 298 | TBB = LastInst->getOperand(0).getMBB(); |
| 299 | Cond.push_back(LastInst->getOperand(1)); |
| 300 | Cond.push_back(LastInst->getOperand(2)); |
| 301 | return false; |
| 302 | } |
| 303 | return true; // Can't handle indirect branch. |
| 304 | } |
| 305 | |
| 306 | // Get the instruction before it if it is a terminator. |
| 307 | MachineInstr *SecondLastInst = I; |
Evan Cheng | 108c872 | 2010-09-23 06:54:40 +0000 | [diff] [blame] | 308 | unsigned SecondLastOpc = SecondLastInst->getOpcode(); |
| 309 | |
| 310 | // If AllowModify is true and the block ends with two or more unconditional |
| 311 | // branches, delete all but the first unconditional branch. |
| 312 | if (AllowModify && isUncondBranchOpcode(LastOpc)) { |
| 313 | while (isUncondBranchOpcode(SecondLastOpc)) { |
| 314 | LastInst->eraseFromParent(); |
| 315 | LastInst = SecondLastInst; |
| 316 | LastOpc = LastInst->getOpcode(); |
Evan Cheng | 676e258 | 2010-09-23 19:42:03 +0000 | [diff] [blame] | 317 | if (I == MBB.begin() || !isUnpredicatedTerminator(--I)) { |
| 318 | // Return now the only terminator is an unconditional branch. |
| 319 | TBB = LastInst->getOperand(0).getMBB(); |
| 320 | return false; |
| 321 | } else { |
Evan Cheng | 108c872 | 2010-09-23 06:54:40 +0000 | [diff] [blame] | 322 | SecondLastInst = I; |
| 323 | SecondLastOpc = SecondLastInst->getOpcode(); |
| 324 | } |
| 325 | } |
| 326 | } |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 327 | |
| 328 | // If there are three terminators, we don't know what sort of block this is. |
| 329 | if (SecondLastInst && I != MBB.begin() && isUnpredicatedTerminator(--I)) |
| 330 | return true; |
| 331 | |
Evan Cheng | 5ca53a7 | 2009-07-27 18:20:05 +0000 | [diff] [blame] | 332 | // If the block ends with a B and a Bcc, handle it. |
Evan Cheng | 5ca53a7 | 2009-07-27 18:20:05 +0000 | [diff] [blame] | 333 | if (isCondBranchOpcode(SecondLastOpc) && isUncondBranchOpcode(LastOpc)) { |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 334 | TBB = SecondLastInst->getOperand(0).getMBB(); |
| 335 | Cond.push_back(SecondLastInst->getOperand(1)); |
| 336 | Cond.push_back(SecondLastInst->getOperand(2)); |
| 337 | FBB = LastInst->getOperand(0).getMBB(); |
| 338 | return false; |
| 339 | } |
| 340 | |
| 341 | // If the block ends with two unconditional branches, handle it. The second |
| 342 | // one is not executed, so remove it. |
Evan Cheng | 5ca53a7 | 2009-07-27 18:20:05 +0000 | [diff] [blame] | 343 | if (isUncondBranchOpcode(SecondLastOpc) && isUncondBranchOpcode(LastOpc)) { |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 344 | TBB = SecondLastInst->getOperand(0).getMBB(); |
| 345 | I = LastInst; |
| 346 | if (AllowModify) |
| 347 | I->eraseFromParent(); |
| 348 | return false; |
| 349 | } |
| 350 | |
| 351 | // ...likewise if it ends with a branch table followed by an unconditional |
| 352 | // branch. The branch folder can create these, and we must get rid of them for |
| 353 | // correctness of Thumb constant islands. |
Bob Wilson | 8d4de5a | 2009-10-28 18:26:41 +0000 | [diff] [blame] | 354 | if ((isJumpTableBranchOpcode(SecondLastOpc) || |
| 355 | isIndirectBranchOpcode(SecondLastOpc)) && |
Evan Cheng | 5ca53a7 | 2009-07-27 18:20:05 +0000 | [diff] [blame] | 356 | isUncondBranchOpcode(LastOpc)) { |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 357 | I = LastInst; |
| 358 | if (AllowModify) |
| 359 | I->eraseFromParent(); |
| 360 | return true; |
| 361 | } |
| 362 | |
| 363 | // Otherwise, can't handle this. |
| 364 | return true; |
| 365 | } |
| 366 | |
| 367 | |
| 368 | unsigned ARMBaseInstrInfo::RemoveBranch(MachineBasicBlock &MBB) const { |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 369 | MachineBasicBlock::iterator I = MBB.end(); |
| 370 | if (I == MBB.begin()) return 0; |
| 371 | --I; |
Dale Johannesen | 93d6a7e | 2010-04-02 01:38:09 +0000 | [diff] [blame] | 372 | while (I->isDebugValue()) { |
| 373 | if (I == MBB.begin()) |
| 374 | return 0; |
| 375 | --I; |
| 376 | } |
Evan Cheng | 5ca53a7 | 2009-07-27 18:20:05 +0000 | [diff] [blame] | 377 | if (!isUncondBranchOpcode(I->getOpcode()) && |
| 378 | !isCondBranchOpcode(I->getOpcode())) |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 379 | return 0; |
| 380 | |
| 381 | // Remove the branch. |
| 382 | I->eraseFromParent(); |
| 383 | |
| 384 | I = MBB.end(); |
| 385 | |
| 386 | if (I == MBB.begin()) return 1; |
| 387 | --I; |
Evan Cheng | 5ca53a7 | 2009-07-27 18:20:05 +0000 | [diff] [blame] | 388 | if (!isCondBranchOpcode(I->getOpcode())) |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 389 | return 1; |
| 390 | |
| 391 | // Remove the branch. |
| 392 | I->eraseFromParent(); |
| 393 | return 2; |
| 394 | } |
| 395 | |
| 396 | unsigned |
| 397 | ARMBaseInstrInfo::InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB, |
Stuart Hastings | 3bf9125 | 2010-06-17 22:43:56 +0000 | [diff] [blame] | 398 | MachineBasicBlock *FBB, |
| 399 | const SmallVectorImpl<MachineOperand> &Cond, |
| 400 | DebugLoc DL) const { |
Evan Cheng | 6495f63 | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 401 | ARMFunctionInfo *AFI = MBB.getParent()->getInfo<ARMFunctionInfo>(); |
| 402 | int BOpc = !AFI->isThumbFunction() |
| 403 | ? ARM::B : (AFI->isThumb2Function() ? ARM::t2B : ARM::tB); |
| 404 | int BccOpc = !AFI->isThumbFunction() |
| 405 | ? ARM::Bcc : (AFI->isThumb2Function() ? ARM::t2Bcc : ARM::tBcc); |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 406 | |
| 407 | // Shouldn't be a fall through. |
| 408 | assert(TBB && "InsertBranch must not be told to insert a fallthrough"); |
| 409 | assert((Cond.size() == 2 || Cond.size() == 0) && |
| 410 | "ARM branch conditions have two components!"); |
| 411 | |
| 412 | if (FBB == 0) { |
| 413 | if (Cond.empty()) // Unconditional branch? |
Stuart Hastings | 3bf9125 | 2010-06-17 22:43:56 +0000 | [diff] [blame] | 414 | BuildMI(&MBB, DL, get(BOpc)).addMBB(TBB); |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 415 | else |
Stuart Hastings | 3bf9125 | 2010-06-17 22:43:56 +0000 | [diff] [blame] | 416 | BuildMI(&MBB, DL, get(BccOpc)).addMBB(TBB) |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 417 | .addImm(Cond[0].getImm()).addReg(Cond[1].getReg()); |
| 418 | return 1; |
| 419 | } |
| 420 | |
| 421 | // Two-way conditional branch. |
Stuart Hastings | 3bf9125 | 2010-06-17 22:43:56 +0000 | [diff] [blame] | 422 | BuildMI(&MBB, DL, get(BccOpc)).addMBB(TBB) |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 423 | .addImm(Cond[0].getImm()).addReg(Cond[1].getReg()); |
Stuart Hastings | 3bf9125 | 2010-06-17 22:43:56 +0000 | [diff] [blame] | 424 | BuildMI(&MBB, DL, get(BOpc)).addMBB(FBB); |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 425 | return 2; |
| 426 | } |
| 427 | |
| 428 | bool ARMBaseInstrInfo:: |
| 429 | ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const { |
| 430 | ARMCC::CondCodes CC = (ARMCC::CondCodes)(int)Cond[0].getImm(); |
| 431 | Cond[0].setImm(ARMCC::getOppositeCondition(CC)); |
| 432 | return false; |
| 433 | } |
| 434 | |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 435 | bool ARMBaseInstrInfo:: |
| 436 | PredicateInstruction(MachineInstr *MI, |
| 437 | const SmallVectorImpl<MachineOperand> &Pred) const { |
| 438 | unsigned Opc = MI->getOpcode(); |
Evan Cheng | 5ca53a7 | 2009-07-27 18:20:05 +0000 | [diff] [blame] | 439 | if (isUncondBranchOpcode(Opc)) { |
| 440 | MI->setDesc(get(getMatchingCondBranchOpcode(Opc))); |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 441 | MI->addOperand(MachineOperand::CreateImm(Pred[0].getImm())); |
| 442 | MI->addOperand(MachineOperand::CreateReg(Pred[1].getReg(), false)); |
| 443 | return true; |
| 444 | } |
| 445 | |
| 446 | int PIdx = MI->findFirstPredOperandIdx(); |
| 447 | if (PIdx != -1) { |
| 448 | MachineOperand &PMO = MI->getOperand(PIdx); |
| 449 | PMO.setImm(Pred[0].getImm()); |
| 450 | MI->getOperand(PIdx+1).setReg(Pred[1].getReg()); |
| 451 | return true; |
| 452 | } |
| 453 | return false; |
| 454 | } |
| 455 | |
| 456 | bool ARMBaseInstrInfo:: |
| 457 | SubsumesPredicate(const SmallVectorImpl<MachineOperand> &Pred1, |
| 458 | const SmallVectorImpl<MachineOperand> &Pred2) const { |
| 459 | if (Pred1.size() > 2 || Pred2.size() > 2) |
| 460 | return false; |
| 461 | |
| 462 | ARMCC::CondCodes CC1 = (ARMCC::CondCodes)Pred1[0].getImm(); |
| 463 | ARMCC::CondCodes CC2 = (ARMCC::CondCodes)Pred2[0].getImm(); |
| 464 | if (CC1 == CC2) |
| 465 | return true; |
| 466 | |
| 467 | switch (CC1) { |
| 468 | default: |
| 469 | return false; |
| 470 | case ARMCC::AL: |
| 471 | return true; |
| 472 | case ARMCC::HS: |
| 473 | return CC2 == ARMCC::HI; |
| 474 | case ARMCC::LS: |
| 475 | return CC2 == ARMCC::LO || CC2 == ARMCC::EQ; |
| 476 | case ARMCC::GE: |
| 477 | return CC2 == ARMCC::GT; |
| 478 | case ARMCC::LE: |
| 479 | return CC2 == ARMCC::LT; |
| 480 | } |
| 481 | } |
| 482 | |
| 483 | bool ARMBaseInstrInfo::DefinesPredicate(MachineInstr *MI, |
| 484 | std::vector<MachineOperand> &Pred) const { |
Evan Cheng | 8fb9036 | 2009-08-08 03:20:32 +0000 | [diff] [blame] | 485 | // FIXME: This confuses implicit_def with optional CPSR def. |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 486 | const TargetInstrDesc &TID = MI->getDesc(); |
| 487 | if (!TID.getImplicitDefs() && !TID.hasOptionalDef()) |
| 488 | return false; |
| 489 | |
| 490 | bool Found = false; |
| 491 | for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) { |
| 492 | const MachineOperand &MO = MI->getOperand(i); |
| 493 | if (MO.isReg() && MO.getReg() == ARM::CPSR) { |
| 494 | Pred.push_back(MO); |
| 495 | Found = true; |
| 496 | } |
| 497 | } |
| 498 | |
| 499 | return Found; |
| 500 | } |
| 501 | |
Evan Cheng | ac0869d | 2009-11-21 06:21:52 +0000 | [diff] [blame] | 502 | /// isPredicable - Return true if the specified instruction can be predicated. |
| 503 | /// By default, this returns true for every instruction with a |
| 504 | /// PredicateOperand. |
| 505 | bool ARMBaseInstrInfo::isPredicable(MachineInstr *MI) const { |
| 506 | const TargetInstrDesc &TID = MI->getDesc(); |
| 507 | if (!TID.isPredicable()) |
| 508 | return false; |
| 509 | |
| 510 | if ((TID.TSFlags & ARMII::DomainMask) == ARMII::DomainNEON) { |
| 511 | ARMFunctionInfo *AFI = |
| 512 | MI->getParent()->getParent()->getInfo<ARMFunctionInfo>(); |
Evan Cheng | d7f0810 | 2009-11-24 08:06:15 +0000 | [diff] [blame] | 513 | return AFI->isThumb2Function(); |
Evan Cheng | ac0869d | 2009-11-21 06:21:52 +0000 | [diff] [blame] | 514 | } |
| 515 | return true; |
| 516 | } |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 517 | |
Chris Lattner | 56856b1 | 2009-12-03 06:58:32 +0000 | [diff] [blame] | 518 | /// FIXME: Works around a gcc miscompilation with -fstrict-aliasing. |
Chandler Carruth | 19e5702 | 2010-10-23 08:40:19 +0000 | [diff] [blame] | 519 | LLVM_ATTRIBUTE_NOINLINE |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 520 | static unsigned getNumJTEntries(const std::vector<MachineJumpTableEntry> &JT, |
Chris Lattner | 56856b1 | 2009-12-03 06:58:32 +0000 | [diff] [blame] | 521 | unsigned JTI); |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 522 | static unsigned getNumJTEntries(const std::vector<MachineJumpTableEntry> &JT, |
| 523 | unsigned JTI) { |
Chris Lattner | 56856b1 | 2009-12-03 06:58:32 +0000 | [diff] [blame] | 524 | assert(JTI < JT.size()); |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 525 | return JT[JTI].MBBs.size(); |
| 526 | } |
| 527 | |
| 528 | /// GetInstSize - Return the size of the specified MachineInstr. |
| 529 | /// |
| 530 | unsigned ARMBaseInstrInfo::GetInstSizeInBytes(const MachineInstr *MI) const { |
| 531 | const MachineBasicBlock &MBB = *MI->getParent(); |
| 532 | const MachineFunction *MF = MBB.getParent(); |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 533 | const MCAsmInfo *MAI = MF->getTarget().getMCAsmInfo(); |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 534 | |
| 535 | // Basic size info comes from the TSFlags field. |
| 536 | const TargetInstrDesc &TID = MI->getDesc(); |
Bruno Cardoso Lopes | 99405df | 2010-06-08 22:51:23 +0000 | [diff] [blame] | 537 | uint64_t TSFlags = TID.TSFlags; |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 538 | |
Evan Cheng | a0ee862 | 2009-07-31 22:22:22 +0000 | [diff] [blame] | 539 | unsigned Opc = MI->getOpcode(); |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 540 | switch ((TSFlags & ARMII::SizeMask) >> ARMII::SizeShift) { |
| 541 | default: { |
| 542 | // If this machine instr is an inline asm, measure it. |
| 543 | if (MI->getOpcode() == ARM::INLINEASM) |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 544 | return getInlineAsmLength(MI->getOperand(0).getSymbolName(), *MAI); |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 545 | if (MI->isLabel()) |
| 546 | return 0; |
Evan Cheng | a0ee862 | 2009-07-31 22:22:22 +0000 | [diff] [blame] | 547 | switch (Opc) { |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 548 | default: |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 549 | llvm_unreachable("Unknown or unset size field for instr!"); |
Chris Lattner | 518bb53 | 2010-02-09 19:54:29 +0000 | [diff] [blame] | 550 | case TargetOpcode::IMPLICIT_DEF: |
| 551 | case TargetOpcode::KILL: |
Bill Wendling | 7431bea | 2010-07-16 22:20:36 +0000 | [diff] [blame] | 552 | case TargetOpcode::PROLOG_LABEL: |
Chris Lattner | 518bb53 | 2010-02-09 19:54:29 +0000 | [diff] [blame] | 553 | case TargetOpcode::EH_LABEL: |
Dale Johannesen | 375be77 | 2010-04-07 19:51:44 +0000 | [diff] [blame] | 554 | case TargetOpcode::DBG_VALUE: |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 555 | return 0; |
| 556 | } |
| 557 | break; |
| 558 | } |
Evan Cheng | 7894762 | 2009-07-24 18:20:44 +0000 | [diff] [blame] | 559 | case ARMII::Size8Bytes: return 8; // ARM instruction x 2. |
| 560 | case ARMII::Size4Bytes: return 4; // ARM / Thumb2 instruction. |
| 561 | case ARMII::Size2Bytes: return 2; // Thumb1 instruction. |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 562 | case ARMII::SizeSpecial: { |
Evan Cheng | a0ee862 | 2009-07-31 22:22:22 +0000 | [diff] [blame] | 563 | switch (Opc) { |
Jim Grosbach | 3c38f96 | 2010-10-06 22:01:26 +0000 | [diff] [blame] | 564 | case ARM::MOVi32imm: |
| 565 | case ARM::t2MOVi32imm: |
| 566 | return 8; |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 567 | case ARM::CONSTPOOL_ENTRY: |
| 568 | // If this machine instr is a constant pool entry, its size is recorded as |
| 569 | // operand #2. |
| 570 | return MI->getOperand(2).getImm(); |
Jim Grosbach | 5eb1951 | 2010-05-22 01:06:18 +0000 | [diff] [blame] | 571 | case ARM::Int_eh_sjlj_longjmp: |
| 572 | return 16; |
| 573 | case ARM::tInt_eh_sjlj_longjmp: |
| 574 | return 10; |
Evan Cheng | 7894762 | 2009-07-24 18:20:44 +0000 | [diff] [blame] | 575 | case ARM::Int_eh_sjlj_setjmp: |
Jim Grosbach | d100755 | 2010-04-28 20:33:09 +0000 | [diff] [blame] | 576 | case ARM::Int_eh_sjlj_setjmp_nofp: |
Jim Grosbach | 0798edd | 2010-05-27 23:49:24 +0000 | [diff] [blame] | 577 | return 20; |
Jim Grosbach | d122874 | 2009-12-01 18:10:36 +0000 | [diff] [blame] | 578 | case ARM::tInt_eh_sjlj_setjmp: |
Jim Grosbach | 5aa1684 | 2009-08-11 19:42:21 +0000 | [diff] [blame] | 579 | case ARM::t2Int_eh_sjlj_setjmp: |
Jim Grosbach | d100755 | 2010-04-28 20:33:09 +0000 | [diff] [blame] | 580 | case ARM::t2Int_eh_sjlj_setjmp_nofp: |
Jim Grosbach | 0798edd | 2010-05-27 23:49:24 +0000 | [diff] [blame] | 581 | return 12; |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 582 | case ARM::BR_JTr: |
| 583 | case ARM::BR_JTm: |
| 584 | case ARM::BR_JTadd: |
Evan Cheng | a0ee862 | 2009-07-31 22:22:22 +0000 | [diff] [blame] | 585 | case ARM::tBR_JTr: |
Evan Cheng | d26b14c | 2009-07-31 18:28:05 +0000 | [diff] [blame] | 586 | case ARM::t2BR_JT: |
Jim Grosbach | d092a87 | 2010-11-29 21:28:32 +0000 | [diff] [blame] | 587 | case ARM::t2TBB_JT: |
| 588 | case ARM::t2TBH_JT: { |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 589 | // These are jumptable branches, i.e. a branch followed by an inlined |
Evan Cheng | d26b14c | 2009-07-31 18:28:05 +0000 | [diff] [blame] | 590 | // jumptable. The size is 4 + 4 * number of entries. For TBB, each |
| 591 | // entry is one byte; TBH two byte each. |
Jim Grosbach | d092a87 | 2010-11-29 21:28:32 +0000 | [diff] [blame] | 592 | unsigned EntrySize = (Opc == ARM::t2TBB_JT) |
| 593 | ? 1 : ((Opc == ARM::t2TBH_JT) ? 2 : 4); |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 594 | unsigned NumOps = TID.getNumOperands(); |
| 595 | MachineOperand JTOP = |
| 596 | MI->getOperand(NumOps - (TID.isPredicable() ? 3 : 2)); |
| 597 | unsigned JTI = JTOP.getIndex(); |
| 598 | const MachineJumpTableInfo *MJTI = MF->getJumpTableInfo(); |
Chris Lattner | b1e8039 | 2010-01-25 23:22:00 +0000 | [diff] [blame] | 599 | assert(MJTI != 0); |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 600 | const std::vector<MachineJumpTableEntry> &JT = MJTI->getJumpTables(); |
| 601 | assert(JTI < JT.size()); |
| 602 | // Thumb instructions are 2 byte aligned, but JT entries are 4 byte |
| 603 | // 4 aligned. The assembler / linker may add 2 byte padding just before |
| 604 | // the JT entries. The size does not include this padding; the |
| 605 | // constant islands pass does separate bookkeeping for it. |
| 606 | // FIXME: If we know the size of the function is less than (1 << 16) *2 |
| 607 | // bytes, we can use 16-bit entries instead. Then there won't be an |
| 608 | // alignment issue. |
Evan Cheng | 25f7cfc | 2009-08-01 06:13:52 +0000 | [diff] [blame] | 609 | unsigned InstSize = (Opc == ARM::tBR_JTr || Opc == ARM::t2BR_JT) ? 2 : 4; |
| 610 | unsigned NumEntries = getNumJTEntries(JT, JTI); |
Jim Grosbach | d092a87 | 2010-11-29 21:28:32 +0000 | [diff] [blame] | 611 | if (Opc == ARM::t2TBB_JT && (NumEntries & 1)) |
Evan Cheng | 25f7cfc | 2009-08-01 06:13:52 +0000 | [diff] [blame] | 612 | // Make sure the instruction that follows TBB is 2-byte aligned. |
| 613 | // FIXME: Constant island pass should insert an "ALIGN" instruction |
| 614 | // instead. |
| 615 | ++NumEntries; |
| 616 | return NumEntries * EntrySize + InstSize; |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 617 | } |
| 618 | default: |
| 619 | // Otherwise, pseudo-instruction sizes are zero. |
| 620 | return 0; |
| 621 | } |
| 622 | } |
| 623 | } |
| 624 | return 0; // Not reached |
| 625 | } |
| 626 | |
Jakob Stoklund Olesen | ac27366 | 2010-07-11 06:33:54 +0000 | [diff] [blame] | 627 | void ARMBaseInstrInfo::copyPhysReg(MachineBasicBlock &MBB, |
| 628 | MachineBasicBlock::iterator I, DebugLoc DL, |
| 629 | unsigned DestReg, unsigned SrcReg, |
| 630 | bool KillSrc) const { |
| 631 | bool GPRDest = ARM::GPRRegClass.contains(DestReg); |
| 632 | bool GPRSrc = ARM::GPRRegClass.contains(SrcReg); |
Bob Wilson | 1665b0a | 2010-02-16 17:24:15 +0000 | [diff] [blame] | 633 | |
Jakob Stoklund Olesen | ac27366 | 2010-07-11 06:33:54 +0000 | [diff] [blame] | 634 | if (GPRDest && GPRSrc) { |
| 635 | AddDefaultCC(AddDefaultPred(BuildMI(MBB, I, DL, get(ARM::MOVr), DestReg) |
| 636 | .addReg(SrcReg, getKillRegState(KillSrc)))); |
| 637 | return; |
David Goodwin | 7bfdca0 | 2009-08-05 21:02:22 +0000 | [diff] [blame] | 638 | } |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 639 | |
Jakob Stoklund Olesen | ac27366 | 2010-07-11 06:33:54 +0000 | [diff] [blame] | 640 | bool SPRDest = ARM::SPRRegClass.contains(DestReg); |
| 641 | bool SPRSrc = ARM::SPRRegClass.contains(SrcReg); |
| 642 | |
| 643 | unsigned Opc; |
| 644 | if (SPRDest && SPRSrc) |
| 645 | Opc = ARM::VMOVS; |
| 646 | else if (GPRDest && SPRSrc) |
| 647 | Opc = ARM::VMOVRS; |
| 648 | else if (SPRDest && GPRSrc) |
| 649 | Opc = ARM::VMOVSR; |
| 650 | else if (ARM::DPRRegClass.contains(DestReg, SrcReg)) |
| 651 | Opc = ARM::VMOVD; |
| 652 | else if (ARM::QPRRegClass.contains(DestReg, SrcReg)) |
| 653 | Opc = ARM::VMOVQ; |
| 654 | else if (ARM::QQPRRegClass.contains(DestReg, SrcReg)) |
| 655 | Opc = ARM::VMOVQQ; |
| 656 | else if (ARM::QQQQPRRegClass.contains(DestReg, SrcReg)) |
| 657 | Opc = ARM::VMOVQQQQ; |
| 658 | else |
| 659 | llvm_unreachable("Impossible reg-to-reg copy"); |
| 660 | |
| 661 | MachineInstrBuilder MIB = BuildMI(MBB, I, DL, get(Opc), DestReg); |
| 662 | MIB.addReg(SrcReg, getKillRegState(KillSrc)); |
| 663 | if (Opc != ARM::VMOVQQ && Opc != ARM::VMOVQQQQ) |
| 664 | AddDefaultPred(MIB); |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 665 | } |
| 666 | |
Evan Cheng | c10b5af | 2010-05-07 00:24:52 +0000 | [diff] [blame] | 667 | static const |
| 668 | MachineInstrBuilder &AddDReg(MachineInstrBuilder &MIB, |
| 669 | unsigned Reg, unsigned SubIdx, unsigned State, |
| 670 | const TargetRegisterInfo *TRI) { |
| 671 | if (!SubIdx) |
| 672 | return MIB.addReg(Reg, State); |
| 673 | |
| 674 | if (TargetRegisterInfo::isPhysicalRegister(Reg)) |
| 675 | return MIB.addReg(TRI->getSubReg(Reg, SubIdx), State); |
| 676 | return MIB.addReg(Reg, State, SubIdx); |
| 677 | } |
| 678 | |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 679 | void ARMBaseInstrInfo:: |
| 680 | storeRegToStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator I, |
| 681 | unsigned SrcReg, bool isKill, int FI, |
Evan Cheng | 746ad69 | 2010-05-06 19:06:44 +0000 | [diff] [blame] | 682 | const TargetRegisterClass *RC, |
| 683 | const TargetRegisterInfo *TRI) const { |
Chris Lattner | c7f3ace | 2010-04-02 20:16:16 +0000 | [diff] [blame] | 684 | DebugLoc DL; |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 685 | if (I != MBB.end()) DL = I->getDebugLoc(); |
Anton Korobeynikov | 249fb33 | 2009-10-07 00:06:35 +0000 | [diff] [blame] | 686 | MachineFunction &MF = *MBB.getParent(); |
| 687 | MachineFrameInfo &MFI = *MF.getFrameInfo(); |
Jim Grosbach | 31bc849 | 2009-11-08 00:27:19 +0000 | [diff] [blame] | 688 | unsigned Align = MFI.getObjectAlignment(FI); |
Anton Korobeynikov | 249fb33 | 2009-10-07 00:06:35 +0000 | [diff] [blame] | 689 | |
| 690 | MachineMemOperand *MMO = |
Chris Lattner | 59db549 | 2010-09-21 04:39:43 +0000 | [diff] [blame] | 691 | MF.getMachineMemOperand(MachinePointerInfo( |
| 692 | PseudoSourceValue::getFixedStack(FI)), |
| 693 | MachineMemOperand::MOStore, |
Anton Korobeynikov | 249fb33 | 2009-10-07 00:06:35 +0000 | [diff] [blame] | 694 | MFI.getObjectSize(FI), |
Jim Grosbach | 31bc849 | 2009-11-08 00:27:19 +0000 | [diff] [blame] | 695 | Align); |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 696 | |
Bob Wilson | 0eb0c74 | 2010-02-16 22:01:59 +0000 | [diff] [blame] | 697 | // tGPR is used sometimes in ARM instructions that need to avoid using |
Jim Grosbach | 6ccfc50 | 2010-07-30 02:41:01 +0000 | [diff] [blame] | 698 | // certain registers. Just treat it as GPR here. Likewise, rGPR. |
| 699 | if (RC == ARM::tGPRRegisterClass || RC == ARM::tcGPRRegisterClass |
| 700 | || RC == ARM::rGPRRegisterClass) |
Bob Wilson | 0eb0c74 | 2010-02-16 22:01:59 +0000 | [diff] [blame] | 701 | RC = ARM::GPRRegisterClass; |
| 702 | |
Bob Wilson | ebe99b2 | 2010-06-18 21:32:42 +0000 | [diff] [blame] | 703 | switch (RC->getID()) { |
| 704 | case ARM::GPRRegClassID: |
Jim Grosbach | 7e3383c | 2010-10-27 23:12:14 +0000 | [diff] [blame] | 705 | AddDefaultPred(BuildMI(MBB, I, DL, get(ARM::STRi12)) |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 706 | .addReg(SrcReg, getKillRegState(isKill)) |
Jim Grosbach | 7e3383c | 2010-10-27 23:12:14 +0000 | [diff] [blame] | 707 | .addFrameIndex(FI).addImm(0).addMemOperand(MMO)); |
Bob Wilson | ebe99b2 | 2010-06-18 21:32:42 +0000 | [diff] [blame] | 708 | break; |
| 709 | case ARM::SPRRegClassID: |
Evan Cheng | d31c549 | 2010-05-06 01:34:11 +0000 | [diff] [blame] | 710 | AddDefaultPred(BuildMI(MBB, I, DL, get(ARM::VSTRS)) |
| 711 | .addReg(SrcReg, getKillRegState(isKill)) |
| 712 | .addFrameIndex(FI).addImm(0).addMemOperand(MMO)); |
Bob Wilson | ebe99b2 | 2010-06-18 21:32:42 +0000 | [diff] [blame] | 713 | break; |
| 714 | case ARM::DPRRegClassID: |
| 715 | case ARM::DPR_VFP2RegClassID: |
| 716 | case ARM::DPR_8RegClassID: |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 717 | AddDefaultPred(BuildMI(MBB, I, DL, get(ARM::VSTRD)) |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 718 | .addReg(SrcReg, getKillRegState(isKill)) |
Anton Korobeynikov | 249fb33 | 2009-10-07 00:06:35 +0000 | [diff] [blame] | 719 | .addFrameIndex(FI).addImm(0).addMemOperand(MMO)); |
Bob Wilson | ebe99b2 | 2010-06-18 21:32:42 +0000 | [diff] [blame] | 720 | break; |
| 721 | case ARM::QPRRegClassID: |
| 722 | case ARM::QPR_VFP2RegClassID: |
| 723 | case ARM::QPR_8RegClassID: |
Jim Grosbach | 0cfcf93 | 2010-09-08 00:26:59 +0000 | [diff] [blame] | 724 | if (Align >= 16 && getRegisterInfo().needsStackRealignment(MF)) { |
Bob Wilson | 168f382 | 2010-09-15 01:48:05 +0000 | [diff] [blame] | 725 | AddDefaultPred(BuildMI(MBB, I, DL, get(ARM::VST1q64Pseudo)) |
Bob Wilson | f967ca0 | 2010-07-06 21:26:18 +0000 | [diff] [blame] | 726 | .addFrameIndex(FI).addImm(16) |
Evan Cheng | 69b9f98 | 2010-05-13 01:12:06 +0000 | [diff] [blame] | 727 | .addReg(SrcReg, getKillRegState(isKill)) |
| 728 | .addMemOperand(MMO)); |
Jim Grosbach | 31bc849 | 2009-11-08 00:27:19 +0000 | [diff] [blame] | 729 | } else { |
Bill Wendling | 73fe34a | 2010-11-16 01:16:36 +0000 | [diff] [blame] | 730 | AddDefaultPred(BuildMI(MBB, I, DL, get(ARM::VSTMQIA)) |
Evan Cheng | 69b9f98 | 2010-05-13 01:12:06 +0000 | [diff] [blame] | 731 | .addReg(SrcReg, getKillRegState(isKill)) |
| 732 | .addFrameIndex(FI) |
Evan Cheng | 69b9f98 | 2010-05-13 01:12:06 +0000 | [diff] [blame] | 733 | .addMemOperand(MMO)); |
Jim Grosbach | 31bc849 | 2009-11-08 00:27:19 +0000 | [diff] [blame] | 734 | } |
Bob Wilson | ebe99b2 | 2010-06-18 21:32:42 +0000 | [diff] [blame] | 735 | break; |
| 736 | case ARM::QQPRRegClassID: |
| 737 | case ARM::QQPR_VFP2RegClassID: |
Evan Cheng | 435d499 | 2010-05-07 02:04:02 +0000 | [diff] [blame] | 738 | if (Align >= 16 && getRegisterInfo().canRealignStack(MF)) { |
Evan Cheng | 22c687b | 2010-05-14 02:13:41 +0000 | [diff] [blame] | 739 | // FIXME: It's possible to only store part of the QQ register if the |
| 740 | // spilled def has a sub-register index. |
Bob Wilson | 168f382 | 2010-09-15 01:48:05 +0000 | [diff] [blame] | 741 | AddDefaultPred(BuildMI(MBB, I, DL, get(ARM::VST1d64QPseudo)) |
| 742 | .addFrameIndex(FI).addImm(16) |
| 743 | .addReg(SrcReg, getKillRegState(isKill)) |
| 744 | .addMemOperand(MMO)); |
Evan Cheng | 435d499 | 2010-05-07 02:04:02 +0000 | [diff] [blame] | 745 | } else { |
| 746 | MachineInstrBuilder MIB = |
Bill Wendling | 73fe34a | 2010-11-16 01:16:36 +0000 | [diff] [blame] | 747 | AddDefaultPred(BuildMI(MBB, I, DL, get(ARM::VSTMDIA)) |
| 748 | .addFrameIndex(FI)) |
Evan Cheng | 435d499 | 2010-05-07 02:04:02 +0000 | [diff] [blame] | 749 | .addMemOperand(MMO); |
Jakob Stoklund Olesen | 558661d | 2010-05-24 16:54:32 +0000 | [diff] [blame] | 750 | MIB = AddDReg(MIB, SrcReg, ARM::dsub_0, getKillRegState(isKill), TRI); |
| 751 | MIB = AddDReg(MIB, SrcReg, ARM::dsub_1, 0, TRI); |
| 752 | MIB = AddDReg(MIB, SrcReg, ARM::dsub_2, 0, TRI); |
| 753 | AddDReg(MIB, SrcReg, ARM::dsub_3, 0, TRI); |
Evan Cheng | 435d499 | 2010-05-07 02:04:02 +0000 | [diff] [blame] | 754 | } |
Bob Wilson | ebe99b2 | 2010-06-18 21:32:42 +0000 | [diff] [blame] | 755 | break; |
| 756 | case ARM::QQQQPRRegClassID: { |
Evan Cheng | 22c687b | 2010-05-14 02:13:41 +0000 | [diff] [blame] | 757 | MachineInstrBuilder MIB = |
Bill Wendling | 73fe34a | 2010-11-16 01:16:36 +0000 | [diff] [blame] | 758 | AddDefaultPred(BuildMI(MBB, I, DL, get(ARM::VSTMDIA)) |
| 759 | .addFrameIndex(FI)) |
Evan Cheng | 22c687b | 2010-05-14 02:13:41 +0000 | [diff] [blame] | 760 | .addMemOperand(MMO); |
Jakob Stoklund Olesen | 558661d | 2010-05-24 16:54:32 +0000 | [diff] [blame] | 761 | MIB = AddDReg(MIB, SrcReg, ARM::dsub_0, getKillRegState(isKill), TRI); |
| 762 | MIB = AddDReg(MIB, SrcReg, ARM::dsub_1, 0, TRI); |
| 763 | MIB = AddDReg(MIB, SrcReg, ARM::dsub_2, 0, TRI); |
| 764 | MIB = AddDReg(MIB, SrcReg, ARM::dsub_3, 0, TRI); |
| 765 | MIB = AddDReg(MIB, SrcReg, ARM::dsub_4, 0, TRI); |
| 766 | MIB = AddDReg(MIB, SrcReg, ARM::dsub_5, 0, TRI); |
| 767 | MIB = AddDReg(MIB, SrcReg, ARM::dsub_6, 0, TRI); |
| 768 | AddDReg(MIB, SrcReg, ARM::dsub_7, 0, TRI); |
Bob Wilson | ebe99b2 | 2010-06-18 21:32:42 +0000 | [diff] [blame] | 769 | break; |
| 770 | } |
| 771 | default: |
| 772 | llvm_unreachable("Unknown regclass!"); |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 773 | } |
| 774 | } |
| 775 | |
Jakob Stoklund Olesen | 3432785 | 2010-09-15 16:36:26 +0000 | [diff] [blame] | 776 | unsigned |
| 777 | ARMBaseInstrInfo::isStoreToStackSlot(const MachineInstr *MI, |
| 778 | int &FrameIndex) const { |
| 779 | switch (MI->getOpcode()) { |
| 780 | default: break; |
Jim Grosbach | 7e3383c | 2010-10-27 23:12:14 +0000 | [diff] [blame] | 781 | case ARM::STRrs: |
Jakob Stoklund Olesen | 3432785 | 2010-09-15 16:36:26 +0000 | [diff] [blame] | 782 | case ARM::t2STRs: // FIXME: don't use t2STRs to access frame. |
| 783 | if (MI->getOperand(1).isFI() && |
| 784 | MI->getOperand(2).isReg() && |
| 785 | MI->getOperand(3).isImm() && |
| 786 | MI->getOperand(2).getReg() == 0 && |
| 787 | MI->getOperand(3).getImm() == 0) { |
| 788 | FrameIndex = MI->getOperand(1).getIndex(); |
| 789 | return MI->getOperand(0).getReg(); |
| 790 | } |
| 791 | break; |
Jim Grosbach | 7e3383c | 2010-10-27 23:12:14 +0000 | [diff] [blame] | 792 | case ARM::STRi12: |
Jakob Stoklund Olesen | 3432785 | 2010-09-15 16:36:26 +0000 | [diff] [blame] | 793 | case ARM::t2STRi12: |
| 794 | case ARM::tSpill: |
| 795 | case ARM::VSTRD: |
| 796 | case ARM::VSTRS: |
| 797 | if (MI->getOperand(1).isFI() && |
| 798 | MI->getOperand(2).isImm() && |
| 799 | MI->getOperand(2).getImm() == 0) { |
| 800 | FrameIndex = MI->getOperand(1).getIndex(); |
| 801 | return MI->getOperand(0).getReg(); |
| 802 | } |
| 803 | break; |
Jakob Stoklund Olesen | d64816a | 2010-09-15 17:27:09 +0000 | [diff] [blame] | 804 | case ARM::VST1q64Pseudo: |
| 805 | if (MI->getOperand(0).isFI() && |
| 806 | MI->getOperand(2).getSubReg() == 0) { |
| 807 | FrameIndex = MI->getOperand(0).getIndex(); |
| 808 | return MI->getOperand(2).getReg(); |
| 809 | } |
Jakob Stoklund Olesen | 31bbc51 | 2010-09-15 21:40:09 +0000 | [diff] [blame] | 810 | break; |
Bill Wendling | 73fe34a | 2010-11-16 01:16:36 +0000 | [diff] [blame] | 811 | case ARM::VSTMQIA: |
Jakob Stoklund Olesen | d64816a | 2010-09-15 17:27:09 +0000 | [diff] [blame] | 812 | if (MI->getOperand(1).isFI() && |
Jakob Stoklund Olesen | d64816a | 2010-09-15 17:27:09 +0000 | [diff] [blame] | 813 | MI->getOperand(0).getSubReg() == 0) { |
| 814 | FrameIndex = MI->getOperand(1).getIndex(); |
| 815 | return MI->getOperand(0).getReg(); |
| 816 | } |
| 817 | break; |
Jakob Stoklund Olesen | 3432785 | 2010-09-15 16:36:26 +0000 | [diff] [blame] | 818 | } |
| 819 | |
| 820 | return 0; |
| 821 | } |
| 822 | |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 823 | void ARMBaseInstrInfo:: |
| 824 | loadRegFromStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator I, |
| 825 | unsigned DestReg, int FI, |
Evan Cheng | 746ad69 | 2010-05-06 19:06:44 +0000 | [diff] [blame] | 826 | const TargetRegisterClass *RC, |
| 827 | const TargetRegisterInfo *TRI) const { |
Chris Lattner | c7f3ace | 2010-04-02 20:16:16 +0000 | [diff] [blame] | 828 | DebugLoc DL; |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 829 | if (I != MBB.end()) DL = I->getDebugLoc(); |
Anton Korobeynikov | 249fb33 | 2009-10-07 00:06:35 +0000 | [diff] [blame] | 830 | MachineFunction &MF = *MBB.getParent(); |
| 831 | MachineFrameInfo &MFI = *MF.getFrameInfo(); |
Jim Grosbach | 31bc849 | 2009-11-08 00:27:19 +0000 | [diff] [blame] | 832 | unsigned Align = MFI.getObjectAlignment(FI); |
Anton Korobeynikov | 249fb33 | 2009-10-07 00:06:35 +0000 | [diff] [blame] | 833 | MachineMemOperand *MMO = |
Chris Lattner | 59db549 | 2010-09-21 04:39:43 +0000 | [diff] [blame] | 834 | MF.getMachineMemOperand( |
| 835 | MachinePointerInfo(PseudoSourceValue::getFixedStack(FI)), |
| 836 | MachineMemOperand::MOLoad, |
Anton Korobeynikov | 249fb33 | 2009-10-07 00:06:35 +0000 | [diff] [blame] | 837 | MFI.getObjectSize(FI), |
Jim Grosbach | 31bc849 | 2009-11-08 00:27:19 +0000 | [diff] [blame] | 838 | Align); |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 839 | |
Bob Wilson | 0eb0c74 | 2010-02-16 22:01:59 +0000 | [diff] [blame] | 840 | // tGPR is used sometimes in ARM instructions that need to avoid using |
| 841 | // certain registers. Just treat it as GPR here. |
Jim Grosbach | 6ccfc50 | 2010-07-30 02:41:01 +0000 | [diff] [blame] | 842 | if (RC == ARM::tGPRRegisterClass || RC == ARM::tcGPRRegisterClass |
| 843 | || RC == ARM::rGPRRegisterClass) |
Bob Wilson | 0eb0c74 | 2010-02-16 22:01:59 +0000 | [diff] [blame] | 844 | RC = ARM::GPRRegisterClass; |
| 845 | |
Bob Wilson | ebe99b2 | 2010-06-18 21:32:42 +0000 | [diff] [blame] | 846 | switch (RC->getID()) { |
| 847 | case ARM::GPRRegClassID: |
Jim Grosbach | 3e55612 | 2010-10-26 22:37:02 +0000 | [diff] [blame] | 848 | AddDefaultPred(BuildMI(MBB, I, DL, get(ARM::LDRi12), DestReg) |
| 849 | .addFrameIndex(FI).addImm(0).addMemOperand(MMO)); |
Bob Wilson | ebe99b2 | 2010-06-18 21:32:42 +0000 | [diff] [blame] | 850 | break; |
| 851 | case ARM::SPRRegClassID: |
Evan Cheng | d31c549 | 2010-05-06 01:34:11 +0000 | [diff] [blame] | 852 | AddDefaultPred(BuildMI(MBB, I, DL, get(ARM::VLDRS), DestReg) |
| 853 | .addFrameIndex(FI).addImm(0).addMemOperand(MMO)); |
Bob Wilson | ebe99b2 | 2010-06-18 21:32:42 +0000 | [diff] [blame] | 854 | break; |
| 855 | case ARM::DPRRegClassID: |
| 856 | case ARM::DPR_VFP2RegClassID: |
| 857 | case ARM::DPR_8RegClassID: |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 858 | AddDefaultPred(BuildMI(MBB, I, DL, get(ARM::VLDRD), DestReg) |
Anton Korobeynikov | 249fb33 | 2009-10-07 00:06:35 +0000 | [diff] [blame] | 859 | .addFrameIndex(FI).addImm(0).addMemOperand(MMO)); |
Bob Wilson | ebe99b2 | 2010-06-18 21:32:42 +0000 | [diff] [blame] | 860 | break; |
| 861 | case ARM::QPRRegClassID: |
| 862 | case ARM::QPR_VFP2RegClassID: |
| 863 | case ARM::QPR_8RegClassID: |
Jim Grosbach | 0cfcf93 | 2010-09-08 00:26:59 +0000 | [diff] [blame] | 864 | if (Align >= 16 && getRegisterInfo().needsStackRealignment(MF)) { |
Bob Wilson | 168f382 | 2010-09-15 01:48:05 +0000 | [diff] [blame] | 865 | AddDefaultPred(BuildMI(MBB, I, DL, get(ARM::VLD1q64Pseudo), DestReg) |
Bob Wilson | f967ca0 | 2010-07-06 21:26:18 +0000 | [diff] [blame] | 866 | .addFrameIndex(FI).addImm(16) |
Evan Cheng | 69b9f98 | 2010-05-13 01:12:06 +0000 | [diff] [blame] | 867 | .addMemOperand(MMO)); |
Jim Grosbach | 31bc849 | 2009-11-08 00:27:19 +0000 | [diff] [blame] | 868 | } else { |
Bill Wendling | 73fe34a | 2010-11-16 01:16:36 +0000 | [diff] [blame] | 869 | AddDefaultPred(BuildMI(MBB, I, DL, get(ARM::VLDMQIA), DestReg) |
Evan Cheng | 69b9f98 | 2010-05-13 01:12:06 +0000 | [diff] [blame] | 870 | .addFrameIndex(FI) |
Evan Cheng | 69b9f98 | 2010-05-13 01:12:06 +0000 | [diff] [blame] | 871 | .addMemOperand(MMO)); |
Jim Grosbach | 31bc849 | 2009-11-08 00:27:19 +0000 | [diff] [blame] | 872 | } |
Bob Wilson | ebe99b2 | 2010-06-18 21:32:42 +0000 | [diff] [blame] | 873 | break; |
| 874 | case ARM::QQPRRegClassID: |
| 875 | case ARM::QQPR_VFP2RegClassID: |
Evan Cheng | 435d499 | 2010-05-07 02:04:02 +0000 | [diff] [blame] | 876 | if (Align >= 16 && getRegisterInfo().canRealignStack(MF)) { |
Bob Wilson | 168f382 | 2010-09-15 01:48:05 +0000 | [diff] [blame] | 877 | AddDefaultPred(BuildMI(MBB, I, DL, get(ARM::VLD1d64QPseudo), DestReg) |
| 878 | .addFrameIndex(FI).addImm(16) |
| 879 | .addMemOperand(MMO)); |
Evan Cheng | 435d499 | 2010-05-07 02:04:02 +0000 | [diff] [blame] | 880 | } else { |
| 881 | MachineInstrBuilder MIB = |
Bill Wendling | 73fe34a | 2010-11-16 01:16:36 +0000 | [diff] [blame] | 882 | AddDefaultPred(BuildMI(MBB, I, DL, get(ARM::VLDMDIA)) |
| 883 | .addFrameIndex(FI)) |
Evan Cheng | 435d499 | 2010-05-07 02:04:02 +0000 | [diff] [blame] | 884 | .addMemOperand(MMO); |
Jakob Stoklund Olesen | 558661d | 2010-05-24 16:54:32 +0000 | [diff] [blame] | 885 | MIB = AddDReg(MIB, DestReg, ARM::dsub_0, RegState::Define, TRI); |
| 886 | MIB = AddDReg(MIB, DestReg, ARM::dsub_1, RegState::Define, TRI); |
| 887 | MIB = AddDReg(MIB, DestReg, ARM::dsub_2, RegState::Define, TRI); |
| 888 | AddDReg(MIB, DestReg, ARM::dsub_3, RegState::Define, TRI); |
Evan Cheng | 435d499 | 2010-05-07 02:04:02 +0000 | [diff] [blame] | 889 | } |
Bob Wilson | ebe99b2 | 2010-06-18 21:32:42 +0000 | [diff] [blame] | 890 | break; |
| 891 | case ARM::QQQQPRRegClassID: { |
| 892 | MachineInstrBuilder MIB = |
Bill Wendling | 73fe34a | 2010-11-16 01:16:36 +0000 | [diff] [blame] | 893 | AddDefaultPred(BuildMI(MBB, I, DL, get(ARM::VLDMDIA)) |
| 894 | .addFrameIndex(FI)) |
Bob Wilson | ebe99b2 | 2010-06-18 21:32:42 +0000 | [diff] [blame] | 895 | .addMemOperand(MMO); |
| 896 | MIB = AddDReg(MIB, DestReg, ARM::dsub_0, RegState::Define, TRI); |
| 897 | MIB = AddDReg(MIB, DestReg, ARM::dsub_1, RegState::Define, TRI); |
| 898 | MIB = AddDReg(MIB, DestReg, ARM::dsub_2, RegState::Define, TRI); |
| 899 | MIB = AddDReg(MIB, DestReg, ARM::dsub_3, RegState::Define, TRI); |
| 900 | MIB = AddDReg(MIB, DestReg, ARM::dsub_4, RegState::Define, TRI); |
| 901 | MIB = AddDReg(MIB, DestReg, ARM::dsub_5, RegState::Define, TRI); |
| 902 | MIB = AddDReg(MIB, DestReg, ARM::dsub_6, RegState::Define, TRI); |
| 903 | AddDReg(MIB, DestReg, ARM::dsub_7, RegState::Define, TRI); |
| 904 | break; |
| 905 | } |
| 906 | default: |
| 907 | llvm_unreachable("Unknown regclass!"); |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 908 | } |
| 909 | } |
| 910 | |
Jakob Stoklund Olesen | 3432785 | 2010-09-15 16:36:26 +0000 | [diff] [blame] | 911 | unsigned |
| 912 | ARMBaseInstrInfo::isLoadFromStackSlot(const MachineInstr *MI, |
| 913 | int &FrameIndex) const { |
| 914 | switch (MI->getOpcode()) { |
| 915 | default: break; |
Jim Grosbach | 3e55612 | 2010-10-26 22:37:02 +0000 | [diff] [blame] | 916 | case ARM::LDRrs: |
Jakob Stoklund Olesen | 3432785 | 2010-09-15 16:36:26 +0000 | [diff] [blame] | 917 | case ARM::t2LDRs: // FIXME: don't use t2LDRs to access frame. |
| 918 | if (MI->getOperand(1).isFI() && |
| 919 | MI->getOperand(2).isReg() && |
| 920 | MI->getOperand(3).isImm() && |
| 921 | MI->getOperand(2).getReg() == 0 && |
| 922 | MI->getOperand(3).getImm() == 0) { |
| 923 | FrameIndex = MI->getOperand(1).getIndex(); |
| 924 | return MI->getOperand(0).getReg(); |
| 925 | } |
| 926 | break; |
Jim Grosbach | 3e55612 | 2010-10-26 22:37:02 +0000 | [diff] [blame] | 927 | case ARM::LDRi12: |
Jakob Stoklund Olesen | 3432785 | 2010-09-15 16:36:26 +0000 | [diff] [blame] | 928 | case ARM::t2LDRi12: |
| 929 | case ARM::tRestore: |
| 930 | case ARM::VLDRD: |
| 931 | case ARM::VLDRS: |
| 932 | if (MI->getOperand(1).isFI() && |
| 933 | MI->getOperand(2).isImm() && |
| 934 | MI->getOperand(2).getImm() == 0) { |
| 935 | FrameIndex = MI->getOperand(1).getIndex(); |
| 936 | return MI->getOperand(0).getReg(); |
| 937 | } |
| 938 | break; |
Jakob Stoklund Olesen | d64816a | 2010-09-15 17:27:09 +0000 | [diff] [blame] | 939 | case ARM::VLD1q64Pseudo: |
| 940 | if (MI->getOperand(1).isFI() && |
| 941 | MI->getOperand(0).getSubReg() == 0) { |
| 942 | FrameIndex = MI->getOperand(1).getIndex(); |
| 943 | return MI->getOperand(0).getReg(); |
| 944 | } |
| 945 | break; |
Bill Wendling | 73fe34a | 2010-11-16 01:16:36 +0000 | [diff] [blame] | 946 | case ARM::VLDMQIA: |
Jakob Stoklund Olesen | 06f264e | 2010-09-15 21:40:11 +0000 | [diff] [blame] | 947 | if (MI->getOperand(1).isFI() && |
Jakob Stoklund Olesen | 06f264e | 2010-09-15 21:40:11 +0000 | [diff] [blame] | 948 | MI->getOperand(0).getSubReg() == 0) { |
| 949 | FrameIndex = MI->getOperand(1).getIndex(); |
| 950 | return MI->getOperand(0).getReg(); |
| 951 | } |
| 952 | break; |
Jakob Stoklund Olesen | 3432785 | 2010-09-15 16:36:26 +0000 | [diff] [blame] | 953 | } |
| 954 | |
| 955 | return 0; |
| 956 | } |
| 957 | |
Evan Cheng | 62b5065 | 2010-04-26 07:39:25 +0000 | [diff] [blame] | 958 | MachineInstr* |
| 959 | ARMBaseInstrInfo::emitFrameIndexDebugValue(MachineFunction &MF, |
Evan Cheng | 8601a3d | 2010-04-29 01:13:30 +0000 | [diff] [blame] | 960 | int FrameIx, uint64_t Offset, |
Evan Cheng | 62b5065 | 2010-04-26 07:39:25 +0000 | [diff] [blame] | 961 | const MDNode *MDPtr, |
| 962 | DebugLoc DL) const { |
| 963 | MachineInstrBuilder MIB = BuildMI(MF, DL, get(ARM::DBG_VALUE)) |
| 964 | .addFrameIndex(FrameIx).addImm(0).addImm(Offset).addMetadata(MDPtr); |
| 965 | return &*MIB; |
| 966 | } |
| 967 | |
Jakob Stoklund Olesen | 30ac046 | 2010-01-06 23:47:07 +0000 | [diff] [blame] | 968 | /// Create a copy of a const pool value. Update CPI to the new index and return |
| 969 | /// the label UID. |
| 970 | static unsigned duplicateCPV(MachineFunction &MF, unsigned &CPI) { |
| 971 | MachineConstantPool *MCP = MF.getConstantPool(); |
| 972 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
| 973 | |
| 974 | const MachineConstantPoolEntry &MCPE = MCP->getConstants()[CPI]; |
| 975 | assert(MCPE.isMachineConstantPoolEntry() && |
| 976 | "Expecting a machine constantpool entry!"); |
| 977 | ARMConstantPoolValue *ACPV = |
| 978 | static_cast<ARMConstantPoolValue*>(MCPE.Val.MachineCPVal); |
| 979 | |
| 980 | unsigned PCLabelId = AFI->createConstPoolEntryUId(); |
| 981 | ARMConstantPoolValue *NewCPV = 0; |
Jim Grosbach | 51f5b67 | 2010-09-10 21:38:22 +0000 | [diff] [blame] | 982 | // FIXME: The below assumes PIC relocation model and that the function |
| 983 | // is Thumb mode (t1 or t2). PCAdjustment would be 8 for ARM mode PIC, and |
| 984 | // zero for non-PIC in ARM or Thumb. The callers are all of thumb LDR |
| 985 | // instructions, so that's probably OK, but is PIC always correct when |
| 986 | // we get here? |
Jakob Stoklund Olesen | 30ac046 | 2010-01-06 23:47:07 +0000 | [diff] [blame] | 987 | if (ACPV->isGlobalValue()) |
| 988 | NewCPV = new ARMConstantPoolValue(ACPV->getGV(), PCLabelId, |
| 989 | ARMCP::CPValue, 4); |
| 990 | else if (ACPV->isExtSymbol()) |
| 991 | NewCPV = new ARMConstantPoolValue(MF.getFunction()->getContext(), |
| 992 | ACPV->getSymbol(), PCLabelId, 4); |
| 993 | else if (ACPV->isBlockAddress()) |
| 994 | NewCPV = new ARMConstantPoolValue(ACPV->getBlockAddress(), PCLabelId, |
| 995 | ARMCP::CPBlockAddress, 4); |
Jim Grosbach | 51f5b67 | 2010-09-10 21:38:22 +0000 | [diff] [blame] | 996 | else if (ACPV->isLSDA()) |
| 997 | NewCPV = new ARMConstantPoolValue(MF.getFunction(), PCLabelId, |
| 998 | ARMCP::CPLSDA, 4); |
Jakob Stoklund Olesen | 30ac046 | 2010-01-06 23:47:07 +0000 | [diff] [blame] | 999 | else |
| 1000 | llvm_unreachable("Unexpected ARM constantpool value type!!"); |
| 1001 | CPI = MCP->getConstantPoolIndex(NewCPV, MCPE.getAlignment()); |
| 1002 | return PCLabelId; |
| 1003 | } |
| 1004 | |
Evan Cheng | fdc8340 | 2009-11-08 00:15:23 +0000 | [diff] [blame] | 1005 | void ARMBaseInstrInfo:: |
| 1006 | reMaterialize(MachineBasicBlock &MBB, |
| 1007 | MachineBasicBlock::iterator I, |
| 1008 | unsigned DestReg, unsigned SubIdx, |
Evan Cheng | d57cdd5 | 2009-11-14 02:55:43 +0000 | [diff] [blame] | 1009 | const MachineInstr *Orig, |
Jakob Stoklund Olesen | 9edf7de | 2010-06-02 22:47:25 +0000 | [diff] [blame] | 1010 | const TargetRegisterInfo &TRI) const { |
Evan Cheng | fdc8340 | 2009-11-08 00:15:23 +0000 | [diff] [blame] | 1011 | unsigned Opcode = Orig->getOpcode(); |
| 1012 | switch (Opcode) { |
| 1013 | default: { |
| 1014 | MachineInstr *MI = MBB.getParent()->CloneMachineInstr(Orig); |
Jakob Stoklund Olesen | 9edf7de | 2010-06-02 22:47:25 +0000 | [diff] [blame] | 1015 | MI->substituteRegister(Orig->getOperand(0).getReg(), DestReg, SubIdx, TRI); |
Evan Cheng | fdc8340 | 2009-11-08 00:15:23 +0000 | [diff] [blame] | 1016 | MBB.insert(I, MI); |
| 1017 | break; |
| 1018 | } |
| 1019 | case ARM::tLDRpci_pic: |
| 1020 | case ARM::t2LDRpci_pic: { |
| 1021 | MachineFunction &MF = *MBB.getParent(); |
Evan Cheng | fdc8340 | 2009-11-08 00:15:23 +0000 | [diff] [blame] | 1022 | unsigned CPI = Orig->getOperand(1).getIndex(); |
Jakob Stoklund Olesen | 30ac046 | 2010-01-06 23:47:07 +0000 | [diff] [blame] | 1023 | unsigned PCLabelId = duplicateCPV(MF, CPI); |
Evan Cheng | fdc8340 | 2009-11-08 00:15:23 +0000 | [diff] [blame] | 1024 | MachineInstrBuilder MIB = BuildMI(MBB, I, Orig->getDebugLoc(), get(Opcode), |
| 1025 | DestReg) |
| 1026 | .addConstantPoolIndex(CPI).addImm(PCLabelId); |
| 1027 | (*MIB).setMemRefs(Orig->memoperands_begin(), Orig->memoperands_end()); |
| 1028 | break; |
| 1029 | } |
| 1030 | } |
Evan Cheng | fdc8340 | 2009-11-08 00:15:23 +0000 | [diff] [blame] | 1031 | } |
| 1032 | |
Jakob Stoklund Olesen | 30ac046 | 2010-01-06 23:47:07 +0000 | [diff] [blame] | 1033 | MachineInstr * |
| 1034 | ARMBaseInstrInfo::duplicate(MachineInstr *Orig, MachineFunction &MF) const { |
| 1035 | MachineInstr *MI = TargetInstrInfoImpl::duplicate(Orig, MF); |
| 1036 | switch(Orig->getOpcode()) { |
| 1037 | case ARM::tLDRpci_pic: |
| 1038 | case ARM::t2LDRpci_pic: { |
| 1039 | unsigned CPI = Orig->getOperand(1).getIndex(); |
| 1040 | unsigned PCLabelId = duplicateCPV(MF, CPI); |
| 1041 | Orig->getOperand(1).setIndex(CPI); |
| 1042 | Orig->getOperand(2).setImm(PCLabelId); |
| 1043 | break; |
| 1044 | } |
| 1045 | } |
| 1046 | return MI; |
| 1047 | } |
| 1048 | |
Evan Cheng | 506049f | 2010-03-03 01:44:33 +0000 | [diff] [blame] | 1049 | bool ARMBaseInstrInfo::produceSameValue(const MachineInstr *MI0, |
| 1050 | const MachineInstr *MI1) const { |
Evan Cheng | d457e6e | 2009-11-07 04:04:34 +0000 | [diff] [blame] | 1051 | int Opcode = MI0->getOpcode(); |
Evan Cheng | 9b82425 | 2009-11-20 02:10:27 +0000 | [diff] [blame] | 1052 | if (Opcode == ARM::t2LDRpci || |
| 1053 | Opcode == ARM::t2LDRpci_pic || |
| 1054 | Opcode == ARM::tLDRpci || |
| 1055 | Opcode == ARM::tLDRpci_pic) { |
Evan Cheng | d457e6e | 2009-11-07 04:04:34 +0000 | [diff] [blame] | 1056 | if (MI1->getOpcode() != Opcode) |
| 1057 | return false; |
| 1058 | if (MI0->getNumOperands() != MI1->getNumOperands()) |
| 1059 | return false; |
| 1060 | |
| 1061 | const MachineOperand &MO0 = MI0->getOperand(1); |
| 1062 | const MachineOperand &MO1 = MI1->getOperand(1); |
| 1063 | if (MO0.getOffset() != MO1.getOffset()) |
| 1064 | return false; |
| 1065 | |
| 1066 | const MachineFunction *MF = MI0->getParent()->getParent(); |
| 1067 | const MachineConstantPool *MCP = MF->getConstantPool(); |
| 1068 | int CPI0 = MO0.getIndex(); |
| 1069 | int CPI1 = MO1.getIndex(); |
| 1070 | const MachineConstantPoolEntry &MCPE0 = MCP->getConstants()[CPI0]; |
| 1071 | const MachineConstantPoolEntry &MCPE1 = MCP->getConstants()[CPI1]; |
| 1072 | ARMConstantPoolValue *ACPV0 = |
| 1073 | static_cast<ARMConstantPoolValue*>(MCPE0.Val.MachineCPVal); |
| 1074 | ARMConstantPoolValue *ACPV1 = |
| 1075 | static_cast<ARMConstantPoolValue*>(MCPE1.Val.MachineCPVal); |
| 1076 | return ACPV0->hasSameValue(ACPV1); |
| 1077 | } |
| 1078 | |
Evan Cheng | 506049f | 2010-03-03 01:44:33 +0000 | [diff] [blame] | 1079 | return MI0->isIdenticalTo(MI1, MachineInstr::IgnoreVRegDefs); |
Evan Cheng | d457e6e | 2009-11-07 04:04:34 +0000 | [diff] [blame] | 1080 | } |
| 1081 | |
Bill Wendling | 4b72210 | 2010-06-23 23:00:16 +0000 | [diff] [blame] | 1082 | /// areLoadsFromSameBasePtr - This is used by the pre-regalloc scheduler to |
| 1083 | /// determine if two loads are loading from the same base address. It should |
| 1084 | /// only return true if the base pointers are the same and the only differences |
| 1085 | /// between the two addresses is the offset. It also returns the offsets by |
| 1086 | /// reference. |
| 1087 | bool ARMBaseInstrInfo::areLoadsFromSameBasePtr(SDNode *Load1, SDNode *Load2, |
| 1088 | int64_t &Offset1, |
| 1089 | int64_t &Offset2) const { |
| 1090 | // Don't worry about Thumb: just ARM and Thumb2. |
| 1091 | if (Subtarget.isThumb1Only()) return false; |
| 1092 | |
| 1093 | if (!Load1->isMachineOpcode() || !Load2->isMachineOpcode()) |
| 1094 | return false; |
| 1095 | |
| 1096 | switch (Load1->getMachineOpcode()) { |
| 1097 | default: |
| 1098 | return false; |
Jim Grosbach | 3e55612 | 2010-10-26 22:37:02 +0000 | [diff] [blame] | 1099 | case ARM::LDRi12: |
Jim Grosbach | c1d3021 | 2010-10-27 00:19:44 +0000 | [diff] [blame] | 1100 | case ARM::LDRBi12: |
Bill Wendling | 4b72210 | 2010-06-23 23:00:16 +0000 | [diff] [blame] | 1101 | case ARM::LDRD: |
| 1102 | case ARM::LDRH: |
| 1103 | case ARM::LDRSB: |
| 1104 | case ARM::LDRSH: |
| 1105 | case ARM::VLDRD: |
| 1106 | case ARM::VLDRS: |
| 1107 | case ARM::t2LDRi8: |
| 1108 | case ARM::t2LDRDi8: |
| 1109 | case ARM::t2LDRSHi8: |
| 1110 | case ARM::t2LDRi12: |
| 1111 | case ARM::t2LDRSHi12: |
| 1112 | break; |
| 1113 | } |
| 1114 | |
| 1115 | switch (Load2->getMachineOpcode()) { |
| 1116 | default: |
| 1117 | return false; |
Jim Grosbach | 3e55612 | 2010-10-26 22:37:02 +0000 | [diff] [blame] | 1118 | case ARM::LDRi12: |
Jim Grosbach | c1d3021 | 2010-10-27 00:19:44 +0000 | [diff] [blame] | 1119 | case ARM::LDRBi12: |
Bill Wendling | 4b72210 | 2010-06-23 23:00:16 +0000 | [diff] [blame] | 1120 | case ARM::LDRD: |
| 1121 | case ARM::LDRH: |
| 1122 | case ARM::LDRSB: |
| 1123 | case ARM::LDRSH: |
| 1124 | case ARM::VLDRD: |
| 1125 | case ARM::VLDRS: |
| 1126 | case ARM::t2LDRi8: |
| 1127 | case ARM::t2LDRDi8: |
| 1128 | case ARM::t2LDRSHi8: |
| 1129 | case ARM::t2LDRi12: |
| 1130 | case ARM::t2LDRSHi12: |
| 1131 | break; |
| 1132 | } |
| 1133 | |
| 1134 | // Check if base addresses and chain operands match. |
| 1135 | if (Load1->getOperand(0) != Load2->getOperand(0) || |
| 1136 | Load1->getOperand(4) != Load2->getOperand(4)) |
| 1137 | return false; |
| 1138 | |
| 1139 | // Index should be Reg0. |
| 1140 | if (Load1->getOperand(3) != Load2->getOperand(3)) |
| 1141 | return false; |
| 1142 | |
| 1143 | // Determine the offsets. |
| 1144 | if (isa<ConstantSDNode>(Load1->getOperand(1)) && |
| 1145 | isa<ConstantSDNode>(Load2->getOperand(1))) { |
| 1146 | Offset1 = cast<ConstantSDNode>(Load1->getOperand(1))->getSExtValue(); |
| 1147 | Offset2 = cast<ConstantSDNode>(Load2->getOperand(1))->getSExtValue(); |
| 1148 | return true; |
| 1149 | } |
| 1150 | |
| 1151 | return false; |
| 1152 | } |
| 1153 | |
| 1154 | /// shouldScheduleLoadsNear - This is a used by the pre-regalloc scheduler to |
| 1155 | /// determine (in conjuction with areLoadsFromSameBasePtr) if two loads should |
| 1156 | /// be scheduled togther. On some targets if two loads are loading from |
| 1157 | /// addresses in the same cache line, it's better if they are scheduled |
| 1158 | /// together. This function takes two integers that represent the load offsets |
| 1159 | /// from the common base address. It returns true if it decides it's desirable |
| 1160 | /// to schedule the two loads together. "NumLoads" is the number of loads that |
| 1161 | /// have already been scheduled after Load1. |
| 1162 | bool ARMBaseInstrInfo::shouldScheduleLoadsNear(SDNode *Load1, SDNode *Load2, |
| 1163 | int64_t Offset1, int64_t Offset2, |
| 1164 | unsigned NumLoads) const { |
| 1165 | // Don't worry about Thumb: just ARM and Thumb2. |
| 1166 | if (Subtarget.isThumb1Only()) return false; |
| 1167 | |
| 1168 | assert(Offset2 > Offset1); |
| 1169 | |
| 1170 | if ((Offset2 - Offset1) / 8 > 64) |
| 1171 | return false; |
| 1172 | |
| 1173 | if (Load1->getMachineOpcode() != Load2->getMachineOpcode()) |
| 1174 | return false; // FIXME: overly conservative? |
| 1175 | |
| 1176 | // Four loads in a row should be sufficient. |
| 1177 | if (NumLoads >= 3) |
| 1178 | return false; |
| 1179 | |
| 1180 | return true; |
| 1181 | } |
| 1182 | |
Evan Cheng | 86050dc | 2010-06-18 23:09:54 +0000 | [diff] [blame] | 1183 | bool ARMBaseInstrInfo::isSchedulingBoundary(const MachineInstr *MI, |
| 1184 | const MachineBasicBlock *MBB, |
| 1185 | const MachineFunction &MF) const { |
Jim Grosbach | 57bb394 | 2010-06-25 18:43:14 +0000 | [diff] [blame] | 1186 | // Debug info is never a scheduling boundary. It's necessary to be explicit |
| 1187 | // due to the special treatment of IT instructions below, otherwise a |
| 1188 | // dbg_value followed by an IT will result in the IT instruction being |
| 1189 | // considered a scheduling hazard, which is wrong. It should be the actual |
| 1190 | // instruction preceding the dbg_value instruction(s), just like it is |
| 1191 | // when debug info is not present. |
| 1192 | if (MI->isDebugValue()) |
| 1193 | return false; |
| 1194 | |
Evan Cheng | 86050dc | 2010-06-18 23:09:54 +0000 | [diff] [blame] | 1195 | // Terminators and labels can't be scheduled around. |
| 1196 | if (MI->getDesc().isTerminator() || MI->isLabel()) |
| 1197 | return true; |
| 1198 | |
| 1199 | // Treat the start of the IT block as a scheduling boundary, but schedule |
| 1200 | // t2IT along with all instructions following it. |
| 1201 | // FIXME: This is a big hammer. But the alternative is to add all potential |
| 1202 | // true and anti dependencies to IT block instructions as implicit operands |
| 1203 | // to the t2IT instruction. The added compile time and complexity does not |
| 1204 | // seem worth it. |
| 1205 | MachineBasicBlock::const_iterator I = MI; |
Jim Grosbach | 57bb394 | 2010-06-25 18:43:14 +0000 | [diff] [blame] | 1206 | // Make sure to skip any dbg_value instructions |
| 1207 | while (++I != MBB->end() && I->isDebugValue()) |
| 1208 | ; |
| 1209 | if (I != MBB->end() && I->getOpcode() == ARM::t2IT) |
Evan Cheng | 86050dc | 2010-06-18 23:09:54 +0000 | [diff] [blame] | 1210 | return true; |
| 1211 | |
| 1212 | // Don't attempt to schedule around any instruction that defines |
| 1213 | // a stack-oriented pointer, as it's unlikely to be profitable. This |
| 1214 | // saves compile time, because it doesn't require every single |
| 1215 | // stack slot reference to depend on the instruction that does the |
| 1216 | // modification. |
| 1217 | if (MI->definesRegister(ARM::SP)) |
| 1218 | return true; |
| 1219 | |
| 1220 | return false; |
| 1221 | } |
| 1222 | |
Owen Anderson | b20b851 | 2010-09-28 18:32:13 +0000 | [diff] [blame] | 1223 | bool ARMBaseInstrInfo::isProfitableToIfCvt(MachineBasicBlock &MBB, |
Evan Cheng | 8239daf | 2010-11-03 00:45:17 +0000 | [diff] [blame] | 1224 | unsigned NumCyles, |
| 1225 | unsigned ExtraPredCycles, |
Owen Anderson | e3cc84a | 2010-10-01 22:45:50 +0000 | [diff] [blame] | 1226 | float Probability, |
| 1227 | float Confidence) const { |
Evan Cheng | 8239daf | 2010-11-03 00:45:17 +0000 | [diff] [blame] | 1228 | if (!NumCyles) |
Evan Cheng | 1315143 | 2010-06-25 22:42:03 +0000 | [diff] [blame] | 1229 | return false; |
Michael J. Spencer | 2bbb769 | 2010-10-05 06:00:33 +0000 | [diff] [blame] | 1230 | |
Owen Anderson | b20b851 | 2010-09-28 18:32:13 +0000 | [diff] [blame] | 1231 | // Attempt to estimate the relative costs of predication versus branching. |
Evan Cheng | 8239daf | 2010-11-03 00:45:17 +0000 | [diff] [blame] | 1232 | float UnpredCost = Probability * NumCyles; |
Owen Anderson | 654d544 | 2010-09-28 21:57:50 +0000 | [diff] [blame] | 1233 | UnpredCost += 1.0; // The branch itself |
Owen Anderson | e3cc84a | 2010-10-01 22:45:50 +0000 | [diff] [blame] | 1234 | UnpredCost += (1.0 - Confidence) * Subtarget.getMispredictionPenalty(); |
Michael J. Spencer | 2bbb769 | 2010-10-05 06:00:33 +0000 | [diff] [blame] | 1235 | |
Evan Cheng | 8239daf | 2010-11-03 00:45:17 +0000 | [diff] [blame] | 1236 | return (float)(NumCyles + ExtraPredCycles) < UnpredCost; |
Evan Cheng | 1315143 | 2010-06-25 22:42:03 +0000 | [diff] [blame] | 1237 | } |
Michael J. Spencer | 2bbb769 | 2010-10-05 06:00:33 +0000 | [diff] [blame] | 1238 | |
Evan Cheng | 1315143 | 2010-06-25 22:42:03 +0000 | [diff] [blame] | 1239 | bool ARMBaseInstrInfo:: |
Evan Cheng | 8239daf | 2010-11-03 00:45:17 +0000 | [diff] [blame] | 1240 | isProfitableToIfCvt(MachineBasicBlock &TMBB, |
| 1241 | unsigned TCycles, unsigned TExtra, |
| 1242 | MachineBasicBlock &FMBB, |
| 1243 | unsigned FCycles, unsigned FExtra, |
Owen Anderson | e3cc84a | 2010-10-01 22:45:50 +0000 | [diff] [blame] | 1244 | float Probability, float Confidence) const { |
Evan Cheng | 8239daf | 2010-11-03 00:45:17 +0000 | [diff] [blame] | 1245 | if (!TCycles || !FCycles) |
Owen Anderson | b20b851 | 2010-09-28 18:32:13 +0000 | [diff] [blame] | 1246 | return false; |
Michael J. Spencer | 2bbb769 | 2010-10-05 06:00:33 +0000 | [diff] [blame] | 1247 | |
Owen Anderson | b20b851 | 2010-09-28 18:32:13 +0000 | [diff] [blame] | 1248 | // Attempt to estimate the relative costs of predication versus branching. |
Evan Cheng | 8239daf | 2010-11-03 00:45:17 +0000 | [diff] [blame] | 1249 | float UnpredCost = Probability * TCycles + (1.0 - Probability) * FCycles; |
Owen Anderson | 654d544 | 2010-09-28 21:57:50 +0000 | [diff] [blame] | 1250 | UnpredCost += 1.0; // The branch itself |
Owen Anderson | e3cc84a | 2010-10-01 22:45:50 +0000 | [diff] [blame] | 1251 | UnpredCost += (1.0 - Confidence) * Subtarget.getMispredictionPenalty(); |
Michael J. Spencer | 2bbb769 | 2010-10-05 06:00:33 +0000 | [diff] [blame] | 1252 | |
Evan Cheng | 8239daf | 2010-11-03 00:45:17 +0000 | [diff] [blame] | 1253 | return (float)(TCycles + FCycles + TExtra + FExtra) < UnpredCost; |
Evan Cheng | 1315143 | 2010-06-25 22:42:03 +0000 | [diff] [blame] | 1254 | } |
| 1255 | |
Evan Cheng | 8fb9036 | 2009-08-08 03:20:32 +0000 | [diff] [blame] | 1256 | /// getInstrPredicate - If instruction is predicated, returns its predicate |
| 1257 | /// condition, otherwise returns AL. It also returns the condition code |
| 1258 | /// register by reference. |
Evan Cheng | 5adb66a | 2009-09-28 09:14:39 +0000 | [diff] [blame] | 1259 | ARMCC::CondCodes |
| 1260 | llvm::getInstrPredicate(const MachineInstr *MI, unsigned &PredReg) { |
Evan Cheng | 8fb9036 | 2009-08-08 03:20:32 +0000 | [diff] [blame] | 1261 | int PIdx = MI->findFirstPredOperandIdx(); |
| 1262 | if (PIdx == -1) { |
| 1263 | PredReg = 0; |
| 1264 | return ARMCC::AL; |
| 1265 | } |
| 1266 | |
| 1267 | PredReg = MI->getOperand(PIdx+1).getReg(); |
| 1268 | return (ARMCC::CondCodes)MI->getOperand(PIdx).getImm(); |
| 1269 | } |
| 1270 | |
| 1271 | |
Evan Cheng | 6495f63 | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 1272 | int llvm::getMatchingCondBranchOpcode(int Opc) { |
Evan Cheng | 5ca53a7 | 2009-07-27 18:20:05 +0000 | [diff] [blame] | 1273 | if (Opc == ARM::B) |
| 1274 | return ARM::Bcc; |
| 1275 | else if (Opc == ARM::tB) |
| 1276 | return ARM::tBcc; |
| 1277 | else if (Opc == ARM::t2B) |
| 1278 | return ARM::t2Bcc; |
| 1279 | |
| 1280 | llvm_unreachable("Unknown unconditional branch opcode!"); |
| 1281 | return 0; |
| 1282 | } |
| 1283 | |
Evan Cheng | 6495f63 | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 1284 | |
| 1285 | void llvm::emitARMRegPlusImmediate(MachineBasicBlock &MBB, |
| 1286 | MachineBasicBlock::iterator &MBBI, DebugLoc dl, |
| 1287 | unsigned DestReg, unsigned BaseReg, int NumBytes, |
| 1288 | ARMCC::CondCodes Pred, unsigned PredReg, |
| 1289 | const ARMBaseInstrInfo &TII) { |
| 1290 | bool isSub = NumBytes < 0; |
| 1291 | if (isSub) NumBytes = -NumBytes; |
| 1292 | |
| 1293 | while (NumBytes) { |
| 1294 | unsigned RotAmt = ARM_AM::getSOImmValRotate(NumBytes); |
| 1295 | unsigned ThisVal = NumBytes & ARM_AM::rotr32(0xFF, RotAmt); |
| 1296 | assert(ThisVal && "Didn't extract field correctly"); |
| 1297 | |
| 1298 | // We will handle these bits from offset, clear them. |
| 1299 | NumBytes &= ~ThisVal; |
| 1300 | |
| 1301 | assert(ARM_AM::getSOImmVal(ThisVal) != -1 && "Bit extraction didn't work?"); |
| 1302 | |
| 1303 | // Build the new ADD / SUB. |
| 1304 | unsigned Opc = isSub ? ARM::SUBri : ARM::ADDri; |
| 1305 | BuildMI(MBB, MBBI, dl, TII.get(Opc), DestReg) |
| 1306 | .addReg(BaseReg, RegState::Kill).addImm(ThisVal) |
| 1307 | .addImm((unsigned)Pred).addReg(PredReg).addReg(0); |
| 1308 | BaseReg = DestReg; |
| 1309 | } |
| 1310 | } |
| 1311 | |
Evan Cheng | cdbb3f5 | 2009-08-27 01:23:50 +0000 | [diff] [blame] | 1312 | bool llvm::rewriteARMFrameIndex(MachineInstr &MI, unsigned FrameRegIdx, |
| 1313 | unsigned FrameReg, int &Offset, |
| 1314 | const ARMBaseInstrInfo &TII) { |
Evan Cheng | 6495f63 | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 1315 | unsigned Opcode = MI.getOpcode(); |
| 1316 | const TargetInstrDesc &Desc = MI.getDesc(); |
| 1317 | unsigned AddrMode = (Desc.TSFlags & ARMII::AddrModeMask); |
| 1318 | bool isSub = false; |
Jim Grosbach | 764ab52 | 2009-08-11 15:33:49 +0000 | [diff] [blame] | 1319 | |
Evan Cheng | 6495f63 | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 1320 | // Memory operands in inline assembly always use AddrMode2. |
| 1321 | if (Opcode == ARM::INLINEASM) |
| 1322 | AddrMode = ARMII::AddrMode2; |
Jim Grosbach | 764ab52 | 2009-08-11 15:33:49 +0000 | [diff] [blame] | 1323 | |
Evan Cheng | 6495f63 | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 1324 | if (Opcode == ARM::ADDri) { |
| 1325 | Offset += MI.getOperand(FrameRegIdx+1).getImm(); |
| 1326 | if (Offset == 0) { |
| 1327 | // Turn it into a move. |
| 1328 | MI.setDesc(TII.get(ARM::MOVr)); |
| 1329 | MI.getOperand(FrameRegIdx).ChangeToRegister(FrameReg, false); |
| 1330 | MI.RemoveOperand(FrameRegIdx+1); |
Evan Cheng | cdbb3f5 | 2009-08-27 01:23:50 +0000 | [diff] [blame] | 1331 | Offset = 0; |
| 1332 | return true; |
Evan Cheng | 6495f63 | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 1333 | } else if (Offset < 0) { |
| 1334 | Offset = -Offset; |
| 1335 | isSub = true; |
| 1336 | MI.setDesc(TII.get(ARM::SUBri)); |
| 1337 | } |
| 1338 | |
| 1339 | // Common case: small offset, fits into instruction. |
| 1340 | if (ARM_AM::getSOImmVal(Offset) != -1) { |
| 1341 | // Replace the FrameIndex with sp / fp |
| 1342 | MI.getOperand(FrameRegIdx).ChangeToRegister(FrameReg, false); |
| 1343 | MI.getOperand(FrameRegIdx+1).ChangeToImmediate(Offset); |
Evan Cheng | cdbb3f5 | 2009-08-27 01:23:50 +0000 | [diff] [blame] | 1344 | Offset = 0; |
| 1345 | return true; |
Evan Cheng | 6495f63 | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 1346 | } |
| 1347 | |
| 1348 | // Otherwise, pull as much of the immedidate into this ADDri/SUBri |
| 1349 | // as possible. |
| 1350 | unsigned RotAmt = ARM_AM::getSOImmValRotate(Offset); |
| 1351 | unsigned ThisImmVal = Offset & ARM_AM::rotr32(0xFF, RotAmt); |
| 1352 | |
| 1353 | // We will handle these bits from offset, clear them. |
| 1354 | Offset &= ~ThisImmVal; |
| 1355 | |
| 1356 | // Get the properly encoded SOImmVal field. |
| 1357 | assert(ARM_AM::getSOImmVal(ThisImmVal) != -1 && |
| 1358 | "Bit extraction didn't work?"); |
| 1359 | MI.getOperand(FrameRegIdx+1).ChangeToImmediate(ThisImmVal); |
| 1360 | } else { |
| 1361 | unsigned ImmIdx = 0; |
| 1362 | int InstrOffs = 0; |
| 1363 | unsigned NumBits = 0; |
| 1364 | unsigned Scale = 1; |
| 1365 | switch (AddrMode) { |
Jim Grosbach | 3e55612 | 2010-10-26 22:37:02 +0000 | [diff] [blame] | 1366 | case ARMII::AddrMode_i12: { |
| 1367 | ImmIdx = FrameRegIdx + 1; |
| 1368 | InstrOffs = MI.getOperand(ImmIdx).getImm(); |
| 1369 | NumBits = 12; |
| 1370 | break; |
| 1371 | } |
Evan Cheng | 6495f63 | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 1372 | case ARMII::AddrMode2: { |
| 1373 | ImmIdx = FrameRegIdx+2; |
| 1374 | InstrOffs = ARM_AM::getAM2Offset(MI.getOperand(ImmIdx).getImm()); |
| 1375 | if (ARM_AM::getAM2Op(MI.getOperand(ImmIdx).getImm()) == ARM_AM::sub) |
| 1376 | InstrOffs *= -1; |
| 1377 | NumBits = 12; |
| 1378 | break; |
| 1379 | } |
| 1380 | case ARMII::AddrMode3: { |
| 1381 | ImmIdx = FrameRegIdx+2; |
| 1382 | InstrOffs = ARM_AM::getAM3Offset(MI.getOperand(ImmIdx).getImm()); |
| 1383 | if (ARM_AM::getAM3Op(MI.getOperand(ImmIdx).getImm()) == ARM_AM::sub) |
| 1384 | InstrOffs *= -1; |
| 1385 | NumBits = 8; |
| 1386 | break; |
| 1387 | } |
Anton Korobeynikov | baf3108 | 2009-08-08 13:35:48 +0000 | [diff] [blame] | 1388 | case ARMII::AddrMode4: |
Jim Grosbach | a443217 | 2009-11-15 21:45:34 +0000 | [diff] [blame] | 1389 | case ARMII::AddrMode6: |
Evan Cheng | cdbb3f5 | 2009-08-27 01:23:50 +0000 | [diff] [blame] | 1390 | // Can't fold any offset even if it's zero. |
| 1391 | return false; |
Evan Cheng | 6495f63 | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 1392 | case ARMII::AddrMode5: { |
| 1393 | ImmIdx = FrameRegIdx+1; |
| 1394 | InstrOffs = ARM_AM::getAM5Offset(MI.getOperand(ImmIdx).getImm()); |
| 1395 | if (ARM_AM::getAM5Op(MI.getOperand(ImmIdx).getImm()) == ARM_AM::sub) |
| 1396 | InstrOffs *= -1; |
| 1397 | NumBits = 8; |
| 1398 | Scale = 4; |
| 1399 | break; |
| 1400 | } |
| 1401 | default: |
| 1402 | llvm_unreachable("Unsupported addressing mode!"); |
| 1403 | break; |
| 1404 | } |
| 1405 | |
| 1406 | Offset += InstrOffs * Scale; |
| 1407 | assert((Offset & (Scale-1)) == 0 && "Can't encode this offset!"); |
| 1408 | if (Offset < 0) { |
| 1409 | Offset = -Offset; |
| 1410 | isSub = true; |
| 1411 | } |
| 1412 | |
| 1413 | // Attempt to fold address comp. if opcode has offset bits |
| 1414 | if (NumBits > 0) { |
| 1415 | // Common case: small offset, fits into instruction. |
| 1416 | MachineOperand &ImmOp = MI.getOperand(ImmIdx); |
| 1417 | int ImmedOffset = Offset / Scale; |
| 1418 | unsigned Mask = (1 << NumBits) - 1; |
| 1419 | if ((unsigned)Offset <= Mask * Scale) { |
| 1420 | // Replace the FrameIndex with sp |
| 1421 | MI.getOperand(FrameRegIdx).ChangeToRegister(FrameReg, false); |
Jim Grosbach | 77aee8e | 2010-10-27 01:19:41 +0000 | [diff] [blame] | 1422 | // FIXME: When addrmode2 goes away, this will simplify (like the |
| 1423 | // T2 version), as the LDR.i12 versions don't need the encoding |
| 1424 | // tricks for the offset value. |
| 1425 | if (isSub) { |
| 1426 | if (AddrMode == ARMII::AddrMode_i12) |
| 1427 | ImmedOffset = -ImmedOffset; |
| 1428 | else |
| 1429 | ImmedOffset |= 1 << NumBits; |
| 1430 | } |
Evan Cheng | 6495f63 | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 1431 | ImmOp.ChangeToImmediate(ImmedOffset); |
Evan Cheng | cdbb3f5 | 2009-08-27 01:23:50 +0000 | [diff] [blame] | 1432 | Offset = 0; |
| 1433 | return true; |
Evan Cheng | 6495f63 | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 1434 | } |
Jim Grosbach | 764ab52 | 2009-08-11 15:33:49 +0000 | [diff] [blame] | 1435 | |
Evan Cheng | 6495f63 | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 1436 | // Otherwise, it didn't fit. Pull in what we can to simplify the immed. |
| 1437 | ImmedOffset = ImmedOffset & Mask; |
Jim Grosbach | 063efbf | 2010-10-27 16:50:31 +0000 | [diff] [blame] | 1438 | if (isSub) { |
| 1439 | if (AddrMode == ARMII::AddrMode_i12) |
| 1440 | ImmedOffset = -ImmedOffset; |
| 1441 | else |
| 1442 | ImmedOffset |= 1 << NumBits; |
| 1443 | } |
Evan Cheng | 6495f63 | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 1444 | ImmOp.ChangeToImmediate(ImmedOffset); |
| 1445 | Offset &= ~(Mask*Scale); |
| 1446 | } |
| 1447 | } |
| 1448 | |
Evan Cheng | cdbb3f5 | 2009-08-27 01:23:50 +0000 | [diff] [blame] | 1449 | Offset = (isSub) ? -Offset : Offset; |
| 1450 | return Offset == 0; |
Evan Cheng | 6495f63 | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 1451 | } |
Bill Wendling | e4ddbdf | 2010-08-06 01:32:48 +0000 | [diff] [blame] | 1452 | |
| 1453 | bool ARMBaseInstrInfo:: |
Eric Christopher | a99c3e9 | 2010-09-28 04:18:29 +0000 | [diff] [blame] | 1454 | AnalyzeCompare(const MachineInstr *MI, unsigned &SrcReg, int &CmpMask, |
| 1455 | int &CmpValue) const { |
Bill Wendling | e4ddbdf | 2010-08-06 01:32:48 +0000 | [diff] [blame] | 1456 | switch (MI->getOpcode()) { |
| 1457 | default: break; |
Bill Wendling | 38ae997 | 2010-08-11 00:23:00 +0000 | [diff] [blame] | 1458 | case ARM::CMPri: |
Bill Wendling | e4ddbdf | 2010-08-06 01:32:48 +0000 | [diff] [blame] | 1459 | case ARM::t2CMPri: |
Bill Wendling | e4ddbdf | 2010-08-06 01:32:48 +0000 | [diff] [blame] | 1460 | SrcReg = MI->getOperand(0).getReg(); |
Gabor Greif | 04ac81d | 2010-09-21 12:01:15 +0000 | [diff] [blame] | 1461 | CmpMask = ~0; |
Bill Wendling | e4ddbdf | 2010-08-06 01:32:48 +0000 | [diff] [blame] | 1462 | CmpValue = MI->getOperand(1).getImm(); |
| 1463 | return true; |
Gabor Greif | 04ac81d | 2010-09-21 12:01:15 +0000 | [diff] [blame] | 1464 | case ARM::TSTri: |
| 1465 | case ARM::t2TSTri: |
| 1466 | SrcReg = MI->getOperand(0).getReg(); |
| 1467 | CmpMask = MI->getOperand(1).getImm(); |
| 1468 | CmpValue = 0; |
| 1469 | return true; |
| 1470 | } |
| 1471 | |
| 1472 | return false; |
| 1473 | } |
| 1474 | |
Gabor Greif | 05642a3 | 2010-09-29 10:12:08 +0000 | [diff] [blame] | 1475 | /// isSuitableForMask - Identify a suitable 'and' instruction that |
| 1476 | /// operates on the given source register and applies the same mask |
| 1477 | /// as a 'tst' instruction. Provide a limited look-through for copies. |
| 1478 | /// When successful, MI will hold the found instruction. |
| 1479 | static bool isSuitableForMask(MachineInstr *&MI, unsigned SrcReg, |
Gabor Greif | 8ff9bb1 | 2010-09-21 13:30:57 +0000 | [diff] [blame] | 1480 | int CmpMask, bool CommonUse) { |
Gabor Greif | 05642a3 | 2010-09-29 10:12:08 +0000 | [diff] [blame] | 1481 | switch (MI->getOpcode()) { |
Gabor Greif | 04ac81d | 2010-09-21 12:01:15 +0000 | [diff] [blame] | 1482 | case ARM::ANDri: |
| 1483 | case ARM::t2ANDri: |
Gabor Greif | 05642a3 | 2010-09-29 10:12:08 +0000 | [diff] [blame] | 1484 | if (CmpMask != MI->getOperand(2).getImm()) |
Gabor Greif | 8ff9bb1 | 2010-09-21 13:30:57 +0000 | [diff] [blame] | 1485 | return false; |
Gabor Greif | 05642a3 | 2010-09-29 10:12:08 +0000 | [diff] [blame] | 1486 | if (SrcReg == MI->getOperand(CommonUse ? 1 : 0).getReg()) |
Gabor Greif | 04ac81d | 2010-09-21 12:01:15 +0000 | [diff] [blame] | 1487 | return true; |
| 1488 | break; |
Gabor Greif | 05642a3 | 2010-09-29 10:12:08 +0000 | [diff] [blame] | 1489 | case ARM::COPY: { |
| 1490 | // Walk down one instruction which is potentially an 'and'. |
| 1491 | const MachineInstr &Copy = *MI; |
Michael J. Spencer | f000a7a | 2010-10-05 06:00:43 +0000 | [diff] [blame] | 1492 | MachineBasicBlock::iterator AND( |
| 1493 | llvm::next(MachineBasicBlock::iterator(MI))); |
Gabor Greif | 05642a3 | 2010-09-29 10:12:08 +0000 | [diff] [blame] | 1494 | if (AND == MI->getParent()->end()) return false; |
| 1495 | MI = AND; |
| 1496 | return isSuitableForMask(MI, Copy.getOperand(0).getReg(), |
| 1497 | CmpMask, true); |
| 1498 | } |
Bill Wendling | e4ddbdf | 2010-08-06 01:32:48 +0000 | [diff] [blame] | 1499 | } |
| 1500 | |
| 1501 | return false; |
| 1502 | } |
| 1503 | |
Bill Wendling | a655686 | 2010-09-11 00:13:50 +0000 | [diff] [blame] | 1504 | /// OptimizeCompareInstr - Convert the instruction supplying the argument to the |
Evan Cheng | eb96a2f | 2010-11-15 21:20:45 +0000 | [diff] [blame] | 1505 | /// comparison into one that sets the zero bit in the flags register. |
Bill Wendling | e4ddbdf | 2010-08-06 01:32:48 +0000 | [diff] [blame] | 1506 | bool ARMBaseInstrInfo:: |
Gabor Greif | 04ac81d | 2010-09-21 12:01:15 +0000 | [diff] [blame] | 1507 | OptimizeCompareInstr(MachineInstr *CmpInstr, unsigned SrcReg, int CmpMask, |
Evan Cheng | eb96a2f | 2010-11-15 21:20:45 +0000 | [diff] [blame] | 1508 | int CmpValue, const MachineRegisterInfo *MRI) const { |
Bill Wendling | 3665661 | 2010-09-10 23:46:12 +0000 | [diff] [blame] | 1509 | if (CmpValue != 0) |
Bill Wendling | 92ad57f | 2010-09-10 23:34:19 +0000 | [diff] [blame] | 1510 | return false; |
| 1511 | |
Bill Wendling | b41ee96 | 2010-10-18 21:22:31 +0000 | [diff] [blame] | 1512 | MachineRegisterInfo::def_iterator DI = MRI->def_begin(SrcReg); |
| 1513 | if (llvm::next(DI) != MRI->def_end()) |
Bill Wendling | 92ad57f | 2010-09-10 23:34:19 +0000 | [diff] [blame] | 1514 | // Only support one definition. |
| 1515 | return false; |
| 1516 | |
| 1517 | MachineInstr *MI = &*DI; |
| 1518 | |
Gabor Greif | 04ac81d | 2010-09-21 12:01:15 +0000 | [diff] [blame] | 1519 | // Masked compares sometimes use the same register as the corresponding 'and'. |
| 1520 | if (CmpMask != ~0) { |
Gabor Greif | 05642a3 | 2010-09-29 10:12:08 +0000 | [diff] [blame] | 1521 | if (!isSuitableForMask(MI, SrcReg, CmpMask, false)) { |
Gabor Greif | 04ac81d | 2010-09-21 12:01:15 +0000 | [diff] [blame] | 1522 | MI = 0; |
Bill Wendling | b41ee96 | 2010-10-18 21:22:31 +0000 | [diff] [blame] | 1523 | for (MachineRegisterInfo::use_iterator UI = MRI->use_begin(SrcReg), |
| 1524 | UE = MRI->use_end(); UI != UE; ++UI) { |
Gabor Greif | 04ac81d | 2010-09-21 12:01:15 +0000 | [diff] [blame] | 1525 | if (UI->getParent() != CmpInstr->getParent()) continue; |
Gabor Greif | 05642a3 | 2010-09-29 10:12:08 +0000 | [diff] [blame] | 1526 | MachineInstr *PotentialAND = &*UI; |
Gabor Greif | 8ff9bb1 | 2010-09-21 13:30:57 +0000 | [diff] [blame] | 1527 | if (!isSuitableForMask(PotentialAND, SrcReg, CmpMask, true)) |
Gabor Greif | 04ac81d | 2010-09-21 12:01:15 +0000 | [diff] [blame] | 1528 | continue; |
Gabor Greif | 05642a3 | 2010-09-29 10:12:08 +0000 | [diff] [blame] | 1529 | MI = PotentialAND; |
Gabor Greif | 04ac81d | 2010-09-21 12:01:15 +0000 | [diff] [blame] | 1530 | break; |
| 1531 | } |
| 1532 | if (!MI) return false; |
| 1533 | } |
| 1534 | } |
| 1535 | |
Bill Wendling | e4ddbdf | 2010-08-06 01:32:48 +0000 | [diff] [blame] | 1536 | // Conservatively refuse to convert an instruction which isn't in the same BB |
| 1537 | // as the comparison. |
| 1538 | if (MI->getParent() != CmpInstr->getParent()) |
| 1539 | return false; |
| 1540 | |
| 1541 | // Check that CPSR isn't set between the comparison instruction and the one we |
| 1542 | // want to change. |
Evan Cheng | 691e64a | 2010-09-21 23:49:07 +0000 | [diff] [blame] | 1543 | MachineBasicBlock::const_iterator I = CmpInstr, E = MI, |
| 1544 | B = MI->getParent()->begin(); |
Bill Wendling | 0aa38b9 | 2010-10-09 00:03:48 +0000 | [diff] [blame] | 1545 | |
| 1546 | // Early exit if CmpInstr is at the beginning of the BB. |
| 1547 | if (I == B) return false; |
| 1548 | |
Bill Wendling | e4ddbdf | 2010-08-06 01:32:48 +0000 | [diff] [blame] | 1549 | --I; |
| 1550 | for (; I != E; --I) { |
| 1551 | const MachineInstr &Instr = *I; |
| 1552 | |
| 1553 | for (unsigned IO = 0, EO = Instr.getNumOperands(); IO != EO; ++IO) { |
| 1554 | const MachineOperand &MO = Instr.getOperand(IO); |
Bill Wendling | 40a5eb1 | 2010-11-01 20:41:43 +0000 | [diff] [blame] | 1555 | if (!MO.isReg()) continue; |
Bill Wendling | e4ddbdf | 2010-08-06 01:32:48 +0000 | [diff] [blame] | 1556 | |
Bill Wendling | 40a5eb1 | 2010-11-01 20:41:43 +0000 | [diff] [blame] | 1557 | // This instruction modifies or uses CPSR after the one we want to |
| 1558 | // change. We can't do this transformation. |
Bill Wendling | e4ddbdf | 2010-08-06 01:32:48 +0000 | [diff] [blame] | 1559 | if (MO.getReg() == ARM::CPSR) |
| 1560 | return false; |
| 1561 | } |
Evan Cheng | 691e64a | 2010-09-21 23:49:07 +0000 | [diff] [blame] | 1562 | |
| 1563 | if (I == B) |
| 1564 | // The 'and' is below the comparison instruction. |
| 1565 | return false; |
Bill Wendling | e4ddbdf | 2010-08-06 01:32:48 +0000 | [diff] [blame] | 1566 | } |
| 1567 | |
| 1568 | // Set the "zero" bit in CPSR. |
| 1569 | switch (MI->getOpcode()) { |
| 1570 | default: break; |
Bill Wendling | 38ae997 | 2010-08-11 00:23:00 +0000 | [diff] [blame] | 1571 | case ARM::ADDri: |
Bob Wilson | 3a95182 | 2010-09-15 17:12:08 +0000 | [diff] [blame] | 1572 | case ARM::ANDri: |
| 1573 | case ARM::t2ANDri: |
Bill Wendling | 38ae997 | 2010-08-11 00:23:00 +0000 | [diff] [blame] | 1574 | case ARM::SUBri: |
| 1575 | case ARM::t2ADDri: |
Bill Wendling | ad42271 | 2010-08-18 21:32:07 +0000 | [diff] [blame] | 1576 | case ARM::t2SUBri: |
Evan Cheng | 3642e64 | 2010-11-17 08:06:50 +0000 | [diff] [blame] | 1577 | // Toggle the optional operand to CPSR. |
| 1578 | MI->getOperand(5).setReg(ARM::CPSR); |
| 1579 | MI->getOperand(5).setIsDef(true); |
Bill Wendling | e4ddbdf | 2010-08-06 01:32:48 +0000 | [diff] [blame] | 1580 | CmpInstr->eraseFromParent(); |
| 1581 | return true; |
| 1582 | } |
Bill Wendling | e4ddbdf | 2010-08-06 01:32:48 +0000 | [diff] [blame] | 1583 | |
| 1584 | return false; |
| 1585 | } |
Evan Cheng | 5f54ce3 | 2010-09-09 18:18:55 +0000 | [diff] [blame] | 1586 | |
Evan Cheng | c4af463 | 2010-11-17 20:13:28 +0000 | [diff] [blame] | 1587 | bool ARMBaseInstrInfo::FoldImmediate(MachineInstr *UseMI, |
| 1588 | MachineInstr *DefMI, unsigned Reg, |
| 1589 | MachineRegisterInfo *MRI) const { |
| 1590 | // Fold large immediates into add, sub, or, xor. |
| 1591 | unsigned DefOpc = DefMI->getOpcode(); |
| 1592 | if (DefOpc != ARM::t2MOVi32imm && DefOpc != ARM::MOVi32imm) |
| 1593 | return false; |
| 1594 | if (!DefMI->getOperand(1).isImm()) |
| 1595 | // Could be t2MOVi32imm <ga:xx> |
| 1596 | return false; |
| 1597 | |
| 1598 | if (!MRI->hasOneNonDBGUse(Reg)) |
| 1599 | return false; |
| 1600 | |
| 1601 | unsigned UseOpc = UseMI->getOpcode(); |
Evan Cheng | 5c71c7a | 2010-11-18 01:43:23 +0000 | [diff] [blame] | 1602 | unsigned NewUseOpc = 0; |
Evan Cheng | c4af463 | 2010-11-17 20:13:28 +0000 | [diff] [blame] | 1603 | uint32_t ImmVal = (uint32_t)DefMI->getOperand(1).getImm(); |
Evan Cheng | 5c71c7a | 2010-11-18 01:43:23 +0000 | [diff] [blame] | 1604 | uint32_t SOImmValV1 = 0, SOImmValV2 = 0; |
Evan Cheng | c4af463 | 2010-11-17 20:13:28 +0000 | [diff] [blame] | 1605 | bool Commute = false; |
| 1606 | switch (UseOpc) { |
| 1607 | default: return false; |
| 1608 | case ARM::SUBrr: |
| 1609 | case ARM::ADDrr: |
| 1610 | case ARM::ORRrr: |
| 1611 | case ARM::EORrr: |
| 1612 | case ARM::t2SUBrr: |
| 1613 | case ARM::t2ADDrr: |
| 1614 | case ARM::t2ORRrr: |
| 1615 | case ARM::t2EORrr: { |
| 1616 | Commute = UseMI->getOperand(2).getReg() != Reg; |
| 1617 | switch (UseOpc) { |
| 1618 | default: break; |
| 1619 | case ARM::SUBrr: { |
| 1620 | if (Commute) |
| 1621 | return false; |
| 1622 | ImmVal = -ImmVal; |
| 1623 | NewUseOpc = ARM::SUBri; |
| 1624 | // Fallthrough |
| 1625 | } |
| 1626 | case ARM::ADDrr: |
| 1627 | case ARM::ORRrr: |
| 1628 | case ARM::EORrr: { |
| 1629 | if (!ARM_AM::isSOImmTwoPartVal(ImmVal)) |
| 1630 | return false; |
| 1631 | SOImmValV1 = (uint32_t)ARM_AM::getSOImmTwoPartFirst(ImmVal); |
| 1632 | SOImmValV2 = (uint32_t)ARM_AM::getSOImmTwoPartSecond(ImmVal); |
| 1633 | switch (UseOpc) { |
| 1634 | default: break; |
| 1635 | case ARM::ADDrr: NewUseOpc = ARM::ADDri; break; |
| 1636 | case ARM::ORRrr: NewUseOpc = ARM::ORRri; break; |
| 1637 | case ARM::EORrr: NewUseOpc = ARM::EORri; break; |
| 1638 | } |
| 1639 | break; |
| 1640 | } |
| 1641 | case ARM::t2SUBrr: { |
| 1642 | if (Commute) |
| 1643 | return false; |
| 1644 | ImmVal = -ImmVal; |
| 1645 | NewUseOpc = ARM::t2SUBri; |
| 1646 | // Fallthrough |
| 1647 | } |
| 1648 | case ARM::t2ADDrr: |
| 1649 | case ARM::t2ORRrr: |
| 1650 | case ARM::t2EORrr: { |
| 1651 | if (!ARM_AM::isT2SOImmTwoPartVal(ImmVal)) |
| 1652 | return false; |
| 1653 | SOImmValV1 = (uint32_t)ARM_AM::getT2SOImmTwoPartFirst(ImmVal); |
| 1654 | SOImmValV2 = (uint32_t)ARM_AM::getT2SOImmTwoPartSecond(ImmVal); |
| 1655 | switch (UseOpc) { |
| 1656 | default: break; |
| 1657 | case ARM::t2ADDrr: NewUseOpc = ARM::t2ADDri; break; |
| 1658 | case ARM::t2ORRrr: NewUseOpc = ARM::t2ORRri; break; |
| 1659 | case ARM::t2EORrr: NewUseOpc = ARM::t2EORri; break; |
| 1660 | } |
| 1661 | break; |
| 1662 | } |
| 1663 | } |
| 1664 | } |
| 1665 | } |
| 1666 | |
| 1667 | unsigned OpIdx = Commute ? 2 : 1; |
| 1668 | unsigned Reg1 = UseMI->getOperand(OpIdx).getReg(); |
| 1669 | bool isKill = UseMI->getOperand(OpIdx).isKill(); |
| 1670 | unsigned NewReg = MRI->createVirtualRegister(MRI->getRegClass(Reg)); |
| 1671 | AddDefaultCC(AddDefaultPred(BuildMI(*UseMI->getParent(), |
| 1672 | *UseMI, UseMI->getDebugLoc(), |
| 1673 | get(NewUseOpc), NewReg) |
| 1674 | .addReg(Reg1, getKillRegState(isKill)) |
| 1675 | .addImm(SOImmValV1))); |
| 1676 | UseMI->setDesc(get(NewUseOpc)); |
| 1677 | UseMI->getOperand(1).setReg(NewReg); |
| 1678 | UseMI->getOperand(1).setIsKill(); |
| 1679 | UseMI->getOperand(2).ChangeToImmediate(SOImmValV2); |
| 1680 | DefMI->eraseFromParent(); |
| 1681 | return true; |
| 1682 | } |
| 1683 | |
Evan Cheng | 5f54ce3 | 2010-09-09 18:18:55 +0000 | [diff] [blame] | 1684 | unsigned |
Evan Cheng | 8239daf | 2010-11-03 00:45:17 +0000 | [diff] [blame] | 1685 | ARMBaseInstrInfo::getNumMicroOps(const InstrItineraryData *ItinData, |
| 1686 | const MachineInstr *MI) const { |
Evan Cheng | 3ef1c87 | 2010-09-10 01:29:16 +0000 | [diff] [blame] | 1687 | if (!ItinData || ItinData->isEmpty()) |
Evan Cheng | 5f54ce3 | 2010-09-09 18:18:55 +0000 | [diff] [blame] | 1688 | return 1; |
| 1689 | |
| 1690 | const TargetInstrDesc &Desc = MI->getDesc(); |
| 1691 | unsigned Class = Desc.getSchedClass(); |
Bob Wilson | 064312d | 2010-09-15 16:28:21 +0000 | [diff] [blame] | 1692 | unsigned UOps = ItinData->Itineraries[Class].NumMicroOps; |
Evan Cheng | 5f54ce3 | 2010-09-09 18:18:55 +0000 | [diff] [blame] | 1693 | if (UOps) |
| 1694 | return UOps; |
| 1695 | |
| 1696 | unsigned Opc = MI->getOpcode(); |
| 1697 | switch (Opc) { |
| 1698 | default: |
| 1699 | llvm_unreachable("Unexpected multi-uops instruction!"); |
| 1700 | break; |
Bill Wendling | 73fe34a | 2010-11-16 01:16:36 +0000 | [diff] [blame] | 1701 | case ARM::VLDMQIA: |
| 1702 | case ARM::VLDMQDB: |
| 1703 | case ARM::VSTMQIA: |
| 1704 | case ARM::VSTMQDB: |
Evan Cheng | 5f54ce3 | 2010-09-09 18:18:55 +0000 | [diff] [blame] | 1705 | return 2; |
| 1706 | |
| 1707 | // The number of uOps for load / store multiple are determined by the number |
| 1708 | // registers. |
Andrew Trick | 6e8f4c4 | 2010-12-24 04:28:06 +0000 | [diff] [blame] | 1709 | // |
Evan Cheng | 3ef1c87 | 2010-09-10 01:29:16 +0000 | [diff] [blame] | 1710 | // On Cortex-A8, each pair of register loads / stores can be scheduled on the |
| 1711 | // same cycle. The scheduling for the first load / store must be done |
| 1712 | // separately by assuming the the address is not 64-bit aligned. |
Bill Wendling | 73fe34a | 2010-11-16 01:16:36 +0000 | [diff] [blame] | 1713 | // |
Evan Cheng | 3ef1c87 | 2010-09-10 01:29:16 +0000 | [diff] [blame] | 1714 | // On Cortex-A9, the formula is simply (#reg / 2) + (#reg % 2). If the address |
Bill Wendling | 73fe34a | 2010-11-16 01:16:36 +0000 | [diff] [blame] | 1715 | // is not 64-bit aligned, then AGU would take an extra cycle. For VFP / NEON |
| 1716 | // load / store multiple, the formula is (#reg / 2) + (#reg % 2) + 1. |
| 1717 | case ARM::VLDMDIA: |
| 1718 | case ARM::VLDMDDB: |
| 1719 | case ARM::VLDMDIA_UPD: |
| 1720 | case ARM::VLDMDDB_UPD: |
| 1721 | case ARM::VLDMSIA: |
| 1722 | case ARM::VLDMSDB: |
| 1723 | case ARM::VLDMSIA_UPD: |
| 1724 | case ARM::VLDMSDB_UPD: |
| 1725 | case ARM::VSTMDIA: |
| 1726 | case ARM::VSTMDDB: |
| 1727 | case ARM::VSTMDIA_UPD: |
| 1728 | case ARM::VSTMDDB_UPD: |
| 1729 | case ARM::VSTMSIA: |
| 1730 | case ARM::VSTMSDB: |
| 1731 | case ARM::VSTMSIA_UPD: |
| 1732 | case ARM::VSTMSDB_UPD: { |
Evan Cheng | 5f54ce3 | 2010-09-09 18:18:55 +0000 | [diff] [blame] | 1733 | unsigned NumRegs = MI->getNumOperands() - Desc.getNumOperands(); |
| 1734 | return (NumRegs / 2) + (NumRegs % 2) + 1; |
| 1735 | } |
Bill Wendling | 73fe34a | 2010-11-16 01:16:36 +0000 | [diff] [blame] | 1736 | |
| 1737 | case ARM::LDMIA_RET: |
| 1738 | case ARM::LDMIA: |
| 1739 | case ARM::LDMDA: |
| 1740 | case ARM::LDMDB: |
| 1741 | case ARM::LDMIB: |
| 1742 | case ARM::LDMIA_UPD: |
| 1743 | case ARM::LDMDA_UPD: |
| 1744 | case ARM::LDMDB_UPD: |
| 1745 | case ARM::LDMIB_UPD: |
| 1746 | case ARM::STMIA: |
| 1747 | case ARM::STMDA: |
| 1748 | case ARM::STMDB: |
| 1749 | case ARM::STMIB: |
| 1750 | case ARM::STMIA_UPD: |
| 1751 | case ARM::STMDA_UPD: |
| 1752 | case ARM::STMDB_UPD: |
| 1753 | case ARM::STMIB_UPD: |
| 1754 | case ARM::tLDMIA: |
| 1755 | case ARM::tLDMIA_UPD: |
| 1756 | case ARM::tSTMIA: |
| 1757 | case ARM::tSTMIA_UPD: |
Evan Cheng | 5f54ce3 | 2010-09-09 18:18:55 +0000 | [diff] [blame] | 1758 | case ARM::tPOP_RET: |
| 1759 | case ARM::tPOP: |
| 1760 | case ARM::tPUSH: |
Bill Wendling | 73fe34a | 2010-11-16 01:16:36 +0000 | [diff] [blame] | 1761 | case ARM::t2LDMIA_RET: |
| 1762 | case ARM::t2LDMIA: |
| 1763 | case ARM::t2LDMDB: |
| 1764 | case ARM::t2LDMIA_UPD: |
| 1765 | case ARM::t2LDMDB_UPD: |
| 1766 | case ARM::t2STMIA: |
| 1767 | case ARM::t2STMDB: |
| 1768 | case ARM::t2STMIA_UPD: |
| 1769 | case ARM::t2STMDB_UPD: { |
Evan Cheng | 3ef1c87 | 2010-09-10 01:29:16 +0000 | [diff] [blame] | 1770 | unsigned NumRegs = MI->getNumOperands() - Desc.getNumOperands() + 1; |
| 1771 | if (Subtarget.isCortexA8()) { |
Evan Cheng | 8239daf | 2010-11-03 00:45:17 +0000 | [diff] [blame] | 1772 | if (NumRegs < 4) |
| 1773 | return 2; |
| 1774 | // 4 registers would be issued: 2, 2. |
| 1775 | // 5 registers would be issued: 2, 2, 1. |
| 1776 | UOps = (NumRegs / 2); |
| 1777 | if (NumRegs % 2) |
| 1778 | ++UOps; |
| 1779 | return UOps; |
Evan Cheng | 3ef1c87 | 2010-09-10 01:29:16 +0000 | [diff] [blame] | 1780 | } else if (Subtarget.isCortexA9()) { |
| 1781 | UOps = (NumRegs / 2); |
| 1782 | // If there are odd number of registers or if it's not 64-bit aligned, |
| 1783 | // then it takes an extra AGU (Address Generation Unit) cycle. |
| 1784 | if ((NumRegs % 2) || |
| 1785 | !MI->hasOneMemOperand() || |
| 1786 | (*MI->memoperands_begin())->getAlignment() < 8) |
| 1787 | ++UOps; |
| 1788 | return UOps; |
| 1789 | } else { |
| 1790 | // Assume the worst. |
| 1791 | return NumRegs; |
Michael J. Spencer | 2bbb769 | 2010-10-05 06:00:33 +0000 | [diff] [blame] | 1792 | } |
Evan Cheng | 5f54ce3 | 2010-09-09 18:18:55 +0000 | [diff] [blame] | 1793 | } |
| 1794 | } |
| 1795 | } |
Evan Cheng | a0792de | 2010-10-06 06:27:31 +0000 | [diff] [blame] | 1796 | |
| 1797 | int |
Evan Cheng | 344d9db | 2010-10-07 23:12:15 +0000 | [diff] [blame] | 1798 | ARMBaseInstrInfo::getVLDMDefCycle(const InstrItineraryData *ItinData, |
| 1799 | const TargetInstrDesc &DefTID, |
| 1800 | unsigned DefClass, |
| 1801 | unsigned DefIdx, unsigned DefAlign) const { |
| 1802 | int RegNo = (int)(DefIdx+1) - DefTID.getNumOperands() + 1; |
| 1803 | if (RegNo <= 0) |
| 1804 | // Def is the address writeback. |
| 1805 | return ItinData->getOperandCycle(DefClass, DefIdx); |
| 1806 | |
| 1807 | int DefCycle; |
| 1808 | if (Subtarget.isCortexA8()) { |
| 1809 | // (regno / 2) + (regno % 2) + 1 |
| 1810 | DefCycle = RegNo / 2 + 1; |
| 1811 | if (RegNo % 2) |
| 1812 | ++DefCycle; |
| 1813 | } else if (Subtarget.isCortexA9()) { |
| 1814 | DefCycle = RegNo; |
| 1815 | bool isSLoad = false; |
Bill Wendling | 73fe34a | 2010-11-16 01:16:36 +0000 | [diff] [blame] | 1816 | |
Evan Cheng | 344d9db | 2010-10-07 23:12:15 +0000 | [diff] [blame] | 1817 | switch (DefTID.getOpcode()) { |
| 1818 | default: break; |
Bill Wendling | 73fe34a | 2010-11-16 01:16:36 +0000 | [diff] [blame] | 1819 | case ARM::VLDMSIA: |
| 1820 | case ARM::VLDMSDB: |
| 1821 | case ARM::VLDMSIA_UPD: |
| 1822 | case ARM::VLDMSDB_UPD: |
Evan Cheng | 344d9db | 2010-10-07 23:12:15 +0000 | [diff] [blame] | 1823 | isSLoad = true; |
| 1824 | break; |
| 1825 | } |
Bill Wendling | 73fe34a | 2010-11-16 01:16:36 +0000 | [diff] [blame] | 1826 | |
Evan Cheng | 344d9db | 2010-10-07 23:12:15 +0000 | [diff] [blame] | 1827 | // If there are odd number of 'S' registers or if it's not 64-bit aligned, |
| 1828 | // then it takes an extra cycle. |
| 1829 | if ((isSLoad && (RegNo % 2)) || DefAlign < 8) |
| 1830 | ++DefCycle; |
| 1831 | } else { |
| 1832 | // Assume the worst. |
| 1833 | DefCycle = RegNo + 2; |
| 1834 | } |
| 1835 | |
| 1836 | return DefCycle; |
| 1837 | } |
| 1838 | |
| 1839 | int |
| 1840 | ARMBaseInstrInfo::getLDMDefCycle(const InstrItineraryData *ItinData, |
| 1841 | const TargetInstrDesc &DefTID, |
| 1842 | unsigned DefClass, |
| 1843 | unsigned DefIdx, unsigned DefAlign) const { |
| 1844 | int RegNo = (int)(DefIdx+1) - DefTID.getNumOperands() + 1; |
| 1845 | if (RegNo <= 0) |
| 1846 | // Def is the address writeback. |
| 1847 | return ItinData->getOperandCycle(DefClass, DefIdx); |
| 1848 | |
| 1849 | int DefCycle; |
| 1850 | if (Subtarget.isCortexA8()) { |
| 1851 | // 4 registers would be issued: 1, 2, 1. |
| 1852 | // 5 registers would be issued: 1, 2, 2. |
| 1853 | DefCycle = RegNo / 2; |
| 1854 | if (DefCycle < 1) |
| 1855 | DefCycle = 1; |
| 1856 | // Result latency is issue cycle + 2: E2. |
| 1857 | DefCycle += 2; |
| 1858 | } else if (Subtarget.isCortexA9()) { |
| 1859 | DefCycle = (RegNo / 2); |
| 1860 | // If there are odd number of registers or if it's not 64-bit aligned, |
| 1861 | // then it takes an extra AGU (Address Generation Unit) cycle. |
| 1862 | if ((RegNo % 2) || DefAlign < 8) |
| 1863 | ++DefCycle; |
| 1864 | // Result latency is AGU cycles + 2. |
| 1865 | DefCycle += 2; |
| 1866 | } else { |
| 1867 | // Assume the worst. |
| 1868 | DefCycle = RegNo + 2; |
| 1869 | } |
| 1870 | |
| 1871 | return DefCycle; |
| 1872 | } |
| 1873 | |
| 1874 | int |
| 1875 | ARMBaseInstrInfo::getVSTMUseCycle(const InstrItineraryData *ItinData, |
| 1876 | const TargetInstrDesc &UseTID, |
| 1877 | unsigned UseClass, |
| 1878 | unsigned UseIdx, unsigned UseAlign) const { |
| 1879 | int RegNo = (int)(UseIdx+1) - UseTID.getNumOperands() + 1; |
| 1880 | if (RegNo <= 0) |
| 1881 | return ItinData->getOperandCycle(UseClass, UseIdx); |
| 1882 | |
| 1883 | int UseCycle; |
| 1884 | if (Subtarget.isCortexA8()) { |
| 1885 | // (regno / 2) + (regno % 2) + 1 |
| 1886 | UseCycle = RegNo / 2 + 1; |
| 1887 | if (RegNo % 2) |
| 1888 | ++UseCycle; |
| 1889 | } else if (Subtarget.isCortexA9()) { |
| 1890 | UseCycle = RegNo; |
| 1891 | bool isSStore = false; |
Bill Wendling | 73fe34a | 2010-11-16 01:16:36 +0000 | [diff] [blame] | 1892 | |
Evan Cheng | 344d9db | 2010-10-07 23:12:15 +0000 | [diff] [blame] | 1893 | switch (UseTID.getOpcode()) { |
| 1894 | default: break; |
Bill Wendling | 73fe34a | 2010-11-16 01:16:36 +0000 | [diff] [blame] | 1895 | case ARM::VSTMSIA: |
| 1896 | case ARM::VSTMSDB: |
| 1897 | case ARM::VSTMSIA_UPD: |
| 1898 | case ARM::VSTMSDB_UPD: |
Evan Cheng | 344d9db | 2010-10-07 23:12:15 +0000 | [diff] [blame] | 1899 | isSStore = true; |
| 1900 | break; |
| 1901 | } |
Bill Wendling | 73fe34a | 2010-11-16 01:16:36 +0000 | [diff] [blame] | 1902 | |
Evan Cheng | 344d9db | 2010-10-07 23:12:15 +0000 | [diff] [blame] | 1903 | // If there are odd number of 'S' registers or if it's not 64-bit aligned, |
| 1904 | // then it takes an extra cycle. |
| 1905 | if ((isSStore && (RegNo % 2)) || UseAlign < 8) |
| 1906 | ++UseCycle; |
| 1907 | } else { |
| 1908 | // Assume the worst. |
| 1909 | UseCycle = RegNo + 2; |
| 1910 | } |
| 1911 | |
| 1912 | return UseCycle; |
| 1913 | } |
| 1914 | |
| 1915 | int |
| 1916 | ARMBaseInstrInfo::getSTMUseCycle(const InstrItineraryData *ItinData, |
| 1917 | const TargetInstrDesc &UseTID, |
| 1918 | unsigned UseClass, |
| 1919 | unsigned UseIdx, unsigned UseAlign) const { |
| 1920 | int RegNo = (int)(UseIdx+1) - UseTID.getNumOperands() + 1; |
| 1921 | if (RegNo <= 0) |
| 1922 | return ItinData->getOperandCycle(UseClass, UseIdx); |
| 1923 | |
| 1924 | int UseCycle; |
| 1925 | if (Subtarget.isCortexA8()) { |
| 1926 | UseCycle = RegNo / 2; |
| 1927 | if (UseCycle < 2) |
| 1928 | UseCycle = 2; |
| 1929 | // Read in E3. |
| 1930 | UseCycle += 2; |
| 1931 | } else if (Subtarget.isCortexA9()) { |
| 1932 | UseCycle = (RegNo / 2); |
| 1933 | // If there are odd number of registers or if it's not 64-bit aligned, |
| 1934 | // then it takes an extra AGU (Address Generation Unit) cycle. |
| 1935 | if ((RegNo % 2) || UseAlign < 8) |
| 1936 | ++UseCycle; |
| 1937 | } else { |
| 1938 | // Assume the worst. |
| 1939 | UseCycle = 1; |
| 1940 | } |
| 1941 | return UseCycle; |
| 1942 | } |
| 1943 | |
| 1944 | int |
Evan Cheng | a0792de | 2010-10-06 06:27:31 +0000 | [diff] [blame] | 1945 | ARMBaseInstrInfo::getOperandLatency(const InstrItineraryData *ItinData, |
| 1946 | const TargetInstrDesc &DefTID, |
| 1947 | unsigned DefIdx, unsigned DefAlign, |
| 1948 | const TargetInstrDesc &UseTID, |
| 1949 | unsigned UseIdx, unsigned UseAlign) const { |
| 1950 | unsigned DefClass = DefTID.getSchedClass(); |
| 1951 | unsigned UseClass = UseTID.getSchedClass(); |
| 1952 | |
| 1953 | if (DefIdx < DefTID.getNumDefs() && UseIdx < UseTID.getNumOperands()) |
| 1954 | return ItinData->getOperandLatency(DefClass, DefIdx, UseClass, UseIdx); |
| 1955 | |
| 1956 | // This may be a def / use of a variable_ops instruction, the operand |
| 1957 | // latency might be determinable dynamically. Let the target try to |
| 1958 | // figure it out. |
Evan Cheng | 9e08ee5 | 2010-10-28 02:00:25 +0000 | [diff] [blame] | 1959 | int DefCycle = -1; |
Evan Cheng | 7e2fe91 | 2010-10-28 06:47:08 +0000 | [diff] [blame] | 1960 | bool LdmBypass = false; |
Evan Cheng | a0792de | 2010-10-06 06:27:31 +0000 | [diff] [blame] | 1961 | switch (DefTID.getOpcode()) { |
| 1962 | default: |
| 1963 | DefCycle = ItinData->getOperandCycle(DefClass, DefIdx); |
| 1964 | break; |
Bill Wendling | 73fe34a | 2010-11-16 01:16:36 +0000 | [diff] [blame] | 1965 | |
| 1966 | case ARM::VLDMDIA: |
| 1967 | case ARM::VLDMDDB: |
| 1968 | case ARM::VLDMDIA_UPD: |
| 1969 | case ARM::VLDMDDB_UPD: |
| 1970 | case ARM::VLDMSIA: |
| 1971 | case ARM::VLDMSDB: |
| 1972 | case ARM::VLDMSIA_UPD: |
| 1973 | case ARM::VLDMSDB_UPD: |
Evan Cheng | 344d9db | 2010-10-07 23:12:15 +0000 | [diff] [blame] | 1974 | DefCycle = getVLDMDefCycle(ItinData, DefTID, DefClass, DefIdx, DefAlign); |
Evan Cheng | 5a50cee | 2010-10-07 01:50:48 +0000 | [diff] [blame] | 1975 | break; |
Bill Wendling | 73fe34a | 2010-11-16 01:16:36 +0000 | [diff] [blame] | 1976 | |
| 1977 | case ARM::LDMIA_RET: |
| 1978 | case ARM::LDMIA: |
| 1979 | case ARM::LDMDA: |
| 1980 | case ARM::LDMDB: |
| 1981 | case ARM::LDMIB: |
| 1982 | case ARM::LDMIA_UPD: |
| 1983 | case ARM::LDMDA_UPD: |
| 1984 | case ARM::LDMDB_UPD: |
| 1985 | case ARM::LDMIB_UPD: |
| 1986 | case ARM::tLDMIA: |
| 1987 | case ARM::tLDMIA_UPD: |
Evan Cheng | a0792de | 2010-10-06 06:27:31 +0000 | [diff] [blame] | 1988 | case ARM::tPUSH: |
Bill Wendling | 73fe34a | 2010-11-16 01:16:36 +0000 | [diff] [blame] | 1989 | case ARM::t2LDMIA_RET: |
| 1990 | case ARM::t2LDMIA: |
| 1991 | case ARM::t2LDMDB: |
| 1992 | case ARM::t2LDMIA_UPD: |
| 1993 | case ARM::t2LDMDB_UPD: |
Evan Cheng | a0792de | 2010-10-06 06:27:31 +0000 | [diff] [blame] | 1994 | LdmBypass = 1; |
Evan Cheng | 344d9db | 2010-10-07 23:12:15 +0000 | [diff] [blame] | 1995 | DefCycle = getLDMDefCycle(ItinData, DefTID, DefClass, DefIdx, DefAlign); |
| 1996 | break; |
Evan Cheng | a0792de | 2010-10-06 06:27:31 +0000 | [diff] [blame] | 1997 | } |
Evan Cheng | a0792de | 2010-10-06 06:27:31 +0000 | [diff] [blame] | 1998 | |
| 1999 | if (DefCycle == -1) |
| 2000 | // We can't seem to determine the result latency of the def, assume it's 2. |
| 2001 | DefCycle = 2; |
| 2002 | |
| 2003 | int UseCycle = -1; |
| 2004 | switch (UseTID.getOpcode()) { |
| 2005 | default: |
| 2006 | UseCycle = ItinData->getOperandCycle(UseClass, UseIdx); |
| 2007 | break; |
Bill Wendling | 73fe34a | 2010-11-16 01:16:36 +0000 | [diff] [blame] | 2008 | |
| 2009 | case ARM::VSTMDIA: |
| 2010 | case ARM::VSTMDDB: |
| 2011 | case ARM::VSTMDIA_UPD: |
| 2012 | case ARM::VSTMDDB_UPD: |
| 2013 | case ARM::VSTMSIA: |
| 2014 | case ARM::VSTMSDB: |
| 2015 | case ARM::VSTMSIA_UPD: |
| 2016 | case ARM::VSTMSDB_UPD: |
Evan Cheng | 344d9db | 2010-10-07 23:12:15 +0000 | [diff] [blame] | 2017 | UseCycle = getVSTMUseCycle(ItinData, UseTID, UseClass, UseIdx, UseAlign); |
Evan Cheng | 5a50cee | 2010-10-07 01:50:48 +0000 | [diff] [blame] | 2018 | break; |
Bill Wendling | 73fe34a | 2010-11-16 01:16:36 +0000 | [diff] [blame] | 2019 | |
| 2020 | case ARM::STMIA: |
| 2021 | case ARM::STMDA: |
| 2022 | case ARM::STMDB: |
| 2023 | case ARM::STMIB: |
| 2024 | case ARM::STMIA_UPD: |
| 2025 | case ARM::STMDA_UPD: |
| 2026 | case ARM::STMDB_UPD: |
| 2027 | case ARM::STMIB_UPD: |
| 2028 | case ARM::tSTMIA: |
| 2029 | case ARM::tSTMIA_UPD: |
Evan Cheng | a0792de | 2010-10-06 06:27:31 +0000 | [diff] [blame] | 2030 | case ARM::tPOP_RET: |
| 2031 | case ARM::tPOP: |
Bill Wendling | 73fe34a | 2010-11-16 01:16:36 +0000 | [diff] [blame] | 2032 | case ARM::t2STMIA: |
| 2033 | case ARM::t2STMDB: |
| 2034 | case ARM::t2STMIA_UPD: |
| 2035 | case ARM::t2STMDB_UPD: |
Evan Cheng | 344d9db | 2010-10-07 23:12:15 +0000 | [diff] [blame] | 2036 | UseCycle = getSTMUseCycle(ItinData, UseTID, UseClass, UseIdx, UseAlign); |
Evan Cheng | 5a50cee | 2010-10-07 01:50:48 +0000 | [diff] [blame] | 2037 | break; |
Evan Cheng | a0792de | 2010-10-06 06:27:31 +0000 | [diff] [blame] | 2038 | } |
Evan Cheng | a0792de | 2010-10-06 06:27:31 +0000 | [diff] [blame] | 2039 | |
| 2040 | if (UseCycle == -1) |
| 2041 | // Assume it's read in the first stage. |
| 2042 | UseCycle = 1; |
| 2043 | |
| 2044 | UseCycle = DefCycle - UseCycle + 1; |
| 2045 | if (UseCycle > 0) { |
| 2046 | if (LdmBypass) { |
| 2047 | // It's a variable_ops instruction so we can't use DefIdx here. Just use |
| 2048 | // first def operand. |
| 2049 | if (ItinData->hasPipelineForwarding(DefClass, DefTID.getNumOperands()-1, |
| 2050 | UseClass, UseIdx)) |
| 2051 | --UseCycle; |
| 2052 | } else if (ItinData->hasPipelineForwarding(DefClass, DefIdx, |
Bill Wendling | 73fe34a | 2010-11-16 01:16:36 +0000 | [diff] [blame] | 2053 | UseClass, UseIdx)) { |
Evan Cheng | a0792de | 2010-10-06 06:27:31 +0000 | [diff] [blame] | 2054 | --UseCycle; |
Bill Wendling | 73fe34a | 2010-11-16 01:16:36 +0000 | [diff] [blame] | 2055 | } |
Evan Cheng | a0792de | 2010-10-06 06:27:31 +0000 | [diff] [blame] | 2056 | } |
| 2057 | |
| 2058 | return UseCycle; |
| 2059 | } |
| 2060 | |
| 2061 | int |
| 2062 | ARMBaseInstrInfo::getOperandLatency(const InstrItineraryData *ItinData, |
| 2063 | const MachineInstr *DefMI, unsigned DefIdx, |
| 2064 | const MachineInstr *UseMI, unsigned UseIdx) const { |
| 2065 | if (DefMI->isCopyLike() || DefMI->isInsertSubreg() || |
| 2066 | DefMI->isRegSequence() || DefMI->isImplicitDef()) |
| 2067 | return 1; |
| 2068 | |
| 2069 | const TargetInstrDesc &DefTID = DefMI->getDesc(); |
| 2070 | if (!ItinData || ItinData->isEmpty()) |
| 2071 | return DefTID.mayLoad() ? 3 : 1; |
| 2072 | |
| 2073 | const TargetInstrDesc &UseTID = UseMI->getDesc(); |
Evan Cheng | dd9dd6f | 2010-10-23 02:04:38 +0000 | [diff] [blame] | 2074 | const MachineOperand &DefMO = DefMI->getOperand(DefIdx); |
Evan Cheng | e09206d | 2010-10-29 23:16:55 +0000 | [diff] [blame] | 2075 | if (DefMO.getReg() == ARM::CPSR) { |
| 2076 | if (DefMI->getOpcode() == ARM::FMSTAT) { |
| 2077 | // fpscr -> cpsr stalls over 20 cycles on A8 (and earlier?) |
| 2078 | return Subtarget.isCortexA9() ? 1 : 20; |
| 2079 | } |
| 2080 | |
Evan Cheng | dd9dd6f | 2010-10-23 02:04:38 +0000 | [diff] [blame] | 2081 | // CPSR set and branch can be paired in the same cycle. |
Evan Cheng | e09206d | 2010-10-29 23:16:55 +0000 | [diff] [blame] | 2082 | if (UseTID.isBranch()) |
| 2083 | return 0; |
| 2084 | } |
Evan Cheng | dd9dd6f | 2010-10-23 02:04:38 +0000 | [diff] [blame] | 2085 | |
Evan Cheng | a0792de | 2010-10-06 06:27:31 +0000 | [diff] [blame] | 2086 | unsigned DefAlign = DefMI->hasOneMemOperand() |
| 2087 | ? (*DefMI->memoperands_begin())->getAlignment() : 0; |
| 2088 | unsigned UseAlign = UseMI->hasOneMemOperand() |
| 2089 | ? (*UseMI->memoperands_begin())->getAlignment() : 0; |
Evan Cheng | 7e2fe91 | 2010-10-28 06:47:08 +0000 | [diff] [blame] | 2090 | int Latency = getOperandLatency(ItinData, DefTID, DefIdx, DefAlign, |
| 2091 | UseTID, UseIdx, UseAlign); |
| 2092 | |
| 2093 | if (Latency > 1 && |
| 2094 | (Subtarget.isCortexA8() || Subtarget.isCortexA9())) { |
| 2095 | // FIXME: Shifter op hack: no shift (i.e. [r +/- r]) or [r + r << 2] |
| 2096 | // variants are one cycle cheaper. |
| 2097 | switch (DefTID.getOpcode()) { |
| 2098 | default: break; |
| 2099 | case ARM::LDRrs: |
| 2100 | case ARM::LDRBrs: { |
| 2101 | unsigned ShOpVal = DefMI->getOperand(3).getImm(); |
| 2102 | unsigned ShImm = ARM_AM::getAM2Offset(ShOpVal); |
| 2103 | if (ShImm == 0 || |
| 2104 | (ShImm == 2 && ARM_AM::getAM2ShiftOpc(ShOpVal) == ARM_AM::lsl)) |
| 2105 | --Latency; |
| 2106 | break; |
| 2107 | } |
| 2108 | case ARM::t2LDRs: |
| 2109 | case ARM::t2LDRBs: |
| 2110 | case ARM::t2LDRHs: |
| 2111 | case ARM::t2LDRSHs: { |
| 2112 | // Thumb2 mode: lsl only. |
| 2113 | unsigned ShAmt = DefMI->getOperand(3).getImm(); |
| 2114 | if (ShAmt == 0 || ShAmt == 2) |
| 2115 | --Latency; |
| 2116 | break; |
| 2117 | } |
| 2118 | } |
| 2119 | } |
| 2120 | |
| 2121 | return Latency; |
Evan Cheng | a0792de | 2010-10-06 06:27:31 +0000 | [diff] [blame] | 2122 | } |
| 2123 | |
| 2124 | int |
| 2125 | ARMBaseInstrInfo::getOperandLatency(const InstrItineraryData *ItinData, |
| 2126 | SDNode *DefNode, unsigned DefIdx, |
| 2127 | SDNode *UseNode, unsigned UseIdx) const { |
| 2128 | if (!DefNode->isMachineOpcode()) |
| 2129 | return 1; |
| 2130 | |
| 2131 | const TargetInstrDesc &DefTID = get(DefNode->getMachineOpcode()); |
| 2132 | if (!ItinData || ItinData->isEmpty()) |
| 2133 | return DefTID.mayLoad() ? 3 : 1; |
| 2134 | |
Evan Cheng | 0897515 | 2010-10-29 18:09:28 +0000 | [diff] [blame] | 2135 | if (!UseNode->isMachineOpcode()) { |
| 2136 | int Latency = ItinData->getOperandCycle(DefTID.getSchedClass(), DefIdx); |
| 2137 | if (Subtarget.isCortexA9()) |
| 2138 | return Latency <= 2 ? 1 : Latency - 1; |
| 2139 | else |
| 2140 | return Latency <= 3 ? 1 : Latency - 2; |
| 2141 | } |
Evan Cheng | a0792de | 2010-10-06 06:27:31 +0000 | [diff] [blame] | 2142 | |
| 2143 | const TargetInstrDesc &UseTID = get(UseNode->getMachineOpcode()); |
| 2144 | const MachineSDNode *DefMN = dyn_cast<MachineSDNode>(DefNode); |
| 2145 | unsigned DefAlign = !DefMN->memoperands_empty() |
| 2146 | ? (*DefMN->memoperands_begin())->getAlignment() : 0; |
| 2147 | const MachineSDNode *UseMN = dyn_cast<MachineSDNode>(UseNode); |
| 2148 | unsigned UseAlign = !UseMN->memoperands_empty() |
| 2149 | ? (*UseMN->memoperands_begin())->getAlignment() : 0; |
Evan Cheng | 7e2fe91 | 2010-10-28 06:47:08 +0000 | [diff] [blame] | 2150 | int Latency = getOperandLatency(ItinData, DefTID, DefIdx, DefAlign, |
| 2151 | UseTID, UseIdx, UseAlign); |
| 2152 | |
| 2153 | if (Latency > 1 && |
| 2154 | (Subtarget.isCortexA8() || Subtarget.isCortexA9())) { |
| 2155 | // FIXME: Shifter op hack: no shift (i.e. [r +/- r]) or [r + r << 2] |
| 2156 | // variants are one cycle cheaper. |
| 2157 | switch (DefTID.getOpcode()) { |
| 2158 | default: break; |
| 2159 | case ARM::LDRrs: |
| 2160 | case ARM::LDRBrs: { |
| 2161 | unsigned ShOpVal = |
| 2162 | cast<ConstantSDNode>(DefNode->getOperand(2))->getZExtValue(); |
| 2163 | unsigned ShImm = ARM_AM::getAM2Offset(ShOpVal); |
| 2164 | if (ShImm == 0 || |
| 2165 | (ShImm == 2 && ARM_AM::getAM2ShiftOpc(ShOpVal) == ARM_AM::lsl)) |
| 2166 | --Latency; |
| 2167 | break; |
| 2168 | } |
| 2169 | case ARM::t2LDRs: |
| 2170 | case ARM::t2LDRBs: |
| 2171 | case ARM::t2LDRHs: |
| 2172 | case ARM::t2LDRSHs: { |
| 2173 | // Thumb2 mode: lsl only. |
| 2174 | unsigned ShAmt = |
| 2175 | cast<ConstantSDNode>(DefNode->getOperand(2))->getZExtValue(); |
| 2176 | if (ShAmt == 0 || ShAmt == 2) |
| 2177 | --Latency; |
| 2178 | break; |
| 2179 | } |
| 2180 | } |
| 2181 | } |
| 2182 | |
| 2183 | return Latency; |
Evan Cheng | a0792de | 2010-10-06 06:27:31 +0000 | [diff] [blame] | 2184 | } |
Evan Cheng | 2312842 | 2010-10-19 18:58:51 +0000 | [diff] [blame] | 2185 | |
Evan Cheng | 8239daf | 2010-11-03 00:45:17 +0000 | [diff] [blame] | 2186 | int ARMBaseInstrInfo::getInstrLatency(const InstrItineraryData *ItinData, |
| 2187 | const MachineInstr *MI, |
| 2188 | unsigned *PredCost) const { |
| 2189 | if (MI->isCopyLike() || MI->isInsertSubreg() || |
| 2190 | MI->isRegSequence() || MI->isImplicitDef()) |
| 2191 | return 1; |
| 2192 | |
| 2193 | if (!ItinData || ItinData->isEmpty()) |
| 2194 | return 1; |
| 2195 | |
| 2196 | const TargetInstrDesc &TID = MI->getDesc(); |
| 2197 | unsigned Class = TID.getSchedClass(); |
| 2198 | unsigned UOps = ItinData->Itineraries[Class].NumMicroOps; |
| 2199 | if (PredCost && TID.hasImplicitDefOfPhysReg(ARM::CPSR)) |
| 2200 | // When predicated, CPSR is an additional source operand for CPSR updating |
| 2201 | // instructions, this apparently increases their latencies. |
| 2202 | *PredCost = 1; |
| 2203 | if (UOps) |
| 2204 | return ItinData->getStageLatency(Class); |
| 2205 | return getNumMicroOps(ItinData, MI); |
| 2206 | } |
| 2207 | |
| 2208 | int ARMBaseInstrInfo::getInstrLatency(const InstrItineraryData *ItinData, |
| 2209 | SDNode *Node) const { |
| 2210 | if (!Node->isMachineOpcode()) |
| 2211 | return 1; |
| 2212 | |
| 2213 | if (!ItinData || ItinData->isEmpty()) |
| 2214 | return 1; |
| 2215 | |
| 2216 | unsigned Opcode = Node->getMachineOpcode(); |
| 2217 | switch (Opcode) { |
| 2218 | default: |
| 2219 | return ItinData->getStageLatency(get(Opcode).getSchedClass()); |
Bill Wendling | 73fe34a | 2010-11-16 01:16:36 +0000 | [diff] [blame] | 2220 | case ARM::VLDMQIA: |
| 2221 | case ARM::VLDMQDB: |
| 2222 | case ARM::VSTMQIA: |
| 2223 | case ARM::VSTMQDB: |
Evan Cheng | 8239daf | 2010-11-03 00:45:17 +0000 | [diff] [blame] | 2224 | return 2; |
Eric Christopher | 8b3ca62 | 2010-11-18 19:40:05 +0000 | [diff] [blame] | 2225 | } |
Evan Cheng | 8239daf | 2010-11-03 00:45:17 +0000 | [diff] [blame] | 2226 | } |
| 2227 | |
Evan Cheng | 2312842 | 2010-10-19 18:58:51 +0000 | [diff] [blame] | 2228 | bool ARMBaseInstrInfo:: |
| 2229 | hasHighOperandLatency(const InstrItineraryData *ItinData, |
| 2230 | const MachineRegisterInfo *MRI, |
| 2231 | const MachineInstr *DefMI, unsigned DefIdx, |
| 2232 | const MachineInstr *UseMI, unsigned UseIdx) const { |
| 2233 | unsigned DDomain = DefMI->getDesc().TSFlags & ARMII::DomainMask; |
| 2234 | unsigned UDomain = UseMI->getDesc().TSFlags & ARMII::DomainMask; |
| 2235 | if (Subtarget.isCortexA8() && |
| 2236 | (DDomain == ARMII::DomainVFP || UDomain == ARMII::DomainVFP)) |
| 2237 | // CortexA8 VFP instructions are not pipelined. |
| 2238 | return true; |
| 2239 | |
| 2240 | // Hoist VFP / NEON instructions with 4 or higher latency. |
| 2241 | int Latency = getOperandLatency(ItinData, DefMI, DefIdx, UseMI, UseIdx); |
| 2242 | if (Latency <= 3) |
| 2243 | return false; |
| 2244 | return DDomain == ARMII::DomainVFP || DDomain == ARMII::DomainNEON || |
| 2245 | UDomain == ARMII::DomainVFP || UDomain == ARMII::DomainNEON; |
| 2246 | } |
Evan Cheng | c8141df | 2010-10-26 02:08:50 +0000 | [diff] [blame] | 2247 | |
| 2248 | bool ARMBaseInstrInfo:: |
| 2249 | hasLowDefLatency(const InstrItineraryData *ItinData, |
| 2250 | const MachineInstr *DefMI, unsigned DefIdx) const { |
| 2251 | if (!ItinData || ItinData->isEmpty()) |
| 2252 | return false; |
| 2253 | |
| 2254 | unsigned DDomain = DefMI->getDesc().TSFlags & ARMII::DomainMask; |
| 2255 | if (DDomain == ARMII::DomainGeneral) { |
| 2256 | unsigned DefClass = DefMI->getDesc().getSchedClass(); |
| 2257 | int DefCycle = ItinData->getOperandCycle(DefClass, DefIdx); |
| 2258 | return (DefCycle != -1 && DefCycle <= 2); |
| 2259 | } |
| 2260 | return false; |
| 2261 | } |
Evan Cheng | 48575f6 | 2010-12-05 22:04:16 +0000 | [diff] [blame] | 2262 | |
| 2263 | bool |
| 2264 | ARMBaseInstrInfo::isFpMLxInstruction(unsigned Opcode, unsigned &MulOpc, |
| 2265 | unsigned &AddSubOpc, |
| 2266 | bool &NegAcc, bool &HasLane) const { |
| 2267 | DenseMap<unsigned, unsigned>::const_iterator I = MLxEntryMap.find(Opcode); |
| 2268 | if (I == MLxEntryMap.end()) |
| 2269 | return false; |
| 2270 | |
| 2271 | const ARM_MLxEntry &Entry = ARM_MLxTable[I->second]; |
| 2272 | MulOpc = Entry.MulOpc; |
| 2273 | AddSubOpc = Entry.AddSubOpc; |
| 2274 | NegAcc = Entry.NegAcc; |
| 2275 | HasLane = Entry.HasLane; |
| 2276 | return true; |
| 2277 | } |