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