mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-09 13:33:17 +00:00
Passing unroll parameters (unroll-count, threshold, and partial unroll) via LoopUnroll class's ctor. Doing so
will allow multiple context with different loop unroll parameters to run. This is a minor change and no effect on existing application. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@129449 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
4f9f41f2f9
commit
32644d9bfd
@ -128,7 +128,7 @@ Pass *createLoopInstSimplifyPass();
|
|||||||
//
|
//
|
||||||
// LoopUnroll - This pass is a simple loop unrolling pass.
|
// LoopUnroll - This pass is a simple loop unrolling pass.
|
||||||
//
|
//
|
||||||
Pass *createLoopUnrollPass();
|
Pass *createLoopUnrollPass(int Threshold = -1, int Count = -1, int AllowPartial = -1);
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
//
|
//
|
||||||
|
@ -43,7 +43,13 @@ namespace {
|
|||||||
class LoopUnroll : public LoopPass {
|
class LoopUnroll : public LoopPass {
|
||||||
public:
|
public:
|
||||||
static char ID; // Pass ID, replacement for typeid
|
static char ID; // Pass ID, replacement for typeid
|
||||||
LoopUnroll() : LoopPass(ID) {
|
LoopUnroll(int T = -1, int C = -1, int P = -1) : LoopPass(ID) {
|
||||||
|
CurrentThreshold = (T == -1) ? UnrollThreshold : T;
|
||||||
|
CurrentCount = (C == -1) ? UnrollCount : C;
|
||||||
|
CurrentAllowPartial = (P == -1) ? UnrollAllowPartial : (bool)P;
|
||||||
|
|
||||||
|
UserThreshold = (T != -1) || (UnrollThreshold.getNumOccurrences() > 0);
|
||||||
|
|
||||||
initializeLoopUnrollPass(*PassRegistry::getPassRegistry());
|
initializeLoopUnrollPass(*PassRegistry::getPassRegistry());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,7 +62,10 @@ namespace {
|
|||||||
// explicit -unroll-threshold).
|
// explicit -unroll-threshold).
|
||||||
static const unsigned OptSizeUnrollThreshold = 50;
|
static const unsigned OptSizeUnrollThreshold = 50;
|
||||||
|
|
||||||
|
unsigned CurrentCount;
|
||||||
unsigned CurrentThreshold;
|
unsigned CurrentThreshold;
|
||||||
|
bool CurrentAllowPartial;
|
||||||
|
bool UserThreshold; // CurrentThreshold is user-specified.
|
||||||
|
|
||||||
bool runOnLoop(Loop *L, LPPassManager &LPM);
|
bool runOnLoop(Loop *L, LPPassManager &LPM);
|
||||||
|
|
||||||
@ -87,7 +96,9 @@ INITIALIZE_PASS_DEPENDENCY(LoopSimplify)
|
|||||||
INITIALIZE_PASS_DEPENDENCY(LCSSA)
|
INITIALIZE_PASS_DEPENDENCY(LCSSA)
|
||||||
INITIALIZE_PASS_END(LoopUnroll, "loop-unroll", "Unroll loops", false, false)
|
INITIALIZE_PASS_END(LoopUnroll, "loop-unroll", "Unroll loops", false, false)
|
||||||
|
|
||||||
Pass *llvm::createLoopUnrollPass() { return new LoopUnroll(); }
|
Pass *llvm::createLoopUnrollPass(int Threshold, int Count, int AllowPartial) {
|
||||||
|
return new LoopUnroll();
|
||||||
|
}
|
||||||
|
|
||||||
/// ApproximateLoopSize - Approximate the size of the loop.
|
/// ApproximateLoopSize - Approximate the size of the loop.
|
||||||
static unsigned ApproximateLoopSize(const Loop *L, unsigned &NumCalls) {
|
static unsigned ApproximateLoopSize(const Loop *L, unsigned &NumCalls) {
|
||||||
@ -119,14 +130,14 @@ bool LoopUnroll::runOnLoop(Loop *L, LPPassManager &LPM) {
|
|||||||
// from UnrollThreshold, it is overridden to a smaller value if the current
|
// from UnrollThreshold, it is overridden to a smaller value if the current
|
||||||
// function is marked as optimize-for-size, and the unroll threshold was
|
// function is marked as optimize-for-size, and the unroll threshold was
|
||||||
// not user specified.
|
// not user specified.
|
||||||
CurrentThreshold = UnrollThreshold;
|
unsigned Threshold = CurrentThreshold;
|
||||||
if (Header->getParent()->hasFnAttr(Attribute::OptimizeForSize) &&
|
if (!UserThreshold &&
|
||||||
UnrollThreshold.getNumOccurrences() == 0)
|
Header->getParent()->hasFnAttr(Attribute::OptimizeForSize))
|
||||||
CurrentThreshold = OptSizeUnrollThreshold;
|
Threshold = OptSizeUnrollThreshold;
|
||||||
|
|
||||||
// Find trip count
|
// Find trip count
|
||||||
unsigned TripCount = L->getSmallConstantTripCount();
|
unsigned TripCount = L->getSmallConstantTripCount();
|
||||||
unsigned Count = UnrollCount;
|
unsigned Count = CurrentCount;
|
||||||
|
|
||||||
// Automatically select an unroll count.
|
// Automatically select an unroll count.
|
||||||
if (Count == 0) {
|
if (Count == 0) {
|
||||||
@ -140,7 +151,7 @@ bool LoopUnroll::runOnLoop(Loop *L, LPPassManager &LPM) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Enforce the threshold.
|
// Enforce the threshold.
|
||||||
if (CurrentThreshold != NoThreshold) {
|
if (Threshold != NoThreshold) {
|
||||||
unsigned NumInlineCandidates;
|
unsigned NumInlineCandidates;
|
||||||
unsigned LoopSize = ApproximateLoopSize(L, NumInlineCandidates);
|
unsigned LoopSize = ApproximateLoopSize(L, NumInlineCandidates);
|
||||||
DEBUG(dbgs() << " Loop Size = " << LoopSize << "\n");
|
DEBUG(dbgs() << " Loop Size = " << LoopSize << "\n");
|
||||||
@ -149,16 +160,16 @@ bool LoopUnroll::runOnLoop(Loop *L, LPPassManager &LPM) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
uint64_t Size = (uint64_t)LoopSize*Count;
|
uint64_t Size = (uint64_t)LoopSize*Count;
|
||||||
if (TripCount != 1 && Size > CurrentThreshold) {
|
if (TripCount != 1 && Size > Threshold) {
|
||||||
DEBUG(dbgs() << " Too large to fully unroll with count: " << Count
|
DEBUG(dbgs() << " Too large to fully unroll with count: " << Count
|
||||||
<< " because size: " << Size << ">" << CurrentThreshold << "\n");
|
<< " because size: " << Size << ">" << Threshold << "\n");
|
||||||
if (!UnrollAllowPartial) {
|
if (!CurrentAllowPartial) {
|
||||||
DEBUG(dbgs() << " will not try to unroll partially because "
|
DEBUG(dbgs() << " will not try to unroll partially because "
|
||||||
<< "-unroll-allow-partial not given\n");
|
<< "-unroll-allow-partial not given\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Reduce unroll count to be modulo of TripCount for partial unrolling
|
// Reduce unroll count to be modulo of TripCount for partial unrolling
|
||||||
Count = CurrentThreshold / LoopSize;
|
Count = Threshold / LoopSize;
|
||||||
while (Count != 0 && TripCount%Count != 0) {
|
while (Count != 0 && TripCount%Count != 0) {
|
||||||
Count--;
|
Count--;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user