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