Dan Gohman | b0cf29c | 2008-08-13 20:19:35 +0000 | [diff] [blame] | 1 | ///===-- FastISel.cpp - Implementation of the FastISel class --------------===// |
| 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 implementation of the FastISel class. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Dan Gohman | 6f2766d | 2008-08-19 22:31:46 +0000 | [diff] [blame] | 14 | #include "llvm/Instructions.h" |
Dan Gohman | b0cf29c | 2008-08-13 20:19:35 +0000 | [diff] [blame] | 15 | #include "llvm/CodeGen/FastISel.h" |
| 16 | #include "llvm/CodeGen/MachineInstrBuilder.h" |
| 17 | #include "llvm/CodeGen/MachineRegisterInfo.h" |
Evan Cheng | 83785c8 | 2008-08-20 22:45:34 +0000 | [diff] [blame] | 18 | #include "llvm/Target/TargetData.h" |
Dan Gohman | b0cf29c | 2008-08-13 20:19:35 +0000 | [diff] [blame] | 19 | #include "llvm/Target/TargetInstrInfo.h" |
Evan Cheng | 83785c8 | 2008-08-20 22:45:34 +0000 | [diff] [blame] | 20 | #include "llvm/Target/TargetLowering.h" |
Dan Gohman | bb46633 | 2008-08-20 21:05:57 +0000 | [diff] [blame] | 21 | #include "llvm/Target/TargetMachine.h" |
Dan Gohman | b0cf29c | 2008-08-13 20:19:35 +0000 | [diff] [blame] | 22 | using namespace llvm; |
| 23 | |
Owen Anderson | 99aaf10 | 2008-09-03 17:37:03 +0000 | [diff] [blame] | 24 | // Don't cache constant materializations. To do so would require |
| 25 | // tracking what uses they dominate. Non-constants, however, already |
| 26 | // have the SSA def-doms-use requirement enforced, so we can cache their |
| 27 | // computations. |
Dan Gohman | 3df24e6 | 2008-09-03 23:12:08 +0000 | [diff] [blame^] | 28 | unsigned FastISel::getRegForValue(Value *V) { |
Owen Anderson | 99aaf10 | 2008-09-03 17:37:03 +0000 | [diff] [blame] | 29 | if (ValueMap.count(V)) |
| 30 | return ValueMap[V]; |
Dan Gohman | ad368ac | 2008-08-27 18:10:19 +0000 | [diff] [blame] | 31 | |
| 32 | MVT::SimpleValueType VT = TLI.getValueType(V->getType()).getSimpleVT(); |
| 33 | if (ConstantInt *CI = dyn_cast<ConstantInt>(V)) { |
| 34 | if (CI->getValue().getActiveBits() > 64) |
| 35 | return 0; |
Owen Anderson | 99aaf10 | 2008-09-03 17:37:03 +0000 | [diff] [blame] | 36 | // Don't cache constant materializations. To do so would require |
| 37 | // tracking what uses they dominate. |
| 38 | return FastEmit_i(VT, VT, ISD::Constant, CI->getZExtValue()); |
Dan Gohman | 205d925 | 2008-08-28 21:19:07 +0000 | [diff] [blame] | 39 | } else if (isa<ConstantPointerNull>(V)) { |
Owen Anderson | 99aaf10 | 2008-09-03 17:37:03 +0000 | [diff] [blame] | 40 | return FastEmit_i(VT, VT, ISD::Constant, 0); |
Dan Gohman | ad368ac | 2008-08-27 18:10:19 +0000 | [diff] [blame] | 41 | } else if (ConstantFP *CF = dyn_cast<ConstantFP>(V)) { |
Owen Anderson | 99aaf10 | 2008-09-03 17:37:03 +0000 | [diff] [blame] | 42 | unsigned Reg = FastEmit_f(VT, VT, ISD::ConstantFP, CF); |
Dan Gohman | ad368ac | 2008-08-27 18:10:19 +0000 | [diff] [blame] | 43 | |
| 44 | if (!Reg) { |
| 45 | const APFloat &Flt = CF->getValueAPF(); |
| 46 | MVT IntVT = TLI.getPointerTy(); |
| 47 | |
| 48 | uint64_t x[2]; |
| 49 | uint32_t IntBitWidth = IntVT.getSizeInBits(); |
| 50 | if (Flt.convertToInteger(x, IntBitWidth, /*isSigned=*/true, |
| 51 | APFloat::rmTowardZero) != APFloat::opOK) |
| 52 | return 0; |
| 53 | APInt IntVal(IntBitWidth, 2, x); |
| 54 | |
| 55 | unsigned IntegerReg = FastEmit_i(IntVT.getSimpleVT(), IntVT.getSimpleVT(), |
| 56 | ISD::Constant, IntVal.getZExtValue()); |
| 57 | if (IntegerReg == 0) |
| 58 | return 0; |
| 59 | Reg = FastEmit_r(IntVT.getSimpleVT(), VT, ISD::SINT_TO_FP, IntegerReg); |
| 60 | if (Reg == 0) |
| 61 | return 0; |
| 62 | } |
Owen Anderson | 99aaf10 | 2008-09-03 17:37:03 +0000 | [diff] [blame] | 63 | |
| 64 | return Reg; |
Dan Gohman | 205d925 | 2008-08-28 21:19:07 +0000 | [diff] [blame] | 65 | } else if (isa<UndefValue>(V)) { |
Owen Anderson | 99aaf10 | 2008-09-03 17:37:03 +0000 | [diff] [blame] | 66 | unsigned Reg = createResultReg(TLI.getRegClassFor(VT)); |
Dan Gohman | 205d925 | 2008-08-28 21:19:07 +0000 | [diff] [blame] | 67 | BuildMI(MBB, TII.get(TargetInstrInfo::IMPLICIT_DEF), Reg); |
Owen Anderson | 99aaf10 | 2008-09-03 17:37:03 +0000 | [diff] [blame] | 68 | return Reg; |
Dan Gohman | ad368ac | 2008-08-27 18:10:19 +0000 | [diff] [blame] | 69 | } |
Owen Anderson | d5d81a4 | 2008-09-03 17:51:57 +0000 | [diff] [blame] | 70 | |
| 71 | return 0; |
Dan Gohman | ad368ac | 2008-08-27 18:10:19 +0000 | [diff] [blame] | 72 | } |
| 73 | |
Owen Anderson | cc54e76 | 2008-08-30 00:38:46 +0000 | [diff] [blame] | 74 | /// UpdateValueMap - Update the value map to include the new mapping for this |
| 75 | /// instruction, or insert an extra copy to get the result in a previous |
| 76 | /// determined register. |
| 77 | /// NOTE: This is only necessary because we might select a block that uses |
| 78 | /// a value before we select the block that defines the value. It might be |
| 79 | /// possible to fix this by selecting blocks in reverse postorder. |
Dan Gohman | 3df24e6 | 2008-09-03 23:12:08 +0000 | [diff] [blame^] | 80 | void FastISel::UpdateValueMap(Instruction* I, unsigned Reg) { |
Owen Anderson | cc54e76 | 2008-08-30 00:38:46 +0000 | [diff] [blame] | 81 | if (!ValueMap.count(I)) |
| 82 | ValueMap[I] = Reg; |
| 83 | else |
| 84 | TII.copyRegToReg(*MBB, MBB->end(), ValueMap[I], |
| 85 | Reg, MRI.getRegClass(Reg), MRI.getRegClass(Reg)); |
| 86 | } |
| 87 | |
Dan Gohman | bdedd44 | 2008-08-20 00:11:48 +0000 | [diff] [blame] | 88 | /// SelectBinaryOp - Select and emit code for a binary operator instruction, |
| 89 | /// which has an opcode which directly corresponds to the given ISD opcode. |
| 90 | /// |
Dan Gohman | 3df24e6 | 2008-09-03 23:12:08 +0000 | [diff] [blame^] | 91 | bool FastISel::SelectBinaryOp(Instruction *I, ISD::NodeType ISDOpcode) { |
Dan Gohman | bdedd44 | 2008-08-20 00:11:48 +0000 | [diff] [blame] | 92 | MVT VT = MVT::getMVT(I->getType(), /*HandleUnknown=*/true); |
| 93 | if (VT == MVT::Other || !VT.isSimple()) |
| 94 | // Unhandled type. Halt "fast" selection and bail. |
| 95 | return false; |
Dan Gohman | b71fea2 | 2008-08-26 20:52:40 +0000 | [diff] [blame] | 96 | // We only handle legal types. For example, on x86-32 the instruction |
| 97 | // selector contains all of the 64-bit instructions from x86-64, |
| 98 | // under the assumption that i64 won't be used if the target doesn't |
| 99 | // support it. |
| 100 | if (!TLI.isTypeLegal(VT)) |
| 101 | return false; |
Dan Gohman | bdedd44 | 2008-08-20 00:11:48 +0000 | [diff] [blame] | 102 | |
Dan Gohman | 3df24e6 | 2008-09-03 23:12:08 +0000 | [diff] [blame^] | 103 | unsigned Op0 = getRegForValue(I->getOperand(0)); |
Dan Gohman | d5fe57d | 2008-08-21 01:41:07 +0000 | [diff] [blame] | 104 | if (Op0 == 0) |
| 105 | // Unhandled operand. Halt "fast" selection and bail. |
| 106 | return false; |
| 107 | |
| 108 | // Check if the second operand is a constant and handle it appropriately. |
| 109 | if (ConstantInt *CI = dyn_cast<ConstantInt>(I->getOperand(1))) { |
Dan Gohman | ad368ac | 2008-08-27 18:10:19 +0000 | [diff] [blame] | 110 | unsigned ResultReg = FastEmit_ri(VT.getSimpleVT(), VT.getSimpleVT(), |
| 111 | ISDOpcode, Op0, CI->getZExtValue()); |
| 112 | if (ResultReg != 0) { |
| 113 | // We successfully emitted code for the given LLVM Instruction. |
Dan Gohman | 3df24e6 | 2008-09-03 23:12:08 +0000 | [diff] [blame^] | 114 | UpdateValueMap(I, ResultReg); |
Dan Gohman | ad368ac | 2008-08-27 18:10:19 +0000 | [diff] [blame] | 115 | return true; |
| 116 | } |
Dan Gohman | d5fe57d | 2008-08-21 01:41:07 +0000 | [diff] [blame] | 117 | } |
| 118 | |
Dan Gohman | 10df0fa | 2008-08-27 01:09:54 +0000 | [diff] [blame] | 119 | // Check if the second operand is a constant float. |
| 120 | if (ConstantFP *CF = dyn_cast<ConstantFP>(I->getOperand(1))) { |
Dan Gohman | ad368ac | 2008-08-27 18:10:19 +0000 | [diff] [blame] | 121 | unsigned ResultReg = FastEmit_rf(VT.getSimpleVT(), VT.getSimpleVT(), |
| 122 | ISDOpcode, Op0, CF); |
| 123 | if (ResultReg != 0) { |
| 124 | // We successfully emitted code for the given LLVM Instruction. |
Dan Gohman | 3df24e6 | 2008-09-03 23:12:08 +0000 | [diff] [blame^] | 125 | UpdateValueMap(I, ResultReg); |
Dan Gohman | ad368ac | 2008-08-27 18:10:19 +0000 | [diff] [blame] | 126 | return true; |
| 127 | } |
Dan Gohman | 10df0fa | 2008-08-27 01:09:54 +0000 | [diff] [blame] | 128 | } |
| 129 | |
Dan Gohman | 3df24e6 | 2008-09-03 23:12:08 +0000 | [diff] [blame^] | 130 | unsigned Op1 = getRegForValue(I->getOperand(1)); |
Dan Gohman | d5fe57d | 2008-08-21 01:41:07 +0000 | [diff] [blame] | 131 | if (Op1 == 0) |
| 132 | // Unhandled operand. Halt "fast" selection and bail. |
| 133 | return false; |
| 134 | |
Dan Gohman | ad368ac | 2008-08-27 18:10:19 +0000 | [diff] [blame] | 135 | // Now we have both operands in registers. Emit the instruction. |
Owen Anderson | 0f84e4e | 2008-08-25 23:58:18 +0000 | [diff] [blame] | 136 | unsigned ResultReg = FastEmit_rr(VT.getSimpleVT(), VT.getSimpleVT(), |
| 137 | ISDOpcode, Op0, Op1); |
Dan Gohman | bdedd44 | 2008-08-20 00:11:48 +0000 | [diff] [blame] | 138 | if (ResultReg == 0) |
| 139 | // Target-specific code wasn't able to find a machine opcode for |
| 140 | // the given ISD opcode and type. Halt "fast" selection and bail. |
| 141 | return false; |
| 142 | |
Dan Gohman | 8014e86 | 2008-08-20 00:23:20 +0000 | [diff] [blame] | 143 | // We successfully emitted code for the given LLVM Instruction. |
Dan Gohman | 3df24e6 | 2008-09-03 23:12:08 +0000 | [diff] [blame^] | 144 | UpdateValueMap(I, ResultReg); |
Dan Gohman | bdedd44 | 2008-08-20 00:11:48 +0000 | [diff] [blame] | 145 | return true; |
| 146 | } |
| 147 | |
Dan Gohman | 3df24e6 | 2008-09-03 23:12:08 +0000 | [diff] [blame^] | 148 | bool FastISel::SelectGetElementPtr(Instruction *I) { |
| 149 | unsigned N = getRegForValue(I->getOperand(0)); |
Evan Cheng | 83785c8 | 2008-08-20 22:45:34 +0000 | [diff] [blame] | 150 | if (N == 0) |
| 151 | // Unhandled operand. Halt "fast" selection and bail. |
| 152 | return false; |
| 153 | |
| 154 | const Type *Ty = I->getOperand(0)->getType(); |
Dan Gohman | 7a0e659 | 2008-08-21 17:25:26 +0000 | [diff] [blame] | 155 | MVT::SimpleValueType VT = TLI.getPointerTy().getSimpleVT(); |
Evan Cheng | 83785c8 | 2008-08-20 22:45:34 +0000 | [diff] [blame] | 156 | for (GetElementPtrInst::op_iterator OI = I->op_begin()+1, E = I->op_end(); |
| 157 | OI != E; ++OI) { |
| 158 | Value *Idx = *OI; |
| 159 | if (const StructType *StTy = dyn_cast<StructType>(Ty)) { |
| 160 | unsigned Field = cast<ConstantInt>(Idx)->getZExtValue(); |
| 161 | if (Field) { |
| 162 | // N = N + Offset |
| 163 | uint64_t Offs = TD.getStructLayout(StTy)->getElementOffset(Field); |
| 164 | // FIXME: This can be optimized by combining the add with a |
| 165 | // subsequent one. |
Dan Gohman | 7a0e659 | 2008-08-21 17:25:26 +0000 | [diff] [blame] | 166 | N = FastEmit_ri_(VT, ISD::ADD, N, Offs, VT); |
Evan Cheng | 83785c8 | 2008-08-20 22:45:34 +0000 | [diff] [blame] | 167 | if (N == 0) |
| 168 | // Unhandled operand. Halt "fast" selection and bail. |
| 169 | return false; |
| 170 | } |
| 171 | Ty = StTy->getElementType(Field); |
| 172 | } else { |
| 173 | Ty = cast<SequentialType>(Ty)->getElementType(); |
| 174 | |
| 175 | // If this is a constant subscript, handle it quickly. |
| 176 | if (ConstantInt *CI = dyn_cast<ConstantInt>(Idx)) { |
| 177 | if (CI->getZExtValue() == 0) continue; |
| 178 | uint64_t Offs = |
| 179 | TD.getABITypeSize(Ty)*cast<ConstantInt>(CI)->getSExtValue(); |
Dan Gohman | 7a0e659 | 2008-08-21 17:25:26 +0000 | [diff] [blame] | 180 | N = FastEmit_ri_(VT, ISD::ADD, N, Offs, VT); |
Evan Cheng | 83785c8 | 2008-08-20 22:45:34 +0000 | [diff] [blame] | 181 | if (N == 0) |
| 182 | // Unhandled operand. Halt "fast" selection and bail. |
| 183 | return false; |
| 184 | continue; |
| 185 | } |
| 186 | |
| 187 | // N = N + Idx * ElementSize; |
| 188 | uint64_t ElementSize = TD.getABITypeSize(Ty); |
Dan Gohman | 3df24e6 | 2008-09-03 23:12:08 +0000 | [diff] [blame^] | 189 | unsigned IdxN = getRegForValue(Idx); |
Evan Cheng | 83785c8 | 2008-08-20 22:45:34 +0000 | [diff] [blame] | 190 | if (IdxN == 0) |
| 191 | // Unhandled operand. Halt "fast" selection and bail. |
| 192 | return false; |
| 193 | |
| 194 | // If the index is smaller or larger than intptr_t, truncate or extend |
| 195 | // it. |
Evan Cheng | 2076aa8 | 2008-08-21 01:19:11 +0000 | [diff] [blame] | 196 | MVT IdxVT = MVT::getMVT(Idx->getType(), /*HandleUnknown=*/false); |
Evan Cheng | 83785c8 | 2008-08-20 22:45:34 +0000 | [diff] [blame] | 197 | if (IdxVT.bitsLT(VT)) |
Dan Gohman | 80bc6e2 | 2008-08-26 20:57:08 +0000 | [diff] [blame] | 198 | IdxN = FastEmit_r(IdxVT.getSimpleVT(), VT, ISD::SIGN_EXTEND, IdxN); |
Evan Cheng | 83785c8 | 2008-08-20 22:45:34 +0000 | [diff] [blame] | 199 | else if (IdxVT.bitsGT(VT)) |
Dan Gohman | 80bc6e2 | 2008-08-26 20:57:08 +0000 | [diff] [blame] | 200 | IdxN = FastEmit_r(IdxVT.getSimpleVT(), VT, ISD::TRUNCATE, IdxN); |
Evan Cheng | 83785c8 | 2008-08-20 22:45:34 +0000 | [diff] [blame] | 201 | if (IdxN == 0) |
| 202 | // Unhandled operand. Halt "fast" selection and bail. |
| 203 | return false; |
| 204 | |
Dan Gohman | 80bc6e2 | 2008-08-26 20:57:08 +0000 | [diff] [blame] | 205 | if (ElementSize != 1) { |
Dan Gohman | f93cf79 | 2008-08-21 17:37:05 +0000 | [diff] [blame] | 206 | IdxN = FastEmit_ri_(VT, ISD::MUL, IdxN, ElementSize, VT); |
Dan Gohman | 80bc6e2 | 2008-08-26 20:57:08 +0000 | [diff] [blame] | 207 | if (IdxN == 0) |
| 208 | // Unhandled operand. Halt "fast" selection and bail. |
| 209 | return false; |
| 210 | } |
Owen Anderson | 0f84e4e | 2008-08-25 23:58:18 +0000 | [diff] [blame] | 211 | N = FastEmit_rr(VT, VT, ISD::ADD, N, IdxN); |
Evan Cheng | 83785c8 | 2008-08-20 22:45:34 +0000 | [diff] [blame] | 212 | if (N == 0) |
| 213 | // Unhandled operand. Halt "fast" selection and bail. |
| 214 | return false; |
| 215 | } |
| 216 | } |
| 217 | |
| 218 | // We successfully emitted code for the given LLVM Instruction. |
Dan Gohman | 3df24e6 | 2008-09-03 23:12:08 +0000 | [diff] [blame^] | 219 | UpdateValueMap(I, N); |
Evan Cheng | 83785c8 | 2008-08-20 22:45:34 +0000 | [diff] [blame] | 220 | return true; |
Dan Gohman | bdedd44 | 2008-08-20 00:11:48 +0000 | [diff] [blame] | 221 | } |
| 222 | |
Dan Gohman | 3df24e6 | 2008-09-03 23:12:08 +0000 | [diff] [blame^] | 223 | bool FastISel::SelectCast(Instruction *I, ISD::NodeType Opcode) { |
Owen Anderson | 6336b70 | 2008-08-27 18:58:30 +0000 | [diff] [blame] | 224 | MVT SrcVT = TLI.getValueType(I->getOperand(0)->getType()); |
| 225 | MVT DstVT = TLI.getValueType(I->getType()); |
Owen Anderson | d0533c9 | 2008-08-26 23:46:32 +0000 | [diff] [blame] | 226 | |
| 227 | if (SrcVT == MVT::Other || !SrcVT.isSimple() || |
| 228 | DstVT == MVT::Other || !DstVT.isSimple() || |
| 229 | !TLI.isTypeLegal(SrcVT) || !TLI.isTypeLegal(DstVT)) |
| 230 | // Unhandled type. Halt "fast" selection and bail. |
| 231 | return false; |
| 232 | |
Dan Gohman | 3df24e6 | 2008-09-03 23:12:08 +0000 | [diff] [blame^] | 233 | unsigned InputReg = getRegForValue(I->getOperand(0)); |
Owen Anderson | d0533c9 | 2008-08-26 23:46:32 +0000 | [diff] [blame] | 234 | if (!InputReg) |
| 235 | // Unhandled operand. Halt "fast" selection and bail. |
| 236 | return false; |
| 237 | |
| 238 | unsigned ResultReg = FastEmit_r(SrcVT.getSimpleVT(), |
| 239 | DstVT.getSimpleVT(), |
| 240 | Opcode, |
| 241 | InputReg); |
| 242 | if (!ResultReg) |
| 243 | return false; |
| 244 | |
Dan Gohman | 3df24e6 | 2008-09-03 23:12:08 +0000 | [diff] [blame^] | 245 | UpdateValueMap(I, ResultReg); |
Owen Anderson | d0533c9 | 2008-08-26 23:46:32 +0000 | [diff] [blame] | 246 | return true; |
| 247 | } |
| 248 | |
Dan Gohman | 3df24e6 | 2008-09-03 23:12:08 +0000 | [diff] [blame^] | 249 | bool FastISel::SelectBitCast(Instruction *I) { |
Dan Gohman | ad368ac | 2008-08-27 18:10:19 +0000 | [diff] [blame] | 250 | // If the bitcast doesn't change the type, just use the operand value. |
| 251 | if (I->getType() == I->getOperand(0)->getType()) { |
Dan Gohman | 3df24e6 | 2008-09-03 23:12:08 +0000 | [diff] [blame^] | 252 | unsigned Reg = getRegForValue(I->getOperand(0)); |
Dan Gohman | a318dab | 2008-08-27 20:41:38 +0000 | [diff] [blame] | 253 | if (Reg == 0) |
| 254 | return false; |
Dan Gohman | 3df24e6 | 2008-09-03 23:12:08 +0000 | [diff] [blame^] | 255 | UpdateValueMap(I, Reg); |
Dan Gohman | ad368ac | 2008-08-27 18:10:19 +0000 | [diff] [blame] | 256 | return true; |
| 257 | } |
| 258 | |
| 259 | // Bitcasts of other values become reg-reg copies or BIT_CONVERT operators. |
Owen Anderson | 6336b70 | 2008-08-27 18:58:30 +0000 | [diff] [blame] | 260 | MVT SrcVT = TLI.getValueType(I->getOperand(0)->getType()); |
| 261 | MVT DstVT = TLI.getValueType(I->getType()); |
Owen Anderson | d0533c9 | 2008-08-26 23:46:32 +0000 | [diff] [blame] | 262 | |
| 263 | if (SrcVT == MVT::Other || !SrcVT.isSimple() || |
| 264 | DstVT == MVT::Other || !DstVT.isSimple() || |
| 265 | !TLI.isTypeLegal(SrcVT) || !TLI.isTypeLegal(DstVT)) |
| 266 | // Unhandled type. Halt "fast" selection and bail. |
| 267 | return false; |
| 268 | |
Dan Gohman | 3df24e6 | 2008-09-03 23:12:08 +0000 | [diff] [blame^] | 269 | unsigned Op0 = getRegForValue(I->getOperand(0)); |
Dan Gohman | ad368ac | 2008-08-27 18:10:19 +0000 | [diff] [blame] | 270 | if (Op0 == 0) |
| 271 | // Unhandled operand. Halt "fast" selection and bail. |
Owen Anderson | d0533c9 | 2008-08-26 23:46:32 +0000 | [diff] [blame] | 272 | return false; |
| 273 | |
Dan Gohman | ad368ac | 2008-08-27 18:10:19 +0000 | [diff] [blame] | 274 | // First, try to perform the bitcast by inserting a reg-reg copy. |
| 275 | unsigned ResultReg = 0; |
| 276 | if (SrcVT.getSimpleVT() == DstVT.getSimpleVT()) { |
| 277 | TargetRegisterClass* SrcClass = TLI.getRegClassFor(SrcVT); |
| 278 | TargetRegisterClass* DstClass = TLI.getRegClassFor(DstVT); |
| 279 | ResultReg = createResultReg(DstClass); |
| 280 | |
| 281 | bool InsertedCopy = TII.copyRegToReg(*MBB, MBB->end(), ResultReg, |
| 282 | Op0, DstClass, SrcClass); |
| 283 | if (!InsertedCopy) |
| 284 | ResultReg = 0; |
| 285 | } |
| 286 | |
| 287 | // If the reg-reg copy failed, select a BIT_CONVERT opcode. |
| 288 | if (!ResultReg) |
| 289 | ResultReg = FastEmit_r(SrcVT.getSimpleVT(), DstVT.getSimpleVT(), |
| 290 | ISD::BIT_CONVERT, Op0); |
| 291 | |
| 292 | if (!ResultReg) |
Owen Anderson | d0533c9 | 2008-08-26 23:46:32 +0000 | [diff] [blame] | 293 | return false; |
| 294 | |
Dan Gohman | 3df24e6 | 2008-09-03 23:12:08 +0000 | [diff] [blame^] | 295 | UpdateValueMap(I, ResultReg); |
Owen Anderson | d0533c9 | 2008-08-26 23:46:32 +0000 | [diff] [blame] | 296 | return true; |
| 297 | } |
| 298 | |
Dan Gohman | 3df24e6 | 2008-09-03 23:12:08 +0000 | [diff] [blame^] | 299 | bool |
| 300 | FastISel::SelectInstruction(Instruction *I) { |
| 301 | switch (I->getOpcode()) { |
| 302 | case Instruction::Add: { |
| 303 | ISD::NodeType Opc = I->getType()->isFPOrFPVector() ? ISD::FADD : ISD::ADD; |
| 304 | return SelectBinaryOp(I, Opc); |
| 305 | } |
| 306 | case Instruction::Sub: { |
| 307 | ISD::NodeType Opc = I->getType()->isFPOrFPVector() ? ISD::FSUB : ISD::SUB; |
| 308 | return SelectBinaryOp(I, Opc); |
| 309 | } |
| 310 | case Instruction::Mul: { |
| 311 | ISD::NodeType Opc = I->getType()->isFPOrFPVector() ? ISD::FMUL : ISD::MUL; |
| 312 | return SelectBinaryOp(I, Opc); |
| 313 | } |
| 314 | case Instruction::SDiv: |
| 315 | return SelectBinaryOp(I, ISD::SDIV); |
| 316 | case Instruction::UDiv: |
| 317 | return SelectBinaryOp(I, ISD::UDIV); |
| 318 | case Instruction::FDiv: |
| 319 | return SelectBinaryOp(I, ISD::FDIV); |
| 320 | case Instruction::SRem: |
| 321 | return SelectBinaryOp(I, ISD::SREM); |
| 322 | case Instruction::URem: |
| 323 | return SelectBinaryOp(I, ISD::UREM); |
| 324 | case Instruction::FRem: |
| 325 | return SelectBinaryOp(I, ISD::FREM); |
| 326 | case Instruction::Shl: |
| 327 | return SelectBinaryOp(I, ISD::SHL); |
| 328 | case Instruction::LShr: |
| 329 | return SelectBinaryOp(I, ISD::SRL); |
| 330 | case Instruction::AShr: |
| 331 | return SelectBinaryOp(I, ISD::SRA); |
| 332 | case Instruction::And: |
| 333 | return SelectBinaryOp(I, ISD::AND); |
| 334 | case Instruction::Or: |
| 335 | return SelectBinaryOp(I, ISD::OR); |
| 336 | case Instruction::Xor: |
| 337 | return SelectBinaryOp(I, ISD::XOR); |
Dan Gohman | b0cf29c | 2008-08-13 20:19:35 +0000 | [diff] [blame] | 338 | |
Dan Gohman | 3df24e6 | 2008-09-03 23:12:08 +0000 | [diff] [blame^] | 339 | case Instruction::GetElementPtr: |
| 340 | return SelectGetElementPtr(I); |
Dan Gohman | bdedd44 | 2008-08-20 00:11:48 +0000 | [diff] [blame] | 341 | |
Dan Gohman | 3df24e6 | 2008-09-03 23:12:08 +0000 | [diff] [blame^] | 342 | case Instruction::Br: { |
| 343 | BranchInst *BI = cast<BranchInst>(I); |
Dan Gohman | bdedd44 | 2008-08-20 00:11:48 +0000 | [diff] [blame] | 344 | |
Dan Gohman | 3df24e6 | 2008-09-03 23:12:08 +0000 | [diff] [blame^] | 345 | if (BI->isUnconditional()) { |
| 346 | MachineFunction::iterator NextMBB = |
| 347 | next(MachineFunction::iterator(MBB)); |
| 348 | BasicBlock *LLVMSucc = BI->getSuccessor(0); |
| 349 | MachineBasicBlock *MSucc = MBBMap[LLVMSucc]; |
Dan Gohman | 6f2766d | 2008-08-19 22:31:46 +0000 | [diff] [blame] | 350 | |
Dan Gohman | 3df24e6 | 2008-09-03 23:12:08 +0000 | [diff] [blame^] | 351 | if (NextMBB != MF.end() && MSucc == NextMBB) { |
| 352 | // The unconditional fall-through case, which needs no instructions. |
Owen Anderson | 9d5b416 | 2008-08-27 00:31:01 +0000 | [diff] [blame] | 353 | } else { |
Dan Gohman | 3df24e6 | 2008-09-03 23:12:08 +0000 | [diff] [blame^] | 354 | // The unconditional branch case. |
| 355 | TII.InsertBranch(*MBB, MSucc, NULL, SmallVector<MachineOperand, 0>()); |
Owen Anderson | 9d5b416 | 2008-08-27 00:31:01 +0000 | [diff] [blame] | 356 | } |
Dan Gohman | 3df24e6 | 2008-09-03 23:12:08 +0000 | [diff] [blame^] | 357 | MBB->addSuccessor(MSucc); |
| 358 | return true; |
Owen Anderson | 9d5b416 | 2008-08-27 00:31:01 +0000 | [diff] [blame] | 359 | } |
Dan Gohman | 3df24e6 | 2008-09-03 23:12:08 +0000 | [diff] [blame^] | 360 | |
| 361 | // Conditional branches are not handed yet. |
| 362 | // Halt "fast" selection and bail. |
| 363 | return false; |
Dan Gohman | b0cf29c | 2008-08-13 20:19:35 +0000 | [diff] [blame] | 364 | } |
| 365 | |
Dan Gohman | 3df24e6 | 2008-09-03 23:12:08 +0000 | [diff] [blame^] | 366 | case Instruction::PHI: |
| 367 | // PHI nodes are already emitted. |
| 368 | return true; |
| 369 | |
| 370 | case Instruction::BitCast: |
| 371 | return SelectBitCast(I); |
| 372 | |
| 373 | case Instruction::FPToSI: |
| 374 | return SelectCast(I, ISD::FP_TO_SINT); |
| 375 | case Instruction::ZExt: |
| 376 | return SelectCast(I, ISD::ZERO_EXTEND); |
| 377 | case Instruction::SExt: |
| 378 | return SelectCast(I, ISD::SIGN_EXTEND); |
| 379 | case Instruction::Trunc: |
| 380 | return SelectCast(I, ISD::TRUNCATE); |
| 381 | case Instruction::SIToFP: |
| 382 | return SelectCast(I, ISD::SINT_TO_FP); |
| 383 | |
| 384 | case Instruction::IntToPtr: // Deliberate fall-through. |
| 385 | case Instruction::PtrToInt: { |
| 386 | MVT SrcVT = TLI.getValueType(I->getOperand(0)->getType()); |
| 387 | MVT DstVT = TLI.getValueType(I->getType()); |
| 388 | if (DstVT.bitsGT(SrcVT)) |
| 389 | return SelectCast(I, ISD::ZERO_EXTEND); |
| 390 | if (DstVT.bitsLT(SrcVT)) |
| 391 | return SelectCast(I, ISD::TRUNCATE); |
| 392 | unsigned Reg = getRegForValue(I->getOperand(0)); |
| 393 | if (Reg == 0) return false; |
| 394 | UpdateValueMap(I, Reg); |
| 395 | return true; |
| 396 | } |
| 397 | |
| 398 | default: |
| 399 | // Unhandled instruction. Halt "fast" selection and bail. |
| 400 | return false; |
| 401 | } |
Dan Gohman | b0cf29c | 2008-08-13 20:19:35 +0000 | [diff] [blame] | 402 | } |
| 403 | |
Dan Gohman | 3df24e6 | 2008-09-03 23:12:08 +0000 | [diff] [blame^] | 404 | FastISel::FastISel(MachineFunction &mf, |
| 405 | DenseMap<const Value *, unsigned> &vm, |
| 406 | DenseMap<const BasicBlock *, MachineBasicBlock *> &bm) |
| 407 | : MBB(0), |
| 408 | ValueMap(vm), |
| 409 | MBBMap(bm), |
| 410 | MF(mf), |
| 411 | MRI(MF.getRegInfo()), |
| 412 | TM(MF.getTarget()), |
Dan Gohman | 22bb311 | 2008-08-22 00:20:26 +0000 | [diff] [blame] | 413 | TD(*TM.getTargetData()), |
| 414 | TII(*TM.getInstrInfo()), |
| 415 | TLI(*TM.getTargetLowering()) { |
Dan Gohman | bb46633 | 2008-08-20 21:05:57 +0000 | [diff] [blame] | 416 | } |
| 417 | |
Dan Gohman | e285a74 | 2008-08-14 21:51:29 +0000 | [diff] [blame] | 418 | FastISel::~FastISel() {} |
| 419 | |
Evan Cheng | 36fd941 | 2008-09-02 21:59:13 +0000 | [diff] [blame] | 420 | unsigned FastISel::FastEmit_(MVT::SimpleValueType, MVT::SimpleValueType, |
| 421 | ISD::NodeType) { |
Dan Gohman | b0cf29c | 2008-08-13 20:19:35 +0000 | [diff] [blame] | 422 | return 0; |
| 423 | } |
| 424 | |
Owen Anderson | 0f84e4e | 2008-08-25 23:58:18 +0000 | [diff] [blame] | 425 | unsigned FastISel::FastEmit_r(MVT::SimpleValueType, MVT::SimpleValueType, |
| 426 | ISD::NodeType, unsigned /*Op0*/) { |
Dan Gohman | b0cf29c | 2008-08-13 20:19:35 +0000 | [diff] [blame] | 427 | return 0; |
| 428 | } |
| 429 | |
Owen Anderson | 0f84e4e | 2008-08-25 23:58:18 +0000 | [diff] [blame] | 430 | unsigned FastISel::FastEmit_rr(MVT::SimpleValueType, MVT::SimpleValueType, |
| 431 | ISD::NodeType, unsigned /*Op0*/, |
| 432 | unsigned /*Op0*/) { |
Dan Gohman | b0cf29c | 2008-08-13 20:19:35 +0000 | [diff] [blame] | 433 | return 0; |
| 434 | } |
| 435 | |
Owen Anderson | 0f84e4e | 2008-08-25 23:58:18 +0000 | [diff] [blame] | 436 | unsigned FastISel::FastEmit_i(MVT::SimpleValueType, MVT::SimpleValueType, |
| 437 | ISD::NodeType, uint64_t /*Imm*/) { |
Evan Cheng | 83785c8 | 2008-08-20 22:45:34 +0000 | [diff] [blame] | 438 | return 0; |
| 439 | } |
| 440 | |
Dan Gohman | 10df0fa | 2008-08-27 01:09:54 +0000 | [diff] [blame] | 441 | unsigned FastISel::FastEmit_f(MVT::SimpleValueType, MVT::SimpleValueType, |
| 442 | ISD::NodeType, ConstantFP * /*FPImm*/) { |
| 443 | return 0; |
| 444 | } |
| 445 | |
Owen Anderson | 0f84e4e | 2008-08-25 23:58:18 +0000 | [diff] [blame] | 446 | unsigned FastISel::FastEmit_ri(MVT::SimpleValueType, MVT::SimpleValueType, |
| 447 | ISD::NodeType, unsigned /*Op0*/, |
| 448 | uint64_t /*Imm*/) { |
Dan Gohman | d5fe57d | 2008-08-21 01:41:07 +0000 | [diff] [blame] | 449 | return 0; |
| 450 | } |
| 451 | |
Dan Gohman | 10df0fa | 2008-08-27 01:09:54 +0000 | [diff] [blame] | 452 | unsigned FastISel::FastEmit_rf(MVT::SimpleValueType, MVT::SimpleValueType, |
| 453 | ISD::NodeType, unsigned /*Op0*/, |
| 454 | ConstantFP * /*FPImm*/) { |
| 455 | return 0; |
| 456 | } |
| 457 | |
Owen Anderson | 0f84e4e | 2008-08-25 23:58:18 +0000 | [diff] [blame] | 458 | unsigned FastISel::FastEmit_rri(MVT::SimpleValueType, MVT::SimpleValueType, |
| 459 | ISD::NodeType, |
Dan Gohman | d5fe57d | 2008-08-21 01:41:07 +0000 | [diff] [blame] | 460 | unsigned /*Op0*/, unsigned /*Op1*/, |
| 461 | uint64_t /*Imm*/) { |
Evan Cheng | 83785c8 | 2008-08-20 22:45:34 +0000 | [diff] [blame] | 462 | return 0; |
| 463 | } |
| 464 | |
| 465 | /// FastEmit_ri_ - This method is a wrapper of FastEmit_ri. It first tries |
| 466 | /// to emit an instruction with an immediate operand using FastEmit_ri. |
| 467 | /// If that fails, it materializes the immediate into a register and try |
| 468 | /// FastEmit_rr instead. |
| 469 | unsigned FastISel::FastEmit_ri_(MVT::SimpleValueType VT, ISD::NodeType Opcode, |
Dan Gohman | d5fe57d | 2008-08-21 01:41:07 +0000 | [diff] [blame] | 470 | unsigned Op0, uint64_t Imm, |
| 471 | MVT::SimpleValueType ImmType) { |
Evan Cheng | 83785c8 | 2008-08-20 22:45:34 +0000 | [diff] [blame] | 472 | // First check if immediate type is legal. If not, we can't use the ri form. |
Dan Gohman | 151ed61 | 2008-08-27 18:15:05 +0000 | [diff] [blame] | 473 | unsigned ResultReg = FastEmit_ri(VT, VT, Opcode, Op0, Imm); |
Evan Cheng | 83785c8 | 2008-08-20 22:45:34 +0000 | [diff] [blame] | 474 | if (ResultReg != 0) |
| 475 | return ResultReg; |
Owen Anderson | 0f84e4e | 2008-08-25 23:58:18 +0000 | [diff] [blame] | 476 | unsigned MaterialReg = FastEmit_i(ImmType, ImmType, ISD::Constant, Imm); |
Dan Gohman | d5fe57d | 2008-08-21 01:41:07 +0000 | [diff] [blame] | 477 | if (MaterialReg == 0) |
| 478 | return 0; |
Owen Anderson | 0f84e4e | 2008-08-25 23:58:18 +0000 | [diff] [blame] | 479 | return FastEmit_rr(VT, VT, Opcode, Op0, MaterialReg); |
Dan Gohman | d5fe57d | 2008-08-21 01:41:07 +0000 | [diff] [blame] | 480 | } |
| 481 | |
Dan Gohman | 10df0fa | 2008-08-27 01:09:54 +0000 | [diff] [blame] | 482 | /// FastEmit_rf_ - This method is a wrapper of FastEmit_ri. It first tries |
| 483 | /// to emit an instruction with a floating-point immediate operand using |
| 484 | /// FastEmit_rf. If that fails, it materializes the immediate into a register |
| 485 | /// and try FastEmit_rr instead. |
| 486 | unsigned FastISel::FastEmit_rf_(MVT::SimpleValueType VT, ISD::NodeType Opcode, |
| 487 | unsigned Op0, ConstantFP *FPImm, |
| 488 | MVT::SimpleValueType ImmType) { |
Dan Gohman | 10df0fa | 2008-08-27 01:09:54 +0000 | [diff] [blame] | 489 | // First check if immediate type is legal. If not, we can't use the rf form. |
Dan Gohman | 151ed61 | 2008-08-27 18:15:05 +0000 | [diff] [blame] | 490 | unsigned ResultReg = FastEmit_rf(VT, VT, Opcode, Op0, FPImm); |
Dan Gohman | 10df0fa | 2008-08-27 01:09:54 +0000 | [diff] [blame] | 491 | if (ResultReg != 0) |
| 492 | return ResultReg; |
| 493 | |
| 494 | // Materialize the constant in a register. |
| 495 | unsigned MaterialReg = FastEmit_f(ImmType, ImmType, ISD::ConstantFP, FPImm); |
| 496 | if (MaterialReg == 0) { |
Dan Gohman | 96a9999 | 2008-08-27 18:01:42 +0000 | [diff] [blame] | 497 | // If the target doesn't have a way to directly enter a floating-point |
| 498 | // value into a register, use an alternate approach. |
| 499 | // TODO: The current approach only supports floating-point constants |
| 500 | // that can be constructed by conversion from integer values. This should |
| 501 | // be replaced by code that creates a load from a constant-pool entry, |
| 502 | // which will require some target-specific work. |
Dan Gohman | 10df0fa | 2008-08-27 01:09:54 +0000 | [diff] [blame] | 503 | const APFloat &Flt = FPImm->getValueAPF(); |
| 504 | MVT IntVT = TLI.getPointerTy(); |
| 505 | |
| 506 | uint64_t x[2]; |
| 507 | uint32_t IntBitWidth = IntVT.getSizeInBits(); |
| 508 | if (Flt.convertToInteger(x, IntBitWidth, /*isSigned=*/true, |
| 509 | APFloat::rmTowardZero) != APFloat::opOK) |
| 510 | return 0; |
| 511 | APInt IntVal(IntBitWidth, 2, x); |
| 512 | |
| 513 | unsigned IntegerReg = FastEmit_i(IntVT.getSimpleVT(), IntVT.getSimpleVT(), |
| 514 | ISD::Constant, IntVal.getZExtValue()); |
| 515 | if (IntegerReg == 0) |
| 516 | return 0; |
| 517 | MaterialReg = FastEmit_r(IntVT.getSimpleVT(), VT, |
| 518 | ISD::SINT_TO_FP, IntegerReg); |
| 519 | if (MaterialReg == 0) |
| 520 | return 0; |
| 521 | } |
| 522 | return FastEmit_rr(VT, VT, Opcode, Op0, MaterialReg); |
| 523 | } |
| 524 | |
Dan Gohman | d5fe57d | 2008-08-21 01:41:07 +0000 | [diff] [blame] | 525 | unsigned FastISel::createResultReg(const TargetRegisterClass* RC) { |
| 526 | return MRI.createVirtualRegister(RC); |
Evan Cheng | 83785c8 | 2008-08-20 22:45:34 +0000 | [diff] [blame] | 527 | } |
| 528 | |
Dan Gohman | b0cf29c | 2008-08-13 20:19:35 +0000 | [diff] [blame] | 529 | unsigned FastISel::FastEmitInst_(unsigned MachineInstOpcode, |
Dan Gohman | 77ad796 | 2008-08-20 18:09:38 +0000 | [diff] [blame] | 530 | const TargetRegisterClass* RC) { |
Dan Gohman | d5fe57d | 2008-08-21 01:41:07 +0000 | [diff] [blame] | 531 | unsigned ResultReg = createResultReg(RC); |
Dan Gohman | bb46633 | 2008-08-20 21:05:57 +0000 | [diff] [blame] | 532 | const TargetInstrDesc &II = TII.get(MachineInstOpcode); |
Dan Gohman | b0cf29c | 2008-08-13 20:19:35 +0000 | [diff] [blame] | 533 | |
Dan Gohman | fd90394 | 2008-08-20 23:53:10 +0000 | [diff] [blame] | 534 | BuildMI(MBB, II, ResultReg); |
Dan Gohman | b0cf29c | 2008-08-13 20:19:35 +0000 | [diff] [blame] | 535 | return ResultReg; |
| 536 | } |
| 537 | |
| 538 | unsigned FastISel::FastEmitInst_r(unsigned MachineInstOpcode, |
| 539 | const TargetRegisterClass *RC, |
| 540 | unsigned Op0) { |
Dan Gohman | d5fe57d | 2008-08-21 01:41:07 +0000 | [diff] [blame] | 541 | unsigned ResultReg = createResultReg(RC); |
Dan Gohman | bb46633 | 2008-08-20 21:05:57 +0000 | [diff] [blame] | 542 | const TargetInstrDesc &II = TII.get(MachineInstOpcode); |
Dan Gohman | b0cf29c | 2008-08-13 20:19:35 +0000 | [diff] [blame] | 543 | |
Dan Gohman | fd90394 | 2008-08-20 23:53:10 +0000 | [diff] [blame] | 544 | BuildMI(MBB, II, ResultReg).addReg(Op0); |
Dan Gohman | b0cf29c | 2008-08-13 20:19:35 +0000 | [diff] [blame] | 545 | return ResultReg; |
| 546 | } |
| 547 | |
| 548 | unsigned FastISel::FastEmitInst_rr(unsigned MachineInstOpcode, |
| 549 | const TargetRegisterClass *RC, |
| 550 | unsigned Op0, unsigned Op1) { |
Dan Gohman | d5fe57d | 2008-08-21 01:41:07 +0000 | [diff] [blame] | 551 | unsigned ResultReg = createResultReg(RC); |
Dan Gohman | bb46633 | 2008-08-20 21:05:57 +0000 | [diff] [blame] | 552 | const TargetInstrDesc &II = TII.get(MachineInstOpcode); |
Dan Gohman | b0cf29c | 2008-08-13 20:19:35 +0000 | [diff] [blame] | 553 | |
Dan Gohman | fd90394 | 2008-08-20 23:53:10 +0000 | [diff] [blame] | 554 | BuildMI(MBB, II, ResultReg).addReg(Op0).addReg(Op1); |
Dan Gohman | b0cf29c | 2008-08-13 20:19:35 +0000 | [diff] [blame] | 555 | return ResultReg; |
| 556 | } |
Dan Gohman | d5fe57d | 2008-08-21 01:41:07 +0000 | [diff] [blame] | 557 | |
| 558 | unsigned FastISel::FastEmitInst_ri(unsigned MachineInstOpcode, |
| 559 | const TargetRegisterClass *RC, |
| 560 | unsigned Op0, uint64_t Imm) { |
| 561 | unsigned ResultReg = createResultReg(RC); |
| 562 | const TargetInstrDesc &II = TII.get(MachineInstOpcode); |
| 563 | |
| 564 | BuildMI(MBB, II, ResultReg).addReg(Op0).addImm(Imm); |
| 565 | return ResultReg; |
| 566 | } |
| 567 | |
Dan Gohman | 10df0fa | 2008-08-27 01:09:54 +0000 | [diff] [blame] | 568 | unsigned FastISel::FastEmitInst_rf(unsigned MachineInstOpcode, |
| 569 | const TargetRegisterClass *RC, |
| 570 | unsigned Op0, ConstantFP *FPImm) { |
| 571 | unsigned ResultReg = createResultReg(RC); |
| 572 | const TargetInstrDesc &II = TII.get(MachineInstOpcode); |
| 573 | |
| 574 | BuildMI(MBB, II, ResultReg).addReg(Op0).addFPImm(FPImm); |
| 575 | return ResultReg; |
| 576 | } |
| 577 | |
Dan Gohman | d5fe57d | 2008-08-21 01:41:07 +0000 | [diff] [blame] | 578 | unsigned FastISel::FastEmitInst_rri(unsigned MachineInstOpcode, |
| 579 | const TargetRegisterClass *RC, |
| 580 | unsigned Op0, unsigned Op1, uint64_t Imm) { |
| 581 | unsigned ResultReg = createResultReg(RC); |
| 582 | const TargetInstrDesc &II = TII.get(MachineInstOpcode); |
| 583 | |
| 584 | BuildMI(MBB, II, ResultReg).addReg(Op0).addReg(Op1).addImm(Imm); |
| 585 | return ResultReg; |
| 586 | } |
Owen Anderson | 6d0c25e | 2008-08-25 20:20:32 +0000 | [diff] [blame] | 587 | |
| 588 | unsigned FastISel::FastEmitInst_i(unsigned MachineInstOpcode, |
| 589 | const TargetRegisterClass *RC, |
| 590 | uint64_t Imm) { |
| 591 | unsigned ResultReg = createResultReg(RC); |
| 592 | const TargetInstrDesc &II = TII.get(MachineInstOpcode); |
| 593 | |
| 594 | BuildMI(MBB, II, ResultReg).addImm(Imm); |
| 595 | return ResultReg; |
Evan Cheng | b41aec5 | 2008-08-25 22:20:39 +0000 | [diff] [blame] | 596 | } |
Owen Anderson | 8970f00 | 2008-08-27 22:30:02 +0000 | [diff] [blame] | 597 | |
Owen Anderson | 40a468f | 2008-08-28 17:47:37 +0000 | [diff] [blame] | 598 | unsigned FastISel::FastEmitInst_extractsubreg(unsigned Op0, uint32_t Idx) { |
| 599 | const TargetRegisterClass* RC = MRI.getRegClass(Op0); |
Owen Anderson | 8970f00 | 2008-08-27 22:30:02 +0000 | [diff] [blame] | 600 | const TargetRegisterClass* SRC = *(RC->subregclasses_begin()+Idx-1); |
| 601 | |
| 602 | unsigned ResultReg = createResultReg(SRC); |
| 603 | const TargetInstrDesc &II = TII.get(TargetInstrInfo::EXTRACT_SUBREG); |
| 604 | |
Owen Anderson | c0bb68b | 2008-08-28 18:26:01 +0000 | [diff] [blame] | 605 | BuildMI(MBB, II, ResultReg).addReg(Op0).addImm(Idx); |
Owen Anderson | 8970f00 | 2008-08-27 22:30:02 +0000 | [diff] [blame] | 606 | return ResultReg; |
| 607 | } |