blob: 965fc0228689cca86d4025bb4e1dab07b8240cf3 [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;
Dan Gohmanb71fea22008-08-26 20:52:40 +000033 // We only handle legal types. For example, on x86-32 the instruction
34 // selector contains all of the 64-bit instructions from x86-64,
35 // under the assumption that i64 won't be used if the target doesn't
36 // support it.
37 if (!TLI.isTypeLegal(VT))
38 return false;
Dan Gohmanbdedd442008-08-20 00:11:48 +000039
Dan Gohmand5fe57d2008-08-21 01:41:07 +000040 unsigned Op0 = ValueMap[I->getOperand(0)];
41 if (Op0 == 0)
42 // Unhandled operand. Halt "fast" selection and bail.
43 return false;
44
45 // Check if the second operand is a constant and handle it appropriately.
46 if (ConstantInt *CI = dyn_cast<ConstantInt>(I->getOperand(1))) {
47 unsigned ResultReg = FastEmit_ri_(VT.getSimpleVT(), ISDOpcode, Op0,
48 CI->getZExtValue(), VT.getSimpleVT());
49 if (ResultReg == 0)
50 // Target-specific code wasn't able to find a machine opcode for
51 // the given ISD opcode and type. Halt "fast" selection and bail.
52 return false;
53
54 // We successfully emitted code for the given LLVM Instruction.
55 ValueMap[I] = ResultReg;
56 return true;
57 }
58
59 unsigned Op1 = ValueMap[I->getOperand(1)];
60 if (Op1 == 0)
61 // Unhandled operand. Halt "fast" selection and bail.
62 return false;
63
Owen Anderson0f84e4e2008-08-25 23:58:18 +000064 unsigned ResultReg = FastEmit_rr(VT.getSimpleVT(), VT.getSimpleVT(),
65 ISDOpcode, Op0, Op1);
Dan Gohmanbdedd442008-08-20 00:11:48 +000066 if (ResultReg == 0)
67 // Target-specific code wasn't able to find a machine opcode for
68 // the given ISD opcode and type. Halt "fast" selection and bail.
69 return false;
70
Dan Gohman8014e862008-08-20 00:23:20 +000071 // We successfully emitted code for the given LLVM Instruction.
Dan Gohmanbdedd442008-08-20 00:11:48 +000072 ValueMap[I] = ResultReg;
73 return true;
74}
75
76bool FastISel::SelectGetElementPtr(Instruction *I,
77 DenseMap<const Value*, unsigned> &ValueMap) {
Evan Cheng83785c82008-08-20 22:45:34 +000078 unsigned N = ValueMap[I->getOperand(0)];
79 if (N == 0)
80 // Unhandled operand. Halt "fast" selection and bail.
81 return false;
82
83 const Type *Ty = I->getOperand(0)->getType();
Dan Gohman7a0e6592008-08-21 17:25:26 +000084 MVT::SimpleValueType VT = TLI.getPointerTy().getSimpleVT();
Evan Cheng83785c82008-08-20 22:45:34 +000085 for (GetElementPtrInst::op_iterator OI = I->op_begin()+1, E = I->op_end();
86 OI != E; ++OI) {
87 Value *Idx = *OI;
88 if (const StructType *StTy = dyn_cast<StructType>(Ty)) {
89 unsigned Field = cast<ConstantInt>(Idx)->getZExtValue();
90 if (Field) {
91 // N = N + Offset
92 uint64_t Offs = TD.getStructLayout(StTy)->getElementOffset(Field);
93 // FIXME: This can be optimized by combining the add with a
94 // subsequent one.
Dan Gohman7a0e6592008-08-21 17:25:26 +000095 N = FastEmit_ri_(VT, ISD::ADD, N, Offs, VT);
Evan Cheng83785c82008-08-20 22:45:34 +000096 if (N == 0)
97 // Unhandled operand. Halt "fast" selection and bail.
98 return false;
99 }
100 Ty = StTy->getElementType(Field);
101 } else {
102 Ty = cast<SequentialType>(Ty)->getElementType();
103
104 // If this is a constant subscript, handle it quickly.
105 if (ConstantInt *CI = dyn_cast<ConstantInt>(Idx)) {
106 if (CI->getZExtValue() == 0) continue;
107 uint64_t Offs =
108 TD.getABITypeSize(Ty)*cast<ConstantInt>(CI)->getSExtValue();
Dan Gohman7a0e6592008-08-21 17:25:26 +0000109 N = FastEmit_ri_(VT, ISD::ADD, N, Offs, VT);
Evan Cheng83785c82008-08-20 22:45:34 +0000110 if (N == 0)
111 // Unhandled operand. Halt "fast" selection and bail.
112 return false;
113 continue;
114 }
115
116 // N = N + Idx * ElementSize;
117 uint64_t ElementSize = TD.getABITypeSize(Ty);
118 unsigned IdxN = ValueMap[Idx];
119 if (IdxN == 0)
120 // Unhandled operand. Halt "fast" selection and bail.
121 return false;
122
123 // If the index is smaller or larger than intptr_t, truncate or extend
124 // it.
Evan Cheng2076aa82008-08-21 01:19:11 +0000125 MVT IdxVT = MVT::getMVT(Idx->getType(), /*HandleUnknown=*/false);
Evan Cheng83785c82008-08-20 22:45:34 +0000126 if (IdxVT.bitsLT(VT))
Owen Anderson0f84e4e2008-08-25 23:58:18 +0000127 IdxN = FastEmit_r(VT, VT, ISD::SIGN_EXTEND, IdxN);
Evan Cheng83785c82008-08-20 22:45:34 +0000128 else if (IdxVT.bitsGT(VT))
Owen Anderson0f84e4e2008-08-25 23:58:18 +0000129 IdxN = FastEmit_r(VT, VT, ISD::TRUNCATE, IdxN);
Evan Cheng83785c82008-08-20 22:45:34 +0000130 if (IdxN == 0)
131 // Unhandled operand. Halt "fast" selection and bail.
132 return false;
133
Dan Gohmanf93cf792008-08-21 17:37:05 +0000134 if (ElementSize != 1)
135 IdxN = FastEmit_ri_(VT, ISD::MUL, IdxN, ElementSize, VT);
Evan Cheng83785c82008-08-20 22:45:34 +0000136 if (IdxN == 0)
137 // Unhandled operand. Halt "fast" selection and bail.
138 return false;
Owen Anderson0f84e4e2008-08-25 23:58:18 +0000139 N = FastEmit_rr(VT, VT, ISD::ADD, N, IdxN);
Evan Cheng83785c82008-08-20 22:45:34 +0000140 if (N == 0)
141 // Unhandled operand. Halt "fast" selection and bail.
142 return false;
143 }
144 }
145
146 // We successfully emitted code for the given LLVM Instruction.
147 ValueMap[I] = N;
148 return true;
Dan Gohmanbdedd442008-08-20 00:11:48 +0000149}
150
Dan Gohmanb0cf29c2008-08-13 20:19:35 +0000151BasicBlock::iterator
Dan Gohmanb7864a92008-08-20 18:09:02 +0000152FastISel::SelectInstructions(BasicBlock::iterator Begin,
153 BasicBlock::iterator End,
Dan Gohmanbb466332008-08-20 21:05:57 +0000154 DenseMap<const Value*, unsigned> &ValueMap,
Dan Gohman6ecf5092008-08-23 02:44:46 +0000155 DenseMap<const BasicBlock*,
Dan Gohman3c8f36f2008-08-22 21:28:19 +0000156 MachineBasicBlock *> &MBBMap,
Dan Gohmanbb466332008-08-20 21:05:57 +0000157 MachineBasicBlock *mbb) {
158 MBB = mbb;
Dan Gohmanb0cf29c2008-08-13 20:19:35 +0000159 BasicBlock::iterator I = Begin;
160
161 for (; I != End; ++I) {
162 switch (I->getOpcode()) {
Dan Gohman8014e862008-08-20 00:23:20 +0000163 case Instruction::Add: {
164 ISD::NodeType Opc = I->getType()->isFPOrFPVector() ? ISD::FADD : ISD::ADD;
165 if (!SelectBinaryOp(I, Opc, ValueMap)) return I; break;
166 }
167 case Instruction::Sub: {
168 ISD::NodeType Opc = I->getType()->isFPOrFPVector() ? ISD::FSUB : ISD::SUB;
169 if (!SelectBinaryOp(I, Opc, ValueMap)) return I; break;
170 }
171 case Instruction::Mul: {
172 ISD::NodeType Opc = I->getType()->isFPOrFPVector() ? ISD::FMUL : ISD::MUL;
173 if (!SelectBinaryOp(I, Opc, ValueMap)) return I; break;
174 }
Dan Gohmanbdedd442008-08-20 00:11:48 +0000175 case Instruction::SDiv:
176 if (!SelectBinaryOp(I, ISD::SDIV, ValueMap)) return I; break;
177 case Instruction::UDiv:
178 if (!SelectBinaryOp(I, ISD::UDIV, ValueMap)) return I; break;
179 case Instruction::FDiv:
180 if (!SelectBinaryOp(I, ISD::FDIV, ValueMap)) return I; break;
181 case Instruction::SRem:
182 if (!SelectBinaryOp(I, ISD::SREM, ValueMap)) return I; break;
183 case Instruction::URem:
184 if (!SelectBinaryOp(I, ISD::UREM, ValueMap)) return I; break;
185 case Instruction::FRem:
186 if (!SelectBinaryOp(I, ISD::FREM, ValueMap)) return I; break;
187 case Instruction::Shl:
188 if (!SelectBinaryOp(I, ISD::SHL, ValueMap)) return I; break;
189 case Instruction::LShr:
190 if (!SelectBinaryOp(I, ISD::SRL, ValueMap)) return I; break;
191 case Instruction::AShr:
192 if (!SelectBinaryOp(I, ISD::SRA, ValueMap)) return I; break;
193 case Instruction::And:
194 if (!SelectBinaryOp(I, ISD::AND, ValueMap)) return I; break;
195 case Instruction::Or:
196 if (!SelectBinaryOp(I, ISD::OR, ValueMap)) return I; break;
197 case Instruction::Xor:
198 if (!SelectBinaryOp(I, ISD::XOR, ValueMap)) return I; break;
199
200 case Instruction::GetElementPtr:
201 if (!SelectGetElementPtr(I, ValueMap)) return I;
Dan Gohmanb0cf29c2008-08-13 20:19:35 +0000202 break;
Dan Gohmanbdedd442008-08-20 00:11:48 +0000203
Dan Gohman6f2766d2008-08-19 22:31:46 +0000204 case Instruction::Br: {
205 BranchInst *BI = cast<BranchInst>(I);
206
Dan Gohmane6798b72008-08-20 01:17:01 +0000207 if (BI->isUnconditional()) {
Dan Gohman3c8f36f2008-08-22 21:28:19 +0000208 MachineFunction::iterator NextMBB =
Dan Gohmane6798b72008-08-20 01:17:01 +0000209 next(MachineFunction::iterator(MBB));
Dan Gohman3c8f36f2008-08-22 21:28:19 +0000210 BasicBlock *LLVMSucc = BI->getSuccessor(0);
211 MachineBasicBlock *MSucc = MBBMap[LLVMSucc];
212
213 if (NextMBB != MF.end() && MSucc == NextMBB) {
214 // The unconditional fall-through case, which needs no instructions.
215 } else {
216 // The unconditional branch case.
217 TII.InsertBranch(*MBB, MSucc, NULL, SmallVector<MachineOperand, 0>());
Dan Gohmane6798b72008-08-20 01:17:01 +0000218 }
Dan Gohman3c8f36f2008-08-22 21:28:19 +0000219 MBB->addSuccessor(MSucc);
220 break;
Dan Gohman6f2766d2008-08-19 22:31:46 +0000221 }
222
Dan Gohman3c8f36f2008-08-22 21:28:19 +0000223 // Conditional branches are not handed yet.
224 // Halt "fast" selection and bail.
Dan Gohman6f2766d2008-08-19 22:31:46 +0000225 return I;
226 }
Dan Gohman3b7753b2008-08-22 17:37:48 +0000227
228 case Instruction::PHI:
229 // PHI nodes are already emitted.
230 break;
Owen Anderson6d0c25e2008-08-25 20:20:32 +0000231
232 case Instruction::BitCast:
233 // BitCast consists of either an immediate to register move
234 // or a register to register move.
235 if (ConstantInt* CI = dyn_cast<ConstantInt>(I->getOperand(0))) {
236 if (I->getType()->isInteger()) {
237 MVT VT = MVT::getMVT(I->getType(), /*HandleUnknown=*/false);
Owen Anderson46aa2f52008-08-26 17:44:42 +0000238 unsigned result = FastEmit_i(VT.getSimpleVT(), VT.getSimpleVT(),
239 ISD::Constant,
240 CI->getZExtValue());
241 if (!result)
242 return I;
243
244 ValueMap[I] = result;
Owen Anderson6d0c25e2008-08-25 20:20:32 +0000245 break;
246 } else
247 // TODO: Support vector and fp constants.
248 return I;
Owen Andersond894f1d2008-08-25 21:32:34 +0000249 } else if (!isa<Constant>(I->getOperand(0))) {
250 // Bitcasts of non-constant values become reg-reg copies.
251 MVT SrcVT = MVT::getMVT(I->getOperand(0)->getType());
Owen Anderson46aa2f52008-08-26 17:44:42 +0000252 MVT DstVT = MVT::getMVT(I->getType());
Owen Andersond894f1d2008-08-25 21:32:34 +0000253
254 if (SrcVT == MVT::Other || !SrcVT.isSimple() ||
255 DstVT == MVT::Other || !DstVT.isSimple() ||
256 !TLI.isTypeLegal(SrcVT) || !TLI.isTypeLegal(DstVT))
257 // Unhandled type. Halt "fast" selection and bail.
258 return I;
Owen Andersond894f1d2008-08-25 21:32:34 +0000259
Owen Andersond894f1d2008-08-25 21:32:34 +0000260 unsigned Op0 = ValueMap[I->getOperand(0)];
Owen Andersond894f1d2008-08-25 21:32:34 +0000261 if (Op0 == 0)
262 // Unhandled operand. Halt "fast" selection and bail.
263 return false;
264
Owen Anderson77a21872008-08-26 18:51:24 +0000265 // First, try to perform the bitcast by inserting a reg-reg copy.
266 unsigned ResultReg = 0;
267 if (SrcVT.getSimpleVT() == DstVT.getSimpleVT()) {
268 TargetRegisterClass* SrcClass = TLI.getRegClassFor(SrcVT);
269 TargetRegisterClass* DstClass = TLI.getRegClassFor(DstVT);
270 ResultReg = createResultReg(DstClass);
271
272 bool InsertedCopy = TII.copyRegToReg(*MBB, MBB->end(), ResultReg,
273 Op0, DstClass, SrcClass);
274 if (!InsertedCopy)
275 ResultReg = 0;
276 }
277
278 // If the reg-reg copy failed, select a BIT_CONVERT opcode.
279 if (!ResultReg)
280 ResultReg = FastEmit_r(SrcVT.getSimpleVT(), DstVT.getSimpleVT(),
281 ISD::BIT_CONVERT, Op0);
282
283 if (!ResultReg)
Owen Anderson940f83e2008-08-26 18:03:31 +0000284 return I;
Owen Andersond894f1d2008-08-25 21:32:34 +0000285
Owen Anderson940f83e2008-08-26 18:03:31 +0000286 ValueMap[I] = ResultReg;
Owen Andersond894f1d2008-08-25 21:32:34 +0000287 break;
Owen Anderson6d0c25e2008-08-25 20:20:32 +0000288 } else
Owen Anderson46aa2f52008-08-26 17:44:42 +0000289 // TODO: Casting a non-integral constant?
290 return I;
291
292 case Instruction::FPToSI:
293 if (!isa<ConstantFP>(I->getOperand(0))) {
294 MVT SrcVT = MVT::getMVT(I->getOperand(0)->getType());
295 MVT DstVT = MVT::getMVT(I->getType());
296
297 if (SrcVT == MVT::Other || !SrcVT.isSimple() ||
298 DstVT == MVT::Other || !DstVT.isSimple() ||
299 !TLI.isTypeLegal(SrcVT) || !TLI.isTypeLegal(DstVT))
300 // Unhandled type. Halt "fast" selection and bail.
301 return I;
Owen Anderson46aa2f52008-08-26 17:44:42 +0000302
303 unsigned InputReg = ValueMap[I->getOperand(0)];
304 if (!InputReg)
305 // Unhandled operand. Halt "fast" selection and bail.
306 return I;
307
308 unsigned ResultReg = FastEmit_r(SrcVT.getSimpleVT(),
309 DstVT.getSimpleVT(),
310 ISD::FP_TO_SINT,
311 InputReg);
312 if (!ResultReg)
313 return I;
314
315 ValueMap[I] = ResultReg;
316 break;
317 } else
318 // TODO: Materialize the FP constant and then convert,
319 // or attempt constant folding.
Owen Anderson6d0c25e2008-08-25 20:20:32 +0000320 return I;
Dan Gohman3b7753b2008-08-22 17:37:48 +0000321
Owen Andersona843b8d2008-08-26 20:37:00 +0000322 case Instruction::SIToFP:
323 if (!isa<ConstantInt>(I->getOperand(0))) {
324 MVT SrcVT = MVT::getMVT(I->getOperand(0)->getType());
325 MVT DstVT = MVT::getMVT(I->getType());
326
327 if (SrcVT == MVT::Other || !SrcVT.isSimple() ||
328 DstVT == MVT::Other || !DstVT.isSimple() ||
329 !TLI.isTypeLegal(SrcVT) || !TLI.isTypeLegal(DstVT))
330 // Unhandled type. Halt "fast" selection and bail.
331 return I;
332
333 unsigned InputReg = ValueMap[I->getOperand(0)];
334 if (!InputReg)
335 // Unhandled operan. Halt "fast" selection and bail.
336 return I;
337
338 unsigned ResultReg = FastEmit_r(SrcVT.getSimpleVT(),
339 DstVT.getSimpleVT(),
340 ISD::SINT_TO_FP,
341 InputReg);
342 if (!ResultReg)
343 return I;
344
345 ValueMap[I] = ResultReg;
346 break;
347 } else
348 // TODO: Materialize constant and convert to FP.
349 return I;
Dan Gohmanb0cf29c2008-08-13 20:19:35 +0000350 default:
351 // Unhandled instruction. Halt "fast" selection and bail.
352 return I;
353 }
354 }
355
356 return I;
357}
358
Dan Gohmanbb466332008-08-20 21:05:57 +0000359FastISel::FastISel(MachineFunction &mf)
Dan Gohman22bb3112008-08-22 00:20:26 +0000360 : MF(mf),
361 MRI(mf.getRegInfo()),
362 TM(mf.getTarget()),
363 TD(*TM.getTargetData()),
364 TII(*TM.getInstrInfo()),
365 TLI(*TM.getTargetLowering()) {
Dan Gohmanbb466332008-08-20 21:05:57 +0000366}
367
Dan Gohmane285a742008-08-14 21:51:29 +0000368FastISel::~FastISel() {}
369
Owen Anderson0f84e4e2008-08-25 23:58:18 +0000370unsigned FastISel::FastEmit_(MVT::SimpleValueType, MVT::SimpleValueType, ISD::NodeType) {
Dan Gohmanb0cf29c2008-08-13 20:19:35 +0000371 return 0;
372}
373
Owen Anderson0f84e4e2008-08-25 23:58:18 +0000374unsigned FastISel::FastEmit_r(MVT::SimpleValueType, MVT::SimpleValueType,
375 ISD::NodeType, unsigned /*Op0*/) {
Dan Gohmanb0cf29c2008-08-13 20:19:35 +0000376 return 0;
377}
378
Owen Anderson0f84e4e2008-08-25 23:58:18 +0000379unsigned FastISel::FastEmit_rr(MVT::SimpleValueType, MVT::SimpleValueType,
380 ISD::NodeType, unsigned /*Op0*/,
381 unsigned /*Op0*/) {
Dan Gohmanb0cf29c2008-08-13 20:19:35 +0000382 return 0;
383}
384
Owen Anderson0f84e4e2008-08-25 23:58:18 +0000385unsigned FastISel::FastEmit_i(MVT::SimpleValueType, MVT::SimpleValueType,
386 ISD::NodeType, uint64_t /*Imm*/) {
Evan Cheng83785c82008-08-20 22:45:34 +0000387 return 0;
388}
389
Owen Anderson0f84e4e2008-08-25 23:58:18 +0000390unsigned FastISel::FastEmit_ri(MVT::SimpleValueType, MVT::SimpleValueType,
391 ISD::NodeType, unsigned /*Op0*/,
392 uint64_t /*Imm*/) {
Dan Gohmand5fe57d2008-08-21 01:41:07 +0000393 return 0;
394}
395
Owen Anderson0f84e4e2008-08-25 23:58:18 +0000396unsigned FastISel::FastEmit_rri(MVT::SimpleValueType, MVT::SimpleValueType,
397 ISD::NodeType,
Dan Gohmand5fe57d2008-08-21 01:41:07 +0000398 unsigned /*Op0*/, unsigned /*Op1*/,
399 uint64_t /*Imm*/) {
Evan Cheng83785c82008-08-20 22:45:34 +0000400 return 0;
401}
402
403/// FastEmit_ri_ - This method is a wrapper of FastEmit_ri. It first tries
404/// to emit an instruction with an immediate operand using FastEmit_ri.
405/// If that fails, it materializes the immediate into a register and try
406/// FastEmit_rr instead.
407unsigned FastISel::FastEmit_ri_(MVT::SimpleValueType VT, ISD::NodeType Opcode,
Dan Gohmand5fe57d2008-08-21 01:41:07 +0000408 unsigned Op0, uint64_t Imm,
409 MVT::SimpleValueType ImmType) {
Evan Cheng83785c82008-08-20 22:45:34 +0000410 unsigned ResultReg = 0;
411 // First check if immediate type is legal. If not, we can't use the ri form.
412 if (TLI.getOperationAction(ISD::Constant, ImmType) == TargetLowering::Legal)
Owen Anderson0f84e4e2008-08-25 23:58:18 +0000413 ResultReg = FastEmit_ri(VT, VT, Opcode, Op0, Imm);
Evan Cheng83785c82008-08-20 22:45:34 +0000414 if (ResultReg != 0)
415 return ResultReg;
Owen Anderson0f84e4e2008-08-25 23:58:18 +0000416 unsigned MaterialReg = FastEmit_i(ImmType, ImmType, ISD::Constant, Imm);
Dan Gohmand5fe57d2008-08-21 01:41:07 +0000417 if (MaterialReg == 0)
418 return 0;
Owen Anderson0f84e4e2008-08-25 23:58:18 +0000419 return FastEmit_rr(VT, VT, Opcode, Op0, MaterialReg);
Dan Gohmand5fe57d2008-08-21 01:41:07 +0000420}
421
422unsigned FastISel::createResultReg(const TargetRegisterClass* RC) {
423 return MRI.createVirtualRegister(RC);
Evan Cheng83785c82008-08-20 22:45:34 +0000424}
425
Dan Gohmanb0cf29c2008-08-13 20:19:35 +0000426unsigned FastISel::FastEmitInst_(unsigned MachineInstOpcode,
Dan Gohman77ad7962008-08-20 18:09:38 +0000427 const TargetRegisterClass* RC) {
Dan Gohmand5fe57d2008-08-21 01:41:07 +0000428 unsigned ResultReg = createResultReg(RC);
Dan Gohmanbb466332008-08-20 21:05:57 +0000429 const TargetInstrDesc &II = TII.get(MachineInstOpcode);
Dan Gohmanb0cf29c2008-08-13 20:19:35 +0000430
Dan Gohmanfd903942008-08-20 23:53:10 +0000431 BuildMI(MBB, II, ResultReg);
Dan Gohmanb0cf29c2008-08-13 20:19:35 +0000432 return ResultReg;
433}
434
435unsigned FastISel::FastEmitInst_r(unsigned MachineInstOpcode,
436 const TargetRegisterClass *RC,
437 unsigned Op0) {
Dan Gohmand5fe57d2008-08-21 01:41:07 +0000438 unsigned ResultReg = createResultReg(RC);
Dan Gohmanbb466332008-08-20 21:05:57 +0000439 const TargetInstrDesc &II = TII.get(MachineInstOpcode);
Dan Gohmanb0cf29c2008-08-13 20:19:35 +0000440
Dan Gohmanfd903942008-08-20 23:53:10 +0000441 BuildMI(MBB, II, ResultReg).addReg(Op0);
Dan Gohmanb0cf29c2008-08-13 20:19:35 +0000442 return ResultReg;
443}
444
445unsigned FastISel::FastEmitInst_rr(unsigned MachineInstOpcode,
446 const TargetRegisterClass *RC,
447 unsigned Op0, unsigned Op1) {
Dan Gohmand5fe57d2008-08-21 01:41:07 +0000448 unsigned ResultReg = createResultReg(RC);
Dan Gohmanbb466332008-08-20 21:05:57 +0000449 const TargetInstrDesc &II = TII.get(MachineInstOpcode);
Dan Gohmanb0cf29c2008-08-13 20:19:35 +0000450
Dan Gohmanfd903942008-08-20 23:53:10 +0000451 BuildMI(MBB, II, ResultReg).addReg(Op0).addReg(Op1);
Dan Gohmanb0cf29c2008-08-13 20:19:35 +0000452 return ResultReg;
453}
Dan Gohmand5fe57d2008-08-21 01:41:07 +0000454
455unsigned FastISel::FastEmitInst_ri(unsigned MachineInstOpcode,
456 const TargetRegisterClass *RC,
457 unsigned Op0, uint64_t Imm) {
458 unsigned ResultReg = createResultReg(RC);
459 const TargetInstrDesc &II = TII.get(MachineInstOpcode);
460
461 BuildMI(MBB, II, ResultReg).addReg(Op0).addImm(Imm);
462 return ResultReg;
463}
464
465unsigned FastISel::FastEmitInst_rri(unsigned MachineInstOpcode,
466 const TargetRegisterClass *RC,
467 unsigned Op0, unsigned Op1, uint64_t Imm) {
468 unsigned ResultReg = createResultReg(RC);
469 const TargetInstrDesc &II = TII.get(MachineInstOpcode);
470
471 BuildMI(MBB, II, ResultReg).addReg(Op0).addReg(Op1).addImm(Imm);
472 return ResultReg;
473}
Owen Anderson6d0c25e2008-08-25 20:20:32 +0000474
475unsigned FastISel::FastEmitInst_i(unsigned MachineInstOpcode,
476 const TargetRegisterClass *RC,
477 uint64_t Imm) {
478 unsigned ResultReg = createResultReg(RC);
479 const TargetInstrDesc &II = TII.get(MachineInstOpcode);
480
481 BuildMI(MBB, II, ResultReg).addImm(Imm);
482 return ResultReg;
Evan Chengb41aec52008-08-25 22:20:39 +0000483}