LLVM: lib/Target/PowerPC/MCTargetDesc/PPCELFStreamer.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
33
34using namespace llvm;
35
37 std::unique_ptr MAB,
38 std::unique_ptr OW,
39 std::unique_ptr Emitter)
41 LastLabel(nullptr) {}
42
43void PPCELFStreamer::emitPrefixedInstruction(const MCInst &Inst,
45
46
47
48
49
50
51
52
53
54
56
57
58
59
60
62
63
64
67
68 if (LastLabel && LastLabel->isDefined() && LastLabelLoc.isValid() &&
71 unsigned InstLine = SourceManager->FindLineNumber(InstLoc);
72 unsigned LabelLine = SourceManager->FindLineNumber(LastLabelLoc);
73
74
75
76 if (InstLine == LabelLine) {
77 LastLabel->setFragment(InstructionFragment);
79 }
80 }
81}
82
87
88
89
90
91
92 std::optional IsPartOfGOTToPCRelPair =
94
95
96
97
98
99 if (IsPartOfGOTToPCRelPair && !*IsPartOfGOTToPCRelPair)
100 emitGOTToPCRelReloc(Inst);
101
102
103 if (->isPrefixedInstruction(Inst)) {
105 return;
106 }
107 emitPrefixedInstruction(Inst, STI);
108
109
110
111
112
113
114 if (IsPartOfGOTToPCRelPair && *IsPartOfGOTToPCRelPair)
115 emitGOTToPCRelLabel(Inst);
116}
117
119 LastLabel = Symbol;
120 LastLabelLoc = Loc;
122}
123
124
125
126
127
128
129
130
131
132
133
134
135void PPCELFStreamer::emitGOTToPCRelReloc(const MCInst &Inst) {
136
138 assert(Operand.isExpr() && "Expecting an MCExpr.");
139
143 "Expecting a symbol of type VK_PCREL_OPT");
148
149 const MCExpr *SubExpr =
152 const MCExpr *CurrentLocationExpr =
154
155 const MCExpr *SubExpr2 =
157
159 F->addFixup(
163}
164
165
166
167void PPCELFStreamer::emitGOTToPCRelLabel(const MCInst &Inst) {
168
170 assert(Operand.isExpr() && "Expecting an MCExpr.");
171
175 "Expecting a symbol of type VK_PCREL_OPT");
179}
180
181
182
183
184
185
186
187
188
189
190
191
192
193
196
198 return std::nullopt;
199
201
202
203
204
206 if (!Operand.isExpr())
207 return std::nullopt;
208
209
213 return std::nullopt;
214
215 return (Inst.getOpcode() == PPC::PLDpc);
216}
217
220 std::unique_ptr &&MAB,
221 std::unique_ptr &&OW,
222 std::unique_ptr &&Emitter) {
223 return new PPCELFStreamer(C, std::move(MAB), std::move(OW),
225}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
dxil DXContainer Global Emitter
MCCodeEmitter * getEmitterPtr() const
static const MCBinaryExpr * createSub(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
static LLVM_ABI const MCConstantExpr * create(int64_t Value, MCContext &Ctx, bool PrintInHex=false, unsigned SizeInBytes=0)
Context object for machine code objects.
LLVM_ABI MCSymbol * createTempSymbol()
Create a temporary symbol with a unique name.
const SourceMgr * getSourceManager() const
LLVM_ABI MCSymbol * getOrCreateSymbol(const Twine &Name)
Lookup the symbol inside with the specified Name.
void emitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc()) override
Emit a label for Symbol into the current section.
MCELFStreamer(MCContext &Context, std::unique_ptr< MCAsmBackend > TAB, std::unique_ptr< MCObjectWriter > OW, std::unique_ptr< MCCodeEmitter > Emitter)
Base class for the full range of assembler expressions which are needed for parsing.
static MCFixup create(uint32_t Offset, const MCExpr *Value, MCFixupKind Kind, bool PCRel=false)
Consider bit fields if we need more flags.
Instances of this class represent a single low-level machine instruction.
unsigned getNumOperands() const
unsigned getOpcode() const
const MCOperand & getOperand(unsigned i) const
MCAssembler & getAssembler()
void emitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI) override
Emit the given Instruction into the current section.
void emitCodeAlignment(Align ByteAlignment, const MCSubtargetInfo *STI, unsigned MaxBytesToEmit=0) override
Emit nops until the byte alignment ByteAlignment is reached.
Instances of this class represent operands of the MCInst class.
const MCExpr * getExpr() const
Streaming machine code generation interface.
MCFragment * getCurrentFragment() const
MCContext & getContext() const
Generic base class for all target subtargets.
Represent a reference to a symbol from inside an expression.
const MCSymbol & getSymbol() const
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx, SMLoc Loc=SMLoc())
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
bool isDefined() const
isDefined - Check if this symbol is defined (i.e., it has an address).
StringRef getName() const
getName - Get the symbol name.
void setFragment(MCFragment *F) const
Mark the symbol as defined in the fragment F.
void setOffset(uint64_t Value)
MCFragment * getFragment() const
uint64_t getOffset() const
void emitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI) override
Emit the given Instruction into the current section.
Definition PPCELFStreamer.cpp:83
PPCELFStreamer(MCContext &Context, std::unique_ptr< MCAsmBackend > MAB, std::unique_ptr< MCObjectWriter > OW, std::unique_ptr< MCCodeEmitter > Emitter)
Definition PPCELFStreamer.cpp:36
void emitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc()) override
Emit a label for Symbol into the current section.
Definition PPCELFStreamer.cpp:118
Represents a location in source code.
constexpr bool isValid() const
This owns the files read by a parser, handles include stacks, and handles diagnostic wrangling.
unsigned FindLineNumber(SMLoc Loc, unsigned BufferID=0) const
Find the line number for the specified location in the specified file.
Triple - Helper class for working with autoconf configuration names.
@ C
The default llvm calling convention, compatible with C.
This is an optimization pass for GlobalISel generic memory operations.
@ FirstLiteralRelocationKind
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
static uint16_t getSpecifier(const MCSymbolRefExpr *SRE)
std::optional< bool > isPartOfGOTToPCRelPair(const MCInst &Inst, const MCSubtargetInfo &STI)
Definition PPCELFStreamer.cpp:194
MCStreamer * createPPCELFStreamer(const Triple &, MCContext &, std::unique_ptr< MCAsmBackend > &&MAB, std::unique_ptr< MCObjectWriter > &&OW, std::unique_ptr< MCCodeEmitter > &&Emitter)
Definition PPCELFStreamer.cpp:219
Implement std::hash so that hash_code can be used in STL containers.
This struct is a compact representation of a valid (non-zero power of two) alignment.