LLVM API Documentation

InstrEmitter.cpp
Go to the documentation of this file.
00001 //==--- InstrEmitter.cpp - Emit MachineInstrs for the SelectionDAG class ---==//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This implements the Emit routines for the SelectionDAG class, which creates
00011 // MachineInstrs based on the decisions of the SelectionDAG instruction
00012 // selection.
00013 //
00014 //===----------------------------------------------------------------------===//
00015 
00016 #define DEBUG_TYPE "instr-emitter"
00017 #include "InstrEmitter.h"
00018 #include "SDNodeDbgValue.h"
00019 #include "llvm/ADT/Statistic.h"
00020 #include "llvm/CodeGen/MachineConstantPool.h"
00021 #include "llvm/CodeGen/MachineFunction.h"
00022 #include "llvm/CodeGen/MachineInstrBuilder.h"
00023 #include "llvm/CodeGen/MachineRegisterInfo.h"
00024 #include "llvm/IR/DataLayout.h"
00025 #include "llvm/Support/Debug.h"
00026 #include "llvm/Support/ErrorHandling.h"
00027 #include "llvm/Support/MathExtras.h"
00028 #include "llvm/Target/TargetInstrInfo.h"
00029 #include "llvm/Target/TargetLowering.h"
00030 #include "llvm/Target/TargetMachine.h"
00031 using namespace llvm;
00032 
00033 /// MinRCSize - Smallest register class we allow when constraining virtual
00034 /// registers.  If satisfying all register class constraints would require
00035 /// using a smaller register class, emit a COPY to a new virtual register
00036 /// instead.
00037 const unsigned MinRCSize = 4;
00038 
00039 /// CountResults - The results of target nodes have register or immediate
00040 /// operands first, then an optional chain, and optional glue operands (which do
00041 /// not go into the resulting MachineInstr).
00042 unsigned InstrEmitter::CountResults(SDNode *Node) {
00043   unsigned N = Node->getNumValues();
00044   while (N && Node->getValueType(N - 1) == MVT::Glue)
00045     --N;
00046   if (N && Node->getValueType(N - 1) == MVT::Other)
00047     --N;    // Skip over chain result.
00048   return N;
00049 }
00050 
00051 /// countOperands - The inputs to target nodes have any actual inputs first,
00052 /// followed by an optional chain operand, then an optional glue operand.
00053 /// Compute the number of actual operands that will go into the resulting
00054 /// MachineInstr.
00055 ///
00056 /// Also count physreg RegisterSDNode and RegisterMaskSDNode operands preceding
00057 /// the chain and glue. These operands may be implicit on the machine instr.
00058 static unsigned countOperands(SDNode *Node, unsigned NumExpUses,
00059                               unsigned &NumImpUses) {
00060   unsigned N = Node->getNumOperands();
00061   while (N && Node->getOperand(N - 1).getValueType() == MVT::Glue)
00062     --N;
00063   if (N && Node->getOperand(N - 1).getValueType() == MVT::Other)
00064     --N; // Ignore chain if it exists.
00065 
00066   // Count RegisterSDNode and RegisterMaskSDNode operands for NumImpUses.
00067   NumImpUses = N - NumExpUses;
00068   for (unsigned I = N; I > NumExpUses; --I) {
00069     if (isa<RegisterMaskSDNode>(Node->getOperand(I - 1)))
00070       continue;
00071     if (RegisterSDNode *RN = dyn_cast<RegisterSDNode>(Node->getOperand(I - 1)))
00072       if (TargetRegisterInfo::isPhysicalRegister(RN->getReg()))
00073         continue;
00074     NumImpUses = N - I;
00075     break;
00076   }
00077 
00078   return N;
00079 }
00080 
00081 /// EmitCopyFromReg - Generate machine code for an CopyFromReg node or an
00082 /// implicit physical register output.
00083 void InstrEmitter::
00084 EmitCopyFromReg(SDNode *Node, unsigned ResNo, bool IsClone, bool IsCloned,
00085                 unsigned SrcReg, DenseMap<SDValue, unsigned> &VRBaseMap) {
00086   unsigned VRBase = 0;
00087   if (TargetRegisterInfo::isVirtualRegister(SrcReg)) {
00088     // Just use the input register directly!
00089     SDValue Op(Node, ResNo);
00090     if (IsClone)
00091       VRBaseMap.erase(Op);
00092     bool isNew = VRBaseMap.insert(std::make_pair(Op, SrcReg)).second;
00093     (void)isNew; // Silence compiler warning.
00094     assert(isNew && "Node emitted out of order - early");
00095     return;
00096   }
00097 
00098   // If the node is only used by a CopyToReg and the dest reg is a vreg, use
00099   // the CopyToReg'd destination register instead of creating a new vreg.
00100   bool MatchReg = true;
00101   const TargetRegisterClass *UseRC = NULL;
00102   MVT VT = Node->getSimpleValueType(ResNo);
00103 
00104   // Stick to the preferred register classes for legal types.
00105   if (TLI->isTypeLegal(VT))
00106     UseRC = TLI->getRegClassFor(VT);
00107 
00108   if (!IsClone && !IsCloned)
00109     for (SDNode::use_iterator UI = Node->use_begin(), E = Node->use_end();
00110          UI != E; ++UI) {
00111       SDNode *User = *UI;
00112       bool Match = true;
00113       if (User->getOpcode() == ISD::CopyToReg &&
00114           User->getOperand(2).getNode() == Node &&
00115           User->getOperand(2).getResNo() == ResNo) {
00116         unsigned DestReg = cast<RegisterSDNode>(User->getOperand(1))->getReg();
00117         if (TargetRegisterInfo::isVirtualRegister(DestReg)) {
00118           VRBase = DestReg;
00119           Match = false;
00120         } else if (DestReg != SrcReg)
00121           Match = false;
00122       } else {
00123         for (unsigned i = 0, e = User->getNumOperands(); i != e; ++i) {
00124           SDValue Op = User->getOperand(i);
00125           if (Op.getNode() != Node || Op.getResNo() != ResNo)
00126             continue;
00127           MVT VT = Node->getSimpleValueType(Op.getResNo());
00128           if (VT == MVT::Other || VT == MVT::Glue)
00129             continue;
00130           Match = false;
00131           if (User->isMachineOpcode()) {
00132             const MCInstrDesc &II = TII->get(User->getMachineOpcode());
00133             const TargetRegisterClass *RC = 0;
00134             if (i+II.getNumDefs() < II.getNumOperands()) {
00135               RC = TRI->getAllocatableClass(
00136                 TII->getRegClass(II, i+II.getNumDefs(), TRI, *MF));
00137             }
00138             if (!UseRC)
00139               UseRC = RC;
00140             else if (RC) {
00141               const TargetRegisterClass *ComRC =
00142                 TRI->getCommonSubClass(UseRC, RC);
00143               // If multiple uses expect disjoint register classes, we emit
00144               // copies in AddRegisterOperand.
00145               if (ComRC)
00146                 UseRC = ComRC;
00147             }
00148           }
00149         }
00150       }
00151       MatchReg &= Match;
00152       if (VRBase)
00153         break;
00154     }
00155 
00156   const TargetRegisterClass *SrcRC = 0, *DstRC = 0;
00157   SrcRC = TRI->getMinimalPhysRegClass(SrcReg, VT);
00158 
00159   // Figure out the register class to create for the destreg.
00160   if (VRBase) {
00161     DstRC = MRI->getRegClass(VRBase);
00162   } else if (UseRC) {
00163     assert(UseRC->hasType(VT) && "Incompatible phys register def and uses!");
00164     DstRC = UseRC;
00165   } else {
00166     DstRC = TLI->getRegClassFor(VT);
00167   }
00168 
00169   // If all uses are reading from the src physical register and copying the
00170   // register is either impossible or very expensive, then don't create a copy.
00171   if (MatchReg && SrcRC->getCopyCost() < 0) {
00172     VRBase = SrcReg;
00173   } else {
00174     // Create the reg, emit the copy.
00175     VRBase = MRI->createVirtualRegister(DstRC);
00176     BuildMI(*MBB, InsertPos, Node->getDebugLoc(), TII->get(TargetOpcode::COPY),
00177             VRBase).addReg(SrcReg);
00178   }
00179 
00180   SDValue Op(Node, ResNo);
00181   if (IsClone)
00182     VRBaseMap.erase(Op);
00183   bool isNew = VRBaseMap.insert(std::make_pair(Op, VRBase)).second;
00184   (void)isNew; // Silence compiler warning.
00185   assert(isNew && "Node emitted out of order - early");
00186 }
00187 
00188 /// getDstOfCopyToRegUse - If the only use of the specified result number of
00189 /// node is a CopyToReg, return its destination register. Return 0 otherwise.
00190 unsigned InstrEmitter::getDstOfOnlyCopyToRegUse(SDNode *Node,
00191                                                 unsigned ResNo) const {
00192   if (!Node->hasOneUse())
00193     return 0;
00194 
00195   SDNode *User = *Node->use_begin();
00196   if (User->getOpcode() == ISD::CopyToReg &&
00197       User->getOperand(2).getNode() == Node &&
00198       User->getOperand(2).getResNo() == ResNo) {
00199     unsigned Reg = cast<RegisterSDNode>(User->getOperand(1))->getReg();
00200     if (TargetRegisterInfo::isVirtualRegister(Reg))
00201       return Reg;
00202   }
00203   return 0;
00204 }
00205 
00206 void InstrEmitter::CreateVirtualRegisters(SDNode *Node,
00207                                        MachineInstrBuilder &MIB,
00208                                        const MCInstrDesc &II,
00209                                        bool IsClone, bool IsCloned,
00210                                        DenseMap<SDValue, unsigned> &VRBaseMap) {
00211   assert(Node->getMachineOpcode() != TargetOpcode::IMPLICIT_DEF &&
00212          "IMPLICIT_DEF should have been handled as a special case elsewhere!");
00213 
00214   for (unsigned i = 0; i < II.getNumDefs(); ++i) {
00215     // If the specific node value is only used by a CopyToReg and the dest reg
00216     // is a vreg in the same register class, use the CopyToReg'd destination
00217     // register instead of creating a new vreg.
00218     unsigned VRBase = 0;
00219     const TargetRegisterClass *RC =
00220       TRI->getAllocatableClass(TII->getRegClass(II, i, TRI, *MF));
00221     if (II.OpInfo[i].isOptionalDef()) {
00222       // Optional def must be a physical register.
00223       unsigned NumResults = CountResults(Node);
00224       VRBase = cast<RegisterSDNode>(Node->getOperand(i-NumResults))->getReg();
00225       assert(TargetRegisterInfo::isPhysicalRegister(VRBase));
00226       MIB.addReg(VRBase, RegState::Define);
00227     }
00228 
00229     if (!VRBase && !IsClone && !IsCloned)
00230       for (SDNode::use_iterator UI = Node->use_begin(), E = Node->use_end();
00231            UI != E; ++UI) {
00232         SDNode *User = *UI;
00233         if (User->getOpcode() == ISD::CopyToReg &&
00234             User->getOperand(2).getNode() == Node &&
00235             User->getOperand(2).getResNo() == i) {
00236           unsigned Reg = cast<RegisterSDNode>(User->getOperand(1))->getReg();
00237           if (TargetRegisterInfo::isVirtualRegister(Reg)) {
00238             const TargetRegisterClass *RegRC = MRI->getRegClass(Reg);
00239             if (RegRC == RC) {
00240               VRBase = Reg;
00241               MIB.addReg(VRBase, RegState::Define);
00242               break;
00243             }
00244           }
00245         }
00246       }
00247 
00248     // Create the result registers for this node and add the result regs to
00249     // the machine instruction.
00250     if (VRBase == 0) {
00251       assert(RC && "Isn't a register operand!");
00252       VRBase = MRI->createVirtualRegister(RC);
00253       MIB.addReg(VRBase, RegState::Define);
00254     }
00255 
00256     SDValue Op(Node, i);
00257     if (IsClone)
00258       VRBaseMap.erase(Op);
00259     bool isNew = VRBaseMap.insert(std::make_pair(Op, VRBase)).second;
00260     (void)isNew; // Silence compiler warning.
00261     assert(isNew && "Node emitted out of order - early");
00262   }
00263 }
00264 
00265 /// getVR - Return the virtual register corresponding to the specified result
00266 /// of the specified node.
00267 unsigned InstrEmitter::getVR(SDValue Op,
00268                              DenseMap<SDValue, unsigned> &VRBaseMap) {
00269   if (Op.isMachineOpcode() &&
00270       Op.getMachineOpcode() == TargetOpcode::IMPLICIT_DEF) {
00271     // Add an IMPLICIT_DEF instruction before every use.
00272     unsigned VReg = getDstOfOnlyCopyToRegUse(Op.getNode(), Op.getResNo());
00273     // IMPLICIT_DEF can produce any type of result so its MCInstrDesc
00274     // does not include operand register class info.
00275     if (!VReg) {
00276       const TargetRegisterClass *RC =
00277         TLI->getRegClassFor(Op.getSimpleValueType());
00278       VReg = MRI->createVirtualRegister(RC);
00279     }
00280     BuildMI(*MBB, InsertPos, Op.getDebugLoc(),
00281             TII->get(TargetOpcode::IMPLICIT_DEF), VReg);
00282     return VReg;
00283   }
00284 
00285   DenseMap<SDValue, unsigned>::iterator I = VRBaseMap.find(Op);
00286   assert(I != VRBaseMap.end() && "Node emitted out of order - late");
00287   return I->second;
00288 }
00289 
00290 
00291 /// AddRegisterOperand - Add the specified register as an operand to the
00292 /// specified machine instr. Insert register copies if the register is
00293 /// not in the required register class.
00294 void
00295 InstrEmitter::AddRegisterOperand(MachineInstrBuilder &MIB,
00296                                  SDValue Op,
00297                                  unsigned IIOpNum,
00298                                  const MCInstrDesc *II,
00299                                  DenseMap<SDValue, unsigned> &VRBaseMap,
00300                                  bool IsDebug, bool IsClone, bool IsCloned) {
00301   assert(Op.getValueType() != MVT::Other &&
00302          Op.getValueType() != MVT::Glue &&
00303          "Chain and glue operands should occur at end of operand list!");
00304   // Get/emit the operand.
00305   unsigned VReg = getVR(Op, VRBaseMap);
00306   assert(TargetRegisterInfo::isVirtualRegister(VReg) && "Not a vreg?");
00307 
00308   const MCInstrDesc &MCID = MIB->getDesc();
00309   bool isOptDef = IIOpNum < MCID.getNumOperands() &&
00310     MCID.OpInfo[IIOpNum].isOptionalDef();
00311 
00312   // If the instruction requires a register in a different class, create
00313   // a new virtual register and copy the value into it, but first attempt to
00314   // shrink VReg's register class within reason.  For example, if VReg == GR32
00315   // and II requires a GR32_NOSP, just constrain VReg to GR32_NOSP.
00316   if (II) {
00317     const TargetRegisterClass *DstRC = 0;
00318     if (IIOpNum < II->getNumOperands())
00319       DstRC = TRI->getAllocatableClass(TII->getRegClass(*II,IIOpNum,TRI,*MF));
00320     if (DstRC && !MRI->constrainRegClass(VReg, DstRC, MinRCSize)) {
00321       unsigned NewVReg = MRI->createVirtualRegister(DstRC);
00322       BuildMI(*MBB, InsertPos, Op.getNode()->getDebugLoc(),
00323               TII->get(TargetOpcode::COPY), NewVReg).addReg(VReg);
00324       VReg = NewVReg;
00325     }
00326   }
00327 
00328   // If this value has only one use, that use is a kill. This is a
00329   // conservative approximation. InstrEmitter does trivial coalescing
00330   // with CopyFromReg nodes, so don't emit kill flags for them.
00331   // Avoid kill flags on Schedule cloned nodes, since there will be
00332   // multiple uses.
00333   // Tied operands are never killed, so we need to check that. And that
00334   // means we need to determine the index of the operand.
00335   bool isKill = Op.hasOneUse() &&
00336                 Op.getNode()->getOpcode() != ISD::CopyFromReg &&
00337                 !IsDebug &&
00338                 !(IsClone || IsCloned);
00339   if (isKill) {
00340     unsigned Idx = MIB->getNumOperands();
00341     while (Idx > 0 &&
00342            MIB->getOperand(Idx-1).isReg() &&
00343            MIB->getOperand(Idx-1).isImplicit())
00344       --Idx;
00345     bool isTied = MCID.getOperandConstraint(Idx, MCOI::TIED_TO) != -1;
00346     if (isTied)
00347       isKill = false;
00348   }
00349 
00350   MIB.addReg(VReg, getDefRegState(isOptDef) | getKillRegState(isKill) |
00351              getDebugRegState(IsDebug));
00352 }
00353 
00354 /// AddOperand - Add the specified operand to the specified machine instr.  II
00355 /// specifies the instruction information for the node, and IIOpNum is the
00356 /// operand number (in the II) that we are adding.
00357 void InstrEmitter::AddOperand(MachineInstrBuilder &MIB,
00358                               SDValue Op,
00359                               unsigned IIOpNum,
00360                               const MCInstrDesc *II,
00361                               DenseMap<SDValue, unsigned> &VRBaseMap,
00362                               bool IsDebug, bool IsClone, bool IsCloned) {
00363   if (Op.isMachineOpcode()) {
00364     AddRegisterOperand(MIB, Op, IIOpNum, II, VRBaseMap,
00365                        IsDebug, IsClone, IsCloned);
00366   } else if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Op)) {
00367     MIB.addImm(C->getSExtValue());
00368   } else if (ConstantFPSDNode *F = dyn_cast<ConstantFPSDNode>(Op)) {
00369     MIB.addFPImm(F->getConstantFPValue());
00370   } else if (RegisterSDNode *R = dyn_cast<RegisterSDNode>(Op)) {
00371     // Turn additional physreg operands into implicit uses on non-variadic
00372     // instructions. This is used by call and return instructions passing
00373     // arguments in registers.
00374     bool Imp = II && (IIOpNum >= II->getNumOperands() && !II->isVariadic());
00375     MIB.addReg(R->getReg(), getImplRegState(Imp));
00376   } else if (RegisterMaskSDNode *RM = dyn_cast<RegisterMaskSDNode>(Op)) {
00377     MIB.addRegMask(RM->getRegMask());
00378   } else if (GlobalAddressSDNode *TGA = dyn_cast<GlobalAddressSDNode>(Op)) {
00379     MIB.addGlobalAddress(TGA->getGlobal(), TGA->getOffset(),
00380                          TGA->getTargetFlags());
00381   } else if (BasicBlockSDNode *BBNode = dyn_cast<BasicBlockSDNode>(Op)) {
00382     MIB.addMBB(BBNode->getBasicBlock());
00383   } else if (FrameIndexSDNode *FI = dyn_cast<FrameIndexSDNode>(Op)) {
00384     MIB.addFrameIndex(FI->getIndex());
00385   } else if (JumpTableSDNode *JT = dyn_cast<JumpTableSDNode>(Op)) {
00386     MIB.addJumpTableIndex(JT->getIndex(), JT->getTargetFlags());
00387   } else if (ConstantPoolSDNode *CP = dyn_cast<ConstantPoolSDNode>(Op)) {
00388     int Offset = CP->getOffset();
00389     unsigned Align = CP->getAlignment();
00390     Type *Type = CP->getType();
00391     // MachineConstantPool wants an explicit alignment.
00392     if (Align == 0) {
00393       Align = TM->getDataLayout()->getPrefTypeAlignment(Type);
00394       if (Align == 0) {
00395         // Alignment of vector types.  FIXME!
00396         Align = TM->getDataLayout()->getTypeAllocSize(Type);
00397       }
00398     }
00399 
00400     unsigned Idx;
00401     MachineConstantPool *MCP = MF->getConstantPool();
00402     if (CP->isMachineConstantPoolEntry())
00403       Idx = MCP->getConstantPoolIndex(CP->getMachineCPVal(), Align);
00404     else
00405       Idx = MCP->getConstantPoolIndex(CP->getConstVal(), Align);
00406     MIB.addConstantPoolIndex(Idx, Offset, CP->getTargetFlags());
00407   } else if (ExternalSymbolSDNode *ES = dyn_cast<ExternalSymbolSDNode>(Op)) {
00408     MIB.addExternalSymbol(ES->getSymbol(), ES->getTargetFlags());
00409   } else if (BlockAddressSDNode *BA = dyn_cast<BlockAddressSDNode>(Op)) {
00410     MIB.addBlockAddress(BA->getBlockAddress(),
00411                         BA->getOffset(),
00412                         BA->getTargetFlags());
00413   } else if (TargetIndexSDNode *TI = dyn_cast<TargetIndexSDNode>(Op)) {
00414     MIB.addTargetIndex(TI->getIndex(), TI->getOffset(), TI->getTargetFlags());
00415   } else {
00416     assert(Op.getValueType() != MVT::Other &&
00417            Op.getValueType() != MVT::Glue &&
00418            "Chain and glue operands should occur at end of operand list!");
00419     AddRegisterOperand(MIB, Op, IIOpNum, II, VRBaseMap,
00420                        IsDebug, IsClone, IsCloned);
00421   }
00422 }
00423 
00424 unsigned InstrEmitter::ConstrainForSubReg(unsigned VReg, unsigned SubIdx,
00425                                           MVT VT, DebugLoc DL) {
00426   const TargetRegisterClass *VRC = MRI->getRegClass(VReg);
00427   const TargetRegisterClass *RC = TRI->getSubClassWithSubReg(VRC, SubIdx);
00428 
00429   // RC is a sub-class of VRC that supports SubIdx.  Try to constrain VReg
00430   // within reason.
00431   if (RC && RC != VRC)
00432     RC = MRI->constrainRegClass(VReg, RC, MinRCSize);
00433 
00434   // VReg has been adjusted.  It can be used with SubIdx operands now.
00435   if (RC)
00436     return VReg;
00437 
00438   // VReg couldn't be reasonably constrained.  Emit a COPY to a new virtual
00439   // register instead.
00440   RC = TRI->getSubClassWithSubReg(TLI->getRegClassFor(VT), SubIdx);
00441   assert(RC && "No legal register class for VT supports that SubIdx");
00442   unsigned NewReg = MRI->createVirtualRegister(RC);
00443   BuildMI(*MBB, InsertPos, DL, TII->get(TargetOpcode::COPY), NewReg)
00444     .addReg(VReg);
00445   return NewReg;
00446 }
00447 
00448 /// EmitSubregNode - Generate machine code for subreg nodes.
00449 ///
00450 void InstrEmitter::EmitSubregNode(SDNode *Node,
00451                                   DenseMap<SDValue, unsigned> &VRBaseMap,
00452                                   bool IsClone, bool IsCloned) {
00453   unsigned VRBase = 0;
00454   unsigned Opc = Node->getMachineOpcode();
00455 
00456   // If the node is only used by a CopyToReg and the dest reg is a vreg, use
00457   // the CopyToReg'd destination register instead of creating a new vreg.
00458   for (SDNode::use_iterator UI = Node->use_begin(), E = Node->use_end();
00459        UI != E; ++UI) {
00460     SDNode *User = *UI;
00461     if (User->getOpcode() == ISD::CopyToReg &&
00462         User->getOperand(2).getNode() == Node) {
00463       unsigned DestReg = cast<RegisterSDNode>(User->getOperand(1))->getReg();
00464       if (TargetRegisterInfo::isVirtualRegister(DestReg)) {
00465         VRBase = DestReg;
00466         break;
00467       }
00468     }
00469   }
00470 
00471   if (Opc == TargetOpcode::EXTRACT_SUBREG) {
00472     // EXTRACT_SUBREG is lowered as %dst = COPY %src:sub.  There are no
00473     // constraints on the %dst register, COPY can target all legal register
00474     // classes.
00475     unsigned SubIdx = cast<ConstantSDNode>(Node->getOperand(1))->getZExtValue();
00476     const TargetRegisterClass *TRC =
00477       TLI->getRegClassFor(Node->getSimpleValueType(0));
00478 
00479     unsigned VReg = getVR(Node->getOperand(0), VRBaseMap);
00480     MachineInstr *DefMI = MRI->getVRegDef(VReg);
00481     unsigned SrcReg, DstReg, DefSubIdx;
00482     if (DefMI &&
00483         TII->isCoalescableExtInstr(*DefMI, SrcReg, DstReg, DefSubIdx) &&
00484         SubIdx == DefSubIdx &&
00485         TRC == MRI->getRegClass(SrcReg)) {
00486       // Optimize these:
00487       // r1025 = s/zext r1024, 4
00488       // r1026 = extract_subreg r1025, 4
00489       // to a copy
00490       // r1026 = copy r1024
00491       VRBase = MRI->createVirtualRegister(TRC);
00492       BuildMI(*MBB, InsertPos, Node->getDebugLoc(),
00493               TII->get(TargetOpcode::COPY), VRBase).addReg(SrcReg);
00494       MRI->clearKillFlags(SrcReg);
00495     } else {
00496       // VReg may not support a SubIdx sub-register, and we may need to
00497       // constrain its register class or issue a COPY to a compatible register
00498       // class.
00499       VReg = ConstrainForSubReg(VReg, SubIdx,
00500                                 Node->getOperand(0).getSimpleValueType(),
00501                                 Node->getDebugLoc());
00502 
00503       // Create the destreg if it is missing.
00504       if (VRBase == 0)
00505         VRBase = MRI->createVirtualRegister(TRC);
00506 
00507       // Create the extract_subreg machine instruction.
00508       BuildMI(*MBB, InsertPos, Node->getDebugLoc(),
00509               TII->get(TargetOpcode::COPY), VRBase).addReg(VReg, 0, SubIdx);
00510     }
00511   } else if (Opc == TargetOpcode::INSERT_SUBREG ||
00512              Opc == TargetOpcode::SUBREG_TO_REG) {
00513     SDValue N0 = Node->getOperand(0);
00514     SDValue N1 = Node->getOperand(1);
00515     SDValue N2 = Node->getOperand(2);
00516     unsigned SubIdx = cast<ConstantSDNode>(N2)->getZExtValue();
00517 
00518     // Figure out the register class to create for the destreg.  It should be
00519     // the largest legal register class supporting SubIdx sub-registers.
00520     // RegisterCoalescer will constrain it further if it decides to eliminate
00521     // the INSERT_SUBREG instruction.
00522     //
00523     //   %dst = INSERT_SUBREG %src, %sub, SubIdx
00524     //
00525     // is lowered by TwoAddressInstructionPass to:
00526     //
00527     //   %dst = COPY %src
00528     //   %dst:SubIdx = COPY %sub
00529     //
00530     // There is no constraint on the %src register class.
00531     //
00532     const TargetRegisterClass *SRC = TLI->getRegClassFor(Node->getSimpleValueType(0));
00533     SRC = TRI->getSubClassWithSubReg(SRC, SubIdx);
00534     assert(SRC && "No register class supports VT and SubIdx for INSERT_SUBREG");
00535 
00536     if (VRBase == 0 || !SRC->hasSubClassEq(MRI->getRegClass(VRBase)))
00537       VRBase = MRI->createVirtualRegister(SRC);
00538 
00539     // Create the insert_subreg or subreg_to_reg machine instruction.
00540     MachineInstrBuilder MIB =
00541       BuildMI(*MF, Node->getDebugLoc(), TII->get(Opc), VRBase);
00542 
00543     // If creating a subreg_to_reg, then the first input operand
00544     // is an implicit value immediate, otherwise it's a register
00545     if (Opc == TargetOpcode::SUBREG_TO_REG) {
00546       const ConstantSDNode *SD = cast<ConstantSDNode>(N0);
00547       MIB.addImm(SD->getZExtValue());
00548     } else
00549       AddOperand(MIB, N0, 0, 0, VRBaseMap, /*IsDebug=*/false,
00550                  IsClone, IsCloned);
00551     // Add the subregster being inserted
00552     AddOperand(MIB, N1, 0, 0, VRBaseMap, /*IsDebug=*/false,
00553                IsClone, IsCloned);
00554     MIB.addImm(SubIdx);
00555     MBB->insert(InsertPos, MIB);
00556   } else
00557     llvm_unreachable("Node is not insert_subreg, extract_subreg, or subreg_to_reg");
00558 
00559   SDValue Op(Node, 0);
00560   bool isNew = VRBaseMap.insert(std::make_pair(Op, VRBase)).second;
00561   (void)isNew; // Silence compiler warning.
00562   assert(isNew && "Node emitted out of order - early");
00563 }
00564 
00565 /// EmitCopyToRegClassNode - Generate machine code for COPY_TO_REGCLASS nodes.
00566 /// COPY_TO_REGCLASS is just a normal copy, except that the destination
00567 /// register is constrained to be in a particular register class.
00568 ///
00569 void
00570 InstrEmitter::EmitCopyToRegClassNode(SDNode *Node,
00571                                      DenseMap<SDValue, unsigned> &VRBaseMap) {
00572   unsigned VReg = getVR(Node->getOperand(0), VRBaseMap);
00573 
00574   // Create the new VReg in the destination class and emit a copy.
00575   unsigned DstRCIdx = cast<ConstantSDNode>(Node->getOperand(1))->getZExtValue();
00576   const TargetRegisterClass *DstRC =
00577     TRI->getAllocatableClass(TRI->getRegClass(DstRCIdx));
00578   unsigned NewVReg = MRI->createVirtualRegister(DstRC);
00579   BuildMI(*MBB, InsertPos, Node->getDebugLoc(), TII->get(TargetOpcode::COPY),
00580     NewVReg).addReg(VReg);
00581 
00582   SDValue Op(Node, 0);
00583   bool isNew = VRBaseMap.insert(std::make_pair(Op, NewVReg)).second;
00584   (void)isNew; // Silence compiler warning.
00585   assert(isNew && "Node emitted out of order - early");
00586 }
00587 
00588 /// EmitRegSequence - Generate machine code for REG_SEQUENCE nodes.
00589 ///
00590 void InstrEmitter::EmitRegSequence(SDNode *Node,
00591                                   DenseMap<SDValue, unsigned> &VRBaseMap,
00592                                   bool IsClone, bool IsCloned) {
00593   unsigned DstRCIdx = cast<ConstantSDNode>(Node->getOperand(0))->getZExtValue();
00594   const TargetRegisterClass *RC = TRI->getRegClass(DstRCIdx);
00595   unsigned NewVReg = MRI->createVirtualRegister(TRI->getAllocatableClass(RC));
00596   const MCInstrDesc &II = TII->get(TargetOpcode::REG_SEQUENCE);
00597   MachineInstrBuilder MIB = BuildMI(*MF, Node->getDebugLoc(), II, NewVReg);
00598   unsigned NumOps = Node->getNumOperands();
00599   assert((NumOps & 1) == 1 &&
00600          "REG_SEQUENCE must have an odd number of operands!");
00601   for (unsigned i = 1; i != NumOps; ++i) {
00602     SDValue Op = Node->getOperand(i);
00603     if ((i & 1) == 0) {
00604       RegisterSDNode *R = dyn_cast<RegisterSDNode>(Node->getOperand(i-1));
00605       // Skip physical registers as they don't have a vreg to get and we'll
00606       // insert copies for them in TwoAddressInstructionPass anyway.
00607       if (!R || !TargetRegisterInfo::isPhysicalRegister(R->getReg())) {
00608         unsigned SubIdx = cast<ConstantSDNode>(Op)->getZExtValue();
00609         unsigned SubReg = getVR(Node->getOperand(i-1), VRBaseMap);
00610         const TargetRegisterClass *TRC = MRI->getRegClass(SubReg);
00611         const TargetRegisterClass *SRC =
00612         TRI->getMatchingSuperRegClass(RC, TRC, SubIdx);
00613         if (SRC && SRC != RC) {
00614           MRI->setRegClass(NewVReg, SRC);
00615           RC = SRC;
00616         }
00617       }
00618     }
00619     AddOperand(MIB, Op, i+1, &II, VRBaseMap, /*IsDebug=*/false,
00620                IsClone, IsCloned);
00621   }
00622 
00623   MBB->insert(InsertPos, MIB);
00624   SDValue Op(Node, 0);
00625   bool isNew = VRBaseMap.insert(std::make_pair(Op, NewVReg)).second;
00626   (void)isNew; // Silence compiler warning.
00627   assert(isNew && "Node emitted out of order - early");
00628 }
00629 
00630 /// EmitDbgValue - Generate machine instruction for a dbg_value node.
00631 ///
00632 MachineInstr *
00633 InstrEmitter::EmitDbgValue(SDDbgValue *SD,
00634                            DenseMap<SDValue, unsigned> &VRBaseMap) {
00635   uint64_t Offset = SD->getOffset();
00636   MDNode* MDPtr = SD->getMDPtr();
00637   DebugLoc DL = SD->getDebugLoc();
00638 
00639   if (SD->getKind() == SDDbgValue::FRAMEIX) {
00640     // Stack address; this needs to be lowered in target-dependent fashion.
00641     // EmitTargetCodeForFrameDebugValue is responsible for allocation.
00642     unsigned FrameIx = SD->getFrameIx();
00643     return TII->emitFrameIndexDebugValue(*MF, FrameIx, Offset, MDPtr, DL);
00644   }
00645   // Otherwise, we're going to create an instruction here.
00646   const MCInstrDesc &II = TII->get(TargetOpcode::DBG_VALUE);
00647   MachineInstrBuilder MIB = BuildMI(*MF, DL, II);
00648   if (SD->getKind() == SDDbgValue::SDNODE) {
00649     SDNode *Node = SD->getSDNode();
00650     SDValue Op = SDValue(Node, SD->getResNo());
00651     // It's possible we replaced this SDNode with other(s) and therefore
00652     // didn't generate code for it.  It's better to catch these cases where
00653     // they happen and transfer the debug info, but trying to guarantee that
00654     // in all cases would be very fragile; this is a safeguard for any
00655     // that were missed.
00656     DenseMap<SDValue, unsigned>::iterator I = VRBaseMap.find(Op);
00657     if (I==VRBaseMap.end())
00658       MIB.addReg(0U);       // undef
00659     else
00660       AddOperand(MIB, Op, (*MIB).getNumOperands(), &II, VRBaseMap,
00661                  /*IsDebug=*/true, /*IsClone=*/false, /*IsCloned=*/false);
00662   } else if (SD->getKind() == SDDbgValue::CONST) {
00663     const Value *V = SD->getConst();
00664     if (const ConstantInt *CI = dyn_cast<ConstantInt>(V)) {
00665       if (CI->getBitWidth() > 64)
00666         MIB.addCImm(CI);
00667       else
00668         MIB.addImm(CI->getSExtValue());
00669     } else if (const ConstantFP *CF = dyn_cast<ConstantFP>(V)) {
00670       MIB.addFPImm(CF);
00671     } else {
00672       // Could be an Undef.  In any case insert an Undef so we can see what we
00673       // dropped.
00674       MIB.addReg(0U);
00675     }
00676   } else {
00677     // Insert an Undef so we can see what we dropped.
00678     MIB.addReg(0U);
00679   }
00680 
00681   MIB.addImm(Offset).addMetadata(MDPtr);
00682   return &*MIB;
00683 }
00684 
00685 /// EmitMachineNode - Generate machine code for a target-specific node and
00686 /// needed dependencies.
00687 ///
00688 void InstrEmitter::
00689 EmitMachineNode(SDNode *Node, bool IsClone, bool IsCloned,
00690                 DenseMap<SDValue, unsigned> &VRBaseMap) {
00691   unsigned Opc = Node->getMachineOpcode();
00692 
00693   // Handle subreg insert/extract specially
00694   if (Opc == TargetOpcode::EXTRACT_SUBREG ||
00695       Opc == TargetOpcode::INSERT_SUBREG ||
00696       Opc == TargetOpcode::SUBREG_TO_REG) {
00697     EmitSubregNode(Node, VRBaseMap, IsClone, IsCloned);
00698     return;
00699   }
00700 
00701   // Handle COPY_TO_REGCLASS specially.
00702   if (Opc == TargetOpcode::COPY_TO_REGCLASS) {
00703     EmitCopyToRegClassNode(Node, VRBaseMap);
00704     return;
00705   }
00706 
00707   // Handle REG_SEQUENCE specially.
00708   if (Opc == TargetOpcode::REG_SEQUENCE) {
00709     EmitRegSequence(Node, VRBaseMap, IsClone, IsCloned);
00710     return;
00711   }
00712 
00713   if (Opc == TargetOpcode::IMPLICIT_DEF)
00714     // We want a unique VR for each IMPLICIT_DEF use.
00715     return;
00716 
00717   const MCInstrDesc &II = TII->get(Opc);
00718   unsigned NumResults = CountResults(Node);
00719   unsigned NumImpUses = 0;
00720   unsigned NodeOperands =
00721     countOperands(Node, II.getNumOperands() - II.getNumDefs(), NumImpUses);
00722   bool HasPhysRegOuts = NumResults > II.getNumDefs() && II.getImplicitDefs()!=0;
00723 #ifndef NDEBUG
00724   unsigned NumMIOperands = NodeOperands + NumResults;
00725   if (II.isVariadic())
00726     assert(NumMIOperands >= II.getNumOperands() &&
00727            "Too few operands for a variadic node!");
00728   else
00729     assert(NumMIOperands >= II.getNumOperands() &&
00730            NumMIOperands <= II.getNumOperands() + II.getNumImplicitDefs() +
00731                             NumImpUses &&
00732            "#operands for dag node doesn't match .td file!");
00733 #endif
00734 
00735   // Create the new machine instruction.
00736   MachineInstrBuilder MIB = BuildMI(*MF, Node->getDebugLoc(), II);
00737 
00738   // Add result register values for things that are defined by this
00739   // instruction.
00740   if (NumResults)
00741     CreateVirtualRegisters(Node, MIB, II, IsClone, IsCloned, VRBaseMap);
00742 
00743   // Emit all of the actual operands of this instruction, adding them to the
00744   // instruction as appropriate.
00745   bool HasOptPRefs = II.getNumDefs() > NumResults;
00746   assert((!HasOptPRefs || !HasPhysRegOuts) &&
00747          "Unable to cope with optional defs and phys regs defs!");
00748   unsigned NumSkip = HasOptPRefs ? II.getNumDefs() - NumResults : 0;
00749   for (unsigned i = NumSkip; i != NodeOperands; ++i)
00750     AddOperand(MIB, Node->getOperand(i), i-NumSkip+II.getNumDefs(), &II,
00751                VRBaseMap, /*IsDebug=*/false, IsClone, IsCloned);
00752 
00753   // Transfer all of the memory reference descriptions of this instruction.
00754   MIB.setMemRefs(cast<MachineSDNode>(Node)->memoperands_begin(),
00755                  cast<MachineSDNode>(Node)->memoperands_end());
00756 
00757   // Insert the instruction into position in the block. This needs to
00758   // happen before any custom inserter hook is called so that the
00759   // hook knows where in the block to insert the replacement code.
00760   MBB->insert(InsertPos, MIB);
00761 
00762   // The MachineInstr may also define physregs instead of virtregs.  These
00763   // physreg values can reach other instructions in different ways:
00764   //
00765   // 1. When there is a use of a Node value beyond the explicitly defined
00766   //    virtual registers, we emit a CopyFromReg for one of the implicitly
00767   //    defined physregs.  This only happens when HasPhysRegOuts is true.
00768   //
00769   // 2. A CopyFromReg reading a physreg may be glued to this instruction.
00770   //
00771   // 3. A glued instruction may implicitly use a physreg.
00772   //
00773   // 4. A glued instruction may use a RegisterSDNode operand.
00774   //
00775   // Collect all the used physreg defs, and make sure that any unused physreg
00776   // defs are marked as dead.
00777   SmallVector<unsigned, 8> UsedRegs;
00778 
00779   // Additional results must be physical register defs.
00780   if (HasPhysRegOuts) {
00781     for (unsigned i = II.getNumDefs(); i < NumResults; ++i) {
00782       unsigned Reg = II.getImplicitDefs()[i - II.getNumDefs()];
00783       if (!Node->hasAnyUseOfValue(i))
00784         continue;
00785       // This implicitly defined physreg has a use.
00786       UsedRegs.push_back(Reg);
00787       EmitCopyFromReg(Node, i, IsClone, IsCloned, Reg, VRBaseMap);
00788     }
00789   }
00790 
00791   // Scan the glue chain for any used physregs.
00792   if (Node->getValueType(Node->getNumValues()-1) == MVT::Glue) {
00793     for (SDNode *F = Node->getGluedUser(); F; F = F->getGluedUser()) {
00794       if (F->getOpcode() == ISD::CopyFromReg) {
00795         UsedRegs.push_back(cast<RegisterSDNode>(F->getOperand(1))->getReg());
00796         continue;
00797       } else if (F->getOpcode() == ISD::CopyToReg) {
00798         // Skip CopyToReg nodes that are internal to the glue chain.
00799         continue;
00800       }
00801       // Collect declared implicit uses.
00802       const MCInstrDesc &MCID = TII->get(F->getMachineOpcode());
00803       UsedRegs.append(MCID.getImplicitUses(),
00804                       MCID.getImplicitUses() + MCID.getNumImplicitUses());
00805       // In addition to declared implicit uses, we must also check for
00806       // direct RegisterSDNode operands.
00807       for (unsigned i = 0, e = F->getNumOperands(); i != e; ++i)
00808         if (RegisterSDNode *R = dyn_cast<RegisterSDNode>(F->getOperand(i))) {
00809           unsigned Reg = R->getReg();
00810           if (TargetRegisterInfo::isPhysicalRegister(Reg))
00811             UsedRegs.push_back(Reg);
00812         }
00813     }
00814   }
00815 
00816   // Finally mark unused registers as dead.
00817   if (!UsedRegs.empty() || II.getImplicitDefs())
00818     MIB->setPhysRegsDeadExcept(UsedRegs, *TRI);
00819 
00820   // Run post-isel target hook to adjust this instruction if needed.
00821 #ifdef NDEBUG
00822   if (II.hasPostISelHook())
00823 #endif
00824     TLI->AdjustInstrPostInstrSelection(MIB, Node);
00825 }
00826 
00827 /// EmitSpecialNode - Generate machine code for a target-independent node and
00828 /// needed dependencies.
00829 void InstrEmitter::
00830 EmitSpecialNode(SDNode *Node, bool IsClone, bool IsCloned,
00831                 DenseMap<SDValue, unsigned> &VRBaseMap) {
00832   switch (Node->getOpcode()) {
00833   default:
00834 #ifndef NDEBUG
00835     Node->dump();
00836 #endif
00837     llvm_unreachable("This target-independent node should have been selected!");
00838   case ISD::EntryToken:
00839     llvm_unreachable("EntryToken should have been excluded from the schedule!");
00840   case ISD::MERGE_VALUES:
00841   case ISD::TokenFactor: // fall thru
00842     break;
00843   case ISD::CopyToReg: {
00844     unsigned SrcReg;
00845     SDValue SrcVal = Node->getOperand(2);
00846     if (RegisterSDNode *R = dyn_cast<RegisterSDNode>(SrcVal))
00847       SrcReg = R->getReg();
00848     else
00849       SrcReg = getVR(SrcVal, VRBaseMap);
00850 
00851     unsigned DestReg = cast<RegisterSDNode>(Node->getOperand(1))->getReg();
00852     if (SrcReg == DestReg) // Coalesced away the copy? Ignore.
00853       break;
00854 
00855     BuildMI(*MBB, InsertPos, Node->getDebugLoc(), TII->get(TargetOpcode::COPY),
00856             DestReg).addReg(SrcReg);
00857     break;
00858   }
00859   case ISD::CopyFromReg: {
00860     unsigned SrcReg = cast<RegisterSDNode>(Node->getOperand(1))->getReg();
00861     EmitCopyFromReg(Node, 0, IsClone, IsCloned, SrcReg, VRBaseMap);
00862     break;
00863   }
00864   case ISD::EH_LABEL: {
00865     MCSymbol *S = cast<EHLabelSDNode>(Node)->getLabel();
00866     BuildMI(*MBB, InsertPos, Node->getDebugLoc(),
00867             TII->get(TargetOpcode::EH_LABEL)).addSym(S);
00868     break;
00869   }
00870 
00871   case ISD::LIFETIME_START:
00872   case ISD::LIFETIME_END: {
00873     unsigned TarOp = (Node->getOpcode() == ISD::LIFETIME_START) ?
00874     TargetOpcode::LIFETIME_START : TargetOpcode::LIFETIME_END;
00875 
00876     FrameIndexSDNode *FI = dyn_cast<FrameIndexSDNode>(Node->getOperand(1));
00877     BuildMI(*MBB, InsertPos, Node->getDebugLoc(), TII->get(TarOp))
00878     .addFrameIndex(FI->getIndex());
00879     break;
00880   }
00881 
00882   case ISD::INLINEASM: {
00883     unsigned NumOps = Node->getNumOperands();
00884     if (Node->getOperand(NumOps-1).getValueType() == MVT::Glue)
00885       --NumOps;  // Ignore the glue operand.
00886 
00887     // Create the inline asm machine instruction.
00888     MachineInstrBuilder MIB = BuildMI(*MF, Node->getDebugLoc(),
00889                                       TII->get(TargetOpcode::INLINEASM));
00890 
00891     // Add the asm string as an external symbol operand.
00892     SDValue AsmStrV = Node->getOperand(InlineAsm::Op_AsmString);
00893     const char *AsmStr = cast<ExternalSymbolSDNode>(AsmStrV)->getSymbol();
00894     MIB.addExternalSymbol(AsmStr);
00895 
00896     // Add the HasSideEffect, isAlignStack, AsmDialect, MayLoad and MayStore
00897     // bits.
00898     int64_t ExtraInfo =
00899       cast<ConstantSDNode>(Node->getOperand(InlineAsm::Op_ExtraInfo))->
00900                           getZExtValue();
00901     MIB.addImm(ExtraInfo);
00902 
00903     // Remember to operand index of the group flags.
00904     SmallVector<unsigned, 8> GroupIdx;
00905 
00906     // Add all of the operand registers to the instruction.
00907     for (unsigned i = InlineAsm::Op_FirstOperand; i != NumOps;) {
00908       unsigned Flags =
00909         cast<ConstantSDNode>(Node->getOperand(i))->getZExtValue();
00910       const unsigned NumVals = InlineAsm::getNumOperandRegisters(Flags);
00911 
00912       GroupIdx.push_back(MIB->getNumOperands());
00913       MIB.addImm(Flags);
00914       ++i;  // Skip the ID value.
00915 
00916       switch (InlineAsm::getKind(Flags)) {
00917       default: llvm_unreachable("Bad flags!");
00918         case InlineAsm::Kind_RegDef:
00919         for (unsigned j = 0; j != NumVals; ++j, ++i) {
00920           unsigned Reg = cast<RegisterSDNode>(Node->getOperand(i))->getReg();
00921           // FIXME: Add dead flags for physical and virtual registers defined.
00922           // For now, mark physical register defs as implicit to help fast
00923           // regalloc. This makes inline asm look a lot like calls.
00924           MIB.addReg(Reg, RegState::Define |
00925                   getImplRegState(TargetRegisterInfo::isPhysicalRegister(Reg)));
00926         }
00927         break;
00928       case InlineAsm::Kind_RegDefEarlyClobber:
00929       case InlineAsm::Kind_Clobber:
00930         for (unsigned j = 0; j != NumVals; ++j, ++i) {
00931           unsigned Reg = cast<RegisterSDNode>(Node->getOperand(i))->getReg();
00932           MIB.addReg(Reg, RegState::Define | RegState::EarlyClobber |
00933                   getImplRegState(TargetRegisterInfo::isPhysicalRegister(Reg)));
00934         }
00935         break;
00936       case InlineAsm::Kind_RegUse:  // Use of register.
00937       case InlineAsm::Kind_Imm:  // Immediate.
00938       case InlineAsm::Kind_Mem:  // Addressing mode.
00939         // The addressing mode has been selected, just add all of the
00940         // operands to the machine instruction.
00941         for (unsigned j = 0; j != NumVals; ++j, ++i)
00942           AddOperand(MIB, Node->getOperand(i), 0, 0, VRBaseMap,
00943                      /*IsDebug=*/false, IsClone, IsCloned);
00944 
00945         // Manually set isTied bits.
00946         if (InlineAsm::getKind(Flags) == InlineAsm::Kind_RegUse) {
00947           unsigned DefGroup = 0;
00948           if (InlineAsm::isUseOperandTiedToDef(Flags, DefGroup)) {
00949             unsigned DefIdx = GroupIdx[DefGroup] + 1;
00950             unsigned UseIdx = GroupIdx.back() + 1;
00951             for (unsigned j = 0; j != NumVals; ++j)
00952               MIB->tieOperands(DefIdx + j, UseIdx + j);
00953           }
00954         }
00955         break;
00956       }
00957     }
00958 
00959     // Get the mdnode from the asm if it exists and add it to the instruction.
00960     SDValue MDV = Node->getOperand(InlineAsm::Op_MDNode);
00961     const MDNode *MD = cast<MDNodeSDNode>(MDV)->getMD();
00962     if (MD)
00963       MIB.addMetadata(MD);
00964 
00965     MBB->insert(InsertPos, MIB);
00966     break;
00967   }
00968   }
00969 }
00970 
00971 /// InstrEmitter - Construct an InstrEmitter and set it to start inserting
00972 /// at the given position in the given block.
00973 InstrEmitter::InstrEmitter(MachineBasicBlock *mbb,
00974                            MachineBasicBlock::iterator insertpos)
00975   : MF(mbb->getParent()),
00976     MRI(&MF->getRegInfo()),
00977     TM(&MF->getTarget()),
00978     TII(TM->getInstrInfo()),
00979     TRI(TM->getRegisterInfo()),
00980     TLI(TM->getTargetLowering()),
00981     MBB(mbb), InsertPos(insertpos) {
00982 }