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 | |
Dan Gohman | ad368ac | 2008-08-27 18:10:19 +0000 | [diff] [blame] | 24 | unsigned FastISel::getRegForValue(Value *V, DenseMap<const Value*, unsigned> &ValueMap) { |
| 25 | unsigned &Reg = ValueMap[V]; |
| 26 | if (Reg != 0) |
| 27 | return Reg; |
| 28 | |
| 29 | MVT::SimpleValueType VT = TLI.getValueType(V->getType()).getSimpleVT(); |
| 30 | if (ConstantInt *CI = dyn_cast<ConstantInt>(V)) { |
| 31 | if (CI->getValue().getActiveBits() > 64) |
| 32 | return 0; |
| 33 | Reg = FastEmit_i(VT, VT, ISD::Constant, CI->getZExtValue()); |
Dan Gohman | 205d925 | 2008-08-28 21:19:07 +0000 | [diff] [blame^] | 34 | } else if (isa<ConstantPointerNull>(V)) { |
| 35 | Reg = FastEmit_i(VT, VT, ISD::Constant, 0); |
Dan Gohman | ad368ac | 2008-08-27 18:10:19 +0000 | [diff] [blame] | 36 | } else if (ConstantFP *CF = dyn_cast<ConstantFP>(V)) { |
| 37 | Reg = FastEmit_f(VT, VT, ISD::ConstantFP, CF); |
| 38 | |
| 39 | if (!Reg) { |
| 40 | const APFloat &Flt = CF->getValueAPF(); |
| 41 | MVT IntVT = TLI.getPointerTy(); |
| 42 | |
| 43 | uint64_t x[2]; |
| 44 | uint32_t IntBitWidth = IntVT.getSizeInBits(); |
| 45 | if (Flt.convertToInteger(x, IntBitWidth, /*isSigned=*/true, |
| 46 | APFloat::rmTowardZero) != APFloat::opOK) |
| 47 | return 0; |
| 48 | APInt IntVal(IntBitWidth, 2, x); |
| 49 | |
| 50 | unsigned IntegerReg = FastEmit_i(IntVT.getSimpleVT(), IntVT.getSimpleVT(), |
| 51 | ISD::Constant, IntVal.getZExtValue()); |
| 52 | if (IntegerReg == 0) |
| 53 | return 0; |
| 54 | Reg = FastEmit_r(IntVT.getSimpleVT(), VT, ISD::SINT_TO_FP, IntegerReg); |
| 55 | if (Reg == 0) |
| 56 | return 0; |
| 57 | } |
Dan Gohman | 205d925 | 2008-08-28 21:19:07 +0000 | [diff] [blame^] | 58 | } else if (isa<UndefValue>(V)) { |
| 59 | Reg = createResultReg(TLI.getRegClassFor(VT)); |
| 60 | BuildMI(MBB, TII.get(TargetInstrInfo::IMPLICIT_DEF), Reg); |
Dan Gohman | ad368ac | 2008-08-27 18:10:19 +0000 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | return Reg; |
| 64 | } |
| 65 | |
Dan Gohman | bdedd44 | 2008-08-20 00:11:48 +0000 | [diff] [blame] | 66 | /// SelectBinaryOp - Select and emit code for a binary operator instruction, |
| 67 | /// which has an opcode which directly corresponds to the given ISD opcode. |
| 68 | /// |
| 69 | bool FastISel::SelectBinaryOp(Instruction *I, ISD::NodeType ISDOpcode, |
| 70 | DenseMap<const Value*, unsigned> &ValueMap) { |
Dan Gohman | bdedd44 | 2008-08-20 00:11:48 +0000 | [diff] [blame] | 71 | MVT VT = MVT::getMVT(I->getType(), /*HandleUnknown=*/true); |
| 72 | if (VT == MVT::Other || !VT.isSimple()) |
| 73 | // Unhandled type. Halt "fast" selection and bail. |
| 74 | return false; |
Dan Gohman | b71fea2 | 2008-08-26 20:52:40 +0000 | [diff] [blame] | 75 | // We only handle legal types. For example, on x86-32 the instruction |
| 76 | // selector contains all of the 64-bit instructions from x86-64, |
| 77 | // under the assumption that i64 won't be used if the target doesn't |
| 78 | // support it. |
| 79 | if (!TLI.isTypeLegal(VT)) |
| 80 | return false; |
Dan Gohman | bdedd44 | 2008-08-20 00:11:48 +0000 | [diff] [blame] | 81 | |
Dan Gohman | ad368ac | 2008-08-27 18:10:19 +0000 | [diff] [blame] | 82 | unsigned Op0 = getRegForValue(I->getOperand(0), ValueMap); |
Dan Gohman | d5fe57d | 2008-08-21 01:41:07 +0000 | [diff] [blame] | 83 | if (Op0 == 0) |
| 84 | // Unhandled operand. Halt "fast" selection and bail. |
| 85 | return false; |
| 86 | |
| 87 | // Check if the second operand is a constant and handle it appropriately. |
| 88 | if (ConstantInt *CI = dyn_cast<ConstantInt>(I->getOperand(1))) { |
Dan Gohman | ad368ac | 2008-08-27 18:10:19 +0000 | [diff] [blame] | 89 | unsigned ResultReg = FastEmit_ri(VT.getSimpleVT(), VT.getSimpleVT(), |
| 90 | ISDOpcode, Op0, CI->getZExtValue()); |
| 91 | if (ResultReg != 0) { |
| 92 | // We successfully emitted code for the given LLVM Instruction. |
| 93 | ValueMap[I] = ResultReg; |
| 94 | return true; |
| 95 | } |
Dan Gohman | d5fe57d | 2008-08-21 01:41:07 +0000 | [diff] [blame] | 96 | } |
| 97 | |
Dan Gohman | 10df0fa | 2008-08-27 01:09:54 +0000 | [diff] [blame] | 98 | // Check if the second operand is a constant float. |
| 99 | if (ConstantFP *CF = dyn_cast<ConstantFP>(I->getOperand(1))) { |
Dan Gohman | ad368ac | 2008-08-27 18:10:19 +0000 | [diff] [blame] | 100 | unsigned ResultReg = FastEmit_rf(VT.getSimpleVT(), VT.getSimpleVT(), |
| 101 | ISDOpcode, Op0, CF); |
| 102 | if (ResultReg != 0) { |
| 103 | // We successfully emitted code for the given LLVM Instruction. |
| 104 | ValueMap[I] = ResultReg; |
| 105 | return true; |
| 106 | } |
Dan Gohman | 10df0fa | 2008-08-27 01:09:54 +0000 | [diff] [blame] | 107 | } |
| 108 | |
Dan Gohman | ad368ac | 2008-08-27 18:10:19 +0000 | [diff] [blame] | 109 | unsigned Op1 = getRegForValue(I->getOperand(1), ValueMap); |
Dan Gohman | d5fe57d | 2008-08-21 01:41:07 +0000 | [diff] [blame] | 110 | if (Op1 == 0) |
| 111 | // Unhandled operand. Halt "fast" selection and bail. |
| 112 | return false; |
| 113 | |
Dan Gohman | ad368ac | 2008-08-27 18:10:19 +0000 | [diff] [blame] | 114 | // Now we have both operands in registers. Emit the instruction. |
Owen Anderson | 0f84e4e | 2008-08-25 23:58:18 +0000 | [diff] [blame] | 115 | unsigned ResultReg = FastEmit_rr(VT.getSimpleVT(), VT.getSimpleVT(), |
| 116 | ISDOpcode, Op0, Op1); |
Dan Gohman | bdedd44 | 2008-08-20 00:11:48 +0000 | [diff] [blame] | 117 | if (ResultReg == 0) |
| 118 | // Target-specific code wasn't able to find a machine opcode for |
| 119 | // the given ISD opcode and type. Halt "fast" selection and bail. |
| 120 | return false; |
| 121 | |
Dan Gohman | 8014e86 | 2008-08-20 00:23:20 +0000 | [diff] [blame] | 122 | // We successfully emitted code for the given LLVM Instruction. |
Dan Gohman | bdedd44 | 2008-08-20 00:11:48 +0000 | [diff] [blame] | 123 | ValueMap[I] = ResultReg; |
| 124 | return true; |
| 125 | } |
| 126 | |
| 127 | bool FastISel::SelectGetElementPtr(Instruction *I, |
| 128 | DenseMap<const Value*, unsigned> &ValueMap) { |
Dan Gohman | ad368ac | 2008-08-27 18:10:19 +0000 | [diff] [blame] | 129 | unsigned N = getRegForValue(I->getOperand(0), ValueMap); |
Evan Cheng | 83785c8 | 2008-08-20 22:45:34 +0000 | [diff] [blame] | 130 | if (N == 0) |
| 131 | // Unhandled operand. Halt "fast" selection and bail. |
| 132 | return false; |
| 133 | |
| 134 | const Type *Ty = I->getOperand(0)->getType(); |
Dan Gohman | 7a0e659 | 2008-08-21 17:25:26 +0000 | [diff] [blame] | 135 | MVT::SimpleValueType VT = TLI.getPointerTy().getSimpleVT(); |
Evan Cheng | 83785c8 | 2008-08-20 22:45:34 +0000 | [diff] [blame] | 136 | for (GetElementPtrInst::op_iterator OI = I->op_begin()+1, E = I->op_end(); |
| 137 | OI != E; ++OI) { |
| 138 | Value *Idx = *OI; |
| 139 | if (const StructType *StTy = dyn_cast<StructType>(Ty)) { |
| 140 | unsigned Field = cast<ConstantInt>(Idx)->getZExtValue(); |
| 141 | if (Field) { |
| 142 | // N = N + Offset |
| 143 | uint64_t Offs = TD.getStructLayout(StTy)->getElementOffset(Field); |
| 144 | // FIXME: This can be optimized by combining the add with a |
| 145 | // subsequent one. |
Dan Gohman | 7a0e659 | 2008-08-21 17:25:26 +0000 | [diff] [blame] | 146 | N = FastEmit_ri_(VT, ISD::ADD, N, Offs, VT); |
Evan Cheng | 83785c8 | 2008-08-20 22:45:34 +0000 | [diff] [blame] | 147 | if (N == 0) |
| 148 | // Unhandled operand. Halt "fast" selection and bail. |
| 149 | return false; |
| 150 | } |
| 151 | Ty = StTy->getElementType(Field); |
| 152 | } else { |
| 153 | Ty = cast<SequentialType>(Ty)->getElementType(); |
| 154 | |
| 155 | // If this is a constant subscript, handle it quickly. |
| 156 | if (ConstantInt *CI = dyn_cast<ConstantInt>(Idx)) { |
| 157 | if (CI->getZExtValue() == 0) continue; |
| 158 | uint64_t Offs = |
| 159 | TD.getABITypeSize(Ty)*cast<ConstantInt>(CI)->getSExtValue(); |
Dan Gohman | 7a0e659 | 2008-08-21 17:25:26 +0000 | [diff] [blame] | 160 | N = FastEmit_ri_(VT, ISD::ADD, N, Offs, VT); |
Evan Cheng | 83785c8 | 2008-08-20 22:45:34 +0000 | [diff] [blame] | 161 | if (N == 0) |
| 162 | // Unhandled operand. Halt "fast" selection and bail. |
| 163 | return false; |
| 164 | continue; |
| 165 | } |
| 166 | |
| 167 | // N = N + Idx * ElementSize; |
| 168 | uint64_t ElementSize = TD.getABITypeSize(Ty); |
Dan Gohman | ad368ac | 2008-08-27 18:10:19 +0000 | [diff] [blame] | 169 | unsigned IdxN = getRegForValue(Idx, ValueMap); |
Evan Cheng | 83785c8 | 2008-08-20 22:45:34 +0000 | [diff] [blame] | 170 | if (IdxN == 0) |
| 171 | // Unhandled operand. Halt "fast" selection and bail. |
| 172 | return false; |
| 173 | |
| 174 | // If the index is smaller or larger than intptr_t, truncate or extend |
| 175 | // it. |
Evan Cheng | 2076aa8 | 2008-08-21 01:19:11 +0000 | [diff] [blame] | 176 | MVT IdxVT = MVT::getMVT(Idx->getType(), /*HandleUnknown=*/false); |
Evan Cheng | 83785c8 | 2008-08-20 22:45:34 +0000 | [diff] [blame] | 177 | if (IdxVT.bitsLT(VT)) |
Dan Gohman | 80bc6e2 | 2008-08-26 20:57:08 +0000 | [diff] [blame] | 178 | IdxN = FastEmit_r(IdxVT.getSimpleVT(), VT, ISD::SIGN_EXTEND, IdxN); |
Evan Cheng | 83785c8 | 2008-08-20 22:45:34 +0000 | [diff] [blame] | 179 | else if (IdxVT.bitsGT(VT)) |
Dan Gohman | 80bc6e2 | 2008-08-26 20:57:08 +0000 | [diff] [blame] | 180 | IdxN = FastEmit_r(IdxVT.getSimpleVT(), VT, ISD::TRUNCATE, IdxN); |
Evan Cheng | 83785c8 | 2008-08-20 22:45:34 +0000 | [diff] [blame] | 181 | if (IdxN == 0) |
| 182 | // Unhandled operand. Halt "fast" selection and bail. |
| 183 | return false; |
| 184 | |
Dan Gohman | 80bc6e2 | 2008-08-26 20:57:08 +0000 | [diff] [blame] | 185 | if (ElementSize != 1) { |
Dan Gohman | f93cf79 | 2008-08-21 17:37:05 +0000 | [diff] [blame] | 186 | IdxN = FastEmit_ri_(VT, ISD::MUL, IdxN, ElementSize, VT); |
Dan Gohman | 80bc6e2 | 2008-08-26 20:57:08 +0000 | [diff] [blame] | 187 | if (IdxN == 0) |
| 188 | // Unhandled operand. Halt "fast" selection and bail. |
| 189 | return false; |
| 190 | } |
Owen Anderson | 0f84e4e | 2008-08-25 23:58:18 +0000 | [diff] [blame] | 191 | N = FastEmit_rr(VT, VT, ISD::ADD, N, IdxN); |
Evan Cheng | 83785c8 | 2008-08-20 22:45:34 +0000 | [diff] [blame] | 192 | if (N == 0) |
| 193 | // Unhandled operand. Halt "fast" selection and bail. |
| 194 | return false; |
| 195 | } |
| 196 | } |
| 197 | |
| 198 | // We successfully emitted code for the given LLVM Instruction. |
| 199 | ValueMap[I] = N; |
| 200 | return true; |
Dan Gohman | bdedd44 | 2008-08-20 00:11:48 +0000 | [diff] [blame] | 201 | } |
| 202 | |
Owen Anderson | d0533c9 | 2008-08-26 23:46:32 +0000 | [diff] [blame] | 203 | bool FastISel::SelectCast(Instruction *I, ISD::NodeType Opcode, |
| 204 | DenseMap<const Value*, unsigned> &ValueMap) { |
Owen Anderson | 6336b70 | 2008-08-27 18:58:30 +0000 | [diff] [blame] | 205 | MVT SrcVT = TLI.getValueType(I->getOperand(0)->getType()); |
| 206 | MVT DstVT = TLI.getValueType(I->getType()); |
Owen Anderson | d0533c9 | 2008-08-26 23:46:32 +0000 | [diff] [blame] | 207 | |
| 208 | if (SrcVT == MVT::Other || !SrcVT.isSimple() || |
| 209 | DstVT == MVT::Other || !DstVT.isSimple() || |
| 210 | !TLI.isTypeLegal(SrcVT) || !TLI.isTypeLegal(DstVT)) |
| 211 | // Unhandled type. Halt "fast" selection and bail. |
| 212 | return false; |
| 213 | |
Dan Gohman | ad368ac | 2008-08-27 18:10:19 +0000 | [diff] [blame] | 214 | unsigned InputReg = getRegForValue(I->getOperand(0), ValueMap); |
Owen Anderson | d0533c9 | 2008-08-26 23:46:32 +0000 | [diff] [blame] | 215 | if (!InputReg) |
| 216 | // Unhandled operand. Halt "fast" selection and bail. |
| 217 | return false; |
| 218 | |
| 219 | unsigned ResultReg = FastEmit_r(SrcVT.getSimpleVT(), |
| 220 | DstVT.getSimpleVT(), |
| 221 | Opcode, |
| 222 | InputReg); |
| 223 | if (!ResultReg) |
| 224 | return false; |
| 225 | |
| 226 | ValueMap[I] = ResultReg; |
| 227 | return true; |
| 228 | } |
| 229 | |
Dan Gohman | ad368ac | 2008-08-27 18:10:19 +0000 | [diff] [blame] | 230 | bool FastISel::SelectBitCast(Instruction *I, |
| 231 | DenseMap<const Value*, unsigned> &ValueMap) { |
| 232 | // If the bitcast doesn't change the type, just use the operand value. |
| 233 | if (I->getType() == I->getOperand(0)->getType()) { |
Dan Gohman | a318dab | 2008-08-27 20:41:38 +0000 | [diff] [blame] | 234 | unsigned Reg = getRegForValue(I->getOperand(0), ValueMap); |
| 235 | if (Reg == 0) |
| 236 | return false; |
| 237 | ValueMap[I] = Reg; |
Dan Gohman | ad368ac | 2008-08-27 18:10:19 +0000 | [diff] [blame] | 238 | return true; |
| 239 | } |
| 240 | |
| 241 | // Bitcasts of other values become reg-reg copies or BIT_CONVERT operators. |
Owen Anderson | 6336b70 | 2008-08-27 18:58:30 +0000 | [diff] [blame] | 242 | MVT SrcVT = TLI.getValueType(I->getOperand(0)->getType()); |
| 243 | MVT DstVT = TLI.getValueType(I->getType()); |
Owen Anderson | d0533c9 | 2008-08-26 23:46:32 +0000 | [diff] [blame] | 244 | |
| 245 | if (SrcVT == MVT::Other || !SrcVT.isSimple() || |
| 246 | DstVT == MVT::Other || !DstVT.isSimple() || |
| 247 | !TLI.isTypeLegal(SrcVT) || !TLI.isTypeLegal(DstVT)) |
| 248 | // Unhandled type. Halt "fast" selection and bail. |
| 249 | return false; |
| 250 | |
Dan Gohman | ad368ac | 2008-08-27 18:10:19 +0000 | [diff] [blame] | 251 | unsigned Op0 = getRegForValue(I->getOperand(0), ValueMap); |
| 252 | if (Op0 == 0) |
| 253 | // Unhandled operand. Halt "fast" selection and bail. |
Owen Anderson | d0533c9 | 2008-08-26 23:46:32 +0000 | [diff] [blame] | 254 | return false; |
| 255 | |
Dan Gohman | ad368ac | 2008-08-27 18:10:19 +0000 | [diff] [blame] | 256 | // First, try to perform the bitcast by inserting a reg-reg copy. |
| 257 | unsigned ResultReg = 0; |
| 258 | if (SrcVT.getSimpleVT() == DstVT.getSimpleVT()) { |
| 259 | TargetRegisterClass* SrcClass = TLI.getRegClassFor(SrcVT); |
| 260 | TargetRegisterClass* DstClass = TLI.getRegClassFor(DstVT); |
| 261 | ResultReg = createResultReg(DstClass); |
| 262 | |
| 263 | bool InsertedCopy = TII.copyRegToReg(*MBB, MBB->end(), ResultReg, |
| 264 | Op0, DstClass, SrcClass); |
| 265 | if (!InsertedCopy) |
| 266 | ResultReg = 0; |
| 267 | } |
| 268 | |
| 269 | // If the reg-reg copy failed, select a BIT_CONVERT opcode. |
| 270 | if (!ResultReg) |
| 271 | ResultReg = FastEmit_r(SrcVT.getSimpleVT(), DstVT.getSimpleVT(), |
| 272 | ISD::BIT_CONVERT, Op0); |
| 273 | |
| 274 | if (!ResultReg) |
Owen Anderson | d0533c9 | 2008-08-26 23:46:32 +0000 | [diff] [blame] | 275 | return false; |
| 276 | |
Dan Gohman | ad368ac | 2008-08-27 18:10:19 +0000 | [diff] [blame] | 277 | ValueMap[I] = ResultReg; |
Owen Anderson | d0533c9 | 2008-08-26 23:46:32 +0000 | [diff] [blame] | 278 | return true; |
| 279 | } |
| 280 | |
Dan Gohman | b0cf29c | 2008-08-13 20:19:35 +0000 | [diff] [blame] | 281 | BasicBlock::iterator |
Dan Gohman | b7864a9 | 2008-08-20 18:09:02 +0000 | [diff] [blame] | 282 | FastISel::SelectInstructions(BasicBlock::iterator Begin, |
| 283 | BasicBlock::iterator End, |
Dan Gohman | bb46633 | 2008-08-20 21:05:57 +0000 | [diff] [blame] | 284 | DenseMap<const Value*, unsigned> &ValueMap, |
Dan Gohman | 6ecf509 | 2008-08-23 02:44:46 +0000 | [diff] [blame] | 285 | DenseMap<const BasicBlock*, |
Dan Gohman | 3c8f36f | 2008-08-22 21:28:19 +0000 | [diff] [blame] | 286 | MachineBasicBlock *> &MBBMap, |
Dan Gohman | bb46633 | 2008-08-20 21:05:57 +0000 | [diff] [blame] | 287 | MachineBasicBlock *mbb) { |
| 288 | MBB = mbb; |
Dan Gohman | b0cf29c | 2008-08-13 20:19:35 +0000 | [diff] [blame] | 289 | BasicBlock::iterator I = Begin; |
| 290 | |
| 291 | for (; I != End; ++I) { |
| 292 | switch (I->getOpcode()) { |
Dan Gohman | 8014e86 | 2008-08-20 00:23:20 +0000 | [diff] [blame] | 293 | case Instruction::Add: { |
| 294 | ISD::NodeType Opc = I->getType()->isFPOrFPVector() ? ISD::FADD : ISD::ADD; |
| 295 | if (!SelectBinaryOp(I, Opc, ValueMap)) return I; break; |
| 296 | } |
| 297 | case Instruction::Sub: { |
| 298 | ISD::NodeType Opc = I->getType()->isFPOrFPVector() ? ISD::FSUB : ISD::SUB; |
| 299 | if (!SelectBinaryOp(I, Opc, ValueMap)) return I; break; |
| 300 | } |
| 301 | case Instruction::Mul: { |
| 302 | ISD::NodeType Opc = I->getType()->isFPOrFPVector() ? ISD::FMUL : ISD::MUL; |
| 303 | if (!SelectBinaryOp(I, Opc, ValueMap)) return I; break; |
| 304 | } |
Dan Gohman | bdedd44 | 2008-08-20 00:11:48 +0000 | [diff] [blame] | 305 | case Instruction::SDiv: |
| 306 | if (!SelectBinaryOp(I, ISD::SDIV, ValueMap)) return I; break; |
| 307 | case Instruction::UDiv: |
| 308 | if (!SelectBinaryOp(I, ISD::UDIV, ValueMap)) return I; break; |
| 309 | case Instruction::FDiv: |
| 310 | if (!SelectBinaryOp(I, ISD::FDIV, ValueMap)) return I; break; |
| 311 | case Instruction::SRem: |
| 312 | if (!SelectBinaryOp(I, ISD::SREM, ValueMap)) return I; break; |
| 313 | case Instruction::URem: |
| 314 | if (!SelectBinaryOp(I, ISD::UREM, ValueMap)) return I; break; |
| 315 | case Instruction::FRem: |
| 316 | if (!SelectBinaryOp(I, ISD::FREM, ValueMap)) return I; break; |
| 317 | case Instruction::Shl: |
| 318 | if (!SelectBinaryOp(I, ISD::SHL, ValueMap)) return I; break; |
| 319 | case Instruction::LShr: |
| 320 | if (!SelectBinaryOp(I, ISD::SRL, ValueMap)) return I; break; |
| 321 | case Instruction::AShr: |
| 322 | if (!SelectBinaryOp(I, ISD::SRA, ValueMap)) return I; break; |
| 323 | case Instruction::And: |
| 324 | if (!SelectBinaryOp(I, ISD::AND, ValueMap)) return I; break; |
| 325 | case Instruction::Or: |
| 326 | if (!SelectBinaryOp(I, ISD::OR, ValueMap)) return I; break; |
| 327 | case Instruction::Xor: |
| 328 | if (!SelectBinaryOp(I, ISD::XOR, ValueMap)) return I; break; |
| 329 | |
| 330 | case Instruction::GetElementPtr: |
| 331 | if (!SelectGetElementPtr(I, ValueMap)) return I; |
Dan Gohman | b0cf29c | 2008-08-13 20:19:35 +0000 | [diff] [blame] | 332 | break; |
Dan Gohman | bdedd44 | 2008-08-20 00:11:48 +0000 | [diff] [blame] | 333 | |
Dan Gohman | 6f2766d | 2008-08-19 22:31:46 +0000 | [diff] [blame] | 334 | case Instruction::Br: { |
| 335 | BranchInst *BI = cast<BranchInst>(I); |
| 336 | |
Dan Gohman | e6798b7 | 2008-08-20 01:17:01 +0000 | [diff] [blame] | 337 | if (BI->isUnconditional()) { |
Dan Gohman | 3c8f36f | 2008-08-22 21:28:19 +0000 | [diff] [blame] | 338 | MachineFunction::iterator NextMBB = |
Dan Gohman | e6798b7 | 2008-08-20 01:17:01 +0000 | [diff] [blame] | 339 | next(MachineFunction::iterator(MBB)); |
Dan Gohman | 3c8f36f | 2008-08-22 21:28:19 +0000 | [diff] [blame] | 340 | BasicBlock *LLVMSucc = BI->getSuccessor(0); |
| 341 | MachineBasicBlock *MSucc = MBBMap[LLVMSucc]; |
| 342 | |
| 343 | if (NextMBB != MF.end() && MSucc == NextMBB) { |
| 344 | // The unconditional fall-through case, which needs no instructions. |
| 345 | } else { |
| 346 | // The unconditional branch case. |
| 347 | TII.InsertBranch(*MBB, MSucc, NULL, SmallVector<MachineOperand, 0>()); |
Dan Gohman | e6798b7 | 2008-08-20 01:17:01 +0000 | [diff] [blame] | 348 | } |
Dan Gohman | 3c8f36f | 2008-08-22 21:28:19 +0000 | [diff] [blame] | 349 | MBB->addSuccessor(MSucc); |
| 350 | break; |
Dan Gohman | 6f2766d | 2008-08-19 22:31:46 +0000 | [diff] [blame] | 351 | } |
| 352 | |
Dan Gohman | 3c8f36f | 2008-08-22 21:28:19 +0000 | [diff] [blame] | 353 | // Conditional branches are not handed yet. |
| 354 | // Halt "fast" selection and bail. |
Dan Gohman | 6f2766d | 2008-08-19 22:31:46 +0000 | [diff] [blame] | 355 | return I; |
| 356 | } |
Dan Gohman | 3b7753b | 2008-08-22 17:37:48 +0000 | [diff] [blame] | 357 | |
| 358 | case Instruction::PHI: |
| 359 | // PHI nodes are already emitted. |
| 360 | break; |
Owen Anderson | 6d0c25e | 2008-08-25 20:20:32 +0000 | [diff] [blame] | 361 | |
| 362 | case Instruction::BitCast: |
Owen Anderson | d0533c9 | 2008-08-26 23:46:32 +0000 | [diff] [blame] | 363 | if (!SelectBitCast(I, ValueMap)) return I; break; |
Owen Anderson | 46aa2f5 | 2008-08-26 17:44:42 +0000 | [diff] [blame] | 364 | |
| 365 | case Instruction::FPToSI: |
Dan Gohman | ad368ac | 2008-08-27 18:10:19 +0000 | [diff] [blame] | 366 | if (!SelectCast(I, ISD::FP_TO_SINT, ValueMap)) return I; |
Owen Anderson | d0533c9 | 2008-08-26 23:46:32 +0000 | [diff] [blame] | 367 | break; |
Owen Anderson | 97e2568 | 2008-08-26 23:14:49 +0000 | [diff] [blame] | 368 | case Instruction::ZExt: |
Dan Gohman | ad368ac | 2008-08-27 18:10:19 +0000 | [diff] [blame] | 369 | if (!SelectCast(I, ISD::ZERO_EXTEND, ValueMap)) return I; |
Owen Anderson | d0533c9 | 2008-08-26 23:46:32 +0000 | [diff] [blame] | 370 | break; |
| 371 | case Instruction::SExt: |
Dan Gohman | ad368ac | 2008-08-27 18:10:19 +0000 | [diff] [blame] | 372 | if (!SelectCast(I, ISD::SIGN_EXTEND, ValueMap)) return I; |
Owen Anderson | d0533c9 | 2008-08-26 23:46:32 +0000 | [diff] [blame] | 373 | break; |
Owen Anderson | c0bb68b | 2008-08-28 18:26:01 +0000 | [diff] [blame] | 374 | case Instruction::Trunc: |
| 375 | if (!SelectCast(I, ISD::TRUNCATE, ValueMap)) return I; |
| 376 | break; |
Owen Anderson | a843b8d | 2008-08-26 20:37:00 +0000 | [diff] [blame] | 377 | case Instruction::SIToFP: |
Dan Gohman | ad368ac | 2008-08-27 18:10:19 +0000 | [diff] [blame] | 378 | if (!SelectCast(I, ISD::SINT_TO_FP, ValueMap)) return I; |
Owen Anderson | d0533c9 | 2008-08-26 23:46:32 +0000 | [diff] [blame] | 379 | break; |
Dan Gohman | 763d893 | 2008-08-26 21:28:54 +0000 | [diff] [blame] | 380 | |
Owen Anderson | 9d5b416 | 2008-08-27 00:31:01 +0000 | [diff] [blame] | 381 | case Instruction::IntToPtr: // Deliberate fall-through. |
| 382 | case Instruction::PtrToInt: { |
| 383 | MVT SrcVT = TLI.getValueType(I->getOperand(0)->getType()); |
| 384 | MVT DstVT = TLI.getValueType(I->getType()); |
| 385 | if (SrcVT.getSimpleVT() == DstVT.getSimpleVT()) { |
Owen Anderson | 96c5ea8 | 2008-08-27 00:35:37 +0000 | [diff] [blame] | 386 | if (ValueMap[I->getOperand(0)]) { |
| 387 | ValueMap[I] = ValueMap[I->getOperand(0)]; |
| 388 | break; |
| 389 | } else |
| 390 | // Unhandled operand |
| 391 | return I; |
Owen Anderson | 9d5b416 | 2008-08-27 00:31:01 +0000 | [diff] [blame] | 392 | } else if (DstVT.bitsGT(SrcVT)) { |
Dan Gohman | ad368ac | 2008-08-27 18:10:19 +0000 | [diff] [blame] | 393 | if (!SelectCast(I, ISD::ZERO_EXTEND, ValueMap)) return I; |
Owen Anderson | 9d5b416 | 2008-08-27 00:31:01 +0000 | [diff] [blame] | 394 | break; |
| 395 | } else { |
| 396 | // TODO: Handle SrcVT > DstVT, where truncation is needed. |
| 397 | return I; |
| 398 | } |
| 399 | } |
| 400 | |
Dan Gohman | b0cf29c | 2008-08-13 20:19:35 +0000 | [diff] [blame] | 401 | default: |
| 402 | // Unhandled instruction. Halt "fast" selection and bail. |
| 403 | return I; |
| 404 | } |
| 405 | } |
| 406 | |
| 407 | return I; |
| 408 | } |
| 409 | |
Dan Gohman | bb46633 | 2008-08-20 21:05:57 +0000 | [diff] [blame] | 410 | FastISel::FastISel(MachineFunction &mf) |
Dan Gohman | 22bb311 | 2008-08-22 00:20:26 +0000 | [diff] [blame] | 411 | : MF(mf), |
| 412 | MRI(mf.getRegInfo()), |
| 413 | TM(mf.getTarget()), |
| 414 | TD(*TM.getTargetData()), |
| 415 | TII(*TM.getInstrInfo()), |
| 416 | TLI(*TM.getTargetLowering()) { |
Dan Gohman | bb46633 | 2008-08-20 21:05:57 +0000 | [diff] [blame] | 417 | } |
| 418 | |
Dan Gohman | e285a74 | 2008-08-14 21:51:29 +0000 | [diff] [blame] | 419 | FastISel::~FastISel() {} |
| 420 | |
Owen Anderson | 0f84e4e | 2008-08-25 23:58:18 +0000 | [diff] [blame] | 421 | unsigned FastISel::FastEmit_(MVT::SimpleValueType, MVT::SimpleValueType, 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 | } |