diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2017-12-18 20:10:56 +0000 | 
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2017-12-18 20:10:56 +0000 | 
| commit | 044eb2f6afba375a914ac9d8024f8f5142bb912e (patch) | |
| tree | 1475247dc9f9fe5be155ebd4c9069c75aadf8c20 /lib/Target/TargetMachine.cpp | |
| parent | eb70dddbd77e120e5d490bd8fbe7ff3f8fa81c6b (diff) | |
Notes
Diffstat (limited to 'lib/Target/TargetMachine.cpp')
| -rw-r--r-- | lib/Target/TargetMachine.cpp | 39 | 
1 files changed, 29 insertions, 10 deletions
diff --git a/lib/Target/TargetMachine.cpp b/lib/Target/TargetMachine.cpp index e8fe0a2b218ee..ad63c7a9cb304 100644 --- a/lib/Target/TargetMachine.cpp +++ b/lib/Target/TargetMachine.cpp @@ -13,7 +13,8 @@  #include "llvm/Target/TargetMachine.h"  #include "llvm/Analysis/TargetTransformInfo.h" -#include "llvm/CodeGen/MachineFunction.h" +#include "llvm/CodeGen/TargetLoweringObjectFile.h" +#include "llvm/CodeGen/TargetSubtargetInfo.h"  #include "llvm/IR/Function.h"  #include "llvm/IR/GlobalAlias.h"  #include "llvm/IR/GlobalValue.h" @@ -26,15 +27,8 @@  #include "llvm/MC/MCSectionMachO.h"  #include "llvm/MC/MCTargetOptions.h"  #include "llvm/MC/SectionKind.h" -#include "llvm/Target/TargetLowering.h" -#include "llvm/Target/TargetLoweringObjectFile.h" -#include "llvm/Target/TargetSubtargetInfo.h"  using namespace llvm; -cl::opt<bool> EnableIPRA("enable-ipra", cl::init(false), cl::Hidden, -                         cl::desc("Enable interprocedural register allocation " -                                  "to reduce load/store at procedure calls.")); -  //---------------------------------------------------------------------------  // TargetMachine Class  // @@ -45,8 +39,6 @@ TargetMachine::TargetMachine(const Target &T, StringRef DataLayoutString,      : TheTarget(T), DL(DataLayoutString), TargetTriple(TT), TargetCPU(CPU),        TargetFS(FS), AsmInfo(nullptr), MRI(nullptr), MII(nullptr), STI(nullptr),        RequireStructuredCFG(false), DefaultOptions(Options), Options(Options) { -  if (EnableIPRA.getNumOccurrences()) -    this->Options.EnableIPRA = EnableIPRA;  }  TargetMachine::~TargetMachine() { @@ -120,6 +112,17 @@ static TLSModel::Model getSelectedTLSModel(const GlobalValue *GV) {  bool TargetMachine::shouldAssumeDSOLocal(const Module &M,                                           const GlobalValue *GV) const { +  // If the IR producer requested that this GV be treated as dso local, obey. +  if (GV && GV->isDSOLocal()) +    return true; + +  // According to the llvm language reference, we should be able to just return +  // false in here if we have a GV, as we know it is dso_preemptable. +  // At this point in time, the various IR producers have not been transitioned +  // to always produce a dso_local when it is possible to do so. As a result we +  // still have some pre-dso_local logic in here to improve the quality of the +  // generated code: +    Reloc::Model RM = getRelocationModel();    const Triple &TT = getTargetTriple(); @@ -134,6 +137,15 @@ bool TargetMachine::shouldAssumeDSOLocal(const Module &M,    if (TT.isOSBinFormatCOFF() || (TT.isOSWindows() && TT.isOSBinFormatMachO()))      return true; +  // Most PIC code sequences that assume that a symbol is local cannot +  // produce a 0 if it turns out the symbol is undefined. While this +  // is ABI and relocation depended, it seems worth it to handle it +  // here. +  // FIXME: this is probably not ELF specific. +  if (GV && isPositionIndependent() && TT.isOSBinFormatELF() && +      GV->hasExternalWeakLinkage()) +    return false; +    if (GV && (GV->hasLocalLinkage() || !GV->hasDefaultVisibility()))      return true; @@ -153,6 +165,13 @@ bool TargetMachine::shouldAssumeDSOLocal(const Module &M,      if (GV && !GV->isDeclarationForLinker())        return true; +    // A symbol marked nonlazybind should not be accessed with a plt. If the +    // symbol turns out to be external, the linker will convert a direct +    // access to an access via the plt, so don't assume it is local. +    const Function *F = dyn_cast_or_null<Function>(GV); +    if (F && F->hasFnAttribute(Attribute::NonLazyBind)) +      return false; +      bool IsTLS = GV && GV->isThreadLocal();      bool IsAccessViaCopyRelocs =          Options.MCOptions.MCPIECopyRelocations && GV && isa<GlobalVariable>(GV);  | 
