xref: /freebsd-src/contrib/llvm-project/llvm/lib/Target/WebAssembly/WebAssemblyTargetTransformInfo.h (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
10b57cec5SDimitry Andric //==- WebAssemblyTargetTransformInfo.h - WebAssembly-specific TTI -*- C++ -*-=//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric ///
90b57cec5SDimitry Andric /// \file
100b57cec5SDimitry Andric /// This file a TargetTransformInfo::Concept conforming object specific
110b57cec5SDimitry Andric /// to the WebAssembly target machine.
120b57cec5SDimitry Andric ///
130b57cec5SDimitry Andric /// It uses the target's detailed information to provide more precise answers to
140b57cec5SDimitry Andric /// certain TTI queries, while letting the target independent and default TTI
150b57cec5SDimitry Andric /// implementations handle the rest.
160b57cec5SDimitry Andric ///
170b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
180b57cec5SDimitry Andric 
190b57cec5SDimitry Andric #ifndef LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYTARGETTRANSFORMINFO_H
200b57cec5SDimitry Andric #define LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYTARGETTRANSFORMINFO_H
210b57cec5SDimitry Andric 
220b57cec5SDimitry Andric #include "WebAssemblyTargetMachine.h"
230b57cec5SDimitry Andric #include "llvm/CodeGen/BasicTTIImpl.h"
240b57cec5SDimitry Andric #include <algorithm>
250b57cec5SDimitry Andric 
260b57cec5SDimitry Andric namespace llvm {
270b57cec5SDimitry Andric 
280b57cec5SDimitry Andric class WebAssemblyTTIImpl final : public BasicTTIImplBase<WebAssemblyTTIImpl> {
290b57cec5SDimitry Andric   typedef BasicTTIImplBase<WebAssemblyTTIImpl> BaseT;
300b57cec5SDimitry Andric   typedef TargetTransformInfo TTI;
310b57cec5SDimitry Andric   friend BaseT;
320b57cec5SDimitry Andric 
330b57cec5SDimitry Andric   const WebAssemblySubtarget *ST;
340b57cec5SDimitry Andric   const WebAssemblyTargetLowering *TLI;
350b57cec5SDimitry Andric 
360b57cec5SDimitry Andric   const WebAssemblySubtarget *getST() const { return ST; }
370b57cec5SDimitry Andric   const WebAssemblyTargetLowering *getTLI() const { return TLI; }
380b57cec5SDimitry Andric 
390b57cec5SDimitry Andric public:
400b57cec5SDimitry Andric   WebAssemblyTTIImpl(const WebAssemblyTargetMachine *TM, const Function &F)
41*0fca6ea1SDimitry Andric       : BaseT(TM, F.getDataLayout()), ST(TM->getSubtargetImpl(F)),
420b57cec5SDimitry Andric         TLI(ST->getTargetLowering()) {}
430b57cec5SDimitry Andric 
440b57cec5SDimitry Andric   /// \name Scalar TTI Implementations
450b57cec5SDimitry Andric   /// @{
460b57cec5SDimitry Andric 
470b57cec5SDimitry Andric   // TODO: Implement more Scalar TTI for WebAssembly
480b57cec5SDimitry Andric 
490b57cec5SDimitry Andric   TTI::PopcntSupportKind getPopcntSupport(unsigned TyWidth) const;
500b57cec5SDimitry Andric 
51fe6060f1SDimitry Andric   void getUnrollingPreferences(Loop *L, ScalarEvolution &SE,
52349cc55cSDimitry Andric                                TTI::UnrollingPreferences &UP,
53349cc55cSDimitry Andric                                OptimizationRemarkEmitter *ORE) const;
54fe6060f1SDimitry Andric 
550b57cec5SDimitry Andric   /// @}
560b57cec5SDimitry Andric 
570b57cec5SDimitry Andric   /// \name Vector TTI Implementations
580b57cec5SDimitry Andric   /// @{
590b57cec5SDimitry Andric 
608bcb0991SDimitry Andric   unsigned getNumberOfRegisters(unsigned ClassID) const;
61fe6060f1SDimitry Andric   TypeSize getRegisterBitWidth(TargetTransformInfo::RegisterKind K) const;
62fe6060f1SDimitry Andric   InstructionCost getArithmeticInstrCost(
63349cc55cSDimitry Andric       unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind,
64bdd1243dSDimitry Andric       TTI::OperandValueInfo Op1Info = {TTI::OK_AnyValue, TTI::OP_None},
65bdd1243dSDimitry Andric       TTI::OperandValueInfo Op2Info = {TTI::OK_AnyValue, TTI::OP_None},
66*0fca6ea1SDimitry Andric       ArrayRef<const Value *> Args = std::nullopt,
67480093f4SDimitry Andric       const Instruction *CxtI = nullptr);
68bdd1243dSDimitry Andric   using BaseT::getVectorInstrCost;
69fe6060f1SDimitry Andric   InstructionCost getVectorInstrCost(unsigned Opcode, Type *Val,
70bdd1243dSDimitry Andric                                      TTI::TargetCostKind CostKind,
71bdd1243dSDimitry Andric                                      unsigned Index, Value *Op0, Value *Op1);
720b57cec5SDimitry Andric 
73*0fca6ea1SDimitry Andric   TTI::ReductionShuffle
74*0fca6ea1SDimitry Andric   getPreferredExpandedReductionShuffle(const IntrinsicInst *II) const;
750b57cec5SDimitry Andric   /// @}
76e8d8bef9SDimitry Andric 
77e8d8bef9SDimitry Andric   bool areInlineCompatible(const Function *Caller,
78e8d8bef9SDimitry Andric                            const Function *Callee) const;
7981ad6265SDimitry Andric 
8081ad6265SDimitry Andric   bool supportsTailCalls() const;
810b57cec5SDimitry Andric };
820b57cec5SDimitry Andric 
830b57cec5SDimitry Andric } // end namespace llvm
840b57cec5SDimitry Andric 
850b57cec5SDimitry Andric #endif
86