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