LLVM API Documentation
00001 //===-- LiveRangeInfo.h - Track all LiveRanges for a Function ----*- C++ -*-==// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file was developed by the LLVM research group and is distributed under 00006 // the University of Illinois Open Source License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file contains the class LiveRangeInfo which constructs and keeps 00011 // the LiveRangeMap which contains all the live ranges used in a method. 00012 // 00013 // Assumptions: 00014 // 00015 // All variables (llvm Values) are defined before they are used. However, a 00016 // constant may not be defined in the machine instruction stream if it can be 00017 // used as an immediate value within a machine instruction. However, register 00018 // allocation does not have to worry about immediate constants since they 00019 // do not require registers. 00020 // 00021 // Since an llvm Value has a list of uses associated, it is sufficient to 00022 // record only the defs in a Live Range. 00023 // 00024 //===----------------------------------------------------------------------===// 00025 00026 #ifndef LIVERANGEINFO_H 00027 #define LIVERANGEINFO_H 00028 00029 #include "llvm/CodeGen/ValueSet.h" 00030 #include "llvm/ADT/hash_map" 00031 00032 namespace llvm { 00033 00034 class V9LiveRange; 00035 class MachineInstr; 00036 class RegClass; 00037 class SparcV9RegInfo; 00038 class TargetMachine; 00039 class Value; 00040 class Function; 00041 class Instruction; 00042 00043 typedef hash_map<const Value*, V9LiveRange*> LiveRangeMapType; 00044 00045 //---------------------------------------------------------------------------- 00046 // Class LiveRangeInfo 00047 // 00048 // Constructs and keeps the LiveRangeMap which contains all the live 00049 // ranges used in a method. Also contain methods to coalesce live ranges. 00050 //---------------------------------------------------------------------------- 00051 00052 class LiveRangeInfo { 00053 const Function *const Meth; // Func for which live range info is held 00054 LiveRangeMapType LiveRangeMap; // A map from Value * to V9LiveRange * to 00055 // record all live ranges in a method 00056 // created by constructLiveRanges 00057 00058 const TargetMachine& TM; // target machine description 00059 00060 std::vector<RegClass *> & RegClassList;// vector containing register classess 00061 00062 const SparcV9RegInfo& MRI; // machine reg info 00063 00064 std::vector<MachineInstr*> CallRetInstrList; // a list of all call/ret instrs 00065 00066 //------------ Private methods (see LiveRangeInfo.cpp for description)------- 00067 00068 V9LiveRange* createNewLiveRange (const Value* Def, 00069 bool isCC = false); 00070 00071 V9LiveRange* createOrAddToLiveRange (const Value* Def, 00072 bool isCC = false); 00073 00074 void unionAndUpdateLRs (V9LiveRange *L1, 00075 V9LiveRange *L2); 00076 00077 void suggestRegs4CallRets (); 00078 public: 00079 00080 LiveRangeInfo(const Function *F, 00081 const TargetMachine& tm, 00082 std::vector<RegClass *> & RCList); 00083 00084 00085 /// Destructor to destroy all LiveRanges in the V9LiveRange Map 00086 /// 00087 ~LiveRangeInfo(); 00088 00089 // Main entry point for live range construction 00090 // 00091 void constructLiveRanges(); 00092 00093 /// return the common live range map for this method 00094 /// 00095 inline const LiveRangeMapType *getLiveRangeMap() const 00096 { return &LiveRangeMap; } 00097 00098 /// Method used to get the live range containing a Value. 00099 /// This may return NULL if no live range exists for a Value (eg, some consts) 00100 /// 00101 inline V9LiveRange *getLiveRangeForValue(const Value *Val) { 00102 return LiveRangeMap[Val]; 00103 } 00104 inline const V9LiveRange *getLiveRangeForValue(const Value *Val) const { 00105 LiveRangeMapType::const_iterator I = LiveRangeMap.find(Val); 00106 return I->second; 00107 } 00108 00109 /// Method for coalescing live ranges. Called only after interference info 00110 /// is calculated. 00111 /// 00112 void coalesceLRs(); 00113 00114 /// debugging method to print the live ranges 00115 /// 00116 void printLiveRanges(); 00117 }; 00118 00119 } // End llvm namespace 00120 00121 #endif