blob: cd9fa07090207544e27e2664a3107261bcb4f7bd [file] [log] [blame]
Eugene Zelenko076468c2017-09-20 21:35:51 +00001//===- ARMTargetTransformInfo.h - ARM 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//===----------------------------------------------------------------------===//
Eugene Zelenko076468c2017-09-20 21:35:51 +00009//
Chandler Carruth93dcdc42015-01-31 11:17:59 +000010/// \file
11/// This file a TargetTransformInfo::Concept conforming object specific to the
12/// ARM target machine. It uses the target's detailed information to
13/// provide more precise answers to certain TTI queries, while letting the
14/// target independent and default TTI implementations handle the rest.
Eugene Zelenko076468c2017-09-20 21:35:51 +000015//
Chandler Carruth93dcdc42015-01-31 11:17:59 +000016//===----------------------------------------------------------------------===//
17
18#ifndef LLVM_LIB_TARGET_ARM_ARMTARGETTRANSFORMINFO_H
19#define LLVM_LIB_TARGET_ARM_ARMTARGETTRANSFORMINFO_H
20
21#include "ARM.h"
Eugene Zelenko076468c2017-09-20 21:35:51 +000022#include "ARMSubtarget.h"
Chandler Carruth93dcdc42015-01-31 11:17:59 +000023#include "ARMTargetMachine.h"
Eugene Zelenko076468c2017-09-20 21:35:51 +000024#include "llvm/ADT/ArrayRef.h"
Chandler Carruth93dcdc42015-01-31 11:17:59 +000025#include "llvm/Analysis/TargetTransformInfo.h"
26#include "llvm/CodeGen/BasicTTIImpl.h"
Eugene Zelenko076468c2017-09-20 21:35:51 +000027#include "llvm/IR/Constant.h"
28#include "llvm/IR/Function.h"
29#include "llvm/MC/SubtargetFeature.h"
Chandler Carruth93dcdc42015-01-31 11:17:59 +000030
31namespace llvm {
32
Eugene Zelenko076468c2017-09-20 21:35:51 +000033class APInt;
34class ARMTargetLowering;
35class Instruction;
36class Loop;
37class SCEV;
38class ScalarEvolution;
39class Type;
40class Value;
41
Chandler Carruth93dcdc42015-01-31 11:17:59 +000042class ARMTTIImpl : public BasicTTIImplBase<ARMTTIImpl> {
Eugene Zelenko076468c2017-09-20 21:35:51 +000043 using BaseT = BasicTTIImplBase<ARMTTIImpl>;
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 ARMSubtarget *ST;
49 const ARMTargetLowering *TLI;
50
Florian Hahn4adcfcf2017-07-13 08:26:17 +000051 // Currently the following features are excluded from InlineFeatureWhitelist.
52 // ModeThumb, FeatureNoARM, ModeSoftFloat, FeatureVFPOnlySP, FeatureD16
53 // Depending on whether they are set or unset, different
54 // instructions/registers are available. For example, inlining a callee with
55 // -thumb-mode in a caller with +thumb-mode, may cause the assembler to
56 // fail if the callee uses ARM only instructions, e.g. in inline asm.
57 const FeatureBitset InlineFeatureWhitelist = {
58 ARM::FeatureVFP2, ARM::FeatureVFP3, ARM::FeatureNEON, ARM::FeatureThumb2,
59 ARM::FeatureFP16, ARM::FeatureVFP4, ARM::FeatureFPARMv8,
60 ARM::FeatureFullFP16, ARM::FeatureHWDivThumb,
61 ARM::FeatureHWDivARM, ARM::FeatureDB, ARM::FeatureV7Clrex,
62 ARM::FeatureAcquireRelease, ARM::FeatureSlowFPBrcc,
63 ARM::FeaturePerfMon, ARM::FeatureTrustZone, ARM::Feature8MSecExt,
64 ARM::FeatureCrypto, ARM::FeatureCRC, ARM::FeatureRAS,
65 ARM::FeatureFPAO, ARM::FeatureFuseAES, ARM::FeatureZCZeroing,
66 ARM::FeatureProfUnpredicate, ARM::FeatureSlowVGETLNi32,
67 ARM::FeatureSlowVDUP32, ARM::FeaturePreferVMOVSR,
68 ARM::FeaturePrefISHSTBarrier, ARM::FeatureMuxedUnits,
69 ARM::FeatureSlowOddRegister, ARM::FeatureSlowLoadDSubreg,
70 ARM::FeatureDontWidenVMOVS, ARM::FeatureExpandMLx,
71 ARM::FeatureHasVMLxHazards, ARM::FeatureNEONForFPMovs,
72 ARM::FeatureNEONForFP, ARM::FeatureCheckVLDnAlign,
73 ARM::FeatureHasSlowFPVMLx, ARM::FeatureVMLxForwarding,
74 ARM::FeaturePref32BitThumb, ARM::FeatureAvoidPartialCPSR,
75 ARM::FeatureCheapPredicableCPSR, ARM::FeatureAvoidMOVsShOp,
76 ARM::FeatureHasRetAddrStack, ARM::FeatureHasNoBranchPredictor,
77 ARM::FeatureDSP, ARM::FeatureMP, ARM::FeatureVirtualization,
78 ARM::FeatureMClass, ARM::FeatureRClass, ARM::FeatureAClass,
79 ARM::FeatureNaClTrap, ARM::FeatureStrictAlign, ARM::FeatureLongCalls,
80 ARM::FeatureExecuteOnly, ARM::FeatureReserveR9, ARM::FeatureNoMovt,
81 ARM::FeatureNoNegativeImmediates
82 };
83
Chandler Carruthc956ab662015-02-01 14:22:17 +000084 const ARMSubtarget *getST() const { return ST; }
Chandler Carruthc340ca82015-02-01 14:01:15 +000085 const ARMTargetLowering *getTLI() const { return TLI; }
86
Chandler Carruth93dcdc42015-01-31 11:17:59 +000087public:
Eric Christophera4e5d3c2015-09-16 23:38:13 +000088 explicit ARMTTIImpl(const ARMBaseTargetMachine *TM, const Function &F)
Mehdi Amini5010ebf2015-07-09 02:08:42 +000089 : BaseT(TM, F.getParent()->getDataLayout()), ST(TM->getSubtargetImpl(F)),
90 TLI(ST->getTargetLowering()) {}
Chandler Carruth93dcdc42015-01-31 11:17:59 +000091
Florian Hahn4adcfcf2017-07-13 08:26:17 +000092 bool areInlineCompatible(const Function *Caller,
93 const Function *Callee) const;
94
Silviu Barangae748c9e2015-09-01 11:19:15 +000095 bool enableInterleavedAccessVectorization() { return true; }
96
Renato Golin4b18a512016-04-18 12:06:47 +000097 /// Floating-point computation using ARMv8 AArch32 Advanced
98 /// SIMD instructions remains unchanged from ARMv7. Only AArch64 SIMD
99 /// is IEEE-754 compliant, but it's not covered in this target.
Renato Golin5cb666a2016-04-14 20:42:18 +0000100 bool isFPVectorizationPotentiallyUnsafe() {
Renato Golin4b18a512016-04-18 12:06:47 +0000101 return !ST->isTargetDarwin();
Renato Golin5cb666a2016-04-14 20:42:18 +0000102 }
103
Chandler Carruth93dcdc42015-01-31 11:17:59 +0000104 /// \name Scalar TTI Implementations
105 /// @{
106
Sjoerd Meijer38c2cd02016-07-14 07:44:20 +0000107 int getIntImmCodeSizeCost(unsigned Opcode, unsigned Idx, const APInt &Imm,
108 Type *Ty);
109
Chandler Carruth93dcdc42015-01-31 11:17:59 +0000110 using BaseT::getIntImmCost;
Chandler Carruth93205eb2015-08-05 18:08:10 +0000111 int getIntImmCost(const APInt &Imm, Type *Ty);
Chandler Carruth93dcdc42015-01-31 11:17:59 +0000112
Tim Northover903f81b2016-04-15 18:17:18 +0000113 int getIntImmCost(unsigned Opcode, unsigned Idx, const APInt &Imm, Type *Ty);
Tim Northover5c02f9a2016-04-13 23:08:27 +0000114
Chandler Carruth93dcdc42015-01-31 11:17:59 +0000115 /// @}
116
117 /// \name Vector TTI Implementations
118 /// @{
119
120 unsigned getNumberOfRegisters(bool Vector) {
121 if (Vector) {
122 if (ST->hasNEON())
123 return 16;
124 return 0;
125 }
126
127 if (ST->isThumb1Only())
128 return 8;
129 return 13;
130 }
131
Daniel Neilsonc0112ae2017-06-12 14:22:21 +0000132 unsigned getRegisterBitWidth(bool Vector) const {
Chandler Carruth93dcdc42015-01-31 11:17:59 +0000133 if (Vector) {
134 if (ST->hasNEON())
135 return 128;
136 return 0;
137 }
138
139 return 32;
140 }
141
Wei Mi062c7442015-05-06 17:12:25 +0000142 unsigned getMaxInterleaveFactor(unsigned VF) {
Diana Picus92423ce2016-06-27 09:08:23 +0000143 return ST->getMaxInterleaveFactor();
Chandler Carruth93dcdc42015-01-31 11:17:59 +0000144 }
145
Chandler Carruth93205eb2015-08-05 18:08:10 +0000146 int getShuffleCost(TTI::ShuffleKind Kind, Type *Tp, int Index, Type *SubTp);
Chandler Carruth93dcdc42015-01-31 11:17:59 +0000147
Jonas Paulssonfccc7d62017-04-12 11:49:08 +0000148 int getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src,
149 const Instruction *I = nullptr);
Chandler Carruth93dcdc42015-01-31 11:17:59 +0000150
Jonas Paulssonfccc7d62017-04-12 11:49:08 +0000151 int getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy,
152 const Instruction *I = nullptr);
Chandler Carruth93dcdc42015-01-31 11:17:59 +0000153
Chandler Carruth93205eb2015-08-05 18:08:10 +0000154 int getVectorInstrCost(unsigned Opcode, Type *Val, unsigned Index);
Chandler Carruth93dcdc42015-01-31 11:17:59 +0000155
Mohammed Agabaria23599ba2017-01-05 14:03:41 +0000156 int getAddressComputationCost(Type *Val, ScalarEvolution *SE,
157 const SCEV *Ptr);
Chandler Carruth93dcdc42015-01-31 11:17:59 +0000158
Chandler Carruth93205eb2015-08-05 18:08:10 +0000159 int getArithmeticInstrCost(
Chandler Carruth93dcdc42015-01-31 11:17:59 +0000160 unsigned Opcode, Type *Ty,
161 TTI::OperandValueKind Op1Info = TTI::OK_AnyValue,
162 TTI::OperandValueKind Op2Info = TTI::OK_AnyValue,
163 TTI::OperandValueProperties Opd1PropInfo = TTI::OP_None,
Mohammed Agabaria2c96c432017-01-11 08:23:37 +0000164 TTI::OperandValueProperties Opd2PropInfo = TTI::OP_None,
165 ArrayRef<const Value *> Args = ArrayRef<const Value *>());
Chandler Carruth93dcdc42015-01-31 11:17:59 +0000166
Chandler Carruth93205eb2015-08-05 18:08:10 +0000167 int getMemoryOpCost(unsigned Opcode, Type *Src, unsigned Alignment,
Jonas Paulssonfccc7d62017-04-12 11:49:08 +0000168 unsigned AddressSpace, const Instruction *I = nullptr);
Chandler Carruth93dcdc42015-01-31 11:17:59 +0000169
Chandler Carruth93205eb2015-08-05 18:08:10 +0000170 int getInterleavedMemoryOpCost(unsigned Opcode, Type *VecTy, unsigned Factor,
171 ArrayRef<unsigned> Indices, unsigned Alignment,
172 unsigned AddressSpace);
Oliver Stannard4df1cc02016-10-07 08:48:24 +0000173
Sam Parker19a08e42017-07-25 08:51:30 +0000174 void getUnrollingPreferences(Loop *L, ScalarEvolution &SE,
175 TTI::UnrollingPreferences &UP);
176
Oliver Stannard4df1cc02016-10-07 08:48:24 +0000177 bool shouldBuildLookupTablesForConstant(Constant *C) const {
178 // In the ROPI and RWPI relocation models we can't have pointers to global
179 // variables or functions in constant data, so don't convert switches to
180 // lookup tables if any of the values would need relocation.
181 if (ST->isROPI() || ST->isRWPI())
182 return !C->needsRelocation();
183
184 return true;
185 }
Chandler Carruth93dcdc42015-01-31 11:17:59 +0000186 /// @}
187};
188
189} // end namespace llvm
190
Eugene Zelenko076468c2017-09-20 21:35:51 +0000191#endif // LLVM_LIB_TARGET_ARM_ARMTARGETTRANSFORMINFO_H