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(); |
| 59 | unsigned TSFlags = MI->getDesc().TSFlags; |
| 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, |
Jim Grosbach | 18f30e6 | 2010-06-02 21:53:11 +0000 | [diff] [blame^] | 350 | MachineBasicBlock *FBB, |
| 351 | const SmallVectorImpl<MachineOperand> &Cond) const { |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 352 | // FIXME this should probably have a DebugLoc argument |
Chris Lattner | c7f3ace | 2010-04-02 20:16:16 +0000 | [diff] [blame] | 353 | DebugLoc dl; |
Evan Cheng | 6495f63 | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 354 | |
| 355 | ARMFunctionInfo *AFI = MBB.getParent()->getInfo<ARMFunctionInfo>(); |
| 356 | int BOpc = !AFI->isThumbFunction() |
| 357 | ? ARM::B : (AFI->isThumb2Function() ? ARM::t2B : ARM::tB); |
| 358 | int BccOpc = !AFI->isThumbFunction() |
| 359 | ? ARM::Bcc : (AFI->isThumb2Function() ? ARM::t2Bcc : ARM::tBcc); |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 360 | |
| 361 | // Shouldn't be a fall through. |
| 362 | assert(TBB && "InsertBranch must not be told to insert a fallthrough"); |
| 363 | assert((Cond.size() == 2 || Cond.size() == 0) && |
| 364 | "ARM branch conditions have two components!"); |
| 365 | |
| 366 | if (FBB == 0) { |
| 367 | if (Cond.empty()) // Unconditional branch? |
| 368 | BuildMI(&MBB, dl, get(BOpc)).addMBB(TBB); |
| 369 | else |
| 370 | BuildMI(&MBB, dl, get(BccOpc)).addMBB(TBB) |
| 371 | .addImm(Cond[0].getImm()).addReg(Cond[1].getReg()); |
| 372 | return 1; |
| 373 | } |
| 374 | |
| 375 | // Two-way conditional branch. |
| 376 | BuildMI(&MBB, dl, get(BccOpc)).addMBB(TBB) |
| 377 | .addImm(Cond[0].getImm()).addReg(Cond[1].getReg()); |
| 378 | BuildMI(&MBB, dl, get(BOpc)).addMBB(FBB); |
| 379 | return 2; |
| 380 | } |
| 381 | |
| 382 | bool ARMBaseInstrInfo:: |
| 383 | ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const { |
| 384 | ARMCC::CondCodes CC = (ARMCC::CondCodes)(int)Cond[0].getImm(); |
| 385 | Cond[0].setImm(ARMCC::getOppositeCondition(CC)); |
| 386 | return false; |
| 387 | } |
| 388 | |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 389 | bool ARMBaseInstrInfo:: |
| 390 | PredicateInstruction(MachineInstr *MI, |
| 391 | const SmallVectorImpl<MachineOperand> &Pred) const { |
| 392 | unsigned Opc = MI->getOpcode(); |
Evan Cheng | 5ca53a7 | 2009-07-27 18:20:05 +0000 | [diff] [blame] | 393 | if (isUncondBranchOpcode(Opc)) { |
| 394 | MI->setDesc(get(getMatchingCondBranchOpcode(Opc))); |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 395 | MI->addOperand(MachineOperand::CreateImm(Pred[0].getImm())); |
| 396 | MI->addOperand(MachineOperand::CreateReg(Pred[1].getReg(), false)); |
| 397 | return true; |
| 398 | } |
| 399 | |
| 400 | int PIdx = MI->findFirstPredOperandIdx(); |
| 401 | if (PIdx != -1) { |
| 402 | MachineOperand &PMO = MI->getOperand(PIdx); |
| 403 | PMO.setImm(Pred[0].getImm()); |
| 404 | MI->getOperand(PIdx+1).setReg(Pred[1].getReg()); |
| 405 | return true; |
| 406 | } |
| 407 | return false; |
| 408 | } |
| 409 | |
| 410 | bool ARMBaseInstrInfo:: |
| 411 | SubsumesPredicate(const SmallVectorImpl<MachineOperand> &Pred1, |
| 412 | const SmallVectorImpl<MachineOperand> &Pred2) const { |
| 413 | if (Pred1.size() > 2 || Pred2.size() > 2) |
| 414 | return false; |
| 415 | |
| 416 | ARMCC::CondCodes CC1 = (ARMCC::CondCodes)Pred1[0].getImm(); |
| 417 | ARMCC::CondCodes CC2 = (ARMCC::CondCodes)Pred2[0].getImm(); |
| 418 | if (CC1 == CC2) |
| 419 | return true; |
| 420 | |
| 421 | switch (CC1) { |
| 422 | default: |
| 423 | return false; |
| 424 | case ARMCC::AL: |
| 425 | return true; |
| 426 | case ARMCC::HS: |
| 427 | return CC2 == ARMCC::HI; |
| 428 | case ARMCC::LS: |
| 429 | return CC2 == ARMCC::LO || CC2 == ARMCC::EQ; |
| 430 | case ARMCC::GE: |
| 431 | return CC2 == ARMCC::GT; |
| 432 | case ARMCC::LE: |
| 433 | return CC2 == ARMCC::LT; |
| 434 | } |
| 435 | } |
| 436 | |
| 437 | bool ARMBaseInstrInfo::DefinesPredicate(MachineInstr *MI, |
| 438 | std::vector<MachineOperand> &Pred) const { |
Evan Cheng | 8fb9036 | 2009-08-08 03:20:32 +0000 | [diff] [blame] | 439 | // FIXME: This confuses implicit_def with optional CPSR def. |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 440 | const TargetInstrDesc &TID = MI->getDesc(); |
| 441 | if (!TID.getImplicitDefs() && !TID.hasOptionalDef()) |
| 442 | return false; |
| 443 | |
| 444 | bool Found = false; |
| 445 | for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) { |
| 446 | const MachineOperand &MO = MI->getOperand(i); |
| 447 | if (MO.isReg() && MO.getReg() == ARM::CPSR) { |
| 448 | Pred.push_back(MO); |
| 449 | Found = true; |
| 450 | } |
| 451 | } |
| 452 | |
| 453 | return Found; |
| 454 | } |
| 455 | |
Evan Cheng | ac0869d | 2009-11-21 06:21:52 +0000 | [diff] [blame] | 456 | /// isPredicable - Return true if the specified instruction can be predicated. |
| 457 | /// By default, this returns true for every instruction with a |
| 458 | /// PredicateOperand. |
| 459 | bool ARMBaseInstrInfo::isPredicable(MachineInstr *MI) const { |
| 460 | const TargetInstrDesc &TID = MI->getDesc(); |
| 461 | if (!TID.isPredicable()) |
| 462 | return false; |
| 463 | |
| 464 | if ((TID.TSFlags & ARMII::DomainMask) == ARMII::DomainNEON) { |
| 465 | ARMFunctionInfo *AFI = |
| 466 | MI->getParent()->getParent()->getInfo<ARMFunctionInfo>(); |
Evan Cheng | d7f0810 | 2009-11-24 08:06:15 +0000 | [diff] [blame] | 467 | return AFI->isThumb2Function(); |
Evan Cheng | ac0869d | 2009-11-21 06:21:52 +0000 | [diff] [blame] | 468 | } |
| 469 | return true; |
| 470 | } |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 471 | |
Chris Lattner | 56856b1 | 2009-12-03 06:58:32 +0000 | [diff] [blame] | 472 | /// FIXME: Works around a gcc miscompilation with -fstrict-aliasing. |
| 473 | DISABLE_INLINE |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 474 | static unsigned getNumJTEntries(const std::vector<MachineJumpTableEntry> &JT, |
Chris Lattner | 56856b1 | 2009-12-03 06:58:32 +0000 | [diff] [blame] | 475 | unsigned JTI); |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 476 | static unsigned getNumJTEntries(const std::vector<MachineJumpTableEntry> &JT, |
| 477 | unsigned JTI) { |
Chris Lattner | 56856b1 | 2009-12-03 06:58:32 +0000 | [diff] [blame] | 478 | assert(JTI < JT.size()); |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 479 | return JT[JTI].MBBs.size(); |
| 480 | } |
| 481 | |
| 482 | /// GetInstSize - Return the size of the specified MachineInstr. |
| 483 | /// |
| 484 | unsigned ARMBaseInstrInfo::GetInstSizeInBytes(const MachineInstr *MI) const { |
| 485 | const MachineBasicBlock &MBB = *MI->getParent(); |
| 486 | const MachineFunction *MF = MBB.getParent(); |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 487 | const MCAsmInfo *MAI = MF->getTarget().getMCAsmInfo(); |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 488 | |
| 489 | // Basic size info comes from the TSFlags field. |
| 490 | const TargetInstrDesc &TID = MI->getDesc(); |
| 491 | unsigned TSFlags = TID.TSFlags; |
| 492 | |
Evan Cheng | a0ee862 | 2009-07-31 22:22:22 +0000 | [diff] [blame] | 493 | unsigned Opc = MI->getOpcode(); |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 494 | switch ((TSFlags & ARMII::SizeMask) >> ARMII::SizeShift) { |
| 495 | default: { |
| 496 | // If this machine instr is an inline asm, measure it. |
| 497 | if (MI->getOpcode() == ARM::INLINEASM) |
Chris Lattner | 33adcfb | 2009-08-22 21:43:10 +0000 | [diff] [blame] | 498 | return getInlineAsmLength(MI->getOperand(0).getSymbolName(), *MAI); |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 499 | if (MI->isLabel()) |
| 500 | return 0; |
Evan Cheng | a0ee862 | 2009-07-31 22:22:22 +0000 | [diff] [blame] | 501 | switch (Opc) { |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 502 | default: |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 503 | llvm_unreachable("Unknown or unset size field for instr!"); |
Chris Lattner | 518bb53 | 2010-02-09 19:54:29 +0000 | [diff] [blame] | 504 | case TargetOpcode::IMPLICIT_DEF: |
| 505 | case TargetOpcode::KILL: |
| 506 | case TargetOpcode::DBG_LABEL: |
| 507 | case TargetOpcode::EH_LABEL: |
Dale Johannesen | 375be77 | 2010-04-07 19:51:44 +0000 | [diff] [blame] | 508 | case TargetOpcode::DBG_VALUE: |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 509 | return 0; |
| 510 | } |
| 511 | break; |
| 512 | } |
Evan Cheng | 7894762 | 2009-07-24 18:20:44 +0000 | [diff] [blame] | 513 | case ARMII::Size8Bytes: return 8; // ARM instruction x 2. |
| 514 | case ARMII::Size4Bytes: return 4; // ARM / Thumb2 instruction. |
| 515 | case ARMII::Size2Bytes: return 2; // Thumb1 instruction. |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 516 | case ARMII::SizeSpecial: { |
Evan Cheng | a0ee862 | 2009-07-31 22:22:22 +0000 | [diff] [blame] | 517 | switch (Opc) { |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 518 | case ARM::CONSTPOOL_ENTRY: |
| 519 | // If this machine instr is a constant pool entry, its size is recorded as |
| 520 | // operand #2. |
| 521 | return MI->getOperand(2).getImm(); |
Jim Grosbach | 5eb1951 | 2010-05-22 01:06:18 +0000 | [diff] [blame] | 522 | case ARM::Int_eh_sjlj_longjmp: |
| 523 | return 16; |
| 524 | case ARM::tInt_eh_sjlj_longjmp: |
| 525 | return 10; |
Evan Cheng | 7894762 | 2009-07-24 18:20:44 +0000 | [diff] [blame] | 526 | case ARM::Int_eh_sjlj_setjmp: |
Jim Grosbach | d100755 | 2010-04-28 20:33:09 +0000 | [diff] [blame] | 527 | case ARM::Int_eh_sjlj_setjmp_nofp: |
Jim Grosbach | 0798edd | 2010-05-27 23:49:24 +0000 | [diff] [blame] | 528 | return 20; |
Jim Grosbach | d122874 | 2009-12-01 18:10:36 +0000 | [diff] [blame] | 529 | case ARM::tInt_eh_sjlj_setjmp: |
Jim Grosbach | 5aa1684 | 2009-08-11 19:42:21 +0000 | [diff] [blame] | 530 | case ARM::t2Int_eh_sjlj_setjmp: |
Jim Grosbach | d100755 | 2010-04-28 20:33:09 +0000 | [diff] [blame] | 531 | case ARM::t2Int_eh_sjlj_setjmp_nofp: |
Jim Grosbach | 0798edd | 2010-05-27 23:49:24 +0000 | [diff] [blame] | 532 | return 12; |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 533 | case ARM::BR_JTr: |
| 534 | case ARM::BR_JTm: |
| 535 | case ARM::BR_JTadd: |
Evan Cheng | a0ee862 | 2009-07-31 22:22:22 +0000 | [diff] [blame] | 536 | case ARM::tBR_JTr: |
Evan Cheng | d26b14c | 2009-07-31 18:28:05 +0000 | [diff] [blame] | 537 | case ARM::t2BR_JT: |
| 538 | case ARM::t2TBB: |
| 539 | case ARM::t2TBH: { |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 540 | // These are jumptable branches, i.e. a branch followed by an inlined |
Evan Cheng | d26b14c | 2009-07-31 18:28:05 +0000 | [diff] [blame] | 541 | // jumptable. The size is 4 + 4 * number of entries. For TBB, each |
| 542 | // entry is one byte; TBH two byte each. |
Evan Cheng | a0ee862 | 2009-07-31 22:22:22 +0000 | [diff] [blame] | 543 | unsigned EntrySize = (Opc == ARM::t2TBB) |
| 544 | ? 1 : ((Opc == ARM::t2TBH) ? 2 : 4); |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 545 | unsigned NumOps = TID.getNumOperands(); |
| 546 | MachineOperand JTOP = |
| 547 | MI->getOperand(NumOps - (TID.isPredicable() ? 3 : 2)); |
| 548 | unsigned JTI = JTOP.getIndex(); |
| 549 | const MachineJumpTableInfo *MJTI = MF->getJumpTableInfo(); |
Chris Lattner | b1e8039 | 2010-01-25 23:22:00 +0000 | [diff] [blame] | 550 | assert(MJTI != 0); |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 551 | const std::vector<MachineJumpTableEntry> &JT = MJTI->getJumpTables(); |
| 552 | assert(JTI < JT.size()); |
| 553 | // Thumb instructions are 2 byte aligned, but JT entries are 4 byte |
| 554 | // 4 aligned. The assembler / linker may add 2 byte padding just before |
| 555 | // the JT entries. The size does not include this padding; the |
| 556 | // constant islands pass does separate bookkeeping for it. |
| 557 | // FIXME: If we know the size of the function is less than (1 << 16) *2 |
| 558 | // bytes, we can use 16-bit entries instead. Then there won't be an |
| 559 | // alignment issue. |
Evan Cheng | 25f7cfc | 2009-08-01 06:13:52 +0000 | [diff] [blame] | 560 | unsigned InstSize = (Opc == ARM::tBR_JTr || Opc == ARM::t2BR_JT) ? 2 : 4; |
| 561 | unsigned NumEntries = getNumJTEntries(JT, JTI); |
| 562 | if (Opc == ARM::t2TBB && (NumEntries & 1)) |
| 563 | // Make sure the instruction that follows TBB is 2-byte aligned. |
| 564 | // FIXME: Constant island pass should insert an "ALIGN" instruction |
| 565 | // instead. |
| 566 | ++NumEntries; |
| 567 | return NumEntries * EntrySize + InstSize; |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 568 | } |
| 569 | default: |
| 570 | // Otherwise, pseudo-instruction sizes are zero. |
| 571 | return 0; |
| 572 | } |
| 573 | } |
| 574 | } |
| 575 | return 0; // Not reached |
| 576 | } |
| 577 | |
| 578 | /// Return true if the instruction is a register to register move and |
| 579 | /// leave the source and dest operands in the passed parameters. |
| 580 | /// |
| 581 | bool |
| 582 | ARMBaseInstrInfo::isMoveInstr(const MachineInstr &MI, |
| 583 | unsigned &SrcReg, unsigned &DstReg, |
| 584 | unsigned& SrcSubIdx, unsigned& DstSubIdx) const { |
Evan Cheng | 68e3c6a | 2009-07-27 00:05:15 +0000 | [diff] [blame] | 585 | switch (MI.getOpcode()) { |
Evan Cheng | dced03f | 2009-07-27 00:24:36 +0000 | [diff] [blame] | 586 | default: break; |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 587 | case ARM::VMOVS: |
Evan Cheng | 68e3c6a | 2009-07-27 00:05:15 +0000 | [diff] [blame] | 588 | case ARM::VMOVD: |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 589 | case ARM::VMOVDneon: |
Evan Cheng | b63387a | 2010-05-06 06:36:08 +0000 | [diff] [blame] | 590 | case ARM::VMOVQ: |
| 591 | case ARM::VMOVQQ : { |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 592 | SrcReg = MI.getOperand(1).getReg(); |
| 593 | DstReg = MI.getOperand(0).getReg(); |
Evan Cheng | b63387a | 2010-05-06 06:36:08 +0000 | [diff] [blame] | 594 | SrcSubIdx = MI.getOperand(1).getSubReg(); |
| 595 | DstSubIdx = MI.getOperand(0).getSubReg(); |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 596 | return true; |
| 597 | } |
Evan Cheng | 68e3c6a | 2009-07-27 00:05:15 +0000 | [diff] [blame] | 598 | case ARM::MOVr: |
| 599 | case ARM::tMOVr: |
| 600 | case ARM::tMOVgpr2tgpr: |
| 601 | case ARM::tMOVtgpr2gpr: |
| 602 | case ARM::tMOVgpr2gpr: |
| 603 | case ARM::t2MOVr: { |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 604 | assert(MI.getDesc().getNumOperands() >= 2 && |
| 605 | MI.getOperand(0).isReg() && |
| 606 | MI.getOperand(1).isReg() && |
| 607 | "Invalid ARM MOV instruction"); |
| 608 | SrcReg = MI.getOperand(1).getReg(); |
| 609 | DstReg = MI.getOperand(0).getReg(); |
Evan Cheng | b63387a | 2010-05-06 06:36:08 +0000 | [diff] [blame] | 610 | SrcSubIdx = MI.getOperand(1).getSubReg(); |
| 611 | DstSubIdx = MI.getOperand(0).getSubReg(); |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 612 | return true; |
| 613 | } |
Evan Cheng | 68e3c6a | 2009-07-27 00:05:15 +0000 | [diff] [blame] | 614 | } |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 615 | |
| 616 | return false; |
| 617 | } |
| 618 | |
Jim Grosbach | 764ab52 | 2009-08-11 15:33:49 +0000 | [diff] [blame] | 619 | unsigned |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 620 | ARMBaseInstrInfo::isLoadFromStackSlot(const MachineInstr *MI, |
| 621 | int &FrameIndex) const { |
Evan Cheng | dced03f | 2009-07-27 00:24:36 +0000 | [diff] [blame] | 622 | switch (MI->getOpcode()) { |
| 623 | default: break; |
| 624 | case ARM::LDR: |
| 625 | case ARM::t2LDRs: // FIXME: don't use t2LDRs to access frame. |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 626 | if (MI->getOperand(1).isFI() && |
| 627 | MI->getOperand(2).isReg() && |
| 628 | MI->getOperand(3).isImm() && |
| 629 | MI->getOperand(2).getReg() == 0 && |
| 630 | MI->getOperand(3).getImm() == 0) { |
| 631 | FrameIndex = MI->getOperand(1).getIndex(); |
| 632 | return MI->getOperand(0).getReg(); |
| 633 | } |
Evan Cheng | dced03f | 2009-07-27 00:24:36 +0000 | [diff] [blame] | 634 | break; |
| 635 | case ARM::t2LDRi12: |
| 636 | case ARM::tRestore: |
David Goodwin | 5ff58b5 | 2009-07-24 00:16:18 +0000 | [diff] [blame] | 637 | if (MI->getOperand(1).isFI() && |
| 638 | MI->getOperand(2).isImm() && |
| 639 | MI->getOperand(2).getImm() == 0) { |
| 640 | FrameIndex = MI->getOperand(1).getIndex(); |
| 641 | return MI->getOperand(0).getReg(); |
| 642 | } |
Evan Cheng | dced03f | 2009-07-27 00:24:36 +0000 | [diff] [blame] | 643 | break; |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 644 | case ARM::VLDRD: |
| 645 | case ARM::VLDRS: |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 646 | if (MI->getOperand(1).isFI() && |
| 647 | MI->getOperand(2).isImm() && |
| 648 | MI->getOperand(2).getImm() == 0) { |
| 649 | FrameIndex = MI->getOperand(1).getIndex(); |
| 650 | return MI->getOperand(0).getReg(); |
| 651 | } |
Evan Cheng | dced03f | 2009-07-27 00:24:36 +0000 | [diff] [blame] | 652 | break; |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 653 | } |
| 654 | |
| 655 | return 0; |
| 656 | } |
| 657 | |
| 658 | unsigned |
| 659 | ARMBaseInstrInfo::isStoreToStackSlot(const MachineInstr *MI, |
| 660 | int &FrameIndex) const { |
Evan Cheng | dced03f | 2009-07-27 00:24:36 +0000 | [diff] [blame] | 661 | switch (MI->getOpcode()) { |
| 662 | default: break; |
| 663 | case ARM::STR: |
| 664 | case ARM::t2STRs: // FIXME: don't use t2STRs to access frame. |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 665 | if (MI->getOperand(1).isFI() && |
| 666 | MI->getOperand(2).isReg() && |
| 667 | MI->getOperand(3).isImm() && |
| 668 | MI->getOperand(2).getReg() == 0 && |
| 669 | MI->getOperand(3).getImm() == 0) { |
| 670 | FrameIndex = MI->getOperand(1).getIndex(); |
| 671 | return MI->getOperand(0).getReg(); |
| 672 | } |
Evan Cheng | dced03f | 2009-07-27 00:24:36 +0000 | [diff] [blame] | 673 | break; |
| 674 | case ARM::t2STRi12: |
| 675 | case ARM::tSpill: |
David Goodwin | 5ff58b5 | 2009-07-24 00:16:18 +0000 | [diff] [blame] | 676 | if (MI->getOperand(1).isFI() && |
| 677 | MI->getOperand(2).isImm() && |
| 678 | MI->getOperand(2).getImm() == 0) { |
| 679 | FrameIndex = MI->getOperand(1).getIndex(); |
| 680 | return MI->getOperand(0).getReg(); |
| 681 | } |
Evan Cheng | dced03f | 2009-07-27 00:24:36 +0000 | [diff] [blame] | 682 | break; |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 683 | case ARM::VSTRD: |
| 684 | case ARM::VSTRS: |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 685 | if (MI->getOperand(1).isFI() && |
| 686 | MI->getOperand(2).isImm() && |
| 687 | MI->getOperand(2).getImm() == 0) { |
| 688 | FrameIndex = MI->getOperand(1).getIndex(); |
| 689 | return MI->getOperand(0).getReg(); |
| 690 | } |
Evan Cheng | dced03f | 2009-07-27 00:24:36 +0000 | [diff] [blame] | 691 | break; |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 692 | } |
| 693 | |
| 694 | return 0; |
| 695 | } |
| 696 | |
| 697 | bool |
| 698 | ARMBaseInstrInfo::copyRegToReg(MachineBasicBlock &MBB, |
| 699 | MachineBasicBlock::iterator I, |
| 700 | unsigned DestReg, unsigned SrcReg, |
| 701 | const TargetRegisterClass *DestRC, |
Dan Gohman | 34dcc6f | 2010-05-06 20:33:48 +0000 | [diff] [blame] | 702 | const TargetRegisterClass *SrcRC, |
| 703 | DebugLoc DL) const { |
Bob Wilson | 1665b0a | 2010-02-16 17:24:15 +0000 | [diff] [blame] | 704 | // tGPR is used sometimes in ARM instructions that need to avoid using |
| 705 | // certain registers. Just treat it as GPR here. |
| 706 | if (DestRC == ARM::tGPRRegisterClass) |
| 707 | DestRC = ARM::GPRRegisterClass; |
| 708 | if (SrcRC == ARM::tGPRRegisterClass) |
| 709 | SrcRC = ARM::GPRRegisterClass; |
| 710 | |
Anton Korobeynikov | 6755d97 | 2010-03-18 22:35:02 +0000 | [diff] [blame] | 711 | // Allow DPR / DPR_VFP2 / DPR_8 cross-class copies. |
| 712 | if (DestRC == ARM::DPR_8RegisterClass) |
| 713 | DestRC = ARM::DPR_VFP2RegisterClass; |
| 714 | if (SrcRC == ARM::DPR_8RegisterClass) |
| 715 | SrcRC = ARM::DPR_VFP2RegisterClass; |
Evan Cheng | b4db6a4 | 2009-11-03 05:51:39 +0000 | [diff] [blame] | 716 | |
Anton Korobeynikov | 6755d97 | 2010-03-18 22:35:02 +0000 | [diff] [blame] | 717 | // Allow QPR / QPR_VFP2 / QPR_8 cross-class copies. |
| 718 | if (DestRC == ARM::QPR_VFP2RegisterClass || |
| 719 | DestRC == ARM::QPR_8RegisterClass) |
| 720 | DestRC = ARM::QPRRegisterClass; |
| 721 | if (SrcRC == ARM::QPR_VFP2RegisterClass || |
| 722 | SrcRC == ARM::QPR_8RegisterClass) |
| 723 | SrcRC = ARM::QPRRegisterClass; |
| 724 | |
Evan Cheng | 22c687b | 2010-05-14 02:13:41 +0000 | [diff] [blame] | 725 | // Allow QQPR / QQPR_VFP2 cross-class copies. |
| 726 | if (DestRC == ARM::QQPR_VFP2RegisterClass) |
Evan Cheng | b63387a | 2010-05-06 06:36:08 +0000 | [diff] [blame] | 727 | DestRC = ARM::QQPRRegisterClass; |
Evan Cheng | 22c687b | 2010-05-14 02:13:41 +0000 | [diff] [blame] | 728 | if (SrcRC == ARM::QQPR_VFP2RegisterClass) |
Evan Cheng | b63387a | 2010-05-06 06:36:08 +0000 | [diff] [blame] | 729 | SrcRC = ARM::QQPRRegisterClass; |
| 730 | |
Anton Korobeynikov | 6755d97 | 2010-03-18 22:35:02 +0000 | [diff] [blame] | 731 | // Disallow copies of unequal sizes. |
| 732 | if (DestRC != SrcRC && DestRC->getSize() != SrcRC->getSize()) |
| 733 | return false; |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 734 | |
David Goodwin | 7bfdca0 | 2009-08-05 21:02:22 +0000 | [diff] [blame] | 735 | if (DestRC == ARM::GPRRegisterClass) { |
Anton Korobeynikov | 6755d97 | 2010-03-18 22:35:02 +0000 | [diff] [blame] | 736 | if (SrcRC == ARM::SPRRegisterClass) |
| 737 | AddDefaultPred(BuildMI(MBB, I, DL, get(ARM::VMOVRS), DestReg) |
| 738 | .addReg(SrcReg)); |
| 739 | else |
| 740 | AddDefaultCC(AddDefaultPred(BuildMI(MBB, I, DL, get(ARM::MOVr), |
| 741 | DestReg).addReg(SrcReg))); |
David Goodwin | 7bfdca0 | 2009-08-05 21:02:22 +0000 | [diff] [blame] | 742 | } else { |
Anton Korobeynikov | 6755d97 | 2010-03-18 22:35:02 +0000 | [diff] [blame] | 743 | unsigned Opc; |
| 744 | |
| 745 | if (DestRC == ARM::SPRRegisterClass) |
| 746 | Opc = (SrcRC == ARM::GPRRegisterClass ? ARM::VMOVSR : ARM::VMOVS); |
| 747 | else if (DestRC == ARM::DPRRegisterClass) |
| 748 | Opc = ARM::VMOVD; |
| 749 | else if (DestRC == ARM::DPR_VFP2RegisterClass || |
| 750 | SrcRC == ARM::DPR_VFP2RegisterClass) |
| 751 | // Always use neon reg-reg move if source or dest is NEON-only regclass. |
| 752 | Opc = ARM::VMOVDneon; |
| 753 | else if (DestRC == ARM::QPRRegisterClass) |
| 754 | Opc = ARM::VMOVQ; |
Evan Cheng | b63387a | 2010-05-06 06:36:08 +0000 | [diff] [blame] | 755 | else if (DestRC == ARM::QQPRRegisterClass) |
| 756 | Opc = ARM::VMOVQQ; |
Evan Cheng | 22c687b | 2010-05-14 02:13:41 +0000 | [diff] [blame] | 757 | else if (DestRC == ARM::QQQQPRRegisterClass) |
| 758 | Opc = ARM::VMOVQQQQ; |
Anton Korobeynikov | 6755d97 | 2010-03-18 22:35:02 +0000 | [diff] [blame] | 759 | else |
| 760 | return false; |
| 761 | |
Evan Cheng | b63387a | 2010-05-06 06:36:08 +0000 | [diff] [blame] | 762 | AddDefaultPred(BuildMI(MBB, I, DL, get(Opc), DestReg).addReg(SrcReg)); |
David Goodwin | 7bfdca0 | 2009-08-05 21:02:22 +0000 | [diff] [blame] | 763 | } |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 764 | |
| 765 | return true; |
| 766 | } |
| 767 | |
Evan Cheng | c10b5af | 2010-05-07 00:24:52 +0000 | [diff] [blame] | 768 | static const |
| 769 | MachineInstrBuilder &AddDReg(MachineInstrBuilder &MIB, |
| 770 | unsigned Reg, unsigned SubIdx, unsigned State, |
| 771 | const TargetRegisterInfo *TRI) { |
| 772 | if (!SubIdx) |
| 773 | return MIB.addReg(Reg, State); |
| 774 | |
| 775 | if (TargetRegisterInfo::isPhysicalRegister(Reg)) |
| 776 | return MIB.addReg(TRI->getSubReg(Reg, SubIdx), State); |
| 777 | return MIB.addReg(Reg, State, SubIdx); |
| 778 | } |
| 779 | |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 780 | void ARMBaseInstrInfo:: |
| 781 | storeRegToStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator I, |
| 782 | unsigned SrcReg, bool isKill, int FI, |
Evan Cheng | 746ad69 | 2010-05-06 19:06:44 +0000 | [diff] [blame] | 783 | const TargetRegisterClass *RC, |
| 784 | const TargetRegisterInfo *TRI) const { |
Chris Lattner | c7f3ace | 2010-04-02 20:16:16 +0000 | [diff] [blame] | 785 | DebugLoc DL; |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 786 | if (I != MBB.end()) DL = I->getDebugLoc(); |
Anton Korobeynikov | 249fb33 | 2009-10-07 00:06:35 +0000 | [diff] [blame] | 787 | MachineFunction &MF = *MBB.getParent(); |
| 788 | MachineFrameInfo &MFI = *MF.getFrameInfo(); |
Jim Grosbach | 31bc849 | 2009-11-08 00:27:19 +0000 | [diff] [blame] | 789 | unsigned Align = MFI.getObjectAlignment(FI); |
Anton Korobeynikov | 249fb33 | 2009-10-07 00:06:35 +0000 | [diff] [blame] | 790 | |
| 791 | MachineMemOperand *MMO = |
Evan Cheng | ff89dcb | 2009-10-18 18:16:27 +0000 | [diff] [blame] | 792 | MF.getMachineMemOperand(PseudoSourceValue::getFixedStack(FI), |
Anton Korobeynikov | 249fb33 | 2009-10-07 00:06:35 +0000 | [diff] [blame] | 793 | MachineMemOperand::MOStore, 0, |
| 794 | MFI.getObjectSize(FI), |
Jim Grosbach | 31bc849 | 2009-11-08 00:27:19 +0000 | [diff] [blame] | 795 | Align); |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 796 | |
Bob Wilson | 0eb0c74 | 2010-02-16 22:01:59 +0000 | [diff] [blame] | 797 | // tGPR is used sometimes in ARM instructions that need to avoid using |
| 798 | // certain registers. Just treat it as GPR here. |
| 799 | if (RC == ARM::tGPRRegisterClass) |
| 800 | RC = ARM::GPRRegisterClass; |
| 801 | |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 802 | if (RC == ARM::GPRRegisterClass) { |
Evan Cheng | 5732ca0 | 2009-07-27 03:14:20 +0000 | [diff] [blame] | 803 | AddDefaultPred(BuildMI(MBB, I, DL, get(ARM::STR)) |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 804 | .addReg(SrcReg, getKillRegState(isKill)) |
Anton Korobeynikov | 249fb33 | 2009-10-07 00:06:35 +0000 | [diff] [blame] | 805 | .addFrameIndex(FI).addReg(0).addImm(0).addMemOperand(MMO)); |
Evan Cheng | d31c549 | 2010-05-06 01:34:11 +0000 | [diff] [blame] | 806 | } else if (RC == ARM::SPRRegisterClass) { |
| 807 | AddDefaultPred(BuildMI(MBB, I, DL, get(ARM::VSTRS)) |
| 808 | .addReg(SrcReg, getKillRegState(isKill)) |
| 809 | .addFrameIndex(FI).addImm(0).addMemOperand(MMO)); |
Anton Korobeynikov | 6ca0b9e | 2009-09-08 15:22:32 +0000 | [diff] [blame] | 810 | } else if (RC == ARM::DPRRegisterClass || |
| 811 | RC == ARM::DPR_VFP2RegisterClass || |
| 812 | RC == ARM::DPR_8RegisterClass) { |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 813 | AddDefaultPred(BuildMI(MBB, I, DL, get(ARM::VSTRD)) |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 814 | .addReg(SrcReg, getKillRegState(isKill)) |
Anton Korobeynikov | 249fb33 | 2009-10-07 00:06:35 +0000 | [diff] [blame] | 815 | .addFrameIndex(FI).addImm(0).addMemOperand(MMO)); |
Evan Cheng | b63387a | 2010-05-06 06:36:08 +0000 | [diff] [blame] | 816 | } else if (RC == ARM::QPRRegisterClass || |
| 817 | RC == ARM::QPR_VFP2RegisterClass || |
| 818 | RC == ARM::QPR_8RegisterClass) { |
Anton Korobeynikov | baf3108 | 2009-08-08 13:35:48 +0000 | [diff] [blame] | 819 | // FIXME: Neon instructions should support predicates |
Evan Cheng | b63387a | 2010-05-06 06:36:08 +0000 | [diff] [blame] | 820 | if (Align >= 16 && getRegisterInfo().canRealignStack(MF)) { |
Evan Cheng | 69b9f98 | 2010-05-13 01:12:06 +0000 | [diff] [blame] | 821 | AddDefaultPred(BuildMI(MBB, I, DL, get(ARM::VST1q)) |
| 822 | .addFrameIndex(FI).addImm(128) |
| 823 | .addReg(SrcReg, getKillRegState(isKill)) |
| 824 | .addMemOperand(MMO)); |
Jim Grosbach | 31bc849 | 2009-11-08 00:27:19 +0000 | [diff] [blame] | 825 | } else { |
Evan Cheng | 69b9f98 | 2010-05-13 01:12:06 +0000 | [diff] [blame] | 826 | AddDefaultPred(BuildMI(MBB, I, DL, get(ARM::VSTMQ)) |
| 827 | .addReg(SrcReg, getKillRegState(isKill)) |
| 828 | .addFrameIndex(FI) |
| 829 | .addImm(ARM_AM::getAM5Opc(ARM_AM::ia, 4)) |
| 830 | .addMemOperand(MMO)); |
Jim Grosbach | 31bc849 | 2009-11-08 00:27:19 +0000 | [diff] [blame] | 831 | } |
Evan Cheng | 22c687b | 2010-05-14 02:13:41 +0000 | [diff] [blame] | 832 | } else if (RC == ARM::QQPRRegisterClass || RC == ARM::QQPR_VFP2RegisterClass){ |
Evan Cheng | 435d499 | 2010-05-07 02:04:02 +0000 | [diff] [blame] | 833 | if (Align >= 16 && getRegisterInfo().canRealignStack(MF)) { |
Evan Cheng | 22c687b | 2010-05-14 02:13:41 +0000 | [diff] [blame] | 834 | // FIXME: It's possible to only store part of the QQ register if the |
| 835 | // spilled def has a sub-register index. |
Evan Cheng | 435d499 | 2010-05-07 02:04:02 +0000 | [diff] [blame] | 836 | MachineInstrBuilder MIB = BuildMI(MBB, I, DL, get(ARM::VST2q32)) |
| 837 | .addFrameIndex(FI).addImm(128); |
Jakob Stoklund Olesen | 558661d | 2010-05-24 16:54:32 +0000 | [diff] [blame] | 838 | MIB = AddDReg(MIB, SrcReg, ARM::dsub_0, getKillRegState(isKill), TRI); |
| 839 | MIB = AddDReg(MIB, SrcReg, ARM::dsub_1, 0, TRI); |
| 840 | MIB = AddDReg(MIB, SrcReg, ARM::dsub_2, 0, TRI); |
| 841 | MIB = AddDReg(MIB, SrcReg, ARM::dsub_3, 0, TRI); |
Evan Cheng | 435d499 | 2010-05-07 02:04:02 +0000 | [diff] [blame] | 842 | AddDefaultPred(MIB.addMemOperand(MMO)); |
| 843 | } else { |
| 844 | MachineInstrBuilder MIB = |
| 845 | AddDefaultPred(BuildMI(MBB, I, DL, get(ARM::VSTMD)) |
| 846 | .addFrameIndex(FI) |
| 847 | .addImm(ARM_AM::getAM5Opc(ARM_AM::ia, 4))) |
| 848 | .addMemOperand(MMO); |
Jakob Stoklund Olesen | 558661d | 2010-05-24 16:54:32 +0000 | [diff] [blame] | 849 | MIB = AddDReg(MIB, SrcReg, ARM::dsub_0, getKillRegState(isKill), TRI); |
| 850 | MIB = AddDReg(MIB, SrcReg, ARM::dsub_1, 0, TRI); |
| 851 | MIB = AddDReg(MIB, SrcReg, ARM::dsub_2, 0, TRI); |
| 852 | AddDReg(MIB, SrcReg, ARM::dsub_3, 0, TRI); |
Evan Cheng | 435d499 | 2010-05-07 02:04:02 +0000 | [diff] [blame] | 853 | } |
Evan Cheng | 22c687b | 2010-05-14 02:13:41 +0000 | [diff] [blame] | 854 | } else { |
| 855 | assert(RC == ARM::QQQQPRRegisterClass && "Unknown regclass!"); |
| 856 | MachineInstrBuilder MIB = |
| 857 | AddDefaultPred(BuildMI(MBB, I, DL, get(ARM::VSTMD)) |
| 858 | .addFrameIndex(FI) |
| 859 | .addImm(ARM_AM::getAM5Opc(ARM_AM::ia, 4))) |
| 860 | .addMemOperand(MMO); |
Jakob Stoklund Olesen | 558661d | 2010-05-24 16:54:32 +0000 | [diff] [blame] | 861 | MIB = AddDReg(MIB, SrcReg, ARM::dsub_0, getKillRegState(isKill), TRI); |
| 862 | MIB = AddDReg(MIB, SrcReg, ARM::dsub_1, 0, TRI); |
| 863 | MIB = AddDReg(MIB, SrcReg, ARM::dsub_2, 0, TRI); |
| 864 | MIB = AddDReg(MIB, SrcReg, ARM::dsub_3, 0, TRI); |
| 865 | MIB = AddDReg(MIB, SrcReg, ARM::dsub_4, 0, TRI); |
| 866 | MIB = AddDReg(MIB, SrcReg, ARM::dsub_5, 0, TRI); |
| 867 | MIB = AddDReg(MIB, SrcReg, ARM::dsub_6, 0, TRI); |
| 868 | AddDReg(MIB, SrcReg, ARM::dsub_7, 0, TRI); |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 869 | } |
| 870 | } |
| 871 | |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 872 | void ARMBaseInstrInfo:: |
| 873 | loadRegFromStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator I, |
| 874 | unsigned DestReg, int FI, |
Evan Cheng | 746ad69 | 2010-05-06 19:06:44 +0000 | [diff] [blame] | 875 | const TargetRegisterClass *RC, |
| 876 | const TargetRegisterInfo *TRI) const { |
Chris Lattner | c7f3ace | 2010-04-02 20:16:16 +0000 | [diff] [blame] | 877 | DebugLoc DL; |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 878 | if (I != MBB.end()) DL = I->getDebugLoc(); |
Anton Korobeynikov | 249fb33 | 2009-10-07 00:06:35 +0000 | [diff] [blame] | 879 | MachineFunction &MF = *MBB.getParent(); |
| 880 | MachineFrameInfo &MFI = *MF.getFrameInfo(); |
Jim Grosbach | 31bc849 | 2009-11-08 00:27:19 +0000 | [diff] [blame] | 881 | unsigned Align = MFI.getObjectAlignment(FI); |
Anton Korobeynikov | 249fb33 | 2009-10-07 00:06:35 +0000 | [diff] [blame] | 882 | MachineMemOperand *MMO = |
Evan Cheng | ff89dcb | 2009-10-18 18:16:27 +0000 | [diff] [blame] | 883 | MF.getMachineMemOperand(PseudoSourceValue::getFixedStack(FI), |
Anton Korobeynikov | 249fb33 | 2009-10-07 00:06:35 +0000 | [diff] [blame] | 884 | MachineMemOperand::MOLoad, 0, |
| 885 | MFI.getObjectSize(FI), |
Jim Grosbach | 31bc849 | 2009-11-08 00:27:19 +0000 | [diff] [blame] | 886 | Align); |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 887 | |
Bob Wilson | 0eb0c74 | 2010-02-16 22:01:59 +0000 | [diff] [blame] | 888 | // tGPR is used sometimes in ARM instructions that need to avoid using |
| 889 | // certain registers. Just treat it as GPR here. |
| 890 | if (RC == ARM::tGPRRegisterClass) |
| 891 | RC = ARM::GPRRegisterClass; |
| 892 | |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 893 | if (RC == ARM::GPRRegisterClass) { |
Evan Cheng | 5732ca0 | 2009-07-27 03:14:20 +0000 | [diff] [blame] | 894 | AddDefaultPred(BuildMI(MBB, I, DL, get(ARM::LDR), DestReg) |
Anton Korobeynikov | 249fb33 | 2009-10-07 00:06:35 +0000 | [diff] [blame] | 895 | .addFrameIndex(FI).addReg(0).addImm(0).addMemOperand(MMO)); |
Evan Cheng | d31c549 | 2010-05-06 01:34:11 +0000 | [diff] [blame] | 896 | } else if (RC == ARM::SPRRegisterClass) { |
| 897 | AddDefaultPred(BuildMI(MBB, I, DL, get(ARM::VLDRS), DestReg) |
| 898 | .addFrameIndex(FI).addImm(0).addMemOperand(MMO)); |
Anton Korobeynikov | 6ca0b9e | 2009-09-08 15:22:32 +0000 | [diff] [blame] | 899 | } else if (RC == ARM::DPRRegisterClass || |
| 900 | RC == ARM::DPR_VFP2RegisterClass || |
| 901 | RC == ARM::DPR_8RegisterClass) { |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 902 | AddDefaultPred(BuildMI(MBB, I, DL, get(ARM::VLDRD), DestReg) |
Anton Korobeynikov | 249fb33 | 2009-10-07 00:06:35 +0000 | [diff] [blame] | 903 | .addFrameIndex(FI).addImm(0).addMemOperand(MMO)); |
Evan Cheng | b63387a | 2010-05-06 06:36:08 +0000 | [diff] [blame] | 904 | } else if (RC == ARM::QPRRegisterClass || |
| 905 | RC == ARM::QPR_VFP2RegisterClass || |
| 906 | RC == ARM::QPR_8RegisterClass) { |
| 907 | if (Align >= 16 && getRegisterInfo().canRealignStack(MF)) { |
Evan Cheng | 69b9f98 | 2010-05-13 01:12:06 +0000 | [diff] [blame] | 908 | AddDefaultPred(BuildMI(MBB, I, DL, get(ARM::VLD1q), DestReg) |
| 909 | .addFrameIndex(FI).addImm(128) |
| 910 | .addMemOperand(MMO)); |
Jim Grosbach | 31bc849 | 2009-11-08 00:27:19 +0000 | [diff] [blame] | 911 | } else { |
Evan Cheng | 69b9f98 | 2010-05-13 01:12:06 +0000 | [diff] [blame] | 912 | AddDefaultPred(BuildMI(MBB, I, DL, get(ARM::VLDMQ), DestReg) |
| 913 | .addFrameIndex(FI) |
| 914 | .addImm(ARM_AM::getAM5Opc(ARM_AM::ia, 4)) |
| 915 | .addMemOperand(MMO)); |
Jim Grosbach | 31bc849 | 2009-11-08 00:27:19 +0000 | [diff] [blame] | 916 | } |
Evan Cheng | 22c687b | 2010-05-14 02:13:41 +0000 | [diff] [blame] | 917 | } else if (RC == ARM::QQPRRegisterClass || RC == ARM::QQPR_VFP2RegisterClass){ |
Evan Cheng | 435d499 | 2010-05-07 02:04:02 +0000 | [diff] [blame] | 918 | if (Align >= 16 && getRegisterInfo().canRealignStack(MF)) { |
| 919 | MachineInstrBuilder MIB = BuildMI(MBB, I, DL, get(ARM::VLD2q32)); |
Jakob Stoklund Olesen | 558661d | 2010-05-24 16:54:32 +0000 | [diff] [blame] | 920 | MIB = AddDReg(MIB, DestReg, ARM::dsub_0, RegState::Define, TRI); |
| 921 | MIB = AddDReg(MIB, DestReg, ARM::dsub_1, RegState::Define, TRI); |
| 922 | MIB = AddDReg(MIB, DestReg, ARM::dsub_2, RegState::Define, TRI); |
| 923 | MIB = AddDReg(MIB, DestReg, ARM::dsub_3, RegState::Define, TRI); |
Evan Cheng | 435d499 | 2010-05-07 02:04:02 +0000 | [diff] [blame] | 924 | AddDefaultPred(MIB.addFrameIndex(FI).addImm(128).addMemOperand(MMO)); |
| 925 | } else { |
| 926 | MachineInstrBuilder MIB = |
| 927 | AddDefaultPred(BuildMI(MBB, I, DL, get(ARM::VLDMD)) |
| 928 | .addFrameIndex(FI) |
| 929 | .addImm(ARM_AM::getAM5Opc(ARM_AM::ia, 4))) |
| 930 | .addMemOperand(MMO); |
Jakob Stoklund Olesen | 558661d | 2010-05-24 16:54:32 +0000 | [diff] [blame] | 931 | MIB = AddDReg(MIB, DestReg, ARM::dsub_0, RegState::Define, TRI); |
| 932 | MIB = AddDReg(MIB, DestReg, ARM::dsub_1, RegState::Define, TRI); |
| 933 | MIB = AddDReg(MIB, DestReg, ARM::dsub_2, RegState::Define, TRI); |
| 934 | AddDReg(MIB, DestReg, ARM::dsub_3, RegState::Define, TRI); |
Evan Cheng | 435d499 | 2010-05-07 02:04:02 +0000 | [diff] [blame] | 935 | } |
Evan Cheng | 22c687b | 2010-05-14 02:13:41 +0000 | [diff] [blame] | 936 | } else { |
| 937 | assert(RC == ARM::QQQQPRRegisterClass && "Unknown regclass!"); |
| 938 | MachineInstrBuilder MIB = |
| 939 | AddDefaultPred(BuildMI(MBB, I, DL, get(ARM::VLDMD)) |
| 940 | .addFrameIndex(FI) |
| 941 | .addImm(ARM_AM::getAM5Opc(ARM_AM::ia, 4))) |
| 942 | .addMemOperand(MMO); |
Jakob Stoklund Olesen | 558661d | 2010-05-24 16:54:32 +0000 | [diff] [blame] | 943 | MIB = AddDReg(MIB, DestReg, ARM::dsub_0, RegState::Define, TRI); |
| 944 | MIB = AddDReg(MIB, DestReg, ARM::dsub_1, RegState::Define, TRI); |
| 945 | MIB = AddDReg(MIB, DestReg, ARM::dsub_2, RegState::Define, TRI); |
| 946 | MIB = AddDReg(MIB, DestReg, ARM::dsub_3, RegState::Define, TRI); |
| 947 | MIB = AddDReg(MIB, DestReg, ARM::dsub_4, RegState::Define, TRI); |
| 948 | MIB = AddDReg(MIB, DestReg, ARM::dsub_5, RegState::Define, TRI); |
| 949 | MIB = AddDReg(MIB, DestReg, ARM::dsub_6, RegState::Define, TRI); |
| 950 | AddDReg(MIB, DestReg, ARM::dsub_7, RegState::Define, TRI); |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 951 | } |
| 952 | } |
| 953 | |
Evan Cheng | 62b5065 | 2010-04-26 07:39:25 +0000 | [diff] [blame] | 954 | MachineInstr* |
| 955 | ARMBaseInstrInfo::emitFrameIndexDebugValue(MachineFunction &MF, |
Evan Cheng | 8601a3d | 2010-04-29 01:13:30 +0000 | [diff] [blame] | 956 | int FrameIx, uint64_t Offset, |
Evan Cheng | 62b5065 | 2010-04-26 07:39:25 +0000 | [diff] [blame] | 957 | const MDNode *MDPtr, |
| 958 | DebugLoc DL) const { |
| 959 | MachineInstrBuilder MIB = BuildMI(MF, DL, get(ARM::DBG_VALUE)) |
| 960 | .addFrameIndex(FrameIx).addImm(0).addImm(Offset).addMetadata(MDPtr); |
| 961 | return &*MIB; |
| 962 | } |
| 963 | |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 964 | MachineInstr *ARMBaseInstrInfo:: |
| 965 | foldMemoryOperandImpl(MachineFunction &MF, MachineInstr *MI, |
| 966 | const SmallVectorImpl<unsigned> &Ops, int FI) const { |
| 967 | if (Ops.size() != 1) return NULL; |
| 968 | |
| 969 | unsigned OpNum = Ops[0]; |
| 970 | unsigned Opc = MI->getOpcode(); |
| 971 | MachineInstr *NewMI = NULL; |
Evan Cheng | 19068ba | 2009-08-10 06:32:05 +0000 | [diff] [blame] | 972 | if (Opc == ARM::MOVr || Opc == ARM::t2MOVr) { |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 973 | // If it is updating CPSR, then it cannot be folded. |
Evan Cheng | 19068ba | 2009-08-10 06:32:05 +0000 | [diff] [blame] | 974 | if (MI->getOperand(4).getReg() == ARM::CPSR && !MI->getOperand(4).isDead()) |
| 975 | return NULL; |
| 976 | unsigned Pred = MI->getOperand(2).getImm(); |
| 977 | unsigned PredReg = MI->getOperand(3).getReg(); |
| 978 | if (OpNum == 0) { // move -> store |
| 979 | unsigned SrcReg = MI->getOperand(1).getReg(); |
Evan Cheng | ed3ad21 | 2009-10-25 07:52:27 +0000 | [diff] [blame] | 980 | unsigned SrcSubReg = MI->getOperand(1).getSubReg(); |
Evan Cheng | 19068ba | 2009-08-10 06:32:05 +0000 | [diff] [blame] | 981 | bool isKill = MI->getOperand(1).isKill(); |
| 982 | bool isUndef = MI->getOperand(1).isUndef(); |
| 983 | if (Opc == ARM::MOVr) |
| 984 | NewMI = BuildMI(MF, MI->getDebugLoc(), get(ARM::STR)) |
Evan Cheng | ed3ad21 | 2009-10-25 07:52:27 +0000 | [diff] [blame] | 985 | .addReg(SrcReg, |
| 986 | getKillRegState(isKill) | getUndefRegState(isUndef), |
| 987 | SrcSubReg) |
Evan Cheng | 19068ba | 2009-08-10 06:32:05 +0000 | [diff] [blame] | 988 | .addFrameIndex(FI).addReg(0).addImm(0).addImm(Pred).addReg(PredReg); |
| 989 | else // ARM::t2MOVr |
| 990 | NewMI = BuildMI(MF, MI->getDebugLoc(), get(ARM::t2STRi12)) |
Evan Cheng | ed3ad21 | 2009-10-25 07:52:27 +0000 | [diff] [blame] | 991 | .addReg(SrcReg, |
| 992 | getKillRegState(isKill) | getUndefRegState(isUndef), |
| 993 | SrcSubReg) |
Evan Cheng | 19068ba | 2009-08-10 06:32:05 +0000 | [diff] [blame] | 994 | .addFrameIndex(FI).addImm(0).addImm(Pred).addReg(PredReg); |
| 995 | } else { // move -> load |
| 996 | unsigned DstReg = MI->getOperand(0).getReg(); |
Evan Cheng | ed3ad21 | 2009-10-25 07:52:27 +0000 | [diff] [blame] | 997 | unsigned DstSubReg = MI->getOperand(0).getSubReg(); |
Evan Cheng | 19068ba | 2009-08-10 06:32:05 +0000 | [diff] [blame] | 998 | bool isDead = MI->getOperand(0).isDead(); |
| 999 | bool isUndef = MI->getOperand(0).isUndef(); |
| 1000 | if (Opc == ARM::MOVr) |
| 1001 | NewMI = BuildMI(MF, MI->getDebugLoc(), get(ARM::LDR)) |
| 1002 | .addReg(DstReg, |
| 1003 | RegState::Define | |
| 1004 | getDeadRegState(isDead) | |
Evan Cheng | ed3ad21 | 2009-10-25 07:52:27 +0000 | [diff] [blame] | 1005 | getUndefRegState(isUndef), DstSubReg) |
Evan Cheng | 19068ba | 2009-08-10 06:32:05 +0000 | [diff] [blame] | 1006 | .addFrameIndex(FI).addReg(0).addImm(0).addImm(Pred).addReg(PredReg); |
| 1007 | else // ARM::t2MOVr |
| 1008 | NewMI = BuildMI(MF, MI->getDebugLoc(), get(ARM::t2LDRi12)) |
| 1009 | .addReg(DstReg, |
| 1010 | RegState::Define | |
| 1011 | getDeadRegState(isDead) | |
Evan Cheng | ed3ad21 | 2009-10-25 07:52:27 +0000 | [diff] [blame] | 1012 | getUndefRegState(isUndef), DstSubReg) |
Evan Cheng | 19068ba | 2009-08-10 06:32:05 +0000 | [diff] [blame] | 1013 | .addFrameIndex(FI).addImm(0).addImm(Pred).addReg(PredReg); |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 1014 | } |
Evan Cheng | 19068ba | 2009-08-10 06:32:05 +0000 | [diff] [blame] | 1015 | } else if (Opc == ARM::tMOVgpr2gpr || |
| 1016 | Opc == ARM::tMOVtgpr2gpr || |
| 1017 | Opc == ARM::tMOVgpr2tgpr) { |
| 1018 | if (OpNum == 0) { // move -> store |
| 1019 | unsigned SrcReg = MI->getOperand(1).getReg(); |
Evan Cheng | ed3ad21 | 2009-10-25 07:52:27 +0000 | [diff] [blame] | 1020 | unsigned SrcSubReg = MI->getOperand(1).getSubReg(); |
Evan Cheng | 19068ba | 2009-08-10 06:32:05 +0000 | [diff] [blame] | 1021 | bool isKill = MI->getOperand(1).isKill(); |
| 1022 | bool isUndef = MI->getOperand(1).isUndef(); |
| 1023 | NewMI = BuildMI(MF, MI->getDebugLoc(), get(ARM::t2STRi12)) |
Evan Cheng | ed3ad21 | 2009-10-25 07:52:27 +0000 | [diff] [blame] | 1024 | .addReg(SrcReg, |
| 1025 | getKillRegState(isKill) | getUndefRegState(isUndef), |
| 1026 | SrcSubReg) |
Evan Cheng | 19068ba | 2009-08-10 06:32:05 +0000 | [diff] [blame] | 1027 | .addFrameIndex(FI).addImm(0).addImm(ARMCC::AL).addReg(0); |
| 1028 | } else { // move -> load |
| 1029 | unsigned DstReg = MI->getOperand(0).getReg(); |
Evan Cheng | ed3ad21 | 2009-10-25 07:52:27 +0000 | [diff] [blame] | 1030 | unsigned DstSubReg = MI->getOperand(0).getSubReg(); |
Evan Cheng | 19068ba | 2009-08-10 06:32:05 +0000 | [diff] [blame] | 1031 | bool isDead = MI->getOperand(0).isDead(); |
| 1032 | bool isUndef = MI->getOperand(0).isUndef(); |
| 1033 | NewMI = BuildMI(MF, MI->getDebugLoc(), get(ARM::t2LDRi12)) |
| 1034 | .addReg(DstReg, |
| 1035 | RegState::Define | |
| 1036 | getDeadRegState(isDead) | |
Evan Cheng | ed3ad21 | 2009-10-25 07:52:27 +0000 | [diff] [blame] | 1037 | getUndefRegState(isUndef), |
| 1038 | DstSubReg) |
Evan Cheng | 19068ba | 2009-08-10 06:32:05 +0000 | [diff] [blame] | 1039 | .addFrameIndex(FI).addImm(0).addImm(ARMCC::AL).addReg(0); |
| 1040 | } |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 1041 | } else if (Opc == ARM::VMOVS) { |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 1042 | unsigned Pred = MI->getOperand(2).getImm(); |
| 1043 | unsigned PredReg = MI->getOperand(3).getReg(); |
| 1044 | if (OpNum == 0) { // move -> store |
| 1045 | unsigned SrcReg = MI->getOperand(1).getReg(); |
Evan Cheng | ed3ad21 | 2009-10-25 07:52:27 +0000 | [diff] [blame] | 1046 | unsigned SrcSubReg = MI->getOperand(1).getSubReg(); |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 1047 | bool isKill = MI->getOperand(1).isKill(); |
| 1048 | bool isUndef = MI->getOperand(1).isUndef(); |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 1049 | NewMI = BuildMI(MF, MI->getDebugLoc(), get(ARM::VSTRS)) |
Evan Cheng | ed3ad21 | 2009-10-25 07:52:27 +0000 | [diff] [blame] | 1050 | .addReg(SrcReg, getKillRegState(isKill) | getUndefRegState(isUndef), |
| 1051 | SrcSubReg) |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 1052 | .addFrameIndex(FI) |
| 1053 | .addImm(0).addImm(Pred).addReg(PredReg); |
| 1054 | } else { // move -> load |
| 1055 | unsigned DstReg = MI->getOperand(0).getReg(); |
Evan Cheng | ed3ad21 | 2009-10-25 07:52:27 +0000 | [diff] [blame] | 1056 | unsigned DstSubReg = MI->getOperand(0).getSubReg(); |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 1057 | bool isDead = MI->getOperand(0).isDead(); |
| 1058 | bool isUndef = MI->getOperand(0).isUndef(); |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 1059 | NewMI = BuildMI(MF, MI->getDebugLoc(), get(ARM::VLDRS)) |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 1060 | .addReg(DstReg, |
| 1061 | RegState::Define | |
| 1062 | getDeadRegState(isDead) | |
Evan Cheng | ed3ad21 | 2009-10-25 07:52:27 +0000 | [diff] [blame] | 1063 | getUndefRegState(isUndef), |
| 1064 | DstSubReg) |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 1065 | .addFrameIndex(FI).addImm(0).addImm(Pred).addReg(PredReg); |
| 1066 | } |
Evan Cheng | 69b9f98 | 2010-05-13 01:12:06 +0000 | [diff] [blame] | 1067 | } else if (Opc == ARM::VMOVD || Opc == ARM::VMOVDneon) { |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 1068 | unsigned Pred = MI->getOperand(2).getImm(); |
| 1069 | unsigned PredReg = MI->getOperand(3).getReg(); |
| 1070 | if (OpNum == 0) { // move -> store |
| 1071 | unsigned SrcReg = MI->getOperand(1).getReg(); |
Evan Cheng | ed3ad21 | 2009-10-25 07:52:27 +0000 | [diff] [blame] | 1072 | unsigned SrcSubReg = MI->getOperand(1).getSubReg(); |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 1073 | bool isKill = MI->getOperand(1).isKill(); |
| 1074 | bool isUndef = MI->getOperand(1).isUndef(); |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 1075 | NewMI = BuildMI(MF, MI->getDebugLoc(), get(ARM::VSTRD)) |
Evan Cheng | ed3ad21 | 2009-10-25 07:52:27 +0000 | [diff] [blame] | 1076 | .addReg(SrcReg, |
| 1077 | getKillRegState(isKill) | getUndefRegState(isUndef), |
| 1078 | SrcSubReg) |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 1079 | .addFrameIndex(FI).addImm(0).addImm(Pred).addReg(PredReg); |
| 1080 | } else { // move -> load |
| 1081 | unsigned DstReg = MI->getOperand(0).getReg(); |
Evan Cheng | ed3ad21 | 2009-10-25 07:52:27 +0000 | [diff] [blame] | 1082 | unsigned DstSubReg = MI->getOperand(0).getSubReg(); |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 1083 | bool isDead = MI->getOperand(0).isDead(); |
| 1084 | bool isUndef = MI->getOperand(0).isUndef(); |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 1085 | NewMI = BuildMI(MF, MI->getDebugLoc(), get(ARM::VLDRD)) |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 1086 | .addReg(DstReg, |
| 1087 | RegState::Define | |
| 1088 | getDeadRegState(isDead) | |
Evan Cheng | ed3ad21 | 2009-10-25 07:52:27 +0000 | [diff] [blame] | 1089 | getUndefRegState(isUndef), |
| 1090 | DstSubReg) |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 1091 | .addFrameIndex(FI).addImm(0).addImm(Pred).addReg(PredReg); |
| 1092 | } |
Evan Cheng | 69b9f98 | 2010-05-13 01:12:06 +0000 | [diff] [blame] | 1093 | } else if (Opc == ARM::VMOVQ) { |
| 1094 | MachineFrameInfo &MFI = *MF.getFrameInfo(); |
| 1095 | unsigned Pred = MI->getOperand(2).getImm(); |
| 1096 | unsigned PredReg = MI->getOperand(3).getReg(); |
| 1097 | if (OpNum == 0) { // move -> store |
| 1098 | unsigned SrcReg = MI->getOperand(1).getReg(); |
| 1099 | unsigned SrcSubReg = MI->getOperand(1).getSubReg(); |
| 1100 | bool isKill = MI->getOperand(1).isKill(); |
| 1101 | bool isUndef = MI->getOperand(1).isUndef(); |
| 1102 | if (MFI.getObjectAlignment(FI) >= 16 && |
| 1103 | getRegisterInfo().canRealignStack(MF)) { |
| 1104 | NewMI = BuildMI(MF, MI->getDebugLoc(), get(ARM::VST1q)) |
| 1105 | .addFrameIndex(FI).addImm(128) |
| 1106 | .addReg(SrcReg, |
| 1107 | getKillRegState(isKill) | getUndefRegState(isUndef), |
| 1108 | SrcSubReg) |
| 1109 | .addImm(Pred).addReg(PredReg); |
| 1110 | } else { |
| 1111 | NewMI = BuildMI(MF, MI->getDebugLoc(), get(ARM::VSTMQ)) |
| 1112 | .addReg(SrcReg, |
| 1113 | getKillRegState(isKill) | getUndefRegState(isUndef), |
| 1114 | SrcSubReg) |
| 1115 | .addFrameIndex(FI).addImm(ARM_AM::getAM5Opc(ARM_AM::ia, 4)) |
| 1116 | .addImm(Pred).addReg(PredReg); |
| 1117 | } |
| 1118 | } else { // move -> load |
| 1119 | unsigned DstReg = MI->getOperand(0).getReg(); |
| 1120 | unsigned DstSubReg = MI->getOperand(0).getSubReg(); |
| 1121 | bool isDead = MI->getOperand(0).isDead(); |
| 1122 | bool isUndef = MI->getOperand(0).isUndef(); |
| 1123 | if (MFI.getObjectAlignment(FI) >= 16 && |
| 1124 | getRegisterInfo().canRealignStack(MF)) { |
| 1125 | NewMI = BuildMI(MF, MI->getDebugLoc(), get(ARM::VLD1q)) |
| 1126 | .addReg(DstReg, |
| 1127 | RegState::Define | |
| 1128 | getDeadRegState(isDead) | |
| 1129 | getUndefRegState(isUndef), |
| 1130 | DstSubReg) |
| 1131 | .addFrameIndex(FI).addImm(128).addImm(Pred).addReg(PredReg); |
| 1132 | } else { |
| 1133 | NewMI = BuildMI(MF, MI->getDebugLoc(), get(ARM::VLDMQ)) |
| 1134 | .addReg(DstReg, |
| 1135 | RegState::Define | |
| 1136 | getDeadRegState(isDead) | |
| 1137 | getUndefRegState(isUndef), |
| 1138 | DstSubReg) |
| 1139 | .addFrameIndex(FI).addImm(ARM_AM::getAM5Opc(ARM_AM::ia, 4)) |
| 1140 | .addImm(Pred).addReg(PredReg); |
| 1141 | } |
| 1142 | } |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 1143 | } |
| 1144 | |
| 1145 | return NewMI; |
| 1146 | } |
| 1147 | |
Jim Grosbach | 764ab52 | 2009-08-11 15:33:49 +0000 | [diff] [blame] | 1148 | MachineInstr* |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 1149 | ARMBaseInstrInfo::foldMemoryOperandImpl(MachineFunction &MF, |
| 1150 | MachineInstr* MI, |
| 1151 | const SmallVectorImpl<unsigned> &Ops, |
| 1152 | MachineInstr* LoadMI) const { |
Evan Cheng | 1f5c988 | 2009-07-27 04:18:04 +0000 | [diff] [blame] | 1153 | // FIXME |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 1154 | return 0; |
| 1155 | } |
| 1156 | |
| 1157 | bool |
| 1158 | ARMBaseInstrInfo::canFoldMemoryOperand(const MachineInstr *MI, |
Evan Cheng | 2294645 | 2009-08-10 05:51:48 +0000 | [diff] [blame] | 1159 | const SmallVectorImpl<unsigned> &Ops) const { |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 1160 | if (Ops.size() != 1) return false; |
| 1161 | |
| 1162 | unsigned Opc = MI->getOpcode(); |
Evan Cheng | 5732ca0 | 2009-07-27 03:14:20 +0000 | [diff] [blame] | 1163 | if (Opc == ARM::MOVr || Opc == ARM::t2MOVr) { |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 1164 | // If it is updating CPSR, then it cannot be folded. |
Evan Cheng | 2294645 | 2009-08-10 05:51:48 +0000 | [diff] [blame] | 1165 | return MI->getOperand(4).getReg() != ARM::CPSR || |
| 1166 | MI->getOperand(4).isDead(); |
Evan Cheng | 19068ba | 2009-08-10 06:32:05 +0000 | [diff] [blame] | 1167 | } else if (Opc == ARM::tMOVgpr2gpr || |
| 1168 | Opc == ARM::tMOVtgpr2gpr || |
| 1169 | Opc == ARM::tMOVgpr2tgpr) { |
| 1170 | return true; |
Evan Cheng | 69b9f98 | 2010-05-13 01:12:06 +0000 | [diff] [blame] | 1171 | } else if (Opc == ARM::VMOVS || Opc == ARM::VMOVD || |
| 1172 | Opc == ARM::VMOVDneon || Opc == ARM::VMOVQ) { |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 1173 | return true; |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 1174 | } |
| 1175 | |
Evan Cheng | 22c687b | 2010-05-14 02:13:41 +0000 | [diff] [blame] | 1176 | // FIXME: VMOVQQ and VMOVQQQQ? |
| 1177 | |
David Goodwin | 334c264 | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 1178 | return false; |
| 1179 | } |
Evan Cheng | 5ca53a7 | 2009-07-27 18:20:05 +0000 | [diff] [blame] | 1180 | |
Jakob Stoklund Olesen | 30ac046 | 2010-01-06 23:47:07 +0000 | [diff] [blame] | 1181 | /// Create a copy of a const pool value. Update CPI to the new index and return |
| 1182 | /// the label UID. |
| 1183 | static unsigned duplicateCPV(MachineFunction &MF, unsigned &CPI) { |
| 1184 | MachineConstantPool *MCP = MF.getConstantPool(); |
| 1185 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
| 1186 | |
| 1187 | const MachineConstantPoolEntry &MCPE = MCP->getConstants()[CPI]; |
| 1188 | assert(MCPE.isMachineConstantPoolEntry() && |
| 1189 | "Expecting a machine constantpool entry!"); |
| 1190 | ARMConstantPoolValue *ACPV = |
| 1191 | static_cast<ARMConstantPoolValue*>(MCPE.Val.MachineCPVal); |
| 1192 | |
| 1193 | unsigned PCLabelId = AFI->createConstPoolEntryUId(); |
| 1194 | ARMConstantPoolValue *NewCPV = 0; |
| 1195 | if (ACPV->isGlobalValue()) |
| 1196 | NewCPV = new ARMConstantPoolValue(ACPV->getGV(), PCLabelId, |
| 1197 | ARMCP::CPValue, 4); |
| 1198 | else if (ACPV->isExtSymbol()) |
| 1199 | NewCPV = new ARMConstantPoolValue(MF.getFunction()->getContext(), |
| 1200 | ACPV->getSymbol(), PCLabelId, 4); |
| 1201 | else if (ACPV->isBlockAddress()) |
| 1202 | NewCPV = new ARMConstantPoolValue(ACPV->getBlockAddress(), PCLabelId, |
| 1203 | ARMCP::CPBlockAddress, 4); |
| 1204 | else |
| 1205 | llvm_unreachable("Unexpected ARM constantpool value type!!"); |
| 1206 | CPI = MCP->getConstantPoolIndex(NewCPV, MCPE.getAlignment()); |
| 1207 | return PCLabelId; |
| 1208 | } |
| 1209 | |
Evan Cheng | fdc8340 | 2009-11-08 00:15:23 +0000 | [diff] [blame] | 1210 | void ARMBaseInstrInfo:: |
| 1211 | reMaterialize(MachineBasicBlock &MBB, |
| 1212 | MachineBasicBlock::iterator I, |
| 1213 | unsigned DestReg, unsigned SubIdx, |
Evan Cheng | d57cdd5 | 2009-11-14 02:55:43 +0000 | [diff] [blame] | 1214 | const MachineInstr *Orig, |
| 1215 | const TargetRegisterInfo *TRI) const { |
Evan Cheng | d57cdd5 | 2009-11-14 02:55:43 +0000 | [diff] [blame] | 1216 | if (SubIdx && TargetRegisterInfo::isPhysicalRegister(DestReg)) { |
| 1217 | DestReg = TRI->getSubReg(DestReg, SubIdx); |
| 1218 | SubIdx = 0; |
| 1219 | } |
| 1220 | |
Evan Cheng | fdc8340 | 2009-11-08 00:15:23 +0000 | [diff] [blame] | 1221 | unsigned Opcode = Orig->getOpcode(); |
| 1222 | switch (Opcode) { |
| 1223 | default: { |
| 1224 | MachineInstr *MI = MBB.getParent()->CloneMachineInstr(Orig); |
| 1225 | MI->getOperand(0).setReg(DestReg); |
| 1226 | MBB.insert(I, MI); |
| 1227 | break; |
| 1228 | } |
| 1229 | case ARM::tLDRpci_pic: |
| 1230 | case ARM::t2LDRpci_pic: { |
| 1231 | MachineFunction &MF = *MBB.getParent(); |
Evan Cheng | fdc8340 | 2009-11-08 00:15:23 +0000 | [diff] [blame] | 1232 | unsigned CPI = Orig->getOperand(1).getIndex(); |
Jakob Stoklund Olesen | 30ac046 | 2010-01-06 23:47:07 +0000 | [diff] [blame] | 1233 | unsigned PCLabelId = duplicateCPV(MF, CPI); |
Evan Cheng | fdc8340 | 2009-11-08 00:15:23 +0000 | [diff] [blame] | 1234 | MachineInstrBuilder MIB = BuildMI(MBB, I, Orig->getDebugLoc(), get(Opcode), |
| 1235 | DestReg) |
| 1236 | .addConstantPoolIndex(CPI).addImm(PCLabelId); |
| 1237 | (*MIB).setMemRefs(Orig->memoperands_begin(), Orig->memoperands_end()); |
| 1238 | break; |
| 1239 | } |
| 1240 | } |
| 1241 | |
| 1242 | MachineInstr *NewMI = prior(I); |
| 1243 | NewMI->getOperand(0).setSubReg(SubIdx); |
| 1244 | } |
| 1245 | |
Jakob Stoklund Olesen | 30ac046 | 2010-01-06 23:47:07 +0000 | [diff] [blame] | 1246 | MachineInstr * |
| 1247 | ARMBaseInstrInfo::duplicate(MachineInstr *Orig, MachineFunction &MF) const { |
| 1248 | MachineInstr *MI = TargetInstrInfoImpl::duplicate(Orig, MF); |
| 1249 | switch(Orig->getOpcode()) { |
| 1250 | case ARM::tLDRpci_pic: |
| 1251 | case ARM::t2LDRpci_pic: { |
| 1252 | unsigned CPI = Orig->getOperand(1).getIndex(); |
| 1253 | unsigned PCLabelId = duplicateCPV(MF, CPI); |
| 1254 | Orig->getOperand(1).setIndex(CPI); |
| 1255 | Orig->getOperand(2).setImm(PCLabelId); |
| 1256 | break; |
| 1257 | } |
| 1258 | } |
| 1259 | return MI; |
| 1260 | } |
| 1261 | |
Evan Cheng | 506049f | 2010-03-03 01:44:33 +0000 | [diff] [blame] | 1262 | bool ARMBaseInstrInfo::produceSameValue(const MachineInstr *MI0, |
| 1263 | const MachineInstr *MI1) const { |
Evan Cheng | d457e6e | 2009-11-07 04:04:34 +0000 | [diff] [blame] | 1264 | int Opcode = MI0->getOpcode(); |
Evan Cheng | 9b82425 | 2009-11-20 02:10:27 +0000 | [diff] [blame] | 1265 | if (Opcode == ARM::t2LDRpci || |
| 1266 | Opcode == ARM::t2LDRpci_pic || |
| 1267 | Opcode == ARM::tLDRpci || |
| 1268 | Opcode == ARM::tLDRpci_pic) { |
Evan Cheng | d457e6e | 2009-11-07 04:04:34 +0000 | [diff] [blame] | 1269 | if (MI1->getOpcode() != Opcode) |
| 1270 | return false; |
| 1271 | if (MI0->getNumOperands() != MI1->getNumOperands()) |
| 1272 | return false; |
| 1273 | |
| 1274 | const MachineOperand &MO0 = MI0->getOperand(1); |
| 1275 | const MachineOperand &MO1 = MI1->getOperand(1); |
| 1276 | if (MO0.getOffset() != MO1.getOffset()) |
| 1277 | return false; |
| 1278 | |
| 1279 | const MachineFunction *MF = MI0->getParent()->getParent(); |
| 1280 | const MachineConstantPool *MCP = MF->getConstantPool(); |
| 1281 | int CPI0 = MO0.getIndex(); |
| 1282 | int CPI1 = MO1.getIndex(); |
| 1283 | const MachineConstantPoolEntry &MCPE0 = MCP->getConstants()[CPI0]; |
| 1284 | const MachineConstantPoolEntry &MCPE1 = MCP->getConstants()[CPI1]; |
| 1285 | ARMConstantPoolValue *ACPV0 = |
| 1286 | static_cast<ARMConstantPoolValue*>(MCPE0.Val.MachineCPVal); |
| 1287 | ARMConstantPoolValue *ACPV1 = |
| 1288 | static_cast<ARMConstantPoolValue*>(MCPE1.Val.MachineCPVal); |
| 1289 | return ACPV0->hasSameValue(ACPV1); |
| 1290 | } |
| 1291 | |
Evan Cheng | 506049f | 2010-03-03 01:44:33 +0000 | [diff] [blame] | 1292 | return MI0->isIdenticalTo(MI1, MachineInstr::IgnoreVRegDefs); |
Evan Cheng | d457e6e | 2009-11-07 04:04:34 +0000 | [diff] [blame] | 1293 | } |
| 1294 | |
Evan Cheng | 8fb9036 | 2009-08-08 03:20:32 +0000 | [diff] [blame] | 1295 | /// getInstrPredicate - If instruction is predicated, returns its predicate |
| 1296 | /// condition, otherwise returns AL. It also returns the condition code |
| 1297 | /// register by reference. |
Evan Cheng | 5adb66a | 2009-09-28 09:14:39 +0000 | [diff] [blame] | 1298 | ARMCC::CondCodes |
| 1299 | llvm::getInstrPredicate(const MachineInstr *MI, unsigned &PredReg) { |
Evan Cheng | 8fb9036 | 2009-08-08 03:20:32 +0000 | [diff] [blame] | 1300 | int PIdx = MI->findFirstPredOperandIdx(); |
| 1301 | if (PIdx == -1) { |
| 1302 | PredReg = 0; |
| 1303 | return ARMCC::AL; |
| 1304 | } |
| 1305 | |
| 1306 | PredReg = MI->getOperand(PIdx+1).getReg(); |
| 1307 | return (ARMCC::CondCodes)MI->getOperand(PIdx).getImm(); |
| 1308 | } |
| 1309 | |
| 1310 | |
Evan Cheng | 6495f63 | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 1311 | int llvm::getMatchingCondBranchOpcode(int Opc) { |
Evan Cheng | 5ca53a7 | 2009-07-27 18:20:05 +0000 | [diff] [blame] | 1312 | if (Opc == ARM::B) |
| 1313 | return ARM::Bcc; |
| 1314 | else if (Opc == ARM::tB) |
| 1315 | return ARM::tBcc; |
| 1316 | else if (Opc == ARM::t2B) |
| 1317 | return ARM::t2Bcc; |
| 1318 | |
| 1319 | llvm_unreachable("Unknown unconditional branch opcode!"); |
| 1320 | return 0; |
| 1321 | } |
| 1322 | |
Evan Cheng | 6495f63 | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 1323 | |
| 1324 | void llvm::emitARMRegPlusImmediate(MachineBasicBlock &MBB, |
| 1325 | MachineBasicBlock::iterator &MBBI, DebugLoc dl, |
| 1326 | unsigned DestReg, unsigned BaseReg, int NumBytes, |
| 1327 | ARMCC::CondCodes Pred, unsigned PredReg, |
| 1328 | const ARMBaseInstrInfo &TII) { |
| 1329 | bool isSub = NumBytes < 0; |
| 1330 | if (isSub) NumBytes = -NumBytes; |
| 1331 | |
| 1332 | while (NumBytes) { |
| 1333 | unsigned RotAmt = ARM_AM::getSOImmValRotate(NumBytes); |
| 1334 | unsigned ThisVal = NumBytes & ARM_AM::rotr32(0xFF, RotAmt); |
| 1335 | assert(ThisVal && "Didn't extract field correctly"); |
| 1336 | |
| 1337 | // We will handle these bits from offset, clear them. |
| 1338 | NumBytes &= ~ThisVal; |
| 1339 | |
| 1340 | assert(ARM_AM::getSOImmVal(ThisVal) != -1 && "Bit extraction didn't work?"); |
| 1341 | |
| 1342 | // Build the new ADD / SUB. |
| 1343 | unsigned Opc = isSub ? ARM::SUBri : ARM::ADDri; |
| 1344 | BuildMI(MBB, MBBI, dl, TII.get(Opc), DestReg) |
| 1345 | .addReg(BaseReg, RegState::Kill).addImm(ThisVal) |
| 1346 | .addImm((unsigned)Pred).addReg(PredReg).addReg(0); |
| 1347 | BaseReg = DestReg; |
| 1348 | } |
| 1349 | } |
| 1350 | |
Evan Cheng | cdbb3f5 | 2009-08-27 01:23:50 +0000 | [diff] [blame] | 1351 | bool llvm::rewriteARMFrameIndex(MachineInstr &MI, unsigned FrameRegIdx, |
| 1352 | unsigned FrameReg, int &Offset, |
| 1353 | const ARMBaseInstrInfo &TII) { |
Evan Cheng | 6495f63 | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 1354 | unsigned Opcode = MI.getOpcode(); |
| 1355 | const TargetInstrDesc &Desc = MI.getDesc(); |
| 1356 | unsigned AddrMode = (Desc.TSFlags & ARMII::AddrModeMask); |
| 1357 | bool isSub = false; |
Jim Grosbach | 764ab52 | 2009-08-11 15:33:49 +0000 | [diff] [blame] | 1358 | |
Evan Cheng | 6495f63 | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 1359 | // Memory operands in inline assembly always use AddrMode2. |
| 1360 | if (Opcode == ARM::INLINEASM) |
| 1361 | AddrMode = ARMII::AddrMode2; |
Jim Grosbach | 764ab52 | 2009-08-11 15:33:49 +0000 | [diff] [blame] | 1362 | |
Evan Cheng | 6495f63 | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 1363 | if (Opcode == ARM::ADDri) { |
| 1364 | Offset += MI.getOperand(FrameRegIdx+1).getImm(); |
| 1365 | if (Offset == 0) { |
| 1366 | // Turn it into a move. |
| 1367 | MI.setDesc(TII.get(ARM::MOVr)); |
| 1368 | MI.getOperand(FrameRegIdx).ChangeToRegister(FrameReg, false); |
| 1369 | MI.RemoveOperand(FrameRegIdx+1); |
Evan Cheng | cdbb3f5 | 2009-08-27 01:23:50 +0000 | [diff] [blame] | 1370 | Offset = 0; |
| 1371 | return true; |
Evan Cheng | 6495f63 | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 1372 | } else if (Offset < 0) { |
| 1373 | Offset = -Offset; |
| 1374 | isSub = true; |
| 1375 | MI.setDesc(TII.get(ARM::SUBri)); |
| 1376 | } |
| 1377 | |
| 1378 | // Common case: small offset, fits into instruction. |
| 1379 | if (ARM_AM::getSOImmVal(Offset) != -1) { |
| 1380 | // Replace the FrameIndex with sp / fp |
| 1381 | MI.getOperand(FrameRegIdx).ChangeToRegister(FrameReg, false); |
| 1382 | MI.getOperand(FrameRegIdx+1).ChangeToImmediate(Offset); |
Evan Cheng | cdbb3f5 | 2009-08-27 01:23:50 +0000 | [diff] [blame] | 1383 | Offset = 0; |
| 1384 | return true; |
Evan Cheng | 6495f63 | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 1385 | } |
| 1386 | |
| 1387 | // Otherwise, pull as much of the immedidate into this ADDri/SUBri |
| 1388 | // as possible. |
| 1389 | unsigned RotAmt = ARM_AM::getSOImmValRotate(Offset); |
| 1390 | unsigned ThisImmVal = Offset & ARM_AM::rotr32(0xFF, RotAmt); |
| 1391 | |
| 1392 | // We will handle these bits from offset, clear them. |
| 1393 | Offset &= ~ThisImmVal; |
| 1394 | |
| 1395 | // Get the properly encoded SOImmVal field. |
| 1396 | assert(ARM_AM::getSOImmVal(ThisImmVal) != -1 && |
| 1397 | "Bit extraction didn't work?"); |
| 1398 | MI.getOperand(FrameRegIdx+1).ChangeToImmediate(ThisImmVal); |
| 1399 | } else { |
| 1400 | unsigned ImmIdx = 0; |
| 1401 | int InstrOffs = 0; |
| 1402 | unsigned NumBits = 0; |
| 1403 | unsigned Scale = 1; |
| 1404 | switch (AddrMode) { |
| 1405 | case ARMII::AddrMode2: { |
| 1406 | ImmIdx = FrameRegIdx+2; |
| 1407 | InstrOffs = ARM_AM::getAM2Offset(MI.getOperand(ImmIdx).getImm()); |
| 1408 | if (ARM_AM::getAM2Op(MI.getOperand(ImmIdx).getImm()) == ARM_AM::sub) |
| 1409 | InstrOffs *= -1; |
| 1410 | NumBits = 12; |
| 1411 | break; |
| 1412 | } |
| 1413 | case ARMII::AddrMode3: { |
| 1414 | ImmIdx = FrameRegIdx+2; |
| 1415 | InstrOffs = ARM_AM::getAM3Offset(MI.getOperand(ImmIdx).getImm()); |
| 1416 | if (ARM_AM::getAM3Op(MI.getOperand(ImmIdx).getImm()) == ARM_AM::sub) |
| 1417 | InstrOffs *= -1; |
| 1418 | NumBits = 8; |
| 1419 | break; |
| 1420 | } |
Anton Korobeynikov | baf3108 | 2009-08-08 13:35:48 +0000 | [diff] [blame] | 1421 | case ARMII::AddrMode4: |
Jim Grosbach | a443217 | 2009-11-15 21:45:34 +0000 | [diff] [blame] | 1422 | case ARMII::AddrMode6: |
Evan Cheng | cdbb3f5 | 2009-08-27 01:23:50 +0000 | [diff] [blame] | 1423 | // Can't fold any offset even if it's zero. |
| 1424 | return false; |
Evan Cheng | 6495f63 | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 1425 | case ARMII::AddrMode5: { |
| 1426 | ImmIdx = FrameRegIdx+1; |
| 1427 | InstrOffs = ARM_AM::getAM5Offset(MI.getOperand(ImmIdx).getImm()); |
| 1428 | if (ARM_AM::getAM5Op(MI.getOperand(ImmIdx).getImm()) == ARM_AM::sub) |
| 1429 | InstrOffs *= -1; |
| 1430 | NumBits = 8; |
| 1431 | Scale = 4; |
| 1432 | break; |
| 1433 | } |
| 1434 | default: |
| 1435 | llvm_unreachable("Unsupported addressing mode!"); |
| 1436 | break; |
| 1437 | } |
| 1438 | |
| 1439 | Offset += InstrOffs * Scale; |
| 1440 | assert((Offset & (Scale-1)) == 0 && "Can't encode this offset!"); |
| 1441 | if (Offset < 0) { |
| 1442 | Offset = -Offset; |
| 1443 | isSub = true; |
| 1444 | } |
| 1445 | |
| 1446 | // Attempt to fold address comp. if opcode has offset bits |
| 1447 | if (NumBits > 0) { |
| 1448 | // Common case: small offset, fits into instruction. |
| 1449 | MachineOperand &ImmOp = MI.getOperand(ImmIdx); |
| 1450 | int ImmedOffset = Offset / Scale; |
| 1451 | unsigned Mask = (1 << NumBits) - 1; |
| 1452 | if ((unsigned)Offset <= Mask * Scale) { |
| 1453 | // Replace the FrameIndex with sp |
| 1454 | MI.getOperand(FrameRegIdx).ChangeToRegister(FrameReg, false); |
| 1455 | if (isSub) |
| 1456 | ImmedOffset |= 1 << NumBits; |
| 1457 | ImmOp.ChangeToImmediate(ImmedOffset); |
Evan Cheng | cdbb3f5 | 2009-08-27 01:23:50 +0000 | [diff] [blame] | 1458 | Offset = 0; |
| 1459 | return true; |
Evan Cheng | 6495f63 | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 1460 | } |
Jim Grosbach | 764ab52 | 2009-08-11 15:33:49 +0000 | [diff] [blame] | 1461 | |
Evan Cheng | 6495f63 | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 1462 | // Otherwise, it didn't fit. Pull in what we can to simplify the immed. |
| 1463 | ImmedOffset = ImmedOffset & Mask; |
| 1464 | if (isSub) |
| 1465 | ImmedOffset |= 1 << NumBits; |
| 1466 | ImmOp.ChangeToImmediate(ImmedOffset); |
| 1467 | Offset &= ~(Mask*Scale); |
| 1468 | } |
| 1469 | } |
| 1470 | |
Evan Cheng | cdbb3f5 | 2009-08-27 01:23:50 +0000 | [diff] [blame] | 1471 | Offset = (isSub) ? -Offset : Offset; |
| 1472 | return Offset == 0; |
Evan Cheng | 6495f63 | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 1473 | } |