llvm.org GIT mirror llvm / e3736f8
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 Chris Lattner 10 years ago
4 changed file(s) with 59 addition(s) and 6 deletion(s). Raw diff Collapse all Expand all
209209 return VReg;
210210 }
211211
212 // A address must be loaded from a small section if its size is less than the
213 // small section size threshold. Data in this section must be addressed using
214 // gp_rel operator.
215 bool MipsTargetLowering::IsInSmallSection(unsigned Size) {
216 return (Size > 0 && (Size <= Subtarget->getSSectionThreshold()));
217 }
218
219 // Discover if this global address can be placed into small data/bss section.
220 bool MipsTargetLowering::IsGlobalInSmallSection(GlobalValue *GV)
221 {
222 const TargetData *TD = getTargetData();
223 const GlobalVariable *GVA = dyn_cast(GV);
224
225 if (!GVA)
226 return false;
227
228 const Type *Ty = GV->getType()->getElementType();
229 unsigned Size = TD->getTypeAllocSize(Ty);
230
231 // if this is a internal constant string, there is a special
232 // section for it, but not in small data/bss.
233 if (GVA->hasInitializer() && GV->hasLocalLinkage()) {
234 Constant *C = GVA->getInitializer();
235 const ConstantArray *CVA = dyn_cast(C);
236 if (CVA && CVA->isCString())
237 return false;
238 }
239
240 return IsInSmallSection(Size);
241 }
242
212243 // Get fp branch code (not opcode) from condition code.
213244 static Mips::FPBranchCode GetFPBranchCodeFromCond(Mips::CondCode CC) {
214245 if (CC >= Mips::FCOND_F && CC <= Mips::FCOND_NGT)
484515 Cond, True, False, CCNode);
485516 }
486517
487 SDValue MipsTargetLowering::
488 LowerGlobalAddress(SDValue Op, SelectionDAG &DAG)
489 {
518 SDValue MipsTargetLowering::LowerGlobalAddress(SDValue Op, SelectionDAG &DAG) {
490519 // FIXME there isn't actually debug info here
491520 DebugLoc dl = Op.getDebugLoc();
492521 GlobalValue *GV = cast(Op)->getGlobal();
493522 SDValue GA = DAG.getTargetGlobalAddress(GV, MVT::i32);
494523
495524 if (getTargetMachine().getRelocationModel() != Reloc::PIC_) {
525 SDVTList VTs = DAG.getVTList(MVT::i32);
526
527 // %gp_rel relocation
528 if (!isa(GV) && IsGlobalInSmallSection(GV)) {
529 SDValue GPRelNode = DAG.getNode(MipsISD::GPRel, dl, VTs, &GA, 1);
530 SDValue GOT = DAG.getGLOBAL_OFFSET_TABLE(MVT::i32);
531 return DAG.getNode(ISD::ADD, dl, MVT::i32, GOT, GPRelNode);
532 }
496533 // %hi/%lo relocation
497 SDValue HiPart = DAG.getNode(MipsISD::Hi, dl, MVT::i32, GA);
534 SDValue HiPart = DAG.getNode(MipsISD::Hi, dl, VTs, &GA, 1);
498535 SDValue Lo = DAG.getNode(MipsISD::Lo, dl, MVT::i32, GA);
499536 return DAG.getNode(ISD::ADD, dl, MVT::i32, HiPart, Lo);
500537
6565 //===--------------------------------------------------------------------===//
6666 // TargetLowering Implementation
6767 //===--------------------------------------------------------------------===//
68 class MipsTargetLowering : public TargetLowering
69 {
68
69 class MipsTargetLowering : public TargetLowering {
7070 public:
7171
7272 explicit MipsTargetLowering(MipsTargetMachine &TM);
8686 private:
8787 // Subtarget Info
8888 const MipsSubtarget *Subtarget;
89
90 bool IsGlobalInSmallSection(GlobalValue *GV);
91 bool IsInSmallSection(unsigned Size);
8992
9093 // Lower Operand helpers
9194 SDValue LowerCallResult(SDValue Chain, SDValue InFlag,
1616 #include "llvm/Support/CommandLine.h"
1717 using namespace llvm;
1818
19 static cl::opt
20 SSThreshold("mips-ssection-threshold", cl::Hidden,
21 cl::desc("Small data and bss section threshold size (default=8)"),
22 cl::init(8));
23
1924 MipsSubtarget::MipsSubtarget(const std::string &TT, const std::string &FS,
2025 bool little) :
2126 MipsArchVersion(Mips1), MipsABI(O32), IsLittle(little), IsSingleFloat(false),
2833
2934 // Parse features string.
3035 ParseSubtargetFeatures(FS, CPU);
36
37 // Small section size threshold
38 SSectionThreshold = SSThreshold;
3139
3240 // Is the target system Linux ?
3341 if (TT.find("linux") == std::string::npos)
5959 // isLinux - Target system is Linux. Is false we consider ELFOS for now.
6060 bool IsLinux;
6161
62 // Put global and static items less than or equal to SSectionThreshold
63 // bytes into the small data or bss section. The default is 8.
64 unsigned SSectionThreshold;
65
6266 /// Features related to the presence of specific instructions.
6367
6468 // HasSEInReg - SEB and SEH (signext in register) instructions.
108112 bool isNotSingleFloat() const { return !IsSingleFloat; };
109113 bool hasVFPU() const { return HasVFPU; };
110114 bool isLinux() const { return IsLinux; };
115 unsigned getSSectionThreshold() const { return SSectionThreshold; }
111116
112117 /// Features related to the presence of specific instructions.
113118 bool hasSEInReg() const { return HasSEInReg; };