Eugene Zelenko | 076468c | 2017-09-20 21:35:51 +0000 | [diff] [blame] | 1 | //===- ARMTargetTransformInfo.h - ARM specific TTI --------------*- C++ -*-===// |
Chandler Carruth | 93dcdc4 | 2015-01-31 11:17:59 +0000 | [diff] [blame] | 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 | //===----------------------------------------------------------------------===// |
Eugene Zelenko | 076468c | 2017-09-20 21:35:51 +0000 | [diff] [blame] | 9 | // |
Chandler Carruth | 93dcdc4 | 2015-01-31 11:17:59 +0000 | [diff] [blame] | 10 | /// \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 Zelenko | 076468c | 2017-09-20 21:35:51 +0000 | [diff] [blame] | 15 | // |
Chandler Carruth | 93dcdc4 | 2015-01-31 11:17:59 +0000 | [diff] [blame] | 16 | //===----------------------------------------------------------------------===// |
| 17 | |
| 18 | #ifndef LLVM_LIB_TARGET_ARM_ARMTARGETTRANSFORMINFO_H |
| 19 | #define LLVM_LIB_TARGET_ARM_ARMTARGETTRANSFORMINFO_H |
| 20 | |
| 21 | #include "ARM.h" |
Eugene Zelenko | 076468c | 2017-09-20 21:35:51 +0000 | [diff] [blame] | 22 | #include "ARMSubtarget.h" |
Chandler Carruth | 93dcdc4 | 2015-01-31 11:17:59 +0000 | [diff] [blame] | 23 | #include "ARMTargetMachine.h" |
Eugene Zelenko | 076468c | 2017-09-20 21:35:51 +0000 | [diff] [blame] | 24 | #include "llvm/ADT/ArrayRef.h" |
Chandler Carruth | 93dcdc4 | 2015-01-31 11:17:59 +0000 | [diff] [blame] | 25 | #include "llvm/Analysis/TargetTransformInfo.h" |
| 26 | #include "llvm/CodeGen/BasicTTIImpl.h" |
Eugene Zelenko | 076468c | 2017-09-20 21:35:51 +0000 | [diff] [blame] | 27 | #include "llvm/IR/Constant.h" |
| 28 | #include "llvm/IR/Function.h" |
| 29 | #include "llvm/MC/SubtargetFeature.h" |
Chandler Carruth | 93dcdc4 | 2015-01-31 11:17:59 +0000 | [diff] [blame] | 30 | |
| 31 | namespace llvm { |
| 32 | |
Eugene Zelenko | 076468c | 2017-09-20 21:35:51 +0000 | [diff] [blame] | 33 | class APInt; |
| 34 | class ARMTargetLowering; |
| 35 | class Instruction; |
| 36 | class Loop; |
| 37 | class SCEV; |
| 38 | class ScalarEvolution; |
| 39 | class Type; |
| 40 | class Value; |
| 41 | |
Chandler Carruth | 93dcdc4 | 2015-01-31 11:17:59 +0000 | [diff] [blame] | 42 | class ARMTTIImpl : public BasicTTIImplBase<ARMTTIImpl> { |
Eugene Zelenko | 076468c | 2017-09-20 21:35:51 +0000 | [diff] [blame] | 43 | using BaseT = BasicTTIImplBase<ARMTTIImpl>; |
| 44 | using TTI = TargetTransformInfo; |
| 45 | |
Chandler Carruth | c340ca8 | 2015-02-01 14:01:15 +0000 | [diff] [blame] | 46 | friend BaseT; |
Chandler Carruth | 93dcdc4 | 2015-01-31 11:17:59 +0000 | [diff] [blame] | 47 | |
| 48 | const ARMSubtarget *ST; |
| 49 | const ARMTargetLowering *TLI; |
| 50 | |
Florian Hahn | 4adcfcf | 2017-07-13 08:26:17 +0000 | [diff] [blame] | 51 | // 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 Carruth | c956ab66 | 2015-02-01 14:22:17 +0000 | [diff] [blame] | 84 | const ARMSubtarget *getST() const { return ST; } |
Chandler Carruth | c340ca8 | 2015-02-01 14:01:15 +0000 | [diff] [blame] | 85 | const ARMTargetLowering *getTLI() const { return TLI; } |
| 86 | |
Chandler Carruth | 93dcdc4 | 2015-01-31 11:17:59 +0000 | [diff] [blame] | 87 | public: |
Eric Christopher | a4e5d3c | 2015-09-16 23:38:13 +0000 | [diff] [blame] | 88 | explicit ARMTTIImpl(const ARMBaseTargetMachine *TM, const Function &F) |
Mehdi Amini | 5010ebf | 2015-07-09 02:08:42 +0000 | [diff] [blame] | 89 | : BaseT(TM, F.getParent()->getDataLayout()), ST(TM->getSubtargetImpl(F)), |
| 90 | TLI(ST->getTargetLowering()) {} |
Chandler Carruth | 93dcdc4 | 2015-01-31 11:17:59 +0000 | [diff] [blame] | 91 | |
Florian Hahn | 4adcfcf | 2017-07-13 08:26:17 +0000 | [diff] [blame] | 92 | bool areInlineCompatible(const Function *Caller, |
| 93 | const Function *Callee) const; |
| 94 | |
Silviu Baranga | e748c9e | 2015-09-01 11:19:15 +0000 | [diff] [blame] | 95 | bool enableInterleavedAccessVectorization() { return true; } |
| 96 | |
Renato Golin | 4b18a51 | 2016-04-18 12:06:47 +0000 | [diff] [blame] | 97 | /// 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 Golin | 5cb666a | 2016-04-14 20:42:18 +0000 | [diff] [blame] | 100 | bool isFPVectorizationPotentiallyUnsafe() { |
Renato Golin | 4b18a51 | 2016-04-18 12:06:47 +0000 | [diff] [blame] | 101 | return !ST->isTargetDarwin(); |
Renato Golin | 5cb666a | 2016-04-14 20:42:18 +0000 | [diff] [blame] | 102 | } |
| 103 | |
Chandler Carruth | 93dcdc4 | 2015-01-31 11:17:59 +0000 | [diff] [blame] | 104 | /// \name Scalar TTI Implementations |
| 105 | /// @{ |
| 106 | |
Sjoerd Meijer | 38c2cd0 | 2016-07-14 07:44:20 +0000 | [diff] [blame] | 107 | int getIntImmCodeSizeCost(unsigned Opcode, unsigned Idx, const APInt &Imm, |
| 108 | Type *Ty); |
| 109 | |
Chandler Carruth | 93dcdc4 | 2015-01-31 11:17:59 +0000 | [diff] [blame] | 110 | using BaseT::getIntImmCost; |
Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 111 | int getIntImmCost(const APInt &Imm, Type *Ty); |
Chandler Carruth | 93dcdc4 | 2015-01-31 11:17:59 +0000 | [diff] [blame] | 112 | |
Tim Northover | 903f81b | 2016-04-15 18:17:18 +0000 | [diff] [blame] | 113 | int getIntImmCost(unsigned Opcode, unsigned Idx, const APInt &Imm, Type *Ty); |
Tim Northover | 5c02f9a | 2016-04-13 23:08:27 +0000 | [diff] [blame] | 114 | |
Chandler Carruth | 93dcdc4 | 2015-01-31 11:17:59 +0000 | [diff] [blame] | 115 | /// @} |
| 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 Neilson | c0112ae | 2017-06-12 14:22:21 +0000 | [diff] [blame] | 132 | unsigned getRegisterBitWidth(bool Vector) const { |
Chandler Carruth | 93dcdc4 | 2015-01-31 11:17:59 +0000 | [diff] [blame] | 133 | if (Vector) { |
| 134 | if (ST->hasNEON()) |
| 135 | return 128; |
| 136 | return 0; |
| 137 | } |
| 138 | |
| 139 | return 32; |
| 140 | } |
| 141 | |
Wei Mi | 062c744 | 2015-05-06 17:12:25 +0000 | [diff] [blame] | 142 | unsigned getMaxInterleaveFactor(unsigned VF) { |
Diana Picus | 92423ce | 2016-06-27 09:08:23 +0000 | [diff] [blame] | 143 | return ST->getMaxInterleaveFactor(); |
Chandler Carruth | 93dcdc4 | 2015-01-31 11:17:59 +0000 | [diff] [blame] | 144 | } |
| 145 | |
Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 146 | int getShuffleCost(TTI::ShuffleKind Kind, Type *Tp, int Index, Type *SubTp); |
Chandler Carruth | 93dcdc4 | 2015-01-31 11:17:59 +0000 | [diff] [blame] | 147 | |
Jonas Paulsson | fccc7d6 | 2017-04-12 11:49:08 +0000 | [diff] [blame] | 148 | int getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src, |
| 149 | const Instruction *I = nullptr); |
Chandler Carruth | 93dcdc4 | 2015-01-31 11:17:59 +0000 | [diff] [blame] | 150 | |
Jonas Paulsson | fccc7d6 | 2017-04-12 11:49:08 +0000 | [diff] [blame] | 151 | int getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy, |
| 152 | const Instruction *I = nullptr); |
Chandler Carruth | 93dcdc4 | 2015-01-31 11:17:59 +0000 | [diff] [blame] | 153 | |
Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 154 | int getVectorInstrCost(unsigned Opcode, Type *Val, unsigned Index); |
Chandler Carruth | 93dcdc4 | 2015-01-31 11:17:59 +0000 | [diff] [blame] | 155 | |
Mohammed Agabaria | 23599ba | 2017-01-05 14:03:41 +0000 | [diff] [blame] | 156 | int getAddressComputationCost(Type *Val, ScalarEvolution *SE, |
| 157 | const SCEV *Ptr); |
Chandler Carruth | 93dcdc4 | 2015-01-31 11:17:59 +0000 | [diff] [blame] | 158 | |
Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 159 | int getArithmeticInstrCost( |
Chandler Carruth | 93dcdc4 | 2015-01-31 11:17:59 +0000 | [diff] [blame] | 160 | 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 Agabaria | 2c96c43 | 2017-01-11 08:23:37 +0000 | [diff] [blame] | 164 | TTI::OperandValueProperties Opd2PropInfo = TTI::OP_None, |
| 165 | ArrayRef<const Value *> Args = ArrayRef<const Value *>()); |
Chandler Carruth | 93dcdc4 | 2015-01-31 11:17:59 +0000 | [diff] [blame] | 166 | |
Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 167 | int getMemoryOpCost(unsigned Opcode, Type *Src, unsigned Alignment, |
Jonas Paulsson | fccc7d6 | 2017-04-12 11:49:08 +0000 | [diff] [blame] | 168 | unsigned AddressSpace, const Instruction *I = nullptr); |
Chandler Carruth | 93dcdc4 | 2015-01-31 11:17:59 +0000 | [diff] [blame] | 169 | |
Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 170 | int getInterleavedMemoryOpCost(unsigned Opcode, Type *VecTy, unsigned Factor, |
| 171 | ArrayRef<unsigned> Indices, unsigned Alignment, |
| 172 | unsigned AddressSpace); |
Oliver Stannard | 4df1cc0 | 2016-10-07 08:48:24 +0000 | [diff] [blame] | 173 | |
Sam Parker | 19a08e4 | 2017-07-25 08:51:30 +0000 | [diff] [blame] | 174 | void getUnrollingPreferences(Loop *L, ScalarEvolution &SE, |
| 175 | TTI::UnrollingPreferences &UP); |
| 176 | |
Oliver Stannard | 4df1cc0 | 2016-10-07 08:48:24 +0000 | [diff] [blame] | 177 | 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 Carruth | 93dcdc4 | 2015-01-31 11:17:59 +0000 | [diff] [blame] | 186 | /// @} |
| 187 | }; |
| 188 | |
| 189 | } // end namespace llvm |
| 190 | |
Eugene Zelenko | 076468c | 2017-09-20 21:35:51 +0000 | [diff] [blame] | 191 | #endif // LLVM_LIB_TARGET_ARM_ARMTARGETTRANSFORMINFO_H |