2001-09-14 13:34:53 +08:00
|
|
|
//===-- TargetMachine.cpp - General Target Information ---------------------==//
|
2005-04-22 06:55:34 +08:00
|
|
|
//
|
2003-10-21 03:43:21 +08:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-30 04:36:04 +08:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-22 06:55:34 +08:00
|
|
|
//
|
2003-10-21 03:43:21 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2001-09-14 13:34:53 +08:00
|
|
|
//
|
|
|
|
// This file describes the general parts of a Target machine.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2001-07-21 20:42:08 +08:00
|
|
|
|
2012-12-04 00:50:05 +08:00
|
|
|
#include "llvm/Target/TargetMachine.h"
|
[PM] Change the core design of the TTI analysis to use a polymorphic
type erased interface and a single analysis pass rather than an
extremely complex analysis group.
The end result is that the TTI analysis can contain a type erased
implementation that supports the polymorphic TTI interface. We can build
one from a target-specific implementation or from a dummy one in the IR.
I've also factored all of the code into "mix-in"-able base classes,
including CRTP base classes to facilitate calling back up to the most
specialized form when delegating horizontally across the surface. These
aren't as clean as I would like and I'm planning to work on cleaning
some of this up, but I wanted to start by putting into the right form.
There are a number of reasons for this change, and this particular
design. The first and foremost reason is that an analysis group is
complete overkill, and the chaining delegation strategy was so opaque,
confusing, and high overhead that TTI was suffering greatly for it.
Several of the TTI functions had failed to be implemented in all places
because of the chaining-based delegation making there be no checking of
this. A few other functions were implemented with incorrect delegation.
The message to me was very clear working on this -- the delegation and
analysis group structure was too confusing to be useful here.
The other reason of course is that this is *much* more natural fit for
the new pass manager. This will lay the ground work for a type-erased
per-function info object that can look up the correct subtarget and even
cache it.
Yet another benefit is that this will significantly simplify the
interaction of the pass managers and the TargetMachine. See the future
work below.
The downside of this change is that it is very, very verbose. I'm going
to work to improve that, but it is somewhat an implementation necessity
in C++ to do type erasure. =/ I discussed this design really extensively
with Eric and Hal prior to going down this path, and afterward showed
them the result. No one was really thrilled with it, but there doesn't
seem to be a substantially better alternative. Using a base class and
virtual method dispatch would make the code much shorter, but as
discussed in the update to the programmer's manual and elsewhere,
a polymorphic interface feels like the more principled approach even if
this is perhaps the least compelling example of it. ;]
Ultimately, there is still a lot more to be done here, but this was the
huge chunk that I couldn't really split things out of because this was
the interface change to TTI. I've tried to minimize all the other parts
of this. The follow up work should include at least:
1) Improving the TargetMachine interface by having it directly return
a TTI object. Because we have a non-pass object with value semantics
and an internal type erasure mechanism, we can narrow the interface
of the TargetMachine to *just* do what we need: build and return
a TTI object that we can then insert into the pass pipeline.
2) Make the TTI object be fully specialized for a particular function.
This will include splitting off a minimal form of it which is
sufficient for the inliner and the old pass manager.
3) Add a new pass manager analysis which produces TTI objects from the
target machine for each function. This may actually be done as part
of #2 in order to use the new analysis to implement #2.
4) Work on narrowing the API between TTI and the targets so that it is
easier to understand and less verbose to type erase.
5) Work on narrowing the API between TTI and its clients so that it is
easier to understand and less verbose to forward.
6) Try to improve the CRTP-based delegation. I feel like this code is
just a bit messy and exacerbating the complexity of implementing
the TTI in each target.
Many thanks to Eric and Hal for their help here. I ended up blocked on
this somewhat more abruptly than I expected, and so I appreciate getting
it sorted out very quickly.
Differential Revision: http://reviews.llvm.org/D7293
llvm-svn: 227669
2015-01-31 11:43:40 +08:00
|
|
|
#include "llvm/Analysis/TargetTransformInfo.h"
|
2013-03-14 06:26:59 +08:00
|
|
|
#include "llvm/CodeGen/MachineFunction.h"
|
|
|
|
#include "llvm/IR/Function.h"
|
2013-01-02 19:36:10 +08:00
|
|
|
#include "llvm/IR/GlobalAlias.h"
|
|
|
|
#include "llvm/IR/GlobalValue.h"
|
|
|
|
#include "llvm/IR/GlobalVariable.h"
|
2016-04-18 17:17:29 +08:00
|
|
|
#include "llvm/IR/LegacyPassManager.h"
|
2014-02-20 04:30:41 +08:00
|
|
|
#include "llvm/IR/Mangler.h"
|
2009-08-23 04:48:53 +08:00
|
|
|
#include "llvm/MC/MCAsmInfo.h"
|
2014-02-20 04:30:41 +08:00
|
|
|
#include "llvm/MC/MCContext.h"
|
2015-03-20 06:36:32 +08:00
|
|
|
#include "llvm/MC/MCInstrInfo.h"
|
2015-01-10 02:55:42 +08:00
|
|
|
#include "llvm/MC/MCSectionMachO.h"
|
2014-04-23 19:16:03 +08:00
|
|
|
#include "llvm/MC/MCTargetOptions.h"
|
2014-02-20 04:30:41 +08:00
|
|
|
#include "llvm/MC/SectionKind.h"
|
|
|
|
#include "llvm/Target/TargetLowering.h"
|
|
|
|
#include "llvm/Target/TargetLoweringObjectFile.h"
|
2014-08-05 05:25:23 +08:00
|
|
|
#include "llvm/Target/TargetSubtargetInfo.h"
|
2003-12-29 05:23:38 +08:00
|
|
|
using namespace llvm;
|
2003-11-12 06:41:34 +08:00
|
|
|
|
2016-07-14 07:39:46 +08:00
|
|
|
cl::opt<bool> EnableIPRA("enable-ipra", cl::init(false), cl::Hidden,
|
|
|
|
cl::desc("Enable interprocedural register allocation "
|
|
|
|
"to reduce load/store at procedure calls."));
|
|
|
|
|
2017-01-19 08:44:11 +08:00
|
|
|
cl::opt<bool> DebugInfoForProfiling(
|
|
|
|
"debug-info-for-profiling", cl::init(false), cl::Hidden,
|
|
|
|
cl::desc("Emit extra debug info to make sample profile more accurate."));
|
|
|
|
|
2001-07-21 20:42:08 +08:00
|
|
|
//---------------------------------------------------------------------------
|
2003-12-29 05:23:38 +08:00
|
|
|
// TargetMachine Class
|
|
|
|
//
|
2004-08-11 07:10:25 +08:00
|
|
|
|
2015-03-12 08:07:24 +08:00
|
|
|
TargetMachine::TargetMachine(const Target &T, StringRef DataLayoutString,
|
2015-06-12 03:41:26 +08:00
|
|
|
const Triple &TT, StringRef CPU, StringRef FS,
|
2011-12-03 06:16:29 +08:00
|
|
|
const TargetOptions &Options)
|
2015-03-12 08:07:24 +08:00
|
|
|
: TheTarget(T), DL(DataLayoutString), TargetTriple(TT), TargetCPU(CPU),
|
2016-07-01 02:25:11 +08:00
|
|
|
TargetFS(FS), AsmInfo(nullptr), MRI(nullptr), MII(nullptr), STI(nullptr),
|
[TM] Restore default TargetOptions in TargetMachine::resetTargetOptions.
Summary:
Previously if you had
* a function with the fast-math-enabled attr, followed by
* a function without the fast-math attr,
the second function would inherit the first function's fast-math-ness.
This means that mixing fast-math and non-fast-math functions in a module
was completely broken unless you explicitly annotated every
non-fast-math function with "unsafe-fp-math"="false". This appears to
have been broken since r176986 (March 2013), when the resetTargetOptions
function was introduced.
This patch tests the correct behavior as best we can. I don't think I
can test FPDenormalMode and NoTrappingFPMath, because they aren't used
in any backends during function lowering. Surprisingly, I also can't
find any uses at all of LessPreciseFPMAD affecting generated code.
The NVPTX/fast-math.ll test changes are an expected result of fixing
this bug. When FMA is disabled, we emit add as "add.rn.f32", which
prevents fma combining. Before this patch, fast-math was enabled in all
functions following the one which explicitly enabled it on itself, so we
were emitting plain "add.f32" where we should have generated
"add.rn.f32".
Reviewers: mkuper
Subscribers: hfinkel, majnemer, jholewinski, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28507
llvm-svn: 291618
2017-01-11 07:43:04 +08:00
|
|
|
RequireStructuredCFG(false), DefaultOptions(Options), Options(Options) {
|
2016-07-14 07:39:46 +08:00
|
|
|
if (EnableIPRA.getNumOccurrences())
|
|
|
|
this->Options.EnableIPRA = EnableIPRA;
|
2017-01-19 08:44:11 +08:00
|
|
|
if (DebugInfoForProfiling.getNumOccurrences())
|
|
|
|
this->Options.DebugInfoForProfiling = DebugInfoForProfiling;
|
2016-07-14 07:39:46 +08:00
|
|
|
}
|
2009-06-09 06:53:56 +08:00
|
|
|
|
2003-12-29 05:23:38 +08:00
|
|
|
TargetMachine::~TargetMachine() {
|
2006-09-08 07:39:26 +08:00
|
|
|
delete AsmInfo;
|
2015-03-20 06:36:32 +08:00
|
|
|
delete MRI;
|
|
|
|
delete MII;
|
2015-03-20 06:36:37 +08:00
|
|
|
delete STI;
|
2003-12-29 05:23:38 +08:00
|
|
|
}
|
|
|
|
|
2016-06-28 05:33:08 +08:00
|
|
|
bool TargetMachine::isPositionIndependent() const {
|
|
|
|
return getRelocationModel() == Reloc::PIC_;
|
|
|
|
}
|
|
|
|
|
2013-03-14 06:26:59 +08:00
|
|
|
/// \brief Reset the target options based on the function's attributes.
|
2015-04-29 02:09:05 +08:00
|
|
|
// FIXME: This function needs to go away for a number of reasons:
|
|
|
|
// a) global state on the TargetMachine is terrible in general,
|
[TM] Restore default TargetOptions in TargetMachine::resetTargetOptions.
Summary:
Previously if you had
* a function with the fast-math-enabled attr, followed by
* a function without the fast-math attr,
the second function would inherit the first function's fast-math-ness.
This means that mixing fast-math and non-fast-math functions in a module
was completely broken unless you explicitly annotated every
non-fast-math function with "unsafe-fp-math"="false". This appears to
have been broken since r176986 (March 2013), when the resetTargetOptions
function was introduced.
This patch tests the correct behavior as best we can. I don't think I
can test FPDenormalMode and NoTrappingFPMath, because they aren't used
in any backends during function lowering. Surprisingly, I also can't
find any uses at all of LessPreciseFPMAD affecting generated code.
The NVPTX/fast-math.ll test changes are an expected result of fixing
this bug. When FMA is disabled, we emit add as "add.rn.f32", which
prevents fma combining. Before this patch, fast-math was enabled in all
functions following the one which explicitly enabled it on itself, so we
were emitting plain "add.f32" where we should have generated
"add.rn.f32".
Reviewers: mkuper
Subscribers: hfinkel, majnemer, jholewinski, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28507
llvm-svn: 291618
2017-01-11 07:43:04 +08:00
|
|
|
// b) these target options should be passed only on the function
|
2015-04-29 02:09:05 +08:00
|
|
|
// and not on the TargetMachine (via TargetOptions) at all.
|
2014-09-26 09:28:10 +08:00
|
|
|
void TargetMachine::resetTargetOptions(const Function &F) const {
|
|
|
|
#define RESET_OPTION(X, Y) \
|
|
|
|
do { \
|
2015-02-14 23:36:52 +08:00
|
|
|
if (F.hasFnAttribute(Y)) \
|
|
|
|
Options.X = (F.getFnAttribute(Y).getValueAsString() == "true"); \
|
[TM] Restore default TargetOptions in TargetMachine::resetTargetOptions.
Summary:
Previously if you had
* a function with the fast-math-enabled attr, followed by
* a function without the fast-math attr,
the second function would inherit the first function's fast-math-ness.
This means that mixing fast-math and non-fast-math functions in a module
was completely broken unless you explicitly annotated every
non-fast-math function with "unsafe-fp-math"="false". This appears to
have been broken since r176986 (March 2013), when the resetTargetOptions
function was introduced.
This patch tests the correct behavior as best we can. I don't think I
can test FPDenormalMode and NoTrappingFPMath, because they aren't used
in any backends during function lowering. Surprisingly, I also can't
find any uses at all of LessPreciseFPMAD affecting generated code.
The NVPTX/fast-math.ll test changes are an expected result of fixing
this bug. When FMA is disabled, we emit add as "add.rn.f32", which
prevents fma combining. Before this patch, fast-math was enabled in all
functions following the one which explicitly enabled it on itself, so we
were emitting plain "add.f32" where we should have generated
"add.rn.f32".
Reviewers: mkuper
Subscribers: hfinkel, majnemer, jholewinski, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28507
llvm-svn: 291618
2017-01-11 07:43:04 +08:00
|
|
|
else \
|
|
|
|
Options.X = DefaultOptions.X; \
|
2013-03-14 06:26:59 +08:00
|
|
|
} while (0)
|
|
|
|
|
|
|
|
RESET_OPTION(LessPreciseFPMADOption, "less-precise-fpmad");
|
|
|
|
RESET_OPTION(UnsafeFPMath, "unsafe-fp-math");
|
|
|
|
RESET_OPTION(NoInfsFPMath, "no-infs-fp-math");
|
|
|
|
RESET_OPTION(NoNaNsFPMath, "no-nans-fp-math");
|
2017-01-25 14:08:42 +08:00
|
|
|
RESET_OPTION(NoSignedZerosFPMath, "no-signed-zeros-fp-math");
|
2016-08-31 22:17:38 +08:00
|
|
|
RESET_OPTION(NoTrappingFPMath, "no-trapping-math");
|
|
|
|
|
|
|
|
StringRef Denormal =
|
|
|
|
F.getFnAttribute("denormal-fp-math").getValueAsString();
|
|
|
|
if (Denormal == "ieee")
|
2016-10-04 16:03:36 +08:00
|
|
|
Options.FPDenormalMode = FPDenormal::IEEE;
|
2016-08-31 22:17:38 +08:00
|
|
|
else if (Denormal == "preserve-sign")
|
2016-10-04 16:03:36 +08:00
|
|
|
Options.FPDenormalMode = FPDenormal::PreserveSign;
|
2016-08-31 22:17:38 +08:00
|
|
|
else if (Denormal == "positive-zero")
|
2016-10-04 16:03:36 +08:00
|
|
|
Options.FPDenormalMode = FPDenormal::PositiveZero;
|
[TM] Restore default TargetOptions in TargetMachine::resetTargetOptions.
Summary:
Previously if you had
* a function with the fast-math-enabled attr, followed by
* a function without the fast-math attr,
the second function would inherit the first function's fast-math-ness.
This means that mixing fast-math and non-fast-math functions in a module
was completely broken unless you explicitly annotated every
non-fast-math function with "unsafe-fp-math"="false". This appears to
have been broken since r176986 (March 2013), when the resetTargetOptions
function was introduced.
This patch tests the correct behavior as best we can. I don't think I
can test FPDenormalMode and NoTrappingFPMath, because they aren't used
in any backends during function lowering. Surprisingly, I also can't
find any uses at all of LessPreciseFPMAD affecting generated code.
The NVPTX/fast-math.ll test changes are an expected result of fixing
this bug. When FMA is disabled, we emit add as "add.rn.f32", which
prevents fma combining. Before this patch, fast-math was enabled in all
functions following the one which explicitly enabled it on itself, so we
were emitting plain "add.f32" where we should have generated
"add.rn.f32".
Reviewers: mkuper
Subscribers: hfinkel, majnemer, jholewinski, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D28507
llvm-svn: 291618
2017-01-11 07:43:04 +08:00
|
|
|
else
|
|
|
|
Options.FPDenormalMode = DefaultOptions.FPDenormalMode;
|
2013-03-14 06:26:59 +08:00
|
|
|
}
|
|
|
|
|
2016-05-19 00:00:24 +08:00
|
|
|
/// Returns the code generation relocation model. The choices are static, PIC,
|
2016-05-19 06:04:49 +08:00
|
|
|
/// and dynamic-no-pic.
|
2016-07-01 02:25:11 +08:00
|
|
|
Reloc::Model TargetMachine::getRelocationModel() const { return RM; }
|
2006-05-24 02:18:46 +08:00
|
|
|
|
2016-06-30 20:44:52 +08:00
|
|
|
/// Returns the code model. The choices are small, kernel, medium, large, and
|
|
|
|
/// target default.
|
2016-07-01 02:25:11 +08:00
|
|
|
CodeModel::Model TargetMachine::getCodeModel() const { return CMModel; }
|
2006-07-06 09:53:36 +08:00
|
|
|
|
2012-06-23 19:37:03 +08:00
|
|
|
/// Get the IR-specified TLS model for Var.
|
2014-05-29 02:15:43 +08:00
|
|
|
static TLSModel::Model getSelectedTLSModel(const GlobalValue *GV) {
|
|
|
|
switch (GV->getThreadLocalMode()) {
|
2012-06-23 19:37:03 +08:00
|
|
|
case GlobalVariable::NotThreadLocal:
|
|
|
|
llvm_unreachable("getSelectedTLSModel for non-TLS variable");
|
|
|
|
break;
|
|
|
|
case GlobalVariable::GeneralDynamicTLSModel:
|
|
|
|
return TLSModel::GeneralDynamic;
|
|
|
|
case GlobalVariable::LocalDynamicTLSModel:
|
|
|
|
return TLSModel::LocalDynamic;
|
|
|
|
case GlobalVariable::InitialExecTLSModel:
|
|
|
|
return TLSModel::InitialExec;
|
|
|
|
case GlobalVariable::LocalExecTLSModel:
|
|
|
|
return TLSModel::LocalExec;
|
|
|
|
}
|
|
|
|
llvm_unreachable("invalid TLS model");
|
|
|
|
}
|
|
|
|
|
2016-06-28 07:15:57 +08:00
|
|
|
bool TargetMachine::shouldAssumeDSOLocal(const Module &M,
|
|
|
|
const GlobalValue *GV) const {
|
|
|
|
Reloc::Model RM = getRelocationModel();
|
|
|
|
const Triple &TT = getTargetTriple();
|
|
|
|
|
|
|
|
// DLLImport explicitly marks the GV as external.
|
|
|
|
if (GV && GV->hasDLLImportStorageClass())
|
|
|
|
return false;
|
|
|
|
|
2016-10-04 04:11:24 +08:00
|
|
|
// Every other GV is local on COFF.
|
|
|
|
// Make an exception for windows OS in the triple: Some firmwares builds use
|
|
|
|
// *-win32-macho triples. This (accidentally?) produced windows relocations
|
|
|
|
// without GOT tables in older clang versions; Keep this behaviour.
|
2016-10-04 06:12:37 +08:00
|
|
|
if (TT.isOSBinFormatCOFF() || (TT.isOSWindows() && TT.isOSBinFormatMachO()))
|
2016-06-28 07:15:57 +08:00
|
|
|
return true;
|
|
|
|
|
|
|
|
if (GV && (GV->hasLocalLinkage() || !GV->hasDefaultVisibility()))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (TT.isOSBinFormatMachO()) {
|
|
|
|
if (RM == Reloc::Static)
|
|
|
|
return true;
|
|
|
|
return GV && GV->isStrongDefinitionForLinker();
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(TT.isOSBinFormatELF());
|
|
|
|
assert(RM != Reloc::DynamicNoPIC);
|
|
|
|
|
|
|
|
bool IsExecutable =
|
|
|
|
RM == Reloc::Static || M.getPIELevel() != PIELevel::Default;
|
|
|
|
if (IsExecutable) {
|
|
|
|
// If the symbol is defined, it cannot be preempted.
|
|
|
|
if (GV && !GV->isDeclarationForLinker())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
bool IsTLS = GV && GV->isThreadLocal();
|
2016-10-14 04:54:39 +08:00
|
|
|
bool IsAccessViaCopyRelocs =
|
|
|
|
Options.MCOptions.MCPIECopyRelocations && GV && isa<GlobalVariable>(GV);
|
2017-01-26 23:02:31 +08:00
|
|
|
Triple::ArchType Arch = TT.getArch();
|
|
|
|
bool IsPPC =
|
|
|
|
Arch == Triple::ppc || Arch == Triple::ppc64 || Arch == Triple::ppc64le;
|
|
|
|
// Check if we can use copy relocations. PowerPC has no copy relocations.
|
|
|
|
if (!IsTLS && !IsPPC && (RM == Reloc::Static || IsAccessViaCopyRelocs))
|
2016-06-28 07:15:57 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ELF supports preemption of other symbols.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-04-09 01:20:55 +08:00
|
|
|
TLSModel::Model TargetMachine::getTLSModel(const GlobalValue *GV) const {
|
2016-06-28 04:19:14 +08:00
|
|
|
bool IsPIE = GV->getParent()->getPIELevel() != PIELevel::Default;
|
|
|
|
Reloc::Model RM = getRelocationModel();
|
|
|
|
bool IsSharedLibrary = RM == Reloc::PIC_ && !IsPIE;
|
2016-06-28 07:15:57 +08:00
|
|
|
bool IsLocal = shouldAssumeDSOLocal(*GV->getParent(), GV);
|
2012-04-09 01:20:55 +08:00
|
|
|
|
2012-06-23 19:37:03 +08:00
|
|
|
TLSModel::Model Model;
|
2016-06-28 04:19:14 +08:00
|
|
|
if (IsSharedLibrary) {
|
|
|
|
if (IsLocal)
|
2012-06-23 19:37:03 +08:00
|
|
|
Model = TLSModel::LocalDynamic;
|
2012-04-09 01:20:55 +08:00
|
|
|
else
|
2012-06-23 19:37:03 +08:00
|
|
|
Model = TLSModel::GeneralDynamic;
|
2012-04-09 01:20:55 +08:00
|
|
|
} else {
|
2016-06-28 04:19:14 +08:00
|
|
|
if (IsLocal)
|
2012-06-23 19:37:03 +08:00
|
|
|
Model = TLSModel::LocalExec;
|
2012-04-09 01:20:55 +08:00
|
|
|
else
|
2012-06-23 19:37:03 +08:00
|
|
|
Model = TLSModel::InitialExec;
|
2012-04-09 01:20:55 +08:00
|
|
|
}
|
2012-06-23 19:37:03 +08:00
|
|
|
|
2014-05-29 02:15:43 +08:00
|
|
|
// If the user specified a more specific model, use that.
|
|
|
|
TLSModel::Model SelectedModel = getSelectedTLSModel(GV);
|
|
|
|
if (SelectedModel > Model)
|
|
|
|
return SelectedModel;
|
2012-06-23 19:37:03 +08:00
|
|
|
|
|
|
|
return Model;
|
2012-04-09 01:20:55 +08:00
|
|
|
}
|
|
|
|
|
2016-06-30 20:44:52 +08:00
|
|
|
/// Returns the optimization level: None, Less, Default, or Aggressive.
|
2016-07-01 02:25:11 +08:00
|
|
|
CodeGenOpt::Level TargetMachine::getOptLevel() const { return OptLevel; }
|
2011-11-16 16:38:26 +08:00
|
|
|
|
2016-07-01 02:25:11 +08:00
|
|
|
void TargetMachine::setOptLevel(CodeGenOpt::Level Level) { OptLevel = Level; }
|
2013-11-23 03:11:24 +08:00
|
|
|
|
2015-02-01 18:11:22 +08:00
|
|
|
TargetIRAnalysis TargetMachine::getTargetIRAnalysis() {
|
2017-01-14 01:12:16 +08:00
|
|
|
return TargetIRAnalysis([](const Function &F) {
|
2015-07-09 10:08:42 +08:00
|
|
|
return TargetTransformInfo(F.getParent()->getDataLayout());
|
|
|
|
});
|
[PM] Change the core design of the TTI analysis to use a polymorphic
type erased interface and a single analysis pass rather than an
extremely complex analysis group.
The end result is that the TTI analysis can contain a type erased
implementation that supports the polymorphic TTI interface. We can build
one from a target-specific implementation or from a dummy one in the IR.
I've also factored all of the code into "mix-in"-able base classes,
including CRTP base classes to facilitate calling back up to the most
specialized form when delegating horizontally across the surface. These
aren't as clean as I would like and I'm planning to work on cleaning
some of this up, but I wanted to start by putting into the right form.
There are a number of reasons for this change, and this particular
design. The first and foremost reason is that an analysis group is
complete overkill, and the chaining delegation strategy was so opaque,
confusing, and high overhead that TTI was suffering greatly for it.
Several of the TTI functions had failed to be implemented in all places
because of the chaining-based delegation making there be no checking of
this. A few other functions were implemented with incorrect delegation.
The message to me was very clear working on this -- the delegation and
analysis group structure was too confusing to be useful here.
The other reason of course is that this is *much* more natural fit for
the new pass manager. This will lay the ground work for a type-erased
per-function info object that can look up the correct subtarget and even
cache it.
Yet another benefit is that this will significantly simplify the
interaction of the pass managers and the TargetMachine. See the future
work below.
The downside of this change is that it is very, very verbose. I'm going
to work to improve that, but it is somewhat an implementation necessity
in C++ to do type erasure. =/ I discussed this design really extensively
with Eric and Hal prior to going down this path, and afterward showed
them the result. No one was really thrilled with it, but there doesn't
seem to be a substantially better alternative. Using a base class and
virtual method dispatch would make the code much shorter, but as
discussed in the update to the programmer's manual and elsewhere,
a polymorphic interface feels like the more principled approach even if
this is perhaps the least compelling example of it. ;]
Ultimately, there is still a lot more to be done here, but this was the
huge chunk that I couldn't really split things out of because this was
the interface change to TTI. I've tried to minimize all the other parts
of this. The follow up work should include at least:
1) Improving the TargetMachine interface by having it directly return
a TTI object. Because we have a non-pass object with value semantics
and an internal type erasure mechanism, we can narrow the interface
of the TargetMachine to *just* do what we need: build and return
a TTI object that we can then insert into the pass pipeline.
2) Make the TTI object be fully specialized for a particular function.
This will include splitting off a minimal form of it which is
sufficient for the inliner and the old pass manager.
3) Add a new pass manager analysis which produces TTI objects from the
target machine for each function. This may actually be done as part
of #2 in order to use the new analysis to implement #2.
4) Work on narrowing the API between TTI and the targets so that it is
easier to understand and less verbose to type erase.
5) Work on narrowing the API between TTI and its clients so that it is
easier to understand and less verbose to forward.
6) Try to improve the CRTP-based delegation. I feel like this code is
just a bit messy and exacerbating the complexity of implementing
the TTI in each target.
Many thanks to Eric and Hal for their help here. I ended up blocked on
this somewhat more abruptly than I expected, and so I appreciate getting
it sorted out very quickly.
Differential Revision: http://reviews.llvm.org/D7293
llvm-svn: 227669
2015-01-31 11:43:40 +08:00
|
|
|
}
|
|
|
|
|
2014-02-20 04:30:41 +08:00
|
|
|
void TargetMachine::getNameWithPrefix(SmallVectorImpl<char> &Name,
|
2016-09-21 06:03:28 +08:00
|
|
|
const GlobalValue *GV, Mangler &Mang,
|
|
|
|
bool MayAlwaysUsePrivate) const {
|
2016-10-15 01:28:23 +08:00
|
|
|
if (MayAlwaysUsePrivate || !GV->hasPrivateLinkage()) {
|
|
|
|
// Simple case: If GV is not private, it is not important to find out if
|
|
|
|
// private labels are legal in this case or not.
|
|
|
|
Mang.getNameWithPrefix(Name, GV, false);
|
|
|
|
return;
|
|
|
|
}
|
2016-09-21 06:03:28 +08:00
|
|
|
const TargetLoweringObjectFile *TLOF = getObjFileLowering();
|
|
|
|
TLOF->getNameWithPrefix(Name, GV, *this);
|
2014-02-20 04:30:41 +08:00
|
|
|
}
|
|
|
|
|
2016-11-23 00:17:20 +08:00
|
|
|
MCSymbol *TargetMachine::getSymbol(const GlobalValue *GV) const {
|
2015-02-03 15:22:52 +08:00
|
|
|
const TargetLoweringObjectFile *TLOF = getObjFileLowering();
|
2016-11-23 00:17:20 +08:00
|
|
|
SmallString<128> NameStr;
|
|
|
|
getNameWithPrefix(NameStr, GV, TLOF->getMangler());
|
2015-05-19 02:43:14 +08:00
|
|
|
return TLOF->getContext().getOrCreateSymbol(NameStr);
|
2014-02-20 04:30:41 +08:00
|
|
|
}
|