diff --git a/llvm/include/llvm/Analysis/TargetTransformInfo.h b/llvm/include/llvm/Analysis/TargetTransformInfo.h --- a/llvm/include/llvm/Analysis/TargetTransformInfo.h +++ b/llvm/include/llvm/Analysis/TargetTransformInfo.h @@ -58,6 +58,7 @@ class StoreInst; class SwitchInst; class TargetLibraryInfo; +class TargetMachine; class Type; class User; class Value; @@ -177,8 +178,11 @@ /// the \c Concept API below. /// /// The TTI implementation will reflect the information in the DataLayout - /// provided if non-null. - explicit TargetTransformInfo(const DataLayout &DL); + /// provided (required), and the TM (if non-null). + TargetTransformInfo(const TargetMachine *TM, const DataLayout &DL); + // prevent this old signature from matching the template constructor above + // (C++ gives a much better error this way) + explicit TargetTransformInfo(const DataLayout &DL) = delete; // Provide move semantics. TargetTransformInfo(TargetTransformInfo &&Arg); @@ -1472,6 +1476,7 @@ public: virtual ~Concept() = 0; virtual const DataLayout &getDataLayout() const = 0; + virtual const TargetMachine *getTargetMachine() const = 0; virtual InstructionCost getGEPCost(Type *PointeeType, const Value *Ptr, ArrayRef Operands, TTI::TargetCostKind CostKind) = 0; @@ -1794,6 +1799,10 @@ return Impl.getDataLayout(); } + const TargetMachine *getTargetMachine() const override { + return Impl.getTargetMachine(); + } + InstructionCost getGEPCost(Type *PointeeType, const Value *Ptr, ArrayRef Operands, @@ -2463,9 +2472,6 @@ /// This may also be less error prone as the callback is likely to reference /// the external TargetMachine, and that reference needs to never dangle. std::function TTICallback; - - /// Helper function used as the callback in the default constructor. - static Result getDefaultTTI(const Function &F); }; /// Wrapper pass for TargetTransformInfo. diff --git a/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h b/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h --- a/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h +++ b/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h @@ -29,6 +29,7 @@ namespace llvm { class Function; +class TargetMachine; /// Base class for use as a mix-in that aids implementing /// a TargetTransformInfo-compatible class. @@ -36,9 +37,12 @@ protected: typedef TargetTransformInfo TTI; + const TargetMachine *TM; const DataLayout &DL; - explicit TargetTransformInfoImplBase(const DataLayout &DL) : DL(DL) {} + explicit TargetTransformInfoImplBase(const TargetMachine *TM, + const DataLayout &DL) + : TM(TM), DL(DL) {} public: // Provide value semantics. MSVC requires that we spell all of these out. @@ -46,6 +50,7 @@ TargetTransformInfoImplBase(TargetTransformInfoImplBase &&Arg) : DL(Arg.DL) {} const DataLayout &getDataLayout() const { return DL; } + const TargetMachine *getTargetMachine() const { return TM; } InstructionCost getGEPCost(Type *PointeeType, const Value *Ptr, ArrayRef Operands, @@ -890,7 +895,9 @@ typedef TargetTransformInfoImplBase BaseT; protected: - explicit TargetTransformInfoImplCRTPBase(const DataLayout &DL) : BaseT(DL) {} + explicit TargetTransformInfoImplCRTPBase(const TargetMachine *TM, + const DataLayout &DL) + : BaseT(TM, DL) {} public: using BaseT::getGEPCost; diff --git a/llvm/include/llvm/CodeGen/BasicTTIImpl.h b/llvm/include/llvm/CodeGen/BasicTTIImpl.h --- a/llvm/include/llvm/CodeGen/BasicTTIImpl.h +++ b/llvm/include/llvm/CodeGen/BasicTTIImpl.h @@ -241,7 +241,7 @@ protected: explicit BasicTTIImplBase(const TargetMachine *TM, const DataLayout &DL) - : BaseT(DL) {} + : BaseT(TM, DL) {} virtual ~BasicTTIImplBase() = default; using TargetTransformInfoImplBase::DL; diff --git a/llvm/lib/Analysis/InlineCost.cpp b/llvm/lib/Analysis/InlineCost.cpp --- a/llvm/lib/Analysis/InlineCost.cpp +++ b/llvm/lib/Analysis/InlineCost.cpp @@ -3101,7 +3101,7 @@ Module *M = F.getParent(); ProfileSummaryInfo PSI(*M); DataLayout DL(M); - TargetTransformInfo TTI(DL); + TargetTransformInfo TTI(nullptr, DL); // FIXME: Redesign the usage of InlineParams to expand the scope of this pass. // In the current implementation, the type of InlineParams doesn't matter as // the pass serves only for verification of inliner's decisions. diff --git a/llvm/lib/Analysis/TargetTransformInfo.cpp b/llvm/lib/Analysis/TargetTransformInfo.cpp --- a/llvm/lib/Analysis/TargetTransformInfo.cpp +++ b/llvm/lib/Analysis/TargetTransformInfo.cpp @@ -39,8 +39,8 @@ /// /// This is used when no target specific information is available. struct NoTTIImpl : TargetTransformInfoImplCRTPBase { - explicit NoTTIImpl(const DataLayout &DL) - : TargetTransformInfoImplCRTPBase(DL) {} + explicit NoTTIImpl(const TargetMachine *TM, const DataLayout &DL) + : TargetTransformInfoImplCRTPBase(TM, DL) {} }; } // namespace @@ -176,8 +176,9 @@ return true; } -TargetTransformInfo::TargetTransformInfo(const DataLayout &DL) - : TTIImpl(new Model(NoTTIImpl(DL))) {} +TargetTransformInfo::TargetTransformInfo(const TargetMachine *TM, + const DataLayout &DL) + : TTIImpl(new Model(NoTTIImpl(TM, DL))) {} TargetTransformInfo::~TargetTransformInfo() = default; @@ -1157,6 +1158,10 @@ TargetTransformInfo::Concept::~Concept() = default; +static TargetIRAnalysis::Result getDefaultTTI(const Function &F) { + return TargetIRAnalysis::Result(nullptr, F.getParent()->getDataLayout()); +} + TargetIRAnalysis::TargetIRAnalysis() : TTICallback(&getDefaultTTI) {} TargetIRAnalysis::TargetIRAnalysis( @@ -1170,10 +1175,6 @@ AnalysisKey TargetIRAnalysis::Key; -TargetIRAnalysis::Result TargetIRAnalysis::getDefaultTTI(const Function &F) { - return Result(F.getParent()->getDataLayout()); -} - // Register the basic pass. INITIALIZE_PASS(TargetTransformInfoWrapperPass, "tti", "Target Transform Information", false, true) diff --git a/llvm/lib/Target/Mips/MipsTargetMachine.cpp b/llvm/lib/Target/Mips/MipsTargetMachine.cpp --- a/llvm/lib/Target/Mips/MipsTargetMachine.cpp +++ b/llvm/lib/Target/Mips/MipsTargetMachine.cpp @@ -280,7 +280,7 @@ if (Subtarget->allowMixed16_32()) { LLVM_DEBUG(errs() << "No Target Transform Info Pass Added\n"); // FIXME: This is no longer necessary as the TTI returned is per-function. - return TargetTransformInfo(F.getParent()->getDataLayout()); + return TargetTransformInfo(this, F.getParent()->getDataLayout()); } LLVM_DEBUG(errs() << "Target Transform Info Pass Added\n"); diff --git a/llvm/lib/Target/TargetMachine.cpp b/llvm/lib/Target/TargetMachine.cpp --- a/llvm/lib/Target/TargetMachine.cpp +++ b/llvm/lib/Target/TargetMachine.cpp @@ -194,7 +194,7 @@ TargetTransformInfo TargetMachine::getTargetTransformInfo(const Function &F) const { - return TargetTransformInfo(F.getParent()->getDataLayout()); + return TargetTransformInfo(this, F.getParent()->getDataLayout()); } void TargetMachine::getNameWithPrefix(SmallVectorImpl &Name, diff --git a/llvm/tools/bugpoint/CrashDebugger.cpp b/llvm/tools/bugpoint/CrashDebugger.cpp --- a/llvm/tools/bugpoint/CrashDebugger.cpp +++ b/llvm/tools/bugpoint/CrashDebugger.cpp @@ -658,7 +658,7 @@ public: ReduceSimplifyCFG(BugDriver &bd, BugTester testFn) - : BD(bd), TestFn(testFn), TTI(bd.getProgram().getDataLayout()) {} + : BD(bd), TestFn(testFn), TTI(nullptr, bd.getProgram().getDataLayout()) {} Expected doTest(std::vector &Prefix, std::vector &Kept) override { diff --git a/llvm/unittests/Transforms/Utils/LocalTest.cpp b/llvm/unittests/Transforms/Utils/LocalTest.cpp --- a/llvm/unittests/Transforms/Utils/LocalTest.cpp +++ b/llvm/unittests/Transforms/Utils/LocalTest.cpp @@ -1005,7 +1005,7 @@ )"); Function &F = *cast(M->getNamedValue("foo")); - TargetTransformInfo TTI(M->getDataLayout()); + TargetTransformInfo TTI(nullptr, M->getDataLayout()); SimplifyCFGOptions Options{}; Options.setAssumptionCache(nullptr); diff --git a/llvm/unittests/Transforms/Utils/LoopRotationUtilsTest.cpp b/llvm/unittests/Transforms/Utils/LoopRotationUtilsTest.cpp --- a/llvm/unittests/Transforms/Utils/LoopRotationUtilsTest.cpp +++ b/llvm/unittests/Transforms/Utils/LoopRotationUtilsTest.cpp @@ -77,7 +77,7 @@ DominatorTree DT(*F); LoopInfo LI(DT); AssumptionCache AC(*F); - TargetTransformInfo TTI(M->getDataLayout()); + TargetTransformInfo TTI(nullptr, M->getDataLayout()); TargetLibraryInfoImpl TLII; TargetLibraryInfo TLI(TLII); ScalarEvolution SE(*F, TLI, AC, DT, LI); @@ -148,7 +148,7 @@ DominatorTree DT(*F); LoopInfo LI(DT); AssumptionCache AC(*F); - TargetTransformInfo TTI(M->getDataLayout()); + TargetTransformInfo TTI(nullptr, M->getDataLayout()); TargetLibraryInfoImpl TLII; TargetLibraryInfo TLI(TLII); ScalarEvolution SE(*F, TLI, AC, DT, LI);