1 ///===-- FastISel.cpp - Implementation of the FastISel class --------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file contains the implementation of the FastISel class.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/Instructions.h"
15 #include "llvm/CodeGen/FastISel.h"
16 #include "llvm/CodeGen/MachineInstrBuilder.h"
17 #include "llvm/CodeGen/MachineRegisterInfo.h"
18 #include "llvm/Target/TargetData.h"
19 #include "llvm/Target/TargetInstrInfo.h"
20 #include "llvm/Target/TargetLowering.h"
21 #include "llvm/Target/TargetMachine.h"
24 unsigned FastISel::getRegForValue(Value *V) {
25 // Look up the value to see if we already have a register for it. We
26 // cache values defined by Instructions across blocks, and other values
27 // only locally. This is because Instructions already have the SSA
28 // def-dominatess-use requirement enforced.
29 if (ValueMap.count(V))
31 unsigned Reg = LocalValueMap[V];
35 MVT::SimpleValueType VT = TLI.getValueType(V->getType()).getSimpleVT();
36 if (!TLI.isTypeLegal(VT))
38 if (ConstantInt *CI = dyn_cast<ConstantInt>(V)) {
39 if (CI->getValue().getActiveBits() > 64)
40 return TargetMaterializeConstant(CI);
41 // Don't cache constant materializations. To do so would require
42 // tracking what uses they dominate.
43 Reg = FastEmit_i(VT, VT, ISD::Constant, CI->getZExtValue());
44 } else if (isa<GlobalValue>(V)) {
45 return TargetMaterializeConstant(cast<Constant>(V));
46 } else if (isa<AllocaInst>(V)) {
47 return TargetMaterializeAlloca(cast<AllocaInst>(V));
48 } else if (isa<ConstantPointerNull>(V)) {
49 Reg = FastEmit_i(VT, VT, ISD::Constant, 0);
50 } else if (ConstantFP *CF = dyn_cast<ConstantFP>(V)) {
51 Reg = FastEmit_f(VT, VT, ISD::ConstantFP, CF);
54 const APFloat &Flt = CF->getValueAPF();
55 MVT IntVT = TLI.getPointerTy();
58 uint32_t IntBitWidth = IntVT.getSizeInBits();
59 if (Flt.convertToInteger(x, IntBitWidth, /*isSigned=*/true,
60 APFloat::rmTowardZero) != APFloat::opOK)
61 return TargetMaterializeConstant(CF);
62 APInt IntVal(IntBitWidth, 2, x);
64 unsigned IntegerReg = FastEmit_i(IntVT.getSimpleVT(), IntVT.getSimpleVT(),
65 ISD::Constant, IntVal.getZExtValue());
67 return TargetMaterializeConstant(CF);
68 Reg = FastEmit_r(IntVT.getSimpleVT(), VT, ISD::SINT_TO_FP, IntegerReg);
70 return TargetMaterializeConstant(CF);
72 } else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(V)) {
73 if (!SelectOperator(CE, CE->getOpcode())) return 0;
74 Reg = LocalValueMap[CE];
75 } else if (isa<UndefValue>(V)) {
76 Reg = createResultReg(TLI.getRegClassFor(VT));
77 BuildMI(MBB, TII.get(TargetInstrInfo::IMPLICIT_DEF), Reg);
82 if (!Reg && isa<Constant>(V))
83 return TargetMaterializeConstant(cast<Constant>(V));
85 LocalValueMap[V] = Reg;
89 unsigned FastISel::lookUpRegForValue(Value *V) {
90 // Look up the value to see if we already have a register for it. We
91 // cache values defined by Instructions across blocks, and other values
92 // only locally. This is because Instructions already have the SSA
93 // def-dominatess-use requirement enforced.
94 if (ValueMap.count(V))
96 return LocalValueMap[V];
99 /// UpdateValueMap - Update the value map to include the new mapping for this
100 /// instruction, or insert an extra copy to get the result in a previous
101 /// determined register.
102 /// NOTE: This is only necessary because we might select a block that uses
103 /// a value before we select the block that defines the value. It might be
104 /// possible to fix this by selecting blocks in reverse postorder.
105 void FastISel::UpdateValueMap(Value* I, unsigned Reg) {
106 if (!isa<Instruction>(I)) {
107 LocalValueMap[I] = Reg;
110 if (!ValueMap.count(I))
113 TII.copyRegToReg(*MBB, MBB->end(), ValueMap[I],
114 Reg, MRI.getRegClass(Reg), MRI.getRegClass(Reg));
117 /// SelectBinaryOp - Select and emit code for a binary operator instruction,
118 /// which has an opcode which directly corresponds to the given ISD opcode.
120 bool FastISel::SelectBinaryOp(User *I, ISD::NodeType ISDOpcode) {
121 MVT VT = MVT::getMVT(I->getType(), /*HandleUnknown=*/true);
122 if (VT == MVT::Other || !VT.isSimple())
123 // Unhandled type. Halt "fast" selection and bail.
126 // We only handle legal types. For example, on x86-32 the instruction
127 // selector contains all of the 64-bit instructions from x86-64,
128 // under the assumption that i64 won't be used if the target doesn't
130 if (!TLI.isTypeLegal(VT)) {
131 // MVT::i1 is special. Allow AND and OR (but not XOR) because they
132 // don't require additional zeroing, which makes them easy.
134 (ISDOpcode == ISD::AND || ISDOpcode == ISD::OR))
135 VT = TLI.getTypeToTransformTo(VT);
140 unsigned Op0 = getRegForValue(I->getOperand(0));
142 // Unhandled operand. Halt "fast" selection and bail.
145 // Check if the second operand is a constant and handle it appropriately.
146 if (ConstantInt *CI = dyn_cast<ConstantInt>(I->getOperand(1))) {
147 unsigned ResultReg = FastEmit_ri(VT.getSimpleVT(), VT.getSimpleVT(),
148 ISDOpcode, Op0, CI->getZExtValue());
149 if (ResultReg != 0) {
150 // We successfully emitted code for the given LLVM Instruction.
151 UpdateValueMap(I, ResultReg);
156 // Check if the second operand is a constant float.
157 if (ConstantFP *CF = dyn_cast<ConstantFP>(I->getOperand(1))) {
158 unsigned ResultReg = FastEmit_rf(VT.getSimpleVT(), VT.getSimpleVT(),
160 if (ResultReg != 0) {
161 // We successfully emitted code for the given LLVM Instruction.
162 UpdateValueMap(I, ResultReg);
167 unsigned Op1 = getRegForValue(I->getOperand(1));
169 // Unhandled operand. Halt "fast" selection and bail.
172 // Now we have both operands in registers. Emit the instruction.
173 unsigned ResultReg = FastEmit_rr(VT.getSimpleVT(), VT.getSimpleVT(),
174 ISDOpcode, Op0, Op1);
176 // Target-specific code wasn't able to find a machine opcode for
177 // the given ISD opcode and type. Halt "fast" selection and bail.
180 // We successfully emitted code for the given LLVM Instruction.
181 UpdateValueMap(I, ResultReg);
185 bool FastISel::SelectGetElementPtr(User *I) {
186 unsigned N = getRegForValue(I->getOperand(0));
188 // Unhandled operand. Halt "fast" selection and bail.
191 const Type *Ty = I->getOperand(0)->getType();
192 MVT::SimpleValueType VT = TLI.getPointerTy().getSimpleVT();
193 for (GetElementPtrInst::op_iterator OI = I->op_begin()+1, E = I->op_end();
196 if (const StructType *StTy = dyn_cast<StructType>(Ty)) {
197 unsigned Field = cast<ConstantInt>(Idx)->getZExtValue();
200 uint64_t Offs = TD.getStructLayout(StTy)->getElementOffset(Field);
201 // FIXME: This can be optimized by combining the add with a
203 N = FastEmit_ri_(VT, ISD::ADD, N, Offs, VT);
205 // Unhandled operand. Halt "fast" selection and bail.
208 Ty = StTy->getElementType(Field);
210 Ty = cast<SequentialType>(Ty)->getElementType();
212 // If this is a constant subscript, handle it quickly.
213 if (ConstantInt *CI = dyn_cast<ConstantInt>(Idx)) {
214 if (CI->getZExtValue() == 0) continue;
216 TD.getABITypeSize(Ty)*cast<ConstantInt>(CI)->getSExtValue();
217 N = FastEmit_ri_(VT, ISD::ADD, N, Offs, VT);
219 // Unhandled operand. Halt "fast" selection and bail.
224 // N = N + Idx * ElementSize;
225 uint64_t ElementSize = TD.getABITypeSize(Ty);
226 unsigned IdxN = getRegForValue(Idx);
228 // Unhandled operand. Halt "fast" selection and bail.
231 // If the index is smaller or larger than intptr_t, truncate or extend
233 MVT IdxVT = MVT::getMVT(Idx->getType(), /*HandleUnknown=*/false);
234 if (IdxVT.bitsLT(VT))
235 IdxN = FastEmit_r(IdxVT.getSimpleVT(), VT, ISD::SIGN_EXTEND, IdxN);
236 else if (IdxVT.bitsGT(VT))
237 IdxN = FastEmit_r(IdxVT.getSimpleVT(), VT, ISD::TRUNCATE, IdxN);
239 // Unhandled operand. Halt "fast" selection and bail.
242 if (ElementSize != 1) {
243 IdxN = FastEmit_ri_(VT, ISD::MUL, IdxN, ElementSize, VT);
245 // Unhandled operand. Halt "fast" selection and bail.
248 N = FastEmit_rr(VT, VT, ISD::ADD, N, IdxN);
250 // Unhandled operand. Halt "fast" selection and bail.
255 // We successfully emitted code for the given LLVM Instruction.
256 UpdateValueMap(I, N);
260 bool FastISel::SelectCast(User *I, ISD::NodeType Opcode) {
261 MVT SrcVT = TLI.getValueType(I->getOperand(0)->getType());
262 MVT DstVT = TLI.getValueType(I->getType());
264 if (SrcVT == MVT::Other || !SrcVT.isSimple() ||
265 DstVT == MVT::Other || !DstVT.isSimple() ||
266 !TLI.isTypeLegal(SrcVT) || !TLI.isTypeLegal(DstVT))
267 // Unhandled type. Halt "fast" selection and bail.
270 unsigned InputReg = getRegForValue(I->getOperand(0));
272 // Unhandled operand. Halt "fast" selection and bail.
275 unsigned ResultReg = FastEmit_r(SrcVT.getSimpleVT(),
282 UpdateValueMap(I, ResultReg);
286 bool FastISel::SelectBitCast(User *I) {
287 // If the bitcast doesn't change the type, just use the operand value.
288 if (I->getType() == I->getOperand(0)->getType()) {
289 unsigned Reg = getRegForValue(I->getOperand(0));
292 UpdateValueMap(I, Reg);
296 // Bitcasts of other values become reg-reg copies or BIT_CONVERT operators.
297 MVT SrcVT = TLI.getValueType(I->getOperand(0)->getType());
298 MVT DstVT = TLI.getValueType(I->getType());
300 if (SrcVT == MVT::Other || !SrcVT.isSimple() ||
301 DstVT == MVT::Other || !DstVT.isSimple() ||
302 !TLI.isTypeLegal(SrcVT) || !TLI.isTypeLegal(DstVT))
303 // Unhandled type. Halt "fast" selection and bail.
306 unsigned Op0 = getRegForValue(I->getOperand(0));
308 // Unhandled operand. Halt "fast" selection and bail.
311 // First, try to perform the bitcast by inserting a reg-reg copy.
312 unsigned ResultReg = 0;
313 if (SrcVT.getSimpleVT() == DstVT.getSimpleVT()) {
314 TargetRegisterClass* SrcClass = TLI.getRegClassFor(SrcVT);
315 TargetRegisterClass* DstClass = TLI.getRegClassFor(DstVT);
316 ResultReg = createResultReg(DstClass);
318 bool InsertedCopy = TII.copyRegToReg(*MBB, MBB->end(), ResultReg,
319 Op0, DstClass, SrcClass);
324 // If the reg-reg copy failed, select a BIT_CONVERT opcode.
326 ResultReg = FastEmit_r(SrcVT.getSimpleVT(), DstVT.getSimpleVT(),
327 ISD::BIT_CONVERT, Op0);
332 UpdateValueMap(I, ResultReg);
337 FastISel::SelectInstruction(Instruction *I) {
338 return SelectOperator(I, I->getOpcode());
342 FastISel::SelectOperator(User *I, unsigned Opcode) {
344 case Instruction::Add: {
345 ISD::NodeType Opc = I->getType()->isFPOrFPVector() ? ISD::FADD : ISD::ADD;
346 return SelectBinaryOp(I, Opc);
348 case Instruction::Sub: {
349 ISD::NodeType Opc = I->getType()->isFPOrFPVector() ? ISD::FSUB : ISD::SUB;
350 return SelectBinaryOp(I, Opc);
352 case Instruction::Mul: {
353 ISD::NodeType Opc = I->getType()->isFPOrFPVector() ? ISD::FMUL : ISD::MUL;
354 return SelectBinaryOp(I, Opc);
356 case Instruction::SDiv:
357 return SelectBinaryOp(I, ISD::SDIV);
358 case Instruction::UDiv:
359 return SelectBinaryOp(I, ISD::UDIV);
360 case Instruction::FDiv:
361 return SelectBinaryOp(I, ISD::FDIV);
362 case Instruction::SRem:
363 return SelectBinaryOp(I, ISD::SREM);
364 case Instruction::URem:
365 return SelectBinaryOp(I, ISD::UREM);
366 case Instruction::FRem:
367 return SelectBinaryOp(I, ISD::FREM);
368 case Instruction::Shl:
369 return SelectBinaryOp(I, ISD::SHL);
370 case Instruction::LShr:
371 return SelectBinaryOp(I, ISD::SRL);
372 case Instruction::AShr:
373 return SelectBinaryOp(I, ISD::SRA);
374 case Instruction::And:
375 return SelectBinaryOp(I, ISD::AND);
376 case Instruction::Or:
377 return SelectBinaryOp(I, ISD::OR);
378 case Instruction::Xor:
379 return SelectBinaryOp(I, ISD::XOR);
381 case Instruction::GetElementPtr:
382 return SelectGetElementPtr(I);
384 case Instruction::Br: {
385 BranchInst *BI = cast<BranchInst>(I);
387 if (BI->isUnconditional()) {
388 MachineFunction::iterator NextMBB =
389 next(MachineFunction::iterator(MBB));
390 BasicBlock *LLVMSucc = BI->getSuccessor(0);
391 MachineBasicBlock *MSucc = MBBMap[LLVMSucc];
393 if (NextMBB != MF.end() && MSucc == NextMBB) {
394 // The unconditional fall-through case, which needs no instructions.
396 // The unconditional branch case.
397 TII.InsertBranch(*MBB, MSucc, NULL, SmallVector<MachineOperand, 0>());
399 MBB->addSuccessor(MSucc);
403 // Conditional branches are not handed yet.
404 // Halt "fast" selection and bail.
408 case Instruction::Unreachable:
412 case Instruction::PHI:
413 // PHI nodes are already emitted.
416 case Instruction::Alloca:
417 // FunctionLowering has the static-sized case covered.
418 if (StaticAllocaMap.count(cast<AllocaInst>(I)))
421 // Dynamic-sized alloca is not handled yet.
424 case Instruction::BitCast:
425 return SelectBitCast(I);
427 case Instruction::FPToSI:
428 return SelectCast(I, ISD::FP_TO_SINT);
429 case Instruction::ZExt:
430 return SelectCast(I, ISD::ZERO_EXTEND);
431 case Instruction::SExt:
432 return SelectCast(I, ISD::SIGN_EXTEND);
433 case Instruction::Trunc:
434 return SelectCast(I, ISD::TRUNCATE);
435 case Instruction::SIToFP:
436 return SelectCast(I, ISD::SINT_TO_FP);
438 case Instruction::IntToPtr: // Deliberate fall-through.
439 case Instruction::PtrToInt: {
440 MVT SrcVT = TLI.getValueType(I->getOperand(0)->getType());
441 MVT DstVT = TLI.getValueType(I->getType());
442 if (DstVT.bitsGT(SrcVT))
443 return SelectCast(I, ISD::ZERO_EXTEND);
444 if (DstVT.bitsLT(SrcVT))
445 return SelectCast(I, ISD::TRUNCATE);
446 unsigned Reg = getRegForValue(I->getOperand(0));
447 if (Reg == 0) return false;
448 UpdateValueMap(I, Reg);
453 // Unhandled instruction. Halt "fast" selection and bail.
458 FastISel::FastISel(MachineFunction &mf,
459 DenseMap<const Value *, unsigned> &vm,
460 DenseMap<const BasicBlock *, MachineBasicBlock *> &bm,
461 DenseMap<const AllocaInst *, int> &am)
467 MRI(MF.getRegInfo()),
468 MFI(*MF.getFrameInfo()),
469 MCP(*MF.getConstantPool()),
471 TD(*TM.getTargetData()),
472 TII(*TM.getInstrInfo()),
473 TLI(*TM.getTargetLowering()) {
476 FastISel::~FastISel() {}
478 unsigned FastISel::FastEmit_(MVT::SimpleValueType, MVT::SimpleValueType,
483 unsigned FastISel::FastEmit_r(MVT::SimpleValueType, MVT::SimpleValueType,
484 ISD::NodeType, unsigned /*Op0*/) {
488 unsigned FastISel::FastEmit_rr(MVT::SimpleValueType, MVT::SimpleValueType,
489 ISD::NodeType, unsigned /*Op0*/,
494 unsigned FastISel::FastEmit_i(MVT::SimpleValueType, MVT::SimpleValueType,
495 ISD::NodeType, uint64_t /*Imm*/) {
499 unsigned FastISel::FastEmit_f(MVT::SimpleValueType, MVT::SimpleValueType,
500 ISD::NodeType, ConstantFP * /*FPImm*/) {
504 unsigned FastISel::FastEmit_ri(MVT::SimpleValueType, MVT::SimpleValueType,
505 ISD::NodeType, unsigned /*Op0*/,
510 unsigned FastISel::FastEmit_rf(MVT::SimpleValueType, MVT::SimpleValueType,
511 ISD::NodeType, unsigned /*Op0*/,
512 ConstantFP * /*FPImm*/) {
516 unsigned FastISel::FastEmit_rri(MVT::SimpleValueType, MVT::SimpleValueType,
518 unsigned /*Op0*/, unsigned /*Op1*/,
523 /// FastEmit_ri_ - This method is a wrapper of FastEmit_ri. It first tries
524 /// to emit an instruction with an immediate operand using FastEmit_ri.
525 /// If that fails, it materializes the immediate into a register and try
526 /// FastEmit_rr instead.
527 unsigned FastISel::FastEmit_ri_(MVT::SimpleValueType VT, ISD::NodeType Opcode,
528 unsigned Op0, uint64_t Imm,
529 MVT::SimpleValueType ImmType) {
530 // First check if immediate type is legal. If not, we can't use the ri form.
531 unsigned ResultReg = FastEmit_ri(VT, VT, Opcode, Op0, Imm);
534 unsigned MaterialReg = FastEmit_i(ImmType, ImmType, ISD::Constant, Imm);
535 if (MaterialReg == 0)
537 return FastEmit_rr(VT, VT, Opcode, Op0, MaterialReg);
540 /// FastEmit_rf_ - This method is a wrapper of FastEmit_ri. It first tries
541 /// to emit an instruction with a floating-point immediate operand using
542 /// FastEmit_rf. If that fails, it materializes the immediate into a register
543 /// and try FastEmit_rr instead.
544 unsigned FastISel::FastEmit_rf_(MVT::SimpleValueType VT, ISD::NodeType Opcode,
545 unsigned Op0, ConstantFP *FPImm,
546 MVT::SimpleValueType ImmType) {
547 // First check if immediate type is legal. If not, we can't use the rf form.
548 unsigned ResultReg = FastEmit_rf(VT, VT, Opcode, Op0, FPImm);
552 // Materialize the constant in a register.
553 unsigned MaterialReg = FastEmit_f(ImmType, ImmType, ISD::ConstantFP, FPImm);
554 if (MaterialReg == 0) {
555 // If the target doesn't have a way to directly enter a floating-point
556 // value into a register, use an alternate approach.
557 // TODO: The current approach only supports floating-point constants
558 // that can be constructed by conversion from integer values. This should
559 // be replaced by code that creates a load from a constant-pool entry,
560 // which will require some target-specific work.
561 const APFloat &Flt = FPImm->getValueAPF();
562 MVT IntVT = TLI.getPointerTy();
565 uint32_t IntBitWidth = IntVT.getSizeInBits();
566 if (Flt.convertToInteger(x, IntBitWidth, /*isSigned=*/true,
567 APFloat::rmTowardZero) != APFloat::opOK)
569 APInt IntVal(IntBitWidth, 2, x);
571 unsigned IntegerReg = FastEmit_i(IntVT.getSimpleVT(), IntVT.getSimpleVT(),
572 ISD::Constant, IntVal.getZExtValue());
575 MaterialReg = FastEmit_r(IntVT.getSimpleVT(), VT,
576 ISD::SINT_TO_FP, IntegerReg);
577 if (MaterialReg == 0)
580 return FastEmit_rr(VT, VT, Opcode, Op0, MaterialReg);
583 unsigned FastISel::createResultReg(const TargetRegisterClass* RC) {
584 return MRI.createVirtualRegister(RC);
587 unsigned FastISel::FastEmitInst_(unsigned MachineInstOpcode,
588 const TargetRegisterClass* RC) {
589 unsigned ResultReg = createResultReg(RC);
590 const TargetInstrDesc &II = TII.get(MachineInstOpcode);
592 BuildMI(MBB, II, ResultReg);
596 unsigned FastISel::FastEmitInst_r(unsigned MachineInstOpcode,
597 const TargetRegisterClass *RC,
599 unsigned ResultReg = createResultReg(RC);
600 const TargetInstrDesc &II = TII.get(MachineInstOpcode);
602 if (II.getNumDefs() >= 1)
603 BuildMI(MBB, II, ResultReg).addReg(Op0);
605 BuildMI(MBB, II).addReg(Op0);
606 bool InsertedCopy = TII.copyRegToReg(*MBB, MBB->end(), ResultReg,
607 II.ImplicitDefs[0], RC, RC);
615 unsigned FastISel::FastEmitInst_rr(unsigned MachineInstOpcode,
616 const TargetRegisterClass *RC,
617 unsigned Op0, unsigned Op1) {
618 unsigned ResultReg = createResultReg(RC);
619 const TargetInstrDesc &II = TII.get(MachineInstOpcode);
621 if (II.getNumDefs() >= 1)
622 BuildMI(MBB, II, ResultReg).addReg(Op0).addReg(Op1);
624 BuildMI(MBB, II).addReg(Op0).addReg(Op1);
625 bool InsertedCopy = TII.copyRegToReg(*MBB, MBB->end(), ResultReg,
626 II.ImplicitDefs[0], RC, RC);
633 unsigned FastISel::FastEmitInst_ri(unsigned MachineInstOpcode,
634 const TargetRegisterClass *RC,
635 unsigned Op0, uint64_t Imm) {
636 unsigned ResultReg = createResultReg(RC);
637 const TargetInstrDesc &II = TII.get(MachineInstOpcode);
639 if (II.getNumDefs() >= 1)
640 BuildMI(MBB, II, ResultReg).addReg(Op0).addImm(Imm);
642 BuildMI(MBB, II).addReg(Op0).addImm(Imm);
643 bool InsertedCopy = TII.copyRegToReg(*MBB, MBB->end(), ResultReg,
644 II.ImplicitDefs[0], RC, RC);
651 unsigned FastISel::FastEmitInst_rf(unsigned MachineInstOpcode,
652 const TargetRegisterClass *RC,
653 unsigned Op0, ConstantFP *FPImm) {
654 unsigned ResultReg = createResultReg(RC);
655 const TargetInstrDesc &II = TII.get(MachineInstOpcode);
657 if (II.getNumDefs() >= 1)
658 BuildMI(MBB, II, ResultReg).addReg(Op0).addFPImm(FPImm);
660 BuildMI(MBB, II).addReg(Op0).addFPImm(FPImm);
661 bool InsertedCopy = TII.copyRegToReg(*MBB, MBB->end(), ResultReg,
662 II.ImplicitDefs[0], RC, RC);
669 unsigned FastISel::FastEmitInst_rri(unsigned MachineInstOpcode,
670 const TargetRegisterClass *RC,
671 unsigned Op0, unsigned Op1, uint64_t Imm) {
672 unsigned ResultReg = createResultReg(RC);
673 const TargetInstrDesc &II = TII.get(MachineInstOpcode);
675 if (II.getNumDefs() >= 1)
676 BuildMI(MBB, II, ResultReg).addReg(Op0).addReg(Op1).addImm(Imm);
678 BuildMI(MBB, II).addReg(Op0).addReg(Op1).addImm(Imm);
679 bool InsertedCopy = TII.copyRegToReg(*MBB, MBB->end(), ResultReg,
680 II.ImplicitDefs[0], RC, RC);
687 unsigned FastISel::FastEmitInst_i(unsigned MachineInstOpcode,
688 const TargetRegisterClass *RC,
690 unsigned ResultReg = createResultReg(RC);
691 const TargetInstrDesc &II = TII.get(MachineInstOpcode);
693 if (II.getNumDefs() >= 1)
694 BuildMI(MBB, II, ResultReg).addImm(Imm);
696 BuildMI(MBB, II).addImm(Imm);
697 bool InsertedCopy = TII.copyRegToReg(*MBB, MBB->end(), ResultReg,
698 II.ImplicitDefs[0], RC, RC);
705 unsigned FastISel::FastEmitInst_extractsubreg(unsigned Op0, uint32_t Idx) {
706 const TargetRegisterClass* RC = MRI.getRegClass(Op0);
707 const TargetRegisterClass* SRC = *(RC->subregclasses_begin()+Idx-1);
709 unsigned ResultReg = createResultReg(SRC);
710 const TargetInstrDesc &II = TII.get(TargetInstrInfo::EXTRACT_SUBREG);
712 if (II.getNumDefs() >= 1)
713 BuildMI(MBB, II, ResultReg).addReg(Op0).addImm(Idx);
715 BuildMI(MBB, II).addReg(Op0).addImm(Idx);
716 bool InsertedCopy = TII.copyRegToReg(*MBB, MBB->end(), ResultReg,
717 II.ImplicitDefs[0], RC, RC);