diff --git a/llvm/include/llvm/Analysis/TargetTransformInfo.h b/llvm/include/llvm/Analysis/TargetTransformInfo.h --- a/llvm/include/llvm/Analysis/TargetTransformInfo.h +++ b/llvm/include/llvm/Analysis/TargetTransformInfo.h @@ -853,6 +853,14 @@ /// prefetching is performed. unsigned getMaxPrefetchIterationsAhead() const; + /// \return the number of write-combining buffers. A write-combining buffer is + /// a per-core resource used for collecting writes to a particular cache line + /// before further processing those writes using other parts of the memory + /// subsystem. Knowledge of the number of write-combining buffers available + /// can help the optimizer manage those resources, for example fissioning + /// loops to avoid oversubscribing write-combining buffers. + unsigned getNumWriteCombiningBuffers() const; + /// \return The maximum interleave factor that any transform should try to /// perform for this target. This number depends on the level of parallelism /// and the number of execution units in the CPU. @@ -1272,6 +1280,9 @@ /// prefetching is performed. virtual unsigned getMaxPrefetchIterationsAhead() const = 0; + /// \return the number of write-combining buffers. + virtual unsigned getNumWriteCombiningBuffers() const = 0; + virtual unsigned getMaxInterleaveFactor(unsigned VF) = 0; virtual unsigned getArithmeticInstrCost(unsigned Opcode, Type *Ty, OperandValueKind Opd1Info, @@ -1652,6 +1663,11 @@ return Impl.getMaxPrefetchIterationsAhead(); } + /// Return the number of write-combining buffers. + unsigned getNumWriteCombiningBuffers() const override { + return Impl.getNumWriteCombiningBuffers(); + } + unsigned getMaxInterleaveFactor(unsigned VF) override { return Impl.getMaxInterleaveFactor(VF); } diff --git a/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h b/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h --- a/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h +++ b/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h @@ -371,6 +371,11 @@ return false; } + /// Return the default number of write-combining buffers. + unsigned getNumWriteCombiningBuffers() const { + return 0; + } + unsigned getMaxInterleaveFactor(unsigned VF) { return 1; } unsigned getArithmeticInstrCost(unsigned Opcode, Type *Ty, diff --git a/llvm/include/llvm/CodeGen/BasicTTIImpl.h b/llvm/include/llvm/CodeGen/BasicTTIImpl.h --- a/llvm/include/llvm/CodeGen/BasicTTIImpl.h +++ b/llvm/include/llvm/CodeGen/BasicTTIImpl.h @@ -543,6 +543,11 @@ return getST()->getMaxPrefetchIterationsAhead(); } + /// Return the number of write-combining buffers. + unsigned getNumWriteCombiningBuffers() const { + return getST()->getNumWriteCombiningBuffers(); + } + /// @} /// \name Vector TTI Implementations diff --git a/llvm/include/llvm/MC/MCSubtargetInfo.h b/llvm/include/llvm/MC/MCSubtargetInfo.h --- a/llvm/include/llvm/MC/MCSubtargetInfo.h +++ b/llvm/include/llvm/MC/MCSubtargetInfo.h @@ -267,6 +267,9 @@ /// prefetching. /// virtual unsigned getMinPrefetchStride() const; + + /// Return the number of write-combining buffers. + virtual unsigned getNumWriteCombiningBuffers() const; }; } // end namespace llvm diff --git a/llvm/lib/Analysis/TargetTransformInfo.cpp b/llvm/lib/Analysis/TargetTransformInfo.cpp --- a/llvm/lib/Analysis/TargetTransformInfo.cpp +++ b/llvm/lib/Analysis/TargetTransformInfo.cpp @@ -546,6 +546,10 @@ return TTIImpl->getMaxPrefetchIterationsAhead(); } +unsigned TargetTransformInfo::getNumWriteCombiningBuffers() const { + return TTIImpl->getNumWriteCombiningBuffers(); +} + unsigned TargetTransformInfo::getMaxInterleaveFactor(unsigned VF) const { return TTIImpl->getMaxInterleaveFactor(VF); } diff --git a/llvm/lib/MC/MCSubtargetInfo.cpp b/llvm/lib/MC/MCSubtargetInfo.cpp --- a/llvm/lib/MC/MCSubtargetInfo.cpp +++ b/llvm/lib/MC/MCSubtargetInfo.cpp @@ -340,3 +340,7 @@ unsigned MCSubtargetInfo::getMinPrefetchStride() const { return 1; } + +unsigned MCSubtargetInfo::getNumWriteCombiningBuffers() const { + return 0; +}