Skip to content

Commit 93dcdc4

Browse files
committed
[PM] Switch the TargetMachine interface from accepting a pass manager
base which it adds a single analysis pass to, to instead return the type erased TargetTransformInfo object constructed for that TargetMachine. This removes all of the pass variants for TTI. There is now a single TTI *pass* in the Analysis layer. All of the Analysis <-> Target communication is through the TTI's type erased interface itself. While the diff is large here, it is nothing more that code motion to make types available in a header file for use in a different source file within each target. I've tried to keep all the doxygen comments and file boilerplate in line with this move, but let me know if I missed anything. With this in place, the next step to making TTI work with the new pass manager is to introduce a really simple new-style analysis that produces a TTI object via a callback into this routine on the target machine. Once we have that, we'll have the building blocks necessary to accept a function argument as well. llvm-svn: 227685
1 parent 9559a5c commit 93dcdc4

40 files changed

+761
-665
lines changed

llvm/include/llvm/Analysis/TargetTransformInfo.h

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,13 @@ class TargetTransformInfo {
6161
/// implementaion that encodes appropriate costs for their target.
6262
template <typename T> TargetTransformInfo(T Impl);
6363

64+
/// \brief Construct a baseline TTI object using a minimal implementation of
65+
/// the \c Concept API below.
66+
///
67+
/// The TTI implementation will reflect the information in the DataLayout
68+
/// provided if non-null.
69+
explicit TargetTransformInfo(const DataLayout *DL);
70+
6471
// Provide move semantics.
6572
TargetTransformInfo(TargetTransformInfo &&Arg);
6673
TargetTransformInfo &operator=(TargetTransformInfo &&RHS);
@@ -723,12 +730,11 @@ class TargetTransformInfoWrapperPass : public ImmutablePass {
723730
const TargetTransformInfo &getTTI() const { return TTI; }
724731
};
725732

726-
/// \brief Create the base case instance of a pass in the TTI analysis group.
733+
/// \brief Create an analysis pass wrapper around a TTI object.
727734
///
728-
/// This class provides the base case for the stack of TTI analyzes. It doesn't
729-
/// delegate to anything and uses the STTI and VTTI objects passed in to
730-
/// satisfy the queries.
731-
ImmutablePass *createNoTargetTransformInfoPass(const DataLayout *DL);
735+
/// This analysis pass just holds the TTI instance and makes it available to
736+
/// clients.
737+
ImmutablePass *createTargetTransformInfoWrapperPass(TargetTransformInfo TTI);
732738

733739
} // End llvm namespace
734740

llvm/include/llvm/CodeGen/BasicTTIImpl.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,30 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
621621

622622
/// @}
623623
};
624+
625+
/// \brief Concrete BasicTTIImpl that can be used if no further customization
626+
/// is needed.
627+
class BasicTTIImpl : public BasicTTIImplBase<BasicTTIImpl> {
628+
typedef BasicTTIImplBase<BasicTTIImpl> BaseT;
629+
630+
public:
631+
explicit BasicTTIImpl(const TargetMachine *TM = nullptr);
632+
633+
// Provide value semantics. MSVC requires that we spell all of these out.
634+
BasicTTIImpl(const BasicTTIImpl &Arg)
635+
: BaseT(static_cast<const BaseT &>(Arg)) {}
636+
BasicTTIImpl(BasicTTIImpl &&Arg)
637+
: BaseT(std::move(static_cast<BaseT &>(Arg))) {}
638+
BasicTTIImpl &operator=(const BasicTTIImpl &RHS) {
639+
BaseT::operator=(static_cast<const BaseT &>(RHS));
640+
return *this;
641+
}
642+
BasicTTIImpl &operator=(BasicTTIImpl &&RHS) {
643+
BaseT::operator=(std::move(static_cast<BaseT &>(RHS)));
644+
return *this;
645+
}
646+
};
647+
624648
}
625649

626650
#endif

