Operand numbers are now ints. Save the register allocation of the value
[oota-llvm.git] / lib / CodeGen / RegAlloc / AllocInfo.h
1 //===-- AllocInfo.h - Store info about regalloc decisions -------*- 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 // This header file contains the data structure used to save the state
11 // of the global, graph-coloring register allocator.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #ifndef ALLOCINFO_H
16 #define ALLOCINFO_H
17
18 #include "llvm/Type.h"
19 #include "llvm/DerivedTypes.h"
20 #include "llvm/Constants.h"
21
22 /// AllocInfo - Structure representing one instruction's operand's-worth of
23 /// register allocation state. We create tables made out of these data
24 /// structures to generate mapping information for this register allocator.
25 ///
26 struct AllocInfo {
27   unsigned Instruction;
28   int Operand; // (-1 if Instruction, or 0...n-1 for an operand.)
29   enum AllocStateTy { NotAllocated = 0, Allocated, Spilled };
30   AllocStateTy AllocState;
31   int Placement;
32
33   AllocInfo (unsigned Instruction_, unsigned Operand_,
34              AllocStateTy AllocState_, int Placement_) :
35     Instruction (Instruction_), Operand (Operand_),
36        AllocState (AllocState_), Placement (Placement_) { }
37
38   /// getConstantType - Return a StructType representing an AllocInfo object.
39   ///
40   static StructType *getConstantType () {
41     std::vector<const Type *> TV;
42     TV.push_back (Type::UIntTy);
43     TV.push_back (Type::IntTy);
44     TV.push_back (Type::UIntTy);
45     TV.push_back (Type::IntTy);
46     return StructType::get (TV);
47   }
48
49   /// toConstant - Convert this AllocInfo into an LLVM Constant of type
50   /// getConstantType(), and return the Constant.
51   ///
52   Constant *toConstant () const {
53     StructType *ST = getConstantType ();
54     std::vector<Constant *> CV;
55     CV.push_back (ConstantUInt::get (Type::UIntTy, Instruction));
56     CV.push_back (ConstantSInt::get (Type::IntTy, Operand));
57     CV.push_back (ConstantUInt::get (Type::UIntTy, AllocState));
58     CV.push_back (ConstantSInt::get (Type::IntTy, Placement));
59     return ConstantStruct::get (ST, CV);
60   }
61
62   /// AllocInfos compare equal if the allocation placements are equal
63   /// (i.e., they can be equal even if they refer to operands from two
64   /// different instructions.)
65   ///
66   bool operator== (const AllocInfo &X) const {
67     return (X.AllocState == AllocState) && (X.Placement == Placement);
68   } 
69   bool operator!= (const AllocInfo &X) const { return !(*this == X); } 
70
71   /// Returns a human-readable string representation of the AllocState member.
72   ///
73   const std::string allocStateToString () const {
74     static const char *AllocStateNames[] =
75       { "NotAllocated", "Allocated", "Spilled" };
76     return std::string (AllocStateNames[AllocState]);
77   }
78 };
79
80 #endif // ALLOCINFO_H