mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-17 03:30:28 +00:00
37aa33bc11
-stable-loops enables a new algorithm for generating the Loop forest. It differs from the original algorithm in a few respects: - Not determined by use-list order. - Initially guarantees RPO order of block and subloops. - Linear in the number of CFG edges. - Nonrecursive. I didn't want to change the LoopInfo API yet, so the block lists are still inclusive. This seems strange to me, and it means that building LoopInfo is not strictly linear, but it may not be a problem in practice. At least the block lists start out in RPO order now. In the future we may add an attribute or wrapper analysis that allows other passes to assume RPO order. The primary motivation of this work was not to optimize LoopInfo, but to allow reproducing performance issues by decomposing the compilation stages. I'm often unable to do this with the current LoopInfo, because the loop tree order determines Loop pass order. Serializing the IR tends to invert the order, which reverses the optimization order. This makes it nearly impossible to debug interdependent loop optimizations such as LSR. I also believe this will provide more stable performance results across time. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@158790 91177308-0d34-0410-b5e6-96231b3b80d8
88 lines
3.1 KiB
C++
88 lines
3.1 KiB
C++
//===- MachineLoopInfo.cpp - Natural Loop Calculator ----------------------===//
|
|
//
|
|
// The LLVM Compiler Infrastructure
|
|
//
|
|
// This file is distributed under the University of Illinois Open Source
|
|
// License. See LICENSE.TXT for details.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This file defines the MachineLoopInfo class that is used to identify natural
|
|
// loops and determine the loop depth of various nodes of the CFG. Note that
|
|
// the loops identified may actually be several natural loops that share the
|
|
// same header node... not just a single natural loop.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "llvm/CodeGen/MachineLoopInfo.h"
|
|
#include "llvm/CodeGen/MachineDominators.h"
|
|
#include "llvm/CodeGen/Passes.h"
|
|
#include "llvm/Analysis/LoopInfoImpl.h"
|
|
#include "llvm/Support/CommandLine.h"
|
|
#include "llvm/Support/Debug.h"
|
|
using namespace llvm;
|
|
|
|
// Explicitly instantiate methods in LoopInfoImpl.h for MI-level Loops.
|
|
template class llvm::LoopBase<MachineBasicBlock, MachineLoop>;
|
|
template class llvm::LoopInfoBase<MachineBasicBlock, MachineLoop>;
|
|
|
|
static cl::opt<bool>
|
|
StableLoopInfo("stable-machine-loops", cl::Hidden, cl::init(false),
|
|
cl::desc("Compute a stable loop tree."));
|
|
|
|
char MachineLoopInfo::ID = 0;
|
|
INITIALIZE_PASS_BEGIN(MachineLoopInfo, "machine-loops",
|
|
"Machine Natural Loop Construction", true, true)
|
|
INITIALIZE_PASS_DEPENDENCY(MachineDominatorTree)
|
|
INITIALIZE_PASS_END(MachineLoopInfo, "machine-loops",
|
|
"Machine Natural Loop Construction", true, true)
|
|
|
|
char &llvm::MachineLoopInfoID = MachineLoopInfo::ID;
|
|
|
|
bool MachineLoopInfo::runOnMachineFunction(MachineFunction &) {
|
|
releaseMemory();
|
|
if (StableLoopInfo)
|
|
LI.Analyze(getAnalysis<MachineDominatorTree>().getBase());
|
|
else
|
|
LI.Calculate(getAnalysis<MachineDominatorTree>().getBase()); // Update
|
|
return false;
|
|
}
|
|
|
|
void MachineLoopInfo::getAnalysisUsage(AnalysisUsage &AU) const {
|
|
AU.setPreservesAll();
|
|
AU.addRequired<MachineDominatorTree>();
|
|
MachineFunctionPass::getAnalysisUsage(AU);
|
|
}
|
|
|
|
MachineBasicBlock *MachineLoop::getTopBlock() {
|
|
MachineBasicBlock *TopMBB = getHeader();
|
|
MachineFunction::iterator Begin = TopMBB->getParent()->begin();
|
|
if (TopMBB != Begin) {
|
|
MachineBasicBlock *PriorMBB = prior(MachineFunction::iterator(TopMBB));
|
|
while (contains(PriorMBB)) {
|
|
TopMBB = PriorMBB;
|
|
if (TopMBB == Begin) break;
|
|
PriorMBB = prior(MachineFunction::iterator(TopMBB));
|
|
}
|
|
}
|
|
return TopMBB;
|
|
}
|
|
|
|
MachineBasicBlock *MachineLoop::getBottomBlock() {
|
|
MachineBasicBlock *BotMBB = getHeader();
|
|
MachineFunction::iterator End = BotMBB->getParent()->end();
|
|
if (BotMBB != prior(End)) {
|
|
MachineBasicBlock *NextMBB = llvm::next(MachineFunction::iterator(BotMBB));
|
|
while (contains(NextMBB)) {
|
|
BotMBB = NextMBB;
|
|
if (BotMBB == llvm::next(MachineFunction::iterator(BotMBB))) break;
|
|
NextMBB = llvm::next(MachineFunction::iterator(BotMBB));
|
|
}
|
|
}
|
|
return BotMBB;
|
|
}
|
|
|
|
void MachineLoop::dump() const {
|
|
print(dbgs());
|
|
}
|