mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-08-07 12:28:24 +00:00
Factor out code for estimating search space complexity into a helper
function. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@104082 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -1241,6 +1241,8 @@ public:
|
|||||||
void GenerateAllReuseFormulae();
|
void GenerateAllReuseFormulae();
|
||||||
|
|
||||||
void FilterOutUndesirableDedicatedRegisters();
|
void FilterOutUndesirableDedicatedRegisters();
|
||||||
|
|
||||||
|
size_t EstimateSearchSpaceComplexity() const;
|
||||||
void NarrowSearchSpaceUsingHeuristics();
|
void NarrowSearchSpaceUsingHeuristics();
|
||||||
|
|
||||||
void SolveRecurse(SmallVectorImpl<const Formula *> &Solution,
|
void SolveRecurse(SmallVectorImpl<const Formula *> &Solution,
|
||||||
@@ -2665,34 +2667,36 @@ void LSRInstance::FilterOutUndesirableDedicatedRegisters() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This is a rough guess that seems to work fairly well.
|
||||||
|
static const size_t ComplexityLimit = UINT16_MAX;
|
||||||
|
|
||||||
|
/// EstimateSearchSpaceComplexity - Estimate the worst-case number of
|
||||||
|
/// solutions the solver might have to consider. It almost never considers
|
||||||
|
/// this many solutions because it prune the search space, but the pruning
|
||||||
|
/// isn't always sufficient.
|
||||||
|
size_t LSRInstance::EstimateSearchSpaceComplexity() const {
|
||||||
|
uint32_t Power = 1;
|
||||||
|
for (SmallVectorImpl<LSRUse>::const_iterator I = Uses.begin(),
|
||||||
|
E = Uses.end(); I != E; ++I) {
|
||||||
|
size_t FSize = I->Formulae.size();
|
||||||
|
if (FSize >= ComplexityLimit) {
|
||||||
|
Power = ComplexityLimit;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
Power *= FSize;
|
||||||
|
if (Power >= ComplexityLimit)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return Power;
|
||||||
|
}
|
||||||
|
|
||||||
/// NarrowSearchSpaceUsingHeuristics - If there are an extraordinary number of
|
/// NarrowSearchSpaceUsingHeuristics - If there are an extraordinary number of
|
||||||
/// formulae to choose from, use some rough heuristics to prune down the number
|
/// formulae to choose from, use some rough heuristics to prune down the number
|
||||||
/// of formulae. This keeps the main solver from taking an extraordinary amount
|
/// of formulae. This keeps the main solver from taking an extraordinary amount
|
||||||
/// of time in some worst-case scenarios.
|
/// of time in some worst-case scenarios.
|
||||||
void LSRInstance::NarrowSearchSpaceUsingHeuristics() {
|
void LSRInstance::NarrowSearchSpaceUsingHeuristics() {
|
||||||
// This is a rough guess that seems to work fairly well.
|
|
||||||
const size_t Limit = UINT16_MAX;
|
|
||||||
|
|
||||||
SmallPtrSet<const SCEV *, 4> Taken;
|
SmallPtrSet<const SCEV *, 4> Taken;
|
||||||
for (;;) {
|
while (EstimateSearchSpaceComplexity() >= ComplexityLimit) {
|
||||||
// Estimate the worst-case number of solutions we might consider. We almost
|
|
||||||
// never consider this many solutions because we prune the search space,
|
|
||||||
// but the pruning isn't always sufficient.
|
|
||||||
uint32_t Power = 1;
|
|
||||||
for (SmallVectorImpl<LSRUse>::const_iterator I = Uses.begin(),
|
|
||||||
E = Uses.end(); I != E; ++I) {
|
|
||||||
size_t FSize = I->Formulae.size();
|
|
||||||
if (FSize >= Limit) {
|
|
||||||
Power = Limit;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
Power *= FSize;
|
|
||||||
if (Power >= Limit)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (Power < Limit)
|
|
||||||
break;
|
|
||||||
|
|
||||||
// Ok, we have too many of formulae on our hands to conveniently handle.
|
// Ok, we have too many of formulae on our hands to conveniently handle.
|
||||||
// Use a rough heuristic to thin out the list.
|
// Use a rough heuristic to thin out the list.
|
||||||
DEBUG(dbgs() << "The search space is too complex.\n");
|
DEBUG(dbgs() << "The search space is too complex.\n");
|
||||||
|
Reference in New Issue
Block a user