Brian Gaeke | 3d7125c | 2003-10-23 20:31:51 +0000 | [diff] [blame] | 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 | |
Brian Gaeke | d0fde30 | 2003-11-11 22:41:34 +0000 | [diff] [blame^] | 22 | namespace llvm { |
| 23 | |
Brian Gaeke | 3d7125c | 2003-10-23 20:31:51 +0000 | [diff] [blame] | 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 | unsigned Instruction; |
Brian Gaeke | 2139041 | 2003-11-10 00:05:26 +0000 | [diff] [blame] | 30 | int Operand; // (-1 if Instruction, or 0...n-1 for an operand.) |
Brian Gaeke | 82c5eb7 | 2003-10-30 21:21:22 +0000 | [diff] [blame] | 31 | enum AllocStateTy { NotAllocated = 0, Allocated, Spilled }; |
| 32 | AllocStateTy AllocState; |
Brian Gaeke | 3d7125c | 2003-10-23 20:31:51 +0000 | [diff] [blame] | 33 | int Placement; |
Brian Gaeke | 82c5eb7 | 2003-10-30 21:21:22 +0000 | [diff] [blame] | 34 | |
Brian Gaeke | 3d7125c | 2003-10-23 20:31:51 +0000 | [diff] [blame] | 35 | AllocInfo (unsigned Instruction_, unsigned Operand_, |
Brian Gaeke | 82c5eb7 | 2003-10-30 21:21:22 +0000 | [diff] [blame] | 36 | AllocStateTy AllocState_, int Placement_) : |
Brian Gaeke | 3d7125c | 2003-10-23 20:31:51 +0000 | [diff] [blame] | 37 | 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 Gaeke | 2139041 | 2003-11-10 00:05:26 +0000 | [diff] [blame] | 45 | TV.push_back (Type::IntTy); |
Brian Gaeke | 3d7125c | 2003-10-23 20:31:51 +0000 | [diff] [blame] | 46 | 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 Gaeke | 2139041 | 2003-11-10 00:05:26 +0000 | [diff] [blame] | 58 | CV.push_back (ConstantSInt::get (Type::IntTy, Operand)); |
Brian Gaeke | 3d7125c | 2003-10-23 20:31:51 +0000 | [diff] [blame] | 59 | 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 Gaeke | 232db6e | 2003-10-23 20:39:18 +0000 | [diff] [blame] | 63 | |
| 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 Gaeke | 82c5eb7 | 2003-10-30 21:21:22 +0000 | [diff] [blame] | 72 | |
| 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 Gaeke | 3d7125c | 2003-10-23 20:31:51 +0000 | [diff] [blame] | 80 | }; |
| 81 | |
Brian Gaeke | d0fde30 | 2003-11-11 22:41:34 +0000 | [diff] [blame^] | 82 | } // End llvm namespace |
| 83 | |
Brian Gaeke | 3d7125c | 2003-10-23 20:31:51 +0000 | [diff] [blame] | 84 | #endif // ALLOCINFO_H |