[CodeGen][NewPM] Port EdgeBundles analysis to NPM (#116616)
This commit is contained in:
parent
68aa6ac58c
commit
cac13606c2
@ -18,10 +18,16 @@
|
||||
#include "llvm/ADT/ArrayRef.h"
|
||||
#include "llvm/ADT/IntEqClasses.h"
|
||||
#include "llvm/CodeGen/MachineFunctionPass.h"
|
||||
#include "llvm/IR/PassManager.h"
|
||||
|
||||
namespace llvm {
|
||||
class EdgeBundlesWrapperLegacy;
|
||||
class EdgeBundlesAnalysis;
|
||||
|
||||
class EdgeBundles {
|
||||
friend class EdgeBundlesWrapperLegacy;
|
||||
friend class EdgeBundlesAnalysis;
|
||||
|
||||
class EdgeBundles : public MachineFunctionPass {
|
||||
const MachineFunction *MF = nullptr;
|
||||
|
||||
/// EC - Each edge bundle is an equivalence class. The keys are:
|
||||
@ -32,10 +38,10 @@ class EdgeBundles : public MachineFunctionPass {
|
||||
/// Blocks - Map each bundle to a list of basic block numbers.
|
||||
SmallVector<SmallVector<unsigned, 8>, 4> Blocks;
|
||||
|
||||
public:
|
||||
static char ID;
|
||||
EdgeBundles() : MachineFunctionPass(ID) {}
|
||||
void init();
|
||||
EdgeBundles(MachineFunction &MF);
|
||||
|
||||
public:
|
||||
/// getBundle - Return the ingoing (Out = false) or outgoing (Out = true)
|
||||
/// bundle number for basic block #N
|
||||
unsigned getBundle(unsigned N, bool Out) const { return EC[2 * N + Out]; }
|
||||
@ -52,11 +58,34 @@ public:
|
||||
/// view - Visualize the annotated bipartite CFG with Graphviz.
|
||||
void view() const;
|
||||
|
||||
// Handle invalidation for the new pass manager
|
||||
bool invalidate(MachineFunction &MF, const PreservedAnalyses &PA,
|
||||
MachineFunctionAnalysisManager::Invalidator &Inv);
|
||||
};
|
||||
|
||||
class EdgeBundlesWrapperLegacy : public MachineFunctionPass {
|
||||
public:
|
||||
static char ID;
|
||||
EdgeBundlesWrapperLegacy() : MachineFunctionPass(ID) {}
|
||||
|
||||
EdgeBundles &getEdgeBundles() { return *Impl; }
|
||||
const EdgeBundles &getEdgeBundles() const { return *Impl; }
|
||||
|
||||
private:
|
||||
bool runOnMachineFunction(MachineFunction&) override;
|
||||
std::unique_ptr<EdgeBundles> Impl;
|
||||
bool runOnMachineFunction(MachineFunction &MF) override;
|
||||
void getAnalysisUsage(AnalysisUsage&) const override;
|
||||
};
|
||||
|
||||
class EdgeBundlesAnalysis : public AnalysisInfoMixin<EdgeBundlesAnalysis> {
|
||||
friend AnalysisInfoMixin<EdgeBundlesAnalysis>;
|
||||
static AnalysisKey Key;
|
||||
|
||||
public:
|
||||
using Result = EdgeBundles;
|
||||
EdgeBundles run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM);
|
||||
};
|
||||
|
||||
} // end namespace llvm
|
||||
|
||||
#endif
|
||||
|
@ -118,7 +118,7 @@ namespace llvm {
|
||||
extern char &MachineRegionInfoPassID;
|
||||
|
||||
/// EdgeBundles analysis - Bundle machine CFG edges.
|
||||
extern char &EdgeBundlesID;
|
||||
extern char &EdgeBundlesWrapperLegacyID;
|
||||
|
||||
/// LiveVariables pass - This pass computes the set of blocks in which each
|
||||
/// variable is life and sets machine operand kill flags.
|
||||
|
@ -102,7 +102,7 @@ void initializeEarlyIfConverterLegacyPass(PassRegistry &);
|
||||
void initializeEarlyIfPredicatorPass(PassRegistry &);
|
||||
void initializeEarlyMachineLICMPass(PassRegistry &);
|
||||
void initializeEarlyTailDuplicateLegacyPass(PassRegistry &);
|
||||
void initializeEdgeBundlesPass(PassRegistry &);
|
||||
void initializeEdgeBundlesWrapperLegacyPass(PassRegistry &);
|
||||
void initializeEHContGuardCatchretPass(PassRegistry &);
|
||||
void initializeExpandLargeFpConvertLegacyPassPass(PassRegistry &);
|
||||
void initializeExpandLargeDivRemLegacyPassPass(PassRegistry &);
|
||||
|
@ -97,6 +97,7 @@ LOOP_PASS("loop-term-fold", LoopTermFoldPass())
|
||||
// LiveVariables can be removed completely, and LiveIntervals can be directly
|
||||
// computed. (We still either need to regenerate kill flags after regalloc, or
|
||||
// preferably fix the scavenger to not depend on them).
|
||||
MACHINE_FUNCTION_ANALYSIS("edge-bundles", EdgeBundlesAnalysis())
|
||||
MACHINE_FUNCTION_ANALYSIS("live-intervals", LiveIntervalsAnalysis())
|
||||
MACHINE_FUNCTION_ANALYSIS("live-reg-matrix", LiveRegMatrixAnalysis())
|
||||
MACHINE_FUNCTION_ANALYSIS("live-vars", LiveVariablesAnalysis())
|
||||
@ -114,7 +115,6 @@ MACHINE_FUNCTION_ANALYSIS("pass-instrumentation", PassInstrumentationAnalysis(PI
|
||||
MACHINE_FUNCTION_ANALYSIS("slot-indexes", SlotIndexesAnalysis())
|
||||
MACHINE_FUNCTION_ANALYSIS("virtregmap", VirtRegMapAnalysis())
|
||||
// MACHINE_FUNCTION_ANALYSIS("live-stacks", LiveStacksPass())
|
||||
// MACHINE_FUNCTION_ANALYSIS("edge-bundles", EdgeBundlesAnalysis())
|
||||
// MACHINE_FUNCTION_ANALYSIS("lazy-machine-bfi",
|
||||
// LazyMachineBlockFrequencyInfoAnalysis())
|
||||
// MACHINE_FUNCTION_ANALYSIS("machine-loops", MachineLoopInfoAnalysis())
|
||||
|
@ -26,20 +26,35 @@ static cl::opt<bool>
|
||||
ViewEdgeBundles("view-edge-bundles", cl::Hidden,
|
||||
cl::desc("Pop up a window to show edge bundle graphs"));
|
||||
|
||||
char EdgeBundles::ID = 0;
|
||||
char EdgeBundlesWrapperLegacy::ID = 0;
|
||||
|
||||
INITIALIZE_PASS(EdgeBundles, "edge-bundles", "Bundle Machine CFG Edges",
|
||||
/* cfg = */true, /* is_analysis = */ true)
|
||||
INITIALIZE_PASS(EdgeBundlesWrapperLegacy, "edge-bundles",
|
||||
"Bundle Machine CFG Edges",
|
||||
/* cfg = */ true, /* is_analysis = */ true)
|
||||
|
||||
char &llvm::EdgeBundlesID = EdgeBundles::ID;
|
||||
char &llvm::EdgeBundlesWrapperLegacyID = EdgeBundlesWrapperLegacy::ID;
|
||||
|
||||
void EdgeBundles::getAnalysisUsage(AnalysisUsage &AU) const {
|
||||
void EdgeBundlesWrapperLegacy::getAnalysisUsage(AnalysisUsage &AU) const {
|
||||
AU.setPreservesAll();
|
||||
MachineFunctionPass::getAnalysisUsage(AU);
|
||||
}
|
||||
|
||||
bool EdgeBundles::runOnMachineFunction(MachineFunction &mf) {
|
||||
MF = &mf;
|
||||
AnalysisKey EdgeBundlesAnalysis::Key;
|
||||
|
||||
EdgeBundles EdgeBundlesAnalysis::run(MachineFunction &MF,
|
||||
MachineFunctionAnalysisManager &MFAM) {
|
||||
EdgeBundles Impl(MF);
|
||||
return Impl;
|
||||
}
|
||||
|
||||
bool EdgeBundlesWrapperLegacy::runOnMachineFunction(MachineFunction &MF) {
|
||||
Impl.reset(new EdgeBundles(MF));
|
||||
return false;
|
||||
}
|
||||
|
||||
EdgeBundles::EdgeBundles(MachineFunction &MF) : MF(&MF) { init(); }
|
||||
|
||||
void EdgeBundles::init() {
|
||||
EC.clear();
|
||||
EC.grow(2 * MF->getNumBlockIDs());
|
||||
|
||||
@ -64,8 +79,6 @@ bool EdgeBundles::runOnMachineFunction(MachineFunction &mf) {
|
||||
if (b1 != b0)
|
||||
Blocks[b1].push_back(i);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
namespace llvm {
|
||||
@ -100,3 +113,11 @@ raw_ostream &WriteGraph<>(raw_ostream &O, const EdgeBundles &G,
|
||||
void EdgeBundles::view() const {
|
||||
ViewGraph(*this, "EdgeBundles");
|
||||
}
|
||||
|
||||
bool EdgeBundles::invalidate(MachineFunction &MF, const PreservedAnalyses &PA,
|
||||
MachineFunctionAnalysisManager::Invalidator &Inv) {
|
||||
// Invalidated when CFG is not preserved
|
||||
auto PAC = PA.getChecker<EdgeBundlesAnalysis>();
|
||||
return !PAC.preserved() && !PAC.preservedSet<CFGAnalyses>() &&
|
||||
!PAC.preservedSet<AllAnalysesOn<MachineFunction>>();
|
||||
}
|
||||
|
@ -161,7 +161,7 @@ INITIALIZE_PASS_DEPENDENCY(MachineDominatorTreeWrapperPass)
|
||||
INITIALIZE_PASS_DEPENDENCY(MachineLoopInfoWrapperPass)
|
||||
INITIALIZE_PASS_DEPENDENCY(VirtRegMapWrapperLegacy)
|
||||
INITIALIZE_PASS_DEPENDENCY(LiveRegMatrixWrapperLegacy)
|
||||
INITIALIZE_PASS_DEPENDENCY(EdgeBundles)
|
||||
INITIALIZE_PASS_DEPENDENCY(EdgeBundlesWrapperLegacy)
|
||||
INITIALIZE_PASS_DEPENDENCY(SpillPlacement)
|
||||
INITIALIZE_PASS_DEPENDENCY(MachineOptimizationRemarkEmitterPass)
|
||||
INITIALIZE_PASS_DEPENDENCY(RegAllocEvictionAdvisorAnalysis)
|
||||
@ -216,7 +216,7 @@ void RAGreedy::getAnalysisUsage(AnalysisUsage &AU) const {
|
||||
AU.addPreserved<VirtRegMapWrapperLegacy>();
|
||||
AU.addRequired<LiveRegMatrixWrapperLegacy>();
|
||||
AU.addPreserved<LiveRegMatrixWrapperLegacy>();
|
||||
AU.addRequired<EdgeBundles>();
|
||||
AU.addRequired<EdgeBundlesWrapperLegacy>();
|
||||
AU.addRequired<SpillPlacement>();
|
||||
AU.addRequired<MachineOptimizationRemarkEmitterPass>();
|
||||
AU.addRequired<RegAllocEvictionAdvisorAnalysis>();
|
||||
@ -2730,7 +2730,7 @@ bool RAGreedy::runOnMachineFunction(MachineFunction &mf) {
|
||||
DomTree = &getAnalysis<MachineDominatorTreeWrapperPass>().getDomTree();
|
||||
ORE = &getAnalysis<MachineOptimizationRemarkEmitterPass>().getORE();
|
||||
Loops = &getAnalysis<MachineLoopInfoWrapperPass>().getLI();
|
||||
Bundles = &getAnalysis<EdgeBundles>();
|
||||
Bundles = &getAnalysis<EdgeBundlesWrapperLegacy>().getEdgeBundles();
|
||||
SpillPlacer = &getAnalysis<SpillPlacement>();
|
||||
DebugVars = &getAnalysis<LiveDebugVariables>();
|
||||
|
||||
|
@ -50,14 +50,14 @@ char &llvm::SpillPlacementID = SpillPlacement::ID;
|
||||
|
||||
INITIALIZE_PASS_BEGIN(SpillPlacement, DEBUG_TYPE,
|
||||
"Spill Code Placement Analysis", true, true)
|
||||
INITIALIZE_PASS_DEPENDENCY(EdgeBundles)
|
||||
INITIALIZE_PASS_DEPENDENCY(EdgeBundlesWrapperLegacy)
|
||||
INITIALIZE_PASS_END(SpillPlacement, DEBUG_TYPE,
|
||||
"Spill Code Placement Analysis", true, true)
|
||||
|
||||
void SpillPlacement::getAnalysisUsage(AnalysisUsage &AU) const {
|
||||
AU.setPreservesAll();
|
||||
AU.addRequired<MachineBlockFrequencyInfoWrapperPass>();
|
||||
AU.addRequiredTransitive<EdgeBundles>();
|
||||
AU.addRequiredTransitive<EdgeBundlesWrapperLegacy>();
|
||||
MachineFunctionPass::getAnalysisUsage(AU);
|
||||
}
|
||||
|
||||
@ -191,7 +191,7 @@ struct SpillPlacement::Node {
|
||||
|
||||
bool SpillPlacement::runOnMachineFunction(MachineFunction &mf) {
|
||||
MF = &mf;
|
||||
bundles = &getAnalysis<EdgeBundles>();
|
||||
bundles = &getAnalysis<EdgeBundlesWrapperLegacy>().getEdgeBundles();
|
||||
|
||||
assert(!nodes && "Leaking node array");
|
||||
nodes = new Node[bundles->getNumBundles()];
|
||||
|
@ -85,6 +85,7 @@
|
||||
#include "llvm/CodeGen/DeadMachineInstructionElim.h"
|
||||
#include "llvm/CodeGen/DwarfEHPrepare.h"
|
||||
#include "llvm/CodeGen/EarlyIfConversion.h"
|
||||
#include "llvm/CodeGen/EdgeBundles.h"
|
||||
#include "llvm/CodeGen/ExpandLargeDivRem.h"
|
||||
#include "llvm/CodeGen/ExpandLargeFpConvert.h"
|
||||
#include "llvm/CodeGen/ExpandMemCmp.h"
|
||||
|
@ -67,7 +67,7 @@ namespace {
|
||||
|
||||
void getAnalysisUsage(AnalysisUsage &AU) const override {
|
||||
AU.setPreservesCFG();
|
||||
AU.addRequired<EdgeBundles>();
|
||||
AU.addRequired<EdgeBundlesWrapperLegacy>();
|
||||
AU.addPreservedID(MachineLoopInfoID);
|
||||
AU.addPreservedID(MachineDominatorsID);
|
||||
MachineFunctionPass::getAnalysisUsage(AU);
|
||||
@ -303,7 +303,7 @@ char FPS::ID = 0;
|
||||
|
||||
INITIALIZE_PASS_BEGIN(FPS, DEBUG_TYPE, "X86 FP Stackifier",
|
||||
false, false)
|
||||
INITIALIZE_PASS_DEPENDENCY(EdgeBundles)
|
||||
INITIALIZE_PASS_DEPENDENCY(EdgeBundlesWrapperLegacy)
|
||||
INITIALIZE_PASS_END(FPS, DEBUG_TYPE, "X86 FP Stackifier",
|
||||
false, false)
|
||||
|
||||
@ -337,7 +337,7 @@ bool FPS::runOnMachineFunction(MachineFunction &MF) {
|
||||
// Early exit.
|
||||
if (!FPIsUsed) return false;
|
||||
|
||||
Bundles = &getAnalysis<EdgeBundles>();
|
||||
Bundles = &getAnalysis<EdgeBundlesWrapperLegacy>().getEdgeBundles();
|
||||
TII = MF.getSubtarget().getInstrInfo();
|
||||
|
||||
// Prepare cross-MBB liveness.
|
||||
|
Loading…
x
Reference in New Issue
Block a user