Included assert.h so that the code compiles under newer versions of GCC.
[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 #include <assert.h>
16
17 class TargetRegisterClass;
18
19 class SSARegMap {
20   std::vector<const TargetRegisterClass*> RegClassMap;
21
22   unsigned rescale(unsigned Reg) { 
23     return Reg - MRegisterInfo::FirstVirtualRegister;
24   }
25
26  public:
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   /// createVirtualRegister - Create and return a new virtual register in the
34   /// function with the specified register class.
35   ///
36   unsigned createVirtualRegister(const TargetRegisterClass *RegClass) {
37     RegClassMap.push_back(RegClass);
38     return RegClassMap.size()+MRegisterInfo::FirstVirtualRegister-1;
39   }
40 };
41
42 #endif