Chandler Carruth | c2c50cd | 2013-01-02 09:10:48 +0000 | [diff] [blame] | 1 | //===- llvm/IR/TargetTransformInfo.cpp --------------------------*- C++ -*-===// |
Nadav Rotem | cbd9a19 | 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 | |
| 10 | #include "llvm/TargetTransformInfo.h" |
| 11 | #include "llvm/Support/ErrorHandling.h" |
| 12 | |
| 13 | using namespace llvm; |
| 14 | |
Chandler Carruth | 7bdf6b0 | 2013-01-05 11:43:11 +0000 | [diff] [blame] | 15 | // Setup the analysis group to manage the TargetTransformInfo passes. |
| 16 | INITIALIZE_ANALYSIS_GROUP(TargetTransformInfo, "Target Information", NoTTI) |
Nadav Rotem | cbd9a19 | 2012-10-18 23:22:48 +0000 | [diff] [blame] | 17 | char TargetTransformInfo::ID = 0; |
| 18 | |
Chandler Carruth | 7bdf6b0 | 2013-01-05 11:43:11 +0000 | [diff] [blame] | 19 | TargetTransformInfo::~TargetTransformInfo() { |
| 20 | } |
| 21 | |
| 22 | void TargetTransformInfo::getAnalysisUsage(AnalysisUsage &AU) const { |
| 23 | AU.addRequired<TargetTransformInfo>(); |
| 24 | } |
| 25 | |
| 26 | bool TargetTransformInfo::isLegalAddImmediate(int64_t Imm) const { |
| 27 | return PrevTTI->isLegalAddImmediate(Imm); |
| 28 | } |
| 29 | |
| 30 | bool TargetTransformInfo::isLegalICmpImmediate(int64_t Imm) const { |
| 31 | return PrevTTI->isLegalICmpImmediate(Imm); |
| 32 | } |
| 33 | |
| 34 | bool TargetTransformInfo::isLegalAddressingMode(Type *Ty, GlobalValue *BaseGV, |
| 35 | int64_t BaseOffset, |
| 36 | bool HasBaseReg, |
| 37 | int64_t Scale) const { |
| 38 | return PrevTTI->isLegalAddressingMode(Ty, BaseGV, BaseOffset, HasBaseReg, |
| 39 | Scale); |
| 40 | } |
| 41 | |
| 42 | bool TargetTransformInfo::isTruncateFree(Type *Ty1, Type *Ty2) const { |
| 43 | return PrevTTI->isTruncateFree(Ty1, Ty2); |
| 44 | } |
| 45 | |
| 46 | bool TargetTransformInfo::isTypeLegal(Type *Ty) const { |
| 47 | return PrevTTI->isTypeLegal(Ty); |
| 48 | } |
| 49 | |
| 50 | unsigned TargetTransformInfo::getJumpBufAlignment() const { |
| 51 | return PrevTTI->getJumpBufAlignment(); |
| 52 | } |
| 53 | |
| 54 | unsigned TargetTransformInfo::getJumpBufSize() const { |
| 55 | return PrevTTI->getJumpBufSize(); |
| 56 | } |
| 57 | |
| 58 | bool TargetTransformInfo::shouldBuildLookupTables() const { |
| 59 | return PrevTTI->shouldBuildLookupTables(); |
| 60 | } |
| 61 | |
| 62 | TargetTransformInfo::PopcntHwSupport |
| 63 | TargetTransformInfo::getPopcntHwSupport(unsigned IntTyWidthInBit) const { |
| 64 | return PrevTTI->getPopcntHwSupport(IntTyWidthInBit); |
| 65 | } |
| 66 | |
| 67 | unsigned TargetTransformInfo::getIntImmCost(const APInt &Imm, Type *Ty) const { |
| 68 | return PrevTTI->getIntImmCost(Imm, Ty); |
| 69 | } |
| 70 | |
| 71 | unsigned TargetTransformInfo::getNumberOfRegisters(bool Vector) const { |
| 72 | return PrevTTI->getNumberOfRegisters(Vector); |
| 73 | } |
| 74 | |
| 75 | unsigned TargetTransformInfo::getArithmeticInstrCost(unsigned Opcode, |
| 76 | Type *Ty) const { |
| 77 | return PrevTTI->getArithmeticInstrCost(Opcode, Ty); |
| 78 | } |
| 79 | |
| 80 | unsigned TargetTransformInfo::getShuffleCost(ShuffleKind Kind, Type *Tp, |
| 81 | int Index, Type *SubTp) const { |
| 82 | return PrevTTI->getShuffleCost(Kind, Tp, Index, SubTp); |
| 83 | } |
| 84 | |
| 85 | unsigned TargetTransformInfo::getCastInstrCost(unsigned Opcode, Type *Dst, |
| 86 | Type *Src) const { |
| 87 | return PrevTTI->getCastInstrCost(Opcode, Dst, Src); |
| 88 | } |
| 89 | |
| 90 | unsigned TargetTransformInfo::getCFInstrCost(unsigned Opcode) const { |
| 91 | return PrevTTI->getCFInstrCost(Opcode); |
| 92 | } |
| 93 | |
| 94 | unsigned TargetTransformInfo::getCmpSelInstrCost(unsigned Opcode, Type *ValTy, |
| 95 | Type *CondTy) const { |
| 96 | return PrevTTI->getCmpSelInstrCost(Opcode, ValTy, CondTy); |
| 97 | } |
| 98 | |
| 99 | unsigned TargetTransformInfo::getVectorInstrCost(unsigned Opcode, Type *Val, |
| 100 | unsigned Index) const { |
| 101 | return PrevTTI->getVectorInstrCost(Opcode, Val, Index); |
| 102 | } |
| 103 | |
| 104 | unsigned TargetTransformInfo::getMemoryOpCost(unsigned Opcode, Type *Src, |
| 105 | unsigned Alignment, |
| 106 | unsigned AddressSpace) const { |
| 107 | return PrevTTI->getMemoryOpCost(Opcode, Src, Alignment, AddressSpace); |
| 108 | ; |
| 109 | } |
| 110 | |
| 111 | unsigned |
| 112 | TargetTransformInfo::getIntrinsicInstrCost(Intrinsic::ID ID, |
| 113 | Type *RetTy, |
| 114 | ArrayRef<Type *> Tys) const { |
| 115 | return PrevTTI->getIntrinsicInstrCost(ID, RetTy, Tys); |
| 116 | } |
| 117 | |
| 118 | unsigned TargetTransformInfo::getNumberOfParts(Type *Tp) const { |
| 119 | return PrevTTI->getNumberOfParts(Tp); |
| 120 | } |
| 121 | |
| 122 | |
| 123 | namespace { |
| 124 | |
| 125 | class NoTTI : public ImmutablePass, public TargetTransformInfo { |
| 126 | const ScalarTargetTransformInfo *STTI; |
| 127 | const VectorTargetTransformInfo *VTTI; |
| 128 | |
| 129 | public: |
| 130 | // FIXME: This constructor doesn't work which breaks the use of NoTTI on the |
| 131 | // commandline. This has to be fixed for NoTTI to be fully usable as an |
| 132 | // analysis pass. |
| 133 | NoTTI() : ImmutablePass(ID), TargetTransformInfo(0) { |
| 134 | llvm_unreachable("Unsupported code path!"); |
| 135 | } |
| 136 | |
| 137 | NoTTI(const ScalarTargetTransformInfo *S, const VectorTargetTransformInfo *V) |
| 138 | : ImmutablePass(ID), |
| 139 | TargetTransformInfo(0), // NoTTI is special and doesn't delegate here. |
| 140 | STTI(S), VTTI(V) { |
| 141 | initializeNoTTIPass(*PassRegistry::getPassRegistry()); |
| 142 | } |
| 143 | |
| 144 | void getAnalysisUsage(AnalysisUsage &AU) const { |
| 145 | // Note that this subclass is special, and must *not* call |
| 146 | // TTI::getAnalysisUsage as it breaks the recursion. |
| 147 | } |
| 148 | |
| 149 | /// Pass identification. |
| 150 | static char ID; |
| 151 | |
| 152 | /// Provide necessary pointer adjustments for the two base classes. |
| 153 | virtual void *getAdjustedAnalysisPointer(const void *ID) { |
| 154 | if (ID == &TargetTransformInfo::ID) |
| 155 | return (TargetTransformInfo*)this; |
| 156 | return this; |
| 157 | } |
| 158 | |
| 159 | |
| 160 | // Delegate all predicates through the STTI or VTTI interface. |
| 161 | |
| 162 | bool isLegalAddImmediate(int64_t Imm) const { |
| 163 | return STTI->isLegalAddImmediate(Imm); |
| 164 | } |
| 165 | |
| 166 | bool isLegalICmpImmediate(int64_t Imm) const { |
| 167 | return STTI->isLegalICmpImmediate(Imm); |
| 168 | } |
| 169 | |
| 170 | bool isLegalAddressingMode(Type *Ty, GlobalValue *BaseGV, int64_t BaseOffset, |
| 171 | bool HasBaseReg, int64_t Scale) const { |
| 172 | return STTI->isLegalAddressingMode(Ty, BaseGV, BaseOffset, HasBaseReg, |
| 173 | Scale); |
| 174 | } |
| 175 | |
| 176 | bool isTruncateFree(Type *Ty1, Type *Ty2) const { |
| 177 | return STTI->isTruncateFree(Ty1, Ty2); |
| 178 | } |
| 179 | |
| 180 | bool isTypeLegal(Type *Ty) const { |
| 181 | return STTI->isTypeLegal(Ty); |
| 182 | } |
| 183 | |
| 184 | unsigned getJumpBufAlignment() const { |
| 185 | return STTI->getJumpBufAlignment(); |
| 186 | } |
| 187 | |
| 188 | unsigned getJumpBufSize() const { |
| 189 | return STTI->getJumpBufSize(); |
| 190 | } |
| 191 | |
| 192 | bool shouldBuildLookupTables() const { |
| 193 | return STTI->shouldBuildLookupTables(); |
| 194 | } |
| 195 | |
| 196 | PopcntHwSupport getPopcntHwSupport(unsigned IntTyWidthInBit) const { |
| 197 | return (PopcntHwSupport)STTI->getPopcntHwSupport(IntTyWidthInBit); |
| 198 | } |
| 199 | |
| 200 | unsigned getIntImmCost(const APInt &Imm, Type *Ty) const { |
| 201 | return STTI->getIntImmCost(Imm, Ty); |
| 202 | } |
| 203 | |
| 204 | unsigned getNumberOfRegisters(bool Vector) const { |
| 205 | return VTTI->getNumberOfRegisters(Vector); |
| 206 | } |
| 207 | |
| 208 | unsigned getArithmeticInstrCost(unsigned Opcode, Type *Ty) const { |
| 209 | return VTTI->getArithmeticInstrCost(Opcode, Ty); |
| 210 | } |
| 211 | |
| 212 | unsigned getShuffleCost(ShuffleKind Kind, Type *Tp, |
| 213 | int Index = 0, Type *SubTp = 0) const { |
| 214 | return VTTI->getShuffleCost((VectorTargetTransformInfo::ShuffleKind)Kind, |
| 215 | Tp, Index, SubTp); |
| 216 | } |
| 217 | |
| 218 | unsigned getCastInstrCost(unsigned Opcode, Type *Dst, |
| 219 | Type *Src) const { |
| 220 | return VTTI->getCastInstrCost(Opcode, Dst, Src); |
| 221 | } |
| 222 | |
| 223 | unsigned getCFInstrCost(unsigned Opcode) const { |
| 224 | return VTTI->getCFInstrCost(Opcode); |
| 225 | } |
| 226 | |
| 227 | unsigned getCmpSelInstrCost(unsigned Opcode, Type *ValTy, |
| 228 | Type *CondTy = 0) const { |
| 229 | return VTTI->getCmpSelInstrCost(Opcode, ValTy, CondTy); |
| 230 | } |
| 231 | |
| 232 | unsigned getVectorInstrCost(unsigned Opcode, Type *Val, |
| 233 | unsigned Index = -1) const { |
| 234 | return VTTI->getVectorInstrCost(Opcode, Val, Index); |
| 235 | } |
| 236 | |
| 237 | unsigned getMemoryOpCost(unsigned Opcode, Type *Src, |
| 238 | unsigned Alignment, |
| 239 | unsigned AddressSpace) const { |
| 240 | return VTTI->getMemoryOpCost(Opcode, Src, Alignment, AddressSpace); |
| 241 | } |
| 242 | |
| 243 | unsigned getIntrinsicInstrCost(Intrinsic::ID ID, |
| 244 | Type *RetTy, |
| 245 | ArrayRef<Type*> Tys) const { |
| 246 | return VTTI->getIntrinsicInstrCost(ID, RetTy, Tys); |
| 247 | } |
| 248 | |
| 249 | unsigned getNumberOfParts(Type *Tp) const { |
| 250 | return VTTI->getNumberOfParts(Tp); |
| 251 | } |
| 252 | }; |
| 253 | |
| 254 | } // end anonymous namespace |
| 255 | |
| 256 | INITIALIZE_AG_PASS(NoTTI, TargetTransformInfo, "no-tti", |
| 257 | "No target information", true, true, true) |
| 258 | char NoTTI::ID = 0; |
| 259 | |
| 260 | ImmutablePass *llvm::createNoTTIPass(const ScalarTargetTransformInfo *S, |
| 261 | const VectorTargetTransformInfo *V) { |
| 262 | return new NoTTI(S, V); |
| 263 | } |