[WebAssembly] Basic TargetTransformInfo support for SIMD128.

llvm-svn: 270508
This commit is contained in:
Dan Gohman 2016-05-23 22:47:07 +00:00
parent 478c1a25fd
commit 73d7a555b9
2 changed files with 65 additions and 1 deletions

View File

@ -25,3 +25,59 @@ WebAssemblyTTIImpl::getPopcntSupport(unsigned TyWidth) const {
assert(isPowerOf2_32(TyWidth) && "Ty width must be power of 2");
return TargetTransformInfo::PSK_FastHardware;
}
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;
}
unsigned WebAssemblyTTIImpl::getRegisterBitWidth(bool Vector) {
if (Vector && getST()->hasSIMD128())
return 128;
return 64;
}
unsigned WebAssemblyTTIImpl::getArithmeticInstrCost(
unsigned Opcode, Type *Ty, TTI::OperandValueKind Opd1Info,
TTI::OperandValueKind Opd2Info, TTI::OperandValueProperties Opd1PropInfo,
TTI::OperandValueProperties Opd2PropInfo) {
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;
}

View File

@ -61,7 +61,15 @@ public:
/// \name Vector TTI Implementations
/// @{
// TODO: Implement Vector TTI for WebAssembly
unsigned getNumberOfRegisters(bool Vector);
unsigned getRegisterBitWidth(bool Vector);
unsigned getArithmeticInstrCost(
unsigned Opcode, Type *Ty,
TTI::OperandValueKind Opd1Info = TTI::OK_AnyValue,
TTI::OperandValueKind Opd2Info = TTI::OK_AnyValue,
TTI::OperandValueProperties Opd1PropInfo = TTI::OP_None,
TTI::OperandValueProperties Opd2PropInfo = TTI::OP_None);
unsigned getVectorInstrCost(unsigned Opcode, Type *Val, unsigned Index);
/// @}
};