LLVM 22.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
42 // Relocation specifiers.
43 enum Specifier {
45 S_GOTPCREL, // symbol@gotpcrel
46 S_GOTPCREL32_LO, // symbol@gotpcrel32@lo
47 S_GOTPCREL32_HI, // symbol@gotpcrel32@hi
48 S_REL32_LO, // symbol@rel32@lo
49 S_REL32_HI, // symbol@rel32@hi
50 S_REL64, // symbol@rel64
51 S_ABS32_LO, // symbol@abs32@lo
52 S_ABS32_HI, // symbol@abs32@hi
53 S_ABS64, // symbol@abs64
54 };
55
56private:
57 VariantKind Kind;
58 MCContext &Ctx;
59 const MCExpr **RawArgs;
61
64
65 bool evaluateExtraSGPRs(MCValue &Res, const MCAssembler *Asm) const;
66 bool evaluateTotalNumVGPR(MCValue &Res, const MCAssembler *Asm) const;
67 bool evaluateAlignTo(MCValue &Res, const MCAssembler *Asm) const;
68 bool evaluateOccupancy(MCValue &Res, const MCAssembler *Asm) const;
69
70public:
71 static const AMDGPUMCExpr *
73
75 MCContext &Ctx) {
76 return create(VariantKind::AGVK_Or, Args, Ctx);
77 }
78
80 MCContext &Ctx) {
81 return create(VariantKind::AGVK_Max, Args, Ctx);
82 }
83
84 static const AMDGPUMCExpr *createExtraSGPRs(const MCExpr *VCCUsed,
85 const MCExpr *FlatScrUsed,
86 bool XNACKUsed, MCContext &Ctx);
87
88 static const AMDGPUMCExpr *createTotalNumVGPR(const MCExpr *NumAGPR,
89 const MCExpr *NumVGPR,
90 MCContext &Ctx);
91
92 static const AMDGPUMCExpr *
95 }
96
97 static const AMDGPUMCExpr *
98 createOccupancy(unsigned InitOcc, const MCExpr *NumSGPRs,
99 const MCExpr *NumVGPRs, unsigned DynamicVGPRBlockSize,
100 const GCNSubtarget &STM, MCContext &Ctx);
101
102 ArrayRef<const MCExpr *> getArgs() const { return Args; }
103 VariantKind getKind() const { return Kind; }
104 const MCExpr *getSubExpr(size_t Index) const;
105
106 void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override;
108 const MCAssembler *Asm) const override;
109 void visitUsedExpr(MCStreamer &Streamer) const override;
110 MCFragment *findAssociatedFragment() const override;
111
112 static bool classof(const MCExpr *E) {
113 return E->getKind() == MCExpr::Target;
114 }
115 static bool isSymbolUsedInExpression(const MCSymbol *Sym, const MCExpr *E);
116};
117
118namespace AMDGPU {
119// Tries to leverage KnownBits for MCExprs to reduce and limit any composed
120// MCExprs printing. E.g., for an expression such as
121// ((unevaluatable_sym | 1) & 1) won't evaluate due to unevaluatable_sym and
122// would verbosely print the full expression; however, KnownBits should deduce
123// the value to be 1. Particularly useful for AMDGPU metadata MCExprs.
124void printAMDGPUMCExpr(const MCExpr *Expr, raw_ostream &OS,
125 const MCAsmInfo *MAI);
126
127const MCExpr *foldAMDGPUMCExpr(const MCExpr *Expr, MCContext &Ctx);
128
130 return AMDGPUMCExpr::Specifier(SRE->getKind());
131}
132} // end namespace AMDGPU
133} // end namespace llvm
134
135#endif // LLVM_LIB_TARGET_AMDGPU_MCTARGETDESC_AMDGPUMCEXPR_H
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
uint32_t Index
Symbol * Sym
Definition: ELF_riscv.cpp:479
raw_pwrite_stream & OS
AMDGPU target specific MCExpr operations.
Definition: AMDGPUMCExpr.h:30
ArrayRef< const MCExpr * > getArgs() const
Definition: AMDGPUMCExpr.h:102
MCFragment * findAssociatedFragment() const override
static const AMDGPUMCExpr * createMax(ArrayRef< const MCExpr * > Args, MCContext &Ctx)
Definition: AMDGPUMCExpr.h:79
void visitUsedExpr(MCStreamer &Streamer) const override
static const AMDGPUMCExpr * createOccupancy(unsigned InitOcc, const MCExpr *NumSGPRs, const MCExpr *NumVGPRs, unsigned DynamicVGPRBlockSize, const GCNSubtarget &STM, MCContext &Ctx)
Mimics GCNSubtarget::computeOccupancy for MCExpr.
static const AMDGPUMCExpr * createTotalNumVGPR(const MCExpr *NumAGPR, const MCExpr *NumVGPR, MCContext &Ctx)
static const AMDGPUMCExpr * create(VariantKind Kind, ArrayRef< const MCExpr * > Args, MCContext &Ctx)
bool evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm) const override
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:93
static const AMDGPUMCExpr * createOr(ArrayRef< const MCExpr * > Args, MCContext &Ctx)
Definition: AMDGPUMCExpr.h:74
const MCExpr * getSubExpr(size_t Index) const
void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override
static bool classof(const MCExpr *E)
Definition: AMDGPUMCExpr.h:112
VariantKind getKind() const
Definition: AMDGPUMCExpr.h:103
static bool isSymbolUsedInExpression(const MCSymbol *Sym, const MCExpr *E)
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:64
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:46
Streaming machine code generation interface.
Definition: MCStreamer.h:220
Represent a reference to a symbol from inside an expression.
Definition: MCExpr.h:190
VariantKind getKind() const
Definition: MCExpr.h:232
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:42
Extension point for target-specific MCExpr subclasses to implement.
Definition: MCExpr.h:465
LLVM Value Representation.
Definition: Value.h:75
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
static AMDGPUMCExpr::Specifier getSpecifier(const MCSymbolRefExpr *SRE)
Definition: AMDGPUMCExpr.h:129
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