mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-14 11:32:34 +00:00
Vectorization Factor clarification
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@173691 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
647c66e24d
commit
237f09db09
@ -516,14 +516,18 @@ public:
|
|||||||
const TargetTransformInfo &TTI)
|
const TargetTransformInfo &TTI)
|
||||||
: TheLoop(L), SE(SE), LI(LI), Legal(Legal), TTI(TTI) {}
|
: TheLoop(L), SE(SE), LI(LI), Legal(Legal), TTI(TTI) {}
|
||||||
|
|
||||||
|
/// Information about vectorization costs
|
||||||
|
struct VectorizationFactor {
|
||||||
|
unsigned Width; // Vector width with best cost
|
||||||
|
unsigned Cost; // Cost of the loop with that width
|
||||||
|
};
|
||||||
/// \return The most profitable vectorization factor and the cost of that VF.
|
/// \return The most profitable vectorization factor and the cost of that VF.
|
||||||
/// This method checks every power of two up to VF. If UserVF is not ZERO
|
/// This method checks every power of two up to VF. If UserVF is not ZERO
|
||||||
/// then this vectorization factor will be selected if vectorization is
|
/// then this vectorization factor will be selected if vectorization is
|
||||||
/// possible.
|
/// possible.
|
||||||
std::pair<unsigned, unsigned>
|
VectorizationFactor selectVectorizationFactor(bool OptForSize, unsigned UserVF);
|
||||||
selectVectorizationFactor(bool OptForSize, unsigned UserVF);
|
|
||||||
|
|
||||||
/// \returns The size (in bits) of the widest type in the code that
|
/// \return The size (in bits) of the widest type in the code that
|
||||||
/// needs to be vectorized. We ignore values that remain scalar such as
|
/// needs to be vectorized. We ignore values that remain scalar such as
|
||||||
/// 64 bit loop indices.
|
/// 64 bit loop indices.
|
||||||
unsigned getWidestType();
|
unsigned getWidestType();
|
||||||
@ -633,24 +637,23 @@ struct LoopVectorize : public LoopPass {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Select the optimal vectorization factor.
|
// Select the optimal vectorization factor.
|
||||||
std::pair<unsigned, unsigned> VFPair;
|
LoopVectorizationCostModel::VectorizationFactor VF;
|
||||||
VFPair = CM.selectVectorizationFactor(OptForSize, VectorizationFactor);
|
VF = CM.selectVectorizationFactor(OptForSize, VectorizationFactor);
|
||||||
// Select the unroll factor.
|
// Select the unroll factor.
|
||||||
unsigned UF = CM.selectUnrollFactor(OptForSize, VectorizationUnroll,
|
unsigned UF = CM.selectUnrollFactor(OptForSize, VectorizationUnroll,
|
||||||
VFPair.first, VFPair.second);
|
VF.Width, VF.Cost);
|
||||||
unsigned VF = VFPair.first;
|
|
||||||
|
|
||||||
if (VF == 1) {
|
if (VF.Width == 1) {
|
||||||
DEBUG(dbgs() << "LV: Vectorization is possible but not beneficial.\n");
|
DEBUG(dbgs() << "LV: Vectorization is possible but not beneficial.\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
DEBUG(dbgs() << "LV: Found a vectorizable loop ("<< VF << ") in "<<
|
DEBUG(dbgs() << "LV: Found a vectorizable loop ("<< VF.Width << ") in "<<
|
||||||
F->getParent()->getModuleIdentifier()<<"\n");
|
F->getParent()->getModuleIdentifier()<<"\n");
|
||||||
DEBUG(dbgs() << "LV: Unroll Factor is " << UF << "\n");
|
DEBUG(dbgs() << "LV: Unroll Factor is " << UF << "\n");
|
||||||
|
|
||||||
// If we decided that it is *legal* to vectorizer the loop then do it.
|
// If we decided that it is *legal* to vectorizer the loop then do it.
|
||||||
InnerLoopVectorizer LB(L, SE, LI, DT, DL, VF, UF);
|
InnerLoopVectorizer LB(L, SE, LI, DT, DL, VF.Width, UF);
|
||||||
LB.vectorize(&LVL);
|
LB.vectorize(&LVL);
|
||||||
|
|
||||||
DEBUG(verifyFunction(*L->getHeader()->getParent()));
|
DEBUG(verifyFunction(*L->getHeader()->getParent()));
|
||||||
@ -2675,12 +2678,14 @@ bool LoopVectorizationLegality::hasComputableBounds(Value *Ptr) {
|
|||||||
return AR->isAffine();
|
return AR->isAffine();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::pair<unsigned, unsigned>
|
LoopVectorizationCostModel::VectorizationFactor
|
||||||
LoopVectorizationCostModel::selectVectorizationFactor(bool OptForSize,
|
LoopVectorizationCostModel::selectVectorizationFactor(bool OptForSize,
|
||||||
unsigned UserVF) {
|
unsigned UserVF) {
|
||||||
|
// Width 1 means no vectorize
|
||||||
|
VectorizationFactor Factor = { 1U, 0U };
|
||||||
if (OptForSize && Legal->getRuntimePointerCheck()->Need) {
|
if (OptForSize && Legal->getRuntimePointerCheck()->Need) {
|
||||||
DEBUG(dbgs() << "LV: Aborting. Runtime ptr check is required in Os.\n");
|
DEBUG(dbgs() << "LV: Aborting. Runtime ptr check is required in Os.\n");
|
||||||
return std::make_pair(1U, 0U);
|
return Factor;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find the trip count.
|
// Find the trip count.
|
||||||
@ -2708,7 +2713,7 @@ LoopVectorizationCostModel::selectVectorizationFactor(bool OptForSize,
|
|||||||
// If we are unable to calculate the trip count then don't try to vectorize.
|
// If we are unable to calculate the trip count then don't try to vectorize.
|
||||||
if (TC < 2) {
|
if (TC < 2) {
|
||||||
DEBUG(dbgs() << "LV: Aborting. A tail loop is required in Os.\n");
|
DEBUG(dbgs() << "LV: Aborting. A tail loop is required in Os.\n");
|
||||||
return std::make_pair(1U, 0U);
|
return Factor;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find the maximum SIMD width that can fit within the trip count.
|
// Find the maximum SIMD width that can fit within the trip count.
|
||||||
@ -2721,7 +2726,7 @@ LoopVectorizationCostModel::selectVectorizationFactor(bool OptForSize,
|
|||||||
// zero then we require a tail.
|
// zero then we require a tail.
|
||||||
if (VF < 2) {
|
if (VF < 2) {
|
||||||
DEBUG(dbgs() << "LV: Aborting. A tail loop is required in Os.\n");
|
DEBUG(dbgs() << "LV: Aborting. A tail loop is required in Os.\n");
|
||||||
return std::make_pair(1U, 0U);
|
return Factor;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2729,7 +2734,8 @@ LoopVectorizationCostModel::selectVectorizationFactor(bool OptForSize,
|
|||||||
assert(isPowerOf2_32(UserVF) && "VF needs to be a power of two");
|
assert(isPowerOf2_32(UserVF) && "VF needs to be a power of two");
|
||||||
DEBUG(dbgs() << "LV: Using user VF "<<UserVF<<".\n");
|
DEBUG(dbgs() << "LV: Using user VF "<<UserVF<<".\n");
|
||||||
|
|
||||||
return std::make_pair(UserVF, 0U);
|
Factor.Width = UserVF;
|
||||||
|
return Factor;
|
||||||
}
|
}
|
||||||
|
|
||||||
float Cost = expectedCost(1);
|
float Cost = expectedCost(1);
|
||||||
@ -2749,8 +2755,9 @@ LoopVectorizationCostModel::selectVectorizationFactor(bool OptForSize,
|
|||||||
}
|
}
|
||||||
|
|
||||||
DEBUG(dbgs() << "LV: Selecting VF = : "<< Width << ".\n");
|
DEBUG(dbgs() << "LV: Selecting VF = : "<< Width << ".\n");
|
||||||
unsigned LoopCost = VF * Cost;
|
Factor.Width = Width;
|
||||||
return std::make_pair(Width, LoopCost);
|
Factor.Cost = Width * Cost;
|
||||||
|
return Factor;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned LoopVectorizationCostModel::getWidestType() {
|
unsigned LoopVectorizationCostModel::getWidestType() {
|
||||||
|
Loading…
Reference in New Issue
Block a user