aboutsummaryrefslogtreecommitdiffstats
path: root/lib/IR/TargetTransformInfo.cpp
blob: 8d5fb0d40bdb20947d5acc01d38fb18ae7039e53 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
//===- llvm/IR/TargetTransformInfo.cpp --------------------------*- C++ -*-===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#include "llvm/TargetTransformInfo.h"
#include "llvm/Support/ErrorHandling.h"

using namespace llvm;

// Setup the analysis group to manage the TargetTransformInfo passes.
INITIALIZE_ANALYSIS_GROUP(TargetTransformInfo, "Target Information", NoTTI)
char TargetTransformInfo::ID = 0;

TargetTransformInfo::~TargetTransformInfo() {
}

void TargetTransformInfo::getAnalysisUsage(AnalysisUsage &AU) const {
  AU.addRequired<TargetTransformInfo>();
}

bool TargetTransformInfo::isLegalAddImmediate(int64_t Imm) const {
  return PrevTTI->isLegalAddImmediate(Imm);
}

bool TargetTransformInfo::isLegalICmpImmediate(int64_t Imm) const {
  return PrevTTI->isLegalICmpImmediate(Imm);
}

bool TargetTransformInfo::isLegalAddressingMode(Type *Ty, GlobalValue *BaseGV,
                                                int64_t BaseOffset,
                                                bool HasBaseReg,
                                                int64_t Scale) const {
  return PrevTTI->isLegalAddressingMode(Ty, BaseGV, BaseOffset, HasBaseReg,
                                        Scale);
}

bool TargetTransformInfo::isTruncateFree(Type *Ty1, Type *Ty2) const {
  return PrevTTI->isTruncateFree(Ty1, Ty2);
}

bool TargetTransformInfo::isTypeLegal(Type *Ty) const {
  return PrevTTI->isTypeLegal(Ty);
}

unsigned TargetTransformInfo::getJumpBufAlignment() const {
  return PrevTTI->getJumpBufAlignment();
}

unsigned TargetTransformInfo::getJumpBufSize() const {
  return PrevTTI->getJumpBufSize();
}

bool TargetTransformInfo::shouldBuildLookupTables() const {
  return PrevTTI->shouldBuildLookupTables();
}

TargetTransformInfo::PopcntHwSupport
TargetTransformInfo::getPopcntHwSupport(unsigned IntTyWidthInBit) const {
  return PrevTTI->getPopcntHwSupport(IntTyWidthInBit);
}

unsigned TargetTransformInfo::getIntImmCost(const APInt &Imm, Type *Ty) const {
  return PrevTTI->getIntImmCost(Imm, Ty);
}

unsigned TargetTransformInfo::getNumberOfRegisters(bool Vector) const {
  return PrevTTI->getNumberOfRegisters(Vector);
}

unsigned TargetTransformInfo::getArithmeticInstrCost(unsigned Opcode,
                                                     Type *Ty) const {
  return PrevTTI->getArithmeticInstrCost(Opcode, Ty);
}

unsigned TargetTransformInfo::getShuffleCost(ShuffleKind Kind, Type *Tp,
                                             int Index, Type *SubTp) const {
  return PrevTTI->getShuffleCost(Kind, Tp, Index, SubTp);
}

unsigned TargetTransformInfo::getCastInstrCost(unsigned Opcode, Type *Dst,
                                               Type *Src) const {
  return PrevTTI->getCastInstrCost(Opcode, Dst, Src);
}

unsigned TargetTransformInfo::getCFInstrCost(unsigned Opcode) const {
  return PrevTTI->getCFInstrCost(Opcode);
}

unsigned TargetTransformInfo::getCmpSelInstrCost(unsigned Opcode, Type *ValTy,
                                                 Type *CondTy) const {
  return PrevTTI->getCmpSelInstrCost(Opcode, ValTy, CondTy);
}

unsigned TargetTransformInfo::getVectorInstrCost(unsigned Opcode, Type *Val,
                                                 unsigned Index) const {
  return PrevTTI->getVectorInstrCost(Opcode, Val, Index);
}

unsigned TargetTransformInfo::getMemoryOpCost(unsigned Opcode, Type *Src,
                                              unsigned Alignment,
                                              unsigned AddressSpace) const {
  return PrevTTI->getMemoryOpCost(Opcode, Src, Alignment, AddressSpace);
  ;
}

unsigned
TargetTransformInfo::getIntrinsicInstrCost(Intrinsic::ID ID,
                                           Type *RetTy,
                                           ArrayRef<Type *> Tys) const {
  return PrevTTI->getIntrinsicInstrCost(ID, RetTy, Tys);
}

unsigned TargetTransformInfo::getNumberOfParts(Type *Tp) const {
  return PrevTTI->getNumberOfParts(Tp);
}


