1 | //===- AMDGPUMCExpr.h - AMDGPU specific MC expression classes ---*- 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_LIB_TARGET_AMDGPU_MCTARGETDESC_AMDGPUMCEXPR_H |
10 | #define LLVM_LIB_TARGET_AMDGPU_MCTARGETDESC_AMDGPUMCEXPR_H |
11 | |
12 | #include "llvm/ADT/ArrayRef.h" |
13 | #include "llvm/MC/MCExpr.h" |
14 | |
15 | namespace llvm { |
16 | |
17 | /// AMDGPU target specific variadic MCExpr operations. |
18 | /// |
19 | /// Takes in a minimum of 1 argument to be used with an operation. The supported |
20 | /// operations are: |
21 | /// - (bitwise) or |
22 | /// - max |
23 | /// |
24 | /// \note If the 'or'/'max' operations are provided only a single argument, the |
25 | /// operation will act as a no-op and simply resolve as the provided argument. |
26 | /// |
27 | class AMDGPUVariadicMCExpr : public MCTargetExpr { |
28 | public: |
29 | enum VariadicKind { AGVK_None, AGVK_Or, AGVK_Max }; |
30 | |
31 | private: |
32 | VariadicKind Kind; |
33 | MCContext &Ctx; |
34 | const MCExpr **RawArgs; |
35 | ArrayRef<const MCExpr *> Args; |
36 | |
37 | AMDGPUVariadicMCExpr(VariadicKind Kind, ArrayRef<const MCExpr *> Args, |
38 | MCContext &Ctx); |
39 | ~AMDGPUVariadicMCExpr(); |
40 | |
41 | public: |
42 | static const AMDGPUVariadicMCExpr * |
43 | create(VariadicKind Kind, ArrayRef<const MCExpr *> Args, MCContext &Ctx); |
44 | |
45 | static const AMDGPUVariadicMCExpr *createOr(ArrayRef<const MCExpr *> Args, |
46 | MCContext &Ctx) { |
47 | return create(Kind: VariadicKind::AGVK_Or, Args, Ctx); |
48 | } |
49 | |
50 | static const AMDGPUVariadicMCExpr *createMax(ArrayRef<const MCExpr *> Args, |
51 | MCContext &Ctx) { |
52 | return create(Kind: VariadicKind::AGVK_Max, Args, Ctx); |
53 | } |
54 | |
55 | VariadicKind getKind() const { return Kind; } |
56 | const MCExpr *getSubExpr(size_t Index) const; |
57 | |
58 | void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override; |
59 | bool evaluateAsRelocatableImpl(MCValue &Res, const MCAsmLayout *Layout, |
60 | const MCFixup *Fixup) const override; |
61 | void visitUsedExpr(MCStreamer &Streamer) const override; |
62 | MCFragment *findAssociatedFragment() const override; |
63 | void fixELFSymbolsInTLSFixups(MCAssembler &) const override{}; |
64 | |
65 | static bool classof(const MCExpr *E) { |
66 | return E->getKind() == MCExpr::Target; |
67 | } |
68 | }; |
69 | |
70 | } // end namespace llvm |
71 | |
72 | #endif // LLVM_LIB_TARGET_AMDGPU_MCTARGETDESC_AMDGPUMCEXPR_H |
73 | |