Extend printBasicBlockLabel a bit so that it can be used to print all
authorNate Begeman <natebegeman@mac.com>
Tue, 2 May 2006 05:37:32 +0000 (05:37 +0000)
committerNate Begeman <natebegeman@mac.com>
Tue, 2 May 2006 05:37:32 +0000 (05:37 +0000)
basic block labels, consolidating the code to do so in one place for each
target.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@28050 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/CodeGen/AsmPrinter.h
lib/CodeGen/AsmPrinter.cpp
lib/Target/Alpha/AlphaAsmPrinter.cpp
lib/Target/IA64/IA64AsmPrinter.cpp
lib/Target/PowerPC/PPCAsmPrinter.cpp
lib/Target/Sparc/SparcAsmPrinter.cpp
lib/Target/X86/X86ATTAsmPrinter.cpp
lib/Target/X86/X86AsmPrinter.cpp
lib/Target/X86/X86AsmPrinter.h
lib/Target/X86/X86IntelAsmPrinter.cpp

index a40185b2d7b26924e53ab4341d91a88b4007f592..60bfabf29c375e97738ddada8420c7420745329b 100644 (file)
@@ -276,7 +276,9 @@ namespace llvm {
     
     /// printBasicBlockLabel - This method prints the label for the specified
     /// MachineBasicBlock
-    virtual void printBasicBlockLabel(const MachineBasicBlock *MBB) const;
+    virtual void printBasicBlockLabel(const MachineBasicBlock *MBB,
+                                      bool printColon = false,
+                                      bool printComment = true) const;
     
   private:
     void EmitXXStructorList(Constant *List);
index 1753160e1f0020b45af7fcb169742d3fc78e29bf..76a03dce95d53e0a9fe307b7db096a9a8ca19e4f 100644 (file)
@@ -728,9 +728,14 @@ bool AsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,
 
 /// printBasicBlockLabel - This method prints the label for the specified
 /// MachineBasicBlock
-void AsmPrinter::printBasicBlockLabel(const MachineBasicBlock *MBB) const {
+void AsmPrinter::printBasicBlockLabel(const MachineBasicBlock *MBB,
+                                      bool printColon,
+                                      bool printComment) const {
   O << PrivateGlobalPrefix << "LBB" 
     << Mang->getValueName(MBB->getParent()->getFunction())
-    << "_" << MBB->getNumber() << '\t' << CommentString
-    << MBB->getBasicBlock()->getName();
+    << "_" << MBB->getNumber();
+  if (printColon)
+    O << ':';
+  if (printComment)
+    O << '\t' << CommentString << MBB->getBasicBlock()->getName();
 }
index 5d1f522ca0aeee9c431f722c9ec0eec2aca01af7..b078b68bd7f978de34046cae136df87bc6e35e00 100644 (file)
@@ -191,9 +191,8 @@ bool AlphaAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
   // Print out code for the function.
   for (MachineFunction::const_iterator I = MF.begin(), E = MF.end();
        I != E; ++I) {
-    // Print a label for the basic block.
-    O << PrivateGlobalPrefix << "LBB" << CurrentFnName << "_" << I->getNumber()
-      << ":\t" << CommentString << " " << I->getBasicBlock()->getName() << "\n";
+    printBasicBlockLabel(I, true);
+    O << '\n';
     for (MachineBasicBlock::const_iterator II = I->begin(), E = I->end();
          II != E; ++II) {
       // Print the assembly for the instruction.
index 359b64410447968066605fb71f6d595a5db2cff1..7caf57362bf1df42daf1bb0fad6a5531d2c9af81 100644 (file)
@@ -153,10 +153,10 @@ bool IA64AsmPrinter::runOnMachineFunction(MachineFunction &MF) {
   for (MachineFunction::const_iterator I = MF.begin(), E = MF.end();
        I != E; ++I) {
     // Print a label for the basic block if there are any predecessors.
-    if (I->pred_begin() != I->pred_end())
-      O << PrivateGlobalPrefix << "LBB" << CurrentFnName << "_"
-        << I->getNumber() << ":\t"
-        << CommentString << " " << I->getBasicBlock()->getName() << "\n";
+    if (I->pred_begin() != I->pred_end()) {
+      printBasicBlockLabel(I, true);
+      O << '\n';
+    }
     for (MachineBasicBlock::const_iterator II = I->begin(), E = I->end();
          II != E; ++II) {
       // Print the assembly for the instruction.
index 11c0ec008b55d68ef812ba510f9ac938f2dde1fa..d32b3231fa875ce27d91a224550363fd6b36b92a 100644 (file)
@@ -233,7 +233,9 @@ namespace {
       printOperand(MI, OpNo+1);
     }
     
-    virtual void printBasicBlockLabel(const MachineBasicBlock *MBB) const; 
+    virtual void printBasicBlockLabel(const MachineBasicBlock *MBB,
+                                      bool printColon = false,
+                                      bool printComment = true) const;
     
     virtual bool runOnMachineFunction(MachineFunction &F) = 0;
     virtual bool doFinalization(Module &M) = 0;
@@ -505,10 +507,15 @@ void PPCAsmPrinter::printMachineInstruction(const MachineInstr *MI) {
   return;
 }
 
-void PPCAsmPrinter::printBasicBlockLabel(const MachineBasicBlock *MBB) const {
+void PPCAsmPrinter::printBasicBlockLabel(const MachineBasicBlock *MBB,
+                                         bool printColon,
+                                         bool printComment) const {
   O << PrivateGlobalPrefix << "BB" << getFunctionNumber() << "_"
-    << MBB->getNumber() << '\t' << CommentString
-    << MBB->getBasicBlock()->getName();
+    << MBB->getNumber();
+  if (printColon)
+    O << ':';
+  if (printComment)
+    O << '\t' << CommentString << MBB->getBasicBlock()->getName();
 }
 
 /// runOnMachineFunction - This uses the printMachineInstruction()
@@ -557,11 +564,8 @@ bool DarwinAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
        I != E; ++I) {
     // Print a label for the basic block.
     if (I != MF.begin()) {
-      O << PrivateGlobalPrefix << "BB" << getFunctionNumber() << '_'
-        << I->getNumber() << ":\t";
-      if (!I->getBasicBlock()->getName().empty())
-        O << CommentString << " " << I->getBasicBlock()->getName();
-      O << "\n";
+      printBasicBlockLabel(I, true);
+      O << '\n';
     }
     for (MachineBasicBlock::const_iterator II = I->begin(), E = I->end();
          II != E; ++II) {
index dc1ab545d768966ca0804ee019d8e6e3087e587c..b4c40f1844a25699596db4143bec46331a3e8f9e 100644 (file)
@@ -116,10 +116,10 @@ bool SparcAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
   for (MachineFunction::const_iterator I = MF.begin(), E = MF.end();
        I != E; ++I) {
     // Print a label for the basic block.
-    if (I != MF.begin())
-      O << ".LBB" << Mang->getValueName(MF.getFunction ())
-        << "_" << I->getNumber () << ":\t! "
-        << I->getBasicBlock ()->getName () << "\n";
+    if (I != MF.begin()) {
+      printBasicBlockLabel(I, true);
+      O << '\n';
+    }
     for (MachineBasicBlock::const_iterator II = I->begin(), E = I->end();
          II != E; ++II) {
       // Print the assembly for the instruction.
index 38601188ff633b4be0cad0b9e83f3b09d70b97e0..1b10123514d7af94300eb1ffb946aafe15a2d8c2 100755 (executable)
@@ -80,10 +80,10 @@ bool X86ATTAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
   for (MachineFunction::const_iterator I = MF.begin(), E = MF.end();
        I != E; ++I) {
     // Print a label for the basic block.
-    if (I->pred_begin() != I->pred_end())
-      O << PrivateGlobalPrefix << "BB" << CurrentFnName << "_" << I->getNumber()
-        << ":\t" << CommentString << " " << I->getBasicBlock()->getName()
-        << "\n";
+    if (I->pred_begin() != I->pred_end()) {
+      printBasicBlockLabel(I, true);
+      O << '\n';
+    }
     for (MachineBasicBlock::const_iterator II = I->begin(), E = I->end();
          II != E; ++II) {
       // Print the assembly for the instruction.
index ee1383e6c2e9be522aad8a354d49226775f298a4..2c41663d9d59175982eb6993fa0b445cfaad98fd 100644 (file)
@@ -206,12 +206,16 @@ bool X86SharedAsmPrinter::doFinalization(Module &M) {
   return false; // success
 }
 
-void X86SharedAsmPrinter::printBasicBlockLabel(const MachineBasicBlock *MBB) 
-     const {
+void X86SharedAsmPrinter::printBasicBlockLabel(const MachineBasicBlock *MBB,
+                                               bool printColon,
+                                               bool printComment) const {
   O << PrivateGlobalPrefix << "BB" 
-  << Mang->getValueName(MBB->getParent()->getFunction())
-  << "_" << MBB->getNumber() << '\t' << CommentString
-  << MBB->getBasicBlock()->getName();
+    << Mang->getValueName(MBB->getParent()->getFunction()) << "_" 
+    << MBB->getNumber();
+  if (printColon)
+    O << ':';
+  if (printComment)
+    O << '\t' << CommentString << MBB->getBasicBlock()->getName();
 }
 
 /// createX86CodePrinterPass - Returns a pass that prints the X86 assembly code
index fa84c9ec132d89429d49a241afea9189162c57ca..2d341d928b327167c810f707050d8b8db3943d22 100755 (executable)
@@ -89,7 +89,9 @@ struct X86SharedAsmPrinter : public AsmPrinter {
        MI->getOperand(Op+3).isConstantPoolIndex());
   }
 
-  virtual void printBasicBlockLabel(const MachineBasicBlock *MBB) const; 
+  virtual void printBasicBlockLabel(const MachineBasicBlock *MBB,
+                                    bool printColon = false,
+                                    bool printComment = true) const;
 };
 
 } // end namespace llvm
index 747d576695df444f610c5a637ea4c0ad3928735e..8f12446b61c5246418bb95b2d2d10597c94b01bb 100755 (executable)
@@ -72,10 +72,10 @@ bool X86IntelAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
   for (MachineFunction::const_iterator I = MF.begin(), E = MF.end();
        I != E; ++I) {
     // Print a label for the basic block if there are any predecessors.
-    if (I->pred_begin() != I->pred_end())
-      O << PrivateGlobalPrefix << "BB" << CurrentFnName << "_" << I->getNumber()
-        << ":\t"
-        << CommentString << " " << I->getBasicBlock()->getName() << "\n";
+    if (I->pred_begin() != I->pred_end()) {
+      printBasicBlockLabel(I, true);
+      O << '\n';
+    }
     for (MachineBasicBlock::const_iterator II = I->begin(), E = I->end();
          II != E; ++II) {
       // Print the assembly for the instruction.