2007-06-06 07:42:06 +00:00
|
|
|
//===-- MipsTargetAsmInfo.cpp - Mips asm properties -------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 20:36:04 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2007-06-06 07:42:06 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file contains the declarations of the MipsTargetAsmInfo properties.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "MipsTargetAsmInfo.h"
|
2007-11-12 19:49:57 +00:00
|
|
|
#include "MipsTargetMachine.h"
|
2007-06-06 07:42:06 +00:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
2008-07-19 13:16:11 +00:00
|
|
|
MipsTargetAsmInfo::MipsTargetAsmInfo(const MipsTargetMachine &TM):
|
|
|
|
ELFTargetAsmInfo(TM) {
|
2008-07-14 14:42:54 +00:00
|
|
|
|
2008-07-22 15:34:27 +00:00
|
|
|
MipsTM = &TM;
|
|
|
|
|
2008-07-14 14:42:54 +00:00
|
|
|
AlignmentIsInBytes = false;
|
|
|
|
COMMDirectiveTakesAlignment = true;
|
|
|
|
Data16bitsDirective = "\t.half\t";
|
|
|
|
Data32bitsDirective = "\t.word\t";
|
|
|
|
Data64bitsDirective = NULL;
|
|
|
|
PrivateGlobalPrefix = "$";
|
|
|
|
JumpTableDataSection = "\t.rdata";
|
|
|
|
CommentString = "#";
|
|
|
|
ReadOnlySection = "\t.rdata";
|
|
|
|
ZeroDirective = "\t.space\t";
|
|
|
|
BSSSection = "\t.section\t.bss";
|
|
|
|
LCOMMDirective = "\t.lcomm\t";
|
2008-07-21 18:52:34 +00:00
|
|
|
CStringSection = ".rodata.str";
|
2007-11-12 19:49:57 +00:00
|
|
|
|
2008-07-15 02:03:36 +00:00
|
|
|
if (!TM.getSubtarget<MipsSubtarget>().hasABICall())
|
2007-11-12 19:49:57 +00:00
|
|
|
JumpTableDirective = "\t.word\t";
|
2008-07-19 13:16:11 +00:00
|
|
|
else
|
2007-11-12 19:49:57 +00:00
|
|
|
JumpTableDirective = "\t.gpword\t";
|
2008-07-22 15:34:27 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
SectionKind::Kind
|
|
|
|
MipsTargetAsmInfo::SectionKindForGlobal(const GlobalValue *GV) const {
|
|
|
|
const TargetData *TD = ETM->getTargetData();
|
|
|
|
const GlobalVariable *GVA = dyn_cast<GlobalVariable>(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);
|
|
|
|
}
|
|
|
|
|
|
|
|
const Type *Ty = GV->getType()->getElementType();
|
|
|
|
unsigned Size = TD->getABITypeSize(Ty);
|
|
|
|
unsigned Threshold =
|
|
|
|
MipsTM->getSubtarget<MipsSubtarget>().getSSectionThreshold();
|
|
|
|
|
|
|
|
if (Size > 0 && Size <= Threshold) {
|
|
|
|
if (isSuitableForBSS(GVA))
|
|
|
|
return SectionKind::SmallBSS;
|
|
|
|
else
|
|
|
|
return SectionKind::SmallData;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ELFTargetAsmInfo::SectionKindForGlobal(GV);
|
|
|
|
}
|
|
|
|
|
|
|
|
const Section*
|
|
|
|
MipsTargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV) const {
|
|
|
|
SectionKind::Kind K = SectionKindForGlobal(GV);
|
|
|
|
const GlobalVariable *GVA = dyn_cast<GlobalVariable>(GV);
|
|
|
|
|
|
|
|
if (GVA && (!GVA->isWeakForLinker()))
|
|
|
|
switch (K) {
|
|
|
|
case SectionKind::SmallData:
|
|
|
|
return getSmallDataSection();
|
|
|
|
case SectionKind::SmallBSS:
|
|
|
|
return getSmallBSSSection();
|
|
|
|
default: break;
|
|
|
|
}
|
2007-11-12 19:49:57 +00:00
|
|
|
|
2008-07-22 15:34:27 +00:00
|
|
|
return ELFTargetAsmInfo::SelectSectionForGlobal(GV);
|
2007-06-06 07:42:06 +00:00
|
|
|
}
|