diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2021-07-29 20:15:26 +0000 |
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2021-07-29 20:15:26 +0000 |
| commit | 344a3780b2e33f6ca763666c380202b18aab72a3 (patch) | |
| tree | f0b203ee6eb71d7fdd792373e3c81eb18d6934dd /llvm/lib/Target/WebAssembly/WebAssemblyTargetTransformInfo.cpp | |
| parent | b60736ec1405bb0a8dd40989f67ef4c93da068ab (diff) | |
vendor/llvm-project/llvmorg-13-init-16847-g88e66fa60ae5vendor/llvm-project/llvmorg-12.0.1-rc2-0-ge7dac564cd0evendor/llvm-project/llvmorg-12.0.1-0-gfed41342a82f
Diffstat (limited to 'llvm/lib/Target/WebAssembly/WebAssemblyTargetTransformInfo.cpp')
| -rw-r--r-- | llvm/lib/Target/WebAssembly/WebAssemblyTargetTransformInfo.cpp | 60 |
1 files changed, 48 insertions, 12 deletions
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyTargetTransformInfo.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyTargetTransformInfo.cpp index be1cfbaef3e4..d9bc7c6d2c3f 100644 --- a/llvm/lib/Target/WebAssembly/WebAssemblyTargetTransformInfo.cpp +++ b/llvm/lib/Target/WebAssembly/WebAssemblyTargetTransformInfo.cpp @@ -36,22 +36,30 @@ unsigned WebAssemblyTTIImpl::getNumberOfRegisters(unsigned ClassID) const { return Result; } -unsigned WebAssemblyTTIImpl::getRegisterBitWidth(bool Vector) const { - if (Vector && getST()->hasSIMD128()) - return 128; +TypeSize WebAssemblyTTIImpl::getRegisterBitWidth( + TargetTransformInfo::RegisterKind K) const { + switch (K) { + case TargetTransformInfo::RGK_Scalar: + return TypeSize::getFixed(64); + case TargetTransformInfo::RGK_FixedWidthVector: + return TypeSize::getFixed(getST()->hasSIMD128() ? 128 : 64); + case TargetTransformInfo::RGK_ScalableVector: + return TypeSize::getScalable(0); + } - return 64; + llvm_unreachable("Unsupported register kind"); } -unsigned WebAssemblyTTIImpl::getArithmeticInstrCost( +InstructionCost WebAssemblyTTIImpl::getArithmeticInstrCost( unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind, - TTI::OperandValueKind Opd1Info, - TTI::OperandValueKind Opd2Info, TTI::OperandValueProperties Opd1PropInfo, + TTI::OperandValueKind Opd1Info, TTI::OperandValueKind Opd2Info, + TTI::OperandValueProperties Opd1PropInfo, TTI::OperandValueProperties Opd2PropInfo, ArrayRef<const Value *> Args, const Instruction *CxtI) { - unsigned Cost = BasicTTIImplBase<WebAssemblyTTIImpl>::getArithmeticInstrCost( - Opcode, Ty, CostKind, Opd1Info, Opd2Info, Opd1PropInfo, Opd2PropInfo); + InstructionCost Cost = + BasicTTIImplBase<WebAssemblyTTIImpl>::getArithmeticInstrCost( + Opcode, Ty, CostKind, Opd1Info, Opd2Info, Opd1PropInfo, Opd2PropInfo); if (auto *VTy = dyn_cast<VectorType>(Ty)) { switch (Opcode) { @@ -74,9 +82,11 @@ unsigned WebAssemblyTTIImpl::getArithmeticInstrCost( return Cost; } -unsigned WebAssemblyTTIImpl::getVectorInstrCost(unsigned Opcode, Type *Val, - unsigned Index) { - unsigned Cost = BasicTTIImplBase::getVectorInstrCost(Opcode, Val, Index); +InstructionCost WebAssemblyTTIImpl::getVectorInstrCost(unsigned Opcode, + Type *Val, + unsigned Index) { + InstructionCost Cost = + BasicTTIImplBase::getVectorInstrCost(Opcode, Val, Index); // SIMD128's insert/extract currently only take constant indices. if (Index == -1u) @@ -102,3 +112,29 @@ bool WebAssemblyTTIImpl::areInlineCompatible(const Function *Caller, return (CallerBits & CalleeBits) == CalleeBits; } + +void WebAssemblyTTIImpl::getUnrollingPreferences( + Loop *L, ScalarEvolution &SE, TTI::UnrollingPreferences &UP) const { + // Scan the loop: don't unroll loops with calls. This is a standard approach + // for most (all?) targets. + for (BasicBlock *BB : L->blocks()) + for (Instruction &I : *BB) + if (isa<CallInst>(I) || isa<InvokeInst>(I)) + if (const Function *F = cast<CallBase>(I).getCalledFunction()) + if (isLoweredToCall(F)) + return; + + // The chosen threshold is within the range of 'LoopMicroOpBufferSize' of + // the various microarchitectures that use the BasicTTI implementation and + // has been selected through heuristics across multiple cores and runtimes. + UP.Partial = UP.Runtime = UP.UpperBound = true; + UP.PartialThreshold = 30; + + // Avoid unrolling when optimizing for size. + UP.OptSizeThreshold = 0; + UP.PartialOptSizeThreshold = 0; + + // Set number of instructions optimized when "back edge" + // becomes "fall through" to default value of 2. + UP.BEInsns = 2; +} |
