llvm.org GIT mirror llvm / 8dd070e
Turn the EdgeBundles class into a stand-alone machine CFG analysis pass. The analysis will be needed by both the greedy register allocator and the X86FloatingPoint pass. It only needs to be computed once when the CFG doesn't change. This pass is very fast, usually showing up as 0.0% wall time. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122832 91177308-0d34-0410-b5e6-96231b3b80d8 Jakob Stoklund Olesen 9 years ago
8 changed file(s) with 147 addition(s) and 88 deletion(s). Raw diff Collapse all Expand all
0 //===-------- EdgeBundles.h - Bundles of CFG edges --------------*- c++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // The EdgeBundles analysis forms equivalence classes of CFG edges such that all
10 // edges leaving a machine basic block are in the same bundle, and all edges
11 // leaving a basic block are in the same bundle.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_CODEGEN_EDGEBUNDLES_H
16 #define LLVM_CODEGEN_EDGEBUNDLES_H
17
18 #include "llvm/ADT/IntEqClasses.h"
19 #include "llvm/CodeGen/MachineFunctionPass.h"
20
21 namespace llvm {
22
23 class EdgeBundles : public MachineFunctionPass {
24 const MachineFunction *MF;
25
26 /// EC - Each edge bundle is an equivalence class. The keys are:
27 /// 2*BB->getNumber() -> Ingoing bundle.
28 /// 2*BB->getNumber()+1 -> Outgoing bundle.
29 IntEqClasses EC;
30
31 public:
32 static char ID;
33 EdgeBundles() : MachineFunctionPass(ID) {}
34
35 /// getBundle - Return the ingoing (Out = false) or outgoing (Out = true)
36 /// bundle number for basic block #N
37 unsigned getBundle(unsigned N, bool Out) const { return EC[2 * N + Out]; }
38
39 /// getMachineFunction - Return the last machine function computed.
40 const MachineFunction *getMachineFunction() const { return MF; }
41
42 /// view - Visualize the annotated bipartite CFG with Graphviz.
43 void view() const;
44
45 private:
46 virtual bool runOnMachineFunction(MachineFunction&);
47 virtual void getAnalysisUsage(AnalysisUsage&) const;
48 };
49
50 /// Specialize WriteGraph, the standard implementation won't work.
51 raw_ostream &WriteGraph(raw_ostream &O, const EdgeBundles &G,
52 bool ShortNames = false,
53 const std::string &Title = "");
54
55 } // end namespace llvm
56
57 #endif
5353 ///
5454 extern char &MachineDominatorsID;
5555
56 /// EdgeBundles analysis - Bundle machine CFG edges.
57 ///
58 extern char &EdgeBundlesID;
59
5660 /// PHIElimination pass - This pass eliminates machine instruction PHI nodes
5761 /// by inserting copy instructions. This destroys SSA information, but is the
5862 /// desired input for some register allocators. This pass is "required" by
9090 void initializeDomViewerPass(PassRegistry&);
9191 void initializeDominanceFrontierPass(PassRegistry&);
9292 void initializeDominatorTreePass(PassRegistry&);
93 void initializeEdgeBundlesPass(PassRegistry&);
9394 void initializeEdgeProfilerPass(PassRegistry&);
9495 void initializeEarlyCSEPass(PassRegistry&);
9596 void initializeExpandISelPseudosPass(PassRegistry&);
99 CriticalAntiDepBreaker.cpp
1010 DeadMachineInstructionElim.cpp
1111 DwarfEHPrepare.cpp
12 EdgeBundles.cpp
1213 ELFCodeEmitter.cpp
1314 ELFWriter.cpp
1415 ExpandISelPseudos.cpp
0 //===-------- EdgeBundles.cpp - Bundles of CFG edges ----------------------===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file provides the implementation of the EdgeBundles analysis.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #include "llvm/CodeGen/EdgeBundles.h"
14 #include "llvm/CodeGen/MachineBasicBlock.h"
15 #include "llvm/CodeGen/MachineFunction.h"
16 #include "llvm/CodeGen/Passes.h"
17 #include "llvm/Support/GraphWriter.h"
18
19 using namespace llvm;
20
21 char EdgeBundles::ID = 0;
22
23 INITIALIZE_PASS(EdgeBundles, "edge-bundles", "Bundle Machine CFG Edges",
24 /* cfg = */true, /* analysis = */ true)
25
26 char &llvm::EdgeBundlesID = EdgeBundles::ID;
27
28 void EdgeBundles::getAnalysisUsage(AnalysisUsage &AU) const {
29 AU.setPreservesAll();
30 MachineFunctionPass::getAnalysisUsage(AU);
31 }
32
33 bool EdgeBundles::runOnMachineFunction(MachineFunction &mf) {
34 MF = &mf;
35 EC.clear();
36 EC.grow(2 * MF->size());
37
38 for (MachineFunction::const_iterator I = MF->begin(), E = MF->end(); I != E;
39 ++I) {
40 const MachineBasicBlock &MBB = *I;
41 unsigned OutE = 2 * MBB.getNumber() + 1;
42 // Join the outgoing bundle with the ingoing bundles of all successors.
43 for (MachineBasicBlock::const_succ_iterator SI = MBB.succ_begin(),
44 SE = MBB.succ_end(); SI != SE; ++SI)
45 EC.join(OutE, 2 * (*SI)->getNumber());
46 }
47 EC.compress();
48 return false;
49 }
50
51 /// view - Visualize the annotated bipartite CFG with Graphviz.
52 void EdgeBundles::view() const {
53 ViewGraph(*this, "EdgeBundles");
54 }
55
56 /// Specialize WriteGraph, the standard implementation won't work.
57 raw_ostream &llvm::WriteGraph(raw_ostream &O, const EdgeBundles &G,
58 bool ShortNames,
59 const std::string &Title) {
60 const MachineFunction *MF = G.getMachineFunction();
61
62 O << "digraph {\n";
63 for (MachineFunction::const_iterator I = MF->begin(), E = MF->end();
64 I != E; ++I) {
65 unsigned BB = I->getNumber();
66 O << "\t\"BB#" << BB << "\" [ shape=box ]\n"
67 << '\t' << G.getBundle(BB, false) << " -> \"BB#" << BB << "\"\n"
68 << "\t\"BB#" << BB << "\" -> " << G.getBundle(BB, true) << '\n';
69 for (MachineBasicBlock::const_succ_iterator SI = I->succ_begin(),
70 SE = I->succ_end(); SI != SE; ++SI)
71 O << "\t\"BB#" << BB << "\" -> \"BB#" << (*SI)->getNumber()
72 << "\" [ color=lightgray ]\n";
73 }
74 O << "}\n";
75 return O;
76 }
77
78
2323 #include "llvm/CodeGen/MachineRegisterInfo.h"
2424 #include "llvm/Support/CommandLine.h"
2525 #include "llvm/Support/Debug.h"
26 #include "llvm/Support/GraphWriter.h"
2726 #include "llvm/Support/raw_ostream.h"
2827 #include "llvm/Target/TargetInstrInfo.h"
2928 #include "llvm/Target/TargetMachine.h"
3332 static cl::opt
3433 AllowSplit("spiller-splits-edges",
3534 cl::desc("Allow critical edge splitting during spilling"));
36
37 //===----------------------------------------------------------------------===//
38 // Edge Bundles
39 //===----------------------------------------------------------------------===//
40
41 /// compute - Compute the edge bundles for MF. Bundles depend only on the CFG.
42 void EdgeBundles::compute(const MachineFunction *mf) {
43 MF = mf;
44 EC.clear();
45 EC.grow(2 * MF->size());
46
47 for (MachineFunction::const_iterator I = MF->begin(), E = MF->end(); I != E;
48 ++I) {
49 const MachineBasicBlock &MBB = *I;
50 unsigned OutE = 2 * MBB.getNumber() + 1;
51 // Join the outgoing bundle with the ingoing bundles of all successors.
52 for (MachineBasicBlock::const_succ_iterator SI = MBB.succ_begin(),
53 SE = MBB.succ_end(); SI != SE; ++SI)
54 EC.join(OutE, 2 * (*SI)->getNumber());
55 }
56 EC.compress();
57 }
58
59 /// view - Visualize the annotated bipartite CFG with Graphviz.
60 void EdgeBundles::view() const {
61 ViewGraph(*this, "EdgeBundles");
62 }
63
64 /// Specialize WriteGraph, the standard implementation won't work.
65 raw_ostream &llvm::WriteGraph(raw_ostream &O, const EdgeBundles &G,
66 bool ShortNames,
67 const std::string &Title) {
68 const MachineFunction *MF = G.getMachineFunction();
69
70 O << "digraph {\n";
71 for (MachineFunction::const_iterator I = MF->begin(), E = MF->end();
72 I != E; ++I) {
73 unsigned BB = I->getNumber();
74 O << "\t\"BB#" << BB << "\" [ shape=box ]\n"
75 << '\t' << G.getBundle(BB, false) << " -> \"BB#" << BB << "\"\n"
76 << "\t\"BB#" << BB << "\" -> " << G.getBundle(BB, true) << '\n';
77 for (MachineBasicBlock::const_succ_iterator SI = I->succ_begin(),
78 SE = I->succ_end(); SI != SE; ++SI)
79 O << "\t\"BB#" << BB << "\" -> \"BB#" << (*SI)->getNumber()
80 << "\" [ color=lightgray ]\n";
81 }
82 O << "}\n";
83 return O;
84 }
85
8635
8736 //===----------------------------------------------------------------------===//
8837 // Split Analysis
None //===-------- SplitKit.cpp - Toolkit for splitting live ranges --*- C++ -*-===//
0 //===-------- SplitKit.h - Toolkit for splitting live ranges ----*- C++ -*-===//
11 //
22 // The LLVM Compiler Infrastructure
33 //
1212 //===----------------------------------------------------------------------===//
1313
1414 #include "llvm/ADT/DenseMap.h"
15 #include "llvm/ADT/IntEqClasses.h"
1615 #include "llvm/ADT/SmallPtrSet.h"
1716 #include "llvm/CodeGen/SlotIndexes.h"
18
19 #include
2017
2118 namespace llvm {
2219
3734 class MachineDominatorTree;
3835 template class DomTreeNodeBase;
3936 typedef DomTreeNodeBase MachineDomTreeNode;
40
41
42 /// EdgeBundles - Group CFG edges into equivalence classes where registers must
43 /// be allocated identically. This annotates the CFG to form a bipartite graph
44 /// where each block is connected to an ingoing and an outgoing bundle.
45 /// Edge bundles are simply numbered, there is no object representation.
46 class EdgeBundles {
47 const MachineFunction *MF;
48
49 /// EC - Each edge bundle is an equivalence class. The keys are:
50 /// 2*BB->getNumber() -> Ingoing bundle.
51 /// 2*BB->getNumber()+1 -> Outgoing bundle.
52 IntEqClasses EC;
53
54 public:
55 /// compute - Compute the edge bundles for MF. Bundles depend only on the CFG.
56 void compute(const MachineFunction *MF);
57
58 /// getBundle - Return the ingoing (Out = false) or outgoing (Out = true)
59 /// bundle number for basic block #N
60 unsigned getBundle(unsigned N, bool Out) const { return EC[2 * N + Out]; }
61
62 /// getMachineFunction - Return the last machine function computed.
63 const MachineFunction *getMachineFunction() const { return MF; }
64
65 /// view - Visualize the annotated bipartite CFG with Graphviz.
66 void view() const;
67 };
68
69 /// Specialize WriteGraph, the standard implementation won't work.
70 raw_ostream &WriteGraph(raw_ostream &O, const EdgeBundles &G,
71 bool ShortNames = false,
72 const std::string &Title = "");
7337
7438
7539 /// SplitAnalysis - Analyze a LiveInterval, looking for live range splitting
3131 #include "llvm/ADT/SmallVector.h"
3232 #include "llvm/ADT/Statistic.h"
3333 #include "llvm/ADT/STLExtras.h"
34 #include "llvm/CodeGen/EdgeBundles.h"
3435 #include "llvm/CodeGen/MachineFunctionPass.h"
3536 #include "llvm/CodeGen/MachineInstrBuilder.h"
3637 #include "llvm/CodeGen/MachineRegisterInfo.h"
5051 struct FPS : public MachineFunctionPass {
5152 static char ID;
5253 FPS() : MachineFunctionPass(ID) {
54 initializeEdgeBundlesPass(*PassRegistry::getPassRegistry());
5355 // This is really only to keep valgrind quiet.
5456 // The logic in isLive() is too much for it.
5557 memset(Stack, 0, sizeof(Stack));
5860
5961 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
6062 AU.setPreservesCFG();
63 AU.addRequired();
6164 AU.addPreservedID(MachineLoopInfoID);
6265 AU.addPreservedID(MachineDominatorsID);
6366 MachineFunctionPass::getAnalysisUsage(AU);