mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-05-18 22:38:56 +00:00
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
This commit is contained in:
parent
d23f0d0451
commit
03e9dd9ffa
@ -82,10 +82,17 @@ public:
|
|||||||
return (AcceptableChars[X/32] & (1 << (X&31))) != 0;
|
return (AcceptableChars[X/32] & (1 << (X&31))) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// getValueName - Returns the mangled name of V, an LLVM Value,
|
/// getMangledName - Returns the mangled name of V, an LLVM Value,
|
||||||
/// in the current module.
|
/// in the current module. If 'Suffix' is specified, the name ends with the
|
||||||
|
/// specified suffix. If 'ForcePrivate' is specified, the label is specified
|
||||||
|
/// to have a private label prefix.
|
||||||
///
|
///
|
||||||
std::string getValueName(const GlobalValue *V, const char *Suffix = "");
|
std::string getMangledName(const GlobalValue *V, const char *Suffix = "",
|
||||||
|
bool ForcePrivate = false);
|
||||||
|
|
||||||
|
std::string getValueName(const GlobalValue *V, const char *Suffix = "") {
|
||||||
|
return getMangledName(V, Suffix);
|
||||||
|
}
|
||||||
|
|
||||||
/// makeNameProper - We don't want identifier names with ., space, or
|
/// makeNameProper - We don't want identifier names with ., space, or
|
||||||
/// - in them, so we mangle these characters into the strings "d_",
|
/// - in them, so we mangle these characters into the strings "d_",
|
||||||
|
@ -233,7 +233,7 @@ bool X86ATTAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
|
|||||||
EmitConstantPool(MF.getConstantPool());
|
EmitConstantPool(MF.getConstantPool());
|
||||||
|
|
||||||
if (F->hasDLLExportLinkage())
|
if (F->hasDLLExportLinkage())
|
||||||
DLLExportedFns.insert(Mang->getValueName(F));
|
DLLExportedFns.insert(Mang->getMangledName(F));
|
||||||
|
|
||||||
// Print the 'header' of function
|
// Print the 'header' of function
|
||||||
emitFunctionHeader(MF);
|
emitFunctionHeader(MF);
|
||||||
@ -304,62 +304,58 @@ void X86ATTAsmPrinter::printSymbolOperand(const MachineOperand &MO) {
|
|||||||
break;
|
break;
|
||||||
case MachineOperand::MO_GlobalAddress: {
|
case MachineOperand::MO_GlobalAddress: {
|
||||||
const GlobalValue *GV = MO.getGlobal();
|
const GlobalValue *GV = MO.getGlobal();
|
||||||
std::string Name = Mang->getValueName(GV);
|
|
||||||
|
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);
|
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Handle dllimport linkage.
|
// Handle dllimport linkage.
|
||||||
if (MO.getTargetFlags() == X86II::MO_DLLIMPORT) {
|
if (MO.getTargetFlags() == X86II::MO_DLLIMPORT)
|
||||||
O << "__imp_" << Name;
|
Name = "__imp_" + Name;
|
||||||
} else 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){
|
|
||||||
HiddenGVStubs.insert(Name);
|
|
||||||
printSuffixedName(Name, "$non_lazy_ptr");
|
|
||||||
} else if (MO.getTargetFlags() == X86II::MO_DARWIN_STUB) {
|
|
||||||
FnStubs.insert(Name);
|
|
||||||
printSuffixedName(Name, "$stub");
|
|
||||||
} else {
|
|
||||||
O << Name;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (needCloseParen)
|
if (MO.getTargetFlags() == X86II::MO_DARWIN_NONLAZY ||
|
||||||
O << ')';
|
MO.getTargetFlags() == X86II::MO_DARWIN_NONLAZY_PIC_BASE)
|
||||||
|
GVStubs.insert(Name);
|
||||||
|
else if (MO.getTargetFlags() == X86II::MO_DARWIN_HIDDEN_NONLAZY ||
|
||||||
|
MO.getTargetFlags() == X86II::MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE)
|
||||||
|
HiddenGVStubs.insert(Name);
|
||||||
|
else if (MO.getTargetFlags() == X86II::MO_DARWIN_STUB)
|
||||||
|
FnStubs.insert(Name);
|
||||||
|
|
||||||
|
// 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());
|
printOffset(MO.getOffset());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case MachineOperand::MO_ExternalSymbol: {
|
case MachineOperand::MO_ExternalSymbol: {
|
||||||
bool needCloseParen = false;
|
|
||||||
std::string Name(TAI->getGlobalPrefix());
|
std::string Name(TAI->getGlobalPrefix());
|
||||||
Name += MO.getSymbolName();
|
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) {
|
if (MO.getTargetFlags() == X86II::MO_DARWIN_STUB) {
|
||||||
|
Name += "$stub";
|
||||||
FnStubs.insert(Name);
|
FnStubs.insert(Name);
|
||||||
printSuffixedName(Name, "$stub");
|
|
||||||
} else {
|
|
||||||
O << Name;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (needCloseParen)
|
// If the name begins with a dollar-sign, enclose it in parens. We do this
|
||||||
O << ')';
|
// to avoid having it look like an integer immediate to the assembler.
|
||||||
|
if (Name[0] == '$')
|
||||||
|
O << '(' << Name << ')';
|
||||||
|
else
|
||||||
|
O << Name;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -787,7 +783,7 @@ void X86ATTAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string name = Mang->getValueName(GVar);
|
std::string name = Mang->getMangledName(GVar);
|
||||||
Constant *C = GVar->getInitializer();
|
Constant *C = GVar->getInitializer();
|
||||||
if (isa<MDNode>(C) || isa<MDString>(C))
|
if (isa<MDNode>(C) || isa<MDString>(C))
|
||||||
return;
|
return;
|
||||||
@ -903,6 +899,20 @@ void X86ATTAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
|
|||||||
EmitGlobalConstant(C);
|
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) {
|
bool X86ATTAsmPrinter::doFinalization(Module &M) {
|
||||||
// Print out module-level global variables here.
|
// Print out module-level global variables here.
|
||||||
for (Module::const_global_iterator I = M.global_begin(), E = M.global_end();
|
for (Module::const_global_iterator I = M.global_begin(), E = M.global_end();
|
||||||
@ -910,7 +920,7 @@ bool X86ATTAsmPrinter::doFinalization(Module &M) {
|
|||||||
printModuleLevelGV(I);
|
printModuleLevelGV(I);
|
||||||
|
|
||||||
if (I->hasDLLExportLinkage())
|
if (I->hasDLLExportLinkage())
|
||||||
DLLExportedGVs.insert(Mang->getValueName(I));
|
DLLExportedGVs.insert(Mang->getMangledName(I));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Subtarget->isTargetDarwin()) {
|
if (Subtarget->isTargetDarwin()) {
|
||||||
@ -921,11 +931,10 @@ bool X86ATTAsmPrinter::doFinalization(Module &M) {
|
|||||||
if (TAI->doesSupportExceptionHandling() && MMI && !Subtarget->is64Bit()) {
|
if (TAI->doesSupportExceptionHandling() && MMI && !Subtarget->is64Bit()) {
|
||||||
const std::vector<Function*> &Personalities = MMI->getPersonalities();
|
const std::vector<Function*> &Personalities = MMI->getPersonalities();
|
||||||
for (unsigned i = 0, e = Personalities.size(); i != e; ++i) {
|
for (unsigned i = 0, e = Personalities.size(); i != e; ++i) {
|
||||||
if (Personalities[i] == 0)
|
if (Personalities[i])
|
||||||
continue;
|
GVStubs.insert(Mang->getMangledName(Personalities[i],
|
||||||
std::string Name = Mang->getValueName(Personalities[i]);
|
"$non_lazy_ptr",
|
||||||
decorateName(Name, Personalities[i]);
|
true /*private label*/));
|
||||||
GVStubs.insert(Name);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -936,10 +945,13 @@ bool X86ATTAsmPrinter::doFinalization(Module &M) {
|
|||||||
SwitchToDataSection("\t.section __IMPORT,__jump_table,symbol_stubs,"
|
SwitchToDataSection("\t.section __IMPORT,__jump_table,symbol_stubs,"
|
||||||
"self_modifying_code+pure_instructions,5", 0);
|
"self_modifying_code+pure_instructions,5", 0);
|
||||||
const char *Name = I->getKeyData();
|
const char *Name = I->getKeyData();
|
||||||
printSuffixedName(Name, "$stub");
|
O << Name << ":\n";
|
||||||
O << ":\n"
|
O << "\t.indirect_symbol ";
|
||||||
"\t.indirect_symbol " << Name << "\n"
|
|
||||||
"\thlt ; hlt ; hlt ; hlt ; hlt\n";
|
// Print the name without the $stub.
|
||||||
|
PrintWithoutDarwinSuffix(Name, I->getKeyLength(), strlen("$stub"), O);
|
||||||
|
O << '\n';
|
||||||
|
O << "\thlt ; hlt ; hlt ; hlt ; hlt\n";
|
||||||
}
|
}
|
||||||
O << '\n';
|
O << '\n';
|
||||||
}
|
}
|
||||||
@ -951,8 +963,10 @@ bool X86ATTAsmPrinter::doFinalization(Module &M) {
|
|||||||
for (StringSet<>::iterator I = GVStubs.begin(), E = GVStubs.end();
|
for (StringSet<>::iterator I = GVStubs.begin(), E = GVStubs.end();
|
||||||
I != E; ++I) {
|
I != E; ++I) {
|
||||||
const char *Name = I->getKeyData();
|
const char *Name = I->getKeyData();
|
||||||
printSuffixedName(Name, "$non_lazy_ptr");
|
O << Name << ":\n\t.indirect_symbol ";
|
||||||
O << ":\n\t.indirect_symbol " << Name << "\n\t.long\t0\n";
|
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(),
|
for (StringSet<>::iterator I = HiddenGVStubs.begin(),
|
||||||
E = HiddenGVStubs.end(); I != E; ++I) {
|
E = HiddenGVStubs.end(); I != E; ++I) {
|
||||||
const char *Name = I->getKeyData();
|
const char *Name = I->getKeyData();
|
||||||
printSuffixedName(Name, "$non_lazy_ptr");
|
O << Name << ":\n" << TAI->getData32bitsDirective();
|
||||||
O << ":\n" << TAI->getData32bitsDirective() << Name << '\n';
|
PrintWithoutDarwinSuffix(Name, I->getKeyLength(),
|
||||||
|
strlen("$non_lazy_ptr"), O);
|
||||||
|
O << '\n';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,12 +116,19 @@ std::string Mangler::makeNameProper(const std::string &X,
|
|||||||
return Result;
|
return Result;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Mangler::getValueName(const GlobalValue *GV, const char *Suffix) {
|
/// getMangledName - Returns the mangled name of V, an LLVM Value,
|
||||||
|
/// in the current module. If 'Suffix' is specified, the name ends with the
|
||||||
|
/// specified suffix. If 'ForcePrivate' is specified, the label is specified
|
||||||
|
/// to have a private label prefix.
|
||||||
|
///
|
||||||
|
std::string Mangler::getMangledName(const GlobalValue *GV, const char *Suffix,
|
||||||
|
bool ForcePrivate) {
|
||||||
assert((!isa<Function>(GV) || !cast<Function>(GV)->isIntrinsic()) &&
|
assert((!isa<Function>(GV) || !cast<Function>(GV)->isIntrinsic()) &&
|
||||||
"Intrinsic functions cannot be mangled by Mangler");
|
"Intrinsic functions cannot be mangled by Mangler");
|
||||||
|
|
||||||
if (GV->hasName())
|
if (GV->hasName())
|
||||||
return makeNameProper(GV->getName() + Suffix, GV->hasPrivateLinkage());
|
return makeNameProper(GV->getName() + Suffix,
|
||||||
|
GV->hasPrivateLinkage() | ForcePrivate);
|
||||||
|
|
||||||
// Get the ID for the global, assigning a new one if we haven't got one
|
// Get the ID for the global, assigning a new one if we haven't got one
|
||||||
// already.
|
// already.
|
||||||
@ -129,7 +136,8 @@ std::string Mangler::getValueName(const GlobalValue *GV, const char *Suffix) {
|
|||||||
if (ID == 0) ID = NextAnonGlobalID++;
|
if (ID == 0) ID = NextAnonGlobalID++;
|
||||||
|
|
||||||
// Must mangle the global into a unique ID.
|
// Must mangle the global into a unique ID.
|
||||||
return "__unnamed_" + utostr(ID) + Suffix;
|
return makeNameProper("__unnamed_" + utostr(ID) + Suffix,
|
||||||
|
GV->hasPrivateLinkage() | ForcePrivate);
|
||||||
}
|
}
|
||||||
|
|
||||||
Mangler::Mangler(Module &M, const char *prefix, const char *privatePrefix)
|
Mangler::Mangler(Module &M, const char *prefix, const char *privatePrefix)
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
; RUN: llvm-as < %s | \
|
; RUN: llvm-as < %s | \
|
||||||
; RUN: llc -relocation-model=dynamic-no-pic -mtriple=i686-apple-darwin8.7.2 |\
|
; RUN: llc -relocation-model=dynamic-no-pic -mtriple=i686-apple-darwin8.7.2 |\
|
||||||
; RUN: grep L_Arr.non_lazy_ptr
|
; RUN: grep LArr.non_lazy_ptr
|
||||||
; RUN: llvm-as < %s | \
|
; RUN: llvm-as < %s | \
|
||||||
; RUN: llc -disable-post-RA-scheduler=true \
|
; RUN: llc -disable-post-RA-scheduler=true \
|
||||||
; RUN: -relocation-model=dynamic-no-pic -mtriple=i686-apple-darwin8.7.2 |\
|
; RUN: -relocation-model=dynamic-no-pic -mtriple=i686-apple-darwin8.7.2 |\
|
||||||
; RUN: %prcontext L_Arr.non_lazy_ptr 1 | grep {4(%esp)}
|
; RUN: %prcontext LArr.non_lazy_ptr 1 | grep {4(%esp)}
|
||||||
|
|
||||||
@Arr = external global [0 x i32] ; <[0 x i32]*> [#uses=1]
|
@Arr = external global [0 x i32] ; <[0 x i32]*> [#uses=1]
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user