mcize jump table and constant pool entry labels, .local on elf,

and some .weak directives.

llvm-svn: 94284
This commit is contained in:
Chris Lattner 2010-01-23 05:19:23 +00:00
parent fe796ddd5a
commit 4225a7b987
4 changed files with 54 additions and 30 deletions

View File

@ -321,6 +321,12 @@ namespace llvm {
/// block label. /// block label.
MCSymbol *GetMBBSymbol(unsigned MBBID) const; MCSymbol *GetMBBSymbol(unsigned MBBID) const;
/// GetCPISymbol - Return the symbol for the specified constant pool entry.
MCSymbol *GetCPISymbol(unsigned CPID) const;
/// GetJTISymbol - Return the symbol for the specified jump table entry.
MCSymbol *GetJTISymbol(unsigned JTID, bool isLinkerPrivate = false) const;
/// GetBlockAddressSymbol - Return the MCSymbol used to satisfy BlockAddress /// GetBlockAddressSymbol - Return the MCSymbol used to satisfy BlockAddress
/// uses of the specified basic block. /// uses of the specified basic block.
MCSymbol *GetBlockAddressSymbol(const BlockAddress *BA, MCSymbol *GetBlockAddressSymbol(const BlockAddress *BA,

View File

@ -47,6 +47,7 @@ namespace llvm {
IndirectSymbol, /// .indirect_symbol (Apple) IndirectSymbol, /// .indirect_symbol (Apple)
Internal, /// .internal (ELF) Internal, /// .internal (ELF)
LazyReference, /// .lazy_reference (Apple) LazyReference, /// .lazy_reference (Apple)
Local, /// .local (ELF)
NoDeadStrip, /// .no_dead_strip (Apple) NoDeadStrip, /// .no_dead_strip (Apple)
PrivateExtern, /// .private_extern (Apple) PrivateExtern, /// .private_extern (Apple)
Protected, /// .protected (ELF) Protected, /// .protected (ELF)

View File

@ -115,9 +115,9 @@ bool AsmPrinter::doInitialization(Module &M) {
EmitStartOfAsmFile(M); EmitStartOfAsmFile(M);
if (MAI->hasSingleParameterDotFile()) { if (MAI->hasSingleParameterDotFile()) {
/* Very minimal debug info. It is ignored if we emit actual // Very minimal debug info. It is ignored if we emit actual
debug info. If we don't, this at least helps the user find where // debug info. If we don't, this at least helps the user find where
a function came from. */ // a function came from.
O << "\t.file\t\"" << M.getModuleIdentifier() << "\"\n"; O << "\t.file\t\"" << M.getModuleIdentifier() << "\"\n";
} }
@ -197,13 +197,12 @@ void AsmPrinter::EmitGlobalVariable(const GlobalVariable *GV) {
if (const char *LComm = MAI->getLCOMMDirective()) { if (const char *LComm = MAI->getLCOMMDirective()) {
// .lcomm _foo, 42 // .lcomm _foo, 42
O << LComm << *GVSym << ',' << Size; O << LComm << *GVSym << ',' << Size << '\n';
O << '\n';
return; return;
} }
// .local _foo // .local _foo
O << "\t.local\t" << *GVSym << '\n'; OutStreamer.EmitSymbolAttribute(GVSym, MCStreamer::Local);
// .comm _foo, 42, 4 // .comm _foo, 42, 4
OutStreamer.EmitCommonSymbol(GVSym, Size, 1 << AlignLog); OutStreamer.EmitCommonSymbol(GVSym, Size, 1 << AlignLog);
return; return;
@ -302,12 +301,14 @@ bool AsmPrinter::doFinalization(Module &M) {
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();
I != E; ++I) { I != E; ++I) {
if (!I->hasExternalWeakLinkage()) continue; if (!I->hasExternalWeakLinkage()) continue;
O << MAI->getWeakRefDirective() << *GetGlobalValueSymbol(I) << '\n'; OutStreamer.EmitSymbolAttribute(GetGlobalValueSymbol(I),
MCStreamer::WeakReference);
} }
for (Module::const_iterator I = M.begin(), E = M.end(); I != E; ++I) { for (Module::const_iterator I = M.begin(), E = M.end(); I != E; ++I) {
if (!I->hasExternalWeakLinkage()) continue; if (!I->hasExternalWeakLinkage()) continue;
O << MAI->getWeakRefDirective() << *GetGlobalValueSymbol(I) << '\n'; OutStreamer.EmitSymbolAttribute(GetGlobalValueSymbol(I),
MCStreamer::WeakReference);
} }
} }
@ -321,9 +322,9 @@ bool AsmPrinter::doFinalization(Module &M) {
MCSymbol *Target = GetGlobalValueSymbol(GV); MCSymbol *Target = GetGlobalValueSymbol(GV);
if (I->hasExternalLinkage() || !MAI->getWeakRefDirective()) if (I->hasExternalLinkage() || !MAI->getWeakRefDirective())
O << "\t.globl\t" << *Name << '\n'; OutStreamer.EmitSymbolAttribute(Name, MCStreamer::Global);
else if (I->hasWeakLinkage()) else if (I->hasWeakLinkage())
O << MAI->getWeakRefDirective() << *Name << '\n'; OutStreamer.EmitSymbolAttribute(Name, MCStreamer::WeakReference);
else else
assert(I->hasLocalLinkage() && "Invalid alias linkage"); assert(I->hasLocalLinkage() && "Invalid alias linkage");
@ -343,6 +344,8 @@ bool AsmPrinter::doFinalization(Module &M) {
// to be executable. Some targets have a directive to declare this. // to be executable. Some targets have a directive to declare this.
Function *InitTrampolineIntrinsic = M.getFunction("llvm.init.trampoline"); Function *InitTrampolineIntrinsic = M.getFunction("llvm.init.trampoline");
if (!InitTrampolineIntrinsic || InitTrampolineIntrinsic->use_empty()) if (!InitTrampolineIntrinsic || InitTrampolineIntrinsic->use_empty())
// FIXME: This is actually a section switch on linux/x86 and systemz, use
// switch section.
if (MAI->getNonexecutableStackDirective()) if (MAI->getNonexecutableStackDirective())
O << MAI->getNonexecutableStackDirective() << '\n'; O << MAI->getNonexecutableStackDirective() << '\n';
@ -449,14 +452,15 @@ void AsmPrinter::EmitConstantPool(MachineConstantPool *MCP) {
const Type *Ty = CPE.getType(); const Type *Ty = CPE.getType();
Offset = NewOffset + TM.getTargetData()->getTypeAllocSize(Ty); Offset = NewOffset + TM.getTargetData()->getTypeAllocSize(Ty);
O << MAI->getPrivateGlobalPrefix() << "CPI" << getFunctionNumber() << '_' // Emit the label with a comment on it.
<< CPI << ':';
if (VerboseAsm) { if (VerboseAsm) {
O.PadToColumn(MAI->getCommentColumn()); OutStreamer.GetCommentOS() << "constant pool ";
O << MAI->getCommentString() << " constant "; WriteTypeSymbolic(OutStreamer.GetCommentOS(), CPE.getType(),
WriteTypeSymbolic(O, CPE.getType(), MF->getFunction()->getParent()); MF->getFunction()->getParent());
OutStreamer.GetCommentOS() << '\n';
} }
O << '\n'; OutStreamer.EmitLabel(GetCPISymbol(CPI));
if (CPE.isMachineConstantPoolEntry()) if (CPE.isMachineConstantPoolEntry())
EmitMachineConstantPoolValue(CPE.Val.MachineCPVal); EmitMachineConstantPoolValue(CPE.Val.MachineCPVal);
else else
@ -518,14 +522,11 @@ void AsmPrinter::EmitJumpTableInfo(MachineJumpTableInfo *MJTI,
// before each jump table. The first label is never referenced, but tells // before each jump table. The first label is never referenced, but tells
// the assembler and linker the extents of the jump table object. The // the assembler and linker the extents of the jump table object. The
// second label is actually referenced by the code. // second label is actually referenced by the code.
if (JTInDiffSection && MAI->getLinkerPrivateGlobalPrefix()[0]) { if (JTInDiffSection && MAI->getLinkerPrivateGlobalPrefix()[0])
O << MAI->getLinkerPrivateGlobalPrefix() OutStreamer.EmitLabel(GetJTISymbol(i, true));
<< "JTI" << getFunctionNumber() << '_' << i << ":\n";
} OutStreamer.EmitLabel(GetJTISymbol(i));
O << MAI->getPrivateGlobalPrefix() << "JTI" << getFunctionNumber()
<< '_' << i << ":\n";
for (unsigned ii = 0, ee = JTBBs.size(); ii != ee; ++ii) { for (unsigned ii = 0, ee = JTBBs.size(); ii != ee; ++ii) {
printPICJumpTableEntry(MJTI, JTBBs[ii], i); printPICJumpTableEntry(MJTI, JTBBs[ii], i);
O << '\n'; O << '\n';
@ -564,8 +565,7 @@ void AsmPrinter::printPICJumpTableEntry(const MachineJumpTableInfo *MJTI,
// If the arch uses custom Jump Table directives, don't calc relative to // If the arch uses custom Jump Table directives, don't calc relative to
// JT // JT
if (!HadJTEntryDirective) if (!HadJTEntryDirective)
O << '-' << MAI->getPrivateGlobalPrefix() << "JTI" O << '-' << *GetJTISymbol(uid);
<< getFunctionNumber() << '_' << uid;
} }
} }
@ -1445,7 +1445,24 @@ MCSymbol *AsmPrinter::GetMBBSymbol(unsigned MBBID) const {
SmallString<60> Name; SmallString<60> Name;
raw_svector_ostream(Name) << MAI->getPrivateGlobalPrefix() << "BB" raw_svector_ostream(Name) << MAI->getPrivateGlobalPrefix() << "BB"
<< getFunctionNumber() << '_' << MBBID; << getFunctionNumber() << '_' << MBBID;
return OutContext.GetOrCreateSymbol(Name.str());
}
/// GetCPISymbol - Return the symbol for the specified constant pool entry.
MCSymbol *AsmPrinter::GetCPISymbol(unsigned CPID) const {
SmallString<60> Name;
raw_svector_ostream(Name) << MAI->getPrivateGlobalPrefix() << "CPI"
<< getFunctionNumber() << '_' << CPID;
return OutContext.GetOrCreateSymbol(Name.str());
}
/// GetJTISymbol - Return the symbol for the specified jump table entry.
MCSymbol *AsmPrinter::GetJTISymbol(unsigned JTID, bool isLinkerPrivate) const {
const char *Prefix = isLinkerPrivate ? MAI->getLinkerPrivateGlobalPrefix() :
MAI->getPrivateGlobalPrefix();
SmallString<60> Name;
raw_svector_ostream(Name) << Prefix << "JTI" << getFunctionNumber() << '_'
<< JTID;
return OutContext.GetOrCreateSymbol(Name.str()); return OutContext.GetOrCreateSymbol(Name.str());
} }
@ -1597,8 +1614,7 @@ void AsmPrinter::printPICJumpTableSetLabel(unsigned uid,
O << MAI->getSetDirective() << ' ' << MAI->getPrivateGlobalPrefix() O << MAI->getSetDirective() << ' ' << MAI->getPrivateGlobalPrefix()
<< getFunctionNumber() << '_' << uid << "_set_" << MBB->getNumber() << ',' << getFunctionNumber() << '_' << uid << "_set_" << MBB->getNumber() << ','
<< *GetMBBSymbol(MBB->getNumber()) << *GetMBBSymbol(MBB->getNumber())
<< '-' << MAI->getPrivateGlobalPrefix() << "JTI" << getFunctionNumber() << '-' << *GetJTISymbol(uid) << '\n';
<< '_' << uid << '\n';
} }
void AsmPrinter::printPICJumpTableSetLabel(unsigned uid, unsigned uid2, void AsmPrinter::printPICJumpTableSetLabel(unsigned uid, unsigned uid2,

View File

@ -224,13 +224,14 @@ void MCAsmStreamer::EmitSymbolAttribute(MCSymbol *Symbol,
case IndirectSymbol: OS << ".indirect_symbol "; break; case IndirectSymbol: OS << ".indirect_symbol "; break;
case Internal: OS << ".internal "; break; case Internal: OS << ".internal "; break;
case LazyReference: OS << ".lazy_reference "; break; case LazyReference: OS << ".lazy_reference "; break;
case Local: OS << ".local "; break;
case NoDeadStrip: OS << ".no_dead_strip "; break; case NoDeadStrip: OS << ".no_dead_strip "; break;
case PrivateExtern: OS << ".private_extern "; break; case PrivateExtern: OS << ".private_extern "; break;
case Protected: OS << ".protected "; break; case Protected: OS << ".protected "; break;
case Reference: OS << ".reference "; break; case Reference: OS << ".reference "; break;
case Weak: OS << ".weak "; break; case Weak: OS << ".weak "; break;
case WeakDefinition: OS << ".weak_definition "; break; case WeakDefinition: OS << ".weak_definition "; break;
case WeakReference: OS << ".weak_reference "; break; case WeakReference: OS << MAI.getWeakRefDirective(); break;// .weak_reference
} }
OS << *Symbol; OS << *Symbol;