LLVM API Documentation
00001 //===-- CodeGen/MachineConstantPool.h - Abstract Constant Pool --*- 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 /// @file This file declares the MachineConstantPool class which is an abstract 00011 /// constant pool to keep track of constants referenced by a function. 00012 // 00013 //===----------------------------------------------------------------------===// 00014 00015 #ifndef LLVM_CODEGEN_MACHINECONSTANTPOOL_H 00016 #define LLVM_CODEGEN_MACHINECONSTANTPOOL_H 00017 00018 #include <vector> 00019 #include <iosfwd> 00020 00021 namespace llvm { 00022 00023 class Constant; 00024 class TargetData; 00025 00026 /// This class is a data container for one entry in a MachineConstantPool. 00027 /// It contains a pointer to the value and an offset from the start of 00028 /// the constant pool. 00029 /// @brief An entry in a MachineConstantPool 00030 struct MachineConstantPoolEntry { 00031 Constant *Val; ///< The constant itself. 00032 unsigned Offset; ///< The offset of the constant from the start of the pool. 00033 MachineConstantPoolEntry(Constant *V, unsigned O) : Val(V), Offset(O) {} 00034 }; 00035 00036 /// The MachineConstantPool class keeps track of constants referenced by a 00037 /// function which must be spilled to memory. This is used for constants which 00038 /// are unable to be used directly as operands to instructions, which typically 00039 /// include floating point and large integer constants. 00040 /// 00041 /// Instructions reference the address of these constant pool constants through 00042 /// the use of MO_ConstantPoolIndex values. When emitting assembly or machine 00043 /// code, these virtual address references are converted to refer to the 00044 /// address of the function constant pool values. 00045 /// @brief The machine constant pool. 00046 class MachineConstantPool { 00047 const TargetData *TD; ///< The machine's TargetData. 00048 unsigned PoolAlignment; ///< The alignment for the pool. 00049 std::vector<MachineConstantPoolEntry> Constants; ///< The pool of constants. 00050 public: 00051 /// @brief The only constructor. 00052 MachineConstantPool(const TargetData *td) : TD(td), PoolAlignment(1) {} 00053 00054 /// getConstantPoolAlignment - Return the log2 of the alignment required by 00055 /// the whole constant pool, of which the first element must be aligned. 00056 unsigned getConstantPoolAlignment() const { return PoolAlignment; } 00057 00058 /// getConstantPoolIndex - Create a new entry in the constant pool or return 00059 /// an existing one. User must specify an alignment in bytes for the object. 00060 unsigned getConstantPoolIndex(Constant *C, unsigned Alignment); 00061 00062 /// isEmpty - Return true if this constant pool contains no constants. 00063 bool isEmpty() const { return Constants.empty(); } 00064 00065 const std::vector<MachineConstantPoolEntry> &getConstants() const { 00066 return Constants; 00067 } 00068 00069 /// print - Used by the MachineFunction printer to print information about 00070 /// constant pool objects. Implemented in MachineFunction.cpp 00071 /// 00072 void print(std::ostream &OS) const; 00073 00074 /// dump - Call print(std::cerr) to be called from the debugger. 00075 /// 00076 void dump() const; 00077 }; 00078 00079 } // End llvm namespace 00080 00081 #endif