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