LLVM API Documentation

MachineConstantPool.h

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