mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-12 13:38:21 +00:00
Restore some "small section" support code, reverting my patch from r76936.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78894 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -210,6 +210,37 @@ AddLiveIn(MachineFunction &MF, unsigned PReg, TargetRegisterClass *RC)
|
|||||||
return VReg;
|
return VReg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// A address must be loaded from a small section if its size is less than the
|
||||||
|
// small section size threshold. Data in this section must be addressed using
|
||||||
|
// gp_rel operator.
|
||||||
|
bool MipsTargetLowering::IsInSmallSection(unsigned Size) {
|
||||||
|
return (Size > 0 && (Size <= Subtarget->getSSectionThreshold()));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Discover if this global address can be placed into small data/bss section.
|
||||||
|
bool MipsTargetLowering::IsGlobalInSmallSection(GlobalValue *GV)
|
||||||
|
{
|
||||||
|
const TargetData *TD = getTargetData();
|
||||||
|
const GlobalVariable *GVA = dyn_cast<GlobalVariable>(GV);
|
||||||
|
|
||||||
|
if (!GVA)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
const Type *Ty = GV->getType()->getElementType();
|
||||||
|
unsigned Size = TD->getTypeAllocSize(Ty);
|
||||||
|
|
||||||
|
// if this is a internal constant string, there is a special
|
||||||
|
// section for it, but not in small data/bss.
|
||||||
|
if (GVA->hasInitializer() && GV->hasLocalLinkage()) {
|
||||||
|
Constant *C = GVA->getInitializer();
|
||||||
|
const ConstantArray *CVA = dyn_cast<ConstantArray>(C);
|
||||||
|
if (CVA && CVA->isCString())
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return IsInSmallSection(Size);
|
||||||
|
}
|
||||||
|
|
||||||
// Get fp branch code (not opcode) from condition code.
|
// Get fp branch code (not opcode) from condition code.
|
||||||
static Mips::FPBranchCode GetFPBranchCodeFromCond(Mips::CondCode CC) {
|
static Mips::FPBranchCode GetFPBranchCodeFromCond(Mips::CondCode CC) {
|
||||||
if (CC >= Mips::FCOND_F && CC <= Mips::FCOND_NGT)
|
if (CC >= Mips::FCOND_F && CC <= Mips::FCOND_NGT)
|
||||||
@ -485,17 +516,23 @@ LowerSELECT(SDValue Op, SelectionDAG &DAG)
|
|||||||
Cond, True, False, CCNode);
|
Cond, True, False, CCNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
SDValue MipsTargetLowering::
|
SDValue MipsTargetLowering::LowerGlobalAddress(SDValue Op, SelectionDAG &DAG) {
|
||||||
LowerGlobalAddress(SDValue Op, SelectionDAG &DAG)
|
|
||||||
{
|
|
||||||
// FIXME there isn't actually debug info here
|
// FIXME there isn't actually debug info here
|
||||||
DebugLoc dl = Op.getDebugLoc();
|
DebugLoc dl = Op.getDebugLoc();
|
||||||
GlobalValue *GV = cast<GlobalAddressSDNode>(Op)->getGlobal();
|
GlobalValue *GV = cast<GlobalAddressSDNode>(Op)->getGlobal();
|
||||||
SDValue GA = DAG.getTargetGlobalAddress(GV, MVT::i32);
|
SDValue GA = DAG.getTargetGlobalAddress(GV, MVT::i32);
|
||||||
|
|
||||||
if (getTargetMachine().getRelocationModel() != Reloc::PIC_) {
|
if (getTargetMachine().getRelocationModel() != Reloc::PIC_) {
|
||||||
|
SDVTList VTs = DAG.getVTList(MVT::i32);
|
||||||
|
|
||||||
|
// %gp_rel relocation
|
||||||
|
if (!isa<Function>(GV) && IsGlobalInSmallSection(GV)) {
|
||||||
|
SDValue GPRelNode = DAG.getNode(MipsISD::GPRel, dl, VTs, &GA, 1);
|
||||||
|
SDValue GOT = DAG.getGLOBAL_OFFSET_TABLE(MVT::i32);
|
||||||
|
return DAG.getNode(ISD::ADD, dl, MVT::i32, GOT, GPRelNode);
|
||||||
|
}
|
||||||
// %hi/%lo relocation
|
// %hi/%lo relocation
|
||||||
SDValue HiPart = DAG.getNode(MipsISD::Hi, dl, MVT::i32, GA);
|
SDValue HiPart = DAG.getNode(MipsISD::Hi, dl, VTs, &GA, 1);
|
||||||
SDValue Lo = DAG.getNode(MipsISD::Lo, dl, MVT::i32, GA);
|
SDValue Lo = DAG.getNode(MipsISD::Lo, dl, MVT::i32, GA);
|
||||||
return DAG.getNode(ISD::ADD, dl, MVT::i32, HiPart, Lo);
|
return DAG.getNode(ISD::ADD, dl, MVT::i32, HiPart, Lo);
|
||||||
|
|
||||||
|
@ -66,8 +66,8 @@ namespace llvm {
|
|||||||
//===--------------------------------------------------------------------===//
|
//===--------------------------------------------------------------------===//
|
||||||
// TargetLowering Implementation
|
// TargetLowering Implementation
|
||||||
//===--------------------------------------------------------------------===//
|
//===--------------------------------------------------------------------===//
|
||||||
class MipsTargetLowering : public TargetLowering
|
|
||||||
{
|
class MipsTargetLowering : public TargetLowering {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
explicit MipsTargetLowering(MipsTargetMachine &TM);
|
explicit MipsTargetLowering(MipsTargetMachine &TM);
|
||||||
@ -88,6 +88,9 @@ namespace llvm {
|
|||||||
// Subtarget Info
|
// Subtarget Info
|
||||||
const MipsSubtarget *Subtarget;
|
const MipsSubtarget *Subtarget;
|
||||||
|
|
||||||
|
bool IsGlobalInSmallSection(GlobalValue *GV);
|
||||||
|
bool IsInSmallSection(unsigned Size);
|
||||||
|
|
||||||
// Lower Operand helpers
|
// Lower Operand helpers
|
||||||
SDValue LowerCallResult(SDValue Chain, SDValue InFlag,
|
SDValue LowerCallResult(SDValue Chain, SDValue InFlag,
|
||||||
unsigned CallConv, bool isVarArg,
|
unsigned CallConv, bool isVarArg,
|
||||||
|
@ -17,6 +17,11 @@
|
|||||||
#include "llvm/Support/CommandLine.h"
|
#include "llvm/Support/CommandLine.h"
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
|
static cl::opt<unsigned>
|
||||||
|
SSThreshold("mips-ssection-threshold", cl::Hidden,
|
||||||
|
cl::desc("Small data and bss section threshold size (default=8)"),
|
||||||
|
cl::init(8));
|
||||||
|
|
||||||
MipsSubtarget::MipsSubtarget(const std::string &TT, const std::string &FS,
|
MipsSubtarget::MipsSubtarget(const std::string &TT, const std::string &FS,
|
||||||
bool little) :
|
bool little) :
|
||||||
MipsArchVersion(Mips1), MipsABI(O32), IsLittle(little), IsSingleFloat(false),
|
MipsArchVersion(Mips1), MipsABI(O32), IsLittle(little), IsSingleFloat(false),
|
||||||
@ -30,6 +35,9 @@ MipsSubtarget::MipsSubtarget(const std::string &TT, const std::string &FS,
|
|||||||
// Parse features string.
|
// Parse features string.
|
||||||
ParseSubtargetFeatures(FS, CPU);
|
ParseSubtargetFeatures(FS, CPU);
|
||||||
|
|
||||||
|
// Small section size threshold
|
||||||
|
SSectionThreshold = SSThreshold;
|
||||||
|
|
||||||
// Is the target system Linux ?
|
// Is the target system Linux ?
|
||||||
if (TT.find("linux") == std::string::npos)
|
if (TT.find("linux") == std::string::npos)
|
||||||
IsLinux = false;
|
IsLinux = false;
|
||||||
|
@ -60,6 +60,10 @@ protected:
|
|||||||
// isLinux - Target system is Linux. Is false we consider ELFOS for now.
|
// isLinux - Target system is Linux. Is false we consider ELFOS for now.
|
||||||
bool IsLinux;
|
bool IsLinux;
|
||||||
|
|
||||||
|
// Put global and static items less than or equal to SSectionThreshold
|
||||||
|
// bytes into the small data or bss section. The default is 8.
|
||||||
|
unsigned SSectionThreshold;
|
||||||
|
|
||||||
/// Features related to the presence of specific instructions.
|
/// Features related to the presence of specific instructions.
|
||||||
|
|
||||||
// HasSEInReg - SEB and SEH (signext in register) instructions.
|
// HasSEInReg - SEB and SEH (signext in register) instructions.
|
||||||
@ -109,6 +113,7 @@ public:
|
|||||||
bool isNotSingleFloat() const { return !IsSingleFloat; };
|
bool isNotSingleFloat() const { return !IsSingleFloat; };
|
||||||
bool hasVFPU() const { return HasVFPU; };
|
bool hasVFPU() const { return HasVFPU; };
|
||||||
bool isLinux() const { return IsLinux; };
|
bool isLinux() const { return IsLinux; };
|
||||||
|
unsigned getSSectionThreshold() const { return SSectionThreshold; }
|
||||||
|
|
||||||
/// Features related to the presence of specific instructions.
|
/// Features related to the presence of specific instructions.
|
||||||
bool hasSEInReg() const { return HasSEInReg; };
|
bool hasSEInReg() const { return HasSEInReg; };
|
||||||
|
Reference in New Issue
Block a user