LLVM API Documentation
00001 //===-- AllocInfo.h - Store info about regalloc decisions -------*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file was developed by the LLVM research group and is distributed under 00006 // the University of Illinois Open Source License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This header file contains the data structure used to save the state 00011 // of the global, graph-coloring register allocator. 00012 // 00013 //===----------------------------------------------------------------------===// 00014 00015 #ifndef ALLOCINFO_H 00016 #define ALLOCINFO_H 00017 00018 #include "llvm/Type.h" 00019 #include "llvm/DerivedTypes.h" 00020 #include "llvm/Constants.h" 00021 00022 namespace llvm { 00023 00024 /// AllocInfo - Structure representing one instruction's operand's-worth of 00025 /// register allocation state. We create tables made out of these data 00026 /// structures to generate mapping information for this register allocator. 00027 /// 00028 struct AllocInfo { 00029 int Instruction; // (-1 if Argument, or 0 .. n - 1 for an instruction). 00030 int Operand; // (-1 if Instruction, or 0 .. n-1 for an operand). 00031 enum AllocStateTy { NotAllocated = 0, Allocated, Spilled }; 00032 AllocStateTy AllocState; 00033 int Placement; 00034 00035 AllocInfo (int Inst_, int Op_, AllocStateTy State_, int Place_) : 00036 Instruction(Inst_), Operand(Op_), AllocState(State_), Placement(Place_) { } 00037 00038 /// AllocInfo constructor -- Default constructor creates an invalid AllocInfo 00039 /// (presumably to be replaced with something meaningful later). 00040 /// 00041 AllocInfo () : 00042 Instruction(-1), Operand(-1), AllocState(NotAllocated), Placement(-1) { } 00043 00044 /// getConstantType - Return a StructType representing an AllocInfo object. 00045 /// 00046 static StructType *getConstantType () { 00047 std::vector<const Type *> TV; 00048 TV.push_back (Type::IntTy); 00049 TV.push_back (Type::IntTy); 00050 TV.push_back (Type::UIntTy); 00051 TV.push_back (Type::IntTy); 00052 return StructType::get (TV); 00053 } 00054 00055 /// toConstant - Convert this AllocInfo into an LLVM Constant of type 00056 /// getConstantType(), and return the Constant. 00057 /// 00058 Constant *toConstant () const { 00059 StructType *ST = getConstantType (); 00060 std::vector<Constant *> CV; 00061 CV.push_back (ConstantSInt::get (Type::IntTy, Instruction)); 00062 CV.push_back (ConstantSInt::get (Type::IntTy, Operand)); 00063 CV.push_back (ConstantUInt::get (Type::UIntTy, AllocState)); 00064 CV.push_back (ConstantSInt::get (Type::IntTy, Placement)); 00065 return ConstantStruct::get (ST, CV); 00066 } 00067 00068 /// AllocInfos compare equal if the allocation placements are equal 00069 /// (i.e., they can be equal even if they refer to operands from two 00070 /// different instructions.) 00071 /// 00072 bool operator== (const AllocInfo &X) const { 00073 return (X.AllocState == AllocState) && (X.Placement == Placement); 00074 } 00075 bool operator!= (const AllocInfo &X) const { return !(*this == X); } 00076 00077 /// Returns a human-readable string representation of the AllocState member. 00078 /// 00079 const std::string allocStateToString () const { 00080 static const char *AllocStateNames[] = 00081 { "NotAllocated", "Allocated", "Spilled" }; 00082 return std::string (AllocStateNames[AllocState]); 00083 } 00084 }; 00085 00086 static inline std::ostream &operator << (std::ostream &OS, AllocInfo &S) { 00087 OS << "(Instruction " << S.Instruction << " Operand " << S.Operand 00088 << " AllocState " << S.allocStateToString () << " Placement " 00089 << S.Placement << ")"; 00090 return OS; 00091 } 00092 00093 } // End llvm namespace 00094 00095 #endif // ALLOCINFO_H