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::PopcntHwSupport
83 TargetTransformInfo::getPopcntHwSupport(unsigned IntTyWidthInBit) const {
84 return PrevTTI->getPopcntHwSupport(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::getArithmeticInstrCost(unsigned Opcode,
97 return PrevTTI->getArithmeticInstrCost(Opcode, Ty);
100 unsigned TargetTransformInfo::getShuffleCost(ShuffleKind Kind, Type *Tp,
101 int Index, Type *SubTp) const {
102 return PrevTTI->getShuffleCost(Kind, Tp, Index, SubTp);
105 unsigned TargetTransformInfo::getCastInstrCost(unsigned Opcode, Type *Dst,
107 return PrevTTI->getCastInstrCost(Opcode, Dst, Src);
110 unsigned TargetTransformInfo::getCFInstrCost(unsigned Opcode) const {
111 return PrevTTI->getCFInstrCost(Opcode);
114 unsigned TargetTransformInfo::getCmpSelInstrCost(unsigned Opcode, Type *ValTy,
115 Type *CondTy) const {
116 return PrevTTI->getCmpSelInstrCost(Opcode, ValTy, CondTy);
119 unsigned TargetTransformInfo::getVectorInstrCost(unsigned Opcode, Type *Val,
120 unsigned Index) const {
121 return PrevTTI->getVectorInstrCost(Opcode, Val, Index);
124 unsigned TargetTransformInfo::getMemoryOpCost(unsigned Opcode, Type *Src,
126 unsigned AddressSpace) const {
127 return PrevTTI->getMemoryOpCost(Opcode, Src, Alignment, AddressSpace);
132 TargetTransformInfo::getIntrinsicInstrCost(Intrinsic::ID ID,
134 ArrayRef<Type *> Tys) const {
135 return PrevTTI->getIntrinsicInstrCost(ID, RetTy, Tys);
138 unsigned TargetTransformInfo::getNumberOfParts(Type *Tp) const {
139 return PrevTTI->getNumberOfParts(Tp);
145 struct NoTTI : ImmutablePass, TargetTransformInfo {
146 NoTTI() : ImmutablePass(ID) {
147 initializeNoTTIPass(*PassRegistry::getPassRegistry());
150 virtual void initializePass() {
151 // Note that this subclass is special, and must *not* call initializeTTI as
152 // it does not chain.
156 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
157 // Note that this subclass is special, and must *not* call
158 // TTI::getAnalysisUsage as it breaks the recursion.
161 /// Pass identification.
164 /// Provide necessary pointer adjustments for the two base classes.
165 virtual void *getAdjustedAnalysisPointer(const void *ID) {
166 if (ID == &TargetTransformInfo::ID)
167 return (TargetTransformInfo*)this;
172 bool isLegalAddImmediate(int64_t Imm) const {
176 bool isLegalICmpImmediate(int64_t Imm) const {
180 bool isLegalAddressingMode(Type *Ty, GlobalValue *BaseGV, int64_t BaseOffset,
181 bool HasBaseReg, int64_t Scale) const {
185 bool isTruncateFree(Type *Ty1, Type *Ty2) const {
189 bool isTypeLegal(Type *Ty) const {
193 unsigned getJumpBufAlignment() const {
197 unsigned getJumpBufSize() const {
201 bool shouldBuildLookupTables() const {
205 PopcntHwSupport getPopcntHwSupport(unsigned IntTyWidthInBit) const {
209 unsigned getIntImmCost(const APInt &Imm, Type *Ty) const {
213 unsigned getNumberOfRegisters(bool Vector) const {
217 unsigned getArithmeticInstrCost(unsigned Opcode, Type *Ty) const {
221 unsigned getShuffleCost(ShuffleKind Kind, Type *Tp,
222 int Index = 0, Type *SubTp = 0) const {
226 unsigned getCastInstrCost(unsigned Opcode, Type *Dst,
231 unsigned getCFInstrCost(unsigned Opcode) const {
235 unsigned getCmpSelInstrCost(unsigned Opcode, Type *ValTy,
236 Type *CondTy = 0) const {
240 unsigned getVectorInstrCost(unsigned Opcode, Type *Val,
241 unsigned Index = -1) const {
245 unsigned getMemoryOpCost(unsigned Opcode, Type *Src,
247 unsigned AddressSpace) const {
251 unsigned getIntrinsicInstrCost(Intrinsic::ID ID,
253 ArrayRef<Type*> Tys) const {
257 unsigned getNumberOfParts(Type *Tp) const {
262 } // end anonymous namespace
264 INITIALIZE_AG_PASS(NoTTI, TargetTransformInfo, "notti",
265 "No target information", true, true, true)
268 ImmutablePass *llvm::createNoTargetTransformInfoPass() {