LLVM  10.0.0svn
Go to the documentation of this file.
1 //==- HexagonTargetTransformInfo.cpp - Hexagon specific TTI pass -*- C++ -*-==//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 /// \file
8 /// This file implements a TargetTransformInfo analysis pass specific to the
9 /// Hexagon target machine. It uses the target's detailed information to provide
10 /// more precise answers to certain TTI queries, while letting the target
11 /// independent and default TTI implementations handle the rest.
12 ///
13 //===----------------------------------------------------------------------===//
18 #include "Hexagon.h"
19 #include "HexagonSubtarget.h"
20 #include "HexagonTargetMachine.h"
21 #include "llvm/ADT/ArrayRef.h"
24 #include "llvm/IR/Function.h"
26 namespace llvm {
28 class Loop;
29 class ScalarEvolution;
30 class User;
31 class Value;
33 class HexagonTTIImpl : public BasicTTIImplBase<HexagonTTIImpl> {
35  using TTI = TargetTransformInfo;
37  friend BaseT;
39  const HexagonSubtarget &ST;
40  const HexagonTargetLowering &TLI;
42  const HexagonSubtarget *getST() const { return &ST; }
43  const HexagonTargetLowering *getTLI() const { return &TLI; }
45  bool useHVX() const;
46  bool isTypeForHVX(Type *VecTy) const;
48  // Returns the number of vector elements of Ty, if Ty is a vector type,
49  // or 1 if Ty is a scalar type. It is incorrect to call this function
50  // with any other type.
51  unsigned getTypeNumElements(Type *Ty) const;
53 public:
54  explicit HexagonTTIImpl(const HexagonTargetMachine *TM, const Function &F)
55  : BaseT(TM, F.getParent()->getDataLayout()),
56  ST(*TM->getSubtargetImpl(F)), TLI(*ST.getTargetLowering()) {}
58  /// \name Scalar TTI Implementations
59  /// @{
61  TTI::PopcntSupportKind getPopcntSupport(unsigned IntTyWidthInBit) const;
63  // The Hexagon target can unroll loops with run-time trip counts.
67  /// Bias LSR towards creating post-increment opportunities.
68  bool shouldFavorPostInc() const;
70  // L1 cache prefetch.
71  unsigned getPrefetchDistance() const override;
72  unsigned getCacheLineSize() const override;
74  /// @}
76  /// \name Vector TTI Implementations
77  /// @{
79  unsigned getNumberOfRegisters(bool vector) const;
80  unsigned getMaxInterleaveFactor(unsigned VF);
81  unsigned getRegisterBitWidth(bool Vector) const;
82  unsigned getMinVectorRegisterBitWidth() const;
83  unsigned getMinimumVF(unsigned ElemWidth) const;
85  bool shouldMaximizeVectorBandwidth(bool OptSize) const {
86  return true;
87  }
89  return false;
90  }
92  return false;
93  }
94  bool enableAggressiveInterleaving(bool LoopHasReductions) {
95  return false;
96  }
98  return false;
99  }
101  return true;
102  }
104  unsigned getScalarizationOverhead(Type *Ty, bool Insert, bool Extract);
106  unsigned VF);
107  unsigned getCallInstrCost(Function *F, Type *RetTy, ArrayRef<Type*> Tys);
108  unsigned getIntrinsicInstrCost(Intrinsic::ID ID, Type *RetTy,
109  ArrayRef<Value*> Args, FastMathFlags FMF, unsigned VF);
110  unsigned getIntrinsicInstrCost(Intrinsic::ID ID, Type *RetTy,
112  unsigned ScalarizationCostPassed = UINT_MAX);
114  const SCEV *S);
115  unsigned getMemoryOpCost(unsigned Opcode, Type *Src, unsigned Alignment,
116  unsigned AddressSpace, const Instruction *I = nullptr);
117  unsigned getMaskedMemoryOpCost(unsigned Opcode, Type *Src, unsigned Alignment,
118  unsigned AddressSpace);
119  unsigned getShuffleCost(TTI::ShuffleKind Kind, Type *Tp, int Index,
120  Type *SubTp);
121  unsigned getGatherScatterOpCost(unsigned Opcode, Type *DataTy, Value *Ptr,
122  bool VariableMask, unsigned Alignment);
123  unsigned getInterleavedMemoryOpCost(unsigned Opcode, Type *VecTy,
124  unsigned Factor, ArrayRef<unsigned> Indices, unsigned Alignment,
125  unsigned AddressSpace, bool UseMaskForCond = false,
126  bool UseMaskForGaps = false);
127  unsigned getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy,
128  const Instruction *I);
129  unsigned getArithmeticInstrCost(unsigned Opcode, Type *Ty,
135  unsigned getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src,
136  const Instruction *I = nullptr);
137  unsigned getVectorInstrCost(unsigned Opcode, Type *Val, unsigned Index);
139  unsigned getCFInstrCost(unsigned Opcode) {
140  return 1;
141  }
143  /// @}
147  // Hexagon specific decision to generate a lookup table.
148  bool shouldBuildLookupTables() const;
149 };
151 } // end namespace llvm
unsigned getOperandsScalarizationOverhead(ArrayRef< const Value *> Args, unsigned VF)
unsigned getScalarizationOverhead(Type *Ty, bool Insert, bool Extract)
unsigned getArithmeticInstrCost(unsigned Opcode, Type *Ty, TTI::OperandValueKind Opd1Info=TTI::OK_AnyValue, TTI::OperandValueKind Opd2Info=TTI::OK_AnyValue, TTI::OperandValueProperties Opd1PropInfo=TTI::OP_None, TTI::OperandValueProperties Opd2PropInfo=TTI::OP_None, ArrayRef< const Value *> Args=ArrayRef< const Value *>())
int getUserCost(const User *U, ArrayRef< const Value *> Operands)
unsigned getMinimumVF(unsigned ElemWidth) const
This class represents lattice values for constants.
Definition: AllocatorList.h:23
The main scalar evolution driver.
unsigned getInterleavedMemoryOpCost(unsigned Opcode, Type *VecTy, unsigned Factor, ArrayRef< unsigned > Indices, unsigned Alignment, unsigned AddressSpace, bool UseMaskForCond=false, bool UseMaskForGaps=false)
Base class which can be used to help build a TTI implementation.
Definition: BasicTTIImpl.h:77
HexagonTTIImpl(const HexagonTargetMachine *TM, const Function &F)
unsigned getGatherScatterOpCost(unsigned Opcode, Type *DataTy, Value *Ptr, bool VariableMask, unsigned Alignment)
unsigned getCFInstrCost(unsigned Opcode)
mir Rename Register Operands
unsigned getMemoryOpCost(unsigned Opcode, Type *Src, unsigned Alignment, unsigned AddressSpace, const Instruction *I=nullptr)
Flags indicating the kind of support for population count.
unsigned getMinVectorRegisterBitWidth() const
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:32
unsigned getAddressComputationCost(Type *Tp, ScalarEvolution *SE, const SCEV *S)
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:46
unsigned getRegisterBitWidth(bool Vector) const
unsigned getShuffleCost(TTI::ShuffleKind Kind, Type *Tp, int Index, Type *SubTp)
This file provides a helper that implements much of the TTI interface in terms of the target-independ...
unsigned getCallInstrCost(Function *F, Type *RetTy, ArrayRef< Type *> Tys)
Additional properties of an operand&#39;s values.
unsigned getVectorInstrCost(unsigned Opcode, Type *Val, unsigned Index)
bool shouldFavorPostInc() const
Bias LSR towards creating post-increment opportunities.
bool enableAggressiveInterleaving(bool LoopHasReductions)
This pass provides access to the codegen interfaces that are needed for IR-level transformations.
Definition: NVPTXBaseInfo.h:21
unsigned getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy, const Instruction *I)
could "use" a pointer
unsigned getIntrinsicInstrCost(Intrinsic::ID ID, Type *RetTy, ArrayRef< Value *> Args, FastMathFlags FMF, unsigned VF)
This class represents an analyzed expression in the program.
unsigned getNumberOfRegisters(bool vector) const
— Vector TTI begin —
Represents a single loop in the control flow graph.
Definition: LoopInfo.h:509
Parameters that control the generic loop unrolling transformation.
#define I(x, y, z)
Definition: MD5.cpp:58
unsigned getMaxInterleaveFactor(unsigned VF)
unsigned getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src, const Instruction *I=nullptr)
unsigned getMaskedMemoryOpCost(unsigned Opcode, Type *Src, unsigned Alignment, unsigned AddressSpace)
LLVM Value Representation.
Definition: Value.h:74
static const Function * getParent(const Value *V)
void getUnrollingPreferences(Loop *L, ScalarEvolution &SE, TTI::UnrollingPreferences &UP)
unsigned getCacheLineSize() const override
const DataLayout & getDataLayout() const
Convenience struct for specifying and reasoning about fast-math flags.
Definition: Operator.h:159
Additional information about an operand&#39;s possible values.
TTI::PopcntSupportKind getPopcntSupport(unsigned IntTyWidthInBit) const
This pass exposes codegen information to IR-level passes.
unsigned getPrefetchDistance() const override
— Vector TTI end —
bool shouldMaximizeVectorBandwidth(bool OptSize) const
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
The various kinds of shuffle patterns for vector queries.