diff options
author | Anton Korobeynikov <asl@math.spbu.ru> | 2008-08-07 09:54:23 +0000 |
---|---|---|
committer | Anton Korobeynikov <asl@math.spbu.ru> | 2008-08-07 09:54:23 +0000 |
commit | 0f3cc657387d44cd7c56e4ddea896a50ab9106b8 (patch) | |
tree | 986da786619ef83826de9e251ff958929c7b49c6 /lib/Target/ARM/ARMAsmPrinter.cpp | |
parent | 79579c911f073073ab2108de71f09a4d6021760c (diff) |
Switch ARM to new section handling stuff
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@54458 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Target/ARM/ARMAsmPrinter.cpp')
-rw-r--r-- | lib/Target/ARM/ARMAsmPrinter.cpp | 265 |
1 files changed, 113 insertions, 152 deletions
diff --git a/lib/Target/ARM/ARMAsmPrinter.cpp b/lib/Target/ARM/ARMAsmPrinter.cpp index b853a84d40..3b30f9c5a0 100644 --- a/lib/Target/ARM/ARMAsmPrinter.cpp +++ b/lib/Target/ARM/ARMAsmPrinter.cpp @@ -113,12 +113,17 @@ namespace { virtual bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo, unsigned AsmVariant, const char *ExtraCode); + void printModuleLevelGV(const GlobalVariable* GVar); bool printInstruction(const MachineInstr *MI); // autogenerated. void printMachineInstruction(const MachineInstr *MI); bool runOnMachineFunction(MachineFunction &F); bool doInitialization(Module &M); bool doFinalization(Module &M); + /// getSectionForFunction - Return the section that we should emit the + /// specified function body into. + virtual std::string getSectionForFunction(const Function &F) const; + virtual void EmitMachineConstantPoolValue(MachineConstantPoolValue *MCPV) { printDataDirective(MCPV->getType()); @@ -172,6 +177,11 @@ FunctionPass *llvm::createARMCodePrinterPass(std::ostream &o, return new ARMAsmPrinter(o, tm, tm.getTargetAsmInfo()); } +// Substitute old hook with new one temporary +std::string ARMAsmPrinter::getSectionForFunction(const Function &F) const { + return TAI->SectionForGlobal(&F); +} + /// runOnMachineFunction - This uses the printInstruction() /// method to print assembly for each instruction. /// @@ -821,176 +831,127 @@ static void PrintUnmangledNameSafely(const Value *V, std::ostream &OS) { OS << *Name; } -bool ARMAsmPrinter::doFinalization(Module &M) { +void ARMAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) { const TargetData *TD = TM.getTargetData(); - for (Module::const_global_iterator I = M.global_begin(), E = M.global_end(); - I != E; ++I) { - if (!I->hasInitializer()) // External global require no code - continue; - - if (EmitSpecialLLVMGlobal(I)) { - if (Subtarget->isTargetDarwin() && - TM.getRelocationModel() == Reloc::Static) { - if (I->getName() == "llvm.global_ctors") - O << ".reference .constructors_used\n"; - else if (I->getName() == "llvm.global_dtors") - O << ".reference .destructors_used\n"; - } - continue; + if (!GVar->hasInitializer()) // External global require no code + return; + + // Check to see if this is a special global used by LLVM, if so, emit it. + + if (EmitSpecialLLVMGlobal(GVar)) { + if (Subtarget->isTargetDarwin() && + TM.getRelocationModel() == Reloc::Static) { + if (GVar->getName() == "llvm.global_ctors") + O << ".reference .constructors_used\n"; + else if (GVar->getName() == "llvm.global_dtors") + O << ".reference .destructors_used\n"; } + return; + } + + std::string SectionName = TAI->SectionForGlobal(GVar); + std::string name = Mang->getValueName(GVar); + Constant *C = GVar->getInitializer(); + const Type *Type = C->getType(); + unsigned Size = TD->getABITypeSize(Type); + unsigned Align = TD->getPreferredAlignmentLog(GVar); - std::string name = Mang->getValueName(I); - Constant *C = I->getInitializer(); - const Type *Type = C->getType(); - unsigned Size = TD->getABITypeSize(Type); - unsigned Align = TD->getPreferredAlignmentLog(I); + const char *VisibilityDirective = NULL; + if (GVar->hasHiddenVisibility()) + VisibilityDirective = TAI->getHiddenDirective(); + else if (GVar->hasProtectedVisibility()) + VisibilityDirective = TAI->getProtectedDirective(); - const char *VisibilityDirective = NULL; - if (I->hasHiddenVisibility()) - VisibilityDirective = TAI->getHiddenDirective(); - else if (I->hasProtectedVisibility()) - VisibilityDirective = TAI->getProtectedDirective(); + if (VisibilityDirective) + O << VisibilityDirective << name << "\n"; - if (VisibilityDirective) - O << VisibilityDirective << name << "\n"; + if (Subtarget->isTargetELF()) + O << "\t.type " << name << ",%object\n"; - if (Subtarget->isTargetELF()) - O << "\t.type " << name << ",%object\n"; - - if (C->isNullValue() && !I->hasSection() && !I->isThreadLocal()) { - if (I->hasExternalLinkage()) { - if (const char *Directive = TAI->getZeroFillDirective()) { - O << "\t.globl\t" << name << "\n"; - O << Directive << "__DATA, __common, " << name << ", " - << Size << ", " << Align << "\n"; - continue; - } - } + SwitchToDataSection(SectionName.c_str()); - if (I->hasInternalLinkage() || I->hasWeakLinkage() || - I->hasLinkOnceLinkage()) { - if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it. - if (!NoZerosInBSS && TAI->getBSSSection()) - SwitchToDataSection(TAI->getBSSSection(), I); - else - SwitchToDataSection(TAI->getDataSection(), I); - if (TAI->getLCOMMDirective() != NULL) { - if (I->hasInternalLinkage()) { - O << TAI->getLCOMMDirective() << name << "," << Size; - if (Subtarget->isTargetDarwin()) - O << "," << Align; - } else - O << TAI->getCOMMDirective() << name << "," << Size; - } else { - if (I->hasInternalLinkage()) - O << "\t.local\t" << name << "\n"; - O << TAI->getCOMMDirective() << name << "," << Size; - if (TAI->getCOMMDirectiveTakesAlignment()) - O << "," << (TAI->getAlignmentIsInBytes() ? (1 << Align) : Align); - } - O << "\t\t" << TAI->getCommentString() << " "; - PrintUnmangledNameSafely(I, O); - O << "\n"; - continue; + if (C->isNullValue() && !GVar->hasSection() && !GVar->isThreadLocal()) { + // FIXME: This seems to be pretty darwin-specific + + if (GVar->hasExternalLinkage()) { + if (const char *Directive = TAI->getZeroFillDirective()) { + O << "\t.globl\t" << name << "\n"; + O << Directive << "__DATA, __common, " << name << ", " + << Size << ", " << Align << "\n"; + return; } } - switch (I->getLinkage()) { - case GlobalValue::LinkOnceLinkage: - case GlobalValue::WeakLinkage: - if (Subtarget->isTargetDarwin()) { - O << "\t.globl " << name << "\n" - << "\t.weak_definition " << name << "\n"; - SwitchToDataSection("\t.section __DATA,__datacoal_nt,coalesced", I); - } else { - std::string SectionName("\t.section\t.llvm.linkonce.d." + - name + - ",\"aw\",%progbits"); - SwitchToDataSection(SectionName.c_str(), I); - O << "\t.weak " << name << "\n"; - } - break; - case GlobalValue::AppendingLinkage: - // FIXME: appending linkage variables should go into a section of - // their name or something. For now, just emit them as external. - case GlobalValue::ExternalLinkage: - O << "\t.globl " << name << "\n"; - // FALL THROUGH - case GlobalValue::InternalLinkage: { - if (I->isConstant()) { - const ConstantArray *CVA = dyn_cast<ConstantArray>(C); - if (TAI->getCStringSection() && CVA && CVA->isCString()) { - SwitchToDataSection(TAI->getCStringSection(), I); - break; - } - } - // FIXME: special handling for ".ctors" & ".dtors" sections - if (I->hasSection() && - (I->getSection() == ".ctors" || - I->getSection() == ".dtors")) { - assert(!Subtarget->isTargetDarwin()); - std::string SectionName = ".section " + I->getSection(); - SectionName += ",\"aw\",%progbits"; - SwitchToDataSection(SectionName.c_str()); - } else if (I->hasSection() && Subtarget->isTargetDarwin()) { - // Honor all section names on Darwin; ObjC uses this - std::string SectionName = ".section " + I->getSection(); - SwitchToDataSection(SectionName.c_str()); + if (GVar->hasInternalLinkage() || GVar->isWeakForLinker()) { + if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it. + + if (TAI->getLCOMMDirective() != NULL) { + if (GVar->hasInternalLinkage()) { + O << TAI->getLCOMMDirective() << name << "," << Size; + if (Subtarget->isTargetDarwin()) + O << "," << Align; + } else + O << TAI->getCOMMDirective() << name << "," << Size; } else { - if (C->isNullValue() && !NoZerosInBSS && TAI->getBSSSection()) - SwitchToDataSection(I->isThreadLocal() ? TAI->getTLSBSSSection() : - TAI->getBSSSection(), I); - else if (!I->isConstant()) - SwitchToDataSection(I->isThreadLocal() ? TAI->getTLSDataSection() : - TAI->getDataSection(), I); - else if (I->isThreadLocal()) - SwitchToDataSection(TAI->getTLSDataSection()); - else { - // Read-only data. - bool HasReloc = C->ContainsRelocations(); - if (HasReloc && - Subtarget->isTargetDarwin() && - TM.getRelocationModel() != Reloc::Static) - SwitchToDataSection("\t.const_data\n"); - else if (!HasReloc && Size == 4 && - TAI->getFourByteConstantSection()) - SwitchToDataSection(TAI->getFourByteConstantSection(), I); - else if (!HasReloc && Size == 8 && - TAI->getEightByteConstantSection()) - SwitchToDataSection(TAI->getEightByteConstantSection(), I); - else if (!HasReloc && Size == 16 && - TAI->getSixteenByteConstantSection()) - SwitchToDataSection(TAI->getSixteenByteConstantSection(), I); - else if (TAI->getReadOnlySection()) - SwitchToDataSection(TAI->getReadOnlySection(), I); - else - SwitchToDataSection(TAI->getDataSection(), I); - } + if (GVar->hasInternalLinkage()) + O << "\t.local\t" << name << "\n"; + O << TAI->getCOMMDirective() << name << "," << Size; + if (TAI->getCOMMDirectiveTakesAlignment()) + O << "," << (TAI->getAlignmentIsInBytes() ? (1 << Align) : Align); } - - break; + O << "\t\t" << TAI->getCommentString() << " "; + PrintUnmangledNameSafely(GVar, O); + O << "\n"; + return; } - default: - assert(0 && "Unknown linkage type!"); - break; + } + + switch (GVar->getLinkage()) { + case GlobalValue::LinkOnceLinkage: + case GlobalValue::WeakLinkage: + if (Subtarget->isTargetDarwin()) { + O << "\t.globl " << name << "\n" + << "\t.weak_definition " << name << "\n"; + } else { + O << "\t.weak " << name << "\n"; } + break; + case GlobalValue::AppendingLinkage: + // FIXME: appending linkage variables should go into a section of + // their name or something. For now, just emit them as external. + case GlobalValue::ExternalLinkage: + O << "\t.globl " << name << "\n"; + // FALL THROUGH + case GlobalValue::InternalLinkage: + break; + default: + assert(0 && "Unknown linkage type!"); + break; + } - EmitAlignment(Align, I); - O << name << ":\t\t\t\t" << TAI->getCommentString() << " "; - PrintUnmangledNameSafely(I, O); - O << "\n"; - if (TAI->hasDotTypeDotSizeDirective()) - O << "\t.size " << name << ", " << Size << "\n"; - // If the initializer is a extern weak symbol, remember to emit the weak - // reference! - if (const GlobalValue *GV = dyn_cast<GlobalValue>(C)) - if (GV->hasExternalWeakLinkage()) + EmitAlignment(Align, GVar); + O << name << ":\t\t\t\t" << TAI->getCommentString() << " "; + PrintUnmangledNameSafely(GVar, O); + O << "\n"; + if (TAI->hasDotTypeDotSizeDirective()) + O << "\t.size " << name << ", " << Size << "\n"; + + // If the initializer is a extern weak symbol, remember to emit the weak + // reference! + if (const GlobalValue *GV = dyn_cast<GlobalValue>(C)) + if (GV->hasExternalWeakLinkage()) ExtWeakSymbols.insert(GV); - EmitGlobalConstant(C); - O << '\n'; - } + EmitGlobalConstant(C); + O << '\n'; +} + + +bool ARMAsmPrinter::doFinalization(Module &M) { + for (Module::const_global_iterator I = M.global_begin(), E = M.global_end(); + I != E; ++I) + printModuleLevelGV(I); if (Subtarget->isTargetDarwin()) { SwitchToDataSection(""); |