xref: /freebsd/contrib/llvm-project/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCExpr.h (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
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 class Function;
18 class GCNSubtarget;
19 
20 /// AMDGPU target specific MCExpr operations.
21 ///
22 /// Takes in a minimum of 1 argument to be used with an operation. The supported
23 /// operations are:
24 ///   - (bitwise) or
25 ///   - max
26 ///
27 /// \note If the 'or'/'max' operations are provided only a single argument, the
28 /// operation will act as a no-op and simply resolve as the provided argument.
29 ///
30 class AMDGPUMCExpr : public MCTargetExpr {
31 public:
32   enum VariantKind {
33     AGVK_None,
34     AGVK_Or,
35     AGVK_Max,
36     AGVK_ExtraSGPRs,
37     AGVK_TotalNumVGPRs,
38     AGVK_AlignTo,
39     AGVK_Occupancy
40   };
41 
42 private:
43   VariantKind Kind;
44   MCContext &Ctx;
45   const MCExpr **RawArgs;
46   ArrayRef<const MCExpr *> Args;
47 
48   AMDGPUMCExpr(VariantKind Kind, ArrayRef<const MCExpr *> Args, MCContext &Ctx);
49   ~AMDGPUMCExpr();
50 
51   bool evaluateExtraSGPRs(MCValue &Res, const MCAssembler *Asm,
52                           const MCFixup *Fixup) const;
53   bool evaluateTotalNumVGPR(MCValue &Res, const MCAssembler *Asm,
54                             const MCFixup *Fixup) const;
55   bool evaluateAlignTo(MCValue &Res, const MCAssembler *Asm,
56                        const MCFixup *Fixup) const;
57   bool evaluateOccupancy(MCValue &Res, const MCAssembler *Asm,
58                          const MCFixup *Fixup) const;
59 
60 public:
61   static const AMDGPUMCExpr *
62   create(VariantKind Kind, ArrayRef<const MCExpr *> Args, MCContext &Ctx);
63 
createOr(ArrayRef<const MCExpr * > Args,MCContext & Ctx)64   static const AMDGPUMCExpr *createOr(ArrayRef<const MCExpr *> Args,
65                                       MCContext &Ctx) {
66     return create(VariantKind::AGVK_Or, Args, Ctx);
67   }
68 
createMax(ArrayRef<const MCExpr * > Args,MCContext & Ctx)69   static const AMDGPUMCExpr *createMax(ArrayRef<const MCExpr *> Args,
70                                        MCContext &Ctx) {
71     return create(VariantKind::AGVK_Max, Args, Ctx);
72   }
73 
74   static const AMDGPUMCExpr *createExtraSGPRs(const MCExpr *VCCUsed,
75                                               const MCExpr *FlatScrUsed,
76                                               bool XNACKUsed, MCContext &Ctx);
77 
78   static const AMDGPUMCExpr *createTotalNumVGPR(const MCExpr *NumAGPR,
79                                                 const MCExpr *NumVGPR,
80                                                 MCContext &Ctx);
81 
82   static const AMDGPUMCExpr *
createAlignTo(const MCExpr * Value,const MCExpr * Align,MCContext & Ctx)83   createAlignTo(const MCExpr *Value, const MCExpr *Align, MCContext &Ctx) {
84     return create(VariantKind::AGVK_AlignTo, {Value, Align}, Ctx);
85   }
86 
87   static const AMDGPUMCExpr *createOccupancy(unsigned InitOcc,
88                                              const MCExpr *NumSGPRs,
89                                              const MCExpr *NumVGPRs,
90                                              const GCNSubtarget &STM,
91                                              MCContext &Ctx);
92 
getKind()93   VariantKind getKind() const { return Kind; }
94   const MCExpr *getSubExpr(size_t Index) const;
95 
96   void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override;
97   bool evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm,
98                                  const MCFixup *Fixup) const override;
99   void visitUsedExpr(MCStreamer &Streamer) const override;
100   MCFragment *findAssociatedFragment() const override;
fixELFSymbolsInTLSFixups(MCAssembler &)101   void fixELFSymbolsInTLSFixups(MCAssembler &) const override{};
102 
classof(const MCExpr * E)103   static bool classof(const MCExpr *E) {
104     return E->getKind() == MCExpr::Target;
105   }
106 };
107 
108 } // end namespace llvm
109 
110 #endif // LLVM_LIB_TARGET_AMDGPU_MCTARGETDESC_AMDGPUMCEXPR_H
111