eliminate uses of mangler and simplify code.
authorChris Lattner <sabre@nondot.org>
Sat, 16 Jan 2010 01:40:07 +0000 (01:40 +0000)
committerChris Lattner <sabre@nondot.org>
Sat, 16 Jan 2010 01:40:07 +0000 (01:40 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@93615 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/ARM/AsmPrinter/ARMMCInstLower.cpp
lib/Target/MSP430/AsmPrinter/MSP430MCInstLower.cpp
lib/Target/PIC16/AsmPrinter/PIC16AsmPrinter.cpp
lib/Target/X86/AsmPrinter/X86AsmPrinter.cpp
lib/Target/X86/AsmPrinter/X86MCInstLower.cpp
lib/Target/XCore/AsmPrinter/XCoreAsmPrinter.cpp

index c49fee3a5505ac5ffa83f844c4049d5c53cec049..f843ee2b0d4232c119c1c4036e2df79c3ca13779 100644 (file)
@@ -22,7 +22,6 @@
 #include "llvm/MC/MCInst.h"
 //#include "llvm/MC/MCStreamer.h"
 #include "llvm/Support/raw_ostream.h"
-#include "llvm/Support/Mangler.h"
 #include "llvm/ADT/SmallString.h"
 using namespace llvm;
 
@@ -40,33 +39,24 @@ MachineModuleInfoMachO &ARMMCInstLower::getMachOMMI() const {
 
 MCSymbol *ARMMCInstLower::
 GetGlobalAddressSymbol(const MachineOperand &MO) const {
-  const GlobalValue *GV = MO.getGlobal();
-  
-  SmallString<128> Name;
-  Mang.getNameWithPrefix(Name, GV, false);
-  
   // FIXME: HANDLE PLT references how??
   switch (MO.getTargetFlags()) {
   default: assert(0 && "Unknown target flag on GV operand");
   case 0: break;
   }
   
-  return Ctx.GetOrCreateSymbol(Name.str());
+  return Printer.GetGlobalValueSymbol(MO.getGlobal());
 }
 
 MCSymbol *ARMMCInstLower::
 GetExternalSymbolSymbol(const MachineOperand &MO) const {
-  SmallString<128> Name;
-  Name += Printer.MAI->getGlobalPrefix();
-  Name += MO.getSymbolName();
-  
   // FIXME: HANDLE PLT references how??
   switch (MO.getTargetFlags()) {
   default: assert(0 && "Unknown target flag on GV operand");
   case 0: break;
   }
   
-  return Ctx.GetOrCreateSymbol(Name.str());
+  return Printer.GetExternalSymbolSymbol(MO.getSymbolName());
 }
 
 
index 595b7e789c7d219f5702731639601e8289525e29..e1f80b7d843e6158df3ab79a11629dda0494cf16 100644 (file)
 #include "llvm/MC/MCInst.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/Support/ErrorHandling.h"
-#include "llvm/Support/Mangler.h"
 #include "llvm/ADT/SmallString.h"
 using namespace llvm;
 
 MCSymbol *MSP430MCInstLower::
 GetGlobalAddressSymbol(const MachineOperand &MO) const {
-  const GlobalValue *GV = MO.getGlobal();
-
-  SmallString<128> Name;
-  Mang.getNameWithPrefix(Name, GV, false);
-
   switch (MO.getTargetFlags()) {
   default: llvm_unreachable("Unknown target flag on GV operand");
   case 0: break;
   }
 
-  return Ctx.GetOrCreateSymbol(Name.str());
+  return Printer.GetGlobalValueSymbol(MO.getGlobal());
 }
 
 MCSymbol *MSP430MCInstLower::
 GetExternalSymbolSymbol(const MachineOperand &MO) const {
-  SmallString<128> Name;
-  Name += Printer.MAI->getGlobalPrefix();
-  Name += MO.getSymbolName();
-
   switch (MO.getTargetFlags()) {
   default: assert(0 && "Unknown target flag on GV operand");
   case 0: break;
   }
 
-  return Ctx.GetOrCreateSymbol(Name.str());
+  return Printer.GetExternalSymbolSymbol(MO.getSymbolName());
 }
 
 MCSymbol *MSP430MCInstLower::
index 6b77bbe445932e99ed1740e89f1748ab0fdd0d18..af2169ef52092cdde89758427f00aac43e62fe68 100644 (file)
@@ -29,7 +29,6 @@
 #include "llvm/Target/TargetLoweringObjectFile.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/FormattedStream.h"
-#include "llvm/Support/Mangler.h"
 #include <cstring>
 using namespace llvm;
 
@@ -185,24 +184,22 @@ void PIC16AsmPrinter::printOperand(const MachineInstr *MI, int opNum) {
       return;
 
     case MachineOperand::MO_GlobalAddress: {
-      std::string Sname = Mang->getMangledName(MO.getGlobal());
+      MCSymbol *Sym = GetGlobalValueSymbol(MO.getGlobal());
       // FIXME: currently we do not have a memcpy def coming in the module
       // by any chance, as we do not link in those as .bc lib. So these calls
       // are always external and it is safe to emit an extern.
-      if (PAN::isMemIntrinsic(Sname)) {
-        LibcallDecls.push_back(createESName(Sname));
-      }
+      if (PAN::isMemIntrinsic(Sym->getName()))
+        LibcallDecls.push_back(createESName(Sym->getName()));
 
-      O << Sname;
+      Sym->print(O, MAI);
       break;
     }
     case MachineOperand::MO_ExternalSymbol: {
        const char *Sname = MO.getSymbolName();
 
       // If its a libcall name, record it to decls section.
-      if (PAN::getSymbolTag(Sname) == PAN::LIBCALL) {
+      if (PAN::getSymbolTag(Sname) == PAN::LIBCALL)
         LibcallDecls.push_back(Sname);
-      }
 
       // Record a call to intrinsic to print the extern declaration for it.
       std::string Sym = Sname;  
@@ -211,7 +208,7 @@ void PIC16AsmPrinter::printOperand(const MachineInstr *MI, int opNum) {
         LibcallDecls.push_back(createESName(Sym));
       }
 
-      O  << Sym;
+      O << Sym;
       break;
     }
     case MachineOperand::MO_MachineBasicBlock:
@@ -317,16 +314,14 @@ void PIC16AsmPrinter::EmitFunctionDecls(Module &M) {
  // Emit declarations for external functions.
   O <<"\n"<<MAI->getCommentString() << "Function Declarations - BEGIN." <<"\n";
   for (Module::iterator I = M.begin(), E = M.end(); I != E; I++) {
-    if (I->isIntrinsic())
-      continue;
-
-    std::string Name = Mang->getMangledName(I);
-    if (Name.compare("@abort") == 0)
+    if (I->isIntrinsic() || I->getName() == "@abort")
       continue;
     
     if (!I->isDeclaration() && !I->hasExternalLinkage())
       continue;
 
+    MCSymbol *Sym = GetGlobalValueSymbol(I);
+    
     // Do not emit memcpy, memset, and memmove here.
     // Calls to these routines can be generated in two ways,
     // 1. User calling the standard lib function
@@ -335,14 +330,14 @@ void PIC16AsmPrinter::EmitFunctionDecls(Module &M) {
     // second case the call is via and externalsym and the prototype is missing.
     // So declarations for these are currently always getting printing by
     // tracking both kind of references in printInstrunction.
-    if (I->isDeclaration() && PAN::isMemIntrinsic(Name)) continue;
+    if (I->isDeclaration() && PAN::isMemIntrinsic(Sym->getName())) continue;
 
     const char *directive = I->isDeclaration() ? MAI->getExternDirective() :
                                                  MAI->getGlobalDirective();
       
-    O << directive << Name << "\n";
-    O << directive << PAN::getRetvalLabel(Name) << "\n";
-    O << directive << PAN::getArgsLabel(Name) << "\n";
+    O << directive << Sym->getName() << "\n";
+    O << directive << PAN::getRetvalLabel(Sym->getName()) << "\n";
+    O << directive << PAN::getArgsLabel(Sym->getName()) << "\n";
   }
 
   O << MAI->getCommentString() << "Function Declarations - END." <<"\n";
@@ -355,7 +350,9 @@ void PIC16AsmPrinter::EmitUndefinedVars(Module &M) {
 
   O << "\n" << MAI->getCommentString() << "Imported Variables - BEGIN" << "\n";
   for (unsigned j = 0; j < Items.size(); j++) {
-    O << MAI->getExternDirective() << Mang->getMangledName(Items[j]) << "\n";
+    O << MAI->getExternDirective();
+    GetGlobalValueSymbol(Items[j])->print(O, MAI);
+    O << "\n";
   }
   O << MAI->getCommentString() << "Imported Variables - END" << "\n";
 }
@@ -367,7 +364,9 @@ void PIC16AsmPrinter::EmitDefinedVars(Module &M) {
 
   O << "\n" << MAI->getCommentString() << "Exported Variables - BEGIN" << "\n";
   for (unsigned j = 0; j < Items.size(); j++) {
-    O << MAI->getGlobalDirective() << Mang->getMangledName(Items[j]) << "\n";
+    O << MAI->getGlobalDirective();
+    GetGlobalValueSymbol(Items[j])->print(O, MAI);
+    O << "\n";
   }
   O <<  MAI->getCommentString() << "Exported Variables - END" << "\n";
 }
@@ -392,7 +391,6 @@ bool PIC16AsmPrinter::doFinalization(Module &M) {
 
 void PIC16AsmPrinter::EmitFunctionFrame(MachineFunction &MF) {
   const Function *F = MF.getFunction();
-  std::string FuncName = Mang->getMangledName(F);
   const TargetData *TD = TM.getTargetData();
   // Emit the data section name.
   O << "\n"; 
@@ -446,10 +444,9 @@ void PIC16AsmPrinter::EmitInitializedDataSection(const PIC16Section *S) {
 
     std::vector<const GlobalVariable*> Items = S->Items;
     for (unsigned j = 0; j < Items.size(); j++) {
-      std::string Name = Mang->getMangledName(Items[j]);
       Constant *C = Items[j]->getInitializer();
       int AddrSpace = Items[j]->getType()->getAddressSpace();
-      O << Name;
+      GetGlobalValueSymbol(Items[j])->print(O, MAI);
       EmitGlobalConstant(C, AddrSpace);
    }
 }
@@ -465,11 +462,11 @@ EmitUninitializedDataSection(const PIC16Section *S) {
     OutStreamer.SwitchSection(S);
     std::vector<const GlobalVariable*> Items = S->Items;
     for (unsigned j = 0; j < Items.size(); j++) {
-      std::string Name = Mang->getMangledName(Items[j]);
       Constant *C = Items[j]->getInitializer();
       const Type *Ty = C->getType();
       unsigned Size = TD->getTypeAllocSize(Ty);
-      O << Name << " RES " << Size << "\n";
+      GetGlobalValueSymbol(Items[j])->print(O, MAI);
+      O << " RES " << Size << "\n";
     }
 }
 
index ea5a6b3af863218ca20075dc6c2df3e0397369d1..d3d4d13ebf56e323a337df884329b9f657d95c82 100644 (file)
@@ -36,7 +36,6 @@
 #include "llvm/CodeGen/MachineModuleInfoImpls.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/FormattedStream.h"
-#include "llvm/Support/Mangler.h"
 #include "llvm/MC/MCAsmInfo.h"
 #include "llvm/Target/TargetLoweringObjectFile.h"
 #include "llvm/Target/TargetOptions.h"
index d710a3f85b2091bfa3878b7d0127cc357ea131fb..667a5a4b1f8387ba19195d8eba772a714c79eb21 100644 (file)
@@ -83,33 +83,24 @@ GetGlobalAddressSymbol(const MachineOperand &MO) const {
     MCSymbol *Sym = Ctx.GetOrCreateSymbol(Name.str());
 
     const MCSymbol *&StubSym = getMachOMMI().getGVStubEntry(Sym);
-    if (StubSym == 0) {
-      Name.clear();
-      Mang->getNameWithPrefix(Name, GV, false);
-      StubSym = Ctx.GetOrCreateSymbol(Name.str());
-    }
+    if (StubSym == 0)
+      StubSym = AsmPrinter.GetGlobalValueSymbol(GV);
     return Sym;
   }
   case X86II::MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE: {
     Name += "$non_lazy_ptr";
     MCSymbol *Sym = Ctx.GetOrCreateSymbol(Name.str());
     const MCSymbol *&StubSym = getMachOMMI().getHiddenGVStubEntry(Sym);
-    if (StubSym == 0) {
-      Name.clear();
-      Mang->getNameWithPrefix(Name, GV, false);
-      StubSym = Ctx.GetOrCreateSymbol(Name.str());
-    }
+    if (StubSym == 0)
+      StubSym = AsmPrinter.GetGlobalValueSymbol(GV);
     return Sym;
   }
   case X86II::MO_DARWIN_STUB: {
     Name += "$stub";
     MCSymbol *Sym = Ctx.GetOrCreateSymbol(Name.str());
     const MCSymbol *&StubSym = getMachOMMI().getFnStubEntry(Sym);
-    if (StubSym == 0) {
-      Name.clear();
-      Mang->getNameWithPrefix(Name, GV, false);
-      StubSym = Ctx.GetOrCreateSymbol(Name.str());
-    }
+    if (StubSym == 0)
+      StubSym = AsmPrinter.GetGlobalValueSymbol(GV);
     return Sym;
   }
   // FIXME: These probably should be a modifier on the symbol or something??
index b8669edbd3538c4d93998e31dcb0fe6656853e16..5ac025b1794d2df08bc7311cd241ff4b053f442e 100644 (file)
@@ -37,7 +37,6 @@
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/FormattedStream.h"
-#include "llvm/Support/Mangler.h"
 #include "llvm/Support/MathExtras.h"
 #include <algorithm>
 #include <cctype>
@@ -340,7 +339,7 @@ void XCoreAsmPrinter::printOperand(const MachineInstr *MI, int opNum) {
     GetMBBSymbol(MO.getMBB()->getNumber())->print(O, MAI);
     break;
   case MachineOperand::MO_GlobalAddress:
-    O << Mang->getMangledName(MO.getGlobal());
+    GetGlobalValueSymbol(MO.getGlobal())->print(O, MAI);
     break;
   case MachineOperand::MO_ExternalSymbol:
     O << MO.getSymbolName();