[llvm] r244089 - [Hexagon] Implement TargetTransformInfo for Hexagon

Eric Christopher echristo at gmail.com
Wed Aug 5 17:33:03 PDT 2015


Hi Krzysztof,



> -      TLOF(make_unique<HexagonTargetObjectFile>()),
> -      Subtarget(TT, CPU, FS, *this) {
> -    initAsmInfo();
> +      TLOF(make_unique<HexagonTargetObjectFile>()) {
> +  initAsmInfo();
>  }
>
> +const HexagonSubtarget *
> +HexagonTargetMachine::getSubtargetImpl(const Function &F) const {
> +  AttributeSet FnAttrs = F.getAttributes();
> +  Attribute CPUAttr =
> +      FnAttrs.getAttribute(AttributeSet::FunctionIndex, "target-cpu");
> +  Attribute FSAttr =
> +      FnAttrs.getAttribute(AttributeSet::FunctionIndex,
> "target-features");
> +
> +  std::string CPU = !CPUAttr.hasAttribute(Attribute::None)
> +                        ? CPUAttr.getValueAsString().str()
> +                        : TargetCPU;
> +  std::string FS = !FSAttr.hasAttribute(Attribute::None)
> +                       ? FSAttr.getValueAsString().str()
> +                       : TargetFS;
> +
> +  auto &I = SubtargetMap[CPU + FS];
> +  if (!I) {
> +    // This needs to be done before we create a new subtarget since any
> +    // creation will depend on the TM and the code generation flags on the
> +    // function that reside in TargetOptions.
> +    resetTargetOptions(F);
> +    I = llvm::make_unique<HexagonSubtarget>(TargetTriple, CPU, FS, *this);
> +  }
> +  return I.get();
> +}
> +
>

Are you actually planning on supporting subtarget features for different
subtargets on functions? Otherwise there's no reason to do this and you can
just have:

getSubtargetImpl(const Function &F) const {
   return &Subtarget;
}

-eric


> +TargetIRAnalysis HexagonTargetMachine::getTargetIRAnalysis() {
> +  return TargetIRAnalysis([this](Function &F) {
> +    return TargetTransformInfo(HexagonTTIImpl(this, F));
> +  });
> +}
> +
> +
>  HexagonTargetMachine::~HexagonTargetMachine() {}
>
>  namespace {
>
> Modified: llvm/trunk/lib/Target/Hexagon/HexagonTargetMachine.h
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Hexagon/HexagonTargetMachine.h?rev=244089&r1=244088&r2=244089&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/Target/Hexagon/HexagonTargetMachine.h (original)
> +++ llvm/trunk/lib/Target/Hexagon/HexagonTargetMachine.h Wed Aug  5
> 13:35:37 2015
> @@ -24,7 +24,7 @@ class Module;
>
>  class HexagonTargetMachine : public LLVMTargetMachine {
>    std::unique_ptr<TargetLoweringObjectFile> TLOF;
> -  HexagonSubtarget Subtarget;
> +  mutable StringMap<std::unique_ptr<HexagonSubtarget>> SubtargetMap;
>
>  public:
>    HexagonTargetMachine(const Target &T, const Triple &TT, StringRef CPU,
> @@ -32,12 +32,12 @@ public:
>                         Reloc::Model RM, CodeModel::Model CM,
>                         CodeGenOpt::Level OL);
>    ~HexagonTargetMachine() override;
> -  const HexagonSubtarget *getSubtargetImpl(const Function &) const
> override {
> -    return &Subtarget;
> -  }
> +  const HexagonSubtarget *getSubtargetImpl(const Function &F) const
> override;
> +
>    static unsigned getModuleMatchQuality(const Module &M);
>
>    TargetPassConfig *createPassConfig(PassManagerBase &PM) override;
> +  TargetIRAnalysis getTargetIRAnalysis() override;
>
>    TargetLoweringObjectFile *getObjFileLowering() const override {
>      return TLOF.get();
>
> Added: llvm/trunk/lib/Target/Hexagon/HexagonTargetTransformInfo.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Hexagon/HexagonTargetTransformInfo.cpp?rev=244089&view=auto
>
> ==============================================================================
> --- llvm/trunk/lib/Target/Hexagon/HexagonTargetTransformInfo.cpp (added)
> +++ llvm/trunk/lib/Target/Hexagon/HexagonTargetTransformInfo.cpp Wed Aug
> 5 13:35:37 2015
> @@ -0,0 +1,44 @@
> +//===-- HexagonTargetTransformInfo.cpp - Hexagon specific TTI pass
> --------===//
> +//
> +//                     The LLVM Compiler Infrastructure
> +//
> +// This file is distributed under the University of Illinois Open Source
> +// License. See LICENSE.TXT for details.
> +//
> +/// \file
> +/// This file implements a TargetTransformInfo analysis pass specific to
> the
> +/// Hexagon target machine. It uses the target's detailed information to
> provide
> +/// more precise answers to certain TTI queries, while letting the target
> +/// independent and default TTI implementations handle the rest.
> +///
>
> +//===----------------------------------------------------------------------===//
> +
> +#include "HexagonTargetTransformInfo.h"
> +#include "llvm/Support/Debug.h"
> +
> +using namespace llvm;
> +
> +#define DEBUG_TYPE "hexagontti"
> +
> +TargetTransformInfo::PopcntSupportKind
> +HexagonTTIImpl::getPopcntSupport(unsigned IntTyWidthInBit) const {
> +  // Return Fast Hardware support as every input  < 64 bits will be
> promoted
> +  // to 64 bits.
> +  return TargetTransformInfo::PSK_FastHardware;
> +}
> +
> +// The Hexagon target can unroll loops with run-time trip counts.
> +void HexagonTTIImpl::getUnrollingPreferences(Loop *L,
> +                                             TTI::UnrollingPreferences
> &UP) {
> +  UP.Runtime = UP.Partial = true;
> +}
> +
> +unsigned HexagonTTIImpl::getNumberOfRegisters(bool vector) const {
> +  if (vector) {
> +    // While its true that v60 has vector registers,
> +    // we do not want to advertise it through this API
> +    // as it enables LOOP and SLP vectorization.
> +    return 0;
> +  }
> +  return 32;
> +}
>
> Added: llvm/trunk/lib/Target/Hexagon/HexagonTargetTransformInfo.h
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Hexagon/HexagonTargetTransformInfo.h?rev=244089&view=auto
>
> ==============================================================================
> --- llvm/trunk/lib/Target/Hexagon/HexagonTargetTransformInfo.h (added)
> +++ llvm/trunk/lib/Target/Hexagon/HexagonTargetTransformInfo.h Wed Aug  5
> 13:35:37 2015
> @@ -0,0 +1,70 @@
> +//===-- HexagonTargetTransformInfo.cpp - Hexagon specific TTI pass
> --------===//
> +//
> +//                     The LLVM Compiler Infrastructure
> +//
> +// This file is distributed under the University of Illinois Open Source
> +// License. See LICENSE.TXT for details.
> +//
> +/// \file
> +/// This file implements a TargetTransformInfo analysis pass specific to
> the
> +/// Hexagon target machine. It uses the target's detailed information to
> provide
> +/// more precise answers to certain TTI queries, while letting the target
> +/// independent and default TTI implementations handle the rest.
> +///
>
> +//===----------------------------------------------------------------------===//
> +
> +#ifndef LLVM_LIB_TARGET_HEXAGON_HEXAGONTARGETTRANSFORMINFO_H
> +#define LLVM_LIB_TARGET_HEXAGON_HEXAGONTARGETTRANSFORMINFO_H
> +
> +#include "Hexagon.h"
> +#include "HexagonTargetMachine.h"
> +#include "llvm/Analysis/TargetTransformInfo.h"
> +#include "llvm/CodeGen/BasicTTIImpl.h"
> +#include "llvm/Target/TargetLowering.h"
> +
> +namespace llvm {
> +
> +class HexagonTTIImpl : public BasicTTIImplBase<HexagonTTIImpl> {
> +  typedef BasicTTIImplBase<HexagonTTIImpl> BaseT;
> +  typedef TargetTransformInfo TTI;
> +  friend BaseT;
> +
> +  const HexagonSubtarget *ST;
> +  const HexagonTargetLowering *TLI;
> +
> +  const HexagonSubtarget *getST() const { return ST; }
> +  const HexagonTargetLowering *getTLI() const { return TLI; }
> +
> +public:
> +  explicit HexagonTTIImpl(const HexagonTargetMachine *TM, Function &F)
> +      : BaseT(TM, F.getParent()->getDataLayout()),
> ST(TM->getSubtargetImpl(F)),
> +        TLI(ST->getTargetLowering()) {}
> +
> +  // Provide value semantics. MSVC requires that we spell all of these
> out.
> +  HexagonTTIImpl(const HexagonTTIImpl &Arg)
> +      : BaseT(static_cast<const BaseT &>(Arg)), ST(Arg.ST), TLI(Arg.TLI)
> {}
> +  HexagonTTIImpl(HexagonTTIImpl &&Arg)
> +      : BaseT(std::move(static_cast<BaseT &>(Arg))),
> ST(std::move(Arg.ST)),
> +        TLI(std::move(Arg.TLI)) {}
> +
> +  /// \name Scalar TTI Implementations
> +  /// @{
> +
> +  TTI::PopcntSupportKind getPopcntSupport(unsigned IntTyWidthInBit) const;
> +
> +  // The Hexagon target can unroll loops with run-time trip counts.
> +  void getUnrollingPreferences(Loop *L, TTI::UnrollingPreferences &UP);
> +
> +  /// @}
> +
> +  /// \name Vector TTI Implementations
> +  /// @{
> +
> +  unsigned getNumberOfRegisters(bool vector) const;
> +
> +  /// @}
> +};
> +
> +} // end namespace llvm
> +
> +#endif
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150806/c97806b1/attachment.html>


More information about the llvm-commits mailing list