We won't use automake
[oota-llvm.git] / lib / Target / SparcV9 / 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 namespace llvm {
23
24 /// AllocInfo - Structure representing one instruction's operand's-worth of
25 /// register allocation state. We create tables made out of these data
26 /// structures to generate mapping information for this register allocator.
27 ///
28 struct AllocInfo {
29   int Instruction; // (-1 if Argument, or 0 .. n - 1 for an instruction).
30   int Operand; // (-1 if Instruction, or 0 .. n-1 for an operand).
31   enum AllocStateTy { NotAllocated = 0, Allocated, Spilled };
32   AllocStateTy AllocState;
33   int Placement;
34
35   AllocInfo (int Inst_, int Op_, AllocStateTy State_, int Place_) :
36     Instruction(Inst_), Operand(Op_), AllocState(State_), Placement(Place_) { }
37
38   /// AllocInfo constructor -- Default constructor creates an invalid AllocInfo 
39   /// (presumably to be replaced with something meaningful later).
40   ///
41   AllocInfo () :
42     Instruction(-1), Operand(-1), AllocState(NotAllocated), Placement(-1) { }
43
44   /// getConstantType - Return a StructType representing an AllocInfo object.
45   ///
46   static StructType *getConstantType () {
47     std::vector<const Type *> TV;
48     TV.push_back (Type::IntTy);
49     TV.push_back (Type::IntTy);
50     TV.push_back (Type::UIntTy);
51     TV.push_back (Type::IntTy);
52     return StructType::get (TV);
53   }
54
55   /// toConstant - Convert this AllocInfo into an LLVM Constant of type
56   /// getConstantType(), and return the Constant.
57   ///
58   Constant *toConstant () const {
59     StructType *ST = getConstantType ();
60     std::vector<Constant *> CV;
61     CV.push_back (ConstantSInt::get (Type::IntTy, Instruction));
62     CV.push_back (ConstantSInt::get (Type::IntTy, Operand));
63     CV.push_back (ConstantUInt::get (Type::UIntTy, AllocState));
64     CV.push_back (ConstantSInt::get (Type::IntTy, Placement));
65     return ConstantStruct::get (ST, CV);
66   }
67
68   /// AllocInfos compare equal if the allocation placements are equal
69   /// (i.e., they can be equal even if they refer to operands from two
70   /// different instructions.)
71   ///
72   bool operator== (const AllocInfo &X) const {
73     return (X.AllocState == AllocState) && (X.Placement == Placement);
74   } 
75   bool operator!= (const AllocInfo &X) const { return !(*this == X); } 
76
77   /// Returns a human-readable string representation of the AllocState member.
78   ///
79   const std::string allocStateToString () const {
80     static const char *AllocStateNames[] =
81       { "NotAllocated", "Allocated", "Spilled" };
82     return std::string (AllocStateNames[AllocState]);
83   }
84 };
85
86 static inline std::ostream &operator << (std::ostream &OS, AllocInfo &S) {
87   OS << "(Instruction " << S.Instruction << " Operand " << S.Operand
88      << " AllocState " << S.allocStateToString () << " Placement "
89      << S.Placement << ")";
90   return OS;
91 }
92
93 } // End llvm namespace
94
95 #endif // ALLOCINFO_H