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