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