Allow the specification of explicit alignments for constant pool entries.
[oota-llvm.git] / include / llvm / CodeGen / MachineConstantPool.h
1 //===-- CodeGen/MachineConstantPool.h - Abstract Constant Pool --*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
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.
7 //
8 //===----------------------------------------------------------------------===//
9 //
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.
14 //
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.
19 //
20 //===----------------------------------------------------------------------===//
21
22 #ifndef LLVM_CODEGEN_MACHINECONSTANTPOOL_H
23 #define LLVM_CODEGEN_MACHINECONSTANTPOOL_H
24
25 #include <vector>
26 #include <iosfwd>
27
28 namespace llvm {
29
30 class Constant;
31
32 class MachineConstantPool {
33   std::vector<std::pair<Constant*,unsigned> > Constants;
34 public:
35
36   /// getConstantPoolIndex - Create a new entry in the constant pool or return
37   /// an existing one. User may specify an alignment that is greater than the
38   /// default alignment. If one is not specified, it will be 0.
39   ///
40   unsigned getConstantPoolIndex(Constant *C, unsigned Alignment = 0) {
41     // Check to see if we already have this constant.
42     //
43     // FIXME, this could be made much more efficient for large constant pools.
44     for (unsigned i = 0, e = Constants.size(); i != e; ++i)
45       if (Constants[i].first == C) {
46         Constants[i].second = std::max(Constants[i].second, Alignment);
47         return i;
48       }
49     Constants.push_back(std::make_pair(C, Alignment));
50     return Constants.size()-1;
51   }
52
53   /// isEmpty - Return true if this constant pool contains no constants.
54   ///
55   bool isEmpty() const { return Constants.empty(); }
56
57   const std::vector<std::pair<Constant*,unsigned> > &getConstants() const {
58     return Constants;
59   }
60
61   /// print - Used by the MachineFunction printer to print information about
62   /// stack objects.  Implemented in MachineFunction.cpp
63   ///
64   void print(std::ostream &OS) const;
65
66   /// dump - Call print(std::cerr) to be called from the debugger.
67   void dump() const;
68 };
69
70 } // End llvm namespace
71
72 #endif