LLVM  3.7.0
TargetTransformInfo.h
Go to the documentation of this file.
1 //===- TargetTransformInfo.h ------------------------------------*- C++ -*-===//
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 /// \file
10 /// This pass exposes codegen information to IR-level passes. Every
11 /// transformation that uses codegen information is broken into three parts:
12 /// 1. The IR-level analysis pass.
13 /// 2. The IR-level transformation interface which provides the needed
14 /// information.
15 /// 3. Codegen-level implementation which uses target-specific hooks.
16 ///
17 /// This file defines #2, which is the interface that IR-level transformations
18 /// use for querying the codegen.
19 ///
20 //===----------------------------------------------------------------------===//
21 
22 #ifndef LLVM_ANALYSIS_TARGETTRANSFORMINFO_H
23 #define LLVM_ANALYSIS_TARGETTRANSFORMINFO_H
24 
25 #include "llvm/ADT/Optional.h"
26 #include "llvm/IR/IntrinsicInst.h"
27 #include "llvm/IR/Intrinsics.h"
28 #include "llvm/Pass.h"
29 #include "llvm/Support/DataTypes.h"
30 #include <functional>
31 
32 namespace llvm {
33 
34 class Function;
35 class GlobalValue;
36 class Loop;
37 class PreservedAnalyses;
38 class Type;
39 class User;
40 class Value;
41 
42 /// \brief Information about a load/store intrinsic defined by the target.
46  NumMemRefs(0), PtrVal(nullptr) {}
47  bool ReadMem;
48  bool WriteMem;
49  bool Vol;
50  // Same Id is set by the target for corresponding load/store intrinsics.
51  unsigned short MatchingId;
54 };
55 
56 /// \brief This pass provides access to the codegen interfaces that are needed
57 /// for IR-level transformations.
59 public:
60  /// \brief Construct a TTI object using a type implementing the \c Concept
61  /// API below.
62  ///
63  /// This is used by targets to construct a TTI wrapping their target-specific
64  /// implementaion that encodes appropriate costs for their target.
65  template <typename T> TargetTransformInfo(T Impl);
66 
67  /// \brief Construct a baseline TTI object using a minimal implementation of
68  /// the \c Concept API below.
69  ///
70  /// The TTI implementation will reflect the information in the DataLayout
71  /// provided if non-null.
72  explicit TargetTransformInfo(const DataLayout &DL);
73 
74  // Provide move semantics.
77 
78  // We need to define the destructor out-of-line to define our sub-classes
79  // out-of-line.
81 
82  /// \brief Handle the invalidation of this information.
83  ///
84  /// When used as a result of \c TargetIRAnalysis this method will be called
85  /// when the function this was computed for changes. When it returns false,
86  /// the information is preserved across those changes.
88  // FIXME: We should probably in some way ensure that the subtarget
89  // information for a function hasn't changed.
90  return false;
91  }
92 
93  /// \name Generic Target Information
94  /// @{
95 
96  /// \brief Underlying constants for 'cost' values in this interface.
97  ///
98  /// Many APIs in this interface return a cost. This enum defines the
99  /// fundamental values that should be used to interpret (and produce) those
100  /// costs. The costs are returned as an unsigned rather than a member of this
101  /// enumeration because it is expected that the cost of one IR instruction
102  /// may have a multiplicative factor to it or otherwise won't fit directly
103  /// into the enum. Moreover, it is common to sum or average costs which works
104  /// better as simple integral values. Thus this enum only provides constants.
105  ///
106  /// Note that these costs should usually reflect the intersection of code-size
107  /// cost and execution cost. A free instruction is typically one that folds
108  /// into another instruction. For example, reg-to-reg moves can often be
109  /// skipped by renaming the registers in the CPU, but they still are encoded
110  /// and thus wouldn't be considered 'free' here.
112  TCC_Free = 0, ///< Expected to fold away in lowering.
113  TCC_Basic = 1, ///< The cost of a typical 'add' instruction.
114  TCC_Expensive = 4 ///< The cost of a 'div' instruction on x86.
115  };
116 
117  /// \brief Estimate the cost of a specific operation when lowered.
118  ///
119  /// Note that this is designed to work on an arbitrary synthetic opcode, and
120  /// thus work for hypothetical queries before an instruction has even been
121  /// formed. However, this does *not* work for GEPs, and must not be called
122  /// for a GEP instruction. Instead, use the dedicated getGEPCost interface as
123  /// analyzing a GEP's cost required more information.
124  ///
125  /// Typically only the result type is required, and the operand type can be
126  /// omitted. However, if the opcode is one of the cast instructions, the
127  /// operand type is required.
128  ///
129  /// The returned cost is defined in terms of \c TargetCostConstants, see its
130  /// comments for a detailed explanation of the cost values.
131  unsigned getOperationCost(unsigned Opcode, Type *Ty,
132  Type *OpTy = nullptr) const;
133 
134  /// \brief Estimate the cost of a GEP operation when lowered.
135  ///
136  /// The contract for this function is the same as \c getOperationCost except
137  /// that it supports an interface that provides extra information specific to
138  /// the GEP operation.
139  unsigned getGEPCost(const Value *Ptr, ArrayRef<const Value *> Operands) const;
140 
141  /// \brief Estimate the cost of a function call when lowered.
142  ///
143  /// The contract for this is the same as \c getOperationCost except that it
144  /// supports an interface that provides extra information specific to call
145  /// instructions.
146  ///
147  /// This is the most basic query for estimating call cost: it only knows the
148  /// function type and (potentially) the number of arguments at the call site.
149  /// The latter is only interesting for varargs function types.
150  unsigned getCallCost(FunctionType *FTy, int NumArgs = -1) const;
151 
152  /// \brief Estimate the cost of calling a specific function when lowered.
153  ///
154  /// This overload adds the ability to reason about the particular function
155  /// being called in the event it is a library call with special lowering.
156  unsigned getCallCost(const Function *F, int NumArgs = -1) const;
157 
158  /// \brief Estimate the cost of calling a specific function when lowered.
159  ///
160  /// This overload allows specifying a set of candidate argument values.
161  unsigned getCallCost(const Function *F,
162  ArrayRef<const Value *> Arguments) const;
163 
164  /// \brief Estimate the cost of an intrinsic when lowered.
165  ///
166  /// Mirrors the \c getCallCost method but uses an intrinsic identifier.
167  unsigned getIntrinsicCost(Intrinsic::ID IID, Type *RetTy,
168  ArrayRef<Type *> ParamTys) const;
169 
170  /// \brief Estimate the cost of an intrinsic when lowered.
171  ///
172  /// Mirrors the \c getCallCost method but uses an intrinsic identifier.
173  unsigned getIntrinsicCost(Intrinsic::ID IID, Type *RetTy,
174  ArrayRef<const Value *> Arguments) const;
175 
176  /// \brief Estimate the cost of a given IR user when lowered.
177  ///
178  /// This can estimate the cost of either a ConstantExpr or Instruction when
179  /// lowered. It has two primary advantages over the \c getOperationCost and
180  /// \c getGEPCost above, and one significant disadvantage: it can only be
181  /// used when the IR construct has already been formed.
182  ///
183  /// The advantages are that it can inspect the SSA use graph to reason more
184  /// accurately about the cost. For example, all-constant-GEPs can often be
185  /// folded into a load or other instruction, but if they are used in some
186  /// other context they may not be folded. This routine can distinguish such
187  /// cases.
188  ///
189  /// The returned cost is defined in terms of \c TargetCostConstants, see its
190  /// comments for a detailed explanation of the cost values.
191  unsigned getUserCost(const User *U) const;
192 
193  /// \brief Return true if branch divergence exists.
194  ///
195  /// Branch divergence has a significantly negative impact on GPU performance
196  /// when threads in the same wavefront take different paths due to conditional
197  /// branches.
198  bool hasBranchDivergence() const;
199 
200  /// \brief Returns whether V is a source of divergence.
201  ///
202  /// This function provides the target-dependent information for
203  /// the target-independent DivergenceAnalysis. DivergenceAnalysis first
204  /// builds the dependency graph, and then runs the reachability algorithm
205  /// starting with the sources of divergence.
206  bool isSourceOfDivergence(const Value *V) const;
207 
208  /// \brief Test whether calls to a function lower to actual program function
209  /// calls.
210  ///
211  /// The idea is to test whether the program is likely to require a 'call'
212  /// instruction or equivalent in order to call the given function.
213  ///
214  /// FIXME: It's not clear that this is a good or useful query API. Client's
215  /// should probably move to simpler cost metrics using the above.
216  /// Alternatively, we could split the cost interface into distinct code-size
217  /// and execution-speed costs. This would allow modelling the core of this
218  /// query more accurately as a call is a single small instruction, but
219  /// incurs significant execution cost.
220  bool isLoweredToCall(const Function *F) const;
221 
222  /// Parameters that control the generic loop unrolling transformation.
224  /// The cost threshold for the unrolled loop. Should be relative to the
225  /// getUserCost values returned by this API, and the expectation is that
226  /// the unrolled loop's instructions when run through that interface should
227  /// not exceed this cost. However, this is only an estimate. Also, specific
228  /// loops may be unrolled even with a cost above this threshold if deemed
229  /// profitable. Set this to UINT_MAX to disable the loop body cost
230  /// restriction.
231  unsigned Threshold;
232  /// If complete unrolling will reduce the cost of the loop below its
233  /// expected dynamic cost while rolled by this percentage, apply a discount
234  /// (below) to its unrolled cost.
236  /// The discount applied to the unrolled cost when the *dynamic* cost
237  /// savings of unrolling exceed the \c PercentDynamicCostSavedThreshold.
239  /// The cost threshold for the unrolled loop when optimizing for size (set
240  /// to UINT_MAX to disable).
242  /// The cost threshold for the unrolled loop, like Threshold, but used
243  /// for partial/runtime unrolling (set to UINT_MAX to disable).
245  /// The cost threshold for the unrolled loop when optimizing for size, like
246  /// OptSizeThreshold, but used for partial/runtime unrolling (set to
247  /// UINT_MAX to disable).
249  /// A forced unrolling factor (the number of concatenated bodies of the
250  /// original loop in the unrolled loop body). When set to 0, the unrolling
251  /// transformation will select an unrolling factor based on the current cost
252  /// threshold and other factors.
253  unsigned Count;
254  // Set the maximum unrolling factor. The unrolling factor may be selected
255  // using the appropriate cost threshold, but may not exceed this number
256  // (set to UINT_MAX to disable). This does not apply in cases where the
257  // loop is being fully unrolled.
258  unsigned MaxCount;
259  /// Allow partial unrolling (unrolling of loops to expand the size of the
260  /// loop body, not only to eliminate small constant-trip-count loops).
261  bool Partial;
262  /// Allow runtime unrolling (unrolling of loops to expand the size of the
263  /// loop body even when the number of loop iterations is not known at
264  /// compile time).
265  bool Runtime;
266  /// Allow emitting expensive instructions (such as divisions) when computing
267  /// the trip count of a loop for runtime unrolling.
269  };
270 
271  /// \brief Get target-customized preferences for the generic loop unrolling
272  /// transformation. The caller will initialize UP with the current
273  /// target-independent defaults.
275 
276  /// @}
277 
278  /// \name Scalar Target Information
279  /// @{
280 
281  /// \brief Flags indicating the kind of support for population count.
282  ///
283  /// Compared to the SW implementation, HW support is supposed to
284  /// significantly boost the performance when the population is dense, and it
285  /// may or may not degrade performance if the population is sparse. A HW
286  /// support is considered as "Fast" if it can outperform, or is on a par
287  /// with, SW implementation when the population is sparse; otherwise, it is
288  /// considered as "Slow".
290 
291  /// \brief Return true if the specified immediate is legal add immediate, that
292  /// is the target has add instructions which can add a register with the
293  /// immediate without having to materialize the immediate into a register.
294  bool isLegalAddImmediate(int64_t Imm) const;
295 
296  /// \brief Return true if the specified immediate is legal icmp immediate,
297  /// that is the target has icmp instructions which can compare a register
298  /// against the immediate without having to materialize the immediate into a
299  /// register.
300  bool isLegalICmpImmediate(int64_t Imm) const;
301 
302  /// \brief Return true if the addressing mode represented by AM is legal for
303  /// this target, for a load/store of the specified type.
304  /// The type may be VoidTy, in which case only return true if the addressing
305  /// mode is legal for a load/store of any legal type.
306  /// TODO: Handle pre/postinc as well.
307  bool isLegalAddressingMode(Type *Ty, GlobalValue *BaseGV, int64_t BaseOffset,
308  bool HasBaseReg, int64_t Scale,
309  unsigned AddrSpace = 0) const;
310 
311  /// \brief Return true if the target works with masked instruction
312  /// AVX2 allows masks for consecutive load and store for i32 and i64 elements.
313  /// AVX-512 architecture will also allow masks for non-consecutive memory
314  /// accesses.
315  bool isLegalMaskedStore(Type *DataType, int Consecutive) const;
316  bool isLegalMaskedLoad(Type *DataType, int Consecutive) const;
317 
318  /// \brief Return the cost of the scaling factor used in the addressing
319  /// mode represented by AM for this target, for a load/store
320  /// of the specified type.
321  /// If the AM is supported, the return value must be >= 0.
322  /// If the AM is not supported, it returns a negative value.
323  /// TODO: Handle pre/postinc as well.
324  int getScalingFactorCost(Type *Ty, GlobalValue *BaseGV, int64_t BaseOffset,
325  bool HasBaseReg, int64_t Scale,
326  unsigned AddrSpace = 0) const;
327 
328  /// \brief Return true if it's free to truncate a value of type Ty1 to type
329  /// Ty2. e.g. On x86 it's free to truncate a i32 value in register EAX to i16
330  /// by referencing its sub-register AX.
331  bool isTruncateFree(Type *Ty1, Type *Ty2) const;
332 
333  /// \brief Return true if it is profitable to hoist instruction in the
334  /// then/else to before if.
335  bool isProfitableToHoist(Instruction *I) const;
336 
337  /// \brief Return true if this type is legal.
338  bool isTypeLegal(Type *Ty) const;
339 
340  /// \brief Returns the target's jmp_buf alignment in bytes.
341  unsigned getJumpBufAlignment() const;
342 
343  /// \brief Returns the target's jmp_buf size in bytes.
344  unsigned getJumpBufSize() const;
345 
346  /// \brief Return true if switches should be turned into lookup tables for the
347  /// target.
348  bool shouldBuildLookupTables() const;
349 
350  /// \brief Don't restrict interleaved unrolling to small loops.
351  bool enableAggressiveInterleaving(bool LoopHasReductions) const;
352 
353  /// \brief Return hardware support for population count.
354  PopcntSupportKind getPopcntSupport(unsigned IntTyWidthInBit) const;
355 
356  /// \brief Return true if the hardware has a fast square-root instruction.
357  bool haveFastSqrt(Type *Ty) const;
358 
359  /// \brief Return the expected cost of supporting the floating point operation
360  /// of the specified type.
361  unsigned getFPOpCost(Type *Ty) const;
362 
363  /// \brief Return the expected cost of materializing for the given integer
364  /// immediate of the specified type.
365  unsigned getIntImmCost(const APInt &Imm, Type *Ty) const;
366 
367  /// \brief Return the expected cost of materialization for the given integer
368  /// immediate of the specified type for a given instruction. The cost can be
369  /// zero if the immediate can be folded into the specified instruction.
370  unsigned getIntImmCost(unsigned Opc, unsigned Idx, const APInt &Imm,
371  Type *Ty) const;
372  unsigned getIntImmCost(Intrinsic::ID IID, unsigned Idx, const APInt &Imm,
373  Type *Ty) const;
374  /// @}
375 
376  /// \name Vector Target Information
377  /// @{
378 
379  /// \brief The various kinds of shuffle patterns for vector queries.
380  enum ShuffleKind {
381  SK_Broadcast, ///< Broadcast element 0 to all other elements.
382  SK_Reverse, ///< Reverse the order of the vector.
383  SK_Alternate, ///< Choose alternate elements from vector.
384  SK_InsertSubvector, ///< InsertSubvector. Index indicates start offset.
385  SK_ExtractSubvector ///< ExtractSubvector Index indicates start offset.
386  };
387 
388  /// \brief Additional information about an operand's possible values.
390  OK_AnyValue, // Operand can have any value.
391  OK_UniformValue, // Operand is uniform (splat of a value).
392  OK_UniformConstantValue, // Operand is uniform constant.
393  OK_NonUniformConstantValue // Operand is a non uniform constant value.
394  };
395 
396  /// \brief Additional properties of an operand's values.
398 
399  /// \return The number of scalar or vector registers that the target has.
400  /// If 'Vectors' is true, it returns the number of vector registers. If it is
401  /// set to false, it returns the number of scalar registers.
402  unsigned getNumberOfRegisters(bool Vector) const;
403 
404  /// \return The width of the largest scalar or vector register type.
405  unsigned getRegisterBitWidth(bool Vector) const;
406 
407  /// \return The maximum interleave factor that any transform should try to
408  /// perform for this target. This number depends on the level of parallelism
409  /// and the number of execution units in the CPU.
410  unsigned getMaxInterleaveFactor(unsigned VF) const;
411 
412  /// \return The expected cost of arithmetic ops, such as mul, xor, fsub, etc.
413  unsigned
414  getArithmeticInstrCost(unsigned Opcode, Type *Ty,
415  OperandValueKind Opd1Info = OK_AnyValue,
416  OperandValueKind Opd2Info = OK_AnyValue,
417  OperandValueProperties Opd1PropInfo = OP_None,
418  OperandValueProperties Opd2PropInfo = OP_None) const;
419 
420  /// \return The cost of a shuffle instruction of kind Kind and of type Tp.
421  /// The index and subtype parameters are used by the subvector insertion and
422  /// extraction shuffle kinds.
423  unsigned getShuffleCost(ShuffleKind Kind, Type *Tp, int Index = 0,
424  Type *SubTp = nullptr) const;
425 
426  /// \return The expected cost of cast instructions, such as bitcast, trunc,
427  /// zext, etc.
428  unsigned getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src) const;
429 
430  /// \return The expected cost of control-flow related instructions such as
431  /// Phi, Ret, Br.
432  unsigned getCFInstrCost(unsigned Opcode) const;
433 
434  /// \returns The expected cost of compare and select instructions.
435  unsigned getCmpSelInstrCost(unsigned Opcode, Type *ValTy,
436  Type *CondTy = nullptr) const;
437 
438  /// \return The expected cost of vector Insert and Extract.
439  /// Use -1 to indicate that there is no information on the index value.
440  unsigned getVectorInstrCost(unsigned Opcode, Type *Val,
441  unsigned Index = -1) const;
442 
443  /// \return The cost of Load and Store instructions.
444  unsigned getMemoryOpCost(unsigned Opcode, Type *Src, unsigned Alignment,
445  unsigned AddressSpace) const;
446 
447  /// \return The cost of masked Load and Store instructions.
448  unsigned getMaskedMemoryOpCost(unsigned Opcode, Type *Src, unsigned Alignment,
449  unsigned AddressSpace) const;
450 
451  /// \return The cost of the interleaved memory operation.
452  /// \p Opcode is the memory operation code
453  /// \p VecTy is the vector type of the interleaved access.
454  /// \p Factor is the interleave factor
455  /// \p Indices is the indices for interleaved load members (as interleaved
456  /// load allows gaps)
457  /// \p Alignment is the alignment of the memory operation
458  /// \p AddressSpace is address space of the pointer.
459  unsigned getInterleavedMemoryOpCost(unsigned Opcode, Type *VecTy,
460  unsigned Factor,
461  ArrayRef<unsigned> Indices,
462  unsigned Alignment,
463  unsigned AddressSpace) const;
464 
465  /// \brief Calculate the cost of performing a vector reduction.
466  ///
467  /// This is the cost of reducing the vector value of type \p Ty to a scalar
468  /// value using the operation denoted by \p Opcode. The form of the reduction
469  /// can either be a pairwise reduction or a reduction that splits the vector
470  /// at every reduction level.
471  ///
472  /// Pairwise:
473  /// (v0, v1, v2, v3)
474  /// ((v0+v1), (v2, v3), undef, undef)
475  /// Split:
476  /// (v0, v1, v2, v3)
477  /// ((v0+v2), (v1+v3), undef, undef)
478  unsigned getReductionCost(unsigned Opcode, Type *Ty,
479  bool IsPairwiseForm) const;
480 
481  /// \returns The cost of Intrinsic instructions.
482  unsigned getIntrinsicInstrCost(Intrinsic::ID ID, Type *RetTy,
483  ArrayRef<Type *> Tys) const;
484 
485  /// \returns The cost of Call instructions.
486  unsigned getCallInstrCost(Function *F, Type *RetTy,
487  ArrayRef<Type *> Tys) const;
488 
489  /// \returns The number of pieces into which the provided type must be
490  /// split during legalization. Zero is returned when the answer is unknown.
491  unsigned getNumberOfParts(Type *Tp) const;
492 
493  /// \returns The cost of the address computation. For most targets this can be
494  /// merged into the instruction indexing mode. Some targets might want to
495  /// distinguish between address computation for memory operations on vector
496  /// types and scalar types. Such targets should override this function.
497  /// The 'IsComplex' parameter is a hint that the address computation is likely
498  /// to involve multiple instructions and as such unlikely to be merged into
499  /// the address indexing mode.
500  unsigned getAddressComputationCost(Type *Ty, bool IsComplex = false) const;
501 
502  /// \returns The cost, if any, of keeping values of the given types alive
503  /// over a callsite.
504  ///
505  /// Some types may require the use of register classes that do not have
506  /// any callee-saved registers, so would require a spill and fill.
508 
509  /// \returns True if the intrinsic is a supported memory intrinsic. Info
510  /// will contain additional information - whether the intrinsic may write
511  /// or read to memory, volatility and the pointer. Info is undefined
512  /// if false is returned.
513  bool getTgtMemIntrinsic(IntrinsicInst *Inst, MemIntrinsicInfo &Info) const;
514 
515  /// \returns A value which is the result of the given memory intrinsic. New
516  /// instructions may be created to extract the result from the given intrinsic
517  /// memory operation. Returns nullptr if the target cannot create a result
518  /// from the given intrinsic.
520  Type *ExpectedType) const;
521 
522  /// \returns True if the two functions have compatible attributes for inlining
523  /// purposes.
524  bool hasCompatibleFunctionAttributes(const Function *Caller,
525  const Function *Callee) const;
526 
527  /// @}
528 
529 private:
530  /// \brief The abstract base class used to type erase specific TTI
531  /// implementations.
532  class Concept;
533 
534  /// \brief The template model for the base class which wraps a concrete
535  /// implementation in a type erased interface.
536  template <typename T> class Model;
537 
538  std::unique_ptr<Concept> TTIImpl;
539 };
540 
542 public:
543  virtual ~Concept() = 0;
544  virtual const DataLayout &getDataLayout() const = 0;
545  virtual unsigned getOperationCost(unsigned Opcode, Type *Ty, Type *OpTy) = 0;
546  virtual unsigned getGEPCost(const Value *Ptr,
548  virtual unsigned getCallCost(FunctionType *FTy, int NumArgs) = 0;
549  virtual unsigned getCallCost(const Function *F, int NumArgs) = 0;
550  virtual unsigned getCallCost(const Function *F,
551  ArrayRef<const Value *> Arguments) = 0;
552  virtual unsigned getIntrinsicCost(Intrinsic::ID IID, Type *RetTy,
553  ArrayRef<Type *> ParamTys) = 0;
554  virtual unsigned getIntrinsicCost(Intrinsic::ID IID, Type *RetTy,
555  ArrayRef<const Value *> Arguments) = 0;
556  virtual unsigned getUserCost(const User *U) = 0;
557  virtual bool hasBranchDivergence() = 0;
558  virtual bool isSourceOfDivergence(const Value *V) = 0;
559  virtual bool isLoweredToCall(const Function *F) = 0;
560  virtual void getUnrollingPreferences(Loop *L, UnrollingPreferences &UP) = 0;
561  virtual bool isLegalAddImmediate(int64_t Imm) = 0;
562  virtual bool isLegalICmpImmediate(int64_t Imm) = 0;
563  virtual bool isLegalAddressingMode(Type *Ty, GlobalValue *BaseGV,
564  int64_t BaseOffset, bool HasBaseReg,
565  int64_t Scale,
566  unsigned AddrSpace) = 0;
567  virtual bool isLegalMaskedStore(Type *DataType, int Consecutive) = 0;
568  virtual bool isLegalMaskedLoad(Type *DataType, int Consecutive) = 0;
569  virtual int getScalingFactorCost(Type *Ty, GlobalValue *BaseGV,
570  int64_t BaseOffset, bool HasBaseReg,
571  int64_t Scale, unsigned AddrSpace) = 0;
572  virtual bool isTruncateFree(Type *Ty1, Type *Ty2) = 0;
573  virtual bool isProfitableToHoist(Instruction *I) = 0;
574  virtual bool isTypeLegal(Type *Ty) = 0;
575  virtual unsigned getJumpBufAlignment() = 0;
576  virtual unsigned getJumpBufSize() = 0;
577  virtual bool shouldBuildLookupTables() = 0;
578  virtual bool enableAggressiveInterleaving(bool LoopHasReductions) = 0;
579  virtual PopcntSupportKind getPopcntSupport(unsigned IntTyWidthInBit) = 0;
580  virtual bool haveFastSqrt(Type *Ty) = 0;
581  virtual unsigned getFPOpCost(Type *Ty) = 0;
582  virtual unsigned getIntImmCost(const APInt &Imm, Type *Ty) = 0;
583  virtual unsigned getIntImmCost(unsigned Opc, unsigned Idx, const APInt &Imm,
584  Type *Ty) = 0;
585  virtual unsigned getIntImmCost(Intrinsic::ID IID, unsigned Idx,
586  const APInt &Imm, Type *Ty) = 0;
587  virtual unsigned getNumberOfRegisters(bool Vector) = 0;
588  virtual unsigned getRegisterBitWidth(bool Vector) = 0;
589  virtual unsigned getMaxInterleaveFactor(unsigned VF) = 0;
590  virtual unsigned
591  getArithmeticInstrCost(unsigned Opcode, Type *Ty, OperandValueKind Opd1Info,
592  OperandValueKind Opd2Info,
593  OperandValueProperties Opd1PropInfo,
594  OperandValueProperties Opd2PropInfo) = 0;
595  virtual unsigned getShuffleCost(ShuffleKind Kind, Type *Tp, int Index,
596  Type *SubTp) = 0;
597  virtual unsigned getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src) = 0;
598  virtual unsigned getCFInstrCost(unsigned Opcode) = 0;
599  virtual unsigned getCmpSelInstrCost(unsigned Opcode, Type *ValTy,
600  Type *CondTy) = 0;
601  virtual unsigned getVectorInstrCost(unsigned Opcode, Type *Val,
602  unsigned Index) = 0;
603  virtual unsigned getMemoryOpCost(unsigned Opcode, Type *Src,
604  unsigned Alignment,
605  unsigned AddressSpace) = 0;
606  virtual unsigned getMaskedMemoryOpCost(unsigned Opcode, Type *Src,
607  unsigned Alignment,
608  unsigned AddressSpace) = 0;
609  virtual unsigned getInterleavedMemoryOpCost(unsigned Opcode, Type *VecTy,
610  unsigned Factor,
611  ArrayRef<unsigned> Indices,
612  unsigned Alignment,
613  unsigned AddressSpace) = 0;
614  virtual unsigned getReductionCost(unsigned Opcode, Type *Ty,
615  bool IsPairwiseForm) = 0;
616  virtual unsigned getIntrinsicInstrCost(Intrinsic::ID ID, Type *RetTy,
617  ArrayRef<Type *> Tys) = 0;
618  virtual unsigned getCallInstrCost(Function *F, Type *RetTy,
619  ArrayRef<Type *> Tys) = 0;
620  virtual unsigned getNumberOfParts(Type *Tp) = 0;
621  virtual unsigned getAddressComputationCost(Type *Ty, bool IsComplex) = 0;
622  virtual unsigned getCostOfKeepingLiveOverCall(ArrayRef<Type *> Tys) = 0;
623  virtual bool getTgtMemIntrinsic(IntrinsicInst *Inst,
624  MemIntrinsicInfo &Info) = 0;
626  Type *ExpectedType) = 0;
627  virtual bool hasCompatibleFunctionAttributes(const Function *Caller,
628  const Function *Callee) const = 0;
629 };
630 
631 template <typename T>
633  T Impl;
634 
635 public:
636  Model(T Impl) : Impl(std::move(Impl)) {}
637  ~Model() override {}
638 
639  const DataLayout &getDataLayout() const override {
640  return Impl.getDataLayout();
641  }
642 
643  unsigned getOperationCost(unsigned Opcode, Type *Ty, Type *OpTy) override {
644  return Impl.getOperationCost(Opcode, Ty, OpTy);
645  }
646  unsigned getGEPCost(const Value *Ptr,
647  ArrayRef<const Value *> Operands) override {
648  return Impl.getGEPCost(Ptr, Operands);
649  }
650  unsigned getCallCost(FunctionType *FTy, int NumArgs) override {
651  return Impl.getCallCost(FTy, NumArgs);
652  }
653  unsigned getCallCost(const Function *F, int NumArgs) override {
654  return Impl.getCallCost(F, NumArgs);
655  }
656  unsigned getCallCost(const Function *F,
657  ArrayRef<const Value *> Arguments) override {
658  return Impl.getCallCost(F, Arguments);
659  }
660  unsigned getIntrinsicCost(Intrinsic::ID IID, Type *RetTy,
661  ArrayRef<Type *> ParamTys) override {
662  return Impl.getIntrinsicCost(IID, RetTy, ParamTys);
663  }
664  unsigned getIntrinsicCost(Intrinsic::ID IID, Type *RetTy,
665  ArrayRef<const Value *> Arguments) override {
666  return Impl.getIntrinsicCost(IID, RetTy, Arguments);
667  }
668  unsigned getUserCost(const User *U) override { return Impl.getUserCost(U); }
669  bool hasBranchDivergence() override { return Impl.hasBranchDivergence(); }
670  bool isSourceOfDivergence(const Value *V) override {
671  return Impl.isSourceOfDivergence(V);
672  }
673  bool isLoweredToCall(const Function *F) override {
674  return Impl.isLoweredToCall(F);
675  }
676  void getUnrollingPreferences(Loop *L, UnrollingPreferences &UP) override {
677  return Impl.getUnrollingPreferences(L, UP);
678  }
679  bool isLegalAddImmediate(int64_t Imm) override {
680  return Impl.isLegalAddImmediate(Imm);
681  }
682  bool isLegalICmpImmediate(int64_t Imm) override {
683  return Impl.isLegalICmpImmediate(Imm);
684  }
685  bool isLegalAddressingMode(Type *Ty, GlobalValue *BaseGV, int64_t BaseOffset,
686  bool HasBaseReg, int64_t Scale,
687  unsigned AddrSpace) override {
688  return Impl.isLegalAddressingMode(Ty, BaseGV, BaseOffset, HasBaseReg,
689  Scale, AddrSpace);
690  }
691  bool isLegalMaskedStore(Type *DataType, int Consecutive) override {
692  return Impl.isLegalMaskedStore(DataType, Consecutive);
693  }
694  bool isLegalMaskedLoad(Type *DataType, int Consecutive) override {
695  return Impl.isLegalMaskedLoad(DataType, Consecutive);
696  }
697  int getScalingFactorCost(Type *Ty, GlobalValue *BaseGV, int64_t BaseOffset,
698  bool HasBaseReg, int64_t Scale,
699  unsigned AddrSpace) override {
700  return Impl.getScalingFactorCost(Ty, BaseGV, BaseOffset, HasBaseReg,
701  Scale, AddrSpace);
702  }
703  bool isTruncateFree(Type *Ty1, Type *Ty2) override {
704  return Impl.isTruncateFree(Ty1, Ty2);
705  }
706  bool isProfitableToHoist(Instruction *I) override {
707  return Impl.isProfitableToHoist(I);
708  }
709  bool isTypeLegal(Type *Ty) override { return Impl.isTypeLegal(Ty); }
710  unsigned getJumpBufAlignment() override { return Impl.getJumpBufAlignment(); }
711  unsigned getJumpBufSize() override { return Impl.getJumpBufSize(); }
712  bool shouldBuildLookupTables() override {
713  return Impl.shouldBuildLookupTables();
714  }
715  bool enableAggressiveInterleaving(bool LoopHasReductions) override {
716  return Impl.enableAggressiveInterleaving(LoopHasReductions);
717  }
718  PopcntSupportKind getPopcntSupport(unsigned IntTyWidthInBit) override {
719  return Impl.getPopcntSupport(IntTyWidthInBit);
720  }
721  bool haveFastSqrt(Type *Ty) override { return Impl.haveFastSqrt(Ty); }
722 
723  unsigned getFPOpCost(Type *Ty) override {
724  return Impl.getFPOpCost(Ty);
725  }
726 
727  unsigned getIntImmCost(const APInt &Imm, Type *Ty) override {
728  return Impl.getIntImmCost(Imm, Ty);
729  }
730  unsigned getIntImmCost(unsigned Opc, unsigned Idx, const APInt &Imm,
731  Type *Ty) override {
732  return Impl.getIntImmCost(Opc, Idx, Imm, Ty);
733  }
734  unsigned getIntImmCost(Intrinsic::ID IID, unsigned Idx, const APInt &Imm,
735  Type *Ty) override {
736  return Impl.getIntImmCost(IID, Idx, Imm, Ty);
737  }
738  unsigned getNumberOfRegisters(bool Vector) override {
739  return Impl.getNumberOfRegisters(Vector);
740  }
741  unsigned getRegisterBitWidth(bool Vector) override {
742  return Impl.getRegisterBitWidth(Vector);
743  }
744  unsigned getMaxInterleaveFactor(unsigned VF) override {
745  return Impl.getMaxInterleaveFactor(VF);
746  }
747  unsigned
748  getArithmeticInstrCost(unsigned Opcode, Type *Ty, OperandValueKind Opd1Info,
749  OperandValueKind Opd2Info,
750  OperandValueProperties Opd1PropInfo,
751  OperandValueProperties Opd2PropInfo) override {
752  return Impl.getArithmeticInstrCost(Opcode, Ty, Opd1Info, Opd2Info,
753  Opd1PropInfo, Opd2PropInfo);
754  }
755  unsigned getShuffleCost(ShuffleKind Kind, Type *Tp, int Index,
756  Type *SubTp) override {
757  return Impl.getShuffleCost(Kind, Tp, Index, SubTp);
758  }
759  unsigned getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src) override {
760  return Impl.getCastInstrCost(Opcode, Dst, Src);
761  }
762  unsigned getCFInstrCost(unsigned Opcode) override {
763  return Impl.getCFInstrCost(Opcode);
764  }
765  unsigned getCmpSelInstrCost(unsigned Opcode, Type *ValTy,
766  Type *CondTy) override {
767  return Impl.getCmpSelInstrCost(Opcode, ValTy, CondTy);
768  }
769  unsigned getVectorInstrCost(unsigned Opcode, Type *Val,
770  unsigned Index) override {
771  return Impl.getVectorInstrCost(Opcode, Val, Index);
772  }
773  unsigned getMemoryOpCost(unsigned Opcode, Type *Src, unsigned Alignment,
774  unsigned AddressSpace) override {
775  return Impl.getMemoryOpCost(Opcode, Src, Alignment, AddressSpace);
776  }
777  unsigned getMaskedMemoryOpCost(unsigned Opcode, Type *Src, unsigned Alignment,
778  unsigned AddressSpace) override {
779  return Impl.getMaskedMemoryOpCost(Opcode, Src, Alignment, AddressSpace);
780  }
781  unsigned getInterleavedMemoryOpCost(unsigned Opcode, Type *VecTy,
782  unsigned Factor,
783  ArrayRef<unsigned> Indices,
784  unsigned Alignment,
785  unsigned AddressSpace) override {
786  return Impl.getInterleavedMemoryOpCost(Opcode, VecTy, Factor, Indices,
787  Alignment, AddressSpace);
788  }
789  unsigned getReductionCost(unsigned Opcode, Type *Ty,
790  bool IsPairwiseForm) override {
791  return Impl.getReductionCost(Opcode, Ty, IsPairwiseForm);
792  }
793  unsigned getIntrinsicInstrCost(Intrinsic::ID ID, Type *RetTy,
794  ArrayRef<Type *> Tys) override {
795  return Impl.getIntrinsicInstrCost(ID, RetTy, Tys);
796  }
797  unsigned getCallInstrCost(Function *F, Type *RetTy,
798  ArrayRef<Type *> Tys) override {
799  return Impl.getCallInstrCost(F, RetTy, Tys);
800  }
801  unsigned getNumberOfParts(Type *Tp) override {
802  return Impl.getNumberOfParts(Tp);
803  }
804  unsigned getAddressComputationCost(Type *Ty, bool IsComplex) override {
805  return Impl.getAddressComputationCost(Ty, IsComplex);
806  }
807  unsigned getCostOfKeepingLiveOverCall(ArrayRef<Type *> Tys) override {
808  return Impl.getCostOfKeepingLiveOverCall(Tys);
809  }
810  bool getTgtMemIntrinsic(IntrinsicInst *Inst,
811  MemIntrinsicInfo &Info) override {
812  return Impl.getTgtMemIntrinsic(Inst, Info);
813  }
814  Value *getOrCreateResultFromMemIntrinsic(IntrinsicInst *Inst,
815  Type *ExpectedType) override {
816  return Impl.getOrCreateResultFromMemIntrinsic(Inst, ExpectedType);
817  }
818  bool hasCompatibleFunctionAttributes(const Function *Caller,
819  const Function *Callee) const override {
820  return Impl.hasCompatibleFunctionAttributes(Caller, Callee);
821  }
822 };
823 
824 template <typename T>
826  : TTIImpl(new Model<T>(Impl)) {}
827 
828 /// \brief Analysis pass providing the \c TargetTransformInfo.
829 ///
830 /// The core idea of the TargetIRAnalysis is to expose an interface through
831 /// which LLVM targets can analyze and provide information about the middle
832 /// end's target-independent IR. This supports use cases such as target-aware
833 /// cost modeling of IR constructs.
834 ///
835 /// This is a function analysis because much of the cost modeling for targets
836 /// is done in a subtarget specific way and LLVM supports compiling different
837 /// functions targeting different subtargets in order to support runtime
838 /// dispatch according to the observed subtarget.
840 public:
842 
843  /// \brief Opaque, unique identifier for this analysis pass.
844  static void *ID() { return (void *)&PassID; }
845 
846  /// \brief Provide access to a name for this pass for debugging purposes.
847  static StringRef name() { return "TargetIRAnalysis"; }
848 
849  /// \brief Default construct a target IR analysis.
850  ///
851  /// This will use the module's datalayout to construct a baseline
852  /// conservative TTI result.
854 
855  /// \brief Construct an IR analysis pass around a target-provide callback.
856  ///
857  /// The callback will be called with a particular function for which the TTI
858  /// is needed and must return a TTI object for that function.
860 
861  // Value semantics. We spell out the constructors for MSVC.
863  : TTICallback(Arg.TTICallback) {}
865  : TTICallback(std::move(Arg.TTICallback)) {}
867  TTICallback = RHS.TTICallback;
868  return *this;
869  }
871  TTICallback = std::move(RHS.TTICallback);
872  return *this;
873  }
874 
875  Result run(Function &F);
876 
877 private:
878  static char PassID;
879 
880  /// \brief The callback used to produce a result.
881  ///
882  /// We use a completely opaque callback so that targets can provide whatever
883  /// mechanism they desire for constructing the TTI for a given function.
884  ///
885  /// FIXME: Should we really use std::function? It's relatively inefficient.
886  /// It might be possible to arrange for even stateful callbacks to outlive
887  /// the analysis and thus use a function_ref which would be lighter weight.
888  /// This may also be less error prone as the callback is likely to reference
889  /// the external TargetMachine, and that reference needs to never dangle.
890  std::function<Result(Function &)> TTICallback;
891 
892  /// \brief Helper function used as the callback in the default constructor.
893  static Result getDefaultTTI(Function &F);
894 };
895 
896 /// \brief Wrapper pass for TargetTransformInfo.
897 ///
898 /// This pass can be constructed from a TTI object which it stores internally
899 /// and is queried by passes.
901  TargetIRAnalysis TIRA;
903 
904  virtual void anchor();
905 
906 public:
907  static char ID;
908 
909  /// \brief We must provide a default constructor for the pass but it should
910  /// never be used.
911  ///
912  /// Use the constructor below or call one of the creation routines.
914 
916 
918 };
919 
920 /// \brief Create an analysis pass wrapper around a TTI object.
921 ///
922 /// This analysis pass just holds the TTI instance and makes it available to
923 /// clients.
925 
926 } // End llvm namespace
927 
928 #endif
PopcntSupportKind getPopcntSupport(unsigned IntTyWidthInBit) const
Return hardware support for population count.
A parsed version of the target data layout string in and methods for querying it. ...
Definition: DataLayout.h:104
unsigned getCallCost(FunctionType *FTy, int NumArgs=-1) const
Estimate the cost of a function call when lowered.
bool Partial
Allow partial unrolling (unrolling of loops to expand the size of the loop body, not only to eliminat...
virtual const DataLayout & getDataLayout() const =0
unsigned getGEPCost(const Value *Ptr, ArrayRef< const Value * > Operands) const
Estimate the cost of a GEP operation when lowered.
TargetTransformInfo & operator=(TargetTransformInfo &&RHS)
bool isSourceOfDivergence(const Value *V) const
Returns whether V is a source of divergence.
virtual unsigned getCostOfKeepingLiveOverCall(ArrayRef< Type * > Tys)=0
virtual unsigned getShuffleCost(ShuffleKind Kind, Type *Tp, int Index, Type *SubTp)=0
unsigned getOperationCost(unsigned Opcode, Type *Ty, Type *OpTy=nullptr) const
Estimate the cost of a specific operation when lowered.
virtual unsigned getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy)=0
TargetIRAnalysis & operator=(const TargetIRAnalysis &RHS)
bool hasBranchDivergence() const
Return true if branch divergence exists.
virtual bool isLoweredToCall(const Function *F)=0
virtual void getUnrollingPreferences(Loop *L, UnrollingPreferences &UP)=0
virtual bool isLegalMaskedStore(Type *DataType, int Consecutive)=0
TargetTransformInfoWrapperPass()
We must provide a default constructor for the pass but it should never be used.
unsigned PartialOptSizeThreshold
The cost threshold for the unrolled loop when optimizing for size, like OptSizeThreshold, but used for partial/runtime unrolling (set to UINT_MAX to disable).
unsigned getJumpBufSize() const
Returns the target's jmp_buf size in bytes.
unsigned PartialThreshold
The cost threshold for the unrolled loop, like Threshold, but used for partial/runtime unrolling (set...
ImmutablePass * createTargetTransformInfoWrapperPass(TargetIRAnalysis TIRA)
Create an analysis pass wrapper around a TTI object.
unsigned getMaxInterleaveFactor(unsigned VF) const
Analysis pass providing the TargetTransformInfo.
virtual bool hasCompatibleFunctionAttributes(const Function *Caller, const Function *Callee) const =0
virtual bool isLegalICmpImmediate(int64_t Imm)=0
unsigned getNumberOfParts(Type *Tp) const
F(f)
bool isLegalMaskedLoad(Type *DataType, int Consecutive) const
virtual unsigned getMaskedMemoryOpCost(unsigned Opcode, Type *Src, unsigned Alignment, unsigned AddressSpace)=0
TargetTransformInfo & getTTI(Function &F)
bool isLegalAddImmediate(int64_t Imm) const
Return true if the specified immediate is legal add immediate, that is the target has add instruction...
TargetIRAnalysis & operator=(TargetIRAnalysis &&RHS)
unsigned getArithmeticInstrCost(unsigned Opcode, Type *Ty, OperandValueKind Opd1Info=OK_AnyValue, OperandValueKind Opd2Info=OK_AnyValue, OperandValueProperties Opd1PropInfo=OP_None, OperandValueProperties Opd2PropInfo=OP_None) const
virtual bool enableAggressiveInterleaving(bool LoopHasReductions)=0
virtual bool shouldBuildLookupTables()=0
virtual bool isTruncateFree(Type *Ty1, Type *Ty2)=0
unsigned getCFInstrCost(unsigned Opcode) const
unsigned getInterleavedMemoryOpCost(unsigned Opcode, Type *VecTy, unsigned Factor, ArrayRef< unsigned > Indices, unsigned Alignment, unsigned AddressSpace) const
static void * ID()
Opaque, unique identifier for this analysis pass.
unsigned getCallInstrCost(Function *F, Type *RetTy, ArrayRef< Type * > Tys) const
bool AllowExpensiveTripCount
Allow emitting expensive instructions (such as divisions) when computing the trip count of a loop for...
unsigned getAddressComputationCost(Type *Ty, bool IsComplex=false) const
#define false
Definition: ConvertUTF.c:65
virtual unsigned getMaxInterleaveFactor(unsigned VF)=0
Choose alternate elements from vector.
virtual unsigned getCallInstrCost(Function *F, Type *RetTy, ArrayRef< Type * > Tys)=0
virtual unsigned getUserCost(const User *U)=0
unsigned getMaskedMemoryOpCost(unsigned Opcode, Type *Src, unsigned Alignment, unsigned AddressSpace) const
FunctionType - Class to represent function types.
Definition: DerivedTypes.h:96
bool isTypeLegal(Type *Ty) const
Return true if this type is legal.
PopcntSupportKind
Flags indicating the kind of support for population count.
unsigned getRegisterBitWidth(bool Vector) const
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: ArrayRef.h:31
virtual unsigned getRegisterBitWidth(bool Vector)=0
virtual bool isLegalAddImmediate(int64_t Imm)=0
unsigned getUserCost(const User *U) const
Estimate the cost of a given IR user when lowered.
void getUnrollingPreferences(Loop *L, UnrollingPreferences &UP) const
Get target-customized preferences for the generic loop unrolling transformation.
Reverse the order of the vector.
virtual int getScalingFactorCost(Type *Ty, GlobalValue *BaseGV, int64_t BaseOffset, bool HasBaseReg, int64_t Scale, unsigned AddrSpace)=0
ExtractSubvector Index indicates start offset.
virtual unsigned getJumpBufSize()=0
bool isLegalAddressingMode(Type *Ty, GlobalValue *BaseGV, int64_t BaseOffset, bool HasBaseReg, int64_t Scale, unsigned AddrSpace=0) const
Return true if the addressing mode represented by AM is legal for this target, for a load/store of th...
unsigned getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy=nullptr) const
virtual unsigned getGEPCost(const Value *Ptr, ArrayRef< const Value * > Operands)=0
Wrapper pass for TargetTransformInfo.
An abstract set of preserved analyses following a transformation pass run.
Definition: PassManager.h:69
virtual unsigned getOperationCost(unsigned Opcode, Type *Ty, Type *OpTy)=0
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:45
virtual unsigned getIntrinsicInstrCost(Intrinsic::ID ID, Type *RetTy, ArrayRef< Type * > Tys)=0
Expected to fold away in lowering.
unsigned DynamicCostSavingsDiscount
The discount applied to the unrolled cost when the dynamic cost savings of unrolling exceed the Perce...
TargetIRAnalysis()
Default construct a target IR analysis.
virtual unsigned getIntImmCost(const APInt &Imm, Type *Ty)=0
virtual unsigned getMemoryOpCost(unsigned Opcode, Type *Src, unsigned Alignment, unsigned AddressSpace)=0
virtual PopcntSupportKind getPopcntSupport(unsigned IntTyWidthInBit)=0
virtual bool isProfitableToHoist(Instruction *I)=0
bool enableAggressiveInterleaving(bool LoopHasReductions) const
Don't restrict interleaved unrolling to small loops.
unsigned Count
A forced unrolling factor (the number of concatenated bodies of the original loop in the unrolled loo...
TargetIRAnalysis(const TargetIRAnalysis &Arg)
SI Fold Operands
virtual bool isLegalMaskedLoad(Type *DataType, int Consecutive)=0
bool isLegalMaskedStore(Type *DataType, int Consecutive) const
Return true if the target works with masked instruction AVX2 allows masks for consecutive load and st...
virtual bool haveFastSqrt(Type *Ty)=0
unsigned getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src) const
virtual unsigned getNumberOfRegisters(bool Vector)=0
unsigned getIntrinsicInstrCost(Intrinsic::ID ID, Type *RetTy, ArrayRef< Type * > Tys) const
int getScalingFactorCost(Type *Ty, GlobalValue *BaseGV, int64_t BaseOffset, bool HasBaseReg, int64_t Scale, unsigned AddrSpace=0) const
Return the cost of the scaling factor used in the addressing mode represented by AM for this target...
OperandValueProperties
Additional properties of an operand's values.
Value * getOrCreateResultFromMemIntrinsic(IntrinsicInst *Inst, Type *ExpectedType) const
virtual unsigned getCallCost(FunctionType *FTy, int NumArgs)=0
virtual unsigned getCFInstrCost(unsigned Opcode)=0
unsigned getMemoryOpCost(unsigned Opcode, Type *Src, unsigned Alignment, unsigned AddressSpace) const
static StringRef name()
Provide access to a name for this pass for debugging purposes.
ImmutablePass class - This class is used to provide information that does not need to be run...
Definition: Pass.h:262
This pass provides access to the codegen interfaces that are needed for IR-level transformations.
bool hasCompatibleFunctionAttributes(const Function *Caller, const Function *Callee) const
virtual unsigned getIntrinsicCost(Intrinsic::ID IID, Type *RetTy, ArrayRef< Type * > ParamTys)=0
virtual unsigned getArithmeticInstrCost(unsigned Opcode, Type *Ty, OperandValueKind Opd1Info, OperandValueKind Opd2Info, OperandValueProperties Opd1PropInfo, OperandValueProperties Opd2PropInfo)=0
AddressSpace
Definition: NVPTXBaseInfo.h:22
virtual unsigned getVectorInstrCost(unsigned Opcode, Type *Val, unsigned Index)=0
unsigned PercentDynamicCostSavedThreshold
If complete unrolling will reduce the cost of the loop below its expected dynamic cost while rolled b...
unsigned getShuffleCost(ShuffleKind Kind, Type *Tp, int Index=0, Type *SubTp=nullptr) const
bool Runtime
Allow runtime unrolling (unrolling of loops to expand the size of the loop body even when the number ...
virtual bool getTgtMemIntrinsic(IntrinsicInst *Inst, MemIntrinsicInfo &Info)=0
bool haveFastSqrt(Type *Ty) const
Return true if the hardware has a fast square-root instruction.
bool getTgtMemIntrinsic(IntrinsicInst *Inst, MemIntrinsicInfo &Info) const
Class for arbitrary precision integers.
Definition: APInt.h:73
unsigned getJumpBufAlignment() const
Returns the target's jmp_buf alignment in bytes.
virtual unsigned getInterleavedMemoryOpCost(unsigned Opcode, Type *VecTy, unsigned Factor, ArrayRef< unsigned > Indices, unsigned Alignment, unsigned AddressSpace)=0
TargetTransformInfo(T Impl)
Construct a TTI object using a type implementing the Concept API below.
bool invalidate(Function &, const PreservedAnalyses &)
Handle the invalidation of this information.
could "use" a pointer
bool isLegalICmpImmediate(int64_t Imm) const
Return true if the specified immediate is legal icmp immediate, that is the target has icmp instructi...
bool shouldBuildLookupTables() const
Return true if switches should be turned into lookup tables for the target.
unsigned Threshold
The cost threshold for the unrolled loop.
virtual bool isTypeLegal(Type *Ty)=0
unsigned getReductionCost(unsigned Opcode, Type *Ty, bool IsPairwiseForm) const
Calculate the cost of performing a vector reduction.
Parameters that control the generic loop unrolling transformation.
unsigned OptSizeThreshold
The cost threshold for the unrolled loop when optimizing for size (set to UINT_MAX to disable)...
TargetIRAnalysis(TargetIRAnalysis &&Arg)
#define I(x, y, z)
Definition: MD5.cpp:54
virtual bool isSourceOfDivergence(const Value *V)=0
unsigned getIntImmCost(const APInt &Imm, Type *Ty) const
Return the expected cost of materializing for the given integer immediate of the specified type...
TargetCostConstants
Underlying constants for 'cost' values in this interface.
virtual Value * getOrCreateResultFromMemIntrinsic(IntrinsicInst *Inst, Type *ExpectedType)=0
virtual unsigned getReductionCost(unsigned Opcode, Type *Ty, bool IsPairwiseForm)=0
InsertSubvector. Index indicates start offset.
bool isLoweredToCall(const Function *F) const
Test whether calls to a function lower to actual program function calls.
The cost of a typical 'add' instruction.
const ARM::ArchExtKind Kind
TargetTransformInfo Result
virtual unsigned getFPOpCost(Type *Ty)=0
LLVM Value Representation.
Definition: Value.h:69
virtual unsigned getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src)=0
unsigned getVectorInstrCost(unsigned Opcode, Type *Val, unsigned Index=-1) const
bool isTruncateFree(Type *Ty1, Type *Ty2) const
Return true if it's free to truncate a value of type Ty1 to type Ty2.
Broadcast element 0 to all other elements.
unsigned getNumberOfRegisters(bool Vector) const
print Print MemDeps of function
unsigned getIntrinsicCost(Intrinsic::ID IID, Type *RetTy, ArrayRef< Type * > ParamTys) const
Estimate the cost of an intrinsic when lowered.
OperandValueKind
Additional information about an operand's possible values.
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:40
virtual bool isLegalAddressingMode(Type *Ty, GlobalValue *BaseGV, int64_t BaseOffset, bool HasBaseReg, int64_t Scale, unsigned AddrSpace)=0
virtual unsigned getNumberOfParts(Type *Tp)=0
virtual unsigned getJumpBufAlignment()=0
unsigned getCostOfKeepingLiveOverCall(ArrayRef< Type * > Tys) const
virtual unsigned getAddressComputationCost(Type *Ty, bool IsComplex)=0
Information about a load/store intrinsic defined by the target.
The cost of a 'div' instruction on x86.
bool isProfitableToHoist(Instruction *I) const
Return true if it is profitable to hoist instruction in the then/else to before if.
unsigned getFPOpCost(Type *Ty) const
Return the expected cost of supporting the floating point operation of the specified type...
IntrinsicInst - A useful wrapper class for inspecting calls to intrinsic functions.
Definition: IntrinsicInst.h:37
ShuffleKind
The various kinds of shuffle patterns for vector queries.