2015-06-30 07:51:55 +08:00
|
|
|
//===-- WebAssemblyTargetTransformInfo.cpp - WebAssembly-specific TTI -----===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
///
|
|
|
|
/// \file
|
2018-05-01 23:54:18 +08:00
|
|
|
/// This file defines the WebAssembly-specific TargetTransformInfo
|
2015-06-30 07:51:55 +08:00
|
|
|
/// implementation.
|
|
|
|
///
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "WebAssemblyTargetTransformInfo.h"
|
2017-11-17 09:07:10 +08:00
|
|
|
#include "llvm/CodeGen/CostTable.h"
|
2015-06-30 07:51:55 +08:00
|
|
|
#include "llvm/Support/Debug.h"
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
#define DEBUG_TYPE "wasmtti"
|
|
|
|
|
|
|
|
TargetTransformInfo::PopcntSupportKind
|
2015-08-25 00:51:46 +08:00
|
|
|
WebAssemblyTTIImpl::getPopcntSupport(unsigned TyWidth) const {
|
2015-06-30 07:51:55 +08:00
|
|
|
assert(isPowerOf2_32(TyWidth) && "Ty width must be power of 2");
|
2015-08-25 00:51:46 +08:00
|
|
|
return TargetTransformInfo::PSK_FastHardware;
|
|
|
|
}
|
2016-05-24 06:47:07 +08:00
|
|
|
|
|
|
|
unsigned WebAssemblyTTIImpl::getNumberOfRegisters(bool Vector) {
|
|
|
|
unsigned Result = BaseT::getNumberOfRegisters(Vector);
|
|
|
|
|
|
|
|
// For SIMD, use at least 16 registers, as a rough guess.
|
|
|
|
if (Vector)
|
|
|
|
Result = std::max(Result, 16u);
|
|
|
|
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
Const correctness for TTI::getRegisterBitWidth
Summary: The method TargetTransformInfo::getRegisterBitWidth() is declared const, but the type erasing implementation classes (TargetTransformInfo::Concept & TargetTransformInfo::Model) that were introduced by Chandler in https://reviews.llvm.org/D7293 do not have the method declared const. This is an NFC to tidy up the const consistency between TTI and its implementation.
Reviewers: chandlerc, rnk, reames
Reviewed By: reames
Subscribers: reames, jfb, arsenm, dschuff, nemanjai, nhaehnle, javed.absar, sbc100, jgravelle-google, llvm-commits
Differential Revision: https://reviews.llvm.org/D33903
llvm-svn: 305189
2017-06-12 22:22:21 +08:00
|
|
|
unsigned WebAssemblyTTIImpl::getRegisterBitWidth(bool Vector) const {
|
2016-05-24 06:47:07 +08:00
|
|
|
if (Vector && getST()->hasSIMD128())
|
|
|
|
return 128;
|
|
|
|
|
|
|
|
return 64;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned WebAssemblyTTIImpl::getArithmeticInstrCost(
|
|
|
|
unsigned Opcode, Type *Ty, TTI::OperandValueKind Opd1Info,
|
|
|
|
TTI::OperandValueKind Opd2Info, TTI::OperandValueProperties Opd1PropInfo,
|
[X86] updating TTI costs for arithmetic instructions on X86\SLM arch.
updated instructions:
pmulld, pmullw, pmulhw, mulsd, mulps, mulpd, divss, divps, divsd, divpd, addpd and subpd.
special optimization case which replaces pmulld with pmullw\pmulhw\pshuf seq.
In case if the real operands bitwidth <= 16.
Differential Revision: https://reviews.llvm.org/D28104
llvm-svn: 291657
2017-01-11 16:23:37 +08:00
|
|
|
TTI::OperandValueProperties Opd2PropInfo, ArrayRef<const Value *> Args) {
|
2016-05-24 06:47:07 +08:00
|
|
|
|
|
|
|
unsigned Cost = BasicTTIImplBase<WebAssemblyTTIImpl>::getArithmeticInstrCost(
|
|
|
|
Opcode, Ty, Opd1Info, Opd2Info, Opd1PropInfo, Opd2PropInfo);
|
|
|
|
|
|
|
|
if (VectorType *VTy = dyn_cast<VectorType>(Ty)) {
|
|
|
|
switch (Opcode) {
|
|
|
|
case Instruction::LShr:
|
|
|
|
case Instruction::AShr:
|
|
|
|
case Instruction::Shl:
|
|
|
|
// SIMD128's shifts currently only accept a scalar shift count. For each
|
|
|
|
// element, we'll need to extract, op, insert. The following is a rough
|
|
|
|
// approxmation.
|
|
|
|
if (Opd2Info != TTI::OK_UniformValue &&
|
|
|
|
Opd2Info != TTI::OK_UniformConstantValue)
|
|
|
|
Cost = VTy->getNumElements() *
|
|
|
|
(TargetTransformInfo::TCC_Basic +
|
|
|
|
getArithmeticInstrCost(Opcode, VTy->getElementType()) +
|
|
|
|
TargetTransformInfo::TCC_Basic);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Cost;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned WebAssemblyTTIImpl::getVectorInstrCost(unsigned Opcode, Type *Val,
|
|
|
|
unsigned Index) {
|
|
|
|
unsigned Cost = BasicTTIImplBase::getVectorInstrCost(Opcode, Val, Index);
|
|
|
|
|
|
|
|
// SIMD128's insert/extract currently only take constant indices.
|
|
|
|
if (Index == -1u)
|
|
|
|
return Cost + 25 * TargetTransformInfo::TCC_Expensive;
|
|
|
|
|
|
|
|
return Cost;
|
|
|
|
}
|