blob: 08c1a8924220fd00085ffad86f1bd75db99774d0 [file] [log] [blame]
Eugene Zelenko96d933d2017-07-25 23:51:02 +00001//===- AArch64TargetTransformInfo.h - AArch64 specific TTI ------*- C++ -*-===//
Chandler Carruth93dcdc42015-01-31 11:17:59 +00002//
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//===----------------------------------------------------------------------===//
9/// \file
10/// This file a TargetTransformInfo::Concept conforming object specific to the
11/// AArch64 target machine. It uses the target's detailed information to
12/// provide more precise answers to certain TTI queries, while letting the
13/// target independent and default TTI implementations handle the rest.
14///
15//===----------------------------------------------------------------------===//
16
17#ifndef LLVM_LIB_TARGET_AARCH64_AARCH64TARGETTRANSFORMINFO_H
18#define LLVM_LIB_TARGET_AARCH64_AARCH64TARGETTRANSFORMINFO_H
19
20#include "AArch64.h"
Eugene Zelenko96d933d2017-07-25 23:51:02 +000021#include "AArch64Subtarget.h"
Chandler Carruth93dcdc42015-01-31 11:17:59 +000022#include "AArch64TargetMachine.h"
Eugene Zelenko96d933d2017-07-25 23:51:02 +000023#include "llvm/ADT/ArrayRef.h"
Chandler Carruth93dcdc42015-01-31 11:17:59 +000024#include "llvm/Analysis/TargetTransformInfo.h"
25#include "llvm/CodeGen/BasicTTIImpl.h"
Eugene Zelenko96d933d2017-07-25 23:51:02 +000026#include "llvm/IR/Function.h"
27#include "llvm/IR/Intrinsics.h"
28#include <cstdint>
Chandler Carruth93dcdc42015-01-31 11:17:59 +000029
30namespace llvm {
31
Eugene Zelenko96d933d2017-07-25 23:51:02 +000032class APInt;
33class Instruction;
34class IntrinsicInst;
35class Loop;
36class SCEV;
37class ScalarEvolution;
38class Type;
39class Value;
40class VectorType;
41
Chandler Carruth93dcdc42015-01-31 11:17:59 +000042class AArch64TTIImpl : public BasicTTIImplBase<AArch64TTIImpl> {
Eugene Zelenko96d933d2017-07-25 23:51:02 +000043 using BaseT = BasicTTIImplBase<AArch64TTIImpl>;
44 using TTI = TargetTransformInfo;
45
Chandler Carruthc340ca82015-02-01 14:01:15 +000046 friend BaseT;
Chandler Carruth93dcdc42015-01-31 11:17:59 +000047
48 const AArch64Subtarget *ST;
49 const AArch64TargetLowering *TLI;
50
Chandler Carruthc956ab662015-02-01 14:22:17 +000051 const AArch64Subtarget *getST() const { return ST; }
Chandler Carruthc340ca82015-02-01 14:01:15 +000052 const AArch64TargetLowering *getTLI() const { return TLI; }
53
Chandler Carruth93dcdc42015-01-31 11:17:59 +000054 enum MemIntrinsicType {
55 VECTOR_LDST_TWO_ELEMENTS,
56 VECTOR_LDST_THREE_ELEMENTS,
57 VECTOR_LDST_FOUR_ELEMENTS
58 };
59
Matthew Simpson78fd46b2017-05-09 20:18:12 +000060 bool isWideningInstruction(Type *Ty, unsigned Opcode,
61 ArrayRef<const Value *> Args);
62
Chandler Carruth93dcdc42015-01-31 11:17:59 +000063public:
Eric Christophera4e5d3c2015-09-16 23:38:13 +000064 explicit AArch64TTIImpl(const AArch64TargetMachine *TM, const Function &F)
Mehdi Amini5010ebf2015-07-09 02:08:42 +000065 : BaseT(TM, F.getParent()->getDataLayout()), ST(TM->getSubtargetImpl(F)),
Chandler Carruthc340ca82015-02-01 14:01:15 +000066 TLI(ST->getTargetLowering()) {}
Chandler Carruth93dcdc42015-01-31 11:17:59 +000067
Florian Hahn2665feb2017-06-27 22:27:32 +000068 bool areInlineCompatible(const Function *Caller,
69 const Function *Callee) const;
70
Chandler Carruth93dcdc42015-01-31 11:17:59 +000071 /// \name Scalar TTI Implementations
72 /// @{
73
74 using BaseT::getIntImmCost;
Chandler Carruth93205eb2015-08-05 18:08:10 +000075 int getIntImmCost(int64_t Val);
76 int getIntImmCost(const APInt &Imm, Type *Ty);
77 int getIntImmCost(unsigned Opcode, unsigned Idx, const APInt &Imm, Type *Ty);
78 int getIntImmCost(Intrinsic::ID IID, unsigned Idx, const APInt &Imm,
79 Type *Ty);
Chandler Carruth93dcdc42015-01-31 11:17:59 +000080 TTI::PopcntSupportKind getPopcntSupport(unsigned TyWidth);
81
82 /// @}
83
84 /// \name Vector TTI Implementations
85 /// @{
86
Silviu Baranga755ec0e2015-09-01 11:26:46 +000087 bool enableInterleavedAccessVectorization() { return true; }
88
Chandler Carruth93dcdc42015-01-31 11:17:59 +000089 unsigned getNumberOfRegisters(bool Vector) {
90 if (Vector) {
91 if (ST->hasNEON())
92 return 32;
93 return 0;
94 }
95 return 31;
96 }
97
Daniel Neilsonc0112ae2017-06-12 14:22:21 +000098 unsigned getRegisterBitWidth(bool Vector) const {
Chandler Carruth93dcdc42015-01-31 11:17:59 +000099 if (Vector) {
100 if (ST->hasNEON())
101 return 128;
102 return 0;
103 }
104 return 64;
105 }
106
Adam Nemete29686e2017-05-15 21:15:01 +0000107 unsigned getMinVectorRegisterBitWidth() {
108 return ST->getMinVectorRegisterBitWidth();
109 }
110
Wei Mi062c7442015-05-06 17:12:25 +0000111 unsigned getMaxInterleaveFactor(unsigned VF);
Chandler Carruth93dcdc42015-01-31 11:17:59 +0000112
Jonas Paulssonfccc7d62017-04-12 11:49:08 +0000113 int getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src,
114 const Instruction *I = nullptr);
Chandler Carruth93dcdc42015-01-31 11:17:59 +0000115
Matthew Simpsone5dfb082016-04-27 15:20:21 +0000116 int getExtractWithExtendCost(unsigned Opcode, Type *Dst, VectorType *VecTy,
117 unsigned Index);
118
Chandler Carruth93205eb2015-08-05 18:08:10 +0000119 int getVectorInstrCost(unsigned Opcode, Type *Val, unsigned Index);
Chandler Carruth93dcdc42015-01-31 11:17:59 +0000120
Chandler Carruth93205eb2015-08-05 18:08:10 +0000121 int getArithmeticInstrCost(
Chandler Carruth93dcdc42015-01-31 11:17:59 +0000122 unsigned Opcode, Type *Ty,
123 TTI::OperandValueKind Opd1Info = TTI::OK_AnyValue,
124 TTI::OperandValueKind Opd2Info = TTI::OK_AnyValue,
125 TTI::OperandValueProperties Opd1PropInfo = TTI::OP_None,
Mohammed Agabaria2c96c432017-01-11 08:23:37 +0000126 TTI::OperandValueProperties Opd2PropInfo = TTI::OP_None,
127 ArrayRef<const Value *> Args = ArrayRef<const Value *>());
Chandler Carruth93dcdc42015-01-31 11:17:59 +0000128
Mohammed Agabaria23599ba2017-01-05 14:03:41 +0000129 int getAddressComputationCost(Type *Ty, ScalarEvolution *SE, const SCEV *Ptr);
Chandler Carruth93dcdc42015-01-31 11:17:59 +0000130
Jonas Paulssonfccc7d62017-04-12 11:49:08 +0000131 int getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy,
132 const Instruction *I = nullptr);
Chandler Carruth93dcdc42015-01-31 11:17:59 +0000133
Chandler Carruth93205eb2015-08-05 18:08:10 +0000134 int getMemoryOpCost(unsigned Opcode, Type *Src, unsigned Alignment,
Jonas Paulssonfccc7d62017-04-12 11:49:08 +0000135 unsigned AddressSpace, const Instruction *I = nullptr);
Chandler Carruth93dcdc42015-01-31 11:17:59 +0000136
Chandler Carruth93205eb2015-08-05 18:08:10 +0000137 int getCostOfKeepingLiveOverCall(ArrayRef<Type *> Tys);
Chandler Carruth93dcdc42015-01-31 11:17:59 +0000138
Geoff Berry66d9bdb2017-06-28 15:53:17 +0000139 void getUnrollingPreferences(Loop *L, ScalarEvolution &SE,
140 TTI::UnrollingPreferences &UP);
Chandler Carruth93dcdc42015-01-31 11:17:59 +0000141
142 Value *getOrCreateResultFromMemIntrinsic(IntrinsicInst *Inst,
143 Type *ExpectedType);
144
145 bool getTgtMemIntrinsic(IntrinsicInst *Inst, MemIntrinsicInfo &Info);
146
Chandler Carruth93205eb2015-08-05 18:08:10 +0000147 int getInterleavedMemoryOpCost(unsigned Opcode, Type *VecTy, unsigned Factor,
148 ArrayRef<unsigned> Indices, unsigned Alignment,
Dorit Nuzman34da6dd2018-10-31 09:57:56 +0000149 unsigned AddressSpace,
150 bool UseMaskForCond = false,
151 bool UseMaskForGaps = false);
Adam Nemet53e758f2016-03-18 00:27:29 +0000152
Jun Bum Limdee55652017-04-03 19:20:07 +0000153 bool
154 shouldConsiderAddressTypePromotion(const Instruction &I,
155 bool &AllowPromotionWithoutCommonHeader);
156
Adam Nemet53e758f2016-03-18 00:27:29 +0000157 unsigned getCacheLineSize();
158
159 unsigned getPrefetchDistance();
Adam Nemet6d8beec2016-03-18 00:27:38 +0000160
161 unsigned getMinPrefetchStride();
Adam Nemet709e3042016-03-18 00:27:43 +0000162
163 unsigned getMaxPrefetchIterationsAhead();
Amara Emerson836b0f42017-05-10 09:42:49 +0000164
165 bool shouldExpandReduction(const IntrinsicInst *II) const {
166 return false;
167 }
Amara Emersonc9916d72017-05-16 21:29:22 +0000168
169 bool useReductionIntrinsic(unsigned Opcode, Type *Ty,
170 TTI::ReductionFlags Flags) const;
Matthew Simpsoneacfefd2018-03-16 11:34:15 +0000171
172 int getArithmeticReductionCost(unsigned Opcode, Type *Ty,
173 bool IsPairwiseForm);
Matthew Simpsonb4096eb2018-04-26 13:48:33 +0000174
175 int getShuffleCost(TTI::ShuffleKind Kind, Type *Tp, int Index, Type *SubTp);
Chandler Carruth93dcdc42015-01-31 11:17:59 +0000176 /// @}
177};
178
179} // end namespace llvm
180
Eugene Zelenko96d933d2017-07-25 23:51:02 +0000181#endif // LLVM_LIB_TARGET_AARCH64_AARCH64TARGETTRANSFORMINFO_H