blob: 8a1a3786387793832925c5f2e8790ead207b91ce [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
Chandler Carruthc956ab662015-02-01 14:22:17 +000036 const ARMSubtarget *getST() const { return ST; }
Chandler Carruthc340ca82015-02-01 14:01:15 +000037 const ARMTargetLowering *getTLI() const { return TLI; }
38
Chandler Carruth93dcdc42015-01-31 11:17:59 +000039public:
Eric Christophera4e5d3c2015-09-16 23:38:13 +000040 explicit ARMTTIImpl(const ARMBaseTargetMachine *TM, const Function &F)
Mehdi Amini5010ebf2015-07-09 02:08:42 +000041 : BaseT(TM, F.getParent()->getDataLayout()), ST(TM->getSubtargetImpl(F)),
42 TLI(ST->getTargetLowering()) {}
Chandler Carruth93dcdc42015-01-31 11:17:59 +000043
Silviu Barangae748c9e2015-09-01 11:19:15 +000044 bool enableInterleavedAccessVectorization() { return true; }
45
Renato Golin4b18a512016-04-18 12:06:47 +000046 /// Floating-point computation using ARMv8 AArch32 Advanced
47 /// SIMD instructions remains unchanged from ARMv7. Only AArch64 SIMD
48 /// is IEEE-754 compliant, but it's not covered in this target.
Renato Golin5cb666a2016-04-14 20:42:18 +000049 bool isFPVectorizationPotentiallyUnsafe() {
Renato Golin4b18a512016-04-18 12:06:47 +000050 return !ST->isTargetDarwin();
Renato Golin5cb666a2016-04-14 20:42:18 +000051 }
52
Chandler Carruth93dcdc42015-01-31 11:17:59 +000053 /// \name Scalar TTI Implementations
54 /// @{
55
Sjoerd Meijer38c2cd02016-07-14 07:44:20 +000056 int getIntImmCodeSizeCost(unsigned Opcode, unsigned Idx, const APInt &Imm,
57 Type *Ty);
58
Chandler Carruth93dcdc42015-01-31 11:17:59 +000059 using BaseT::getIntImmCost;
Chandler Carruth93205eb2015-08-05 18:08:10 +000060 int getIntImmCost(const APInt &Imm, Type *Ty);
Chandler Carruth93dcdc42015-01-31 11:17:59 +000061
Tim Northover903f81b2016-04-15 18:17:18 +000062 int getIntImmCost(unsigned Opcode, unsigned Idx, const APInt &Imm, Type *Ty);
Tim Northover5c02f9a2016-04-13 23:08:27 +000063
Chandler Carruth93dcdc42015-01-31 11:17:59 +000064 /// @}
65
66 /// \name Vector TTI Implementations
67 /// @{
68
69 unsigned getNumberOfRegisters(bool Vector) {
70 if (Vector) {
71 if (ST->hasNEON())
72 return 16;
73 return 0;
74 }
75
76 if (ST->isThumb1Only())
77 return 8;
78 return 13;
79 }
80
Daniel Neilsonc0112ae2017-06-12 14:22:21 +000081 unsigned getRegisterBitWidth(bool Vector) const {
Chandler Carruth93dcdc42015-01-31 11:17:59 +000082 if (Vector) {
83 if (ST->hasNEON())
84 return 128;
85 return 0;
86 }
87
88 return 32;
89 }
90
Wei Mi062c7442015-05-06 17:12:25 +000091 unsigned getMaxInterleaveFactor(unsigned VF) {
Diana Picus92423ce2016-06-27 09:08:23 +000092 return ST->getMaxInterleaveFactor();
Chandler Carruth93dcdc42015-01-31 11:17:59 +000093 }
94
Chandler Carruth93205eb2015-08-05 18:08:10 +000095 int getShuffleCost(TTI::ShuffleKind Kind, Type *Tp, int Index, Type *SubTp);
Chandler Carruth93dcdc42015-01-31 11:17:59 +000096
Jonas Paulssonfccc7d62017-04-12 11:49:08 +000097 int getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src,
98 const Instruction *I = nullptr);
Chandler Carruth93dcdc42015-01-31 11:17:59 +000099
Jonas Paulssonfccc7d62017-04-12 11:49:08 +0000100 int getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy,
101 const Instruction *I = nullptr);
Chandler Carruth93dcdc42015-01-31 11:17:59 +0000102
Chandler Carruth93205eb2015-08-05 18:08:10 +0000103 int getVectorInstrCost(unsigned Opcode, Type *Val, unsigned Index);
Chandler Carruth93dcdc42015-01-31 11:17:59 +0000104
Mohammed Agabaria23599ba2017-01-05 14:03:41 +0000105 int getAddressComputationCost(Type *Val, ScalarEvolution *SE,
106 const SCEV *Ptr);
Chandler Carruth93dcdc42015-01-31 11:17:59 +0000107
Chandler Carruth93205eb2015-08-05 18:08:10 +0000108 int getFPOpCost(Type *Ty);
Cameron Esfahani17177d12015-02-05 02:09:33 +0000109
Chandler Carruth93205eb2015-08-05 18:08:10 +0000110 int getArithmeticInstrCost(
Chandler Carruth93dcdc42015-01-31 11:17:59 +0000111 unsigned Opcode, Type *Ty,
112 TTI::OperandValueKind Op1Info = TTI::OK_AnyValue,
113 TTI::OperandValueKind Op2Info = TTI::OK_AnyValue,
114 TTI::OperandValueProperties Opd1PropInfo = TTI::OP_None,
Mohammed Agabaria2c96c432017-01-11 08:23:37 +0000115 TTI::OperandValueProperties Opd2PropInfo = TTI::OP_None,
116 ArrayRef<const Value *> Args = ArrayRef<const Value *>());
Chandler Carruth93dcdc42015-01-31 11:17:59 +0000117
Chandler Carruth93205eb2015-08-05 18:08:10 +0000118 int getMemoryOpCost(unsigned Opcode, Type *Src, unsigned Alignment,
Jonas Paulssonfccc7d62017-04-12 11:49:08 +0000119 unsigned AddressSpace, const Instruction *I = nullptr);
Chandler Carruth93dcdc42015-01-31 11:17:59 +0000120
Chandler Carruth93205eb2015-08-05 18:08:10 +0000121 int getInterleavedMemoryOpCost(unsigned Opcode, Type *VecTy, unsigned Factor,
122 ArrayRef<unsigned> Indices, unsigned Alignment,
123 unsigned AddressSpace);
Oliver Stannard4df1cc02016-10-07 08:48:24 +0000124
125 bool shouldBuildLookupTablesForConstant(Constant *C) const {
126 // In the ROPI and RWPI relocation models we can't have pointers to global
127 // variables or functions in constant data, so don't convert switches to
128 // lookup tables if any of the values would need relocation.
129 if (ST->isROPI() || ST->isRWPI())
130 return !C->needsRelocation();
131
132 return true;
133 }
Chandler Carruth93dcdc42015-01-31 11:17:59 +0000134 /// @}
135};
136
137} // end namespace llvm
138
139#endif