2017-06-02 07:25:02 +08:00
|
|
|
//===- lib/Codegen/MachineRegionInfo.cpp ----------------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2017-06-06 19:49:48 +08:00
|
|
|
#include "llvm/CodeGen/MachineRegionInfo.h"
|
2014-07-20 02:29:29 +08:00
|
|
|
#include "llvm/ADT/Statistic.h"
|
|
|
|
#include "llvm/Analysis/RegionInfoImpl.h"
|
2015-01-14 19:23:27 +08:00
|
|
|
#include "llvm/CodeGen/MachinePostDominators.h"
|
2017-06-02 07:25:02 +08:00
|
|
|
#include "llvm/Pass.h"
|
|
|
|
#include "llvm/Support/Compiler.h"
|
|
|
|
#include "llvm/Support/Debug.h"
|
2014-07-20 02:29:29 +08:00
|
|
|
|
2017-02-18 08:41:16 +08:00
|
|
|
#define DEBUG_TYPE "machine-region-info"
|
2014-07-30 08:25:24 +08:00
|
|
|
|
2014-07-20 02:29:29 +08:00
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
STATISTIC(numMachineRegions, "The # of machine regions");
|
|
|
|
STATISTIC(numMachineSimpleRegions, "The # of simple machine regions");
|
|
|
|
|
|
|
|
namespace llvm {
|
2017-06-02 07:25:02 +08:00
|
|
|
|
2014-07-20 02:29:29 +08:00
|
|
|
template class RegionBase<RegionTraits<MachineFunction>>;
|
|
|
|
template class RegionNodeBase<RegionTraits<MachineFunction>>;
|
|
|
|
template class RegionInfoBase<RegionTraits<MachineFunction>>;
|
2017-06-02 07:25:02 +08:00
|
|
|
|
|
|
|
} // end namespace llvm
|
2014-07-20 02:29:29 +08:00
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// MachineRegion implementation
|
|
|
|
|
|
|
|
MachineRegion::MachineRegion(MachineBasicBlock *Entry, MachineBasicBlock *Exit,
|
|
|
|
MachineRegionInfo* RI,
|
|
|
|
MachineDominatorTree *DT, MachineRegion *Parent) :
|
2017-06-02 07:25:02 +08:00
|
|
|
RegionBase<RegionTraits<MachineFunction>>(Entry, Exit, RI, DT, Parent) {}
|
2014-07-20 02:29:29 +08:00
|
|
|
|
2017-06-02 07:25:02 +08:00
|
|
|
MachineRegion::~MachineRegion() = default;
|
2014-07-20 02:29:29 +08:00
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// MachineRegionInfo implementation
|
|
|
|
|
2017-06-02 07:25:02 +08:00
|
|
|
MachineRegionInfo::MachineRegionInfo() = default;
|
2014-07-20 02:29:29 +08:00
|
|
|
|
2017-06-02 07:25:02 +08:00
|
|
|
MachineRegionInfo::~MachineRegionInfo() = default;
|
2014-07-20 02:29:29 +08:00
|
|
|
|
|
|
|
void MachineRegionInfo::updateStatistics(MachineRegion *R) {
|
|
|
|
++numMachineRegions;
|
|
|
|
|
|
|
|
// TODO: Slow. Should only be enabled if -stats is used.
|
|
|
|
if (R->isSimple())
|
|
|
|
++numMachineSimpleRegions;
|
|
|
|
}
|
|
|
|
|
2014-07-20 19:14:55 +08:00
|
|
|
void MachineRegionInfo::recalculate(MachineFunction &F,
|
|
|
|
MachineDominatorTree *DT_,
|
|
|
|
MachinePostDominatorTree *PDT_,
|
|
|
|
MachineDominanceFrontier *DF_) {
|
2014-07-20 02:29:29 +08:00
|
|
|
DT = DT_;
|
|
|
|
PDT = PDT_;
|
|
|
|
DF = DF_;
|
|
|
|
|
|
|
|
MachineBasicBlock *Entry = GraphTraits<MachineFunction*>::getEntryNode(&F);
|
|
|
|
|
|
|
|
TopLevelRegion = new MachineRegion(Entry, nullptr, this, DT, nullptr);
|
|
|
|
updateStatistics(TopLevelRegion);
|
|
|
|
calculate(F);
|
|
|
|
}
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// MachineRegionInfoPass implementation
|
|
|
|
//
|
|
|
|
|
|
|
|
MachineRegionInfoPass::MachineRegionInfoPass() : MachineFunctionPass(ID) {
|
|
|
|
initializeMachineRegionInfoPassPass(*PassRegistry::getPassRegistry());
|
|
|
|
}
|
|
|
|
|
2017-06-02 07:25:02 +08:00
|
|
|
MachineRegionInfoPass::~MachineRegionInfoPass() = default;
|
2014-07-20 02:29:29 +08:00
|
|
|
|
|
|
|
bool MachineRegionInfoPass::runOnMachineFunction(MachineFunction &F) {
|
|
|
|
releaseMemory();
|
|
|
|
|
|
|
|
auto DT = &getAnalysis<MachineDominatorTree>();
|
|
|
|
auto PDT = &getAnalysis<MachinePostDominatorTree>();
|
|
|
|
auto DF = &getAnalysis<MachineDominanceFrontier>();
|
|
|
|
|
|
|
|
RI.recalculate(F, DT, PDT, DF);
|
2017-02-18 08:41:16 +08:00
|
|
|
|
|
|
|
DEBUG(RI.dump());
|
|
|
|
|
2014-07-20 02:29:29 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MachineRegionInfoPass::releaseMemory() {
|
|
|
|
RI.releaseMemory();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MachineRegionInfoPass::verifyAnalysis() const {
|
|
|
|
// Only do verification when user wants to, otherwise this expensive check
|
|
|
|
// will be invoked by PMDataManager::verifyPreservedAnalysis when
|
|
|
|
// a regionpass (marked PreservedAll) finish.
|
|
|
|
if (MachineRegionInfo::VerifyRegionInfo)
|
|
|
|
RI.verifyAnalysis();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MachineRegionInfoPass::getAnalysisUsage(AnalysisUsage &AU) const {
|
|
|
|
AU.setPreservesAll();
|
2017-02-18 08:41:16 +08:00
|
|
|
AU.addRequired<MachineDominatorTree>();
|
|
|
|
AU.addRequired<MachinePostDominatorTree>();
|
|
|
|
AU.addRequired<MachineDominanceFrontier>();
|
|
|
|
MachineFunctionPass::getAnalysisUsage(AU);
|
2014-07-20 02:29:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void MachineRegionInfoPass::print(raw_ostream &OS, const Module *) const {
|
|
|
|
RI.print(OS);
|
|
|
|
}
|
|
|
|
|
2014-07-20 08:00:42 +08:00
|
|
|
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
|
2016-01-30 04:50:44 +08:00
|
|
|
LLVM_DUMP_METHOD void MachineRegionInfoPass::dump() const {
|
2014-07-20 02:29:29 +08:00
|
|
|
RI.dump();
|
|
|
|
}
|
2014-07-20 08:00:42 +08:00
|
|
|
#endif
|
2014-07-20 02:29:29 +08:00
|
|
|
|
|
|
|
char MachineRegionInfoPass::ID = 0;
|
2017-04-11 19:40:55 +08:00
|
|
|
char &MachineRegionInfoPassID = MachineRegionInfoPass::ID;
|
2014-07-20 02:29:29 +08:00
|
|
|
|
2017-02-18 08:41:16 +08:00
|
|
|
INITIALIZE_PASS_BEGIN(MachineRegionInfoPass, DEBUG_TYPE,
|
|
|
|
"Detect single entry single exit regions", true, true)
|
2014-07-20 02:29:29 +08:00
|
|
|
INITIALIZE_PASS_DEPENDENCY(MachineDominatorTree)
|
|
|
|
INITIALIZE_PASS_DEPENDENCY(MachinePostDominatorTree)
|
|
|
|
INITIALIZE_PASS_DEPENDENCY(MachineDominanceFrontier)
|
2017-02-18 08:41:16 +08:00
|
|
|
INITIALIZE_PASS_END(MachineRegionInfoPass, DEBUG_TYPE,
|
|
|
|
"Detect single entry single exit regions", true, true)
|
2014-07-20 02:29:29 +08:00
|
|
|
|
|
|
|
// Create methods available outside of this file, to use them
|
|
|
|
// "include/llvm/LinkAllPasses.h". Otherwise the pass would be deleted by
|
|
|
|
// the link time optimization.
|
|
|
|
|
|
|
|
namespace llvm {
|
2017-06-02 07:25:02 +08:00
|
|
|
|
|
|
|
FunctionPass *createMachineRegionInfoPass() {
|
|
|
|
return new MachineRegionInfoPass();
|
2014-07-20 02:29:29 +08:00
|
|
|
}
|
|
|
|
|
2017-06-02 07:25:02 +08:00
|
|
|
} // end namespace llvm
|