Chandler Carruth | d3e7355 | 2013-01-07 03:08:10 +0000 | [diff] [blame] | 1 | //===- llvm/Analysis/TargetTransformInfo.cpp ------------------------------===// |
Nadav Rotem | 5dc203e | 2012-10-18 23:22:48 +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 | //===----------------------------------------------------------------------===// |
| 9 | |
Chandler Carruth | d3e7355 | 2013-01-07 03:08:10 +0000 | [diff] [blame] | 10 | #include "llvm/Analysis/TargetTransformInfo.h" |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 11 | #include "llvm/Analysis/TargetTransformInfoImpl.h" |
Chandler Carruth | 219b89b | 2014-03-04 11:01:28 +0000 | [diff] [blame] | 12 | #include "llvm/IR/CallSite.h" |
Chandler Carruth | 511aa76 | 2013-01-21 01:27:39 +0000 | [diff] [blame] | 13 | #include "llvm/IR/DataLayout.h" |
Chandler Carruth | 511aa76 | 2013-01-21 01:27:39 +0000 | [diff] [blame] | 14 | #include "llvm/IR/Instruction.h" |
Chandler Carruth | 511aa76 | 2013-01-21 01:27:39 +0000 | [diff] [blame] | 15 | #include "llvm/IR/Instructions.h" |
Chandler Carruth | 8a8cd2b | 2014-01-07 11:48:04 +0000 | [diff] [blame] | 16 | #include "llvm/IR/IntrinsicInst.h" |
Chandler Carruth | e038552 | 2015-02-01 10:11:22 +0000 | [diff] [blame] | 17 | #include "llvm/IR/Module.h" |
Chandler Carruth | 8a8cd2b | 2014-01-07 11:48:04 +0000 | [diff] [blame] | 18 | #include "llvm/IR/Operator.h" |
Guozhi Wei | 62d6414 | 2017-09-08 22:29:17 +0000 | [diff] [blame] | 19 | #include "llvm/IR/PatternMatch.h" |
Sean Fertile | 9cd1cdf | 2017-07-07 02:00:06 +0000 | [diff] [blame] | 20 | #include "llvm/Support/CommandLine.h" |
Nadav Rotem | 5dc203e | 2012-10-18 23:22:48 +0000 | [diff] [blame] | 21 | #include "llvm/Support/ErrorHandling.h" |
Benjamin Kramer | 82de7d3 | 2016-05-27 14:27:24 +0000 | [diff] [blame] | 22 | #include <utility> |
Nadav Rotem | 5dc203e | 2012-10-18 23:22:48 +0000 | [diff] [blame] | 23 | |
| 24 | using namespace llvm; |
Guozhi Wei | 62d6414 | 2017-09-08 22:29:17 +0000 | [diff] [blame] | 25 | using namespace PatternMatch; |
Nadav Rotem | 5dc203e | 2012-10-18 23:22:48 +0000 | [diff] [blame] | 26 | |
Chandler Carruth | f1221bd | 2014-04-22 02:48:03 +0000 | [diff] [blame] | 27 | #define DEBUG_TYPE "tti" |
| 28 | |
Guozhi Wei | 62d6414 | 2017-09-08 22:29:17 +0000 | [diff] [blame] | 29 | static cl::opt<bool> EnableReduxCost("costmodel-reduxcost", cl::init(false), |
| 30 | cl::Hidden, |
| 31 | cl::desc("Recognize reduction patterns.")); |
| 32 | |
Chandler Carruth | 93dcdc4 | 2015-01-31 11:17:59 +0000 | [diff] [blame] | 33 | namespace { |
| 34 | /// \brief No-op implementation of the TTI interface using the utility base |
| 35 | /// classes. |
| 36 | /// |
| 37 | /// This is used when no target specific information is available. |
| 38 | struct NoTTIImpl : TargetTransformInfoImplCRTPBase<NoTTIImpl> { |
Mehdi Amini | 5010ebf | 2015-07-09 02:08:42 +0000 | [diff] [blame] | 39 | explicit NoTTIImpl(const DataLayout &DL) |
Chandler Carruth | 93dcdc4 | 2015-01-31 11:17:59 +0000 | [diff] [blame] | 40 | : TargetTransformInfoImplCRTPBase<NoTTIImpl>(DL) {} |
| 41 | }; |
| 42 | } |
| 43 | |
Mehdi Amini | 5010ebf | 2015-07-09 02:08:42 +0000 | [diff] [blame] | 44 | TargetTransformInfo::TargetTransformInfo(const DataLayout &DL) |
Chandler Carruth | 93dcdc4 | 2015-01-31 11:17:59 +0000 | [diff] [blame] | 45 | : TTIImpl(new Model<NoTTIImpl>(NoTTIImpl(DL))) {} |
| 46 | |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 47 | TargetTransformInfo::~TargetTransformInfo() {} |
Nadav Rotem | 5dc203e | 2012-10-18 23:22:48 +0000 | [diff] [blame] | 48 | |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 49 | TargetTransformInfo::TargetTransformInfo(TargetTransformInfo &&Arg) |
| 50 | : TTIImpl(std::move(Arg.TTIImpl)) {} |
Chandler Carruth | 539edf4 | 2013-01-05 11:43:11 +0000 | [diff] [blame] | 51 | |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 52 | TargetTransformInfo &TargetTransformInfo::operator=(TargetTransformInfo &&RHS) { |
| 53 | TTIImpl = std::move(RHS.TTIImpl); |
| 54 | return *this; |
Chandler Carruth | 539edf4 | 2013-01-05 11:43:11 +0000 | [diff] [blame] | 55 | } |
| 56 | |
Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 57 | int TargetTransformInfo::getOperationCost(unsigned Opcode, Type *Ty, |
| 58 | Type *OpTy) const { |
| 59 | int Cost = TTIImpl->getOperationCost(Opcode, Ty, OpTy); |
| 60 | assert(Cost >= 0 && "TTI should not produce negative costs!"); |
| 61 | return Cost; |
Chandler Carruth | 511aa76 | 2013-01-21 01:27:39 +0000 | [diff] [blame] | 62 | } |
| 63 | |
Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 64 | int TargetTransformInfo::getCallCost(FunctionType *FTy, int NumArgs) const { |
| 65 | int Cost = TTIImpl->getCallCost(FTy, NumArgs); |
| 66 | assert(Cost >= 0 && "TTI should not produce negative costs!"); |
| 67 | return Cost; |
Chandler Carruth | 0ba8db4 | 2013-01-22 11:26:02 +0000 | [diff] [blame] | 68 | } |
| 69 | |
Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 70 | int TargetTransformInfo::getCallCost(const Function *F, |
| 71 | ArrayRef<const Value *> Arguments) const { |
| 72 | int Cost = TTIImpl->getCallCost(F, Arguments); |
| 73 | assert(Cost >= 0 && "TTI should not produce negative costs!"); |
| 74 | return Cost; |
Chandler Carruth | 0ba8db4 | 2013-01-22 11:26:02 +0000 | [diff] [blame] | 75 | } |
| 76 | |
Justin Lebar | 8650a4d | 2016-04-15 01:38:48 +0000 | [diff] [blame] | 77 | unsigned TargetTransformInfo::getInliningThresholdMultiplier() const { |
| 78 | return TTIImpl->getInliningThresholdMultiplier(); |
| 79 | } |
| 80 | |
Jingyue Wu | 15f3e82 | 2016-07-08 21:48:05 +0000 | [diff] [blame] | 81 | int TargetTransformInfo::getGEPCost(Type *PointeeType, const Value *Ptr, |
| 82 | ArrayRef<const Value *> Operands) const { |
| 83 | return TTIImpl->getGEPCost(PointeeType, Ptr, Operands); |
| 84 | } |
| 85 | |
Haicheng Wu | abdef9e | 2017-07-15 02:12:16 +0000 | [diff] [blame] | 86 | int TargetTransformInfo::getExtCost(const Instruction *I, |
| 87 | const Value *Src) const { |
| 88 | return TTIImpl->getExtCost(I, Src); |
| 89 | } |
| 90 | |
Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 91 | int TargetTransformInfo::getIntrinsicCost( |
| 92 | Intrinsic::ID IID, Type *RetTy, ArrayRef<const Value *> Arguments) const { |
| 93 | int Cost = TTIImpl->getIntrinsicCost(IID, RetTy, Arguments); |
| 94 | assert(Cost >= 0 && "TTI should not produce negative costs!"); |
| 95 | return Cost; |
Chandler Carruth | 0ba8db4 | 2013-01-22 11:26:02 +0000 | [diff] [blame] | 96 | } |
| 97 | |
Jun Bum Lim | 919f9e8 | 2017-04-28 16:04:03 +0000 | [diff] [blame] | 98 | unsigned |
| 99 | TargetTransformInfo::getEstimatedNumberOfCaseClusters(const SwitchInst &SI, |
| 100 | unsigned &JTSize) const { |
| 101 | return TTIImpl->getEstimatedNumberOfCaseClusters(SI, JTSize); |
| 102 | } |
| 103 | |
Evgeny Astigeevich | 70ed78e | 2017-06-29 13:42:12 +0000 | [diff] [blame] | 104 | int TargetTransformInfo::getUserCost(const User *U, |
| 105 | ArrayRef<const Value *> Operands) const { |
| 106 | int Cost = TTIImpl->getUserCost(U, Operands); |
Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 107 | assert(Cost >= 0 && "TTI should not produce negative costs!"); |
| 108 | return Cost; |
Chandler Carruth | 511aa76 | 2013-01-21 01:27:39 +0000 | [diff] [blame] | 109 | } |
| 110 | |
Tom Stellard | 8b1e021 | 2013-07-27 00:01:07 +0000 | [diff] [blame] | 111 | bool TargetTransformInfo::hasBranchDivergence() const { |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 112 | return TTIImpl->hasBranchDivergence(); |
Tom Stellard | 8b1e021 | 2013-07-27 00:01:07 +0000 | [diff] [blame] | 113 | } |
| 114 | |
Jingyue Wu | 5da831c | 2015-04-10 05:03:50 +0000 | [diff] [blame] | 115 | bool TargetTransformInfo::isSourceOfDivergence(const Value *V) const { |
| 116 | return TTIImpl->isSourceOfDivergence(V); |
| 117 | } |
| 118 | |
Alexander Timofeev | 0f9c84c | 2017-06-15 19:33:10 +0000 | [diff] [blame] | 119 | bool llvm::TargetTransformInfo::isAlwaysUniform(const Value *V) const { |
| 120 | return TTIImpl->isAlwaysUniform(V); |
| 121 | } |
| 122 | |
Matt Arsenault | 42b6478 | 2017-01-30 23:02:12 +0000 | [diff] [blame] | 123 | unsigned TargetTransformInfo::getFlatAddressSpace() const { |
| 124 | return TTIImpl->getFlatAddressSpace(); |
| 125 | } |
| 126 | |
Chandler Carruth | 0ba8db4 | 2013-01-22 11:26:02 +0000 | [diff] [blame] | 127 | bool TargetTransformInfo::isLoweredToCall(const Function *F) const { |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 128 | return TTIImpl->isLoweredToCall(F); |
Chandler Carruth | 0ba8db4 | 2013-01-22 11:26:02 +0000 | [diff] [blame] | 129 | } |
| 130 | |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 131 | void TargetTransformInfo::getUnrollingPreferences( |
Geoff Berry | 66d9bdb | 2017-06-28 15:53:17 +0000 | [diff] [blame] | 132 | Loop *L, ScalarEvolution &SE, UnrollingPreferences &UP) const { |
| 133 | return TTIImpl->getUnrollingPreferences(L, SE, UP); |
Hal Finkel | 8f2e700 | 2013-09-11 19:25:43 +0000 | [diff] [blame] | 134 | } |
| 135 | |
Chandler Carruth | 539edf4 | 2013-01-05 11:43:11 +0000 | [diff] [blame] | 136 | bool TargetTransformInfo::isLegalAddImmediate(int64_t Imm) const { |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 137 | return TTIImpl->isLegalAddImmediate(Imm); |
Chandler Carruth | 539edf4 | 2013-01-05 11:43:11 +0000 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | bool TargetTransformInfo::isLegalICmpImmediate(int64_t Imm) const { |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 141 | return TTIImpl->isLegalICmpImmediate(Imm); |
Chandler Carruth | 539edf4 | 2013-01-05 11:43:11 +0000 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | bool TargetTransformInfo::isLegalAddressingMode(Type *Ty, GlobalValue *BaseGV, |
| 145 | int64_t BaseOffset, |
| 146 | bool HasBaseReg, |
Matt Arsenault | e83379e | 2015-06-07 20:12:03 +0000 | [diff] [blame] | 147 | int64_t Scale, |
Jonas Paulsson | 024e319 | 2017-07-21 11:59:37 +0000 | [diff] [blame] | 148 | unsigned AddrSpace, |
| 149 | Instruction *I) const { |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 150 | return TTIImpl->isLegalAddressingMode(Ty, BaseGV, BaseOffset, HasBaseReg, |
Jonas Paulsson | 024e319 | 2017-07-21 11:59:37 +0000 | [diff] [blame] | 151 | Scale, AddrSpace, I); |
Chandler Carruth | 539edf4 | 2013-01-05 11:43:11 +0000 | [diff] [blame] | 152 | } |
| 153 | |
Evgeny Stupachenko | f2b3b46 | 2017-06-05 23:37:00 +0000 | [diff] [blame] | 154 | bool TargetTransformInfo::isLSRCostLess(LSRCost &C1, LSRCost &C2) const { |
| 155 | return TTIImpl->isLSRCostLess(C1, C2); |
| 156 | } |
| 157 | |
Elena Demikhovsky | 20662e3 | 2015-10-19 07:43:38 +0000 | [diff] [blame] | 158 | bool TargetTransformInfo::isLegalMaskedStore(Type *DataType) const { |
| 159 | return TTIImpl->isLegalMaskedStore(DataType); |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 160 | } |
| 161 | |
Elena Demikhovsky | 20662e3 | 2015-10-19 07:43:38 +0000 | [diff] [blame] | 162 | bool TargetTransformInfo::isLegalMaskedLoad(Type *DataType) const { |
| 163 | return TTIImpl->isLegalMaskedLoad(DataType); |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 164 | } |
| 165 | |
Elena Demikhovsky | 0928585 | 2015-10-25 15:37:55 +0000 | [diff] [blame] | 166 | bool TargetTransformInfo::isLegalMaskedGather(Type *DataType) const { |
| 167 | return TTIImpl->isLegalMaskedGather(DataType); |
| 168 | } |
| 169 | |
| 170 | bool TargetTransformInfo::isLegalMaskedScatter(Type *DataType) const { |
Mohammed Agabaria | cef53dc | 2017-07-27 10:28:16 +0000 | [diff] [blame] | 171 | return TTIImpl->isLegalMaskedScatter(DataType); |
Elena Demikhovsky | 0928585 | 2015-10-25 15:37:55 +0000 | [diff] [blame] | 172 | } |
| 173 | |
Sanjay Patel | 6fd4391 | 2017-09-09 13:38:18 +0000 | [diff] [blame] | 174 | bool TargetTransformInfo::hasDivRemOp(Type *DataType, bool IsSigned) const { |
| 175 | return TTIImpl->hasDivRemOp(DataType, IsSigned); |
| 176 | } |
| 177 | |
Artem Belevich | cb8f632 | 2017-10-24 20:31:44 +0000 | [diff] [blame] | 178 | bool TargetTransformInfo::hasVolatileVariant(Instruction *I, |
| 179 | unsigned AddrSpace) const { |
| 180 | return TTIImpl->hasVolatileVariant(I, AddrSpace); |
| 181 | } |
| 182 | |
Jonas Paulsson | 8624b7e | 2017-05-24 13:42:56 +0000 | [diff] [blame] | 183 | bool TargetTransformInfo::prefersVectorizedAddressing() const { |
| 184 | return TTIImpl->prefersVectorizedAddressing(); |
| 185 | } |
| 186 | |
Quentin Colombet | bf490d4 | 2013-05-31 21:29:03 +0000 | [diff] [blame] | 187 | int TargetTransformInfo::getScalingFactorCost(Type *Ty, GlobalValue *BaseGV, |
| 188 | int64_t BaseOffset, |
| 189 | bool HasBaseReg, |
Matt Arsenault | e83379e | 2015-06-07 20:12:03 +0000 | [diff] [blame] | 190 | int64_t Scale, |
| 191 | unsigned AddrSpace) const { |
Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 192 | int Cost = TTIImpl->getScalingFactorCost(Ty, BaseGV, BaseOffset, HasBaseReg, |
| 193 | Scale, AddrSpace); |
| 194 | assert(Cost >= 0 && "TTI should not produce negative costs!"); |
| 195 | return Cost; |
Quentin Colombet | bf490d4 | 2013-05-31 21:29:03 +0000 | [diff] [blame] | 196 | } |
| 197 | |
Jonas Paulsson | 024e319 | 2017-07-21 11:59:37 +0000 | [diff] [blame] | 198 | bool TargetTransformInfo::LSRWithInstrQueries() const { |
| 199 | return TTIImpl->LSRWithInstrQueries(); |
| 200 | } |
| 201 | |
Chandler Carruth | 539edf4 | 2013-01-05 11:43:11 +0000 | [diff] [blame] | 202 | bool TargetTransformInfo::isTruncateFree(Type *Ty1, Type *Ty2) const { |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 203 | return TTIImpl->isTruncateFree(Ty1, Ty2); |
Chandler Carruth | 539edf4 | 2013-01-05 11:43:11 +0000 | [diff] [blame] | 204 | } |
| 205 | |
Chad Rosier | 5439005 | 2015-02-23 19:15:16 +0000 | [diff] [blame] | 206 | bool TargetTransformInfo::isProfitableToHoist(Instruction *I) const { |
| 207 | return TTIImpl->isProfitableToHoist(I); |
| 208 | } |
| 209 | |
Chandler Carruth | 539edf4 | 2013-01-05 11:43:11 +0000 | [diff] [blame] | 210 | bool TargetTransformInfo::isTypeLegal(Type *Ty) const { |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 211 | return TTIImpl->isTypeLegal(Ty); |
Chandler Carruth | 539edf4 | 2013-01-05 11:43:11 +0000 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | unsigned TargetTransformInfo::getJumpBufAlignment() const { |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 215 | return TTIImpl->getJumpBufAlignment(); |
Chandler Carruth | 539edf4 | 2013-01-05 11:43:11 +0000 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | unsigned TargetTransformInfo::getJumpBufSize() const { |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 219 | return TTIImpl->getJumpBufSize(); |
Chandler Carruth | 539edf4 | 2013-01-05 11:43:11 +0000 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | bool TargetTransformInfo::shouldBuildLookupTables() const { |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 223 | return TTIImpl->shouldBuildLookupTables(); |
Chandler Carruth | 539edf4 | 2013-01-05 11:43:11 +0000 | [diff] [blame] | 224 | } |
Oliver Stannard | 4df1cc0 | 2016-10-07 08:48:24 +0000 | [diff] [blame] | 225 | bool TargetTransformInfo::shouldBuildLookupTablesForConstant(Constant *C) const { |
| 226 | return TTIImpl->shouldBuildLookupTablesForConstant(C); |
| 227 | } |
Chandler Carruth | 539edf4 | 2013-01-05 11:43:11 +0000 | [diff] [blame] | 228 | |
Jonas Paulsson | 8e2f948 | 2017-01-26 07:03:25 +0000 | [diff] [blame] | 229 | unsigned TargetTransformInfo:: |
| 230 | getScalarizationOverhead(Type *Ty, bool Insert, bool Extract) const { |
| 231 | return TTIImpl->getScalarizationOverhead(Ty, Insert, Extract); |
| 232 | } |
| 233 | |
| 234 | unsigned TargetTransformInfo:: |
| 235 | getOperandsScalarizationOverhead(ArrayRef<const Value *> Args, |
| 236 | unsigned VF) const { |
| 237 | return TTIImpl->getOperandsScalarizationOverhead(Args, VF); |
| 238 | } |
| 239 | |
Jonas Paulsson | da74ed4 | 2017-04-12 12:41:37 +0000 | [diff] [blame] | 240 | bool TargetTransformInfo::supportsEfficientVectorElementLoadStore() const { |
| 241 | return TTIImpl->supportsEfficientVectorElementLoadStore(); |
| 242 | } |
| 243 | |
Olivier Sallenave | 049d803 | 2015-03-06 23:12:04 +0000 | [diff] [blame] | 244 | bool TargetTransformInfo::enableAggressiveInterleaving(bool LoopHasReductions) const { |
| 245 | return TTIImpl->enableAggressiveInterleaving(LoopHasReductions); |
| 246 | } |
| 247 | |
Clement Courbet | b2c3eb8 | 2017-10-30 14:19:33 +0000 | [diff] [blame] | 248 | const TargetTransformInfo::MemCmpExpansionOptions * |
| 249 | TargetTransformInfo::enableMemCmpExpansion(bool IsZeroCmp) const { |
| 250 | return TTIImpl->enableMemCmpExpansion(IsZeroCmp); |
Zaara Syeda | 3a7578c | 2017-05-31 17:12:38 +0000 | [diff] [blame] | 251 | } |
| 252 | |
Silviu Baranga | 61bdc51 | 2015-08-10 14:50:54 +0000 | [diff] [blame] | 253 | bool TargetTransformInfo::enableInterleavedAccessVectorization() const { |
| 254 | return TTIImpl->enableInterleavedAccessVectorization(); |
| 255 | } |
| 256 | |
Renato Golin | 5cb666a | 2016-04-14 20:42:18 +0000 | [diff] [blame] | 257 | bool TargetTransformInfo::isFPVectorizationPotentiallyUnsafe() const { |
| 258 | return TTIImpl->isFPVectorizationPotentiallyUnsafe(); |
| 259 | } |
| 260 | |
Alina Sbirlea | 6f937b1 | 2016-08-04 16:38:44 +0000 | [diff] [blame] | 261 | bool TargetTransformInfo::allowsMisalignedMemoryAccesses(LLVMContext &Context, |
| 262 | unsigned BitWidth, |
Alina Sbirlea | 327955e | 2016-07-11 20:46:17 +0000 | [diff] [blame] | 263 | unsigned AddressSpace, |
| 264 | unsigned Alignment, |
| 265 | bool *Fast) const { |
Alina Sbirlea | 6f937b1 | 2016-08-04 16:38:44 +0000 | [diff] [blame] | 266 | return TTIImpl->allowsMisalignedMemoryAccesses(Context, BitWidth, AddressSpace, |
Alina Sbirlea | 327955e | 2016-07-11 20:46:17 +0000 | [diff] [blame] | 267 | Alignment, Fast); |
| 268 | } |
| 269 | |
Chandler Carruth | 50a36cd | 2013-01-07 03:16:03 +0000 | [diff] [blame] | 270 | TargetTransformInfo::PopcntSupportKind |
| 271 | TargetTransformInfo::getPopcntSupport(unsigned IntTyWidthInBit) const { |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 272 | return TTIImpl->getPopcntSupport(IntTyWidthInBit); |
Chandler Carruth | 539edf4 | 2013-01-05 11:43:11 +0000 | [diff] [blame] | 273 | } |
| 274 | |
Richard Sandiford | 37cd6cf | 2013-08-23 10:27:02 +0000 | [diff] [blame] | 275 | bool TargetTransformInfo::haveFastSqrt(Type *Ty) const { |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 276 | return TTIImpl->haveFastSqrt(Ty); |
Richard Sandiford | 37cd6cf | 2013-08-23 10:27:02 +0000 | [diff] [blame] | 277 | } |
| 278 | |
Sanjay Patel | 0de1a4b | 2017-11-27 21:15:43 +0000 | [diff] [blame] | 279 | bool TargetTransformInfo::isFCmpOrdCheaperThanFCmpZero(Type *Ty) const { |
| 280 | return TTIImpl->isFCmpOrdCheaperThanFCmpZero(Ty); |
| 281 | } |
| 282 | |
Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 283 | int TargetTransformInfo::getFPOpCost(Type *Ty) const { |
| 284 | int Cost = TTIImpl->getFPOpCost(Ty); |
| 285 | assert(Cost >= 0 && "TTI should not produce negative costs!"); |
| 286 | return Cost; |
Cameron Esfahani | 17177d1 | 2015-02-05 02:09:33 +0000 | [diff] [blame] | 287 | } |
| 288 | |
Sjoerd Meijer | 38c2cd0 | 2016-07-14 07:44:20 +0000 | [diff] [blame] | 289 | int TargetTransformInfo::getIntImmCodeSizeCost(unsigned Opcode, unsigned Idx, |
| 290 | const APInt &Imm, |
| 291 | Type *Ty) const { |
| 292 | int Cost = TTIImpl->getIntImmCodeSizeCost(Opcode, Idx, Imm, Ty); |
| 293 | assert(Cost >= 0 && "TTI should not produce negative costs!"); |
| 294 | return Cost; |
| 295 | } |
| 296 | |
Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 297 | int TargetTransformInfo::getIntImmCost(const APInt &Imm, Type *Ty) const { |
| 298 | int Cost = TTIImpl->getIntImmCost(Imm, Ty); |
| 299 | assert(Cost >= 0 && "TTI should not produce negative costs!"); |
| 300 | return Cost; |
Chandler Carruth | 539edf4 | 2013-01-05 11:43:11 +0000 | [diff] [blame] | 301 | } |
| 302 | |
Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 303 | int TargetTransformInfo::getIntImmCost(unsigned Opcode, unsigned Idx, |
| 304 | const APInt &Imm, Type *Ty) const { |
| 305 | int Cost = TTIImpl->getIntImmCost(Opcode, Idx, Imm, Ty); |
| 306 | assert(Cost >= 0 && "TTI should not produce negative costs!"); |
| 307 | return Cost; |
Juergen Ributzka | f26beda | 2014-01-25 02:02:55 +0000 | [diff] [blame] | 308 | } |
| 309 | |
Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 310 | int TargetTransformInfo::getIntImmCost(Intrinsic::ID IID, unsigned Idx, |
| 311 | const APInt &Imm, Type *Ty) const { |
| 312 | int Cost = TTIImpl->getIntImmCost(IID, Idx, Imm, Ty); |
| 313 | assert(Cost >= 0 && "TTI should not produce negative costs!"); |
| 314 | return Cost; |
Juergen Ributzka | f26beda | 2014-01-25 02:02:55 +0000 | [diff] [blame] | 315 | } |
| 316 | |
Chandler Carruth | 539edf4 | 2013-01-05 11:43:11 +0000 | [diff] [blame] | 317 | unsigned TargetTransformInfo::getNumberOfRegisters(bool Vector) const { |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 318 | return TTIImpl->getNumberOfRegisters(Vector); |
Chandler Carruth | 539edf4 | 2013-01-05 11:43:11 +0000 | [diff] [blame] | 319 | } |
| 320 | |
Nadav Rotem | b1791a7 | 2013-01-09 22:29:00 +0000 | [diff] [blame] | 321 | unsigned TargetTransformInfo::getRegisterBitWidth(bool Vector) const { |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 322 | return TTIImpl->getRegisterBitWidth(Vector); |
Nadav Rotem | b1791a7 | 2013-01-09 22:29:00 +0000 | [diff] [blame] | 323 | } |
| 324 | |
Adam Nemet | e29686e | 2017-05-15 21:15:01 +0000 | [diff] [blame] | 325 | unsigned TargetTransformInfo::getMinVectorRegisterBitWidth() const { |
| 326 | return TTIImpl->getMinVectorRegisterBitWidth(); |
| 327 | } |
| 328 | |
Jun Bum Lim | dee5565 | 2017-04-03 19:20:07 +0000 | [diff] [blame] | 329 | bool TargetTransformInfo::shouldConsiderAddressTypePromotion( |
| 330 | const Instruction &I, bool &AllowPromotionWithoutCommonHeader) const { |
| 331 | return TTIImpl->shouldConsiderAddressTypePromotion( |
| 332 | I, AllowPromotionWithoutCommonHeader); |
| 333 | } |
| 334 | |
Adam Nemet | af76110 | 2016-01-21 18:28:36 +0000 | [diff] [blame] | 335 | unsigned TargetTransformInfo::getCacheLineSize() const { |
| 336 | return TTIImpl->getCacheLineSize(); |
| 337 | } |
| 338 | |
Tobias Grosser | d7eb619 | 2017-08-24 09:46:25 +0000 | [diff] [blame] | 339 | llvm::Optional<unsigned> TargetTransformInfo::getCacheSize(CacheLevel Level) |
| 340 | const { |
| 341 | return TTIImpl->getCacheSize(Level); |
| 342 | } |
| 343 | |
| 344 | llvm::Optional<unsigned> TargetTransformInfo::getCacheAssociativity( |
| 345 | CacheLevel Level) const { |
| 346 | return TTIImpl->getCacheAssociativity(Level); |
| 347 | } |
| 348 | |
Adam Nemet | dadfbb5 | 2016-01-27 22:21:25 +0000 | [diff] [blame] | 349 | unsigned TargetTransformInfo::getPrefetchDistance() const { |
| 350 | return TTIImpl->getPrefetchDistance(); |
| 351 | } |
| 352 | |
Adam Nemet | 6d8beec | 2016-03-18 00:27:38 +0000 | [diff] [blame] | 353 | unsigned TargetTransformInfo::getMinPrefetchStride() const { |
| 354 | return TTIImpl->getMinPrefetchStride(); |
| 355 | } |
| 356 | |
Adam Nemet | 709e304 | 2016-03-18 00:27:43 +0000 | [diff] [blame] | 357 | unsigned TargetTransformInfo::getMaxPrefetchIterationsAhead() const { |
| 358 | return TTIImpl->getMaxPrefetchIterationsAhead(); |
| 359 | } |
| 360 | |
Wei Mi | 062c744 | 2015-05-06 17:12:25 +0000 | [diff] [blame] | 361 | unsigned TargetTransformInfo::getMaxInterleaveFactor(unsigned VF) const { |
| 362 | return TTIImpl->getMaxInterleaveFactor(VF); |
Nadav Rotem | b696c36 | 2013-01-09 01:15:42 +0000 | [diff] [blame] | 363 | } |
| 364 | |
Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 365 | int TargetTransformInfo::getArithmeticInstrCost( |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 366 | unsigned Opcode, Type *Ty, OperandValueKind Opd1Info, |
| 367 | OperandValueKind Opd2Info, OperandValueProperties Opd1PropInfo, |
Mohammed Agabaria | 2c96c43 | 2017-01-11 08:23:37 +0000 | [diff] [blame] | 368 | OperandValueProperties Opd2PropInfo, |
| 369 | ArrayRef<const Value *> Args) const { |
Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 370 | int Cost = TTIImpl->getArithmeticInstrCost(Opcode, Ty, Opd1Info, Opd2Info, |
Mohammed Agabaria | 2c96c43 | 2017-01-11 08:23:37 +0000 | [diff] [blame] | 371 | Opd1PropInfo, Opd2PropInfo, Args); |
Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 372 | assert(Cost >= 0 && "TTI should not produce negative costs!"); |
| 373 | return Cost; |
Chandler Carruth | 539edf4 | 2013-01-05 11:43:11 +0000 | [diff] [blame] | 374 | } |
| 375 | |
Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 376 | int TargetTransformInfo::getShuffleCost(ShuffleKind Kind, Type *Ty, int Index, |
| 377 | Type *SubTp) const { |
| 378 | int Cost = TTIImpl->getShuffleCost(Kind, Ty, Index, SubTp); |
| 379 | assert(Cost >= 0 && "TTI should not produce negative costs!"); |
| 380 | return Cost; |
Chandler Carruth | 539edf4 | 2013-01-05 11:43:11 +0000 | [diff] [blame] | 381 | } |
| 382 | |
Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 383 | int TargetTransformInfo::getCastInstrCost(unsigned Opcode, Type *Dst, |
Jonas Paulsson | fccc7d6 | 2017-04-12 11:49:08 +0000 | [diff] [blame] | 384 | Type *Src, const Instruction *I) const { |
| 385 | assert ((I == nullptr || I->getOpcode() == Opcode) && |
| 386 | "Opcode should reflect passed instruction."); |
| 387 | int Cost = TTIImpl->getCastInstrCost(Opcode, Dst, Src, I); |
Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 388 | assert(Cost >= 0 && "TTI should not produce negative costs!"); |
| 389 | return Cost; |
Chandler Carruth | 539edf4 | 2013-01-05 11:43:11 +0000 | [diff] [blame] | 390 | } |
| 391 | |
Matthew Simpson | e5dfb08 | 2016-04-27 15:20:21 +0000 | [diff] [blame] | 392 | int TargetTransformInfo::getExtractWithExtendCost(unsigned Opcode, Type *Dst, |
| 393 | VectorType *VecTy, |
| 394 | unsigned Index) const { |
| 395 | int Cost = TTIImpl->getExtractWithExtendCost(Opcode, Dst, VecTy, Index); |
| 396 | assert(Cost >= 0 && "TTI should not produce negative costs!"); |
| 397 | return Cost; |
| 398 | } |
| 399 | |
Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 400 | int TargetTransformInfo::getCFInstrCost(unsigned Opcode) const { |
| 401 | int Cost = TTIImpl->getCFInstrCost(Opcode); |
| 402 | assert(Cost >= 0 && "TTI should not produce negative costs!"); |
| 403 | return Cost; |
Chandler Carruth | 539edf4 | 2013-01-05 11:43:11 +0000 | [diff] [blame] | 404 | } |
| 405 | |
Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 406 | int TargetTransformInfo::getCmpSelInstrCost(unsigned Opcode, Type *ValTy, |
Jonas Paulsson | fccc7d6 | 2017-04-12 11:49:08 +0000 | [diff] [blame] | 407 | Type *CondTy, const Instruction *I) const { |
| 408 | assert ((I == nullptr || I->getOpcode() == Opcode) && |
| 409 | "Opcode should reflect passed instruction."); |
| 410 | int Cost = TTIImpl->getCmpSelInstrCost(Opcode, ValTy, CondTy, I); |
Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 411 | assert(Cost >= 0 && "TTI should not produce negative costs!"); |
| 412 | return Cost; |
Chandler Carruth | 539edf4 | 2013-01-05 11:43:11 +0000 | [diff] [blame] | 413 | } |
| 414 | |
Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 415 | int TargetTransformInfo::getVectorInstrCost(unsigned Opcode, Type *Val, |
| 416 | unsigned Index) const { |
| 417 | int Cost = TTIImpl->getVectorInstrCost(Opcode, Val, Index); |
| 418 | assert(Cost >= 0 && "TTI should not produce negative costs!"); |
| 419 | return Cost; |
Chandler Carruth | 539edf4 | 2013-01-05 11:43:11 +0000 | [diff] [blame] | 420 | } |
| 421 | |
Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 422 | int TargetTransformInfo::getMemoryOpCost(unsigned Opcode, Type *Src, |
| 423 | unsigned Alignment, |
Jonas Paulsson | fccc7d6 | 2017-04-12 11:49:08 +0000 | [diff] [blame] | 424 | unsigned AddressSpace, |
| 425 | const Instruction *I) const { |
| 426 | assert ((I == nullptr || I->getOpcode() == Opcode) && |
| 427 | "Opcode should reflect passed instruction."); |
| 428 | int Cost = TTIImpl->getMemoryOpCost(Opcode, Src, Alignment, AddressSpace, I); |
Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 429 | assert(Cost >= 0 && "TTI should not produce negative costs!"); |
| 430 | return Cost; |
Elena Demikhovsky | a3232f7 | 2015-01-25 08:44:46 +0000 | [diff] [blame] | 431 | } |
| 432 | |
Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 433 | int TargetTransformInfo::getMaskedMemoryOpCost(unsigned Opcode, Type *Src, |
| 434 | unsigned Alignment, |
| 435 | unsigned AddressSpace) const { |
| 436 | int Cost = |
| 437 | TTIImpl->getMaskedMemoryOpCost(Opcode, Src, Alignment, AddressSpace); |
| 438 | assert(Cost >= 0 && "TTI should not produce negative costs!"); |
| 439 | return Cost; |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 440 | } |
| 441 | |
Elena Demikhovsky | 5494698 | 2015-12-28 20:10:59 +0000 | [diff] [blame] | 442 | int TargetTransformInfo::getGatherScatterOpCost(unsigned Opcode, Type *DataTy, |
| 443 | Value *Ptr, bool VariableMask, |
| 444 | unsigned Alignment) const { |
| 445 | int Cost = TTIImpl->getGatherScatterOpCost(Opcode, DataTy, Ptr, VariableMask, |
| 446 | Alignment); |
| 447 | assert(Cost >= 0 && "TTI should not produce negative costs!"); |
| 448 | return Cost; |
| 449 | } |
| 450 | |
Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 451 | int TargetTransformInfo::getInterleavedMemoryOpCost( |
Hao Liu | 32c0539 | 2015-06-08 06:39:56 +0000 | [diff] [blame] | 452 | unsigned Opcode, Type *VecTy, unsigned Factor, ArrayRef<unsigned> Indices, |
| 453 | unsigned Alignment, unsigned AddressSpace) const { |
Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 454 | int Cost = TTIImpl->getInterleavedMemoryOpCost(Opcode, VecTy, Factor, Indices, |
| 455 | Alignment, AddressSpace); |
| 456 | assert(Cost >= 0 && "TTI should not produce negative costs!"); |
| 457 | return Cost; |
Hao Liu | 32c0539 | 2015-06-08 06:39:56 +0000 | [diff] [blame] | 458 | } |
| 459 | |
Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 460 | int TargetTransformInfo::getIntrinsicInstrCost(Intrinsic::ID ID, Type *RetTy, |
Jonas Paulsson | a48ea23 | 2017-03-14 06:35:36 +0000 | [diff] [blame] | 461 | ArrayRef<Type *> Tys, FastMathFlags FMF, |
| 462 | unsigned ScalarizationCostPassed) const { |
| 463 | int Cost = TTIImpl->getIntrinsicInstrCost(ID, RetTy, Tys, FMF, |
| 464 | ScalarizationCostPassed); |
Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 465 | assert(Cost >= 0 && "TTI should not produce negative costs!"); |
| 466 | return Cost; |
| 467 | } |
| 468 | |
Elena Demikhovsky | 5494698 | 2015-12-28 20:10:59 +0000 | [diff] [blame] | 469 | int TargetTransformInfo::getIntrinsicInstrCost(Intrinsic::ID ID, Type *RetTy, |
Jonas Paulsson | a48ea23 | 2017-03-14 06:35:36 +0000 | [diff] [blame] | 470 | ArrayRef<Value *> Args, FastMathFlags FMF, unsigned VF) const { |
| 471 | int Cost = TTIImpl->getIntrinsicInstrCost(ID, RetTy, Args, FMF, VF); |
Elena Demikhovsky | 5494698 | 2015-12-28 20:10:59 +0000 | [diff] [blame] | 472 | assert(Cost >= 0 && "TTI should not produce negative costs!"); |
| 473 | return Cost; |
| 474 | } |
| 475 | |
Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 476 | int TargetTransformInfo::getCallInstrCost(Function *F, Type *RetTy, |
| 477 | ArrayRef<Type *> Tys) const { |
| 478 | int Cost = TTIImpl->getCallInstrCost(F, RetTy, Tys); |
| 479 | assert(Cost >= 0 && "TTI should not produce negative costs!"); |
| 480 | return Cost; |
Michael Zolotukhin | 7ed84a8 | 2015-03-17 19:26:23 +0000 | [diff] [blame] | 481 | } |
| 482 | |
Chandler Carruth | 539edf4 | 2013-01-05 11:43:11 +0000 | [diff] [blame] | 483 | unsigned TargetTransformInfo::getNumberOfParts(Type *Tp) const { |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 484 | return TTIImpl->getNumberOfParts(Tp); |
Chandler Carruth | 539edf4 | 2013-01-05 11:43:11 +0000 | [diff] [blame] | 485 | } |
| 486 | |
Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 487 | int TargetTransformInfo::getAddressComputationCost(Type *Tp, |
Mohammed Agabaria | 23599ba | 2017-01-05 14:03:41 +0000 | [diff] [blame] | 488 | ScalarEvolution *SE, |
| 489 | const SCEV *Ptr) const { |
| 490 | int Cost = TTIImpl->getAddressComputationCost(Tp, SE, Ptr); |
Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 491 | assert(Cost >= 0 && "TTI should not produce negative costs!"); |
| 492 | return Cost; |
Arnold Schwaighofer | 594fa2d | 2013-02-08 14:50:48 +0000 | [diff] [blame] | 493 | } |
Chandler Carruth | 539edf4 | 2013-01-05 11:43:11 +0000 | [diff] [blame] | 494 | |
Alexey Bataev | 3e9b3eb | 2017-07-31 14:19:32 +0000 | [diff] [blame] | 495 | int TargetTransformInfo::getArithmeticReductionCost(unsigned Opcode, Type *Ty, |
| 496 | bool IsPairwiseForm) const { |
| 497 | int Cost = TTIImpl->getArithmeticReductionCost(Opcode, Ty, IsPairwiseForm); |
Chandler Carruth | 93205eb | 2015-08-05 18:08:10 +0000 | [diff] [blame] | 498 | assert(Cost >= 0 && "TTI should not produce negative costs!"); |
| 499 | return Cost; |
Arnold Schwaighofer | cae8735 | 2013-09-17 18:06:50 +0000 | [diff] [blame] | 500 | } |
| 501 | |
Alexey Bataev | 6dd29fc | 2017-09-08 13:49:36 +0000 | [diff] [blame] | 502 | int TargetTransformInfo::getMinMaxReductionCost(Type *Ty, Type *CondTy, |
| 503 | bool IsPairwiseForm, |
| 504 | bool IsUnsigned) const { |
| 505 | int Cost = |
| 506 | TTIImpl->getMinMaxReductionCost(Ty, CondTy, IsPairwiseForm, IsUnsigned); |
| 507 | assert(Cost >= 0 && "TTI should not produce negative costs!"); |
| 508 | return Cost; |
| 509 | } |
| 510 | |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 511 | unsigned |
| 512 | TargetTransformInfo::getCostOfKeepingLiveOverCall(ArrayRef<Type *> Tys) const { |
| 513 | return TTIImpl->getCostOfKeepingLiveOverCall(Tys); |
Chad Rosier | f9327d6 | 2015-01-26 22:51:15 +0000 | [diff] [blame] | 514 | } |
| 515 | |
| 516 | bool TargetTransformInfo::getTgtMemIntrinsic(IntrinsicInst *Inst, |
| 517 | MemIntrinsicInfo &Info) const { |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 518 | return TTIImpl->getTgtMemIntrinsic(Inst, Info); |
Chad Rosier | f9327d6 | 2015-01-26 22:51:15 +0000 | [diff] [blame] | 519 | } |
| 520 | |
Anna Thomas | b2a212c | 2017-06-06 16:45:25 +0000 | [diff] [blame] | 521 | unsigned TargetTransformInfo::getAtomicMemIntrinsicMaxElementSize() const { |
| 522 | return TTIImpl->getAtomicMemIntrinsicMaxElementSize(); |
| 523 | } |
| 524 | |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 525 | Value *TargetTransformInfo::getOrCreateResultFromMemIntrinsic( |
| 526 | IntrinsicInst *Inst, Type *ExpectedType) const { |
| 527 | return TTIImpl->getOrCreateResultFromMemIntrinsic(Inst, ExpectedType); |
| 528 | } |
| 529 | |
Sean Fertile | 9cd1cdf | 2017-07-07 02:00:06 +0000 | [diff] [blame] | 530 | Type *TargetTransformInfo::getMemcpyLoopLoweringType(LLVMContext &Context, |
| 531 | Value *Length, |
| 532 | unsigned SrcAlign, |
| 533 | unsigned DestAlign) const { |
| 534 | return TTIImpl->getMemcpyLoopLoweringType(Context, Length, SrcAlign, |
| 535 | DestAlign); |
| 536 | } |
| 537 | |
| 538 | void TargetTransformInfo::getMemcpyLoopResidualLoweringType( |
| 539 | SmallVectorImpl<Type *> &OpsOut, LLVMContext &Context, |
| 540 | unsigned RemainingBytes, unsigned SrcAlign, unsigned DestAlign) const { |
| 541 | TTIImpl->getMemcpyLoopResidualLoweringType(OpsOut, Context, RemainingBytes, |
| 542 | SrcAlign, DestAlign); |
| 543 | } |
| 544 | |
Eric Christopher | d566fb1 | 2015-07-29 22:09:48 +0000 | [diff] [blame] | 545 | bool TargetTransformInfo::areInlineCompatible(const Function *Caller, |
| 546 | const Function *Callee) const { |
| 547 | return TTIImpl->areInlineCompatible(Caller, Callee); |
Eric Christopher | 4371b13 | 2015-07-02 01:11:47 +0000 | [diff] [blame] | 548 | } |
| 549 | |
Volkan Keles | 1c38681 | 2016-10-03 10:31:34 +0000 | [diff] [blame] | 550 | unsigned TargetTransformInfo::getLoadStoreVecRegBitWidth(unsigned AS) const { |
| 551 | return TTIImpl->getLoadStoreVecRegBitWidth(AS); |
| 552 | } |
| 553 | |
| 554 | bool TargetTransformInfo::isLegalToVectorizeLoad(LoadInst *LI) const { |
| 555 | return TTIImpl->isLegalToVectorizeLoad(LI); |
| 556 | } |
| 557 | |
| 558 | bool TargetTransformInfo::isLegalToVectorizeStore(StoreInst *SI) const { |
| 559 | return TTIImpl->isLegalToVectorizeStore(SI); |
| 560 | } |
| 561 | |
| 562 | bool TargetTransformInfo::isLegalToVectorizeLoadChain( |
| 563 | unsigned ChainSizeInBytes, unsigned Alignment, unsigned AddrSpace) const { |
| 564 | return TTIImpl->isLegalToVectorizeLoadChain(ChainSizeInBytes, Alignment, |
| 565 | AddrSpace); |
| 566 | } |
| 567 | |
| 568 | bool TargetTransformInfo::isLegalToVectorizeStoreChain( |
| 569 | unsigned ChainSizeInBytes, unsigned Alignment, unsigned AddrSpace) const { |
| 570 | return TTIImpl->isLegalToVectorizeStoreChain(ChainSizeInBytes, Alignment, |
| 571 | AddrSpace); |
| 572 | } |
| 573 | |
| 574 | unsigned TargetTransformInfo::getLoadVectorFactor(unsigned VF, |
| 575 | unsigned LoadSize, |
| 576 | unsigned ChainSizeInBytes, |
| 577 | VectorType *VecTy) const { |
| 578 | return TTIImpl->getLoadVectorFactor(VF, LoadSize, ChainSizeInBytes, VecTy); |
| 579 | } |
| 580 | |
| 581 | unsigned TargetTransformInfo::getStoreVectorFactor(unsigned VF, |
| 582 | unsigned StoreSize, |
| 583 | unsigned ChainSizeInBytes, |
| 584 | VectorType *VecTy) const { |
| 585 | return TTIImpl->getStoreVectorFactor(VF, StoreSize, ChainSizeInBytes, VecTy); |
| 586 | } |
| 587 | |
Amara Emerson | cf9daa3 | 2017-05-09 10:43:25 +0000 | [diff] [blame] | 588 | bool TargetTransformInfo::useReductionIntrinsic(unsigned Opcode, |
| 589 | Type *Ty, ReductionFlags Flags) const { |
| 590 | return TTIImpl->useReductionIntrinsic(Opcode, Ty, Flags); |
| 591 | } |
| 592 | |
Amara Emerson | 836b0f4 | 2017-05-10 09:42:49 +0000 | [diff] [blame] | 593 | bool TargetTransformInfo::shouldExpandReduction(const IntrinsicInst *II) const { |
| 594 | return TTIImpl->shouldExpandReduction(II); |
| 595 | } |
Amara Emerson | cf9daa3 | 2017-05-09 10:43:25 +0000 | [diff] [blame] | 596 | |
Guozhi Wei | 62d6414 | 2017-09-08 22:29:17 +0000 | [diff] [blame] | 597 | int TargetTransformInfo::getInstructionLatency(const Instruction *I) const { |
| 598 | return TTIImpl->getInstructionLatency(I); |
| 599 | } |
| 600 | |
| 601 | static bool isReverseVectorMask(ArrayRef<int> Mask) { |
| 602 | for (unsigned i = 0, MaskSize = Mask.size(); i < MaskSize; ++i) |
| 603 | if (Mask[i] >= 0 && Mask[i] != (int)(MaskSize - 1 - i)) |
| 604 | return false; |
| 605 | return true; |
| 606 | } |
| 607 | |
| 608 | static bool isSingleSourceVectorMask(ArrayRef<int> Mask) { |
| 609 | bool Vec0 = false; |
| 610 | bool Vec1 = false; |
| 611 | for (unsigned i = 0, NumVecElts = Mask.size(); i < NumVecElts; ++i) { |
| 612 | if (Mask[i] >= 0) { |
| 613 | if ((unsigned)Mask[i] >= NumVecElts) |
| 614 | Vec1 = true; |
| 615 | else |
| 616 | Vec0 = true; |
| 617 | } |
| 618 | } |
| 619 | return !(Vec0 && Vec1); |
| 620 | } |
| 621 | |
| 622 | static bool isZeroEltBroadcastVectorMask(ArrayRef<int> Mask) { |
| 623 | for (unsigned i = 0; i < Mask.size(); ++i) |
| 624 | if (Mask[i] > 0) |
| 625 | return false; |
| 626 | return true; |
| 627 | } |
| 628 | |
| 629 | static bool isAlternateVectorMask(ArrayRef<int> Mask) { |
| 630 | bool isAlternate = true; |
| 631 | unsigned MaskSize = Mask.size(); |
| 632 | |
| 633 | // Example: shufflevector A, B, <0,5,2,7> |
| 634 | for (unsigned i = 0; i < MaskSize && isAlternate; ++i) { |
| 635 | if (Mask[i] < 0) |
| 636 | continue; |
| 637 | isAlternate = Mask[i] == (int)((i & 1) ? MaskSize + i : i); |
| 638 | } |
| 639 | |
| 640 | if (isAlternate) |
| 641 | return true; |
| 642 | |
| 643 | isAlternate = true; |
| 644 | // Example: shufflevector A, B, <4,1,6,3> |
| 645 | for (unsigned i = 0; i < MaskSize && isAlternate; ++i) { |
| 646 | if (Mask[i] < 0) |
| 647 | continue; |
| 648 | isAlternate = Mask[i] == (int)((i & 1) ? i : MaskSize + i); |
| 649 | } |
| 650 | |
| 651 | return isAlternate; |
| 652 | } |
| 653 | |
| 654 | static TargetTransformInfo::OperandValueKind getOperandInfo(Value *V) { |
| 655 | TargetTransformInfo::OperandValueKind OpInfo = |
| 656 | TargetTransformInfo::OK_AnyValue; |
| 657 | |
| 658 | // Check for a splat of a constant or for a non uniform vector of constants. |
| 659 | if (isa<ConstantVector>(V) || isa<ConstantDataVector>(V)) { |
| 660 | OpInfo = TargetTransformInfo::OK_NonUniformConstantValue; |
| 661 | if (cast<Constant>(V)->getSplatValue() != nullptr) |
| 662 | OpInfo = TargetTransformInfo::OK_UniformConstantValue; |
| 663 | } |
| 664 | |
| 665 | // Check for a splat of a uniform value. This is not loop aware, so return |
| 666 | // true only for the obviously uniform cases (argument, globalvalue) |
| 667 | const Value *Splat = getSplatValue(V); |
| 668 | if (Splat && (isa<Argument>(Splat) || isa<GlobalValue>(Splat))) |
| 669 | OpInfo = TargetTransformInfo::OK_UniformValue; |
| 670 | |
| 671 | return OpInfo; |
| 672 | } |
| 673 | |
| 674 | static bool matchPairwiseShuffleMask(ShuffleVectorInst *SI, bool IsLeft, |
| 675 | unsigned Level) { |
| 676 | // We don't need a shuffle if we just want to have element 0 in position 0 of |
| 677 | // the vector. |
| 678 | if (!SI && Level == 0 && IsLeft) |
| 679 | return true; |
| 680 | else if (!SI) |
| 681 | return false; |
| 682 | |
| 683 | SmallVector<int, 32> Mask(SI->getType()->getVectorNumElements(), -1); |
| 684 | |
| 685 | // Build a mask of 0, 2, ... (left) or 1, 3, ... (right) depending on whether |
| 686 | // we look at the left or right side. |
| 687 | for (unsigned i = 0, e = (1 << Level), val = !IsLeft; i != e; ++i, val += 2) |
| 688 | Mask[i] = val; |
| 689 | |
| 690 | SmallVector<int, 16> ActualMask = SI->getShuffleMask(); |
| 691 | return Mask == ActualMask; |
| 692 | } |
| 693 | |
| 694 | namespace { |
| 695 | /// Kind of the reduction data. |
| 696 | enum ReductionKind { |
| 697 | RK_None, /// Not a reduction. |
| 698 | RK_Arithmetic, /// Binary reduction data. |
| 699 | RK_MinMax, /// Min/max reduction data. |
| 700 | RK_UnsignedMinMax, /// Unsigned min/max reduction data. |
| 701 | }; |
| 702 | /// Contains opcode + LHS/RHS parts of the reduction operations. |
| 703 | struct ReductionData { |
| 704 | ReductionData() = delete; |
| 705 | ReductionData(ReductionKind Kind, unsigned Opcode, Value *LHS, Value *RHS) |
| 706 | : Opcode(Opcode), LHS(LHS), RHS(RHS), Kind(Kind) { |
| 707 | assert(Kind != RK_None && "expected binary or min/max reduction only."); |
| 708 | } |
| 709 | unsigned Opcode = 0; |
| 710 | Value *LHS = nullptr; |
| 711 | Value *RHS = nullptr; |
| 712 | ReductionKind Kind = RK_None; |
| 713 | bool hasSameData(ReductionData &RD) const { |
| 714 | return Kind == RD.Kind && Opcode == RD.Opcode; |
| 715 | } |
| 716 | }; |
| 717 | } // namespace |
| 718 | |
| 719 | static Optional<ReductionData> getReductionData(Instruction *I) { |
| 720 | Value *L, *R; |
| 721 | if (m_BinOp(m_Value(L), m_Value(R)).match(I)) |
| 722 | return ReductionData(RK_Arithmetic, I->getOpcode(), L, R); |
| 723 | if (auto *SI = dyn_cast<SelectInst>(I)) { |
| 724 | if (m_SMin(m_Value(L), m_Value(R)).match(SI) || |
| 725 | m_SMax(m_Value(L), m_Value(R)).match(SI) || |
| 726 | m_OrdFMin(m_Value(L), m_Value(R)).match(SI) || |
| 727 | m_OrdFMax(m_Value(L), m_Value(R)).match(SI) || |
| 728 | m_UnordFMin(m_Value(L), m_Value(R)).match(SI) || |
| 729 | m_UnordFMax(m_Value(L), m_Value(R)).match(SI)) { |
| 730 | auto *CI = cast<CmpInst>(SI->getCondition()); |
| 731 | return ReductionData(RK_MinMax, CI->getOpcode(), L, R); |
| 732 | } |
| 733 | if (m_UMin(m_Value(L), m_Value(R)).match(SI) || |
| 734 | m_UMax(m_Value(L), m_Value(R)).match(SI)) { |
| 735 | auto *CI = cast<CmpInst>(SI->getCondition()); |
| 736 | return ReductionData(RK_UnsignedMinMax, CI->getOpcode(), L, R); |
| 737 | } |
| 738 | } |
| 739 | return llvm::None; |
| 740 | } |
| 741 | |
| 742 | static ReductionKind matchPairwiseReductionAtLevel(Instruction *I, |
| 743 | unsigned Level, |
| 744 | unsigned NumLevels) { |
| 745 | // Match one level of pairwise operations. |
| 746 | // %rdx.shuf.0.0 = shufflevector <4 x float> %rdx, <4 x float> undef, |
| 747 | // <4 x i32> <i32 0, i32 2 , i32 undef, i32 undef> |
| 748 | // %rdx.shuf.0.1 = shufflevector <4 x float> %rdx, <4 x float> undef, |
| 749 | // <4 x i32> <i32 1, i32 3, i32 undef, i32 undef> |
| 750 | // %bin.rdx.0 = fadd <4 x float> %rdx.shuf.0.0, %rdx.shuf.0.1 |
| 751 | if (!I) |
| 752 | return RK_None; |
| 753 | |
| 754 | assert(I->getType()->isVectorTy() && "Expecting a vector type"); |
| 755 | |
| 756 | Optional<ReductionData> RD = getReductionData(I); |
| 757 | if (!RD) |
| 758 | return RK_None; |
| 759 | |
| 760 | ShuffleVectorInst *LS = dyn_cast<ShuffleVectorInst>(RD->LHS); |
| 761 | if (!LS && Level) |
| 762 | return RK_None; |
| 763 | ShuffleVectorInst *RS = dyn_cast<ShuffleVectorInst>(RD->RHS); |
| 764 | if (!RS && Level) |
| 765 | return RK_None; |
| 766 | |
| 767 | // On level 0 we can omit one shufflevector instruction. |
| 768 | if (!Level && !RS && !LS) |
| 769 | return RK_None; |
| 770 | |
| 771 | // Shuffle inputs must match. |
| 772 | Value *NextLevelOpL = LS ? LS->getOperand(0) : nullptr; |
| 773 | Value *NextLevelOpR = RS ? RS->getOperand(0) : nullptr; |
| 774 | Value *NextLevelOp = nullptr; |
| 775 | if (NextLevelOpR && NextLevelOpL) { |
| 776 | // If we have two shuffles their operands must match. |
| 777 | if (NextLevelOpL != NextLevelOpR) |
| 778 | return RK_None; |
| 779 | |
| 780 | NextLevelOp = NextLevelOpL; |
| 781 | } else if (Level == 0 && (NextLevelOpR || NextLevelOpL)) { |
| 782 | // On the first level we can omit the shufflevector <0, undef,...>. So the |
| 783 | // input to the other shufflevector <1, undef> must match with one of the |
| 784 | // inputs to the current binary operation. |
| 785 | // Example: |
| 786 | // %NextLevelOpL = shufflevector %R, <1, undef ...> |
| 787 | // %BinOp = fadd %NextLevelOpL, %R |
| 788 | if (NextLevelOpL && NextLevelOpL != RD->RHS) |
| 789 | return RK_None; |
| 790 | else if (NextLevelOpR && NextLevelOpR != RD->LHS) |
| 791 | return RK_None; |
| 792 | |
| 793 | NextLevelOp = NextLevelOpL ? RD->RHS : RD->LHS; |
| 794 | } else |
| 795 | return RK_None; |
| 796 | |
| 797 | // Check that the next levels binary operation exists and matches with the |
| 798 | // current one. |
| 799 | if (Level + 1 != NumLevels) { |
| 800 | Optional<ReductionData> NextLevelRD = |
| 801 | getReductionData(cast<Instruction>(NextLevelOp)); |
| 802 | if (!NextLevelRD || !RD->hasSameData(*NextLevelRD)) |
| 803 | return RK_None; |
| 804 | } |
| 805 | |
| 806 | // Shuffle mask for pairwise operation must match. |
| 807 | if (matchPairwiseShuffleMask(LS, /*IsLeft=*/true, Level)) { |
| 808 | if (!matchPairwiseShuffleMask(RS, /*IsLeft=*/false, Level)) |
| 809 | return RK_None; |
| 810 | } else if (matchPairwiseShuffleMask(RS, /*IsLeft=*/true, Level)) { |
| 811 | if (!matchPairwiseShuffleMask(LS, /*IsLeft=*/false, Level)) |
| 812 | return RK_None; |
| 813 | } else { |
| 814 | return RK_None; |
| 815 | } |
| 816 | |
| 817 | if (++Level == NumLevels) |
| 818 | return RD->Kind; |
| 819 | |
| 820 | // Match next level. |
| 821 | return matchPairwiseReductionAtLevel(cast<Instruction>(NextLevelOp), Level, |
| 822 | NumLevels); |
| 823 | } |
| 824 | |
| 825 | static ReductionKind matchPairwiseReduction(const ExtractElementInst *ReduxRoot, |
| 826 | unsigned &Opcode, Type *&Ty) { |
| 827 | if (!EnableReduxCost) |
| 828 | return RK_None; |
| 829 | |
| 830 | // Need to extract the first element. |
| 831 | ConstantInt *CI = dyn_cast<ConstantInt>(ReduxRoot->getOperand(1)); |
| 832 | unsigned Idx = ~0u; |
| 833 | if (CI) |
| 834 | Idx = CI->getZExtValue(); |
| 835 | if (Idx != 0) |
| 836 | return RK_None; |
| 837 | |
| 838 | auto *RdxStart = dyn_cast<Instruction>(ReduxRoot->getOperand(0)); |
| 839 | if (!RdxStart) |
| 840 | return RK_None; |
| 841 | Optional<ReductionData> RD = getReductionData(RdxStart); |
| 842 | if (!RD) |
| 843 | return RK_None; |
| 844 | |
| 845 | Type *VecTy = RdxStart->getType(); |
| 846 | unsigned NumVecElems = VecTy->getVectorNumElements(); |
| 847 | if (!isPowerOf2_32(NumVecElems)) |
| 848 | return RK_None; |
| 849 | |
| 850 | // We look for a sequence of shuffle,shuffle,add triples like the following |
| 851 | // that builds a pairwise reduction tree. |
| 852 | // |
| 853 | // (X0, X1, X2, X3) |
| 854 | // (X0 + X1, X2 + X3, undef, undef) |
| 855 | // ((X0 + X1) + (X2 + X3), undef, undef, undef) |
| 856 | // |
| 857 | // %rdx.shuf.0.0 = shufflevector <4 x float> %rdx, <4 x float> undef, |
| 858 | // <4 x i32> <i32 0, i32 2 , i32 undef, i32 undef> |
| 859 | // %rdx.shuf.0.1 = shufflevector <4 x float> %rdx, <4 x float> undef, |
| 860 | // <4 x i32> <i32 1, i32 3, i32 undef, i32 undef> |
| 861 | // %bin.rdx.0 = fadd <4 x float> %rdx.shuf.0.0, %rdx.shuf.0.1 |
| 862 | // %rdx.shuf.1.0 = shufflevector <4 x float> %bin.rdx.0, <4 x float> undef, |
| 863 | // <4 x i32> <i32 0, i32 undef, i32 undef, i32 undef> |
| 864 | // %rdx.shuf.1.1 = shufflevector <4 x float> %bin.rdx.0, <4 x float> undef, |
| 865 | // <4 x i32> <i32 1, i32 undef, i32 undef, i32 undef> |
| 866 | // %bin.rdx8 = fadd <4 x float> %rdx.shuf.1.0, %rdx.shuf.1.1 |
| 867 | // %r = extractelement <4 x float> %bin.rdx8, i32 0 |
| 868 | if (matchPairwiseReductionAtLevel(RdxStart, 0, Log2_32(NumVecElems)) == |
| 869 | RK_None) |
| 870 | return RK_None; |
| 871 | |
| 872 | Opcode = RD->Opcode; |
| 873 | Ty = VecTy; |
| 874 | |
| 875 | return RD->Kind; |
| 876 | } |
| 877 | |
| 878 | static std::pair<Value *, ShuffleVectorInst *> |
| 879 | getShuffleAndOtherOprd(Value *L, Value *R) { |
| 880 | ShuffleVectorInst *S = nullptr; |
| 881 | |
| 882 | if ((S = dyn_cast<ShuffleVectorInst>(L))) |
| 883 | return std::make_pair(R, S); |
| 884 | |
| 885 | S = dyn_cast<ShuffleVectorInst>(R); |
| 886 | return std::make_pair(L, S); |
| 887 | } |
| 888 | |
| 889 | static ReductionKind |
| 890 | matchVectorSplittingReduction(const ExtractElementInst *ReduxRoot, |
| 891 | unsigned &Opcode, Type *&Ty) { |
| 892 | if (!EnableReduxCost) |
| 893 | return RK_None; |
| 894 | |
| 895 | // Need to extract the first element. |
| 896 | ConstantInt *CI = dyn_cast<ConstantInt>(ReduxRoot->getOperand(1)); |
| 897 | unsigned Idx = ~0u; |
| 898 | if (CI) |
| 899 | Idx = CI->getZExtValue(); |
| 900 | if (Idx != 0) |
| 901 | return RK_None; |
| 902 | |
| 903 | auto *RdxStart = dyn_cast<Instruction>(ReduxRoot->getOperand(0)); |
| 904 | if (!RdxStart) |
| 905 | return RK_None; |
| 906 | Optional<ReductionData> RD = getReductionData(RdxStart); |
| 907 | if (!RD) |
| 908 | return RK_None; |
| 909 | |
| 910 | Type *VecTy = ReduxRoot->getOperand(0)->getType(); |
| 911 | unsigned NumVecElems = VecTy->getVectorNumElements(); |
| 912 | if (!isPowerOf2_32(NumVecElems)) |
| 913 | return RK_None; |
| 914 | |
| 915 | // We look for a sequence of shuffles and adds like the following matching one |
| 916 | // fadd, shuffle vector pair at a time. |
| 917 | // |
| 918 | // %rdx.shuf = shufflevector <4 x float> %rdx, <4 x float> undef, |
| 919 | // <4 x i32> <i32 2, i32 3, i32 undef, i32 undef> |
| 920 | // %bin.rdx = fadd <4 x float> %rdx, %rdx.shuf |
| 921 | // %rdx.shuf7 = shufflevector <4 x float> %bin.rdx, <4 x float> undef, |
| 922 | // <4 x i32> <i32 1, i32 undef, i32 undef, i32 undef> |
| 923 | // %bin.rdx8 = fadd <4 x float> %bin.rdx, %rdx.shuf7 |
| 924 | // %r = extractelement <4 x float> %bin.rdx8, i32 0 |
| 925 | |
| 926 | unsigned MaskStart = 1; |
| 927 | Instruction *RdxOp = RdxStart; |
| 928 | SmallVector<int, 32> ShuffleMask(NumVecElems, 0); |
| 929 | unsigned NumVecElemsRemain = NumVecElems; |
| 930 | while (NumVecElemsRemain - 1) { |
| 931 | // Check for the right reduction operation. |
| 932 | if (!RdxOp) |
| 933 | return RK_None; |
| 934 | Optional<ReductionData> RDLevel = getReductionData(RdxOp); |
| 935 | if (!RDLevel || !RDLevel->hasSameData(*RD)) |
| 936 | return RK_None; |
| 937 | |
| 938 | Value *NextRdxOp; |
| 939 | ShuffleVectorInst *Shuffle; |
| 940 | std::tie(NextRdxOp, Shuffle) = |
| 941 | getShuffleAndOtherOprd(RDLevel->LHS, RDLevel->RHS); |
| 942 | |
| 943 | // Check the current reduction operation and the shuffle use the same value. |
| 944 | if (Shuffle == nullptr) |
| 945 | return RK_None; |
| 946 | if (Shuffle->getOperand(0) != NextRdxOp) |
| 947 | return RK_None; |
| 948 | |
| 949 | // Check that shuffle masks matches. |
| 950 | for (unsigned j = 0; j != MaskStart; ++j) |
| 951 | ShuffleMask[j] = MaskStart + j; |
| 952 | // Fill the rest of the mask with -1 for undef. |
| 953 | std::fill(&ShuffleMask[MaskStart], ShuffleMask.end(), -1); |
| 954 | |
| 955 | SmallVector<int, 16> Mask = Shuffle->getShuffleMask(); |
| 956 | if (ShuffleMask != Mask) |
| 957 | return RK_None; |
| 958 | |
| 959 | RdxOp = dyn_cast<Instruction>(NextRdxOp); |
| 960 | NumVecElemsRemain /= 2; |
| 961 | MaskStart *= 2; |
| 962 | } |
| 963 | |
| 964 | Opcode = RD->Opcode; |
| 965 | Ty = VecTy; |
| 966 | return RD->Kind; |
| 967 | } |
| 968 | |
| 969 | int TargetTransformInfo::getInstructionThroughput(const Instruction *I) const { |
| 970 | switch (I->getOpcode()) { |
| 971 | case Instruction::GetElementPtr: |
| 972 | return getUserCost(I); |
| 973 | |
| 974 | case Instruction::Ret: |
| 975 | case Instruction::PHI: |
| 976 | case Instruction::Br: { |
| 977 | return getCFInstrCost(I->getOpcode()); |
| 978 | } |
| 979 | case Instruction::Add: |
| 980 | case Instruction::FAdd: |
| 981 | case Instruction::Sub: |
| 982 | case Instruction::FSub: |
| 983 | case Instruction::Mul: |
| 984 | case Instruction::FMul: |
| 985 | case Instruction::UDiv: |
| 986 | case Instruction::SDiv: |
| 987 | case Instruction::FDiv: |
| 988 | case Instruction::URem: |
| 989 | case Instruction::SRem: |
| 990 | case Instruction::FRem: |
| 991 | case Instruction::Shl: |
| 992 | case Instruction::LShr: |
| 993 | case Instruction::AShr: |
| 994 | case Instruction::And: |
| 995 | case Instruction::Or: |
| 996 | case Instruction::Xor: { |
| 997 | TargetTransformInfo::OperandValueKind Op1VK = |
| 998 | getOperandInfo(I->getOperand(0)); |
| 999 | TargetTransformInfo::OperandValueKind Op2VK = |
| 1000 | getOperandInfo(I->getOperand(1)); |
| 1001 | SmallVector<const Value*, 2> Operands(I->operand_values()); |
| 1002 | return getArithmeticInstrCost(I->getOpcode(), I->getType(), Op1VK, |
| 1003 | Op2VK, TargetTransformInfo::OP_None, |
| 1004 | TargetTransformInfo::OP_None, |
| 1005 | Operands); |
| 1006 | } |
| 1007 | case Instruction::Select: { |
| 1008 | const SelectInst *SI = cast<SelectInst>(I); |
| 1009 | Type *CondTy = SI->getCondition()->getType(); |
| 1010 | return getCmpSelInstrCost(I->getOpcode(), I->getType(), CondTy, I); |
| 1011 | } |
| 1012 | case Instruction::ICmp: |
| 1013 | case Instruction::FCmp: { |
| 1014 | Type *ValTy = I->getOperand(0)->getType(); |
| 1015 | return getCmpSelInstrCost(I->getOpcode(), ValTy, I->getType(), I); |
| 1016 | } |
| 1017 | case Instruction::Store: { |
| 1018 | const StoreInst *SI = cast<StoreInst>(I); |
| 1019 | Type *ValTy = SI->getValueOperand()->getType(); |
| 1020 | return getMemoryOpCost(I->getOpcode(), ValTy, |
| 1021 | SI->getAlignment(), |
| 1022 | SI->getPointerAddressSpace(), I); |
| 1023 | } |
| 1024 | case Instruction::Load: { |
| 1025 | const LoadInst *LI = cast<LoadInst>(I); |
| 1026 | return getMemoryOpCost(I->getOpcode(), I->getType(), |
| 1027 | LI->getAlignment(), |
| 1028 | LI->getPointerAddressSpace(), I); |
| 1029 | } |
| 1030 | case Instruction::ZExt: |
| 1031 | case Instruction::SExt: |
| 1032 | case Instruction::FPToUI: |
| 1033 | case Instruction::FPToSI: |
| 1034 | case Instruction::FPExt: |
| 1035 | case Instruction::PtrToInt: |
| 1036 | case Instruction::IntToPtr: |
| 1037 | case Instruction::SIToFP: |
| 1038 | case Instruction::UIToFP: |
| 1039 | case Instruction::Trunc: |
| 1040 | case Instruction::FPTrunc: |
| 1041 | case Instruction::BitCast: |
| 1042 | case Instruction::AddrSpaceCast: { |
| 1043 | Type *SrcTy = I->getOperand(0)->getType(); |
| 1044 | return getCastInstrCost(I->getOpcode(), I->getType(), SrcTy, I); |
| 1045 | } |
| 1046 | case Instruction::ExtractElement: { |
| 1047 | const ExtractElementInst * EEI = cast<ExtractElementInst>(I); |
| 1048 | ConstantInt *CI = dyn_cast<ConstantInt>(I->getOperand(1)); |
| 1049 | unsigned Idx = -1; |
| 1050 | if (CI) |
| 1051 | Idx = CI->getZExtValue(); |
| 1052 | |
| 1053 | // Try to match a reduction sequence (series of shufflevector and vector |
| 1054 | // adds followed by a extractelement). |
| 1055 | unsigned ReduxOpCode; |
| 1056 | Type *ReduxType; |
| 1057 | |
| 1058 | switch (matchVectorSplittingReduction(EEI, ReduxOpCode, ReduxType)) { |
| 1059 | case RK_Arithmetic: |
| 1060 | return getArithmeticReductionCost(ReduxOpCode, ReduxType, |
| 1061 | /*IsPairwiseForm=*/false); |
| 1062 | case RK_MinMax: |
| 1063 | return getMinMaxReductionCost( |
| 1064 | ReduxType, CmpInst::makeCmpResultType(ReduxType), |
| 1065 | /*IsPairwiseForm=*/false, /*IsUnsigned=*/false); |
| 1066 | case RK_UnsignedMinMax: |
| 1067 | return getMinMaxReductionCost( |
| 1068 | ReduxType, CmpInst::makeCmpResultType(ReduxType), |
| 1069 | /*IsPairwiseForm=*/false, /*IsUnsigned=*/true); |
| 1070 | case RK_None: |
| 1071 | break; |
| 1072 | } |
| 1073 | |
| 1074 | switch (matchPairwiseReduction(EEI, ReduxOpCode, ReduxType)) { |
| 1075 | case RK_Arithmetic: |
| 1076 | return getArithmeticReductionCost(ReduxOpCode, ReduxType, |
| 1077 | /*IsPairwiseForm=*/true); |
| 1078 | case RK_MinMax: |
| 1079 | return getMinMaxReductionCost( |
| 1080 | ReduxType, CmpInst::makeCmpResultType(ReduxType), |
| 1081 | /*IsPairwiseForm=*/true, /*IsUnsigned=*/false); |
| 1082 | case RK_UnsignedMinMax: |
| 1083 | return getMinMaxReductionCost( |
| 1084 | ReduxType, CmpInst::makeCmpResultType(ReduxType), |
| 1085 | /*IsPairwiseForm=*/true, /*IsUnsigned=*/true); |
| 1086 | case RK_None: |
| 1087 | break; |
| 1088 | } |
| 1089 | |
| 1090 | return getVectorInstrCost(I->getOpcode(), |
| 1091 | EEI->getOperand(0)->getType(), Idx); |
| 1092 | } |
| 1093 | case Instruction::InsertElement: { |
| 1094 | const InsertElementInst * IE = cast<InsertElementInst>(I); |
| 1095 | ConstantInt *CI = dyn_cast<ConstantInt>(IE->getOperand(2)); |
| 1096 | unsigned Idx = -1; |
| 1097 | if (CI) |
| 1098 | Idx = CI->getZExtValue(); |
| 1099 | return getVectorInstrCost(I->getOpcode(), |
| 1100 | IE->getType(), Idx); |
| 1101 | } |
| 1102 | case Instruction::ShuffleVector: { |
| 1103 | const ShuffleVectorInst *Shuffle = cast<ShuffleVectorInst>(I); |
| 1104 | Type *VecTypOp0 = Shuffle->getOperand(0)->getType(); |
| 1105 | unsigned NumVecElems = VecTypOp0->getVectorNumElements(); |
| 1106 | SmallVector<int, 16> Mask = Shuffle->getShuffleMask(); |
| 1107 | |
| 1108 | if (NumVecElems == Mask.size()) { |
| 1109 | if (isReverseVectorMask(Mask)) |
| 1110 | return getShuffleCost(TargetTransformInfo::SK_Reverse, VecTypOp0, |
| 1111 | 0, nullptr); |
| 1112 | if (isAlternateVectorMask(Mask)) |
| 1113 | return getShuffleCost(TargetTransformInfo::SK_Alternate, |
| 1114 | VecTypOp0, 0, nullptr); |
| 1115 | |
| 1116 | if (isZeroEltBroadcastVectorMask(Mask)) |
| 1117 | return getShuffleCost(TargetTransformInfo::SK_Broadcast, |
| 1118 | VecTypOp0, 0, nullptr); |
| 1119 | |
| 1120 | if (isSingleSourceVectorMask(Mask)) |
| 1121 | return getShuffleCost(TargetTransformInfo::SK_PermuteSingleSrc, |
| 1122 | VecTypOp0, 0, nullptr); |
| 1123 | |
| 1124 | return getShuffleCost(TargetTransformInfo::SK_PermuteTwoSrc, |
| 1125 | VecTypOp0, 0, nullptr); |
| 1126 | } |
| 1127 | |
| 1128 | return -1; |
| 1129 | } |
| 1130 | case Instruction::Call: |
| 1131 | if (const IntrinsicInst *II = dyn_cast<IntrinsicInst>(I)) { |
| 1132 | SmallVector<Value *, 4> Args(II->arg_operands()); |
| 1133 | |
| 1134 | FastMathFlags FMF; |
| 1135 | if (auto *FPMO = dyn_cast<FPMathOperator>(II)) |
| 1136 | FMF = FPMO->getFastMathFlags(); |
| 1137 | |
| 1138 | return getIntrinsicInstrCost(II->getIntrinsicID(), II->getType(), |
| 1139 | Args, FMF); |
| 1140 | } |
| 1141 | return -1; |
| 1142 | default: |
| 1143 | // We don't have any information on this instruction. |
| 1144 | return -1; |
| 1145 | } |
| 1146 | } |
| 1147 | |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 1148 | TargetTransformInfo::Concept::~Concept() {} |
| 1149 | |
Chandler Carruth | e038552 | 2015-02-01 10:11:22 +0000 | [diff] [blame] | 1150 | TargetIRAnalysis::TargetIRAnalysis() : TTICallback(&getDefaultTTI) {} |
| 1151 | |
| 1152 | TargetIRAnalysis::TargetIRAnalysis( |
Eric Christopher | a4e5d3c | 2015-09-16 23:38:13 +0000 | [diff] [blame] | 1153 | std::function<Result(const Function &)> TTICallback) |
Benjamin Kramer | 82de7d3 | 2016-05-27 14:27:24 +0000 | [diff] [blame] | 1154 | : TTICallback(std::move(TTICallback)) {} |
Chandler Carruth | e038552 | 2015-02-01 10:11:22 +0000 | [diff] [blame] | 1155 | |
Chandler Carruth | 164a2aa6 | 2016-06-17 00:11:01 +0000 | [diff] [blame] | 1156 | TargetIRAnalysis::Result TargetIRAnalysis::run(const Function &F, |
Sean Silva | 36e0d01 | 2016-08-09 00:28:15 +0000 | [diff] [blame] | 1157 | FunctionAnalysisManager &) { |
Chandler Carruth | e038552 | 2015-02-01 10:11:22 +0000 | [diff] [blame] | 1158 | return TTICallback(F); |
| 1159 | } |
| 1160 | |
Chandler Carruth | dab4eae | 2016-11-23 17:53:26 +0000 | [diff] [blame] | 1161 | AnalysisKey TargetIRAnalysis::Key; |
NAKAMURA Takumi | df0cd72 | 2016-02-28 17:17:00 +0000 | [diff] [blame] | 1162 | |
Eric Christopher | a4e5d3c | 2015-09-16 23:38:13 +0000 | [diff] [blame] | 1163 | TargetIRAnalysis::Result TargetIRAnalysis::getDefaultTTI(const Function &F) { |
Mehdi Amini | 5010ebf | 2015-07-09 02:08:42 +0000 | [diff] [blame] | 1164 | return Result(F.getParent()->getDataLayout()); |
Chandler Carruth | e038552 | 2015-02-01 10:11:22 +0000 | [diff] [blame] | 1165 | } |
| 1166 | |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 1167 | // Register the basic pass. |
| 1168 | INITIALIZE_PASS(TargetTransformInfoWrapperPass, "tti", |
| 1169 | "Target Transform Information", false, true) |
| 1170 | char TargetTransformInfoWrapperPass::ID = 0; |
Chandler Carruth | 539edf4 | 2013-01-05 11:43:11 +0000 | [diff] [blame] | 1171 | |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 1172 | void TargetTransformInfoWrapperPass::anchor() {} |
Chandler Carruth | 539edf4 | 2013-01-05 11:43:11 +0000 | [diff] [blame] | 1173 | |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 1174 | TargetTransformInfoWrapperPass::TargetTransformInfoWrapperPass() |
Chandler Carruth | 5ec2b1d | 2015-02-01 12:26:09 +0000 | [diff] [blame] | 1175 | : ImmutablePass(ID) { |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 1176 | initializeTargetTransformInfoWrapperPassPass( |
| 1177 | *PassRegistry::getPassRegistry()); |
| 1178 | } |
| 1179 | |
| 1180 | TargetTransformInfoWrapperPass::TargetTransformInfoWrapperPass( |
Chandler Carruth | 5ec2b1d | 2015-02-01 12:26:09 +0000 | [diff] [blame] | 1181 | TargetIRAnalysis TIRA) |
| 1182 | : ImmutablePass(ID), TIRA(std::move(TIRA)) { |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 1183 | initializeTargetTransformInfoWrapperPassPass( |
| 1184 | *PassRegistry::getPassRegistry()); |
| 1185 | } |
| 1186 | |
Eric Christopher | a4e5d3c | 2015-09-16 23:38:13 +0000 | [diff] [blame] | 1187 | TargetTransformInfo &TargetTransformInfoWrapperPass::getTTI(const Function &F) { |
Sean Silva | 36e0d01 | 2016-08-09 00:28:15 +0000 | [diff] [blame] | 1188 | FunctionAnalysisManager DummyFAM; |
Chandler Carruth | 164a2aa6 | 2016-06-17 00:11:01 +0000 | [diff] [blame] | 1189 | TTI = TIRA.run(F, DummyFAM); |
Chandler Carruth | 5ec2b1d | 2015-02-01 12:26:09 +0000 | [diff] [blame] | 1190 | return *TTI; |
| 1191 | } |
| 1192 | |
Chandler Carruth | 93dcdc4 | 2015-01-31 11:17:59 +0000 | [diff] [blame] | 1193 | ImmutablePass * |
Chandler Carruth | 5ec2b1d | 2015-02-01 12:26:09 +0000 | [diff] [blame] | 1194 | llvm::createTargetTransformInfoWrapperPass(TargetIRAnalysis TIRA) { |
| 1195 | return new TargetTransformInfoWrapperPass(std::move(TIRA)); |
Chandler Carruth | 539edf4 | 2013-01-05 11:43:11 +0000 | [diff] [blame] | 1196 | } |