Revert 42908 for now.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@42960 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/AsmPrinter.cpp b/lib/CodeGen/AsmPrinter.cpp
index e8ce0b7..47a5345 100644
--- a/lib/CodeGen/AsmPrinter.cpp
+++ b/lib/CodeGen/AsmPrinter.cpp
@@ -35,7 +35,7 @@
 char AsmPrinter::ID = 0;
 AsmPrinter::AsmPrinter(std::ostream &o, TargetMachine &tm,
                        const TargetAsmInfo *T)
-  : MachineFunctionPass((intptr_t)&ID), O(o), TM(tm), TAI(T)
+  : MachineFunctionPass((intptr_t)&ID), FunctionNumber(0), O(o), TM(tm), TAI(T)
 {}
 
 std::string AsmPrinter::getSectionForFunction(const Function &F) const {
@@ -169,6 +169,7 @@
 void AsmPrinter::SetupMachineFunction(MachineFunction &MF) {
   // What's my mangled name?
   CurrentFnName = Mang->getValueName(MF.getFunction());
+  IncrementFunctionNumber();
 }
 
 /// EmitConstantPool - Print to the current output stream assembly
@@ -218,9 +219,8 @@
   SwitchToDataSection(Section);
   EmitAlignment(Alignment);
   for (unsigned i = 0, e = CP.size(); i != e; ++i) {
-    O << TAI->getPrivateGlobalPrefix() << "CPI" << CP[i].second
-      << '_' << CurrentFnName
-      << ":\t\t\t\t\t" << TAI->getCommentString() << ' ';
+    O << TAI->getPrivateGlobalPrefix() << "CPI" << getFunctionNumber() << '_'
+      << CP[i].second << ":\t\t\t\t\t" << TAI->getCommentString() << " ";
     WriteTypeSymbolic(O, CP[i].first.getType(), 0) << '\n';
     if (CP[i].first.isMachineConstantPoolEntry())
       EmitMachineConstantPoolValue(CP[i].first.Val.MachineCPVal);
@@ -293,10 +293,10 @@
     // the assembler and linker the extents of the jump table object.  The
     // second label is actually referenced by the code.
     if (const char *JTLabelPrefix = TAI->getJumpTableSpecialLabelPrefix())
-      O << JTLabelPrefix << "JTI" << i << '_' << CurrentFnName << ":\n";
+      O << JTLabelPrefix << "JTI" << getFunctionNumber() << '_' << i << ":\n";
     
-    O << TAI->getPrivateGlobalPrefix() << "JTI" << i
-      << '_' << CurrentFnName << ":\n";
+    O << TAI->getPrivateGlobalPrefix() << "JTI" << getFunctionNumber() 
+      << '_' << i << ":\n";
     
     for (unsigned ii = 0, ee = JTBBs.size(); ii != ee; ++ii) {
       O << JTEntryDirective << ' ';
@@ -306,15 +306,15 @@
       // If we're emitting non-PIC code, then emit the entries as direct
       // references to the target basic blocks.
       if (!EmittedSets.empty()) {
-        O << TAI->getPrivateGlobalPrefix() << i
-          << '_' << "_set_" << JTBBs[ii]->getNumber() << '_' << CurrentFnName;
+        O << TAI->getPrivateGlobalPrefix() << getFunctionNumber()
+          << '_' << i << "_set_" << JTBBs[ii]->getNumber();
       } else if (IsPic) {
         printBasicBlockLabel(JTBBs[ii], false, false);
         // If the arch uses custom Jump Table directives, don't calc relative to
         // JT
         if (!HadJTEntryDirective) 
           O << '-' << TAI->getPrivateGlobalPrefix() << "JTI"
-            << i << '_' << CurrentFnName;
+            << getFunctionNumber() << '_' << i;
       } else {
         printBasicBlockLabel(JTBBs[ii], false, false);
       }
@@ -1242,8 +1242,8 @@
 void AsmPrinter::printBasicBlockLabel(const MachineBasicBlock *MBB,
                                       bool printColon,
                                       bool printComment) const {
-  O << TAI->getPrivateGlobalPrefix() << "BB" << MBB->getNumber() << '_'
-    << CurrentFnName;
+  O << TAI->getPrivateGlobalPrefix() << "BB" << getFunctionNumber() << "_"
+    << MBB->getNumber();
   if (printColon)
     O << ':';
   if (printComment && MBB->getBasicBlock())
@@ -1259,10 +1259,10 @@
     return;
   
   O << TAI->getSetDirective() << ' ' << TAI->getPrivateGlobalPrefix()
-    << uid << "_set_" << MBB->getNumber() << '_' << CurrentFnName << ',';
+    << getFunctionNumber() << '_' << uid << "_set_" << MBB->getNumber() << ',';
   printBasicBlockLabel(MBB, false, false);
-  O << '-' << TAI->getPrivateGlobalPrefix() << "JTI" << uid
-    << '_' << CurrentFnName << '\n';
+  O << '-' << TAI->getPrivateGlobalPrefix() << "JTI" << getFunctionNumber() 
+    << '_' << uid << '\n';
 }
 
 void AsmPrinter::printSetLabel(unsigned uid, unsigned uid2,
@@ -1271,11 +1271,11 @@
     return;
   
   O << TAI->getSetDirective() << ' ' << TAI->getPrivateGlobalPrefix()
-    << uid << '_' << uid2
-    << "_set_" << MBB->getNumber() << '_' << CurrentFnName << ',';
+    << getFunctionNumber() << '_' << uid << '_' << uid2
+    << "_set_" << MBB->getNumber() << ',';
   printBasicBlockLabel(MBB, false, false);
-  O << '-' << TAI->getPrivateGlobalPrefix() << "JTI" << uid 
-    << '_' << uid2 << '_' << CurrentFnName << '\n';
+  O << '-' << TAI->getPrivateGlobalPrefix() << "JTI" << getFunctionNumber() 
+    << '_' << uid << '_' << uid2 << '\n';
 }
 
 /// printDataDirective - This method prints the asm directive for the
diff --git a/lib/Target/ARM/ARMAsmPrinter.cpp b/lib/Target/ARM/ARMAsmPrinter.cpp
index b10399a..9435cc1 100644
--- a/lib/Target/ARM/ARMAsmPrinter.cpp
+++ b/lib/Target/ARM/ARMAsmPrinter.cpp
@@ -319,12 +319,12 @@
     break;
   }
   case MachineOperand::MO_ConstantPoolIndex:
-    O << TAI->getPrivateGlobalPrefix() << "CPI" << MO.getConstantPoolIndex()
-      << '_' << CurrentFnName;
+    O << TAI->getPrivateGlobalPrefix() << "CPI" << getFunctionNumber()
+      << '_' << MO.getConstantPoolIndex();
     break;
   case MachineOperand::MO_JumpTableIndex:
-    O << TAI->getPrivateGlobalPrefix() << "JTI" << MO.getJumpTableIndex()
-      << '_' << CurrentFnName;
+    O << TAI->getPrivateGlobalPrefix() << "JTI" << getFunctionNumber()
+      << '_' << MO.getJumpTableIndex();
     break;
   default:
     O << "<unknown operand type>"; abort (); break;
@@ -652,8 +652,8 @@
   // data itself.
   if (!strcmp(Modifier, "label")) {
     unsigned ID = MI->getOperand(OpNo).getImm();
-    O << TAI->getPrivateGlobalPrefix() << "CPI" << ID
-      << '_' << CurrentFnName << ":\n";
+    O << TAI->getPrivateGlobalPrefix() << "CPI" << getFunctionNumber()
+      << '_' << ID << ":\n";
   } else {
     assert(!strcmp(Modifier, "cpentry") && "Unknown modifier for CPE");
     unsigned CPI = MI->getOperand(OpNo).getConstantPoolIndex();
@@ -677,8 +677,8 @@
   const MachineOperand &MO1 = MI->getOperand(OpNo);
   const MachineOperand &MO2 = MI->getOperand(OpNo+1); // Unique Id
   unsigned JTI = MO1.getJumpTableIndex();
-  O << TAI->getPrivateGlobalPrefix() << "JTI" << JTI
-    << '_' << MO2.getImmedValue() << '_' << CurrentFnName << ":\n";
+  O << TAI->getPrivateGlobalPrefix() << "JTI" << getFunctionNumber()
+    << '_' << JTI << '_' << MO2.getImmedValue() << ":\n";
 
   const char *JTEntryDirective = TAI->getJumpTableDirective();
   if (!JTEntryDirective)
@@ -697,16 +697,15 @@
 
     O << JTEntryDirective << ' ';
     if (UseSet)
-      O << TAI->getPrivateGlobalPrefix() << JTI
-        << '_' << MO2.getImmedValue()
-        << "_set_" << MBB->getNumber()
-        << CurrentFnName;
+      O << TAI->getPrivateGlobalPrefix() << getFunctionNumber()
+        << '_' << JTI << '_' << MO2.getImmedValue()
+        << "_set_" << MBB->getNumber();
     else if (TM.getRelocationModel() == Reloc::PIC_) {
       printBasicBlockLabel(MBB, false, false);
       // If the arch uses custom Jump Table directives, don't calc relative to JT
       if (!TAI->getJumpTableDirective()) 
         O << '-' << TAI->getPrivateGlobalPrefix() << "JTI"
-          << JTI << '_' << MO2.getImmedValue() << '_' << CurrentFnName;
+          << getFunctionNumber() << '_' << JTI << '_' << MO2.getImmedValue();
     } else
       printBasicBlockLabel(MBB, false, false);
     if (i != e-1)
diff --git a/lib/Target/Alpha/AlphaAsmPrinter.cpp b/lib/Target/Alpha/AlphaAsmPrinter.cpp
index f726ff9..412f282 100644
--- a/lib/Target/Alpha/AlphaAsmPrinter.cpp
+++ b/lib/Target/Alpha/AlphaAsmPrinter.cpp
@@ -104,8 +104,8 @@
     return;
 
   case MachineOperand::MO_ConstantPoolIndex:
-    O << TAI->getPrivateGlobalPrefix() << "CPI" << MO.getConstantPoolIndex()
-      << '_' << CurrentFnName;
+    O << TAI->getPrivateGlobalPrefix() << "CPI" << getFunctionNumber() << "_"
+      << MO.getConstantPoolIndex();
     return;
 
   case MachineOperand::MO_ExternalSymbol:
@@ -121,8 +121,8 @@
   }
 
   case MachineOperand::MO_JumpTableIndex:
-    O << TAI->getPrivateGlobalPrefix() << "JTI" << MO.getJumpTableIndex()
-      << '_' << CurrentFnName;
+    O << TAI->getPrivateGlobalPrefix() << "JTI" << getFunctionNumber()
+      << '_' << MO.getJumpTableIndex();
     return;
 
   default:
diff --git a/lib/Target/IA64/IA64AsmPrinter.cpp b/lib/Target/IA64/IA64AsmPrinter.cpp
index d7c8226..08a27d4 100644
--- a/lib/Target/IA64/IA64AsmPrinter.cpp
+++ b/lib/Target/IA64/IA64AsmPrinter.cpp
@@ -179,8 +179,8 @@
     return;
   case MachineOperand::MO_ConstantPoolIndex: {
     O << "@gprel(" << TAI->getPrivateGlobalPrefix()
-      << "CPI" << MO.getConstantPoolIndex() << '_'
-      << CurrentFnName << ")";
+      << "CPI" << getFunctionNumber() << "_"
+      << MO.getConstantPoolIndex() << ")";
     return;
   }
 
diff --git a/lib/Target/Mips/MipsAsmPrinter.cpp b/lib/Target/Mips/MipsAsmPrinter.cpp
index ff02d43..cd5c1a3 100644
--- a/lib/Target/Mips/MipsAsmPrinter.cpp
+++ b/lib/Target/Mips/MipsAsmPrinter.cpp
@@ -363,7 +363,7 @@
 
     case MachineOperand::MO_ConstantPoolIndex:
       O << TAI->getPrivateGlobalPrefix() << "CPI"
-        << MO.getConstantPoolIndex() << '_' << CurrentFnName;
+        << getFunctionNumber() << "_" << MO.getConstantPoolIndex();
       break;
   
     default:
diff --git a/lib/Target/PowerPC/PPCAsmPrinter.cpp b/lib/Target/PowerPC/PPCAsmPrinter.cpp
index a75136b..9ff41ca 100644
--- a/lib/Target/PowerPC/PPCAsmPrinter.cpp
+++ b/lib/Target/PowerPC/PPCAsmPrinter.cpp
@@ -164,7 +164,7 @@
         O << "lo16(";
         printOp(MI->getOperand(OpNo));
         if (TM.getRelocationModel() == Reloc::PIC_)
-          O << "-\"L" "pb$" << CurrentFnName << "\")";
+          O << "-\"L" << getFunctionNumber() << "$pb\")";
         else
           O << ')';
       }
@@ -208,8 +208,8 @@
      O << (int)MI->getOperand(OpNo).getImmedValue()*4;
     }
     void printPICLabel(const MachineInstr *MI, unsigned OpNo) {
-      O << "\"L" "pb$" << CurrentFnName << "\"\n";
-      O << "\"L" "pb$" << CurrentFnName << "\":";
+      O << "\"L" << getFunctionNumber() << "$pb\"\n";
+      O << "\"L" << getFunctionNumber() << "$pb\":";
     }
     void printSymbolHi(const MachineInstr *MI, unsigned OpNo) {
       if (MI->getOperand(OpNo).isImmediate()) {
@@ -218,7 +218,7 @@
         if (Subtarget.isDarwin()) O << "ha16(";
         printOp(MI->getOperand(OpNo));
         if (TM.getRelocationModel() == Reloc::PIC_)
-          O << "-\"L" "pb$" << CurrentFnName << "\"";
+          O << "-\"L" << getFunctionNumber() << "$pb\"";
         if (Subtarget.isDarwin())
           O << ')';
         else
@@ -232,7 +232,7 @@
         if (Subtarget.isDarwin()) O << "lo16(";
         printOp(MI->getOperand(OpNo));
         if (TM.getRelocationModel() == Reloc::PIC_)
-          O << "-\"L" "pb$" << CurrentFnName << "\"";
+          O << "-\"L" << getFunctionNumber() << "$pb\"";
         if (Subtarget.isDarwin())
           O << ')';
         else
@@ -362,13 +362,13 @@
     printBasicBlockLabel(MO.getMachineBasicBlock());
     return;
   case MachineOperand::MO_JumpTableIndex:
-    O << TAI->getPrivateGlobalPrefix() << "JTI" << MO.getJumpTableIndex()
-      << '_' << CurrentFnName;
+    O << TAI->getPrivateGlobalPrefix() << "JTI" << getFunctionNumber()
+      << '_' << MO.getJumpTableIndex();
     // FIXME: PIC relocation model
     return;
   case MachineOperand::MO_ConstantPoolIndex:
-    O << TAI->getPrivateGlobalPrefix() << "CPI" << MO.getConstantPoolIndex()
-      << '_' << CurrentFnName;
+    O << TAI->getPrivateGlobalPrefix() << "CPI" << getFunctionNumber()
+      << '_' << MO.getConstantPoolIndex();
     return;
   case MachineOperand::MO_ExternalSymbol:
     // Computing the address of an external symbol, not calling it.
diff --git a/lib/Target/Sparc/SparcAsmPrinter.cpp b/lib/Target/Sparc/SparcAsmPrinter.cpp
index c9c1815..98d59ee 100644
--- a/lib/Target/Sparc/SparcAsmPrinter.cpp
+++ b/lib/Target/Sparc/SparcAsmPrinter.cpp
@@ -164,8 +164,8 @@
     O << MO.getSymbolName();
     break;
   case MachineOperand::MO_ConstantPoolIndex:
-    O << TAI->getPrivateGlobalPrefix() << "CPI" << MO.getConstantPoolIndex()
-      << '_' << CurrentFnName;
+    O << TAI->getPrivateGlobalPrefix() << "CPI" << getFunctionNumber() << "_"
+      << MO.getConstantPoolIndex();
     break;
   default:
     O << "<unknown operand type>"; abort (); break;
diff --git a/lib/Target/X86/X86ATTAsmPrinter.cpp b/lib/Target/X86/X86ATTAsmPrinter.cpp
index 4a52269..0655877 100644
--- a/lib/Target/X86/X86ATTAsmPrinter.cpp
+++ b/lib/Target/X86/X86ATTAsmPrinter.cpp
@@ -31,14 +31,14 @@
 
 STATISTIC(EmittedInsts, "Number of machine instrs printed");
 
-static std::string computePICLabel(const std::string &FnName,
+static std::string computePICLabel(unsigned FnNum,
                                    const TargetAsmInfo *TAI,
                                    const X86Subtarget* Subtarget)  {
   std::string label;
   if (Subtarget->isTargetDarwin())
-    label =  "\"L" "pb$" + FnName + "\"";
+    label =  "\"L" + utostr_32(FnNum) + "$pb\"";
   else if (Subtarget->isTargetELF())
-    label = ".Lllvm$piclabel$" + FnName;
+    label = ".Lllvm$" + utostr_32(FnNum) + "$piclabel";
   else
     assert(0 && "Don't know how to print PIC label!\n");
 
@@ -236,13 +236,13 @@
   case MachineOperand::MO_JumpTableIndex: {
     bool isMemOp  = Modifier && !strcmp(Modifier, "mem");
     if (!isMemOp) O << '$';
-    O << TAI->getPrivateGlobalPrefix() << "JTI" << MO.getJumpTableIndex()
-      << '_' << CurrentFnName;
+    O << TAI->getPrivateGlobalPrefix() << "JTI" << getFunctionNumber() << "_"
+      << MO.getJumpTableIndex();
 
     if (TM.getRelocationModel() == Reloc::PIC_) {
       if (Subtarget->isPICStyleStub())
-        O << "-\"" << TAI->getPrivateGlobalPrefix() << "pb$" << CurrentFnName
-          << "\"";
+        O << "-\"" << TAI->getPrivateGlobalPrefix() << getFunctionNumber()
+          << "$pb\"";
       else if (Subtarget->isPICStyleGOT())
         O << "@GOTOFF";
     }
@@ -254,13 +254,13 @@
   case MachineOperand::MO_ConstantPoolIndex: {
     bool isMemOp  = Modifier && !strcmp(Modifier, "mem");
     if (!isMemOp) O << '$';
-    O << TAI->getPrivateGlobalPrefix() << "CPI" << MO.getConstantPoolIndex()
-      << '_' << CurrentFnName;
+    O << TAI->getPrivateGlobalPrefix() << "CPI" << getFunctionNumber() << "_"
+      << MO.getConstantPoolIndex();
 
     if (TM.getRelocationModel() == Reloc::PIC_) {
       if (Subtarget->isPICStyleStub())
-        O << "-\"" << TAI->getPrivateGlobalPrefix() << "pb$" << CurrentFnName
-          << "\"";
+        O << "-\"" << TAI->getPrivateGlobalPrefix() << getFunctionNumber()
+          << "$pb\"";
       else if (Subtarget->isPICStyleGOT())
         O << "@GOTOFF";
     }
@@ -317,8 +317,8 @@
       }
       
       if (!isCallOp && TM.getRelocationModel() == Reloc::PIC_)
-        O << "-\"" << TAI->getPrivateGlobalPrefix() << "pb$" << CurrentFnName
-          << "\"";
+        O << "-\"" << TAI->getPrivateGlobalPrefix() << getFunctionNumber()
+          << "$pb\"";
     } else {
       if (GV->hasDLLImportLinkage()) {
         O << "__imp_";          
@@ -418,7 +418,7 @@
         //   popl %some_register
         //   addl $_GLOBAL_ADDRESS_TABLE_ + [.-piclabel], %some_register
         O << " + [.-"
-          << computePICLabel(CurrentFnName, TAI, Subtarget) << "]";
+          << computePICLabel(getFunctionNumber(), TAI, Subtarget) << "]";
 
       if (isCallOp)
         O << "@PLT";
@@ -498,7 +498,7 @@
 }
 
 void X86ATTAsmPrinter::printPICLabel(const MachineInstr *MI, unsigned Op) {
-  std::string label = computePICLabel(CurrentFnName, TAI, Subtarget);
+  std::string label = computePICLabel(getFunctionNumber(), TAI, Subtarget);
   O << label << "\n" << label << ":";
 }
 
diff --git a/lib/Target/X86/X86IntelAsmPrinter.cpp b/lib/Target/X86/X86IntelAsmPrinter.cpp
index 642045b..bd8886c 100644
--- a/lib/Target/X86/X86IntelAsmPrinter.cpp
+++ b/lib/Target/X86/X86IntelAsmPrinter.cpp
@@ -140,15 +140,15 @@
   case MachineOperand::MO_JumpTableIndex: {
     bool isMemOp  = Modifier && !strcmp(Modifier, "mem");
     if (!isMemOp) O << "OFFSET ";
-    O << TAI->getPrivateGlobalPrefix() << "JTI" << MO.getJumpTableIndex()
-      << '_' << CurrentFnName;
+    O << TAI->getPrivateGlobalPrefix() << "JTI" << getFunctionNumber()
+      << "_" << MO.getJumpTableIndex();
     return;
   }    
   case MachineOperand::MO_ConstantPoolIndex: {
     bool isMemOp  = Modifier && !strcmp(Modifier, "mem");
     if (!isMemOp) O << "OFFSET ";
     O << "[" << TAI->getPrivateGlobalPrefix() << "CPI"
-      << MO.getConstantPoolIndex() << '_' << CurrentFnName;
+      << getFunctionNumber() << "_" << MO.getConstantPoolIndex();
     int Offset = MO.getOffset();
     if (Offset > 0)
       O << " + " << Offset;
@@ -236,8 +236,8 @@
 }
 
 void X86IntelAsmPrinter::printPICLabel(const MachineInstr *MI, unsigned Op) {
-  O << "\"L" "pb$" << CurrentFnName << "\"\n";
-  O << "\"L" "pb$" << CurrentFnName << "\":";
+  O << "\"L" << getFunctionNumber() << "$pb\"\n";
+  O << "\"L" << getFunctionNumber() << "$pb\":";
 }
 
 bool X86IntelAsmPrinter::printAsmMRegister(const MachineOperand &MO,