diff options
| author | Chris Lattner <sabre@nondot.org> | 2009-07-22 00:05:44 +0000 |
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2009-07-22 00:05:44 +0000 |
| commit | 4565ef5b65b7d0b778b41836d70b806196cc8e24 (patch) | |
| tree | 6938ad8daf6bcadd6914dcc163a1ebb7ac57d678 /llvm/lib | |
| parent | 71dfd782ce8b4523ae1200011074d1cea02978bd (diff) | |
| download | bcm5719-llvm-4565ef5b65b7d0b778b41836d70b806196cc8e24.tar.gz bcm5719-llvm-4565ef5b65b7d0b778b41836d70b806196cc8e24.zip | |
reimplement Constant::ContainsRelocations as
Constant::getRelocationInfo(), which has a much simpler
to use API. It still should not be part of libvmcore, but
is better than it was. Also teach it to be smart about
hidden visibility.
llvm-svn: 76700
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/CodeGen/MachineFunction.cpp | 14 | ||||
| -rw-r--r-- | llvm/lib/Target/ELFTargetAsmInfo.cpp | 18 | ||||
| -rw-r--r-- | llvm/lib/Target/TargetAsmInfo.cpp | 4 | ||||
| -rw-r--r-- | llvm/lib/VMCore/Constants.cpp | 47 |
4 files changed, 36 insertions, 47 deletions
diff --git a/llvm/lib/CodeGen/MachineFunction.cpp b/llvm/lib/CodeGen/MachineFunction.cpp index 682b8a7388a..9d6669b0852 100644 --- a/llvm/lib/CodeGen/MachineFunction.cpp +++ b/llvm/lib/CodeGen/MachineFunction.cpp @@ -547,19 +547,7 @@ const Type *MachineConstantPoolEntry::getType() const { unsigned MachineConstantPoolEntry::getRelocationInfo() const { if (isMachineConstantPoolEntry()) return Val.MachineCPVal->getRelocationInfo(); - - // FIXME: This API sucks. - - // If no relocations, return 0. - if (!Val.ConstVal->ContainsRelocations()) - return 0; - - // If it contains no global relocations, return 1. - if (!Val.ConstVal->ContainsRelocations(Reloc::Global)) - return 1; - - // Otherwise, it has general relocations. - return 2; + return Val.ConstVal->getRelocationInfo(); } MachineConstantPool::~MachineConstantPool() { diff --git a/llvm/lib/Target/ELFTargetAsmInfo.cpp b/llvm/lib/Target/ELFTargetAsmInfo.cpp index 5deabee0ba2..1bcfaf91ad0 100644 --- a/llvm/lib/Target/ELFTargetAsmInfo.cpp +++ b/llvm/lib/Target/ELFTargetAsmInfo.cpp @@ -54,20 +54,20 @@ ELFTargetAsmInfo::SectionKindForGlobal(const GlobalValue *GV) const { // Decide, whether we need data.rel stuff const GlobalVariable* GVar = dyn_cast<GlobalVariable>(GV); - if (GVar->hasInitializer()) { + if (GVar->hasInitializer() && TM.getRelocationModel() != Reloc::Static) { Constant *C = GVar->getInitializer(); bool isConstant = GVar->isConstant(); - // By default - all relocations in PIC mode would force symbol to be // placed in r/w section. - if (TM.getRelocationModel() != Reloc::Static && - C->ContainsRelocations(Reloc::LocalOrGlobal)) - return (C->ContainsRelocations(Reloc::Global) ? - (isConstant ? - SectionKind::DataRelRO : SectionKind::DataRel) : - (isConstant ? - SectionKind::DataRelROLocal : SectionKind::DataRelLocal)); + switch (C->getRelocationInfo()) { + default: break; + case 1: + return isConstant ? SectionKind::DataRelROLocal : + SectionKind::DataRelLocal; + case 2: + return isConstant ? SectionKind::DataRelRO : SectionKind::DataRel; + } } return Kind; diff --git a/llvm/lib/Target/TargetAsmInfo.cpp b/llvm/lib/Target/TargetAsmInfo.cpp index 580c3fe4db0..96814fee4c9 100644 --- a/llvm/lib/Target/TargetAsmInfo.cpp +++ b/llvm/lib/Target/TargetAsmInfo.cpp @@ -202,13 +202,13 @@ TargetAsmInfo::SectionKindForGlobal(const GlobalValue *GV) const { if (isSuitableForBSS(GVar)) { // Variable can be easily put to BSS section. - return (isThreadLocal ? SectionKind::ThreadBSS : SectionKind::BSS); + return isThreadLocal ? SectionKind::ThreadBSS : SectionKind::BSS; } else if (GVar->isConstant() && !isThreadLocal) { // Now we know, that variable has initializer and it is constant. We need to // check its initializer to decide, which section to output it into. Also // note, there is no thread-local r/o section. Constant *C = GVar->getInitializer(); - if (C->ContainsRelocations(Reloc::LocalOrGlobal)) { + if (C->getRelocationInfo() != 0) { // Decide whether it is still possible to put symbol into r/o section. if (TM.getRelocationModel() != Reloc::Static) return SectionKind::Data; diff --git a/llvm/lib/VMCore/Constants.cpp b/llvm/lib/VMCore/Constants.cpp index e64b0c4ff50..2eb73398c5b 100644 --- a/llvm/lib/VMCore/Constants.cpp +++ b/llvm/lib/VMCore/Constants.cpp @@ -101,34 +101,35 @@ bool Constant::canTrap() const { } } -/// ContainsRelocations - Return true if the constant value contains relocations -/// which cannot be resolved at compile time. Kind argument is used to filter -/// only 'interesting' sorts of relocations. -bool Constant::ContainsRelocations(unsigned Kind) const { - if (const GlobalValue* GV = dyn_cast<GlobalValue>(this)) { - bool isLocal = GV->hasLocalLinkage(); - if ((Kind & Reloc::Local) && isLocal) { - // Global has local linkage and 'local' kind of relocations are - // requested - return true; - } - - if ((Kind & Reloc::Global) && !isLocal) { - // Global has non-local linkage and 'global' kind of relocations are - // requested - return true; - } - return false; +/// getRelocationInfo - This method classifies the entry according to +/// whether or not it may generate a relocation entry. This must be +/// conservative, so if it might codegen to a relocatable entry, it should say +/// so. The return values are: +/// +/// 0: This constant pool entry is guaranteed to never have a relocation +/// applied to it (because it holds a simple constant like '4'). +/// 1: This entry has relocations, but the entries are guaranteed to be +/// resolvable by the static linker, so the dynamic linker will never see +/// them. +/// 2: This entry may have arbitrary relocations. +/// +/// FIXME: This really should not be in VMCore. +unsigned Constant::getRelocationInfo() const { + if (const GlobalValue* GV = dyn_cast<GlobalValue>(this)) { + if (GV->hasLocalLinkage() || GV->hasHiddenVisibility()) + return 1; // Local to this file/library. + return 2; // Global reference. } - + + unsigned Result = 0; for (unsigned i = 0, e = getNumOperands(); i != e; ++i) - if (getOperand(i)->ContainsRelocations(Kind)) - return true; - - return false; + Result = std::max(Result, getOperand(i)->getRelocationInfo()); + + return Result; } + /// getVectorElements - This method, which is only valid on constant of vector /// type, returns the elements of the vector in the specified smallvector. /// This handles breaking down a vector undef into undef elements, etc. For |