llvm/include/llvm/Target/TargetMachine.h

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class TargetPassConfig;
4040
class TargetRegisterInfo;
4141
class TargetSelectionDAGInfo;
4242
class TargetSubtargetInfo;
43+
class TargetTransformInfo;
4344
class formatted_raw_ostream;
4445
class raw_ostream;
4546
class TargetLoweringObjectFile;
@@ -186,8 +187,12 @@ class TargetMachine {
186187
/// sections.
187188
void setFunctionSections(bool);
188189

189-
/// \brief Register analysis passes for this target with a pass manager.
190-
virtual void addAnalysisPasses(PassManagerBase &);
190+
/// \brief Get a TTI implementation for the target.
191+
///
192+
/// Targets should override this method to provide target-accurate
193+
/// information to the mid-level optimizer. If left with the baseline only
194+
/// a very conservative set of heuristics will be used.
195+
virtual TargetTransformInfo getTTI();
191196

192197
/// CodeGenFileType - These enums are meant to be passed into
193198
/// addPassesToEmitFile to indicate what type of file to emit, and returned by
@@ -240,10 +245,12 @@ class LLVMTargetMachine : public TargetMachine {
240245

241246
void initAsmInfo();
242247
public:
243-
/// \brief Register analysis passes for this target with a pass manager.
248+
/// \brief Get a TTI implementation for the target.
244249
///
245-
/// This registers target independent analysis passes.
246-
void addAnalysisPasses(PassManagerBase &PM) override;
250+
/// This uses the common code generator to produce a TTI implementation.
251+
/// Targets may override it to provide more customized TTI implementation
252+
/// instead.
253+
TargetTransformInfo getTTI() override;
247254

248255
/// createPassConfig - Create a pass configuration object to be used by
249256
/// addPassToEmitX methods for generating a pipeline of CodeGen passes.

llvm/lib/Analysis/TargetTransformInfo.cpp

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,20 @@ using namespace llvm;
2121

2222
#define DEBUG_TYPE "tti"
2323

24+
namespace {
25+
/// \brief No-op implementation of the TTI interface using the utility base
26+
/// classes.
27+
///
28+
/// This is used when no target specific information is available.
29+
struct NoTTIImpl : TargetTransformInfoImplCRTPBase<NoTTIImpl> {
30+
explicit NoTTIImpl(const DataLayout *DL)
31+
: TargetTransformInfoImplCRTPBase<NoTTIImpl>(DL) {}
32+
};
33+
}
34+
35+
TargetTransformInfo::TargetTransformInfo(const DataLayout *DL)
36+
: TTIImpl(new Model<NoTTIImpl>(NoTTIImpl(DL))) {}
37+
2438
TargetTransformInfo::~TargetTransformInfo() {}
2539

2640
TargetTransformInfo::TargetTransformInfo(TargetTransformInfo &&Arg)
@@ -241,17 +255,6 @@ Value *TargetTransformInfo::getOrCreateResultFromMemIntrinsic(
241255

242256
TargetTransformInfo::Concept::~Concept() {}
243257

244-
namespace {
245-
/// \brief No-op implementation of the TTI interface using the utility base
246-
/// classes.
247-
///
248-
/// This is used when no target specific information is available.
249-
struct NoTTIImpl : TargetTransformInfoImplCRTPBase<NoTTIImpl> {
250-
explicit NoTTIImpl(const DataLayout *DL)
251-
: TargetTransformInfoImplCRTPBase<NoTTIImpl>(DL) {}
252-
};
253-
}
254-
255258
// Register the basic pass.
256259
INITIALIZE_PASS(TargetTransformInfoWrapperPass, "tti",
257260
"Target Transform Information", false, true)
@@ -272,6 +275,7 @@ TargetTransformInfoWrapperPass::TargetTransformInfoWrapperPass(
272275
*PassRegistry::getPassRegistry());
273276
}
274277

275-
ImmutablePass *llvm::createNoTargetTransformInfoPass(const DataLayout *DL) {
276-
return new TargetTransformInfoWrapperPass(NoTTIImpl(DL));
278+
ImmutablePass *
279+
llvm::createTargetTransformInfoWrapperPass(TargetTransformInfo TTI) {
280+
return new TargetTransformInfoWrapperPass(std::move(TTI));
277281
}

llvm/lib/CodeGen/BasicTargetTransformInfo.cpp

Lines changed: 5 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -24,45 +24,13 @@
2424
#include <utility>
2525
using namespace llvm;
2626

27+
#define DEBUG_TYPE "basictti"
28+
29+
// This flag is used by the template base class for BasicTTIImpl, and here to
30+
// provide a definition.
2731
cl::opt<unsigned>
2832
llvm::PartialUnrollingThreshold("partial-unrolling-threshold", cl::init(0),
2933
cl::desc("Threshold for partial unrolling"),
3034
cl::Hidden);
3135

32-
#define DEBUG_TYPE "basictti"
33-
34-
namespace {
35-
class BasicTTIImpl : public BasicTTIImplBase<BasicTTIImpl> {
36-
typedef BasicTTIImplBase<BasicTTIImpl> BaseT;
37-
38-
public:
39-
explicit BasicTTIImpl(const TargetMachine *TM = nullptr) : BaseT(TM) {}
40-
41-
// Provide value semantics. MSVC requires that we spell all of these out.
42-
BasicTTIImpl(const BasicTTIImpl &Arg)
43-
: BaseT(static_cast<const BaseT &>(Arg)) {}
44-
BasicTTIImpl(BasicTTIImpl &&Arg)
45-
: BaseT(std::move(static_cast<BaseT &>(Arg))) {}
46-
BasicTTIImpl &operator=(const BasicTTIImpl &RHS) {
47-
BaseT::operator=(static_cast<const BaseT &>(RHS));
48-
return *this;
49-
}
50-
BasicTTIImpl &operator=(BasicTTIImpl &&RHS) {
51-
BaseT::operator=(std::move(static_cast<BaseT &>(RHS)));
52-
return *this;
53-
}
54-
};
55-
}
56-
57-
ImmutablePass *
58-
llvm::createBasicTargetTransformInfoPass(const TargetMachine *TM) {
59-
return new TargetTransformInfoWrapperPass(BasicTTIImpl(TM));
60-
}
61-
62-
63-
//===----------------------------------------------------------------------===//
64-
//
65-
// Calls used by the vectorizers.
66-
//
67-
//===----------------------------------------------------------------------===//
68-
36+
BasicTTIImpl::BasicTTIImpl(const TargetMachine *TM) : BaseT(TM) {}

llvm/lib/CodeGen/LLVMTargetMachine.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "llvm/Analysis/JumpInstrTableInfo.h"
1616
#include "llvm/Analysis/Passes.h"
1717
#include "llvm/CodeGen/AsmPrinter.h"
18+
#include "llvm/CodeGen/BasicTTIImpl.h"
1819
#include "llvm/CodeGen/ForwardControlFlowIntegrity.h"
1920
#include "llvm/CodeGen/JumpInstrTables.h"
2021
#include "llvm/CodeGen/MachineFunctionAnalysis.h"
@@ -77,8 +78,8 @@ LLVMTargetMachine::LLVMTargetMachine(const Target &T, StringRef Triple,
7778
CodeGenInfo = T.createMCCodeGenInfo(Triple, RM, CM, OL);
7879
}
7980

80-
void LLVMTargetMachine::addAnalysisPasses(PassManagerBase &PM) {
81-
PM.add(createBasicTargetTransformInfoPass(this));
81+
TargetTransformInfo LLVMTargetMachine::getTTI() {
82+
return TargetTransformInfo(BasicTTIImpl(this));
8283
}
8384

8485
/// addPassesToX helper drives creation and initialization of TargetPassConfig.
@@ -89,7 +90,7 @@ static MCContext *addPassesToGenerateCode(LLVMTargetMachine *TM,
8990
AnalysisID StopAfter) {
9091

9192
// Add internal analysis passes from the target machine.
92-
TM->addAnalysisPasses(PM);
93+
PM.add(createTargetTransformInfoWrapperPass(TM->getTTI()));
9394

9495
// Targets may override createPassConfig to provide a target-specific
9596
// subclass.

llvm/lib/LTO/LTOCodeGenerator.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "llvm/ADT/StringExtras.h"
1717
#include "llvm/Analysis/Passes.h"
1818
#include "llvm/Analysis/TargetLibraryInfo.h"
19+
#include "llvm/Analysis/TargetTransformInfo.h"
1920
#include "llvm/Bitcode/ReaderWriter.h"
2021
#include "llvm/CodeGen/RuntimeLibcalls.h"
2122
#include "llvm/Config/config.h"
@@ -489,7 +490,7 @@ bool LTOCodeGenerator::generateObjectFile(raw_ostream &out,
489490
mergedModule->setDataLayout(TargetMach->getDataLayout());
490491

491492
passes.add(new DataLayoutPass());
492-
TargetMach->addAnalysisPasses(passes);
493+
passes.add(createTargetTransformInfoWrapperPass(TargetMach->getTTI()));
493494

494495
Triple TargetTriple(TargetMach->getTargetTriple());
495496
PassManagerBuilder PMB;

llvm/lib/Target/AArch64/AArch64TargetMachine.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "AArch64.h"
1414
#include "AArch64TargetMachine.h"
1515
#include "AArch64TargetObjectFile.h"
16+
#include "AArch64TargetTransformInfo.h"
1617
#include "llvm/CodeGen/Passes.h"
1718
#include "llvm/CodeGen/RegAllocRegistry.h"
1819
#include "llvm/IR/Function.h"
@@ -195,8 +196,8 @@ class AArch64PassConfig : public TargetPassConfig {
195196
};
196197
} // namespace
197198

198-
void AArch64TargetMachine::addAnalysisPasses(PassManagerBase &PM) {
199-
PM.add(createAArch64TargetTransformInfoPass(this));
199+
TargetTransformInfo AArch64TargetMachine::getTTI() {
200+
return TargetTransformInfo(AArch64TTIImpl(this));
200201
}
201202

202203
TargetPassConfig *AArch64TargetMachine::createPassConfig(PassManagerBase &PM) {

llvm/lib/Target/AArch64/AArch64TargetMachine.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class AArch64TargetMachine : public LLVMTargetMachine {
4646
TargetPassConfig *createPassConfig(PassManagerBase &PM) override;
4747

4848
/// \brief Register AArch64 analysis passes with a pass manager.
49-
void addAnalysisPasses(PassManagerBase &PM) override;
49+
TargetTransformInfo getTTI() override;
5050

5151
TargetLoweringObjectFile* getObjFileLowering() const override {
5252
return TLOF.get();

0 commit comments

Comments
 (0)