Jim Grosbach | 31c24bf | 2009-11-07 22:00:39 +0000 | [diff] [blame] | 1 | //===- ARMBaseInstrInfo.cpp - ARM Instruction Information -------*- C++ -*-===// |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file contains the Base ARM implementation of the TargetInstrInfo class. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "ARMBaseInstrInfo.h" |
| 15 | #include "ARM.h" |
| 16 | #include "ARMAddressingModes.h" |
Evan Cheng | d457e6e | 2009-11-07 04:04:34 +0000 | [diff] [blame] | 17 | #include "ARMConstantPoolValue.h" |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 18 | #include "ARMGenInstrInfo.inc" |
| 19 | #include "ARMMachineFunctionInfo.h" |
Anton Korobeynikov | f95215f | 2009-11-02 00:10:38 +0000 | [diff] [blame] | 20 | #include "ARMRegisterInfo.h" |
Evan Cheng | fdc8340 | 2009-11-08 00:15:23 +0000 | [diff] [blame] | 21 | #include "llvm/Constants.h" |
| 22 | #include "llvm/Function.h" |
| 23 | #include "llvm/GlobalValue.h" |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 24 | #include "llvm/ADT/STLExtras.h" |
| 25 | #include "llvm/CodeGen/LiveVariables.h" |
Evan Cheng | d457e6e | 2009-11-07 04:04:34 +0000 | [diff] [blame] | 26 | #include "llvm/CodeGen/MachineConstantPool.h" |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 27 | #include "llvm/CodeGen/MachineFrameInfo.h" |
| 28 | #include "llvm/CodeGen/MachineInstrBuilder.h" |
| 29 | #include "llvm/CodeGen/MachineJumpTableInfo.h" |
Anton Korobeynikov | 249fb33 | 2009-10-07 00:06:35 +0000 | [diff] [blame] | 30 | #include "llvm/CodeGen/MachineMemOperand.h" |
Evan Cheng | 2457f2c | 2010-05-22 01:47:14 +0000 | [diff] [blame] | 31 | #include "llvm/CodeGen/MachineRegisterInfo.h" |
Anton Korobeynikov | 249fb33 | 2009-10-07 00:06:35 +0000 | [diff] [blame] | 32 | #include "llvm/CodeGen/PseudoSourceValue.h" |
Chris Lattner | af76e59 | 2009-08-22 20:48:53 +0000 | [diff] [blame] | 33 | #include "llvm/MC/MCAsmInfo.h" |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 34 | #include "llvm/Support/CommandLine.h" |
Anton Korobeynikov | f95215f | 2009-11-02 00:10:38 +0000 | [diff] [blame] | 35 | #include "llvm/Support/Debug.h" |
Torok Edwin | c25e758 | 2009-07-11 20:10:48 +0000 | [diff] [blame] | 36 | #include "llvm/Support/ErrorHandling.h" |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 37 | using namespace llvm; |
| 38 | |
| 39 | static cl::opt<bool> |
| 40 | EnableARM3Addr("enable-arm-3-addr-conv", cl::Hidden, |
| 41 | cl::desc("Enable ARM 2-addr to 3-addr conv")); |
| 42 | |
Anton Korobeynikov | f95215f | 2009-11-02 00:10:38 +0000 | [diff] [blame] | 43 | ARMBaseInstrInfo::ARMBaseInstrInfo(const ARMSubtarget& STI) |
| 44 | : TargetInstrInfoImpl(ARMInsts, array_lengthof(ARMInsts)), |
| 45 | Subtarget(STI) { |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | MachineInstr * |
| 49 | ARMBaseInstrInfo::convertToThreeAddress(MachineFunction::iterator &MFI, |
| 50 | MachineBasicBlock::iterator &MBBI, |
| 51 | LiveVariables *LV) const { |
Evan Cheng | 78703dd | 2009-07-27 18:44:00 +0000 | [diff] [blame] | 52 | // FIXME: Thumb2 support. |
| 53 | |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 54 | if (!EnableARM3Addr) |
| 55 | return NULL; |
| 56 | |
| 57 | MachineInstr *MI = MBBI; |
| 58 | MachineFunction &MF = *MI->getParent()->getParent(); |
Bruno Cardoso Lopes | 99405df | 2010-06-08 22:51:23 +0000 | [diff] [blame] | 59 | uint64_t TSFlags = MI->getDesc().TSFlags; |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 60 | bool isPre = false; |
| 61 | switch ((TSFlags & ARMII::IndexModeMask) >> ARMII::IndexModeShift) { |
| 62 | default: return NULL; |
| 63 | case ARMII::IndexModePre: |
| 64 | isPre = true; |
| 65 | break; |
| 66 | case ARMII::IndexModePost: |
| 67 | break; |
| 68 | } |
| 69 | |
| 70 | // Try splitting an indexed load/store to an un-indexed one plus an add/sub |
| 71 | // operation. |
| 72 | unsigned MemOpc = getUnindexedOpcode(MI->getOpcode()); |
| 73 | if (MemOpc == 0) |
| 74 | return NULL; |
| 75 | |
| 76 | MachineInstr *UpdateMI = NULL; |
| 77 | MachineInstr *MemMI = NULL; |
| 78 | unsigned AddrMode = (TSFlags & ARMII::AddrModeMask); |
| 79 | const TargetInstrDesc &TID = MI->getDesc(); |
| 80 | unsigned NumOps = TID.getNumOperands(); |
| 81 | bool isLoad = !TID.mayStore(); |
| 82 | const MachineOperand &WB = isLoad ? MI->getOperand(1) : MI->getOperand(0); |
| 83 | const MachineOperand &Base = MI->getOperand(2); |
| 84 | const MachineOperand &Offset = MI->getOperand(NumOps-3); |
| 85 | unsigned WBReg = WB.getReg(); |
| 86 | unsigned BaseReg = Base.getReg(); |
| 87 | unsigned OffReg = Offset.getReg(); |
| 88 | unsigned OffImm = MI->getOperand(NumOps-2).getImm(); |
| 89 | ARMCC::CondCodes Pred = (ARMCC::CondCodes)MI->getOperand(NumOps-1).getImm(); |
| 90 | switch (AddrMode) { |
| 91 | default: |
| 92 | assert(false && "Unknown indexed op!"); |
| 93 | return NULL; |
| 94 | case ARMII::AddrMode2: { |
| 95 | bool isSub = ARM_AM::getAM2Op(OffImm) == ARM_AM::sub; |
| 96 | unsigned Amt = ARM_AM::getAM2Offset(OffImm); |
| 97 | if (OffReg == 0) { |
Evan Cheng | e7cbe41 | 2009-07-08 21:03:57 +0000 | [diff] [blame] | 98 | if (ARM_AM::getSOImmVal(Amt) == -1) |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 99 | // Can't encode it in a so_imm operand. This transformation will |
| 100 | // add more than 1 instruction. Abandon! |
| 101 | return NULL; |
| 102 | UpdateMI = BuildMI(MF, MI->getDebugLoc(), |
Evan Cheng | 78703dd | 2009-07-27 18:44:00 +0000 | [diff] [blame] | 103 | get(isSub ? ARM::SUBri : ARM::ADDri), WBReg) |
Evan Cheng | e7cbe41 | 2009-07-08 21:03:57 +0000 | [diff] [blame] | 104 | .addReg(BaseReg).addImm(Amt) |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 105 | .addImm(Pred).addReg(0).addReg(0); |
| 106 | } else if (Amt != 0) { |
| 107 | ARM_AM::ShiftOpc ShOpc = ARM_AM::getAM2ShiftOpc(OffImm); |
| 108 | unsigned SOOpc = ARM_AM::getSORegOpc(ShOpc, Amt); |
| 109 | UpdateMI = BuildMI(MF, MI->getDebugLoc(), |
Evan Cheng | 78703dd | 2009-07-27 18:44:00 +0000 | [diff] [blame] | 110 | get(isSub ? ARM::SUBrs : ARM::ADDrs), WBReg) |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 111 | .addReg(BaseReg).addReg(OffReg).addReg(0).addImm(SOOpc) |
| 112 | .addImm(Pred).addReg(0).addReg(0); |
| 113 | } else |
| 114 | UpdateMI = BuildMI(MF, MI->getDebugLoc(), |
Evan Cheng | 78703dd | 2009-07-27 18:44:00 +0000 | [diff] [blame] | 115 | get(isSub ? ARM::SUBrr : ARM::ADDrr), WBReg) |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 116 | .addReg(BaseReg).addReg(OffReg) |
| 117 | .addImm(Pred).addReg(0).addReg(0); |
| 118 | break; |
| 119 | } |
| 120 | case ARMII::AddrMode3 : { |
| 121 | bool isSub = ARM_AM::getAM3Op(OffImm) == ARM_AM::sub; |
| 122 | unsigned Amt = ARM_AM::getAM3Offset(OffImm); |
| 123 | if (OffReg == 0) |
| 124 | // Immediate is 8-bits. It's guaranteed to fit in a so_imm operand. |
| 125 | UpdateMI = BuildMI(MF, MI->getDebugLoc(), |
Evan Cheng | 78703dd | 2009-07-27 18:44:00 +0000 | [diff] [blame] | 126 | get(isSub ? ARM::SUBri : ARM::ADDri), WBReg) |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 127 | .addReg(BaseReg).addImm(Amt) |
| 128 | .addImm(Pred).addReg(0).addReg(0); |
| 129 | else |
| 130 | UpdateMI = BuildMI(MF, MI->getDebugLoc(), |
Evan Cheng | 78703dd | 2009-07-27 18:44:00 +0000 | [diff] [blame] | 131 | get(isSub ? ARM::SUBrr : ARM::ADDrr), WBReg) |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 132 | .addReg(BaseReg).addReg(OffReg) |
| 133 | .addImm(Pred).addReg(0).addReg(0); |
| 134 | break; |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | std::vector<MachineInstr*> NewMIs; |
| 139 | if (isPre) { |
| 140 | if (isLoad) |
| 141 | MemMI = BuildMI(MF, MI->getDebugLoc(), |
| 142 | get(MemOpc), MI->getOperand(0).getReg()) |
| 143 | .addReg(WBReg).addReg(0).addImm(0).addImm(Pred); |
| 144 | else |
| 145 | MemMI = BuildMI(MF, MI->getDebugLoc(), |
| 146 | get(MemOpc)).addReg(MI->getOperand(1).getReg()) |
| 147 | .addReg(WBReg).addReg(0).addImm(0).addImm(Pred); |
| 148 | NewMIs.push_back(MemMI); |
| 149 | NewMIs.push_back(UpdateMI); |
| 150 | } else { |
| 151 | if (isLoad) |
| 152 | MemMI = BuildMI(MF, MI->getDebugLoc(), |
| 153 | get(MemOpc), MI->getOperand(0).getReg()) |
| 154 | .addReg(BaseReg).addReg(0).addImm(0).addImm(Pred); |
| 155 | else |
| 156 | MemMI = BuildMI(MF, MI->getDebugLoc(), |
| 157 | get(MemOpc)).addReg(MI->getOperand(1).getReg()) |
| 158 | .addReg(BaseReg).addReg(0).addImm(0).addImm(Pred); |
| 159 | if (WB.isDead()) |
| 160 | UpdateMI->getOperand(0).setIsDead(); |
| 161 | NewMIs.push_back(UpdateMI); |
| 162 | NewMIs.push_back(MemMI); |
| 163 | } |
| 164 | |
| 165 | // Transfer LiveVariables states, kill / dead info. |
| 166 | if (LV) { |
| 167 | for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) { |
| 168 | MachineOperand &MO = MI->getOperand(i); |
| 169 | if (MO.isReg() && MO.getReg() && |
| 170 | TargetRegisterInfo::isVirtualRegister(MO.getReg())) { |
| 171 | unsigned Reg = MO.getReg(); |
| 172 | |
| 173 | LiveVariables::VarInfo &VI = LV->getVarInfo(Reg); |
| 174 | if (MO.isDef()) { |
| 175 | MachineInstr *NewMI = (Reg == WBReg) ? UpdateMI : MemMI; |
| 176 | if (MO.isDead()) |
| 177 | LV->addVirtualRegisterDead(Reg, NewMI); |
| 178 | } |
| 179 | if (MO.isUse() && MO.isKill()) { |
| 180 | for (unsigned j = 0; j < 2; ++j) { |
| 181 | // Look at the two new MI's in reverse order. |
| 182 | MachineInstr *NewMI = NewMIs[j]; |
| 183 | if (!NewMI->readsRegister(Reg)) |
| 184 | continue; |
| 185 | LV->addVirtualRegisterKilled(Reg, NewMI); |
| 186 | if (VI.removeKill(MI)) |
| 187 | VI.Kills.push_back(NewMI); |
| 188 | break; |
| 189 | } |
| 190 | } |
| 191 | } |
| 192 | } |
| 193 | } |
| 194 | |
| 195 | MFI->insert(MBBI, NewMIs[1]); |
| 196 | MFI->insert(MBBI, NewMIs[0]); |
| 197 | return NewMIs[0]; |
| 198 | } |
| 199 | |
Evan Cheng | 2457f2c | 2010-05-22 01:47:14 +0000 | [diff] [blame] | 200 | bool |
| 201 | ARMBaseInstrInfo::spillCalleeSavedRegisters(MachineBasicBlock &MBB, |
Jim Grosbach | 18f30e6 | 2010-06-02 21:53:11 +0000 | [diff] [blame] | 202 | MachineBasicBlock::iterator MI, |
| 203 | const std::vector<CalleeSavedInfo> &CSI, |
| 204 | const TargetRegisterInfo *TRI) const { |
Evan Cheng | 2457f2c | 2010-05-22 01:47:14 +0000 | [diff] [blame] | 205 | if (CSI.empty()) |
| 206 | return false; |
| 207 | |
| 208 | DebugLoc DL; |
| 209 | if (MI != MBB.end()) DL = MI->getDebugLoc(); |
| 210 | |
| 211 | for (unsigned i = 0, e = CSI.size(); i != e; ++i) { |
| 212 | unsigned Reg = CSI[i].getReg(); |
| 213 | bool isKill = true; |
| 214 | |
| 215 | // Add the callee-saved register as live-in unless it's LR and |
| 216 | // @llvm.returnaddress is called. If LR is returned for @llvm.returnaddress |
| 217 | // then it's already added to the function and entry block live-in sets. |
| 218 | if (Reg == ARM::LR) { |
| 219 | MachineFunction &MF = *MBB.getParent(); |
| 220 | if (MF.getFrameInfo()->isReturnAddressTaken() && |
| 221 | MF.getRegInfo().isLiveIn(Reg)) |
| 222 | isKill = false; |
| 223 | } |
| 224 | |
| 225 | if (isKill) |
| 226 | MBB.addLiveIn(Reg); |
| 227 | |
| 228 | // Insert the spill to the stack frame. The register is killed at the spill |
| 229 | // |
Rafael Espindola | 42d075c | 2010-06-02 20:02:30 +0000 | [diff] [blame] | 230 | const TargetRegisterClass *RC = TRI->getMinimalPhysRegClass(Reg); |
Evan Cheng | 2457f2c | 2010-05-22 01:47:14 +0000 | [diff] [blame] | 231 | storeRegToStackSlot(MBB, MI, Reg, isKill, |
Rafael Espindola | 42d075c | 2010-06-02 20:02:30 +0000 | [diff] [blame] | 232 | CSI[i].getFrameIdx(), RC, TRI); |
Evan Cheng | 2457f2c | 2010-05-22 01:47:14 +0000 | [diff] [blame] | 233 | } |
| 234 | return true; |
| 235 | } |
| 236 | |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 237 | // Branch analysis. |
| 238 | bool |
| 239 | ARMBaseInstrInfo::AnalyzeBranch(MachineBasicBlock &MBB,MachineBasicBlock *&TBB, |
| 240 | MachineBasicBlock *&FBB, |
| 241 | SmallVectorImpl<MachineOperand> &Cond, |
| 242 | bool AllowModify) const { |
| 243 | // If the block has no terminators, it just falls into the block after it. |
| 244 | MachineBasicBlock::iterator I = MBB.end(); |
Dale Johannesen | 93d6a7e | 2010-04-02 01:38:09 +0000 | [diff] [blame] | 245 | if (I == MBB.begin()) |
| 246 | return false; |
| 247 | --I; |
| 248 | while (I->isDebugValue()) { |
| 249 | if (I == MBB.begin()) |
| 250 | return false; |
| 251 | --I; |
| 252 | } |
| 253 | if (!isUnpredicatedTerminator(I)) |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 254 | return false; |
| 255 | |
| 256 | // Get the last instruction in the block. |
| 257 | MachineInstr *LastInst = I; |
| 258 | |
| 259 | // If there is only one terminator instruction, process it. |
| 260 | unsigned LastOpc = LastInst->getOpcode(); |
| 261 | if (I == MBB.begin() || !isUnpredicatedTerminator(--I)) { |
Evan Cheng | 5ca53a7 | 2009-07-27 18:20:05 +0000 | [diff] [blame] | 262 | if (isUncondBranchOpcode(LastOpc)) { |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 263 | TBB = LastInst->getOperand(0).getMBB(); |
| 264 | return false; |
| 265 | } |
Evan Cheng | 5ca53a7 | 2009-07-27 18:20:05 +0000 | [diff] [blame] | 266 | if (isCondBranchOpcode(LastOpc)) { |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 267 | // Block ends with fall-through condbranch. |
| 268 | TBB = LastInst->getOperand(0).getMBB(); |
| 269 | Cond.push_back(LastInst->getOperand(1)); |
| 270 | Cond.push_back(LastInst->getOperand(2)); |
| 271 | return false; |
| 272 | } |
| 273 | return true; // Can't handle indirect branch. |
| 274 | } |
| 275 | |
| 276 | // Get the instruction before it if it is a terminator. |
| 277 | MachineInstr *SecondLastInst = I; |
| 278 | |
| 279 | // If there are three terminators, we don't know what sort of block this is. |
| 280 | if (SecondLastInst && I != MBB.begin() && isUnpredicatedTerminator(--I)) |
| 281 | return true; |
| 282 | |
Evan Cheng | 5ca53a7 | 2009-07-27 18:20:05 +0000 | [diff] [blame] | 283 | // If the block ends with a B and a Bcc, handle it. |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 284 | unsigned SecondLastOpc = SecondLastInst->getOpcode(); |
Evan Cheng | 5ca53a7 | 2009-07-27 18:20:05 +0000 | [diff] [blame] | 285 | if (isCondBranchOpcode(SecondLastOpc) && isUncondBranchOpcode(LastOpc)) { |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 286 | TBB = SecondLastInst->getOperand(0).getMBB(); |
| 287 | Cond.push_back(SecondLastInst->getOperand(1)); |
| 288 | Cond.push_back(SecondLastInst->getOperand(2)); |
| 289 | FBB = LastInst->getOperand(0).getMBB(); |
| 290 | return false; |
| 291 | } |
| 292 | |
| 293 | // If the block ends with two unconditional branches, handle it. The second |
| 294 | // one is not executed, so remove it. |
Evan Cheng | 5ca53a7 | 2009-07-27 18:20:05 +0000 | [diff] [blame] | 295 | if (isUncondBranchOpcode(SecondLastOpc) && isUncondBranchOpcode(LastOpc)) { |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 296 | TBB = SecondLastInst->getOperand(0).getMBB(); |
| 297 | I = LastInst; |
| 298 | if (AllowModify) |
| 299 | I->eraseFromParent(); |
| 300 | return false; |
| 301 | } |
| 302 | |
| 303 | // ...likewise if it ends with a branch table followed by an unconditional |
| 304 | // branch. The branch folder can create these, and we must get rid of them for |
| 305 | // correctness of Thumb constant islands. |
Bob Wilson | 8d4de5a | 2009-10-28 18:26:41 +0000 | [diff] [blame] | 306 | if ((isJumpTableBranchOpcode(SecondLastOpc) || |
| 307 | isIndirectBranchOpcode(SecondLastOpc)) && |
Evan Cheng | 5ca53a7 | 2009-07-27 18:20:05 +0000 | [diff] [blame] | 308 | isUncondBranchOpcode(LastOpc)) { |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 309 | I = LastInst; |
| 310 | if (AllowModify) |
| 311 | I->eraseFromParent(); |
| 312 | return true; |
| 313 | } |
| 314 | |
| 315 | // Otherwise, can't handle this. |
| 316 | return true; |
| 317 | } |
| 318 | |
| 319 | |
| 320 | unsigned ARMBaseInstrInfo::RemoveBranch(MachineBasicBlock &MBB) const { |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 321 | MachineBasicBlock::iterator I = MBB.end(); |
| 322 | if (I == MBB.begin()) return 0; |
| 323 | --I; |
Dale Johannesen | 93d6a7e | 2010-04-02 01:38:09 +0000 | [diff] [blame] | 324 | while (I->isDebugValue()) { |
| 325 | if (I == MBB.begin()) |
| 326 | return 0; |
| 327 | --I; |
| 328 | } |
Evan Cheng | 5ca53a7 | 2009-07-27 18:20:05 +0000 | [diff] [blame] | 329 | if (!isUncondBranchOpcode(I->getOpcode()) && |
| 330 | !isCondBranchOpcode(I->getOpcode())) |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 331 | return 0; |
| 332 | |
| 333 | // Remove the branch. |
| 334 | I->eraseFromParent(); |
| 335 | |
| 336 | I = MBB.end(); |
| 337 | |
| 338 | if (I == MBB.begin()) return 1; |
| 339 | --I; |
Evan Cheng | 5ca53a7 | 2009-07-27 18:20:05 +0000 | [diff] [blame] | 340 | if (!isCondBranchOpcode(I->getOpcode())) |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 341 | return 1; |
| 342 | |
| 343 | // Remove the branch. |
| 344 | I->eraseFromParent(); |
| 345 | return 2; |
| 346 | } |
| 347 | |
| 348 | unsigned |
| 349 | ARMBaseInstrInfo::InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB, |
Stuart Hastings | 3bf9125 | 2010-06-17 22:43:56 +0000 | [diff] [blame] | 350 | MachineBasicBlock *FBB, |
| 351 | const SmallVectorImpl<MachineOperand> &Cond, |
| 352 | DebugLoc DL) const { |
Evan Cheng | 6495f63 | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 353 | ARMFunctionInfo *AFI = MBB.getParent()->getInfo<ARMFunctionInfo>(); |
| 354 | int BOpc = !AFI->isThumbFunction() |
| 355 | ? ARM::B : (AFI->isThumb2Function() ? ARM::t2B : ARM::tB); |
| 356 | int BccOpc = !AFI->isThumbFunction() |
| 357 | ? ARM::Bcc : (AFI->isThumb2Function() ? ARM::t2Bcc : ARM::tBcc); |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 358 | |
| 359 | // Shouldn't be a fall through. |
| 360 | assert(TBB && "InsertBranch must not be told to insert a fallthrough"); |
| 361 | assert((Cond.size() == 2 || Cond.size() == 0) && |
| 362 | "ARM branch conditions have two components!"); |
| 363 | |
| 364 | if (FBB == 0) { |
| 365 | if (Cond.empty()) // Unconditional branch? |
Stuart Hastings | 3bf9125 | 2010-06-17 22:43:56 +0000 | [diff] [blame] | 366 | BuildMI(&MBB, DL, get(BOpc)).addMBB(TBB); |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 367 | else |
Stuart Hastings | 3bf9125 | 2010-06-17 22:43:56 +0000 | [diff] [blame] | 368 | BuildMI(&MBB, DL, get(BccOpc)).addMBB(TBB) |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 369 | .addImm(Cond[0].getImm()).addReg(Cond[1].getReg()); |
| 370 | return 1; |
| 371 | } |
| 372 | |
| 373 | // Two-way conditional branch. |
Stuart Hastings | 3bf9125 | 2010-06-17 22:43:56 +0000 | [diff] [blame] | 374 | BuildMI(&MBB, DL, get(BccOpc)).addMBB(TBB) |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 375 | .addImm(Cond[0].getImm()).addReg(Cond[1].getReg()); |
Stuart Hastings | 3bf9125 | 2010-06-17 22:43:56 +0000 | [diff] [blame] | 376 | BuildMI(&MBB, DL, get(BOpc)).addMBB(FBB); |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 377 | return 2; |
| 378 | } |
| 379 | |
| 380 | bool ARMBaseInstrInfo:: |
| 381 | ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const { |
| 382 | ARMCC::CondCodes CC = (ARMCC::CondCodes)(int)Cond[0].getImm(); |
| 383 | Cond[0].setImm(ARMCC::getOppositeCondition(CC)); |
| 384 | return false; |
| 385 | } |
| 386 | |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 387 | bool ARMBaseInstrInfo:: |
| 388 | PredicateInstruction(MachineInstr *MI, |
| 389 | const SmallVectorImpl<MachineOperand> &Pred) const { |
| 390 | unsigned Opc = MI->getOpcode(); |
Evan Cheng | 5ca53a7 | 2009-07-27 18:20:05 +0000 | [diff] [blame] | 391 | if (isUncondBranchOpcode(Opc)) { |
| 392 | MI->setDesc(get(getMatchingCondBranchOpcode(Opc))); |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 393 | MI->addOperand(MachineOperand::CreateImm(Pred[0].getImm())); |
| 394 | MI->addOperand(MachineOperand::CreateReg(Pred[1].getReg(), false)); |
| 395 | return true; |
| 396 | } |
| 397 | |
| 398 | int PIdx = MI->findFirstPredOperandIdx(); |
| 399 | if (PIdx != -1) { |
| 400 | MachineOperand &PMO = MI->getOperand(PIdx); |
| 401 | PMO.setImm(Pred[0].getImm()); |
| 402 | MI->getOperand(PIdx+1).setReg(Pred[1].getReg()); |
| 403 | return true; |
| 404 | } |
| 405 | return false; |
| 406 | } |
| 407 | |
| 408 | bool ARMBaseInstrInfo:: |
| 409 | SubsumesPredicate(const SmallVectorImpl<MachineOperand> &Pred1, |
| 410 | const SmallVectorImpl<MachineOperand> &Pred2) const { |
| 411 | if (Pred1.size() > 2 || Pred2.size() > 2) |
| 412 | return false; |
| 413 | |
| 414 | ARMCC::CondCodes CC1 = (ARMCC::CondCodes)Pred1[0].getImm(); |
| 415 | ARMCC::CondCodes CC2 = (ARMCC::CondCodes)Pred2[0].getImm(); |
| 416 | if (CC1 == CC2) |
| 417 | return true; |
| 418 | |
| 419 | switch (CC1) { |
| 420 | default: |
| 421 | return false; |
| 422 | case ARMCC::AL: |
| 423 | return true; |
| 424 | case ARMCC::HS: |
| 425 | return CC2 == ARMCC::HI; |
| 426 | case ARMCC::LS: |
| 427 | return CC2 == ARMCC::LO || CC2 == ARMCC::EQ; |
| 428 | case ARMCC::GE: |
| 429 | return CC2 == ARMCC::GT; |
| 430 | case ARMCC::LE: |
| 431 | return CC2 == ARMCC::LT; |
| 432 | } |
| 433 | } |
| 434 | |
| 435 | bool ARMBaseInstrInfo::DefinesPredicate(MachineInstr *MI, |
| 436 | std::vector<MachineOperand> &Pred) const { |
Evan Cheng | 8fb9036 | 2009-08-08 03:20:32 +0000 | [diff] [blame] | 437 | // FIXME: This confuses implicit_def with optional CPSR def. |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 438 | const TargetInstrDesc &TID = MI->getDesc(); |
| 439 | if (!TID.getImplicitDefs() && !TID.hasOptionalDef()) |
| 440 | return false; |
| 441 | |
| 442 | bool Found = false; |
| 443 | for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) { |
| 444 | const MachineOperand &MO = MI->getOperand(i); |
| 445 | if (MO.isReg() && MO.getReg() == ARM::CPSR) { |
| 446 | Pred.push_back(MO); |
| 447 | Found = true; |
| 448 | } |
| 449 | } |
| 450 | |
| 451 | return Found; |
| 452 | } |
| 453 | |
Evan Cheng | ac0869d | 2009-11-21 06:21:52 +0000 | [diff] [blame] | 454 | /// isPredicable - Return true if the specified instruction can be predicated. |
| 455 | /// By default, this returns true for every instruction with a |
| 456 | /// PredicateOperand. |
| 457 | bool ARMBaseInstrInfo::isPredicable(MachineInstr *MI) const { |
| 458 | const TargetInstrDesc &TID = MI->getDesc(); |
| 459 | if (!TID.isPredicable()) |
| 460 | return false; |
| 461 | |
| 462 | if ((TID.TSFlags & ARMII::DomainMask) == ARMII::DomainNEON) { |
| 463 | ARMFunctionInfo *AFI = |
| 464 | MI->getParent()->getParent()->getInfo<ARMFunctionInfo>(); |
Evan Cheng | d7f0810 | 2009-11-24 08:06:15 +0000 | [diff] [blame] | 465 | return AFI->isThumb2Function(); |
Evan Cheng | ac0869d | 2009-11-21 06:21:52 +0000 | [diff] [blame] | 466 | } |
| 467 | return true; |
| 468 | } |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 469 | |
Chris Lattner | 56856b1 | 2009-12-03 06:58:32 +0000 | [diff] [blame] | 470 | /// FIXME: Works around a gcc miscompilation with -fstrict-aliasing. |
| 471 | DISABLE_INLINE |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 472 | static unsigned getNumJTEntries(const std::vector<MachineJumpTableEntry> &JT, |
Chris Lattner | 56856b1 | 2009-12-03 06:58:32 +0000 | [diff] [blame] | 473 | unsigned JTI); |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 474 | static unsigned getNumJTEntries(const std::vector<MachineJumpTableEntry> &JT, |
| 475 | unsigned JTI) { |
Chris Lattner | 56856b1 | 2009-12-03 06:58:32 +0000 | [diff] [blame] | 476 | assert(JTI < JT.size()); |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 477 | return JT[JTI].MBBs.size(); |
| 478 | } |
| 479 | |
| 480 | /// GetInstSize - Return the size of the specified MachineInstr. |
| 481 | /// |
| 482 | unsigned ARMBaseInstrInfo::GetInstSizeInBytes(const MachineInstr *MI) const { |
| 483 | const MachineBasicBlock &MBB = *MI->getParent(); |
| 484 | const MachineFunction *MF = MBB.getParent(); |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 485 | const MCAsmInfo *MAI = MF->getTarget().getMCAsmInfo(); |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 486 | |
| 487 | // Basic size info comes from the TSFlags field. |
| 488 | const TargetInstrDesc &TID = MI->getDesc(); |
Bruno Cardoso Lopes | 99405df | 2010-06-08 22:51:23 +0000 | [diff] [blame] | 489 | uint64_t TSFlags = TID.TSFlags; |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 490 | |
Evan Cheng | a0ee862 | 2009-07-31 22:22:22 +0000 | [diff] [blame] | 491 | unsigned Opc = MI->getOpcode(); |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 492 | switch ((TSFlags & ARMII::SizeMask) >> ARMII::SizeShift) { |
| 493 | default: { |
| 494 | // If this machine instr is an inline asm, measure it. |
| 495 | if (MI->getOpcode() == ARM::INLINEASM) |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 496 | return getInlineAsmLength(MI->getOperand(0).getSymbolName(), *MAI); |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 497 | if (MI->isLabel()) |
| 498 | return 0; |
Evan Cheng | a0ee862 | 2009-07-31 22:22:22 +0000 | [diff] [blame] | 499 | switch (Opc) { |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 500 | default: |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 501 | llvm_unreachable("Unknown or unset size field for instr!"); |
Chris Lattner | 518bb53 | 2010-02-09 19:54:29 +0000 | [diff] [blame] | 502 | case TargetOpcode::IMPLICIT_DEF: |
| 503 | case TargetOpcode::KILL: |
| 504 | case TargetOpcode::DBG_LABEL: |
| 505 | case TargetOpcode::EH_LABEL: |
Dale Johannesen | 375be77 | 2010-04-07 19:51:44 +0000 | [diff] [blame] | 506 | case TargetOpcode::DBG_VALUE: |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 507 | return 0; |
| 508 | } |
| 509 | break; |
| 510 | } |
Evan Cheng | 7894762 | 2009-07-24 18:20:44 +0000 | [diff] [blame] | 511 | case ARMII::Size8Bytes: return 8; // ARM instruction x 2. |
| 512 | case ARMII::Size4Bytes: return 4; // ARM / Thumb2 instruction. |
| 513 | case ARMII::Size2Bytes: return 2; // Thumb1 instruction. |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 514 | case ARMII::SizeSpecial: { |
Evan Cheng | a0ee862 | 2009-07-31 22:22:22 +0000 | [diff] [blame] | 515 | switch (Opc) { |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 516 | case ARM::CONSTPOOL_ENTRY: |
| 517 | // If this machine instr is a constant pool entry, its size is recorded as |
| 518 | // operand #2. |
| 519 | return MI->getOperand(2).getImm(); |
Jim Grosbach | 5eb1951 | 2010-05-22 01:06:18 +0000 | [diff] [blame] | 520 | case ARM::Int_eh_sjlj_longjmp: |
| 521 | return 16; |
| 522 | case ARM::tInt_eh_sjlj_longjmp: |
| 523 | return 10; |
Evan Cheng | 7894762 | 2009-07-24 18:20:44 +0000 | [diff] [blame] | 524 | case ARM::Int_eh_sjlj_setjmp: |
Jim Grosbach | d100755 | 2010-04-28 20:33:09 +0000 | [diff] [blame] | 525 | case ARM::Int_eh_sjlj_setjmp_nofp: |
Jim Grosbach | 0798edd | 2010-05-27 23:49:24 +0000 | [diff] [blame] | 526 | return 20; |
Jim Grosbach | d122874 | 2009-12-01 18:10:36 +0000 | [diff] [blame] | 527 | case ARM::tInt_eh_sjlj_setjmp: |
Jim Grosbach | 5aa1684 | 2009-08-11 19:42:21 +0000 | [diff] [blame] | 528 | case ARM::t2Int_eh_sjlj_setjmp: |
Jim Grosbach | d100755 | 2010-04-28 20:33:09 +0000 | [diff] [blame] | 529 | case ARM::t2Int_eh_sjlj_setjmp_nofp: |
Jim Grosbach | 0798edd | 2010-05-27 23:49:24 +0000 | [diff] [blame] | 530 | return 12; |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 531 | case ARM::BR_JTr: |
| 532 | case ARM::BR_JTm: |
| 533 | case ARM::BR_JTadd: |
Evan Cheng | a0ee862 | 2009-07-31 22:22:22 +0000 | [diff] [blame] | 534 | case ARM::tBR_JTr: |
Evan Cheng | d26b14c | 2009-07-31 18:28:05 +0000 | [diff] [blame] | 535 | case ARM::t2BR_JT: |
| 536 | case ARM::t2TBB: |
| 537 | case ARM::t2TBH: { |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 538 | // These are jumptable branches, i.e. a branch followed by an inlined |
Evan Cheng | d26b14c | 2009-07-31 18:28:05 +0000 | [diff] [blame] | 539 | // jumptable. The size is 4 + 4 * number of entries. For TBB, each |
| 540 | // entry is one byte; TBH two byte each. |
Evan Cheng | a0ee862 | 2009-07-31 22:22:22 +0000 | [diff] [blame] | 541 | unsigned EntrySize = (Opc == ARM::t2TBB) |
| 542 | ? 1 : ((Opc == ARM::t2TBH) ? 2 : 4); |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 543 | unsigned NumOps = TID.getNumOperands(); |
| 544 | MachineOperand JTOP = |
| 545 | MI->getOperand(NumOps - (TID.isPredicable() ? 3 : 2)); |
| 546 | unsigned JTI = JTOP.getIndex(); |
| 547 | const MachineJumpTableInfo *MJTI = MF->getJumpTableInfo(); |
Chris Lattner | b1e8039 | 2010-01-25 23:22:00 +0000 | [diff] [blame] | 548 | assert(MJTI != 0); |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 549 | const std::vector<MachineJumpTableEntry> &JT = MJTI->getJumpTables(); |
| 550 | assert(JTI < JT.size()); |
| 551 | // Thumb instructions are 2 byte aligned, but JT entries are 4 byte |
| 552 | // 4 aligned. The assembler / linker may add 2 byte padding just before |
| 553 | // the JT entries. The size does not include this padding; the |
| 554 | // constant islands pass does separate bookkeeping for it. |
| 555 | // FIXME: If we know the size of the function is less than (1 << 16) *2 |
| 556 | // bytes, we can use 16-bit entries instead. Then there won't be an |
| 557 | // alignment issue. |
Evan Cheng | 25f7cfc | 2009-08-01 06:13:52 +0000 | [diff] [blame] | 558 | unsigned InstSize = (Opc == ARM::tBR_JTr || Opc == ARM::t2BR_JT) ? 2 : 4; |
| 559 | unsigned NumEntries = getNumJTEntries(JT, JTI); |
| 560 | if (Opc == ARM::t2TBB && (NumEntries & 1)) |
| 561 | // Make sure the instruction that follows TBB is 2-byte aligned. |
| 562 | // FIXME: Constant island pass should insert an "ALIGN" instruction |
| 563 | // instead. |
| 564 | ++NumEntries; |
| 565 | return NumEntries * EntrySize + InstSize; |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 566 | } |
| 567 | default: |
| 568 | // Otherwise, pseudo-instruction sizes are zero. |
| 569 | return 0; |
| 570 | } |
| 571 | } |
| 572 | } |
| 573 | return 0; // Not reached |
| 574 | } |
| 575 | |
| 576 | /// Return true if the instruction is a register to register move and |
| 577 | /// leave the source and dest operands in the passed parameters. |
| 578 | /// |
| 579 | bool |
| 580 | ARMBaseInstrInfo::isMoveInstr(const MachineInstr &MI, |
| 581 | unsigned &SrcReg, unsigned &DstReg, |
| 582 | unsigned& SrcSubIdx, unsigned& DstSubIdx) const { |
Evan Cheng | 68e3c6a | 2009-07-27 00:05:15 +0000 | [diff] [blame] | 583 | switch (MI.getOpcode()) { |
Evan Cheng | dced03f | 2009-07-27 00:24:36 +0000 | [diff] [blame] | 584 | default: break; |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 585 | case ARM::VMOVS: |
Evan Cheng | 68e3c6a | 2009-07-27 00:05:15 +0000 | [diff] [blame] | 586 | case ARM::VMOVD: |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 587 | case ARM::VMOVDneon: |
Evan Cheng | b63387a | 2010-05-06 06:36:08 +0000 | [diff] [blame] | 588 | case ARM::VMOVQ: |
| 589 | case ARM::VMOVQQ : { |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 590 | SrcReg = MI.getOperand(1).getReg(); |
| 591 | DstReg = MI.getOperand(0).getReg(); |
Evan Cheng | b63387a | 2010-05-06 06:36:08 +0000 | [diff] [blame] | 592 | SrcSubIdx = MI.getOperand(1).getSubReg(); |
| 593 | DstSubIdx = MI.getOperand(0).getSubReg(); |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 594 | return true; |
| 595 | } |
Evan Cheng | 68e3c6a | 2009-07-27 00:05:15 +0000 | [diff] [blame] | 596 | case ARM::MOVr: |
Dale Johannesen | 6470a11 | 2010-06-15 22:08:33 +0000 | [diff] [blame] | 597 | case ARM::MOVr_TC: |
Evan Cheng | 68e3c6a | 2009-07-27 00:05:15 +0000 | [diff] [blame] | 598 | case ARM::tMOVr: |
| 599 | case ARM::tMOVgpr2tgpr: |
| 600 | case ARM::tMOVtgpr2gpr: |
| 601 | case ARM::tMOVgpr2gpr: |
| 602 | case ARM::t2MOVr: { |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 603 | assert(MI.getDesc().getNumOperands() >= 2 && |
| 604 | MI.getOperand(0).isReg() && |
| 605 | MI.getOperand(1).isReg() && |
| 606 | "Invalid ARM MOV instruction"); |
| 607 | SrcReg = MI.getOperand(1).getReg(); |
| 608 | DstReg = MI.getOperand(0).getReg(); |
Evan Cheng | b63387a | 2010-05-06 06:36:08 +0000 | [diff] [blame] | 609 | SrcSubIdx = MI.getOperand(1).getSubReg(); |
| 610 | DstSubIdx = MI.getOperand(0).getSubReg(); |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 611 | return true; |
| 612 | } |
Evan Cheng | 68e3c6a | 2009-07-27 00:05:15 +0000 | [diff] [blame] | 613 | } |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 614 | |
| 615 | return false; |
| 616 | } |
| 617 | |
Jim Grosbach | 764ab52 | 2009-08-11 15:33:49 +0000 | [diff] [blame] | 618 | unsigned |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 619 | ARMBaseInstrInfo::isLoadFromStackSlot(const MachineInstr *MI, |
| 620 | int &FrameIndex) const { |
Evan Cheng | dced03f | 2009-07-27 00:24:36 +0000 | [diff] [blame] | 621 | switch (MI->getOpcode()) { |
| 622 | default: break; |
| 623 | case ARM::LDR: |
| 624 | case ARM::t2LDRs: // FIXME: don't use t2LDRs to access frame. |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 625 | if (MI->getOperand(1).isFI() && |
| 626 | MI->getOperand(2).isReg() && |
| 627 | MI->getOperand(3).isImm() && |
| 628 | MI->getOperand(2).getReg() == 0 && |
| 629 | MI->getOperand(3).getImm() == 0) { |
| 630 | FrameIndex = MI->getOperand(1).getIndex(); |
| 631 | return MI->getOperand(0).getReg(); |
| 632 | } |
Evan Cheng | dced03f | 2009-07-27 00:24:36 +0000 | [diff] [blame] | 633 | break; |
| 634 | case ARM::t2LDRi12: |
| 635 | case ARM::tRestore: |
David Goodwin | 5ff58b5 | 2009-07-24 00:16:18 +0000 | [diff] [blame] | 636 | if (MI->getOperand(1).isFI() && |
| 637 | MI->getOperand(2).isImm() && |
| 638 | MI->getOperand(2).getImm() == 0) { |
| 639 | FrameIndex = MI->getOperand(1).getIndex(); |
| 640 | return MI->getOperand(0).getReg(); |
| 641 | } |
Evan Cheng | dced03f | 2009-07-27 00:24:36 +0000 | [diff] [blame] | 642 | break; |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 643 | case ARM::VLDRD: |
| 644 | case ARM::VLDRS: |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 645 | if (MI->getOperand(1).isFI() && |
| 646 | MI->getOperand(2).isImm() && |
| 647 | MI->getOperand(2).getImm() == 0) { |
| 648 | FrameIndex = MI->getOperand(1).getIndex(); |
| 649 | return MI->getOperand(0).getReg(); |
| 650 | } |
Evan Cheng | dced03f | 2009-07-27 00:24:36 +0000 | [diff] [blame] | 651 | break; |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 652 | } |
| 653 | |
| 654 | return 0; |
| 655 | } |
| 656 | |
| 657 | unsigned |
| 658 | ARMBaseInstrInfo::isStoreToStackSlot(const MachineInstr *MI, |
| 659 | int &FrameIndex) const { |
Evan Cheng | dced03f | 2009-07-27 00:24:36 +0000 | [diff] [blame] | 660 | switch (MI->getOpcode()) { |
| 661 | default: break; |
| 662 | case ARM::STR: |
| 663 | case ARM::t2STRs: // FIXME: don't use t2STRs to access frame. |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 664 | if (MI->getOperand(1).isFI() && |
| 665 | MI->getOperand(2).isReg() && |
| 666 | MI->getOperand(3).isImm() && |
| 667 | MI->getOperand(2).getReg() == 0 && |
| 668 | MI->getOperand(3).getImm() == 0) { |
| 669 | FrameIndex = MI->getOperand(1).getIndex(); |
| 670 | return MI->getOperand(0).getReg(); |
| 671 | } |
Evan Cheng | dced03f | 2009-07-27 00:24:36 +0000 | [diff] [blame] | 672 | break; |
| 673 | case ARM::t2STRi12: |
| 674 | case ARM::tSpill: |
David Goodwin | 5ff58b5 | 2009-07-24 00:16:18 +0000 | [diff] [blame] | 675 | if (MI->getOperand(1).isFI() && |
| 676 | MI->getOperand(2).isImm() && |
| 677 | MI->getOperand(2).getImm() == 0) { |
| 678 | FrameIndex = MI->getOperand(1).getIndex(); |
| 679 | return MI->getOperand(0).getReg(); |
| 680 | } |
Evan Cheng | dced03f | 2009-07-27 00:24:36 +0000 | [diff] [blame] | 681 | break; |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 682 | case ARM::VSTRD: |
| 683 | case ARM::VSTRS: |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 684 | if (MI->getOperand(1).isFI() && |
| 685 | MI->getOperand(2).isImm() && |
| 686 | MI->getOperand(2).getImm() == 0) { |
| 687 | FrameIndex = MI->getOperand(1).getIndex(); |
| 688 | return MI->getOperand(0).getReg(); |
| 689 | } |
Evan Cheng | dced03f | 2009-07-27 00:24:36 +0000 | [diff] [blame] | 690 | break; |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 691 | } |
| 692 | |
| 693 | return 0; |
| 694 | } |
| 695 | |
| 696 | bool |
| 697 | ARMBaseInstrInfo::copyRegToReg(MachineBasicBlock &MBB, |
| 698 | MachineBasicBlock::iterator I, |
| 699 | unsigned DestReg, unsigned SrcReg, |
| 700 | const TargetRegisterClass *DestRC, |
Dan Gohman | 34dcc6f | 2010-05-06 20:33:48 +0000 | [diff] [blame] | 701 | const TargetRegisterClass *SrcRC, |
| 702 | DebugLoc DL) const { |
Dale Johannesen | 6470a11 | 2010-06-15 22:08:33 +0000 | [diff] [blame] | 703 | // tGPR or tcGPR is used sometimes in ARM instructions that need to avoid |
| 704 | // using certain registers. Just treat them as GPR here. |
| 705 | if (DestRC == ARM::tGPRRegisterClass || DestRC == ARM::tcGPRRegisterClass) |
Bob Wilson | 1665b0a | 2010-02-16 17:24:15 +0000 | [diff] [blame] | 706 | DestRC = ARM::GPRRegisterClass; |
Dale Johannesen | 6470a11 | 2010-06-15 22:08:33 +0000 | [diff] [blame] | 707 | if (SrcRC == ARM::tGPRRegisterClass || SrcRC == ARM::tcGPRRegisterClass) |
Bob Wilson | 1665b0a | 2010-02-16 17:24:15 +0000 | [diff] [blame] | 708 | SrcRC = ARM::GPRRegisterClass; |
| 709 | |
Anton Korobeynikov | 6755d97 | 2010-03-18 22:35:02 +0000 | [diff] [blame] | 710 | // Allow DPR / DPR_VFP2 / DPR_8 cross-class copies. |
| 711 | if (DestRC == ARM::DPR_8RegisterClass) |
| 712 | DestRC = ARM::DPR_VFP2RegisterClass; |
| 713 | if (SrcRC == ARM::DPR_8RegisterClass) |
| 714 | SrcRC = ARM::DPR_VFP2RegisterClass; |
Evan Cheng | b4db6a4 | 2009-11-03 05:51:39 +0000 | [diff] [blame] | 715 | |
Anton Korobeynikov | 6755d97 | 2010-03-18 22:35:02 +0000 | [diff] [blame] | 716 | // Allow QPR / QPR_VFP2 / QPR_8 cross-class copies. |
| 717 | if (DestRC == ARM::QPR_VFP2RegisterClass || |
| 718 | DestRC == ARM::QPR_8RegisterClass) |
| 719 | DestRC = ARM::QPRRegisterClass; |
| 720 | if (SrcRC == ARM::QPR_VFP2RegisterClass || |
| 721 | SrcRC == ARM::QPR_8RegisterClass) |
| 722 | SrcRC = ARM::QPRRegisterClass; |
| 723 | |
Evan Cheng | 22c687b | 2010-05-14 02:13:41 +0000 | [diff] [blame] | 724 | // Allow QQPR / QQPR_VFP2 cross-class copies. |
| 725 | if (DestRC == ARM::QQPR_VFP2RegisterClass) |
Evan Cheng | b63387a | 2010-05-06 06:36:08 +0000 | [diff] [blame] | 726 | DestRC = ARM::QQPRRegisterClass; |
Evan Cheng | 22c687b | 2010-05-14 02:13:41 +0000 | [diff] [blame] | 727 | if (SrcRC == ARM::QQPR_VFP2RegisterClass) |
Evan Cheng | b63387a | 2010-05-06 06:36:08 +0000 | [diff] [blame] | 728 | SrcRC = ARM::QQPRRegisterClass; |
| 729 | |
Anton Korobeynikov | 6755d97 | 2010-03-18 22:35:02 +0000 | [diff] [blame] | 730 | // Disallow copies of unequal sizes. |
| 731 | if (DestRC != SrcRC && DestRC->getSize() != SrcRC->getSize()) |
| 732 | return false; |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 733 | |
David Goodwin | 7bfdca0 | 2009-08-05 21:02:22 +0000 | [diff] [blame] | 734 | if (DestRC == ARM::GPRRegisterClass) { |
Anton Korobeynikov | 6755d97 | 2010-03-18 22:35:02 +0000 | [diff] [blame] | 735 | if (SrcRC == ARM::SPRRegisterClass) |
| 736 | AddDefaultPred(BuildMI(MBB, I, DL, get(ARM::VMOVRS), DestReg) |
| 737 | .addReg(SrcReg)); |
| 738 | else |
| 739 | AddDefaultCC(AddDefaultPred(BuildMI(MBB, I, DL, get(ARM::MOVr), |
| 740 | DestReg).addReg(SrcReg))); |
David Goodwin | 7bfdca0 | 2009-08-05 21:02:22 +0000 | [diff] [blame] | 741 | } else { |
Anton Korobeynikov | 6755d97 | 2010-03-18 22:35:02 +0000 | [diff] [blame] | 742 | unsigned Opc; |
| 743 | |
| 744 | if (DestRC == ARM::SPRRegisterClass) |
| 745 | Opc = (SrcRC == ARM::GPRRegisterClass ? ARM::VMOVSR : ARM::VMOVS); |
| 746 | else if (DestRC == ARM::DPRRegisterClass) |
| 747 | Opc = ARM::VMOVD; |
| 748 | else if (DestRC == ARM::DPR_VFP2RegisterClass || |
| 749 | SrcRC == ARM::DPR_VFP2RegisterClass) |
| 750 | // Always use neon reg-reg move if source or dest is NEON-only regclass. |
| 751 | Opc = ARM::VMOVDneon; |
| 752 | else if (DestRC == ARM::QPRRegisterClass) |
| 753 | Opc = ARM::VMOVQ; |
Evan Cheng | b63387a | 2010-05-06 06:36:08 +0000 | [diff] [blame] | 754 | else if (DestRC == ARM::QQPRRegisterClass) |
| 755 | Opc = ARM::VMOVQQ; |
Evan Cheng | 22c687b | 2010-05-14 02:13:41 +0000 | [diff] [blame] | 756 | else if (DestRC == ARM::QQQQPRRegisterClass) |
| 757 | Opc = ARM::VMOVQQQQ; |
Anton Korobeynikov | 6755d97 | 2010-03-18 22:35:02 +0000 | [diff] [blame] | 758 | else |
| 759 | return false; |
| 760 | |
Bob Wilson | 14f1d4e | 2010-06-15 05:51:27 +0000 | [diff] [blame] | 761 | MachineInstrBuilder MIB = BuildMI(MBB, I, DL, get(Opc), DestReg); |
| 762 | MIB.addReg(SrcReg); |
| 763 | if (Opc != ARM::VMOVQQ && Opc != ARM::VMOVQQQQ) |
| 764 | AddDefaultPred(MIB); |
David Goodwin | 7bfdca0 | 2009-08-05 21:02:22 +0000 | [diff] [blame] | 765 | } |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 766 | |
| 767 | return true; |
| 768 | } |
| 769 | |
Evan Cheng | c10b5af | 2010-05-07 00:24:52 +0000 | [diff] [blame] | 770 | static const |
| 771 | MachineInstrBuilder &AddDReg(MachineInstrBuilder &MIB, |
| 772 | unsigned Reg, unsigned SubIdx, unsigned State, |
| 773 | const TargetRegisterInfo *TRI) { |
| 774 | if (!SubIdx) |
| 775 | return MIB.addReg(Reg, State); |
| 776 | |
| 777 | if (TargetRegisterInfo::isPhysicalRegister(Reg)) |
| 778 | return MIB.addReg(TRI->getSubReg(Reg, SubIdx), State); |
| 779 | return MIB.addReg(Reg, State, SubIdx); |
| 780 | } |
| 781 | |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 782 | void ARMBaseInstrInfo:: |
| 783 | storeRegToStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator I, |
| 784 | unsigned SrcReg, bool isKill, int FI, |
Evan Cheng | 746ad69 | 2010-05-06 19:06:44 +0000 | [diff] [blame] | 785 | const TargetRegisterClass *RC, |
| 786 | const TargetRegisterInfo *TRI) const { |
Chris Lattner | c7f3ace | 2010-04-02 20:16:16 +0000 | [diff] [blame] | 787 | DebugLoc DL; |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 788 | if (I != MBB.end()) DL = I->getDebugLoc(); |
Anton Korobeynikov | 249fb33 | 2009-10-07 00:06:35 +0000 | [diff] [blame] | 789 | MachineFunction &MF = *MBB.getParent(); |
| 790 | MachineFrameInfo &MFI = *MF.getFrameInfo(); |
Jim Grosbach | 31bc849 | 2009-11-08 00:27:19 +0000 | [diff] [blame] | 791 | unsigned Align = MFI.getObjectAlignment(FI); |
Anton Korobeynikov | 249fb33 | 2009-10-07 00:06:35 +0000 | [diff] [blame] | 792 | |
| 793 | MachineMemOperand *MMO = |
Evan Cheng | ff89dcb | 2009-10-18 18:16:27 +0000 | [diff] [blame] | 794 | MF.getMachineMemOperand(PseudoSourceValue::getFixedStack(FI), |
Anton Korobeynikov | 249fb33 | 2009-10-07 00:06:35 +0000 | [diff] [blame] | 795 | MachineMemOperand::MOStore, 0, |
| 796 | MFI.getObjectSize(FI), |
Jim Grosbach | 31bc849 | 2009-11-08 00:27:19 +0000 | [diff] [blame] | 797 | Align); |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 798 | |
Bob Wilson | 0eb0c74 | 2010-02-16 22:01:59 +0000 | [diff] [blame] | 799 | // tGPR is used sometimes in ARM instructions that need to avoid using |
| 800 | // certain registers. Just treat it as GPR here. |
Dale Johannesen | 6470a11 | 2010-06-15 22:08:33 +0000 | [diff] [blame] | 801 | if (RC == ARM::tGPRRegisterClass || RC == ARM::tcGPRRegisterClass) |
Bob Wilson | 0eb0c74 | 2010-02-16 22:01:59 +0000 | [diff] [blame] | 802 | RC = ARM::GPRRegisterClass; |
| 803 | |
Bob Wilson | ebe99b2 | 2010-06-18 21:32:42 +0000 | [diff] [blame] | 804 | switch (RC->getID()) { |
| 805 | case ARM::GPRRegClassID: |
Evan Cheng | 5732ca0 | 2009-07-27 03:14:20 +0000 | [diff] [blame] | 806 | AddDefaultPred(BuildMI(MBB, I, DL, get(ARM::STR)) |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 807 | .addReg(SrcReg, getKillRegState(isKill)) |
Anton Korobeynikov | 249fb33 | 2009-10-07 00:06:35 +0000 | [diff] [blame] | 808 | .addFrameIndex(FI).addReg(0).addImm(0).addMemOperand(MMO)); |
Bob Wilson | ebe99b2 | 2010-06-18 21:32:42 +0000 | [diff] [blame] | 809 | break; |
| 810 | case ARM::SPRRegClassID: |
Evan Cheng | d31c549 | 2010-05-06 01:34:11 +0000 | [diff] [blame] | 811 | AddDefaultPred(BuildMI(MBB, I, DL, get(ARM::VSTRS)) |
| 812 | .addReg(SrcReg, getKillRegState(isKill)) |
| 813 | .addFrameIndex(FI).addImm(0).addMemOperand(MMO)); |
Bob Wilson | ebe99b2 | 2010-06-18 21:32:42 +0000 | [diff] [blame] | 814 | break; |
| 815 | case ARM::DPRRegClassID: |
| 816 | case ARM::DPR_VFP2RegClassID: |
| 817 | case ARM::DPR_8RegClassID: |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 818 | AddDefaultPred(BuildMI(MBB, I, DL, get(ARM::VSTRD)) |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 819 | .addReg(SrcReg, getKillRegState(isKill)) |
Anton Korobeynikov | 249fb33 | 2009-10-07 00:06:35 +0000 | [diff] [blame] | 820 | .addFrameIndex(FI).addImm(0).addMemOperand(MMO)); |
Bob Wilson | ebe99b2 | 2010-06-18 21:32:42 +0000 | [diff] [blame] | 821 | break; |
| 822 | case ARM::QPRRegClassID: |
| 823 | case ARM::QPR_VFP2RegClassID: |
| 824 | case ARM::QPR_8RegClassID: |
Anton Korobeynikov | baf3108 | 2009-08-08 13:35:48 +0000 | [diff] [blame] | 825 | // FIXME: Neon instructions should support predicates |
Evan Cheng | b63387a | 2010-05-06 06:36:08 +0000 | [diff] [blame] | 826 | if (Align >= 16 && getRegisterInfo().canRealignStack(MF)) { |
Evan Cheng | 69b9f98 | 2010-05-13 01:12:06 +0000 | [diff] [blame] | 827 | AddDefaultPred(BuildMI(MBB, I, DL, get(ARM::VST1q)) |
| 828 | .addFrameIndex(FI).addImm(128) |
| 829 | .addReg(SrcReg, getKillRegState(isKill)) |
| 830 | .addMemOperand(MMO)); |
Jim Grosbach | 31bc849 | 2009-11-08 00:27:19 +0000 | [diff] [blame] | 831 | } else { |
Evan Cheng | 69b9f98 | 2010-05-13 01:12:06 +0000 | [diff] [blame] | 832 | AddDefaultPred(BuildMI(MBB, I, DL, get(ARM::VSTMQ)) |
| 833 | .addReg(SrcReg, getKillRegState(isKill)) |
| 834 | .addFrameIndex(FI) |
| 835 | .addImm(ARM_AM::getAM5Opc(ARM_AM::ia, 4)) |
| 836 | .addMemOperand(MMO)); |
Jim Grosbach | 31bc849 | 2009-11-08 00:27:19 +0000 | [diff] [blame] | 837 | } |
Bob Wilson | ebe99b2 | 2010-06-18 21:32:42 +0000 | [diff] [blame] | 838 | break; |
| 839 | case ARM::QQPRRegClassID: |
| 840 | case ARM::QQPR_VFP2RegClassID: |
Evan Cheng | 435d499 | 2010-05-07 02:04:02 +0000 | [diff] [blame] | 841 | if (Align >= 16 && getRegisterInfo().canRealignStack(MF)) { |
Evan Cheng | 22c687b | 2010-05-14 02:13:41 +0000 | [diff] [blame] | 842 | // FIXME: It's possible to only store part of the QQ register if the |
| 843 | // spilled def has a sub-register index. |
Evan Cheng | 435d499 | 2010-05-07 02:04:02 +0000 | [diff] [blame] | 844 | MachineInstrBuilder MIB = BuildMI(MBB, I, DL, get(ARM::VST2q32)) |
| 845 | .addFrameIndex(FI).addImm(128); |
Jakob Stoklund Olesen | 558661d | 2010-05-24 16:54:32 +0000 | [diff] [blame] | 846 | MIB = AddDReg(MIB, SrcReg, ARM::dsub_0, getKillRegState(isKill), TRI); |
| 847 | MIB = AddDReg(MIB, SrcReg, ARM::dsub_1, 0, TRI); |
| 848 | MIB = AddDReg(MIB, SrcReg, ARM::dsub_2, 0, TRI); |
| 849 | MIB = AddDReg(MIB, SrcReg, ARM::dsub_3, 0, TRI); |
Evan Cheng | 435d499 | 2010-05-07 02:04:02 +0000 | [diff] [blame] | 850 | AddDefaultPred(MIB.addMemOperand(MMO)); |
| 851 | } else { |
| 852 | MachineInstrBuilder MIB = |
| 853 | AddDefaultPred(BuildMI(MBB, I, DL, get(ARM::VSTMD)) |
| 854 | .addFrameIndex(FI) |
| 855 | .addImm(ARM_AM::getAM5Opc(ARM_AM::ia, 4))) |
| 856 | .addMemOperand(MMO); |
Jakob Stoklund Olesen | 558661d | 2010-05-24 16:54:32 +0000 | [diff] [blame] | 857 | MIB = AddDReg(MIB, SrcReg, ARM::dsub_0, getKillRegState(isKill), TRI); |
| 858 | MIB = AddDReg(MIB, SrcReg, ARM::dsub_1, 0, TRI); |
| 859 | MIB = AddDReg(MIB, SrcReg, ARM::dsub_2, 0, TRI); |
| 860 | AddDReg(MIB, SrcReg, ARM::dsub_3, 0, TRI); |
Evan Cheng | 435d499 | 2010-05-07 02:04:02 +0000 | [diff] [blame] | 861 | } |
Bob Wilson | ebe99b2 | 2010-06-18 21:32:42 +0000 | [diff] [blame] | 862 | break; |
| 863 | case ARM::QQQQPRRegClassID: { |
Evan Cheng | 22c687b | 2010-05-14 02:13:41 +0000 | [diff] [blame] | 864 | MachineInstrBuilder MIB = |
| 865 | AddDefaultPred(BuildMI(MBB, I, DL, get(ARM::VSTMD)) |
| 866 | .addFrameIndex(FI) |
| 867 | .addImm(ARM_AM::getAM5Opc(ARM_AM::ia, 4))) |
| 868 | .addMemOperand(MMO); |
Jakob Stoklund Olesen | 558661d | 2010-05-24 16:54:32 +0000 | [diff] [blame] | 869 | MIB = AddDReg(MIB, SrcReg, ARM::dsub_0, getKillRegState(isKill), TRI); |
| 870 | MIB = AddDReg(MIB, SrcReg, ARM::dsub_1, 0, TRI); |
| 871 | MIB = AddDReg(MIB, SrcReg, ARM::dsub_2, 0, TRI); |
| 872 | MIB = AddDReg(MIB, SrcReg, ARM::dsub_3, 0, TRI); |
| 873 | MIB = AddDReg(MIB, SrcReg, ARM::dsub_4, 0, TRI); |
| 874 | MIB = AddDReg(MIB, SrcReg, ARM::dsub_5, 0, TRI); |
| 875 | MIB = AddDReg(MIB, SrcReg, ARM::dsub_6, 0, TRI); |
| 876 | AddDReg(MIB, SrcReg, ARM::dsub_7, 0, TRI); |
Bob Wilson | ebe99b2 | 2010-06-18 21:32:42 +0000 | [diff] [blame] | 877 | break; |
| 878 | } |
| 879 | default: |
| 880 | llvm_unreachable("Unknown regclass!"); |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 881 | } |
| 882 | } |
| 883 | |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 884 | void ARMBaseInstrInfo:: |
| 885 | loadRegFromStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator I, |
| 886 | unsigned DestReg, int FI, |
Evan Cheng | 746ad69 | 2010-05-06 19:06:44 +0000 | [diff] [blame] | 887 | const TargetRegisterClass *RC, |
| 888 | const TargetRegisterInfo *TRI) const { |
Chris Lattner | c7f3ace | 2010-04-02 20:16:16 +0000 | [diff] [blame] | 889 | DebugLoc DL; |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 890 | if (I != MBB.end()) DL = I->getDebugLoc(); |
Anton Korobeynikov | 249fb33 | 2009-10-07 00:06:35 +0000 | [diff] [blame] | 891 | MachineFunction &MF = *MBB.getParent(); |
| 892 | MachineFrameInfo &MFI = *MF.getFrameInfo(); |
Jim Grosbach | 31bc849 | 2009-11-08 00:27:19 +0000 | [diff] [blame] | 893 | unsigned Align = MFI.getObjectAlignment(FI); |
Anton Korobeynikov | 249fb33 | 2009-10-07 00:06:35 +0000 | [diff] [blame] | 894 | MachineMemOperand *MMO = |
Evan Cheng | ff89dcb | 2009-10-18 18:16:27 +0000 | [diff] [blame] | 895 | MF.getMachineMemOperand(PseudoSourceValue::getFixedStack(FI), |
Anton Korobeynikov | 249fb33 | 2009-10-07 00:06:35 +0000 | [diff] [blame] | 896 | MachineMemOperand::MOLoad, 0, |
| 897 | MFI.getObjectSize(FI), |
Jim Grosbach | 31bc849 | 2009-11-08 00:27:19 +0000 | [diff] [blame] | 898 | Align); |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 899 | |
Bob Wilson | 0eb0c74 | 2010-02-16 22:01:59 +0000 | [diff] [blame] | 900 | // tGPR is used sometimes in ARM instructions that need to avoid using |
| 901 | // certain registers. Just treat it as GPR here. |
Dale Johannesen | 6470a11 | 2010-06-15 22:08:33 +0000 | [diff] [blame] | 902 | if (RC == ARM::tGPRRegisterClass || RC == ARM::tcGPRRegisterClass) |
Bob Wilson | 0eb0c74 | 2010-02-16 22:01:59 +0000 | [diff] [blame] | 903 | RC = ARM::GPRRegisterClass; |
| 904 | |
Bob Wilson | ebe99b2 | 2010-06-18 21:32:42 +0000 | [diff] [blame] | 905 | switch (RC->getID()) { |
| 906 | case ARM::GPRRegClassID: |
Evan Cheng | 5732ca0 | 2009-07-27 03:14:20 +0000 | [diff] [blame] | 907 | AddDefaultPred(BuildMI(MBB, I, DL, get(ARM::LDR), DestReg) |
Anton Korobeynikov | 249fb33 | 2009-10-07 00:06:35 +0000 | [diff] [blame] | 908 | .addFrameIndex(FI).addReg(0).addImm(0).addMemOperand(MMO)); |
Bob Wilson | ebe99b2 | 2010-06-18 21:32:42 +0000 | [diff] [blame] | 909 | break; |
| 910 | case ARM::SPRRegClassID: |
Evan Cheng | d31c549 | 2010-05-06 01:34:11 +0000 | [diff] [blame] | 911 | AddDefaultPred(BuildMI(MBB, I, DL, get(ARM::VLDRS), DestReg) |
| 912 | .addFrameIndex(FI).addImm(0).addMemOperand(MMO)); |
Bob Wilson | ebe99b2 | 2010-06-18 21:32:42 +0000 | [diff] [blame] | 913 | break; |
| 914 | case ARM::DPRRegClassID: |
| 915 | case ARM::DPR_VFP2RegClassID: |
| 916 | case ARM::DPR_8RegClassID: |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 917 | AddDefaultPred(BuildMI(MBB, I, DL, get(ARM::VLDRD), DestReg) |
Anton Korobeynikov | 249fb33 | 2009-10-07 00:06:35 +0000 | [diff] [blame] | 918 | .addFrameIndex(FI).addImm(0).addMemOperand(MMO)); |
Bob Wilson | ebe99b2 | 2010-06-18 21:32:42 +0000 | [diff] [blame] | 919 | break; |
| 920 | case ARM::QPRRegClassID: |
| 921 | case ARM::QPR_VFP2RegClassID: |
| 922 | case ARM::QPR_8RegClassID: |
Evan Cheng | b63387a | 2010-05-06 06:36:08 +0000 | [diff] [blame] | 923 | if (Align >= 16 && getRegisterInfo().canRealignStack(MF)) { |
Evan Cheng | 69b9f98 | 2010-05-13 01:12:06 +0000 | [diff] [blame] | 924 | AddDefaultPred(BuildMI(MBB, I, DL, get(ARM::VLD1q), DestReg) |
| 925 | .addFrameIndex(FI).addImm(128) |
| 926 | .addMemOperand(MMO)); |
Jim Grosbach | 31bc849 | 2009-11-08 00:27:19 +0000 | [diff] [blame] | 927 | } else { |
Evan Cheng | 69b9f98 | 2010-05-13 01:12:06 +0000 | [diff] [blame] | 928 | AddDefaultPred(BuildMI(MBB, I, DL, get(ARM::VLDMQ), DestReg) |
| 929 | .addFrameIndex(FI) |
| 930 | .addImm(ARM_AM::getAM5Opc(ARM_AM::ia, 4)) |
| 931 | .addMemOperand(MMO)); |
Jim Grosbach | 31bc849 | 2009-11-08 00:27:19 +0000 | [diff] [blame] | 932 | } |
Bob Wilson | ebe99b2 | 2010-06-18 21:32:42 +0000 | [diff] [blame] | 933 | break; |
| 934 | case ARM::QQPRRegClassID: |
| 935 | case ARM::QQPR_VFP2RegClassID: |
Evan Cheng | 435d499 | 2010-05-07 02:04:02 +0000 | [diff] [blame] | 936 | if (Align >= 16 && getRegisterInfo().canRealignStack(MF)) { |
| 937 | MachineInstrBuilder MIB = BuildMI(MBB, I, DL, get(ARM::VLD2q32)); |
Jakob Stoklund Olesen | 558661d | 2010-05-24 16:54:32 +0000 | [diff] [blame] | 938 | MIB = AddDReg(MIB, DestReg, ARM::dsub_0, RegState::Define, TRI); |
| 939 | MIB = AddDReg(MIB, DestReg, ARM::dsub_1, RegState::Define, TRI); |
| 940 | MIB = AddDReg(MIB, DestReg, ARM::dsub_2, RegState::Define, TRI); |
| 941 | MIB = AddDReg(MIB, DestReg, ARM::dsub_3, RegState::Define, TRI); |
Evan Cheng | 435d499 | 2010-05-07 02:04:02 +0000 | [diff] [blame] | 942 | AddDefaultPred(MIB.addFrameIndex(FI).addImm(128).addMemOperand(MMO)); |
| 943 | } else { |
| 944 | MachineInstrBuilder MIB = |
| 945 | AddDefaultPred(BuildMI(MBB, I, DL, get(ARM::VLDMD)) |
| 946 | .addFrameIndex(FI) |
| 947 | .addImm(ARM_AM::getAM5Opc(ARM_AM::ia, 4))) |
| 948 | .addMemOperand(MMO); |
Jakob Stoklund Olesen | 558661d | 2010-05-24 16:54:32 +0000 | [diff] [blame] | 949 | MIB = AddDReg(MIB, DestReg, ARM::dsub_0, RegState::Define, TRI); |
| 950 | MIB = AddDReg(MIB, DestReg, ARM::dsub_1, RegState::Define, TRI); |
| 951 | MIB = AddDReg(MIB, DestReg, ARM::dsub_2, RegState::Define, TRI); |
| 952 | AddDReg(MIB, DestReg, ARM::dsub_3, RegState::Define, TRI); |
Evan Cheng | 435d499 | 2010-05-07 02:04:02 +0000 | [diff] [blame] | 953 | } |
Bob Wilson | ebe99b2 | 2010-06-18 21:32:42 +0000 | [diff] [blame] | 954 | break; |
| 955 | case ARM::QQQQPRRegClassID: { |
| 956 | MachineInstrBuilder MIB = |
| 957 | AddDefaultPred(BuildMI(MBB, I, DL, get(ARM::VLDMD)) |
| 958 | .addFrameIndex(FI) |
| 959 | .addImm(ARM_AM::getAM5Opc(ARM_AM::ia, 4))) |
| 960 | .addMemOperand(MMO); |
| 961 | MIB = AddDReg(MIB, DestReg, ARM::dsub_0, RegState::Define, TRI); |
| 962 | MIB = AddDReg(MIB, DestReg, ARM::dsub_1, RegState::Define, TRI); |
| 963 | MIB = AddDReg(MIB, DestReg, ARM::dsub_2, RegState::Define, TRI); |
| 964 | MIB = AddDReg(MIB, DestReg, ARM::dsub_3, RegState::Define, TRI); |
| 965 | MIB = AddDReg(MIB, DestReg, ARM::dsub_4, RegState::Define, TRI); |
| 966 | MIB = AddDReg(MIB, DestReg, ARM::dsub_5, RegState::Define, TRI); |
| 967 | MIB = AddDReg(MIB, DestReg, ARM::dsub_6, RegState::Define, TRI); |
| 968 | AddDReg(MIB, DestReg, ARM::dsub_7, RegState::Define, TRI); |
| 969 | break; |
| 970 | } |
| 971 | default: |
| 972 | llvm_unreachable("Unknown regclass!"); |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 973 | } |
| 974 | } |
| 975 | |
Evan Cheng | 62b5065 | 2010-04-26 07:39:25 +0000 | [diff] [blame] | 976 | MachineInstr* |
| 977 | ARMBaseInstrInfo::emitFrameIndexDebugValue(MachineFunction &MF, |
Evan Cheng | 8601a3d | 2010-04-29 01:13:30 +0000 | [diff] [blame] | 978 | int FrameIx, uint64_t Offset, |
Evan Cheng | 62b5065 | 2010-04-26 07:39:25 +0000 | [diff] [blame] | 979 | const MDNode *MDPtr, |
| 980 | DebugLoc DL) const { |
| 981 | MachineInstrBuilder MIB = BuildMI(MF, DL, get(ARM::DBG_VALUE)) |
| 982 | .addFrameIndex(FrameIx).addImm(0).addImm(Offset).addMetadata(MDPtr); |
| 983 | return &*MIB; |
| 984 | } |
| 985 | |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 986 | MachineInstr *ARMBaseInstrInfo:: |
| 987 | foldMemoryOperandImpl(MachineFunction &MF, MachineInstr *MI, |
| 988 | const SmallVectorImpl<unsigned> &Ops, int FI) const { |
| 989 | if (Ops.size() != 1) return NULL; |
| 990 | |
| 991 | unsigned OpNum = Ops[0]; |
| 992 | unsigned Opc = MI->getOpcode(); |
| 993 | MachineInstr *NewMI = NULL; |
Evan Cheng | 19068ba | 2009-08-10 06:32:05 +0000 | [diff] [blame] | 994 | if (Opc == ARM::MOVr || Opc == ARM::t2MOVr) { |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 995 | // If it is updating CPSR, then it cannot be folded. |
Evan Cheng | 19068ba | 2009-08-10 06:32:05 +0000 | [diff] [blame] | 996 | if (MI->getOperand(4).getReg() == ARM::CPSR && !MI->getOperand(4).isDead()) |
| 997 | return NULL; |
| 998 | unsigned Pred = MI->getOperand(2).getImm(); |
| 999 | unsigned PredReg = MI->getOperand(3).getReg(); |
| 1000 | if (OpNum == 0) { // move -> store |
| 1001 | unsigned SrcReg = MI->getOperand(1).getReg(); |
Evan Cheng | ed3ad21 | 2009-10-25 07:52:27 +0000 | [diff] [blame] | 1002 | unsigned SrcSubReg = MI->getOperand(1).getSubReg(); |
Evan Cheng | 19068ba | 2009-08-10 06:32:05 +0000 | [diff] [blame] | 1003 | bool isKill = MI->getOperand(1).isKill(); |
| 1004 | bool isUndef = MI->getOperand(1).isUndef(); |
| 1005 | if (Opc == ARM::MOVr) |
| 1006 | NewMI = BuildMI(MF, MI->getDebugLoc(), get(ARM::STR)) |
Evan Cheng | ed3ad21 | 2009-10-25 07:52:27 +0000 | [diff] [blame] | 1007 | .addReg(SrcReg, |
| 1008 | getKillRegState(isKill) | getUndefRegState(isUndef), |
| 1009 | SrcSubReg) |
Evan Cheng | 19068ba | 2009-08-10 06:32:05 +0000 | [diff] [blame] | 1010 | .addFrameIndex(FI).addReg(0).addImm(0).addImm(Pred).addReg(PredReg); |
| 1011 | else // ARM::t2MOVr |
| 1012 | NewMI = BuildMI(MF, MI->getDebugLoc(), get(ARM::t2STRi12)) |
Evan Cheng | ed3ad21 | 2009-10-25 07:52:27 +0000 | [diff] [blame] | 1013 | .addReg(SrcReg, |
| 1014 | getKillRegState(isKill) | getUndefRegState(isUndef), |
| 1015 | SrcSubReg) |
Evan Cheng | 19068ba | 2009-08-10 06:32:05 +0000 | [diff] [blame] | 1016 | .addFrameIndex(FI).addImm(0).addImm(Pred).addReg(PredReg); |
| 1017 | } else { // move -> load |
| 1018 | unsigned DstReg = MI->getOperand(0).getReg(); |
Evan Cheng | ed3ad21 | 2009-10-25 07:52:27 +0000 | [diff] [blame] | 1019 | unsigned DstSubReg = MI->getOperand(0).getSubReg(); |
Evan Cheng | 19068ba | 2009-08-10 06:32:05 +0000 | [diff] [blame] | 1020 | bool isDead = MI->getOperand(0).isDead(); |
| 1021 | bool isUndef = MI->getOperand(0).isUndef(); |
| 1022 | if (Opc == ARM::MOVr) |
| 1023 | NewMI = BuildMI(MF, MI->getDebugLoc(), get(ARM::LDR)) |
| 1024 | .addReg(DstReg, |
| 1025 | RegState::Define | |
| 1026 | getDeadRegState(isDead) | |
Evan Cheng | ed3ad21 | 2009-10-25 07:52:27 +0000 | [diff] [blame] | 1027 | getUndefRegState(isUndef), DstSubReg) |
Evan Cheng | 19068ba | 2009-08-10 06:32:05 +0000 | [diff] [blame] | 1028 | .addFrameIndex(FI).addReg(0).addImm(0).addImm(Pred).addReg(PredReg); |
| 1029 | else // ARM::t2MOVr |
| 1030 | NewMI = BuildMI(MF, MI->getDebugLoc(), get(ARM::t2LDRi12)) |
| 1031 | .addReg(DstReg, |
| 1032 | RegState::Define | |
| 1033 | getDeadRegState(isDead) | |
Evan Cheng | ed3ad21 | 2009-10-25 07:52:27 +0000 | [diff] [blame] | 1034 | getUndefRegState(isUndef), DstSubReg) |
Evan Cheng | 19068ba | 2009-08-10 06:32:05 +0000 | [diff] [blame] | 1035 | .addFrameIndex(FI).addImm(0).addImm(Pred).addReg(PredReg); |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 1036 | } |
Evan Cheng | 19068ba | 2009-08-10 06:32:05 +0000 | [diff] [blame] | 1037 | } else if (Opc == ARM::tMOVgpr2gpr || |
| 1038 | Opc == ARM::tMOVtgpr2gpr || |
| 1039 | Opc == ARM::tMOVgpr2tgpr) { |
| 1040 | if (OpNum == 0) { // move -> store |
| 1041 | unsigned SrcReg = MI->getOperand(1).getReg(); |
Evan Cheng | ed3ad21 | 2009-10-25 07:52:27 +0000 | [diff] [blame] | 1042 | unsigned SrcSubReg = MI->getOperand(1).getSubReg(); |
Evan Cheng | 19068ba | 2009-08-10 06:32:05 +0000 | [diff] [blame] | 1043 | bool isKill = MI->getOperand(1).isKill(); |
| 1044 | bool isUndef = MI->getOperand(1).isUndef(); |
| 1045 | NewMI = BuildMI(MF, MI->getDebugLoc(), get(ARM::t2STRi12)) |
Evan Cheng | ed3ad21 | 2009-10-25 07:52:27 +0000 | [diff] [blame] | 1046 | .addReg(SrcReg, |
| 1047 | getKillRegState(isKill) | getUndefRegState(isUndef), |
| 1048 | SrcSubReg) |
Evan Cheng | 19068ba | 2009-08-10 06:32:05 +0000 | [diff] [blame] | 1049 | .addFrameIndex(FI).addImm(0).addImm(ARMCC::AL).addReg(0); |
| 1050 | } else { // move -> load |
| 1051 | unsigned DstReg = MI->getOperand(0).getReg(); |
Evan Cheng | ed3ad21 | 2009-10-25 07:52:27 +0000 | [diff] [blame] | 1052 | unsigned DstSubReg = MI->getOperand(0).getSubReg(); |
Evan Cheng | 19068ba | 2009-08-10 06:32:05 +0000 | [diff] [blame] | 1053 | bool isDead = MI->getOperand(0).isDead(); |
| 1054 | bool isUndef = MI->getOperand(0).isUndef(); |
| 1055 | NewMI = BuildMI(MF, MI->getDebugLoc(), get(ARM::t2LDRi12)) |
| 1056 | .addReg(DstReg, |
| 1057 | RegState::Define | |
| 1058 | getDeadRegState(isDead) | |
Evan Cheng | ed3ad21 | 2009-10-25 07:52:27 +0000 | [diff] [blame] | 1059 | getUndefRegState(isUndef), |
| 1060 | DstSubReg) |
Evan Cheng | 19068ba | 2009-08-10 06:32:05 +0000 | [diff] [blame] | 1061 | .addFrameIndex(FI).addImm(0).addImm(ARMCC::AL).addReg(0); |
| 1062 | } |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 1063 | } else if (Opc == ARM::VMOVS) { |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 1064 | unsigned Pred = MI->getOperand(2).getImm(); |
| 1065 | unsigned PredReg = MI->getOperand(3).getReg(); |
| 1066 | if (OpNum == 0) { // move -> store |
| 1067 | unsigned SrcReg = MI->getOperand(1).getReg(); |
Evan Cheng | ed3ad21 | 2009-10-25 07:52:27 +0000 | [diff] [blame] | 1068 | unsigned SrcSubReg = MI->getOperand(1).getSubReg(); |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 1069 | bool isKill = MI->getOperand(1).isKill(); |
| 1070 | bool isUndef = MI->getOperand(1).isUndef(); |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 1071 | NewMI = BuildMI(MF, MI->getDebugLoc(), get(ARM::VSTRS)) |
Evan Cheng | ed3ad21 | 2009-10-25 07:52:27 +0000 | [diff] [blame] | 1072 | .addReg(SrcReg, getKillRegState(isKill) | getUndefRegState(isUndef), |
| 1073 | SrcSubReg) |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 1074 | .addFrameIndex(FI) |
| 1075 | .addImm(0).addImm(Pred).addReg(PredReg); |
| 1076 | } else { // move -> load |
| 1077 | unsigned DstReg = MI->getOperand(0).getReg(); |
Evan Cheng | ed3ad21 | 2009-10-25 07:52:27 +0000 | [diff] [blame] | 1078 | unsigned DstSubReg = MI->getOperand(0).getSubReg(); |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 1079 | bool isDead = MI->getOperand(0).isDead(); |
| 1080 | bool isUndef = MI->getOperand(0).isUndef(); |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 1081 | NewMI = BuildMI(MF, MI->getDebugLoc(), get(ARM::VLDRS)) |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 1082 | .addReg(DstReg, |
| 1083 | RegState::Define | |
| 1084 | getDeadRegState(isDead) | |
Evan Cheng | ed3ad21 | 2009-10-25 07:52:27 +0000 | [diff] [blame] | 1085 | getUndefRegState(isUndef), |
| 1086 | DstSubReg) |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 1087 | .addFrameIndex(FI).addImm(0).addImm(Pred).addReg(PredReg); |
| 1088 | } |
Evan Cheng | 69b9f98 | 2010-05-13 01:12:06 +0000 | [diff] [blame] | 1089 | } else if (Opc == ARM::VMOVD || Opc == ARM::VMOVDneon) { |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 1090 | unsigned Pred = MI->getOperand(2).getImm(); |
| 1091 | unsigned PredReg = MI->getOperand(3).getReg(); |
| 1092 | if (OpNum == 0) { // move -> store |
| 1093 | unsigned SrcReg = MI->getOperand(1).getReg(); |
Evan Cheng | ed3ad21 | 2009-10-25 07:52:27 +0000 | [diff] [blame] | 1094 | unsigned SrcSubReg = MI->getOperand(1).getSubReg(); |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 1095 | bool isKill = MI->getOperand(1).isKill(); |
| 1096 | bool isUndef = MI->getOperand(1).isUndef(); |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 1097 | NewMI = BuildMI(MF, MI->getDebugLoc(), get(ARM::VSTRD)) |
Evan Cheng | ed3ad21 | 2009-10-25 07:52:27 +0000 | [diff] [blame] | 1098 | .addReg(SrcReg, |
| 1099 | getKillRegState(isKill) | getUndefRegState(isUndef), |
| 1100 | SrcSubReg) |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 1101 | .addFrameIndex(FI).addImm(0).addImm(Pred).addReg(PredReg); |
| 1102 | } else { // move -> load |
| 1103 | unsigned DstReg = MI->getOperand(0).getReg(); |
Evan Cheng | ed3ad21 | 2009-10-25 07:52:27 +0000 | [diff] [blame] | 1104 | unsigned DstSubReg = MI->getOperand(0).getSubReg(); |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 1105 | bool isDead = MI->getOperand(0).isDead(); |
| 1106 | bool isUndef = MI->getOperand(0).isUndef(); |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 1107 | NewMI = BuildMI(MF, MI->getDebugLoc(), get(ARM::VLDRD)) |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 1108 | .addReg(DstReg, |
| 1109 | RegState::Define | |
| 1110 | getDeadRegState(isDead) | |
Evan Cheng | ed3ad21 | 2009-10-25 07:52:27 +0000 | [diff] [blame] | 1111 | getUndefRegState(isUndef), |
| 1112 | DstSubReg) |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 1113 | .addFrameIndex(FI).addImm(0).addImm(Pred).addReg(PredReg); |
| 1114 | } |
Evan Cheng | 69b9f98 | 2010-05-13 01:12:06 +0000 | [diff] [blame] | 1115 | } else if (Opc == ARM::VMOVQ) { |
| 1116 | MachineFrameInfo &MFI = *MF.getFrameInfo(); |
| 1117 | unsigned Pred = MI->getOperand(2).getImm(); |
| 1118 | unsigned PredReg = MI->getOperand(3).getReg(); |
| 1119 | if (OpNum == 0) { // move -> store |
| 1120 | unsigned SrcReg = MI->getOperand(1).getReg(); |
| 1121 | unsigned SrcSubReg = MI->getOperand(1).getSubReg(); |
| 1122 | bool isKill = MI->getOperand(1).isKill(); |
| 1123 | bool isUndef = MI->getOperand(1).isUndef(); |
| 1124 | if (MFI.getObjectAlignment(FI) >= 16 && |
| 1125 | getRegisterInfo().canRealignStack(MF)) { |
| 1126 | NewMI = BuildMI(MF, MI->getDebugLoc(), get(ARM::VST1q)) |
| 1127 | .addFrameIndex(FI).addImm(128) |
| 1128 | .addReg(SrcReg, |
| 1129 | getKillRegState(isKill) | getUndefRegState(isUndef), |
| 1130 | SrcSubReg) |
| 1131 | .addImm(Pred).addReg(PredReg); |
| 1132 | } else { |
| 1133 | NewMI = BuildMI(MF, MI->getDebugLoc(), get(ARM::VSTMQ)) |
| 1134 | .addReg(SrcReg, |
| 1135 | getKillRegState(isKill) | getUndefRegState(isUndef), |
| 1136 | SrcSubReg) |
| 1137 | .addFrameIndex(FI).addImm(ARM_AM::getAM5Opc(ARM_AM::ia, 4)) |
| 1138 | .addImm(Pred).addReg(PredReg); |
| 1139 | } |
| 1140 | } else { // move -> load |
| 1141 | unsigned DstReg = MI->getOperand(0).getReg(); |
| 1142 | unsigned DstSubReg = MI->getOperand(0).getSubReg(); |
| 1143 | bool isDead = MI->getOperand(0).isDead(); |
| 1144 | bool isUndef = MI->getOperand(0).isUndef(); |
| 1145 | if (MFI.getObjectAlignment(FI) >= 16 && |
| 1146 | getRegisterInfo().canRealignStack(MF)) { |
| 1147 | NewMI = BuildMI(MF, MI->getDebugLoc(), get(ARM::VLD1q)) |
| 1148 | .addReg(DstReg, |
| 1149 | RegState::Define | |
| 1150 | getDeadRegState(isDead) | |
| 1151 | getUndefRegState(isUndef), |
| 1152 | DstSubReg) |
| 1153 | .addFrameIndex(FI).addImm(128).addImm(Pred).addReg(PredReg); |
| 1154 | } else { |
| 1155 | NewMI = BuildMI(MF, MI->getDebugLoc(), get(ARM::VLDMQ)) |
| 1156 | .addReg(DstReg, |
| 1157 | RegState::Define | |
| 1158 | getDeadRegState(isDead) | |
| 1159 | getUndefRegState(isUndef), |
| 1160 | DstSubReg) |
| 1161 | .addFrameIndex(FI).addImm(ARM_AM::getAM5Opc(ARM_AM::ia, 4)) |
| 1162 | .addImm(Pred).addReg(PredReg); |
| 1163 | } |
| 1164 | } |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 1165 | } |
| 1166 | |
| 1167 | return NewMI; |
| 1168 | } |
| 1169 | |
Jim Grosbach | 764ab52 | 2009-08-11 15:33:49 +0000 | [diff] [blame] | 1170 | MachineInstr* |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 1171 | ARMBaseInstrInfo::foldMemoryOperandImpl(MachineFunction &MF, |
| 1172 | MachineInstr* MI, |
| 1173 | const SmallVectorImpl<unsigned> &Ops, |
| 1174 | MachineInstr* LoadMI) const { |
Evan Cheng | 1f5c988 | 2009-07-27 04:18:04 +0000 | [diff] [blame] | 1175 | // FIXME |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 1176 | return 0; |
| 1177 | } |
| 1178 | |
| 1179 | bool |
| 1180 | ARMBaseInstrInfo::canFoldMemoryOperand(const MachineInstr *MI, |
Evan Cheng | 2294645 | 2009-08-10 05:51:48 +0000 | [diff] [blame] | 1181 | const SmallVectorImpl<unsigned> &Ops) const { |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 1182 | if (Ops.size() != 1) return false; |
| 1183 | |
| 1184 | unsigned Opc = MI->getOpcode(); |
Evan Cheng | 5732ca0 | 2009-07-27 03:14:20 +0000 | [diff] [blame] | 1185 | if (Opc == ARM::MOVr || Opc == ARM::t2MOVr) { |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 1186 | // If it is updating CPSR, then it cannot be folded. |
Evan Cheng | 2294645 | 2009-08-10 05:51:48 +0000 | [diff] [blame] | 1187 | return MI->getOperand(4).getReg() != ARM::CPSR || |
| 1188 | MI->getOperand(4).isDead(); |
Evan Cheng | 19068ba | 2009-08-10 06:32:05 +0000 | [diff] [blame] | 1189 | } else if (Opc == ARM::tMOVgpr2gpr || |
| 1190 | Opc == ARM::tMOVtgpr2gpr || |
| 1191 | Opc == ARM::tMOVgpr2tgpr) { |
| 1192 | return true; |
Evan Cheng | 69b9f98 | 2010-05-13 01:12:06 +0000 | [diff] [blame] | 1193 | } else if (Opc == ARM::VMOVS || Opc == ARM::VMOVD || |
| 1194 | Opc == ARM::VMOVDneon || Opc == ARM::VMOVQ) { |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 1195 | return true; |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 1196 | } |
| 1197 | |
Evan Cheng | 22c687b | 2010-05-14 02:13:41 +0000 | [diff] [blame] | 1198 | // FIXME: VMOVQQ and VMOVQQQQ? |
| 1199 | |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 1200 | return false; |
| 1201 | } |
Evan Cheng | 5ca53a7 | 2009-07-27 18:20:05 +0000 | [diff] [blame] | 1202 | |
Jakob Stoklund Olesen | 30ac046 | 2010-01-06 23:47:07 +0000 | [diff] [blame] | 1203 | /// Create a copy of a const pool value. Update CPI to the new index and return |
| 1204 | /// the label UID. |
| 1205 | static unsigned duplicateCPV(MachineFunction &MF, unsigned &CPI) { |
| 1206 | MachineConstantPool *MCP = MF.getConstantPool(); |
| 1207 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
| 1208 | |
| 1209 | const MachineConstantPoolEntry &MCPE = MCP->getConstants()[CPI]; |
| 1210 | assert(MCPE.isMachineConstantPoolEntry() && |
| 1211 | "Expecting a machine constantpool entry!"); |
| 1212 | ARMConstantPoolValue *ACPV = |
| 1213 | static_cast<ARMConstantPoolValue*>(MCPE.Val.MachineCPVal); |
| 1214 | |
| 1215 | unsigned PCLabelId = AFI->createConstPoolEntryUId(); |
| 1216 | ARMConstantPoolValue *NewCPV = 0; |
| 1217 | if (ACPV->isGlobalValue()) |
| 1218 | NewCPV = new ARMConstantPoolValue(ACPV->getGV(), PCLabelId, |
| 1219 | ARMCP::CPValue, 4); |
| 1220 | else if (ACPV->isExtSymbol()) |
| 1221 | NewCPV = new ARMConstantPoolValue(MF.getFunction()->getContext(), |
| 1222 | ACPV->getSymbol(), PCLabelId, 4); |
| 1223 | else if (ACPV->isBlockAddress()) |
| 1224 | NewCPV = new ARMConstantPoolValue(ACPV->getBlockAddress(), PCLabelId, |
| 1225 | ARMCP::CPBlockAddress, 4); |
| 1226 | else |
| 1227 | llvm_unreachable("Unexpected ARM constantpool value type!!"); |
| 1228 | CPI = MCP->getConstantPoolIndex(NewCPV, MCPE.getAlignment()); |
| 1229 | return PCLabelId; |
| 1230 | } |
| 1231 | |
Evan Cheng | fdc8340 | 2009-11-08 00:15:23 +0000 | [diff] [blame] | 1232 | void ARMBaseInstrInfo:: |
| 1233 | reMaterialize(MachineBasicBlock &MBB, |
| 1234 | MachineBasicBlock::iterator I, |
| 1235 | unsigned DestReg, unsigned SubIdx, |
Evan Cheng | d57cdd5 | 2009-11-14 02:55:43 +0000 | [diff] [blame] | 1236 | const MachineInstr *Orig, |
Jakob Stoklund Olesen | 9edf7de | 2010-06-02 22:47:25 +0000 | [diff] [blame] | 1237 | const TargetRegisterInfo &TRI) const { |
Evan Cheng | fdc8340 | 2009-11-08 00:15:23 +0000 | [diff] [blame] | 1238 | unsigned Opcode = Orig->getOpcode(); |
| 1239 | switch (Opcode) { |
| 1240 | default: { |
| 1241 | MachineInstr *MI = MBB.getParent()->CloneMachineInstr(Orig); |
Jakob Stoklund Olesen | 9edf7de | 2010-06-02 22:47:25 +0000 | [diff] [blame] | 1242 | MI->substituteRegister(Orig->getOperand(0).getReg(), DestReg, SubIdx, TRI); |
Evan Cheng | fdc8340 | 2009-11-08 00:15:23 +0000 | [diff] [blame] | 1243 | MBB.insert(I, MI); |
| 1244 | break; |
| 1245 | } |
| 1246 | case ARM::tLDRpci_pic: |
| 1247 | case ARM::t2LDRpci_pic: { |
| 1248 | MachineFunction &MF = *MBB.getParent(); |
Evan Cheng | fdc8340 | 2009-11-08 00:15:23 +0000 | [diff] [blame] | 1249 | unsigned CPI = Orig->getOperand(1).getIndex(); |
Jakob Stoklund Olesen | 30ac046 | 2010-01-06 23:47:07 +0000 | [diff] [blame] | 1250 | unsigned PCLabelId = duplicateCPV(MF, CPI); |
Evan Cheng | fdc8340 | 2009-11-08 00:15:23 +0000 | [diff] [blame] | 1251 | MachineInstrBuilder MIB = BuildMI(MBB, I, Orig->getDebugLoc(), get(Opcode), |
| 1252 | DestReg) |
| 1253 | .addConstantPoolIndex(CPI).addImm(PCLabelId); |
| 1254 | (*MIB).setMemRefs(Orig->memoperands_begin(), Orig->memoperands_end()); |
| 1255 | break; |
| 1256 | } |
| 1257 | } |
Evan Cheng | fdc8340 | 2009-11-08 00:15:23 +0000 | [diff] [blame] | 1258 | } |
| 1259 | |
Jakob Stoklund Olesen | 30ac046 | 2010-01-06 23:47:07 +0000 | [diff] [blame] | 1260 | MachineInstr * |
| 1261 | ARMBaseInstrInfo::duplicate(MachineInstr *Orig, MachineFunction &MF) const { |
| 1262 | MachineInstr *MI = TargetInstrInfoImpl::duplicate(Orig, MF); |
| 1263 | switch(Orig->getOpcode()) { |
| 1264 | case ARM::tLDRpci_pic: |
| 1265 | case ARM::t2LDRpci_pic: { |
| 1266 | unsigned CPI = Orig->getOperand(1).getIndex(); |
| 1267 | unsigned PCLabelId = duplicateCPV(MF, CPI); |
| 1268 | Orig->getOperand(1).setIndex(CPI); |
| 1269 | Orig->getOperand(2).setImm(PCLabelId); |
| 1270 | break; |
| 1271 | } |
| 1272 | } |
| 1273 | return MI; |
| 1274 | } |
| 1275 | |
Evan Cheng | 506049f | 2010-03-03 01:44:33 +0000 | [diff] [blame] | 1276 | bool ARMBaseInstrInfo::produceSameValue(const MachineInstr *MI0, |
| 1277 | const MachineInstr *MI1) const { |
Evan Cheng | d457e6e | 2009-11-07 04:04:34 +0000 | [diff] [blame] | 1278 | int Opcode = MI0->getOpcode(); |
Evan Cheng | 9b82425 | 2009-11-20 02:10:27 +0000 | [diff] [blame] | 1279 | if (Opcode == ARM::t2LDRpci || |
| 1280 | Opcode == ARM::t2LDRpci_pic || |
| 1281 | Opcode == ARM::tLDRpci || |
| 1282 | Opcode == ARM::tLDRpci_pic) { |
Evan Cheng | d457e6e | 2009-11-07 04:04:34 +0000 | [diff] [blame] | 1283 | if (MI1->getOpcode() != Opcode) |
| 1284 | return false; |
| 1285 | if (MI0->getNumOperands() != MI1->getNumOperands()) |
| 1286 | return false; |
| 1287 | |
| 1288 | const MachineOperand &MO0 = MI0->getOperand(1); |
| 1289 | const MachineOperand &MO1 = MI1->getOperand(1); |
| 1290 | if (MO0.getOffset() != MO1.getOffset()) |
| 1291 | return false; |
| 1292 | |
| 1293 | const MachineFunction *MF = MI0->getParent()->getParent(); |
| 1294 | const MachineConstantPool *MCP = MF->getConstantPool(); |
| 1295 | int CPI0 = MO0.getIndex(); |
| 1296 | int CPI1 = MO1.getIndex(); |
| 1297 | const MachineConstantPoolEntry &MCPE0 = MCP->getConstants()[CPI0]; |
| 1298 | const MachineConstantPoolEntry &MCPE1 = MCP->getConstants()[CPI1]; |
| 1299 | ARMConstantPoolValue *ACPV0 = |
| 1300 | static_cast<ARMConstantPoolValue*>(MCPE0.Val.MachineCPVal); |
| 1301 | ARMConstantPoolValue *ACPV1 = |
| 1302 | static_cast<ARMConstantPoolValue*>(MCPE1.Val.MachineCPVal); |
| 1303 | return ACPV0->hasSameValue(ACPV1); |
| 1304 | } |
| 1305 | |
Evan Cheng | 506049f | 2010-03-03 01:44:33 +0000 | [diff] [blame] | 1306 | return MI0->isIdenticalTo(MI1, MachineInstr::IgnoreVRegDefs); |
Evan Cheng | d457e6e | 2009-11-07 04:04:34 +0000 | [diff] [blame] | 1307 | } |
| 1308 | |
Bill Wendling | 4b72210 | 2010-06-23 23:00:16 +0000 | [diff] [blame^] | 1309 | /// areLoadsFromSameBasePtr - This is used by the pre-regalloc scheduler to |
| 1310 | /// determine if two loads are loading from the same base address. It should |
| 1311 | /// only return true if the base pointers are the same and the only differences |
| 1312 | /// between the two addresses is the offset. It also returns the offsets by |
| 1313 | /// reference. |
| 1314 | bool ARMBaseInstrInfo::areLoadsFromSameBasePtr(SDNode *Load1, SDNode *Load2, |
| 1315 | int64_t &Offset1, |
| 1316 | int64_t &Offset2) const { |
| 1317 | // Don't worry about Thumb: just ARM and Thumb2. |
| 1318 | if (Subtarget.isThumb1Only()) return false; |
| 1319 | |
| 1320 | if (!Load1->isMachineOpcode() || !Load2->isMachineOpcode()) |
| 1321 | return false; |
| 1322 | |
| 1323 | switch (Load1->getMachineOpcode()) { |
| 1324 | default: |
| 1325 | return false; |
| 1326 | case ARM::LDR: |
| 1327 | case ARM::LDRB: |
| 1328 | case ARM::LDRD: |
| 1329 | case ARM::LDRH: |
| 1330 | case ARM::LDRSB: |
| 1331 | case ARM::LDRSH: |
| 1332 | case ARM::VLDRD: |
| 1333 | case ARM::VLDRS: |
| 1334 | case ARM::t2LDRi8: |
| 1335 | case ARM::t2LDRDi8: |
| 1336 | case ARM::t2LDRSHi8: |
| 1337 | case ARM::t2LDRi12: |
| 1338 | case ARM::t2LDRSHi12: |
| 1339 | break; |
| 1340 | } |
| 1341 | |
| 1342 | switch (Load2->getMachineOpcode()) { |
| 1343 | default: |
| 1344 | return false; |
| 1345 | case ARM::LDR: |
| 1346 | case ARM::LDRB: |
| 1347 | case ARM::LDRD: |
| 1348 | case ARM::LDRH: |
| 1349 | case ARM::LDRSB: |
| 1350 | case ARM::LDRSH: |
| 1351 | case ARM::VLDRD: |
| 1352 | case ARM::VLDRS: |
| 1353 | case ARM::t2LDRi8: |
| 1354 | case ARM::t2LDRDi8: |
| 1355 | case ARM::t2LDRSHi8: |
| 1356 | case ARM::t2LDRi12: |
| 1357 | case ARM::t2LDRSHi12: |
| 1358 | break; |
| 1359 | } |
| 1360 | |
| 1361 | // Check if base addresses and chain operands match. |
| 1362 | if (Load1->getOperand(0) != Load2->getOperand(0) || |
| 1363 | Load1->getOperand(4) != Load2->getOperand(4)) |
| 1364 | return false; |
| 1365 | |
| 1366 | // Index should be Reg0. |
| 1367 | if (Load1->getOperand(3) != Load2->getOperand(3)) |
| 1368 | return false; |
| 1369 | |
| 1370 | // Determine the offsets. |
| 1371 | if (isa<ConstantSDNode>(Load1->getOperand(1)) && |
| 1372 | isa<ConstantSDNode>(Load2->getOperand(1))) { |
| 1373 | Offset1 = cast<ConstantSDNode>(Load1->getOperand(1))->getSExtValue(); |
| 1374 | Offset2 = cast<ConstantSDNode>(Load2->getOperand(1))->getSExtValue(); |
| 1375 | return true; |
| 1376 | } |
| 1377 | |
| 1378 | return false; |
| 1379 | } |
| 1380 | |
| 1381 | /// shouldScheduleLoadsNear - This is a used by the pre-regalloc scheduler to |
| 1382 | /// determine (in conjuction with areLoadsFromSameBasePtr) if two loads should |
| 1383 | /// be scheduled togther. On some targets if two loads are loading from |
| 1384 | /// addresses in the same cache line, it's better if they are scheduled |
| 1385 | /// together. This function takes two integers that represent the load offsets |
| 1386 | /// from the common base address. It returns true if it decides it's desirable |
| 1387 | /// to schedule the two loads together. "NumLoads" is the number of loads that |
| 1388 | /// have already been scheduled after Load1. |
| 1389 | bool ARMBaseInstrInfo::shouldScheduleLoadsNear(SDNode *Load1, SDNode *Load2, |
| 1390 | int64_t Offset1, int64_t Offset2, |
| 1391 | unsigned NumLoads) const { |
| 1392 | // Don't worry about Thumb: just ARM and Thumb2. |
| 1393 | if (Subtarget.isThumb1Only()) return false; |
| 1394 | |
| 1395 | assert(Offset2 > Offset1); |
| 1396 | |
| 1397 | if ((Offset2 - Offset1) / 8 > 64) |
| 1398 | return false; |
| 1399 | |
| 1400 | if (Load1->getMachineOpcode() != Load2->getMachineOpcode()) |
| 1401 | return false; // FIXME: overly conservative? |
| 1402 | |
| 1403 | // Four loads in a row should be sufficient. |
| 1404 | if (NumLoads >= 3) |
| 1405 | return false; |
| 1406 | |
| 1407 | return true; |
| 1408 | } |
| 1409 | |
Evan Cheng | 86050dc | 2010-06-18 23:09:54 +0000 | [diff] [blame] | 1410 | bool ARMBaseInstrInfo::isSchedulingBoundary(const MachineInstr *MI, |
| 1411 | const MachineBasicBlock *MBB, |
| 1412 | const MachineFunction &MF) const { |
| 1413 | // Terminators and labels can't be scheduled around. |
| 1414 | if (MI->getDesc().isTerminator() || MI->isLabel()) |
| 1415 | return true; |
| 1416 | |
| 1417 | // Treat the start of the IT block as a scheduling boundary, but schedule |
| 1418 | // t2IT along with all instructions following it. |
| 1419 | // FIXME: This is a big hammer. But the alternative is to add all potential |
| 1420 | // true and anti dependencies to IT block instructions as implicit operands |
| 1421 | // to the t2IT instruction. The added compile time and complexity does not |
| 1422 | // seem worth it. |
| 1423 | MachineBasicBlock::const_iterator I = MI; |
| 1424 | if (++I != MBB->end() && I->getOpcode() == ARM::t2IT) |
| 1425 | return true; |
| 1426 | |
| 1427 | // Don't attempt to schedule around any instruction that defines |
| 1428 | // a stack-oriented pointer, as it's unlikely to be profitable. This |
| 1429 | // saves compile time, because it doesn't require every single |
| 1430 | // stack slot reference to depend on the instruction that does the |
| 1431 | // modification. |
| 1432 | if (MI->definesRegister(ARM::SP)) |
| 1433 | return true; |
| 1434 | |
| 1435 | return false; |
| 1436 | } |
| 1437 | |
Evan Cheng | 8fb9036 | 2009-08-08 03:20:32 +0000 | [diff] [blame] | 1438 | /// getInstrPredicate - If instruction is predicated, returns its predicate |
| 1439 | /// condition, otherwise returns AL. It also returns the condition code |
| 1440 | /// register by reference. |
Evan Cheng | 5adb66a | 2009-09-28 09:14:39 +0000 | [diff] [blame] | 1441 | ARMCC::CondCodes |
| 1442 | llvm::getInstrPredicate(const MachineInstr *MI, unsigned &PredReg) { |
Evan Cheng | 8fb9036 | 2009-08-08 03:20:32 +0000 | [diff] [blame] | 1443 | int PIdx = MI->findFirstPredOperandIdx(); |
| 1444 | if (PIdx == -1) { |
| 1445 | PredReg = 0; |
| 1446 | return ARMCC::AL; |
| 1447 | } |
| 1448 | |
| 1449 | PredReg = MI->getOperand(PIdx+1).getReg(); |
| 1450 | return (ARMCC::CondCodes)MI->getOperand(PIdx).getImm(); |
| 1451 | } |
| 1452 | |
| 1453 | |
Evan Cheng | 6495f63 | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 1454 | int llvm::getMatchingCondBranchOpcode(int Opc) { |
Evan Cheng | 5ca53a7 | 2009-07-27 18:20:05 +0000 | [diff] [blame] | 1455 | if (Opc == ARM::B) |
| 1456 | return ARM::Bcc; |
| 1457 | else if (Opc == ARM::tB) |
| 1458 | return ARM::tBcc; |
| 1459 | else if (Opc == ARM::t2B) |
| 1460 | return ARM::t2Bcc; |
| 1461 | |
| 1462 | llvm_unreachable("Unknown unconditional branch opcode!"); |
| 1463 | return 0; |
| 1464 | } |
| 1465 | |
Evan Cheng | 6495f63 | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 1466 | |
| 1467 | void llvm::emitARMRegPlusImmediate(MachineBasicBlock &MBB, |
| 1468 | MachineBasicBlock::iterator &MBBI, DebugLoc dl, |
| 1469 | unsigned DestReg, unsigned BaseReg, int NumBytes, |
| 1470 | ARMCC::CondCodes Pred, unsigned PredReg, |
| 1471 | const ARMBaseInstrInfo &TII) { |
| 1472 | bool isSub = NumBytes < 0; |
| 1473 | if (isSub) NumBytes = -NumBytes; |
| 1474 | |
| 1475 | while (NumBytes) { |
| 1476 | unsigned RotAmt = ARM_AM::getSOImmValRotate(NumBytes); |
| 1477 | unsigned ThisVal = NumBytes & ARM_AM::rotr32(0xFF, RotAmt); |
| 1478 | assert(ThisVal && "Didn't extract field correctly"); |
| 1479 | |
| 1480 | // We will handle these bits from offset, clear them. |
| 1481 | NumBytes &= ~ThisVal; |
| 1482 | |
| 1483 | assert(ARM_AM::getSOImmVal(ThisVal) != -1 && "Bit extraction didn't work?"); |
| 1484 | |
| 1485 | // Build the new ADD / SUB. |
| 1486 | unsigned Opc = isSub ? ARM::SUBri : ARM::ADDri; |
| 1487 | BuildMI(MBB, MBBI, dl, TII.get(Opc), DestReg) |
| 1488 | .addReg(BaseReg, RegState::Kill).addImm(ThisVal) |
| 1489 | .addImm((unsigned)Pred).addReg(PredReg).addReg(0); |
| 1490 | BaseReg = DestReg; |
| 1491 | } |
| 1492 | } |
| 1493 | |
Evan Cheng | cdbb3f5 | 2009-08-27 01:23:50 +0000 | [diff] [blame] | 1494 | bool llvm::rewriteARMFrameIndex(MachineInstr &MI, unsigned FrameRegIdx, |
| 1495 | unsigned FrameReg, int &Offset, |
| 1496 | const ARMBaseInstrInfo &TII) { |
Evan Cheng | 6495f63 | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 1497 | unsigned Opcode = MI.getOpcode(); |
| 1498 | const TargetInstrDesc &Desc = MI.getDesc(); |
| 1499 | unsigned AddrMode = (Desc.TSFlags & ARMII::AddrModeMask); |
| 1500 | bool isSub = false; |
Jim Grosbach | 764ab52 | 2009-08-11 15:33:49 +0000 | [diff] [blame] | 1501 | |
Evan Cheng | 6495f63 | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 1502 | // Memory operands in inline assembly always use AddrMode2. |
| 1503 | if (Opcode == ARM::INLINEASM) |
| 1504 | AddrMode = ARMII::AddrMode2; |
Jim Grosbach | 764ab52 | 2009-08-11 15:33:49 +0000 | [diff] [blame] | 1505 | |
Evan Cheng | 6495f63 | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 1506 | if (Opcode == ARM::ADDri) { |
| 1507 | Offset += MI.getOperand(FrameRegIdx+1).getImm(); |
| 1508 | if (Offset == 0) { |
| 1509 | // Turn it into a move. |
| 1510 | MI.setDesc(TII.get(ARM::MOVr)); |
| 1511 | MI.getOperand(FrameRegIdx).ChangeToRegister(FrameReg, false); |
| 1512 | MI.RemoveOperand(FrameRegIdx+1); |
Evan Cheng | cdbb3f5 | 2009-08-27 01:23:50 +0000 | [diff] [blame] | 1513 | Offset = 0; |
| 1514 | return true; |
Evan Cheng | 6495f63 | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 1515 | } else if (Offset < 0) { |
| 1516 | Offset = -Offset; |
| 1517 | isSub = true; |
| 1518 | MI.setDesc(TII.get(ARM::SUBri)); |
| 1519 | } |
| 1520 | |
| 1521 | // Common case: small offset, fits into instruction. |
| 1522 | if (ARM_AM::getSOImmVal(Offset) != -1) { |
| 1523 | // Replace the FrameIndex with sp / fp |
| 1524 | MI.getOperand(FrameRegIdx).ChangeToRegister(FrameReg, false); |
| 1525 | MI.getOperand(FrameRegIdx+1).ChangeToImmediate(Offset); |
Evan Cheng | cdbb3f5 | 2009-08-27 01:23:50 +0000 | [diff] [blame] | 1526 | Offset = 0; |
| 1527 | return true; |
Evan Cheng | 6495f63 | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 1528 | } |
| 1529 | |
| 1530 | // Otherwise, pull as much of the immedidate into this ADDri/SUBri |
| 1531 | // as possible. |
| 1532 | unsigned RotAmt = ARM_AM::getSOImmValRotate(Offset); |
| 1533 | unsigned ThisImmVal = Offset & ARM_AM::rotr32(0xFF, RotAmt); |
| 1534 | |
| 1535 | // We will handle these bits from offset, clear them. |
| 1536 | Offset &= ~ThisImmVal; |
| 1537 | |
| 1538 | // Get the properly encoded SOImmVal field. |
| 1539 | assert(ARM_AM::getSOImmVal(ThisImmVal) != -1 && |
| 1540 | "Bit extraction didn't work?"); |
| 1541 | MI.getOperand(FrameRegIdx+1).ChangeToImmediate(ThisImmVal); |
| 1542 | } else { |
| 1543 | unsigned ImmIdx = 0; |
| 1544 | int InstrOffs = 0; |
| 1545 | unsigned NumBits = 0; |
| 1546 | unsigned Scale = 1; |
| 1547 | switch (AddrMode) { |
| 1548 | case ARMII::AddrMode2: { |
| 1549 | ImmIdx = FrameRegIdx+2; |
| 1550 | InstrOffs = ARM_AM::getAM2Offset(MI.getOperand(ImmIdx).getImm()); |
| 1551 | if (ARM_AM::getAM2Op(MI.getOperand(ImmIdx).getImm()) == ARM_AM::sub) |
| 1552 | InstrOffs *= -1; |
| 1553 | NumBits = 12; |
| 1554 | break; |
| 1555 | } |
| 1556 | case ARMII::AddrMode3: { |
| 1557 | ImmIdx = FrameRegIdx+2; |
| 1558 | InstrOffs = ARM_AM::getAM3Offset(MI.getOperand(ImmIdx).getImm()); |
| 1559 | if (ARM_AM::getAM3Op(MI.getOperand(ImmIdx).getImm()) == ARM_AM::sub) |
| 1560 | InstrOffs *= -1; |
| 1561 | NumBits = 8; |
| 1562 | break; |
| 1563 | } |
Anton Korobeynikov | baf3108 | 2009-08-08 13:35:48 +0000 | [diff] [blame] | 1564 | case ARMII::AddrMode4: |
Jim Grosbach | a443217 | 2009-11-15 21:45:34 +0000 | [diff] [blame] | 1565 | case ARMII::AddrMode6: |
Evan Cheng | cdbb3f5 | 2009-08-27 01:23:50 +0000 | [diff] [blame] | 1566 | // Can't fold any offset even if it's zero. |
| 1567 | return false; |
Evan Cheng | 6495f63 | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 1568 | case ARMII::AddrMode5: { |
| 1569 | ImmIdx = FrameRegIdx+1; |
| 1570 | InstrOffs = ARM_AM::getAM5Offset(MI.getOperand(ImmIdx).getImm()); |
| 1571 | if (ARM_AM::getAM5Op(MI.getOperand(ImmIdx).getImm()) == ARM_AM::sub) |
| 1572 | InstrOffs *= -1; |
| 1573 | NumBits = 8; |
| 1574 | Scale = 4; |
| 1575 | break; |
| 1576 | } |
| 1577 | default: |
| 1578 | llvm_unreachable("Unsupported addressing mode!"); |
| 1579 | break; |
| 1580 | } |
| 1581 | |
| 1582 | Offset += InstrOffs * Scale; |
| 1583 | assert((Offset & (Scale-1)) == 0 && "Can't encode this offset!"); |
| 1584 | if (Offset < 0) { |
| 1585 | Offset = -Offset; |
| 1586 | isSub = true; |
| 1587 | } |
| 1588 | |
| 1589 | // Attempt to fold address comp. if opcode has offset bits |
| 1590 | if (NumBits > 0) { |
| 1591 | // Common case: small offset, fits into instruction. |
| 1592 | MachineOperand &ImmOp = MI.getOperand(ImmIdx); |
| 1593 | int ImmedOffset = Offset / Scale; |
| 1594 | unsigned Mask = (1 << NumBits) - 1; |
| 1595 | if ((unsigned)Offset <= Mask * Scale) { |
| 1596 | // Replace the FrameIndex with sp |
| 1597 | MI.getOperand(FrameRegIdx).ChangeToRegister(FrameReg, false); |
| 1598 | if (isSub) |
| 1599 | ImmedOffset |= 1 << NumBits; |
| 1600 | ImmOp.ChangeToImmediate(ImmedOffset); |
Evan Cheng | cdbb3f5 | 2009-08-27 01:23:50 +0000 | [diff] [blame] | 1601 | Offset = 0; |
| 1602 | return true; |
Evan Cheng | 6495f63 | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 1603 | } |
Jim Grosbach | 764ab52 | 2009-08-11 15:33:49 +0000 | [diff] [blame] | 1604 | |
Evan Cheng | 6495f63 | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 1605 | // Otherwise, it didn't fit. Pull in what we can to simplify the immed. |
| 1606 | ImmedOffset = ImmedOffset & Mask; |
| 1607 | if (isSub) |
| 1608 | ImmedOffset |= 1 << NumBits; |
| 1609 | ImmOp.ChangeToImmediate(ImmedOffset); |
| 1610 | Offset &= ~(Mask*Scale); |
| 1611 | } |
| 1612 | } |
| 1613 | |
Evan Cheng | cdbb3f5 | 2009-08-27 01:23:50 +0000 | [diff] [blame] | 1614 | Offset = (isSub) ? -Offset : Offset; |
| 1615 | return Offset == 0; |
Evan Cheng | 6495f63 | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 1616 | } |