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_CONSTANTPOOLS_H
16 #define LLVM_MC_CONSTANTPOOLS_H
18 #include "llvm/ADT/MapVector.h"
19 #include "llvm/ADT/SmallVector.h"
28 struct ConstantPoolEntry {
29 ConstantPoolEntry(MCSymbol *L, const MCExpr *Val, unsigned Sz)
30 : Label(L), Value(Val), Size(Sz) {}
36 // A class to keep track of assembler-generated constant pools that are use to
37 // implement the ldr-pseudo.
39 typedef SmallVector<ConstantPoolEntry, 4> EntryVecTy;
43 // Initialize a new empty constant pool
46 // Add a new entry to the constant pool in the next slot.
47 // \param Value is the new entry to put in the constant pool.
48 // \param Size is the size in bytes of the entry
50 // \returns a MCExpr that references the newly inserted value
51 const MCExpr *addEntry(const MCExpr *Value, MCContext &Context,
54 // Emit the contents of the constant pool using the provided streamer.
55 void emitEntries(MCStreamer &Streamer);
57 // Return true if the constant pool is empty
61 class AssemblerConstantPools {
62 // Map type used to keep track of per-Section constant pools used by the
63 // ldr-pseudo opcode. The map associates a section to its constant pool. The
64 // constant pool is a vector of (label, value) pairs. When the ldr
65 // pseudo is parsed we insert a new (label, value) pair into the constant pool
66 // for the current section and add MCSymbolRefExpr to the new label as
67 // an opcode to the ldr. After we have parsed all the user input we
68 // output the (label, value) pairs in each constant pool at the end of the
71 // We use the MapVector for the map type to ensure stable iteration of
72 // the sections at the end of the parse. We need to iterate over the
73 // sections in a stable order to ensure that we have print the
74 // constant pools in a deterministic order when printing an assembly
76 typedef MapVector<MCSection *, ConstantPool> ConstantPoolMapTy;
77 ConstantPoolMapTy ConstantPools;
80 void emitAll(MCStreamer &Streamer);
81 void emitForCurrentSection(MCStreamer &Streamer);
82 const MCExpr *addEntry(MCStreamer &Streamer, const MCExpr *Expr,
86 ConstantPool *getConstantPool(MCSection *Section);
87 ConstantPool &getOrCreateConstantPool(MCSection *Section);
89 } // end namespace llvm