Chandler Carruth | 93dcdc4 | 2015-01-31 11:17:59 +0000 | [diff] [blame] | 1 | //===-- 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 | |
| 26 | namespace llvm { |
| 27 | |
| 28 | class ARMTTIImpl : public BasicTTIImplBase<ARMTTIImpl> { |
| 29 | typedef BasicTTIImplBase<ARMTTIImpl> BaseT; |
| 30 | typedef TargetTransformInfo TTI; |
Chandler Carruth | c340ca8 | 2015-02-01 14:01:15 +0000 | [diff] [blame] | 31 | friend BaseT; |
Chandler Carruth | 93dcdc4 | 2015-01-31 11:17:59 +0000 | [diff] [blame] | 32 | |
| 33 | const ARMSubtarget *ST; |
| 34 | const ARMTargetLowering *TLI; |
| 35 | |
Florian Hahn | 4adcfcf | 2017-07-13 08:26:17 +0000 | [diff] [blame] | 36 | // 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 Carruth | c956ab66 | 2015-02-01 14:22:17 +0000 | [diff] [blame] | 69 | const ARMSubtarget *getST() const { return ST; } |
Chandler Carruth | c340ca8 | 2015-02-01 14:01:15 +0000 | [diff] [blame] | 70 | const ARMTargetLowering *getTLI() const { return TLI; } |
| 71 | |
Chandler Carruth | 93dcdc4 | 2015-01-31 11:17:59 +0000 | [diff] [blame] | 72 | public: |
Eric Christopher | a4e5d3c | 2015-09-16 23:38:13 +0000 | [diff] [blame] | 73 | explicit ARMTTIImpl(const ARMBaseTargetMachine *TM, const Function &F) |
Mehdi Amini | 5010ebf | 2015-07-09 02:08:42 +0000 | [diff] [blame] | 74 | : BaseT(TM, F.getParent()->getDataLayout()), ST(TM->getSubtargetImpl(F)), |
| 75 | TLI(ST->getTargetLowering()) {} |
Chandler Carruth | 93dcdc4 | 2015-01-31 11:17:59 +0000 | [diff] [blame] | 76 | |
Florian Hahn | 4adcfcf | 2017-07-13 08:26:17 +0000 | [diff] [blame] | 77 | bool areInlineCompatible(const Function *Caller, |
| 78 | const Function *Callee) const; |
| 79 | |
Silviu Baranga | e748c9e | 2015-09-01 11:19:15 +0000 | [diff] [blame] | 80 | bool enableInterleavedAccessVectorization() { return true; } |
| 81 | |
Renato Golin | 4b18a51 | 2016-04-18 12:06:47 +0000 | [diff] [blame] | 82 | /// 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 Golin | 5cb666a | 2016-04-14 20:42:18 +0000 | [diff] [blame] | 85 | bool isFPVectorizationPotentiallyUnsafe() { |
Renato Golin | 4b18a51 | 2016-04-18 12:06:47 +0000 | [diff] [blame] | 86 | return !ST->isTargetDarwin(); |
Renato Golin | 5cb666a | 2016-04-14 20:42:18 +0000 | [diff] [blame] | 87 | } |
| 88 | |
Chandler Carruth | 93dcdc4 | 2015-01-31 11:17:59 +0000 | [diff] [blame] | 89 | /// \name Scalar TTI Implementations |
| 90 | /// @{ |
| 91 | |
Sjoerd Meijer | 38c2cd0 | 2016-07-14 07:44:20 +0000 | [diff] [blame] | 92 | int getIntImmCodeSizeCost(unsigned Opcode, unsigned Idx, const APInt &Imm, |
| 93 | Type *Ty); |
| 94 | |
Chandler Carruth | 93dcdc4 | 2015-01-31 11:17:59 +0000 | [diff] [blame] | 95 | using BaseT::getIntImmCost; |
Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 96 | int getIntImmCost(const APInt &Imm, Type *Ty); |
Chandler Carruth | 93dcdc4 | 2015-01-31 11:17:59 +0000 | [diff] [blame] | 97 | |
Tim Northover | 903f81b | 2016-04-15 18:17:18 +0000 | [diff] [blame] | 98 | int getIntImmCost(unsigned Opcode, unsigned Idx, const APInt &Imm, Type *Ty); |
Tim Northover | 5c02f9a | 2016-04-13 23:08:27 +0000 | [diff] [blame] | 99 | |
Chandler Carruth | 93dcdc4 | 2015-01-31 11:17:59 +0000 | [diff] [blame] | 100 | /// @} |
| 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 Neilson | c0112ae | 2017-06-12 14:22:21 +0000 | [diff] [blame] | 117 | unsigned getRegisterBitWidth(bool Vector) const { |
Chandler Carruth | 93dcdc4 | 2015-01-31 11:17:59 +0000 | [diff] [blame] | 118 | if (Vector) { |
| 119 | if (ST->hasNEON()) |
| 120 | return 128; |
| 121 | return 0; |
| 122 | } |
| 123 | |
| 124 | return 32; |
| 125 | } |
| 126 | |
Wei Mi | 062c744 | 2015-05-06 17:12:25 +0000 | [diff] [blame] | 127 | unsigned getMaxInterleaveFactor(unsigned VF) { |
Diana Picus | 92423ce | 2016-06-27 09:08:23 +0000 | [diff] [blame] | 128 | return ST->getMaxInterleaveFactor(); |
Chandler Carruth | 93dcdc4 | 2015-01-31 11:17:59 +0000 | [diff] [blame] | 129 | } |
| 130 | |
Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 131 | int getShuffleCost(TTI::ShuffleKind Kind, Type *Tp, int Index, Type *SubTp); |
Chandler Carruth | 93dcdc4 | 2015-01-31 11:17:59 +0000 | [diff] [blame] | 132 | |
Jonas Paulsson | fccc7d6 | 2017-04-12 11:49:08 +0000 | [diff] [blame] | 133 | int getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src, |
| 134 | const Instruction *I = nullptr); |
Chandler Carruth | 93dcdc4 | 2015-01-31 11:17:59 +0000 | [diff] [blame] | 135 | |
Jonas Paulsson | fccc7d6 | 2017-04-12 11:49:08 +0000 | [diff] [blame] | 136 | int getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy, |
| 137 | const Instruction *I = nullptr); |
Chandler Carruth | 93dcdc4 | 2015-01-31 11:17:59 +0000 | [diff] [blame] | 138 | |
Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 139 | int getVectorInstrCost(unsigned Opcode, Type *Val, unsigned Index); |
Chandler Carruth | 93dcdc4 | 2015-01-31 11:17:59 +0000 | [diff] [blame] | 140 | |
Mohammed Agabaria | 23599ba | 2017-01-05 14:03:41 +0000 | [diff] [blame] | 141 | int getAddressComputationCost(Type *Val, ScalarEvolution *SE, |
| 142 | const SCEV *Ptr); |
Chandler Carruth | 93dcdc4 | 2015-01-31 11:17:59 +0000 | [diff] [blame] | 143 | |
Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 144 | int getFPOpCost(Type *Ty); |
Cameron Esfahani | 17177d1 | 2015-02-05 02:09:33 +0000 | [diff] [blame] | 145 | |
Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 146 | int getArithmeticInstrCost( |
Chandler Carruth | 93dcdc4 | 2015-01-31 11:17:59 +0000 | [diff] [blame] | 147 | 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 Agabaria | 2c96c43 | 2017-01-11 08:23:37 +0000 | [diff] [blame] | 151 | TTI::OperandValueProperties Opd2PropInfo = TTI::OP_None, |
| 152 | ArrayRef<const Value *> Args = ArrayRef<const Value *>()); |
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 getMemoryOpCost(unsigned Opcode, Type *Src, unsigned Alignment, |
Jonas Paulsson | fccc7d6 | 2017-04-12 11:49:08 +0000 | [diff] [blame] | 155 | unsigned AddressSpace, const Instruction *I = nullptr); |
Chandler Carruth | 93dcdc4 | 2015-01-31 11:17:59 +0000 | [diff] [blame] | 156 | |
Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 157 | int getInterleavedMemoryOpCost(unsigned Opcode, Type *VecTy, unsigned Factor, |
| 158 | ArrayRef<unsigned> Indices, unsigned Alignment, |
| 159 | unsigned AddressSpace); |
Oliver Stannard | 4df1cc0 | 2016-10-07 08:48:24 +0000 | [diff] [blame] | 160 | |
| 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 Carruth | 93dcdc4 | 2015-01-31 11:17:59 +0000 | [diff] [blame] | 170 | /// @} |
| 171 | }; |
| 172 | |
| 173 | } // end namespace llvm |
| 174 | |
| 175 | #endif |