1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-23 19:23:23 +01:00

MCize a bunch more stuff, eliminating a lot of uses of the mangler

and CurrentFnName.

llvm-svn: 93594
This commit is contained in:
Chris Lattner 2010-01-16 00:21:18 +00:00
parent c35c4386a0
commit 40eb58664f
10 changed files with 367 additions and 196 deletions

View File

@ -256,7 +256,9 @@ bool ARMAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
case Function::InternalLinkage:
break;
case Function::ExternalLinkage:
O << "\t.globl\t" << CurrentFnName << "\n";
O << "\t.globl\t";
CurrentFnSym->print(O, MAI);
O << "\n";
break;
case Function::LinkerPrivateLinkage:
case Function::WeakAnyLinkage:
@ -264,29 +266,38 @@ bool ARMAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
case Function::LinkOnceAnyLinkage:
case Function::LinkOnceODRLinkage:
if (Subtarget->isTargetDarwin()) {
O << "\t.globl\t" << CurrentFnName << "\n";
O << "\t.weak_definition\t" << CurrentFnName << "\n";
O << "\t.globl\t";
CurrentFnSym->print(O, MAI);
O << "\n";
O << "\t.weak_definition\t";
CurrentFnSym->print(O, MAI);
O << "\n";
} else {
O << MAI->getWeakRefDirective() << CurrentFnName << "\n";
O << MAI->getWeakRefDirective();
CurrentFnSym->print(O, MAI);
O << "\n";
}
break;
}
printVisibility(CurrentFnName, F->getVisibility());
printVisibility(CurrentFnSym, F->getVisibility());
unsigned FnAlign = 1 << MF.getAlignment(); // MF alignment is log2.
if (AFI->isThumbFunction()) {
EmitAlignment(FnAlign, F, AFI->getAlign());
O << "\t.code\t16\n";
O << "\t.thumb_func";
if (Subtarget->isTargetDarwin())
O << "\t" << CurrentFnName;
if (Subtarget->isTargetDarwin()) {
O << "\t";
CurrentFnSym->print(O, MAI);
}
O << "\n";
} else {
EmitAlignment(FnAlign, F);
}
O << CurrentFnName << ":\n";
CurrentFnSym->print(O, MAI);
O << ":\n";
// Emit pre-function debug information.
DW->BeginFunction(&MF);
@ -313,8 +324,13 @@ bool ARMAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
printMachineInstruction(II);
}
if (MAI->hasDotTypeDotSizeDirective())
O << "\t.size " << CurrentFnName << ", .-" << CurrentFnName << "\n";
if (MAI->hasDotTypeDotSizeDirective()) {
O << "\t.size ";
CurrentFnSym->print(O, MAI);
O << ", .-";
CurrentFnSym->print(O, MAI);
O << "\n";
}
// Emit post-function debug information.
DW->EndFunction(&MF);

View File

@ -147,22 +147,29 @@ bool AlphaAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
case Function::PrivateLinkage:
case Function::LinkerPrivateLinkage:
break;
case Function::ExternalLinkage:
O << "\t.globl " << CurrentFnName << "\n";
break;
case Function::ExternalLinkage:
O << "\t.globl ";
CurrentFnSym->print(O, MAI);
O << "\n";
break;
case Function::WeakAnyLinkage:
case Function::WeakODRLinkage:
case Function::LinkOnceAnyLinkage:
case Function::LinkOnceODRLinkage:
O << MAI->getWeakRefDirective() << CurrentFnName << "\n";
O << MAI->getWeakRefDirective();
CurrentFnSym->print(O, MAI);
O << "\n";
break;
}
printVisibility(CurrentFnName, F->getVisibility());
printVisibility(CurrentFnSym, F->getVisibility());
O << "\t.ent " << CurrentFnName << "\n";
O << "\t.ent ";
CurrentFnSym->print(O, MAI);
O << "\n";
O << CurrentFnName << ":\n";
CurrentFnSym->print(O, MAI);
O << ":\n";
// Print out code for the function.
for (MachineFunction::const_iterator I = MF.begin(), E = MF.end();
@ -184,7 +191,9 @@ bool AlphaAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
}
}
O << "\t.end " << CurrentFnName << "\n";
O << "\t.end ";
CurrentFnSym->print(O, MAI);
O << "\n";
// We didn't modify anything.
return false;

View File

