[llvm] r218004 - Add a new pass FunctionTargetTransformInfo. This pass serves as a

Eric Christopher echristo at gmail.com
Wed Sep 17 17:50:48 PDT 2014


I did :)

I should have a script that asks me before I commit a new file "Did you add
this to cmake yet?"

Thanks!

-eric

On Wed, Sep 17, 2014 at 5:48 PM, Juergen Ributzka <juergen at apple.com> wrote:

> I think you forgot to update the cmake files ;-)
>
> > On Sep 17, 2014, at 5:34 PM, Eric Christopher <echristo at gmail.com>
> wrote:
> >
> > Author: echristo
> > Date: Wed Sep 17 19:34:14 2014
> > New Revision: 218004
> >
> > URL: http://llvm.org/viewvc/llvm-project?rev=218004&view=rev
> > Log:
> > Add a new pass FunctionTargetTransformInfo. This pass serves as a
> > shim between the TargetTransformInfo immutable pass and the Subtarget
> > via the TargetMachine and Function. Migrate a single call from
> > BasicTargetTransformInfo as an example and provide shims where
> TargetMachine
> > begins taking a Function to determine the subtarget.
> >
> > No functional change.
> >
> > Added:
> >    llvm/trunk/include/llvm/Analysis/FunctionTargetTransformInfo.h
> >    llvm/trunk/lib/Analysis/FunctionTargetTransformInfo.cpp
> > Modified:
> >    llvm/trunk/include/llvm/Analysis/TargetTransformInfo.h
> >    llvm/trunk/include/llvm/InitializePasses.h
> >    llvm/trunk/include/llvm/Target/TargetMachine.h
> >    llvm/trunk/lib/Analysis/TargetTransformInfo.cpp
> >    llvm/trunk/lib/CodeGen/BasicTargetTransformInfo.cpp
> >    llvm/trunk/lib/Target/PowerPC/PPCTargetTransformInfo.cpp
> >    llvm/trunk/lib/Target/R600/AMDGPUTargetTransformInfo.cpp
> >    llvm/trunk/lib/Transforms/Scalar/LoopUnrollPass.cpp
> >
> > Added: llvm/trunk/include/llvm/Analysis/FunctionTargetTransformInfo.h
> > URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/FunctionTargetTransformInfo.h?rev=218004&view=auto
> >
> ==============================================================================
> > --- llvm/trunk/include/llvm/Analysis/FunctionTargetTransformInfo.h
> (added)
> > +++ llvm/trunk/include/llvm/Analysis/FunctionTargetTransformInfo.h Wed
> Sep 17 19:34:14 2014
> > @@ -0,0 +1,49 @@
> > +//===- llvm/Analysis/FunctionTargetTransformInfo.h --------------*- C++
> -*-===//
> > +//
> > +//                     The LLVM Compiler Infrastructure
> > +//
> > +// This file is distributed under the University of Illinois Open Source
> > +// License. See LICENSE.TXT for details.
> > +//
> >
> +//===----------------------------------------------------------------------===//
> > +//
> > +// This pass wraps a TargetTransformInfo in a FunctionPass so that it
> can
> > +// forward along the current Function so that we can make target
> specific
> > +// decisions based on the particular subtarget specified for each
> Function.
> > +//
> >
> +//===----------------------------------------------------------------------===//
> > +
> > +#ifndef LLVM_ANALYSIS_FUNCTIONTARGETTRANSFORMINFO_H
> > +#define LLVM_ANALYSIS_FUNCTIONTARGETTRANSFORMINFO_H
> > +
> > +#include "llvm/Pass.h"
> > +#include "TargetTransformInfo.h"
> > +
> > +namespace llvm {
> > +class FunctionTargetTransformInfo final : public FunctionPass {
> > +private:
> > +  const Function *Fn;
> > +  const TargetTransformInfo *TTI;
> > +
> > +  FunctionTargetTransformInfo(const FunctionTargetTransformInfo &)
> > +      LLVM_DELETED_FUNCTION;
> > +  void operator=(const FunctionTargetTransformInfo &)
> LLVM_DELETED_FUNCTION;
> > +
> > +public:
> > +  static char ID;
> > +  FunctionTargetTransformInfo();
> > +
> > +  // Implementation boilerplate.
> > +  void getAnalysisUsage(AnalysisUsage &AU) const override;
> > +  void releaseMemory() override;
> > +  bool runOnFunction(Function &F) override;
> > +
> > +  // Shimmed functions from TargetTransformInfo.
> > +  void
> > +  getUnrollingPreferences(Loop *L,
> > +                          TargetTransformInfo::UnrollingPreferences
> &UP) const {
> > +    TTI->getUnrollingPreferences(Fn, L, UP);
> > +  }
> > +};
> > +}
> > +#endif
> >
> > Modified: llvm/trunk/include/llvm/Analysis/TargetTransformInfo.h
> > URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/TargetTransformInfo.h?rev=218004&r1=218003&r2=218004&view=diff
> >
> ==============================================================================
> > --- llvm/trunk/include/llvm/Analysis/TargetTransformInfo.h (original)
> > +++ llvm/trunk/include/llvm/Analysis/TargetTransformInfo.h Wed Sep 17
> 19:34:14 2014
> > @@ -28,6 +28,7 @@
> >
> > namespace llvm {
> >
> > +class Function;
> > class GlobalValue;
> > class Loop;
> > class Type;
> > @@ -227,7 +228,8 @@ public:
> >   /// \brief Get target-customized preferences for the generic loop
> unrolling
> >   /// transformation. The caller will initialize UP with the current
> >   /// target-independent defaults.
> > -  virtual void getUnrollingPreferences(Loop *L, UnrollingPreferences
> &UP) const;
> > +  virtual void getUnrollingPreferences(const Function *F, Loop *L,
> > +                                       UnrollingPreferences &UP) const;
> >
> >   /// @}
> >
> >
> > Modified: llvm/trunk/include/llvm/InitializePasses.h
> > URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/InitializePasses.h?rev=218004&r1=218003&r2=218004&view=diff
> >
> ==============================================================================
> > --- llvm/trunk/include/llvm/InitializePasses.h (original)
> > +++ llvm/trunk/include/llvm/InitializePasses.h Wed Sep 17 19:34:14 2014
> > @@ -261,6 +261,7 @@ void initializeTailDuplicatePassPass(Pas
> > void initializeTargetPassConfigPass(PassRegistry&);
> > void initializeDataLayoutPassPass(PassRegistry &);
> > void initializeTargetTransformInfoAnalysisGroup(PassRegistry&);
> > +void initializeFunctionTargetTransformInfoPass(PassRegistry &);
> > void initializeNoTTIPass(PassRegistry&);
> > void initializeTargetLibraryInfoPass(PassRegistry&);
> > void initializeAssumptionTrackerPass(PassRegistry &);
> >
> > Modified: llvm/trunk/include/llvm/Target/TargetMachine.h
> > URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/TargetMachine.h?rev=218004&r1=218003&r2=218004&view=diff
> >
> ==============================================================================
> > --- llvm/trunk/include/llvm/Target/TargetMachine.h (original)
> > +++ llvm/trunk/include/llvm/Target/TargetMachine.h Wed Sep 17 19:34:14
> 2014
> > @@ -99,6 +99,9 @@ public:
> >   virtual const TargetSubtargetInfo *getSubtargetImpl() const {
> >     return nullptr;
> >   }
> > +  virtual const TargetSubtargetInfo *getSubtargetImpl(const Function *)
> const {
> > +    return getSubtargetImpl();
> > +  }
> >
> >   /// getSubtarget - This method returns a pointer to the specified type
> of
> >   /// TargetSubtargetInfo.  In debug builds, it verifies that the object
> being
> > @@ -106,6 +109,9 @@ public:
> >   template<typename STC> const STC &getSubtarget() const {
> >     return *static_cast<const STC*>(getSubtargetImpl());
> >   }
> > +  template <typename STC> const STC &getSubtarget(const Function *)
> const {
> > +    return *static_cast<const STC*>(getSubtargetImpl());
> > +  }
> >
> >   /// \brief Reset the target options based on the function's attributes.
> >   void resetTargetOptions(const MachineFunction *MF) const;
> >
> > Added: llvm/trunk/lib/Analysis/FunctionTargetTransformInfo.cpp
> > URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/FunctionTargetTransformInfo.cpp?rev=218004&view=auto
> >
> ==============================================================================
> > --- llvm/trunk/lib/Analysis/FunctionTargetTransformInfo.cpp (added)
> > +++ llvm/trunk/lib/Analysis/FunctionTargetTransformInfo.cpp Wed Sep 17
> 19:34:14 2014
> > @@ -0,0 +1,50 @@
> > +//===- llvm/Analysis/FunctionTargetTransformInfo.h --------------*- C++
> -*-===//
> > +//
> > +//                     The LLVM Compiler Infrastructure
> > +//
> > +// This file is distributed under the University of Illinois Open Source
> > +// License. See LICENSE.TXT for details.
> > +//
> >
> +//===----------------------------------------------------------------------===//
> > +//
> > +// This pass wraps a TargetTransformInfo in a FunctionPass so that it
> can
> > +// forward along the current Function so that we can make target
> specific
> > +// decisions based on the particular subtarget specified for each
> Function.
> > +//
> >
> +//===----------------------------------------------------------------------===//
> > +
> > +#include "llvm/InitializePasses.h"
> > +#include "llvm/Analysis/FunctionTargetTransformInfo.h"
> > +
> > +using namespace llvm;
> > +
> > +#define DEBUG_TYPE "function-tti"
> > +static const char ftti_name[] = "Function TargetTransformInfo";
> > +INITIALIZE_PASS_BEGIN(FunctionTargetTransformInfo, "function_tti",
> ftti_name, false, true)
> > +INITIALIZE_AG_DEPENDENCY(TargetTransformInfo)
> > +INITIALIZE_PASS_END(FunctionTargetTransformInfo, "function_tti",
> ftti_name, false, true)
> > +char FunctionTargetTransformInfo::ID = 0;
> > +
> > +namespace llvm {
> > +FunctionPass *createFunctionTargetTransformInfoPass() {
> > +  return new FunctionTargetTransformInfo();
> > +}
> > +}
> > +
> > +FunctionTargetTransformInfo::FunctionTargetTransformInfo()
> > +  : FunctionPass(ID), Fn(nullptr), TTI(nullptr) {
> > +
> initializeFunctionTargetTransformInfoPass(*PassRegistry::getPassRegistry());
> > +}
> > +
> > +void FunctionTargetTransformInfo::getAnalysisUsage(AnalysisUsage &AU)
> const {
> > +  AU.setPreservesAll();
> > +  AU.addRequired<TargetTransformInfo>();
> > +}
> > +
> > +void FunctionTargetTransformInfo::releaseMemory() {}
> > +
> > +bool FunctionTargetTransformInfo::runOnFunction(Function &F) {
> > +  Fn = &F;
> > +  TTI = &getAnalysis<TargetTransformInfo>();
> > +  return false;
> > +}
> >
> > Modified: llvm/trunk/lib/Analysis/TargetTransformInfo.cpp
> > URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/TargetTransformInfo.cpp?rev=218004&r1=218003&r2=218004&view=diff
> >
> ==============================================================================
> > --- llvm/trunk/lib/Analysis/TargetTransformInfo.cpp (original)
> > +++ llvm/trunk/lib/Analysis/TargetTransformInfo.cpp Wed Sep 17 19:34:14
> 2014
> > @@ -87,9 +87,10 @@ bool TargetTransformInfo::isLoweredToCal
> >   return PrevTTI->isLoweredToCall(F);
> > }
> >
> > -void TargetTransformInfo::getUnrollingPreferences(Loop *L,
> > -                            UnrollingPreferences &UP) const {
> > -  PrevTTI->getUnrollingPreferences(L, UP);
> > +void
> > +TargetTransformInfo::getUnrollingPreferences(const Function *F, Loop *L,
> > +                                             UnrollingPreferences &UP)
> const {
> > +  PrevTTI->getUnrollingPreferences(F, L, UP);
> > }
> >
> > bool TargetTransformInfo::isLegalAddImmediate(int64_t Imm) const {
> > @@ -487,8 +488,8 @@ struct NoTTI final : ImmutablePass, Targ
> >     return true;
> >   }
> >
> > -  void getUnrollingPreferences(Loop *, UnrollingPreferences &) const
> override {
> > -  }
> > +  void getUnrollingPreferences(const Function *, Loop *,
> > +                               UnrollingPreferences &) const override {}
> >
> >   bool isLegalAddImmediate(int64_t Imm) const override {
> >     return false;
> >
> > Modified: llvm/trunk/lib/CodeGen/BasicTargetTransformInfo.cpp
> > URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/BasicTargetTransformInfo.cpp?rev=218004&r1=218003&r2=218004&view=diff
> >
> ==============================================================================
> > --- llvm/trunk/lib/CodeGen/BasicTargetTransformInfo.cpp (original)
> > +++ llvm/trunk/lib/CodeGen/BasicTargetTransformInfo.cpp Wed Sep 17
> 19:34:14 2014
> > @@ -92,7 +92,7 @@ public:
> >   unsigned getJumpBufSize() const override;
> >   bool shouldBuildLookupTables() const override;
> >   bool haveFastSqrt(Type *Ty) const override;
> > -  void getUnrollingPreferences(Loop *L,
> > +  void getUnrollingPreferences(const Function *F, Loop *L,
> >                                UnrollingPreferences &UP) const override;
> >
> >   /// @}
> > @@ -199,7 +199,7 @@ bool BasicTTI::haveFastSqrt(Type *Ty) co
> >   return TLI->isTypeLegal(VT) &&
> TLI->isOperationLegalOrCustom(ISD::FSQRT, VT);
> > }
> >
> > -void BasicTTI::getUnrollingPreferences(Loop *L,
> > +void BasicTTI::getUnrollingPreferences(const Function *F, Loop *L,
> >                                        UnrollingPreferences &UP) const {
> >   // This unrolling functionality is target independent, but to provide
> some
> >   // motivation for its intended use, for x86:
> > @@ -225,7 +225,7 @@ void BasicTTI::getUnrollingPreferences(L
> >   // until someone finds a case where it matters in practice.
> >
> >   unsigned MaxOps;
> > -  const TargetSubtargetInfo *ST =
> &TM->getSubtarget<TargetSubtargetInfo>();
> > +  const TargetSubtargetInfo *ST =
> &TM->getSubtarget<TargetSubtargetInfo>(F);
> >   if (PartialUnrollingThreshold.getNumOccurrences() > 0)
> >     MaxOps = PartialUnrollingThreshold;
> >   else if (ST->getSchedModel().LoopMicroOpBufferSize > 0)
> >
> > Modified: llvm/trunk/lib/Target/PowerPC/PPCTargetTransformInfo.cpp
> > URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PowerPC/PPCTargetTransformInfo.cpp?rev=218004&r1=218003&r2=218004&view=diff
> >
> ==============================================================================
> > --- llvm/trunk/lib/Target/PowerPC/PPCTargetTransformInfo.cpp (original)
> > +++ llvm/trunk/lib/Target/PowerPC/PPCTargetTransformInfo.cpp Wed Sep 17
> 19:34:14 2014
> > @@ -38,6 +38,7 @@ void initializePPCTTIPass(PassRegistry &
> > namespace {
> >
> > class PPCTTI final : public ImmutablePass, public TargetTransformInfo {
> > +  const TargetMachine *TM;
> >   const PPCSubtarget *ST;
> >   const PPCTargetLowering *TLI;
> >
> > @@ -47,7 +48,7 @@ public:
> >   }
> >
> >   PPCTTI(const PPCTargetMachine *TM)
> > -      : ImmutablePass(ID), ST(TM->getSubtargetImpl()),
> > +      : ImmutablePass(ID), TM(TM), ST(TM->getSubtargetImpl()),
> >         TLI(TM->getSubtargetImpl()->getTargetLowering()) {
> >     initializePPCTTIPass(*PassRegistry::getPassRegistry());
> >   }
> > @@ -80,8 +81,8 @@ public:
> >                          Type *Ty) const override;
> >
> >   PopcntSupportKind getPopcntSupport(unsigned TyWidth) const override;
> > -  void getUnrollingPreferences(
> > -    Loop *L, UnrollingPreferences &UP) const override;
> > +  void getUnrollingPreferences(const Function *F, Loop *L,
> > +                               UnrollingPreferences &UP) const override;
> >
> >   /// @}
> >
> > @@ -269,8 +270,9 @@ unsigned PPCTTI::getIntImmCost(unsigned
> >   return PPCTTI::getIntImmCost(Imm, Ty);
> > }
> >
> > -void PPCTTI::getUnrollingPreferences(Loop *L, UnrollingPreferences &UP)
> const {
> > -  if (ST->getDarwinDirective() == PPC::DIR_A2) {
> > +void PPCTTI::getUnrollingPreferences(const Function *F, Loop *L,
> > +                                     UnrollingPreferences &UP) const {
> > +  if (TM->getSubtarget<PPCSubtarget>(F).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;
> >
> > Modified: llvm/trunk/lib/Target/R600/AMDGPUTargetTransformInfo.cpp
> > URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/R600/AMDGPUTargetTransformInfo.cpp?rev=218004&r1=218003&r2=218004&view=diff
> >
> ==============================================================================
> > --- llvm/trunk/lib/Target/R600/AMDGPUTargetTransformInfo.cpp (original)
> > +++ llvm/trunk/lib/Target/R600/AMDGPUTargetTransformInfo.cpp Wed Sep 17
> 19:34:14 2014
> > @@ -74,7 +74,7 @@ public:
> >
> >   bool hasBranchDivergence() const override;
> >
> > -  void getUnrollingPreferences(Loop *L,
> > +  void getUnrollingPreferences(const Function *F, Loop *L,
> >                                UnrollingPreferences &UP) const override;
> >
> >   PopcntSupportKind getPopcntSupport(unsigned IntTyWidthInBit) const
> override;
> > @@ -99,7 +99,7 @@ llvm::createAMDGPUTargetTransformInfoPas
> >
> > bool AMDGPUTTI::hasBranchDivergence() const { return true; }
> >
> > -void AMDGPUTTI::getUnrollingPreferences(Loop *L,
> > +void AMDGPUTTI::getUnrollingPreferences(const Function *, Loop *L,
> >                                         UnrollingPreferences &UP) const {
> >   UP.Threshold = 300; // Twice the default.
> >   UP.Count = UINT_MAX;
> >
> > Modified: llvm/trunk/lib/Transforms/Scalar/LoopUnrollPass.cpp
> > URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/LoopUnrollPass.cpp?rev=218004&r1=218003&r2=218004&view=diff
> >
> ==============================================================================
> > --- llvm/trunk/lib/Transforms/Scalar/LoopUnrollPass.cpp (original)
> > +++ llvm/trunk/lib/Transforms/Scalar/LoopUnrollPass.cpp Wed Sep 17
> 19:34:14 2014
> > @@ -15,6 +15,7 @@
> > #include "llvm/Transforms/Scalar.h"
> > #include "llvm/Analysis/AssumptionTracker.h"
> > #include "llvm/Analysis/CodeMetrics.h"
> > +#include "llvm/Analysis/FunctionTargetTransformInfo.h"
> > #include "llvm/Analysis/LoopPass.h"
> > #include "llvm/Analysis/ScalarEvolution.h"
> > #include "llvm/Analysis/TargetTransformInfo.h"
> > @@ -113,6 +114,7 @@ namespace {
> >       AU.addRequired<ScalarEvolution>();
> >       AU.addPreserved<ScalarEvolution>();
> >       AU.addRequired<TargetTransformInfo>();
> > +      AU.addRequired<FunctionTargetTransformInfo>();
> >       // FIXME: Loop unroll requires LCSSA. And LCSSA requires dom info.
> >       // If loop unroll does not preserve dom info then LCSSA pass on
> next
> >       // loop will receive invalid dom info.
> > @@ -122,7 +124,7 @@ namespace {
> >
> >     // Fill in the UnrollingPreferences parameter with values from the
> >     // TargetTransformationInfo.
> > -    void getUnrollingPreferences(Loop *L, const TargetTransformInfo
> &TTI,
> > +    void getUnrollingPreferences(Loop *L, const
> FunctionTargetTransformInfo &FTTI,
> >
> TargetTransformInfo::UnrollingPreferences &UP) {
> >       UP.Threshold = CurrentThreshold;
> >       UP.OptSizeThreshold = OptSizeUnrollThreshold;
> > @@ -132,7 +134,7 @@ namespace {
> >       UP.MaxCount = UINT_MAX;
> >       UP.Partial = CurrentAllowPartial;
> >       UP.Runtime = CurrentRuntime;
> > -      TTI.getUnrollingPreferences(L, UP);
> > +      FTTI.getUnrollingPreferences(L, UP);
> >     }
> >
> >     // Select and return an unroll count based on parameters from
> > @@ -185,6 +187,7 @@ char LoopUnroll::ID = 0;
> > INITIALIZE_PASS_BEGIN(LoopUnroll, "loop-unroll", "Unroll loops", false,
> false)
> > INITIALIZE_AG_DEPENDENCY(TargetTransformInfo)
> > INITIALIZE_PASS_DEPENDENCY(AssumptionTracker)
> > +INITIALIZE_PASS_DEPENDENCY(FunctionTargetTransformInfo)
> > INITIALIZE_PASS_DEPENDENCY(LoopInfo)
> > INITIALIZE_PASS_DEPENDENCY(LoopSimplify)
> > INITIALIZE_PASS_DEPENDENCY(LCSSA)
> > @@ -358,6 +361,8 @@ bool LoopUnroll::runOnLoop(Loop *L, LPPa
> >   LoopInfo *LI = &getAnalysis<LoopInfo>();
> >   ScalarEvolution *SE = &getAnalysis<ScalarEvolution>();
> >   const TargetTransformInfo &TTI = getAnalysis<TargetTransformInfo>();
> > +  const FunctionTargetTransformInfo &FTTI =
> > +      getAnalysis<FunctionTargetTransformInfo>();
> >   AssumptionTracker *AT = &getAnalysis<AssumptionTracker>();
> >
> >   BasicBlock *Header = L->getHeader();
> > @@ -372,7 +377,7 @@ bool LoopUnroll::runOnLoop(Loop *L, LPPa
> >   bool HasPragma = PragmaFullUnroll || PragmaCount > 0;
> >
> >   TargetTransformInfo::UnrollingPreferences UP;
> > -  getUnrollingPreferences(L, TTI, UP);
> > +  getUnrollingPreferences(L, FTTI, UP);
> >
> >   // Find trip count and trip multiple if count is not available
> >   unsigned TripCount = 0;
> >
> >
> > _______________________________________________
> > llvm-commits mailing list
> > llvm-commits at cs.uiuc.edu
> > http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140917/be7456bd/attachment.html>


More information about the llvm-commits mailing list