Extend printBasicBlockLabel a bit so that it can be used to print all
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
diff --git a/include/llvm/CodeGen/AsmPrinter.h b/include/llvm/CodeGen/AsmPrinter.h
index a40185b..60bfabf 100644
--- a/include/llvm/CodeGen/AsmPrinter.h
+++ b/include/llvm/CodeGen/AsmPrinter.h
@@ -276,7 +276,9 @@
/// 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);
diff --git a/lib/CodeGen/AsmPrinter.cpp b/lib/CodeGen/AsmPrinter.cpp
index 1753160..76a03dc 100644
--- a/lib/CodeGen/AsmPrinter.cpp
+++ b/lib/CodeGen/AsmPrinter.cpp
@@ -728,9 +728,14 @@
/// 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();
}
diff --git a/lib/Target/Alpha/AlphaAsmPrinter.cpp b/lib/Target/Alpha/AlphaAsmPrinter.cpp
index 5d1f522..b078b68 100644
--- a/lib/Target/Alpha/AlphaAsmPrinter.cpp
+++ b/lib/Target/Alpha/AlphaAsmPrinter.cpp
@@ -191,9 +191,8 @@
// 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.
diff --git a/lib/Target/IA64/IA64AsmPrinter.cpp b/lib/Target/IA64/IA64AsmPrinter.cpp
index 359b644..7caf573 100644
--- a/lib/Target/IA64/IA64AsmPrinter.cpp
+++ b/lib/Target/IA64/IA64AsmPrinter.cpp
@@ -153,10 +153,10 @@
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.
diff --git a/lib/Target/PowerPC/PPCAsmPrinter.cpp b/lib/Target/PowerPC/PPCAsmPrinter.cpp
index 11c0ec0..d32b323 100644
--- a/lib/Target/PowerPC/PPCAsmPrinter.cpp
+++ b/lib/Target/PowerPC/PPCAsmPrinter.cpp
@@ -233,7 +233,9 @@
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 @@
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 @@
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) {
diff --git a/lib/Target/Sparc/SparcAsmPrinter.cpp b/lib/Target/Sparc/SparcAsmPrinter.cpp
index dc1ab54..b4c40f1 100644
--- a/lib/Target/Sparc/SparcAsmPrinter.cpp
+++ b/lib/Target/Sparc/SparcAsmPrinter.cpp
@@ -116,10 +116,10 @@
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.
diff --git a/lib/Target/X86/X86ATTAsmPrinter.cpp b/lib/Target/X86/X86ATTAsmPrinter.cpp
index 3860118..1b10123 100755
--- a/lib/Target/X86/X86ATTAsmPrinter.cpp
+++ b/lib/Target/X86/X86ATTAsmPrinter.cpp
@@ -80,10 +80,10 @@
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.
diff --git a/lib/Target/X86/X86AsmPrinter.cpp b/lib/Target/X86/X86AsmPrinter.cpp
index ee1383e..2c41663 100644
--- a/lib/Target/X86/X86AsmPrinter.cpp
+++ b/lib/Target/X86/X86AsmPrinter.cpp
@@ -206,12 +206,16 @@
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
diff --git a/lib/Target/X86/X86AsmPrinter.h b/lib/Target/X86/X86AsmPrinter.h
index fa84c9e..2d341d9 100755
--- a/lib/Target/X86/X86AsmPrinter.h
+++ b/lib/Target/X86/X86AsmPrinter.h
@@ -89,7 +89,9 @@
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
diff --git a/lib/Target/X86/X86IntelAsmPrinter.cpp b/lib/Target/X86/X86IntelAsmPrinter.cpp
index 747d576..8f12446 100755
--- a/lib/Target/X86/X86IntelAsmPrinter.cpp
+++ b/lib/Target/X86/X86IntelAsmPrinter.cpp
@@ -72,10 +72,10 @@
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.