Skip to content
AsmPrinter.cpp 72.9 KiB
Newer Older
David Greene's avatar
 
David Greene committed
  if (!MI.getDebugLoc().isUnknown()) {
    DILocation DLT = MF->getDILocation(MI.getDebugLoc());
David Greene's avatar
 
David Greene committed

    // Print source line info.
    O.PadToColumn(MAI->getCommentColumn());
    O << MAI->getCommentString() << ' ';
    DIScope Scope = DLT.getScope();
    // Omit the directory, because it's likely to be long and uninteresting.
    if (!Scope.isNull())
      O << Scope.getFilename();
    else
      O << "<unknown>";
    O << ':' << DLT.getLineNumber();
    if (DLT.getColumnNumber() != 0)
      O << ':' << DLT.getColumnNumber();
David Greene's avatar
 
David Greene committed
    Newline = true;
David Greene's avatar
 
David Greene committed
  }
David Greene's avatar
 
David Greene committed

David Greene's avatar
 
David Greene committed
  // Check for spills and reloads
  int FI;

  const MachineFrameInfo *FrameInfo =
    MI.getParent()->getParent()->getFrameInfo();

  // We assume a single instruction only has a spill or reload, not
  // both.
David Greene's avatar
 
David Greene committed
  const MachineMemOperand *MMO;
David Greene's avatar
 
David Greene committed
  if (TM.getInstrInfo()->isLoadFromStackSlotPostFE(&MI, FI)) {
    if (FrameInfo->isSpillSlotObjectIndex(FI)) {
David Greene's avatar
 
David Greene committed
      MMO = *MI.memoperands_begin();
David Greene's avatar
 
David Greene committed
      if (Newline) O << '\n';
      O.PadToColumn(MAI->getCommentColumn());
      O << MAI->getCommentString() << ' ' << MMO->getSize() << "-byte Reload";
David Greene's avatar
 
David Greene committed
      Newline = true;
    }
  }
David Greene's avatar
 
David Greene committed
  else if (TM.getInstrInfo()->hasLoadFromStackSlot(&MI, MMO, FI)) {
David Greene's avatar
 
David Greene committed
    if (FrameInfo->isSpillSlotObjectIndex(FI)) {
      if (Newline) O << '\n';
      O.PadToColumn(MAI->getCommentColumn());
      O << MAI->getCommentString() << ' '
        << MMO->getSize() << "-byte Folded Reload";
David Greene's avatar
 
David Greene committed
      Newline = true;
    }
  }
  else if (TM.getInstrInfo()->isStoreToStackSlotPostFE(&MI, FI)) {
    if (FrameInfo->isSpillSlotObjectIndex(FI)) {
David Greene's avatar
 
David Greene committed
      MMO = *MI.memoperands_begin();
David Greene's avatar
 
David Greene committed
      if (Newline) O << '\n';
      O.PadToColumn(MAI->getCommentColumn());
      O << MAI->getCommentString() << ' ' << MMO->getSize() << "-byte Spill";
David Greene's avatar
 
David Greene committed
      Newline = true;
    }
  }
David Greene's avatar
 
David Greene committed
  else if (TM.getInstrInfo()->hasStoreToStackSlot(&MI, MMO, FI)) {
David Greene's avatar
 
David Greene committed
    if (FrameInfo->isSpillSlotObjectIndex(FI)) {
      if (Newline) O << '\n';
      O.PadToColumn(MAI->getCommentColumn());
      O << MAI->getCommentString() << ' '
        << MMO->getSize() << "-byte Folded Spill";
David Greene's avatar
 
David Greene committed
      Newline = true;
    }
  }

  // Check for spill-induced copies
  unsigned SrcReg, DstReg, SrcSubIdx, DstSubIdx;
  if (TM.getInstrInfo()->isMoveInstr(MI, SrcReg, DstReg,
                                      SrcSubIdx, DstSubIdx)) {
    if (MI.getAsmPrinterFlag(ReloadReuse)) {
      if (Newline) O << '\n';
      O.PadToColumn(MAI->getCommentColumn());
      O << MAI->getCommentString() << " Reload Reuse";
    }
  }
David Greene's avatar
 
David Greene committed
}

David Greene's avatar
 
David Greene committed
/// PrintChildLoopComment - Print comments about child loops within
/// the loop for this basic block, with nesting.
///
static void PrintChildLoopComment(formatted_raw_ostream &O,
                                  const MachineLoop *loop,
David Greene's avatar
 
David Greene committed
                                  int FunctionNumber) {
  // Add child loop information
  for(MachineLoop::iterator cl = loop->begin(),
        clend = loop->end();
      cl != clend;
      ++cl) {
    MachineBasicBlock *Header = (*cl)->getHeader();
    assert(Header && "No header for loop");

    O << '\n';
    O.PadToColumn(MAI->getCommentColumn());
David Greene's avatar
 
David Greene committed

    O.indent(((*cl)->getLoopDepth()-1)*2)
David Greene's avatar
 
David Greene committed
      << " Child Loop BB" << FunctionNumber << "_"
      << Header->getNumber() << " Depth " << (*cl)->getLoopDepth();

    PrintChildLoopComment(O, *cl, MAI, FunctionNumber);
David Greene's avatar
 
David Greene committed
  }
}

David Greene's avatar
 
David Greene committed
/// EmitComments - Pretty-print comments for basic blocks
David Greene's avatar
 
David Greene committed
void AsmPrinter::EmitComments(const MachineBasicBlock &MBB) const {
David Greene's avatar
 
David Greene committed
  if (VerboseAsm) {
David Greene's avatar
 
David Greene committed
    // Add loop depth information
    const MachineLoop *loop = LI->getLoopFor(&MBB);

    if (loop) {
      // Print a newline after bb# annotation.
      O << "\n";
      O.PadToColumn(MAI->getCommentColumn());
      O << MAI->getCommentString() << " Loop Depth " << loop->getLoopDepth()
David Greene's avatar
 
David Greene committed
        << '\n';

      O.PadToColumn(MAI->getCommentColumn());
David Greene's avatar
 
David Greene committed

      MachineBasicBlock *Header = loop->getHeader();
      assert(Header && "No header for loop");
      
      if (Header == &MBB) {
        O << MAI->getCommentString() << " Loop Header";
        PrintChildLoopComment(O, loop, MAI, getFunctionNumber());
David Greene's avatar
 
David Greene committed
      }
      else {
        O << MAI->getCommentString() << " Loop Header is BB"
David Greene's avatar
 
David Greene committed
          << getFunctionNumber() << "_" << loop->getHeader()->getNumber();
      }

      if (loop->empty()) {
        O << '\n';
        O.PadToColumn(MAI->getCommentColumn());
        O << MAI->getCommentString() << " Inner Loop";
David Greene's avatar
 
David Greene committed
      }

      // Add parent loop information
      for (const MachineLoop *CurLoop = loop->getParentLoop();
           CurLoop;
           CurLoop = CurLoop->getParentLoop()) {
        MachineBasicBlock *Header = CurLoop->getHeader();
        assert(Header && "No header for loop");

        O << '\n';
        O.PadToColumn(MAI->getCommentColumn());
        O << MAI->getCommentString();
        O.indent((CurLoop->getLoopDepth()-1)*2)
David Greene's avatar
 
David Greene committed
          << " Inside Loop BB" << getFunctionNumber() << "_"
David Greene's avatar
 
David Greene committed
          << Header->getNumber() << " Depth " << CurLoop->getLoopDepth();
      }
    }
  }
}