[multiversion] Switch the TTI queries from TargetMachine to Subtarget
authorChandler Carruth <chandlerc@gmail.com>
Sun, 1 Feb 2015 14:22:17 +0000 (14:22 +0000)
committerChandler Carruth <chandlerc@gmail.com>
Sun, 1 Feb 2015 14:22:17 +0000 (14:22 +0000)
now that we have a correct and cached subtarget specific to the
function.

Also, finish providing a cached per-function subtarget in the core
LLVMTargetMachine -- that layer hadn't switched over yet.

The only use of the TargetMachine was to re-lookup a subtarget for
a particular function to work around the fact that TTI was immutable.
Now that it is per-function and we haved a cached subtarget, use it.

This still leaves a few interfaces with real warts on them where we were
passing Function objects through the TTI interface. I'll remove these
and clean their usage up in subsequent commits now that this isn't
necessary.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@227738 91177308-0d34-0410-b5e6-96231b3b80d8

12 files changed:
include/llvm/CodeGen/BasicTTIImpl.h
lib/CodeGen/BasicTargetTransformInfo.cpp
lib/CodeGen/LLVMTargetMachine.cpp
lib/Target/AArch64/AArch64TargetTransformInfo.h
lib/Target/ARM/ARMTargetTransformInfo.h
lib/Target/Mips/MipsTargetMachine.cpp
lib/Target/NVPTX/NVPTXTargetTransformInfo.h
lib/Target/PowerPC/PPCTargetTransformInfo.cpp
lib/Target/PowerPC/PPCTargetTransformInfo.h
lib/Target/R600/AMDGPUTargetTransformInfo.h
lib/Target/X86/X86TargetTransformInfo.h
lib/Target/XCore/XCoreTargetTransformInfo.h

index 90c41dc9b9d14ae39d8ba546ba500d7076a192b2..d7129579cf014f7e9a23d2beaba6efb388f3df16 100644 (file)
@@ -31,10 +31,10 @@ extern cl::opt<unsigned> PartialUnrollingThreshold;
 /// This class provides as much implementation of the TTI interface as is
 /// possible using the target independent parts of the code generator.
 ///
-/// In order to subclass it, your class must implement a getTM() method to
-/// return the target machine, and a getTLI() method to return the target
-/// lowering. We need these methods implemented in the derived class so that
-/// this class doesn't have to duplicate storage for them.
+/// In order to subclass it, your class must implement a getST() method to
+/// return the subtarget, and a getTLI() method to return the target lowering.
+/// We need these methods implemented in the derived class so that this class
+/// doesn't have to duplicate storage for them.
 template <typename T>
 class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
 private:
@@ -80,8 +80,8 @@ private:
   }
 
   /// \brief Local query method delegates up to T which *must* implement this!
