LLVM 24.0.0git
MCExpr.h
Go to the documentation of this file.
1//===- MCExpr.h - Assembly Level Expressions --------------------*- 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#ifndef LLVM_MC_MCEXPR_H
10#define LLVM_MC_MCEXPR_H
11
12#include "llvm/ADT/DenseMap.h"
14#include "llvm/Support/SMLoc.h"
15#include <cstdint>
16
17namespace llvm {
18
19class MCAsmInfo;
20class MCAssembler;
21class MCContext;
22class MCFragment;
23class MCStreamer;
24class MCSymbol;
25class MCValue;
26class raw_ostream;
27class MCSymbolRefExpr;
28
29/// Base class for the full range of assembler expressions which are
30/// needed for parsing.
31class MCExpr {
32public:
33 // Allow MC classes to access the private `print` function.
34 friend class MCAsmInfo;
35 friend class MCFragment;
36 friend class MCOperand;
38 Binary, ///< Binary expressions.
39 Constant, ///< Constant expressions.
40 SymbolRef, ///< References to labels and assigned expressions.
41 Unary, ///< Unary expressions.
42 Specifier, ///< Expression with a relocation specifier.
43 Target ///< Target specific expression.
44 };
45
46private:
47 static const unsigned NumSubclassDataBits = 24;
48 static_assert(
49 NumSubclassDataBits == CHAR_BIT * (sizeof(unsigned) - sizeof(ExprKind)),
50 "ExprKind and SubclassData together should take up one word");
51
52 ExprKind Kind;
53 /// Field reserved for use by MCExpr subclasses.
54 unsigned SubclassData : NumSubclassDataBits;
55 SMLoc Loc;
56
57 void print(raw_ostream &OS, const MCAsmInfo *MAI,
58 int SurroundingPrec = 0) const;
59 bool evaluateAsAbsolute(int64_t &Res, const MCAssembler *Asm,
60 bool InSet) const;
61
62protected:
63 using Spec = uint16_t;
64 explicit MCExpr(ExprKind Kind, SMLoc Loc, unsigned SubclassData = 0)
65 : Kind(Kind), SubclassData(SubclassData), Loc(Loc) {
66 assert(SubclassData < (1 << NumSubclassDataBits) &&
67 "Subclass data too large");
68 }
69
71 bool InSet) const;
72
73 unsigned getSubclassData() const { return SubclassData; }
74
75public:
76 MCExpr(const MCExpr &) = delete;
77 MCExpr &operator=(const MCExpr &) = delete;
78
79 /// \name Accessors
80 /// @{
81
82 ExprKind getKind() const { return Kind; }
83 SMLoc getLoc() const { return Loc; }
84
85 /// @}
86 /// \name Utility Methods
87 /// @{
88
89 LLVM_ABI void dump() const;
90
91 /// @}
92 /// \name Expression Evaluation
93 /// @{
94
95 /// Try to evaluate the expression to an absolute value.
96 ///
97 /// \param Res - The absolute value, if evaluation succeeds.
98 /// \return - True on success.
99 LLVM_ABI bool evaluateAsAbsolute(int64_t &Res) const;
100 LLVM_ABI bool evaluateAsAbsolute(int64_t &Res, const MCAssembler &Asm) const;
101 LLVM_ABI bool evaluateAsAbsolute(int64_t &Res, const MCAssembler *Asm) const;
102
103 /// Aggressive variant of evaluateAsRelocatable when relocations are
104 /// unavailable (e.g. .fill). Expects callers to handle errors when true is
105 /// returned.
106 LLVM_ABI bool evaluateKnownAbsolute(int64_t &Res,
107 const MCAssembler &Asm) const;
108
109 /// Try to evaluate the expression to a relocatable value, i.e. an
110 /// expression of the fixed form (a - b + constant).
111 ///
112 /// \param Res - The relocatable value, if evaluation succeeds.
113 /// \param Asm - The assembler object to use for evaluating values.
114 /// \return - True on success.
116 const MCAssembler *Asm) const;
117
118 /// Try to evaluate the expression to the form (a - b + constant) where
119 /// neither a nor b are variables.
120 ///
121 /// This is a more aggressive variant of evaluateAsRelocatable. The intended
122 /// use is for when relocations are not available, like the .size directive.
123 LLVM_ABI bool evaluateAsValue(MCValue &Res, const MCAssembler &Asm) const;
124
125 /// Find the "associated section" for this expression, which is
126 /// currently defined as the absolute section for constants, or
127 /// otherwise the section associated with the first defined symbol in the
128 /// expression.
130
131 /// @}
132
133 LLVM_ABI static bool evaluateSymbolicAdd(const MCAssembler *, bool,
134 const MCValue &, const MCValue &,
135 MCValue &);
136};
137
138//// Represent a constant integer expression.
139class MCConstantExpr : public MCExpr {
140 int64_t Value;
141
142 // Subclass data stores SizeInBytes in bits 0..7 and PrintInHex in bit 8.
143 static const unsigned SizeInBytesBits = 8;
144 static const unsigned SizeInBytesMask = (1 << SizeInBytesBits) - 1;
145 static const unsigned PrintInHexBit = 1 << SizeInBytesBits;
146
147 static unsigned encodeSubclassData(bool PrintInHex, unsigned SizeInBytes) {
148 assert(SizeInBytes <= sizeof(int64_t) && "Excessive size");
149 return SizeInBytes | (PrintInHex ? PrintInHexBit : 0);
150 }
151
152 MCConstantExpr(int64_t Value, bool PrintInHex, unsigned SizeInBytes)
154 encodeSubclassData(PrintInHex, SizeInBytes)), Value(Value) {}
155
156public:
157 /// \name Construction
158 /// @{
159
160 LLVM_ABI static const MCConstantExpr *create(int64_t Value, MCContext &Ctx,
161 bool PrintInHex = false,
162 unsigned SizeInBytes = 0);
163
164 /// @}
165 /// \name Accessors
166 /// @{
167
168 int64_t getValue() const { return Value; }
169 unsigned getSizeInBytes() const {
170 return getSubclassData() & SizeInBytesMask;
171 }
172
173 bool useHexFormat() const { return (getSubclassData() & PrintInHexBit) != 0; }
174
175 /// @}
176
177 static bool classof(const MCExpr *E) {
178 return E->getKind() == MCExpr::Constant;
179 }
180};
181
182/// Represent a reference to a symbol from inside an expression.
183///
184/// A symbol reference in an expression may be a use of a label, a use of an
185/// assembler variable (defined constant), or constitute an implicit definition
186/// of the symbol as external.
187class MCSymbolRefExpr : public MCExpr {
188public:
189 // VariantKind isn't ideal for encoding relocation operators because:
190 // (a) other expressions, like MCConstantExpr (e.g., 4@l) and MCBinaryExpr
191 // (e.g., (a+1)@l), also need it; (b) semantics become unclear (e.g., folding
192 // expressions with @). MCSpecifierExpr, as used by AArch64 and RISC-V, offers
193 // a cleaner approach.
195 VK_COFF_IMGREL32 = 3, // symbol@imgrel (image-relative)
196
198 };
199
200private:
201 /// The symbol being referenced.
202 const MCSymbol *Symbol;
203
204 explicit MCSymbolRefExpr(const MCSymbol *Symbol, Spec specifier, SMLoc Loc);
205
206public:
207 /// \name Construction
208 /// @{
209
210 static const MCSymbolRefExpr *create(const MCSymbol *Symbol, MCContext &Ctx,
211 SMLoc Loc = SMLoc()) {
212 return MCSymbolRefExpr::create(Symbol, 0, Ctx, Loc);
213 }
214
215 LLVM_ABI static const MCSymbolRefExpr *create(const MCSymbol *Symbol,
216 Spec specifier, MCContext &Ctx,
217 SMLoc Loc = SMLoc());
218
219 /// @}
220 /// \name Accessors
221 /// @{
222
223 const MCSymbol &getSymbol() const { return *Symbol; }
224
225 // Some targets encode the relocation specifier within SymA using
226 // MCSymbolRefExpr::SubclassData, which is copied to MCValue::Specifier,
227 // though this method is now deprecated.
230
231 /// @}
232
233 static bool classof(const MCExpr *E) {
234 return E->getKind() == MCExpr::SymbolRef;
235 }
236};
237
238/// Unary assembler expressions.
239class MCUnaryExpr : public MCExpr {
240public:
241 enum Opcode {
242 LNot, ///< Logical negation.
243 Minus, ///< Unary minus.
244 Not, ///< Bitwise negation.
245 Plus ///< Unary plus.
246 };
247
248private:
249 const MCExpr *Expr;
250
251 MCUnaryExpr(Opcode Op, const MCExpr *Expr, SMLoc Loc)
252 : MCExpr(MCExpr::Unary, Loc, Op), Expr(Expr) {}
253
254public:
255 /// \name Construction
256 /// @{
257
258 LLVM_ABI static const MCUnaryExpr *
259 create(Opcode Op, const MCExpr *Expr, MCContext &Ctx, SMLoc Loc = SMLoc());
260
261 static const MCUnaryExpr *createLNot(const MCExpr *Expr, MCContext &Ctx, SMLoc Loc = SMLoc()) {
262 return create(LNot, Expr, Ctx, Loc);
263 }
264
265 static const MCUnaryExpr *createMinus(const MCExpr *Expr, MCContext &Ctx, SMLoc Loc = SMLoc()) {
266 return create(Minus, Expr, Ctx, Loc);
267 }
268
269 static const MCUnaryExpr *createNot(const MCExpr *Expr, MCContext &Ctx, SMLoc Loc = SMLoc()) {
270 return create(Not, Expr, Ctx, Loc);
271 }
272
273 static const MCUnaryExpr *createPlus(const MCExpr *Expr, MCContext &Ctx, SMLoc Loc = SMLoc()) {
274 return create(Plus, Expr, Ctx, Loc);
275 }
276
277 /// @}
278 /// \name Accessors
279 /// @{
280
281 /// Get the kind of this unary expression.
282 Opcode getOpcode() const { return (Opcode)getSubclassData(); }
283
284 /// Get the child of this unary expression.
285 const MCExpr *getSubExpr() const { return Expr; }
286
287 /// @}
288
289 static bool classof(const MCExpr *E) {
290 return E->getKind() == MCExpr::Unary;
291 }
292};
293
294/// Binary assembler expressions.
295class MCBinaryExpr : public MCExpr {
296public:
297 enum Opcode {
298 Add, ///< Addition.
299 And, ///< Bitwise and.
300 Div, ///< Signed division.
301 EQ, ///< Equality comparison.
302 GT, ///< Signed greater than comparison (result is either 0 or some
303 ///< target-specific non-zero value)
304 GTE, ///< Signed greater than or equal comparison (result is either 0 or
305 ///< some target-specific non-zero value).
306 LAnd, ///< Logical and.
307 LOr, ///< Logical or.
308 LT, ///< Signed less than comparison (result is either 0 or
309 ///< some target-specific non-zero value).
310 LTE, ///< Signed less than or equal comparison (result is either 0 or
311 ///< some target-specific non-zero value).
312 Mod, ///< Signed remainder.
313 Mul, ///< Multiplication.
314 NE, ///< Inequality comparison.
315 Or, ///< Bitwise or.
316 OrNot, ///< Bitwise or not.
317 Shl, ///< Shift left.
318 AShr, ///< Arithmetic shift right.
319 LShr, ///< Logical shift right.
320 Sub, ///< Subtraction.
321 Xor ///< Bitwise exclusive or.
322 };
323
324private:
325 const MCExpr *LHS, *RHS;
326
327 MCBinaryExpr(Opcode Op, const MCExpr *LHS, const MCExpr *RHS,
328 SMLoc Loc = SMLoc())
329 : MCExpr(MCExpr::Binary, Loc, Op), LHS(LHS), RHS(RHS) {}
330
331public:
332 /// \name Construction
333 /// @{
334
335 LLVM_ABI static const MCBinaryExpr *create(Opcode Op, const MCExpr *LHS,
336 const MCExpr *RHS, MCContext &Ctx,
337 SMLoc Loc = SMLoc());
338
339 static const MCBinaryExpr *createAdd(const MCExpr *LHS, const MCExpr *RHS,
340 MCContext &Ctx, SMLoc Loc = SMLoc()) {
341 return create(Add, LHS, RHS, Ctx, Loc);
342 }
343
344 static const MCBinaryExpr *createAnd(const MCExpr *LHS, const MCExpr *RHS,
345 MCContext &Ctx) {
346 return create(And, LHS, RHS, Ctx);
347 }
348
349 static const MCBinaryExpr *createDiv(const MCExpr *LHS, const MCExpr *RHS,
350 MCContext &Ctx) {
351 return create(Div, LHS, RHS, Ctx);
352 }
353
354 static const MCBinaryExpr *createEQ(const MCExpr *LHS, const MCExpr *RHS,
355 MCContext &Ctx) {
356 return create(EQ, LHS, RHS, Ctx);
357 }
358
359 static const MCBinaryExpr *createGT(const MCExpr *LHS, const MCExpr *RHS,
360 MCContext &Ctx) {
361 return create(GT, LHS, RHS, Ctx);
362 }
363
364 static const MCBinaryExpr *createGTE(const MCExpr *LHS, const MCExpr *RHS,
365 MCContext &Ctx) {
366 return create(GTE, LHS, RHS, Ctx);
367 }
368
369 static const MCBinaryExpr *createLAnd(const MCExpr *LHS, const MCExpr *RHS,
370 MCContext &Ctx) {
371 return create(LAnd, LHS, RHS, Ctx);
372 }
373
374 static const MCBinaryExpr *createLOr(const MCExpr *LHS, const MCExpr *RHS,
375 MCContext &Ctx) {
376 return create(LOr, LHS, RHS, Ctx);
377 }
378
379 static const MCBinaryExpr *createLT(const MCExpr *LHS, const MCExpr *RHS,
380 MCContext &Ctx) {
381 return create(LT, LHS, RHS, Ctx);
382 }
383
384 static const MCBinaryExpr *createLTE(const MCExpr *LHS, const MCExpr *RHS,
385 MCContext &Ctx) {
386 return create(LTE, LHS, RHS, Ctx);
387 }
388
389 static const MCBinaryExpr *createMod(const MCExpr *LHS, const MCExpr *RHS,
390 MCContext &Ctx) {
391 return create(Mod, LHS, RHS, Ctx);
392 }
393
394 static const MCBinaryExpr *createMul(const MCExpr *LHS, const MCExpr *RHS,
395 MCContext &Ctx) {
396 return create(Mul, LHS, RHS, Ctx);
397 }
398
399 static const MCBinaryExpr *createNE(const MCExpr *LHS, const MCExpr *RHS,
400 MCContext &Ctx) {
401 return create(NE, LHS, RHS, Ctx);
402 }
403
404 static const MCBinaryExpr *createOr(const MCExpr *LHS, const MCExpr *RHS,
405 MCContext &Ctx) {
406 return create(Or, LHS, RHS, Ctx);
407 }
408
409 static const MCBinaryExpr *createShl(const MCExpr *LHS, const MCExpr *RHS,
410 MCContext &Ctx) {
411 return create(Shl, LHS, RHS, Ctx);
412 }
413
414 static const MCBinaryExpr *createAShr(const MCExpr *LHS, const MCExpr *RHS,
415 MCContext &Ctx) {
416 return create(AShr, LHS, RHS, Ctx);
417 }
418
419 static const MCBinaryExpr *createLShr(const MCExpr *LHS, const MCExpr *RHS,
420 MCContext &Ctx) {
421 return create(LShr, LHS, RHS, Ctx);
422 }
423
424 static const MCBinaryExpr *createSub(const MCExpr *LHS, const MCExpr *RHS,
425 MCContext &Ctx) {
426 return create(Sub, LHS, RHS, Ctx);
427 }
428
429 static const MCBinaryExpr *createXor(const MCExpr *LHS, const MCExpr *RHS,
430 MCContext &Ctx) {
431 return create(Xor, LHS, RHS, Ctx);
432 }
433
434 /// @}
435 /// \name Accessors
436 /// @{
437
438 /// Get the kind of this binary expression.
439 Opcode getOpcode() const { return (Opcode)getSubclassData(); }
440
441 /// Get the left-hand side expression of the binary operator.
442 const MCExpr *getLHS() const { return LHS; }
443
444 /// Get the right-hand side expression of the binary operator.
445 const MCExpr *getRHS() const { return RHS; }
446
447 /// @}
448
449 static bool classof(const MCExpr *E) {
450 return E->getKind() == MCExpr::Binary;
451 }
452};
453
454/// Extension point for target-specific MCExpr subclasses to implement.
455/// This can encode a relocation operator, serving as a replacement for
456/// MCSymbolRefExpr::VariantKind. Ideally, limit this to
457/// top-level use, avoiding its inclusion as a subexpression.
458///
459/// NOTE: All subclasses are required to have trivial destructors because
460/// MCExprs are bump pointer allocated and not destructed.
462 virtual void anchor();
463
464protected:
466 virtual ~MCTargetExpr() = default;
467
468public:
469 virtual void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const = 0;
471 const MCAssembler *Asm) const = 0;
472 // allow Target Expressions to be checked for equality
473 virtual bool isEqualTo(const MCExpr *x) const { return false; }
474 // This should be set when assigned expressions are not valid ".set"
475 // expressions, e.g. registers, and must be inlined.
476 virtual bool inlineAssignedExpr() const { return false; }
477 virtual void visitUsedExpr(MCStreamer& Streamer) const = 0;
478 virtual MCFragment *findAssociatedFragment() const = 0;
479
480 static bool classof(const MCExpr *E) {
481 return E->getKind() == MCExpr::Target;
482 }
483};
484
485/// Extension point for target-specific MCExpr subclasses with a relocation
486/// specifier, serving as a replacement for MCSymbolRefExpr::VariantKind.
487/// Limit this to top-level use, avoiding its inclusion as a subexpression.
488///
489/// NOTE: All subclasses are required to have trivial destructors because
490/// MCExprs are bump pointer allocated and not destructed.
492protected:
493 const MCExpr *Expr;
494
495 explicit MCSpecifierExpr(const MCExpr *Expr, Spec S, SMLoc Loc = SMLoc())
496 : MCExpr(Specifier, Loc, S), Expr(Expr) {}
497
498public:
499 static const MCSpecifierExpr *create(const MCExpr *Expr, Spec S,
500 MCContext &Ctx, SMLoc Loc = SMLoc());
501 static const MCSpecifierExpr *create(const MCSymbol *Sym, Spec S,
502 MCContext &Ctx, SMLoc Loc = SMLoc());
503
504 Spec getSpecifier() const { return getSubclassData(); }
505 const MCExpr *getSubExpr() const { return Expr; }
506
507 static bool classof(const MCExpr *E) {
508 return E->getKind() == MCExpr::Specifier;
509 }
510};
511
512} // end namespace llvm
513
514#endif // LLVM_MC_MCEXPR_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val)
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
#define LLVM_ABI
Definition Compiler.h:211
This file defines the DenseMap class.
std::unique_ptr< MCStreamer > && Streamer
Value * RHS
Value * LHS
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition MCAsmInfo.h:69
Binary assembler expressions.
Definition MCExpr.h:295
const MCExpr * getLHS() const
Get the left-hand side expression of the binary operator.
Definition MCExpr.h:442
static const MCBinaryExpr * createEQ(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition MCExpr.h:354
static const MCBinaryExpr * createLShr(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition MCExpr.h:419
static const MCBinaryExpr * createLAnd(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition MCExpr.h:369
static const MCBinaryExpr * createAdd(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx, SMLoc Loc=SMLoc())
Definition MCExpr.h:339
const MCExpr * getRHS() const
Get the right-hand side expression of the binary operator.
Definition MCExpr.h:445
static const MCBinaryExpr * createXor(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition MCExpr.h:429
static const MCBinaryExpr * createAnd(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition MCExpr.h:344
static bool classof(const MCExpr *E)
Definition MCExpr.h:449
static const MCBinaryExpr * createLT(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition MCExpr.h:379
Opcode getOpcode() const
Get the kind of this binary expression.
Definition MCExpr.h:439
static const MCBinaryExpr * createOr(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition MCExpr.h:404
static const MCBinaryExpr * createMod(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition MCExpr.h:389
static const MCBinaryExpr * createLOr(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition MCExpr.h:374
static const MCBinaryExpr * createNE(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition MCExpr.h:399
static const MCBinaryExpr * createGTE(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition MCExpr.h:364
static const MCBinaryExpr * createMul(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition MCExpr.h:394
static const MCBinaryExpr * createLTE(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition MCExpr.h:384
static const MCBinaryExpr * createAShr(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition MCExpr.h:414
static const MCBinaryExpr * createGT(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition MCExpr.h:359
static const MCBinaryExpr * createDiv(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition MCExpr.h:349
static LLVM_ABI const MCBinaryExpr * create(Opcode Op, const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx, SMLoc Loc=SMLoc())
Definition MCExpr.cpp:201
static const MCBinaryExpr * createShl(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition MCExpr.h:409
static const MCBinaryExpr * createSub(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition MCExpr.h:424
@ Div
Signed division.
Definition MCExpr.h:300
@ Shl
Shift left.
Definition MCExpr.h:317
@ AShr
Arithmetic shift right.
Definition MCExpr.h:318
@ LShr
Logical shift right.
Definition MCExpr.h:319
@ GTE
Signed greater than or equal comparison (result is either 0 or some target-specific non-zero value).
Definition MCExpr.h:304
@ EQ
Equality comparison.
Definition MCExpr.h:301
@ Sub
Subtraction.
Definition MCExpr.h:320
@ Mul
Multiplication.
Definition MCExpr.h:313
@ GT
Signed greater than comparison (result is either 0 or some target-specific non-zero value)
Definition MCExpr.h:302
@ Mod
Signed remainder.
Definition MCExpr.h:312
@ And
Bitwise and.
Definition MCExpr.h:299
@ Or
Bitwise or.
Definition MCExpr.h:315
@ Xor
Bitwise exclusive or.
Definition MCExpr.h:321
@ OrNot
Bitwise or not.
Definition MCExpr.h:316
@ LAnd
Logical and.
Definition MCExpr.h:306
@ LOr
Logical or.
Definition MCExpr.h:307
@ LT
Signed less than comparison (result is either 0 or some target-specific non-zero value).
Definition MCExpr.h:308
@ Add
Addition.
Definition MCExpr.h:298
@ LTE
Signed less than or equal comparison (result is either 0 or some target-specific non-zero value).
Definition MCExpr.h:310
@ NE
Inequality comparison.
Definition MCExpr.h:314
static bool classof(const MCExpr *E)
Definition MCExpr.h:177
bool useHexFormat() const
Definition MCExpr.h:173
unsigned getSizeInBytes() const
Definition MCExpr.h:169
int64_t getValue() const
Definition MCExpr.h:168
static LLVM_ABI const MCConstantExpr * create(int64_t Value, MCContext &Ctx, bool PrintInHex=false, unsigned SizeInBytes=0)
Definition MCExpr.cpp:212
Context object for machine code objects.
Definition MCContext.h:84
Base class for the full range of assembler expressions which are needed for parsing.
Definition MCExpr.h:31
uint16_t Spec
Definition MCExpr.h:63
friend class MCAsmInfo
Definition MCExpr.h:34
LLVM_ABI bool evaluateAsValue(MCValue &Res, const MCAssembler &Asm) const
Try to evaluate the expression to the form (a - b + constant) where neither a nor b are variables.
Definition MCExpr.cpp:453
MCExpr & operator=(const MCExpr &)=delete
LLVM_ABI bool evaluateAsRelocatable(MCValue &Res, const MCAssembler *Asm) const
Try to evaluate the expression to a relocatable value, i.e.
Definition MCExpr.cpp:450
MCExpr(ExprKind Kind, SMLoc Loc, unsigned SubclassData=0)
Definition MCExpr.h:64
@ Unary
Unary expressions.
Definition MCExpr.h:41
@ Constant
Constant expressions.
Definition MCExpr.h:39
@ SymbolRef
References to labels and assigned expressions.
Definition MCExpr.h:40
@ Target
Target specific expression.
Definition MCExpr.h:43
@ Specifier
Expression with a relocation specifier.
Definition MCExpr.h:42
@ Binary
Binary expressions.
Definition MCExpr.h:38
MCExpr(const MCExpr &)=delete
static LLVM_ABI bool evaluateSymbolicAdd(const MCAssembler *, bool, const MCValue &, const MCValue &, MCValue &)
Definition MCExpr.cpp:407
friend class MCOperand
Definition MCExpr.h:36
LLVM_ABI bool evaluateKnownAbsolute(int64_t &Res, const MCAssembler &Asm) const
Aggressive variant of evaluateAsRelocatable when relocations are unavailable (e.g.
Definition MCExpr.cpp:250
friend class MCFragment
Definition MCExpr.h:35
unsigned getSubclassData() const
Definition MCExpr.h:73
LLVM_ABI MCFragment * findAssociatedFragment() const
Find the "associated section" for this expression, which is currently defined as the absolute section...
Definition MCExpr.cpp:692
LLVM_ABI bool evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm, bool InSet) const
Definition MCExpr.cpp:457
LLVM_ABI void dump() const
Definition MCExpr.cpp:193
ExprKind getKind() const
Definition MCExpr.h:82
SMLoc getLoc() const
Definition MCExpr.h:83
Extension point for target-specific MCExpr subclasses with a relocation specifier,...
Definition MCExpr.h:491
const MCExpr * getSubExpr() const
Definition MCExpr.h:505
static bool classof(const MCExpr *E)
Definition MCExpr.h:507
const MCExpr * Expr
Definition MCExpr.h:493
MCSpecifierExpr(const MCExpr *Expr, Spec S, SMLoc Loc=SMLoc())
Definition MCExpr.h:495
Spec getSpecifier() const
Definition MCExpr.h:504
Streaming machine code generation interface.
Definition MCStreamer.h:221
Represent a reference to a symbol from inside an expression.
Definition MCExpr.h:187
const MCSymbol & getSymbol() const
Definition MCExpr.h:223
static bool classof(const MCExpr *E)
Definition MCExpr.h:233
uint16_t getSpecifier() const
Definition MCExpr.h:229
VariantKind getKind() const
Definition MCExpr.h:228
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx, SMLoc Loc=SMLoc())
Definition MCExpr.h:210
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition MCSymbol.h:42
static bool classof(const MCExpr *E)
Definition MCExpr.h:480
virtual void visitUsedExpr(MCStreamer &Streamer) const =0
virtual void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const =0
virtual MCFragment * findAssociatedFragment() const =0
virtual bool isEqualTo(const MCExpr *x) const
Definition MCExpr.h:473
virtual bool evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm) const =0
virtual bool inlineAssignedExpr() const
Definition MCExpr.h:476
virtual ~MCTargetExpr()=default
Unary assembler expressions.
Definition MCExpr.h:239
Opcode getOpcode() const
Get the kind of this unary expression.
Definition MCExpr.h:282
static bool classof(const MCExpr *E)
Definition MCExpr.h:289
static LLVM_ABI const MCUnaryExpr * create(Opcode Op, const MCExpr *Expr, MCContext &Ctx, SMLoc Loc=SMLoc())
Definition MCExpr.cpp:207
static const MCUnaryExpr * createLNot(const MCExpr *Expr, MCContext &Ctx, SMLoc Loc=SMLoc())
Definition MCExpr.h:261
@ Minus
Unary minus.
Definition MCExpr.h:243
@ Plus
Unary plus.
Definition MCExpr.h:245
@ Not
Bitwise negation.
Definition MCExpr.h:244
@ LNot
Logical negation.
Definition MCExpr.h:242
const MCExpr * getSubExpr() const
Get the child of this unary expression.
Definition MCExpr.h:285
static const MCUnaryExpr * createPlus(const MCExpr *Expr, MCContext &Ctx, SMLoc Loc=SMLoc())
Definition MCExpr.h:273
static const MCUnaryExpr * createNot(const MCExpr *Expr, MCContext &Ctx, SMLoc Loc=SMLoc())
Definition MCExpr.h:269
static const MCUnaryExpr * createMinus(const MCExpr *Expr, MCContext &Ctx, SMLoc Loc=SMLoc())
Definition MCExpr.h:265
Represents a location in source code.
Definition SMLoc.h:22
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
This is an optimization pass for GlobalISel generic memory operations.
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Value
Definition InstrProf.h:143
DWARFExpression::Operation Op