#include "llvm/Constants.h"
#include "llvm/DerivedTypes.h"
#include "llvm/Module.h"
+#include "llvm/MDNode.h"
#include "llvm/Assembly/Writer.h"
#include "llvm/CodeGen/AsmPrinter.h"
#include "llvm/CodeGen/DwarfWriter.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Debug.h"
+#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/Compiler.h"
-#include "llvm/Support/raw_ostream.h"
+#include "llvm/Support/FormattedStream.h"
#include "llvm/Target/TargetAsmInfo.h"
#include "llvm/Target/TargetRegisterInfo.h"
#include "llvm/Target/TargetInstrInfo.h"
#include "llvm/Target/TargetOptions.h"
+#include "llvm/Target/TargetRegistry.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/ADT/StringExtras.h"
-#include <set>
+#include "llvm/ADT/StringSet.h"
using namespace llvm;
STATISTIC(EmittedInsts, "Number of machine instrs printed");
namespace {
- struct VISIBILITY_HIDDEN PPCAsmPrinter : public AsmPrinter {
- std::set<std::string> FnStubs, GVStubs;
- const PPCSubtarget &Subtarget;
+ class VISIBILITY_HIDDEN PPCAsmPrinter : public AsmPrinter {
+ protected:
+ struct FnStubInfo {
+ std::string Stub, LazyPtr, AnonSymbol;
+
+ FnStubInfo() {}
+
+ void Init(const GlobalValue *GV, Mangler *Mang) {
+ // Already initialized.
+ if (!Stub.empty()) return;
+ Stub = Mang->getMangledName(GV, "$stub", true);
+ LazyPtr = Mang->getMangledName(GV, "$lazy_ptr", true);
+ AnonSymbol = Mang->getMangledName(GV, "$stub$tmp", true);
+ }
- PPCAsmPrinter(raw_ostream &O, TargetMachine &TM, const TargetAsmInfo *T)
- : AsmPrinter(O, TM, T), Subtarget(TM.getSubtarget<PPCSubtarget>()) {
- }
+ void Init(const std::string &GV, Mangler *Mang) {
+ // Already initialized.
+ if (!Stub.empty()) return;
+ Stub = Mang->makeNameProper(GV+"$stub", true);
+ LazyPtr = Mang->makeNameProper(GV+"$lazy_ptr", true);
+ AnonSymbol = Mang->makeNameProper(GV+"$stub$tmp", true);
+ }
+ };
+
+ StringMap<FnStubInfo> FnStubs;
+ StringMap<std::string> GVStubs, HiddenGVStubs;
+ const PPCSubtarget &Subtarget;
+ public:
+ explicit PPCAsmPrinter(formatted_raw_ostream &O, TargetMachine &TM,
+ const TargetAsmInfo *T, bool V)
+ : AsmPrinter(O, TM, T, V),
+ Subtarget(TM.getSubtarget<PPCSubtarget>()) {}
virtual const char *getPassName() const {
return "PowerPC Assembly Printer";
unsigned enumRegToMachineReg(unsigned enumReg) {
switch (enumReg) {
- default: assert(0 && "Unhandled register!"); break;
+ default: llvm_unreachable("Unhandled register!");
case PPC::CR0: return 0;
case PPC::CR1: return 1;
case PPC::CR2: return 2;
case PPC::CR6: return 6;
case PPC::CR7: return 7;
}
- abort();
+ llvm_unreachable(0);
}
/// printInstruction - This method is automatically generated by tablegen
void printOperand(const MachineInstr *MI, unsigned OpNo) {
const MachineOperand &MO = MI->getOperand(OpNo);
- if (MO.isRegister()) {
+ if (MO.isReg()) {
printRegister(MO, false);
- } else if (MO.isImmediate()) {
+ } else if (MO.isImm()) {
O << MO.getImm();
} else {
printOp(MO);
O << (unsigned short)MI->getOperand(OpNo).getImm();
}
void printS16X4ImmOperand(const MachineInstr *MI, unsigned OpNo) {
- if (MI->getOperand(OpNo).isImmediate()) {
+ if (MI->getOperand(OpNo).isImm()) {
O << (short)(MI->getOperand(OpNo).getImm()*4);
} else {
O << "lo16(";
void printBranchOperand(const MachineInstr *MI, unsigned OpNo) {
// Branches can take an immediate operand. This is used by the branch
// selection pass to print $+8, an eight byte displacement from the PC.
- if (MI->getOperand(OpNo).isImmediate()) {
+ if (MI->getOperand(OpNo).isImm()) {
O << "$+" << MI->getOperand(OpNo).getImm()*4;
} else {
printOp(MI->getOperand(OpNo));
if (TM.getRelocationModel() != Reloc::Static) {
if (MO.getType() == MachineOperand::MO_GlobalAddress) {
GlobalValue *GV = MO.getGlobal();
- if (((GV->isDeclaration() || GV->hasWeakLinkage() ||
- GV->hasLinkOnceLinkage() || GV->hasCommonLinkage()))) {
+ if (GV->isDeclaration() || GV->isWeakForLinker()) {
// Dynamically-resolved functions need a stub for the function.
- std::string Name = Mang->getValueName(GV);
- FnStubs.insert(Name);
- printSuffixedName(Name, "$stub");
- if (GV->hasExternalWeakLinkage())
- ExtWeakSymbols.insert(GV);
+ FnStubInfo &FnInfo = FnStubs[Mang->getMangledName(GV)];
+ FnInfo.Init(GV, Mang);
+ O << FnInfo.Stub;
return;
}
}
if (MO.getType() == MachineOperand::MO_ExternalSymbol) {
- std::string Name(TAI->getGlobalPrefix()); Name += MO.getSymbolName();
- FnStubs.insert(Name);
- printSuffixedName(Name, "$stub");
+ FnStubInfo &FnInfo =FnStubs[Mang->makeNameProper(MO.getSymbolName())];
+ FnInfo.Init(MO.getSymbolName(), Mang);
+ O << FnInfo.Stub;
return;
}
}
O << "\"L" << getFunctionNumber() << "$pb\":";
}
void printSymbolHi(const MachineInstr *MI, unsigned OpNo) {
- if (MI->getOperand(OpNo).isImmediate()) {
+ if (MI->getOperand(OpNo).isImm()) {
printS16ImmOperand(MI, OpNo);
} else {
if (Subtarget.isDarwin()) O << "ha16(";
}
}
void printSymbolLo(const MachineInstr *MI, unsigned OpNo) {
- if (MI->getOperand(OpNo).isImmediate()) {
+ if (MI->getOperand(OpNo).isImm()) {
printS16ImmOperand(MI, OpNo);
} else {
if (Subtarget.isDarwin()) O << "lo16(";
void printMemRegImm(const MachineInstr *MI, unsigned OpNo) {
printSymbolLo(MI, OpNo);
O << '(';
- if (MI->getOperand(OpNo+1).isRegister() &&
+ if (MI->getOperand(OpNo+1).isReg() &&
MI->getOperand(OpNo+1).getReg() == PPC::R0)
O << "0";
else
O << ')';
}
void printMemRegImmShifted(const MachineInstr *MI, unsigned OpNo) {
- if (MI->getOperand(OpNo).isImmediate())
+ if (MI->getOperand(OpNo).isImm())
printS16X4ImmOperand(MI, OpNo);
else
printSymbolLo(MI, OpNo);
O << '(';
- if (MI->getOperand(OpNo+1).isRegister() &&
+ if (MI->getOperand(OpNo+1).isReg() &&
MI->getOperand(OpNo+1).getReg() == PPC::R0)
O << "0";
else
};
/// PPCLinuxAsmPrinter - PowerPC assembly printer, customized for Linux
- struct VISIBILITY_HIDDEN PPCLinuxAsmPrinter : public PPCAsmPrinter {
-
- DwarfWriter DW;
- MachineModuleInfo *MMI;
-
- PPCLinuxAsmPrinter(raw_ostream &O, PPCTargetMachine &TM,
- const TargetAsmInfo *T)
- : PPCAsmPrinter(O, TM, T), DW(O, this, T), MMI(0) {
- }
+ class VISIBILITY_HIDDEN PPCLinuxAsmPrinter : public PPCAsmPrinter {
+ public:
+ explicit PPCLinuxAsmPrinter(formatted_raw_ostream &O, TargetMachine &TM,
+ const TargetAsmInfo *T, bool V)
+ : PPCAsmPrinter(O, TM, T, V){}
virtual const char *getPassName() const {
return "Linux PPC Assembly Printer";
}
bool runOnMachineFunction(MachineFunction &F);
- bool doInitialization(Module &M);
bool doFinalization(Module &M);
void getAnalysisUsage(AnalysisUsage &AU) const {
AU.setPreservesAll();
AU.addRequired<MachineModuleInfo>();
+ AU.addRequired<DwarfWriter>();
PPCAsmPrinter::getAnalysisUsage(AU);
}
/// PPCDarwinAsmPrinter - PowerPC assembly printer, customized for Darwin/Mac
/// OS X
- struct VISIBILITY_HIDDEN PPCDarwinAsmPrinter : public PPCAsmPrinter {
-
- DwarfWriter DW;
- MachineModuleInfo *MMI;
-
- PPCDarwinAsmPrinter(raw_ostream &O, PPCTargetMachine &TM,
- const TargetAsmInfo *T)
- : PPCAsmPrinter(O, TM, T), DW(O, this, T), MMI(0) {
- }
+ class VISIBILITY_HIDDEN PPCDarwinAsmPrinter : public PPCAsmPrinter {
+ formatted_raw_ostream &OS;
+ public:
+ explicit PPCDarwinAsmPrinter(formatted_raw_ostream &O, TargetMachine &TM,
+ const TargetAsmInfo *T, bool V)
+ : PPCAsmPrinter(O, TM, T, V), OS(O) {}
virtual const char *getPassName() const {
return "Darwin PPC Assembly Printer";
void getAnalysisUsage(AnalysisUsage &AU) const {
AU.setPreservesAll();
AU.addRequired<MachineModuleInfo>();
+ AU.addRequired<DwarfWriter>();
PPCAsmPrinter::getAnalysisUsage(AU);
}
void PPCAsmPrinter::printOp(const MachineOperand &MO) {
switch (MO.getType()) {
case MachineOperand::MO_Immediate:
- cerr << "printOp() does not handle immediate values\n";
- abort();
- return;
+ llvm_unreachable("printOp() does not handle immediate values");
case MachineOperand::MO_MachineBasicBlock:
printBasicBlockLabel(MO.getMBB());
O << TAI->getPrivateGlobalPrefix() << "CPI" << getFunctionNumber()
<< '_' << MO.getIndex();
return;
- case MachineOperand::MO_ExternalSymbol:
+ case MachineOperand::MO_ExternalSymbol: {
// Computing the address of an external symbol, not calling it.
+ std::string Name(TAI->getGlobalPrefix());
+ Name += MO.getSymbolName();
+
if (TM.getRelocationModel() != Reloc::Static) {
- std::string Name(TAI->getGlobalPrefix()); Name += MO.getSymbolName();
- GVStubs.insert(Name);
- printSuffixedName(Name, "$non_lazy_ptr");
- return;
+ GVStubs[Name] = Name+"$non_lazy_ptr";
+ Name += "$non_lazy_ptr";
}
- O << TAI->getGlobalPrefix() << MO.getSymbolName();
+ O << Name;
return;
+ }
case MachineOperand::MO_GlobalAddress: {
// Computing the address of a global symbol, not calling it.
GlobalValue *GV = MO.getGlobal();
- std::string Name = Mang->getValueName(GV);
+ std::string Name;
// External or weakly linked global variables need non-lazily-resolved stubs
- if (TM.getRelocationModel() != Reloc::Static) {
- if (((GV->isDeclaration() || GV->hasWeakLinkage() ||
- GV->hasLinkOnceLinkage() || GV->hasCommonLinkage()))) {
- GVStubs.insert(Name);
- printSuffixedName(Name, "$non_lazy_ptr");
- if (GV->hasExternalWeakLinkage())
- ExtWeakSymbols.insert(GV);
- return;
+ if (TM.getRelocationModel() != Reloc::Static &&
+ (GV->isDeclaration() || GV->isWeakForLinker())) {
+ if (!GV->hasHiddenVisibility()) {
+ Name = Mang->getMangledName(GV, "$non_lazy_ptr", true);
+ GVStubs[Mang->getMangledName(GV)] = Name;
+ } else if (GV->isDeclaration() || GV->hasCommonLinkage() ||
+ GV->hasAvailableExternallyLinkage()) {
+ Name = Mang->getMangledName(GV, "$non_lazy_ptr", true);
+ HiddenGVStubs[Mang->getMangledName(GV)] = Name;
+ } else {
+ Name = Mang->getMangledName(GV);
}
+ } else {
+ Name = Mang->getMangledName(GV);
}
O << Name;
- if (MO.getOffset() > 0)
- O << "+" << MO.getOffset();
- else if (MO.getOffset() < 0)
- O << MO.getOffset();
-
- if (GV->hasExternalWeakLinkage())
- ExtWeakSymbols.insert(GV);
+ printOffset(MO.getOffset());
return;
}
/// EmitExternalGlobal - In this case we need to use the indirect symbol.
///
void PPCAsmPrinter::EmitExternalGlobal(const GlobalVariable *GV) {
- std::string Name = getGlobalLinkName(GV);
+ std::string Name;
+
if (TM.getRelocationModel() != Reloc::Static) {
- GVStubs.insert(Name);
- printSuffixedName(Name, "$non_lazy_ptr");
- return;
+ Name = Mang->getMangledName(GV, "$non_lazy_ptr", true);
+ } else {
+ Name = Mang->getMangledName(GV);
}
O << Name;
}
return false;
case 'L': // Write second word of DImode reference.
// Verify that this operand has two consecutive registers.
- if (!MI->getOperand(OpNo).isRegister() ||
+ if (!MI->getOperand(OpNo).isReg() ||
OpNo+1 == MI->getNumOperands() ||
- !MI->getOperand(OpNo+1).isRegister())
+ !MI->getOperand(OpNo+1).isReg())
return true;
++OpNo; // Return the high-part.
break;
case 'I':
// Write 'i' if an integer constant, otherwise nothing. Used to print
// addi vs add, etc.
- if (MI->getOperand(OpNo).isImmediate())
+ if (MI->getOperand(OpNo).isImm())
O << "i";
return false;
}
const char *ExtraCode) {
if (ExtraCode && ExtraCode[0])
return true; // Unknown modifier.
- if (MI->getOperand(OpNo).isRegister())
+ if (MI->getOperand(OpNo).isReg())
printMemRegReg(MI, OpNo);
else
printMemRegImm(MI, OpNo);
if (printInstruction(MI))
return; // Printer was automatically generated
- assert(0 && "Unhandled instruction in asm writer!");
- abort();
- return;
+ llvm_unreachable("Unhandled instruction in asm writer!");
}
/// runOnMachineFunction - This uses the printMachineInstruction()
/// method to print assembly for each instruction.
///
bool PPCLinuxAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
+ this->MF = &MF;
SetupMachineFunction(MF);
O << "\n\n";
SwitchToSection(TAI->SectionForGlobal(F));
switch (F->getLinkage()) {
- default: assert(0 && "Unknown linkage type!");
+ default: llvm_unreachable("Unknown linkage type!");
+ case Function::PrivateLinkage:
case Function::InternalLinkage: // Symbols default to internal.
break;
case Function::ExternalLinkage:
O << "\t.global\t" << CurrentFnName << '\n'
<< "\t.type\t" << CurrentFnName << ", @function\n";
break;
- case Function::WeakLinkage:
- case Function::LinkOnceLinkage:
+ case Function::WeakAnyLinkage:
+ case Function::WeakODRLinkage:
+ case Function::LinkOnceAnyLinkage:
+ case Function::LinkOnceODRLinkage:
O << "\t.global\t" << CurrentFnName << '\n';
O << "\t.weak\t" << CurrentFnName << '\n';
break;
printVisibility(CurrentFnName, F->getVisibility());
- EmitAlignment(2, F);
+ EmitAlignment(MF.getAlignment(), F);
O << CurrentFnName << ":\n";
// Emit pre-function debug information.
- DW.BeginFunction(&MF);
+ DW->BeginFunction(&MF);
// Print out code for the function.
for (MachineFunction::const_iterator I = MF.begin(), E = MF.end();
// Print out jump tables referenced by the function.
EmitJumpTableInfo(MF.getJumpTableInfo(), MF);
+ SwitchToSection(TAI->SectionForGlobal(F));
+
// Emit post-function debug information.
- DW.EndFunction(&MF);
+ DW->EndFunction(&MF);
+
+ O.flush();
// We didn't modify anything.
return false;
}
-bool PPCLinuxAsmPrinter::doInitialization(Module &M) {
- bool Result = AsmPrinter::doInitialization(M);
-
- // Emit initial debug information.
- DW.BeginModule(&M);
-
- // AsmPrinter::doInitialization should have done this analysis.
- MMI = getAnalysisToUpdate<MachineModuleInfo>();
- assert(MMI);
- DW.SetModuleInfo(MMI);
-
- // GNU as handles section names wrapped in quotes
- Mang->setUseQuotes(true);
-
- SwitchToSection(TAI->getTextSection());
-
- return Result;
-}
-
/// PrintUnmangledNameSafely - Print out the printable characters in the name.
-/// Don't print things like \n or \0.
-static void PrintUnmangledNameSafely(const Value *V, raw_ostream &OS) {
+/// Don't print things like \\n or \\0.
+static void PrintUnmangledNameSafely(const Value *V, formatted_raw_ostream &OS) {
for (const char *Name = V->getNameStart(), *E = Name+V->getNameLen();
Name != E; ++Name)
if (isprint(*Name))
if (EmitSpecialLLVMGlobal(GVar))
return;
- std::string name = Mang->getValueName(GVar);
+ std::string name = Mang->getMangledName(GVar);
printVisibility(name, GVar->getVisibility());
Constant *C = GVar->getInitializer();
+ if (isa<MDNode>(C) || isa<MDString>(C))
+ return;
const Type *Type = C->getType();
- unsigned Size = TD->getABITypeSize(Type);
+ unsigned Size = TD->getTypeAllocSize(Type);
unsigned Align = TD->getPreferredAlignmentLog(GVar);
SwitchToSection(TAI->SectionForGlobal(GVar));
if (C->isNullValue() && /* FIXME: Verify correct */
!GVar->hasSection() &&
- (GVar->hasInternalLinkage() || GVar->hasExternalLinkage() ||
- GVar->mayBeOverridden())) {
+ (GVar->hasLocalLinkage() || GVar->hasExternalLinkage() ||
+ GVar->isWeakForLinker())) {
if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it.
if (GVar->hasExternalLinkage()) {
O << "\t.type " << name << ", @object\n";
O << name << ":\n";
O << "\t.zero " << Size << '\n';
- } else if (GVar->hasInternalLinkage()) {
+ } else if (GVar->hasLocalLinkage()) {
O << TAI->getLCOMMDirective() << name << ',' << Size;
} else {
O << ".comm " << name << ',' << Size;
}
- O << "\t\t" << TAI->getCommentString() << " '";
- PrintUnmangledNameSafely(GVar, O);
- O << "'\n";
+ if (VerboseAsm) {
+ O << "\t\t" << TAI->getCommentString() << " '";
+ PrintUnmangledNameSafely(GVar, O);
+ O << "'";
+ }
+ O << '\n';
return;
}
switch (GVar->getLinkage()) {
- case GlobalValue::LinkOnceLinkage:
- case GlobalValue::WeakLinkage:
+ 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.type " << name << ", @object\n";
// FALL THROUGH
case GlobalValue::InternalLinkage:
+ case GlobalValue::PrivateLinkage:
break;
default:
- cerr << "Unknown linkage type!";
- abort();
+ llvm_unreachable("Unknown linkage type!");
}
EmitAlignment(Align, GVar);
- O << name << ":\t\t\t\t" << TAI->getCommentString() << " '";
- PrintUnmangledNameSafely(GVar, O);
- O << "'\n";
-
- // If the initializer is a extern weak symbol, remember to emit the weak
- // reference!
- if (const GlobalValue *GV = dyn_cast<GlobalValue>(C))
- if (GV->hasExternalWeakLinkage())
- ExtWeakSymbols.insert(GV);
+ O << name << ":";
+ if (VerboseAsm) {
+ O << "\t\t\t\t" << TAI->getCommentString() << " '";
+ PrintUnmangledNameSafely(GVar, O);
+ O << "'";
+ }
+ O << '\n';
EmitGlobalConstant(C);
O << '\n';
I != E; ++I)
printModuleLevelGV(I);
- // TODO
-
- // Emit initial debug information.
- DW.EndModule();
-
return AsmPrinter::doFinalization(M);
}
/// method to print assembly for each instruction.
///
bool PPCDarwinAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
+ this->MF = &MF;
+
SetupMachineFunction(MF);
O << "\n\n";
SwitchToSection(TAI->SectionForGlobal(F));
switch (F->getLinkage()) {
- default: assert(0 && "Unknown linkage type!");
+ default: llvm_unreachable("Unknown linkage type!");
+ case Function::PrivateLinkage:
case Function::InternalLinkage: // Symbols default to internal.
break;
case Function::ExternalLinkage:
O << "\t.globl\t" << CurrentFnName << '\n';
break;
- case Function::WeakLinkage:
- case Function::LinkOnceLinkage:
+ case Function::WeakAnyLinkage:
+ case Function::WeakODRLinkage:
+ case Function::LinkOnceAnyLinkage:
+ case Function::LinkOnceODRLinkage:
O << "\t.globl\t" << CurrentFnName << '\n';
O << "\t.weak_definition\t" << CurrentFnName << '\n';
break;
printVisibility(CurrentFnName, F->getVisibility());
- EmitAlignment(F->hasFnAttr(Attribute::OptimizeForSize) ? 2 : 4, F);
+ EmitAlignment(MF.getAlignment(), F);
O << CurrentFnName << ":\n";
// Emit pre-function debug information.
- DW.BeginFunction(&MF);
+ DW->BeginFunction(&MF);
// If the function is empty, then we need to emit *something*. Otherwise, the
// function's label might be associated with something that it wasn't meant to
I != E; ++I) {
// Print a label for the basic block.
if (I != MF.begin()) {
- printBasicBlockLabel(I, true, true);
+ printBasicBlockLabel(I, true, true, VerboseAsm);
O << '\n';
}
for (MachineBasicBlock::const_iterator II = I->begin(), IE = I->end();
EmitJumpTableInfo(MF.getJumpTableInfo(), MF);
// Emit post-function debug information.
- DW.EndFunction(&MF);
+ DW->EndFunction(&MF);
// We didn't modify anything.
return false;
O << "\t.machine " << CPUDirectives[Directive] << '\n';
bool Result = AsmPrinter::doInitialization(M);
-
- // Emit initial debug information.
- DW.BeginModule(&M);
-
- // We need this for Personality functions.
- // AsmPrinter::doInitialization should have done this analysis.
- MMI = getAnalysisToUpdate<MachineModuleInfo>();
assert(MMI);
- DW.SetModuleInfo(MMI);
-
- // Darwin wants symbols to be quoted if they have complex names.
- Mang->setUseQuotes(true);
// Prime text sections so they are adjacent. This reduces the likelihood a
// large data or debug section causes a branch to exceed 16M limit.
return;
}
- std::string name = Mang->getValueName(GVar);
-
+ std::string name = Mang->getMangledName(GVar);
printVisibility(name, GVar->getVisibility());
Constant *C = GVar->getInitializer();
const Type *Type = C->getType();
- unsigned Size = TD->getABITypeSize(Type);
+ unsigned Size = TD->getTypeAllocSize(Type);
unsigned Align = TD->getPreferredAlignmentLog(GVar);
SwitchToSection(TAI->SectionForGlobal(GVar));
if (C->isNullValue() && /* FIXME: Verify correct */
!GVar->hasSection() &&
- (GVar->hasInternalLinkage() || GVar->hasExternalLinkage() ||
- GVar->mayBeOverridden())) {
+ (GVar->hasLocalLinkage() || GVar->hasExternalLinkage() ||
+ GVar->isWeakForLinker()) &&
+ TAI->SectionKindForGlobal(GVar) != SectionKind::RODataMergeStr) {
if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it.
if (GVar->hasExternalLinkage()) {
O << "\t.globl " << name << '\n';
O << "\t.zerofill __DATA, __common, " << name << ", "
<< Size << ", " << Align;
- } else if (GVar->hasInternalLinkage()) {
+ } else if (GVar->hasLocalLinkage()) {
O << TAI->getLCOMMDirective() << name << ',' << Size << ',' << Align;
} else if (!GVar->hasCommonLinkage()) {
O << "\t.globl " << name << '\n'
<< TAI->getWeakDefDirective() << name << '\n';
EmitAlignment(Align, GVar);
- O << name << ":\t\t\t\t" << TAI->getCommentString() << " ";
- PrintUnmangledNameSafely(GVar, O);
+ O << name << ":";
+ if (VerboseAsm) {
+ O << "\t\t\t\t" << TAI->getCommentString() << " ";
+ PrintUnmangledNameSafely(GVar, O);
+ }
O << '\n';
EmitGlobalConstant(C);
return;
if (Subtarget.isDarwin9())
O << ',' << Align;
}
- O << "\t\t" << TAI->getCommentString() << " '";
- PrintUnmangledNameSafely(GVar, O);
- O << "'\n";
+ if (VerboseAsm) {
+ O << "\t\t" << TAI->getCommentString() << " '";
+ PrintUnmangledNameSafely(GVar, O);
+ O << "'";
+ }
+ O << '\n';
return;
}
switch (GVar->getLinkage()) {
- case GlobalValue::LinkOnceLinkage:
- case GlobalValue::WeakLinkage:
+ case GlobalValue::LinkOnceAnyLinkage:
+ case GlobalValue::LinkOnceODRLinkage:
+ case GlobalValue::WeakAnyLinkage:
+ case GlobalValue::WeakODRLinkage:
case GlobalValue::CommonLinkage:
O << "\t.globl " << name << '\n'
<< "\t.weak_definition " << name << '\n';
O << "\t.globl " << name << '\n';
// FALL THROUGH
case GlobalValue::InternalLinkage:
+ case GlobalValue::PrivateLinkage:
break;
default:
- cerr << "Unknown linkage type!";
- abort();
+ llvm_unreachable("Unknown linkage type!");
}
EmitAlignment(Align, GVar);
- O << name << ":\t\t\t\t" << TAI->getCommentString() << " '";
- PrintUnmangledNameSafely(GVar, O);
- O << "'\n";
-
- // If the initializer is a extern weak symbol, remember to emit the weak
- // reference!
- if (const GlobalValue *GV = dyn_cast<GlobalValue>(C))
- if (GV->hasExternalWeakLinkage())
- ExtWeakSymbols.insert(GV);
+ O << name << ":";
+ if (VerboseAsm) {
+ O << "\t\t\t\t" << TAI->getCommentString() << " '";
+ PrintUnmangledNameSafely(GVar, O);
+ O << "'";
+ }
+ O << '\n';
EmitGlobalConstant(C);
O << '\n';
bool isPPC64 = TD->getPointerSizeInBits() == 64;
// Output stubs for dynamically-linked functions
- if (TM.getRelocationModel() == Reloc::PIC_) {
- for (std::set<std::string>::iterator i = FnStubs.begin(), e = FnStubs.end();
- i != e; ++i) {
+ if (TM.getRelocationModel() == Reloc::PIC_ && !FnStubs.empty()) {
+ for (StringMap<FnStubInfo>::iterator I = FnStubs.begin(), E = FnStubs.end();
+ I != E; ++I) {
SwitchToTextSection("\t.section __TEXT,__picsymbolstub1,symbol_stubs,"
"pure_instructions,32");
EmitAlignment(4);
- std::string p = *i;
- std::string L0p = (p[0]=='\"') ? "\"L0$" + p.substr(1) : "L0$" + p ;
- printSuffixedName(p, "$stub");
- O << ":\n";
- O << "\t.indirect_symbol " << *i << '\n';
+ const FnStubInfo &Info = I->second;
+ O << Info.Stub << ":\n";
+ O << "\t.indirect_symbol " << I->getKeyData() << '\n';
O << "\tmflr r0\n";
- O << "\tbcl 20,31," << L0p << '\n';
- O << L0p << ":\n";
+ O << "\tbcl 20,31," << Info.AnonSymbol << '\n';
+ O << Info.AnonSymbol << ":\n";
O << "\tmflr r11\n";
- O << "\taddis r11,r11,ha16(";
- printSuffixedName(p, "$lazy_ptr");
- O << "-" << L0p << ")\n";
+ O << "\taddis r11,r11,ha16(" << Info.LazyPtr << "-" << Info.AnonSymbol;
+ O << ")\n";
O << "\tmtlr r0\n";
- if (isPPC64)
- O << "\tldu r12,lo16(";
- else
- O << "\tlwzu r12,lo16(";
- printSuffixedName(p, "$lazy_ptr");
- O << "-" << L0p << ")(r11)\n";
+ O << (isPPC64 ? "\tldu" : "\tlwzu") << " r12,lo16(";
+ O << Info.LazyPtr << "-" << Info.AnonSymbol << ")(r11)\n";
O << "\tmtctr r12\n";
O << "\tbctr\n";
+
SwitchToDataSection(".lazy_symbol_pointer");
- printSuffixedName(p, "$lazy_ptr");
- O << ":\n";
- O << "\t.indirect_symbol " << *i << '\n';
- if (isPPC64)
- O << "\t.quad dyld_stub_binding_helper\n";
- else
- O << "\t.long dyld_stub_binding_helper\n";
+ O << Info.LazyPtr << ":\n";
+ O << "\t.indirect_symbol " << I->getKeyData() << '\n';
+ O << (isPPC64 ? "\t.quad" : "\t.long") << " dyld_stub_binding_helper\n";
}
- } else {
- for (std::set<std::string>::iterator i = FnStubs.begin(), e = FnStubs.end();
- i != e; ++i) {
+ } else if (!FnStubs.empty()) {
+ for (StringMap<FnStubInfo>::iterator I = FnStubs.begin(), E = FnStubs.end();
+ I != E; ++I) {
SwitchToTextSection("\t.section __TEXT,__symbol_stub1,symbol_stubs,"
"pure_instructions,16");
EmitAlignment(4);
- std::string p = *i;
- printSuffixedName(p, "$stub");
- O << ":\n";
- O << "\t.indirect_symbol " << *i << '\n';
- O << "\tlis r11,ha16(";
- printSuffixedName(p, "$lazy_ptr");
- O << ")\n";
- if (isPPC64)
- O << "\tldu r12,lo16(";
- else
- O << "\tlwzu r12,lo16(";
- printSuffixedName(p, "$lazy_ptr");
- O << ")(r11)\n";
+ const FnStubInfo &Info = I->second;
+ O << Info.Stub << ":\n";
+ O << "\t.indirect_symbol " << I->getKeyData() << '\n';
+ O << "\tlis r11,ha16(" << Info.LazyPtr << ")\n";
+ O << (isPPC64 ? "\tldu" : "\tlwzu") << " r12,lo16(";
+ O << Info.LazyPtr << ")(r11)\n";
O << "\tmtctr r12\n";
O << "\tbctr\n";
SwitchToDataSection(".lazy_symbol_pointer");
- printSuffixedName(p, "$lazy_ptr");
- O << ":\n";
- O << "\t.indirect_symbol " << *i << '\n';
- if (isPPC64)
- O << "\t.quad dyld_stub_binding_helper\n";
- else
- O << "\t.long dyld_stub_binding_helper\n";
+ O << Info.LazyPtr << ":\n";
+ O << "\t.indirect_symbol " << I->getKeyData() << '\n';
+ O << (isPPC64 ? "\t.quad" : "\t.long") << " dyld_stub_binding_helper\n";
}
}
if (TAI->doesSupportExceptionHandling() && MMI) {
// Add the (possibly multiple) personalities to the set of global values.
// Only referenced functions get into the Personalities list.
- const std::vector<Function *>& Personalities = MMI->getPersonalities();
-
+ const std::vector<Function *> &Personalities = MMI->getPersonalities();
for (std::vector<Function *>::const_iterator I = Personalities.begin(),
- E = Personalities.end(); I != E; ++I)
- if (*I) GVStubs.insert("_" + (*I)->getName());
+ E = Personalities.end(); I != E; ++I) {
+ if (*I)
+ GVStubs[Mang->getMangledName(*I)] =
+ Mang->getMangledName(*I, "$non_lazy_ptr", true);
+ }
}
// Output stubs for external and common global variables.
if (!GVStubs.empty()) {
SwitchToDataSection(".non_lazy_symbol_pointer");
- for (std::set<std::string>::iterator I = GVStubs.begin(),
+ for (StringMap<std::string>::iterator I = GVStubs.begin(),
E = GVStubs.end(); I != E; ++I) {
- std::string p = *I;
- printSuffixedName(p, "$non_lazy_ptr");
- O << ":\n";
- O << "\t.indirect_symbol " << *I << '\n';
- if (isPPC64)
- O << "\t.quad\t0\n";
- else
- O << "\t.long\t0\n";
+ O << I->second << ":\n";
+ O << "\t.indirect_symbol " << I->getKeyData() << '\n';
+ O << (isPPC64 ? "\t.quad\t0\n" : "\t.long\t0\n");
}
}
- // Emit initial debug information.
- DW.EndModule();
+ if (!HiddenGVStubs.empty()) {
+ SwitchToSection(TAI->getDataSection());
+ EmitAlignment(isPPC64 ? 3 : 2);
+ for (StringMap<std::string>::iterator I = HiddenGVStubs.begin(),
+ E = HiddenGVStubs.end(); I != E; ++I) {
+ O << I->second << ":\n";
+ O << (isPPC64 ? "\t.quad\t" : "\t.long\t") << I->getKeyData() << '\n';
+ }
+ }
// Funny Darwin hack: This flag tells the linker that no global symbols
// contain code that falls through to other global symbols (e.g. the obvious
/// for a MachineFunction to the given output stream, in a format that the
/// Darwin assembler can deal with.
///
-FunctionPass *llvm::createPPCAsmPrinterPass(raw_ostream &o,
- PPCTargetMachine &tm) {
+FunctionPass *llvm::createPPCAsmPrinterPass(formatted_raw_ostream &o,
+ TargetMachine &tm,
+ bool verbose) {
const PPCSubtarget *Subtarget = &tm.getSubtarget<PPCSubtarget>();
if (Subtarget->isDarwin()) {
- return new PPCDarwinAsmPrinter(o, tm, tm.getTargetAsmInfo());
+ return new PPCDarwinAsmPrinter(o, tm, tm.getTargetAsmInfo(), verbose);
} else {
- return new PPCLinuxAsmPrinter(o, tm, tm.getTargetAsmInfo());
+ return new PPCLinuxAsmPrinter(o, tm, tm.getTargetAsmInfo(), verbose);
}
}
-namespace {
- static struct Register {
- Register() {
- PPCTargetMachine::registerAsmPrinter(createPPCAsmPrinterPass);
- }
- } Registrator;
+// Force static initialization.
+extern "C" void LLVMInitializePowerPCAsmPrinter() {
+ extern Target ThePPC32Target;
+ TargetRegistry::RegisterAsmPrinter(ThePPC32Target, createPPCAsmPrinterPass);
+
+ extern Target ThePPC64Target;
+ TargetRegistry::RegisterAsmPrinter(ThePPC64Target, createPPCAsmPrinterPass);
}