From 2e0ffe985896c332c51bc6be50c26087e755c6f9 Mon Sep 17 00:00:00 2001 From: Peter Collingbourne Date: Fri, 31 Mar 2017 04:46:31 +0000 Subject: [PATCH] Move llvm::canBeOmittedFromSymbolTable() to Analysis. llvm-svn: 299182 --- llvm/include/llvm/Analysis/ObjectUtils.h | 42 ++++++++++++++++++++++++++++++ llvm/include/llvm/CodeGen/Analysis.h | 7 ----- llvm/include/llvm/LTO/LTO.h | 2 +- llvm/lib/CodeGen/Analysis.cpp | 19 -------------- llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp | 1 + llvm/lib/LTO/LTOModule.cpp | 2 +- 6 files changed, 45 insertions(+), 28 deletions(-) create mode 100644 llvm/include/llvm/Analysis/ObjectUtils.h diff --git a/llvm/include/llvm/Analysis/ObjectUtils.h b/llvm/include/llvm/Analysis/ObjectUtils.h new file mode 100644 index 0000000..2ad3b17 --- /dev/null +++ b/llvm/include/llvm/Analysis/ObjectUtils.h @@ -0,0 +1,42 @@ +//===- 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(GV)) + if (!Var->isConstant()) + return false; + + return GV->hasAtLeastLocalUnnamedAddr(); +} + +} + +#endif diff --git a/llvm/include/llvm/CodeGen/Analysis.h b/llvm/include/llvm/CodeGen/Analysis.h index f20185c..ba88f1f 100644 --- a/llvm/include/llvm/CodeGen/Analysis.h +++ b/llvm/include/llvm/CodeGen/Analysis.h @@ -123,13 +123,6 @@ bool returnTypeIsEligibleForTailCall(const Function *F, const Instruction *I, const ReturnInst *Ret, const TargetLoweringBase &TLI); -// 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 GlobalValue *GV); - DenseMap getFuncletMembership(const MachineFunction &MF); diff --git a/llvm/include/llvm/LTO/LTO.h b/llvm/include/llvm/LTO/LTO.h index 2020d61..a74601b 100644 --- a/llvm/include/llvm/LTO/LTO.h +++ b/llvm/include/llvm/LTO/LTO.h @@ -19,7 +19,7 @@ #include "llvm/ADT/MapVector.h" #include "llvm/ADT/StringMap.h" #include "llvm/ADT/StringSet.h" -#include "llvm/CodeGen/Analysis.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/Analysis.cpp b/llvm/lib/CodeGen/Analysis.cpp index afbb854..09a37a7 100644 --- a/llvm/lib/CodeGen/Analysis.cpp +++ b/llvm/lib/CodeGen/Analysis.cpp @@ -612,25 +612,6 @@ bool llvm::returnTypeIsEligibleForTailCall(const Function *F, return true; } -bool llvm::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 (const GlobalVariable *Var = dyn_cast(GV)) { - if (!Var->isConstant()) - return false; - } - - return GV->hasAtLeastLocalUnnamedAddr(); -} - static void collectFuncletMembers( DenseMap &FuncletMembership, int Funclet, const MachineBasicBlock *MBB) { diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp index fb6fa4d..834a59a 100644 --- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -28,6 +28,7 @@ #include "llvm/ADT/Triple.h" #include "llvm/ADT/Twine.h" #include "llvm/Analysis/ConstantFolding.h" +#include "llvm/Analysis/ObjectUtils.h" #include "llvm/CodeGen/Analysis.h" #include "llvm/CodeGen/AsmPrinter.h" #include "llvm/CodeGen/GCMetadata.h" diff --git a/llvm/lib/LTO/LTOModule.cpp b/llvm/lib/LTO/LTOModule.cpp index 4736842..0d96b07 100644 --- a/llvm/lib/LTO/LTOModule.cpp +++ b/llvm/lib/LTO/LTOModule.cpp @@ -14,8 +14,8 @@ #include "llvm/LTO/legacy/LTOModule.h" #include "llvm/ADT/Triple.h" +#include "llvm/Analysis/ObjectUtils.h" #include "llvm/Bitcode/BitcodeReader.h" -#include "llvm/CodeGen/Analysis.h" #include "llvm/CodeGen/TargetLoweringObjectFileImpl.h" #include "llvm/IR/Constants.h" #include "llvm/IR/DiagnosticPrinter.h" -- 2.7.4