#include "MipsTargetAsmInfo.h"
#include "MipsTargetMachine.h"
+#include "llvm/GlobalVariable.h"
using namespace llvm;
MipsTargetAsmInfo::MipsTargetAsmInfo(const MipsTargetMachine &TM):
ELFTargetAsmInfo(TM) {
- MipsTM = &TM;
+ Subtarget = &TM.getSubtarget<MipsSubtarget>();
AlignmentIsInBytes = false;
COMMDirectiveTakesAlignment = true;
PrivateGlobalPrefix = "$";
JumpTableDataSection = "\t.rdata";
CommentString = "#";
- ReadOnlySection = "\t.rdata";
ZeroDirective = "\t.space\t";
BSSSection = "\t.section\t.bss";
- LCOMMDirective = "\t.lcomm\t";
CStringSection = ".rodata.str";
- if (!TM.getSubtarget<MipsSubtarget>().hasABICall())
+ if (!Subtarget->hasABICall()) {
JumpTableDirective = "\t.word\t";
- else
+ SmallDataSection = getNamedSection("\t.sdata", SectionFlags::Writeable);
+ SmallBSSSection = getNamedSection("\t.sbss",
+ SectionFlags::Writeable |
+ SectionFlags::BSS);
+ } else
JumpTableDirective = "\t.gpword\t";
-
- SmallDataSection = getNamedSection("\t.sdata", SectionFlags::Writeable);
- SmallBSSSection = getNamedSection("\t.sbss",
- SectionFlags::Writeable | SectionFlags::BSS);
-}
-static bool isSuitableForBSS(const GlobalVariable *GV) {
- if (!GV->hasInitializer())
- return true;
+}
- // Leave constant zeros in readonly constant sections, so they can be shared
- Constant *C = GV->getInitializer();
- return (C->isNullValue() && !GV->isConstant() && !NoZerosInBSS);
+unsigned MipsTargetAsmInfo::
+SectionFlagsForGlobal(const GlobalValue *GV, const char* Name) const {
+ unsigned Flags = ELFTargetAsmInfo::SectionFlagsForGlobal(GV, Name);
+ // Mask out Small Section flag bit, Mips doesnt support 's' section symbol
+ // for its small sections.
+ return (Flags & (~SectionFlags::Small));
}
-SectionKind::Kind
-MipsTargetAsmInfo::SectionKindForGlobal(const GlobalValue *GV) const {
- const TargetData *TD = ETM->getTargetData();
- const GlobalVariable *GVA = dyn_cast<GlobalVariable>(GV);
+SectionKind::Kind MipsTargetAsmInfo::
+SectionKindForGlobal(const GlobalValue *GV) const {
+ SectionKind::Kind K = ELFTargetAsmInfo::SectionKindForGlobal(GV);
- if (!GVA)
- return ELFTargetAsmInfo::SectionKindForGlobal(GV);
-
- // if this is a internal constant string, there is a special
- // section for it, but not in small data/bss.
- if (GVA->hasInitializer() && GV->hasInternalLinkage()) {
- Constant *C = GVA->getInitializer();
- const ConstantArray *CVA = dyn_cast<ConstantArray>(C);
- if (CVA && CVA->isCString())
- return ELFTargetAsmInfo::SectionKindForGlobal(GV);
- }
+ if (Subtarget->hasABICall())
+ return K;
+
+ if (K != SectionKind::Data && K != SectionKind::BSS &&
+ K != SectionKind::RODataMergeConst)
+ return K;
- const Type *Ty = GV->getType()->getElementType();
- unsigned Size = TD->getABITypeSize(Ty);
- unsigned Threshold =
- MipsTM->getSubtarget<MipsSubtarget>().getSSectionThreshold();
+ if (isa<GlobalVariable>(GV)) {
+ const TargetData *TD = TM.getTargetData();
+ unsigned Size = TD->getTypePaddedSize(GV->getType()->getElementType());
+ unsigned Threshold = Subtarget->getSSectionThreshold();
- if (Size > 0 && Size <= Threshold) {
- if (isSuitableForBSS(GVA))
- return SectionKind::SmallBSS;
- else
- return SectionKind::SmallData;
+ if (Size > 0 && Size <= Threshold) {
+ if (K == SectionKind::BSS)
+ return SectionKind::SmallBSS;
+ else
+ return SectionKind::SmallData;
+ }
}
- return ELFTargetAsmInfo::SectionKindForGlobal(GV);
+ return K;
}
-const Section*
-MipsTargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV) const {
+const Section* MipsTargetAsmInfo::
+SelectSectionForGlobal(const GlobalValue *GV) const {
SectionKind::Kind K = SectionKindForGlobal(GV);
const GlobalVariable *GVA = dyn_cast<GlobalVariable>(GV);
- if (GVA && (!GVA->isWeakForLinker()))
+ if (GVA && (!GVA->mayBeOverridden()))
switch (K) {
case SectionKind::SmallData:
return getSmallDataSection();