[multiversion] Remove the cached TargetMachine pointer from the
[oota-llvm.git] / lib / Target / ARM / ARMTargetTransformInfo.h
1 //===-- ARMTargetTransformInfo.h - ARM specific TTI -------------*- 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 file a TargetTransformInfo::Concept conforming object specific to the
11 /// ARM target machine. It uses the target's detailed information to
12 /// provide more precise answers to certain TTI queries, while letting the
13 /// target independent and default TTI implementations handle the rest.
14 ///
15 //===----------------------------------------------------------------------===//
16
17 #ifndef LLVM_LIB_TARGET_ARM_ARMTARGETTRANSFORMINFO_H
18 #define LLVM_LIB_TARGET_ARM_ARMTARGETTRANSFORMINFO_H
19
20 #include "ARM.h"
21 #include "ARMTargetMachine.h"
22 #include "llvm/Analysis/TargetTransformInfo.h"
23 #include "llvm/CodeGen/BasicTTIImpl.h"
24 #include "llvm/Target/TargetLowering.h"
25
26 namespace llvm {
27
28 class ARMTTIImpl : public BasicTTIImplBase<ARMTTIImpl> {
29   typedef BasicTTIImplBase<ARMTTIImpl> BaseT;
30   typedef TargetTransformInfo TTI;
31   friend BaseT;
32
33   const ARMBaseTargetMachine *TM;
34   const ARMSubtarget *ST;
35   const ARMTargetLowering *TLI;
36
37   /// Estimate the overhead of scalarizing an instruction. Insert and Extract
38   /// are set if the result needs to be inserted and/or extracted from vectors.
39   unsigned getScalarizationOverhead(Type *Ty, bool Insert, bool Extract);
40
41   const ARMBaseTargetMachine *getTM() const { return TM; }
42   const ARMTargetLowering *getTLI() const { return TLI; }
43
44 public:
45   explicit ARMTTIImpl(const ARMBaseTargetMachine *TM, Function &F)
46       : BaseT(TM), TM(TM), ST(TM->getSubtargetImpl(F)),
47         TLI(ST->getTargetLowering()) {}
48
49   // Provide value semantics. MSVC requires that we spell all of these out.
50   ARMTTIImpl(const ARMTTIImpl &Arg)
51       : BaseT(static_cast<const BaseT &>(Arg)), TM(Arg.TM), ST(Arg.ST), TLI(Arg.TLI) {}
52   ARMTTIImpl(ARMTTIImpl &&Arg)
53       : BaseT(std::move(static_cast<BaseT &>(Arg))), TM(std::move(Arg.TM)),
54         ST(std::move(Arg.ST)), TLI(std::move(Arg.TLI)) {}
55   ARMTTIImpl &operator=(const ARMTTIImpl &RHS) {
56     BaseT::operator=(static_cast<const BaseT &>(RHS));
57     TM = RHS.TM;
58     ST = RHS.ST;
59     TLI = RHS.TLI;
60     return *this;
61   }
62   ARMTTIImpl &operator=(ARMTTIImpl &&RHS) {
63     BaseT::operator=(std::move(static_cast<BaseT &>(RHS)));
64     TM = std::move(RHS.TM);
65     ST = std::move(RHS.ST);
66     TLI = std::move(RHS.TLI);
67     return *this;
68   }
69
70   /// \name Scalar TTI Implementations
71   /// @{
72
73   using BaseT::getIntImmCost;
74   unsigned getIntImmCost(const APInt &Imm, Type *Ty);
75
76   /// @}
77
78   /// \name Vector TTI Implementations
79   /// @{
80
81   unsigned getNumberOfRegisters(bool Vector) {
82     if (Vector) {
83       if (ST->hasNEON())
84         return 16;
85       return 0;
86     }
87
88     if (ST->isThumb1Only())
89       return 8;
90     return 13;
91   }
92
93   unsigned getRegisterBitWidth(bool Vector) {
94     if (Vector) {
95       if (ST->hasNEON())
96         return 128;
97       return 0;
98     }
99
100     return 32;
101   }
102
103   unsigned getMaxInterleaveFactor() {
104     // These are out of order CPUs:
105     if (ST->isCortexA15() || ST->isSwift())
106       return 2;
107     return 1;
108   }
109
110   unsigned getShuffleCost(TTI::ShuffleKind Kind, Type *Tp, int Index,
111                           Type *SubTp);
112
113   unsigned getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src);
114
115   unsigned getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy);
116
117   unsigned getVectorInstrCost(unsigned Opcode, Type *Val, unsigned Index);
118
119   unsigned getAddressComputationCost(Type *Val, bool IsComplex);
120
121   unsigned getArithmeticInstrCost(
122       unsigned Opcode, Type *Ty,
123       TTI::OperandValueKind Op1Info = TTI::OK_AnyValue,
124       TTI::OperandValueKind Op2Info = TTI::OK_AnyValue,
125       TTI::OperandValueProperties Opd1PropInfo = TTI::OP_None,
126       TTI::OperandValueProperties Opd2PropInfo = TTI::OP_None);
127
128   unsigned getMemoryOpCost(unsigned Opcode, Type *Src, unsigned Alignment,
129                            unsigned AddressSpace);
130
131   /// @}
132 };
133
134 } // end namespace llvm
135
136 #endif