aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Target/TargetAsmInfo.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-07-28 03:13:23 +0000
committerChris Lattner <sabre@nondot.org>2009-07-28 03:13:23 +0000
commitf0144127b98425d214e59e4a1a4b342b78e3642b (patch)
treecfcb5bc95b5b8060f71ee1b251f0f3e93fbfff2a /lib/Target/TargetAsmInfo.cpp
parent7988aff079c54583d7f4d0011ffcfa3d62ff6a85 (diff)
downloadexternal_llvm-f0144127b98425d214e59e4a1a4b342b78e3642b.tar.gz
external_llvm-f0144127b98425d214e59e4a1a4b342b78e3642b.tar.bz2
external_llvm-f0144127b98425d214e59e4a1a4b342b78e3642b.zip
Rip all of the global variable lowering logic out of TargetAsmInfo. Since
it is highly specific to the object file that will be generated in the end, this introduces a new TargetLoweringObjectFile interface that is implemented for each of ELF/MachO/COFF/Alpha/PIC16 and XCore. Though still is still a brutal and ugly refactoring, this is a major step towards goodness. This patch also: 1. fixes a bunch of dangling pointer problems in the PIC16 backend. 2. disables the TargetLowering copy ctor which PIC16 was accidentally using. 3. gets us closer to xcore having its own crazy target section flags and pic16 not having to shadow sections with its own objects. 4. fixes wierdness where ELF targets would set CStringSection but not CStringSection_. Factor the code better. 5. fixes some bugs in string lowering on ELF targets. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@77294 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Target/TargetAsmInfo.cpp')
-rw-r--r--lib/Target/TargetAsmInfo.cpp218
1 files changed, 0 insertions, 218 deletions
diff --git a/lib/Target/TargetAsmInfo.cpp b/lib/Target/TargetAsmInfo.cpp
index 1cb085bcd1..e71bd01aae 100644
--- a/lib/Target/TargetAsmInfo.cpp
+++ b/lib/Target/TargetAsmInfo.cpp
@@ -30,10 +30,6 @@ using namespace llvm;
TargetAsmInfo::TargetAsmInfo(const TargetMachine &tm) : TM(tm) {
BSSSection = "\t.bss";
- BSSSection_ = 0;
- ReadOnlySection = 0;
- TLSDataSection = 0;
- TLSBSSSection = 0;
ZeroFillDirective = 0;
NonexecutableStackDirective = 0;
NeedsSet = false;
@@ -78,7 +74,6 @@ TargetAsmInfo::TargetAsmInfo(const TargetMachine &tm) : TM(tm) {
JumpTableDataSection = "\t.section .rodata";
JumpTableDirective = 0;
CStringSection = 0;
- CStringSection_ = 0;
// FIXME: Flags are ELFish - replace with normal section stuff.
StaticCtorsSection = "\t.section .ctors,\"aw\",@progbits";
StaticDtorsSection = "\t.section .dtors,\"aw\",@progbits";
@@ -158,219 +153,6 @@ unsigned TargetAsmInfo::PreferredEHDataFormat(DwarfEncoding::Target Reason,
return dwarf::DW_EH_PE_absptr;
}
-static bool isSuitableForBSS(const GlobalVariable *GV) {
- Constant *C = GV->getInitializer();
-
- // Must have zero initializer.
- if (!C->isNullValue())
- return false;
-
- // Leave constant zeros in readonly constant sections, so they can be shared.
- if (GV->isConstant())
- return false;
-
- // If the global has an explicit section specified, don't put it in BSS.
- if (!GV->getSection().empty())
- return false;
-
- // If -nozero-initialized-in-bss is specified, don't ever use BSS.
- if (NoZerosInBSS)
- return false;
-
- // Otherwise, put it in BSS!
- return true;
-}
-
-static bool isConstantString(const Constant *C) {
- // First check: is we have constant array of i8 terminated with zero
- const ConstantArray *CVA = dyn_cast<ConstantArray>(C);
- // Check, if initializer is a null-terminated string
- if (CVA && CVA->isCString())
- return true;
-
- // Another possibility: [1 x i8] zeroinitializer
- if (isa<ConstantAggregateZero>(C))
- if (const ArrayType *Ty = dyn_cast<ArrayType>(C->getType()))
- return (Ty->getElementType() == Type::Int8Ty &&
- Ty->getNumElements() == 1);
-
- return false;
-}
-
-static SectionKind::Kind SectionKindForGlobal(const GlobalValue *GV,
- const TargetMachine &TM) {
- Reloc::Model ReloModel = TM.getRelocationModel();
-
- // Early exit - functions should be always in text sections.
- const GlobalVariable *GVar = dyn_cast<GlobalVariable>(GV);
- if (GVar == 0)
- return SectionKind::Text;
-
-
- // Handle thread-local data first.
- if (GVar->isThreadLocal()) {
- if (isSuitableForBSS(GVar))
- return SectionKind::ThreadBSS;
- return SectionKind::ThreadData;
- }
-
- // Variable can be easily put to BSS section.
- if (isSuitableForBSS(GVar))
- return SectionKind::BSS;
-
- Constant *C = GVar->getInitializer();
-
- // If the global is marked constant, we can put it into a mergable section,
- // a mergable string section, or general .data if it contains relocations.
- if (GVar->isConstant()) {
- // If the initializer for the global contains something that requires a
- // relocation, then we may have to drop this into a wriable data section
- // even though it is marked const.
- switch (C->getRelocationInfo()) {
- default: llvm_unreachable("unknown relocation info kind");
- case Constant::NoRelocation:
- // If initializer is a null-terminated string, put it in a "cstring"
- // section if the target has it.
- if (isConstantString(C))
- return SectionKind::MergeableCString;
-
- // Otherwise, just drop it into a mergable constant section. If we have
- // a section for this size, use it, otherwise use the arbitrary sized
- // mergable section.
- switch (TM.getTargetData()->getTypeAllocSize(C->getType())) {
- case 4: return SectionKind::MergeableConst4;
- case 8: return SectionKind::MergeableConst8;
- case 16: return SectionKind::MergeableConst16;
- default: return SectionKind::MergeableConst;
- }
-
- case Constant::LocalRelocation:
- // In static relocation model, the linker will resolve all addresses, so
- // the relocation entries will actually be constants by the time the app
- // starts up. However, we can't put this into a mergable section, because
- // the linker doesn't take relocations into consideration when it tries to
- // merge entries in the section.
- if (ReloModel == Reloc::Static)
- return SectionKind::ReadOnly;
-
- // Otherwise, the dynamic linker needs to fix it up, put it in the
- // writable data.rel.local section.
- return SectionKind::ReadOnlyWithRelLocal;
-
- case Constant::GlobalRelocations:
- // In static relocation model, the linker will resolve all addresses, so
- // the relocation entries will actually be constants by the time the app
- // starts up. However, we can't put this into a mergable section, because
- // the linker doesn't take relocations into consideration when it tries to
- // merge entries in the section.
- if (ReloModel == Reloc::Static)
- return SectionKind::ReadOnly;
-
- // Otherwise, the dynamic linker needs to fix it up, put it in the
- // writable data.rel section.
- return SectionKind::ReadOnlyWithRel;
- }
- }
-
- // Okay, this isn't a constant. If the initializer for the global is going
- // to require a runtime relocation by the dynamic linker, put it into a more
- // specific section to improve startup time of the app. This coalesces these
- // globals together onto fewer pages, improving the locality of the dynamic
- // linker.
- if (ReloModel == Reloc::Static)
- return SectionKind::DataNoRel;
-
- switch (C->getRelocationInfo()) {
- default: llvm_unreachable("unknown relocation info kind");
- case Constant::NoRelocation:
- return SectionKind::DataNoRel;
- case Constant::LocalRelocation:
- return SectionKind::DataRelLocal;
- case Constant::GlobalRelocations:
- return SectionKind::DataRel;
- }
-}
-
-/// SectionForGlobal - This method computes the appropriate section to emit
-/// the specified global variable or function definition. This should not
-/// be passed external (or available externally) globals.
-const Section *TargetAsmInfo::SectionForGlobal(const GlobalValue *GV) const {
- assert(!GV->isDeclaration() && !GV->hasAvailableExternallyLinkage() &&
- "Can only be used for global definitions");
-
- SectionKind::Kind GVKind = SectionKindForGlobal(GV, TM);
-
- SectionKind Kind = SectionKind::get(GVKind, GV->isWeakForLinker(),
- GV->hasSection());
-
-
- // Select section name.
- if (GV->hasSection()) {
- // If the target has special section hacks for specifically named globals,
- // return them now.
- if (const Section *TS = getSpecialCasedSectionGlobals(GV, Kind))
- return TS;
-
- // If the target has magic semantics for certain section names, make sure to
- // pick up the flags. This allows the user to write things with attribute
- // section and still get the appropriate section flags printed.
- GVKind = getKindForNamedSection(GV->getSection().c_str(), GVKind);
-
- return getOrCreateSection(GV->getSection().c_str(), false, GVKind);
- }
-
-
- // Use default section depending on the 'type' of global
- return SelectSectionForGlobal(GV, Kind);
-}
-
-// Lame default implementation. Calculate the section name for global.
-const Section*
-TargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV,
- SectionKind Kind) const {
- assert(!Kind.isThreadLocal() && "Doesn't support TLS");
-
- if (Kind.isText())
- return getTextSection();
-
- if (Kind.isBSS())
- if (const Section *S = getBSSSection_())
- return S;
-
- if (Kind.isReadOnly())
- if (const Section *S = getReadOnlySection())
- return S;
-
- return getDataSection();
-}
-
-/// getSectionForMergableConstant - Given a mergable constant with the
-/// specified size and relocation information, return a section that it
-/// should be placed in.
-const Section *
-TargetAsmInfo::getSectionForMergeableConstant(SectionKind Kind) const {
- if (Kind.isReadOnly())
- if (const Section *S = getReadOnlySection())
- return S;
-
- return getDataSection();
-}
-
-
-const Section *TargetAsmInfo::getOrCreateSection(const char *Name,
- bool isDirective,
- SectionKind::Kind Kind) const {
- Section &S = Sections[Name];
-
- // This is newly-created section, set it up properly.
- if (S.Name.empty()) {
- S.Kind = SectionKind::get(Kind, false /*weak*/, !isDirective);
- S.Name = Name;
- }
-
- return &S;
-}
-
unsigned TargetAsmInfo::getULEB128Size(unsigned Value) {
unsigned Size = 0;
do {