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 | #include <algorithm> |
25 | |
26 | namespace llvm { |
27 | |
28 | class WebAssemblyTTIImpl final : public BasicTTIImplBase<WebAssemblyTTIImpl> { |
29 | typedef BasicTTIImplBase<WebAssemblyTTIImpl> BaseT; |
30 | typedef TargetTransformInfo TTI; |
31 | friend BaseT; |
32 | |
33 | const WebAssemblySubtarget *ST; |
34 | const WebAssemblyTargetLowering *TLI; |
35 | |
36 | const WebAssemblySubtarget *getST() const { return ST; } |
37 | const WebAssemblyTargetLowering *getTLI() const { return TLI; } |
38 | |
39 | public: |
40 | WebAssemblyTTIImpl(const WebAssemblyTargetMachine *TM, const Function &F) |
41 | : BaseT(TM, F.getDataLayout()), ST(TM->getSubtargetImpl(F)), |
42 | TLI(ST->getTargetLowering()) {} |
43 | |
44 | /// \name Scalar TTI Implementations |
45 | /// @{ |
46 | |
47 | // TODO: Implement more Scalar TTI for WebAssembly |
48 | |
49 | TTI::PopcntSupportKind getPopcntSupport(unsigned TyWidth) const override; |
50 | |
51 | void (Loop *L, ScalarEvolution &SE, |
52 | TTI::UnrollingPreferences &UP, |
53 | OptimizationRemarkEmitter *ORE) const override; |
54 | |
55 | /// @} |
56 | |
57 | /// \name Vector TTI Implementations |
58 | /// @{ |
59 | |
60 | bool enableInterleavedAccessVectorization() const override { return true; } |
61 | |
62 | unsigned getNumberOfRegisters(unsigned ClassID) const override; |
63 | TypeSize |
64 | getRegisterBitWidth(TargetTransformInfo::RegisterKind K) const override; |
65 | InstructionCost getArithmeticInstrCost( |
66 | unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind, |
67 | TTI::OperandValueInfo Op1Info = {.Kind: TTI::OK_AnyValue, .Properties: TTI::OP_None}, |
68 | TTI::OperandValueInfo Op2Info = {.Kind: TTI::OK_AnyValue, .Properties: TTI::OP_None}, |
69 | ArrayRef<const Value *> Args = {}, |
70 | const Instruction *CxtI = nullptr) const override; |
71 | |
72 | InstructionCost |
73 | getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src, |
74 | TTI::CastContextHint CCH, TTI::TargetCostKind CostKind, |
75 | const Instruction *I = nullptr) const override; |
76 | InstructionCost getMemoryOpCost( |
77 | unsigned Opcode, Type *Src, Align Alignment, unsigned AddressSpace, |
78 | TTI::TargetCostKind CostKind, |
79 | TTI::OperandValueInfo OpInfo = {.Kind: TTI::OK_AnyValue, .Properties: TTI::OP_None}, |
80 | const Instruction *I = nullptr) const override; |
81 | using BaseT::getVectorInstrCost; |
82 | InstructionCost getVectorInstrCost(unsigned Opcode, Type *Val, |
83 | TTI::TargetCostKind CostKind, |
84 | unsigned Index, const Value *Op0, |
85 | const Value *Op1) const override; |
86 | InstructionCost getPartialReductionCost( |
87 | unsigned Opcode, Type *InputTypeA, Type *InputTypeB, Type *AccumType, |
88 | ElementCount VF, TTI::PartialReductionExtendKind OpAExtend, |
89 | TTI::PartialReductionExtendKind OpBExtend, std::optional<unsigned> BinOp, |
90 | TTI::TargetCostKind CostKind) const override; |
91 | TTI::ReductionShuffle |
92 | getPreferredExpandedReductionShuffle(const IntrinsicInst *II) const override; |
93 | |
94 | bool supportsTailCalls() const override; |
95 | |
96 | bool isProfitableToSinkOperands(Instruction *I, |
97 | SmallVectorImpl<Use *> &Ops) const override; |
98 | |
99 | /// @} |
100 | }; |
101 | |
102 | } // end namespace llvm |
103 | |
104 | #endif |
105 | |