SSARegMap -- the mapping between SSARegisters and their RegisterClasses, which
[oota-llvm.git] / include / llvm / CodeGen / SSARegMap.h
1 //===-- llvm/CodeGen/SSARegMap.h --------------------------------*- C++ -*-===//
2 // 
3 // Map register numbers to register classes that are correctly sized (typed) to
4 // hold the information. Assists register allocation. Contained by
5 // MachineFunction, should be deleted by register allocator when it is no
6 // longer needed.
7 //   
8 //===----------------------------------------------------------------------===//
9
10 #ifndef LLVM_CODEGEN_SSAREGMAP_H
11 #define LLVM_CODEGEN_SSAREGMAP_H
12
13 #include "llvm/Target/MRegisterInfo.h"
14
15 class TargetRegisterClass;
16
17 class SSARegMap {
18   std::vector<const TargetRegisterClass*> RegClassMap;
19
20   unsigned rescale(unsigned Reg) { 
21     return Reg - MRegisterInfo::FirstVirtualRegister;
22   }
23
24  public:
25   SSARegMap() {}
26
27   const TargetRegisterClass* getRegClass(unsigned Reg) {
28     unsigned actualReg = rescale(Reg);
29     assert(actualReg < RegClassMap.size() && "Register out of bounds");
30     return RegClassMap[actualReg];
31   }
32
33   void addRegMap(unsigned Reg, const TargetRegisterClass* RegClass) {
34     assert(rescale(Reg) == RegClassMap.size() && 
35            "Register mapping not added in sequential order!");
36     RegClassMap.push_back(RegClass);
37   }
38 };
39
40 #endif