mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-12-19 11:23:32 +00:00
Move DataLayout back to the TargetMachine from TargetSubtargetInfo
derived classes. Since global data alignment, layout, and mangling is often based on the DataLayout, move it to the TargetMachine. This ensures that global data is going to be layed out and mangled consistently if the subtarget changes on a per function basis. Prior to this all targets(*) have had subtarget dependent code moved out and onto the TargetMachine. *One target hasn't been migrated as part of this change: R600. The R600 port has, as a subtarget feature, the size of pointers and this affects global data layout. I've currently hacked in a FIXME to enable progress, but the port needs to be updated to either pass the 64-bitness to the TargetMachine, or fix the DataLayout to avoid subtarget dependent features. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@227113 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -561,7 +561,7 @@ bool MipsAsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI,
|
||||
|
||||
void MipsAsmPrinter::printOperand(const MachineInstr *MI, int opNum,
|
||||
raw_ostream &O) {
|
||||
const DataLayout *DL = TM.getSubtargetImpl()->getDataLayout();
|
||||
const DataLayout *DL = TM.getDataLayout();
|
||||
const MachineOperand &MO = MI->getOperand(opNum);
|
||||
bool closeP = false;
|
||||
|
||||
|
||||
@@ -562,7 +562,7 @@ MipsConstantIslands::doInitialPlacement(std::vector<MachineInstr*> &CPEMIs) {
|
||||
// identity mapping of CPI's to CPE's.
|
||||
const std::vector<MachineConstantPoolEntry> &CPs = MCP->getConstants();
|
||||
|
||||
const DataLayout &TD = *MF->getSubtarget().getDataLayout();
|
||||
const DataLayout &TD = *MF->getTarget().getDataLayout();
|
||||
for (unsigned i = 0, e = CPs.size(); i != e; ++i) {
|
||||
unsigned Size = TD.getTypeAllocSize(CPs[i].getType());
|
||||
assert(Size >= 4 && "Too small constant pool entry");
|
||||
|
||||
@@ -64,36 +64,6 @@ GPOpt("mgpopt", cl::Hidden,
|
||||
|
||||
void MipsSubtarget::anchor() { }
|
||||
|
||||
static std::string computeDataLayout(const MipsSubtarget &ST) {
|
||||
std::string Ret = "";
|
||||
|
||||
// There are both little and big endian mips.
|
||||
if (ST.isLittle())
|
||||
Ret += "e";
|
||||
else
|
||||
Ret += "E";
|
||||
|
||||
Ret += "-m:m";
|
||||
|
||||
// Pointers are 32 bit on some ABIs.
|
||||
if (!ST.isABI_N64())
|
||||
Ret += "-p:32:32";
|
||||
|
||||
// 8 and 16 bit integers only need no have natural alignment, but try to
|
||||
// align them to 32 bits. 64 bit integers have natural alignment.
|
||||
Ret += "-i8:8:32-i16:16:32-i64:64";
|
||||
|
||||
// 32 bit registers are always available and the stack is at least 64 bit
|
||||
// aligned. On N64 64 bit registers are also available and the stack is
|
||||
// 128 bit aligned.
|
||||
if (ST.isABI_N64() || ST.isABI_N32())
|
||||
Ret += "-n32:64-S128";
|
||||
else
|
||||
Ret += "-n32-S64";
|
||||
|
||||
return Ret;
|
||||
}
|
||||
|
||||
MipsSubtarget::MipsSubtarget(const std::string &TT, const std::string &CPU,
|
||||
const std::string &FS, bool little,
|
||||
const MipsTargetMachine &TM)
|
||||
@@ -105,9 +75,9 @@ MipsSubtarget::MipsSubtarget(const std::string &TT, const std::string &CPU,
|
||||
HasMips5_32r2(false), InMips16Mode(false),
|
||||
InMips16HardFloat(Mips16HardFloat), InMicroMipsMode(false), HasDSP(false),
|
||||
HasDSPR2(false), AllowMixed16_32(Mixed16_32 | Mips_Os16), Os16(Mips_Os16),
|
||||
HasMSA(false), TM(TM), TargetTriple(TT),
|
||||
DL(computeDataLayout(initializeSubtargetDependencies(CPU, FS, TM))),
|
||||
TSInfo(DL), InstrInfo(MipsInstrInfo::create(*this)),
|
||||
HasMSA(false), TM(TM), TargetTriple(TT), TSInfo(*TM.getDataLayout()),
|
||||
InstrInfo(
|
||||
MipsInstrInfo::create(initializeSubtargetDependencies(CPU, FS, TM))),
|
||||
FrameLowering(MipsFrameLowering::create(*this)),
|
||||
TLInfo(MipsTargetLowering::create(TM, *this)) {
|
||||
|
||||
|
||||
@@ -137,7 +137,6 @@ class MipsSubtarget : public MipsGenSubtargetInfo {
|
||||
|
||||
Triple TargetTriple;
|
||||
|
||||
const DataLayout DL; // Calculates type size & alignment
|
||||
const MipsSelectionDAGInfo TSInfo;
|
||||
std::unique_ptr<const MipsInstrInfo> InstrInfo;
|
||||
std::unique_ptr<const MipsFrameLowering> FrameLowering;
|
||||
@@ -267,7 +266,6 @@ public:
|
||||
const MipsSelectionDAGInfo *getSelectionDAGInfo() const override {
|
||||
return &TSInfo;
|
||||
}
|
||||
const DataLayout *getDataLayout() const override { return &DL; }
|
||||
const MipsInstrInfo *getInstrInfo() const override { return InstrInfo.get(); }
|
||||
const TargetFrameLowering *getFrameLowering() const override {
|
||||
return FrameLowering.get();
|
||||
|
||||
@@ -46,6 +46,36 @@ extern "C" void LLVMInitializeMipsTarget() {
|
||||
RegisterTargetMachine<MipselTargetMachine> B(TheMips64elTarget);
|
||||
}
|
||||
|
||||
static std::string computeDataLayout(bool isLittle, MipsABIInfo &ABI) {
|
||||
std::string Ret = "";
|
||||
|
||||
// There are both little and big endian mips.
|
||||
if (isLittle)
|
||||
Ret += "e";
|
||||
else
|
||||
Ret += "E";
|
||||
|
||||
Ret += "-m:m";
|
||||
|
||||
// Pointers are 32 bit on some ABIs.
|
||||
if (!ABI.IsN64())
|
||||
Ret += "-p:32:32";
|
||||
|
||||
// 8 and 16 bit integers only need no have natural alignment, but try to
|
||||
// align them to 32 bits. 64 bit integers have natural alignment.
|
||||
Ret += "-i8:8:32-i16:16:32-i64:64";
|
||||
|
||||
// 32 bit registers are always available and the stack is at least 64 bit
|
||||
// aligned. On N64 64 bit registers are also available and the stack is
|
||||
// 128 bit aligned.
|
||||
if (ABI.IsN64() || ABI.IsN32())
|
||||
Ret += "-n32:64-S128";
|
||||
else
|
||||
Ret += "-n32-S64";
|
||||
|
||||
return Ret;
|
||||
}
|
||||
|
||||
// On function prologue, the stack is created by decrementing
|
||||
// its pointer. Once decremented, all references are done with positive
|
||||
// offset from the stack/frame pointer, using StackGrowsUp enables
|
||||
@@ -59,7 +89,8 @@ MipsTargetMachine::MipsTargetMachine(const Target &T, StringRef TT,
|
||||
: LLVMTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL),
|
||||
isLittle(isLittle), TLOF(make_unique<MipsTargetObjectFile>()),
|
||||
ABI(MipsABIInfo::computeTargetABI(Triple(TT), CPU, Options.MCOptions)),
|
||||
Subtarget(nullptr), DefaultSubtarget(TT, CPU, FS, isLittle, *this),
|
||||
DL(computeDataLayout(isLittle, ABI)), Subtarget(nullptr),
|
||||
DefaultSubtarget(TT, CPU, FS, isLittle, *this),
|
||||
NoMips16Subtarget(TT, CPU, FS.empty() ? "-mips16" : FS.str() + ",-mips16",
|
||||
isLittle, *this),
|
||||
Mips16Subtarget(TT, CPU, FS.empty() ? "+mips16" : FS.str() + ",+mips16",
|
||||
|
||||
@@ -30,6 +30,7 @@ class MipsTargetMachine : public LLVMTargetMachine {
|
||||
std::unique_ptr<TargetLoweringObjectFile> TLOF;
|
||||
// Selected ABI
|
||||
MipsABIInfo ABI;
|
||||
const DataLayout DL; // Calculates type size & alignment
|
||||
MipsSubtarget *Subtarget;
|
||||
MipsSubtarget DefaultSubtarget;
|
||||
MipsSubtarget NoMips16Subtarget;
|
||||
@@ -45,6 +46,7 @@ public:
|
||||
|
||||
void addAnalysisPasses(PassManagerBase &PM) override;
|
||||
|
||||
const DataLayout *getDataLayout() const override { return &DL; }
|
||||
const MipsSubtarget *getSubtargetImpl() const override {
|
||||
if (Subtarget)
|
||||
return Subtarget;
|
||||
|
||||
@@ -109,8 +109,7 @@ IsGlobalInSmallSectionImpl(const GlobalValue *GV,
|
||||
return false;
|
||||
|
||||
Type *Ty = GV->getType()->getElementType();
|
||||
return IsInSmallSection(
|
||||
TM.getSubtargetImpl()->getDataLayout()->getTypeAllocSize(Ty));
|
||||
return IsInSmallSection(TM.getDataLayout()->getTypeAllocSize(Ty));
|
||||
}
|
||||
|
||||
const MCSection *MipsTargetObjectFile::
|
||||
@@ -132,10 +131,9 @@ SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
|
||||
/// Return true if this constant should be placed into small data section.
|
||||
bool MipsTargetObjectFile::
|
||||
IsConstantInSmallSection(const Constant *CN, const TargetMachine &TM) const {
|
||||
return (TM.getSubtarget<MipsSubtarget>().useSmallSection() &&
|
||||
LocalSData &&
|
||||
IsInSmallSection(TM.getSubtargetImpl()->getDataLayout()
|
||||
->getTypeAllocSize(CN->getType())));
|
||||
return (
|
||||
TM.getSubtarget<MipsSubtarget>().useSmallSection() && LocalSData &&
|
||||
IsInSmallSection(TM.getDataLayout()->getTypeAllocSize(CN->getType())));
|
||||
}
|
||||
|
||||
const MCSection *MipsTargetObjectFile::
|
||||
|
||||
Reference in New Issue
Block a user