blob: 731a5adf3d739714d9ea8fd7a82bb09f6e4d6e60 [file] [log] [blame]
Chandler Carruth93dcdc42015-01-31 11:17:59 +00001//===-- ARMTargetTransformInfo.h - ARM specific TTI -------------*- 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//===----------------------------------------------------------------------===//
9/// \file
10/// This file a TargetTransformInfo::Concept conforming object specific to the
11/// ARM 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_ARM_ARMTARGETTRANSFORMINFO_H
18#define LLVM_LIB_TARGET_ARM_ARMTARGETTRANSFORMINFO_H
19
20#include "ARM.h"
21#include "ARMTargetMachine.h"
22#include "llvm/Analysis/TargetTransformInfo.h"
23#include "llvm/CodeGen/BasicTTIImpl.h"
24#include "llvm/Target/TargetLowering.h"
25
26namespace llvm {
27
28class ARMTTIImpl : public BasicTTIImplBase<ARMTTIImpl> {
29 typedef BasicTTIImplBase<ARMTTIImpl> BaseT;
30 typedef TargetTransformInfo TTI;
Chandler Carruthc340ca82015-02-01 14:01:15 +000031 friend BaseT;
Chandler Carruth93dcdc42015-01-31 11:17:59 +000032
33 const ARMSubtarget *ST;
34 const ARMTargetLowering *TLI;
35
36 /// Estimate the overhead of scalarizing an instruction. Insert and Extract
37 /// are set if the result needs to be inserted and/or extracted from vectors.
38 unsigned getScalarizationOverhead(Type *Ty, bool Insert, bool Extract);
39
Chandler Carruthc956ab662015-02-01 14:22:17 +000040 const ARMSubtarget *getST() const { return ST; }
Chandler Carruthc340ca82015-02-01 14:01:15 +000041 const ARMTargetLowering *getTLI() const { return TLI; }
42
Chandler Carruth93dcdc42015-01-31 11:17:59 +000043public:
Eric Christophera4e5d3c2015-09-16 23:38:13 +000044 explicit ARMTTIImpl(const ARMBaseTargetMachine *TM, const Function &F)
Mehdi Amini5010ebf2015-07-09 02:08:42 +000045 : BaseT(TM, F.getParent()->getDataLayout()), ST(TM->getSubtargetImpl(F)),
46 TLI(ST->getTargetLowering()) {}
Chandler Carruth93dcdc42015-01-31 11:17:59 +000047
Silviu Barangae748c9e2015-09-01 11:19:15 +000048 bool enableInterleavedAccessVectorization() { return true; }
49
Renato Golin4b18a512016-04-18 12:06:47 +000050 /// Floating-point computation using ARMv8 AArch32 Advanced
51 /// SIMD instructions remains unchanged from ARMv7. Only AArch64 SIMD
52 /// is IEEE-754 compliant, but it's not covered in this target.
Renato Golin5cb666a2016-04-14 20:42:18 +000053 bool isFPVectorizationPotentiallyUnsafe() {
Renato Golin4b18a512016-04-18 12:06:47 +000054 return !ST->isTargetDarwin();
Renato Golin5cb666a2016-04-14 20:42:18 +000055 }
56
Chandler Carruth93dcdc42015-01-31 11:17:59 +000057 /// \name Scalar TTI Implementations
58 /// @{
59
Sjoerd Meijer38c2cd02016-07-14 07:44:20 +000060 int getIntImmCodeSizeCost(unsigned Opcode, unsigned Idx, const APInt &Imm,
61 Type *Ty);
62
Chandler Carruth93dcdc42015-01-31 11:17:59 +000063 using BaseT::getIntImmCost;
Chandler Carruth93205eb2015-08-05 18:08:10 +000064 int getIntImmCost(const APInt &Imm, Type *Ty);
Chandler Carruth93dcdc42015-01-31 11:17:59 +000065
Tim Northover903f81b2016-04-15 18:17:18 +000066 int getIntImmCost(unsigned Opcode, unsigned Idx, const APInt &Imm, Type *Ty);
Tim Northover5c02f9a2016-04-13 23:08:27 +000067
Chandler Carruth93dcdc42015-01-31 11:17:59 +000068 /// @}
69
70 /// \name Vector TTI Implementations
71 /// @{
72
73 unsigned getNumberOfRegisters(bool Vector) {
74 if (Vector) {
75 if (ST->hasNEON())
76 return 16;
77 return 0;
78 }
79
80 if (ST->isThumb1Only())
81 return 8;
82 return 13;
83 }
84
85 unsigned getRegisterBitWidth(bool Vector) {
86 if (Vector) {
87 if (ST->hasNEON())
88 return 128;
89 return 0;
90 }
91
92 return 32;
93 }
94
Wei Mi062c7442015-05-06 17:12:25 +000095 unsigned getMaxInterleaveFactor(unsigned VF) {
Diana Picus92423ce2016-06-27 09:08:23 +000096 return ST->getMaxInterleaveFactor();
Chandler Carruth93dcdc42015-01-31 11:17:59 +000097 }
98
Chandler Carruth93205eb2015-08-05 18:08:10 +000099 int getShuffleCost(TTI::ShuffleKind Kind, Type *Tp, int Index, Type *SubTp);
Chandler Carruth93dcdc42015-01-31 11:17:59 +0000100
Chandler Carruth93205eb2015-08-05 18:08:10 +0000101 int getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src);
Chandler Carruth93dcdc42015-01-31 11:17:59 +0000102
Chandler Carruth93205eb2015-08-05 18:08:10 +0000103 int getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy);
Chandler Carruth93dcdc42015-01-31 11:17:59 +0000104
Chandler Carruth93205eb2015-08-05 18:08:10 +0000105 int getVectorInstrCost(unsigned Opcode, Type *Val, unsigned Index);
Chandler Carruth93dcdc42015-01-31 11:17:59 +0000106
Mohammed Agabaria23599ba2017-01-05 14:03:41 +0000107 int getAddressComputationCost(Type *Val, ScalarEvolution *SE,
108 const SCEV *Ptr);
Chandler Carruth93dcdc42015-01-31 11:17:59 +0000109
Chandler Carruth93205eb2015-08-05 18:08:10 +0000110 int getFPOpCost(Type *Ty);
Cameron Esfahani17177d12015-02-05 02:09:33 +0000111
Chandler Carruth93205eb2015-08-05 18:08:10 +0000112 int getArithmeticInstrCost(
Chandler Carruth93dcdc42015-01-31 11:17:59 +0000113 unsigned Opcode, Type *Ty,
114 TTI::OperandValueKind Op1Info = TTI::OK_AnyValue,
115 TTI::OperandValueKind Op2Info = TTI::OK_AnyValue,
116 TTI::OperandValueProperties Opd1PropInfo = TTI::OP_None,
117 TTI::OperandValueProperties Opd2PropInfo = TTI::OP_None);
118
Chandler Carruth93205eb2015-08-05 18:08:10 +0000119 int getMemoryOpCost(unsigned Opcode, Type *Src, unsigned Alignment,
120 unsigned AddressSpace);
Chandler Carruth93dcdc42015-01-31 11:17:59 +0000121
Chandler Carruth93205eb2015-08-05 18:08:10 +0000122 int getInterleavedMemoryOpCost(unsigned Opcode, Type *VecTy, unsigned Factor,
123 ArrayRef<unsigned> Indices, unsigned Alignment,
124 unsigned AddressSpace);
Oliver Stannard4df1cc02016-10-07 08:48:24 +0000125
126 bool shouldBuildLookupTablesForConstant(Constant *C) const {
127 // In the ROPI and RWPI relocation models we can't have pointers to global
128 // variables or functions in constant data, so don't convert switches to
129 // lookup tables if any of the values would need relocation.
130 if (ST->isROPI() || ST->isRWPI())
131 return !C->needsRelocation();
132
133 return true;
134 }
Chandler Carruth93dcdc42015-01-31 11:17:59 +0000135 /// @}
136};
137
138} // end namespace llvm
139
140#endif