EXTRACT_SUBREG coalescing support. The coalescer now treats EXTRACT_SUBREG like
[oota-llvm.git] / include / llvm / CodeGen / SSARegMap.h
1 //===-- llvm/CodeGen/SSARegMap.h --------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // Map register numbers to register classes that are correctly sized (typed) to
11 // hold the information. Assists register allocation. Contained by
12 // MachineFunction, should be deleted by register allocator when it is no
13 // longer needed.
14 //
15 //===----------------------------------------------------------------------===//
16
17 #ifndef LLVM_CODEGEN_SSAREGMAP_H
18 #define LLVM_CODEGEN_SSAREGMAP_H
19
20 #include "llvm/Target/MRegisterInfo.h"
21 #include "llvm/ADT/IndexedMap.h"
22
23 namespace llvm {
24
25 class TargetRegisterClass;
26
27 class SSARegMap {
28   IndexedMap<const TargetRegisterClass*, VirtReg2IndexFunctor> RegClassMap;
29   IndexedMap<std::pair<unsigned, unsigned>, VirtReg2IndexFunctor> RegSubIdxMap;
30   unsigned NextRegNum;
31
32  public:
33   SSARegMap() : NextRegNum(MRegisterInfo::FirstVirtualRegister) { }
34
35   const TargetRegisterClass* getRegClass(unsigned Reg) {
36     return RegClassMap[Reg];
37   }
38
39   /// createVirtualRegister - Create and return a new virtual register in the
40   /// function with the specified register class.
41   ///
42   unsigned createVirtualRegister(const TargetRegisterClass *RegClass) {
43     assert(RegClass && "Cannot create register without RegClass!");
44     RegClassMap.grow(NextRegNum);
45     RegClassMap[NextRegNum] = RegClass;
46     RegSubIdxMap.grow(NextRegNum);
47     RegSubIdxMap[NextRegNum] = std::make_pair(0,0);
48     return NextRegNum++;
49   }
50
51   unsigned getLastVirtReg() const {
52     return NextRegNum - 1;
53   }
54
55   void setIsSubRegister(unsigned Reg, unsigned SuperReg, unsigned SubIdx) {
56     RegSubIdxMap[Reg] = std::make_pair(SuperReg, SubIdx);
57   }
58
59   bool isSubRegister(unsigned Reg) const {
60     return RegSubIdxMap[Reg].first != 0;
61   }
62
63   unsigned getSuperRegister(unsigned Reg) const {
64     return RegSubIdxMap[Reg].first;
65   }
66
67   unsigned getSubRegisterIndex(unsigned Reg) const {
68     return RegSubIdxMap[Reg].second;
69   }
70 };
71
72 } // End llvm namespace
73
74 #endif