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 { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 58 | // Can only insert uncond branches so far. |
| 59 | assert(Cond.empty() && !FBB && TBB && "Can only handle uncond branches!"); |
| 60 | BuildMI(&MBB, get(IA64::BRL_NOTCALL)).addMBB(TBB); |
| 61 | return 1; |
| 62 | } |
Owen Anderson | 8f2c893 | 2007-12-31 06:32:00 +0000 | [diff] [blame] | 63 | |
Owen Anderson | 9fa72d9 | 2008-08-26 18:03:31 +0000 | [diff] [blame] | 64 | bool IA64InstrInfo::copyRegToReg(MachineBasicBlock &MBB, |
Bill Wendling | 5b8a97b | 2009-02-12 00:02:55 +0000 | [diff] [blame] | 65 | MachineBasicBlock::iterator MI, |
| 66 | unsigned DestReg, unsigned SrcReg, |
| 67 | const TargetRegisterClass *DestRC, |
| 68 | const TargetRegisterClass *SrcRC) const { |
Owen Anderson | 8f2c893 | 2007-12-31 06:32:00 +0000 | [diff] [blame] | 69 | if (DestRC != SrcRC) { |
Owen Anderson | 9fa72d9 | 2008-08-26 18:03:31 +0000 | [diff] [blame] | 70 | // Not yet supported! |
| 71 | return false; |
Owen Anderson | 8f2c893 | 2007-12-31 06:32:00 +0000 | [diff] [blame] | 72 | } |
| 73 | |
Bill Wendling | 5b8a97b | 2009-02-12 00:02:55 +0000 | [diff] [blame] | 74 | DebugLoc DL = DebugLoc::getUnknownLoc(); |
| 75 | if (MI != MBB.end()) DL = MI->getDebugLoc(); |
| 76 | |
Owen Anderson | 8f2c893 | 2007-12-31 06:32:00 +0000 | [diff] [blame] | 77 | if(DestRC == IA64::PRRegisterClass ) // if a bool, we use pseudocode |
| 78 | // (SrcReg) DestReg = cmp.eq.unc(r0, r0) |
Bill Wendling | 5b8a97b | 2009-02-12 00:02:55 +0000 | [diff] [blame] | 79 | BuildMI(MBB, MI, DL, get(IA64::PCMPEQUNC), DestReg) |
Owen Anderson | 8f2c893 | 2007-12-31 06:32:00 +0000 | [diff] [blame] | 80 | .addReg(IA64::r0).addReg(IA64::r0).addReg(SrcReg); |
| 81 | else // otherwise, MOV works (for both gen. regs and FP regs) |
Bill Wendling | 5b8a97b | 2009-02-12 00:02:55 +0000 | [diff] [blame] | 82 | BuildMI(MBB, MI, DL, get(IA64::MOV), DestReg).addReg(SrcReg); |
Owen Anderson | 9fa72d9 | 2008-08-26 18:03:31 +0000 | [diff] [blame] | 83 | |
| 84 | return true; |
Owen Anderson | 8f2c893 | 2007-12-31 06:32:00 +0000 | [diff] [blame] | 85 | } |
Owen Anderson | 8187543 | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 86 | |
| 87 | void IA64InstrInfo::storeRegToStackSlot(MachineBasicBlock &MBB, |
| 88 | MachineBasicBlock::iterator MI, |
| 89 | unsigned SrcReg, bool isKill, |
| 90 | int FrameIdx, |
| 91 | const TargetRegisterClass *RC) const{ |
Bill Wendling | 5b8a97b | 2009-02-12 00:02:55 +0000 | [diff] [blame] | 92 | DebugLoc DL = DebugLoc::getUnknownLoc(); |
| 93 | if (MI != MBB.end()) DL = MI->getDebugLoc(); |
Owen Anderson | 8187543 | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 94 | |
| 95 | if (RC == IA64::FPRegisterClass) { |
Bill Wendling | 5b8a97b | 2009-02-12 00:02:55 +0000 | [diff] [blame] | 96 | BuildMI(MBB, MI, DL, get(IA64::STF_SPILL)).addFrameIndex(FrameIdx) |
Owen Anderson | 8187543 | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 97 | .addReg(SrcReg, false, false, isKill); |
| 98 | } else if (RC == IA64::GRRegisterClass) { |
Bill Wendling | 5b8a97b | 2009-02-12 00:02:55 +0000 | [diff] [blame] | 99 | BuildMI(MBB, MI, DL, get(IA64::ST8)).addFrameIndex(FrameIdx) |
Owen Anderson | 8187543 | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 100 | .addReg(SrcReg, false, false, isKill); |
| 101 | } else if (RC == IA64::PRRegisterClass) { |
| 102 | /* we use IA64::r2 as a temporary register for doing this hackery. */ |
| 103 | // first we load 0: |
Bill Wendling | 5b8a97b | 2009-02-12 00:02:55 +0000 | [diff] [blame] | 104 | BuildMI(MBB, MI, DL, get(IA64::MOV), IA64::r2).addReg(IA64::r0); |
Owen Anderson | 8187543 | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 105 | // then conditionally add 1: |
Bill Wendling | 5b8a97b | 2009-02-12 00:02:55 +0000 | [diff] [blame] | 106 | BuildMI(MBB, MI, DL, get(IA64::CADDIMM22), IA64::r2).addReg(IA64::r2) |
Owen Anderson | 8187543 | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 107 | .addImm(1).addReg(SrcReg, false, false, isKill); |
| 108 | // and then store it to the stack |
Bill Wendling | 5b8a97b | 2009-02-12 00:02:55 +0000 | [diff] [blame] | 109 | BuildMI(MBB, MI, DL, get(IA64::ST8)) |
| 110 | .addFrameIndex(FrameIdx) |
| 111 | .addReg(IA64::r2); |
Owen Anderson | 8187543 | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 112 | } else assert(0 && |
| 113 | "sorry, I don't know how to store this sort of reg in the stack\n"); |
| 114 | } |
| 115 | |
| 116 | void IA64InstrInfo::storeRegToAddr(MachineFunction &MF, unsigned SrcReg, |
Bill Wendling | 5b8a97b | 2009-02-12 00:02:55 +0000 | [diff] [blame] | 117 | bool isKill, |
| 118 | SmallVectorImpl<MachineOperand> &Addr, |
| 119 | const TargetRegisterClass *RC, |
Owen Anderson | 8187543 | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 120 | SmallVectorImpl<MachineInstr*> &NewMIs) const { |
| 121 | unsigned Opc = 0; |
| 122 | if (RC == IA64::FPRegisterClass) { |
| 123 | Opc = IA64::STF8; |
| 124 | } else if (RC == IA64::GRRegisterClass) { |
| 125 | Opc = IA64::ST8; |
| 126 | } else if (RC == IA64::PRRegisterClass) { |
| 127 | Opc = IA64::ST1; |
| 128 | } else { |
| 129 | assert(0 && |
| 130 | "sorry, I don't know how to store this sort of reg\n"); |
| 131 | } |
| 132 | |
Dale Johannesen | 77cce4d | 2009-02-12 23:08:38 +0000 | [diff] [blame^] | 133 | DebugLoc DL = DebugLoc::getUnknownLoc(); |
| 134 | MachineInstrBuilder MIB = BuildMI(MF, DL, get(Opc)); |
Owen Anderson | 8187543 | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 135 | for (unsigned i = 0, e = Addr.size(); i != e; ++i) { |
| 136 | MachineOperand &MO = Addr[i]; |
Dan Gohman | b9f4fa7 | 2008-10-03 15:45:36 +0000 | [diff] [blame] | 137 | if (MO.isReg()) |
Owen Anderson | 8187543 | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 138 | MIB.addReg(MO.getReg()); |
Dan Gohman | b9f4fa7 | 2008-10-03 15:45:36 +0000 | [diff] [blame] | 139 | else if (MO.isImm()) |
Owen Anderson | 8187543 | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 140 | MIB.addImm(MO.getImm()); |
| 141 | else |
| 142 | MIB.addFrameIndex(MO.getIndex()); |
| 143 | } |
| 144 | MIB.addReg(SrcReg, false, false, isKill); |
| 145 | NewMIs.push_back(MIB); |
| 146 | return; |
| 147 | |
| 148 | } |
| 149 | |
| 150 | void IA64InstrInfo::loadRegFromStackSlot(MachineBasicBlock &MBB, |
Bill Wendling | 5b8a97b | 2009-02-12 00:02:55 +0000 | [diff] [blame] | 151 | MachineBasicBlock::iterator MI, |
| 152 | unsigned DestReg, int FrameIdx, |
| 153 | const TargetRegisterClass *RC)const{ |
| 154 | DebugLoc DL = DebugLoc::getUnknownLoc(); |
| 155 | if (MI != MBB.end()) DL = MI->getDebugLoc(); |
Owen Anderson | 8187543 | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 156 | |
| 157 | if (RC == IA64::FPRegisterClass) { |
Bill Wendling | 5b8a97b | 2009-02-12 00:02:55 +0000 | [diff] [blame] | 158 | BuildMI(MBB, MI, DL, get(IA64::LDF_FILL), DestReg).addFrameIndex(FrameIdx); |
Owen Anderson | 8187543 | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 159 | } else if (RC == IA64::GRRegisterClass) { |
Bill Wendling | 5b8a97b | 2009-02-12 00:02:55 +0000 | [diff] [blame] | 160 | BuildMI(MBB, MI, DL, get(IA64::LD8), DestReg).addFrameIndex(FrameIdx); |
| 161 | } else if (RC == IA64::PRRegisterClass) { |
| 162 | // first we load a byte from the stack into r2, our 'predicate hackery' |
| 163 | // scratch reg |
| 164 | BuildMI(MBB, MI, DL, get(IA64::LD8), IA64::r2).addFrameIndex(FrameIdx); |
| 165 | // then we compare it to zero. If it _is_ zero, compare-not-equal to |
| 166 | // r0 gives us 0, which is what we want, so that's nice. |
| 167 | BuildMI(MBB, MI, DL, get(IA64::CMPNE), DestReg) |
| 168 | .addReg(IA64::r2) |
| 169 | .addReg(IA64::r0); |
| 170 | } else { |
| 171 | assert(0 && |
| 172 | "sorry, I don't know how to load this sort of reg from the stack\n"); |
| 173 | } |
Owen Anderson | 8187543 | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | void IA64InstrInfo::loadRegFromAddr(MachineFunction &MF, unsigned DestReg, |
Bill Wendling | 5b8a97b | 2009-02-12 00:02:55 +0000 | [diff] [blame] | 177 | SmallVectorImpl<MachineOperand> &Addr, |
| 178 | const TargetRegisterClass *RC, |
Owen Anderson | 8187543 | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 179 | SmallVectorImpl<MachineInstr*> &NewMIs) const { |
| 180 | unsigned Opc = 0; |
| 181 | if (RC == IA64::FPRegisterClass) { |
| 182 | Opc = IA64::LDF8; |
| 183 | } else if (RC == IA64::GRRegisterClass) { |
| 184 | Opc = IA64::LD8; |
| 185 | } else if (RC == IA64::PRRegisterClass) { |
| 186 | Opc = IA64::LD1; |
| 187 | } else { |
| 188 | assert(0 && |
Dale Johannesen | 77cce4d | 2009-02-12 23:08:38 +0000 | [diff] [blame^] | 189 | "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] | 190 | } |
| 191 | |
Dale Johannesen | 77cce4d | 2009-02-12 23:08:38 +0000 | [diff] [blame^] | 192 | DebugLoc DL = DebugLoc::getUnknownLoc(); |
| 193 | MachineInstrBuilder MIB = BuildMI(MF, DL, get(Opc), DestReg); |
Owen Anderson | 8187543 | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 194 | for (unsigned i = 0, e = Addr.size(); i != e; ++i) { |
| 195 | MachineOperand &MO = Addr[i]; |
Dan Gohman | b9f4fa7 | 2008-10-03 15:45:36 +0000 | [diff] [blame] | 196 | if (MO.isReg()) |
Owen Anderson | 8187543 | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 197 | MIB.addReg(MO.getReg()); |
Dan Gohman | b9f4fa7 | 2008-10-03 15:45:36 +0000 | [diff] [blame] | 198 | else if (MO.isImm()) |
Owen Anderson | 8187543 | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 199 | MIB.addImm(MO.getImm()); |
| 200 | else |
| 201 | MIB.addFrameIndex(MO.getIndex()); |
| 202 | } |
| 203 | NewMIs.push_back(MIB); |
| 204 | return; |
| 205 | } |