@ -39,7 +39,6 @@
#include "llvm/Support/Debug.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/FormattedStream.h"
#include "llvm/Support/Mangler.h"
#include "llvm/Support/MathExtras.h"
using namespace llvm;
@ -329,30 +328,25 @@ void SPUAsmPrinter::printOp(const MachineOperand &MO) {
case MachineOperand::MO_ExternalSymbol:
// Computing the address of an external symbol, not calling it.
if (TM.getRelocationModel() != Reloc::Static) {
std::string Name(MAI->getGlobalPrefix()); Name += MO.getSymbolName();
O << "L" << Name << "$non_lazy_ptr";
O << "L" << MAI->getGlobalPrefix() << MO.getSymbolName()
<< "$non_lazy_ptr";
return;
}
O << MAI->getGlobalPrefix() << MO.getSymbolName();
GetExternalSymbolSymbol(MO.getSymbolName())->print(O, MAI);
return;
case MachineOperand::MO_GlobalAddress: {
// Computing the address of a global symbol, not calling it.
GlobalValue *GV = MO.getGlobal();
std::string Name = Mang->getMangledName(GV);
case MachineOperand::MO_GlobalAddress:
// External or weakly linked global variables need non-lazily-resolved
// stubs
if (TM.getRelocationModel() != Reloc::Static) {
GlobalValue *GV = MO.getGlobal();
if (((GV->isDeclaration() || GV->hasWeakLinkage() ||
GV->hasLinkOnceLinkage() || GV->hasCommonLinkage()))) {
O << "L" << Name << "$non_lazy_ptr";
GetPrivateGlobalValueSymbolStub(GV, "$non_lazy_ptr")->print(O, MAI);
return;
}
}
O << Name;
GetGlobalValueSymbol(MO.getGlobal())->print(O, MAI);
return;
}
default:
O << "<unknown operand type: " << MO.getType() << ">";
return;
@ -505,9 +499,9 @@ void LinuxAsmPrinter::PrintGlobalVariable(const GlobalVariable *GVar) {
if (EmitSpecialLLVMGlobal(GVar))
return;
std::string name = Mang->getMangledName(GVar);
MCSymbol *GVarSym = GetGlobalValueSymbol(GVar);
printVisibility(name, GVar->getVisibility());
printVisibility(GVarSym, GVar->getVisibility());
Constant *C = GVar->getInitializer();
const Type *Type = C->getType();
@ -524,14 +518,23 @@ void LinuxAsmPrinter::PrintGlobalVariable(const GlobalVariable *GVar) {
if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it.
if (GVar->hasExternalLinkage()) {
O << "\t.global " << name << '\n';
O << "\t.type " << name << ", @object\n";
O << name << ":\n";
O << "\t.global ";
GVarSym->print(O, MAI);
O << '\n';
O << "\t.type ";
GVarSym->print(O, MAI);
O << ", @object\n";
GVarSym->print(O, MAI);
O << ":\n";
O << "\t.zero " << Size << '\n';
} else if (GVar->hasLocalLinkage()) {
O << MAI->getLCOMMDirective() << name << ',' << Size;
O << MAI->getLCOMMDirective();
GVarSym->print(O, MAI);
O << ',' << Size;
} else {
O << ".comm " << name << ',' << Size;
O << ".comm ";
GVarSym->print(O, MAI);
O << ',' << Size;
}
O << "\t\t" << MAI->getCommentString() << " '";
WriteAsOperand(O, GVar, /*PrintType=*/false, GVar->getParent());
@ -540,34 +543,42 @@ void LinuxAsmPrinter::PrintGlobalVariable(const GlobalVariable *GVar) {
}
switch (GVar->getLinkage()) {
// Should never be seen for the CellSPU platform...
case GlobalValue::LinkOnceAnyLinkage:
case GlobalValue::LinkOnceODRLinkage:
case GlobalValue::WeakAnyLinkage:
case GlobalValue::WeakODRLinkage:
case GlobalValue::CommonLinkage:
O << "\t.global " << name << '\n'
<< "\t.type " << name << ", @object\n"
<< "\t.weak " << name << '\n';
// Should never be seen for the CellSPU platform...
case GlobalValue::LinkOnceAnyLinkage:
case GlobalValue::LinkOnceODRLinkage:
case GlobalValue::WeakAnyLinkage:
case GlobalValue::WeakODRLinkage:
case GlobalValue::CommonLinkage:
O << "\t.global ";
GVarSym->print(O, MAI);
O << "\n\t.type ";
GVarSym->print(O, MAI);
O << ", @object\n" << "\t.weak ";
GVarSym->print(O, MAI);
O << '\n';
break;
case GlobalValue::AppendingLinkage:
case GlobalValue::AppendingLinkage:
// FIXME: appending linkage variables should go into a section of
// their name or something. For now, just emit them as external.
case GlobalValue::ExternalLinkage:
case GlobalValue::ExternalLinkage:
// If external or appending, declare as a global symbol
O << "\t.global " << name << '\n'
<< "\t.type " << name << ", @object\n";
// FALL THROUGH
case GlobalValue::PrivateLinkage:
case GlobalValue::LinkerPrivateLinkage:
case GlobalValue::InternalLinkage:
O << "\t.global ";
GVarSym->print(O, MAI);
O << "\n\t.type ";
GVarSym->print(O, MAI);
O << ", @object\n";
break;
default:
case GlobalValue::PrivateLinkage:
case GlobalValue::LinkerPrivateLinkage:
case GlobalValue::InternalLinkage:
break;
default:
llvm_report_error("Unknown linkage type!");
}
EmitAlignment(Align, GVar);
O << name << ":\t\t\t\t" << MAI->getCommentString() << " '";
GVarSym->print(O, MAI);
O << ":\t\t\t\t" << MAI->getCommentString() << " '";
WriteAsOperand(O, GVar, /*PrintType=*/false, GVar->getParent());
O << "'\n";

View File

@ -38,9 +38,7 @@
#include "llvm/ADT/Statistic.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/FormattedStream.h"
#include "llvm/Support/Mangler.h"
#include "llvm/Support/ErrorHandling.h"
using namespace llvm;
STATISTIC(EmittedInsts, "Number of machine instrs printed");
@ -101,14 +99,16 @@ void MSP430AsmPrinter::PrintGlobalVariable(const GlobalVariable* GVar) {
const TargetData *TD = TM.getTargetData();
std::string name = Mang->getMangledName(GVar);
MCSymbol *GVarSym = GetGlobalValueSymbol(GVar);
Constant *C = GVar->getInitializer();
unsigned Size = TD->getTypeAllocSize(C->getType());
unsigned Align = TD->getPreferredAlignmentLog(GVar);
printVisibility(name, GVar->getVisibility());
printVisibility(GVarSym, GVar->getVisibility());
O << "\t.type\t" << name << ",@object\n";
O << "\t.type\t";
GVarSym->print(O, MAI);
O << ",@object\n";
OutStreamer.SwitchSection(getObjFileLowering().SectionForGlobal(GVar, Mang,
TM));
@ -119,10 +119,15 @@ void MSP430AsmPrinter::PrintGlobalVariable(const GlobalVariable* GVar) {
if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it.
if (GVar->hasLocalLinkage())
O << "\t.local\t" << name << '\n';
if (GVar->hasLocalLinkage()) {
O << "\t.local\t";
GVarSym->print(O, MAI);
O << '\n';
}
O << MAI->getCOMMDirective() << name << ',' << Size;
O << MAI->getCOMMDirective();
GVarSym->print(O, MAI);
O << ',' << Size;
if (MAI->getCOMMDirectiveTakesAlignment())
O << ',' << (MAI->getAlignmentIsInBytes() ? (1 << Align) : Align);
@ -141,7 +146,9 @@ void MSP430AsmPrinter::PrintGlobalVariable(const GlobalVariable* GVar) {
case GlobalValue::LinkOnceODRLinkage:
case GlobalValue::WeakAnyLinkage:
case GlobalValue::WeakODRLinkage:
O << "\t.weak\t" << name << '\n';
O << "\t.weak\t";
GVarSym->print(O, MAI);
O << '\n';
break;
case GlobalValue::DLLExportLinkage:
case GlobalValue::AppendingLinkage:
@ -149,7 +156,9 @@ void MSP430AsmPrinter::PrintGlobalVariable(const GlobalVariable* GVar) {
// their name or something. For now, just emit them as external.
case GlobalValue::ExternalLinkage:
// If external or appending, declare as a global symbol
O << "\t.globl " << name << '\n';
O << "\t.globl ";
GVarSym->print(O, MAI);
O << '\n';
// FALL THROUGH
case GlobalValue::PrivateLinkage:
case GlobalValue::LinkerPrivateLinkage:
@ -161,7 +170,8 @@ void MSP430AsmPrinter::PrintGlobalVariable(const GlobalVariable* GVar) {
// Use 16-bit alignment by default to simplify bunch of stuff
EmitAlignment(Align, GVar);
O << name << ":";
GVarSym->print(O, MAI);
O << ":";
if (VerboseAsm) {
O.PadToColumn(MAI->getCommentColumn());
O << MAI->getCommentString() << ' ';
@ -171,8 +181,11 @@ void MSP430AsmPrinter::PrintGlobalVariable(const GlobalVariable* GVar) {
EmitGlobalConstant(C);
if (MAI->hasDotTypeDotSizeDirective())
O << "\t.size\t" << name << ", " << Size << '\n';
if (MAI->hasDotTypeDotSizeDirective()) {
O << "\t.size\t";
GVarSym->print(O, MAI);
O << ", " << Size << '\n';
}
}
void MSP430AsmPrinter::emitFunctionHeader(const MachineFunction &MF) {
@ -190,20 +203,27 @@ void MSP430AsmPrinter::emitFunctionHeader(const MachineFunction &MF) {
case Function::LinkerPrivateLinkage:
break;
case Function::ExternalLinkage:
O << "\t.globl\t" << CurrentFnName << '\n';
O << "\t.globl\t";
CurrentFnSym->print(O, MAI);
O << '\n';
break;
case Function::LinkOnceAnyLinkage:
case Function::LinkOnceODRLinkage:
case Function::WeakAnyLinkage:
case Function::WeakODRLinkage:
O << "\t.weak\t" << CurrentFnName << '\n';
O << "\t.weak\t";
CurrentFnSym->print(O, MAI);
O << '\n';
break;
}
printVisibility(CurrentFnName, F->getVisibility());
printVisibility(CurrentFnSym, F->getVisibility());
O << "\t.type\t" << CurrentFnName << ",@function\n"
<< CurrentFnName << ":\n";
O << "\t.type\t";
CurrentFnSym->print(O, MAI);
O << ",@function\n";
CurrentFnSym->print(O, MAI);
O << ":\n";
}
bool MSP430AsmPrinter::runOnMachineFunction(MachineFunction &MF) {
@ -225,8 +245,13 @@ bool MSP430AsmPrinter::runOnMachineFunction(MachineFunction &MF) {
printMachineInstruction(II);
}
if (MAI->hasDotTypeDotSizeDirective())
O << "\t.size\t" << CurrentFnName << ", .-" << CurrentFnName << '\n';
if (MAI->hasDotTypeDotSizeDirective()) {
O << "\t.size\t";
CurrentFnSym->print(O, MAI);
O << ", .-";
CurrentFnSym->print(O, MAI);
O << '\n';
}
// We didn't modify anything
return false;
@ -263,14 +288,14 @@ void MSP430AsmPrinter::printOperand(const MachineInstr *MI, int OpNum,
return;
case MachineOperand::MO_GlobalAddress: {
bool isMemOp = Modifier && !strcmp(Modifier, "mem");
std::string Name = Mang->getMangledName(MO.getGlobal());
uint64_t Offset = MO.getOffset();
O << (isMemOp ? '&' : '#');
if (Offset)
O << '(' << Offset << '+';
O << Name;
GetGlobalValueSymbol(MO.getGlobal())->print(O, MAI);
if (Offset)
O << ')';
@ -278,11 +303,8 @@ void MSP430AsmPrinter::printOperand(const MachineInstr *MI, int OpNum,
}
case MachineOperand::MO_ExternalSymbol: {
bool isMemOp = Modifier && !strcmp(Modifier, "mem");
std::string Name(MAI->getGlobalPrefix());
Name += MO.getSymbolName();
O << (isMemOp ? '&' : '#') << Name;
O << (isMemOp ? '&' : '#');
O << MAI->getGlobalPrefix() << MO.getSymbolName();
return;
}
default:

View File

@ -37,7 +37,6 @@
#include "llvm/Target/TargetOptions.h"
#include "llvm/Target/TargetRegistry.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/Mangler.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/Support/Debug.h"
@ -45,7 +44,6 @@
#include "llvm/Support/FormattedStream.h"
#include "llvm/Support/MathExtras.h"
#include <cctype>
using namespace llvm;
STATISTIC(EmittedInsts, "Number of machine instrs printed");
@ -219,15 +217,23 @@ void MipsAsmPrinter::emitFunctionStart(MachineFunction &MF) {
// 2 bits aligned
EmitAlignment(MF.getAlignment(), F);
O << "\t.globl\t" << CurrentFnName << '\n';
O << "\t.ent\t" << CurrentFnName << '\n';
O << "\t.globl\t";
CurrentFnSym->print(O, MAI);
O << '\n';
O << "\t.ent\t";
CurrentFnSym->print(O, MAI);
O << '\n';
printVisibility(CurrentFnName, F->getVisibility());
printVisibility(CurrentFnSym, F->getVisibility());
if ((MAI->hasDotTypeDotSizeDirective()) && Subtarget->isLinux())
O << "\t.type\t" << CurrentFnName << ", @function\n";
if ((MAI->hasDotTypeDotSizeDirective()) && Subtarget->isLinux()) {
O << "\t.type\t";
CurrentFnSym->print(O, MAI);
O << ", @function\n";
}
O << CurrentFnName << ":\n";
CurrentFnSym->print(O, MAI);
O << ":\n";
emitFrameDirective(MF);
printSavedRegsBitmask(MF);
@ -243,9 +249,16 @@ void MipsAsmPrinter::emitFunctionEnd(MachineFunction &MF) {
O << "\t.set\tmacro\n";
O << "\t.set\treorder\n";
O << "\t.end\t" << CurrentFnName << '\n';
if (MAI->hasDotTypeDotSizeDirective() && !Subtarget->isLinux())
O << "\t.size\t" << CurrentFnName << ", .-" << CurrentFnName << '\n';
O << "\t.end\t";
CurrentFnSym->print(O, MAI);
O << '\n';
if (MAI->hasDotTypeDotSizeDirective() && !Subtarget->isLinux()) {
O << "\t.size\t";
CurrentFnSym->print(O, MAI);
O << ", .-";
CurrentFnSym->print(O, MAI);
O << '\n';
}
}
/// runOnMachineFunction - This uses the printMachineInstruction()
@ -350,16 +363,16 @@ void MipsAsmPrinter::printOperand(const MachineInstr *MI, int opNum) {
return;
case MachineOperand::MO_GlobalAddress:
O << Mang->getMangledName(MO.getGlobal());
GetGlobalValueSymbol(MO.getGlobal())->print(O, MAI);
break;
case MachineOperand::MO_ExternalSymbol:
O << MO.getSymbolName();
GetExternalSymbolSymbol(MO.getSymbolName())->print(O, MAI);
break;
case MachineOperand::MO_JumpTableIndex:
O << MAI->getPrivateGlobalPrefix() << "JTI" << getFunctionNumber()
<< '_' << MO.getIndex();
<< '_' << MO.getIndex();
break;
case MachineOperand::MO_ConstantPoolIndex:
@ -436,7 +449,7 @@ void MipsAsmPrinter::PrintGlobalVariable(const GlobalVariable *GVar) {
return;
O << "\n\n";
std::string name = Mang->getMangledName(GVar);
MCSymbol *GVarSym = GetGlobalValueSymbol(GVar);
Constant *C = GVar->getInitializer();
const Type *CTy = C->getType();
unsigned Size = TD->getTypeAllocSize(CTy);
@ -455,7 +468,7 @@ void MipsAsmPrinter::PrintGlobalVariable(const GlobalVariable *GVar) {
} else
Align = TD->getPreferredTypeAlignmentShift(CTy);
printVisibility(name, GVar->getVisibility());
printVisibility(GVarSym, GVar->getVisibility());
OutStreamer.SwitchSection(getObjFileLowering().SectionForGlobal(GVar, Mang,
TM));
@ -465,10 +478,15 @@ void MipsAsmPrinter::PrintGlobalVariable(const GlobalVariable *GVar) {
(GVar->hasLocalLinkage() || GVar->isWeakForLinker())) {
if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it.
if (GVar->hasLocalLinkage())
O << "\t.local\t" << name << '\n';
if (GVar->hasLocalLinkage()) {
O << "\t.local\t";
GVarSym->print(O, MAI);
O << '\n';
}
O << MAI->getCOMMDirective() << name << ',' << Size;
O << MAI->getCOMMDirective();
GVarSym->print(O, MAI);
O << ',' << Size;
if (MAI->getCOMMDirectiveTakesAlignment())
O << ',' << (1 << Align);
@ -484,14 +502,18 @@ void MipsAsmPrinter::PrintGlobalVariable(const GlobalVariable *GVar) {
case GlobalValue::WeakODRLinkage:
// FIXME: Verify correct for weak.
// Nonnull linkonce -> weak
O << "\t.weak " << name << '\n';
O << "\t.weak ";
GVarSym->print(O, MAI);
O << '\n';
break;
case GlobalValue::AppendingLinkage:
// FIXME: appending linkage variables should go into a section of their name
// or something. For now, just emit them as external.
case GlobalValue::ExternalLinkage:
// If external or appending, declare as a global symbol
O << MAI->getGlobalDirective() << name << '\n';
O << MAI->getGlobalDirective();
GVarSym->print(O, MAI);
O << '\n';
// Fall Through
case GlobalValue::PrivateLinkage:
case GlobalValue::LinkerPrivateLinkage:
@ -512,11 +534,16 @@ void MipsAsmPrinter::PrintGlobalVariable(const GlobalVariable *GVar) {
EmitAlignment(Align, GVar);
if (MAI->hasDotTypeDotSizeDirective() && printSizeAndType) {
O << "\t.type " << name << ",@object\n";
O << "\t.size " << name << ',' << Size << '\n';
O << "\t.type ";
GVarSym->print(O, MAI);
O << ",@object\n";
O << "\t.size ";
GVarSym->print(O, MAI);
O << ',' << Size << '\n';
}
O << name << ":\n";
GVarSym->print(O, MAI);
O << ":\n";
EmitGlobalConstant(C);
}

View File

@ -641,34 +641,47 @@ bool PPCLinuxAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
case Function::InternalLinkage: // Symbols default to internal.
break;
case Function::ExternalLinkage:
O << "\t.global\t" << CurrentFnName << '\n'
<< "\t.type\t" << CurrentFnName << ", @function\n";
O << "\t.global\t";
CurrentFnSym->print(O, MAI);
O << '\n' << "\t.type\t";
CurrentFnSym->print(O, MAI);
O << ", @function\n";
break;
case Function::LinkerPrivateLinkage:
case Function::WeakAnyLinkage:
case Function::WeakODRLinkage:
case Function::LinkOnceAnyLinkage:
case Function::LinkOnceODRLinkage:
O << "\t.global\t" << CurrentFnName << '\n';
O << "\t.weak\t" << CurrentFnName << '\n';
O << "\t.global\t";
CurrentFnSym->print(O, MAI);
O << '\n';
O << "\t.weak\t";
CurrentFnSym->print(O, MAI);
O << '\n';
break;
}
printVisibility(CurrentFnName, F->getVisibility());
printVisibility(CurrentFnSym, F->getVisibility());
EmitAlignment(MF.getAlignment(), F);
if (Subtarget.isPPC64()) {
// Emit an official procedure descriptor.
// FIXME 64-bit SVR4: Use MCSection here?
// FIXME 64-bit SVR4: Use MCSection here!
O << "\t.section\t\".opd\",\"aw\"\n";
O << "\t.align 3\n";
O << CurrentFnName << ":\n";
O << "\t.quad .L." << CurrentFnName << ",.TOC.@tocbase\n";
CurrentFnSym->print(O, MAI);
O << ":\n";
O << "\t.quad .L.";
CurrentFnSym->print(O, MAI);
O << ",.TOC.@tocbase\n";
O << "\t.previous\n";
O << ".L." << CurrentFnName << ":\n";
O << ".L.";
CurrentFnSym->print(O, MAI);
O << ":\n";
} else {
O << CurrentFnName << ":\n";
CurrentFnSym->print(O, MAI);
O << ":\n";
}
// Emit pre-function debug information.
@ -688,7 +701,11 @@ bool PPCLinuxAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
}
}
O << "\t.size\t" << CurrentFnName << ",.-" << CurrentFnName << '\n';
O << "\t.size\t";
CurrentFnSym->print(O, MAI);
O << ",.-";
CurrentFnSym->print(O, MAI);
O << '\n';
OutStreamer.SwitchSection(getObjFileLowering().SectionForGlobal(F, Mang, TM));
@ -829,22 +846,29 @@ bool PPCDarwinAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
case Function::InternalLinkage: // Symbols default to internal.
break;
case Function::ExternalLinkage:
O << "\t.globl\t" << CurrentFnName << '\n';
O << "\t.globl\t";
CurrentFnSym->print(O, MAI);
O << '\n';
break;
case Function::WeakAnyLinkage:
case Function::WeakODRLinkage:
case Function::LinkOnceAnyLinkage:
case Function::LinkOnceODRLinkage:
case Function::LinkerPrivateLinkage:
O << "\t.globl\t" << CurrentFnName << '\n';
O << "\t.weak_definition\t" << CurrentFnName << '\n';
O << "\t.globl\t";
CurrentFnSym->print(O, MAI);
O << '\n';
O << "\t.weak_definition\t";
CurrentFnSym->print(O, MAI);
O << '\n';
break;
}
printVisibility(CurrentFnName, F->getVisibility());
printVisibility(CurrentFnSym, F->getVisibility());
EmitAlignment(MF.getAlignment(), F);
O << CurrentFnName << ":\n";
CurrentFnSym->print(O, MAI);
O << ":\n";
// Emit pre-function debug information.
DW->BeginFunction(&MF);

View File

@ -138,7 +138,11 @@ bool SparcAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
DW->EndFunction(&MF);
// We didn't modify anything.
O << "\t.size\t" << CurrentFnName << ", .-" << CurrentFnName << '\n';
O << "\t.size\t";
CurrentFnSym->print(O, MAI);
O << ", .-";
CurrentFnSym->print(O, MAI);
O << '\n';
return false;
}
@ -156,7 +160,9 @@ void SparcAsmPrinter::emitFunctionHeader(const MachineFunction &MF) {
case Function::DLLExportLinkage:
case Function::ExternalLinkage:
// Function is externally visible
O << "\t.global\t" << CurrentFnName << '\n';
O << "\t.global\t";
CurrentFnSym->print(O, MAI);
O << '\n';
break;
case Function::LinkerPrivateLinkage:
case Function::LinkOnceAnyLinkage:
@ -164,14 +170,18 @@ void SparcAsmPrinter::emitFunctionHeader(const MachineFunction &MF) {
case Function::WeakAnyLinkage:
case Function::WeakODRLinkage:
// Function is weak
O << "\t.weak\t" << CurrentFnName << '\n' ;
O << "\t.weak\t";CurrentFnSym->print(O, MAI);
O << '\n' ;
break;
}
printVisibility(CurrentFnName, F->getVisibility());
printVisibility(CurrentFnSym, F->getVisibility());
O << "\t.type\t" << CurrentFnName << ", #function\n";
O << CurrentFnName << ":\n";
O << "\t.type\t";
CurrentFnSym->print(O, MAI);
O << ", #function\n";
CurrentFnSym->print(O, MAI);
O << ":\n";
}

View File

@ -99,20 +99,27 @@ void SystemZAsmPrinter::emitFunctionHeader(const MachineFunction &MF) {
case Function::LinkerPrivateLinkage:
break;
case Function::ExternalLinkage:
O << "\t.globl\t" << CurrentFnName << '\n';
O << "\t.globl\t";
CurrentFnSym->print(O, MAI);
O << '\n';
break;
case Function::LinkOnceAnyLinkage:
case Function::LinkOnceODRLinkage:
case Function::WeakAnyLinkage:
case Function::WeakODRLinkage:
O << "\t.weak\t" << CurrentFnName << '\n';
O << "\t.weak\t";
CurrentFnSym->print(O, MAI);
O << '\n';
break;
}
printVisibility(CurrentFnName, F->getVisibility());
printVisibility(CurrentFnSym, F->getVisibility());
O << "\t.type\t" << CurrentFnName << ",@function\n"
<< CurrentFnName << ":\n";
O << "\t.type\t";
CurrentFnSym->print(O, MAI);
O << ",@function\n";
CurrentFnSym->print(O, MAI);
O << ":\n";
}
bool SystemZAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
@ -137,8 +144,13 @@ bool SystemZAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
printMachineInstruction(II);
}
if (MAI->hasDotTypeDotSizeDirective())
O << "\t.size\t" << CurrentFnName << ", .-" << CurrentFnName << '\n';
if (MAI->hasDotTypeDotSizeDirective()) {
O << "\t.size\t";
CurrentFnSym->print(O, MAI);
O << ", .-";
CurrentFnSym->print(O, MAI);
O << '\n';
}
// Print out jump tables referenced by the function.
EmitJumpTableInfo(MF.getJumpTableInfo(), MF);

View File

@ -84,7 +84,9 @@ void X86AsmPrinter::emitFunctionHeader(const MachineFunction &MF) {
break;
case Function::DLLExportLinkage:
case Function::ExternalLinkage:
O << "\t.globl\t" << CurrentFnName << '\n';
O << "\t.globl\t";
CurrentFnSym->print(O, MAI);
O << '\n';
break;
case Function::LinkerPrivateLinkage:
case Function::LinkOnceAnyLinkage:
@ -92,30 +94,41 @@ void X86AsmPrinter::emitFunctionHeader(const MachineFunction &MF) {
case Function::WeakAnyLinkage:
case Function::WeakODRLinkage:
if (Subtarget->isTargetDarwin()) {
O << "\t.globl\t" << CurrentFnName << '\n';
O << MAI->getWeakDefDirective() << CurrentFnName << '\n';
O << "\t.globl\t";
CurrentFnSym->print(O, MAI);
O << '\n';
O << MAI->getWeakDefDirective();
CurrentFnSym->print(O, MAI);
O << '\n';
} else if (Subtarget->isTargetCygMing()) {
O << "\t.globl\t" << CurrentFnName << "\n"
"\t.linkonce discard\n";
O << "\t.globl\t";
CurrentFnSym->print(O, MAI);
O << "\n\t.linkonce discard\n";
} else {
O << "\t.weak\t" << CurrentFnName << '\n';
O << "\t.weak\t";
CurrentFnSym->print(O, MAI);
O << '\n';
}
break;
}
printVisibility(CurrentFnName, F->getVisibility());
printVisibility(CurrentFnSym, F->getVisibility());
if (Subtarget->isTargetELF())
O << "\t.type\t" << CurrentFnName << ",@function\n";
else if (Subtarget->isTargetCygMing()) {
O << "\t.def\t " << CurrentFnName
<< ";\t.scl\t" <<
if (Subtarget->isTargetELF()) {
O << "\t.type\t";
CurrentFnSym->print(O, MAI);
O << ",@function\n";
} else if (Subtarget->isTargetCygMing()) {
O << "\t.def\t ";
CurrentFnSym->print(O, MAI);
O << ";\t.scl\t" <<
(F->hasInternalLinkage() ? COFF::C_STAT : COFF::C_EXT)
<< ";\t.type\t" << (COFF::DT_FCN << COFF::N_BTSHFT)
<< ";\t.endef\n";
}
O << CurrentFnName << ':';
CurrentFnSym->print(O, MAI);
O << ':';
if (VerboseAsm) {
O.PadToColumn(MAI->getCommentColumn());
O << MAI->getCommentString() << ' ';
@ -125,8 +138,11 @@ void X86AsmPrinter::emitFunctionHeader(const MachineFunction &MF) {
// Add some workaround for linkonce linkage on Cygwin\MinGW
if (Subtarget->isTargetCygMing() &&
(F->hasLinkOnceLinkage() || F->hasWeakLinkage()))
O << "Lllvm$workaround$fake$stub$" << CurrentFnName << ":\n";
(F->hasLinkOnceLinkage() || F->hasWeakLinkage())) {
O << "Lllvm$workaround$fake$stub$";
CurrentFnSym->print(O, MAI);
O << ":\n";
}
}
/// runOnMachineFunction - This uses the printMachineInstruction()
@ -183,8 +199,13 @@ bool X86AsmPrinter::runOnMachineFunction(MachineFunction &MF) {
O << "\tnop\n";
}
if (MAI->hasDotTypeDotSizeDirective())
O << "\t.size\t" << CurrentFnName << ", .-" << CurrentFnName << '\n';
if (MAI->hasDotTypeDotSizeDirective()) {
O << "\t.size\t";
CurrentFnSym->print(O, MAI);
O << ", .-";
CurrentFnSym->print(O, MAI);
O << '\n';
}
// Emit post-function debug information.
if (MAI->doesSupportDebugInformation() || MAI->doesSupportExceptionHandling())

View File

@ -69,10 +69,9 @@ namespace {
bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
unsigned AsmVariant, const char *ExtraCode);
void emitGlobalDirective(const std::string &name);
void emitExternDirective(const std::string &name);
void emitGlobalDirective(const MCSymbol *Sym);
void emitArrayBound(const std::string &name, const GlobalVariable *GV);
void emitArrayBound(const MCSymbol *Sym, const GlobalVariable *GV);
virtual void PrintGlobalVariable(const GlobalVariable *GV);
void emitFunctionStart(MachineFunction &MF);
@ -95,35 +94,31 @@ namespace {
#include "XCoreGenAsmWriter.inc"
void XCoreAsmPrinter::
emitGlobalDirective(const std::string &name)
{
O << MAI->getGlobalDirective() << name;
void XCoreAsmPrinter::emitGlobalDirective(const MCSymbol *Sym) {
O << MAI->getGlobalDirective();
Sym->print(O, MAI);
O << "\n";
}
void XCoreAsmPrinter::
emitExternDirective(const std::string &name)
{
O << "\t.extern\t" << name;
O << '\n';
}
void XCoreAsmPrinter::
emitArrayBound(const std::string &name, const GlobalVariable *GV)
{
void XCoreAsmPrinter::emitArrayBound(const MCSymbol *Sym,
const GlobalVariable *GV) {
assert(((GV->hasExternalLinkage() ||
GV->hasWeakLinkage()) ||
GV->hasLinkOnceLinkage()) && "Unexpected linkage");
if (const ArrayType *ATy = dyn_cast<ArrayType>(
cast<PointerType>(GV->getType())->getElementType()))
{
O << MAI->getGlobalDirective() << name << ".globound" << "\n";
O << MAI->getSetDirective() << name << ".globound" << ","
cast<PointerType>(GV->getType())->getElementType())) {
O << MAI->getGlobalDirective();
Sym->print(O, MAI);
O << ".globound" << "\n";
O << MAI->getSetDirective();
Sym->print(O, MAI);
O << ".globound" << ","
<< ATy->getNumElements() << "\n";
if (GV->hasWeakLinkage() || GV->hasLinkOnceLinkage()) {
// TODO Use COMDAT groups for LinkOnceLinkage
O << MAI->getWeakDefDirective() << name << ".globound" << "\n";
O << MAI->getWeakDefDirective();
Sym->print(O, MAI);
O << ".globound" << "\n";
}
}
}
@ -135,15 +130,19 @@ void XCoreAsmPrinter::PrintGlobalVariable(const GlobalVariable *GV) {
return;
const TargetData *TD = TM.getTargetData();
OutStreamer.SwitchSection(getObjFileLowering().SectionForGlobal(GV, Mang,TM));
std::string name = Mang->getMangledName(GV);
MCSymbol *GVSym = GetGlobalValueSymbol(GV);
Constant *C = GV->getInitializer();
unsigned Align = (unsigned)TD->getPreferredTypeAlignmentShift(C->getType());
// Mark the start of the global
O << "\t.cc_top " << name << ".data," << name << "\n";
O << "\t.cc_top ";
GVSym->print(O, MAI);
O << ".data,";
GVSym->print(O, MAI);
O << "\n";
switch (GV->getLinkage()) {
case GlobalValue::AppendingLinkage:
@ -153,11 +152,13 @@ void XCoreAsmPrinter::PrintGlobalVariable(const GlobalVariable *GV) {
case GlobalValue::WeakAnyLinkage:
case GlobalValue::WeakODRLinkage:
case GlobalValue::ExternalLinkage:
emitArrayBound(name, GV);
emitGlobalDirective(name);
emitArrayBound(GVSym, GV);
emitGlobalDirective(GVSym);
// TODO Use COMDAT groups for LinkOnceLinkage
if (GV->hasWeakLinkage() || GV->hasLinkOnceLinkage()) {
O << MAI->getWeakDefDirective() << name << "\n";
O << MAI->getWeakDefDirective();
GVSym->print(O, MAI);
O << "\n";
}
// FALL THROUGH
case GlobalValue::InternalLinkage:
@ -181,10 +182,15 @@ void XCoreAsmPrinter::PrintGlobalVariable(const GlobalVariable *GV) {
Size *= MaxThreads;
}
if (MAI->hasDotTypeDotSizeDirective()) {
O << "\t.type " << name << ",@object\n";
O << "\t.size " << name << "," << Size << "\n";
O << "\t.type ";
GVSym->print(O, MAI);
O << ",@object\n";
O << "\t.size ";
GVSym->print(O, MAI);
O << "," << Size << "\n";
}
O << name << ":\n";
GVSym->print(O, MAI);
O << ":\n";
EmitGlobalConstant(C);
if (GV->isThreadLocal()) {
@ -199,7 +205,9 @@ void XCoreAsmPrinter::PrintGlobalVariable(const GlobalVariable *GV) {
}
// Mark the end of the global
O << "\t.cc_bottom " << name << ".data\n";
O << "\t.cc_bottom ";
GVSym->print(O, MAI);
O << ".data\n";
}
/// Emit the directives on the start of functions
@ -210,7 +218,11 @@ void XCoreAsmPrinter::emitFunctionStart(MachineFunction &MF) {
OutStreamer.SwitchSection(getObjFileLowering().SectionForGlobal(F, Mang, TM));
// Mark the start of the function
O << "\t.cc_top " << CurrentFnName << ".function," << CurrentFnName << "\n";
O << "\t.cc_top ";
CurrentFnSym->print(O, MAI);
O << ".function,";
CurrentFnSym->print(O, MAI);
O << "\n";
switch (F->getLinkage()) {
default: llvm_unreachable("Unknown linkage type!");
@ -219,31 +231,38 @@ void XCoreAsmPrinter::emitFunctionStart(MachineFunction &MF) {
case Function::LinkerPrivateLinkage:
break;
case Function::ExternalLinkage:
emitGlobalDirective(CurrentFnName);
emitGlobalDirective(CurrentFnSym);
break;
case Function::LinkOnceAnyLinkage:
case Function::LinkOnceODRLinkage:
case Function::WeakAnyLinkage:
case Function::WeakODRLinkage:
// TODO Use COMDAT groups for LinkOnceLinkage
O << MAI->getGlobalDirective() << CurrentFnName << "\n";
O << MAI->getWeakDefDirective() << CurrentFnName << "\n";
O << MAI->getGlobalDirective();
CurrentFnSym->print(O, MAI);
O << "\n";
O << MAI->getWeakDefDirective();
CurrentFnSym->print(O, MAI);
O << "\n";
break;
}
// (1 << 1) byte aligned
EmitAlignment(MF.getAlignment(), F, 1);
if (MAI->hasDotTypeDotSizeDirective()) {
O << "\t.type " << CurrentFnName << ",@function\n";
O << "\t.type ";
CurrentFnSym->print(O, MAI);
O << ",@function\n";
}
O << CurrentFnName << ":\n";
CurrentFnSym->print(O, MAI);
O << ":\n";
}
/// Emit the directives on the end of functions
void XCoreAsmPrinter::
emitFunctionEnd(MachineFunction &MF)
{
void XCoreAsmPrinter::emitFunctionEnd(MachineFunction &MF) {
// Mark the end of the function
O << "\t.cc_bottom " << CurrentFnName << ".function\n";
O << "\t.cc_bottom ";
CurrentFnSym->print(O, MAI);
O << ".function\n";
}
/// runOnMachineFunction - This uses the printMachineInstruction()