blob: c6accdbef8d5e3383473ecfcc7db4245cdf68c36 [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
Brian Gaeke960707c2003-11-11 22:41:34 +000032namespace llvm {
33
Chris Lattnerb0da8b22002-02-04 05:52:08 +000034class LiveRange;
35class MachineInstr;
Chris Lattnerb0da8b22002-02-04 05:52:08 +000036class RegClass;
Brian Gaekedca24dd2004-06-03 02:45:09 +000037class SparcV9RegInfo;
Chris Lattnerb0da8b22002-02-04 05:52:08 +000038class TargetMachine;
39class Value;
Chris Lattner4e8c4872002-03-23 22:51:58 +000040class Function;
Chris Lattnerb0da8b22002-02-04 05:52:08 +000041class Instruction;
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +000042
Chris Lattnere5833332002-07-24 21:21:33 +000043typedef hash_map<const Value*, LiveRange*> LiveRangeMapType;
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +000044
Ruchira Sasankaf20079d2002-01-07 19:16:26 +000045//----------------------------------------------------------------------------
46// Class LiveRangeInfo
47//
Brian Gaeke75ed4b82003-09-15 05:28:42 +000048// Constructs and keeps the LiveRangeMap which contains all the live
Ruchira Sasankaf20079d2002-01-07 19:16:26 +000049// ranges used in a method. Also contain methods to coalesce live ranges.
50//----------------------------------------------------------------------------
51
Chris Lattnerb0da8b22002-02-04 05:52:08 +000052class LiveRangeInfo {
Chris Lattner4e8c4872002-03-23 22:51:58 +000053 const Function *const Meth; // Func for which live range info is held
Ruchira Sasankaf20079d2002-01-07 19:16:26 +000054 LiveRangeMapType LiveRangeMap; // A map from Value * to LiveRange * to
55 // record all live ranges in a method
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +000056 // created by constructLiveRanges
Ruchira Sasankaf20079d2002-01-07 19:16:26 +000057
Ruchira Sasankaf60342a2001-09-15 00:33:26 +000058 const TargetMachine& TM; // target machine description
Ruchira Sasankaf20079d2002-01-07 19:16:26 +000059
Chris Lattner7f74a562002-01-20 22:54:45 +000060 std::vector<RegClass *> & RegClassList;// vector containing register classess
Ruchira Sasankaf20079d2002-01-07 19:16:26 +000061
Brian Gaekedca24dd2004-06-03 02:45:09 +000062 const SparcV9RegInfo& MRI; // machine reg info
Ruchira Sasankaf60342a2001-09-15 00:33:26 +000063
Chris Lattner6d6d87f2002-10-29 17:03:19 +000064 std::vector<MachineInstr*> CallRetInstrList; // a list of all call/ret instrs
Ruchira Sasankaf60342a2001-09-15 00:33:26 +000065
Ruchira Sasankaf20079d2002-01-07 19:16:26 +000066
67 //------------ Private methods (see LiveRangeInfo.cpp for description)-------
68
Vikram S. Adve90119032002-09-28 17:05:43 +000069 LiveRange* createNewLiveRange (const Value* Def,
70 bool isCC = false);
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +000071
Vikram S. Adve90119032002-09-28 17:05:43 +000072 LiveRange* createOrAddToLiveRange (const Value* Def,
73 bool isCC = false);
74
75 void unionAndUpdateLRs (LiveRange *L1,
76 LiveRange *L2);
77
78 void addInterference (const Instruction *Inst,
79 const ValueSet *LVSet);
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +000080
Vikram S. Adve90119032002-09-28 17:05:43 +000081 void suggestRegs4CallRets ();
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +000082
Vikram S. Adve90119032002-09-28 17:05:43 +000083 const Function *getMethod () const { return Meth; }
Ruchira Sasankaf20079d2002-01-07 19:16:26 +000084
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +000085public:
86
Chris Lattner4e8c4872002-03-23 22:51:58 +000087 LiveRangeInfo(const Function *F,
Ruchira Sasankaf60342a2001-09-15 00:33:26 +000088 const TargetMachine& tm,
Chris Lattner7f74a562002-01-20 22:54:45 +000089 std::vector<RegClass *> & RCList);
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +000090
Ruchira Sasankaf20079d2002-01-07 19:16:26 +000091
Misha Brukman0b624fe2003-10-23 18:03:50 +000092 /// Destructor to destroy all LiveRanges in the LiveRange Map
93 ///
Ruchira Sasankaf20079d2002-01-07 19:16:26 +000094 ~LiveRangeInfo();
95
96 // Main entry point for live range construction
97 //
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +000098 void constructLiveRanges();
Ruchira Sasanka560b0ad2001-09-30 23:19:57 +000099
Misha Brukman0b624fe2003-10-23 18:03:50 +0000100 /// return the common live range map for this method
101 ///
Chris Lattner6d6d87f2002-10-29 17:03:19 +0000102 inline const LiveRangeMapType *getLiveRangeMap() const
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +0000103 { return &LiveRangeMap; }
104
Misha Brukman0b624fe2003-10-23 18:03:50 +0000105 /// Method used to get the live range containing a Value.
106 /// This may return NULL if no live range exists for a Value (eg, some consts)
107 ///
Vikram S. Advee2ef34a2003-07-29 19:38:22 +0000108 inline LiveRange *getLiveRangeForValue(const Value *Val) {
109 return LiveRangeMap[Val];
110 }
111 inline const LiveRange *getLiveRangeForValue(const Value *Val) const {
112 LiveRangeMapType::const_iterator I = LiveRangeMap.find(Val);
113 return I->second;
114 }
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +0000115
Misha Brukman0b624fe2003-10-23 18:03:50 +0000116 /// Method for coalescing live ranges. Called only after interference info
117 /// is calculated.
118 ///
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +0000119 void coalesceLRs();
120
Misha Brukman0b624fe2003-10-23 18:03:50 +0000121 /// debugging method to print the live ranges
122 ///
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +0000123 void printLiveRanges();
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +0000124};
125
Brian Gaeke960707c2003-11-11 22:41:34 +0000126} // End llvm namespace
127
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +0000128#endif