08fa672a816e085b5d06581c02aca62105f0e817
[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   const TargetRegisterClass* getRegClass(unsigned Reg) {
26     unsigned actualReg = rescale(Reg);
27     assert(actualReg < RegClassMap.size() && "Register out of bounds");
28     return RegClassMap[actualReg];
29   }
30
31   /// createVirtualRegister - Create and return a new virtual register in the
32   /// function with the specified register class.
33   ///
34   unsigned createVirtualRegister(const TargetRegisterClass *RegClass) {
35     RegClassMap.push_back(RegClass);
36     return RegClassMap.size()+MRegisterInfo::FirstVirtualRegister-1;
37   }
38 };
39
40 #endif