1be04929f7fd76a921540e9901f24563e51dc1219Chandler Carruth//===- llvm/Analysis/TargetTransformInfo.h ----------------------*- C++ -*-===//
2cbd9a19b5d6ff93efa82c467508ede78b8af3bacNadav Rotem//
3cbd9a19b5d6ff93efa82c467508ede78b8af3bacNadav Rotem//                     The LLVM Compiler Infrastructure
4cbd9a19b5d6ff93efa82c467508ede78b8af3bacNadav Rotem//
5cbd9a19b5d6ff93efa82c467508ede78b8af3bacNadav Rotem// This file is distributed under the University of Illinois Open Source
6cbd9a19b5d6ff93efa82c467508ede78b8af3bacNadav Rotem// License. See LICENSE.TXT for details.
7cbd9a19b5d6ff93efa82c467508ede78b8af3bacNadav Rotem//
8cbd9a19b5d6ff93efa82c467508ede78b8af3bacNadav Rotem//===----------------------------------------------------------------------===//
9cbd9a19b5d6ff93efa82c467508ede78b8af3bacNadav Rotem//
10cbd9a19b5d6ff93efa82c467508ede78b8af3bacNadav Rotem// This pass exposes codegen information to IR-level passes. Every
11cbd9a19b5d6ff93efa82c467508ede78b8af3bacNadav Rotem// transformation that uses codegen information is broken into three parts:
12cbd9a19b5d6ff93efa82c467508ede78b8af3bacNadav Rotem// 1. The IR-level analysis pass.
13cbd9a19b5d6ff93efa82c467508ede78b8af3bacNadav Rotem// 2. The IR-level transformation interface which provides the needed
14cbd9a19b5d6ff93efa82c467508ede78b8af3bacNadav Rotem//    information.
15cbd9a19b5d6ff93efa82c467508ede78b8af3bacNadav Rotem// 3. Codegen-level implementation which uses target-specific hooks.
16cbd9a19b5d6ff93efa82c467508ede78b8af3bacNadav Rotem//
17cbd9a19b5d6ff93efa82c467508ede78b8af3bacNadav Rotem// This file defines #2, which is the interface that IR-level transformations
18cbd9a19b5d6ff93efa82c467508ede78b8af3bacNadav Rotem// use for querying the codegen.
19cbd9a19b5d6ff93efa82c467508ede78b8af3bacNadav Rotem//
20cbd9a19b5d6ff93efa82c467508ede78b8af3bacNadav Rotem//===----------------------------------------------------------------------===//
21cbd9a19b5d6ff93efa82c467508ede78b8af3bacNadav Rotem
22674be02d525d4e24bc6943ed9274958c580bcfbcJakub Staszak#ifndef LLVM_ANALYSIS_TARGETTRANSFORMINFO_H
23674be02d525d4e24bc6943ed9274958c580bcfbcJakub Staszak#define LLVM_ANALYSIS_TARGETTRANSFORMINFO_H
24cbd9a19b5d6ff93efa82c467508ede78b8af3bacNadav Rotem
25be04929f7fd76a921540e9901f24563e51dc1219Chandler Carruth#include "llvm/IR/Intrinsics.h"
26255f89faee13dc491cb64fbeae3c763e7e2ea4e6Chandler Carruth#include "llvm/Pass.h"
27cbd9a19b5d6ff93efa82c467508ede78b8af3bacNadav Rotem#include "llvm/Support/DataTypes.h"
28cbd9a19b5d6ff93efa82c467508ede78b8af3bacNadav Rotem
29cbd9a19b5d6ff93efa82c467508ede78b8af3bacNadav Rotemnamespace llvm {
30cbd9a19b5d6ff93efa82c467508ede78b8af3bacNadav Rotem
31e939a066c85a21e86d32e0a57fd16f4188576633Jakub Staszakclass GlobalValue;
324f7e2c38e864d7eaeb407ac501478e9579624d1bHal Finkelclass Loop;
33e939a066c85a21e86d32e0a57fd16f4188576633Jakub Staszakclass Type;
34e939a066c85a21e86d32e0a57fd16f4188576633Jakub Staszakclass User;
35e939a066c85a21e86d32e0a57fd16f4188576633Jakub Staszakclass Value;
36e939a066c85a21e86d32e0a57fd16f4188576633Jakub Staszak
377bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth/// TargetTransformInfo - This pass provides access to the codegen
387bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth/// interfaces that are needed for IR-level transformations.
397bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruthclass TargetTransformInfo {
407bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruthprotected:
417bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth  /// \brief The TTI instance one level down the stack.
427bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth  ///
437bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth  /// This is used to implement the default behavior all of the methods which
447bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth  /// is to delegate up through the stack of TTIs until one can answer the
457bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth  /// query.
46aeef83c6afa1e18d1cf9d359cc678ca0ad556175Chandler Carruth  TargetTransformInfo *PrevTTI;
477bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth
48aeef83c6afa1e18d1cf9d359cc678ca0ad556175Chandler Carruth  /// \brief The top of the stack of TTI analyses available.
49aeef83c6afa1e18d1cf9d359cc678ca0ad556175Chandler Carruth  ///
50aeef83c6afa1e18d1cf9d359cc678ca0ad556175Chandler Carruth  /// This is a convenience routine maintained as TTI analyses become available
51aeef83c6afa1e18d1cf9d359cc678ca0ad556175Chandler Carruth  /// that complements the PrevTTI delegation chain. When one part of an
52aeef83c6afa1e18d1cf9d359cc678ca0ad556175Chandler Carruth  /// analysis pass wants to query another part of the analysis pass it can use
53aeef83c6afa1e18d1cf9d359cc678ca0ad556175Chandler Carruth  /// this to start back at the top of the stack.
54aeef83c6afa1e18d1cf9d359cc678ca0ad556175Chandler Carruth  TargetTransformInfo *TopTTI;
55aeef83c6afa1e18d1cf9d359cc678ca0ad556175Chandler Carruth
56aeef83c6afa1e18d1cf9d359cc678ca0ad556175Chandler Carruth  /// All pass subclasses must in their initializePass routine call
57aeef83c6afa1e18d1cf9d359cc678ca0ad556175Chandler Carruth  /// pushTTIStack with themselves to update the pointers tracking the previous
58aeef83c6afa1e18d1cf9d359cc678ca0ad556175Chandler Carruth  /// TTI instance in the analysis group's stack, and the top of the analysis
59aeef83c6afa1e18d1cf9d359cc678ca0ad556175Chandler Carruth  /// group's stack.
60aeef83c6afa1e18d1cf9d359cc678ca0ad556175Chandler Carruth  void pushTTIStack(Pass *P);
61aeef83c6afa1e18d1cf9d359cc678ca0ad556175Chandler Carruth
627bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth  /// All pass subclasses must call TargetTransformInfo::getAnalysisUsage.
637bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth  virtual void getAnalysisUsage(AnalysisUsage &AU) const;
64cbd9a19b5d6ff93efa82c467508ede78b8af3bacNadav Rotem
65cbd9a19b5d6ff93efa82c467508ede78b8af3bacNadav Rotempublic:
667bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth  /// This class is intended to be subclassed by real implementations.
677bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth  virtual ~TargetTransformInfo() = 0;
687bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth
691e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth  /// \name Generic Target Information
701e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth  /// @{
711e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth
721e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth  /// \brief Underlying constants for 'cost' values in this interface.
731e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth  ///
741e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth  /// Many APIs in this interface return a cost. This enum defines the
751e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth  /// fundamental values that should be used to interpret (and produce) those
761e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth  /// costs. The costs are returned as an unsigned rather than a member of this
771e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth  /// enumeration because it is expected that the cost of one IR instruction
78f84606732c76899af54c295ec987c96c88452747Jakub Staszak  /// may have a multiplicative factor to it or otherwise won't fit directly
791e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth  /// into the enum. Moreover, it is common to sum or average costs which works
801e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth  /// better as simple integral values. Thus this enum only provides constants.
811e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth  ///
821e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth  /// Note that these costs should usually reflect the intersection of code-size
831e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth  /// cost and execution cost. A free instruction is typically one that folds
841e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth  /// into another instruction. For example, reg-to-reg moves can often be
851e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth  /// skipped by renaming the registers in the CPU, but they still are encoded
861e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth  /// and thus wouldn't be considered 'free' here.
871e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth  enum TargetCostConstants {
881e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth    TCC_Free = 0,       ///< Expected to fold away in lowering.
891e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth    TCC_Basic = 1,      ///< The cost of a typical 'add' instruction.
90c61aa59bcc62019b8e31fcbb3582255be3a63052Chandler Carruth    TCC_Expensive = 4   ///< The cost of a 'div' instruction on x86.
911e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth  };
921e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth
931e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth  /// \brief Estimate the cost of a specific operation when lowered.
941e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth  ///
951e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth  /// Note that this is designed to work on an arbitrary synthetic opcode, and
961e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth  /// thus work for hypothetical queries before an instruction has even been
971e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth  /// formed. However, this does *not* work for GEPs, and must not be called
981e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth  /// for a GEP instruction. Instead, use the dedicated getGEPCost interface as
991e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth  /// analyzing a GEP's cost required more information.
1001e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth  ///
1011e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth  /// Typically only the result type is required, and the operand type can be
1021e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth  /// omitted. However, if the opcode is one of the cast instructions, the
1031e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth  /// operand type is required.
1041e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth  ///
1051e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth  /// The returned cost is defined in terms of \c TargetCostConstants, see its
1061e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth  /// comments for a detailed explanation of the cost values.
1071e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth  virtual unsigned getOperationCost(unsigned Opcode, Type *Ty,
108dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines                                    Type *OpTy = nullptr) const;
1091e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth
1101e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth  /// \brief Estimate the cost of a GEP operation when lowered.
1111e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth  ///
1121e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth  /// The contract for this function is the same as \c getOperationCost except
1131e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth  /// that it supports an interface that provides extra information specific to
1141e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth  /// the GEP operation.
1151e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth  virtual unsigned getGEPCost(const Value *Ptr,
1161e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth                              ArrayRef<const Value *> Operands) const;
1171e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth
11813086a658ae06046ded902229f9918b8bad505bdChandler Carruth  /// \brief Estimate the cost of a function call when lowered.
11913086a658ae06046ded902229f9918b8bad505bdChandler Carruth  ///
12013086a658ae06046ded902229f9918b8bad505bdChandler Carruth  /// The contract for this is the same as \c getOperationCost except that it
12113086a658ae06046ded902229f9918b8bad505bdChandler Carruth  /// supports an interface that provides extra information specific to call
12213086a658ae06046ded902229f9918b8bad505bdChandler Carruth  /// instructions.
12313086a658ae06046ded902229f9918b8bad505bdChandler Carruth  ///
12413086a658ae06046ded902229f9918b8bad505bdChandler Carruth  /// This is the most basic query for estimating call cost: it only knows the
12513086a658ae06046ded902229f9918b8bad505bdChandler Carruth  /// function type and (potentially) the number of arguments at the call site.
12613086a658ae06046ded902229f9918b8bad505bdChandler Carruth  /// The latter is only interesting for varargs function types.
12713086a658ae06046ded902229f9918b8bad505bdChandler Carruth  virtual unsigned getCallCost(FunctionType *FTy, int NumArgs = -1) const;
12813086a658ae06046ded902229f9918b8bad505bdChandler Carruth
12913086a658ae06046ded902229f9918b8bad505bdChandler Carruth  /// \brief Estimate the cost of calling a specific function when lowered.
13013086a658ae06046ded902229f9918b8bad505bdChandler Carruth  ///
13113086a658ae06046ded902229f9918b8bad505bdChandler Carruth  /// This overload adds the ability to reason about the particular function
13213086a658ae06046ded902229f9918b8bad505bdChandler Carruth  /// being called in the event it is a library call with special lowering.
13313086a658ae06046ded902229f9918b8bad505bdChandler Carruth  virtual unsigned getCallCost(const Function *F, int NumArgs = -1) const;
13413086a658ae06046ded902229f9918b8bad505bdChandler Carruth
13513086a658ae06046ded902229f9918b8bad505bdChandler Carruth  /// \brief Estimate the cost of calling a specific function when lowered.
13613086a658ae06046ded902229f9918b8bad505bdChandler Carruth  ///
13713086a658ae06046ded902229f9918b8bad505bdChandler Carruth  /// This overload allows specifying a set of candidate argument values.
13813086a658ae06046ded902229f9918b8bad505bdChandler Carruth  virtual unsigned getCallCost(const Function *F,
13913086a658ae06046ded902229f9918b8bad505bdChandler Carruth                               ArrayRef<const Value *> Arguments) const;
14013086a658ae06046ded902229f9918b8bad505bdChandler Carruth
14113086a658ae06046ded902229f9918b8bad505bdChandler Carruth  /// \brief Estimate the cost of an intrinsic when lowered.
14213086a658ae06046ded902229f9918b8bad505bdChandler Carruth  ///
14313086a658ae06046ded902229f9918b8bad505bdChandler Carruth  /// Mirrors the \c getCallCost method but uses an intrinsic identifier.
14413086a658ae06046ded902229f9918b8bad505bdChandler Carruth  virtual unsigned getIntrinsicCost(Intrinsic::ID IID, Type *RetTy,
14513086a658ae06046ded902229f9918b8bad505bdChandler Carruth                                    ArrayRef<Type *> ParamTys) const;
14613086a658ae06046ded902229f9918b8bad505bdChandler Carruth
14713086a658ae06046ded902229f9918b8bad505bdChandler Carruth  /// \brief Estimate the cost of an intrinsic when lowered.
14813086a658ae06046ded902229f9918b8bad505bdChandler Carruth  ///
14913086a658ae06046ded902229f9918b8bad505bdChandler Carruth  /// Mirrors the \c getCallCost method but uses an intrinsic identifier.
15013086a658ae06046ded902229f9918b8bad505bdChandler Carruth  virtual unsigned getIntrinsicCost(Intrinsic::ID IID, Type *RetTy,
15113086a658ae06046ded902229f9918b8bad505bdChandler Carruth                                    ArrayRef<const Value *> Arguments) const;
15213086a658ae06046ded902229f9918b8bad505bdChandler Carruth
1531e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth  /// \brief Estimate the cost of a given IR user when lowered.
1541e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth  ///
1551e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth  /// This can estimate the cost of either a ConstantExpr or Instruction when
1561e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth  /// lowered. It has two primary advantages over the \c getOperationCost and
1571e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth  /// \c getGEPCost above, and one significant disadvantage: it can only be
1581e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth  /// used when the IR construct has already been formed.
1591e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth  ///
1601e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth  /// The advantages are that it can inspect the SSA use graph to reason more
1611e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth  /// accurately about the cost. For example, all-constant-GEPs can often be
1621e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth  /// folded into a load or other instruction, but if they are used in some
1631e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth  /// other context they may not be folded. This routine can distinguish such
1641e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth  /// cases.
1651e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth  ///
1661e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth  /// The returned cost is defined in terms of \c TargetCostConstants, see its
1671e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth  /// comments for a detailed explanation of the cost values.
1681e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth  virtual unsigned getUserCost(const User *U) const;
1691e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth
17057e6b2d1f3de0bf459e96f7038e692d624f7e580Tom Stellard  /// \brief hasBranchDivergence - Return true if branch divergence exists.
17157e6b2d1f3de0bf459e96f7038e692d624f7e580Tom Stellard  /// Branch divergence has a significantly negative impact on GPU performance
17257e6b2d1f3de0bf459e96f7038e692d624f7e580Tom Stellard  /// when threads in the same wavefront take different paths due to conditional
17357e6b2d1f3de0bf459e96f7038e692d624f7e580Tom Stellard  /// branches.
17457e6b2d1f3de0bf459e96f7038e692d624f7e580Tom Stellard  virtual bool hasBranchDivergence() const;
17557e6b2d1f3de0bf459e96f7038e692d624f7e580Tom Stellard
17613086a658ae06046ded902229f9918b8bad505bdChandler Carruth  /// \brief Test whether calls to a function lower to actual program function
17713086a658ae06046ded902229f9918b8bad505bdChandler Carruth  /// calls.
17813086a658ae06046ded902229f9918b8bad505bdChandler Carruth  ///
17913086a658ae06046ded902229f9918b8bad505bdChandler Carruth  /// The idea is to test whether the program is likely to require a 'call'
18013086a658ae06046ded902229f9918b8bad505bdChandler Carruth  /// instruction or equivalent in order to call the given function.
18113086a658ae06046ded902229f9918b8bad505bdChandler Carruth  ///
18213086a658ae06046ded902229f9918b8bad505bdChandler Carruth  /// FIXME: It's not clear that this is a good or useful query API. Client's
18313086a658ae06046ded902229f9918b8bad505bdChandler Carruth  /// should probably move to simpler cost metrics using the above.
18413086a658ae06046ded902229f9918b8bad505bdChandler Carruth  /// Alternatively, we could split the cost interface into distinct code-size
18513086a658ae06046ded902229f9918b8bad505bdChandler Carruth  /// and execution-speed costs. This would allow modelling the core of this
18613086a658ae06046ded902229f9918b8bad505bdChandler Carruth  /// query more accurately as the a call is a single small instruction, but
18713086a658ae06046ded902229f9918b8bad505bdChandler Carruth  /// incurs significant execution cost.
18813086a658ae06046ded902229f9918b8bad505bdChandler Carruth  virtual bool isLoweredToCall(const Function *F) const;
18913086a658ae06046ded902229f9918b8bad505bdChandler Carruth
1904f7e2c38e864d7eaeb407ac501478e9579624d1bHal Finkel  /// Parameters that control the generic loop unrolling transformation.
1914f7e2c38e864d7eaeb407ac501478e9579624d1bHal Finkel  struct UnrollingPreferences {
1924f7e2c38e864d7eaeb407ac501478e9579624d1bHal Finkel    /// The cost threshold for the unrolled loop, compared to
1934f7e2c38e864d7eaeb407ac501478e9579624d1bHal Finkel    /// CodeMetrics.NumInsts aggregated over all basic blocks in the loop body.
1944f7e2c38e864d7eaeb407ac501478e9579624d1bHal Finkel    /// The unrolling factor is set such that the unrolled loop body does not
1954f7e2c38e864d7eaeb407ac501478e9579624d1bHal Finkel    /// exceed this cost. Set this to UINT_MAX to disable the loop body cost
1964f7e2c38e864d7eaeb407ac501478e9579624d1bHal Finkel    /// restriction.
1974f7e2c38e864d7eaeb407ac501478e9579624d1bHal Finkel    unsigned Threshold;
1984f7e2c38e864d7eaeb407ac501478e9579624d1bHal Finkel    /// The cost threshold for the unrolled loop when optimizing for size (set
1994f7e2c38e864d7eaeb407ac501478e9579624d1bHal Finkel    /// to UINT_MAX to disable).
2004f7e2c38e864d7eaeb407ac501478e9579624d1bHal Finkel    unsigned OptSizeThreshold;
20136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    /// The cost threshold for the unrolled loop, like Threshold, but used
20236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    /// for partial/runtime unrolling (set to UINT_MAX to disable).
20336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    unsigned PartialThreshold;
20436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    /// The cost threshold for the unrolled loop when optimizing for size, like
20536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    /// OptSizeThreshold, but used for partial/runtime unrolling (set to UINT_MAX
20636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    /// to disable).
20736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    unsigned PartialOptSizeThreshold;
2084f7e2c38e864d7eaeb407ac501478e9579624d1bHal Finkel    /// A forced unrolling factor (the number of concatenated bodies of the
2094f7e2c38e864d7eaeb407ac501478e9579624d1bHal Finkel    /// original loop in the unrolled loop body). When set to 0, the unrolling
2104f7e2c38e864d7eaeb407ac501478e9579624d1bHal Finkel    /// transformation will select an unrolling factor based on the current cost
2114f7e2c38e864d7eaeb407ac501478e9579624d1bHal Finkel    /// threshold and other factors.
2124f7e2c38e864d7eaeb407ac501478e9579624d1bHal Finkel    unsigned Count;
21336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    // Set the maximum unrolling factor. The unrolling factor may be selected
21436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    // using the appropriate cost threshold, but may not exceed this number
21536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    // (set to UINT_MAX to disable). This does not apply in cases where the
21636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    // loop is being fully unrolled.
21736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    unsigned MaxCount;
2184f7e2c38e864d7eaeb407ac501478e9579624d1bHal Finkel    /// Allow partial unrolling (unrolling of loops to expand the size of the
2194f7e2c38e864d7eaeb407ac501478e9579624d1bHal Finkel    /// loop body, not only to eliminate small constant-trip-count loops).
2204f7e2c38e864d7eaeb407ac501478e9579624d1bHal Finkel    bool     Partial;
2214f7e2c38e864d7eaeb407ac501478e9579624d1bHal Finkel    /// Allow runtime unrolling (unrolling of loops to expand the size of the
2224f7e2c38e864d7eaeb407ac501478e9579624d1bHal Finkel    /// loop body even when the number of loop iterations is not known at compile
2234f7e2c38e864d7eaeb407ac501478e9579624d1bHal Finkel    /// time).
2244f7e2c38e864d7eaeb407ac501478e9579624d1bHal Finkel    bool     Runtime;
2254f7e2c38e864d7eaeb407ac501478e9579624d1bHal Finkel  };
2264f7e2c38e864d7eaeb407ac501478e9579624d1bHal Finkel
2274f7e2c38e864d7eaeb407ac501478e9579624d1bHal Finkel  /// \brief Get target-customized preferences for the generic loop unrolling
2284f7e2c38e864d7eaeb407ac501478e9579624d1bHal Finkel  /// transformation. The caller will initialize UP with the current
2294f7e2c38e864d7eaeb407ac501478e9579624d1bHal Finkel  /// target-independent defaults.
2304f7e2c38e864d7eaeb407ac501478e9579624d1bHal Finkel  virtual void getUnrollingPreferences(Loop *L, UnrollingPreferences &UP) const;
2314f7e2c38e864d7eaeb407ac501478e9579624d1bHal Finkel
2321e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth  /// @}
2331e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth
2347bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth  /// \name Scalar Target Information
2357bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth  /// @{
2367bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth
237d1b8ef97c47d347f2a2261a0d6de4872f248321fChandler Carruth  /// \brief Flags indicating the kind of support for population count.
238d1b8ef97c47d347f2a2261a0d6de4872f248321fChandler Carruth  ///
239d1b8ef97c47d347f2a2261a0d6de4872f248321fChandler Carruth  /// Compared to the SW implementation, HW support is supposed to
240d1b8ef97c47d347f2a2261a0d6de4872f248321fChandler Carruth  /// significantly boost the performance when the population is dense, and it
241d1b8ef97c47d347f2a2261a0d6de4872f248321fChandler Carruth  /// may or may not degrade performance if the population is sparse. A HW
242d1b8ef97c47d347f2a2261a0d6de4872f248321fChandler Carruth  /// support is considered as "Fast" if it can outperform, or is on a par
243f84606732c76899af54c295ec987c96c88452747Jakub Staszak  /// with, SW implementation when the population is sparse; otherwise, it is
244d1b8ef97c47d347f2a2261a0d6de4872f248321fChandler Carruth  /// considered as "Slow".
245d1b8ef97c47d347f2a2261a0d6de4872f248321fChandler Carruth  enum PopcntSupportKind {
246d1b8ef97c47d347f2a2261a0d6de4872f248321fChandler Carruth    PSK_Software,
247d1b8ef97c47d347f2a2261a0d6de4872f248321fChandler Carruth    PSK_SlowHardware,
248d1b8ef97c47d347f2a2261a0d6de4872f248321fChandler Carruth    PSK_FastHardware
2495518a1355b8b09bf92419b65ea4e4854734b0ebcShuxin Yang  };
2505518a1355b8b09bf92419b65ea4e4854734b0ebcShuxin Yang
25136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  /// \brief Return true if the specified immediate is legal add immediate, that
25236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  /// is the target has add instructions which can add a register with the
25336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  /// immediate without having to materialize the immediate into a register.
2547bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth  virtual bool isLegalAddImmediate(int64_t Imm) const;
2557bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth
25636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  /// \brief Return true if the specified immediate is legal icmp immediate,
25736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  /// that is the target has icmp instructions which can compare a register
25836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  /// against the immediate without having to materialize the immediate into a
25936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  /// register.
2607bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth  virtual bool isLegalICmpImmediate(int64_t Imm) const;
2617bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth
26236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  /// \brief Return true if the addressing mode represented by AM is legal for
26336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  /// this target, for a load/store of the specified type.
264cbd9a19b5d6ff93efa82c467508ede78b8af3bacNadav Rotem  /// The type may be VoidTy, in which case only return true if the addressing
265cbd9a19b5d6ff93efa82c467508ede78b8af3bacNadav Rotem  /// mode is legal for a load/store of any legal type.
266cbd9a19b5d6ff93efa82c467508ede78b8af3bacNadav Rotem  /// TODO: Handle pre/postinc as well.
26764e407be0d91916d71c9259f62ba5c1f4b2993caChandler Carruth  virtual bool isLegalAddressingMode(Type *Ty, GlobalValue *BaseGV,
26864e407be0d91916d71c9259f62ba5c1f4b2993caChandler Carruth                                     int64_t BaseOffset, bool HasBaseReg,
2697bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth                                     int64_t Scale) const;
2707bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth
27106f5ebc5a1604b01689cf2d482dd05f956538af6Quentin Colombet  /// \brief Return the cost of the scaling factor used in the addressing
27206f5ebc5a1604b01689cf2d482dd05f956538af6Quentin Colombet  /// mode represented by AM for this target, for a load/store
27306f5ebc5a1604b01689cf2d482dd05f956538af6Quentin Colombet  /// of the specified type.
27406f5ebc5a1604b01689cf2d482dd05f956538af6Quentin Colombet  /// If the AM is supported, the return value must be >= 0.
27506f5ebc5a1604b01689cf2d482dd05f956538af6Quentin Colombet  /// If the AM is not supported, it returns a negative value.
27606f5ebc5a1604b01689cf2d482dd05f956538af6Quentin Colombet  /// TODO: Handle pre/postinc as well.
27706f5ebc5a1604b01689cf2d482dd05f956538af6Quentin Colombet  virtual int getScalingFactorCost(Type *Ty, GlobalValue *BaseGV,
27806f5ebc5a1604b01689cf2d482dd05f956538af6Quentin Colombet                                   int64_t BaseOffset, bool HasBaseReg,
27906f5ebc5a1604b01689cf2d482dd05f956538af6Quentin Colombet                                   int64_t Scale) const;
28006f5ebc5a1604b01689cf2d482dd05f956538af6Quentin Colombet
28136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  /// \brief Return true if it's free to truncate a value of type Ty1 to type
28236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  /// Ty2. e.g. On x86 it's free to truncate a i32 value in register EAX to i16
28336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  /// by referencing its sub-register AX.
2847bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth  virtual bool isTruncateFree(Type *Ty1, Type *Ty2) const;
2857bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth
28636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  /// \brief Return true if this type is legal.
2877bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth  virtual bool isTypeLegal(Type *Ty) const;
2887bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth
28936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  /// \brief Returns the target's jmp_buf alignment in bytes.
2907bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth  virtual unsigned getJumpBufAlignment() const;
2917bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth
29236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  /// \brief Returns the target's jmp_buf size in bytes.
2937bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth  virtual unsigned getJumpBufSize() const;
2947bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth
29536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  /// \brief Return true if switches should be turned into lookup tables for the
29636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  /// target.
2977bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth  virtual bool shouldBuildLookupTables() const;
2987bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth
29936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  /// \brief Return hardware support for population count.
300d1b8ef97c47d347f2a2261a0d6de4872f248321fChandler Carruth  virtual PopcntSupportKind getPopcntSupport(unsigned IntTyWidthInBit) const;
3017bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth
30236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  /// \brief Return true if the hardware has a fast square-root instruction.
303a8a7099c1849fcbb4a68642a292fd0250aa46505Richard Sandiford  virtual bool haveFastSqrt(Type *Ty) const;
304a8a7099c1849fcbb4a68642a292fd0250aa46505Richard Sandiford
30536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  /// \brief Return the expected cost of materializing for the given integer
30636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  /// immediate of the specified type.
3077bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth  virtual unsigned getIntImmCost(const APInt &Imm, Type *Ty) const;
308cbd9a19b5d6ff93efa82c467508ede78b8af3bacNadav Rotem
30936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  /// \brief Return the expected cost of materialization for the given integer
31036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  /// immediate of the specified type for a given instruction. The cost can be
31136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  /// zero if the immediate can be folded into the specified instruction.
31236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  virtual unsigned getIntImmCost(unsigned Opc, unsigned Idx, const APInt &Imm,
31336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines                                 Type *Ty) const;
31436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  virtual unsigned getIntImmCost(Intrinsic::ID IID, unsigned Idx,
31536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines                                 const APInt &Imm, Type *Ty) const;
3167bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth  /// @}
3177bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth
3187bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth  /// \name Vector Target Information
3197bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth  /// @{
320270483466124fe1e19d5439e958fef63cebd43cdNadav Rotem
321bb00800ff46e7a2a628d0a6741a7f0422c74c198Chandler Carruth  /// \brief The various kinds of shuffle patterns for vector queries.
322daf7b5c8f2889ddb923544565f07518d504aa574Nadav Rotem  enum ShuffleKind {
323bb00800ff46e7a2a628d0a6741a7f0422c74c198Chandler Carruth    SK_Broadcast,       ///< Broadcast element 0 to all other elements.
324bb00800ff46e7a2a628d0a6741a7f0422c74c198Chandler Carruth    SK_Reverse,         ///< Reverse the order of the vector.
325cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines    SK_Alternate,       ///< Choose alternate elements from vector.
326bb00800ff46e7a2a628d0a6741a7f0422c74c198Chandler Carruth    SK_InsertSubvector, ///< InsertSubvector. Index indicates start offset.
327bb00800ff46e7a2a628d0a6741a7f0422c74c198Chandler Carruth    SK_ExtractSubvector ///< ExtractSubvector Index indicates start offset.
328daf7b5c8f2889ddb923544565f07518d504aa574Nadav Rotem  };
329daf7b5c8f2889ddb923544565f07518d504aa574Nadav Rotem
330135fe6ac5f5b80ef68c19b3ec7bb0063e28f2babBenjamin Kramer  /// \brief Additional information about an operand's possible values.
3316bf4f676413b8f7d97aaff289997aab344180957Arnold Schwaighofer  enum OperandValueKind {
33236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    OK_AnyValue,                 // Operand can have any value.
33336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    OK_UniformValue,             // Operand is uniform (splat of a value).
33436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    OK_UniformConstantValue,     // Operand is uniform constant.
33536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    OK_NonUniformConstantValue   // Operand is a non uniform constant value.
3366bf4f676413b8f7d97aaff289997aab344180957Arnold Schwaighofer  };
3376bf4f676413b8f7d97aaff289997aab344180957Arnold Schwaighofer
338e503319874f57ab4a0354521b03a71cf8e07b866Nadav Rotem  /// \return The number of scalar or vector registers that the target has.
339e503319874f57ab4a0354521b03a71cf8e07b866Nadav Rotem  /// If 'Vectors' is true, it returns the number of vector registers. If it is
340e503319874f57ab4a0354521b03a71cf8e07b866Nadav Rotem  /// set to false, it returns the number of scalar registers.
3417bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth  virtual unsigned getNumberOfRegisters(bool Vector) const;
342e503319874f57ab4a0354521b03a71cf8e07b866Nadav Rotem
34314925e6b885f8bd8cf448627386d412831f4bf1bNadav Rotem  /// \return The width of the largest scalar or vector register type.
34414925e6b885f8bd8cf448627386d412831f4bf1bNadav Rotem  virtual unsigned getRegisterBitWidth(bool Vector) const;
34514925e6b885f8bd8cf448627386d412831f4bf1bNadav Rotem
34683be7b0dd3ae9a3cb22d36ae4c1775972553b94bNadav Rotem  /// \return The maximum unroll factor that the vectorizer should try to
34783be7b0dd3ae9a3cb22d36ae4c1775972553b94bNadav Rotem  /// perform for this target. This number depends on the level of parallelism
34883be7b0dd3ae9a3cb22d36ae4c1775972553b94bNadav Rotem  /// and the number of execution units in the CPU.
34983be7b0dd3ae9a3cb22d36ae4c1775972553b94bNadav Rotem  virtual unsigned getMaximumUnrollFactor() const;
35083be7b0dd3ae9a3cb22d36ae4c1775972553b94bNadav Rotem
351e503319874f57ab4a0354521b03a71cf8e07b866Nadav Rotem  /// \return The expected cost of arithmetic ops, such as mul, xor, fsub, etc.
3526bf4f676413b8f7d97aaff289997aab344180957Arnold Schwaighofer  virtual unsigned getArithmeticInstrCost(unsigned Opcode, Type *Ty,
3536bf4f676413b8f7d97aaff289997aab344180957Arnold Schwaighofer                                  OperandValueKind Opd1Info = OK_AnyValue,
3546bf4f676413b8f7d97aaff289997aab344180957Arnold Schwaighofer                                  OperandValueKind Opd2Info = OK_AnyValue) const;
355a5a3a61c5fdcee972791d4e08441ba6edf131b88Nadav Rotem
356e503319874f57ab4a0354521b03a71cf8e07b866Nadav Rotem  /// \return The cost of a shuffle instruction of kind Kind and of type Tp.
357be76df6ce69ea1a4b6306af6fc06ccada708256dHal Finkel  /// The index and subtype parameters are used by the subvector insertion and
358be76df6ce69ea1a4b6306af6fc06ccada708256dHal Finkel  /// extraction shuffle kinds.
3597bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth  virtual unsigned getShuffleCost(ShuffleKind Kind, Type *Tp, int Index = 0,
360dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines                                  Type *SubTp = nullptr) const;
361270483466124fe1e19d5439e958fef63cebd43cdNadav Rotem
362e503319874f57ab4a0354521b03a71cf8e07b866Nadav Rotem  /// \return The expected cost of cast instructions, such as bitcast, trunc,
363a5a3a61c5fdcee972791d4e08441ba6edf131b88Nadav Rotem  /// zext, etc.
364a5a3a61c5fdcee972791d4e08441ba6edf131b88Nadav Rotem  virtual unsigned getCastInstrCost(unsigned Opcode, Type *Dst,
3657bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth                                    Type *Src) const;
366a5a3a61c5fdcee972791d4e08441ba6edf131b88Nadav Rotem
367f84606732c76899af54c295ec987c96c88452747Jakub Staszak  /// \return The expected cost of control-flow related instructions such as
368a5a3a61c5fdcee972791d4e08441ba6edf131b88Nadav Rotem  /// Phi, Ret, Br.
3697bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth  virtual unsigned getCFInstrCost(unsigned Opcode) const;
370a5a3a61c5fdcee972791d4e08441ba6edf131b88Nadav Rotem
371e503319874f57ab4a0354521b03a71cf8e07b866Nadav Rotem  /// \returns The expected cost of compare and select instructions.
372a5a3a61c5fdcee972791d4e08441ba6edf131b88Nadav Rotem  virtual unsigned getCmpSelInstrCost(unsigned Opcode, Type *ValTy,
373dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines                                      Type *CondTy = nullptr) const;
374a5a3a61c5fdcee972791d4e08441ba6edf131b88Nadav Rotem
375e503319874f57ab4a0354521b03a71cf8e07b866Nadav Rotem  /// \return The expected cost of vector Insert and Extract.
376f1495671605b50a4b0386697fee0b76ebae9d17fNadav Rotem  /// Use -1 to indicate that there is no information on the index value.
377a5a3a61c5fdcee972791d4e08441ba6edf131b88Nadav Rotem  virtual unsigned getVectorInstrCost(unsigned Opcode, Type *Val,
3787bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth                                      unsigned Index = -1) const;
379a5a3a61c5fdcee972791d4e08441ba6edf131b88Nadav Rotem
380e503319874f57ab4a0354521b03a71cf8e07b866Nadav Rotem  /// \return The cost of Load and Store instructions.
381270483466124fe1e19d5439e958fef63cebd43cdNadav Rotem  virtual unsigned getMemoryOpCost(unsigned Opcode, Type *Src,
382270483466124fe1e19d5439e958fef63cebd43cdNadav Rotem                                   unsigned Alignment,
3837bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth                                   unsigned AddressSpace) const;
384270483466124fe1e19d5439e958fef63cebd43cdNadav Rotem
38565457b679ae240c1a37da82c5484dac478c47b6dArnold Schwaighofer  /// \brief Calculate the cost of performing a vector reduction.
38665457b679ae240c1a37da82c5484dac478c47b6dArnold Schwaighofer  ///
38765457b679ae240c1a37da82c5484dac478c47b6dArnold Schwaighofer  /// This is the cost of reducing the vector value of type \p Ty to a scalar
38865457b679ae240c1a37da82c5484dac478c47b6dArnold Schwaighofer  /// value using the operation denoted by \p Opcode. The form of the reduction
38965457b679ae240c1a37da82c5484dac478c47b6dArnold Schwaighofer  /// can either be a pairwise reduction or a reduction that splits the vector
39065457b679ae240c1a37da82c5484dac478c47b6dArnold Schwaighofer  /// at every reduction level.
39165457b679ae240c1a37da82c5484dac478c47b6dArnold Schwaighofer  ///
39265457b679ae240c1a37da82c5484dac478c47b6dArnold Schwaighofer  /// Pairwise:
39365457b679ae240c1a37da82c5484dac478c47b6dArnold Schwaighofer  ///  (v0, v1, v2, v3)
39465457b679ae240c1a37da82c5484dac478c47b6dArnold Schwaighofer  ///  ((v0+v1), (v2, v3), undef, undef)
39565457b679ae240c1a37da82c5484dac478c47b6dArnold Schwaighofer  /// Split:
39665457b679ae240c1a37da82c5484dac478c47b6dArnold Schwaighofer  ///  (v0, v1, v2, v3)
39765457b679ae240c1a37da82c5484dac478c47b6dArnold Schwaighofer  ///  ((v0+v2), (v1+v3), undef, undef)
39865457b679ae240c1a37da82c5484dac478c47b6dArnold Schwaighofer  virtual unsigned getReductionCost(unsigned Opcode, Type *Ty,
39965457b679ae240c1a37da82c5484dac478c47b6dArnold Schwaighofer                                    bool IsPairwiseForm) const;
40065457b679ae240c1a37da82c5484dac478c47b6dArnold Schwaighofer
401e503319874f57ab4a0354521b03a71cf8e07b866Nadav Rotem  /// \returns The cost of Intrinsic instructions.
4027bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth  virtual unsigned getIntrinsicInstrCost(Intrinsic::ID ID, Type *RetTy,
4037bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth                                         ArrayRef<Type *> Tys) const;
404880166684e5af0f5b4bfe26870b9f7813e537354Paul Redmond
405e503319874f57ab4a0354521b03a71cf8e07b866Nadav Rotem  /// \returns The number of pieces into which the provided type must be
406102a7c088c16b8bbed7cf56da9994fa52a9028c5Hal Finkel  /// split during legalization. Zero is returned when the answer is unknown.
4077bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth  virtual unsigned getNumberOfParts(Type *Tp) const;
408cbd9a19b5d6ff93efa82c467508ede78b8af3bacNadav Rotem
409fb55a8fd7c38aa09d9c243d48a8a72d890f36a3dArnold Schwaighofer  /// \returns The cost of the address computation. For most targets this can be
410fb55a8fd7c38aa09d9c243d48a8a72d890f36a3dArnold Schwaighofer  /// merged into the instruction indexing mode. Some targets might want to
411fb55a8fd7c38aa09d9c243d48a8a72d890f36a3dArnold Schwaighofer  /// distinguish between address computation for memory operations on vector
412fb55a8fd7c38aa09d9c243d48a8a72d890f36a3dArnold Schwaighofer  /// types and scalar types. Such targets should override this function.
413c0a11edba6ea46c782672ab3fb4e4ab3dc267a22Arnold Schwaighofer  /// The 'IsComplex' parameter is a hint that the address computation is likely
414c0a11edba6ea46c782672ab3fb4e4ab3dc267a22Arnold Schwaighofer  /// to involve multiple instructions and as such unlikely to be merged into
415c0a11edba6ea46c782672ab3fb4e4ab3dc267a22Arnold Schwaighofer  /// the address indexing mode.
416c0a11edba6ea46c782672ab3fb4e4ab3dc267a22Arnold Schwaighofer  virtual unsigned getAddressComputationCost(Type *Ty,
417c0a11edba6ea46c782672ab3fb4e4ab3dc267a22Arnold Schwaighofer                                             bool IsComplex = false) const;
418fb55a8fd7c38aa09d9c243d48a8a72d890f36a3dArnold Schwaighofer
4197bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth  /// @}
4209eac3912d3e507e0424be72b7888cc14713001e8Chandler Carruth
4217bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth  /// Analysis group identification.
4227bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth  static char ID;
4237bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth};
4249eac3912d3e507e0424be72b7888cc14713001e8Chandler Carruth
4257bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth/// \brief Create the base case instance of a pass in the TTI analysis group.
4267bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth///
427f84606732c76899af54c295ec987c96c88452747Jakub Staszak/// This class provides the base case for the stack of TTI analyzes. It doesn't
4287bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth/// delegate to anything and uses the STTI and VTTI objects passed in to
4297bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth/// satisfy the queries.
430aeef83c6afa1e18d1cf9d359cc678ca0ad556175Chandler CarruthImmutablePass *createNoTargetTransformInfoPass();
4317bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth
432cbd9a19b5d6ff93efa82c467508ede78b8af3bacNadav Rotem} // End llvm namespace
433cbd9a19b5d6ff93efa82c467508ede78b8af3bacNadav Rotem
434cbd9a19b5d6ff93efa82c467508ede78b8af3bacNadav Rotem#endif
435