LLVM  12.0.0git
WebAssemblyTargetTransformInfo.cpp
Go to the documentation of this file.
1 //===-- WebAssemblyTargetTransformInfo.cpp - WebAssembly-specific TTI -----===//
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 defines the WebAssembly-specific TargetTransformInfo
11 /// implementation.
12 ///
13 //===----------------------------------------------------------------------===//
14 
16 #include "llvm/CodeGen/CostTable.h"
17 #include "llvm/Support/Debug.h"
18 using namespace llvm;
19 
20 #define DEBUG_TYPE "wasmtti"
21 
23 WebAssemblyTTIImpl::getPopcntSupport(unsigned TyWidth) const {
24  assert(isPowerOf2_32(TyWidth) && "Ty width must be power of 2");
26 }
27 
28 unsigned WebAssemblyTTIImpl::getNumberOfRegisters(unsigned ClassID) const {
29  unsigned Result = BaseT::getNumberOfRegisters(ClassID);
30 
31  // For SIMD, use at least 16 registers, as a rough guess.
32  bool Vector = (ClassID == 1);
33  if (Vector)
34  Result = std::max(Result, 16u);
35 
36  return Result;
37 }
38 
40  if (Vector && getST()->hasSIMD128())
41  return 128;
42 
43  return 64;
44 }
45 
47  unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind,
48  TTI::OperandValueKind Opd1Info,
51  const Instruction *CxtI) {
52 
54  Opcode, Ty, CostKind, Opd1Info, Opd2Info, Opd1PropInfo, Opd2PropInfo);
55 
56  if (auto *VTy = dyn_cast<VectorType>(Ty)) {
57  switch (Opcode) {
58  case Instruction::LShr:
59  case Instruction::AShr:
60  case Instruction::Shl:
61  // SIMD128's shifts currently only accept a scalar shift count. For each
62  // element, we'll need to extract, op, insert. The following is a rough
63  // approxmation.
64  if (Opd2Info != TTI::OK_UniformValue &&
65  Opd2Info != TTI::OK_UniformConstantValue)
66  Cost =
67  cast<FixedVectorType>(VTy)->getNumElements() *
69  getArithmeticInstrCost(Opcode, VTy->getElementType(), CostKind) +
71  break;
72  }
73  }
74  return Cost;
75 }
76 
77 unsigned WebAssemblyTTIImpl::getVectorInstrCost(unsigned Opcode, Type *Val,
78  unsigned Index) {
79  unsigned Cost = BasicTTIImplBase::getVectorInstrCost(Opcode, Val, Index);
80 
81  // SIMD128's insert/extract currently only take constant indices.
82  if (Index == -1u)
83  return Cost + 25 * TargetTransformInfo::TCC_Expensive;
84 
85  return Cost;
86 }
This class represents lattice values for constants.
Definition: AllocatorList.h:23
Cost tables and simple lookup functions.
unsigned getVectorInstrCost(unsigned Opcode, Type *Val, unsigned Index)
This file a TargetTransformInfo::Concept conforming object specific to the WebAssembly target machine...
TTI::PopcntSupportKind getPopcntSupport(unsigned TyWidth) const
static cl::opt< TargetTransformInfo::TargetCostKind > CostKind("cost-kind", cl::desc("Target cost kind"), cl::init(TargetTransformInfo::TCK_RecipThroughput), cl::values(clEnumValN(TargetTransformInfo::TCK_RecipThroughput, "throughput", "Reciprocal throughput"), clEnumValN(TargetTransformInfo::TCK_Latency, "latency", "Instruction latency"), clEnumValN(TargetTransformInfo::TCK_CodeSize, "code-size", "Code size")))
unsigned getArithmeticInstrCost(unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind=TTI::TCK_SizeAndLatency, TTI::OperandValueKind Opd1Info=TTI::OK_AnyValue, TTI::OperandValueKind Opd2Info=TTI::OK_AnyValue, TTI::OperandValueProperties Opd1PropInfo=TTI::OP_None, TTI::OperandValueProperties Opd2PropInfo=TTI::OP_None, ArrayRef< const Value *> Args=ArrayRef< const Value *>(), const Instruction *CxtI=nullptr)
PopcntSupportKind
Flags indicating the kind of support for population count.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:32
constexpr bool isPowerOf2_32(uint32_t Value)
Return true if the argument is a power of two > 0.
Definition: MathExtras.h:492
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:46
unsigned getNumberOfRegisters(unsigned ClassID) const
unsigned getNumberOfRegisters(unsigned ClassID) const
OperandValueProperties
Additional properties of an operand&#39;s values.
Align max(MaybeAlign Lhs, Align Rhs)
Definition: Alignment.h:350
unsigned getRegisterBitWidth(bool Vector) const
unsigned getVectorInstrCost(unsigned Opcode, Type *Val, unsigned Index)
Definition: BasicTTIImpl.h:903
unsigned getArithmeticInstrCost(unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind=TTI::TCK_RecipThroughput, TTI::OperandValueKind Opd1Info=TTI::OK_AnyValue, TTI::OperandValueKind Opd2Info=TTI::OK_AnyValue, TTI::OperandValueProperties Opd1PropInfo=TTI::OP_None, TTI::OperandValueProperties Opd2PropInfo=TTI::OP_None, ArrayRef< const Value *> Args=ArrayRef< const Value *>(), const Instruction *CxtI=nullptr)
Definition: BasicTTIImpl.h:615
static Value * getNumElements(BasicBlock *Preheader, Value *BTC)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
The cost of a typical &#39;add&#39; instruction.
OperandValueKind
Additional information about an operand&#39;s possible values.
TargetCostKind
The kind of cost model.
The cost of a &#39;div&#39; instruction on x86.
constexpr char Args[]
Key for Kernel::Metadata::mArgs.