LLVM  8.0.1
HexagonTargetTransformInfo.h
Go to the documentation of this file.
1 //==- HexagonTargetTransformInfo.cpp - Hexagon specific TTI pass -*- C++ -*-==//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 /// \file
9 /// This file implements a TargetTransformInfo analysis pass specific to the
10 /// Hexagon target machine. It uses the target's detailed information to provide
11 /// more precise answers to certain TTI queries, while letting the target
12 /// independent and default TTI implementations handle the rest.
13 ///
14 //===----------------------------------------------------------------------===//
15 
16 #ifndef LLVM_LIB_TARGET_HEXAGON_HEXAGONTARGETTRANSFORMINFO_H
17 #define LLVM_LIB_TARGET_HEXAGON_HEXAGONTARGETTRANSFORMINFO_H
18 
19 #include "Hexagon.h"
20 #include "HexagonSubtarget.h"
21 #include "HexagonTargetMachine.h"
22 #include "llvm/ADT/ArrayRef.h"
25 #include "llvm/IR/Function.h"
26 
27 namespace llvm {
28 
29 class Loop;
30 class ScalarEvolution;
31 class User;
32 class Value;
33 
34 class HexagonTTIImpl : public BasicTTIImplBase<HexagonTTIImpl> {
36  using TTI = TargetTransformInfo;
37 
38  friend BaseT;
39 
40  const HexagonSubtarget &ST;
41  const HexagonTargetLowering &TLI;
42 
43  const HexagonSubtarget *getST() const { return &ST; }
44  const HexagonTargetLowering *getTLI() const { return &TLI; }
45 
46  bool useHVX() const;
47  bool isTypeForHVX(Type *VecTy) const;
48 
49  // Returns the number of vector elements of Ty, if Ty is a vector type,
50  // or 1 if Ty is a scalar type. It is incorrect to call this function
51  // with any other type.
52  unsigned getTypeNumElements(Type *Ty) const;
53 
54 public:
55  explicit HexagonTTIImpl(const HexagonTargetMachine *TM, const Function &F)
56  : BaseT(TM, F.getParent()->getDataLayout()),
57  ST(*TM->getSubtargetImpl(F)), TLI(*ST.getTargetLowering()) {}
58 
59  /// \name Scalar TTI Implementations
60  /// @{
61 
62  TTI::PopcntSupportKind getPopcntSupport(unsigned IntTyWidthInBit) const;
63 
64  // The Hexagon target can unroll loops with run-time trip counts.
67 
68  /// Bias LSR towards creating post-increment opportunities.
69  bool shouldFavorPostInc() const;
70 
71  // L1 cache prefetch.
72  unsigned getPrefetchDistance() const;
73  unsigned getCacheLineSize() const;
74 
75  /// @}
76 
77  /// \name Vector TTI Implementations
78  /// @{
79 
80  unsigned getNumberOfRegisters(bool vector) const;
81  unsigned getMaxInterleaveFactor(unsigned VF);
82  unsigned getRegisterBitWidth(bool Vector) const;
83  unsigned getMinVectorRegisterBitWidth() const;
84  unsigned getMinimumVF(unsigned ElemWidth) const;
85 
86  bool shouldMaximizeVectorBandwidth(bool OptSize) const {
87  return true;
88  }
90  return false;
91  }
93  return false;
94  }
95  bool enableAggressiveInterleaving(bool LoopHasReductions) {
96  return false;
97  }
99  return false;
100  }
102  return true;
103  }
104 
105  unsigned getScalarizationOverhead(Type *Ty, bool Insert, bool Extract);
107  unsigned VF);
108  unsigned getCallInstrCost(Function *F, Type *RetTy, ArrayRef<Type*> Tys);
109  unsigned getIntrinsicInstrCost(Intrinsic::ID ID, Type *RetTy,
110  ArrayRef<Value*> Args, FastMathFlags FMF, unsigned VF);
111  unsigned getIntrinsicInstrCost(Intrinsic::ID ID, Type *RetTy,
113  unsigned ScalarizationCostPassed = UINT_MAX);
115  const SCEV *S);
116  unsigned getMemoryOpCost(unsigned Opcode, Type *Src, unsigned Alignment,
117  unsigned AddressSpace, const Instruction *I = nullptr);
118  unsigned getMaskedMemoryOpCost(unsigned Opcode, Type *Src, unsigned Alignment,
119  unsigned AddressSpace);
120  unsigned getShuffleCost(TTI::ShuffleKind Kind, Type *Tp, int Index,
121  Type *SubTp);
122  unsigned getGatherScatterOpCost(unsigned Opcode, Type *DataTy, Value *Ptr,
123  bool VariableMask, unsigned Alignment);
124  unsigned getInterleavedMemoryOpCost(unsigned Opcode, Type *VecTy,
125  unsigned Factor, ArrayRef<unsigned> Indices, unsigned Alignment,
126  unsigned AddressSpace, bool UseMaskForCond = false,
127  bool UseMaskForGaps = false);
128  unsigned getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy,
129  const Instruction *I);
130  unsigned getArithmeticInstrCost(unsigned Opcode, Type *Ty,
136  unsigned getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src,
137  const Instruction *I = nullptr);
138  unsigned getVectorInstrCost(unsigned Opcode, Type *Val, unsigned Index);
139 
140  unsigned getCFInstrCost(unsigned Opcode) {
141  return 1;
142  }
143 
144  /// @}
145 
146  int getUserCost(const User *U, ArrayRef<const Value *> Operands);
147 
148  // Hexagon specific decision to generate a lookup table.
149  bool shouldBuildLookupTables() const;
150 };
151 
152 } // end namespace llvm
153 #endif // LLVM_LIB_TARGET_HEXAGON_HEXAGONTARGETTRANSFORMINFO_H
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:24
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)
F(f)
Base class which can be used to help build a TTI implementation.
Definition: BasicTTIImpl.h:78
HexagonTTIImpl(const HexagonTargetMachine *TM, const Function &F)
unsigned getGatherScatterOpCost(unsigned Opcode, Type *DataTy, Value *Ptr, bool VariableMask, unsigned Alignment)
unsigned getCFInstrCost(unsigned Opcode)
unsigned getMemoryOpCost(unsigned Opcode, Type *Src, unsigned Alignment, unsigned AddressSpace, const Instruction *I=nullptr)
PopcntSupportKind
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:33
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)
OperandValueProperties
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.
AddressSpace
Definition: NVPTXBaseInfo.h:22
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)
unsigned getPrefetchDistance() const
— Vector TTI end —
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:465
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)
const unsigned Kind
LLVM Value Representation.
Definition: Value.h:73
static const Function * getParent(const Value *V)
void getUnrollingPreferences(Loop *L, ScalarEvolution &SE, TTI::UnrollingPreferences &UP)
const DataLayout & getDataLayout() const
Convenience struct for specifying and reasoning about fast-math flags.
Definition: Operator.h:160
OperandValueKind
Additional information about an operand&#39;s possible values.
TTI::PopcntSupportKind getPopcntSupport(unsigned IntTyWidthInBit) const
This pass exposes codegen information to IR-level passes.
bool shouldMaximizeVectorBandwidth(bool OptSize) const
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
ShuffleKind
The various kinds of shuffle patterns for vector queries.