1 //===-- CodeGen/MachineConstantPool.h - Abstract Constant Pool --*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
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.
8 //===----------------------------------------------------------------------===//
10 /// @file This file declares the MachineConstantPool class which is an abstract
11 /// constant pool to keep track of constants referenced by a function.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_CODEGEN_MACHINECONSTANTPOOL_H
16 #define LLVM_CODEGEN_MACHINECONSTANTPOOL_H
26 /// This class is a data container for one entry in a MachineConstantPool.
27 /// It contains a pointer to the value and an offset from the start of
28 /// the constant pool.
29 /// @brief An entry in a MachineConstantPool
30 struct MachineConstantPoolEntry {
31 Constant *Val; ///< The constant itself.
32 unsigned Offset; ///< The offset of the constant from the start of the pool.
33 MachineConstantPoolEntry(Constant *V, unsigned O) : Val(V), Offset(O) {}
36 /// The MachineConstantPool class keeps track of constants referenced by a
37 /// function which must be spilled to memory. This is used for constants which
38 /// are unable to be used directly as operands to instructions, which typically
39 /// include floating point and large integer constants.
41 /// Instructions reference the address of these constant pool constants through
42 /// the use of MO_ConstantPoolIndex values. When emitting assembly or machine
43 /// code, these virtual address references are converted to refer to the
44 /// address of the function constant pool values.
45 /// @brief The machine constant pool.
46 class MachineConstantPool {
47 const TargetData *TD; ///< The machine's TargetData.
48 unsigned PoolAlignment; ///< The alignment for the pool.
49 std::vector<MachineConstantPoolEntry> Constants; ///< The pool of constants.
51 /// @brief The only constructor.
52 MachineConstantPool(const TargetData *td) : TD(td), PoolAlignment(1) {}
54 /// getConstantPoolAlignment - Return the log2 of the alignment required by
55 /// the whole constant pool, of which the first element must be aligned.
56 unsigned getConstantPoolAlignment() const { return PoolAlignment; }
58 /// getConstantPoolIndex - Create a new entry in the constant pool or return
59 /// an existing one. User must specify an alignment in bytes for the object.
60 unsigned getConstantPoolIndex(Constant *C, unsigned Alignment);
62 /// isEmpty - Return true if this constant pool contains no constants.
63 bool isEmpty() const { return Constants.empty(); }
65 const std::vector<MachineConstantPoolEntry> &getConstants() const {
69 /// print - Used by the MachineFunction printer to print information about
70 /// constant pool objects. Implemented in MachineFunction.cpp
72 void print(std::ostream &OS) const;
74 /// dump - Call print(std::cerr) to be called from the debugger.
79 } // End llvm namespace