OSDN Git Service

instead of keeping track of Constant/alignment pairs, actually compute the
[android-x86/external-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 class TargetData;
32
33 /// MachineConstantPoolEntry - One entry in the constant pool.
34 ///
35 struct MachineConstantPoolEntry {
36   /// Val - The constant itself.
37   Constant *Val;
38   /// Offset - The offset of the constant from the start of the constant pool.
39   unsigned Offset;
40   
41   MachineConstantPoolEntry(Constant *V, unsigned O) : Val(V), Offset(O) {}
42 };
43   
44 class MachineConstantPool {
45   const TargetData &TD;
46   unsigned PoolAlignment;
47   std::vector<MachineConstantPoolEntry> Constants;
48 public:
49   MachineConstantPool(const TargetData &td) : TD(td), PoolAlignment(1) {}
50     
51   /// getConstantPoolAlignment - Return the log2 of the alignment required by
52   /// the whole constant pool, of which the first element must be aligned.
53   unsigned getConstantPoolAlignment() const { return PoolAlignment; }
54   
55   /// getConstantPoolIndex - Create a new entry in the constant pool or return
56   /// an existing one.  User must specify an alignment in bytes for the object.
57   ///
58   unsigned getConstantPoolIndex(Constant *C, unsigned Alignment);
59   
60   /// isEmpty - Return true if this constant pool contains no constants.
61   ///
62   bool isEmpty() const { return Constants.empty(); }
63
64   const std::vector<MachineConstantPoolEntry> &getConstants() const {
65     return Constants;
66   }
67
68   /// print - Used by the MachineFunction printer to print information about
69   /// stack objects.  Implemented in MachineFunction.cpp
70   ///
71   void print(std::ostream &OS) const;
72
73   /// dump - Call print(std::cerr) to be called from the debugger.
74   ///
75   void dump() const;
76 };
77
78 } // End llvm namespace
79
80 #endif