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