blob: 8188928353208b00bd5b65dcf2a0ca08517497cb [file] [log] [blame]
Dan Gohmanb0cf29c2008-08-13 20:19:35 +00001///===-- 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 Gohman6f2766d2008-08-19 22:31:46 +000014#include "llvm/Instructions.h"
Dan Gohmanb0cf29c2008-08-13 20:19:35 +000015#include "llvm/CodeGen/FastISel.h"
16#include "llvm/CodeGen/MachineInstrBuilder.h"
17#include "llvm/CodeGen/MachineRegisterInfo.h"
Evan Cheng83785c82008-08-20 22:45:34 +000018#include "llvm/Target/TargetData.h"
Dan Gohmanb0cf29c2008-08-13 20:19:35 +000019#include "llvm/Target/TargetInstrInfo.h"
Evan Cheng83785c82008-08-20 22:45:34 +000020#include "llvm/Target/TargetLowering.h"
Dan Gohmanbb466332008-08-20 21:05:57 +000021#include "llvm/Target/TargetMachine.h"
Dan Gohmanb0cf29c2008-08-13 20:19:35 +000022using namespace llvm;
23
Dan Gohmanbdedd442008-08-20 00:11:48 +000024/// SelectBinaryOp - Select and emit code for a binary operator instruction,
25/// which has an opcode which directly corresponds to the given ISD opcode.
26///
27bool FastISel::SelectBinaryOp(Instruction *I, ISD::NodeType ISDOpcode,
28 DenseMap<const Value*, unsigned> &ValueMap) {
Dan Gohmanbdedd442008-08-20 00:11:48 +000029 MVT VT = MVT::getMVT(I->getType(), /*HandleUnknown=*/true);
30 if (VT == MVT::Other || !VT.isSimple())
31 // Unhandled type. Halt "fast" selection and bail.
32 return false;
33
Dan Gohmand5fe57d2008-08-21 01:41:07 +000034 unsigned Op0 = ValueMap[I->getOperand(0)];
35 if (Op0 == 0)
36 // Unhandled operand. Halt "fast" selection and bail.
37 return false;
38
39 // Check if the second operand is a constant and handle it appropriately.
40 if (ConstantInt *CI = dyn_cast<ConstantInt>(I->getOperand(1))) {
41 unsigned ResultReg = FastEmit_ri_(VT.getSimpleVT(), ISDOpcode, Op0,
42 CI->getZExtValue(), VT.getSimpleVT());
43 if (ResultReg == 0)
44 // Target-specific code wasn't able to find a machine opcode for
45 // the given ISD opcode and type. Halt "fast" selection and bail.
46 return false;
47
48 // We successfully emitted code for the given LLVM Instruction.
49 ValueMap[I] = ResultReg;
50 return true;
51 }
52
53 unsigned Op1 = ValueMap[I->getOperand(1)];
54 if (Op1 == 0)
55 // Unhandled operand. Halt "fast" selection and bail.
56 return false;
57
Owen Anderson0f84e4e2008-08-25 23:58:18 +000058 unsigned ResultReg = FastEmit_rr(VT.getSimpleVT(), VT.getSimpleVT(),
59 ISDOpcode, Op0, Op1);
Dan Gohmanbdedd442008-08-20 00:11:48 +000060 if (ResultReg == 0)
61 // Target-specific code wasn't able to find a machine opcode for
62 // the given ISD opcode and type. Halt "fast" selection and bail.
63 return false;
64
Dan Gohman8014e862008-08-20 00:23:20 +000065 // We successfully emitted code for the given LLVM Instruction.
Dan Gohmanbdedd442008-08-20 00:11:48 +000066 ValueMap[I] = ResultReg;
67 return true;
68}
69
70bool FastISel::SelectGetElementPtr(Instruction *I,
71 DenseMap<const Value*, unsigned> &ValueMap) {
Evan Cheng83785c82008-08-20 22:45:34 +000072 unsigned N = ValueMap[I->getOperand(0)];
73 if (N == 0)
74 // Unhandled operand. Halt "fast" selection and bail.
75 return false;
76
77 const Type *Ty = I->getOperand(0)->getType();
Dan Gohman7a0e6592008-08-21 17:25:26 +000078 MVT::SimpleValueType VT = TLI.getPointerTy().getSimpleVT();
Evan Cheng83785c82008-08-20 22:45:34 +000079 for (GetElementPtrInst::op_iterator OI = I->op_begin()+1, E = I->op_end();
80 OI != E; ++OI) {
81 Value *Idx = *OI;
82 if (const StructType *StTy = dyn_cast<StructType>(Ty)) {
83 unsigned Field = cast<ConstantInt>(Idx)->getZExtValue();
84 if (Field) {
85 // N = N + Offset
86 uint64_t Offs = TD.getStructLayout(StTy)->getElementOffset(Field);
87 // FIXME: This can be optimized by combining the add with a
88 // subsequent one.
Dan Gohman7a0e6592008-08-21 17:25:26 +000089 N = FastEmit_ri_(VT, ISD::ADD, N, Offs, VT);
Evan Cheng83785c82008-08-20 22:45:34 +000090 if (N == 0)
91 // Unhandled operand. Halt "fast" selection and bail.
92 return false;
93 }
94 Ty = StTy->getElementType(Field);
95 } else {
96 Ty = cast<SequentialType>(Ty)->getElementType();
97
98 // If this is a constant subscript, handle it quickly.
99 if (ConstantInt *CI = dyn_cast<ConstantInt>(Idx)) {
100 if (CI->getZExtValue() == 0) continue;
101 uint64_t Offs =
102 TD.getABITypeSize(Ty)*cast<ConstantInt>(CI)->getSExtValue();
Dan Gohman7a0e6592008-08-21 17:25:26 +0000103 N = FastEmit_ri_(VT, ISD::ADD, N, Offs, VT);
Evan Cheng83785c82008-08-20 22:45:34 +0000104 if (N == 0)
105 // Unhandled operand. Halt "fast" selection and bail.
106 return false;
107 continue;
108 }
109
110 // N = N + Idx * ElementSize;
111 uint64_t ElementSize = TD.getABITypeSize(Ty);
112 unsigned IdxN = ValueMap[Idx];
113 if (IdxN == 0)
114 // Unhandled operand. Halt "fast" selection and bail.
115 return false;
116
117 // If the index is smaller or larger than intptr_t, truncate or extend
118 // it.
Evan Cheng2076aa82008-08-21 01:19:11 +0000119 MVT IdxVT = MVT::getMVT(Idx->getType(), /*HandleUnknown=*/false);
Evan Cheng83785c82008-08-20 22:45:34 +0000120 if (IdxVT.bitsLT(VT))
Owen Anderson0f84e4e2008-08-25 23:58:18 +0000121 IdxN = FastEmit_r(VT, VT, ISD::SIGN_EXTEND, IdxN);
Evan Cheng83785c82008-08-20 22:45:34 +0000122 else if (IdxVT.bitsGT(VT))
Owen Anderson0f84e4e2008-08-25 23:58:18 +0000123 IdxN = FastEmit_r(VT, VT, ISD::TRUNCATE, IdxN);
Evan Cheng83785c82008-08-20 22:45:34 +0000124 if (IdxN == 0)
125 // Unhandled operand. Halt "fast" selection and bail.
126 return false;
127
Dan Gohmanf93cf792008-08-21 17:37:05 +0000128 if (ElementSize != 1)
129 IdxN = FastEmit_ri_(VT, ISD::MUL, IdxN, ElementSize, VT);
Evan Cheng83785c82008-08-20 22:45:34 +0000130 if (IdxN == 0)
131 // Unhandled operand. Halt "fast" selection and bail.
132 return false;
Owen Anderson0f84e4e2008-08-25 23:58:18 +0000133 N = FastEmit_rr(VT, VT, ISD::ADD, N, IdxN);
Evan Cheng83785c82008-08-20 22:45:34 +0000134 if (N == 0)
135 // Unhandled operand. Halt "fast" selection and bail.
136 return false;
137 }
138 }
139
140 // We successfully emitted code for the given LLVM Instruction.
141 ValueMap[I] = N;
142 return true;
Dan Gohmanbdedd442008-08-20 00:11:48 +0000143}
144
Dan Gohmanb0cf29c2008-08-13 20:19:35 +0000145BasicBlock::iterator
Dan Gohmanb7864a92008-08-20 18:09:02 +0000146FastISel::SelectInstructions(BasicBlock::iterator Begin,
147 BasicBlock::iterator End,
Dan Gohmanbb466332008-08-20 21:05:57 +0000148 DenseMap<const Value*, unsigned> &ValueMap,
Dan Gohman6ecf5092008-08-23 02:44:46 +0000149 DenseMap<const BasicBlock*,
Dan Gohman3c8f36f2008-08-22 21:28:19 +0000150 MachineBasicBlock *> &MBBMap,
Dan Gohmanbb466332008-08-20 21:05:57 +0000151 MachineBasicBlock *mbb) {
152 MBB = mbb;
Dan Gohmanb0cf29c2008-08-13 20:19:35 +0000153 BasicBlock::iterator I = Begin;
154
155 for (; I != End; ++I) {
156 switch (I->getOpcode()) {
Dan Gohman8014e862008-08-20 00:23:20 +0000157 case Instruction::Add: {
158 ISD::NodeType Opc = I->getType()->isFPOrFPVector() ? ISD::FADD : ISD::ADD;
159 if (!SelectBinaryOp(I, Opc, ValueMap)) return I; break;
160 }
161 case Instruction::Sub: {
162 ISD::NodeType Opc = I->getType()->isFPOrFPVector() ? ISD::FSUB : ISD::SUB;
163 if (!SelectBinaryOp(I, Opc, ValueMap)) return I; break;
164 }
165 case Instruction::Mul: {
166 ISD::NodeType Opc = I->getType()->isFPOrFPVector() ? ISD::FMUL : ISD::MUL;
167 if (!SelectBinaryOp(I, Opc, ValueMap)) return I; break;
168 }
Dan Gohmanbdedd442008-08-20 00:11:48 +0000169 case Instruction::SDiv:
170 if (!SelectBinaryOp(I, ISD::SDIV, ValueMap)) return I; break;
171 case Instruction::UDiv:
172 if (!SelectBinaryOp(I, ISD::UDIV, ValueMap)) return I; break;
173 case Instruction::FDiv:
174 if (!SelectBinaryOp(I, ISD::FDIV, ValueMap)) return I; break;
175 case Instruction::SRem:
176 if (!SelectBinaryOp(I, ISD::SREM, ValueMap)) return I; break;
177 case Instruction::URem:
178 if (!SelectBinaryOp(I, ISD::UREM, ValueMap)) return I; break;
179 case Instruction::FRem:
180 if (!SelectBinaryOp(I, ISD::FREM, ValueMap)) return I; break;
181 case Instruction::Shl:
182 if (!SelectBinaryOp(I, ISD::SHL, ValueMap)) return I; break;
183 case Instruction::LShr:
184 if (!SelectBinaryOp(I, ISD::SRL, ValueMap)) return I; break;
185 case Instruction::AShr:
186 if (!SelectBinaryOp(I, ISD::SRA, ValueMap)) return I; break;
187 case Instruction::And:
188 if (!SelectBinaryOp(I, ISD::AND, ValueMap)) return I; break;
189 case Instruction::Or:
190 if (!SelectBinaryOp(I, ISD::OR, ValueMap)) return I; break;
191 case Instruction::Xor:
192 if (!SelectBinaryOp(I, ISD::XOR, ValueMap)) return I; break;
193
194 case Instruction::GetElementPtr:
195 if (!SelectGetElementPtr(I, ValueMap)) return I;
Dan Gohmanb0cf29c2008-08-13 20:19:35 +0000196 break;
Dan Gohmanbdedd442008-08-20 00:11:48 +0000197
Dan Gohman6f2766d2008-08-19 22:31:46 +0000198 case Instruction::Br: {
199 BranchInst *BI = cast<BranchInst>(I);
200
Dan Gohmane6798b72008-08-20 01:17:01 +0000201 if (BI->isUnconditional()) {
Dan Gohman3c8f36f2008-08-22 21:28:19 +0000202 MachineFunction::iterator NextMBB =
Dan Gohmane6798b72008-08-20 01:17:01 +0000203 next(MachineFunction::iterator(MBB));
Dan Gohman3c8f36f2008-08-22 21:28:19 +0000204 BasicBlock *LLVMSucc = BI->getSuccessor(0);
205 MachineBasicBlock *MSucc = MBBMap[LLVMSucc];
206
207 if (NextMBB != MF.end() && MSucc == NextMBB) {
208 // The unconditional fall-through case, which needs no instructions.
209 } else {
210 // The unconditional branch case.
211 TII.InsertBranch(*MBB, MSucc, NULL, SmallVector<MachineOperand, 0>());
Dan Gohmane6798b72008-08-20 01:17:01 +0000212 }
Dan Gohman3c8f36f2008-08-22 21:28:19 +0000213 MBB->addSuccessor(MSucc);
214 break;
Dan Gohman6f2766d2008-08-19 22:31:46 +0000215 }
216
Dan Gohman3c8f36f2008-08-22 21:28:19 +0000217 // Conditional branches are not handed yet.
218 // Halt "fast" selection and bail.
Dan Gohman6f2766d2008-08-19 22:31:46 +0000219 return I;
220 }
Dan Gohman3b7753b2008-08-22 17:37:48 +0000221
222 case Instruction::PHI:
223 // PHI nodes are already emitted.
224 break;
Owen Anderson6d0c25e2008-08-25 20:20:32 +0000225
226 case Instruction::BitCast:
227 // BitCast consists of either an immediate to register move
228 // or a register to register move.
229 if (ConstantInt* CI = dyn_cast<ConstantInt>(I->getOperand(0))) {
230 if (I->getType()->isInteger()) {
231 MVT VT = MVT::getMVT(I->getType(), /*HandleUnknown=*/false);
Owen Anderson46aa2f52008-08-26 17:44:42 +0000232 unsigned result = FastEmit_i(VT.getSimpleVT(), VT.getSimpleVT(),
233 ISD::Constant,
234 CI->getZExtValue());
235 if (!result)
236 return I;
237
238 ValueMap[I] = result;
Owen Anderson6d0c25e2008-08-25 20:20:32 +0000239 break;
240 } else
241 // TODO: Support vector and fp constants.
242 return I;
Owen Andersond894f1d2008-08-25 21:32:34 +0000243 } else if (!isa<Constant>(I->getOperand(0))) {
244 // Bitcasts of non-constant values become reg-reg copies.
245 MVT SrcVT = MVT::getMVT(I->getOperand(0)->getType());
Owen Anderson46aa2f52008-08-26 17:44:42 +0000246 MVT DstVT = MVT::getMVT(I->getType());
Owen Andersond894f1d2008-08-25 21:32:34 +0000247
248 if (SrcVT == MVT::Other || !SrcVT.isSimple() ||
249 DstVT == MVT::Other || !DstVT.isSimple() ||
250 !TLI.isTypeLegal(SrcVT) || !TLI.isTypeLegal(DstVT))
251 // Unhandled type. Halt "fast" selection and bail.
252 return I;
Owen Andersond894f1d2008-08-25 21:32:34 +0000253
Owen Andersond894f1d2008-08-25 21:32:34 +0000254 unsigned Op0 = ValueMap[I->getOperand(0)];
Owen Andersond894f1d2008-08-25 21:32:34 +0000255 if (Op0 == 0)
256 // Unhandled operand. Halt "fast" selection and bail.
257 return false;
258
Owen Anderson77a21872008-08-26 18:51:24 +0000259 // First, try to perform the bitcast by inserting a reg-reg copy.
260 unsigned ResultReg = 0;
261 if (SrcVT.getSimpleVT() == DstVT.getSimpleVT()) {
262 TargetRegisterClass* SrcClass = TLI.getRegClassFor(SrcVT);
263 TargetRegisterClass* DstClass = TLI.getRegClassFor(DstVT);
264 ResultReg = createResultReg(DstClass);
265
266 bool InsertedCopy = TII.copyRegToReg(*MBB, MBB->end(), ResultReg,
267 Op0, DstClass, SrcClass);
268 if (!InsertedCopy)
269 ResultReg = 0;
270 }
271
272 // If the reg-reg copy failed, select a BIT_CONVERT opcode.
273 if (!ResultReg)
274 ResultReg = FastEmit_r(SrcVT.getSimpleVT(), DstVT.getSimpleVT(),
275 ISD::BIT_CONVERT, Op0);
276
277 if (!ResultReg)
Owen Anderson940f83e2008-08-26 18:03:31 +0000278 return I;
Owen Andersond894f1d2008-08-25 21:32:34 +0000279
Owen Anderson940f83e2008-08-26 18:03:31 +0000280 ValueMap[I] = ResultReg;
Owen Andersond894f1d2008-08-25 21:32:34 +0000281 break;
Owen Anderson6d0c25e2008-08-25 20:20:32 +0000282 } else
Owen Anderson46aa2f52008-08-26 17:44:42 +0000283 // TODO: Casting a non-integral constant?
284 return I;
285
286 case Instruction::FPToSI:
287 if (!isa<ConstantFP>(I->getOperand(0))) {
288 MVT SrcVT = MVT::getMVT(I->getOperand(0)->getType());
289 MVT DstVT = MVT::getMVT(I->getType());
290
291 if (SrcVT == MVT::Other || !SrcVT.isSimple() ||
292 DstVT == MVT::Other || !DstVT.isSimple() ||
293 !TLI.isTypeLegal(SrcVT) || !TLI.isTypeLegal(DstVT))
294 // Unhandled type. Halt "fast" selection and bail.
295 return I;
Owen Anderson46aa2f52008-08-26 17:44:42 +0000296
297 unsigned InputReg = ValueMap[I->getOperand(0)];
298 if (!InputReg)
299 // Unhandled operand. Halt "fast" selection and bail.
300 return I;
301
302 unsigned ResultReg = FastEmit_r(SrcVT.getSimpleVT(),
303 DstVT.getSimpleVT(),
304 ISD::FP_TO_SINT,
305 InputReg);
306 if (!ResultReg)
307 return I;
308
309 ValueMap[I] = ResultReg;
310 break;
311 } else
312 // TODO: Materialize the FP constant and then convert,
313 // or attempt constant folding.
Owen Anderson6d0c25e2008-08-25 20:20:32 +0000314 return I;
Dan Gohman3b7753b2008-08-22 17:37:48 +0000315
Owen Andersona843b8d2008-08-26 20:37:00 +0000316 case Instruction::SIToFP:
317 if (!isa<ConstantInt>(I->getOperand(0))) {
318 MVT SrcVT = MVT::getMVT(I->getOperand(0)->getType());
319 MVT DstVT = MVT::getMVT(I->getType());
320
321 if (SrcVT == MVT::Other || !SrcVT.isSimple() ||
322 DstVT == MVT::Other || !DstVT.isSimple() ||
323 !TLI.isTypeLegal(SrcVT) || !TLI.isTypeLegal(DstVT))
324 // Unhandled type. Halt "fast" selection and bail.
325 return I;
326
327 unsigned InputReg = ValueMap[I->getOperand(0)];
328 if (!InputReg)
329 // Unhandled operan. Halt "fast" selection and bail.
330 return I;
331
332 unsigned ResultReg = FastEmit_r(SrcVT.getSimpleVT(),
333 DstVT.getSimpleVT(),
334 ISD::SINT_TO_FP,
335 InputReg);
336 if (!ResultReg)
337 return I;
338
339 ValueMap[I] = ResultReg;
340 break;
341 } else
342 // TODO: Materialize constant and convert to FP.
343 return I;
Dan Gohmanb0cf29c2008-08-13 20:19:35 +0000344 default:
345 // Unhandled instruction. Halt "fast" selection and bail.
346 return I;
347 }
348 }
349
350 return I;
351}
352
Dan Gohmanbb466332008-08-20 21:05:57 +0000353FastISel::FastISel(MachineFunction &mf)
Dan Gohman22bb3112008-08-22 00:20:26 +0000354 : MF(mf),
355 MRI(mf.getRegInfo()),
356 TM(mf.getTarget()),
357 TD(*TM.getTargetData()),
358 TII(*TM.getInstrInfo()),
359 TLI(*TM.getTargetLowering()) {
Dan Gohmanbb466332008-08-20 21:05:57 +0000360}
361
Dan Gohmane285a742008-08-14 21:51:29 +0000362FastISel::~FastISel() {}
363
Owen Anderson0f84e4e2008-08-25 23:58:18 +0000364unsigned FastISel::FastEmit_(MVT::SimpleValueType, MVT::SimpleValueType, ISD::NodeType) {
Dan Gohmanb0cf29c2008-08-13 20:19:35 +0000365 return 0;
366}
367
Owen Anderson0f84e4e2008-08-25 23:58:18 +0000368unsigned FastISel::FastEmit_r(MVT::SimpleValueType, MVT::SimpleValueType,
369 ISD::NodeType, unsigned /*Op0*/) {
Dan Gohmanb0cf29c2008-08-13 20:19:35 +0000370 return 0;
371}
372
Owen Anderson0f84e4e2008-08-25 23:58:18 +0000373unsigned FastISel::FastEmit_rr(MVT::SimpleValueType, MVT::SimpleValueType,
374 ISD::NodeType, unsigned /*Op0*/,
375 unsigned /*Op0*/) {
Dan Gohmanb0cf29c2008-08-13 20:19:35 +0000376 return 0;
377}
378
Owen Anderson0f84e4e2008-08-25 23:58:18 +0000379unsigned FastISel::FastEmit_i(MVT::SimpleValueType, MVT::SimpleValueType,
380 ISD::NodeType, uint64_t /*Imm*/) {
Evan Cheng83785c82008-08-20 22:45:34 +0000381 return 0;
382}
383
Owen Anderson0f84e4e2008-08-25 23:58:18 +0000384unsigned FastISel::FastEmit_ri(MVT::SimpleValueType, MVT::SimpleValueType,
385 ISD::NodeType, unsigned /*Op0*/,
386 uint64_t /*Imm*/) {
Dan Gohmand5fe57d2008-08-21 01:41:07 +0000387 return 0;
388}
389
Owen Anderson0f84e4e2008-08-25 23:58:18 +0000390unsigned FastISel::FastEmit_rri(MVT::SimpleValueType, MVT::SimpleValueType,
391 ISD::NodeType,
Dan Gohmand5fe57d2008-08-21 01:41:07 +0000392 unsigned /*Op0*/, unsigned /*Op1*/,
393 uint64_t /*Imm*/) {
Evan Cheng83785c82008-08-20 22:45:34 +0000394 return 0;
395}
396
397/// FastEmit_ri_ - This method is a wrapper of FastEmit_ri. It first tries
398/// to emit an instruction with an immediate operand using FastEmit_ri.
399/// If that fails, it materializes the immediate into a register and try
400/// FastEmit_rr instead.
401unsigned FastISel::FastEmit_ri_(MVT::SimpleValueType VT, ISD::NodeType Opcode,
Dan Gohmand5fe57d2008-08-21 01:41:07 +0000402 unsigned Op0, uint64_t Imm,
403 MVT::SimpleValueType ImmType) {
Evan Cheng83785c82008-08-20 22:45:34 +0000404 unsigned ResultReg = 0;
405 // First check if immediate type is legal. If not, we can't use the ri form.
406 if (TLI.getOperationAction(ISD::Constant, ImmType) == TargetLowering::Legal)
Owen Anderson0f84e4e2008-08-25 23:58:18 +0000407 ResultReg = FastEmit_ri(VT, VT, Opcode, Op0, Imm);
Evan Cheng83785c82008-08-20 22:45:34 +0000408 if (ResultReg != 0)
409 return ResultReg;
Owen Anderson0f84e4e2008-08-25 23:58:18 +0000410 unsigned MaterialReg = FastEmit_i(ImmType, ImmType, ISD::Constant, Imm);
Dan Gohmand5fe57d2008-08-21 01:41:07 +0000411 if (MaterialReg == 0)
412 return 0;
Owen Anderson0f84e4e2008-08-25 23:58:18 +0000413 return FastEmit_rr(VT, VT, Opcode, Op0, MaterialReg);
Dan Gohmand5fe57d2008-08-21 01:41:07 +0000414}
415
416unsigned FastISel::createResultReg(const TargetRegisterClass* RC) {
417 return MRI.createVirtualRegister(RC);
Evan Cheng83785c82008-08-20 22:45:34 +0000418}
419
Dan Gohmanb0cf29c2008-08-13 20:19:35 +0000420unsigned FastISel::FastEmitInst_(unsigned MachineInstOpcode,
Dan Gohman77ad7962008-08-20 18:09:38 +0000421 const TargetRegisterClass* RC) {
Dan Gohmand5fe57d2008-08-21 01:41:07 +0000422 unsigned ResultReg = createResultReg(RC);
Dan Gohmanbb466332008-08-20 21:05:57 +0000423 const TargetInstrDesc &II = TII.get(MachineInstOpcode);
Dan Gohmanb0cf29c2008-08-13 20:19:35 +0000424
Dan Gohmanfd903942008-08-20 23:53:10 +0000425 BuildMI(MBB, II, ResultReg);
Dan Gohmanb0cf29c2008-08-13 20:19:35 +0000426 return ResultReg;
427}
428
429unsigned FastISel::FastEmitInst_r(unsigned MachineInstOpcode,
430 const TargetRegisterClass *RC,
431 unsigned Op0) {
Dan Gohmand5fe57d2008-08-21 01:41:07 +0000432 unsigned ResultReg = createResultReg(RC);
Dan Gohmanbb466332008-08-20 21:05:57 +0000433 const TargetInstrDesc &II = TII.get(MachineInstOpcode);
Dan Gohmanb0cf29c2008-08-13 20:19:35 +0000434
Dan Gohmanfd903942008-08-20 23:53:10 +0000435 BuildMI(MBB, II, ResultReg).addReg(Op0);
Dan Gohmanb0cf29c2008-08-13 20:19:35 +0000436 return ResultReg;
437}
438
439unsigned FastISel::FastEmitInst_rr(unsigned MachineInstOpcode,
440 const TargetRegisterClass *RC,
441 unsigned Op0, unsigned Op1) {
Dan Gohmand5fe57d2008-08-21 01:41:07 +0000442 unsigned ResultReg = createResultReg(RC);
Dan Gohmanbb466332008-08-20 21:05:57 +0000443 const TargetInstrDesc &II = TII.get(MachineInstOpcode);
Dan Gohmanb0cf29c2008-08-13 20:19:35 +0000444
Dan Gohmanfd903942008-08-20 23:53:10 +0000445 BuildMI(MBB, II, ResultReg).addReg(Op0).addReg(Op1);
Dan Gohmanb0cf29c2008-08-13 20:19:35 +0000446 return ResultReg;
447}
Dan Gohmand5fe57d2008-08-21 01:41:07 +0000448
449unsigned FastISel::FastEmitInst_ri(unsigned MachineInstOpcode,
450 const TargetRegisterClass *RC,
451 unsigned Op0, uint64_t Imm) {
452 unsigned ResultReg = createResultReg(RC);
453 const TargetInstrDesc &II = TII.get(MachineInstOpcode);
454
455 BuildMI(MBB, II, ResultReg).addReg(Op0).addImm(Imm);
456 return ResultReg;
457}
458
459unsigned FastISel::FastEmitInst_rri(unsigned MachineInstOpcode,
460 const TargetRegisterClass *RC,
461 unsigned Op0, unsigned Op1, uint64_t Imm) {
462 unsigned ResultReg = createResultReg(RC);
463 const TargetInstrDesc &II = TII.get(MachineInstOpcode);
464
465 BuildMI(MBB, II, ResultReg).addReg(Op0).addReg(Op1).addImm(Imm);
466 return ResultReg;
467}
Owen Anderson6d0c25e2008-08-25 20:20:32 +0000468
469unsigned FastISel::FastEmitInst_i(unsigned MachineInstOpcode,
470 const TargetRegisterClass *RC,
471 uint64_t Imm) {
472 unsigned ResultReg = createResultReg(RC);
473 const TargetInstrDesc &II = TII.get(MachineInstOpcode);
474
475 BuildMI(MBB, II, ResultReg).addImm(Imm);
476 return ResultReg;
Evan Chengb41aec52008-08-25 22:20:39 +0000477}