blob: 67f58a7ed04bc58127470aa69a5a7d39dc7e15a8 [file] [log] [blame]
Brian Gaeke3d7125c2003-10-23 20:31:51 +00001//===-- 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
Brian Gaeked0fde302003-11-11 22:41:34 +000022namespace llvm {
23
Brian Gaeke3d7125c2003-10-23 20:31:51 +000024/// 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///
28struct AllocInfo {
29 unsigned Instruction;
Brian Gaeke21390412003-11-10 00:05:26 +000030 int Operand; // (-1 if Instruction, or 0...n-1 for an operand.)
Brian Gaeke82c5eb72003-10-30 21:21:22 +000031 enum AllocStateTy { NotAllocated = 0, Allocated, Spilled };
32 AllocStateTy AllocState;
Brian Gaeke3d7125c2003-10-23 20:31:51 +000033 int Placement;
Brian Gaeke82c5eb72003-10-30 21:21:22 +000034
Brian Gaeke3d7125c2003-10-23 20:31:51 +000035 AllocInfo (unsigned Instruction_, unsigned Operand_,
Brian Gaeke82c5eb72003-10-30 21:21:22 +000036 AllocStateTy AllocState_, int Placement_) :
Brian Gaeke3d7125c2003-10-23 20:31:51 +000037 Instruction (Instruction_), Operand (Operand_),
38 AllocState (AllocState_), Placement (Placement_) { }
39
40 /// getConstantType - Return a StructType representing an AllocInfo object.
41 ///
42 static StructType *getConstantType () {
43 std::vector<const Type *> TV;
44 TV.push_back (Type::UIntTy);
Brian Gaeke21390412003-11-10 00:05:26 +000045 TV.push_back (Type::IntTy);
Brian Gaeke3d7125c2003-10-23 20:31:51 +000046 TV.push_back (Type::UIntTy);
47 TV.push_back (Type::IntTy);
48 return StructType::get (TV);
49 }
50
51 /// toConstant - Convert this AllocInfo into an LLVM Constant of type
52 /// getConstantType(), and return the Constant.
53 ///
54 Constant *toConstant () const {
55 StructType *ST = getConstantType ();
56 std::vector<Constant *> CV;
57 CV.push_back (ConstantUInt::get (Type::UIntTy, Instruction));
Brian Gaeke21390412003-11-10 00:05:26 +000058 CV.push_back (ConstantSInt::get (Type::IntTy, Operand));
Brian Gaeke3d7125c2003-10-23 20:31:51 +000059 CV.push_back (ConstantUInt::get (Type::UIntTy, AllocState));
60 CV.push_back (ConstantSInt::get (Type::IntTy, Placement));
61 return ConstantStruct::get (ST, CV);
62 }
Brian Gaeke232db6e2003-10-23 20:39:18 +000063
64 /// AllocInfos compare equal if the allocation placements are equal
65 /// (i.e., they can be equal even if they refer to operands from two
66 /// different instructions.)
67 ///
68 bool operator== (const AllocInfo &X) const {
69 return (X.AllocState == AllocState) && (X.Placement == Placement);
70 }
71 bool operator!= (const AllocInfo &X) const { return !(*this == X); }
Brian Gaeke82c5eb72003-10-30 21:21:22 +000072
73 /// Returns a human-readable string representation of the AllocState member.
74 ///
75 const std::string allocStateToString () const {
76 static const char *AllocStateNames[] =
77 { "NotAllocated", "Allocated", "Spilled" };
78 return std::string (AllocStateNames[AllocState]);
79 }
Brian Gaeke3d7125c2003-10-23 20:31:51 +000080};
81
Brian Gaeked0fde302003-11-11 22:41:34 +000082} // End llvm namespace
83
Brian Gaeke3d7125c2003-10-23 20:31:51 +000084#endif // ALLOCINFO_H