1//==- WebAssemblyTargetTransformInfo.h - WebAssembly-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///
9/// \file
10/// This file a TargetTransformInfoImplBase conforming object specific
11/// to the WebAssembly target machine.
12///
13/// It uses the target's detailed information to provide more precise answers to
14/// certain TTI queries, while letting the target independent and default TTI
15/// implementations handle the rest.
16///
17//===----------------------------------------------------------------------===//
18
19#ifndef LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYTARGETTRANSFORMINFO_H
20#define LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYTARGETTRANSFORMINFO_H
21
22#include "WebAssemblyTargetMachine.h"
23#include "llvm/CodeGen/BasicTTIImpl.h"
24
25namespace llvm {
26
27class WebAssemblyTTIImpl final : public BasicTTIImplBase<WebAssemblyTTIImpl> {
28 typedef BasicTTIImplBase<WebAssemblyTTIImpl> BaseT;
29 typedef TargetTransformInfo TTI;
30 friend BaseT;
31
32 const WebAssemblySubtarget *ST;
33 const WebAssemblyTargetLowering *TLI;
34
35 const WebAssemblySubtarget *getST() const { return ST; }
36 const WebAssemblyTargetLowering *getTLI() const { return TLI; }
37
38public:
39 WebAssemblyTTIImpl(const WebAssemblyTargetMachine *TM, const Function &F)
40 : BaseT(TM, F.getDataLayout()), ST(TM->getSubtargetImpl(F)),
41 TLI(ST->getTargetLowering()) {}
42
43 /// \name Scalar TTI Implementations
44 /// @{
45
46 // TODO: Implement more Scalar TTI for WebAssembly
47
48 TTI::PopcntSupportKind getPopcntSupport(unsigned TyWidth) const override;
49
50 void getUnrollingPreferences(Loop *L, ScalarEvolution &SE,
51 TTI::UnrollingPreferences &UP,
52 OptimizationRemarkEmitter *ORE) const override;
53
54 /// @}
55
56 /// \name Vector TTI Implementations
57 /// @{
58
59 bool enableInterleavedAccessVectorization() const override { return true; }
60
61 unsigned getNumberOfRegisters(unsigned ClassID) const override;
62 TypeSize
63 getRegisterBitWidth(TargetTransformInfo::RegisterKind K) const override;
64 InstructionCost getArithmeticInstrCost(
65 unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind,
66 TTI::OperandValueInfo Op1Info = {.Kind: TTI::OK_AnyValue, .Properties: TTI::OP_None},
67 TTI::OperandValueInfo Op2Info = {.Kind: TTI::OK_AnyValue, .Properties: TTI::OP_None},
68 ArrayRef<const Value *> Args = {},
69 const Instruction *CxtI = nullptr) const override;
70
71 InstructionCost
72 getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src,
73 TTI::CastContextHint CCH, TTI::TargetCostKind CostKind,
74 const Instruction *I = nullptr) const override;
75
76 TTI::MemCmpExpansionOptions
77 enableMemCmpExpansion(bool OptSize, bool IsZeroCmp) 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 InstructionCost getInterleavedMemoryOpCost(
85 unsigned Opcode, Type *Ty, unsigned Factor, ArrayRef<unsigned> Indices,
86 Align Alignment, unsigned AddressSpace, TTI::TargetCostKind CostKind,
87 bool UseMaskForCond, bool UseMaskForGaps) const override;
88 using BaseT::getVectorInstrCost;
89 InstructionCost
90 getVectorInstrCost(unsigned Opcode, Type *Val, TTI::TargetCostKind CostKind,
91 unsigned Index, const Value *Op0, const Value *Op1,
92 TTI::VectorInstrContext VIC =
93 TTI::VectorInstrContext::None) const override;
94 InstructionCost getPartialReductionCost(
95 unsigned Opcode, Type *InputTypeA, Type *InputTypeB, Type *AccumType,
96 ElementCount VF, TTI::PartialReductionExtendKind OpAExtend,
97 TTI::PartialReductionExtendKind OpBExtend, std::optional<unsigned> BinOp,
98 TTI::TargetCostKind CostKind,
99 std::optional<FastMathFlags> FMF) const override;
100
101 InstructionCost
102 getIntrinsicInstrCost(const IntrinsicCostAttributes &ICA,
103 TTI::TargetCostKind CostKind) const override;
104
105 TTI::ReductionShuffle
106 getPreferredExpandedReductionShuffle(const IntrinsicInst *II) const override;
107
108 bool supportsTailCalls() const override;
109
110 bool isProfitableToSinkOperands(Instruction *I,
111 SmallVectorImpl<Use *> &Ops) const override;
112
113 std::optional<Instruction *>
114 instCombineIntrinsic(InstCombiner &IC, IntrinsicInst &II) const override;
115
116 /// @}
117};
118
119} // end namespace llvm
120
121#endif
122