slightly simplify and document SSARegMap.
[oota-llvm.git] / include / llvm / CodeGen / SSARegMap.h
1 //===-- llvm/CodeGen/SSARegMap.h --------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines the SSARegMap class.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_CODEGEN_SSAREGMAP_H
15 #define LLVM_CODEGEN_SSAREGMAP_H
16
17 #include "llvm/Target/MRegisterInfo.h"
18 #include <vector>
19
20 namespace llvm {
21   
22 /// SSARegMap - Keep track of information for each virtual register, including
23 /// its register class.
24 class SSARegMap {
25   /// VRegInfo - Information we keep for each virtual register.  The entries in
26   /// this vector are actually converted to vreg numbers by adding the 
27   /// MRegisterInfo::FirstVirtualRegister delta to their index.
28   std::vector<const TargetRegisterClass*> VRegInfo;
29   
30 public:
31   SSARegMap() {
32     VRegInfo.reserve(256);
33   }
34
35   /// getRegClass - Return the register class of the specified virtual register.
36   const TargetRegisterClass *getRegClass(unsigned Reg) {
37     Reg -= MRegisterInfo::FirstVirtualRegister;
38     assert(Reg < VRegInfo.size() && "Invalid vreg!");
39     return VRegInfo[Reg];
40   }
41
42   /// createVirtualRegister - Create and return a new virtual register in the
43   /// function with the specified register class.
44   ///
45   unsigned createVirtualRegister(const TargetRegisterClass *RegClass) {
46     assert(RegClass && "Cannot create register without RegClass!");
47     VRegInfo.push_back(RegClass);
48     return getLastVirtReg();
49   }
50
51   /// getLastVirtReg - Return the highest currently assigned virtual register.
52   ///
53   unsigned getLastVirtReg() const {
54     return VRegInfo.size()+MRegisterInfo::FirstVirtualRegister-1;
55   }
56 };
57
58 } // End llvm namespace
59
60 #endif