LLVM
8.0.1
include
llvm
MC
ConstantPools.h
Go to the documentation of this file.
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
#ifndef LLVM_MC_CONSTANTPOOLS_H
15
#define LLVM_MC_CONSTANTPOOLS_H
16
17
#include "
llvm/ADT/DenseMap.h
"
18
#include "
llvm/ADT/MapVector.h
"
19
#include "
llvm/ADT/SmallVector.h
"
20
#include "
llvm/Support/SMLoc.h
"
21
#include <cstdint>
22
#include <map>
23
24
namespace
llvm
{
25
26
class
MCContext;
27
class
MCExpr;
28
class
MCSection;
29
class
MCStreamer;
30
class
MCSymbol
;
31
class
MCSymbolRefExpr;
32
33
struct
ConstantPoolEntry
{
34
ConstantPoolEntry
(
MCSymbol
*L,
const
MCExpr
*Val,
unsigned
Sz,
SMLoc
Loc_)
35
:
Label
(L),
Value
(Val),
Size
(Sz),
Loc
(Loc_) {}
36
37
MCSymbol
*
Label
;
38
const
MCExpr
*
Value
;
39
unsigned
Size
;
40
SMLoc
Loc
;
41
};
42
43
// A class to keep track of assembler-generated constant pools that are use to
44
// implement the ldr-pseudo.
45
class
ConstantPool
{
46
using
EntryVecTy
=
SmallVector<ConstantPoolEntry, 4>
;
47
EntryVecTy
Entries;
48
std::map<int64_t, const MCSymbolRefExpr *> CachedEntries;
49
50
public
:
51
// Initialize a new empty constant pool
52
ConstantPool
() =
default
;
53
54
// Add a new entry to the constant pool in the next slot.
55
// \param Value is the new entry to put in the constant pool.
56
// \param Size is the size in bytes of the entry
57
//
58
// \returns a MCExpr that references the newly inserted value
59
const
MCExpr
*addEntry(
const
MCExpr
*
Value
,
MCContext
&
Context
,
60
unsigned
Size
,
SMLoc
Loc
);
61
62
// Emit the contents of the constant pool using the provided streamer.
63
void
emitEntries(
MCStreamer
&Streamer);
64
65
// Return true if the constant pool is empty
66
bool
empty
();
67
68
void
clearCache();
69
};
70
71
class
AssemblerConstantPools
{
72
// Map type used to keep track of per-Section constant pools used by the
73
// ldr-pseudo opcode. The map associates a section to its constant pool. The
74
// constant pool is a vector of (label, value) pairs. When the ldr
75
// pseudo is parsed we insert a new (label, value) pair into the constant pool
76
// for the current section and add MCSymbolRefExpr to the new label as
77
// an opcode to the ldr. After we have parsed all the user input we
78
// output the (label, value) pairs in each constant pool at the end of the
79
// section.
80
//
81
// We use the MapVector for the map type to ensure stable iteration of
82
// the sections at the end of the parse. We need to iterate over the
83
// sections in a stable order to ensure that we have print the
84
// constant pools in a deterministic order when printing an assembly
85
// file.
86
using
ConstantPoolMapTy
=
MapVector<MCSection *, ConstantPool>
;
87
ConstantPoolMapTy
ConstantPools;
88
89
public
:
90
void
emitAll(
MCStreamer
&Streamer);
91
void
emitForCurrentSection(
MCStreamer
&Streamer);
92
void
clearCacheForCurrentSection(
MCStreamer
&Streamer);
93
const
MCExpr
*addEntry(
MCStreamer
&Streamer,
const
MCExpr
*Expr,
94
unsigned
Size
,
SMLoc
Loc
);
95
96
private
:
97
ConstantPool
*getConstantPool(
MCSection
*
Section
);
98
ConstantPool
&getOrCreateConstantPool(
MCSection
*Section);
99
};
100
101
}
// end namespace llvm
102
103
#endif // LLVM_MC_CONSTANTPOOLS_H
llvm::ISD::ConstantPool
Definition:
ISDOpcodes.h:63
MapVector.h
llvm::MCSection
Instances of this class represent a uniqued identifier for a section in the current translation unit...
Definition:
MCSection.h:39
llvm::ConstantPoolEntry::Value
const MCExpr * Value
Definition:
ConstantPools.h:38
Context
LLVMContext & Context
Definition:
NVVMIntrRange.cpp:72
llvm
This class represents lattice values for constants.
Definition:
AllocatorList.h:24
llvm::MCSymbol
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition:
MCSymbol.h:42
llvm::ConstantPoolEntry
Definition:
ConstantPools.h:33
llvm::MapVector< MCSection *, ConstantPool >
llvm::ISD::MCSymbol
Definition:
ISDOpcodes.h:139
llvm::ConstantPoolEntry::Loc
SMLoc Loc
Definition:
ConstantPools.h:40
llvm::MCExpr
Base class for the full range of assembler expressions which are needed for parsing.
Definition:
MCExpr.h:36
llvm::ConstantPoolEntry::ConstantPoolEntry
ConstantPoolEntry(MCSymbol *L, const MCExpr *Val, unsigned Sz, SMLoc Loc_)
Definition:
ConstantPools.h:34
llvm::MCContext
Context object for machine code objects.
Definition:
MCContext.h:63
SMLoc.h
llvm::MCStreamer
Streaming machine code generation interface.
Definition:
MCStreamer.h:189
llvm::AssemblerConstantPools
Definition:
ConstantPools.h:71
DenseMap.h
llvm::empty
constexpr bool empty(const T &RangeOrContainer)
Test whether RangeOrContainer is empty. Similar to C++17 std::empty.
Definition:
STLExtras.h:210
llvm::ARMBuildAttrs::Section
Legacy Tags.
Definition:
ARMBuildAttributes.h:76
llvm::ConstantPool
Definition:
ConstantPools.h:45
llvm::ConstantPoolEntry::Label
MCSymbol * Label
Definition:
ConstantPools.h:37
llvm::SmallVector< ConstantPoolEntry, 4 >
llvm::Value
LLVM Value Representation.
Definition:
Value.h:73
SmallVector.h
llvm::ConstantPoolEntry::Size
unsigned Size
Definition:
ConstantPools.h:39
llvm::SMLoc
Represents a location in source code.
Definition:
SMLoc.h:24
Generated on Sun Dec 20 2020 13:53:30 for LLVM by
1.8.13