diff options
author | Evan Cheng <evan.cheng@apple.com> | 2008-08-08 06:56:16 +0000 |
---|---|---|
committer | Evan Cheng <evan.cheng@apple.com> | 2008-08-08 06:56:16 +0000 |
commit | 711b6dce246c87b5d830966bed823d0e7aa15300 (patch) | |
tree | 9ecbf910a5d51f5486b38f2db97d122569501a6a /lib | |
parent | 15621a2569c3789a00624aaa0d255eaf3f130b63 (diff) |
It's not legal to output a GV in a coalesced section if it's used in an ARM PIC relative constantpool.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@54519 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Target/ARM/ARMAsmPrinter.cpp | 32 | ||||
-rw-r--r-- | lib/Target/DarwinTargetAsmInfo.cpp | 17 | ||||
-rw-r--r-- | lib/Target/ELFTargetAsmInfo.cpp | 3 | ||||
-rw-r--r-- | lib/Target/Mips/MipsTargetAsmInfo.cpp | 2 | ||||
-rw-r--r-- | lib/Target/Mips/MipsTargetAsmInfo.h | 3 | ||||
-rw-r--r-- | lib/Target/TargetAsmInfo.cpp | 8 |
6 files changed, 41 insertions, 24 deletions
diff --git a/lib/Target/ARM/ARMAsmPrinter.cpp b/lib/Target/ARM/ARMAsmPrinter.cpp index 3b30f9c5a0..420ccd0bcc 100644 --- a/lib/Target/ARM/ARMAsmPrinter.cpp +++ b/lib/Target/ARM/ARMAsmPrinter.cpp @@ -29,6 +29,7 @@ #include "llvm/Target/TargetData.h" #include "llvm/Target/TargetMachine.h" #include "llvm/Target/TargetOptions.h" +#include "llvm/ADT/SmallPtrSet.h" #include "llvm/ADT/Statistic.h" #include "llvm/ADT/StringExtras.h" #include "llvm/Support/Compiler.h" @@ -65,14 +66,18 @@ namespace { typedef std::map<const Value *, unsigned> ValueMapTy; ValueMapTy NumberForBB; - /// Keeps the set of GlobalValues that require non-lazy-pointers for - /// indirect access. + /// GVNonLazyPtrs - Keeps the set of GlobalValues that require + /// non-lazy-pointers for indirect access. std::set<std::string> GVNonLazyPtrs; - /// Keeps the set of external function GlobalAddresses that the asm - /// printer should generate stubs for. + /// FnStubs - Keeps the set of external function GlobalAddresses that the + /// asm printer should generate stubs for. std::set<std::string> FnStubs; + /// PCRelGVs - Keeps the set of GlobalValues used in pc relative + /// constantpool. + SmallPtrSet<const GlobalValue*, 8> PCRelGVs; + /// True if asm printer is printing a series of CONSTPOOL_ENTRY. bool InCPMode; @@ -124,10 +129,12 @@ namespace { /// specified function body into. virtual std::string getSectionForFunction(const Function &F) const; + /// EmitMachineConstantPoolValue - Print a machine constantpool value to + /// the .s file. virtual void EmitMachineConstantPoolValue(MachineConstantPoolValue *MCPV) { printDataDirective(MCPV->getType()); - ARMConstantPoolValue *ACPV = (ARMConstantPoolValue*)MCPV; + ARMConstantPoolValue *ACPV = static_cast<ARMConstantPoolValue*>(MCPV); GlobalValue *GV = ACPV->getGV(); std::string Name = GV ? Mang->getValueName(GV) : TAI->getGlobalPrefix(); if (!GV) @@ -680,9 +687,15 @@ void ARMAsmPrinter::printCPInstOperand(const MachineInstr *MI, int OpNo, const MachineConstantPoolEntry &MCPE = // Chasing pointers is fun? MI->getParent()->getParent()->getConstantPool()->getConstants()[CPI]; - if (MCPE.isMachineConstantPoolEntry()) + if (MCPE.isMachineConstantPoolEntry()) { EmitMachineConstantPoolValue(MCPE.Val.MachineCPVal); - else { + ARMConstantPoolValue *ACPV = + static_cast<ARMConstantPoolValue*>(MCPE.Val.MachineCPVal); + if (ACPV->getPCAdjustment() != 0) { + const GlobalValue *GV = ACPV->getGV(); + PCRelGVs.insert(GV); + } + } else { EmitGlobalConstant(MCPE.Val.ConstVal); // remember to emit the weak reference if (const GlobalValue *GV = dyn_cast<GlobalValue>(MCPE.Val.ConstVal)) @@ -850,7 +863,8 @@ void ARMAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) { return; } - std::string SectionName = TAI->SectionForGlobal(GVar); + bool NoCoalesc = PCRelGVs.count(GVar); + std::string SectionName = TAI->SectionForGlobal(GVar, NoCoalesc); std::string name = Mang->getValueName(GVar); Constant *C = GVar->getInitializer(); const Type *Type = C->getType(); @@ -887,7 +901,7 @@ void ARMAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) { if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it. if (TAI->getLCOMMDirective() != NULL) { - if (GVar->hasInternalLinkage()) { + if (NoCoalesc || GVar->hasInternalLinkage()) { O << TAI->getLCOMMDirective() << name << "," << Size; if (Subtarget->isTargetDarwin()) O << "," << Align; diff --git a/lib/Target/DarwinTargetAsmInfo.cpp b/lib/Target/DarwinTargetAsmInfo.cpp index 749cb71794..978f5cf36a 100644 --- a/lib/Target/DarwinTargetAsmInfo.cpp +++ b/lib/Target/DarwinTargetAsmInfo.cpp @@ -51,14 +51,15 @@ DarwinTargetAsmInfo::DarwinTargetAsmInfo(const TargetMachine &TM) { } const Section* -DarwinTargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV) const { +DarwinTargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV, + bool NoCoalesce) const { SectionKind::Kind Kind = SectionKindForGlobal(GV); - bool isWeak = GV->isWeakForLinker(); + bool CanCoalesce = !NoCoalesce && GV->isWeakForLinker(); bool isNonStatic = (DTM->getRelocationModel() != Reloc::Static); switch (Kind) { case SectionKind::Text: - if (isWeak) + if (CanCoalesce) return TextCoalSection; else return getTextSection_(); @@ -67,18 +68,18 @@ DarwinTargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV) const { case SectionKind::BSS: case SectionKind::ThreadBSS: if (cast<GlobalVariable>(GV)->isConstant()) - return (isWeak ? ConstDataCoalSection : ConstDataSection); + return (CanCoalesce ? ConstDataCoalSection : ConstDataSection); else - return (isWeak ? DataCoalSection : getDataSection_()); + return (CanCoalesce ? DataCoalSection : getDataSection_()); case SectionKind::ROData: - return (isWeak ? ConstDataCoalSection : + return (CanCoalesce ? ConstDataCoalSection : (isNonStatic ? ConstDataSection : getReadOnlySection_())); case SectionKind::RODataMergeStr: - return (isWeak ? + return (CanCoalesce ? ConstDataCoalSection : MergeableStringSection(cast<GlobalVariable>(GV))); case SectionKind::RODataMergeConst: - return (isWeak ? + return (CanCoalesce ? ConstDataCoalSection: MergeableConstSection(cast<GlobalVariable>(GV))); default: diff --git a/lib/Target/ELFTargetAsmInfo.cpp b/lib/Target/ELFTargetAsmInfo.cpp index 82ac847e84..523527c7b6 100644 --- a/lib/Target/ELFTargetAsmInfo.cpp +++ b/lib/Target/ELFTargetAsmInfo.cpp @@ -40,7 +40,8 @@ ELFTargetAsmInfo::ELFTargetAsmInfo(const TargetMachine &TM) { } const Section* -ELFTargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV) const { +ELFTargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV, + bool NoCoalesce) const { SectionKind::Kind Kind = SectionKindForGlobal(GV); if (const Function *F = dyn_cast<Function>(GV)) { diff --git a/lib/Target/Mips/MipsTargetAsmInfo.cpp b/lib/Target/Mips/MipsTargetAsmInfo.cpp index 04edd0d4b5..eff69abc6d 100644 --- a/lib/Target/Mips/MipsTargetAsmInfo.cpp +++ b/lib/Target/Mips/MipsTargetAsmInfo.cpp @@ -82,7 +82,7 @@ SectionKindForGlobal(const GlobalValue *GV) const { } const Section* MipsTargetAsmInfo:: -SelectSectionForGlobal(const GlobalValue *GV) const { +SelectSectionForGlobal(const GlobalValue *GV, bool NoCoalesce) const { SectionKind::Kind K = SectionKindForGlobal(GV); const GlobalVariable *GVA = dyn_cast<GlobalVariable>(GV); diff --git a/lib/Target/Mips/MipsTargetAsmInfo.h b/lib/Target/Mips/MipsTargetAsmInfo.h index 2b5a739e72..806cda8be3 100644 --- a/lib/Target/Mips/MipsTargetAsmInfo.h +++ b/lib/Target/Mips/MipsTargetAsmInfo.h @@ -40,7 +40,8 @@ namespace llvm { SectionFlagsForGlobal(const GlobalValue *GV = NULL, const char* name = NULL) const; - virtual const Section* SelectSectionForGlobal(const GlobalValue *GV) const; + virtual const Section* SelectSectionForGlobal(const GlobalValue *GV, + bool NoCoalesce) const; private: const MipsSubtarget *Subtarget; diff --git a/lib/Target/TargetAsmInfo.cpp b/lib/Target/TargetAsmInfo.cpp index 9bc0b4055e..cf43112634 100644 --- a/lib/Target/TargetAsmInfo.cpp +++ b/lib/Target/TargetAsmInfo.cpp @@ -272,7 +272,7 @@ TargetAsmInfo::SectionFlagsForGlobal(const GlobalValue *GV, } std::string -TargetAsmInfo::SectionForGlobal(const GlobalValue *GV) const { +TargetAsmInfo::SectionForGlobal(const GlobalValue *GV, bool NoCoalesce) const { const Section* S; // Select section name if (GV->hasSection()) { @@ -282,7 +282,7 @@ TargetAsmInfo::SectionForGlobal(const GlobalValue *GV) const { S = getNamedSection(GV->getSection().c_str(), Flags); } else { // Use default section depending on the 'type' of global - S = SelectSectionForGlobal(GV); + S = SelectSectionForGlobal(GV, NoCoalesce); } if (!S->isNamed()) @@ -295,8 +295,8 @@ TargetAsmInfo::SectionForGlobal(const GlobalValue *GV) const { } // Lame default implementation. Calculate the section name for global. -const Section* -TargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV) const { +const Section* TargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV, + bool NoCoalesce) const { SectionKind::Kind Kind = SectionKindForGlobal(GV); if (GV->isWeakForLinker()) { |