1 //===- ConstantPool.h - Keep track of assembler-generated ------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file declares the ConstantPool and AssemblerConstantPools classes.
12 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_MC_CONSTANTPOOL_H
16 #define LLVM_MC_CONSTANTPOOL_H
18 #include "llvm/ADT/SmallVector.h"
26 struct ConstantPoolEntry {
32 // A class to keep track of assembler-generated constant pools that are use to
33 // implement the ldr-pseudo.
35 typedef SmallVector<ConstantPoolEntry, 4> EntryVecTy;
39 // Initialize a new empty constant pool
42 // Add a new entry to the constant pool in the next slot.
43 // \param Value is the new entry to put in the constant pool.
44 // \param Size is the size in bytes of the entry
46 // \returns a MCExpr that references the newly inserted value
47 const MCExpr *addEntry(const MCExpr *Value, MCContext &Context,
50 // Emit the contents of the constant pool using the provided streamer.
51 void emitEntries(MCStreamer &Streamer);
53 // Return true if the constant pool is empty
57 class AssemblerConstantPools {
58 // Map type used to keep track of per-Section constant pools used by the
59 // ldr-pseudo opcode. The map associates a section to its constant pool. The
60 // constant pool is a vector of (label, value) pairs. When the ldr
61 // pseudo is parsed we insert a new (label, value) pair into the constant pool
62 // for the current section and add MCSymbolRefExpr to the new label as
63 // an opcode to the ldr. After we have parsed all the user input we
64 // output the (label, value) pairs in each constant pool at the end of the
67 // We use the MapVector for the map type to ensure stable iteration of
68 // the sections at the end of the parse. We need to iterate over the
69 // sections in a stable order to ensure that we have print the
70 // constant pools in a deterministic order when printing an assembly
72 typedef MapVector<const MCSection *, ConstantPool> ConstantPoolMapTy;
73 ConstantPoolMapTy ConstantPools;
76 AssemblerConstantPools() {}
77 ~AssemblerConstantPools() {}
79 void emitAll(MCStreamer &Streamer);
80 void emitForCurrentSection(MCStreamer &Streamer);
81 const MCExpr *addEntry(MCStreamer &Streamer, const MCExpr *Expr,
85 ConstantPool *getConstantPool(const MCSection *Section);
86 ConstantPool &getOrCreateConstantPool(const MCSection *Section);
88 } // end namespace llvm