LLVM: include/llvm/MC/MCExpr.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9#ifndef LLVM_MC_MCEXPR_H
10#define LLVM_MC_MCEXPR_H
11
15#include
16
17namespace llvm {
18
31
32
33
35public:
36
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
57 unsigned SubclassData : NumSubclassDataBits;
59
61 int SurroundingPrec = 0) const;
62 bool evaluateAsAbsolute(int64_t &Res, const MCAssembler *Asm,
63 bool InSet) const;
64
65protected:
68 : Kind(Kind), SubclassData(SubclassData), Loc(Loc) {
69 assert(SubclassData < (1 << NumSubclassDataBits) &&
70 "Subclass data too large");
71 }
72
74 bool InSet) const;
75
77
78public:
81
82
83
84
87
88
89
90
91
93
94
95
96
97
98
99
100
101
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
107
108
111
112
113
114
115
116
117
120
121
122
123
124
125
127
128
129
130
131
133
134
135
139};
140
141
142class MCConstantExpr : public MCExpr {
143 int64_t Value;
144
145
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
161
162
164 bool PrintInHex = false,
165 unsigned SizeInBytes = 0);
166
167
168
169
170
171 int64_t getValue() const { return Value; }
175
177
178
179
183};
184
185
186
187
188
189
190class MCSymbolRefExpr : public MCExpr {
191public:
192
193
194
195
196
202
203private:
204
206
209
210public:
211
212
213
218
222
223
224
225
226
228
229
230
231
234
235
236
240};
241
242
243class MCUnaryExpr : public MCExpr {
244public:
251
252private:
254
257
258public:
259
260
261
262 LLVM_ABI static const MCUnaryExpr *
263 create(Opcode Op, const MCExpr *Expr, MCContext &Ctx, SMLoc Loc = SMLoc());
264
268
272
274 return create(Not, Expr, Ctx, Loc);
275 }
276
280
281
282
283
284
285
287
288
290
291
292
296};
297
298
299class MCBinaryExpr : public MCExpr {
300public:
307
309
313
315
326 };
327
328private:
330
334
335public:
336
337
338
340 const MCExpr *RHS, MCContext &Ctx,
341 SMLoc Loc = SMLoc());
342
345 return create(Add, LHS, RHS, Ctx, Loc);
346 }
347
352
357
360 return create(EQ, LHS, RHS, Ctx);
361 }
362
365 return create(GT, LHS, RHS, Ctx);
366 }
367
372
377
382
385 return create(LT, LHS, RHS, Ctx);
386 }
387
392
397
402
405 return create(NE, LHS, RHS, Ctx);
406 }
407
410 return create(Or, LHS, RHS, Ctx);
411 }
412
417
422
427
432
437
438
439
440
441
442
444
445
447
448
450
451
452
456};
457
458
459
460
461
462
463
464
466 virtual void anchor();
467
468protected:
471
472public:
476
478
479
483
487};
488
489
490
491
492
493
494
496protected:
498
501
502public:
507
510
514};
515
516}
517
518#endif
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")
This file defines the DenseMap class.
This class is intended to be used as a base class for asm properties and features specific to the tar...
Binary assembler expressions.
Definition MCExpr.h:299
const MCExpr * getLHS() const
Get the left-hand side expression of the binary operator.
Definition MCExpr.h:446
static const MCBinaryExpr * createEQ(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition MCExpr.h:358
static const MCBinaryExpr * createLShr(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition MCExpr.h:423
static const MCBinaryExpr * createLAnd(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition MCExpr.h:373
static const MCBinaryExpr * createAdd(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx, SMLoc Loc=SMLoc())
Definition MCExpr.h:343
const MCExpr * getRHS() const
Get the right-hand side expression of the binary operator.
Definition MCExpr.h:449
static const MCBinaryExpr * createXor(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition MCExpr.h:433
static const MCBinaryExpr * createAnd(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition MCExpr.h:348
static bool classof(const MCExpr *E)
Definition MCExpr.h:453
static const MCBinaryExpr * createLT(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition MCExpr.h:383
Opcode getOpcode() const
Get the kind of this binary expression.
Definition MCExpr.h:443
static const MCBinaryExpr * createOr(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition MCExpr.h:408
static const MCBinaryExpr * createMod(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition MCExpr.h:393
static const MCBinaryExpr * createLOr(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition MCExpr.h:378
static const MCBinaryExpr * createNE(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition MCExpr.h:403
static const MCBinaryExpr * createGTE(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition MCExpr.h:368
static const MCBinaryExpr * createMul(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition MCExpr.h:398
static const MCBinaryExpr * createLTE(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition MCExpr.h:388
static const MCBinaryExpr * createAShr(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition MCExpr.h:418
static const MCBinaryExpr * createGT(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition MCExpr.h:363
static const MCBinaryExpr * createDiv(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition MCExpr.h:353
static LLVM_ABI const MCBinaryExpr * create(Opcode Op, const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx, SMLoc Loc=SMLoc())
static const MCBinaryExpr * createShl(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition MCExpr.h:413
static const MCBinaryExpr * createSub(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition MCExpr.h:428
Opcode
Definition MCExpr.h:301
@ Div
Signed division.
Definition MCExpr.h:304
@ Shl
Shift left.
Definition MCExpr.h:321
@ AShr
Arithmetic shift right.
Definition MCExpr.h:322
@ LShr
Logical shift right.
Definition MCExpr.h:323
@ GTE
Signed greater than or equal comparison (result is either 0 or some target-specific non-zero value).
Definition MCExpr.h:308
@ EQ
Equality comparison.
Definition MCExpr.h:305
@ Sub
Subtraction.
Definition MCExpr.h:324
@ Mul
Multiplication.
Definition MCExpr.h:317
@ GT
Signed greater than comparison (result is either 0 or some target-specific non-zero value)
Definition MCExpr.h:306
@ Mod
Signed remainder.
Definition MCExpr.h:316
@ And
Bitwise and.
Definition MCExpr.h:303
@ Or
Bitwise or.
Definition MCExpr.h:319
@ Xor
Bitwise exclusive or.
Definition MCExpr.h:325
@ OrNot
Bitwise or not.
Definition MCExpr.h:320
@ LAnd
Logical and.
Definition MCExpr.h:310
@ LOr
Logical or.
Definition MCExpr.h:311
@ LT
Signed less than comparison (result is either 0 or some target-specific non-zero value).
Definition MCExpr.h:312
@ Add
Addition.
Definition MCExpr.h:302
@ LTE
Signed less than or equal comparison (result is either 0 or some target-specific non-zero value).
Definition MCExpr.h:314
@ NE
Inequality comparison.
Definition MCExpr.h:318
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)
Context object for machine code objects.
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.
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.
MCExpr(ExprKind Kind, SMLoc Loc, unsigned SubclassData=0)
Definition MCExpr.h:67
ExprKind
Definition MCExpr.h:40
@ 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 &)
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.
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...
LLVM_ABI bool evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm, bool InSet) const
LLVM_ABI void dump() const
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)...
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Extension point for target-specific MCExpr subclasses with a relocation specifier,...
Definition MCExpr.h:495
const MCExpr * getSubExpr() const
Definition MCExpr.h:509
static bool classof(const MCExpr *E)
Definition MCExpr.h:511
const MCExpr * Expr
Definition MCExpr.h:497
MCSpecifierExpr(const MCExpr *Expr, Spec S, SMLoc Loc=SMLoc())
Definition MCExpr.h:499
Spec getSpecifier() const
Definition MCExpr.h:508
Streaming machine code generation interface.
Represent a reference to a symbol from inside an expression.
Definition MCExpr.h:190
const MCSymbol & getSymbol() const
Definition MCExpr.h:227
static bool classof(const MCExpr *E)
Definition MCExpr.h:237
VariantKind
Definition MCExpr.h:197
@ FirstTargetSpecifier
Definition MCExpr.h:200
@ VK_COFF_IMGREL32
Definition MCExpr.h:198
uint16_t getSpecifier() const
Definition MCExpr.h:233
VariantKind getKind() const
Definition MCExpr.h:232
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx, SMLoc Loc=SMLoc())
Definition MCExpr.h:214
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
static bool classof(const MCExpr *E)
Definition MCExpr.h:484
virtual void visitUsedExpr(MCStreamer &Streamer) const =0
virtual void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const =0
virtual MCFragment * findAssociatedFragment() const =0
MCTargetExpr()
Definition MCExpr.h:469
virtual bool isEqualTo(const MCExpr *x) const
Definition MCExpr.h:477
virtual bool evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm) const =0
virtual bool inlineAssignedExpr() const
Definition MCExpr.h:480
virtual ~MCTargetExpr()=default
Unary assembler expressions.
Definition MCExpr.h:243
Opcode getOpcode() const
Get the kind of this unary expression.
Definition MCExpr.h:286
static bool classof(const MCExpr *E)
Definition MCExpr.h:293
static LLVM_ABI const MCUnaryExpr * create(Opcode Op, const MCExpr *Expr, MCContext &Ctx, SMLoc Loc=SMLoc())
static const MCUnaryExpr * createLNot(const MCExpr *Expr, MCContext &Ctx, SMLoc Loc=SMLoc())
Definition MCExpr.h:265
Opcode
Definition MCExpr.h:245
@ Minus
Unary minus.
Definition MCExpr.h:247
@ Plus
Unary plus.
Definition MCExpr.h:249
@ Not
Bitwise negation.
Definition MCExpr.h:248
@ LNot
Logical negation.
Definition MCExpr.h:246
const MCExpr * getSubExpr() const
Get the child of this unary expression.
Definition MCExpr.h:289
static const MCUnaryExpr * createPlus(const MCExpr *Expr, MCContext &Ctx, SMLoc Loc=SMLoc())
Definition MCExpr.h:277
static const MCUnaryExpr * createNot(const MCExpr *Expr, MCContext &Ctx, SMLoc Loc=SMLoc())
Definition MCExpr.h:273
static const MCUnaryExpr * createMinus(const MCExpr *Expr, MCContext &Ctx, SMLoc Loc=SMLoc())
Definition MCExpr.h:269
Represents a location in source code.
StringRef - Represent a constant reference to a string, i.e.
This class implements an extremely fast bulk output stream that can only output to a stream.
This is an optimization pass for GlobalISel generic memory operations.
FunctionAddr VTableAddr Value
DWARFExpression::Operation Op