blob: 0695a4e63346736812c5a3424a8fc7de27039331 [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
Florian Hahn4adcfcf2017-07-13 08:26:17 +000036 // Currently the following features are excluded from InlineFeatureWhitelist.
37 // ModeThumb, FeatureNoARM, ModeSoftFloat, FeatureVFPOnlySP, FeatureD16
38 // Depending on whether they are set or unset, different
39 // instructions/registers are available. For example, inlining a callee with
40 // -thumb-mode in a caller with +thumb-mode, may cause the assembler to
41 // fail if the callee uses ARM only instructions, e.g. in inline asm.
42 const FeatureBitset InlineFeatureWhitelist = {
43 ARM::FeatureVFP2, ARM::FeatureVFP3, ARM::FeatureNEON, ARM::FeatureThumb2,
44 ARM::FeatureFP16, ARM::FeatureVFP4, ARM::FeatureFPARMv8,
45 ARM::FeatureFullFP16, ARM::FeatureHWDivThumb,
46 ARM::FeatureHWDivARM, ARM::FeatureDB, ARM::FeatureV7Clrex,
47 ARM::FeatureAcquireRelease, ARM::FeatureSlowFPBrcc,
48 ARM::FeaturePerfMon, ARM::FeatureTrustZone, ARM::Feature8MSecExt,
49 ARM::FeatureCrypto, ARM::FeatureCRC, ARM::FeatureRAS,
50 ARM::FeatureFPAO, ARM::FeatureFuseAES, ARM::FeatureZCZeroing,
51 ARM::FeatureProfUnpredicate, ARM::FeatureSlowVGETLNi32,
52 ARM::FeatureSlowVDUP32, ARM::FeaturePreferVMOVSR,
53 ARM::FeaturePrefISHSTBarrier, ARM::FeatureMuxedUnits,
54 ARM::FeatureSlowOddRegister, ARM::FeatureSlowLoadDSubreg,
55 ARM::FeatureDontWidenVMOVS, ARM::FeatureExpandMLx,
56 ARM::FeatureHasVMLxHazards, ARM::FeatureNEONForFPMovs,
57 ARM::FeatureNEONForFP, ARM::FeatureCheckVLDnAlign,
58 ARM::FeatureHasSlowFPVMLx, ARM::FeatureVMLxForwarding,
59 ARM::FeaturePref32BitThumb, ARM::FeatureAvoidPartialCPSR,
60 ARM::FeatureCheapPredicableCPSR, ARM::FeatureAvoidMOVsShOp,
61 ARM::FeatureHasRetAddrStack, ARM::FeatureHasNoBranchPredictor,
62 ARM::FeatureDSP, ARM::FeatureMP, ARM::FeatureVirtualization,
63 ARM::FeatureMClass, ARM::FeatureRClass, ARM::FeatureAClass,
64 ARM::FeatureNaClTrap, ARM::FeatureStrictAlign, ARM::FeatureLongCalls,
65 ARM::FeatureExecuteOnly, ARM::FeatureReserveR9, ARM::FeatureNoMovt,
66 ARM::FeatureNoNegativeImmediates
67 };
68
Chandler Carruthc956ab662015-02-01 14:22:17 +000069 const ARMSubtarget *getST() const { return ST; }
Chandler Carruthc340ca82015-02-01 14:01:15 +000070 const ARMTargetLowering *getTLI() const { return TLI; }
71
Chandler Carruth93dcdc42015-01-31 11:17:59 +000072public:
Eric Christophera4e5d3c2015-09-16 23:38:13 +000073 explicit ARMTTIImpl(const ARMBaseTargetMachine *TM, const Function &F)
Mehdi Amini5010ebf2015-07-09 02:08:42 +000074 : BaseT(TM, F.getParent()->getDataLayout()), ST(TM->getSubtargetImpl(F)),
75 TLI(ST->getTargetLowering()) {}
Chandler Carruth93dcdc42015-01-31 11:17:59 +000076
Florian Hahn4adcfcf2017-07-13 08:26:17 +000077 bool areInlineCompatible(const Function *Caller,
78 const Function *Callee) const;
79
Silviu Barangae748c9e2015-09-01 11:19:15 +000080 bool enableInterleavedAccessVectorization() { return true; }
81
Renato Golin4b18a512016-04-18 12:06:47 +000082 /// Floating-point computation using ARMv8 AArch32 Advanced
83 /// SIMD instructions remains unchanged from ARMv7. Only AArch64 SIMD
84 /// is IEEE-754 compliant, but it's not covered in this target.
Renato Golin5cb666a2016-04-14 20:42:18 +000085 bool isFPVectorizationPotentiallyUnsafe() {
Renato Golin4b18a512016-04-18 12:06:47 +000086 return !ST->isTargetDarwin();
Renato Golin5cb666a2016-04-14 20:42:18 +000087 }
88
Chandler Carruth93dcdc42015-01-31 11:17:59 +000089 /// \name Scalar TTI Implementations
90 /// @{
91
Sjoerd Meijer38c2cd02016-07-14 07:44:20 +000092 int getIntImmCodeSizeCost(unsigned Opcode, unsigned Idx, const APInt &Imm,
93 Type *Ty);
94
Chandler Carruth93dcdc42015-01-31 11:17:59 +000095 using BaseT::getIntImmCost;
Chandler Carruth93205eb2015-08-05 18:08:10 +000096 int getIntImmCost(const APInt &Imm, Type *Ty);
Chandler Carruth93dcdc42015-01-31 11:17:59 +000097
Tim Northover903f81b2016-04-15 18:17:18 +000098 int getIntImmCost(unsigned Opcode, unsigned Idx, const APInt &Imm, Type *Ty);
Tim Northover5c02f9a2016-04-13 23:08:27 +000099
Chandler Carruth93dcdc42015-01-31 11:17:59 +0000100 /// @}
101
102 /// \name Vector TTI Implementations
103 /// @{
104
105 unsigned getNumberOfRegisters(bool Vector) {
106 if (Vector) {
107 if (ST->hasNEON())
108 return 16;
109 return 0;
110 }
111
112 if (ST->isThumb1Only())
113 return 8;
114 return 13;
115 }
116
Daniel Neilsonc0112ae2017-06-12 14:22:21 +0000117 unsigned getRegisterBitWidth(bool Vector) const {
Chandler Carruth93dcdc42015-01-31 11:17:59 +0000118 if (Vector) {
119 if (ST->hasNEON())
120 return 128;
121 return 0;
122 }
123
124 return 32;
125 }
126
Wei Mi062c7442015-05-06 17:12:25 +0000127 unsigned getMaxInterleaveFactor(unsigned VF) {
Diana Picus92423ce2016-06-27 09:08:23 +0000128 return ST->getMaxInterleaveFactor();
Chandler Carruth93dcdc42015-01-31 11:17:59 +0000129 }
130
Chandler Carruth93205eb2015-08-05 18:08:10 +0000131 int getShuffleCost(TTI::ShuffleKind Kind, Type *Tp, int Index, Type *SubTp);
Chandler Carruth93dcdc42015-01-31 11:17:59 +0000132
Jonas Paulssonfccc7d62017-04-12 11:49:08 +0000133 int getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src,
134 const Instruction *I = nullptr);
Chandler Carruth93dcdc42015-01-31 11:17:59 +0000135
Jonas Paulssonfccc7d62017-04-12 11:49:08 +0000136 int getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy,
137 const Instruction *I = nullptr);
Chandler Carruth93dcdc42015-01-31 11:17:59 +0000138
Chandler Carruth93205eb2015-08-05 18:08:10 +0000139 int getVectorInstrCost(unsigned Opcode, Type *Val, unsigned Index);
Chandler Carruth93dcdc42015-01-31 11:17:59 +0000140
Mohammed Agabaria23599ba2017-01-05 14:03:41 +0000141 int getAddressComputationCost(Type *Val, ScalarEvolution *SE,
142 const SCEV *Ptr);
Chandler Carruth93dcdc42015-01-31 11:17:59 +0000143
Chandler Carruth93205eb2015-08-05 18:08:10 +0000144 int getFPOpCost(Type *Ty);
Cameron Esfahani17177d12015-02-05 02:09:33 +0000145
Chandler Carruth93205eb2015-08-05 18:08:10 +0000146 int getArithmeticInstrCost(
Chandler Carruth93dcdc42015-01-31 11:17:59 +0000147 unsigned Opcode, Type *Ty,
148 TTI::OperandValueKind Op1Info = TTI::OK_AnyValue,
149 TTI::OperandValueKind Op2Info = TTI::OK_AnyValue,
150 TTI::OperandValueProperties Opd1PropInfo = TTI::OP_None,
Mohammed Agabaria2c96c432017-01-11 08:23:37 +0000151 TTI::OperandValueProperties Opd2PropInfo = TTI::OP_None,
152 ArrayRef<const Value *> Args = ArrayRef<const Value *>());
Chandler Carruth93dcdc42015-01-31 11:17:59 +0000153
Chandler Carruth93205eb2015-08-05 18:08:10 +0000154 int getMemoryOpCost(unsigned Opcode, Type *Src, unsigned Alignment,
Jonas Paulssonfccc7d62017-04-12 11:49:08 +0000155 unsigned AddressSpace, const Instruction *I = nullptr);
Chandler Carruth93dcdc42015-01-31 11:17:59 +0000156
Chandler Carruth93205eb2015-08-05 18:08:10 +0000157 int getInterleavedMemoryOpCost(unsigned Opcode, Type *VecTy, unsigned Factor,
158 ArrayRef<unsigned> Indices, unsigned Alignment,
159 unsigned AddressSpace);
Oliver Stannard4df1cc02016-10-07 08:48:24 +0000160
161 bool shouldBuildLookupTablesForConstant(Constant *C) const {
162 // In the ROPI and RWPI relocation models we can't have pointers to global
163 // variables or functions in constant data, so don't convert switches to
164 // lookup tables if any of the values would need relocation.
165 if (ST->isROPI() || ST->isRWPI())
166 return !C->needsRelocation();
167
168 return true;
169 }
Chandler Carruth93dcdc42015-01-31 11:17:59 +0000170 /// @}
171};
172
173} // end namespace llvm
174
175#endif