blob: a6569146057f4ffbc85e82167fa0be1f07dbfbb3 [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"
Reid Spencer7c16caa2004-09-01 22:55:40 +000030#include "llvm/ADT/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 //------------ Private methods (see LiveRangeInfo.cpp for description)-------
67
Vikram S. Adve90119032002-09-28 17:05:43 +000068 LiveRange* createNewLiveRange (const Value* Def,
69 bool isCC = false);
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +000070
Vikram S. Adve90119032002-09-28 17:05:43 +000071 LiveRange* createOrAddToLiveRange (const Value* Def,
72 bool isCC = false);
73
74 void unionAndUpdateLRs (LiveRange *L1,
75 LiveRange *L2);
76
Vikram S. Adve90119032002-09-28 17:05:43 +000077 void suggestRegs4CallRets ();
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +000078public:
79
Chris Lattner4e8c4872002-03-23 22:51:58 +000080 LiveRangeInfo(const Function *F,
Ruchira Sasankaf60342a2001-09-15 00:33:26 +000081 const TargetMachine& tm,
Chris Lattner7f74a562002-01-20 22:54:45 +000082 std::vector<RegClass *> & RCList);
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +000083
Ruchira Sasankaf20079d2002-01-07 19:16:26 +000084
Misha Brukman0b624fe2003-10-23 18:03:50 +000085 /// Destructor to destroy all LiveRanges in the LiveRange Map
86 ///
Ruchira Sasankaf20079d2002-01-07 19:16:26 +000087 ~LiveRangeInfo();
88
89 // Main entry point for live range construction
90 //
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +000091 void constructLiveRanges();
Ruchira Sasanka560b0ad2001-09-30 23:19:57 +000092
Misha Brukman0b624fe2003-10-23 18:03:50 +000093 /// return the common live range map for this method
94 ///
Chris Lattner6d6d87f2002-10-29 17:03:19 +000095 inline const LiveRangeMapType *getLiveRangeMap() const
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +000096 { return &LiveRangeMap; }
97
Misha Brukman0b624fe2003-10-23 18:03:50 +000098 /// Method used to get the live range containing a Value.
99 /// This may return NULL if no live range exists for a Value (eg, some consts)
100 ///
Vikram S. Advee2ef34a2003-07-29 19:38:22 +0000101 inline LiveRange *getLiveRangeForValue(const Value *Val) {
102 return LiveRangeMap[Val];
103 }
104 inline const LiveRange *getLiveRangeForValue(const Value *Val) const {
105 LiveRangeMapType::const_iterator I = LiveRangeMap.find(Val);
106 return I->second;
107 }
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +0000108
Misha Brukman0b624fe2003-10-23 18:03:50 +0000109 /// Method for coalescing live ranges. Called only after interference info
110 /// is calculated.
111 ///
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +0000112 void coalesceLRs();
113
Misha Brukman0b624fe2003-10-23 18:03:50 +0000114 /// debugging method to print the live ranges
115 ///
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +0000116 void printLiveRanges();
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +0000117};
118
Brian Gaeke960707c2003-11-11 22:41:34 +0000119} // End llvm namespace
120
Ruchira Sasankae5d0fb82001-09-08 14:10:34 +0000121#endif