1 //===-- AllocInfo.h - Store info about regalloc decisions -------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
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.
8 //===----------------------------------------------------------------------===//
10 // This header file contains the data structure used to save the state
11 // of the global, graph-coloring register allocator.
13 //===----------------------------------------------------------------------===//
18 #include "llvm/Type.h"
19 #include "llvm/DerivedTypes.h"
20 #include "llvm/Constants.h"
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.
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;
35 AllocInfo (int Inst_, int Op_, AllocStateTy State_, int Place_) :
36 Instruction(Inst_), Operand(Op_), AllocState(State_), Placement(Place_) { }
38 /// AllocInfo constructor -- Default constructor creates an invalid AllocInfo
39 /// (presumably to be replaced with something meaningful later).
42 Instruction(-1), Operand(-1), AllocState(NotAllocated), Placement(-1) { }
44 /// getConstantType - Return a StructType representing an AllocInfo object.
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);
55 /// toConstant - Convert this AllocInfo into an LLVM Constant of type
56 /// getConstantType(), and return the Constant.
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);
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.)
72 bool operator== (const AllocInfo &X) const {
73 return (X.AllocState == AllocState) && (X.Placement == Placement);
75 bool operator!= (const AllocInfo &X) const { return !(*this == X); }
77 /// Returns a human-readable string representation of the AllocState member.
79 const std::string allocStateToString () const {
80 static const char *AllocStateNames[] =
81 { "NotAllocated", "Allocated", "Spilled" };
82 return std::string (AllocStateNames[AllocState]);
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 << ")";
93 } // End llvm namespace