1//===- LoongArchTargetTransformInfo.h - LoongArch specific TTI --*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8/// \file
9/// This file a TargetTransformInfoImplBase conforming object specific to the
10/// LoongArch target machine. It uses the target's detailed information to
11/// provide more precise answers to certain TTI queries, while letting the
12/// target independent and default TTI implementations handle the rest.
13///
14//===----------------------------------------------------------------------===//
15
16#ifndef LLVM_LIB_TARGET_LOONGARCH_LOONGARCHTARGETTRANSFORMINFO_H
17#define LLVM_LIB_TARGET_LOONGARCH_LOONGARCHTARGETTRANSFORMINFO_H
18
19#include "LoongArchSubtarget.h"
20#include "LoongArchTargetMachine.h"
21#include "llvm/Analysis/TargetTransformInfo.h"
22#include "llvm/CodeGen/BasicTTIImpl.h"
23
24namespace llvm {
25
26class LoongArchTTIImpl : public BasicTTIImplBase<LoongArchTTIImpl> {
27 typedef BasicTTIImplBase<LoongArchTTIImpl> BaseT;
28 typedef TargetTransformInfo TTI;
29 friend BaseT;
30
31 enum LoongArchRegisterClass { GPRRC, FPRRC, VRRC };
32 const LoongArchSubtarget *ST;
33 const LoongArchTargetLowering *TLI;
34
35 const LoongArchSubtarget *getST() const { return ST; }
36 const LoongArchTargetLowering *getTLI() const { return TLI; }
37
38public:
39 explicit LoongArchTTIImpl(const LoongArchTargetMachine *TM, const Function &F)
40 : BaseT(TM, F.getDataLayout()), ST(TM->getSubtargetImpl(F)),
41 TLI(ST->getTargetLowering()) {}
42
43 TypeSize
44 getRegisterBitWidth(TargetTransformInfo::RegisterKind K) const override;
45 unsigned getNumberOfRegisters(unsigned ClassID) const override;
46 unsigned getRegisterClassForType(bool Vector,
47 Type *Ty = nullptr) const override;
48 unsigned getMaxInterleaveFactor(ElementCount VF,
49 bool HasUnorderedReductions) const override;
50 const char *getRegisterClassName(unsigned ClassID) const override;
51 TTI::PopcntSupportKind getPopcntSupport(unsigned TyWidth) const override;
52
53 unsigned getCacheLineSize() const override;
54
55 bool shouldExpandReduction(const IntrinsicInst *II) const override;
56
57 InstructionCost getArithmeticInstrCost(
58 unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind,
59 TTI::OperandValueInfo Op1Info = {.Kind: TTI::OK_AnyValue, .Properties: TTI::OP_None},
60 TTI::OperandValueInfo Op2Info = {.Kind: TTI::OK_AnyValue, .Properties: TTI::OP_None},
61 ArrayRef<const Value *> Args = {},
62 const Instruction *CxtI = nullptr) const override;
63
64 using BaseT::getVectorInstrCost;
65 InstructionCost
66 getVectorInstrCost(unsigned Opcode, Type *Val, TTI::TargetCostKind CostKind,
67 unsigned Index, const Value *Op0, const Value *Op1,
68 TTI::VectorInstrContext VIC =
69 TTI::VectorInstrContext::None) const override;
70
71 InstructionCost
72 getShuffleCost(TTI::ShuffleKind Kind, VectorType *DstTy, VectorType *SrcTy,
73 TTI::TargetCostKind CostKind, ArrayRef<int> Mask, int Index,
74 VectorType *SubTp, ArrayRef<const Value *> Args = {},
75 const Instruction *CxtI = nullptr,
76 TTI::VectorInstrContext VIC =
77 TTI::VectorInstrContext::None) const override;
78
79 InstructionCost getMemoryOpCost(
80 unsigned Opcode, Type *Src, Align Alignment, unsigned AddressSpace,
81 TTI::TargetCostKind CostKind,
82 TTI::OperandValueInfo OpInfo = {.Kind: TTI::OK_AnyValue, .Properties: TTI::OP_None},
83 const Instruction *I = nullptr) const override;
84
85 TTI::MemCmpExpansionOptions
86 enableMemCmpExpansion(bool OptSize, bool IsZeroCmp) const override;
87
88 InstructionCost getPartialReductionCost(
89 unsigned Opcode, Type *InputTypeA, Type *InputTypeB, Type *AccumType,
90 ElementCount VF, TTI::PartialReductionExtendKind OpAExtend,
91 TTI::PartialReductionExtendKind OpBExtend, std::optional<unsigned> BinOp,
92 TTI::TargetCostKind CostKind,
93 std::optional<FastMathFlags> FMF) const override {
94 return InstructionCost::getInvalid();
95 }
96};
97
98} // end namespace llvm
99
100#endif // LLVM_LIB_TARGET_LOONGARCH_LOONGARCHTARGETTRANSFORMINFO_H
101