blob: a9cb349af59ed8c6b88f6917b0614ea12ac9f038 [file] [log] [blame]
Chris Lattner4e8c4872002-03-23 22:51:58 +00001//===-- LiveRangeInfo.h - Track all LiveRanges for a Function ----*- C++ -*-==//
John Criswell29265fe2003-10-21 15:17:13 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file was developed by the LLVM research group and is distributed under
6// the University of Illinois Open Source License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
Chris Lattnerb0da8b22002-02-04 05:52:08 +00009//
10// This file contains the class LiveRangeInfo which constructs and keeps
Brian Gaeke75ed4b82003-09-15 05:28:42 +000011// the LiveRangeMap which contains all the live ranges used in a method.
Chris Lattnerb0da8b22002-02-04 05:52:08 +000012//
13// Assumptions:
14//
15// All variables (llvm Values) are defined before they are used. However, a
16// constant may not be defined in the machine instruction stream if it can be
17// used as an immediate value within a machine instruction. However, register
18// allocation does not have to worry about immediate constants since they
19// do not require registers.
20//
21// Since an llvm Value has a list of uses associated, it is sufficient to
22// record only the defs in a Live Range.
23//
24//===----------------------------------------------------------------------===//
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +000025
Brian Gaeke3a0a5fc2003-09-21 02:31:37 +000026#ifndef LIVERANGEINFO_H
27#define LIVERANGEINFO_H
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +000028
Chris Lattnerde1d7292003-01-14 22:56:37 +000029#include "llvm/CodeGen/ValueSet.h"
Chris Lattner981e5852003-07-26 23:00:29 +000030#include "Support/hash_map"
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +000031
Chris Lattnerb0da8b22002-02-04 05:52:08 +000032class LiveRange;
33class MachineInstr;
Chris Lattnerb0da8b22002-02-04 05:52:08 +000034class RegClass;
Chris Lattnerf9781b52002-12-29 03:13:05 +000035class TargetRegInfo;
Chris Lattnerb0da8b22002-02-04 05:52:08 +000036class TargetMachine;
37class Value;
Chris Lattner4e8c4872002-03-23 22:51:58 +000038class Function;
Chris Lattnerb0da8b22002-02-04 05:52:08 +000039class Instruction;
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +000040
Chris Lattnere5833332002-07-24 21:21:33 +000041typedef hash_map<const Value*, LiveRange*> LiveRangeMapType;
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +000042
Ruchira Sasankaf20079d2002-01-07 19:16:26 +000043//----------------------------------------------------------------------------
44// Class LiveRangeInfo
45//
Brian Gaeke75ed4b82003-09-15 05:28:42 +000046// Constructs and keeps the LiveRangeMap which contains all the live
Ruchira Sasankaf20079d2002-01-07 19:16:26 +000047// ranges used in a method. Also contain methods to coalesce live ranges.
48//----------------------------------------------------------------------------
49
Chris Lattnerb0da8b22002-02-04 05:52:08 +000050class LiveRangeInfo {
Chris Lattner4e8c4872002-03-23 22:51:58 +000051 const Function *const Meth; // Func for which live range info is held
Ruchira Sasankaf20079d2002-01-07 19:16:26 +000052 LiveRangeMapType LiveRangeMap; // A map from Value * to LiveRange * to
53 // record all live ranges in a method
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +000054 // created by constructLiveRanges
Ruchira Sasankaf20079d2002-01-07 19:16:26 +000055
Ruchira Sasankaf60342a2001-09-15 00:33:26 +000056 const TargetMachine& TM; // target machine description
Ruchira Sasankaf20079d2002-01-07 19:16:26 +000057
Chris Lattner7f74a562002-01-20 22:54:45 +000058 std::vector<RegClass *> & RegClassList;// vector containing register classess
Ruchira Sasankaf20079d2002-01-07 19:16:26 +000059
Chris Lattnerf9781b52002-12-29 03:13:05 +000060 const TargetRegInfo& MRI; // machine reg info
Ruchira Sasankaf60342a2001-09-15 00:33:26 +000061
Chris Lattner6d6d87f2002-10-29 17:03:19 +000062 std::vector<MachineInstr*> CallRetInstrList; // a list of all call/ret instrs
Ruchira Sasankaf60342a2001-09-15 00:33:26 +000063
Ruchira Sasankaf20079d2002-01-07 19:16:26 +000064
65 //------------ Private methods (see LiveRangeInfo.cpp for description)-------
66
Vikram S. Adve90119032002-09-28 17:05:43 +000067 LiveRange* createNewLiveRange (const Value* Def,
68 bool isCC = false);
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +000069
Vikram S. Adve90119032002-09-28 17:05:43 +000070 LiveRange* createOrAddToLiveRange (const Value* Def,
71 bool isCC = false);
72
73 void unionAndUpdateLRs (LiveRange *L1,
74 LiveRange *L2);
75
76 void addInterference (const Instruction *Inst,
77 const ValueSet *LVSet);
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +000078
Vikram S. Adve90119032002-09-28 17:05:43 +000079 void suggestRegs4CallRets ();
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +000080
Vikram S. Adve90119032002-09-28 17:05:43 +000081 const Function *getMethod () const { return Meth; }
Ruchira Sasankaf20079d2002-01-07 19:16:26 +000082
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +000083public:
84
Chris Lattner4e8c4872002-03-23 22:51:58 +000085 LiveRangeInfo(const Function *F,
Ruchira Sasankaf60342a2001-09-15 00:33:26 +000086 const TargetMachine& tm,
Chris Lattner7f74a562002-01-20 22:54:45 +000087 std::vector<RegClass *> & RCList);
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +000088
Ruchira Sasankaf20079d2002-01-07 19:16:26 +000089
90 // Destructor to destroy all LiveRanges in the LiveRange Map
91 ~LiveRangeInfo();
92
93 // Main entry point for live range construction
94 //
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +000095 void constructLiveRanges();
Ruchira Sasanka560b0ad2001-09-30 23:19:57 +000096
Ruchira Sasankaf20079d2002-01-07 19:16:26 +000097 // return the common live range map for this method
98 //
Chris Lattner6d6d87f2002-10-29 17:03:19 +000099 inline const LiveRangeMapType *getLiveRangeMap() const
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +0000100 { return &LiveRangeMap; }
101
Vikram S. Advee2ef34a2003-07-29 19:38:22 +0000102 // Method used to get the live range containing a Value.
103 // This may return NULL if no live range exists for a Value (eg, some consts)
104 inline LiveRange *getLiveRangeForValue(const Value *Val) {
105 return LiveRangeMap[Val];
106 }
107 inline const LiveRange *getLiveRangeForValue(const Value *Val) const {
108 LiveRangeMapType::const_iterator I = LiveRangeMap.find(Val);
109 return I->second;
110 }
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +0000111
Ruchira Sasankaf20079d2002-01-07 19:16:26 +0000112 // Method for coalescing live ranges. Called only after interference info
113 // is calculated.
114 //
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +0000115 void coalesceLRs();
116
Ruchira Sasankaf20079d2002-01-07 19:16:26 +0000117 // debugging method to print the live ranges
118 //
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +0000119 void printLiveRanges();
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +0000120};
121
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +0000122#endif