LLVM 20.0.0git
AMDGPUMCExpr.h
Go to the documentation of this file.
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
15namespace llvm {
16
17class Function;
18class 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///
30class AMDGPUMCExpr : public MCTargetExpr {
31public:
40 };
41
42private:
43 VariantKind Kind;
44 MCContext &Ctx;
45 const MCExpr **RawArgs;
47
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
60public:
61 static const AMDGPUMCExpr *
63
65 MCContext &Ctx) {
66 return create(VariantKind::AGVK_Or, Args, Ctx);
67 }
68
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 *
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
93 ArrayRef<const MCExpr *> getArgs() const { return Args; }
94 VariantKind getKind() const { return Kind; }
95 const MCExpr *getSubExpr(size_t Index) const;
96
97 void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override;
98 bool evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm,
99 const MCFixup *Fixup) const override;
100 void visitUsedExpr(MCStreamer &Streamer) const override;
101 MCFragment *findAssociatedFragment() const override;
102 void fixELFSymbolsInTLSFixups(MCAssembler &) const override{};
103
104 static bool classof(const MCExpr *E) {
105 return E->getKind() == MCExpr::Target;
106 }
107};
108
109namespace AMDGPU {
110// Tries to leverage KnownBits for MCExprs to reduce and limit any composed
111// MCExprs printing. E.g., for an expression such as
112// ((unevaluatable_sym | 1) & 1) won't evaluate due to unevaluatable_sym and
113// would verbosely print the full expression; however, KnownBits should deduce
114// the value to be 1. Particularly useful for AMDGPU metadata MCExprs.
115void printAMDGPUMCExpr(const MCExpr *Expr, raw_ostream &OS,
116 const MCAsmInfo *MAI);
117
118const MCExpr *foldAMDGPUMCExpr(const MCExpr *Expr, MCContext &Ctx);
119
120} // end namespace AMDGPU
121} // end namespace llvm
122
123#endif // LLVM_LIB_TARGET_AMDGPU_MCTARGETDESC_AMDGPUMCEXPR_H
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
PowerPC TLS Dynamic Call Fixup
raw_pwrite_stream & OS
AMDGPU target specific MCExpr operations.
Definition: AMDGPUMCExpr.h:30
ArrayRef< const MCExpr * > getArgs() const
Definition: AMDGPUMCExpr.h:93
MCFragment * findAssociatedFragment() const override
static const AMDGPUMCExpr * createMax(ArrayRef< const MCExpr * > Args, MCContext &Ctx)
Definition: AMDGPUMCExpr.h:69
void visitUsedExpr(MCStreamer &Streamer) const override
static const AMDGPUMCExpr * createOccupancy(unsigned InitOcc, const MCExpr *NumSGPRs, const MCExpr *NumVGPRs, const GCNSubtarget &STM, MCContext &Ctx)
Mimics GCNSubtarget::computeOccupancy for MCExpr.
void fixELFSymbolsInTLSFixups(MCAssembler &) const override
Definition: AMDGPUMCExpr.h:102
static const AMDGPUMCExpr * createTotalNumVGPR(const MCExpr *NumAGPR, const MCExpr *NumVGPR, MCContext &Ctx)
static const AMDGPUMCExpr * create(VariantKind Kind, ArrayRef< const MCExpr * > Args, MCContext &Ctx)
static const AMDGPUMCExpr * createExtraSGPRs(const MCExpr *VCCUsed, const MCExpr *FlatScrUsed, bool XNACKUsed, MCContext &Ctx)
Allow delayed MCExpr resolve of ExtraSGPRs (in case VCCUsed or FlatScrUsed are unresolvable but neede...
static const AMDGPUMCExpr * createAlignTo(const MCExpr *Value, const MCExpr *Align, MCContext &Ctx)
Definition: AMDGPUMCExpr.h:83
static const AMDGPUMCExpr * createOr(ArrayRef< const MCExpr * > Args, MCContext &Ctx)
Definition: AMDGPUMCExpr.h:64
const MCExpr * getSubExpr(size_t Index) const
bool evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm, const MCFixup *Fixup) const override
void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override
static bool classof(const MCExpr *E)
Definition: AMDGPUMCExpr.h:104
VariantKind getKind() const
Definition: AMDGPUMCExpr.h:94
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition: MCAsmInfo.h:56
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
@ Target
Target specific expression.
Definition: MCExpr.h:41
Encode information on a single operation to perform on a byte sequence (e.g., an encoded instruction)...
Definition: MCFixup.h:71
Streaming machine code generation interface.
Definition: MCStreamer.h:213
This is an extension point for target-specific MCExpr subclasses to implement.
Definition: MCExpr.h:652
This represents an "assembler immediate".
Definition: MCValue.h:36
LLVM Value Representation.
Definition: Value.h:74
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
void printAMDGPUMCExpr(const MCExpr *Expr, raw_ostream &OS, const MCAsmInfo *MAI)
const MCExpr * foldAMDGPUMCExpr(const MCExpr *Expr, MCContext &Ctx)
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39