-  const TargetMachine *getTM() const {
-    return static_cast<const T *>(this)->getTM();
+  const TargetSubtargetInfo *getST() const {
+    return static_cast<const T *>(this)->getST();
   }
 
   /// \brief Local query method delegates up to T which *must* implement this!
@@ -193,7 +193,7 @@ public:
     // until someone finds a case where it matters in practice.
 
     unsigned MaxOps;
-    const TargetSubtargetInfo *ST = getTM()->getSubtargetImpl(*F);
+    const TargetSubtargetInfo *ST = getST();
     if (PartialUnrollingThreshold.getNumOccurrences() > 0)
       MaxOps = PartialUnrollingThreshold;
     else if (ST->getSchedModel().LoopMicroOpBufferSize > 0)
@@ -639,30 +639,30 @@ class BasicTTIImpl : public BasicTTIImplBase<BasicTTIImpl> {
   typedef BasicTTIImplBase<BasicTTIImpl> BaseT;
   friend class BasicTTIImplBase<BasicTTIImpl>;
 
-  const TargetMachine *TM;
+  const TargetSubtargetInfo *ST;
   const TargetLoweringBase *TLI;
 
-  const TargetMachine *getTM() const { return TM; }
+  const TargetSubtargetInfo *getST() const { return ST; }
   const TargetLoweringBase *getTLI() const { return TLI; }
 
 public:
-  explicit BasicTTIImpl(const TargetMachine *TM);
+  explicit BasicTTIImpl(const TargetMachine *ST, Function &F);
 
   // Provide value semantics. MSVC requires that we spell all of these out.
   BasicTTIImpl(const BasicTTIImpl &Arg)
-      : BaseT(static_cast<const BaseT &>(Arg)), TM(Arg.TM), TLI(Arg.TLI) {}
+      : BaseT(static_cast<const BaseT &>(Arg)), ST(Arg.ST), TLI(Arg.TLI) {}
   BasicTTIImpl(BasicTTIImpl &&Arg)
-      : BaseT(std::move(static_cast<BaseT &>(Arg))), TM(std::move(Arg.TM)),
+      : BaseT(std::move(static_cast<BaseT &>(Arg))), ST(std::move(Arg.ST)),
         TLI(std::move(Arg.TLI)) {}
   BasicTTIImpl &operator=(const BasicTTIImpl &RHS) {
     BaseT::operator=(static_cast<const BaseT &>(RHS));
-    TM = RHS.TM;
+    ST = RHS.ST;
     TLI = RHS.TLI;
     return *this;
   }
   BasicTTIImpl &operator=(BasicTTIImpl &&RHS) {
     BaseT::operator=(std::move(static_cast<BaseT &>(RHS)));
-    TM = std::move(RHS.TM);
+    ST = std::move(RHS.ST);
     TLI = std::move(RHS.TLI);
     return *this;
   }
index e0334732fdcd5cae2dc79f9fa063728acc558e46..2496d215cc0caeead84293307d286327d5cbf0f8 100644 (file)
@@ -33,5 +33,5 @@ cl::opt<unsigned>
                                     cl::desc("Threshold for partial unrolling"),
                                     cl::Hidden);
 
-BasicTTIImpl::BasicTTIImpl(const TargetMachine *TM)
-    : BaseT(TM), TM(TM), TLI(TM->getSubtargetImpl()->getTargetLowering()) {}
+BasicTTIImpl::BasicTTIImpl(const TargetMachine *TM, Function &F)
+    : BaseT(TM), ST(TM->getSubtargetImpl(F)), TLI(ST->getTargetLowering()) {}
index d3d8a50829288b88309d9d3eb6fb6575383b1c50..617ed75c24f7284209c3944160f4eaee07377cc3 100644 (file)
@@ -79,8 +79,9 @@ LLVMTargetMachine::LLVMTargetMachine(const Target &T, StringRef Triple,
 }
 
 TargetIRAnalysis LLVMTargetMachine::getTargetIRAnalysis() {
-  return TargetIRAnalysis(
-      [this](Function &) { return TargetTransformInfo(BasicTTIImpl(this)); });
+  return TargetIRAnalysis([this](Function &F) {
+    return TargetTransformInfo(BasicTTIImpl(this, F));
+  });
 }
 
 /// addPassesToX helper drives creation and initialization of TargetPassConfig.
index 5d83e5e433d16215d7fb8cae2ad3f76a5b7814f0..fffeb981b5300818014d28898f3bd0bfcaf45cb6 100644 (file)
@@ -39,7 +39,7 @@ class AArch64TTIImpl : public BasicTTIImplBase<AArch64TTIImpl> {
   /// are set if the result needs to be inserted and/or extracted from vectors.
   unsigned getScalarizationOverhead(Type *Ty, bool Insert, bool Extract);
 
-  const AArch64TargetMachine *getTM() const { return TM; }
+  const AArch64Subtarget *getST() const { return ST; }
   const AArch64TargetLowering *getTLI() const { return TLI; }
 
   enum MemIntrinsicType {
index b9e52914d2ad5e596f5ffb53c21dd1c440945132..6167fae9c8aafac68b6db429acccdb293757a8f8 100644 (file)
@@ -30,7 +30,6 @@ class ARMTTIImpl : public BasicTTIImplBase<ARMTTIImpl> {
   typedef TargetTransformInfo TTI;
   friend BaseT;
 
-  const ARMBaseTargetMachine *TM;
   const ARMSubtarget *ST;
   const ARMTargetLowering *TLI;
 
@@ -38,30 +37,27 @@ class ARMTTIImpl : public BasicTTIImplBase<ARMTTIImpl> {
   /// are set if the result needs to be inserted and/or extracted from vectors.
   unsigned getScalarizationOverhead(Type *Ty, bool Insert, bool Extract);
 
-  const ARMBaseTargetMachine *getTM() const { return TM; }
+  const ARMSubtarget *getST() const { return ST; }
   const ARMTargetLowering *getTLI() const { return TLI; }
 
 public:
   explicit ARMTTIImpl(const ARMBaseTargetMachine *TM, Function &F)
-      : BaseT(TM), TM(TM), ST(TM->getSubtargetImpl(F)),
-        TLI(ST->getTargetLowering()) {}
+      : BaseT(TM), ST(TM->getSubtargetImpl(F)), TLI(ST->getTargetLowering()) {}
 
   // Provide value semantics. MSVC requires that we spell all of these out.
   ARMTTIImpl(const ARMTTIImpl &Arg)
-      : BaseT(static_cast<const BaseT &>(Arg)), TM(Arg.TM), ST(Arg.ST), TLI(Arg.TLI) {}
+      : BaseT(static_cast<const BaseT &>(Arg)), ST(Arg.ST), TLI(Arg.TLI) {}
   ARMTTIImpl(ARMTTIImpl &&Arg)
-      : BaseT(std::move(static_cast<BaseT &>(Arg))), TM(std::move(Arg.TM)),
-        ST(std::move(Arg.ST)), TLI(std::move(Arg.TLI)) {}
+      : BaseT(std::move(static_cast<BaseT &>(Arg))), ST(std::move(Arg.ST)),
+        TLI(std::move(Arg.TLI)) {}
   ARMTTIImpl &operator=(const ARMTTIImpl &RHS) {
     BaseT::operator=(static_cast<const BaseT &>(RHS));
-    TM = RHS.TM;
     ST = RHS.ST;
     TLI = RHS.TLI;
     return *this;
   }
   ARMTTIImpl &operator=(ARMTTIImpl &&RHS) {
     BaseT::operator=(std::move(static_cast<BaseT &>(RHS)));
-    TM = std::move(RHS.TM);
     ST = std::move(RHS.ST);
     TLI = std::move(RHS.TLI);
     return *this;
index 0fd3a14b7cf70e9b4e7b7cf53b362c59a4c55df8..0ae3c991261444ee9a49f3b298c03d7024102868 100644 (file)
@@ -247,7 +247,7 @@ TargetIRAnalysis MipsTargetMachine::getTargetIRAnalysis() {
     }
 
     DEBUG(errs() << "Target Transform Info Pass Added\n");
-    return TargetTransformInfo(BasicTTIImpl(this));
+    return TargetTransformInfo(BasicTTIImpl(this, F));
   });
 }
 
index 3e96979f0862c1bcaffb6203f09f92326405df84..bf21e881b4b814de653123f8b9200bc5951aa295 100644 (file)
@@ -30,30 +30,31 @@ class NVPTXTTIImpl : public BasicTTIImplBase<NVPTXTTIImpl> {
   typedef TargetTransformInfo TTI;
   friend BaseT;
 
-  const NVPTXTargetMachine *TM;
+  const NVPTXSubtarget *ST;
   const NVPTXTargetLowering *TLI;
 
-  const NVPTXTargetMachine *getTM() const { return TM; };
+  const NVPTXSubtarget *getST() const { return ST; };
   const NVPTXTargetLowering *getTLI() const { return TLI; };
 
 public:
   explicit NVPTXTTIImpl(const NVPTXTargetMachine *TM)
-      : BaseT(TM), TM(TM), TLI(TM->getSubtargetImpl()->getTargetLowering()) {}
+      : BaseT(TM), ST(TM->getSubtargetImpl()), TLI(ST->getTargetLowering()) {}
 
   // Provide value semantics. MSVC requires that we spell all of these out.
   NVPTXTTIImpl(const NVPTXTTIImpl &Arg)
-      : BaseT(static_cast<const BaseT &>(Arg)), TM(Arg.TM), TLI(Arg.TLI) {}
+      : BaseT(static_cast<const BaseT &>(Arg)), ST(Arg.ST), TLI(Arg.TLI) {}
   NVPTXTTIImpl(NVPTXTTIImpl &&Arg)
-      : BaseT(std::move(static_cast<BaseT &>(Arg))), TM(std::move(Arg.TM)), TLI(std::move(Arg.TLI)) {}
+      : BaseT(std::move(static_cast<BaseT &>(Arg))), ST(std::move(Arg.ST)),
+        TLI(std::move(Arg.TLI)) {}
   NVPTXTTIImpl &operator=(const NVPTXTTIImpl &RHS) {
     BaseT::operator=(static_cast<const BaseT &>(RHS));
-    TM = RHS.TM;
+    ST = RHS.ST;
     TLI = RHS.TLI;
     return *this;
   }
   NVPTXTTIImpl &operator=(NVPTXTTIImpl &&RHS) {
     BaseT::operator=(std::move(static_cast<BaseT &>(RHS)));
-    TM = std::move(RHS.TM);
+    ST = std::move(RHS.ST);
     TLI = std::move(RHS.TLI);
     return *this;
   }
index 3519229eb093c29dfed3e96d0d2749d5ee8a9967..98fe5cdd8db2b6ca901440a73e4b4202e728c8a6 100644 (file)
@@ -183,7 +183,7 @@ unsigned PPCTTIImpl::getIntImmCost(unsigned Opcode, unsigned Idx,
 
 void PPCTTIImpl::getUnrollingPreferences(const Function *F, Loop *L,
                                          TTI::UnrollingPreferences &UP) {
-  if (TM->getSubtarget<PPCSubtarget>(F).getDarwinDirective() == PPC::DIR_A2) {
+  if (ST->getDarwinDirective() == PPC::DIR_A2) {
     // The A2 is in-order with a deep pipeline, and concatenation unrolling
     // helps expose latency-hiding opportunities to the instruction scheduler.
     UP.Partial = UP.Runtime = true;
index 83cb5e5d113683c7a9ddd52ea5d42a7b39fca5b3..0429a26c200c5dde542ea4034d1a0a0291a49bb7 100644 (file)
@@ -30,35 +30,30 @@ class PPCTTIImpl : public BasicTTIImplBase<PPCTTIImpl> {
   typedef TargetTransformInfo TTI;
   friend BaseT;
 
-  const PPCTargetMachine *TM;
   const PPCSubtarget *ST;
   const PPCTargetLowering *TLI;
 
-  const PPCTargetMachine *getTM() const { return TM; }
+  const PPCSubtarget *getST() const { return ST; }
   const PPCTargetLowering *getTLI() const { return TLI; }
 
 public:
   explicit PPCTTIImpl(const PPCTargetMachine *TM, Function &F)
-      : BaseT(TM), TM(TM), ST(TM->getSubtargetImpl(F)),
-        TLI(ST->getTargetLowering()) {}
+      : BaseT(TM), ST(TM->getSubtargetImpl(F)), TLI(ST->getTargetLowering()) {}
 
   // Provide value semantics. MSVC requires that we spell all of these out.
   PPCTTIImpl(const PPCTTIImpl &Arg)
-      : BaseT(static_cast<const BaseT &>(Arg)), TM(Arg.TM), ST(Arg.ST),
-        TLI(Arg.TLI) {}
+      : BaseT(static_cast<const BaseT &>(Arg)), ST(Arg.ST), TLI(Arg.TLI) {}
   PPCTTIImpl(PPCTTIImpl &&Arg)
-      : BaseT(std::move(static_cast<BaseT &>(Arg))), TM(std::move(Arg.TM)),
-        ST(std::move(Arg.ST)), TLI(std::move(Arg.TLI)) {}
+      : BaseT(std::move(static_cast<BaseT &>(Arg))), ST(std::move(Arg.ST)),
+        TLI(std::move(Arg.TLI)) {}
   PPCTTIImpl &operator=(const PPCTTIImpl &RHS) {
     BaseT::operator=(static_cast<const BaseT &>(RHS));
-    TM = RHS.TM;
     ST = RHS.ST;
     TLI = RHS.TLI;
     return *this;
   }
   PPCTTIImpl &operator=(PPCTTIImpl &&RHS) {
     BaseT::operator=(std::move(static_cast<BaseT &>(RHS)));
-    TM = std::move(RHS.TM);
     ST = std::move(RHS.ST);
     TLI = std::move(RHS.TLI);
     return *this;
index 3d3f86e5d0e05a86b74b7330f80b5f31320a9d96..4c4103302065bf9df4e6b12114058e26dace7ea4 100644 (file)
@@ -30,35 +30,30 @@ class AMDGPUTTIImpl : public BasicTTIImplBase<AMDGPUTTIImpl> {
   typedef TargetTransformInfo TTI;
   friend BaseT;
 
-  const AMDGPUTargetMachine *TM;
   const AMDGPUSubtarget *ST;
   const AMDGPUTargetLowering *TLI;
 
-  const AMDGPUTargetMachine *getTM() const { return TM; }
+  const AMDGPUSubtarget *getST() const { return ST; }
   const AMDGPUTargetLowering *getTLI() const { return TLI; }
 
 public:
   explicit AMDGPUTTIImpl(const AMDGPUTargetMachine *TM)
-      : BaseT(TM), TM(TM), ST(TM->getSubtargetImpl()),
-        TLI(ST->getTargetLowering()) {}
+      : BaseT(TM), ST(TM->getSubtargetImpl()), TLI(ST->getTargetLowering()) {}
 
   // Provide value semantics. MSVC requires that we spell all of these out.
   AMDGPUTTIImpl(const AMDGPUTTIImpl &Arg)
-      : BaseT(static_cast<const BaseT &>(Arg)), TM(Arg.TM), ST(Arg.ST),
-        TLI(Arg.TLI) {}
+      : BaseT(static_cast<const BaseT &>(Arg)), ST(Arg.ST), TLI(Arg.TLI) {}
   AMDGPUTTIImpl(AMDGPUTTIImpl &&Arg)
-      : BaseT(std::move(static_cast<BaseT &>(Arg))), TM(std::move(Arg.TM)),
-        ST(std::move(Arg.ST)), TLI(std::move(Arg.TLI)) {}
+      : BaseT(std::move(static_cast<BaseT &>(Arg))), ST(std::move(Arg.ST)),
+        TLI(std::move(Arg.TLI)) {}
   AMDGPUTTIImpl &operator=(const AMDGPUTTIImpl &RHS) {
     BaseT::operator=(static_cast<const BaseT &>(RHS));
-    TM = RHS.TM;
     ST = RHS.ST;
     TLI = RHS.TLI;
     return *this;
   }
   AMDGPUTTIImpl &operator=(AMDGPUTTIImpl &&RHS) {
     BaseT::operator=(std::move(static_cast<BaseT &>(RHS)));
-    TM = std::move(RHS.TM);
     ST = std::move(RHS.ST);
     TLI = std::move(RHS.TLI);
     return *this;
index 57d40581a23ab25703c17b0b8146c3e7582674bd..9f0adcfef623a561a2f6ffcea8f362216ad7ab12 100644 (file)
@@ -30,37 +30,32 @@ class X86TTIImpl : public BasicTTIImplBase<X86TTIImpl> {
   typedef TargetTransformInfo TTI;
   friend BaseT;
 
-  const X86TargetMachine *TM;
   const X86Subtarget *ST;
   const X86TargetLowering *TLI;
 
   unsigned getScalarizationOverhead(Type *Ty, bool Insert, bool Extract);
 
-  const X86TargetMachine *getTM() const { return TM; }
+  const X86Subtarget *getST() const { return ST; }
   const X86TargetLowering *getTLI() const { return TLI; }
 
 public:
   explicit X86TTIImpl(const X86TargetMachine *TM, Function &F)
-      : BaseT(TM), TM(TM), ST(TM->getSubtargetImpl(F)),
-        TLI(ST->getTargetLowering()) {}
+      : BaseT(TM), ST(TM->getSubtargetImpl(F)), TLI(ST->getTargetLowering()) {}
 
   // Provide value semantics. MSVC requires that we spell all of these out.
   X86TTIImpl(const X86TTIImpl &Arg)
-      : BaseT(static_cast<const BaseT &>(Arg)), TM(Arg.TM), ST(Arg.ST),
-        TLI(Arg.TLI) {}
+      : BaseT(static_cast<const BaseT &>(Arg)), ST(Arg.ST), TLI(Arg.TLI) {}
   X86TTIImpl(X86TTIImpl &&Arg)
-      : BaseT(std::move(static_cast<BaseT &>(Arg))), TM(std::move(Arg.TM)),
-        ST(std::move(Arg.ST)), TLI(std::move(Arg.TLI)) {}
+      : BaseT(std::move(static_cast<BaseT &>(Arg))), ST(std::move(Arg.ST)),
+        TLI(std::move(Arg.TLI)) {}
   X86TTIImpl &operator=(const X86TTIImpl &RHS) {
     BaseT::operator=(static_cast<const BaseT &>(RHS));
-    TM = RHS.TM;
     ST = RHS.ST;
     TLI = RHS.TLI;
     return *this;
   }
   X86TTIImpl &operator=(X86TTIImpl &&RHS) {
     BaseT::operator=(std::move(static_cast<BaseT &>(RHS)));
-    TM = std::move(RHS.TM);
     ST = std::move(RHS.ST);
     TLI = std::move(RHS.TLI);
     return *this;
index 8a0c58ffaba2bbd18d6ef7cdd537e058244726f3..70b47dfa11565b8167aea548e51b83f685aa4148 100644 (file)
@@ -30,31 +30,31 @@ class XCoreTTIImpl : public BasicTTIImplBase<XCoreTTIImpl> {
   typedef TargetTransformInfo TTI;
   friend BaseT;
 
-  const XCoreTargetMachine *TM;
+  const XCoreSubtarget *ST;
   const XCoreTargetLowering *TLI;
 
-  const XCoreTargetMachine *getTM() const { return TM; }
+  const XCoreSubtarget *getST() const { return ST; }
   const XCoreTargetLowering *getTLI() const { return TLI; }
 
 public:
   explicit XCoreTTIImpl(const XCoreTargetMachine *TM)
-      : BaseT(TM), TM(TM), TLI(TM->getSubtargetImpl()->getTargetLowering()) {}
+      : BaseT(TM), ST(TM->getSubtargetImpl()), TLI(ST->getTargetLowering()) {}
 
   // Provide value semantics. MSVC requires that we spell all of these out.
   XCoreTTIImpl(const XCoreTTIImpl &Arg)
-      : BaseT(static_cast<const BaseT &>(Arg)), TM(Arg.TM), TLI(Arg.TLI) {}
+      : BaseT(static_cast<const BaseT &>(Arg)), ST(Arg.ST), TLI(Arg.TLI) {}
   XCoreTTIImpl(XCoreTTIImpl &&Arg)
-      : BaseT(std::move(static_cast<BaseT &>(Arg))), TM(std::move(Arg.TM)),
+      : BaseT(std::move(static_cast<BaseT &>(Arg))), ST(std::move(Arg.ST)),
         TLI(std::move(Arg.TLI)) {}
   XCoreTTIImpl &operator=(const XCoreTTIImpl &RHS) {
     BaseT::operator=(static_cast<const BaseT &>(RHS));
-    TM = RHS.TM;
+    ST = RHS.ST;
     TLI = RHS.TLI;
     return *this;
   }
   XCoreTTIImpl &operator=(XCoreTTIImpl &&RHS) {
     BaseT::operator=(std::move(static_cast<BaseT &>(RHS)));
-    TM = std::move(RHS.TM);
+    ST = std::move(RHS.ST);
     TLI = std::move(RHS.TLI);
     return *this;
   }