/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/include/llvm/MC/MCExpr.h
Line | Count | Source (jump to first uncovered line) |
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" |
13 | | #include "llvm/Support/SMLoc.h" |
14 | | #include <cstdint> |
15 | | |
16 | | namespace llvm { |
17 | | |
18 | | class MCAsmInfo; |
19 | | class MCAsmLayout; |
20 | | class MCAssembler; |
21 | | class MCContext; |
22 | | class MCFixup; |
23 | | class MCFragment; |
24 | | class MCSection; |
25 | | class MCStreamer; |
26 | | class MCSymbol; |
27 | | class MCValue; |
28 | | class raw_ostream; |
29 | | class StringRef; |
30 | | |
31 | | using SectionAddrMap = DenseMap<const MCSection *, uint64_t>; |
32 | | |
33 | | /// Base class for the full range of assembler expressions which are |
34 | | /// needed for parsing. |
35 | | class MCExpr { |
36 | | public: |
37 | | enum ExprKind { |
38 | | Binary, ///< Binary expressions. |
39 | | Constant, ///< Constant expressions. |
40 | | SymbolRef, ///< References to labels and assigned expressions. |
41 | | Unary, ///< Unary expressions. |
42 | | Target ///< Target specific expression. |
43 | | }; |
44 | | |
45 | | private: |
46 | | ExprKind Kind; |
47 | | SMLoc Loc; |
48 | | |
49 | | bool evaluateAsAbsolute(int64_t &Res, const MCAssembler *Asm, |
50 | | const MCAsmLayout *Layout, |
51 | | const SectionAddrMap *Addrs) const; |
52 | | |
53 | | bool evaluateAsAbsolute(int64_t &Res, const MCAssembler *Asm, |
54 | | const MCAsmLayout *Layout, |
55 | | const SectionAddrMap *Addrs, bool InSet) const; |
56 | | |
57 | | protected: |
58 | 16.4M | explicit MCExpr(ExprKind Kind, SMLoc Loc) : Kind(Kind), Loc(Loc) {} |
59 | | |
60 | | bool evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm, |
61 | | const MCAsmLayout *Layout, |
62 | | const MCFixup *Fixup, |
63 | | const SectionAddrMap *Addrs, bool InSet) const; |
64 | | |
65 | | public: |
66 | | MCExpr(const MCExpr &) = delete; |
67 | | MCExpr &operator=(const MCExpr &) = delete; |
68 | | |
69 | | /// \name Accessors |
70 | | /// @{ |
71 | | |
72 | 56.7M | ExprKind getKind() const { return Kind; } |
73 | 11 | SMLoc getLoc() const { return Loc; } |
74 | | |
75 | | /// @} |
76 | | /// \name Utility Methods |
77 | | /// @{ |
78 | | |
79 | | void print(raw_ostream &OS, const MCAsmInfo *MAI, |
80 | | bool InParens = false) const; |
81 | | void dump() const; |
82 | | |
83 | | /// @} |
84 | | /// \name Expression Evaluation |
85 | | /// @{ |
86 | | |
87 | | /// Try to evaluate the expression to an absolute value. |
88 | | /// |
89 | | /// \param Res - The absolute value, if evaluation succeeds. |
90 | | /// \param Layout - The assembler layout object to use for evaluating symbol |
91 | | /// values. If not given, then only non-symbolic expressions will be |
92 | | /// evaluated. |
93 | | /// \return - True on success. |
94 | | bool evaluateAsAbsolute(int64_t &Res, const MCAsmLayout &Layout, |
95 | | const SectionAddrMap &Addrs) const; |
96 | | bool evaluateAsAbsolute(int64_t &Res) const; |
97 | | bool evaluateAsAbsolute(int64_t &Res, const MCAssembler &Asm) const; |
98 | | bool evaluateAsAbsolute(int64_t &Res, const MCAssembler *Asm) const; |
99 | | bool evaluateAsAbsolute(int64_t &Res, const MCAsmLayout &Layout) const; |
100 | | |
101 | | bool evaluateKnownAbsolute(int64_t &Res, const MCAsmLayout &Layout) const; |
102 | | |
103 | | /// Try to evaluate the expression to a relocatable value, i.e. an |
104 | | /// expression of the fixed form (a - b + constant). |
105 | | /// |
106 | | /// \param Res - The relocatable value, if evaluation succeeds. |
107 | | /// \param Layout - The assembler layout object to use for evaluating values. |
108 | | /// \param Fixup - The Fixup object if available. |
109 | | /// \return - True on success. |
110 | | bool evaluateAsRelocatable(MCValue &Res, const MCAsmLayout *Layout, |
111 | | const MCFixup *Fixup) const; |
112 | | |
113 | | /// Try to evaluate the expression to the form (a - b + constant) where |
114 | | /// neither a nor b are variables. |
115 | | /// |
116 | | /// This is a more aggressive variant of evaluateAsRelocatable. The intended |
117 | | /// use is for when relocations are not available, like the .size directive. |
118 | | bool evaluateAsValue(MCValue &Res, const MCAsmLayout &Layout) const; |
119 | | |
120 | | /// Find the "associated section" for this expression, which is |
121 | | /// currently defined as the absolute section for constants, or |
122 | | /// otherwise the section associated with the first defined symbol in the |
123 | | /// expression. |
124 | | MCFragment *findAssociatedFragment() const; |
125 | | |
126 | | /// @} |
127 | | }; |
128 | | |
129 | 11.1k | inline raw_ostream &operator<<(raw_ostream &OS, const MCExpr &E) { |
130 | 11.1k | E.print(OS, nullptr); |
131 | 11.1k | return OS; |
132 | 11.1k | } |
133 | | |
134 | | //// Represent a constant integer expression. |
135 | | class MCConstantExpr : public MCExpr { |
136 | | int64_t Value; |
137 | | |
138 | | explicit MCConstantExpr(int64_t Value) |
139 | 3.07M | : MCExpr(MCExpr::Constant, SMLoc()), Value(Value) {} |
140 | | |
141 | | public: |
142 | | /// \name Construction |
143 | | /// @{ |
144 | | |
145 | | static const MCConstantExpr *create(int64_t Value, MCContext &Ctx); |
146 | | |
147 | | /// @} |
148 | | /// \name Accessors |
149 | | /// @{ |
150 | | |
151 | 4.82M | int64_t getValue() const { return Value; } |
152 | | |
153 | | /// @} |
154 | | |
155 | 9.86M | static bool classof(const MCExpr *E) { |
156 | 9.86M | return E->getKind() == MCExpr::Constant; |
157 | 9.86M | } |
158 | | }; |
159 | | |
160 | | /// Represent a reference to a symbol from inside an expression. |
161 | | /// |
162 | | /// A symbol reference in an expression may be a use of a label, a use of an |
163 | | /// assembler variable (defined constant), or constitute an implicit definition |
164 | | /// of the symbol as external. |
165 | | class MCSymbolRefExpr : public MCExpr { |
166 | | public: |
167 | | enum VariantKind : uint16_t { |
168 | | VK_None, |
169 | | VK_Invalid, |
170 | | |
171 | | VK_GOT, |
172 | | VK_GOTOFF, |
173 | | VK_GOTREL, |
174 | | VK_GOTPCREL, |
175 | | VK_GOTTPOFF, |
176 | | VK_INDNTPOFF, |
177 | | VK_NTPOFF, |
178 | | VK_GOTNTPOFF, |
179 | | VK_PLT, |
180 | | VK_TLSGD, |
181 | | VK_TLSLD, |
182 | | VK_TLSLDM, |
183 | | VK_TPOFF, |
184 | | VK_DTPOFF, |
185 | | VK_TLSCALL, // symbol(tlscall) |
186 | | VK_TLSDESC, // symbol(tlsdesc) |
187 | | VK_TLVP, // Mach-O thread local variable relocations |
188 | | VK_TLVPPAGE, |
189 | | VK_TLVPPAGEOFF, |
190 | | VK_PAGE, |
191 | | VK_PAGEOFF, |
192 | | VK_GOTPAGE, |
193 | | VK_GOTPAGEOFF, |
194 | | VK_SECREL, |
195 | | VK_SIZE, // symbol@SIZE |
196 | | VK_WEAKREF, // The link between the symbols in .weakref foo, bar |
197 | | |
198 | | VK_X86_ABS8, |
199 | | |
200 | | VK_ARM_NONE, |
201 | | VK_ARM_GOT_PREL, |
202 | | VK_ARM_TARGET1, |
203 | | VK_ARM_TARGET2, |
204 | | VK_ARM_PREL31, |
205 | | VK_ARM_SBREL, // symbol(sbrel) |
206 | | VK_ARM_TLSLDO, // symbol(tlsldo) |
207 | | VK_ARM_TLSDESCSEQ, |
208 | | |
209 | | VK_AVR_NONE, |
210 | | VK_AVR_LO8, |
211 | | VK_AVR_HI8, |
212 | | VK_AVR_HLO8, |
213 | | VK_AVR_DIFF8, |
214 | | VK_AVR_DIFF16, |
215 | | VK_AVR_DIFF32, |
216 | | |
217 | | VK_PPC_LO, // symbol@l |
218 | | VK_PPC_HI, // symbol@h |
219 | | VK_PPC_HA, // symbol@ha |
220 | | VK_PPC_HIGH, // symbol@high |
221 | | VK_PPC_HIGHA, // symbol@higha |
222 | | VK_PPC_HIGHER, // symbol@higher |
223 | | VK_PPC_HIGHERA, // symbol@highera |
224 | | VK_PPC_HIGHEST, // symbol@highest |
225 | | VK_PPC_HIGHESTA, // symbol@highesta |
226 | | VK_PPC_GOT_LO, // symbol@got@l |
227 | | VK_PPC_GOT_HI, // symbol@got@h |
228 | | VK_PPC_GOT_HA, // symbol@got@ha |
229 | | VK_PPC_TOCBASE, // symbol@tocbase |
230 | | VK_PPC_TOC, // symbol@toc |
231 | | VK_PPC_TOC_LO, // symbol@toc@l |
232 | | VK_PPC_TOC_HI, // symbol@toc@h |
233 | | VK_PPC_TOC_HA, // symbol@toc@ha |
234 | | VK_PPC_DTPMOD, // symbol@dtpmod |
235 | | VK_PPC_TPREL_LO, // symbol@tprel@l |
236 | | VK_PPC_TPREL_HI, // symbol@tprel@h |
237 | | VK_PPC_TPREL_HA, // symbol@tprel@ha |
238 | | VK_PPC_TPREL_HIGH, // symbol@tprel@high |
239 | | VK_PPC_TPREL_HIGHA, // symbol@tprel@higha |
240 | | VK_PPC_TPREL_HIGHER, // symbol@tprel@higher |
241 | | VK_PPC_TPREL_HIGHERA, // symbol@tprel@highera |
242 | | VK_PPC_TPREL_HIGHEST, // symbol@tprel@highest |
243 | | VK_PPC_TPREL_HIGHESTA, // symbol@tprel@highesta |
244 | | VK_PPC_DTPREL_LO, // symbol@dtprel@l |
245 | | VK_PPC_DTPREL_HI, // symbol@dtprel@h |
246 | | VK_PPC_DTPREL_HA, // symbol@dtprel@ha |
247 | | VK_PPC_DTPREL_HIGH, // symbol@dtprel@high |
248 | | VK_PPC_DTPREL_HIGHA, // symbol@dtprel@higha |
249 | | VK_PPC_DTPREL_HIGHER, // symbol@dtprel@higher |
250 | | VK_PPC_DTPREL_HIGHERA, // symbol@dtprel@highera |
251 | | VK_PPC_DTPREL_HIGHEST, // symbol@dtprel@highest |
252 | | VK_PPC_DTPREL_HIGHESTA,// symbol@dtprel@highesta |
253 | | VK_PPC_GOT_TPREL, // symbol@got@tprel |
254 | | VK_PPC_GOT_TPREL_LO, // symbol@got@tprel@l |
255 | | VK_PPC_GOT_TPREL_HI, // symbol@got@tprel@h |
256 | | VK_PPC_GOT_TPREL_HA, // symbol@got@tprel@ha |
257 | | VK_PPC_GOT_DTPREL, // symbol@got@dtprel |
258 | | VK_PPC_GOT_DTPREL_LO, // symbol@got@dtprel@l |
259 | | VK_PPC_GOT_DTPREL_HI, // symbol@got@dtprel@h |
260 | | VK_PPC_GOT_DTPREL_HA, // symbol@got@dtprel@ha |
261 | | VK_PPC_TLS, // symbol@tls |
262 | | VK_PPC_GOT_TLSGD, // symbol@got@tlsgd |
263 | | VK_PPC_GOT_TLSGD_LO, // symbol@got@tlsgd@l |
264 | | VK_PPC_GOT_TLSGD_HI, // symbol@got@tlsgd@h |
265 | | VK_PPC_GOT_TLSGD_HA, // symbol@got@tlsgd@ha |
266 | | VK_PPC_TLSGD, // symbol@tlsgd |
267 | | VK_PPC_GOT_TLSLD, // symbol@got@tlsld |
268 | | VK_PPC_GOT_TLSLD_LO, // symbol@got@tlsld@l |
269 | | VK_PPC_GOT_TLSLD_HI, // symbol@got@tlsld@h |
270 | | VK_PPC_GOT_TLSLD_HA, // symbol@got@tlsld@ha |
271 | | VK_PPC_TLSLD, // symbol@tlsld |
272 | | VK_PPC_LOCAL, // symbol@local |
273 | | |
274 | | VK_COFF_IMGREL32, // symbol@imgrel (image-relative) |
275 | | |
276 | | VK_Hexagon_PCREL, |
277 | | VK_Hexagon_LO16, |
278 | | VK_Hexagon_HI16, |
279 | | VK_Hexagon_GPREL, |
280 | | VK_Hexagon_GD_GOT, |
281 | | VK_Hexagon_LD_GOT, |
282 | | VK_Hexagon_GD_PLT, |
283 | | VK_Hexagon_LD_PLT, |
284 | | VK_Hexagon_IE, |
285 | | VK_Hexagon_IE_GOT, |
286 | | |
287 | | VK_WebAssembly_FUNCTION, // Function table index, rather than virtual addr |
288 | | VK_WebAssembly_GLOBAL, // Global object index |
289 | | VK_WebAssembly_TYPEINDEX,// Type table index |
290 | | VK_WebAssembly_EVENT, // Event index |
291 | | |
292 | | VK_AMDGPU_GOTPCREL32_LO, // symbol@gotpcrel32@lo |
293 | | VK_AMDGPU_GOTPCREL32_HI, // symbol@gotpcrel32@hi |
294 | | VK_AMDGPU_REL32_LO, // symbol@rel32@lo |
295 | | VK_AMDGPU_REL32_HI, // symbol@rel32@hi |
296 | | VK_AMDGPU_REL64, // symbol@rel64 |
297 | | |
298 | | VK_TPREL, |
299 | | VK_DTPREL |
300 | | }; |
301 | | |
302 | | private: |
303 | | /// The symbol reference modifier. |
304 | | const VariantKind Kind; |
305 | | |
306 | | /// Specifies how the variant kind should be printed. |
307 | | const unsigned UseParensForSymbolVariant : 1; |
308 | | |
309 | | // FIXME: Remove this bit. |
310 | | const unsigned HasSubsectionsViaSymbols : 1; |
311 | | |
312 | | /// The symbol being referenced. |
313 | | const MCSymbol *Symbol; |
314 | | |
315 | | explicit MCSymbolRefExpr(const MCSymbol *Symbol, VariantKind Kind, |
316 | | const MCAsmInfo *MAI, SMLoc Loc = SMLoc()); |
317 | | |
318 | | public: |
319 | | /// \name Construction |
320 | | /// @{ |
321 | | |
322 | 4.26M | static const MCSymbolRefExpr *create(const MCSymbol *Symbol, MCContext &Ctx) { |
323 | 4.26M | return MCSymbolRefExpr::create(Symbol, VK_None, Ctx); |
324 | 4.26M | } |
325 | | |
326 | | static const MCSymbolRefExpr *create(const MCSymbol *Symbol, VariantKind Kind, |
327 | | MCContext &Ctx, SMLoc Loc = SMLoc()); |
328 | | static const MCSymbolRefExpr *create(StringRef Name, VariantKind Kind, |
329 | | MCContext &Ctx); |
330 | | |
331 | | /// @} |
332 | | /// \name Accessors |
333 | | /// @{ |
334 | | |
335 | 65.5M | const MCSymbol &getSymbol() const { return *Symbol; } |
336 | | |
337 | 18.0M | VariantKind getKind() const { return Kind; } |
338 | | |
339 | | void printVariantKind(raw_ostream &OS) const; |
340 | | |
341 | 1.40M | bool hasSubsectionsViaSymbols() const { return HasSubsectionsViaSymbols; } |
342 | | |
343 | | /// @} |
344 | | /// \name Static Utility Functions |
345 | | /// @{ |
346 | | |
347 | | static StringRef getVariantKindName(VariantKind Kind); |
348 | | |
349 | | static VariantKind getVariantKindForName(StringRef Name); |
350 | | |
351 | | /// @} |
352 | | |
353 | 1.68M | static bool classof(const MCExpr *E) { |
354 | 1.68M | return E->getKind() == MCExpr::SymbolRef; |
355 | 1.68M | } |
356 | | }; |
357 | | |
358 | | /// Unary assembler expressions. |
359 | | class MCUnaryExpr : public MCExpr { |
360 | | public: |
361 | | enum Opcode { |
362 | | LNot, ///< Logical negation. |
363 | | Minus, ///< Unary minus. |
364 | | Not, ///< Bitwise negation. |
365 | | Plus ///< Unary plus. |
366 | | }; |
367 | | |
368 | | private: |
369 | | Opcode Op; |
370 | | const MCExpr *Expr; |
371 | | |
372 | | MCUnaryExpr(Opcode Op, const MCExpr *Expr, SMLoc Loc) |
373 | 22.0k | : MCExpr(MCExpr::Unary, Loc), Op(Op), Expr(Expr) {} |
374 | | |
375 | | public: |
376 | | /// \name Construction |
377 | | /// @{ |
378 | | |
379 | | static const MCUnaryExpr *create(Opcode Op, const MCExpr *Expr, |
380 | | MCContext &Ctx, SMLoc Loc = SMLoc()); |
381 | | |
382 | 4 | static const MCUnaryExpr *createLNot(const MCExpr *Expr, MCContext &Ctx, SMLoc Loc = SMLoc()) { |
383 | 4 | return create(LNot, Expr, Ctx, Loc); |
384 | 4 | } |
385 | | |
386 | 21.8k | static const MCUnaryExpr *createMinus(const MCExpr *Expr, MCContext &Ctx, SMLoc Loc = SMLoc()) { |
387 | 21.8k | return create(Minus, Expr, Ctx, Loc); |
388 | 21.8k | } |
389 | | |
390 | 148 | static const MCUnaryExpr *createNot(const MCExpr *Expr, MCContext &Ctx, SMLoc Loc = SMLoc()) { |
391 | 148 | return create(Not, Expr, Ctx, Loc); |
392 | 148 | } |
393 | | |
394 | 21 | static const MCUnaryExpr *createPlus(const MCExpr *Expr, MCContext &Ctx, SMLoc Loc = SMLoc()) { |
395 | 21 | return create(Plus, Expr, Ctx, Loc); |
396 | 21 | } |
397 | | |
398 | | /// @} |
399 | | /// \name Accessors |
400 | | /// @{ |
401 | | |
402 | | /// Get the kind of this unary expression. |
403 | 22.0k | Opcode getOpcode() const { return Op; } |
404 | | |
405 | | /// Get the child of this unary expression. |
406 | 22.1k | const MCExpr *getSubExpr() const { return Expr; } |
407 | | |
408 | | /// @} |
409 | | |
410 | 14 | static bool classof(const MCExpr *E) { |
411 | 14 | return E->getKind() == MCExpr::Unary; |
412 | 14 | } |
413 | | }; |
414 | | |
415 | | /// Binary assembler expressions. |
416 | | class MCBinaryExpr : public MCExpr { |
417 | | public: |
418 | | enum Opcode { |
419 | | Add, ///< Addition. |
420 | | And, ///< Bitwise and. |
421 | | Div, ///< Signed division. |
422 | | EQ, ///< Equality comparison. |
423 | | GT, ///< Signed greater than comparison (result is either 0 or some |
424 | | ///< target-specific non-zero value) |
425 | | GTE, ///< Signed greater than or equal comparison (result is either 0 or |
426 | | ///< some target-specific non-zero value). |
427 | | LAnd, ///< Logical and. |
428 | | LOr, ///< Logical or. |
429 | | LT, ///< Signed less than comparison (result is either 0 or |
430 | | ///< some target-specific non-zero value). |
431 | | LTE, ///< Signed less than or equal comparison (result is either 0 or |
432 | | ///< some target-specific non-zero value). |
433 | | Mod, ///< Signed remainder. |
434 | | Mul, ///< Multiplication. |
435 | | NE, ///< Inequality comparison. |
436 | | Or, ///< Bitwise or. |
437 | | Shl, ///< Shift left. |
438 | | AShr, ///< Arithmetic shift right. |
439 | | LShr, ///< Logical shift right. |
440 | | Sub, ///< Subtraction. |
441 | | Xor ///< Bitwise exclusive or. |
442 | | }; |
443 | | |
444 | | private: |
445 | | Opcode Op; |
446 | | const MCExpr *LHS, *RHS; |
447 | | |
448 | | MCBinaryExpr(Opcode Op, const MCExpr *LHS, const MCExpr *RHS, |
449 | | SMLoc Loc = SMLoc()) |
450 | 2.78M | : MCExpr(MCExpr::Binary, Loc), Op(Op), LHS(LHS), RHS(RHS) {} |
451 | | |
452 | | public: |
453 | | /// \name Construction |
454 | | /// @{ |
455 | | |
456 | | static const MCBinaryExpr *create(Opcode Op, const MCExpr *LHS, |
457 | | const MCExpr *RHS, MCContext &Ctx, |
458 | | SMLoc Loc = SMLoc()); |
459 | | |
460 | | static const MCBinaryExpr *createAdd(const MCExpr *LHS, const MCExpr *RHS, |
461 | 547k | MCContext &Ctx) { |
462 | 547k | return create(Add, LHS, RHS, Ctx); |
463 | 547k | } |
464 | | |
465 | | static const MCBinaryExpr *createAnd(const MCExpr *LHS, const MCExpr *RHS, |
466 | 12 | MCContext &Ctx) { |
467 | 12 | return create(And, LHS, RHS, Ctx); |
468 | 12 | } |
469 | | |
470 | | static const MCBinaryExpr *createDiv(const MCExpr *LHS, const MCExpr *RHS, |
471 | 4.64k | MCContext &Ctx) { |
472 | 4.64k | return create(Div, LHS, RHS, Ctx); |
473 | 4.64k | } |
474 | | |
475 | | static const MCBinaryExpr *createEQ(const MCExpr *LHS, const MCExpr *RHS, |
476 | | MCContext &Ctx) { |
477 | | return create(EQ, LHS, RHS, Ctx); |
478 | | } |
479 | | |
480 | | static const MCBinaryExpr *createGT(const MCExpr *LHS, const MCExpr *RHS, |
481 | | MCContext &Ctx) { |
482 | | return create(GT, LHS, RHS, Ctx); |
483 | | } |
484 | | |
485 | | static const MCBinaryExpr *createGTE(const MCExpr *LHS, const MCExpr *RHS, |
486 | | MCContext &Ctx) { |
487 | | return create(GTE, LHS, RHS, Ctx); |
488 | | } |
489 | | |
490 | | static const MCBinaryExpr *createLAnd(const MCExpr *LHS, const MCExpr *RHS, |
491 | | MCContext &Ctx) { |
492 | | return create(LAnd, LHS, RHS, Ctx); |
493 | | } |
494 | | |
495 | | static const MCBinaryExpr *createLOr(const MCExpr *LHS, const MCExpr *RHS, |
496 | | MCContext &Ctx) { |
497 | | return create(LOr, LHS, RHS, Ctx); |
498 | | } |
499 | | |
500 | | static const MCBinaryExpr *createLT(const MCExpr *LHS, const MCExpr *RHS, |
501 | | MCContext &Ctx) { |
502 | | return create(LT, LHS, RHS, Ctx); |
503 | | } |
504 | | |
505 | | static const MCBinaryExpr *createLTE(const MCExpr *LHS, const MCExpr *RHS, |
506 | | MCContext &Ctx) { |
507 | | return create(LTE, LHS, RHS, Ctx); |
508 | | } |
509 | | |
510 | | static const MCBinaryExpr *createMod(const MCExpr *LHS, const MCExpr *RHS, |
511 | 0 | MCContext &Ctx) { |
512 | 0 | return create(Mod, LHS, RHS, Ctx); |
513 | 0 | } |
514 | | |
515 | | static const MCBinaryExpr *createMul(const MCExpr *LHS, const MCExpr *RHS, |
516 | 1 | MCContext &Ctx) { |
517 | 1 | return create(Mul, LHS, RHS, Ctx); |
518 | 1 | } |
519 | | |
520 | | static const MCBinaryExpr *createNE(const MCExpr *LHS, const MCExpr *RHS, |
521 | | MCContext &Ctx) { |
522 | | return create(NE, LHS, RHS, Ctx); |
523 | | } |
524 | | |
525 | | static const MCBinaryExpr *createOr(const MCExpr *LHS, const MCExpr *RHS, |
526 | 0 | MCContext &Ctx) { |
527 | 0 | return create(Or, LHS, RHS, Ctx); |
528 | 0 | } |
529 | | |
530 | | static const MCBinaryExpr *createShl(const MCExpr *LHS, const MCExpr *RHS, |
531 | 0 | MCContext &Ctx) { |
532 | 0 | return create(Shl, LHS, RHS, Ctx); |
533 | 0 | } |
534 | | |
535 | | static const MCBinaryExpr *createAShr(const MCExpr *LHS, const MCExpr *RHS, |
536 | | MCContext &Ctx) { |
537 | | return create(AShr, LHS, RHS, Ctx); |
538 | | } |
539 | | |
540 | | static const MCBinaryExpr *createLShr(const MCExpr *LHS, const MCExpr *RHS, |
541 | 13.3k | MCContext &Ctx) { |
542 | 13.3k | return create(LShr, LHS, RHS, Ctx); |
543 | 13.3k | } |
544 | | |
545 | | static const MCBinaryExpr *createSub(const MCExpr *LHS, const MCExpr *RHS, |
546 | 690k | MCContext &Ctx) { |
547 | 690k | return create(Sub, LHS, RHS, Ctx); |
548 | 690k | } |
549 | | |
550 | | static const MCBinaryExpr *createXor(const MCExpr *LHS, const MCExpr *RHS, |
551 | 0 | MCContext &Ctx) { |
552 | 0 | return create(Xor, LHS, RHS, Ctx); |
553 | 0 | } |
554 | | |
555 | | /// @} |
556 | | /// \name Accessors |
557 | | /// @{ |
558 | | |
559 | | /// Get the kind of this binary expression. |
560 | 9.00M | Opcode getOpcode() const { return Op; } |
561 | | |
562 | | /// Get the left-hand side expression of the binary operator. |
563 | 10.5M | const MCExpr *getLHS() const { return LHS; } |
564 | | |
565 | | /// Get the right-hand side expression of the binary operator. |
566 | 10.5M | const MCExpr *getRHS() const { return RHS; } |
567 | | |
568 | | /// @} |
569 | | |
570 | 13.3k | static bool classof(const MCExpr *E) { |
571 | 13.3k | return E->getKind() == MCExpr::Binary; |
572 | 13.3k | } |
573 | | }; |
574 | | |
575 | | /// This is an extension point for target-specific MCExpr subclasses to |
576 | | /// implement. |
577 | | /// |
578 | | /// NOTE: All subclasses are required to have trivial destructors because |
579 | | /// MCExprs are bump pointer allocated and not destructed. |
580 | | class MCTargetExpr : public MCExpr { |
581 | | virtual void anchor(); |
582 | | |
583 | | protected: |
584 | 431k | MCTargetExpr() : MCExpr(Target, SMLoc()) {} |
585 | 0 | virtual ~MCTargetExpr() = default; |
586 | | |
587 | | public: |
588 | | virtual void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const = 0; |
589 | | virtual bool evaluateAsRelocatableImpl(MCValue &Res, |
590 | | const MCAsmLayout *Layout, |
591 | | const MCFixup *Fixup) const = 0; |
592 | | // allow Target Expressions to be checked for equality |
593 | 0 | virtual bool isEqualTo(const MCExpr *x) const { return false; } |
594 | | // This should be set when assigned expressions are not valid ".set" |
595 | | // expressions, e.g. registers, and must be inlined. |
596 | 0 | virtual bool inlineAssignedExpr() const { return false; } |
597 | | virtual void visitUsedExpr(MCStreamer& Streamer) const = 0; |
598 | | virtual MCFragment *findAssociatedFragment() const = 0; |
599 | | |
600 | | virtual void fixELFSymbolsInTLSFixups(MCAssembler &) const = 0; |
601 | | |
602 | 6.22k | static bool classof(const MCExpr *E) { |
603 | 6.22k | return E->getKind() == MCExpr::Target; |
604 | 6.22k | } |
605 | | }; |
606 | | |
607 | | } // end namespace llvm |
608 | | |
609 | | #endif // LLVM_MC_MCEXPR_H |