Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1 | //===- IA64InstrInfo.cpp - IA64 Instruction Information -----------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 081ce94 | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file contains the IA64 implementation of the TargetInstrInfo class. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "IA64InstrInfo.h" |
| 15 | #include "IA64.h" |
| 16 | #include "IA64InstrBuilder.h" |
| 17 | #include "llvm/CodeGen/MachineInstrBuilder.h" |
Dan Gohman | c24a3f8 | 2009-01-05 17:59:02 +0000 | [diff] [blame] | 18 | #include "llvm/ADT/SmallVector.h" |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 19 | #include "IA64GenInstrInfo.inc" |
| 20 | using namespace llvm; |
| 21 | |
| 22 | IA64InstrInfo::IA64InstrInfo() |
Chris Lattner | d2fd6db | 2008-01-01 01:03:04 +0000 | [diff] [blame] | 23 | : TargetInstrInfoImpl(IA64Insts, sizeof(IA64Insts)/sizeof(IA64Insts[0])), |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 24 | RI(*this) { |
| 25 | } |
| 26 | |
| 27 | |
| 28 | bool IA64InstrInfo::isMoveInstr(const MachineInstr& MI, |
Evan Cheng | f97496a | 2009-01-20 19:12:24 +0000 | [diff] [blame] | 29 | unsigned& sourceReg, |
| 30 | unsigned& destReg, |
| 31 | unsigned& SrcSR, unsigned& DstSR) const { |
| 32 | SrcSR = DstSR = 0; // No sub-registers. |
| 33 | |
Chris Lattner | 99aa337 | 2008-01-07 02:48:55 +0000 | [diff] [blame] | 34 | unsigned oc = MI.getOpcode(); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 35 | if (oc == IA64::MOV || oc == IA64::FMOV) { |
| 36 | // TODO: this doesn't detect predicate moves |
| 37 | assert(MI.getNumOperands() >= 2 && |
Dan Gohman | b9f4fa7 | 2008-10-03 15:45:36 +0000 | [diff] [blame] | 38 | /* MI.getOperand(0).isReg() && |
| 39 | MI.getOperand(1).isReg() && */ |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 40 | "invalid register-register move instruction"); |
Dan Gohman | b9f4fa7 | 2008-10-03 15:45:36 +0000 | [diff] [blame] | 41 | if (MI.getOperand(0).isReg() && |
| 42 | MI.getOperand(1).isReg()) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 43 | // if both operands of the MOV/FMOV are registers, then |
| 44 | // yes, this is a move instruction |
| 45 | sourceReg = MI.getOperand(1).getReg(); |
| 46 | destReg = MI.getOperand(0).getReg(); |
| 47 | return true; |
| 48 | } |
| 49 | } |
| 50 | return false; // we don't consider e.g. %regN = MOV <FrameIndex #x> a |
| 51 | // move instruction |
| 52 | } |
| 53 | |
| 54 | unsigned |
| 55 | IA64InstrInfo::InsertBranch(MachineBasicBlock &MBB,MachineBasicBlock *TBB, |
| 56 | MachineBasicBlock *FBB, |
Owen Anderson | d131b5b | 2008-08-14 22:49:33 +0000 | [diff] [blame] | 57 | const SmallVectorImpl<MachineOperand> &Cond)const { |
Dale Johannesen | 2ba7836 | 2009-02-13 02:34:39 +0000 | [diff] [blame] | 58 | // FIXME this should probably have a DebugLoc argument |
| 59 | DebugLoc dl = DebugLoc::getUnknownLoc(); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 60 | // Can only insert uncond branches so far. |
| 61 | assert(Cond.empty() && !FBB && TBB && "Can only handle uncond branches!"); |
Dale Johannesen | 2ba7836 | 2009-02-13 02:34:39 +0000 | [diff] [blame] | 62 | BuildMI(&MBB, dl, get(IA64::BRL_NOTCALL)).addMBB(TBB); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 63 | return 1; |
| 64 | } |
Owen Anderson | 8f2c893 | 2007-12-31 06:32:00 +0000 | [diff] [blame] | 65 | |
Owen Anderson | 9fa72d9 | 2008-08-26 18:03:31 +0000 | [diff] [blame] | 66 | bool IA64InstrInfo::copyRegToReg(MachineBasicBlock &MBB, |
Bill Wendling | 5b8a97b | 2009-02-12 00:02:55 +0000 | [diff] [blame] | 67 | MachineBasicBlock::iterator MI, |
| 68 | unsigned DestReg, unsigned SrcReg, |
| 69 | const TargetRegisterClass *DestRC, |
| 70 | const TargetRegisterClass *SrcRC) const { |
Owen Anderson | 8f2c893 | 2007-12-31 06:32:00 +0000 | [diff] [blame] | 71 | if (DestRC != SrcRC) { |
Owen Anderson | 9fa72d9 | 2008-08-26 18:03:31 +0000 | [diff] [blame] | 72 | // Not yet supported! |
| 73 | return false; |
Owen Anderson | 8f2c893 | 2007-12-31 06:32:00 +0000 | [diff] [blame] | 74 | } |
| 75 | |
Bill Wendling | 5b8a97b | 2009-02-12 00:02:55 +0000 | [diff] [blame] | 76 | DebugLoc DL = DebugLoc::getUnknownLoc(); |
| 77 | if (MI != MBB.end()) DL = MI->getDebugLoc(); |
| 78 | |
Owen Anderson | 8f2c893 | 2007-12-31 06:32:00 +0000 | [diff] [blame] | 79 | if(DestRC == IA64::PRRegisterClass ) // if a bool, we use pseudocode |
| 80 | // (SrcReg) DestReg = cmp.eq.unc(r0, r0) |
Bill Wendling | 5b8a97b | 2009-02-12 00:02:55 +0000 | [diff] [blame] | 81 | BuildMI(MBB, MI, DL, get(IA64::PCMPEQUNC), DestReg) |
Owen Anderson | 8f2c893 | 2007-12-31 06:32:00 +0000 | [diff] [blame] | 82 | .addReg(IA64::r0).addReg(IA64::r0).addReg(SrcReg); |
| 83 | else // otherwise, MOV works (for both gen. regs and FP regs) |
Bill Wendling | 5b8a97b | 2009-02-12 00:02:55 +0000 | [diff] [blame] | 84 | BuildMI(MBB, MI, DL, get(IA64::MOV), DestReg).addReg(SrcReg); |
Owen Anderson | 9fa72d9 | 2008-08-26 18:03:31 +0000 | [diff] [blame] | 85 | |
| 86 | return true; |
Owen Anderson | 8f2c893 | 2007-12-31 06:32:00 +0000 | [diff] [blame] | 87 | } |
Owen Anderson | 8187543 | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 88 | |
| 89 | void IA64InstrInfo::storeRegToStackSlot(MachineBasicBlock &MBB, |
| 90 | MachineBasicBlock::iterator MI, |
| 91 | unsigned SrcReg, bool isKill, |
| 92 | int FrameIdx, |
| 93 | const TargetRegisterClass *RC) const{ |
Bill Wendling | 5b8a97b | 2009-02-12 00:02:55 +0000 | [diff] [blame] | 94 | DebugLoc DL = DebugLoc::getUnknownLoc(); |
| 95 | if (MI != MBB.end()) DL = MI->getDebugLoc(); |
Owen Anderson | 8187543 | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 96 | |
| 97 | if (RC == IA64::FPRegisterClass) { |
Bill Wendling | 5b8a97b | 2009-02-12 00:02:55 +0000 | [diff] [blame] | 98 | BuildMI(MBB, MI, DL, get(IA64::STF_SPILL)).addFrameIndex(FrameIdx) |
Bill Wendling | 2b73976 | 2009-05-13 21:33:08 +0000 | [diff] [blame] | 99 | .addReg(SrcReg, getKillRegState(isKill)); |
Owen Anderson | 8187543 | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 100 | } else if (RC == IA64::GRRegisterClass) { |
Bill Wendling | 5b8a97b | 2009-02-12 00:02:55 +0000 | [diff] [blame] | 101 | BuildMI(MBB, MI, DL, get(IA64::ST8)).addFrameIndex(FrameIdx) |
Bill Wendling | 2b73976 | 2009-05-13 21:33:08 +0000 | [diff] [blame] | 102 | .addReg(SrcReg, getKillRegState(isKill)); |
Owen Anderson | 8187543 | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 103 | } else if (RC == IA64::PRRegisterClass) { |
| 104 | /* we use IA64::r2 as a temporary register for doing this hackery. */ |
| 105 | // first we load 0: |
Bill Wendling | 5b8a97b | 2009-02-12 00:02:55 +0000 | [diff] [blame] | 106 | BuildMI(MBB, MI, DL, get(IA64::MOV), IA64::r2).addReg(IA64::r0); |
Owen Anderson | 8187543 | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 107 | // then conditionally add 1: |
Bill Wendling | 5b8a97b | 2009-02-12 00:02:55 +0000 | [diff] [blame] | 108 | BuildMI(MBB, MI, DL, get(IA64::CADDIMM22), IA64::r2).addReg(IA64::r2) |
Bill Wendling | 2b73976 | 2009-05-13 21:33:08 +0000 | [diff] [blame] | 109 | .addImm(1).addReg(SrcReg, getKillRegState(isKill)); |
Owen Anderson | 8187543 | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 110 | // and then store it to the stack |
Bill Wendling | 5b8a97b | 2009-02-12 00:02:55 +0000 | [diff] [blame] | 111 | BuildMI(MBB, MI, DL, get(IA64::ST8)) |
| 112 | .addFrameIndex(FrameIdx) |
| 113 | .addReg(IA64::r2); |
Owen Anderson | 8187543 | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 114 | } else assert(0 && |
| 115 | "sorry, I don't know how to store this sort of reg in the stack\n"); |
| 116 | } |
| 117 | |
| 118 | void IA64InstrInfo::storeRegToAddr(MachineFunction &MF, unsigned SrcReg, |
Bill Wendling | 5b8a97b | 2009-02-12 00:02:55 +0000 | [diff] [blame] | 119 | bool isKill, |
| 120 | SmallVectorImpl<MachineOperand> &Addr, |
| 121 | const TargetRegisterClass *RC, |
Owen Anderson | 8187543 | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 122 | SmallVectorImpl<MachineInstr*> &NewMIs) const { |
| 123 | unsigned Opc = 0; |
| 124 | if (RC == IA64::FPRegisterClass) { |
| 125 | Opc = IA64::STF8; |
| 126 | } else if (RC == IA64::GRRegisterClass) { |
| 127 | Opc = IA64::ST8; |
| 128 | } else if (RC == IA64::PRRegisterClass) { |
| 129 | Opc = IA64::ST1; |
| 130 | } else { |
| 131 | assert(0 && |
| 132 | "sorry, I don't know how to store this sort of reg\n"); |
| 133 | } |
| 134 | |
Dale Johannesen | 77cce4d | 2009-02-12 23:08:38 +0000 | [diff] [blame] | 135 | DebugLoc DL = DebugLoc::getUnknownLoc(); |
| 136 | MachineInstrBuilder MIB = BuildMI(MF, DL, get(Opc)); |
Dan Gohman | c909bbb | 2009-02-18 05:45:50 +0000 | [diff] [blame] | 137 | for (unsigned i = 0, e = Addr.size(); i != e; ++i) |
| 138 | MIB.addOperand(Addr[i]); |
Bill Wendling | 2b73976 | 2009-05-13 21:33:08 +0000 | [diff] [blame] | 139 | MIB.addReg(SrcReg, getKillRegState(isKill)); |
Owen Anderson | 8187543 | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 140 | NewMIs.push_back(MIB); |
| 141 | return; |
| 142 | |
| 143 | } |
| 144 | |
| 145 | void IA64InstrInfo::loadRegFromStackSlot(MachineBasicBlock &MBB, |
Bill Wendling | 5b8a97b | 2009-02-12 00:02:55 +0000 | [diff] [blame] | 146 | MachineBasicBlock::iterator MI, |
| 147 | unsigned DestReg, int FrameIdx, |
| 148 | const TargetRegisterClass *RC)const{ |
| 149 | DebugLoc DL = DebugLoc::getUnknownLoc(); |
| 150 | if (MI != MBB.end()) DL = MI->getDebugLoc(); |
Owen Anderson | 8187543 | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 151 | |
| 152 | if (RC == IA64::FPRegisterClass) { |
Bill Wendling | 5b8a97b | 2009-02-12 00:02:55 +0000 | [diff] [blame] | 153 | BuildMI(MBB, MI, DL, get(IA64::LDF_FILL), DestReg).addFrameIndex(FrameIdx); |
Owen Anderson | 8187543 | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 154 | } else if (RC == IA64::GRRegisterClass) { |
Bill Wendling | 5b8a97b | 2009-02-12 00:02:55 +0000 | [diff] [blame] | 155 | BuildMI(MBB, MI, DL, get(IA64::LD8), DestReg).addFrameIndex(FrameIdx); |
| 156 | } else if (RC == IA64::PRRegisterClass) { |
| 157 | // first we load a byte from the stack into r2, our 'predicate hackery' |
| 158 | // scratch reg |
| 159 | BuildMI(MBB, MI, DL, get(IA64::LD8), IA64::r2).addFrameIndex(FrameIdx); |
| 160 | // then we compare it to zero. If it _is_ zero, compare-not-equal to |
| 161 | // r0 gives us 0, which is what we want, so that's nice. |
| 162 | BuildMI(MBB, MI, DL, get(IA64::CMPNE), DestReg) |
| 163 | .addReg(IA64::r2) |
| 164 | .addReg(IA64::r0); |
| 165 | } else { |
| 166 | assert(0 && |
| 167 | "sorry, I don't know how to load this sort of reg from the stack\n"); |
| 168 | } |
Owen Anderson | 8187543 | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | void IA64InstrInfo::loadRegFromAddr(MachineFunction &MF, unsigned DestReg, |
Bill Wendling | 5b8a97b | 2009-02-12 00:02:55 +0000 | [diff] [blame] | 172 | SmallVectorImpl<MachineOperand> &Addr, |
| 173 | const TargetRegisterClass *RC, |
Owen Anderson | 8187543 | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 174 | SmallVectorImpl<MachineInstr*> &NewMIs) const { |
| 175 | unsigned Opc = 0; |
| 176 | if (RC == IA64::FPRegisterClass) { |
| 177 | Opc = IA64::LDF8; |
| 178 | } else if (RC == IA64::GRRegisterClass) { |
| 179 | Opc = IA64::LD8; |
| 180 | } else if (RC == IA64::PRRegisterClass) { |
| 181 | Opc = IA64::LD1; |
| 182 | } else { |
| 183 | assert(0 && |
Dale Johannesen | 77cce4d | 2009-02-12 23:08:38 +0000 | [diff] [blame] | 184 | "sorry, I don't know how to load this sort of reg\n"); |
Owen Anderson | 8187543 | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 185 | } |
| 186 | |
Dale Johannesen | 77cce4d | 2009-02-12 23:08:38 +0000 | [diff] [blame] | 187 | DebugLoc DL = DebugLoc::getUnknownLoc(); |
| 188 | MachineInstrBuilder MIB = BuildMI(MF, DL, get(Opc), DestReg); |
Dan Gohman | c909bbb | 2009-02-18 05:45:50 +0000 | [diff] [blame] | 189 | for (unsigned i = 0, e = Addr.size(); i != e; ++i) |
| 190 | MIB.addOperand(Addr[i]); |
Owen Anderson | 8187543 | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 191 | NewMIs.push_back(MIB); |
| 192 | return; |
| 193 | } |