mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-08-14 15:28:20 +00:00
Switch IA64 to new section-handling stuff
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@54453 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -109,6 +109,7 @@ namespace {
|
|||||||
|
|
||||||
void printMachineInstruction(const MachineInstr *MI);
|
void printMachineInstruction(const MachineInstr *MI);
|
||||||
void printOp(const MachineOperand &MO, bool isBRCALLinsn= false);
|
void printOp(const MachineOperand &MO, bool isBRCALLinsn= false);
|
||||||
|
void printModuleLevelGV(const GlobalVariable* GVar);
|
||||||
bool runOnMachineFunction(MachineFunction &F);
|
bool runOnMachineFunction(MachineFunction &F);
|
||||||
bool doInitialization(Module &M);
|
bool doInitialization(Module &M);
|
||||||
bool doFinalization(Module &M);
|
bool doFinalization(Module &M);
|
||||||
@@ -256,78 +257,92 @@ bool IA64AsmPrinter::doInitialization(Module &M) {
|
|||||||
return Result;
|
return Result;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IA64AsmPrinter::doFinalization(Module &M) {
|
void IA64AsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
|
||||||
const TargetData *TD = TM.getTargetData();
|
const TargetData *TD = TM.getTargetData();
|
||||||
|
|
||||||
|
if (!GVar->hasInitializer())
|
||||||
|
return; // External global require no code
|
||||||
|
|
||||||
|
// Check to see if this is a special global used by LLVM, if so, emit it.
|
||||||
|
if (EmitSpecialLLVMGlobal(GVar))
|
||||||
|
return;
|
||||||
|
|
||||||
|
O << "\n\n";
|
||||||
|
std::string SectionName = TAI->SectionForGlobal(GVar);
|
||||||
|
std::string name = Mang->getValueName(GVar);
|
||||||
|
Constant *C = GVar->getInitializer();
|
||||||
|
unsigned Size = TD->getABITypeSize(C->getType());
|
||||||
|
unsigned Align = TD->getPreferredAlignmentLog(GVar);
|
||||||
|
|
||||||
|
// FIXME: ELF supports visibility
|
||||||
|
|
||||||
|
SwitchToDataSection(SectionName.c_str());
|
||||||
|
|
||||||
|
if (C->isNullValue() && !GVar->hasSection()) {
|
||||||
|
if (!GVar->isThreadLocal() &&
|
||||||
|
(GVar->hasInternalLinkage() || GVar->isWeakForLinker())) {
|
||||||
|
if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it.
|
||||||
|
|
||||||
|
if (GVar->hasInternalLinkage()) {
|
||||||
|
O << "\t.lcomm " << name << "#," << Size
|
||||||
|
<< "," << (1 << Align);
|
||||||
|
O << "\n";
|
||||||
|
} else {
|
||||||
|
O << "\t.common " << name << "#," << Size
|
||||||
|
<< "," << (1 << Align);
|
||||||
|
O << "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (GVar->getLinkage()) {
|
||||||
|
case GlobalValue::LinkOnceLinkage:
|
||||||
|
case GlobalValue::CommonLinkage:
|
||||||
|
case GlobalValue::WeakLinkage:
|
||||||
|
// Nonnull linkonce -> weak
|
||||||
|
O << "\t.weak " << name << "\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 << TAI->getGlobalDirective() << name << "\n";
|
||||||
|
// FALL THROUGH
|
||||||
|
case GlobalValue::InternalLinkage:
|
||||||
|
break;
|
||||||
|
case GlobalValue::GhostLinkage:
|
||||||
|
cerr << "GhostLinkage cannot appear in IA64AsmPrinter!\n";
|
||||||
|
abort();
|
||||||
|
case GlobalValue::DLLImportLinkage:
|
||||||
|
cerr << "DLLImport linkage is not supported by this target!\n";
|
||||||
|
abort();
|
||||||
|
case GlobalValue::DLLExportLinkage:
|
||||||
|
cerr << "DLLExport linkage is not supported by this target!\n";
|
||||||
|
abort();
|
||||||
|
default:
|
||||||
|
assert(0 && "Unknown linkage type!");
|
||||||
|
}
|
||||||
|
|
||||||
|
EmitAlignment(Align);
|
||||||
|
|
||||||
|
if (TAI->hasDotTypeDotSizeDirective()) {
|
||||||
|
O << "\t.type " << name << ",@object\n";
|
||||||
|
O << "\t.size " << name << "," << Size << "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
O << name << ":\t\t\t\t// " << *C << "\n";
|
||||||
|
EmitGlobalConstant(C);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool IA64AsmPrinter::doFinalization(Module &M) {
|
||||||
// Print out module-level global variables here.
|
// Print out module-level global variables here.
|
||||||
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->hasInitializer()) { // External global require no code
|
printModuleLevelGV(I);
|
||||||
// Check to see if this is a special global used by LLVM, if so, emit it.
|
|
||||||
if (EmitSpecialLLVMGlobal(I))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
O << "\n\n";
|
|
||||||
std::string name = Mang->getValueName(I);
|
|
||||||
Constant *C = I->getInitializer();
|
|
||||||
unsigned Size = TD->getABITypeSize(C->getType());
|
|
||||||
unsigned Align = TD->getPreferredAlignmentLog(I);
|
|
||||||
|
|
||||||
if (C->isNullValue() &&
|
|
||||||
(I->hasLinkOnceLinkage() || I->hasInternalLinkage() ||
|
|
||||||
I->hasCommonLinkage() ||
|
|
||||||
I->hasWeakLinkage() /* FIXME: Verify correct */)) {
|
|
||||||
SwitchToDataSection(".data", I);
|
|
||||||
if (I->hasInternalLinkage()) {
|
|
||||||
O << "\t.lcomm " << name << "#," << TD->getABITypeSize(C->getType())
|
|
||||||
<< "," << (1 << Align);
|
|
||||||
O << "\n";
|
|
||||||
} else {
|
|
||||||
O << "\t.common " << name << "#," << TD->getABITypeSize(C->getType())
|
|
||||||
<< "," << (1 << Align);
|
|
||||||
O << "\n";
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
switch (I->getLinkage()) {
|
|
||||||
case GlobalValue::LinkOnceLinkage:
|
|
||||||
case GlobalValue::CommonLinkage:
|
|
||||||
case GlobalValue::WeakLinkage: // FIXME: Verify correct for weak.
|
|
||||||
// Nonnull linkonce -> weak
|
|
||||||
O << "\t.weak " << name << "\n";
|
|
||||||
O << "\t.section\t.llvm.linkonce.d." << name
|
|
||||||
<< ", \"aw\", \"progbits\"\n";
|
|
||||||
SwitchToDataSection("", I);
|
|
||||||
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 << "\t.global " << name << "\n";
|
|
||||||
// FALL THROUGH
|
|
||||||
case GlobalValue::InternalLinkage:
|
|
||||||
SwitchToDataSection(C->isNullValue() ? ".bss" : ".data", I);
|
|
||||||
break;
|
|
||||||
case GlobalValue::GhostLinkage:
|
|
||||||
cerr << "GhostLinkage cannot appear in IA64AsmPrinter!\n";
|
|
||||||
abort();
|
|
||||||
case GlobalValue::DLLImportLinkage:
|
|
||||||
cerr << "DLLImport linkage is not supported by this target!\n";
|
|
||||||
abort();
|
|
||||||
case GlobalValue::DLLExportLinkage:
|
|
||||||
cerr << "DLLExport linkage is not supported by this target!\n";
|
|
||||||
abort();
|
|
||||||
default:
|
|
||||||
assert(0 && "Unknown linkage type!");
|
|
||||||
}
|
|
||||||
|
|
||||||
EmitAlignment(Align);
|
|
||||||
O << "\t.type " << name << ",@object\n";
|
|
||||||
O << "\t.size " << name << "," << Size << "\n";
|
|
||||||
O << name << ":\t\t\t\t// " << *C << "\n";
|
|
||||||
EmitGlobalConstant(C);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// we print out ".global X \n .type X, @function" for each external function
|
// we print out ".global X \n .type X, @function" for each external function
|
||||||
O << "\n\n// br.call targets referenced (and not defined) above: \n";
|
O << "\n\n// br.call targets referenced (and not defined) above: \n";
|
||||||
|
@@ -15,7 +15,8 @@
|
|||||||
|
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
IA64TargetAsmInfo::IA64TargetAsmInfo(const IA64TargetMachine &TM) {
|
IA64TargetAsmInfo::IA64TargetAsmInfo(const TargetMachine &TM):
|
||||||
|
ELFTargetAsmInfo(TM) {
|
||||||
CommentString = "//";
|
CommentString = "//";
|
||||||
Data8bitsDirective = "\tdata1\t"; // FIXME: check that we are
|
Data8bitsDirective = "\tdata1\t"; // FIXME: check that we are
|
||||||
Data16bitsDirective = "\tdata2.ua\t"; // disabling auto-alignment
|
Data16bitsDirective = "\tdata2.ua\t"; // disabling auto-alignment
|
||||||
@@ -32,3 +33,5 @@ IA64TargetAsmInfo::IA64TargetAsmInfo(const IA64TargetMachine &TM) {
|
|||||||
// FIXME: would be nice to have rodata (no 'w') when appropriate?
|
// FIXME: would be nice to have rodata (no 'w') when appropriate?
|
||||||
ConstantPoolSection = "\n\t.section .data, \"aw\", \"progbits\"\n";
|
ConstantPoolSection = "\n\t.section .data, \"aw\", \"progbits\"\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME: Support small data/bss/rodata sections someday.
|
||||||
|
@@ -15,14 +15,15 @@
|
|||||||
#define IA64TARGETASMINFO_H
|
#define IA64TARGETASMINFO_H
|
||||||
|
|
||||||
#include "llvm/Target/TargetAsmInfo.h"
|
#include "llvm/Target/TargetAsmInfo.h"
|
||||||
|
#include "llvm/Target/ELFTargetAsmInfo.h"
|
||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
|
|
||||||
// Forward declaration.
|
// Forward declaration.
|
||||||
class IA64TargetMachine;
|
class TargetMachine;
|
||||||
|
|
||||||
struct IA64TargetAsmInfo : public TargetAsmInfo {
|
struct IA64TargetAsmInfo : public ELFTargetAsmInfo {
|
||||||
explicit IA64TargetAsmInfo(const IA64TargetMachine &TM);
|
explicit IA64TargetAsmInfo(const TargetMachine &TM);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user