mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-05-18 06:38:41 +00:00
Make LoopUnswitch's cost estimation count Instructions, rather than
BasicBlocks, so that it doesn't blindly procede in the presence of large individual BasicBlocks. This addresses a class of code-size expansion problems. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@83992 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
61358ab843
commit
b24f6c7495
@ -56,9 +56,11 @@ STATISTIC(NumSelects , "Number of selects unswitched");
|
|||||||
STATISTIC(NumTrivial , "Number of unswitches that are trivial");
|
STATISTIC(NumTrivial , "Number of unswitches that are trivial");
|
||||||
STATISTIC(NumSimplify, "Number of simplifications of unswitched code");
|
STATISTIC(NumSimplify, "Number of simplifications of unswitched code");
|
||||||
|
|
||||||
|
// The specific value of 50 here was chosen based only on intuition and a
|
||||||
|
// few specific examples.
|
||||||
static cl::opt<unsigned>
|
static cl::opt<unsigned>
|
||||||
Threshold("loop-unswitch-threshold", cl::desc("Max loop size to unswitch"),
|
Threshold("loop-unswitch-threshold", cl::desc("Max loop size to unswitch"),
|
||||||
cl::init(10), cl::Hidden);
|
cl::init(50), cl::Hidden);
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
class LoopUnswitch : public LoopPass {
|
class LoopUnswitch : public LoopPass {
|
||||||
@ -406,27 +408,13 @@ unsigned LoopUnswitch::getLoopUnswitchCost(Value *LIC) {
|
|||||||
if (IsTrivialUnswitchCondition(LIC))
|
if (IsTrivialUnswitchCondition(LIC))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
// FIXME: This is really overly conservative. However, more liberal
|
// FIXME: This is really overly conservative and brain dead.
|
||||||
// estimations have thus far resulted in excessive unswitching, which is bad
|
|
||||||
// both in compile time and in code size. This should be replaced once
|
|
||||||
// someone figures out how a good estimation.
|
|
||||||
return currentLoop->getBlocks().size();
|
|
||||||
|
|
||||||
unsigned Cost = 0;
|
unsigned Cost = 0;
|
||||||
// FIXME: this is brain dead. It should take into consideration code
|
|
||||||
// shrinkage.
|
|
||||||
for (Loop::block_iterator I = currentLoop->block_begin(),
|
for (Loop::block_iterator I = currentLoop->block_begin(),
|
||||||
E = currentLoop->block_end();
|
E = currentLoop->block_end();
|
||||||
I != E; ++I) {
|
I != E; ++I)
|
||||||
BasicBlock *BB = *I;
|
// Count instructions.
|
||||||
// Do not include empty blocks in the cost calculation. This happen due to
|
Cost += (*I)->size();
|
||||||
// loop canonicalization and will be removed.
|
|
||||||
if (BB->begin() == BasicBlock::iterator(BB->getTerminator()))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
// Count basic blocks.
|
|
||||||
++Cost;
|
|
||||||
}
|
|
||||||
|
|
||||||
return Cost;
|
return Cost;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user