add a new MachineBasicBlock::getSymbol method, replacing
authorChris Lattner <sabre@nondot.org>
Tue, 26 Jan 2010 04:55:51 +0000 (04:55 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 26 Jan 2010 04:55:51 +0000 (04:55 +0000)
the AsmPrinter::GetMBBSymbol.

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

19 files changed:
include/llvm/CodeGen/AsmPrinter.h
include/llvm/CodeGen/MachineBasicBlock.h
lib/CodeGen/AsmPrinter/AsmPrinter.cpp
lib/CodeGen/MachineBasicBlock.cpp
lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp
lib/Target/ARM/AsmPrinter/ARMMCInstLower.cpp
lib/Target/Alpha/AsmPrinter/AlphaAsmPrinter.cpp
lib/Target/Blackfin/AsmPrinter/BlackfinAsmPrinter.cpp
lib/Target/CellSPU/AsmPrinter/SPUAsmPrinter.cpp
lib/Target/MSP430/AsmPrinter/MSP430AsmPrinter.cpp
lib/Target/MSP430/AsmPrinter/MSP430MCInstLower.cpp
lib/Target/Mips/AsmPrinter/MipsAsmPrinter.cpp
lib/Target/PIC16/AsmPrinter/PIC16AsmPrinter.cpp
lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp
lib/Target/Sparc/AsmPrinter/SparcAsmPrinter.cpp
lib/Target/SystemZ/AsmPrinter/SystemZAsmPrinter.cpp
lib/Target/X86/AsmPrinter/X86AsmPrinter.cpp
lib/Target/X86/AsmPrinter/X86MCInstLower.cpp
lib/Target/XCore/AsmPrinter/XCoreAsmPrinter.cpp

index 696b70485106cc70a6f22756f6eeb61cc0513d96..98a28a2eee58ef8713fc1d336e226e4c7a849626 100644 (file)
@@ -301,10 +301,6 @@ namespace llvm {
     /// ExternalSymbol.
     MCSymbol *GetExternalSymbolSymbol(StringRef Sym) const;
     
-    /// GetMBBSymbol - Return the MCSymbol corresponding to the specified basic
-    /// block label.
-    MCSymbol *GetMBBSymbol(unsigned MBBID) const;
-    
     /// GetCPISymbol - Return the symbol for the specified constant pool entry.
     MCSymbol *GetCPISymbol(unsigned CPID) const;
 
index 20644c17e1adb5d30d52ad180712a0297f92ee92..283322b7461ba8f08f7db097ef6e89984794c34e 100644 (file)
@@ -352,6 +352,10 @@ public:
   int getNumber() const { return Number; }
   void setNumber(int N) { Number = N; }
 
+  /// getSymbol - Return the MCSymbol for this basic block.
+  ///
+  MCSymbol *getSymbol(MCContext &Ctx) const;
+  
 private:   // Methods used to maintain doubly linked list of blocks...
   friend struct ilist_traits<MachineBasicBlock>;
 
index 537993373a6e36654795d8706093bfa955ee8315..5c46da52c2af49cc28819d5166949ba0b38339f0 100644 (file)
@@ -534,7 +534,7 @@ void AsmPrinter::EmitJumpTableInfo(MachineFunction &MF) {
       // In non-pic mode, the entries in the jump table are direct references
       // to the basic blocks.
       for (unsigned ii = 0, ee = JTBBs.size(); ii != ee; ++ii) {
-        MCSymbol *MBBSym = GetMBBSymbol(JTBBs[ii]->getNumber());
+        MCSymbol *MBBSym = JTBBs[ii]->getSymbol(OutContext);
         OutStreamer.EmitValue(MCSymbolRefExpr::Create(MBBSym, OutContext),
                               EntrySize, /*addrspace*/0);
       }      
@@ -557,13 +557,13 @@ void AsmPrinter::printPICJumpTableEntry(const MachineJumpTableInfo *MJTI,
   case MachineJumpTableInfo::EK_BlockAddress:
     // EK_BlockAddress - Each entry is a plain address of block, e.g.:
     //     .word LBB123
-    Value = MCSymbolRefExpr::Create(GetMBBSymbol(MBB->getNumber()), OutContext);
+    Value = MCSymbolRefExpr::Create(MBB->getSymbol(OutContext), OutContext);
     break;
   case MachineJumpTableInfo::EK_GPRel32BlockAddress: {
     // EK_GPRel32BlockAddress - Each entry is an address of block, encoded
     // with a relocation as gp-relative, e.g.:
     //     .gprel32 LBB123
-    MCSymbol *MBBSym = GetMBBSymbol(MBB->getNumber());
+    MCSymbol *MBBSym = MBB->getSymbol(OutContext);
     OutStreamer.EmitGPRel32Value(MCSymbolRefExpr::Create(MBBSym, OutContext));
     return;
   }
@@ -587,7 +587,7 @@ void AsmPrinter::printPICJumpTableEntry(const MachineJumpTableInfo *MJTI,
       break;
     }
     // Otherwise, use the difference as the jump table entry.
-    Value = MCSymbolRefExpr::Create(GetMBBSymbol(MBB->getNumber()), OutContext);
+    Value = MCSymbolRefExpr::Create(MBB->getSymbol(OutContext), OutContext);
     const MCExpr *JTI = MCSymbolRefExpr::Create(GetJTISymbol(uid), OutContext);
     Value = MCBinaryExpr::CreateSub(Value, JTI, OutContext);
     break;
@@ -1286,7 +1286,7 @@ void AsmPrinter::printInlineAsm(const MachineInstr *MI) const {
           ++OpNo;  // Skip over the ID number.
 
           if (Modifier[0] == 'l')  // labels are target independent
-            O << *GetMBBSymbol(MI->getOperand(OpNo).getMBB()->getNumber());
+            O << *MI->getOperand(OpNo).getMBB()->getSymbol(OutContext);
           else {
             AsmPrinter *AP = const_cast<AsmPrinter*>(this);
             if ((OpFlags & 7) == 4) {
@@ -1386,13 +1386,6 @@ MCSymbol *AsmPrinter::GetBlockAddressSymbol(const Function *F,
   return OutContext.GetOrCreateSymbol(NameResult.str());
 }
 
-MCSymbol *AsmPrinter::GetMBBSymbol(unsigned MBBID) const {
-  SmallString<60> Name;
-  raw_svector_ostream(Name) << MAI->getPrivateGlobalPrefix() << "BB"
-    << getFunctionNumber() << '_' << MBBID;
-  return OutContext.GetOrCreateSymbol(Name.str());
-}
-
 /// GetCPISymbol - Return the symbol for the specified constant pool entry.
 MCSymbol *AsmPrinter::GetCPISymbol(unsigned CPID) const {
   SmallString<60> Name;
@@ -1555,7 +1548,7 @@ void AsmPrinter::EmitBasicBlockStart(const MachineBasicBlock *MBB) const {
       PrintBasicBlockLoopComments(*MBB, LI, *this);
     }
 
-    OutStreamer.EmitLabel(GetMBBSymbol(MBB->getNumber()));
+    OutStreamer.EmitLabel(MBB->getSymbol(OutContext));
   }
 }
 
@@ -1568,7 +1561,7 @@ void AsmPrinter::printPICJumpTableSetLabel(unsigned uid,
   
   O << MAI->getSetDirective() << ' ' << MAI->getPrivateGlobalPrefix()
     << *GetJTSetSymbol(uid, MBB->getNumber()) << ','
-    << *GetMBBSymbol(MBB->getNumber()) << '-' << *GetJTISymbol(uid) << '\n';
+    << *MBB->getSymbol(OutContext) << '-' << *GetJTISymbol(uid) << '\n';
 }
 
 void AsmPrinter::printVisibility(MCSymbol *Sym, unsigned Visibility) const {
index 9215bd583b59b707239acc33d9d8dc8f18e51488..9c318a50274b5e314cf39d7cfc71a9ea6bd345c6 100644 (file)
 #include "llvm/CodeGen/MachineBasicBlock.h"
 #include "llvm/BasicBlock.h"
 #include "llvm/CodeGen/MachineFunction.h"
+#include "llvm/MC/MCAsmInfo.h"
+#include "llvm/MC/MCContext.h"
 #include "llvm/Target/TargetRegisterInfo.h"
 #include "llvm/Target/TargetData.h"
 #include "llvm/Target/TargetInstrDesc.h"
 #include "llvm/Target/TargetInstrInfo.h"
 #include "llvm/Target/TargetMachine.h"
+#include "llvm/Assembly/Writer.h"
+#include "llvm/ADT/SmallString.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/LeakDetector.h"
 #include "llvm/Support/raw_ostream.h"
-#include "llvm/Assembly/Writer.h"
 #include <algorithm>
 using namespace llvm;
 
@@ -36,6 +39,18 @@ MachineBasicBlock::~MachineBasicBlock() {
   LeakDetector::removeGarbageObject(this);
 }
 
+/// getSymbol - Return the MCSymbol for this basic block.
+///
+MCSymbol *MachineBasicBlock::getSymbol(MCContext &Ctx) const {
+  SmallString<60> Name;
+  const MachineFunction *MF = getParent();
+  raw_svector_ostream(Name)
+    << MF->getTarget().getMCAsmInfo()->getPrivateGlobalPrefix() << "BB"
+    << MF->getFunctionNumber() << '_' << getNumber();
+  return Ctx.GetOrCreateSymbol(Name.str());
+}
+
+
 raw_ostream &llvm::operator<<(raw_ostream &OS, const MachineBasicBlock &MBB) {
   MBB.print(OS);
   return OS;
index 8b711fd54e46d27631513905c23b54997c156bcc..bb6fc2f2dfae8f63f7eabc615680be2e55dd9783 100644 (file)
@@ -369,7 +369,7 @@ void ARMAsmPrinter::printOperand(const MachineInstr *MI, int OpNum,
     break;
   }
   case MachineOperand::MO_MachineBasicBlock:
-    O << *GetMBBSymbol(MO.getMBB()->getNumber());
+    O << *MO.getMBB()->getSymbol(OutContext);
     return;
   case MachineOperand::MO_GlobalAddress: {
     bool isCallOp = Modifier && !strcmp(Modifier, "call");
@@ -948,16 +948,16 @@ void ARMAsmPrinter::printJTBlockOperand(const MachineInstr *MI, int OpNum) {
     if (UseSet && isNew) {
       O << MAI->getSetDirective() << ' '
         << *GetARMSetPICJumpTableLabel2(JTI, MO2.getImm(), MBB) << ','
-        << *GetMBBSymbol(MBB->getNumber()) << '-' << *JTISymbol << '\n';
+        << *MBB->getSymbol(OutContext) << '-' << *JTISymbol << '\n';
     }
 
     O << JTEntryDirective << ' ';
     if (UseSet)
       O << *GetARMSetPICJumpTableLabel2(JTI, MO2.getImm(), MBB);
     else if (TM.getRelocationModel() == Reloc::PIC_)
-      O << *GetMBBSymbol(MBB->getNumber()) << '-' << *JTISymbol;
+      O << *MBB->getSymbol(OutContext) << '-' << *JTISymbol;
     else
-      O << *GetMBBSymbol(MBB->getNumber());
+      O << *MBB->getSymbol(OutContext);
 
     if (i != e-1)
       O << '\n';
@@ -989,9 +989,9 @@ void ARMAsmPrinter::printJT2BlockOperand(const MachineInstr *MI, int OpNum) {
       O << MAI->getData16bitsDirective();
     
     if (ByteOffset || HalfWordOffset)
-      O << '(' << *GetMBBSymbol(MBB->getNumber()) << "-" << *JTISymbol << ")/2";
+      O << '(' << *MBB->getSymbol(OutContext) << "-" << *JTISymbol << ")/2";
     else
-      O << "\tb.w " << *GetMBBSymbol(MBB->getNumber());
+      O << "\tb.w " << *MBB->getSymbol(OutContext);
 
     if (i != e-1)
       O << '\n';
index f843ee2b0d4232c119c1c4036e2df79c3ca13779..1b2dd48db8f480593a136488daa405c55c81e468 100644 (file)
@@ -135,7 +135,7 @@ void ARMMCInstLower::Lower(const MachineInstr *MI, MCInst &OutMI) const {
       break;
     case MachineOperand::MO_MachineBasicBlock:
       MCOp = MCOperand::CreateExpr(MCSymbolRefExpr::Create(
-                       Printer.GetMBBSymbol(MO.getMBB()->getNumber()), Ctx));
+                       MO.getMBB()->getSymbol(Ctx), Ctx));
       break;
     case MachineOperand::MO_GlobalAddress:
       MCOp = LowerSymbolOperand(MO, GetGlobalAddressSymbol(MO));
index c22ff75fe733f7aefe32355b6dc3439218d4c2ce..f6a65a203078ce71e78101bc87666784a7f73c76 100644 (file)
@@ -93,7 +93,7 @@ void AlphaAsmPrinter::printOp(const MachineOperand &MO, bool IsCallOp) {
     return;
 
   case MachineOperand::MO_MachineBasicBlock:
-    O << *GetMBBSymbol(MO.getMBB()->getNumber());
+    O << *MO.getMBB()->getSymbol(OutContext);
     return;
 
   case MachineOperand::MO_ConstantPoolIndex:
index de623bc64a83170cd5179dda7cae2c5fea8a86c5..7d9759726ea25ef785b2e2051ba3ae50ade9d345 100644 (file)
@@ -152,7 +152,7 @@ void BlackfinAsmPrinter::printOperand(const MachineInstr *MI, int opNum) {
     O << MO.getImm();
     break;
   case MachineOperand::MO_MachineBasicBlock:
-    O << *GetMBBSymbol(MO.getMBB()->getNumber());
+    O << *MO.getMBB()->getSymbol(OutContext);
     return;
   case MachineOperand::MO_GlobalAddress:
     O << *GetGlobalValueSymbol(MO.getGlobal());
index 08b45ea86f934f047811c6cab32a4f55baa413a5..af28f89f83f35619e3b7aa86e03aaed7cc4e058d 100644 (file)
@@ -312,7 +312,7 @@ void SPUAsmPrinter::printOp(const MachineOperand &MO) {
     return;
 
   case MachineOperand::MO_MachineBasicBlock:
-    O << *GetMBBSymbol(MO.getMBB()->getNumber());
+    O << *MO.getMBB()->getSymbol(OutContext);
     return;
   case MachineOperand::MO_JumpTableIndex:
     O << MAI->getPrivateGlobalPrefix() << "JTI" << getFunctionNumber()
index 6033197e263ced62178d986d0000a61df60bb0e4..4748cc55eaeacdd3ee0236632d639c315d248a4f 100644 (file)
@@ -173,7 +173,7 @@ void MSP430AsmPrinter::printOperand(const MachineInstr *MI, int OpNum,
     O << MO.getImm();
     return;
   case MachineOperand::MO_MachineBasicBlock:
-    O << *GetMBBSymbol(MO.getMBB()->getNumber());
+    O << *MO.getMBB()->getSymbol(OutContext);
     return;
   case MachineOperand::MO_GlobalAddress: {
     bool isMemOp  = Modifier && !strcmp(Modifier, "mem");
index e1f80b7d843e6158df3ab79a11629dda0494cf16..4eb7f3d9cf53fc44ab7628c9cc78cc94b9e7c4bb 100644 (file)
@@ -116,7 +116,7 @@ void MSP430MCInstLower::Lower(const MachineInstr *MI, MCInst &OutMI) const {
       break;
     case MachineOperand::MO_MachineBasicBlock:
       MCOp = MCOperand::CreateExpr(MCSymbolRefExpr::Create(
-                         Printer.GetMBBSymbol(MO.getMBB()->getNumber()), Ctx));
+                         MO.getMBB()->getSymbol(Printer.OutContext), Ctx));
       break;
     case MachineOperand::MO_GlobalAddress:
       MCOp = LowerSymbolOperand(MO, GetGlobalAddressSymbol(MO));
index d96e207101f4ee81cdd114239c04a25077c5f485..49e5e6060680d2236d53ab1eefaa765d2e587ba3 100644 (file)
@@ -341,7 +341,7 @@ void MipsAsmPrinter::printOperand(const MachineInstr *MI, int opNum) {
       break;
 
     case MachineOperand::MO_MachineBasicBlock:
-      O << *GetMBBSymbol(MO.getMBB()->getNumber());
+      O << *MO.getMBB()->getSymbol(OutContext);
       return;
 
     case MachineOperand::MO_GlobalAddress:
index f20c8044077dc1a472ef81733684ba34e943f6f7..a7c22951a91cef338206b6d848f893bbfa434bc6 100644 (file)
@@ -209,7 +209,7 @@ void PIC16AsmPrinter::printOperand(const MachineInstr *MI, int opNum) {
       break;
     }
     case MachineOperand::MO_MachineBasicBlock:
-      O << *GetMBBSymbol(MO.getMBB()->getNumber());
+      O << *MO.getMBB()->getSymbol(OutContext);
       return;
 
     default:
index e6fb24722ccfc4058aaec0c06be7f98bee716a36..922ea1a18056d431b704bc65d99efa151e250404 100644 (file)
@@ -382,7 +382,7 @@ void PPCAsmPrinter::printOp(const MachineOperand &MO) {
     llvm_unreachable("printOp() does not handle immediate values");
 
   case MachineOperand::MO_MachineBasicBlock:
-    O << *GetMBBSymbol(MO.getMBB()->getNumber());
+    O << *MO.getMBB()->getSymbol(OutContext);
     return;
   case MachineOperand::MO_JumpTableIndex:
     O << MAI->getPrivateGlobalPrefix() << "JTI" << getFunctionNumber()
index 1026dbaa7fb8731399cdc6fd9d12bae086a463cb..28dfa6310021fcbaba2b538a821fc9bb93571b6e 100644 (file)
@@ -191,7 +191,7 @@ void SparcAsmPrinter::printOperand(const MachineInstr *MI, int opNum) {
     O << (int)MO.getImm();
     break;
   case MachineOperand::MO_MachineBasicBlock:
-    O << *GetMBBSymbol(MO.getMBB()->getNumber());
+    O << *MO.getMBB()->getSymbol(OutContext);
     return;
   case MachineOperand::MO_GlobalAddress:
     O << *GetGlobalValueSymbol(MO.getGlobal());
index 59260f63e81815a468edbb1f71ec85c303a15b23..15508afa29bc306024b7c51c70023eca02e3d5be 100644 (file)
@@ -166,7 +166,7 @@ void SystemZAsmPrinter::printPCRelImmOperand(const MachineInstr *MI, int OpNum){
     O << MO.getImm();
     return;
   case MachineOperand::MO_MachineBasicBlock:
-    O << *GetMBBSymbol(MO.getMBB()->getNumber());
+    O << *MO.getMBB()->getSymbol(OutContext);
     return;
   case MachineOperand::MO_GlobalAddress: {
     const GlobalValue *GV = MO.getGlobal();
@@ -221,7 +221,7 @@ void SystemZAsmPrinter::printOperand(const MachineInstr *MI, int OpNum,
     O << MO.getImm();
     return;
   case MachineOperand::MO_MachineBasicBlock:
-    O << *GetMBBSymbol(MO.getMBB()->getNumber());
+    O << *MO.getMBB()->getSymbol(OutContext);
     return;
   case MachineOperand::MO_JumpTableIndex:
     O << MAI->getPrivateGlobalPrefix() << "JTI" << getFunctionNumber() << '_'
index c5ed9180127c290b0013ee91b1cd062e77f836c9..6e53f0eeb759d2dd3af330f58d603b9f37c5c44e 100644 (file)
@@ -340,7 +340,7 @@ void X86AsmPrinter::print_pcrel_imm(const MachineInstr *MI, unsigned OpNo) {
     O << MO.getImm();
     return;
   case MachineOperand::MO_MachineBasicBlock:
-    O << *GetMBBSymbol(MO.getMBB()->getNumber());
+    O << *MO.getMBB()->getSymbol(OutContext);
     return;
   case MachineOperand::MO_GlobalAddress:
   case MachineOperand::MO_ExternalSymbol:
@@ -465,7 +465,7 @@ void X86AsmPrinter::printPICJumpTableSetLabel(unsigned uid,
   O << MAI->getSetDirective() << ' ' << MAI->getPrivateGlobalPrefix()
     << getFunctionNumber() << '_' << uid << "_set_" << MBB->getNumber() << ',';
   
-  O << *GetMBBSymbol(MBB->getNumber());
+  O << *MBB->getSymbol(OutContext);
   
   if (Subtarget->isPICStyleRIPRel())
     O << '-' << *GetJTISymbol(uid) << '\n';
@@ -495,9 +495,9 @@ void X86AsmPrinter::printPICJumpTableEntry(const MachineJumpTableInfo *MJTI,
   if (Subtarget->isPICStyleRIPRel() || Subtarget->isPICStyleStubPIC()) {
     O << *GetJTSetSymbol(uid, MBB->getNumber());
   } else if (Subtarget->isPICStyleGOT())
-    O << *GetMBBSymbol(MBB->getNumber()) << "@GOTOFF";
+    O << *MBB->getSymbol(OutContext) << "@GOTOFF";
   else  // mdynamic-no-pic
-    O << *GetMBBSymbol(MBB->getNumber());
+    O << *MBB->getSymbol(OutContext);
   O << '\n';
 }
 
index 86b50a51c64a1c110bfd172d1d48c63b6462a495..f40d1324b8d0257414af636b9b90944fdfa2560e 100644 (file)
@@ -323,7 +323,7 @@ void X86MCInstLower::Lower(const MachineInstr *MI, MCInst &OutMI) const {
       break;
     case MachineOperand::MO_MachineBasicBlock:
       MCOp = MCOperand::CreateExpr(MCSymbolRefExpr::Create(
-                       AsmPrinter.GetMBBSymbol(MO.getMBB()->getNumber()), Ctx));
+                       MO.getMBB()->getSymbol(Ctx), Ctx));
       break;
     case MachineOperand::MO_GlobalAddress:
       MCOp = LowerSymbolOperand(MO, GetGlobalAddressSymbol(MO));
index 5f1e2d090a8cfb94c225a5dc41bb2a8b8e6cb728..e955ef96ee0a684816a67fad045102e9312893ef 100644 (file)
@@ -297,7 +297,7 @@ void XCoreAsmPrinter::printOperand(const MachineInstr *MI, int opNum) {
     O << MO.getImm();
     break;
   case MachineOperand::MO_MachineBasicBlock:
-    O << *GetMBBSymbol(MO.getMBB()->getNumber());
+    O << *MO.getMBB()->getSymbol(OutContext);
     break;
   case MachineOperand::MO_GlobalAddress:
     O << *GetGlobalValueSymbol(MO.getGlobal());