02af2d34c518050134b8537f9565058d541b4716
[oota-llvm.git] / lib / Analysis / TargetTransformInfo.cpp
1 //===- llvm/Analysis/TargetTransformInfo.cpp ------------------------------===//
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 #define DEBUG_TYPE "tti"
11 #include "llvm/Analysis/TargetTransformInfo.h"
12 #include "llvm/Support/ErrorHandling.h"
13
14 using namespace llvm;
15
16 // Setup the analysis group to manage the TargetTransformInfo passes.
17 INITIALIZE_ANALYSIS_GROUP(TargetTransformInfo, "Target Information", NoTTI)
18 char TargetTransformInfo::ID = 0;
19
20 TargetTransformInfo::~TargetTransformInfo() {
21 }
22
23 void TargetTransformInfo::pushTTIStack(Pass *P) {
24   TopTTI = this;
25   PrevTTI = &P->getAnalysis<TargetTransformInfo>();
26
27   // Walk up the chain and update the top TTI pointer.
28   for (TargetTransformInfo *PTTI = PrevTTI; PTTI; PTTI = PTTI->PrevTTI)
29     PTTI->TopTTI = this;
30 }
31
32 void TargetTransformInfo::popTTIStack() {
33   TopTTI = 0;
34
35   // Walk up the chain and update the top TTI pointer.
36   for (TargetTransformInfo *PTTI = PrevTTI; PTTI; PTTI = PTTI->PrevTTI)
37     PTTI->TopTTI = PrevTTI;
38
39   PrevTTI = 0;
40 }
41
42 void TargetTransformInfo::getAnalysisUsage(AnalysisUsage &AU) const {
43   AU.addRequired<TargetTransformInfo>();
44 }
45
46 bool TargetTransformInfo::isLegalAddImmediate(int64_t Imm) const {
47   return PrevTTI->isLegalAddImmediate(Imm);
48 }
49
50 bool TargetTransformInfo::isLegalICmpImmediate(int64_t Imm) const {
51   return PrevTTI->isLegalICmpImmediate(Imm);
52 }
53
54 bool TargetTransformInfo::isLegalAddressingMode(Type *Ty, GlobalValue *BaseGV,
55                                                 int64_t BaseOffset,
56                                                 bool HasBaseReg,
57                                                 int64_t Scale) const {
58   return PrevTTI->isLegalAddressingMode(Ty, BaseGV, BaseOffset, HasBaseReg,
59                                         Scale);
60 }
61
62 bool TargetTransformInfo::isTruncateFree(Type *Ty1, Type *Ty2) const {
63   return PrevTTI->isTruncateFree(Ty1, Ty2);
64 }
65
66 bool TargetTransformInfo::isTypeLegal(Type *Ty) const {
67   return PrevTTI->isTypeLegal(Ty);
68 }
69
70 unsigned TargetTransformInfo::getJumpBufAlignment() const {
71   return PrevTTI->getJumpBufAlignment();
72 }
73
74 unsigned TargetTransformInfo::getJumpBufSize() const {
75   return PrevTTI->getJumpBufSize();
76 }
77
78 bool TargetTransformInfo::shouldBuildLookupTables() const {
79   return PrevTTI->shouldBuildLookupTables();
80 }
81
82 TargetTransformInfo::PopcntSupportKind
83 TargetTransformInfo::getPopcntSupport(unsigned IntTyWidthInBit) const {
84   return PrevTTI->getPopcntSupport(IntTyWidthInBit);
85 }
86
87 unsigned TargetTransformInfo::getIntImmCost(const APInt &Imm, Type *Ty) const {
88   return PrevTTI->getIntImmCost(Imm, Ty);
89 }
90
91 unsigned TargetTransformInfo::getNumberOfRegisters(bool Vector) const {
92   return PrevTTI->getNumberOfRegisters(Vector);
93 }
94
95 unsigned TargetTransformInfo::getMaximumUnrollFactor() const {
96   return PrevTTI->getMaximumUnrollFactor();
97 }
98
99 unsigned TargetTransformInfo::getArithmeticInstrCost(unsigned Opcode,
100                                                      Type *Ty) const {
101   return PrevTTI->getArithmeticInstrCost(Opcode, Ty);
102 }
103
104 unsigned TargetTransformInfo::getShuffleCost(ShuffleKind Kind, Type *Tp,
105                                              int Index, Type *SubTp) const {
106   return PrevTTI->getShuffleCost(Kind, Tp, Index, SubTp);
107 }
108
109 unsigned TargetTransformInfo::getCastInstrCost(unsigned Opcode, Type *Dst,
110                                                Type *Src) const {
111   return PrevTTI->getCastInstrCost(Opcode, Dst, Src);
112 }
113
114 unsigned TargetTransformInfo::getCFInstrCost(unsigned Opcode) const {
115   return PrevTTI->getCFInstrCost(Opcode);
116 }
117
118 unsigned TargetTransformInfo::getCmpSelInstrCost(unsigned Opcode, Type *ValTy,
119                                                  Type *CondTy) const {
120   return PrevTTI->getCmpSelInstrCost(Opcode, ValTy, CondTy);
121 }
122
123 unsigned TargetTransformInfo::getVectorInstrCost(unsigned Opcode, Type *Val,
124                                                  unsigned Index) const {
125   return PrevTTI->getVectorInstrCost(Opcode, Val, Index);
126 }
127
128 unsigned TargetTransformInfo::getMemoryOpCost(unsigned Opcode, Type *Src,
129                                               unsigned Alignment,
130                                               unsigned AddressSpace) const {
131   return PrevTTI->getMemoryOpCost(Opcode, Src, Alignment, AddressSpace);
132   ;
133 }
134
135 unsigned
136 TargetTransformInfo::getIntrinsicInstrCost(Intrinsic::ID ID,
137                                            Type *RetTy,
138                                            ArrayRef<Type *> Tys) const {
139   return PrevTTI->getIntrinsicInstrCost(ID, RetTy, Tys);
140 }
141
142 unsigned TargetTransformInfo::getNumberOfParts(Type *Tp) const {
143   return PrevTTI->getNumberOfParts(Tp);
144 }
145
146
147 namespace {
148
149 struct NoTTI : ImmutablePass, TargetTransformInfo {
150   NoTTI() : ImmutablePass(ID) {
151     initializeNoTTIPass(*PassRegistry::getPassRegistry());
152   }
153
154   virtual void initializePass() {
155     // Note that this subclass is special, and must *not* call initializeTTI as
156     // it does not chain.
157     PrevTTI = 0;
158   }
159
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.
163   }
164
165   /// Pass identification.
166   static char ID;
167
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;
172     return this;
173   }
174
175
176   bool isLegalAddImmediate(int64_t Imm) const {
177     return false;
178   }
179
180   bool isLegalICmpImmediate(int64_t Imm) const {
181     return false;
182   }
183
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;
189   }
190
191   bool isTruncateFree(Type *Ty1, Type *Ty2) const {
192     return false;
193   }
194
195   bool isTypeLegal(Type *Ty) const {
196     return false;
197   }
198
199   unsigned getJumpBufAlignment() const {
200     return 0;
201   }
202
203   unsigned getJumpBufSize() const {
204     return 0;
205   }
206
207   bool shouldBuildLookupTables() const {
208     return true;
209   }
210
211   PopcntSupportKind getPopcntSupport(unsigned IntTyWidthInBit) const {
212     return PSK_Software;
213   }
214
215   unsigned getIntImmCost(const APInt &Imm, Type *Ty) const {
216     return 1;
217   }
218
219   unsigned getNumberOfRegisters(bool Vector) const {
220     return 8;
221   }
222
223   unsigned getMaximumUnrollFactor() const {
224     return 1;
225   }
226
227   unsigned getArithmeticInstrCost(unsigned Opcode, Type *Ty) const {
228     return 1;
229   }
230
231   unsigned getShuffleCost(ShuffleKind Kind, Type *Tp,
232                           int Index = 0, Type *SubTp = 0) const {
233     return 1;
234   }
235
236   unsigned getCastInstrCost(unsigned Opcode, Type *Dst,
237                             Type *Src) const {
238     return 1;
239   }
240
241   unsigned getCFInstrCost(unsigned Opcode) const {
242     return 1;
243   }
244
245   unsigned getCmpSelInstrCost(unsigned Opcode, Type *ValTy,
246                               Type *CondTy = 0) const {
247     return 1;
248   }
249
250   unsigned getVectorInstrCost(unsigned Opcode, Type *Val,
251                               unsigned Index = -1) const {
252     return 1;
253   }
254
255   unsigned getMemoryOpCost(unsigned Opcode, Type *Src,
256                            unsigned Alignment,
257                            unsigned AddressSpace) const {
258     return 1;
259   }
260
261   unsigned getIntrinsicInstrCost(Intrinsic::ID ID,
262                                  Type *RetTy,
263                                  ArrayRef<Type*> Tys) const {
264     return 1;
265   }
266
267   unsigned getNumberOfParts(Type *Tp) const {
268     return 0;
269   }
270 };
271
272 } // end anonymous namespace
273
274 INITIALIZE_AG_PASS(NoTTI, TargetTransformInfo, "notti",
275                    "No target information", true, true, true)
276 char NoTTI::ID = 0;
277
278 ImmutablePass *llvm::createNoTargetTransformInfoPass() {
279   return new NoTTI();
280 }