mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-09-27 15:57:13 +00:00
Switch to new section name handling facility
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@53316 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
7e7fc82cf3
commit
e87f52d722
@ -293,13 +293,16 @@ void AsmPrinter::EmitJumpTableInfo(MachineJumpTableInfo *MJTI,
|
|||||||
// the appropriate section.
|
// the appropriate section.
|
||||||
TargetLowering *LoweringInfo = TM.getTargetLowering();
|
TargetLowering *LoweringInfo = TM.getTargetLowering();
|
||||||
|
|
||||||
const char* JumpTableDataSection = TAI->getJumpTableDataSection();
|
const char* JumpTableDataSection = TAI->getJumpTableDataSection();
|
||||||
|
const Function *F = MF.getFunction();
|
||||||
|
unsigned SectionFlags = TAI->SectionFlagsForGlobal(F);
|
||||||
if ((IsPic && !(LoweringInfo && LoweringInfo->usesGlobalOffsetTable())) ||
|
if ((IsPic && !(LoweringInfo && LoweringInfo->usesGlobalOffsetTable())) ||
|
||||||
!JumpTableDataSection) {
|
!JumpTableDataSection ||
|
||||||
|
SectionFlags & SectionFlags::Linkonce) {
|
||||||
// In PIC mode, we need to emit the jump table to the same section as the
|
// In PIC mode, we need to emit the jump table to the same section as the
|
||||||
// function body itself, otherwise the label differences won't make sense.
|
// function body itself, otherwise the label differences won't make sense.
|
||||||
// We should also do if the section name is NULL.
|
// We should also do if the section name is NULL or function is declared in
|
||||||
const Function *F = MF.getFunction();
|
// discardable section.
|
||||||
SwitchToTextSection(getSectionForFunction(*F).c_str(), F);
|
SwitchToTextSection(getSectionForFunction(*F).c_str(), F);
|
||||||
} else {
|
} else {
|
||||||
SwitchToDataSection(JumpTableDataSection);
|
SwitchToDataSection(JumpTableDataSection);
|
||||||
|
@ -147,26 +147,9 @@ void X86ATTAsmPrinter::decorateName(std::string &Name,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// getSectionForFunction - Return the section that we should emit the
|
// Substitute old hook with new one temporary
|
||||||
/// specified function body into.
|
|
||||||
std::string X86ATTAsmPrinter::getSectionForFunction(const Function &F) const {
|
std::string X86ATTAsmPrinter::getSectionForFunction(const Function &F) const {
|
||||||
switch (F.getLinkage()) {
|
return TAI->SectionForGlobal(&F);
|
||||||
default: assert(0 && "Unknown linkage type!");
|
|
||||||
case Function::InternalLinkage:
|
|
||||||
case Function::DLLExportLinkage:
|
|
||||||
case Function::ExternalLinkage:
|
|
||||||
return TAI->getTextSection();
|
|
||||||
case Function::WeakLinkage:
|
|
||||||
case Function::LinkOnceLinkage:
|
|
||||||
if (Subtarget->isTargetDarwin()) {
|
|
||||||
return ".section __TEXT,__textcoal_nt,coalesced,pure_instructions";
|
|
||||||
} else if (Subtarget->isTargetCygMing()) {
|
|
||||||
return "\t.section\t.text$linkonce." + CurrentFnName + ",\"ax\"";
|
|
||||||
} else {
|
|
||||||
return "\t.section\t.llvm.linkonce.t." + CurrentFnName +
|
|
||||||
",\"ax\",@progbits";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void X86ATTAsmPrinter::emitFunctionHeader(const MachineFunction &MF) {
|
void X86ATTAsmPrinter::emitFunctionHeader(const MachineFunction &MF) {
|
||||||
@ -174,7 +157,7 @@ void X86ATTAsmPrinter::emitFunctionHeader(const MachineFunction &MF) {
|
|||||||
|
|
||||||
decorateName(CurrentFnName, F);
|
decorateName(CurrentFnName, F);
|
||||||
|
|
||||||
SwitchToTextSection(getSectionForFunction(*F).c_str(), F);
|
SwitchToTextSection(TAI->SectionForGlobal(F).c_str(), F);
|
||||||
|
|
||||||
unsigned FnAlign = OptimizeForSize ? 1 : 4;
|
unsigned FnAlign = OptimizeForSize ? 1 : 4;
|
||||||
switch (F->getLinkage()) {
|
switch (F->getLinkage()) {
|
||||||
@ -774,8 +757,7 @@ void X86ATTAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
|
|||||||
if (!GVar->hasInitializer())
|
if (!GVar->hasInitializer())
|
||||||
return; // External global require no code
|
return; // External global require no code
|
||||||
|
|
||||||
GVar->dump();
|
std::string SectionName = TAI->SectionForGlobal(GVar);
|
||||||
std::cout << TAI->SectionForGlobal(GVar) << std::endl;
|
|
||||||
|
|
||||||
// Check to see if this is a special global used by LLVM, if so, emit it.
|
// Check to see if this is a special global used by LLVM, if so, emit it.
|
||||||
if (EmitSpecialLLVMGlobal(GVar)) {
|
if (EmitSpecialLLVMGlobal(GVar)) {
|
||||||
@ -806,7 +788,10 @@ void X86ATTAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
|
|||||||
if (Subtarget->isTargetELF())
|
if (Subtarget->isTargetELF())
|
||||||
O << "\t.type\t" << name << ",@object\n";
|
O << "\t.type\t" << name << ",@object\n";
|
||||||
|
|
||||||
|
SwitchToDataSection(SectionName.c_str());
|
||||||
|
|
||||||
if (C->isNullValue() && !GVar->hasSection()) {
|
if (C->isNullValue() && !GVar->hasSection()) {
|
||||||
|
// FIXME: This seems to be pretty darwin-specific
|
||||||
if (GVar->hasExternalLinkage()) {
|
if (GVar->hasExternalLinkage()) {
|
||||||
if (const char *Directive = TAI->getZeroFillDirective()) {
|
if (const char *Directive = TAI->getZeroFillDirective()) {
|
||||||
O << "\t.globl " << name << '\n';
|
O << "\t.globl " << name << '\n';
|
||||||
@ -820,10 +805,7 @@ void X86ATTAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
|
|||||||
(GVar->hasInternalLinkage() || GVar->hasWeakLinkage() ||
|
(GVar->hasInternalLinkage() || GVar->hasWeakLinkage() ||
|
||||||
GVar->hasLinkOnceLinkage() || GVar->hasCommonLinkage())) {
|
GVar->hasLinkOnceLinkage() || GVar->hasCommonLinkage())) {
|
||||||
if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it.
|
if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it.
|
||||||
if (!NoZerosInBSS && TAI->getBSSSection())
|
|
||||||
SwitchToDataSection(TAI->getBSSSection(), GVar);
|
|
||||||
else
|
|
||||||
SwitchToDataSection(TAI->getDataSection(), GVar);
|
|
||||||
if (TAI->getLCOMMDirective() != NULL) {
|
if (TAI->getLCOMMDirective() != NULL) {
|
||||||
if (GVar->hasInternalLinkage()) {
|
if (GVar->hasInternalLinkage()) {
|
||||||
O << TAI->getLCOMMDirective() << name << ',' << Size;
|
O << TAI->getLCOMMDirective() << name << ',' << Size;
|
||||||
@ -832,7 +814,6 @@ void X86ATTAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
|
|||||||
} else if (Subtarget->isTargetDarwin() && !GVar->hasCommonLinkage()) {
|
} else if (Subtarget->isTargetDarwin() && !GVar->hasCommonLinkage()) {
|
||||||
O << "\t.globl " << name << '\n'
|
O << "\t.globl " << name << '\n'
|
||||||
<< TAI->getWeakDefDirective() << name << '\n';
|
<< TAI->getWeakDefDirective() << name << '\n';
|
||||||
SwitchToDataSection("\t.section __DATA,__datacoal_nt,coalesced", GVar);
|
|
||||||
EmitAlignment(Align, GVar);
|
EmitAlignment(Align, GVar);
|
||||||
O << name << ":\t\t\t\t" << TAI->getCommentString() << ' ';
|
O << name << ":\t\t\t\t" << TAI->getCommentString() << ' ';
|
||||||
PrintUnmangledNameSafely(GVar, O);
|
PrintUnmangledNameSafely(GVar, O);
|
||||||
@ -869,27 +850,10 @@ void X86ATTAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
|
|||||||
if (Subtarget->isTargetDarwin()) {
|
if (Subtarget->isTargetDarwin()) {
|
||||||
O << "\t.globl " << name << '\n'
|
O << "\t.globl " << name << '\n'
|
||||||
<< TAI->getWeakDefDirective() << name << '\n';
|
<< TAI->getWeakDefDirective() << name << '\n';
|
||||||
if (!GVar->isConstant())
|
|
||||||
SwitchToDataSection("\t.section __DATA,__datacoal_nt,coalesced", GVar);
|
|
||||||
else {
|
|
||||||
const ArrayType *AT = dyn_cast<ArrayType>(Type);
|
|
||||||
if (AT && AT->getElementType()==Type::Int8Ty)
|
|
||||||
SwitchToDataSection("\t.section __TEXT,__const_coal,coalesced", GVar);
|
|
||||||
else
|
|
||||||
SwitchToDataSection("\t.section __DATA,__const_coal,coalesced", GVar);
|
|
||||||
}
|
|
||||||
} else if (Subtarget->isTargetCygMing()) {
|
} else if (Subtarget->isTargetCygMing()) {
|
||||||
std::string SectionName(".section\t.data$linkonce." +
|
|
||||||
name +
|
|
||||||
",\"aw\"");
|
|
||||||
SwitchToDataSection(SectionName.c_str(), GVar);
|
|
||||||
O << "\t.globl\t" << name << "\n"
|
O << "\t.globl\t" << name << "\n"
|
||||||
"\t.linkonce same_size\n";
|
"\t.linkonce same_size\n";
|
||||||
} else {
|
} else {
|
||||||
std::string SectionName("\t.section\t.llvm.linkonce.d." +
|
|
||||||
name +
|
|
||||||
",\"aw\",@progbits");
|
|
||||||
SwitchToDataSection(SectionName.c_str(), GVar);
|
|
||||||
O << "\t.weak\t" << name << '\n';
|
O << "\t.weak\t" << name << '\n';
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -901,64 +865,8 @@ void X86ATTAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
|
|||||||
// If external or appending, declare as a global symbol
|
// If external or appending, declare as a global symbol
|
||||||
O << "\t.globl " << name << '\n';
|
O << "\t.globl " << name << '\n';
|
||||||
// FALL THROUGH
|
// FALL THROUGH
|
||||||
case GlobalValue::InternalLinkage: {
|
case GlobalValue::InternalLinkage:
|
||||||
if (GVar->isConstant()) {
|
|
||||||
const ConstantArray *CVA = dyn_cast<ConstantArray>(C);
|
|
||||||
if (TAI->getCStringSection() && CVA && CVA->isCString()) {
|
|
||||||
SwitchToDataSection(TAI->getCStringSection(), GVar);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// FIXME: special handling for ".ctors" & ".dtors" sections
|
|
||||||
if (GVar->hasSection() &&
|
|
||||||
(GVar->getSection() == ".ctors" || GVar->getSection() == ".dtors")) {
|
|
||||||
std::string SectionName = ".section " + GVar->getSection();
|
|
||||||
|
|
||||||
if (Subtarget->isTargetCygMing()) {
|
|
||||||
SectionName += ",\"aw\"";
|
|
||||||
} else {
|
|
||||||
assert(!Subtarget->isTargetDarwin());
|
|
||||||
SectionName += ",\"aw\",@progbits";
|
|
||||||
}
|
|
||||||
SwitchToDataSection(SectionName.c_str());
|
|
||||||
} else if (GVar->hasSection() && Subtarget->isTargetDarwin()) {
|
|
||||||
// Honor all section names on Darwin; ObjC uses this
|
|
||||||
std::string SectionName = ".section " + GVar->getSection();
|
|
||||||
SwitchToDataSection(SectionName.c_str());
|
|
||||||
} else {
|
|
||||||
if (C->isNullValue() && !NoZerosInBSS && TAI->getBSSSection())
|
|
||||||
SwitchToDataSection(GVar->isThreadLocal() ? TAI->getTLSBSSSection() :
|
|
||||||
TAI->getBSSSection(), GVar);
|
|
||||||
else if (!GVar->isConstant())
|
|
||||||
SwitchToDataSection(GVar->isThreadLocal() ? TAI->getTLSDataSection() :
|
|
||||||
TAI->getDataSection(), GVar);
|
|
||||||
else if (GVar->isThreadLocal())
|
|
||||||
SwitchToDataSection(TAI->getTLSDataSection());
|
|
||||||
else {
|
|
||||||
// Read-only data.
|
|
||||||
bool HasReloc = C->ContainsRelocations();
|
|
||||||
if (HasReloc &&
|
|
||||||
Subtarget->isTargetDarwin() &&
|
|
||||||
TM.getRelocationModel() != Reloc::Static)
|
|
||||||
SwitchToDataSection("\t.const_data\n");
|
|
||||||
else if (!HasReloc && Size == 4 &&
|
|
||||||
TAI->getFourByteConstantSection())
|
|
||||||
SwitchToDataSection(TAI->getFourByteConstantSection(), GVar);
|
|
||||||
else if (!HasReloc && Size == 8 &&
|
|
||||||
TAI->getEightByteConstantSection())
|
|
||||||
SwitchToDataSection(TAI->getEightByteConstantSection(), GVar);
|
|
||||||
else if (!HasReloc && Size == 16 &&
|
|
||||||
TAI->getSixteenByteConstantSection())
|
|
||||||
SwitchToDataSection(TAI->getSixteenByteConstantSection(), GVar);
|
|
||||||
else if (TAI->getReadOnlySection())
|
|
||||||
SwitchToDataSection(TAI->getReadOnlySection(), GVar);
|
|
||||||
else
|
|
||||||
SwitchToDataSection(TAI->getDataSection(), GVar);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
default:
|
default:
|
||||||
assert(0 && "Unknown linkage type!");
|
assert(0 && "Unknown linkage type!");
|
||||||
}
|
}
|
||||||
|
@ -47,7 +47,8 @@ bool X86Subtarget::GVRequiresExtraLoad(const GlobalValue* GV,
|
|||||||
// Extra load is needed for all externally visible.
|
// Extra load is needed for all externally visible.
|
||||||
if (isDirectCall)
|
if (isDirectCall)
|
||||||
return false;
|
return false;
|
||||||
if (GV->hasInternalLinkage() || GV->hasHiddenVisibility())
|
if (GV->hasInternalLinkage() ||
|
||||||
|
(GV->hasHiddenVisibility() && !GV->isDeclaration()))
|
||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
} else if (isTargetCygMing() || isTargetWindows()) {
|
} else if (isTargetCygMing() || isTargetWindows()) {
|
||||||
|
Loading…
Reference in New Issue
Block a user