1 //===- llvm/Analysis/TargetTransformInfo.cpp ------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #define DEBUG_TYPE "tti"
11 #include "llvm/Analysis/TargetTransformInfo.h"
12 #include "llvm/Support/ErrorHandling.h"
16 // Setup the analysis group to manage the TargetTransformInfo passes.
17 INITIALIZE_ANALYSIS_GROUP(TargetTransformInfo, "Target Information", NoTTI)
18 char TargetTransformInfo::ID = 0;
20 TargetTransformInfo::~TargetTransformInfo() {
23 void TargetTransformInfo::pushTTIStack(Pass *P) {
25 PrevTTI = &P->getAnalysis<TargetTransformInfo>();
27 // Walk up the chain and update the top TTI pointer.
28 for (TargetTransformInfo *PTTI = PrevTTI; PTTI; PTTI = PTTI->PrevTTI)
32 void TargetTransformInfo::popTTIStack() {
35 // Walk up the chain and update the top TTI pointer.
36 for (TargetTransformInfo *PTTI = PrevTTI; PTTI; PTTI = PTTI->PrevTTI)
37 PTTI->TopTTI = PrevTTI;
42 void TargetTransformInfo::getAnalysisUsage(AnalysisUsage &AU) const {
43 AU.addRequired<TargetTransformInfo>();
46 bool TargetTransformInfo::isLegalAddImmediate(int64_t Imm) const {
47 return PrevTTI->isLegalAddImmediate(Imm);
50 bool TargetTransformInfo::isLegalICmpImmediate(int64_t Imm) const {
51 return PrevTTI->isLegalICmpImmediate(Imm);
54 bool TargetTransformInfo::isLegalAddressingMode(Type *Ty, GlobalValue *BaseGV,
57 int64_t Scale) const {
58 return PrevTTI->isLegalAddressingMode(Ty, BaseGV, BaseOffset, HasBaseReg,
62 bool TargetTransformInfo::isTruncateFree(Type *Ty1, Type *Ty2) const {
63 return PrevTTI->isTruncateFree(Ty1, Ty2);
66 bool TargetTransformInfo::isTypeLegal(Type *Ty) const {
67 return PrevTTI->isTypeLegal(Ty);
70 unsigned TargetTransformInfo::getJumpBufAlignment() const {
71 return PrevTTI->getJumpBufAlignment();
74 unsigned TargetTransformInfo::getJumpBufSize() const {
75 return PrevTTI->getJumpBufSize();
78 bool TargetTransformInfo::shouldBuildLookupTables() const {
79 return PrevTTI->shouldBuildLookupTables();
82 TargetTransformInfo::PopcntSupportKind
83 TargetTransformInfo::getPopcntSupport(unsigned IntTyWidthInBit) const {
84 return PrevTTI->getPopcntSupport(IntTyWidthInBit);
87 unsigned TargetTransformInfo::getIntImmCost(const APInt &Imm, Type *Ty) const {
88 return PrevTTI->getIntImmCost(Imm, Ty);
91 unsigned TargetTransformInfo::getNumberOfRegisters(bool Vector) const {
92 return PrevTTI->getNumberOfRegisters(Vector);
95 unsigned TargetTransformInfo::getMaximumUnrollFactor() const {
96 return PrevTTI->getMaximumUnrollFactor();
99 unsigned TargetTransformInfo::getArithmeticInstrCost(unsigned Opcode,
101 return PrevTTI->getArithmeticInstrCost(Opcode, Ty);
104 unsigned TargetTransformInfo::getShuffleCost(ShuffleKind Kind, Type *Tp,
105 int Index, Type *SubTp) const {
106 return PrevTTI->getShuffleCost(Kind, Tp, Index, SubTp);
109 unsigned TargetTransformInfo::getCastInstrCost(unsigned Opcode, Type *Dst,
111 return PrevTTI->getCastInstrCost(Opcode, Dst, Src);
114 unsigned TargetTransformInfo::getCFInstrCost(unsigned Opcode) const {
115 return PrevTTI->getCFInstrCost(Opcode);
118 unsigned TargetTransformInfo::getCmpSelInstrCost(unsigned Opcode, Type *ValTy,
119 Type *CondTy) const {
120 return PrevTTI->getCmpSelInstrCost(Opcode, ValTy, CondTy);
123 unsigned TargetTransformInfo::getVectorInstrCost(unsigned Opcode, Type *Val,
124 unsigned Index) const {
125 return PrevTTI->getVectorInstrCost(Opcode, Val, Index);
128 unsigned TargetTransformInfo::getMemoryOpCost(unsigned Opcode, Type *Src,
130 unsigned AddressSpace) const {
131 return PrevTTI->getMemoryOpCost(Opcode, Src, Alignment, AddressSpace);
136 TargetTransformInfo::getIntrinsicInstrCost(Intrinsic::ID ID,
138 ArrayRef<Type *> Tys) const {
139 return PrevTTI->getIntrinsicInstrCost(ID, RetTy, Tys);
142 unsigned TargetTransformInfo::getNumberOfParts(Type *Tp) const {
143 return PrevTTI->getNumberOfParts(Tp);
149 struct NoTTI : ImmutablePass, TargetTransformInfo {
150 NoTTI() : ImmutablePass(ID) {
151 initializeNoTTIPass(*PassRegistry::getPassRegistry());
154 virtual void initializePass() {
155 // Note that this subclass is special, and must *not* call initializeTTI as
156 // it does not chain.
160 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
161 // Note that this subclass is special, and must *not* call
162 // TTI::getAnalysisUsage as it breaks the recursion.
165 /// Pass identification.
168 /// Provide necessary pointer adjustments for the two base classes.
169 virtual void *getAdjustedAnalysisPointer(const void *ID) {
170 if (ID == &TargetTransformInfo::ID)
171 return (TargetTransformInfo*)this;
176 bool isLegalAddImmediate(int64_t Imm) const {
180 bool isLegalICmpImmediate(int64_t Imm) const {
184 bool isLegalAddressingMode(Type *Ty, GlobalValue *BaseGV, int64_t BaseOffset,
185 bool HasBaseReg, int64_t Scale) const {
186 // Guess that reg+reg addressing is allowed. This heuristic is taken from
187 // the implementation of LSR.
188 return !BaseGV && BaseOffset == 0 && Scale <= 1;
191 bool isTruncateFree(Type *Ty1, Type *Ty2) const {
195 bool isTypeLegal(Type *Ty) const {
199 unsigned getJumpBufAlignment() const {
203 unsigned getJumpBufSize() const {
207 bool shouldBuildLookupTables() const {
211 PopcntSupportKind getPopcntSupport(unsigned IntTyWidthInBit) const {
215 unsigned getIntImmCost(const APInt &Imm, Type *Ty) const {
219 unsigned getNumberOfRegisters(bool Vector) const {
223 unsigned getMaximumUnrollFactor() const {
227 unsigned getArithmeticInstrCost(unsigned Opcode, Type *Ty) const {
231 unsigned getShuffleCost(ShuffleKind Kind, Type *Tp,
232 int Index = 0, Type *SubTp = 0) const {
236 unsigned getCastInstrCost(unsigned Opcode, Type *Dst,
241 unsigned getCFInstrCost(unsigned Opcode) const {
245 unsigned getCmpSelInstrCost(unsigned Opcode, Type *ValTy,
246 Type *CondTy = 0) const {
250 unsigned getVectorInstrCost(unsigned Opcode, Type *Val,
251 unsigned Index = -1) const {
255 unsigned getMemoryOpCost(unsigned Opcode, Type *Src,
257 unsigned AddressSpace) const {
261 unsigned getIntrinsicInstrCost(Intrinsic::ID ID,
263 ArrayRef<Type*> Tys) const {
267 unsigned getNumberOfParts(Type *Tp) const {
272 } // end anonymous namespace
274 INITIALIZE_AG_PASS(NoTTI, TargetTransformInfo, "notti",
275 "No target information", true, true, true)
278 ImmutablePass *llvm::createNoTargetTransformInfoPass() {