namespace {

class NoTTI : public ImmutablePass, public TargetTransformInfo {
  const ScalarTargetTransformInfo *STTI;
  const VectorTargetTransformInfo *VTTI;

public:
  // FIXME: This constructor doesn't work which breaks the use of NoTTI on the
  // commandline. This has to be fixed for NoTTI to be fully usable as an
  // analysis pass.
  NoTTI() : ImmutablePass(ID), TargetTransformInfo(0) {
    llvm_unreachable("Unsupported code path!");
  }

  NoTTI(const ScalarTargetTransformInfo *S, const VectorTargetTransformInfo *V)
      : ImmutablePass(ID),
        TargetTransformInfo(0), // NoTTI is special and doesn't delegate here.
        STTI(S), VTTI(V) {
    initializeNoTTIPass(*PassRegistry::getPassRegistry());
  }

  void getAnalysisUsage(AnalysisUsage &AU) const {
    // Note that this subclass is special, and must *not* call
    // TTI::getAnalysisUsage as it breaks the recursion.
  }

  /// Pass identification.
  static char ID;

  /// Provide necessary pointer adjustments for the two base classes.
  virtual void *getAdjustedAnalysisPointer(const void *ID) {
    if (ID == &TargetTransformInfo::ID)
      return (TargetTransformInfo*)this;
    return this;
  }


  // Delegate all predicates through the STTI or VTTI interface.

  bool isLegalAddImmediate(int64_t Imm) const {
    return STTI->isLegalAddImmediate(Imm);
  }

  bool isLegalICmpImmediate(int64_t Imm) const {
    return STTI->isLegalICmpImmediate(Imm);
  }

  bool isLegalAddressingMode(Type *Ty, GlobalValue *BaseGV, int64_t BaseOffset,
                             bool HasBaseReg, int64_t Scale) const {
    return STTI->isLegalAddressingMode(Ty, BaseGV, BaseOffset, HasBaseReg,
                                       Scale);
  }

  bool isTruncateFree(Type *Ty1, Type *Ty2) const {
    return STTI->isTruncateFree(Ty1, Ty2);
  }

  bool isTypeLegal(Type *Ty) const {
    return STTI->isTypeLegal(Ty);
  }

  unsigned getJumpBufAlignment() const {
    return STTI->getJumpBufAlignment();
  }

  unsigned getJumpBufSize() const {
    return STTI->getJumpBufSize();
  }

  bool shouldBuildLookupTables() const {
    return STTI->shouldBuildLookupTables();
  }

  PopcntHwSupport getPopcntHwSupport(unsigned IntTyWidthInBit) const {
    return (PopcntHwSupport)STTI->getPopcntHwSupport(IntTyWidthInBit);
  }

  unsigned getIntImmCost(const APInt &Imm, Type *Ty) const {
    return STTI->getIntImmCost(Imm, Ty);
  }

  unsigned getNumberOfRegisters(bool Vector) const {
    return VTTI->getNumberOfRegisters(Vector);
  }

  unsigned getArithmeticInstrCost(unsigned Opcode, Type *Ty) const {
    return VTTI->getArithmeticInstrCost(Opcode, Ty);
  }

  unsigned getShuffleCost(ShuffleKind Kind, Type *Tp,
                          int Index = 0, Type *SubTp = 0) const {
    return VTTI->getShuffleCost((VectorTargetTransformInfo::ShuffleKind)Kind,
                                Tp, Index, SubTp);
  }

  unsigned getCastInstrCost(unsigned Opcode, Type *Dst,
                            Type *Src) const {
    return VTTI->getCastInstrCost(Opcode, Dst, Src);
  }

  unsigned getCFInstrCost(unsigned Opcode) const {
    return VTTI->getCFInstrCost(Opcode);
  }

  unsigned getCmpSelInstrCost(unsigned Opcode, Type *ValTy,
                              Type *CondTy = 0) const {
    return VTTI->getCmpSelInstrCost(Opcode, ValTy, CondTy);
  }

  unsigned getVectorInstrCost(unsigned Opcode, Type *Val,
                              unsigned Index = -1) const {
    return VTTI->getVectorInstrCost(Opcode, Val, Index);
  }

  unsigned getMemoryOpCost(unsigned Opcode, Type *Src,
                           unsigned Alignment,
                           unsigned AddressSpace) const {
    return VTTI->getMemoryOpCost(Opcode, Src, Alignment, AddressSpace);
  }

  unsigned getIntrinsicInstrCost(Intrinsic::ID ID,
                                 Type *RetTy,
                                 ArrayRef<Type*> Tys) const {
    return VTTI->getIntrinsicInstrCost(ID, RetTy, Tys);
  }

  unsigned getNumberOfParts(Type *Tp) const {
    return VTTI->getNumberOfParts(Tp);
  }
};

} // end anonymous namespace

INITIALIZE_AG_PASS(NoTTI, TargetTransformInfo, "no-tti",
                   "No target information", true, true, true)
char NoTTI::ID = 0;

ImmutablePass *llvm::createNoTTIPass(const ScalarTargetTransformInfo *S,
                                     const VectorTargetTransformInfo *V) {
  return new NoTTI(S, V);
}