Move TargetTransformInfo to live under the Analysis library. This no
[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::PopcntHwSupport
83 TargetTransformInfo::getPopcntHwSupport(unsigned IntTyWidthInBit) const {
84   return PrevTTI->getPopcntHwSupport(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::getArithmeticInstrCost(unsigned Opcode,
96                                                      Type *Ty) const {
97   return PrevTTI->getArithmeticInstrCost(Opcode, Ty);
98 }
99
100 unsigned TargetTransformInfo::getShuffleCost(ShuffleKind Kind, Type *Tp,
101                                              int Index, Type *SubTp) const {
102   return PrevTTI->getShuffleCost(Kind, Tp, Index, SubTp);
103 }
104
105 unsigned TargetTransformInfo::getCastInstrCost(unsigned Opcode, Type *Dst,
106                                                Type *Src) const {
107   return PrevTTI->getCastInstrCost(Opcode, Dst, Src);
108 }
109
110 unsigned TargetTransformInfo::getCFInstrCost(unsigned Opcode) const {
111   return PrevTTI->getCFInstrCost(Opcode);
112 }
113
114 unsigned TargetTransformInfo::getCmpSelInstrCost(unsigned Opcode, Type *ValTy,
115                                                  Type *CondTy) const {
116   return PrevTTI->getCmpSelInstrCost(Opcode, ValTy, CondTy);
117 }
118
119 unsigned TargetTransformInfo::getVectorInstrCost(unsigned Opcode, Type *Val,
120                                                  unsigned Index) const {
121   return PrevTTI->getVectorInstrCost(Opcode, Val, Index);
122 }
123
124 unsigned TargetTransformInfo::getMemoryOpCost(unsigned Opcode, Type *Src,
125                                               unsigned Alignment,
126                                               unsigned AddressSpace) const {
127   return PrevTTI->getMemoryOpCost(Opcode, Src, Alignment, AddressSpace);
128   ;
129 }
130
131 unsigned
132 TargetTransformInfo::getIntrinsicInstrCost(Intrinsic::ID ID,
133                                            Type *RetTy,
134                                            ArrayRef<Type *> Tys) const {
135   return PrevTTI->getIntrinsicInstrCost(ID, RetTy, Tys);
136 }
137
138 unsigned TargetTransformInfo::getNumberOfParts(Type *Tp) const {
139   return PrevTTI->getNumberOfParts(Tp);
140 }
141
142
143 namespace {
144
145 struct NoTTI : ImmutablePass, TargetTransformInfo {
146   NoTTI() : ImmutablePass(ID) {
147     initializeNoTTIPass(*PassRegistry::getPassRegistry());
148   }
149
150   virtual void initializePass() {
151     // Note that this subclass is special, and must *not* call initializeTTI as
152     // it does not chain.
153     PrevTTI = 0;
154   }
155
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.
159   }
160
161   /// Pass identification.
162   static char ID;
163
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;
168     return this;
169   }
170
171
172   bool isLegalAddImmediate(int64_t Imm) const {
173     return false;
174   }
175
176   bool isLegalICmpImmediate(int64_t Imm) const {
177     return false;
178   }
179
180   bool isLegalAddressingMode(Type *Ty, GlobalValue *BaseGV, int64_t BaseOffset,
181                              bool HasBaseReg, int64_t Scale) const {
182     return false;
183   }
184
185   bool isTruncateFree(Type *Ty1, Type *Ty2) const {
186     return false;
187   }
188
189   bool isTypeLegal(Type *Ty) const {
190     return false;
191   }
192
193   unsigned getJumpBufAlignment() const {
194     return 0;
195   }
196
197   unsigned getJumpBufSize() const {
198     return 0;
199   }
200
201   bool shouldBuildLookupTables() const {
202     return true;
203   }
204
205   PopcntHwSupport getPopcntHwSupport(unsigned IntTyWidthInBit) const {
206     return None;
207   }
208
209   unsigned getIntImmCost(const APInt &Imm, Type *Ty) const {
210     return 1;
211   }
212
213   unsigned getNumberOfRegisters(bool Vector) const {
214     return 8;
215   }
216
217   unsigned getArithmeticInstrCost(unsigned Opcode, Type *Ty) const {
218     return 1;
219   }
220
221   unsigned getShuffleCost(ShuffleKind Kind, Type *Tp,
222                           int Index = 0, Type *SubTp = 0) const {
223     return 1;
224   }
225
226   unsigned getCastInstrCost(unsigned Opcode, Type *Dst,
227                             Type *Src) const {
228     return 1;
229   }
230
231   unsigned getCFInstrCost(unsigned Opcode) const {
232     return 1;
233   }
234
235   unsigned getCmpSelInstrCost(unsigned Opcode, Type *ValTy,
236                               Type *CondTy = 0) const {
237     return 1;
238   }
239
240   unsigned getVectorInstrCost(unsigned Opcode, Type *Val,
241                               unsigned Index = -1) const {
242     return 1;
243   }
244
245   unsigned getMemoryOpCost(unsigned Opcode, Type *Src,
246                            unsigned Alignment,
247                            unsigned AddressSpace) const {
248     return 1;
249   }
250
251   unsigned getIntrinsicInstrCost(Intrinsic::ID ID,
252                                  Type *RetTy,
253                                  ArrayRef<Type*> Tys) const {
254     return 1;
255   }
256
257   unsigned getNumberOfParts(Type *Tp) const {
258     return 0;
259   }
260 };
261
262 } // end anonymous namespace
263
264 INITIALIZE_AG_PASS(NoTTI, TargetTransformInfo, "notti",
265                    "No target information", true, true, true)
266 char NoTTI::ID = 0;
267
268 ImmutablePass *llvm::createNoTargetTransformInfoPass() {
269   return new NoTTI();
270 }