diff options
| author | Roman Divacky <rdivacky@FreeBSD.org> | 2009-11-18 14:58:34 +0000 | 
|---|---|---|
| committer | Roman Divacky <rdivacky@FreeBSD.org> | 2009-11-18 14:58:34 +0000 | 
| commit | 907da171cc911d701da02a5cab898a9c49dd7724 (patch) | |
| tree | 6a111e552c75afc66228e3d8f19b6731e4013f10 /lib/CodeGen/MachineInstr.cpp | |
| parent | 72cc50852bec44580ee7efe1aa2076273008a6ae (diff) | |
Notes
Diffstat (limited to 'lib/CodeGen/MachineInstr.cpp')
| -rw-r--r-- | lib/CodeGen/MachineInstr.cpp | 85 | 
1 files changed, 64 insertions, 21 deletions
diff --git a/lib/CodeGen/MachineInstr.cpp b/lib/CodeGen/MachineInstr.cpp index 5744c8a54552..b250faa62ae6 100644 --- a/lib/CodeGen/MachineInstr.cpp +++ b/lib/CodeGen/MachineInstr.cpp @@ -189,19 +189,19 @@ bool MachineOperand::isIdenticalTo(const MachineOperand &Other) const {  /// print - Print the specified machine operand.  ///  void MachineOperand::print(raw_ostream &OS, const TargetMachine *TM) const { +  // If the instruction is embedded into a basic block, we can find the +  // target info for the instruction. +  if (!TM) +    if (const MachineInstr *MI = getParent()) +      if (const MachineBasicBlock *MBB = MI->getParent()) +        if (const MachineFunction *MF = MBB->getParent()) +          TM = &MF->getTarget(); +    switch (getType()) {    case MachineOperand::MO_Register:      if (getReg() == 0 || TargetRegisterInfo::isVirtualRegister(getReg())) {        OS << "%reg" << getReg();      } else { -      // If the instruction is embedded into a basic block, we can find the -      // target info for the instruction. -      if (TM == 0) -        if (const MachineInstr *MI = getParent()) -          if (const MachineBasicBlock *MBB = MI->getParent()) -            if (const MachineFunction *MF = MBB->getParent()) -              TM = &MF->getTarget(); -              if (TM)          OS << "%" << TM->getRegisterInfo()->get(getReg()).Name;        else @@ -265,7 +265,8 @@ void MachineOperand::print(raw_ostream &OS, const TargetMachine *TM) const {      OS << "<jt#" << getIndex() << '>';      break;    case MachineOperand::MO_GlobalAddress: -    OS << "<ga:" << ((Value*)getGlobal())->getName(); +    OS << "<ga:"; +    WriteAsOperand(OS, getGlobal(), /*PrintType=*/false);      if (getOffset()) OS << "+" << getOffset();      OS << '>';      break; @@ -375,7 +376,7 @@ raw_ostream &llvm::operator<<(raw_ostream &OS, const MachineMemOperand &MMO) {  /// MachineInstr ctor - This constructor creates a dummy MachineInstr with  /// TID NULL and no operands.  MachineInstr::MachineInstr() -  : TID(0), NumImplicitOps(0), MemRefs(0), MemRefsEnd(0), +  : TID(0), NumImplicitOps(0), AsmPrinterFlags(0), MemRefs(0), MemRefsEnd(0),      Parent(0), debugLoc(DebugLoc::getUnknownLoc()) {    // Make sure that we get added to a machine basicblock    LeakDetector::addGarbageObject(this); @@ -395,7 +396,8 @@ void MachineInstr::addImplicitDefUseOperands() {  /// TargetInstrDesc or the numOperands if it is not zero. (for  /// instructions with variable number of operands).  MachineInstr::MachineInstr(const TargetInstrDesc &tid, bool NoImp) -  : TID(&tid), NumImplicitOps(0), MemRefs(0), MemRefsEnd(0), Parent(0), +  : TID(&tid), NumImplicitOps(0), AsmPrinterFlags(0), +    MemRefs(0), MemRefsEnd(0), Parent(0),      debugLoc(DebugLoc::getUnknownLoc()) {    if (!NoImp && TID->getImplicitDefs())      for (const unsigned *ImpDefs = TID->getImplicitDefs(); *ImpDefs; ++ImpDefs) @@ -413,7 +415,7 @@ MachineInstr::MachineInstr(const TargetInstrDesc &tid, bool NoImp)  /// MachineInstr ctor - As above, but with a DebugLoc.  MachineInstr::MachineInstr(const TargetInstrDesc &tid, const DebugLoc dl,                             bool NoImp) -  : TID(&tid), NumImplicitOps(0), MemRefs(0), MemRefsEnd(0), +  : TID(&tid), NumImplicitOps(0), AsmPrinterFlags(0), MemRefs(0), MemRefsEnd(0),      Parent(0), debugLoc(dl) {    if (!NoImp && TID->getImplicitDefs())      for (const unsigned *ImpDefs = TID->getImplicitDefs(); *ImpDefs; ++ImpDefs) @@ -433,7 +435,8 @@ MachineInstr::MachineInstr(const TargetInstrDesc &tid, const DebugLoc dl,  /// basic block.  ///  MachineInstr::MachineInstr(MachineBasicBlock *MBB, const TargetInstrDesc &tid) -  : TID(&tid), NumImplicitOps(0), MemRefs(0), MemRefsEnd(0), Parent(0),  +  : TID(&tid), NumImplicitOps(0), AsmPrinterFlags(0), +    MemRefs(0), MemRefsEnd(0), Parent(0),       debugLoc(DebugLoc::getUnknownLoc()) {    assert(MBB && "Cannot use inserting ctor with null basic block!");    if (TID->ImplicitDefs) @@ -453,7 +456,7 @@ MachineInstr::MachineInstr(MachineBasicBlock *MBB, const TargetInstrDesc &tid)  ///  MachineInstr::MachineInstr(MachineBasicBlock *MBB, const DebugLoc dl,                             const TargetInstrDesc &tid) -  : TID(&tid), NumImplicitOps(0), MemRefs(0), MemRefsEnd(0), +  : TID(&tid), NumImplicitOps(0), AsmPrinterFlags(0), MemRefs(0), MemRefsEnd(0),      Parent(0), debugLoc(dl) {    assert(MBB && "Cannot use inserting ctor with null basic block!");    if (TID->ImplicitDefs) @@ -472,7 +475,7 @@ MachineInstr::MachineInstr(MachineBasicBlock *MBB, const DebugLoc dl,  /// MachineInstr ctor - Copies MachineInstr arg exactly  ///  MachineInstr::MachineInstr(MachineFunction &MF, const MachineInstr &MI) -  : TID(&MI.getDesc()), NumImplicitOps(0), +  : TID(&MI.getDesc()), NumImplicitOps(0), AsmPrinterFlags(0),      MemRefs(MI.MemRefs), MemRefsEnd(MI.MemRefsEnd),      Parent(0), debugLoc(MI.getDebugLoc()) {    Operands.reserve(MI.getNumOperands()); @@ -1060,9 +1063,16 @@ void MachineInstr::dump() const {  }  void MachineInstr::print(raw_ostream &OS, const TargetMachine *TM) const { -  unsigned StartOp = 0, e = getNumOperands(); +  // We can be a bit tidier if we know the TargetMachine and/or MachineFunction. +  const MachineFunction *MF = 0; +  if (const MachineBasicBlock *MBB = getParent()) { +    MF = MBB->getParent(); +    if (!TM && MF) +      TM = &MF->getTarget(); +  }    // Print explicitly defined operands on the left of an assignment syntax. +  unsigned StartOp = 0, e = getNumOperands();    for (; StartOp < e && getOperand(StartOp).isReg() &&           getOperand(StartOp).isDef() &&           !getOperand(StartOp).isImplicit(); @@ -1078,11 +1088,45 @@ void MachineInstr::print(raw_ostream &OS, const TargetMachine *TM) const {    OS << getDesc().getName();    // Print the rest of the operands. +  bool OmittedAnyCallClobbers = false; +  bool FirstOp = true;    for (unsigned i = StartOp, e = getNumOperands(); i != e; ++i) { -    if (i != StartOp) -      OS << ","; +    const MachineOperand &MO = getOperand(i); + +    // Omit call-clobbered registers which aren't used anywhere. This makes +    // call instructions much less noisy on targets where calls clobber lots +    // of registers. Don't rely on MO.isDead() because we may be called before +    // LiveVariables is run, or we may be looking at a non-allocatable reg. +    if (MF && getDesc().isCall() && +        MO.isReg() && MO.isImplicit() && MO.isDef()) { +      unsigned Reg = MO.getReg(); +      if (Reg != 0 && TargetRegisterInfo::isPhysicalRegister(Reg)) { +        const MachineRegisterInfo &MRI = MF->getRegInfo(); +        if (MRI.use_empty(Reg) && !MRI.isLiveOut(Reg)) { +          bool HasAliasLive = false; +          for (const unsigned *Alias = TM->getRegisterInfo()->getAliasSet(Reg); +               unsigned AliasReg = *Alias; ++Alias) +            if (!MRI.use_empty(AliasReg) || MRI.isLiveOut(AliasReg)) { +              HasAliasLive = true; +              break; +            } +          if (!HasAliasLive) { +            OmittedAnyCallClobbers = true; +            continue; +          } +        } +      } +    } + +    if (FirstOp) FirstOp = false; else OS << ",";      OS << " "; -    getOperand(i).print(OS, TM); +    MO.print(OS, TM); +  } + +  // Briefly indicate whether any call clobbers were omitted. +  if (OmittedAnyCallClobbers) { +    if (FirstOp) FirstOp = false; else OS << ","; +    OS << " ...";    }    bool HaveSemi = false; @@ -1098,12 +1142,11 @@ void MachineInstr::print(raw_ostream &OS, const TargetMachine *TM) const {      }    } -  if (!debugLoc.isUnknown()) { +  if (!debugLoc.isUnknown() && MF) {      if (!HaveSemi) OS << ";"; HaveSemi = true;      // TODO: print InlinedAtLoc information -    const MachineFunction *MF = getParent()->getParent();      DebugLocTuple DLT = MF->getDebugLocTuple(debugLoc);      DICompileUnit CU(DLT.Scope);      if (!CU.isNull())  | 
