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 // The MachineConstantPool class keeps track of constants referenced by a
11 // function which must be spilled to memory. This is used for constants which
12 // are unable to be used directly as operands to instructions, which typically
13 // include floating point and large integer constants.
15 // Instructions reference the address of these constant pool constants through
16 // the use of MO_ConstantPoolIndex values. When emitting assembly or machine
17 // code, these virtual address references are converted to refer to the
18 // address of the function constant pool values.
20 //===----------------------------------------------------------------------===//
22 #ifndef LLVM_CODEGEN_MACHINECONSTANTPOOL_H
23 #define LLVM_CODEGEN_MACHINECONSTANTPOOL_H
32 class MachineConstantPool {
33 std::vector<std::pair<Constant*,unsigned> > Constants;
36 /// getConstantPoolIndex - Create a new entry in the constant pool or return
37 /// an existing one. User must specify an alignment in bytes for the object.
39 unsigned getConstantPoolIndex(Constant *C, unsigned Alignment) {
40 // Check to see if we already have this constant.
42 // FIXME, this could be made much more efficient for large constant pools.
43 for (unsigned i = 0, e = Constants.size(); i != e; ++i)
44 if (Constants[i].first == C && Constants[i].second >= Alignment)
46 Constants.push_back(std::make_pair(C, Alignment));
47 return Constants.size()-1;
50 /// isEmpty - Return true if this constant pool contains no constants.
52 bool isEmpty() const { return Constants.empty(); }
54 const std::vector<std::pair<Constant*,unsigned> > &getConstants() const {
58 /// print - Used by the MachineFunction printer to print information about
59 /// stack objects. Implemented in MachineFunction.cpp
61 void print(std::ostream &OS) const;
63 /// dump - Call print(std::cerr) to be called from the debugger.
67 } // End llvm namespace