xref: /aosp_15_r20/external/llvm/lib/Target/ARM/ARMTargetTransformInfo.h (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker //===-- ARMTargetTransformInfo.h - ARM specific TTI -------------*- C++ -*-===//
2*9880d681SAndroid Build Coastguard Worker //
3*9880d681SAndroid Build Coastguard Worker //                     The LLVM Compiler Infrastructure
4*9880d681SAndroid Build Coastguard Worker //
5*9880d681SAndroid Build Coastguard Worker // This file is distributed under the University of Illinois Open Source
6*9880d681SAndroid Build Coastguard Worker // License. See LICENSE.TXT for details.
7*9880d681SAndroid Build Coastguard Worker //
8*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===//
9*9880d681SAndroid Build Coastguard Worker /// \file
10*9880d681SAndroid Build Coastguard Worker /// This file a TargetTransformInfo::Concept conforming object specific to the
11*9880d681SAndroid Build Coastguard Worker /// ARM target machine. It uses the target's detailed information to
12*9880d681SAndroid Build Coastguard Worker /// provide more precise answers to certain TTI queries, while letting the
13*9880d681SAndroid Build Coastguard Worker /// target independent and default TTI implementations handle the rest.
14*9880d681SAndroid Build Coastguard Worker ///
15*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===//
16*9880d681SAndroid Build Coastguard Worker 
17*9880d681SAndroid Build Coastguard Worker #ifndef LLVM_LIB_TARGET_ARM_ARMTARGETTRANSFORMINFO_H
18*9880d681SAndroid Build Coastguard Worker #define LLVM_LIB_TARGET_ARM_ARMTARGETTRANSFORMINFO_H
19*9880d681SAndroid Build Coastguard Worker 
20*9880d681SAndroid Build Coastguard Worker #include "ARM.h"
21*9880d681SAndroid Build Coastguard Worker #include "ARMTargetMachine.h"
22*9880d681SAndroid Build Coastguard Worker #include "llvm/Analysis/TargetTransformInfo.h"
23*9880d681SAndroid Build Coastguard Worker #include "llvm/CodeGen/BasicTTIImpl.h"
24*9880d681SAndroid Build Coastguard Worker #include "llvm/Target/TargetLowering.h"
25*9880d681SAndroid Build Coastguard Worker 
26*9880d681SAndroid Build Coastguard Worker namespace llvm {
27*9880d681SAndroid Build Coastguard Worker 
28*9880d681SAndroid Build Coastguard Worker class ARMTTIImpl : public BasicTTIImplBase<ARMTTIImpl> {
29*9880d681SAndroid Build Coastguard Worker   typedef BasicTTIImplBase<ARMTTIImpl> BaseT;
30*9880d681SAndroid Build Coastguard Worker   typedef TargetTransformInfo TTI;
31*9880d681SAndroid Build Coastguard Worker   friend BaseT;
32*9880d681SAndroid Build Coastguard Worker 
33*9880d681SAndroid Build Coastguard Worker   const ARMSubtarget *ST;
34*9880d681SAndroid Build Coastguard Worker   const ARMTargetLowering *TLI;
35*9880d681SAndroid Build Coastguard Worker 
36*9880d681SAndroid Build Coastguard Worker   /// Estimate the overhead of scalarizing an instruction. Insert and Extract
37*9880d681SAndroid Build Coastguard Worker   /// are set if the result needs to be inserted and/or extracted from vectors.
38*9880d681SAndroid Build Coastguard Worker   unsigned getScalarizationOverhead(Type *Ty, bool Insert, bool Extract);
39*9880d681SAndroid Build Coastguard Worker 
getST()40*9880d681SAndroid Build Coastguard Worker   const ARMSubtarget *getST() const { return ST; }
getTLI()41*9880d681SAndroid Build Coastguard Worker   const ARMTargetLowering *getTLI() const { return TLI; }
42*9880d681SAndroid Build Coastguard Worker 
43*9880d681SAndroid Build Coastguard Worker public:
ARMTTIImpl(const ARMBaseTargetMachine * TM,const Function & F)44*9880d681SAndroid Build Coastguard Worker   explicit ARMTTIImpl(const ARMBaseTargetMachine *TM, const Function &F)
45*9880d681SAndroid Build Coastguard Worker       : BaseT(TM, F.getParent()->getDataLayout()), ST(TM->getSubtargetImpl(F)),
46*9880d681SAndroid Build Coastguard Worker         TLI(ST->getTargetLowering()) {}
47*9880d681SAndroid Build Coastguard Worker 
48*9880d681SAndroid Build Coastguard Worker   // Provide value semantics. MSVC requires that we spell all of these out.
ARMTTIImpl(const ARMTTIImpl & Arg)49*9880d681SAndroid Build Coastguard Worker   ARMTTIImpl(const ARMTTIImpl &Arg)
50*9880d681SAndroid Build Coastguard Worker       : BaseT(static_cast<const BaseT &>(Arg)), ST(Arg.ST), TLI(Arg.TLI) {}
ARMTTIImpl(ARMTTIImpl && Arg)51*9880d681SAndroid Build Coastguard Worker   ARMTTIImpl(ARMTTIImpl &&Arg)
52*9880d681SAndroid Build Coastguard Worker       : BaseT(std::move(static_cast<BaseT &>(Arg))), ST(std::move(Arg.ST)),
53*9880d681SAndroid Build Coastguard Worker         TLI(std::move(Arg.TLI)) {}
54*9880d681SAndroid Build Coastguard Worker 
enableInterleavedAccessVectorization()55*9880d681SAndroid Build Coastguard Worker   bool enableInterleavedAccessVectorization() { return true; }
56*9880d681SAndroid Build Coastguard Worker 
57*9880d681SAndroid Build Coastguard Worker   /// Floating-point computation using ARMv8 AArch32 Advanced
58*9880d681SAndroid Build Coastguard Worker   /// SIMD instructions remains unchanged from ARMv7. Only AArch64 SIMD
59*9880d681SAndroid Build Coastguard Worker   /// is IEEE-754 compliant, but it's not covered in this target.
isFPVectorizationPotentiallyUnsafe()60*9880d681SAndroid Build Coastguard Worker   bool isFPVectorizationPotentiallyUnsafe() {
61*9880d681SAndroid Build Coastguard Worker     return !ST->isTargetDarwin();
62*9880d681SAndroid Build Coastguard Worker   }
63*9880d681SAndroid Build Coastguard Worker 
64*9880d681SAndroid Build Coastguard Worker   /// \name Scalar TTI Implementations
65*9880d681SAndroid Build Coastguard Worker   /// @{
66*9880d681SAndroid Build Coastguard Worker 
67*9880d681SAndroid Build Coastguard Worker   int getIntImmCodeSizeCost(unsigned Opcode, unsigned Idx, const APInt &Imm,
68*9880d681SAndroid Build Coastguard Worker                             Type *Ty);
69*9880d681SAndroid Build Coastguard Worker 
70*9880d681SAndroid Build Coastguard Worker   using BaseT::getIntImmCost;
71*9880d681SAndroid Build Coastguard Worker   int getIntImmCost(const APInt &Imm, Type *Ty);
72*9880d681SAndroid Build Coastguard Worker 
73*9880d681SAndroid Build Coastguard Worker   int getIntImmCost(unsigned Opcode, unsigned Idx, const APInt &Imm, Type *Ty);
74*9880d681SAndroid Build Coastguard Worker 
75*9880d681SAndroid Build Coastguard Worker   /// @}
76*9880d681SAndroid Build Coastguard Worker 
77*9880d681SAndroid Build Coastguard Worker   /// \name Vector TTI Implementations
78*9880d681SAndroid Build Coastguard Worker   /// @{
79*9880d681SAndroid Build Coastguard Worker 
getNumberOfRegisters(bool Vector)80*9880d681SAndroid Build Coastguard Worker   unsigned getNumberOfRegisters(bool Vector) {
81*9880d681SAndroid Build Coastguard Worker     if (Vector) {
82*9880d681SAndroid Build Coastguard Worker       if (ST->hasNEON())
83*9880d681SAndroid Build Coastguard Worker         return 16;
84*9880d681SAndroid Build Coastguard Worker       return 0;
85*9880d681SAndroid Build Coastguard Worker     }
86*9880d681SAndroid Build Coastguard Worker 
87*9880d681SAndroid Build Coastguard Worker     if (ST->isThumb1Only())
88*9880d681SAndroid Build Coastguard Worker       return 8;
89*9880d681SAndroid Build Coastguard Worker     return 13;
90*9880d681SAndroid Build Coastguard Worker   }
91*9880d681SAndroid Build Coastguard Worker 
getRegisterBitWidth(bool Vector)92*9880d681SAndroid Build Coastguard Worker   unsigned getRegisterBitWidth(bool Vector) {
93*9880d681SAndroid Build Coastguard Worker     if (Vector) {
94*9880d681SAndroid Build Coastguard Worker       if (ST->hasNEON())
95*9880d681SAndroid Build Coastguard Worker         return 128;
96*9880d681SAndroid Build Coastguard Worker       return 0;
97*9880d681SAndroid Build Coastguard Worker     }
98*9880d681SAndroid Build Coastguard Worker 
99*9880d681SAndroid Build Coastguard Worker     return 32;
100*9880d681SAndroid Build Coastguard Worker   }
101*9880d681SAndroid Build Coastguard Worker 
getMaxInterleaveFactor(unsigned VF)102*9880d681SAndroid Build Coastguard Worker   unsigned getMaxInterleaveFactor(unsigned VF) {
103*9880d681SAndroid Build Coastguard Worker     return ST->getMaxInterleaveFactor();
104*9880d681SAndroid Build Coastguard Worker   }
105*9880d681SAndroid Build Coastguard Worker 
106*9880d681SAndroid Build Coastguard Worker   int getShuffleCost(TTI::ShuffleKind Kind, Type *Tp, int Index, Type *SubTp);
107*9880d681SAndroid Build Coastguard Worker 
108*9880d681SAndroid Build Coastguard Worker   int getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src);
109*9880d681SAndroid Build Coastguard Worker 
110*9880d681SAndroid Build Coastguard Worker   int getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy);
111*9880d681SAndroid Build Coastguard Worker 
112*9880d681SAndroid Build Coastguard Worker   int getVectorInstrCost(unsigned Opcode, Type *Val, unsigned Index);
113*9880d681SAndroid Build Coastguard Worker 
114*9880d681SAndroid Build Coastguard Worker   int getAddressComputationCost(Type *Val, bool IsComplex);
115*9880d681SAndroid Build Coastguard Worker 
116*9880d681SAndroid Build Coastguard Worker   int getFPOpCost(Type *Ty);
117*9880d681SAndroid Build Coastguard Worker 
118*9880d681SAndroid Build Coastguard Worker   int getArithmeticInstrCost(
119*9880d681SAndroid Build Coastguard Worker       unsigned Opcode, Type *Ty,
120*9880d681SAndroid Build Coastguard Worker       TTI::OperandValueKind Op1Info = TTI::OK_AnyValue,
121*9880d681SAndroid Build Coastguard Worker       TTI::OperandValueKind Op2Info = TTI::OK_AnyValue,
122*9880d681SAndroid Build Coastguard Worker       TTI::OperandValueProperties Opd1PropInfo = TTI::OP_None,
123*9880d681SAndroid Build Coastguard Worker       TTI::OperandValueProperties Opd2PropInfo = TTI::OP_None);
124*9880d681SAndroid Build Coastguard Worker 
125*9880d681SAndroid Build Coastguard Worker   int getMemoryOpCost(unsigned Opcode, Type *Src, unsigned Alignment,
126*9880d681SAndroid Build Coastguard Worker                       unsigned AddressSpace);
127*9880d681SAndroid Build Coastguard Worker 
128*9880d681SAndroid Build Coastguard Worker   int getInterleavedMemoryOpCost(unsigned Opcode, Type *VecTy, unsigned Factor,
129*9880d681SAndroid Build Coastguard Worker                                  ArrayRef<unsigned> Indices, unsigned Alignment,
130*9880d681SAndroid Build Coastguard Worker                                  unsigned AddressSpace);
131*9880d681SAndroid Build Coastguard Worker   /// @}
132*9880d681SAndroid Build Coastguard Worker };
133*9880d681SAndroid Build Coastguard Worker 
134*9880d681SAndroid Build Coastguard Worker } // end namespace llvm
135*9880d681SAndroid Build Coastguard Worker 
136*9880d681SAndroid Build Coastguard Worker #endif
137