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