llvm.org GIT mirror llvm / ceadc01
Add MachineLoopRanges analysis. A MachineLoopRange contains the intervals of slot indexes covered by the blocks in a loop. This representation of the loop blocks is more efficient to compare against interfering registers during register coalescing. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@121917 91177308-0d34-0410-b5e6-96231b3b80d8 Jakob Stoklund Olesen 9 years ago
5 changed file(s) with 176 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
0 //===- MachineLoopRanges.h - Ranges of machine loops -----------*- 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 // This file provides the interface to the MachineLoopRanges analysis.
10 //
11 // Provide on-demand information about the ranges of machine instructions
12 // covered by a loop.
13 //
14 //===----------------------------------------------------------------------===//
15
16 #ifndef LLVM_CODEGEN_MACHINELOOPRANGES_H
17 #define LLVM_CODEGEN_MACHINELOOPRANGES_H
18
19 #include "llvm/ADT/IntervalMap.h"
20 #include "llvm/CodeGen/SlotIndexes.h"
21
22 namespace llvm {
23
24 class MachineLoop;
25 class MachineLoopInfo;
26 class raw_ostream;
27
28 /// MachineLoopRange - Range information for a single loop.
29 class MachineLoopRange {
30 friend class MachineLoopRanges;
31 typedef IntervalMap RangeMap;
32 typedef RangeMap::Allocator Allocator;
33
34 /// The mapped loop.
35 const MachineLoop *const Loop;
36
37 /// Map intervals to a bit mask.
38 /// Bit 0 = inside loop block.
39 RangeMap Intervals;
40
41 /// Create a MachineLoopRange, only accessible to MachineLoopRanges.
42 MachineLoopRange(const MachineLoop*, Allocator&, SlotIndexes&);
43
44 public:
45 /// overlaps - Return true if this loop overlaps the given range of machine
46 /// inteructions.
47 bool overlaps(SlotIndex Start, SlotIndex Stop);
48
49 /// print - Print loop ranges on OS.
50 void print(raw_ostream&) const;
51 };
52
53 raw_ostream &operator<<(raw_ostream&, const MachineLoopRange&);
54
55 /// MachineLoopRanges - Analysis pass that provides on-demand per-loop range
56 /// information.
57 class MachineLoopRanges : public MachineFunctionPass {
58 typedef DenseMap CacheMap;
59 typedef MachineLoopRange::Allocator MapAllocator;
60
61 MapAllocator Allocator;
62 SlotIndexes *Indexes;
63 CacheMap Cache;
64
65 public:
66 static char ID; // Pass identification, replacement for typeid
67
68 MachineLoopRanges() : MachineFunctionPass(ID), Indexes(0) {}
69 ~MachineLoopRanges() { releaseMemory(); }
70
71 /// getLoopRange - Return the range of loop.
72 MachineLoopRange *getLoopRange(const MachineLoop *Loop);
73
74 private:
75 virtual bool runOnMachineFunction(MachineFunction&);
76 virtual void releaseMemory();
77 virtual void getAnalysisUsage(AnalysisUsage&) const;
78 };
79
80
81 } // end namespace llvm
82
83 #endif // LLVM_CODEGEN_MACHINELOOPRANGES_H
4444 ///
4545 extern char &MachineLoopInfoID;
4646
47 /// MachineLoopRanges pass - This pass is an on-demand loop coverage
48 /// analysis pass.
49 ///
50 extern char &MachineLoopRangesID;
51
4752 /// MachineDominators pass - This pass is a machine dominators analysis pass.
4853 ///
4954 extern char &MachineDominatorsID;
141141 void initializeMachineDominatorTreePass(PassRegistry&);
142142 void initializeMachineLICMPass(PassRegistry&);
143143 void initializeMachineLoopInfoPass(PassRegistry&);
144 void initializeMachineLoopRangesPass(PassRegistry&);
144145 void initializeMachineModuleInfoPass(PassRegistry&);
145146 void initializeMachineSinkingPass(PassRegistry&);
146147 void initializeMachineVerifierPassPass(PassRegistry&);
3939 MachineInstr.cpp
4040 MachineLICM.cpp
4141 MachineLoopInfo.cpp
42 MachineLoopRanges.cpp
4243 MachineModuleInfo.cpp
4344 MachineModuleInfoImpls.cpp
4445 MachinePassRegistry.cpp
0 //===- MachineLoopRanges.cpp - Ranges of machine loops --------------------===//
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 MachineLoopRanges analysis.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #include "llvm/CodeGen/MachineLoopRanges.h"
14 #include "llvm/CodeGen/MachineLoopInfo.h"
15 #include "llvm/CodeGen/Passes.h"
16
17 using namespace llvm;
18
19 char MachineLoopRanges::ID = 0;
20 INITIALIZE_PASS_BEGIN(MachineLoopRanges, "machine-loop-ranges",
21 "Machine Loop Ranges", true, true)
22 INITIALIZE_PASS_DEPENDENCY(SlotIndexes)
23 INITIALIZE_PASS_DEPENDENCY(MachineLoopInfo)
24 INITIALIZE_PASS_END(MachineLoopRanges, "machine-loop-ranges",
25 "Machine Loop Ranges", true, true)
26
27 char &llvm::MachineLoopRangesID = MachineLoopRanges::ID;
28
29 void MachineLoopRanges::getAnalysisUsage(AnalysisUsage &AU) const {
30 AU.setPreservesAll();
31 AU.addRequiredTransitive();
32 AU.addRequiredTransitive();
33 MachineFunctionPass::getAnalysisUsage(AU);
34 }
35
36 /// runOnMachineFunction - Don't do much, loop ranges are computed on demand.
37 bool MachineLoopRanges::runOnMachineFunction(MachineFunction &) {
38 releaseMemory();
39 Indexes = &getAnalysis();
40 return false;
41 }
42
43 void MachineLoopRanges::releaseMemory() {
44 DeleteContainerSeconds(Cache);
45 Cache.clear();
46 }
47
48 MachineLoopRange *MachineLoopRanges::getLoopRange(const MachineLoop *Loop) {
49 MachineLoopRange *&Range = Cache[Loop];
50 if (!Range)
51 Range = new MachineLoopRange(Loop, Allocator, *Indexes);
52 return Range;
53 }
54
55 /// Create a MachineLoopRange, only accessible to MachineLoopRanges.
56 MachineLoopRange::MachineLoopRange(const MachineLoop *loop,
57 MachineLoopRange::Allocator &alloc,
58 SlotIndexes &Indexes)
59 : Loop(loop), Intervals(alloc) {
60 // Compute loop coverage.
61 for (MachineLoop::block_iterator I = Loop->block_begin(),
62 E = Loop->block_end(); I != E; ++I) {
63 const std::pair &Range = Indexes.getMBBRange(*I);
64 Intervals.insert(Range.first, Range.second, 1u);
65 }
66 }
67
68 /// overlaps - Return true if this loop overlaps the given range of machine
69 /// instructions.
70 bool MachineLoopRange::overlaps(SlotIndex Start, SlotIndex Stop) {
71 RangeMap::const_iterator I = Intervals.find(Start);
72 return I.valid() && Stop > I.start();
73 }
74
75 void MachineLoopRange::print(raw_ostream &OS) const {
76 OS << "Loop#" << Loop->getHeader()->getNumber() << " =";
77 for (RangeMap::const_iterator I = Intervals.begin(); I.valid(); ++I)
78 OS << " [" << I.start() << ';' << I.stop() << ')';
79 }
80
81 raw_ostream &llvm::operator<<(raw_ostream &OS, const MachineLoopRange &MLR) {
82 MLR.print(OS);
83 return OS;
84 }