diff options
author | Chris Lattner <sabre@nondot.org> | 2009-07-14 06:04:35 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2009-07-14 06:04:35 +0000 |
commit | 03e9dd9ffae4370bf53bcdf04504e5ad908a1ec6 (patch) | |
tree | 0d1dbf0fa27121183c6d5fce5e791e854c15ce20 /lib/Target/X86/AsmPrinter | |
parent | d23f0d0451a4ffc0c12d7a73559fa35587ce7abb (diff) | |
download | external_llvm-03e9dd9ffae4370bf53bcdf04504e5ad908a1ec6.zip external_llvm-03e9dd9ffae4370bf53bcdf04504e5ad908a1ec6.tar.gz external_llvm-03e9dd9ffae4370bf53bcdf04504e5ad908a1ec6.tar.bz2 |
Change the X86 asmprinter to use the mangler to apply suffixes like "$non_lazy_ptr"
to symbols instead of doing it with "printSuffixedName". This gets us to the point
where there is a real separation between computing a symbol name and printing it,
something I need for MC printer stuff.
This patch also fixes a corner case bug where unnamed private globals wouldn't get
the private label prefix.
Next up, rename all uses of getValueName -> getMangledName for better greppability,
and then tackle the ppc/arm backends to eliminate "printSuffixedName".
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@75610 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Target/X86/AsmPrinter')
-rw-r--r-- | lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp | 124 |
1 files changed, 70 insertions, 54 deletions
diff --git a/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp b/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp index f160bd0..80da514 100644 --- a/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp +++ b/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp @@ -233,7 +233,7 @@ bool X86ATTAsmPrinter::runOnMachineFunction(MachineFunction &MF) { EmitConstantPool(MF.getConstantPool()); if (F->hasDLLExportLinkage()) - DLLExportedFns.insert(Mang->getValueName(F)); + DLLExportedFns.insert(Mang->getMangledName(F)); // Print the 'header' of function emitFunctionHeader(MF); @@ -304,62 +304,58 @@ void X86ATTAsmPrinter::printSymbolOperand(const MachineOperand &MO) { break; case MachineOperand::MO_GlobalAddress: { const GlobalValue *GV = MO.getGlobal(); - std::string Name = Mang->getValueName(GV); - decorateName(Name, GV); - bool needCloseParen = false; - if (Name[0] == '$') { - // The name begins with a dollar-sign. In order to avoid having it look - // like an integer immediate to the assembler, enclose it in parens. - O << '('; - needCloseParen = true; - } + const char *Suffix = ""; + + if (MO.getTargetFlags() == X86II::MO_DARWIN_STUB) + Suffix = "$stub"; + else if (MO.getTargetFlags() == X86II::MO_DARWIN_NONLAZY || + MO.getTargetFlags() == X86II::MO_DARWIN_NONLAZY_PIC_BASE || + MO.getTargetFlags() == X86II::MO_DARWIN_HIDDEN_NONLAZY || + MO.getTargetFlags() == X86II::MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE) + Suffix = "$non_lazy_ptr"; + + std::string Name = Mang->getMangledName(GV, Suffix, Suffix[0] != '\0'); + decorateName(Name, GV); // Handle dllimport linkage. - if (MO.getTargetFlags() == X86II::MO_DLLIMPORT) { - O << "__imp_" << Name; - } else if (MO.getTargetFlags() == X86II::MO_DARWIN_NONLAZY || - MO.getTargetFlags() == X86II::MO_DARWIN_NONLAZY_PIC_BASE) { + if (MO.getTargetFlags() == X86II::MO_DLLIMPORT) + Name = "__imp_" + Name; + + if (MO.getTargetFlags() == X86II::MO_DARWIN_NONLAZY || + MO.getTargetFlags() == X86II::MO_DARWIN_NONLAZY_PIC_BASE) GVStubs.insert(Name); - printSuffixedName(Name, "$non_lazy_ptr"); - } else if (MO.getTargetFlags() == X86II::MO_DARWIN_HIDDEN_NONLAZY || - MO.getTargetFlags() == X86II::MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE){ + else if (MO.getTargetFlags() == X86II::MO_DARWIN_HIDDEN_NONLAZY || + MO.getTargetFlags() == X86II::MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE) HiddenGVStubs.insert(Name); - printSuffixedName(Name, "$non_lazy_ptr"); - } else if (MO.getTargetFlags() == X86II::MO_DARWIN_STUB) { + else if (MO.getTargetFlags() == X86II::MO_DARWIN_STUB) FnStubs.insert(Name); - printSuffixedName(Name, "$stub"); - } else { - O << Name; - } - if (needCloseParen) - O << ')'; + // If the name begins with a dollar-sign, enclose it in parens. We do this + // to avoid having it look like an integer immediate to the assembler. + if (Name[0] == '$') + O << '(' << Name << ')'; + else + O << Name; printOffset(MO.getOffset()); break; } case MachineOperand::MO_ExternalSymbol: { - bool needCloseParen = false; std::string Name(TAI->getGlobalPrefix()); Name += MO.getSymbolName(); - - if (Name[0] == '$') { - // The name begins with a dollar-sign. In order to avoid having it look - // like an integer immediate to the assembler, enclose it in parens. - O << '('; - needCloseParen = true; - } - + if (MO.getTargetFlags() == X86II::MO_DARWIN_STUB) { + Name += "$stub"; FnStubs.insert(Name); - printSuffixedName(Name, "$stub"); - } else { - O << Name; } - if (needCloseParen) - O << ')'; + // If the name begins with a dollar-sign, enclose it in parens. We do this + // to avoid having it look like an integer immediate to the assembler. + if (Name[0] == '$') + O << '(' << Name << ')'; + else + O << Name; break; } } @@ -787,7 +783,7 @@ void X86ATTAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) { return; } - std::string name = Mang->getValueName(GVar); + std::string name = Mang->getMangledName(GVar); Constant *C = GVar->getInitializer(); if (isa<MDNode>(C) || isa<MDString>(C)) return; @@ -903,6 +899,20 @@ void X86ATTAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) { EmitGlobalConstant(C); } +/// PrintWithoutDarwinSuffix - Print a name that has a suffix appended to it +/// without the suffix. This is used for darwin stub emission, where we have to +/// be careful to remove the suffix even if the name is quoted. +static void PrintWithoutDarwinSuffix(const char *Name, unsigned NameLen, + unsigned SuffixLen, raw_ostream &O) { + assert(NameLen > SuffixLen && "Invalid empty name or bogus suffix"); + if (Name[NameLen-1] != '"') { + O.write(Name, NameLen-SuffixLen); // foo$stub -> foo + } else { + O.write(Name, NameLen-SuffixLen-1); // "foo$stub" -> "foo + O << '"'; // -> " + } +} + bool X86ATTAsmPrinter::doFinalization(Module &M) { // Print out module-level global variables here. for (Module::const_global_iterator I = M.global_begin(), E = M.global_end(); @@ -910,7 +920,7 @@ bool X86ATTAsmPrinter::doFinalization(Module &M) { printModuleLevelGV(I); if (I->hasDLLExportLinkage()) - DLLExportedGVs.insert(Mang->getValueName(I)); + DLLExportedGVs.insert(Mang->getMangledName(I)); } if (Subtarget->isTargetDarwin()) { @@ -921,11 +931,10 @@ bool X86ATTAsmPrinter::doFinalization(Module &M) { if (TAI->doesSupportExceptionHandling() && MMI && !Subtarget->is64Bit()) { const std::vector<Function*> &Personalities = MMI->getPersonalities(); for (unsigned i = 0, e = Personalities.size(); i != e; ++i) { - if (Personalities[i] == 0) - continue; - std::string Name = Mang->getValueName(Personalities[i]); - decorateName(Name, Personalities[i]); - GVStubs.insert(Name); + if (Personalities[i]) + GVStubs.insert(Mang->getMangledName(Personalities[i], + "$non_lazy_ptr", + true /*private label*/)); } } @@ -936,10 +945,13 @@ bool X86ATTAsmPrinter::doFinalization(Module &M) { SwitchToDataSection("\t.section __IMPORT,__jump_table,symbol_stubs," "self_modifying_code+pure_instructions,5", 0); const char *Name = I->getKeyData(); - printSuffixedName(Name, "$stub"); - O << ":\n" - "\t.indirect_symbol " << Name << "\n" - "\thlt ; hlt ; hlt ; hlt ; hlt\n"; + O << Name << ":\n"; + O << "\t.indirect_symbol "; + + // Print the name without the $stub. + PrintWithoutDarwinSuffix(Name, I->getKeyLength(), strlen("$stub"), O); + O << '\n'; + O << "\thlt ; hlt ; hlt ; hlt ; hlt\n"; } O << '\n'; } @@ -951,8 +963,10 @@ bool X86ATTAsmPrinter::doFinalization(Module &M) { for (StringSet<>::iterator I = GVStubs.begin(), E = GVStubs.end(); I != E; ++I) { const char *Name = I->getKeyData(); - printSuffixedName(Name, "$non_lazy_ptr"); - O << ":\n\t.indirect_symbol " << Name << "\n\t.long\t0\n"; + O << Name << ":\n\t.indirect_symbol "; + PrintWithoutDarwinSuffix(Name, I->getKeyLength(), + strlen("$non_lazy_ptr"), O); + O << "\n\t.long\t0\n"; } } @@ -962,8 +976,10 @@ bool X86ATTAsmPrinter::doFinalization(Module &M) { for (StringSet<>::iterator I = HiddenGVStubs.begin(), E = HiddenGVStubs.end(); I != E; ++I) { const char *Name = I->getKeyData(); - printSuffixedName(Name, "$non_lazy_ptr"); - O << ":\n" << TAI->getData32bitsDirective() << Name << '\n'; + O << Name << ":\n" << TAI->getData32bitsDirective(); + PrintWithoutDarwinSuffix(Name, I->getKeyLength(), + strlen("$non_lazy_ptr"), O); + O << '\n'; } } |