diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2018-07-30 16:33:32 +0000 | 
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2018-07-30 16:33:32 +0000 | 
| commit | 51315c45ff5643a27f9c84b816db54ee870ba29b (patch) | |
| tree | 1d87443fa0e53d3e6b315ce25787e64be0906bf7 /contrib/llvm/lib/Target/TargetMachine.cpp | |
| parent | 6dfd050075216be8538ae375a22d30db72916f7e (diff) | |
| parent | eb11fae6d08f479c0799db45860a98af528fa6e7 (diff) | |
Notes
Diffstat (limited to 'contrib/llvm/lib/Target/TargetMachine.cpp')
| -rw-r--r-- | contrib/llvm/lib/Target/TargetMachine.cpp | 47 | 
1 files changed, 32 insertions, 15 deletions
| diff --git a/contrib/llvm/lib/Target/TargetMachine.cpp b/contrib/llvm/lib/Target/TargetMachine.cpp index c4c0dd22ee0c..092f5ea4104b 100644 --- a/contrib/llvm/lib/Target/TargetMachine.cpp +++ b/contrib/llvm/lib/Target/TargetMachine.cpp @@ -13,8 +13,6 @@  #include "llvm/Target/TargetMachine.h"  #include "llvm/Analysis/TargetTransformInfo.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" @@ -27,6 +25,7 @@  #include "llvm/MC/MCSectionMachO.h"  #include "llvm/MC/MCTargetOptions.h"  #include "llvm/MC/SectionKind.h" +#include "llvm/Target/TargetLoweringObjectFile.h"  using namespace llvm;  //--------------------------------------------------------------------------- @@ -52,7 +51,7 @@ bool TargetMachine::isPositionIndependent() const {    return getRelocationModel() == Reloc::PIC_;  } -/// \brief Reset the target options based on the function's attributes. +/// Reset the target options based on the function's attributes.  // FIXME: This function needs to go away for a number of reasons:  // a) global state on the TargetMachine is terrible in general,  // b) these target options should be passed only on the function @@ -116,12 +115,24 @@ bool TargetMachine::shouldAssumeDSOLocal(const Module &M,    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: +  // If we are not supossed to use a PLT, we cannot assume that intrinsics are +  // local since the linker can convert some direct access to access via plt. +  if (M.getRtLibUseGOT() && !GV) +    return false; + +  // 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. +  // In the case of intrinsics, GV is null and there is nowhere to put +  // dso_local. Returning false for those will produce worse code in some +  // architectures. For example, on x86 the caller has to set ebx before calling +  // a plt. +  // As a result we still have some logic in here to improve the quality of the +  // generated code. +  // FIXME: Add a module level metadata for whether intrinsics should be assumed +  // local.    Reloc::Model RM = getRelocationModel();    const Triple &TT = getTargetTriple(); @@ -131,7 +142,7 @@ bool TargetMachine::shouldAssumeDSOLocal(const Module &M,      return false;    // Every other GV is local on COFF. -  // Make an exception for windows OS in the triple: Some firmwares builds use +  // Make an exception for windows OS in the triple: Some firmware builds use    // *-win32-macho triples. This (accidentally?) produced windows relocations    // without GOT tables in older clang versions; Keep this behaviour.    if (TT.isOSBinFormatCOFF() || (TT.isOSWindows() && TT.isOSBinFormatMachO())) @@ -141,12 +152,10 @@ bool TargetMachine::shouldAssumeDSOLocal(const Module &M,    // 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()) +  if (GV && isPositionIndependent() && GV->hasExternalWeakLinkage())      return false; -  if (GV && (GV->hasLocalLinkage() || !GV->hasDefaultVisibility())) +  if (GV && !GV->hasDefaultVisibility())      return true;    if (TT.isOSBinFormatMachO()) { @@ -174,7 +183,7 @@ bool TargetMachine::shouldAssumeDSOLocal(const Module &M,      bool IsTLS = GV && GV->isThreadLocal();      bool IsAccessViaCopyRelocs = -        Options.MCOptions.MCPIECopyRelocations && GV && isa<GlobalVariable>(GV); +        GV && Options.MCOptions.MCPIECopyRelocations && isa<GlobalVariable>(GV);      Triple::ArchType Arch = TT.getArch();      bool IsPPC =          Arch == Triple::ppc || Arch == Triple::ppc64 || Arch == Triple::ppc64le; @@ -187,6 +196,14 @@ bool TargetMachine::shouldAssumeDSOLocal(const Module &M,    return false;  } +bool TargetMachine::useEmulatedTLS() const { +  // Returns Options.EmulatedTLS if the -emulated-tls or -no-emulated-tls +  // was specified explicitly; otherwise uses target triple to decide default. +  if (Options.ExplicitEmulatedTLS) +    return Options.EmulatedTLS; +  return getTargetTriple().hasDefaultEmulatedTLS(); +} +  TLSModel::Model TargetMachine::getTLSModel(const GlobalValue *GV) const {    bool IsPIE = GV->getParent()->getPIELevel() != PIELevel::Default;    Reloc::Model RM = getRelocationModel(); | 
