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" |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 18 | #include "ARMMachineFunctionInfo.h" |
Anton Korobeynikov | f95215f | 2009-11-02 00:10:38 +0000 | [diff] [blame] | 19 | #include "ARMRegisterInfo.h" |
Chris Lattner | 4dbbe34 | 2010-07-20 21:17:29 +0000 | [diff] [blame] | 20 | #include "ARMGenInstrInfo.inc" |
Evan Cheng | fdc8340 | 2009-11-08 00:15:23 +0000 | [diff] [blame] | 21 | #include "llvm/Constants.h" |
| 22 | #include "llvm/Function.h" |
| 23 | #include "llvm/GlobalValue.h" |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 24 | #include "llvm/ADT/STLExtras.h" |
| 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" |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 37 | using namespace llvm; |
| 38 | |
| 39 | static cl::opt<bool> |
| 40 | EnableARM3Addr("enable-arm-3-addr-conv", cl::Hidden, |
| 41 | cl::desc("Enable ARM 2-addr to 3-addr conv")); |
| 42 | |
Owen Anderson | b3c04ec | 2010-09-30 23:48:38 +0000 | [diff] [blame] | 43 | static cl::opt<bool> |
Owen Anderson | 00d4f48 | 2010-10-01 20:33:47 +0000 | [diff] [blame] | 44 | OldARMIfCvt("old-arm-ifcvt", cl::Hidden, |
Owen Anderson | b3c04ec | 2010-09-30 23:48:38 +0000 | [diff] [blame] | 45 | cl::desc("Use old-style ARM if-conversion heuristics")); |
| 46 | |
Anton Korobeynikov | f95215f | 2009-11-02 00:10:38 +0000 | [diff] [blame] | 47 | ARMBaseInstrInfo::ARMBaseInstrInfo(const ARMSubtarget& STI) |
| 48 | : TargetInstrInfoImpl(ARMInsts, array_lengthof(ARMInsts)), |
| 49 | Subtarget(STI) { |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | MachineInstr * |
| 53 | ARMBaseInstrInfo::convertToThreeAddress(MachineFunction::iterator &MFI, |
| 54 | MachineBasicBlock::iterator &MBBI, |
| 55 | LiveVariables *LV) const { |
Evan Cheng | 78703dd | 2009-07-27 18:44:00 +0000 | [diff] [blame] | 56 | // FIXME: Thumb2 support. |
| 57 | |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 58 | if (!EnableARM3Addr) |
| 59 | return NULL; |
| 60 | |
| 61 | MachineInstr *MI = MBBI; |
| 62 | MachineFunction &MF = *MI->getParent()->getParent(); |
Bruno Cardoso Lopes | 99405df | 2010-06-08 22:51:23 +0000 | [diff] [blame] | 63 | uint64_t TSFlags = MI->getDesc().TSFlags; |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 64 | bool isPre = false; |
| 65 | switch ((TSFlags & ARMII::IndexModeMask) >> ARMII::IndexModeShift) { |
| 66 | default: return NULL; |
| 67 | case ARMII::IndexModePre: |
| 68 | isPre = true; |
| 69 | break; |
| 70 | case ARMII::IndexModePost: |
| 71 | break; |
| 72 | } |
| 73 | |
| 74 | // Try splitting an indexed load/store to an un-indexed one plus an add/sub |
| 75 | // operation. |
| 76 | unsigned MemOpc = getUnindexedOpcode(MI->getOpcode()); |
| 77 | if (MemOpc == 0) |
| 78 | return NULL; |
| 79 | |
| 80 | MachineInstr *UpdateMI = NULL; |
| 81 | MachineInstr *MemMI = NULL; |
| 82 | unsigned AddrMode = (TSFlags & ARMII::AddrModeMask); |
| 83 | const TargetInstrDesc &TID = MI->getDesc(); |
| 84 | unsigned NumOps = TID.getNumOperands(); |
| 85 | bool isLoad = !TID.mayStore(); |
| 86 | const MachineOperand &WB = isLoad ? MI->getOperand(1) : MI->getOperand(0); |
| 87 | const MachineOperand &Base = MI->getOperand(2); |
| 88 | const MachineOperand &Offset = MI->getOperand(NumOps-3); |
| 89 | unsigned WBReg = WB.getReg(); |
| 90 | unsigned BaseReg = Base.getReg(); |
| 91 | unsigned OffReg = Offset.getReg(); |
| 92 | unsigned OffImm = MI->getOperand(NumOps-2).getImm(); |
| 93 | ARMCC::CondCodes Pred = (ARMCC::CondCodes)MI->getOperand(NumOps-1).getImm(); |
| 94 | switch (AddrMode) { |
| 95 | default: |
| 96 | assert(false && "Unknown indexed op!"); |
| 97 | return NULL; |
| 98 | case ARMII::AddrMode2: { |
| 99 | bool isSub = ARM_AM::getAM2Op(OffImm) == ARM_AM::sub; |
| 100 | unsigned Amt = ARM_AM::getAM2Offset(OffImm); |
| 101 | if (OffReg == 0) { |
Evan Cheng | e7cbe41 | 2009-07-08 21:03:57 +0000 | [diff] [blame] | 102 | if (ARM_AM::getSOImmVal(Amt) == -1) |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 103 | // Can't encode it in a so_imm operand. This transformation will |
| 104 | // add more than 1 instruction. Abandon! |
| 105 | return NULL; |
| 106 | UpdateMI = BuildMI(MF, MI->getDebugLoc(), |
Evan Cheng | 78703dd | 2009-07-27 18:44:00 +0000 | [diff] [blame] | 107 | get(isSub ? ARM::SUBri : ARM::ADDri), WBReg) |
Evan Cheng | e7cbe41 | 2009-07-08 21:03:57 +0000 | [diff] [blame] | 108 | .addReg(BaseReg).addImm(Amt) |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 109 | .addImm(Pred).addReg(0).addReg(0); |
| 110 | } else if (Amt != 0) { |
| 111 | ARM_AM::ShiftOpc ShOpc = ARM_AM::getAM2ShiftOpc(OffImm); |
| 112 | unsigned SOOpc = ARM_AM::getSORegOpc(ShOpc, Amt); |
| 113 | UpdateMI = BuildMI(MF, MI->getDebugLoc(), |
Evan Cheng | 78703dd | 2009-07-27 18:44:00 +0000 | [diff] [blame] | 114 | get(isSub ? ARM::SUBrs : ARM::ADDrs), WBReg) |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 115 | .addReg(BaseReg).addReg(OffReg).addReg(0).addImm(SOOpc) |
| 116 | .addImm(Pred).addReg(0).addReg(0); |
| 117 | } else |
| 118 | UpdateMI = BuildMI(MF, MI->getDebugLoc(), |
Evan Cheng | 78703dd | 2009-07-27 18:44:00 +0000 | [diff] [blame] | 119 | get(isSub ? ARM::SUBrr : ARM::ADDrr), WBReg) |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 120 | .addReg(BaseReg).addReg(OffReg) |
| 121 | .addImm(Pred).addReg(0).addReg(0); |
| 122 | break; |
| 123 | } |
| 124 | case ARMII::AddrMode3 : { |
| 125 | bool isSub = ARM_AM::getAM3Op(OffImm) == ARM_AM::sub; |
| 126 | unsigned Amt = ARM_AM::getAM3Offset(OffImm); |
| 127 | if (OffReg == 0) |
| 128 | // Immediate is 8-bits. It's guaranteed to fit in a so_imm operand. |
| 129 | UpdateMI = BuildMI(MF, MI->getDebugLoc(), |
Evan Cheng | 78703dd | 2009-07-27 18:44:00 +0000 | [diff] [blame] | 130 | get(isSub ? ARM::SUBri : ARM::ADDri), WBReg) |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 131 | .addReg(BaseReg).addImm(Amt) |
| 132 | .addImm(Pred).addReg(0).addReg(0); |
| 133 | else |
| 134 | UpdateMI = BuildMI(MF, MI->getDebugLoc(), |
Evan Cheng | 78703dd | 2009-07-27 18:44:00 +0000 | [diff] [blame] | 135 | get(isSub ? ARM::SUBrr : ARM::ADDrr), WBReg) |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 136 | .addReg(BaseReg).addReg(OffReg) |
| 137 | .addImm(Pred).addReg(0).addReg(0); |
| 138 | break; |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | std::vector<MachineInstr*> NewMIs; |
| 143 | if (isPre) { |
| 144 | if (isLoad) |
| 145 | MemMI = BuildMI(MF, MI->getDebugLoc(), |
| 146 | get(MemOpc), MI->getOperand(0).getReg()) |
Jim Grosbach | 3e55612 | 2010-10-26 22:37:02 +0000 | [diff] [blame^] | 147 | .addReg(WBReg).addImm(0).addImm(Pred); |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 148 | else |
| 149 | MemMI = BuildMI(MF, MI->getDebugLoc(), |
| 150 | get(MemOpc)).addReg(MI->getOperand(1).getReg()) |
| 151 | .addReg(WBReg).addReg(0).addImm(0).addImm(Pred); |
| 152 | NewMIs.push_back(MemMI); |
| 153 | NewMIs.push_back(UpdateMI); |
| 154 | } else { |
| 155 | if (isLoad) |
| 156 | MemMI = BuildMI(MF, MI->getDebugLoc(), |
| 157 | get(MemOpc), MI->getOperand(0).getReg()) |
Jim Grosbach | 3e55612 | 2010-10-26 22:37:02 +0000 | [diff] [blame^] | 158 | .addReg(BaseReg).addImm(0).addImm(Pred); |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 159 | else |
| 160 | MemMI = BuildMI(MF, MI->getDebugLoc(), |
| 161 | get(MemOpc)).addReg(MI->getOperand(1).getReg()) |
| 162 | .addReg(BaseReg).addReg(0).addImm(0).addImm(Pred); |
| 163 | if (WB.isDead()) |
| 164 | UpdateMI->getOperand(0).setIsDead(); |
| 165 | NewMIs.push_back(UpdateMI); |
| 166 | NewMIs.push_back(MemMI); |
| 167 | } |
| 168 | |
| 169 | // Transfer LiveVariables states, kill / dead info. |
| 170 | if (LV) { |
| 171 | for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) { |
| 172 | MachineOperand &MO = MI->getOperand(i); |
| 173 | if (MO.isReg() && MO.getReg() && |
| 174 | TargetRegisterInfo::isVirtualRegister(MO.getReg())) { |
| 175 | unsigned Reg = MO.getReg(); |
| 176 | |
| 177 | LiveVariables::VarInfo &VI = LV->getVarInfo(Reg); |
| 178 | if (MO.isDef()) { |
| 179 | MachineInstr *NewMI = (Reg == WBReg) ? UpdateMI : MemMI; |
| 180 | if (MO.isDead()) |
| 181 | LV->addVirtualRegisterDead(Reg, NewMI); |
| 182 | } |
| 183 | if (MO.isUse() && MO.isKill()) { |
| 184 | for (unsigned j = 0; j < 2; ++j) { |
| 185 | // Look at the two new MI's in reverse order. |
| 186 | MachineInstr *NewMI = NewMIs[j]; |
| 187 | if (!NewMI->readsRegister(Reg)) |
| 188 | continue; |
| 189 | LV->addVirtualRegisterKilled(Reg, NewMI); |
| 190 | if (VI.removeKill(MI)) |
| 191 | VI.Kills.push_back(NewMI); |
| 192 | break; |
| 193 | } |
| 194 | } |
| 195 | } |
| 196 | } |
| 197 | } |
| 198 | |
| 199 | MFI->insert(MBBI, NewMIs[1]); |
| 200 | MFI->insert(MBBI, NewMIs[0]); |
| 201 | return NewMIs[0]; |
| 202 | } |
| 203 | |
Evan Cheng | 2457f2c | 2010-05-22 01:47:14 +0000 | [diff] [blame] | 204 | bool |
| 205 | ARMBaseInstrInfo::spillCalleeSavedRegisters(MachineBasicBlock &MBB, |
Jim Grosbach | 18f30e6 | 2010-06-02 21:53:11 +0000 | [diff] [blame] | 206 | MachineBasicBlock::iterator MI, |
| 207 | const std::vector<CalleeSavedInfo> &CSI, |
| 208 | const TargetRegisterInfo *TRI) const { |
Evan Cheng | 2457f2c | 2010-05-22 01:47:14 +0000 | [diff] [blame] | 209 | if (CSI.empty()) |
| 210 | return false; |
| 211 | |
| 212 | DebugLoc DL; |
| 213 | if (MI != MBB.end()) DL = MI->getDebugLoc(); |
| 214 | |
| 215 | for (unsigned i = 0, e = CSI.size(); i != e; ++i) { |
| 216 | unsigned Reg = CSI[i].getReg(); |
| 217 | bool isKill = true; |
| 218 | |
| 219 | // Add the callee-saved register as live-in unless it's LR and |
| 220 | // @llvm.returnaddress is called. If LR is returned for @llvm.returnaddress |
| 221 | // then it's already added to the function and entry block live-in sets. |
| 222 | if (Reg == ARM::LR) { |
| 223 | MachineFunction &MF = *MBB.getParent(); |
| 224 | if (MF.getFrameInfo()->isReturnAddressTaken() && |
| 225 | MF.getRegInfo().isLiveIn(Reg)) |
| 226 | isKill = false; |
| 227 | } |
| 228 | |
| 229 | if (isKill) |
| 230 | MBB.addLiveIn(Reg); |
| 231 | |
| 232 | // Insert the spill to the stack frame. The register is killed at the spill |
Michael J. Spencer | 2bbb769 | 2010-10-05 06:00:33 +0000 | [diff] [blame] | 233 | // |
Rafael Espindola | 42d075c | 2010-06-02 20:02:30 +0000 | [diff] [blame] | 234 | const TargetRegisterClass *RC = TRI->getMinimalPhysRegClass(Reg); |
Evan Cheng | 2457f2c | 2010-05-22 01:47:14 +0000 | [diff] [blame] | 235 | storeRegToStackSlot(MBB, MI, Reg, isKill, |
Rafael Espindola | 42d075c | 2010-06-02 20:02:30 +0000 | [diff] [blame] | 236 | CSI[i].getFrameIdx(), RC, TRI); |
Evan Cheng | 2457f2c | 2010-05-22 01:47:14 +0000 | [diff] [blame] | 237 | } |
| 238 | return true; |
| 239 | } |
| 240 | |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 241 | // Branch analysis. |
| 242 | bool |
| 243 | ARMBaseInstrInfo::AnalyzeBranch(MachineBasicBlock &MBB,MachineBasicBlock *&TBB, |
| 244 | MachineBasicBlock *&FBB, |
| 245 | SmallVectorImpl<MachineOperand> &Cond, |
| 246 | bool AllowModify) const { |
| 247 | // If the block has no terminators, it just falls into the block after it. |
| 248 | MachineBasicBlock::iterator I = MBB.end(); |
Dale Johannesen | 93d6a7e | 2010-04-02 01:38:09 +0000 | [diff] [blame] | 249 | if (I == MBB.begin()) |
| 250 | return false; |
| 251 | --I; |
| 252 | while (I->isDebugValue()) { |
| 253 | if (I == MBB.begin()) |
| 254 | return false; |
| 255 | --I; |
| 256 | } |
| 257 | if (!isUnpredicatedTerminator(I)) |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 258 | return false; |
| 259 | |
| 260 | // Get the last instruction in the block. |
| 261 | MachineInstr *LastInst = I; |
| 262 | |
| 263 | // If there is only one terminator instruction, process it. |
| 264 | unsigned LastOpc = LastInst->getOpcode(); |
| 265 | if (I == MBB.begin() || !isUnpredicatedTerminator(--I)) { |
Evan Cheng | 5ca53a7 | 2009-07-27 18:20:05 +0000 | [diff] [blame] | 266 | if (isUncondBranchOpcode(LastOpc)) { |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 267 | TBB = LastInst->getOperand(0).getMBB(); |
| 268 | return false; |
| 269 | } |
Evan Cheng | 5ca53a7 | 2009-07-27 18:20:05 +0000 | [diff] [blame] | 270 | if (isCondBranchOpcode(LastOpc)) { |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 271 | // Block ends with fall-through condbranch. |
| 272 | TBB = LastInst->getOperand(0).getMBB(); |
| 273 | Cond.push_back(LastInst->getOperand(1)); |
| 274 | Cond.push_back(LastInst->getOperand(2)); |
| 275 | return false; |
| 276 | } |
| 277 | return true; // Can't handle indirect branch. |
| 278 | } |
| 279 | |
| 280 | // Get the instruction before it if it is a terminator. |
| 281 | MachineInstr *SecondLastInst = I; |
Evan Cheng | 108c872 | 2010-09-23 06:54:40 +0000 | [diff] [blame] | 282 | unsigned SecondLastOpc = SecondLastInst->getOpcode(); |
| 283 | |
| 284 | // If AllowModify is true and the block ends with two or more unconditional |
| 285 | // branches, delete all but the first unconditional branch. |
| 286 | if (AllowModify && isUncondBranchOpcode(LastOpc)) { |
| 287 | while (isUncondBranchOpcode(SecondLastOpc)) { |
| 288 | LastInst->eraseFromParent(); |
| 289 | LastInst = SecondLastInst; |
| 290 | LastOpc = LastInst->getOpcode(); |
Evan Cheng | 676e258 | 2010-09-23 19:42:03 +0000 | [diff] [blame] | 291 | if (I == MBB.begin() || !isUnpredicatedTerminator(--I)) { |
| 292 | // Return now the only terminator is an unconditional branch. |
| 293 | TBB = LastInst->getOperand(0).getMBB(); |
| 294 | return false; |
| 295 | } else { |
Evan Cheng | 108c872 | 2010-09-23 06:54:40 +0000 | [diff] [blame] | 296 | SecondLastInst = I; |
| 297 | SecondLastOpc = SecondLastInst->getOpcode(); |
| 298 | } |
| 299 | } |
| 300 | } |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 301 | |
| 302 | // If there are three terminators, we don't know what sort of block this is. |
| 303 | if (SecondLastInst && I != MBB.begin() && isUnpredicatedTerminator(--I)) |
| 304 | return true; |
| 305 | |
Evan Cheng | 5ca53a7 | 2009-07-27 18:20:05 +0000 | [diff] [blame] | 306 | // If the block ends with a B and a Bcc, handle it. |
Evan Cheng | 5ca53a7 | 2009-07-27 18:20:05 +0000 | [diff] [blame] | 307 | if (isCondBranchOpcode(SecondLastOpc) && isUncondBranchOpcode(LastOpc)) { |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 308 | TBB = SecondLastInst->getOperand(0).getMBB(); |
| 309 | Cond.push_back(SecondLastInst->getOperand(1)); |
| 310 | Cond.push_back(SecondLastInst->getOperand(2)); |
| 311 | FBB = LastInst->getOperand(0).getMBB(); |
| 312 | return false; |
| 313 | } |
| 314 | |
| 315 | // If the block ends with two unconditional branches, handle it. The second |
| 316 | // one is not executed, so remove it. |
Evan Cheng | 5ca53a7 | 2009-07-27 18:20:05 +0000 | [diff] [blame] | 317 | if (isUncondBranchOpcode(SecondLastOpc) && isUncondBranchOpcode(LastOpc)) { |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 318 | TBB = SecondLastInst->getOperand(0).getMBB(); |
| 319 | I = LastInst; |
| 320 | if (AllowModify) |
| 321 | I->eraseFromParent(); |
| 322 | return false; |
| 323 | } |
| 324 | |
| 325 | // ...likewise if it ends with a branch table followed by an unconditional |
| 326 | // branch. The branch folder can create these, and we must get rid of them for |
| 327 | // correctness of Thumb constant islands. |
Bob Wilson | 8d4de5a | 2009-10-28 18:26:41 +0000 | [diff] [blame] | 328 | if ((isJumpTableBranchOpcode(SecondLastOpc) || |
| 329 | isIndirectBranchOpcode(SecondLastOpc)) && |
Evan Cheng | 5ca53a7 | 2009-07-27 18:20:05 +0000 | [diff] [blame] | 330 | isUncondBranchOpcode(LastOpc)) { |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 331 | I = LastInst; |
| 332 | if (AllowModify) |
| 333 | I->eraseFromParent(); |
| 334 | return true; |
| 335 | } |
| 336 | |
| 337 | // Otherwise, can't handle this. |
| 338 | return true; |
| 339 | } |
| 340 | |
| 341 | |
| 342 | unsigned ARMBaseInstrInfo::RemoveBranch(MachineBasicBlock &MBB) const { |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 343 | MachineBasicBlock::iterator I = MBB.end(); |
| 344 | if (I == MBB.begin()) return 0; |
| 345 | --I; |
Dale Johannesen | 93d6a7e | 2010-04-02 01:38:09 +0000 | [diff] [blame] | 346 | while (I->isDebugValue()) { |
| 347 | if (I == MBB.begin()) |
| 348 | return 0; |
| 349 | --I; |
| 350 | } |
Evan Cheng | 5ca53a7 | 2009-07-27 18:20:05 +0000 | [diff] [blame] | 351 | if (!isUncondBranchOpcode(I->getOpcode()) && |
| 352 | !isCondBranchOpcode(I->getOpcode())) |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 353 | return 0; |
| 354 | |
| 355 | // Remove the branch. |
| 356 | I->eraseFromParent(); |
| 357 | |
| 358 | I = MBB.end(); |
| 359 | |
| 360 | if (I == MBB.begin()) return 1; |
| 361 | --I; |
Evan Cheng | 5ca53a7 | 2009-07-27 18:20:05 +0000 | [diff] [blame] | 362 | if (!isCondBranchOpcode(I->getOpcode())) |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 363 | return 1; |
| 364 | |
| 365 | // Remove the branch. |
| 366 | I->eraseFromParent(); |
| 367 | return 2; |
| 368 | } |
| 369 | |
| 370 | unsigned |
| 371 | ARMBaseInstrInfo::InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB, |
Stuart Hastings | 3bf9125 | 2010-06-17 22:43:56 +0000 | [diff] [blame] | 372 | MachineBasicBlock *FBB, |
| 373 | const SmallVectorImpl<MachineOperand> &Cond, |
| 374 | DebugLoc DL) const { |
Evan Cheng | 6495f63 | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 375 | ARMFunctionInfo *AFI = MBB.getParent()->getInfo<ARMFunctionInfo>(); |
| 376 | int BOpc = !AFI->isThumbFunction() |
| 377 | ? ARM::B : (AFI->isThumb2Function() ? ARM::t2B : ARM::tB); |
| 378 | int BccOpc = !AFI->isThumbFunction() |
| 379 | ? ARM::Bcc : (AFI->isThumb2Function() ? ARM::t2Bcc : ARM::tBcc); |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 380 | |
| 381 | // Shouldn't be a fall through. |
| 382 | assert(TBB && "InsertBranch must not be told to insert a fallthrough"); |
| 383 | assert((Cond.size() == 2 || Cond.size() == 0) && |
| 384 | "ARM branch conditions have two components!"); |
| 385 | |
| 386 | if (FBB == 0) { |
| 387 | if (Cond.empty()) // Unconditional branch? |
Stuart Hastings | 3bf9125 | 2010-06-17 22:43:56 +0000 | [diff] [blame] | 388 | BuildMI(&MBB, DL, get(BOpc)).addMBB(TBB); |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 389 | else |
Stuart Hastings | 3bf9125 | 2010-06-17 22:43:56 +0000 | [diff] [blame] | 390 | BuildMI(&MBB, DL, get(BccOpc)).addMBB(TBB) |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 391 | .addImm(Cond[0].getImm()).addReg(Cond[1].getReg()); |
| 392 | return 1; |
| 393 | } |
| 394 | |
| 395 | // Two-way conditional branch. |
Stuart Hastings | 3bf9125 | 2010-06-17 22:43:56 +0000 | [diff] [blame] | 396 | BuildMI(&MBB, DL, get(BccOpc)).addMBB(TBB) |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 397 | .addImm(Cond[0].getImm()).addReg(Cond[1].getReg()); |
Stuart Hastings | 3bf9125 | 2010-06-17 22:43:56 +0000 | [diff] [blame] | 398 | BuildMI(&MBB, DL, get(BOpc)).addMBB(FBB); |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 399 | return 2; |
| 400 | } |
| 401 | |
| 402 | bool ARMBaseInstrInfo:: |
| 403 | ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const { |
| 404 | ARMCC::CondCodes CC = (ARMCC::CondCodes)(int)Cond[0].getImm(); |
| 405 | Cond[0].setImm(ARMCC::getOppositeCondition(CC)); |
| 406 | return false; |
| 407 | } |
| 408 | |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 409 | bool ARMBaseInstrInfo:: |
| 410 | PredicateInstruction(MachineInstr *MI, |
| 411 | const SmallVectorImpl<MachineOperand> &Pred) const { |
| 412 | unsigned Opc = MI->getOpcode(); |
Evan Cheng | 5ca53a7 | 2009-07-27 18:20:05 +0000 | [diff] [blame] | 413 | if (isUncondBranchOpcode(Opc)) { |
| 414 | MI->setDesc(get(getMatchingCondBranchOpcode(Opc))); |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 415 | MI->addOperand(MachineOperand::CreateImm(Pred[0].getImm())); |
| 416 | MI->addOperand(MachineOperand::CreateReg(Pred[1].getReg(), false)); |
| 417 | return true; |
| 418 | } |
| 419 | |
| 420 | int PIdx = MI->findFirstPredOperandIdx(); |
| 421 | if (PIdx != -1) { |
| 422 | MachineOperand &PMO = MI->getOperand(PIdx); |
| 423 | PMO.setImm(Pred[0].getImm()); |
| 424 | MI->getOperand(PIdx+1).setReg(Pred[1].getReg()); |
| 425 | return true; |
| 426 | } |
| 427 | return false; |
| 428 | } |
| 429 | |
| 430 | bool ARMBaseInstrInfo:: |
| 431 | SubsumesPredicate(const SmallVectorImpl<MachineOperand> &Pred1, |
| 432 | const SmallVectorImpl<MachineOperand> &Pred2) const { |
| 433 | if (Pred1.size() > 2 || Pred2.size() > 2) |
| 434 | return false; |
| 435 | |
| 436 | ARMCC::CondCodes CC1 = (ARMCC::CondCodes)Pred1[0].getImm(); |
| 437 | ARMCC::CondCodes CC2 = (ARMCC::CondCodes)Pred2[0].getImm(); |
| 438 | if (CC1 == CC2) |
| 439 | return true; |
| 440 | |
| 441 | switch (CC1) { |
| 442 | default: |
| 443 | return false; |
| 444 | case ARMCC::AL: |
| 445 | return true; |
| 446 | case ARMCC::HS: |
| 447 | return CC2 == ARMCC::HI; |
| 448 | case ARMCC::LS: |
| 449 | return CC2 == ARMCC::LO || CC2 == ARMCC::EQ; |
| 450 | case ARMCC::GE: |
| 451 | return CC2 == ARMCC::GT; |
| 452 | case ARMCC::LE: |
| 453 | return CC2 == ARMCC::LT; |
| 454 | } |
| 455 | } |
| 456 | |
| 457 | bool ARMBaseInstrInfo::DefinesPredicate(MachineInstr *MI, |
| 458 | std::vector<MachineOperand> &Pred) const { |
Evan Cheng | 8fb9036 | 2009-08-08 03:20:32 +0000 | [diff] [blame] | 459 | // FIXME: This confuses implicit_def with optional CPSR def. |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 460 | const TargetInstrDesc &TID = MI->getDesc(); |
| 461 | if (!TID.getImplicitDefs() && !TID.hasOptionalDef()) |
| 462 | return false; |
| 463 | |
| 464 | bool Found = false; |
| 465 | for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) { |
| 466 | const MachineOperand &MO = MI->getOperand(i); |
| 467 | if (MO.isReg() && MO.getReg() == ARM::CPSR) { |
| 468 | Pred.push_back(MO); |
| 469 | Found = true; |
| 470 | } |
| 471 | } |
| 472 | |
| 473 | return Found; |
| 474 | } |
| 475 | |
Evan Cheng | ac0869d | 2009-11-21 06:21:52 +0000 | [diff] [blame] | 476 | /// isPredicable - Return true if the specified instruction can be predicated. |
| 477 | /// By default, this returns true for every instruction with a |
| 478 | /// PredicateOperand. |
| 479 | bool ARMBaseInstrInfo::isPredicable(MachineInstr *MI) const { |
| 480 | const TargetInstrDesc &TID = MI->getDesc(); |
| 481 | if (!TID.isPredicable()) |
| 482 | return false; |
| 483 | |
| 484 | if ((TID.TSFlags & ARMII::DomainMask) == ARMII::DomainNEON) { |
| 485 | ARMFunctionInfo *AFI = |
| 486 | MI->getParent()->getParent()->getInfo<ARMFunctionInfo>(); |
Evan Cheng | d7f0810 | 2009-11-24 08:06:15 +0000 | [diff] [blame] | 487 | return AFI->isThumb2Function(); |
Evan Cheng | ac0869d | 2009-11-21 06:21:52 +0000 | [diff] [blame] | 488 | } |
| 489 | return true; |
| 490 | } |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 491 | |
Chris Lattner | 56856b1 | 2009-12-03 06:58:32 +0000 | [diff] [blame] | 492 | /// FIXME: Works around a gcc miscompilation with -fstrict-aliasing. |
Chandler Carruth | 19e5702 | 2010-10-23 08:40:19 +0000 | [diff] [blame] | 493 | LLVM_ATTRIBUTE_NOINLINE |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 494 | static unsigned getNumJTEntries(const std::vector<MachineJumpTableEntry> &JT, |
Chris Lattner | 56856b1 | 2009-12-03 06:58:32 +0000 | [diff] [blame] | 495 | unsigned JTI); |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 496 | static unsigned getNumJTEntries(const std::vector<MachineJumpTableEntry> &JT, |
| 497 | unsigned JTI) { |
Chris Lattner | 56856b1 | 2009-12-03 06:58:32 +0000 | [diff] [blame] | 498 | assert(JTI < JT.size()); |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 499 | return JT[JTI].MBBs.size(); |
| 500 | } |
| 501 | |
| 502 | /// GetInstSize - Return the size of the specified MachineInstr. |
| 503 | /// |
| 504 | unsigned ARMBaseInstrInfo::GetInstSizeInBytes(const MachineInstr *MI) const { |
| 505 | const MachineBasicBlock &MBB = *MI->getParent(); |
| 506 | const MachineFunction *MF = MBB.getParent(); |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 507 | const MCAsmInfo *MAI = MF->getTarget().getMCAsmInfo(); |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 508 | |
| 509 | // Basic size info comes from the TSFlags field. |
| 510 | const TargetInstrDesc &TID = MI->getDesc(); |
Bruno Cardoso Lopes | 99405df | 2010-06-08 22:51:23 +0000 | [diff] [blame] | 511 | uint64_t TSFlags = TID.TSFlags; |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 512 | |
Evan Cheng | a0ee862 | 2009-07-31 22:22:22 +0000 | [diff] [blame] | 513 | unsigned Opc = MI->getOpcode(); |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 514 | switch ((TSFlags & ARMII::SizeMask) >> ARMII::SizeShift) { |
| 515 | default: { |
| 516 | // If this machine instr is an inline asm, measure it. |
| 517 | if (MI->getOpcode() == ARM::INLINEASM) |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 518 | return getInlineAsmLength(MI->getOperand(0).getSymbolName(), *MAI); |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 519 | if (MI->isLabel()) |
| 520 | return 0; |
Evan Cheng | a0ee862 | 2009-07-31 22:22:22 +0000 | [diff] [blame] | 521 | switch (Opc) { |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 522 | default: |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 523 | llvm_unreachable("Unknown or unset size field for instr!"); |
Chris Lattner | 518bb53 | 2010-02-09 19:54:29 +0000 | [diff] [blame] | 524 | case TargetOpcode::IMPLICIT_DEF: |
| 525 | case TargetOpcode::KILL: |
Bill Wendling | 7431bea | 2010-07-16 22:20:36 +0000 | [diff] [blame] | 526 | case TargetOpcode::PROLOG_LABEL: |
Chris Lattner | 518bb53 | 2010-02-09 19:54:29 +0000 | [diff] [blame] | 527 | case TargetOpcode::EH_LABEL: |
Dale Johannesen | 375be77 | 2010-04-07 19:51:44 +0000 | [diff] [blame] | 528 | case TargetOpcode::DBG_VALUE: |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 529 | return 0; |
| 530 | } |
| 531 | break; |
| 532 | } |
Evan Cheng | 7894762 | 2009-07-24 18:20:44 +0000 | [diff] [blame] | 533 | case ARMII::Size8Bytes: return 8; // ARM instruction x 2. |
| 534 | case ARMII::Size4Bytes: return 4; // ARM / Thumb2 instruction. |
| 535 | case ARMII::Size2Bytes: return 2; // Thumb1 instruction. |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 536 | case ARMII::SizeSpecial: { |
Evan Cheng | a0ee862 | 2009-07-31 22:22:22 +0000 | [diff] [blame] | 537 | switch (Opc) { |
Jim Grosbach | 3c38f96 | 2010-10-06 22:01:26 +0000 | [diff] [blame] | 538 | case ARM::MOVi32imm: |
| 539 | case ARM::t2MOVi32imm: |
| 540 | return 8; |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 541 | case ARM::CONSTPOOL_ENTRY: |
| 542 | // If this machine instr is a constant pool entry, its size is recorded as |
| 543 | // operand #2. |
| 544 | return MI->getOperand(2).getImm(); |
Jim Grosbach | 5eb1951 | 2010-05-22 01:06:18 +0000 | [diff] [blame] | 545 | case ARM::Int_eh_sjlj_longjmp: |
| 546 | return 16; |
| 547 | case ARM::tInt_eh_sjlj_longjmp: |
| 548 | return 10; |
Evan Cheng | 7894762 | 2009-07-24 18:20:44 +0000 | [diff] [blame] | 549 | case ARM::Int_eh_sjlj_setjmp: |
Jim Grosbach | d100755 | 2010-04-28 20:33:09 +0000 | [diff] [blame] | 550 | case ARM::Int_eh_sjlj_setjmp_nofp: |
Jim Grosbach | 0798edd | 2010-05-27 23:49:24 +0000 | [diff] [blame] | 551 | return 20; |
Jim Grosbach | d122874 | 2009-12-01 18:10:36 +0000 | [diff] [blame] | 552 | case ARM::tInt_eh_sjlj_setjmp: |
Jim Grosbach | 5aa1684 | 2009-08-11 19:42:21 +0000 | [diff] [blame] | 553 | case ARM::t2Int_eh_sjlj_setjmp: |
Jim Grosbach | d100755 | 2010-04-28 20:33:09 +0000 | [diff] [blame] | 554 | case ARM::t2Int_eh_sjlj_setjmp_nofp: |
Jim Grosbach | 0798edd | 2010-05-27 23:49:24 +0000 | [diff] [blame] | 555 | return 12; |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 556 | case ARM::BR_JTr: |
| 557 | case ARM::BR_JTm: |
| 558 | case ARM::BR_JTadd: |
Evan Cheng | a0ee862 | 2009-07-31 22:22:22 +0000 | [diff] [blame] | 559 | case ARM::tBR_JTr: |
Evan Cheng | d26b14c | 2009-07-31 18:28:05 +0000 | [diff] [blame] | 560 | case ARM::t2BR_JT: |
| 561 | case ARM::t2TBB: |
| 562 | case ARM::t2TBH: { |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 563 | // These are jumptable branches, i.e. a branch followed by an inlined |
Evan Cheng | d26b14c | 2009-07-31 18:28:05 +0000 | [diff] [blame] | 564 | // jumptable. The size is 4 + 4 * number of entries. For TBB, each |
| 565 | // entry is one byte; TBH two byte each. |
Evan Cheng | a0ee862 | 2009-07-31 22:22:22 +0000 | [diff] [blame] | 566 | unsigned EntrySize = (Opc == ARM::t2TBB) |
| 567 | ? 1 : ((Opc == ARM::t2TBH) ? 2 : 4); |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 568 | unsigned NumOps = TID.getNumOperands(); |
| 569 | MachineOperand JTOP = |
| 570 | MI->getOperand(NumOps - (TID.isPredicable() ? 3 : 2)); |
| 571 | unsigned JTI = JTOP.getIndex(); |
| 572 | const MachineJumpTableInfo *MJTI = MF->getJumpTableInfo(); |
Chris Lattner | b1e8039 | 2010-01-25 23:22:00 +0000 | [diff] [blame] | 573 | assert(MJTI != 0); |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 574 | const std::vector<MachineJumpTableEntry> &JT = MJTI->getJumpTables(); |
| 575 | assert(JTI < JT.size()); |
| 576 | // Thumb instructions are 2 byte aligned, but JT entries are 4 byte |
| 577 | // 4 aligned. The assembler / linker may add 2 byte padding just before |
| 578 | // the JT entries. The size does not include this padding; the |
| 579 | // constant islands pass does separate bookkeeping for it. |
| 580 | // FIXME: If we know the size of the function is less than (1 << 16) *2 |
| 581 | // bytes, we can use 16-bit entries instead. Then there won't be an |
| 582 | // alignment issue. |
Evan Cheng | 25f7cfc | 2009-08-01 06:13:52 +0000 | [diff] [blame] | 583 | unsigned InstSize = (Opc == ARM::tBR_JTr || Opc == ARM::t2BR_JT) ? 2 : 4; |
| 584 | unsigned NumEntries = getNumJTEntries(JT, JTI); |
| 585 | if (Opc == ARM::t2TBB && (NumEntries & 1)) |
| 586 | // Make sure the instruction that follows TBB is 2-byte aligned. |
| 587 | // FIXME: Constant island pass should insert an "ALIGN" instruction |
| 588 | // instead. |
| 589 | ++NumEntries; |
| 590 | return NumEntries * EntrySize + InstSize; |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 591 | } |
| 592 | default: |
| 593 | // Otherwise, pseudo-instruction sizes are zero. |
| 594 | return 0; |
| 595 | } |
| 596 | } |
| 597 | } |
| 598 | return 0; // Not reached |
| 599 | } |
| 600 | |
Jakob Stoklund Olesen | ac27366 | 2010-07-11 06:33:54 +0000 | [diff] [blame] | 601 | void ARMBaseInstrInfo::copyPhysReg(MachineBasicBlock &MBB, |
| 602 | MachineBasicBlock::iterator I, DebugLoc DL, |
| 603 | unsigned DestReg, unsigned SrcReg, |
| 604 | bool KillSrc) const { |
| 605 | bool GPRDest = ARM::GPRRegClass.contains(DestReg); |
| 606 | bool GPRSrc = ARM::GPRRegClass.contains(SrcReg); |
Bob Wilson | 1665b0a | 2010-02-16 17:24:15 +0000 | [diff] [blame] | 607 | |
Jakob Stoklund Olesen | ac27366 | 2010-07-11 06:33:54 +0000 | [diff] [blame] | 608 | if (GPRDest && GPRSrc) { |
| 609 | AddDefaultCC(AddDefaultPred(BuildMI(MBB, I, DL, get(ARM::MOVr), DestReg) |
| 610 | .addReg(SrcReg, getKillRegState(KillSrc)))); |
| 611 | return; |
David Goodwin | 7bfdca0 | 2009-08-05 21:02:22 +0000 | [diff] [blame] | 612 | } |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 613 | |
Jakob Stoklund Olesen | ac27366 | 2010-07-11 06:33:54 +0000 | [diff] [blame] | 614 | bool SPRDest = ARM::SPRRegClass.contains(DestReg); |
| 615 | bool SPRSrc = ARM::SPRRegClass.contains(SrcReg); |
| 616 | |
| 617 | unsigned Opc; |
| 618 | if (SPRDest && SPRSrc) |
| 619 | Opc = ARM::VMOVS; |
| 620 | else if (GPRDest && SPRSrc) |
| 621 | Opc = ARM::VMOVRS; |
| 622 | else if (SPRDest && GPRSrc) |
| 623 | Opc = ARM::VMOVSR; |
| 624 | else if (ARM::DPRRegClass.contains(DestReg, SrcReg)) |
| 625 | Opc = ARM::VMOVD; |
| 626 | else if (ARM::QPRRegClass.contains(DestReg, SrcReg)) |
| 627 | Opc = ARM::VMOVQ; |
| 628 | else if (ARM::QQPRRegClass.contains(DestReg, SrcReg)) |
| 629 | Opc = ARM::VMOVQQ; |
| 630 | else if (ARM::QQQQPRRegClass.contains(DestReg, SrcReg)) |
| 631 | Opc = ARM::VMOVQQQQ; |
| 632 | else |
| 633 | llvm_unreachable("Impossible reg-to-reg copy"); |
| 634 | |
| 635 | MachineInstrBuilder MIB = BuildMI(MBB, I, DL, get(Opc), DestReg); |
| 636 | MIB.addReg(SrcReg, getKillRegState(KillSrc)); |
| 637 | if (Opc != ARM::VMOVQQ && Opc != ARM::VMOVQQQQ) |
| 638 | AddDefaultPred(MIB); |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 639 | } |
| 640 | |
Evan Cheng | c10b5af | 2010-05-07 00:24:52 +0000 | [diff] [blame] | 641 | static const |
| 642 | MachineInstrBuilder &AddDReg(MachineInstrBuilder &MIB, |
| 643 | unsigned Reg, unsigned SubIdx, unsigned State, |
| 644 | const TargetRegisterInfo *TRI) { |
| 645 | if (!SubIdx) |
| 646 | return MIB.addReg(Reg, State); |
| 647 | |
| 648 | if (TargetRegisterInfo::isPhysicalRegister(Reg)) |
| 649 | return MIB.addReg(TRI->getSubReg(Reg, SubIdx), State); |
| 650 | return MIB.addReg(Reg, State, SubIdx); |
| 651 | } |
| 652 | |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 653 | void ARMBaseInstrInfo:: |
| 654 | storeRegToStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator I, |
| 655 | unsigned SrcReg, bool isKill, int FI, |
Evan Cheng | 746ad69 | 2010-05-06 19:06:44 +0000 | [diff] [blame] | 656 | const TargetRegisterClass *RC, |
| 657 | const TargetRegisterInfo *TRI) const { |
Chris Lattner | c7f3ace | 2010-04-02 20:16:16 +0000 | [diff] [blame] | 658 | DebugLoc DL; |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 659 | if (I != MBB.end()) DL = I->getDebugLoc(); |
Anton Korobeynikov | 249fb33 | 2009-10-07 00:06:35 +0000 | [diff] [blame] | 660 | MachineFunction &MF = *MBB.getParent(); |
| 661 | MachineFrameInfo &MFI = *MF.getFrameInfo(); |
Jim Grosbach | 31bc849 | 2009-11-08 00:27:19 +0000 | [diff] [blame] | 662 | unsigned Align = MFI.getObjectAlignment(FI); |
Anton Korobeynikov | 249fb33 | 2009-10-07 00:06:35 +0000 | [diff] [blame] | 663 | |
| 664 | MachineMemOperand *MMO = |
Chris Lattner | 59db549 | 2010-09-21 04:39:43 +0000 | [diff] [blame] | 665 | MF.getMachineMemOperand(MachinePointerInfo( |
| 666 | PseudoSourceValue::getFixedStack(FI)), |
| 667 | MachineMemOperand::MOStore, |
Anton Korobeynikov | 249fb33 | 2009-10-07 00:06:35 +0000 | [diff] [blame] | 668 | MFI.getObjectSize(FI), |
Jim Grosbach | 31bc849 | 2009-11-08 00:27:19 +0000 | [diff] [blame] | 669 | Align); |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 670 | |
Bob Wilson | 0eb0c74 | 2010-02-16 22:01:59 +0000 | [diff] [blame] | 671 | // tGPR is used sometimes in ARM instructions that need to avoid using |
Jim Grosbach | 6ccfc50 | 2010-07-30 02:41:01 +0000 | [diff] [blame] | 672 | // certain registers. Just treat it as GPR here. Likewise, rGPR. |
| 673 | if (RC == ARM::tGPRRegisterClass || RC == ARM::tcGPRRegisterClass |
| 674 | || RC == ARM::rGPRRegisterClass) |
Bob Wilson | 0eb0c74 | 2010-02-16 22:01:59 +0000 | [diff] [blame] | 675 | RC = ARM::GPRRegisterClass; |
| 676 | |
Bob Wilson | ebe99b2 | 2010-06-18 21:32:42 +0000 | [diff] [blame] | 677 | switch (RC->getID()) { |
| 678 | case ARM::GPRRegClassID: |
Evan Cheng | 5732ca0 | 2009-07-27 03:14:20 +0000 | [diff] [blame] | 679 | AddDefaultPred(BuildMI(MBB, I, DL, get(ARM::STR)) |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 680 | .addReg(SrcReg, getKillRegState(isKill)) |
Anton Korobeynikov | 249fb33 | 2009-10-07 00:06:35 +0000 | [diff] [blame] | 681 | .addFrameIndex(FI).addReg(0).addImm(0).addMemOperand(MMO)); |
Bob Wilson | ebe99b2 | 2010-06-18 21:32:42 +0000 | [diff] [blame] | 682 | break; |
| 683 | case ARM::SPRRegClassID: |
Evan Cheng | d31c549 | 2010-05-06 01:34:11 +0000 | [diff] [blame] | 684 | AddDefaultPred(BuildMI(MBB, I, DL, get(ARM::VSTRS)) |
| 685 | .addReg(SrcReg, getKillRegState(isKill)) |
| 686 | .addFrameIndex(FI).addImm(0).addMemOperand(MMO)); |
Bob Wilson | ebe99b2 | 2010-06-18 21:32:42 +0000 | [diff] [blame] | 687 | break; |
| 688 | case ARM::DPRRegClassID: |
| 689 | case ARM::DPR_VFP2RegClassID: |
| 690 | case ARM::DPR_8RegClassID: |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 691 | AddDefaultPred(BuildMI(MBB, I, DL, get(ARM::VSTRD)) |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 692 | .addReg(SrcReg, getKillRegState(isKill)) |
Anton Korobeynikov | 249fb33 | 2009-10-07 00:06:35 +0000 | [diff] [blame] | 693 | .addFrameIndex(FI).addImm(0).addMemOperand(MMO)); |
Bob Wilson | ebe99b2 | 2010-06-18 21:32:42 +0000 | [diff] [blame] | 694 | break; |
| 695 | case ARM::QPRRegClassID: |
| 696 | case ARM::QPR_VFP2RegClassID: |
| 697 | case ARM::QPR_8RegClassID: |
Jim Grosbach | 0cfcf93 | 2010-09-08 00:26:59 +0000 | [diff] [blame] | 698 | if (Align >= 16 && getRegisterInfo().needsStackRealignment(MF)) { |
Bob Wilson | 168f382 | 2010-09-15 01:48:05 +0000 | [diff] [blame] | 699 | AddDefaultPred(BuildMI(MBB, I, DL, get(ARM::VST1q64Pseudo)) |
Bob Wilson | f967ca0 | 2010-07-06 21:26:18 +0000 | [diff] [blame] | 700 | .addFrameIndex(FI).addImm(16) |
Evan Cheng | 69b9f98 | 2010-05-13 01:12:06 +0000 | [diff] [blame] | 701 | .addReg(SrcReg, getKillRegState(isKill)) |
| 702 | .addMemOperand(MMO)); |
Jim Grosbach | 31bc849 | 2009-11-08 00:27:19 +0000 | [diff] [blame] | 703 | } else { |
Evan Cheng | 69b9f98 | 2010-05-13 01:12:06 +0000 | [diff] [blame] | 704 | AddDefaultPred(BuildMI(MBB, I, DL, get(ARM::VSTMQ)) |
| 705 | .addReg(SrcReg, getKillRegState(isKill)) |
| 706 | .addFrameIndex(FI) |
Bob Wilson | d4bfd54 | 2010-08-27 23:18:17 +0000 | [diff] [blame] | 707 | .addImm(ARM_AM::getAM4ModeImm(ARM_AM::ia)) |
Evan Cheng | 69b9f98 | 2010-05-13 01:12:06 +0000 | [diff] [blame] | 708 | .addMemOperand(MMO)); |
Jim Grosbach | 31bc849 | 2009-11-08 00:27:19 +0000 | [diff] [blame] | 709 | } |
Bob Wilson | ebe99b2 | 2010-06-18 21:32:42 +0000 | [diff] [blame] | 710 | break; |
| 711 | case ARM::QQPRRegClassID: |
| 712 | case ARM::QQPR_VFP2RegClassID: |
Evan Cheng | 435d499 | 2010-05-07 02:04:02 +0000 | [diff] [blame] | 713 | if (Align >= 16 && getRegisterInfo().canRealignStack(MF)) { |
Evan Cheng | 22c687b | 2010-05-14 02:13:41 +0000 | [diff] [blame] | 714 | // FIXME: It's possible to only store part of the QQ register if the |
| 715 | // spilled def has a sub-register index. |
Bob Wilson | 168f382 | 2010-09-15 01:48:05 +0000 | [diff] [blame] | 716 | AddDefaultPred(BuildMI(MBB, I, DL, get(ARM::VST1d64QPseudo)) |
| 717 | .addFrameIndex(FI).addImm(16) |
| 718 | .addReg(SrcReg, getKillRegState(isKill)) |
| 719 | .addMemOperand(MMO)); |
Evan Cheng | 435d499 | 2010-05-07 02:04:02 +0000 | [diff] [blame] | 720 | } else { |
| 721 | MachineInstrBuilder MIB = |
| 722 | AddDefaultPred(BuildMI(MBB, I, DL, get(ARM::VSTMD)) |
| 723 | .addFrameIndex(FI) |
Bob Wilson | d4bfd54 | 2010-08-27 23:18:17 +0000 | [diff] [blame] | 724 | .addImm(ARM_AM::getAM4ModeImm(ARM_AM::ia))) |
Evan Cheng | 435d499 | 2010-05-07 02:04:02 +0000 | [diff] [blame] | 725 | .addMemOperand(MMO); |
Jakob Stoklund Olesen | 558661d | 2010-05-24 16:54:32 +0000 | [diff] [blame] | 726 | MIB = AddDReg(MIB, SrcReg, ARM::dsub_0, getKillRegState(isKill), TRI); |
| 727 | MIB = AddDReg(MIB, SrcReg, ARM::dsub_1, 0, TRI); |
| 728 | MIB = AddDReg(MIB, SrcReg, ARM::dsub_2, 0, TRI); |
| 729 | AddDReg(MIB, SrcReg, ARM::dsub_3, 0, TRI); |
Evan Cheng | 435d499 | 2010-05-07 02:04:02 +0000 | [diff] [blame] | 730 | } |
Bob Wilson | ebe99b2 | 2010-06-18 21:32:42 +0000 | [diff] [blame] | 731 | break; |
| 732 | case ARM::QQQQPRRegClassID: { |
Evan Cheng | 22c687b | 2010-05-14 02:13:41 +0000 | [diff] [blame] | 733 | MachineInstrBuilder MIB = |
| 734 | AddDefaultPred(BuildMI(MBB, I, DL, get(ARM::VSTMD)) |
| 735 | .addFrameIndex(FI) |
Bob Wilson | d4bfd54 | 2010-08-27 23:18:17 +0000 | [diff] [blame] | 736 | .addImm(ARM_AM::getAM4ModeImm(ARM_AM::ia))) |
Evan Cheng | 22c687b | 2010-05-14 02:13:41 +0000 | [diff] [blame] | 737 | .addMemOperand(MMO); |
Jakob Stoklund Olesen | 558661d | 2010-05-24 16:54:32 +0000 | [diff] [blame] | 738 | MIB = AddDReg(MIB, SrcReg, ARM::dsub_0, getKillRegState(isKill), TRI); |
| 739 | MIB = AddDReg(MIB, SrcReg, ARM::dsub_1, 0, TRI); |
| 740 | MIB = AddDReg(MIB, SrcReg, ARM::dsub_2, 0, TRI); |
| 741 | MIB = AddDReg(MIB, SrcReg, ARM::dsub_3, 0, TRI); |
| 742 | MIB = AddDReg(MIB, SrcReg, ARM::dsub_4, 0, TRI); |
| 743 | MIB = AddDReg(MIB, SrcReg, ARM::dsub_5, 0, TRI); |
| 744 | MIB = AddDReg(MIB, SrcReg, ARM::dsub_6, 0, TRI); |
| 745 | AddDReg(MIB, SrcReg, ARM::dsub_7, 0, TRI); |
Bob Wilson | ebe99b2 | 2010-06-18 21:32:42 +0000 | [diff] [blame] | 746 | break; |
| 747 | } |
| 748 | default: |
| 749 | llvm_unreachable("Unknown regclass!"); |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 750 | } |
| 751 | } |
| 752 | |
Jakob Stoklund Olesen | 3432785 | 2010-09-15 16:36:26 +0000 | [diff] [blame] | 753 | unsigned |
| 754 | ARMBaseInstrInfo::isStoreToStackSlot(const MachineInstr *MI, |
| 755 | int &FrameIndex) const { |
| 756 | switch (MI->getOpcode()) { |
| 757 | default: break; |
| 758 | case ARM::STR: |
| 759 | case ARM::t2STRs: // FIXME: don't use t2STRs to access frame. |
| 760 | if (MI->getOperand(1).isFI() && |
| 761 | MI->getOperand(2).isReg() && |
| 762 | MI->getOperand(3).isImm() && |
| 763 | MI->getOperand(2).getReg() == 0 && |
| 764 | MI->getOperand(3).getImm() == 0) { |
| 765 | FrameIndex = MI->getOperand(1).getIndex(); |
| 766 | return MI->getOperand(0).getReg(); |
| 767 | } |
| 768 | break; |
| 769 | case ARM::t2STRi12: |
| 770 | case ARM::tSpill: |
| 771 | case ARM::VSTRD: |
| 772 | case ARM::VSTRS: |
| 773 | if (MI->getOperand(1).isFI() && |
| 774 | MI->getOperand(2).isImm() && |
| 775 | MI->getOperand(2).getImm() == 0) { |
| 776 | FrameIndex = MI->getOperand(1).getIndex(); |
| 777 | return MI->getOperand(0).getReg(); |
| 778 | } |
| 779 | break; |
Jakob Stoklund Olesen | d64816a | 2010-09-15 17:27:09 +0000 | [diff] [blame] | 780 | case ARM::VST1q64Pseudo: |
| 781 | if (MI->getOperand(0).isFI() && |
| 782 | MI->getOperand(2).getSubReg() == 0) { |
| 783 | FrameIndex = MI->getOperand(0).getIndex(); |
| 784 | return MI->getOperand(2).getReg(); |
| 785 | } |
Jakob Stoklund Olesen | 31bbc51 | 2010-09-15 21:40:09 +0000 | [diff] [blame] | 786 | break; |
Jakob Stoklund Olesen | d64816a | 2010-09-15 17:27:09 +0000 | [diff] [blame] | 787 | case ARM::VSTMQ: |
| 788 | if (MI->getOperand(1).isFI() && |
| 789 | MI->getOperand(2).isImm() && |
| 790 | MI->getOperand(2).getImm() == ARM_AM::getAM4ModeImm(ARM_AM::ia) && |
| 791 | MI->getOperand(0).getSubReg() == 0) { |
| 792 | FrameIndex = MI->getOperand(1).getIndex(); |
| 793 | return MI->getOperand(0).getReg(); |
| 794 | } |
| 795 | break; |
Jakob Stoklund Olesen | 3432785 | 2010-09-15 16:36:26 +0000 | [diff] [blame] | 796 | } |
| 797 | |
| 798 | return 0; |
| 799 | } |
| 800 | |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 801 | void ARMBaseInstrInfo:: |
| 802 | loadRegFromStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator I, |
| 803 | unsigned DestReg, int FI, |
Evan Cheng | 746ad69 | 2010-05-06 19:06:44 +0000 | [diff] [blame] | 804 | const TargetRegisterClass *RC, |
| 805 | const TargetRegisterInfo *TRI) const { |
Chris Lattner | c7f3ace | 2010-04-02 20:16:16 +0000 | [diff] [blame] | 806 | DebugLoc DL; |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 807 | if (I != MBB.end()) DL = I->getDebugLoc(); |
Anton Korobeynikov | 249fb33 | 2009-10-07 00:06:35 +0000 | [diff] [blame] | 808 | MachineFunction &MF = *MBB.getParent(); |
| 809 | MachineFrameInfo &MFI = *MF.getFrameInfo(); |
Jim Grosbach | 31bc849 | 2009-11-08 00:27:19 +0000 | [diff] [blame] | 810 | unsigned Align = MFI.getObjectAlignment(FI); |
Anton Korobeynikov | 249fb33 | 2009-10-07 00:06:35 +0000 | [diff] [blame] | 811 | MachineMemOperand *MMO = |
Chris Lattner | 59db549 | 2010-09-21 04:39:43 +0000 | [diff] [blame] | 812 | MF.getMachineMemOperand( |
| 813 | MachinePointerInfo(PseudoSourceValue::getFixedStack(FI)), |
| 814 | MachineMemOperand::MOLoad, |
Anton Korobeynikov | 249fb33 | 2009-10-07 00:06:35 +0000 | [diff] [blame] | 815 | MFI.getObjectSize(FI), |
Jim Grosbach | 31bc849 | 2009-11-08 00:27:19 +0000 | [diff] [blame] | 816 | Align); |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 817 | |
Bob Wilson | 0eb0c74 | 2010-02-16 22:01:59 +0000 | [diff] [blame] | 818 | // tGPR is used sometimes in ARM instructions that need to avoid using |
| 819 | // certain registers. Just treat it as GPR here. |
Jim Grosbach | 6ccfc50 | 2010-07-30 02:41:01 +0000 | [diff] [blame] | 820 | if (RC == ARM::tGPRRegisterClass || RC == ARM::tcGPRRegisterClass |
| 821 | || RC == ARM::rGPRRegisterClass) |
Bob Wilson | 0eb0c74 | 2010-02-16 22:01:59 +0000 | [diff] [blame] | 822 | RC = ARM::GPRRegisterClass; |
| 823 | |
Bob Wilson | ebe99b2 | 2010-06-18 21:32:42 +0000 | [diff] [blame] | 824 | switch (RC->getID()) { |
| 825 | case ARM::GPRRegClassID: |
Jim Grosbach | 3e55612 | 2010-10-26 22:37:02 +0000 | [diff] [blame^] | 826 | AddDefaultPred(BuildMI(MBB, I, DL, get(ARM::LDRi12), DestReg) |
| 827 | .addFrameIndex(FI).addImm(0).addMemOperand(MMO)); |
Bob Wilson | ebe99b2 | 2010-06-18 21:32:42 +0000 | [diff] [blame] | 828 | break; |
| 829 | case ARM::SPRRegClassID: |
Evan Cheng | d31c549 | 2010-05-06 01:34:11 +0000 | [diff] [blame] | 830 | AddDefaultPred(BuildMI(MBB, I, DL, get(ARM::VLDRS), DestReg) |
| 831 | .addFrameIndex(FI).addImm(0).addMemOperand(MMO)); |
Bob Wilson | ebe99b2 | 2010-06-18 21:32:42 +0000 | [diff] [blame] | 832 | break; |
| 833 | case ARM::DPRRegClassID: |
| 834 | case ARM::DPR_VFP2RegClassID: |
| 835 | case ARM::DPR_8RegClassID: |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 836 | AddDefaultPred(BuildMI(MBB, I, DL, get(ARM::VLDRD), DestReg) |
Anton Korobeynikov | 249fb33 | 2009-10-07 00:06:35 +0000 | [diff] [blame] | 837 | .addFrameIndex(FI).addImm(0).addMemOperand(MMO)); |
Bob Wilson | ebe99b2 | 2010-06-18 21:32:42 +0000 | [diff] [blame] | 838 | break; |
| 839 | case ARM::QPRRegClassID: |
| 840 | case ARM::QPR_VFP2RegClassID: |
| 841 | case ARM::QPR_8RegClassID: |
Jim Grosbach | 0cfcf93 | 2010-09-08 00:26:59 +0000 | [diff] [blame] | 842 | if (Align >= 16 && getRegisterInfo().needsStackRealignment(MF)) { |
Bob Wilson | 168f382 | 2010-09-15 01:48:05 +0000 | [diff] [blame] | 843 | AddDefaultPred(BuildMI(MBB, I, DL, get(ARM::VLD1q64Pseudo), DestReg) |
Bob Wilson | f967ca0 | 2010-07-06 21:26:18 +0000 | [diff] [blame] | 844 | .addFrameIndex(FI).addImm(16) |
Evan Cheng | 69b9f98 | 2010-05-13 01:12:06 +0000 | [diff] [blame] | 845 | .addMemOperand(MMO)); |
Jim Grosbach | 31bc849 | 2009-11-08 00:27:19 +0000 | [diff] [blame] | 846 | } else { |
Evan Cheng | 69b9f98 | 2010-05-13 01:12:06 +0000 | [diff] [blame] | 847 | AddDefaultPred(BuildMI(MBB, I, DL, get(ARM::VLDMQ), DestReg) |
| 848 | .addFrameIndex(FI) |
Bob Wilson | d4bfd54 | 2010-08-27 23:18:17 +0000 | [diff] [blame] | 849 | .addImm(ARM_AM::getAM4ModeImm(ARM_AM::ia)) |
Evan Cheng | 69b9f98 | 2010-05-13 01:12:06 +0000 | [diff] [blame] | 850 | .addMemOperand(MMO)); |
Jim Grosbach | 31bc849 | 2009-11-08 00:27:19 +0000 | [diff] [blame] | 851 | } |
Bob Wilson | ebe99b2 | 2010-06-18 21:32:42 +0000 | [diff] [blame] | 852 | break; |
| 853 | case ARM::QQPRRegClassID: |
| 854 | case ARM::QQPR_VFP2RegClassID: |
Evan Cheng | 435d499 | 2010-05-07 02:04:02 +0000 | [diff] [blame] | 855 | if (Align >= 16 && getRegisterInfo().canRealignStack(MF)) { |
Bob Wilson | 168f382 | 2010-09-15 01:48:05 +0000 | [diff] [blame] | 856 | AddDefaultPred(BuildMI(MBB, I, DL, get(ARM::VLD1d64QPseudo), DestReg) |
| 857 | .addFrameIndex(FI).addImm(16) |
| 858 | .addMemOperand(MMO)); |
Evan Cheng | 435d499 | 2010-05-07 02:04:02 +0000 | [diff] [blame] | 859 | } else { |
| 860 | MachineInstrBuilder MIB = |
| 861 | AddDefaultPred(BuildMI(MBB, I, DL, get(ARM::VLDMD)) |
| 862 | .addFrameIndex(FI) |
Bob Wilson | d4bfd54 | 2010-08-27 23:18:17 +0000 | [diff] [blame] | 863 | .addImm(ARM_AM::getAM4ModeImm(ARM_AM::ia))) |
Evan Cheng | 435d499 | 2010-05-07 02:04:02 +0000 | [diff] [blame] | 864 | .addMemOperand(MMO); |
Jakob Stoklund Olesen | 558661d | 2010-05-24 16:54:32 +0000 | [diff] [blame] | 865 | MIB = AddDReg(MIB, DestReg, ARM::dsub_0, RegState::Define, TRI); |
| 866 | MIB = AddDReg(MIB, DestReg, ARM::dsub_1, RegState::Define, TRI); |
| 867 | MIB = AddDReg(MIB, DestReg, ARM::dsub_2, RegState::Define, TRI); |
| 868 | AddDReg(MIB, DestReg, ARM::dsub_3, RegState::Define, TRI); |
Evan Cheng | 435d499 | 2010-05-07 02:04:02 +0000 | [diff] [blame] | 869 | } |
Bob Wilson | ebe99b2 | 2010-06-18 21:32:42 +0000 | [diff] [blame] | 870 | break; |
| 871 | case ARM::QQQQPRRegClassID: { |
| 872 | MachineInstrBuilder MIB = |
| 873 | AddDefaultPred(BuildMI(MBB, I, DL, get(ARM::VLDMD)) |
| 874 | .addFrameIndex(FI) |
Bob Wilson | d4bfd54 | 2010-08-27 23:18:17 +0000 | [diff] [blame] | 875 | .addImm(ARM_AM::getAM4ModeImm(ARM_AM::ia))) |
Bob Wilson | ebe99b2 | 2010-06-18 21:32:42 +0000 | [diff] [blame] | 876 | .addMemOperand(MMO); |
| 877 | MIB = AddDReg(MIB, DestReg, ARM::dsub_0, RegState::Define, TRI); |
| 878 | MIB = AddDReg(MIB, DestReg, ARM::dsub_1, RegState::Define, TRI); |
| 879 | MIB = AddDReg(MIB, DestReg, ARM::dsub_2, RegState::Define, TRI); |
| 880 | MIB = AddDReg(MIB, DestReg, ARM::dsub_3, RegState::Define, TRI); |
| 881 | MIB = AddDReg(MIB, DestReg, ARM::dsub_4, RegState::Define, TRI); |
| 882 | MIB = AddDReg(MIB, DestReg, ARM::dsub_5, RegState::Define, TRI); |
| 883 | MIB = AddDReg(MIB, DestReg, ARM::dsub_6, RegState::Define, TRI); |
| 884 | AddDReg(MIB, DestReg, ARM::dsub_7, RegState::Define, TRI); |
| 885 | break; |
| 886 | } |
| 887 | default: |
| 888 | llvm_unreachable("Unknown regclass!"); |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 889 | } |
| 890 | } |
| 891 | |
Jakob Stoklund Olesen | 3432785 | 2010-09-15 16:36:26 +0000 | [diff] [blame] | 892 | unsigned |
| 893 | ARMBaseInstrInfo::isLoadFromStackSlot(const MachineInstr *MI, |
| 894 | int &FrameIndex) const { |
| 895 | switch (MI->getOpcode()) { |
| 896 | default: break; |
Jim Grosbach | 3e55612 | 2010-10-26 22:37:02 +0000 | [diff] [blame^] | 897 | case ARM::LDRrs: |
Jakob Stoklund Olesen | 3432785 | 2010-09-15 16:36:26 +0000 | [diff] [blame] | 898 | case ARM::t2LDRs: // FIXME: don't use t2LDRs to access frame. |
| 899 | if (MI->getOperand(1).isFI() && |
| 900 | MI->getOperand(2).isReg() && |
| 901 | MI->getOperand(3).isImm() && |
| 902 | MI->getOperand(2).getReg() == 0 && |
| 903 | MI->getOperand(3).getImm() == 0) { |
| 904 | FrameIndex = MI->getOperand(1).getIndex(); |
| 905 | return MI->getOperand(0).getReg(); |
| 906 | } |
| 907 | break; |
Jim Grosbach | 3e55612 | 2010-10-26 22:37:02 +0000 | [diff] [blame^] | 908 | case ARM::LDRi12: |
Jakob Stoklund Olesen | 3432785 | 2010-09-15 16:36:26 +0000 | [diff] [blame] | 909 | case ARM::t2LDRi12: |
| 910 | case ARM::tRestore: |
| 911 | case ARM::VLDRD: |
| 912 | case ARM::VLDRS: |
| 913 | if (MI->getOperand(1).isFI() && |
| 914 | MI->getOperand(2).isImm() && |
| 915 | MI->getOperand(2).getImm() == 0) { |
| 916 | FrameIndex = MI->getOperand(1).getIndex(); |
| 917 | return MI->getOperand(0).getReg(); |
| 918 | } |
| 919 | break; |
Jakob Stoklund Olesen | d64816a | 2010-09-15 17:27:09 +0000 | [diff] [blame] | 920 | case ARM::VLD1q64Pseudo: |
| 921 | if (MI->getOperand(1).isFI() && |
| 922 | MI->getOperand(0).getSubReg() == 0) { |
| 923 | FrameIndex = MI->getOperand(1).getIndex(); |
| 924 | return MI->getOperand(0).getReg(); |
| 925 | } |
| 926 | break; |
Jakob Stoklund Olesen | 06f264e | 2010-09-15 21:40:11 +0000 | [diff] [blame] | 927 | case ARM::VLDMQ: |
| 928 | if (MI->getOperand(1).isFI() && |
| 929 | MI->getOperand(2).isImm() && |
| 930 | MI->getOperand(2).getImm() == ARM_AM::getAM4ModeImm(ARM_AM::ia) && |
| 931 | MI->getOperand(0).getSubReg() == 0) { |
| 932 | FrameIndex = MI->getOperand(1).getIndex(); |
| 933 | return MI->getOperand(0).getReg(); |
| 934 | } |
| 935 | break; |
Jakob Stoklund Olesen | 3432785 | 2010-09-15 16:36:26 +0000 | [diff] [blame] | 936 | } |
| 937 | |
| 938 | return 0; |
| 939 | } |
| 940 | |
Evan Cheng | 62b5065 | 2010-04-26 07:39:25 +0000 | [diff] [blame] | 941 | MachineInstr* |
| 942 | ARMBaseInstrInfo::emitFrameIndexDebugValue(MachineFunction &MF, |
Evan Cheng | 8601a3d | 2010-04-29 01:13:30 +0000 | [diff] [blame] | 943 | int FrameIx, uint64_t Offset, |
Evan Cheng | 62b5065 | 2010-04-26 07:39:25 +0000 | [diff] [blame] | 944 | const MDNode *MDPtr, |
| 945 | DebugLoc DL) const { |
| 946 | MachineInstrBuilder MIB = BuildMI(MF, DL, get(ARM::DBG_VALUE)) |
| 947 | .addFrameIndex(FrameIx).addImm(0).addImm(Offset).addMetadata(MDPtr); |
| 948 | return &*MIB; |
| 949 | } |
| 950 | |
Jakob Stoklund Olesen | 30ac046 | 2010-01-06 23:47:07 +0000 | [diff] [blame] | 951 | /// Create a copy of a const pool value. Update CPI to the new index and return |
| 952 | /// the label UID. |
| 953 | static unsigned duplicateCPV(MachineFunction &MF, unsigned &CPI) { |
| 954 | MachineConstantPool *MCP = MF.getConstantPool(); |
| 955 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
| 956 | |
| 957 | const MachineConstantPoolEntry &MCPE = MCP->getConstants()[CPI]; |
| 958 | assert(MCPE.isMachineConstantPoolEntry() && |
| 959 | "Expecting a machine constantpool entry!"); |
| 960 | ARMConstantPoolValue *ACPV = |
| 961 | static_cast<ARMConstantPoolValue*>(MCPE.Val.MachineCPVal); |
| 962 | |
| 963 | unsigned PCLabelId = AFI->createConstPoolEntryUId(); |
| 964 | ARMConstantPoolValue *NewCPV = 0; |
Jim Grosbach | 51f5b67 | 2010-09-10 21:38:22 +0000 | [diff] [blame] | 965 | // FIXME: The below assumes PIC relocation model and that the function |
| 966 | // is Thumb mode (t1 or t2). PCAdjustment would be 8 for ARM mode PIC, and |
| 967 | // zero for non-PIC in ARM or Thumb. The callers are all of thumb LDR |
| 968 | // instructions, so that's probably OK, but is PIC always correct when |
| 969 | // we get here? |
Jakob Stoklund Olesen | 30ac046 | 2010-01-06 23:47:07 +0000 | [diff] [blame] | 970 | if (ACPV->isGlobalValue()) |
| 971 | NewCPV = new ARMConstantPoolValue(ACPV->getGV(), PCLabelId, |
| 972 | ARMCP::CPValue, 4); |
| 973 | else if (ACPV->isExtSymbol()) |
| 974 | NewCPV = new ARMConstantPoolValue(MF.getFunction()->getContext(), |
| 975 | ACPV->getSymbol(), PCLabelId, 4); |
| 976 | else if (ACPV->isBlockAddress()) |
| 977 | NewCPV = new ARMConstantPoolValue(ACPV->getBlockAddress(), PCLabelId, |
| 978 | ARMCP::CPBlockAddress, 4); |
Jim Grosbach | 51f5b67 | 2010-09-10 21:38:22 +0000 | [diff] [blame] | 979 | else if (ACPV->isLSDA()) |
| 980 | NewCPV = new ARMConstantPoolValue(MF.getFunction(), PCLabelId, |
| 981 | ARMCP::CPLSDA, 4); |
Jakob Stoklund Olesen | 30ac046 | 2010-01-06 23:47:07 +0000 | [diff] [blame] | 982 | else |
| 983 | llvm_unreachable("Unexpected ARM constantpool value type!!"); |
| 984 | CPI = MCP->getConstantPoolIndex(NewCPV, MCPE.getAlignment()); |
| 985 | return PCLabelId; |
| 986 | } |
| 987 | |
Evan Cheng | fdc8340 | 2009-11-08 00:15:23 +0000 | [diff] [blame] | 988 | void ARMBaseInstrInfo:: |
| 989 | reMaterialize(MachineBasicBlock &MBB, |
| 990 | MachineBasicBlock::iterator I, |
| 991 | unsigned DestReg, unsigned SubIdx, |
Evan Cheng | d57cdd5 | 2009-11-14 02:55:43 +0000 | [diff] [blame] | 992 | const MachineInstr *Orig, |
Jakob Stoklund Olesen | 9edf7de | 2010-06-02 22:47:25 +0000 | [diff] [blame] | 993 | const TargetRegisterInfo &TRI) const { |
Evan Cheng | fdc8340 | 2009-11-08 00:15:23 +0000 | [diff] [blame] | 994 | unsigned Opcode = Orig->getOpcode(); |
| 995 | switch (Opcode) { |
| 996 | default: { |
| 997 | MachineInstr *MI = MBB.getParent()->CloneMachineInstr(Orig); |
Jakob Stoklund Olesen | 9edf7de | 2010-06-02 22:47:25 +0000 | [diff] [blame] | 998 | MI->substituteRegister(Orig->getOperand(0).getReg(), DestReg, SubIdx, TRI); |
Evan Cheng | fdc8340 | 2009-11-08 00:15:23 +0000 | [diff] [blame] | 999 | MBB.insert(I, MI); |
| 1000 | break; |
| 1001 | } |
| 1002 | case ARM::tLDRpci_pic: |
| 1003 | case ARM::t2LDRpci_pic: { |
| 1004 | MachineFunction &MF = *MBB.getParent(); |
Evan Cheng | fdc8340 | 2009-11-08 00:15:23 +0000 | [diff] [blame] | 1005 | unsigned CPI = Orig->getOperand(1).getIndex(); |
Jakob Stoklund Olesen | 30ac046 | 2010-01-06 23:47:07 +0000 | [diff] [blame] | 1006 | unsigned PCLabelId = duplicateCPV(MF, CPI); |
Evan Cheng | fdc8340 | 2009-11-08 00:15:23 +0000 | [diff] [blame] | 1007 | MachineInstrBuilder MIB = BuildMI(MBB, I, Orig->getDebugLoc(), get(Opcode), |
| 1008 | DestReg) |
| 1009 | .addConstantPoolIndex(CPI).addImm(PCLabelId); |
| 1010 | (*MIB).setMemRefs(Orig->memoperands_begin(), Orig->memoperands_end()); |
| 1011 | break; |
| 1012 | } |
| 1013 | } |
Evan Cheng | fdc8340 | 2009-11-08 00:15:23 +0000 | [diff] [blame] | 1014 | } |
| 1015 | |
Jakob Stoklund Olesen | 30ac046 | 2010-01-06 23:47:07 +0000 | [diff] [blame] | 1016 | MachineInstr * |
| 1017 | ARMBaseInstrInfo::duplicate(MachineInstr *Orig, MachineFunction &MF) const { |
| 1018 | MachineInstr *MI = TargetInstrInfoImpl::duplicate(Orig, MF); |
| 1019 | switch(Orig->getOpcode()) { |
| 1020 | case ARM::tLDRpci_pic: |
| 1021 | case ARM::t2LDRpci_pic: { |
| 1022 | unsigned CPI = Orig->getOperand(1).getIndex(); |
| 1023 | unsigned PCLabelId = duplicateCPV(MF, CPI); |
| 1024 | Orig->getOperand(1).setIndex(CPI); |
| 1025 | Orig->getOperand(2).setImm(PCLabelId); |
| 1026 | break; |
| 1027 | } |
| 1028 | } |
| 1029 | return MI; |
| 1030 | } |
| 1031 | |
Evan Cheng | 506049f | 2010-03-03 01:44:33 +0000 | [diff] [blame] | 1032 | bool ARMBaseInstrInfo::produceSameValue(const MachineInstr *MI0, |
| 1033 | const MachineInstr *MI1) const { |
Evan Cheng | d457e6e | 2009-11-07 04:04:34 +0000 | [diff] [blame] | 1034 | int Opcode = MI0->getOpcode(); |
Evan Cheng | 9b82425 | 2009-11-20 02:10:27 +0000 | [diff] [blame] | 1035 | if (Opcode == ARM::t2LDRpci || |
| 1036 | Opcode == ARM::t2LDRpci_pic || |
| 1037 | Opcode == ARM::tLDRpci || |
| 1038 | Opcode == ARM::tLDRpci_pic) { |
Evan Cheng | d457e6e | 2009-11-07 04:04:34 +0000 | [diff] [blame] | 1039 | if (MI1->getOpcode() != Opcode) |
| 1040 | return false; |
| 1041 | if (MI0->getNumOperands() != MI1->getNumOperands()) |
| 1042 | return false; |
| 1043 | |
| 1044 | const MachineOperand &MO0 = MI0->getOperand(1); |
| 1045 | const MachineOperand &MO1 = MI1->getOperand(1); |
| 1046 | if (MO0.getOffset() != MO1.getOffset()) |
| 1047 | return false; |
| 1048 | |
| 1049 | const MachineFunction *MF = MI0->getParent()->getParent(); |
| 1050 | const MachineConstantPool *MCP = MF->getConstantPool(); |
| 1051 | int CPI0 = MO0.getIndex(); |
| 1052 | int CPI1 = MO1.getIndex(); |
| 1053 | const MachineConstantPoolEntry &MCPE0 = MCP->getConstants()[CPI0]; |
| 1054 | const MachineConstantPoolEntry &MCPE1 = MCP->getConstants()[CPI1]; |
| 1055 | ARMConstantPoolValue *ACPV0 = |
| 1056 | static_cast<ARMConstantPoolValue*>(MCPE0.Val.MachineCPVal); |
| 1057 | ARMConstantPoolValue *ACPV1 = |
| 1058 | static_cast<ARMConstantPoolValue*>(MCPE1.Val.MachineCPVal); |
| 1059 | return ACPV0->hasSameValue(ACPV1); |
| 1060 | } |
| 1061 | |
Evan Cheng | 506049f | 2010-03-03 01:44:33 +0000 | [diff] [blame] | 1062 | return MI0->isIdenticalTo(MI1, MachineInstr::IgnoreVRegDefs); |
Evan Cheng | d457e6e | 2009-11-07 04:04:34 +0000 | [diff] [blame] | 1063 | } |
| 1064 | |
Bill Wendling | 4b72210 | 2010-06-23 23:00:16 +0000 | [diff] [blame] | 1065 | /// areLoadsFromSameBasePtr - This is used by the pre-regalloc scheduler to |
| 1066 | /// determine if two loads are loading from the same base address. It should |
| 1067 | /// only return true if the base pointers are the same and the only differences |
| 1068 | /// between the two addresses is the offset. It also returns the offsets by |
| 1069 | /// reference. |
| 1070 | bool ARMBaseInstrInfo::areLoadsFromSameBasePtr(SDNode *Load1, SDNode *Load2, |
| 1071 | int64_t &Offset1, |
| 1072 | int64_t &Offset2) const { |
| 1073 | // Don't worry about Thumb: just ARM and Thumb2. |
| 1074 | if (Subtarget.isThumb1Only()) return false; |
| 1075 | |
| 1076 | if (!Load1->isMachineOpcode() || !Load2->isMachineOpcode()) |
| 1077 | return false; |
| 1078 | |
| 1079 | switch (Load1->getMachineOpcode()) { |
| 1080 | default: |
| 1081 | return false; |
Jim Grosbach | 3e55612 | 2010-10-26 22:37:02 +0000 | [diff] [blame^] | 1082 | case ARM::LDRi12: |
Bill Wendling | 4b72210 | 2010-06-23 23:00:16 +0000 | [diff] [blame] | 1083 | case ARM::LDRB: |
| 1084 | case ARM::LDRD: |
| 1085 | case ARM::LDRH: |
| 1086 | case ARM::LDRSB: |
| 1087 | case ARM::LDRSH: |
| 1088 | case ARM::VLDRD: |
| 1089 | case ARM::VLDRS: |
| 1090 | case ARM::t2LDRi8: |
| 1091 | case ARM::t2LDRDi8: |
| 1092 | case ARM::t2LDRSHi8: |
| 1093 | case ARM::t2LDRi12: |
| 1094 | case ARM::t2LDRSHi12: |
| 1095 | break; |
| 1096 | } |
| 1097 | |
| 1098 | switch (Load2->getMachineOpcode()) { |
| 1099 | default: |
| 1100 | return false; |
Jim Grosbach | 3e55612 | 2010-10-26 22:37:02 +0000 | [diff] [blame^] | 1101 | case ARM::LDRi12: |
Bill Wendling | 4b72210 | 2010-06-23 23:00:16 +0000 | [diff] [blame] | 1102 | case ARM::LDRB: |
| 1103 | case ARM::LDRD: |
| 1104 | case ARM::LDRH: |
| 1105 | case ARM::LDRSB: |
| 1106 | case ARM::LDRSH: |
| 1107 | case ARM::VLDRD: |
| 1108 | case ARM::VLDRS: |
| 1109 | case ARM::t2LDRi8: |
| 1110 | case ARM::t2LDRDi8: |
| 1111 | case ARM::t2LDRSHi8: |
| 1112 | case ARM::t2LDRi12: |
| 1113 | case ARM::t2LDRSHi12: |
| 1114 | break; |
| 1115 | } |
| 1116 | |
| 1117 | // Check if base addresses and chain operands match. |
| 1118 | if (Load1->getOperand(0) != Load2->getOperand(0) || |
| 1119 | Load1->getOperand(4) != Load2->getOperand(4)) |
| 1120 | return false; |
| 1121 | |
| 1122 | // Index should be Reg0. |
| 1123 | if (Load1->getOperand(3) != Load2->getOperand(3)) |
| 1124 | return false; |
| 1125 | |
| 1126 | // Determine the offsets. |
| 1127 | if (isa<ConstantSDNode>(Load1->getOperand(1)) && |
| 1128 | isa<ConstantSDNode>(Load2->getOperand(1))) { |
| 1129 | Offset1 = cast<ConstantSDNode>(Load1->getOperand(1))->getSExtValue(); |
| 1130 | Offset2 = cast<ConstantSDNode>(Load2->getOperand(1))->getSExtValue(); |
| 1131 | return true; |
| 1132 | } |
| 1133 | |
| 1134 | return false; |
| 1135 | } |
| 1136 | |
| 1137 | /// shouldScheduleLoadsNear - This is a used by the pre-regalloc scheduler to |
| 1138 | /// determine (in conjuction with areLoadsFromSameBasePtr) if two loads should |
| 1139 | /// be scheduled togther. On some targets if two loads are loading from |
| 1140 | /// addresses in the same cache line, it's better if they are scheduled |
| 1141 | /// together. This function takes two integers that represent the load offsets |
| 1142 | /// from the common base address. It returns true if it decides it's desirable |
| 1143 | /// to schedule the two loads together. "NumLoads" is the number of loads that |
| 1144 | /// have already been scheduled after Load1. |
| 1145 | bool ARMBaseInstrInfo::shouldScheduleLoadsNear(SDNode *Load1, SDNode *Load2, |
| 1146 | int64_t Offset1, int64_t Offset2, |
| 1147 | unsigned NumLoads) const { |
| 1148 | // Don't worry about Thumb: just ARM and Thumb2. |
| 1149 | if (Subtarget.isThumb1Only()) return false; |
| 1150 | |
| 1151 | assert(Offset2 > Offset1); |
| 1152 | |
| 1153 | if ((Offset2 - Offset1) / 8 > 64) |
| 1154 | return false; |
| 1155 | |
| 1156 | if (Load1->getMachineOpcode() != Load2->getMachineOpcode()) |
| 1157 | return false; // FIXME: overly conservative? |
| 1158 | |
| 1159 | // Four loads in a row should be sufficient. |
| 1160 | if (NumLoads >= 3) |
| 1161 | return false; |
| 1162 | |
| 1163 | return true; |
| 1164 | } |
| 1165 | |
Evan Cheng | 86050dc | 2010-06-18 23:09:54 +0000 | [diff] [blame] | 1166 | bool ARMBaseInstrInfo::isSchedulingBoundary(const MachineInstr *MI, |
| 1167 | const MachineBasicBlock *MBB, |
| 1168 | const MachineFunction &MF) const { |
Jim Grosbach | 57bb394 | 2010-06-25 18:43:14 +0000 | [diff] [blame] | 1169 | // Debug info is never a scheduling boundary. It's necessary to be explicit |
| 1170 | // due to the special treatment of IT instructions below, otherwise a |
| 1171 | // dbg_value followed by an IT will result in the IT instruction being |
| 1172 | // considered a scheduling hazard, which is wrong. It should be the actual |
| 1173 | // instruction preceding the dbg_value instruction(s), just like it is |
| 1174 | // when debug info is not present. |
| 1175 | if (MI->isDebugValue()) |
| 1176 | return false; |
| 1177 | |
Evan Cheng | 86050dc | 2010-06-18 23:09:54 +0000 | [diff] [blame] | 1178 | // Terminators and labels can't be scheduled around. |
| 1179 | if (MI->getDesc().isTerminator() || MI->isLabel()) |
| 1180 | return true; |
| 1181 | |
| 1182 | // Treat the start of the IT block as a scheduling boundary, but schedule |
| 1183 | // t2IT along with all instructions following it. |
| 1184 | // FIXME: This is a big hammer. But the alternative is to add all potential |
| 1185 | // true and anti dependencies to IT block instructions as implicit operands |
| 1186 | // to the t2IT instruction. The added compile time and complexity does not |
| 1187 | // seem worth it. |
| 1188 | MachineBasicBlock::const_iterator I = MI; |
Jim Grosbach | 57bb394 | 2010-06-25 18:43:14 +0000 | [diff] [blame] | 1189 | // Make sure to skip any dbg_value instructions |
| 1190 | while (++I != MBB->end() && I->isDebugValue()) |
| 1191 | ; |
| 1192 | if (I != MBB->end() && I->getOpcode() == ARM::t2IT) |
Evan Cheng | 86050dc | 2010-06-18 23:09:54 +0000 | [diff] [blame] | 1193 | return true; |
| 1194 | |
| 1195 | // Don't attempt to schedule around any instruction that defines |
| 1196 | // a stack-oriented pointer, as it's unlikely to be profitable. This |
| 1197 | // saves compile time, because it doesn't require every single |
| 1198 | // stack slot reference to depend on the instruction that does the |
| 1199 | // modification. |
| 1200 | if (MI->definesRegister(ARM::SP)) |
| 1201 | return true; |
| 1202 | |
| 1203 | return false; |
| 1204 | } |
| 1205 | |
Owen Anderson | b20b851 | 2010-09-28 18:32:13 +0000 | [diff] [blame] | 1206 | bool ARMBaseInstrInfo::isProfitableToIfCvt(MachineBasicBlock &MBB, |
| 1207 | unsigned NumInstrs, |
Owen Anderson | e3cc84a | 2010-10-01 22:45:50 +0000 | [diff] [blame] | 1208 | float Probability, |
| 1209 | float Confidence) const { |
Evan Cheng | 1315143 | 2010-06-25 22:42:03 +0000 | [diff] [blame] | 1210 | if (!NumInstrs) |
| 1211 | return false; |
Michael J. Spencer | 2bbb769 | 2010-10-05 06:00:33 +0000 | [diff] [blame] | 1212 | |
Owen Anderson | b3c04ec | 2010-09-30 23:48:38 +0000 | [diff] [blame] | 1213 | // Use old-style heuristics |
Owen Anderson | 00d4f48 | 2010-10-01 20:33:47 +0000 | [diff] [blame] | 1214 | if (OldARMIfCvt) { |
Owen Anderson | b3c04ec | 2010-09-30 23:48:38 +0000 | [diff] [blame] | 1215 | if (Subtarget.getCPUString() == "generic") |
| 1216 | // Generic (and overly aggressive) if-conversion limits for testing. |
| 1217 | return NumInstrs <= 10; |
Owen Anderson | 00d4f48 | 2010-10-01 20:33:47 +0000 | [diff] [blame] | 1218 | if (Subtarget.hasV7Ops()) |
Owen Anderson | b3c04ec | 2010-09-30 23:48:38 +0000 | [diff] [blame] | 1219 | return NumInstrs <= 3; |
| 1220 | return NumInstrs <= 2; |
| 1221 | } |
Michael J. Spencer | 2bbb769 | 2010-10-05 06:00:33 +0000 | [diff] [blame] | 1222 | |
Owen Anderson | b20b851 | 2010-09-28 18:32:13 +0000 | [diff] [blame] | 1223 | // Attempt to estimate the relative costs of predication versus branching. |
| 1224 | float UnpredCost = Probability * NumInstrs; |
Owen Anderson | 654d544 | 2010-09-28 21:57:50 +0000 | [diff] [blame] | 1225 | UnpredCost += 1.0; // The branch itself |
Owen Anderson | e3cc84a | 2010-10-01 22:45:50 +0000 | [diff] [blame] | 1226 | UnpredCost += (1.0 - Confidence) * Subtarget.getMispredictionPenalty(); |
Michael J. Spencer | 2bbb769 | 2010-10-05 06:00:33 +0000 | [diff] [blame] | 1227 | |
Owen Anderson | b20b851 | 2010-09-28 18:32:13 +0000 | [diff] [blame] | 1228 | float PredCost = NumInstrs; |
Michael J. Spencer | 2bbb769 | 2010-10-05 06:00:33 +0000 | [diff] [blame] | 1229 | |
Owen Anderson | b20b851 | 2010-09-28 18:32:13 +0000 | [diff] [blame] | 1230 | return PredCost < UnpredCost; |
Michael J. Spencer | 2bbb769 | 2010-10-05 06:00:33 +0000 | [diff] [blame] | 1231 | |
Evan Cheng | 1315143 | 2010-06-25 22:42:03 +0000 | [diff] [blame] | 1232 | } |
Michael J. Spencer | 2bbb769 | 2010-10-05 06:00:33 +0000 | [diff] [blame] | 1233 | |
Evan Cheng | 1315143 | 2010-06-25 22:42:03 +0000 | [diff] [blame] | 1234 | bool ARMBaseInstrInfo:: |
| 1235 | isProfitableToIfCvt(MachineBasicBlock &TMBB, unsigned NumT, |
Owen Anderson | b20b851 | 2010-09-28 18:32:13 +0000 | [diff] [blame] | 1236 | MachineBasicBlock &FMBB, unsigned NumF, |
Owen Anderson | e3cc84a | 2010-10-01 22:45:50 +0000 | [diff] [blame] | 1237 | float Probability, float Confidence) const { |
Owen Anderson | b3c04ec | 2010-09-30 23:48:38 +0000 | [diff] [blame] | 1238 | // Use old-style if-conversion heuristics |
Owen Anderson | 00d4f48 | 2010-10-01 20:33:47 +0000 | [diff] [blame] | 1239 | if (OldARMIfCvt) { |
Owen Anderson | b3c04ec | 2010-09-30 23:48:38 +0000 | [diff] [blame] | 1240 | return NumT && NumF && NumT <= 2 && NumF <= 2; |
| 1241 | } |
| 1242 | |
Owen Anderson | b20b851 | 2010-09-28 18:32:13 +0000 | [diff] [blame] | 1243 | if (!NumT || !NumF) |
| 1244 | return false; |
Michael J. Spencer | 2bbb769 | 2010-10-05 06:00:33 +0000 | [diff] [blame] | 1245 | |
Owen Anderson | b20b851 | 2010-09-28 18:32:13 +0000 | [diff] [blame] | 1246 | // Attempt to estimate the relative costs of predication versus branching. |
| 1247 | float UnpredCost = Probability * NumT + (1.0 - Probability) * NumF; |
Owen Anderson | 654d544 | 2010-09-28 21:57:50 +0000 | [diff] [blame] | 1248 | UnpredCost += 1.0; // The branch itself |
Owen Anderson | e3cc84a | 2010-10-01 22:45:50 +0000 | [diff] [blame] | 1249 | UnpredCost += (1.0 - Confidence) * Subtarget.getMispredictionPenalty(); |
Michael J. Spencer | 2bbb769 | 2010-10-05 06:00:33 +0000 | [diff] [blame] | 1250 | |
Owen Anderson | b20b851 | 2010-09-28 18:32:13 +0000 | [diff] [blame] | 1251 | float PredCost = NumT + NumF; |
Michael J. Spencer | 2bbb769 | 2010-10-05 06:00:33 +0000 | [diff] [blame] | 1252 | |
Owen Anderson | b20b851 | 2010-09-28 18:32:13 +0000 | [diff] [blame] | 1253 | return PredCost < 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); |
| 1422 | if (isSub) |
| 1423 | ImmedOffset |= 1 << NumBits; |
| 1424 | ImmOp.ChangeToImmediate(ImmedOffset); |
Evan Cheng | cdbb3f5 | 2009-08-27 01:23:50 +0000 | [diff] [blame] | 1425 | Offset = 0; |
| 1426 | return true; |
Evan Cheng | 6495f63 | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 1427 | } |
Jim Grosbach | 764ab52 | 2009-08-11 15:33:49 +0000 | [diff] [blame] | 1428 | |
Evan Cheng | 6495f63 | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 1429 | // Otherwise, it didn't fit. Pull in what we can to simplify the immed. |
| 1430 | ImmedOffset = ImmedOffset & Mask; |
| 1431 | if (isSub) |
| 1432 | ImmedOffset |= 1 << NumBits; |
| 1433 | ImmOp.ChangeToImmediate(ImmedOffset); |
| 1434 | Offset &= ~(Mask*Scale); |
| 1435 | } |
| 1436 | } |
| 1437 | |
Evan Cheng | cdbb3f5 | 2009-08-27 01:23:50 +0000 | [diff] [blame] | 1438 | Offset = (isSub) ? -Offset : Offset; |
| 1439 | return Offset == 0; |
Evan Cheng | 6495f63 | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 1440 | } |
Bill Wendling | e4ddbdf | 2010-08-06 01:32:48 +0000 | [diff] [blame] | 1441 | |
| 1442 | bool ARMBaseInstrInfo:: |
Eric Christopher | a99c3e9 | 2010-09-28 04:18:29 +0000 | [diff] [blame] | 1443 | AnalyzeCompare(const MachineInstr *MI, unsigned &SrcReg, int &CmpMask, |
| 1444 | int &CmpValue) const { |
Bill Wendling | e4ddbdf | 2010-08-06 01:32:48 +0000 | [diff] [blame] | 1445 | switch (MI->getOpcode()) { |
| 1446 | default: break; |
Bill Wendling | 38ae997 | 2010-08-11 00:23:00 +0000 | [diff] [blame] | 1447 | case ARM::CMPri: |
| 1448 | case ARM::CMPzri: |
Bill Wendling | e4ddbdf | 2010-08-06 01:32:48 +0000 | [diff] [blame] | 1449 | case ARM::t2CMPri: |
| 1450 | case ARM::t2CMPzri: |
| 1451 | SrcReg = MI->getOperand(0).getReg(); |
Gabor Greif | 04ac81d | 2010-09-21 12:01:15 +0000 | [diff] [blame] | 1452 | CmpMask = ~0; |
Bill Wendling | e4ddbdf | 2010-08-06 01:32:48 +0000 | [diff] [blame] | 1453 | CmpValue = MI->getOperand(1).getImm(); |
| 1454 | return true; |
Gabor Greif | 04ac81d | 2010-09-21 12:01:15 +0000 | [diff] [blame] | 1455 | case ARM::TSTri: |
| 1456 | case ARM::t2TSTri: |
| 1457 | SrcReg = MI->getOperand(0).getReg(); |
| 1458 | CmpMask = MI->getOperand(1).getImm(); |
| 1459 | CmpValue = 0; |
| 1460 | return true; |
| 1461 | } |
| 1462 | |
| 1463 | return false; |
| 1464 | } |
| 1465 | |
Gabor Greif | 05642a3 | 2010-09-29 10:12:08 +0000 | [diff] [blame] | 1466 | /// isSuitableForMask - Identify a suitable 'and' instruction that |
| 1467 | /// operates on the given source register and applies the same mask |
| 1468 | /// as a 'tst' instruction. Provide a limited look-through for copies. |
| 1469 | /// When successful, MI will hold the found instruction. |
| 1470 | static bool isSuitableForMask(MachineInstr *&MI, unsigned SrcReg, |
Gabor Greif | 8ff9bb1 | 2010-09-21 13:30:57 +0000 | [diff] [blame] | 1471 | int CmpMask, bool CommonUse) { |
Gabor Greif | 05642a3 | 2010-09-29 10:12:08 +0000 | [diff] [blame] | 1472 | switch (MI->getOpcode()) { |
Gabor Greif | 04ac81d | 2010-09-21 12:01:15 +0000 | [diff] [blame] | 1473 | case ARM::ANDri: |
| 1474 | case ARM::t2ANDri: |
Gabor Greif | 05642a3 | 2010-09-29 10:12:08 +0000 | [diff] [blame] | 1475 | if (CmpMask != MI->getOperand(2).getImm()) |
Gabor Greif | 8ff9bb1 | 2010-09-21 13:30:57 +0000 | [diff] [blame] | 1476 | return false; |
Gabor Greif | 05642a3 | 2010-09-29 10:12:08 +0000 | [diff] [blame] | 1477 | if (SrcReg == MI->getOperand(CommonUse ? 1 : 0).getReg()) |
Gabor Greif | 04ac81d | 2010-09-21 12:01:15 +0000 | [diff] [blame] | 1478 | return true; |
| 1479 | break; |
Gabor Greif | 05642a3 | 2010-09-29 10:12:08 +0000 | [diff] [blame] | 1480 | case ARM::COPY: { |
| 1481 | // Walk down one instruction which is potentially an 'and'. |
| 1482 | const MachineInstr &Copy = *MI; |
Michael J. Spencer | f000a7a | 2010-10-05 06:00:43 +0000 | [diff] [blame] | 1483 | MachineBasicBlock::iterator AND( |
| 1484 | llvm::next(MachineBasicBlock::iterator(MI))); |
Gabor Greif | 05642a3 | 2010-09-29 10:12:08 +0000 | [diff] [blame] | 1485 | if (AND == MI->getParent()->end()) return false; |
| 1486 | MI = AND; |
| 1487 | return isSuitableForMask(MI, Copy.getOperand(0).getReg(), |
| 1488 | CmpMask, true); |
| 1489 | } |
Bill Wendling | e4ddbdf | 2010-08-06 01:32:48 +0000 | [diff] [blame] | 1490 | } |
| 1491 | |
| 1492 | return false; |
| 1493 | } |
| 1494 | |
Bill Wendling | a655686 | 2010-09-11 00:13:50 +0000 | [diff] [blame] | 1495 | /// OptimizeCompareInstr - Convert the instruction supplying the argument to the |
Bill Wendling | 92ad57f | 2010-09-10 23:34:19 +0000 | [diff] [blame] | 1496 | /// comparison into one that sets the zero bit in the flags register. Update the |
| 1497 | /// iterator *only* if a transformation took place. |
Bill Wendling | e4ddbdf | 2010-08-06 01:32:48 +0000 | [diff] [blame] | 1498 | bool ARMBaseInstrInfo:: |
Gabor Greif | 04ac81d | 2010-09-21 12:01:15 +0000 | [diff] [blame] | 1499 | OptimizeCompareInstr(MachineInstr *CmpInstr, unsigned SrcReg, int CmpMask, |
Bill Wendling | b41ee96 | 2010-10-18 21:22:31 +0000 | [diff] [blame] | 1500 | int CmpValue, const MachineRegisterInfo *MRI, |
| 1501 | MachineBasicBlock::iterator &MII) const { |
Bill Wendling | 3665661 | 2010-09-10 23:46:12 +0000 | [diff] [blame] | 1502 | if (CmpValue != 0) |
Bill Wendling | 92ad57f | 2010-09-10 23:34:19 +0000 | [diff] [blame] | 1503 | return false; |
| 1504 | |
Bill Wendling | b41ee96 | 2010-10-18 21:22:31 +0000 | [diff] [blame] | 1505 | MachineRegisterInfo::def_iterator DI = MRI->def_begin(SrcReg); |
| 1506 | if (llvm::next(DI) != MRI->def_end()) |
Bill Wendling | 92ad57f | 2010-09-10 23:34:19 +0000 | [diff] [blame] | 1507 | // Only support one definition. |
| 1508 | return false; |
| 1509 | |
| 1510 | MachineInstr *MI = &*DI; |
| 1511 | |
Gabor Greif | 04ac81d | 2010-09-21 12:01:15 +0000 | [diff] [blame] | 1512 | // Masked compares sometimes use the same register as the corresponding 'and'. |
| 1513 | if (CmpMask != ~0) { |
Gabor Greif | 05642a3 | 2010-09-29 10:12:08 +0000 | [diff] [blame] | 1514 | if (!isSuitableForMask(MI, SrcReg, CmpMask, false)) { |
Gabor Greif | 04ac81d | 2010-09-21 12:01:15 +0000 | [diff] [blame] | 1515 | MI = 0; |
Bill Wendling | b41ee96 | 2010-10-18 21:22:31 +0000 | [diff] [blame] | 1516 | for (MachineRegisterInfo::use_iterator UI = MRI->use_begin(SrcReg), |
| 1517 | UE = MRI->use_end(); UI != UE; ++UI) { |
Gabor Greif | 04ac81d | 2010-09-21 12:01:15 +0000 | [diff] [blame] | 1518 | if (UI->getParent() != CmpInstr->getParent()) continue; |
Gabor Greif | 05642a3 | 2010-09-29 10:12:08 +0000 | [diff] [blame] | 1519 | MachineInstr *PotentialAND = &*UI; |
Gabor Greif | 8ff9bb1 | 2010-09-21 13:30:57 +0000 | [diff] [blame] | 1520 | if (!isSuitableForMask(PotentialAND, SrcReg, CmpMask, true)) |
Gabor Greif | 04ac81d | 2010-09-21 12:01:15 +0000 | [diff] [blame] | 1521 | continue; |
Gabor Greif | 05642a3 | 2010-09-29 10:12:08 +0000 | [diff] [blame] | 1522 | MI = PotentialAND; |
Gabor Greif | 04ac81d | 2010-09-21 12:01:15 +0000 | [diff] [blame] | 1523 | break; |
| 1524 | } |
| 1525 | if (!MI) return false; |
| 1526 | } |
| 1527 | } |
| 1528 | |
Bill Wendling | e4ddbdf | 2010-08-06 01:32:48 +0000 | [diff] [blame] | 1529 | // Conservatively refuse to convert an instruction which isn't in the same BB |
| 1530 | // as the comparison. |
| 1531 | if (MI->getParent() != CmpInstr->getParent()) |
| 1532 | return false; |
| 1533 | |
| 1534 | // Check that CPSR isn't set between the comparison instruction and the one we |
| 1535 | // want to change. |
Evan Cheng | 691e64a | 2010-09-21 23:49:07 +0000 | [diff] [blame] | 1536 | MachineBasicBlock::const_iterator I = CmpInstr, E = MI, |
| 1537 | B = MI->getParent()->begin(); |
Bill Wendling | 0aa38b9 | 2010-10-09 00:03:48 +0000 | [diff] [blame] | 1538 | |
| 1539 | // Early exit if CmpInstr is at the beginning of the BB. |
| 1540 | if (I == B) return false; |
| 1541 | |
Bill Wendling | e4ddbdf | 2010-08-06 01:32:48 +0000 | [diff] [blame] | 1542 | --I; |
| 1543 | for (; I != E; --I) { |
| 1544 | const MachineInstr &Instr = *I; |
| 1545 | |
| 1546 | for (unsigned IO = 0, EO = Instr.getNumOperands(); IO != EO; ++IO) { |
| 1547 | const MachineOperand &MO = Instr.getOperand(IO); |
Bill Wendling | 75486db | 2010-08-10 21:38:11 +0000 | [diff] [blame] | 1548 | if (!MO.isReg() || !MO.isDef()) continue; |
Bill Wendling | e4ddbdf | 2010-08-06 01:32:48 +0000 | [diff] [blame] | 1549 | |
| 1550 | // This instruction modifies CPSR before the one we want to change. We |
| 1551 | // can't do this transformation. |
| 1552 | if (MO.getReg() == ARM::CPSR) |
| 1553 | return false; |
| 1554 | } |
Evan Cheng | 691e64a | 2010-09-21 23:49:07 +0000 | [diff] [blame] | 1555 | |
| 1556 | if (I == B) |
| 1557 | // The 'and' is below the comparison instruction. |
| 1558 | return false; |
Bill Wendling | e4ddbdf | 2010-08-06 01:32:48 +0000 | [diff] [blame] | 1559 | } |
| 1560 | |
| 1561 | // Set the "zero" bit in CPSR. |
| 1562 | switch (MI->getOpcode()) { |
| 1563 | default: break; |
Bill Wendling | 38ae997 | 2010-08-11 00:23:00 +0000 | [diff] [blame] | 1564 | case ARM::ADDri: |
Bob Wilson | 3a95182 | 2010-09-15 17:12:08 +0000 | [diff] [blame] | 1565 | case ARM::ANDri: |
| 1566 | case ARM::t2ANDri: |
Bill Wendling | 38ae997 | 2010-08-11 00:23:00 +0000 | [diff] [blame] | 1567 | case ARM::SUBri: |
| 1568 | case ARM::t2ADDri: |
Bill Wendling | ad42271 | 2010-08-18 21:32:07 +0000 | [diff] [blame] | 1569 | case ARM::t2SUBri: |
Bill Wendling | e4ddbdf | 2010-08-06 01:32:48 +0000 | [diff] [blame] | 1570 | MI->RemoveOperand(5); |
Bill Wendling | ad42271 | 2010-08-18 21:32:07 +0000 | [diff] [blame] | 1571 | MachineInstrBuilder(MI) |
| 1572 | .addReg(ARM::CPSR, RegState::Define | RegState::Implicit); |
Bill Wendling | 220e240 | 2010-09-10 21:55:43 +0000 | [diff] [blame] | 1573 | MII = llvm::next(MachineBasicBlock::iterator(CmpInstr)); |
Bill Wendling | e4ddbdf | 2010-08-06 01:32:48 +0000 | [diff] [blame] | 1574 | CmpInstr->eraseFromParent(); |
| 1575 | return true; |
| 1576 | } |
Bill Wendling | e4ddbdf | 2010-08-06 01:32:48 +0000 | [diff] [blame] | 1577 | |
| 1578 | return false; |
| 1579 | } |
Evan Cheng | 5f54ce3 | 2010-09-09 18:18:55 +0000 | [diff] [blame] | 1580 | |
| 1581 | unsigned |
| 1582 | ARMBaseInstrInfo::getNumMicroOps(const MachineInstr *MI, |
Evan Cheng | 3ef1c87 | 2010-09-10 01:29:16 +0000 | [diff] [blame] | 1583 | const InstrItineraryData *ItinData) const { |
| 1584 | if (!ItinData || ItinData->isEmpty()) |
Evan Cheng | 5f54ce3 | 2010-09-09 18:18:55 +0000 | [diff] [blame] | 1585 | return 1; |
| 1586 | |
| 1587 | const TargetInstrDesc &Desc = MI->getDesc(); |
| 1588 | unsigned Class = Desc.getSchedClass(); |
Bob Wilson | 064312d | 2010-09-15 16:28:21 +0000 | [diff] [blame] | 1589 | unsigned UOps = ItinData->Itineraries[Class].NumMicroOps; |
Evan Cheng | 5f54ce3 | 2010-09-09 18:18:55 +0000 | [diff] [blame] | 1590 | if (UOps) |
| 1591 | return UOps; |
| 1592 | |
| 1593 | unsigned Opc = MI->getOpcode(); |
| 1594 | switch (Opc) { |
| 1595 | default: |
| 1596 | llvm_unreachable("Unexpected multi-uops instruction!"); |
| 1597 | break; |
Evan Cheng | 3ef1c87 | 2010-09-10 01:29:16 +0000 | [diff] [blame] | 1598 | case ARM::VLDMQ: |
Evan Cheng | 5f54ce3 | 2010-09-09 18:18:55 +0000 | [diff] [blame] | 1599 | case ARM::VSTMQ: |
| 1600 | return 2; |
| 1601 | |
| 1602 | // The number of uOps for load / store multiple are determined by the number |
| 1603 | // registers. |
Evan Cheng | 3ef1c87 | 2010-09-10 01:29:16 +0000 | [diff] [blame] | 1604 | // On Cortex-A8, each pair of register loads / stores can be scheduled on the |
| 1605 | // same cycle. The scheduling for the first load / store must be done |
| 1606 | // separately by assuming the the address is not 64-bit aligned. |
| 1607 | // On Cortex-A9, the formula is simply (#reg / 2) + (#reg % 2). If the address |
| 1608 | // is not 64-bit aligned, then AGU would take an extra cycle. |
| 1609 | // For VFP / NEON load / store multiple, the formula is |
Evan Cheng | 5f54ce3 | 2010-09-09 18:18:55 +0000 | [diff] [blame] | 1610 | // (#reg / 2) + (#reg % 2) + 1. |
Evan Cheng | 5f54ce3 | 2010-09-09 18:18:55 +0000 | [diff] [blame] | 1611 | case ARM::VLDMD: |
| 1612 | case ARM::VLDMS: |
| 1613 | case ARM::VLDMD_UPD: |
| 1614 | case ARM::VLDMS_UPD: |
| 1615 | case ARM::VSTMD: |
| 1616 | case ARM::VSTMS: |
| 1617 | case ARM::VSTMD_UPD: |
| 1618 | case ARM::VSTMS_UPD: { |
| 1619 | unsigned NumRegs = MI->getNumOperands() - Desc.getNumOperands(); |
| 1620 | return (NumRegs / 2) + (NumRegs % 2) + 1; |
| 1621 | } |
| 1622 | case ARM::LDM_RET: |
| 1623 | case ARM::LDM: |
| 1624 | case ARM::LDM_UPD: |
| 1625 | case ARM::STM: |
| 1626 | case ARM::STM_UPD: |
| 1627 | case ARM::tLDM: |
| 1628 | case ARM::tLDM_UPD: |
| 1629 | case ARM::tSTM_UPD: |
| 1630 | case ARM::tPOP_RET: |
| 1631 | case ARM::tPOP: |
| 1632 | case ARM::tPUSH: |
| 1633 | case ARM::t2LDM_RET: |
| 1634 | case ARM::t2LDM: |
| 1635 | case ARM::t2LDM_UPD: |
| 1636 | case ARM::t2STM: |
| 1637 | case ARM::t2STM_UPD: { |
Evan Cheng | 3ef1c87 | 2010-09-10 01:29:16 +0000 | [diff] [blame] | 1638 | unsigned NumRegs = MI->getNumOperands() - Desc.getNumOperands() + 1; |
| 1639 | if (Subtarget.isCortexA8()) { |
| 1640 | // 4 registers would be issued: 1, 2, 1. |
| 1641 | // 5 registers would be issued: 1, 2, 2. |
| 1642 | return 1 + (NumRegs / 2); |
| 1643 | } else if (Subtarget.isCortexA9()) { |
| 1644 | UOps = (NumRegs / 2); |
| 1645 | // If there are odd number of registers or if it's not 64-bit aligned, |
| 1646 | // then it takes an extra AGU (Address Generation Unit) cycle. |
| 1647 | if ((NumRegs % 2) || |
| 1648 | !MI->hasOneMemOperand() || |
| 1649 | (*MI->memoperands_begin())->getAlignment() < 8) |
| 1650 | ++UOps; |
| 1651 | return UOps; |
| 1652 | } else { |
| 1653 | // Assume the worst. |
| 1654 | return NumRegs; |
Michael J. Spencer | 2bbb769 | 2010-10-05 06:00:33 +0000 | [diff] [blame] | 1655 | } |
Evan Cheng | 5f54ce3 | 2010-09-09 18:18:55 +0000 | [diff] [blame] | 1656 | } |
| 1657 | } |
| 1658 | } |
Evan Cheng | a0792de | 2010-10-06 06:27:31 +0000 | [diff] [blame] | 1659 | |
| 1660 | int |
Evan Cheng | 344d9db | 2010-10-07 23:12:15 +0000 | [diff] [blame] | 1661 | ARMBaseInstrInfo::getVLDMDefCycle(const InstrItineraryData *ItinData, |
| 1662 | const TargetInstrDesc &DefTID, |
| 1663 | unsigned DefClass, |
| 1664 | unsigned DefIdx, unsigned DefAlign) const { |
| 1665 | int RegNo = (int)(DefIdx+1) - DefTID.getNumOperands() + 1; |
| 1666 | if (RegNo <= 0) |
| 1667 | // Def is the address writeback. |
| 1668 | return ItinData->getOperandCycle(DefClass, DefIdx); |
| 1669 | |
| 1670 | int DefCycle; |
| 1671 | if (Subtarget.isCortexA8()) { |
| 1672 | // (regno / 2) + (regno % 2) + 1 |
| 1673 | DefCycle = RegNo / 2 + 1; |
| 1674 | if (RegNo % 2) |
| 1675 | ++DefCycle; |
| 1676 | } else if (Subtarget.isCortexA9()) { |
| 1677 | DefCycle = RegNo; |
| 1678 | bool isSLoad = false; |
| 1679 | switch (DefTID.getOpcode()) { |
| 1680 | default: break; |
| 1681 | case ARM::VLDMS: |
| 1682 | case ARM::VLDMS_UPD: |
| 1683 | isSLoad = true; |
| 1684 | break; |
| 1685 | } |
| 1686 | // If there are odd number of 'S' registers or if it's not 64-bit aligned, |
| 1687 | // then it takes an extra cycle. |
| 1688 | if ((isSLoad && (RegNo % 2)) || DefAlign < 8) |
| 1689 | ++DefCycle; |
| 1690 | } else { |
| 1691 | // Assume the worst. |
| 1692 | DefCycle = RegNo + 2; |
| 1693 | } |
| 1694 | |
| 1695 | return DefCycle; |
| 1696 | } |
| 1697 | |
| 1698 | int |
| 1699 | ARMBaseInstrInfo::getLDMDefCycle(const InstrItineraryData *ItinData, |
| 1700 | const TargetInstrDesc &DefTID, |
| 1701 | unsigned DefClass, |
| 1702 | unsigned DefIdx, unsigned DefAlign) const { |
| 1703 | int RegNo = (int)(DefIdx+1) - DefTID.getNumOperands() + 1; |
| 1704 | if (RegNo <= 0) |
| 1705 | // Def is the address writeback. |
| 1706 | return ItinData->getOperandCycle(DefClass, DefIdx); |
| 1707 | |
| 1708 | int DefCycle; |
| 1709 | if (Subtarget.isCortexA8()) { |
| 1710 | // 4 registers would be issued: 1, 2, 1. |
| 1711 | // 5 registers would be issued: 1, 2, 2. |
| 1712 | DefCycle = RegNo / 2; |
| 1713 | if (DefCycle < 1) |
| 1714 | DefCycle = 1; |
| 1715 | // Result latency is issue cycle + 2: E2. |
| 1716 | DefCycle += 2; |
| 1717 | } else if (Subtarget.isCortexA9()) { |
| 1718 | DefCycle = (RegNo / 2); |
| 1719 | // If there are odd number of registers or if it's not 64-bit aligned, |
| 1720 | // then it takes an extra AGU (Address Generation Unit) cycle. |
| 1721 | if ((RegNo % 2) || DefAlign < 8) |
| 1722 | ++DefCycle; |
| 1723 | // Result latency is AGU cycles + 2. |
| 1724 | DefCycle += 2; |
| 1725 | } else { |
| 1726 | // Assume the worst. |
| 1727 | DefCycle = RegNo + 2; |
| 1728 | } |
| 1729 | |
| 1730 | return DefCycle; |
| 1731 | } |
| 1732 | |
| 1733 | int |
| 1734 | ARMBaseInstrInfo::getVSTMUseCycle(const InstrItineraryData *ItinData, |
| 1735 | const TargetInstrDesc &UseTID, |
| 1736 | unsigned UseClass, |
| 1737 | unsigned UseIdx, unsigned UseAlign) const { |
| 1738 | int RegNo = (int)(UseIdx+1) - UseTID.getNumOperands() + 1; |
| 1739 | if (RegNo <= 0) |
| 1740 | return ItinData->getOperandCycle(UseClass, UseIdx); |
| 1741 | |
| 1742 | int UseCycle; |
| 1743 | if (Subtarget.isCortexA8()) { |
| 1744 | // (regno / 2) + (regno % 2) + 1 |
| 1745 | UseCycle = RegNo / 2 + 1; |
| 1746 | if (RegNo % 2) |
| 1747 | ++UseCycle; |
| 1748 | } else if (Subtarget.isCortexA9()) { |
| 1749 | UseCycle = RegNo; |
| 1750 | bool isSStore = false; |
| 1751 | switch (UseTID.getOpcode()) { |
| 1752 | default: break; |
| 1753 | case ARM::VSTMS: |
| 1754 | case ARM::VSTMS_UPD: |
| 1755 | isSStore = true; |
| 1756 | break; |
| 1757 | } |
| 1758 | // If there are odd number of 'S' registers or if it's not 64-bit aligned, |
| 1759 | // then it takes an extra cycle. |
| 1760 | if ((isSStore && (RegNo % 2)) || UseAlign < 8) |
| 1761 | ++UseCycle; |
| 1762 | } else { |
| 1763 | // Assume the worst. |
| 1764 | UseCycle = RegNo + 2; |
| 1765 | } |
| 1766 | |
| 1767 | return UseCycle; |
| 1768 | } |
| 1769 | |
| 1770 | int |
| 1771 | ARMBaseInstrInfo::getSTMUseCycle(const InstrItineraryData *ItinData, |
| 1772 | const TargetInstrDesc &UseTID, |
| 1773 | unsigned UseClass, |
| 1774 | unsigned UseIdx, unsigned UseAlign) const { |
| 1775 | int RegNo = (int)(UseIdx+1) - UseTID.getNumOperands() + 1; |
| 1776 | if (RegNo <= 0) |
| 1777 | return ItinData->getOperandCycle(UseClass, UseIdx); |
| 1778 | |
| 1779 | int UseCycle; |
| 1780 | if (Subtarget.isCortexA8()) { |
| 1781 | UseCycle = RegNo / 2; |
| 1782 | if (UseCycle < 2) |
| 1783 | UseCycle = 2; |
| 1784 | // Read in E3. |
| 1785 | UseCycle += 2; |
| 1786 | } else if (Subtarget.isCortexA9()) { |
| 1787 | UseCycle = (RegNo / 2); |
| 1788 | // If there are odd number of registers or if it's not 64-bit aligned, |
| 1789 | // then it takes an extra AGU (Address Generation Unit) cycle. |
| 1790 | if ((RegNo % 2) || UseAlign < 8) |
| 1791 | ++UseCycle; |
| 1792 | } else { |
| 1793 | // Assume the worst. |
| 1794 | UseCycle = 1; |
| 1795 | } |
| 1796 | return UseCycle; |
| 1797 | } |
| 1798 | |
| 1799 | int |
Evan Cheng | a0792de | 2010-10-06 06:27:31 +0000 | [diff] [blame] | 1800 | ARMBaseInstrInfo::getOperandLatency(const InstrItineraryData *ItinData, |
| 1801 | const TargetInstrDesc &DefTID, |
| 1802 | unsigned DefIdx, unsigned DefAlign, |
| 1803 | const TargetInstrDesc &UseTID, |
| 1804 | unsigned UseIdx, unsigned UseAlign) const { |
| 1805 | unsigned DefClass = DefTID.getSchedClass(); |
| 1806 | unsigned UseClass = UseTID.getSchedClass(); |
| 1807 | |
| 1808 | if (DefIdx < DefTID.getNumDefs() && UseIdx < UseTID.getNumOperands()) |
| 1809 | return ItinData->getOperandLatency(DefClass, DefIdx, UseClass, UseIdx); |
| 1810 | |
| 1811 | // This may be a def / use of a variable_ops instruction, the operand |
| 1812 | // latency might be determinable dynamically. Let the target try to |
| 1813 | // figure it out. |
| 1814 | bool LdmBypass = false; |
| 1815 | int DefCycle = -1; |
| 1816 | switch (DefTID.getOpcode()) { |
| 1817 | default: |
| 1818 | DefCycle = ItinData->getOperandCycle(DefClass, DefIdx); |
| 1819 | break; |
Evan Cheng | 5a50cee | 2010-10-07 01:50:48 +0000 | [diff] [blame] | 1820 | case ARM::VLDMD: |
| 1821 | case ARM::VLDMS: |
| 1822 | case ARM::VLDMD_UPD: |
| 1823 | case ARM::VLDMS_UPD: { |
Evan Cheng | 344d9db | 2010-10-07 23:12:15 +0000 | [diff] [blame] | 1824 | DefCycle = getVLDMDefCycle(ItinData, DefTID, DefClass, DefIdx, DefAlign); |
Evan Cheng | 5a50cee | 2010-10-07 01:50:48 +0000 | [diff] [blame] | 1825 | break; |
| 1826 | } |
Evan Cheng | a0792de | 2010-10-06 06:27:31 +0000 | [diff] [blame] | 1827 | case ARM::LDM_RET: |
| 1828 | case ARM::LDM: |
| 1829 | case ARM::LDM_UPD: |
| 1830 | case ARM::tLDM: |
| 1831 | case ARM::tLDM_UPD: |
| 1832 | case ARM::tPUSH: |
| 1833 | case ARM::t2LDM_RET: |
| 1834 | case ARM::t2LDM: |
| 1835 | case ARM::t2LDM_UPD: { |
| 1836 | LdmBypass = 1; |
Evan Cheng | 344d9db | 2010-10-07 23:12:15 +0000 | [diff] [blame] | 1837 | DefCycle = getLDMDefCycle(ItinData, DefTID, DefClass, DefIdx, DefAlign); |
| 1838 | break; |
Evan Cheng | a0792de | 2010-10-06 06:27:31 +0000 | [diff] [blame] | 1839 | } |
| 1840 | } |
| 1841 | |
| 1842 | if (DefCycle == -1) |
| 1843 | // We can't seem to determine the result latency of the def, assume it's 2. |
| 1844 | DefCycle = 2; |
| 1845 | |
| 1846 | int UseCycle = -1; |
| 1847 | switch (UseTID.getOpcode()) { |
| 1848 | default: |
| 1849 | UseCycle = ItinData->getOperandCycle(UseClass, UseIdx); |
| 1850 | break; |
Evan Cheng | 5a50cee | 2010-10-07 01:50:48 +0000 | [diff] [blame] | 1851 | case ARM::VSTMD: |
| 1852 | case ARM::VSTMS: |
| 1853 | case ARM::VSTMD_UPD: |
| 1854 | case ARM::VSTMS_UPD: { |
Evan Cheng | 344d9db | 2010-10-07 23:12:15 +0000 | [diff] [blame] | 1855 | UseCycle = getVSTMUseCycle(ItinData, UseTID, UseClass, UseIdx, UseAlign); |
Evan Cheng | 5a50cee | 2010-10-07 01:50:48 +0000 | [diff] [blame] | 1856 | break; |
| 1857 | } |
Evan Cheng | a0792de | 2010-10-06 06:27:31 +0000 | [diff] [blame] | 1858 | case ARM::STM: |
| 1859 | case ARM::STM_UPD: |
| 1860 | case ARM::tSTM_UPD: |
| 1861 | case ARM::tPOP_RET: |
| 1862 | case ARM::tPOP: |
| 1863 | case ARM::t2STM: |
| 1864 | case ARM::t2STM_UPD: { |
Evan Cheng | 344d9db | 2010-10-07 23:12:15 +0000 | [diff] [blame] | 1865 | UseCycle = getSTMUseCycle(ItinData, UseTID, UseClass, UseIdx, UseAlign); |
Evan Cheng | 5a50cee | 2010-10-07 01:50:48 +0000 | [diff] [blame] | 1866 | break; |
Evan Cheng | a0792de | 2010-10-06 06:27:31 +0000 | [diff] [blame] | 1867 | } |
| 1868 | } |
| 1869 | |
| 1870 | if (UseCycle == -1) |
| 1871 | // Assume it's read in the first stage. |
| 1872 | UseCycle = 1; |
| 1873 | |
| 1874 | UseCycle = DefCycle - UseCycle + 1; |
| 1875 | if (UseCycle > 0) { |
| 1876 | if (LdmBypass) { |
| 1877 | // It's a variable_ops instruction so we can't use DefIdx here. Just use |
| 1878 | // first def operand. |
| 1879 | if (ItinData->hasPipelineForwarding(DefClass, DefTID.getNumOperands()-1, |
| 1880 | UseClass, UseIdx)) |
| 1881 | --UseCycle; |
| 1882 | } else if (ItinData->hasPipelineForwarding(DefClass, DefIdx, |
| 1883 | UseClass, UseIdx)) |
| 1884 | --UseCycle; |
| 1885 | } |
| 1886 | |
| 1887 | return UseCycle; |
| 1888 | } |
| 1889 | |
| 1890 | int |
| 1891 | ARMBaseInstrInfo::getOperandLatency(const InstrItineraryData *ItinData, |
| 1892 | const MachineInstr *DefMI, unsigned DefIdx, |
| 1893 | const MachineInstr *UseMI, unsigned UseIdx) const { |
| 1894 | if (DefMI->isCopyLike() || DefMI->isInsertSubreg() || |
| 1895 | DefMI->isRegSequence() || DefMI->isImplicitDef()) |
| 1896 | return 1; |
| 1897 | |
| 1898 | const TargetInstrDesc &DefTID = DefMI->getDesc(); |
| 1899 | if (!ItinData || ItinData->isEmpty()) |
| 1900 | return DefTID.mayLoad() ? 3 : 1; |
| 1901 | |
Evan Cheng | dd9dd6f | 2010-10-23 02:04:38 +0000 | [diff] [blame] | 1902 | |
Evan Cheng | a0792de | 2010-10-06 06:27:31 +0000 | [diff] [blame] | 1903 | const TargetInstrDesc &UseTID = UseMI->getDesc(); |
Evan Cheng | dd9dd6f | 2010-10-23 02:04:38 +0000 | [diff] [blame] | 1904 | const MachineOperand &DefMO = DefMI->getOperand(DefIdx); |
| 1905 | if (DefMO.getReg() == ARM::CPSR && UseTID.isBranch()) |
| 1906 | // CPSR set and branch can be paired in the same cycle. |
| 1907 | return 0; |
| 1908 | |
Evan Cheng | a0792de | 2010-10-06 06:27:31 +0000 | [diff] [blame] | 1909 | unsigned DefAlign = DefMI->hasOneMemOperand() |
| 1910 | ? (*DefMI->memoperands_begin())->getAlignment() : 0; |
| 1911 | unsigned UseAlign = UseMI->hasOneMemOperand() |
| 1912 | ? (*UseMI->memoperands_begin())->getAlignment() : 0; |
| 1913 | return getOperandLatency(ItinData, DefTID, DefIdx, DefAlign, |
| 1914 | UseTID, UseIdx, UseAlign); |
| 1915 | } |
| 1916 | |
| 1917 | int |
| 1918 | ARMBaseInstrInfo::getOperandLatency(const InstrItineraryData *ItinData, |
| 1919 | SDNode *DefNode, unsigned DefIdx, |
| 1920 | SDNode *UseNode, unsigned UseIdx) const { |
| 1921 | if (!DefNode->isMachineOpcode()) |
| 1922 | return 1; |
| 1923 | |
| 1924 | const TargetInstrDesc &DefTID = get(DefNode->getMachineOpcode()); |
| 1925 | if (!ItinData || ItinData->isEmpty()) |
| 1926 | return DefTID.mayLoad() ? 3 : 1; |
| 1927 | |
| 1928 | if (!UseNode->isMachineOpcode()) |
| 1929 | return ItinData->getOperandCycle(DefTID.getSchedClass(), DefIdx); |
| 1930 | |
| 1931 | const TargetInstrDesc &UseTID = get(UseNode->getMachineOpcode()); |
| 1932 | const MachineSDNode *DefMN = dyn_cast<MachineSDNode>(DefNode); |
| 1933 | unsigned DefAlign = !DefMN->memoperands_empty() |
| 1934 | ? (*DefMN->memoperands_begin())->getAlignment() : 0; |
| 1935 | const MachineSDNode *UseMN = dyn_cast<MachineSDNode>(UseNode); |
| 1936 | unsigned UseAlign = !UseMN->memoperands_empty() |
| 1937 | ? (*UseMN->memoperands_begin())->getAlignment() : 0; |
| 1938 | return getOperandLatency(ItinData, DefTID, DefIdx, DefAlign, |
| 1939 | UseTID, UseIdx, UseAlign); |
| 1940 | } |
Evan Cheng | 2312842 | 2010-10-19 18:58:51 +0000 | [diff] [blame] | 1941 | |
| 1942 | bool ARMBaseInstrInfo:: |
| 1943 | hasHighOperandLatency(const InstrItineraryData *ItinData, |
| 1944 | const MachineRegisterInfo *MRI, |
| 1945 | const MachineInstr *DefMI, unsigned DefIdx, |
| 1946 | const MachineInstr *UseMI, unsigned UseIdx) const { |
| 1947 | unsigned DDomain = DefMI->getDesc().TSFlags & ARMII::DomainMask; |
| 1948 | unsigned UDomain = UseMI->getDesc().TSFlags & ARMII::DomainMask; |
| 1949 | if (Subtarget.isCortexA8() && |
| 1950 | (DDomain == ARMII::DomainVFP || UDomain == ARMII::DomainVFP)) |
| 1951 | // CortexA8 VFP instructions are not pipelined. |
| 1952 | return true; |
| 1953 | |
| 1954 | // Hoist VFP / NEON instructions with 4 or higher latency. |
| 1955 | int Latency = getOperandLatency(ItinData, DefMI, DefIdx, UseMI, UseIdx); |
| 1956 | if (Latency <= 3) |
| 1957 | return false; |
| 1958 | return DDomain == ARMII::DomainVFP || DDomain == ARMII::DomainNEON || |
| 1959 | UDomain == ARMII::DomainVFP || UDomain == ARMII::DomainNEON; |
| 1960 | } |
Evan Cheng | c8141df | 2010-10-26 02:08:50 +0000 | [diff] [blame] | 1961 | |
| 1962 | bool ARMBaseInstrInfo:: |
| 1963 | hasLowDefLatency(const InstrItineraryData *ItinData, |
| 1964 | const MachineInstr *DefMI, unsigned DefIdx) const { |
| 1965 | if (!ItinData || ItinData->isEmpty()) |
| 1966 | return false; |
| 1967 | |
| 1968 | unsigned DDomain = DefMI->getDesc().TSFlags & ARMII::DomainMask; |
| 1969 | if (DDomain == ARMII::DomainGeneral) { |
| 1970 | unsigned DefClass = DefMI->getDesc().getSchedClass(); |
| 1971 | int DefCycle = ItinData->getOperandCycle(DefClass, DefIdx); |
| 1972 | return (DefCycle != -1 && DefCycle <= 2); |
| 1973 | } |
| 1974 | return false; |
| 1975 | } |