[Orc] Add explicit move construction/assignment to RCMemoryManager.
[oota-llvm.git] / include / llvm / MC / ConstantPools.h
1 //===- ConstantPool.h - Keep track of assembler-generated  ------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file declares the ConstantPool and AssemblerConstantPools classes.
11 //
12 //===----------------------------------------------------------------------===//
13
14
15 #ifndef LLVM_MC_CONSTANTPOOLS_H
16 #define LLVM_MC_CONSTANTPOOLS_H
17
18 #include "llvm/ADT/MapVector.h"
19 #include "llvm/ADT/SmallVector.h"
20 #include "llvm/Support/SMLoc.h"
21
22 namespace llvm {
23 class MCContext;
24 class MCExpr;
25 class MCSection;
26 class MCStreamer;
27 class MCSymbol;
28
29 struct ConstantPoolEntry {
30   ConstantPoolEntry(MCSymbol *L, const MCExpr *Val, unsigned Sz, SMLoc Loc_)
31     : Label(L), Value(Val), Size(Sz), Loc(Loc_) {}
32   MCSymbol *Label;
33   const MCExpr *Value;
34   unsigned Size;
35   SMLoc Loc;
36 };
37
38 // A class to keep track of assembler-generated constant pools that are use to
39 // implement the ldr-pseudo.
40 class ConstantPool {
41   typedef SmallVector<ConstantPoolEntry, 4> EntryVecTy;
42   EntryVecTy Entries;
43
44 public:
45   // Initialize a new empty constant pool
46   ConstantPool() {}
47
48   // Add a new entry to the constant pool in the next slot.
49   // \param Value is the new entry to put in the constant pool.
50   // \param Size is the size in bytes of the entry
51   //
52   // \returns a MCExpr that references the newly inserted value
53   const MCExpr *addEntry(const MCExpr *Value, MCContext &Context,
54                          unsigned Size, SMLoc Loc);
55
56   // Emit the contents of the constant pool using the provided streamer.
57   void emitEntries(MCStreamer &Streamer);
58
59   // Return true if the constant pool is empty
60   bool empty();
61 };
62
63 class AssemblerConstantPools {
64   // Map type used to keep track of per-Section constant pools used by the
65   // ldr-pseudo opcode. The map associates a section to its constant pool. The
66   // constant pool is a vector of (label, value) pairs. When the ldr
67   // pseudo is parsed we insert a new (label, value) pair into the constant pool
68   // for the current section and add MCSymbolRefExpr to the new label as
69   // an opcode to the ldr. After we have parsed all the user input we
70   // output the (label, value) pairs in each constant pool at the end of the
71   // section.
72   //
73   // We use the MapVector for the map type to ensure stable iteration of
74   // the sections at the end of the parse. We need to iterate over the
75   // sections in a stable order to ensure that we have print the
76   // constant pools in a deterministic order when printing an assembly
77   // file.
78   typedef MapVector<MCSection *, ConstantPool> ConstantPoolMapTy;
79   ConstantPoolMapTy ConstantPools;
80
81 public:
82   void emitAll(MCStreamer &Streamer);
83   void emitForCurrentSection(MCStreamer &Streamer);
84   const MCExpr *addEntry(MCStreamer &Streamer, const MCExpr *Expr,
85                          unsigned Size, SMLoc Loc);
86
87 private:
88   ConstantPool *getConstantPool(MCSection *Section);
89   ConstantPool &getOrCreateConstantPool(MCSection *Section);
90 };
91 } // end namespace llvm
92
93 #endif