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"
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.
28 int Operand; // (-1 if Instruction, or 0...n-1 for an operand.)
29 enum AllocStateTy { NotAllocated = 0, Allocated, Spilled };
30 AllocStateTy AllocState;
33 AllocInfo (unsigned Instruction_, unsigned Operand_,
34 AllocStateTy AllocState_, int Placement_) :
35 Instruction (Instruction_), Operand (Operand_),
36 AllocState (AllocState_), Placement (Placement_) { }
38 /// getConstantType - Return a StructType representing an AllocInfo object.
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);
49 /// toConstant - Convert this AllocInfo into an LLVM Constant of type
50 /// getConstantType(), and return the Constant.
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);
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.)
66 bool operator== (const AllocInfo &X) const {
67 return (X.AllocState == AllocState) && (X.Placement == Placement);
69 bool operator!= (const AllocInfo &X) const { return !(*this == X); }
71 /// Returns a human-readable string representation of the AllocState member.
73 const std::string allocStateToString () const {
74 static const char *AllocStateNames[] =
75 { "NotAllocated", "Allocated", "Spilled" };
76 return std::string (AllocStateNames[AllocState]);