1*9880d681SAndroid Build Coastguard Worker //===-- WebAssemblyTargetTransformInfo.cpp - WebAssembly-specific TTI -----===//
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 ///
10*9880d681SAndroid Build Coastguard Worker /// \file
11*9880d681SAndroid Build Coastguard Worker /// \brief This file defines the WebAssembly-specific TargetTransformInfo
12*9880d681SAndroid Build Coastguard Worker /// implementation.
13*9880d681SAndroid Build Coastguard Worker ///
14*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===//
15*9880d681SAndroid Build Coastguard Worker
16*9880d681SAndroid Build Coastguard Worker #include "WebAssemblyTargetTransformInfo.h"
17*9880d681SAndroid Build Coastguard Worker #include "llvm/Support/Debug.h"
18*9880d681SAndroid Build Coastguard Worker #include "llvm/Target/CostTable.h"
19*9880d681SAndroid Build Coastguard Worker using namespace llvm;
20*9880d681SAndroid Build Coastguard Worker
21*9880d681SAndroid Build Coastguard Worker #define DEBUG_TYPE "wasmtti"
22*9880d681SAndroid Build Coastguard Worker
23*9880d681SAndroid Build Coastguard Worker TargetTransformInfo::PopcntSupportKind
getPopcntSupport(unsigned TyWidth) const24*9880d681SAndroid Build Coastguard Worker WebAssemblyTTIImpl::getPopcntSupport(unsigned TyWidth) const {
25*9880d681SAndroid Build Coastguard Worker assert(isPowerOf2_32(TyWidth) && "Ty width must be power of 2");
26*9880d681SAndroid Build Coastguard Worker return TargetTransformInfo::PSK_FastHardware;
27*9880d681SAndroid Build Coastguard Worker }
28*9880d681SAndroid Build Coastguard Worker
getNumberOfRegisters(bool Vector)29*9880d681SAndroid Build Coastguard Worker unsigned WebAssemblyTTIImpl::getNumberOfRegisters(bool Vector) {
30*9880d681SAndroid Build Coastguard Worker unsigned Result = BaseT::getNumberOfRegisters(Vector);
31*9880d681SAndroid Build Coastguard Worker
32*9880d681SAndroid Build Coastguard Worker // For SIMD, use at least 16 registers, as a rough guess.
33*9880d681SAndroid Build Coastguard Worker if (Vector)
34*9880d681SAndroid Build Coastguard Worker Result = std::max(Result, 16u);
35*9880d681SAndroid Build Coastguard Worker
36*9880d681SAndroid Build Coastguard Worker return Result;
37*9880d681SAndroid Build Coastguard Worker }
38*9880d681SAndroid Build Coastguard Worker
getRegisterBitWidth(bool Vector)39*9880d681SAndroid Build Coastguard Worker unsigned WebAssemblyTTIImpl::getRegisterBitWidth(bool Vector) {
40*9880d681SAndroid Build Coastguard Worker if (Vector && getST()->hasSIMD128())
41*9880d681SAndroid Build Coastguard Worker return 128;
42*9880d681SAndroid Build Coastguard Worker
43*9880d681SAndroid Build Coastguard Worker return 64;
44*9880d681SAndroid Build Coastguard Worker }
45*9880d681SAndroid Build Coastguard Worker
getArithmeticInstrCost(unsigned Opcode,Type * Ty,TTI::OperandValueKind Opd1Info,TTI::OperandValueKind Opd2Info,TTI::OperandValueProperties Opd1PropInfo,TTI::OperandValueProperties Opd2PropInfo)46*9880d681SAndroid Build Coastguard Worker unsigned WebAssemblyTTIImpl::getArithmeticInstrCost(
47*9880d681SAndroid Build Coastguard Worker unsigned Opcode, Type *Ty, TTI::OperandValueKind Opd1Info,
48*9880d681SAndroid Build Coastguard Worker TTI::OperandValueKind Opd2Info, TTI::OperandValueProperties Opd1PropInfo,
49*9880d681SAndroid Build Coastguard Worker TTI::OperandValueProperties Opd2PropInfo) {
50*9880d681SAndroid Build Coastguard Worker
51*9880d681SAndroid Build Coastguard Worker unsigned Cost = BasicTTIImplBase<WebAssemblyTTIImpl>::getArithmeticInstrCost(
52*9880d681SAndroid Build Coastguard Worker Opcode, Ty, Opd1Info, Opd2Info, Opd1PropInfo, Opd2PropInfo);
53*9880d681SAndroid Build Coastguard Worker
54*9880d681SAndroid Build Coastguard Worker if (VectorType *VTy = dyn_cast<VectorType>(Ty)) {
55*9880d681SAndroid Build Coastguard Worker switch (Opcode) {
56*9880d681SAndroid Build Coastguard Worker case Instruction::LShr:
57*9880d681SAndroid Build Coastguard Worker case Instruction::AShr:
58*9880d681SAndroid Build Coastguard Worker case Instruction::Shl:
59*9880d681SAndroid Build Coastguard Worker // SIMD128's shifts currently only accept a scalar shift count. For each
60*9880d681SAndroid Build Coastguard Worker // element, we'll need to extract, op, insert. The following is a rough
61*9880d681SAndroid Build Coastguard Worker // approxmation.
62*9880d681SAndroid Build Coastguard Worker if (Opd2Info != TTI::OK_UniformValue &&
63*9880d681SAndroid Build Coastguard Worker Opd2Info != TTI::OK_UniformConstantValue)
64*9880d681SAndroid Build Coastguard Worker Cost = VTy->getNumElements() *
65*9880d681SAndroid Build Coastguard Worker (TargetTransformInfo::TCC_Basic +
66*9880d681SAndroid Build Coastguard Worker getArithmeticInstrCost(Opcode, VTy->getElementType()) +
67*9880d681SAndroid Build Coastguard Worker TargetTransformInfo::TCC_Basic);
68*9880d681SAndroid Build Coastguard Worker break;
69*9880d681SAndroid Build Coastguard Worker }
70*9880d681SAndroid Build Coastguard Worker }
71*9880d681SAndroid Build Coastguard Worker return Cost;
72*9880d681SAndroid Build Coastguard Worker }
73*9880d681SAndroid Build Coastguard Worker
getVectorInstrCost(unsigned Opcode,Type * Val,unsigned Index)74*9880d681SAndroid Build Coastguard Worker unsigned WebAssemblyTTIImpl::getVectorInstrCost(unsigned Opcode, Type *Val,
75*9880d681SAndroid Build Coastguard Worker unsigned Index) {
76*9880d681SAndroid Build Coastguard Worker unsigned Cost = BasicTTIImplBase::getVectorInstrCost(Opcode, Val, Index);
77*9880d681SAndroid Build Coastguard Worker
78*9880d681SAndroid Build Coastguard Worker // SIMD128's insert/extract currently only take constant indices.
79*9880d681SAndroid Build Coastguard Worker if (Index == -1u)
80*9880d681SAndroid Build Coastguard Worker return Cost + 25 * TargetTransformInfo::TCC_Expensive;
81*9880d681SAndroid Build Coastguard Worker
82*9880d681SAndroid Build Coastguard Worker return Cost;
83*9880d681SAndroid Build Coastguard Worker }
84