LLVM API Documentation

SSARegMap.h

Go to the documentation of this file.
00001 //===-- llvm/CodeGen/SSARegMap.h --------------------------------*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file was developed by the LLVM research group and is distributed under
00006 // the University of Illinois Open Source License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // Map register numbers to register classes that are correctly sized (typed) to
00011 // hold the information. Assists register allocation. Contained by
00012 // MachineFunction, should be deleted by register allocator when it is no
00013 // longer needed.
00014 //
00015 //===----------------------------------------------------------------------===//
00016 
00017 #ifndef LLVM_CODEGEN_SSAREGMAP_H
00018 #define LLVM_CODEGEN_SSAREGMAP_H
00019 
00020 #include "llvm/Target/MRegisterInfo.h"
00021 #include "llvm/ADT/DenseMap.h"
00022 
00023 namespace llvm {
00024 
00025 class TargetRegisterClass;
00026 
00027 class SSARegMap {
00028   DenseMap<const TargetRegisterClass*, VirtReg2IndexFunctor> RegClassMap;
00029   unsigned NextRegNum;
00030 
00031  public:
00032   SSARegMap() : NextRegNum(MRegisterInfo::FirstVirtualRegister) { }
00033 
00034   const TargetRegisterClass* getRegClass(unsigned Reg) {
00035     return RegClassMap[Reg];
00036   }
00037 
00038   /// createVirtualRegister - Create and return a new virtual register in the
00039   /// function with the specified register class.
00040   ///
00041   unsigned createVirtualRegister(const TargetRegisterClass *RegClass) {
00042     assert(RegClass && "Cannot create register without RegClass!");
00043     RegClassMap.grow(NextRegNum);
00044     RegClassMap[NextRegNum] = RegClass;
00045     return NextRegNum++;
00046   }
00047 
00048   unsigned getLastVirtReg() const {
00049     return NextRegNum - 1;
00050   }
00051 };
00052 
00053 } // End llvm namespace
00054 
00055 #endif