diff options
-rw-r--r-- | llvm/include/llvm/Analysis/ObjectUtils.h | 42 | ||||
-rw-r--r-- | llvm/include/llvm/IR/GlobalValue.h | 7 | ||||
-rw-r--r-- | llvm/include/llvm/LTO/LTO.h | 1 | ||||
-rw-r--r-- | llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp | 3 | ||||
-rw-r--r-- | llvm/lib/IR/Globals.cpp | 18 | ||||
-rw-r--r-- | llvm/lib/LTO/LTOModule.cpp | 3 | ||||
-rw-r--r-- | llvm/lib/Object/IRSymtab.cpp | 3 |
7 files changed, 28 insertions, 49 deletions
diff --git a/llvm/include/llvm/Analysis/ObjectUtils.h b/llvm/include/llvm/Analysis/ObjectUtils.h deleted file mode 100644 index 2ad3b171700..00000000000 --- a/llvm/include/llvm/Analysis/ObjectUtils.h +++ /dev/null @@ -1,42 +0,0 @@ -//===- Analysis/ObjectUtils.h - analysis utils for object files -*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -#ifndef LLVM_ANALYSIS_OBJECT_UTILS_H -#define LLVM_ANALYSIS_OBJECT_UTILS_H - -#include "llvm/IR/GlobalVariable.h" - -namespace llvm { - -/// True if GV can be left out of the object symbol table. This is the case -/// for linkonce_odr values whose address is not significant. While legal, it is -/// not normally profitable to omit them from the .o symbol table. Using this -/// analysis makes sense when the information can be passed down to the linker -/// or we are in LTO. -inline bool canBeOmittedFromSymbolTable(const GlobalValue *GV) { - if (!GV->hasLinkOnceODRLinkage()) - return false; - - // We assume that anyone who sets global unnamed_addr on a non-constant knows - // what they're doing. - if (GV->hasGlobalUnnamedAddr()) - return true; - - // If it is a non constant variable, it needs to be uniqued across shared - // objects. - if (auto *Var = dyn_cast<GlobalVariable>(GV)) - if (!Var->isConstant()) - return false; - - return GV->hasAtLeastLocalUnnamedAddr(); -} - -} - -#endif diff --git a/llvm/include/llvm/IR/GlobalValue.h b/llvm/include/llvm/IR/GlobalValue.h index 9478a4633f7..35b0b6989cd 100644 --- a/llvm/include/llvm/IR/GlobalValue.h +++ b/llvm/include/llvm/IR/GlobalValue.h @@ -572,6 +572,13 @@ public: V->getValueID() == Value::GlobalAliasVal || V->getValueID() == Value::GlobalIFuncVal; } + + /// True if GV can be left out of the object symbol table. This is the case + /// for linkonce_odr values whose address is not significant. While legal, it + /// is not normally profitable to omit them from the .o symbol table. Using + /// this analysis makes sense when the information can be passed down to the + /// linker or we are in LTO. + bool canBeOmittedFromSymbolTable() const; }; } // end namespace llvm diff --git a/llvm/include/llvm/LTO/LTO.h b/llvm/include/llvm/LTO/LTO.h index f376d6f64bd..7d6beab6b44 100644 --- a/llvm/include/llvm/LTO/LTO.h +++ b/llvm/include/llvm/LTO/LTO.h @@ -19,7 +19,6 @@ #include "llvm/ADT/MapVector.h" #include "llvm/ADT/StringMap.h" #include "llvm/ADT/StringSet.h" -#include "llvm/Analysis/ObjectUtils.h" #include "llvm/IR/DiagnosticInfo.h" #include "llvm/IR/ModuleSummaryIndex.h" #include "llvm/LTO/Config.h" diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp index f08bd9251f9..14c4c302eaa 100644 --- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -31,7 +31,6 @@ #include "llvm/ADT/Twine.h" #include "llvm/Analysis/ConstantFolding.h" #include "llvm/Analysis/EHPersonalities.h" -#include "llvm/Analysis/ObjectUtils.h" #include "llvm/Analysis/OptimizationRemarkEmitter.h" #include "llvm/BinaryFormat/Dwarf.h" #include "llvm/BinaryFormat/ELF.h" @@ -376,7 +375,7 @@ static bool canBeHidden(const GlobalValue *GV, const MCAsmInfo &MAI) { if (!MAI.hasWeakDefCanBeHiddenDirective()) return false; - return canBeOmittedFromSymbolTable(GV); + return GV->canBeOmittedFromSymbolTable(); } void AsmPrinter::EmitLinkage(const GlobalValue *GV, MCSymbol *GVSym) const { diff --git a/llvm/lib/IR/Globals.cpp b/llvm/lib/IR/Globals.cpp index da1b6c5e0c9..20b2334a626 100644 --- a/llvm/lib/IR/Globals.cpp +++ b/llvm/lib/IR/Globals.cpp @@ -281,6 +281,24 @@ Optional<ConstantRange> GlobalValue::getAbsoluteSymbolRange() const { return getConstantRangeFromMetadata(*MD); } +bool GlobalValue::canBeOmittedFromSymbolTable() const { + if (!hasLinkOnceODRLinkage()) + return false; + + // We assume that anyone who sets global unnamed_addr on a non-constant + // knows what they're doing. + if (hasGlobalUnnamedAddr()) + return true; + + // If it is a non constant variable, it needs to be uniqued across shared + // objects. + if (auto *Var = dyn_cast<GlobalVariable>(this)) + if (!Var->isConstant()) + return false; + + return hasAtLeastLocalUnnamedAddr(); +} + //===----------------------------------------------------------------------===// // GlobalVariable Implementation //===----------------------------------------------------------------------===// diff --git a/llvm/lib/LTO/LTOModule.cpp b/llvm/lib/LTO/LTOModule.cpp index b26c371a082..2b96356b51b 100644 --- a/llvm/lib/LTO/LTOModule.cpp +++ b/llvm/lib/LTO/LTOModule.cpp @@ -14,7 +14,6 @@ #include "llvm/LTO/legacy/LTOModule.h" #include "llvm/ADT/Triple.h" -#include "llvm/Analysis/ObjectUtils.h" #include "llvm/Bitcode/BitcodeReader.h" #include "llvm/CodeGen/TargetLoweringObjectFile.h" #include "llvm/CodeGen/TargetSubtargetInfo.h" @@ -444,7 +443,7 @@ void LTOModule::addDefinedSymbol(StringRef Name, const GlobalValue *def, attr |= LTO_SYMBOL_SCOPE_HIDDEN; else if (def->hasProtectedVisibility()) attr |= LTO_SYMBOL_SCOPE_PROTECTED; - else if (canBeOmittedFromSymbolTable(def)) + else if (def->canBeOmittedFromSymbolTable()) attr |= LTO_SYMBOL_SCOPE_DEFAULT_CAN_BE_HIDDEN; else attr |= LTO_SYMBOL_SCOPE_DEFAULT; diff --git a/llvm/lib/Object/IRSymtab.cpp b/llvm/lib/Object/IRSymtab.cpp index 2d8d3f7c087..c4ed1881173 100644 --- a/llvm/lib/Object/IRSymtab.cpp +++ b/llvm/lib/Object/IRSymtab.cpp @@ -15,7 +15,6 @@ #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringRef.h" #include "llvm/ADT/Triple.h" -#include "llvm/Analysis/ObjectUtils.h" #include "llvm/IR/Comdat.h" #include "llvm/IR/DataLayout.h" #include "llvm/IR/GlobalAlias.h" @@ -232,7 +231,7 @@ Error Builder::addSymbol(const ModuleSymbolTable &Msymtab, Sym.Flags |= 1 << storage::Symbol::FB_tls; if (GV->hasGlobalUnnamedAddr()) Sym.Flags |= 1 << storage::Symbol::FB_unnamed_addr; - if (canBeOmittedFromSymbolTable(GV)) + if (GV->canBeOmittedFromSymbolTable()) Sym.Flags |= 1 << storage::Symbol::FB_may_omit; Sym.Flags |= unsigned(GV->getVisibility()) << storage::Symbol::FB_visibility; |