mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-08-17 21:29:20 +00:00
Switch ARM to new section handling stuff
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@54458 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
79579c911f
commit
0f3cc65738
@ -113,12 +113,17 @@ namespace {
|
||||
virtual bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
|
||||
unsigned AsmVariant, const char *ExtraCode);
|
||||
|
||||
void printModuleLevelGV(const GlobalVariable* GVar);
|
||||
bool printInstruction(const MachineInstr *MI); // autogenerated.
|
||||
void printMachineInstruction(const MachineInstr *MI);
|
||||
bool runOnMachineFunction(MachineFunction &F);
|
||||
bool doInitialization(Module &M);
|
||||
bool doFinalization(Module &M);
|
||||
|
||||
/// getSectionForFunction - Return the section that we should emit the
|
||||
/// specified function body into.
|
||||
virtual std::string getSectionForFunction(const Function &F) const;
|
||||
|
||||
virtual void EmitMachineConstantPoolValue(MachineConstantPoolValue *MCPV) {
|
||||
printDataDirective(MCPV->getType());
|
||||
|
||||
@ -172,6 +177,11 @@ FunctionPass *llvm::createARMCodePrinterPass(std::ostream &o,
|
||||
return new ARMAsmPrinter(o, tm, tm.getTargetAsmInfo());
|
||||
}
|
||||
|
||||
// Substitute old hook with new one temporary
|
||||
std::string ARMAsmPrinter::getSectionForFunction(const Function &F) const {
|
||||
return TAI->SectionForGlobal(&F);
|
||||
}
|
||||
|
||||
/// runOnMachineFunction - This uses the printInstruction()
|
||||
/// method to print assembly for each instruction.
|
||||
///
|
||||
@ -821,35 +831,36 @@ static void PrintUnmangledNameSafely(const Value *V, std::ostream &OS) {
|
||||
OS << *Name;
|
||||
}
|
||||
|
||||
bool ARMAsmPrinter::doFinalization(Module &M) {
|
||||
void ARMAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
|
||||
const TargetData *TD = TM.getTargetData();
|
||||
|
||||
for (Module::const_global_iterator I = M.global_begin(), E = M.global_end();
|
||||
I != E; ++I) {
|
||||
if (!I->hasInitializer()) // External global require no code
|
||||
continue;
|
||||
if (!GVar->hasInitializer()) // External global require no code
|
||||
return;
|
||||
|
||||
if (EmitSpecialLLVMGlobal(I)) {
|
||||
// Check to see if this is a special global used by LLVM, if so, emit it.
|
||||
|
||||
if (EmitSpecialLLVMGlobal(GVar)) {
|
||||
if (Subtarget->isTargetDarwin() &&
|
||||
TM.getRelocationModel() == Reloc::Static) {
|
||||
if (I->getName() == "llvm.global_ctors")
|
||||
if (GVar->getName() == "llvm.global_ctors")
|
||||
O << ".reference .constructors_used\n";
|
||||
else if (I->getName() == "llvm.global_dtors")
|
||||
else if (GVar->getName() == "llvm.global_dtors")
|
||||
O << ".reference .destructors_used\n";
|
||||
}
|
||||
continue;
|
||||
return;
|
||||
}
|
||||
|
||||
std::string name = Mang->getValueName(I);
|
||||
Constant *C = I->getInitializer();
|
||||
std::string SectionName = TAI->SectionForGlobal(GVar);
|
||||
std::string name = Mang->getValueName(GVar);
|
||||
Constant *C = GVar->getInitializer();
|
||||
const Type *Type = C->getType();
|
||||
unsigned Size = TD->getABITypeSize(Type);
|
||||
unsigned Align = TD->getPreferredAlignmentLog(I);
|
||||
unsigned Align = TD->getPreferredAlignmentLog(GVar);
|
||||
|
||||
const char *VisibilityDirective = NULL;
|
||||
if (I->hasHiddenVisibility())
|
||||
if (GVar->hasHiddenVisibility())
|
||||
VisibilityDirective = TAI->getHiddenDirective();
|
||||
else if (I->hasProtectedVisibility())
|
||||
else if (GVar->hasProtectedVisibility())
|
||||
VisibilityDirective = TAI->getProtectedDirective();
|
||||
|
||||
if (VisibilityDirective)
|
||||
@ -858,56 +869,51 @@ bool ARMAsmPrinter::doFinalization(Module &M) {
|
||||
if (Subtarget->isTargetELF())
|
||||
O << "\t.type " << name << ",%object\n";
|
||||
|
||||
if (C->isNullValue() && !I->hasSection() && !I->isThreadLocal()) {
|
||||
if (I->hasExternalLinkage()) {
|
||||
SwitchToDataSection(SectionName.c_str());
|
||||
|
||||
if (C->isNullValue() && !GVar->hasSection() && !GVar->isThreadLocal()) {
|
||||
// FIXME: This seems to be pretty darwin-specific
|
||||
|
||||
if (GVar->hasExternalLinkage()) {
|
||||
if (const char *Directive = TAI->getZeroFillDirective()) {
|
||||
O << "\t.globl\t" << name << "\n";
|
||||
O << Directive << "__DATA, __common, " << name << ", "
|
||||
<< Size << ", " << Align << "\n";
|
||||
continue;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (I->hasInternalLinkage() || I->hasWeakLinkage() ||
|
||||
I->hasLinkOnceLinkage()) {
|
||||
if (GVar->hasInternalLinkage() || GVar->isWeakForLinker()) {
|
||||
if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it.
|
||||
if (!NoZerosInBSS && TAI->getBSSSection())
|
||||
SwitchToDataSection(TAI->getBSSSection(), I);
|
||||
else
|
||||
SwitchToDataSection(TAI->getDataSection(), I);
|
||||
|
||||
if (TAI->getLCOMMDirective() != NULL) {
|
||||
if (I->hasInternalLinkage()) {
|
||||
if (GVar->hasInternalLinkage()) {
|
||||
O << TAI->getLCOMMDirective() << name << "," << Size;
|
||||
if (Subtarget->isTargetDarwin())
|
||||
O << "," << Align;
|
||||
} else
|
||||
O << TAI->getCOMMDirective() << name << "," << Size;
|
||||
} else {
|
||||
if (I->hasInternalLinkage())
|
||||
if (GVar->hasInternalLinkage())
|
||||
O << "\t.local\t" << name << "\n";
|
||||
O << TAI->getCOMMDirective() << name << "," << Size;
|
||||
if (TAI->getCOMMDirectiveTakesAlignment())
|
||||
O << "," << (TAI->getAlignmentIsInBytes() ? (1 << Align) : Align);
|
||||
}
|
||||
O << "\t\t" << TAI->getCommentString() << " ";
|
||||
PrintUnmangledNameSafely(I, O);
|
||||
PrintUnmangledNameSafely(GVar, O);
|
||||
O << "\n";
|
||||
continue;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
switch (I->getLinkage()) {
|
||||
switch (GVar->getLinkage()) {
|
||||
case GlobalValue::LinkOnceLinkage:
|
||||
case GlobalValue::WeakLinkage:
|
||||
if (Subtarget->isTargetDarwin()) {
|
||||
O << "\t.globl " << name << "\n"
|
||||
<< "\t.weak_definition " << name << "\n";
|
||||
SwitchToDataSection("\t.section __DATA,__datacoal_nt,coalesced", I);
|
||||
} else {
|
||||
std::string SectionName("\t.section\t.llvm.linkonce.d." +
|
||||
name +
|
||||
",\"aw\",%progbits");
|
||||
SwitchToDataSection(SectionName.c_str(), I);
|
||||
O << "\t.weak " << name << "\n";
|
||||
}
|
||||
break;
|
||||
@ -917,71 +923,20 @@ bool ARMAsmPrinter::doFinalization(Module &M) {
|
||||
case GlobalValue::ExternalLinkage:
|
||||
O << "\t.globl " << name << "\n";
|
||||
// FALL THROUGH
|
||||
case GlobalValue::InternalLinkage: {
|
||||
if (I->isConstant()) {
|
||||
const ConstantArray *CVA = dyn_cast<ConstantArray>(C);
|
||||
if (TAI->getCStringSection() && CVA && CVA->isCString()) {
|
||||
SwitchToDataSection(TAI->getCStringSection(), I);
|
||||
case GlobalValue::InternalLinkage:
|
||||
break;
|
||||
}
|
||||
}
|
||||
// FIXME: special handling for ".ctors" & ".dtors" sections
|
||||
if (I->hasSection() &&
|
||||
(I->getSection() == ".ctors" ||
|
||||
I->getSection() == ".dtors")) {
|
||||
assert(!Subtarget->isTargetDarwin());
|
||||
std::string SectionName = ".section " + I->getSection();
|
||||
SectionName += ",\"aw\",%progbits";
|
||||
SwitchToDataSection(SectionName.c_str());
|
||||
} else if (I->hasSection() && Subtarget->isTargetDarwin()) {
|
||||
// Honor all section names on Darwin; ObjC uses this
|
||||
std::string SectionName = ".section " + I->getSection();
|
||||
SwitchToDataSection(SectionName.c_str());
|
||||
} else {
|
||||
if (C->isNullValue() && !NoZerosInBSS && TAI->getBSSSection())
|
||||
SwitchToDataSection(I->isThreadLocal() ? TAI->getTLSBSSSection() :
|
||||
TAI->getBSSSection(), I);
|
||||
else if (!I->isConstant())
|
||||
SwitchToDataSection(I->isThreadLocal() ? TAI->getTLSDataSection() :
|
||||
TAI->getDataSection(), I);
|
||||
else if (I->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(), I);
|
||||
else if (!HasReloc && Size == 8 &&
|
||||
TAI->getEightByteConstantSection())
|
||||
SwitchToDataSection(TAI->getEightByteConstantSection(), I);
|
||||
else if (!HasReloc && Size == 16 &&
|
||||
TAI->getSixteenByteConstantSection())
|
||||
SwitchToDataSection(TAI->getSixteenByteConstantSection(), I);
|
||||
else if (TAI->getReadOnlySection())
|
||||
SwitchToDataSection(TAI->getReadOnlySection(), I);
|
||||
else
|
||||
SwitchToDataSection(TAI->getDataSection(), I);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
default:
|
||||
assert(0 && "Unknown linkage type!");
|
||||
break;
|
||||
}
|
||||
|
||||
EmitAlignment(Align, I);
|
||||
EmitAlignment(Align, GVar);
|
||||
O << name << ":\t\t\t\t" << TAI->getCommentString() << " ";
|
||||
PrintUnmangledNameSafely(I, O);
|
||||
PrintUnmangledNameSafely(GVar, O);
|
||||
O << "\n";
|
||||
if (TAI->hasDotTypeDotSizeDirective())
|
||||
O << "\t.size " << name << ", " << Size << "\n";
|
||||
|
||||
// If the initializer is a extern weak symbol, remember to emit the weak
|
||||
// reference!
|
||||
if (const GlobalValue *GV = dyn_cast<GlobalValue>(C))
|
||||
@ -990,7 +945,13 @@ bool ARMAsmPrinter::doFinalization(Module &M) {
|
||||
|
||||
EmitGlobalConstant(C);
|
||||
O << '\n';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool ARMAsmPrinter::doFinalization(Module &M) {
|
||||
for (Module::const_global_iterator I = M.global_begin(), E = M.global_end();
|
||||
I != E; ++I)
|
||||
printModuleLevelGV(I);
|
||||
|
||||
if (Subtarget->isTargetDarwin()) {
|
||||
SwitchToDataSection("");
|
||||
|
@ -43,13 +43,28 @@ static const char *const arm_asm_table[] = {
|
||||
0,0};
|
||||
|
||||
ARMTargetAsmInfo::ARMTargetAsmInfo(const ARMTargetMachine &TM) {
|
||||
Subtarget = &TM.getSubtarget<ARMSubtarget>();
|
||||
AsmTransCBE = arm_asm_table;
|
||||
if (Subtarget->isTargetDarwin()) {
|
||||
|
||||
AlignmentIsInBytes = false;
|
||||
Data64bitsDirective = 0;
|
||||
CommentString = "@";
|
||||
DataSection = "\t.data";
|
||||
ConstantPoolSection = "\t.text\n";
|
||||
COMMDirectiveTakesAlignment = false;
|
||||
InlineAsmStart = "@ InlineAsm Start";
|
||||
InlineAsmEnd = "@ InlineAsm End";
|
||||
LCOMMDirective = "\t.lcomm\t";
|
||||
}
|
||||
|
||||
ARMDarwinTargetAsmInfo::ARMDarwinTargetAsmInfo(const ARMTargetMachine &TM):
|
||||
ARMTargetAsmInfo(TM), DarwinTargetAsmInfo(TM) {
|
||||
Subtarget = &DTM->getSubtarget<ARMSubtarget>();
|
||||
|
||||
GlobalPrefix = "_";
|
||||
PrivateGlobalPrefix = "L";
|
||||
StringConstantPrefix = "\1LC";
|
||||
BSSSection = 0; // no BSS section.
|
||||
BSSSection = 0; // no BSS section
|
||||
ZeroDirective = "\t.space\t";
|
||||
ZeroFillDirective = "\t.zerofill\t"; // Uses .zerofill
|
||||
SetDirective = "\t.set\t";
|
||||
WeakRefDirective = "\t.weak_reference\t";
|
||||
@ -89,11 +104,20 @@ ARMTargetAsmInfo::ARMTargetAsmInfo(const ARMTargetMachine &TM) {
|
||||
DwarfARangesSection = ".section __DWARF,__debug_aranges,regular,debug";
|
||||
DwarfRangesSection = ".section __DWARF,__debug_ranges,regular,debug";
|
||||
DwarfMacInfoSection = ".section __DWARF,__debug_macinfo,regular,debug";
|
||||
} else {
|
||||
}
|
||||
|
||||
ARMELFTargetAsmInfo::ARMELFTargetAsmInfo(const ARMTargetMachine &TM):
|
||||
ARMTargetAsmInfo(TM), ELFTargetAsmInfo(TM) {
|
||||
Subtarget = &ETM->getSubtarget<ARMSubtarget>();
|
||||
|
||||
NeedsSet = false;
|
||||
HasLEB128 = true;
|
||||
AbsoluteDebugSectionOffsets = true;
|
||||
CStringSection = ".rodata.str";
|
||||
ReadOnlySection = "\t.section\t.rodata\n";
|
||||
FourByteConstantSection = "\t.section\t.rodata.cst4,\"aM\",@progbits,4";
|
||||
EightByteConstantSection = "\t.section\t.rodata.cst8,\"aM\",@progbits,8";
|
||||
SixteenByteConstantSection = "\t.section\t.rodata.cst16,\"aM\",@progbits,16";
|
||||
PrivateGlobalPrefix = ".L";
|
||||
WeakRefDirective = "\t.weak\t";
|
||||
SetDirective = "\t.set\t";
|
||||
@ -119,18 +143,6 @@ ARMTargetAsmInfo::ARMTargetAsmInfo(const ARMTargetMachine &TM) {
|
||||
}
|
||||
TLSDataSection = "\t.section .tdata,\"awT\",%progbits";
|
||||
TLSBSSSection = "\t.section .tbss,\"awT\",%nobits";
|
||||
}
|
||||
|
||||
ZeroDirective = "\t.space\t";
|
||||
AlignmentIsInBytes = false;
|
||||
Data64bitsDirective = 0;
|
||||
CommentString = "@";
|
||||
DataSection = "\t.data";
|
||||
ConstantPoolSection = "\t.text\n";
|
||||
COMMDirectiveTakesAlignment = false;
|
||||
InlineAsmStart = "@ InlineAsm Start";
|
||||
InlineAsmEnd = "@ InlineAsm End";
|
||||
LCOMMDirective = "\t.lcomm\t";
|
||||
}
|
||||
|
||||
/// Count the number of comma-separated arguments.
|
||||
|
@ -15,6 +15,9 @@
|
||||
#define ARMTARGETASMINFO_H
|
||||
|
||||
#include "llvm/Target/TargetAsmInfo.h"
|
||||
#include "llvm/Target/ELFTargetAsmInfo.h"
|
||||
#include "llvm/Target/DarwinTargetAsmInfo.h"
|
||||
|
||||
#include "ARMSubtarget.h"
|
||||
|
||||
namespace llvm {
|
||||
@ -22,7 +25,7 @@ namespace llvm {
|
||||
// Forward declaration.
|
||||
class ARMTargetMachine;
|
||||
|
||||
struct ARMTargetAsmInfo : public TargetAsmInfo {
|
||||
struct ARMTargetAsmInfo : public virtual TargetAsmInfo {
|
||||
explicit ARMTargetAsmInfo(const ARMTargetMachine &TM);
|
||||
|
||||
const ARMSubtarget *Subtarget;
|
||||
@ -32,6 +35,15 @@ namespace llvm {
|
||||
unsigned countString(const char *p) const;
|
||||
};
|
||||
|
||||
struct ARMDarwinTargetAsmInfo : public virtual ARMTargetAsmInfo,
|
||||
public virtual DarwinTargetAsmInfo {
|
||||
explicit ARMDarwinTargetAsmInfo(const ARMTargetMachine &TM);
|
||||
};
|
||||
|
||||
struct ARMELFTargetAsmInfo : public virtual ARMTargetAsmInfo,
|
||||
public virtual ELFTargetAsmInfo {
|
||||
explicit ARMELFTargetAsmInfo(const ARMTargetMachine &TM);
|
||||
};
|
||||
|
||||
} // namespace llvm
|
||||
|
||||
|
@ -110,7 +110,14 @@ unsigned ARMTargetMachine::getModuleMatchQuality(const Module &M) {
|
||||
|
||||
|
||||
const TargetAsmInfo *ARMTargetMachine::createTargetAsmInfo() const {
|
||||
switch (Subtarget.TargetType) {
|
||||
case ARMSubtarget::isDarwin:
|
||||
return new ARMDarwinTargetAsmInfo(*this);
|
||||
case ARMSubtarget::isELF:
|
||||
return new ARMELFTargetAsmInfo(*this);
|
||||
default:
|
||||
return new ARMTargetAsmInfo(*this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -754,8 +754,6 @@ void X86ATTAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
|
||||
if (!GVar->hasInitializer())
|
||||
return; // External global require no code
|
||||
|
||||
std::string SectionName = TAI->SectionForGlobal(GVar);
|
||||
|
||||
// Check to see if this is a special global used by LLVM, if so, emit it.
|
||||
if (EmitSpecialLLVMGlobal(GVar)) {
|
||||
if (Subtarget->isTargetDarwin() &&
|
||||
@ -768,6 +766,7 @@ void X86ATTAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::string SectionName = TAI->SectionForGlobal(GVar);
|
||||
std::string name = Mang->getValueName(GVar);
|
||||
Constant *C = GVar->getInitializer();
|
||||
const Type *Type = C->getType();
|
||||
|
Loading…
Reference in New Issue
Block a user