LLVM 24.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
17enum class LitModifier { None, Lit, Lit64 };
18
19/// AMDGPU target specific MCExpr operations.
20///
21/// Takes in a minimum of 1 argument to be used with an operation. The supported
22/// operations are:
23/// - (bitwise) or
24/// - max
25/// - min
26///
27/// \note If the 'or'/'max'/'min' operations are provided only a single
28/// argument, the operation will act as a no-op and simply resolve as the
29/// provided argument.
30///
31class AMDGPUMCExpr : public MCTargetExpr {
32public:
46
47 // Relocation specifiers.
50 S_GOTPCREL, // symbol@gotpcrel
51 S_GOTPCREL32_LO, // symbol@gotpcrel32@lo
52 S_GOTPCREL32_HI, // symbol@gotpcrel32@hi
53 S_REL32_LO, // symbol@rel32@lo
54 S_REL32_HI, // symbol@rel32@hi
55 S_REL64, // symbol@rel64
56 S_ABS32_LO, // symbol@abs32@lo
57 S_ABS32_HI, // symbol@abs32@hi
58 S_ABS64, // symbol@abs64
59 };
60
61private:
62 VariantKind Kind;
63 MCContext &Ctx;
64 const MCExpr **RawArgs;
66
67 AMDGPUMCExpr(VariantKind Kind, ArrayRef<const MCExpr *> Args, MCContext &Ctx);
68 ~AMDGPUMCExpr() override;
69
70 bool evaluateExtraSGPRs(MCValue &Res, const MCAssembler *Asm) const;
71 bool evaluateTotalNumVGPR(MCValue &Res, const MCAssembler *Asm) const;
72 bool evaluateAlignTo(MCValue &Res, const MCAssembler *Asm) const;
73 bool evaluateOccupancy(MCValue &Res, const MCAssembler *Asm) const;
74 bool evaluateInstPrefSize(MCValue &Res, const MCAssembler *Asm) const;
75
76public:
77 static const AMDGPUMCExpr *
78 create(VariantKind Kind, ArrayRef<const MCExpr *> Args, MCContext &Ctx);
79
80 /// \returns the required operand count for \p Kind, or 0 for the variadic
81 /// kinds (or/max/min). Used at parse time and by the create() assert.
82 static unsigned getNumExpectedArgs(VariantKind Kind);
83
84 static const AMDGPUMCExpr *createOr(ArrayRef<const MCExpr *> Args,
85 MCContext &Ctx) {
86 return create(VariantKind::AGVK_Or, Args, Ctx);
87 }
88
89 static const AMDGPUMCExpr *createMax(ArrayRef<const MCExpr *> Args,
90 MCContext &Ctx) {
91 return create(VariantKind::AGVK_Max, Args, Ctx);
92 }
93 static const AMDGPUMCExpr *createMin(ArrayRef<const MCExpr *> Args,
94 MCContext &Ctx) {
95 return create(VariantKind::AGVK_Min, Args, Ctx);
96 }
97
98 static const AMDGPUMCExpr *createExtraSGPRs(const MCExpr *VCCUsed,
99 const MCExpr *FlatScrUsed,
100 bool XNACKUsed, MCContext &Ctx);
101
102 static const AMDGPUMCExpr *createTotalNumVGPR(const MCExpr *NumAGPR,
103 const MCExpr *NumVGPR,
104 MCContext &Ctx);
105
106 static const AMDGPUMCExpr *
109 }
110
111 /// Create an expression for instruction prefetch size computation:
112 /// min(divideCeil(CodeSizeBytes, CacheLineSize), (1 << FieldWidth) - 1)
113 /// FieldWidth and CacheLineSize are derived from the subtarget.
114 static const AMDGPUMCExpr *createInstPrefSize(const MCExpr *CodeSizeBytes,
115 MCContext &Ctx);
116
117 static const AMDGPUMCExpr *createLit(LitModifier Lit, int64_t Value,
118 MCContext &Ctx);
119
120 ArrayRef<const MCExpr *> getArgs() const { return Args; }
121 VariantKind getKind() const { return Kind; }
122 MCContext &getCtx() const { return Ctx; }
123 const MCExpr *getSubExpr(size_t Index) const;
124
125 void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override;
127 const MCAssembler *Asm) const override;
128 void visitUsedExpr(MCStreamer &Streamer) const override;
129 MCFragment *findAssociatedFragment() const override;
130
131 static bool classof(const MCExpr *E) {
132 return E->getKind() == MCExpr::Target;
133 }
134 static bool isSymbolUsedInExpression(const MCSymbol *Sym, const MCExpr *E);
135};
136
137namespace AMDGPU {
138// Tries to leverage KnownBits for MCExprs to reduce and limit any composed
139// MCExprs printing. E.g., for an expression such as
140// ((unevaluatable_sym | 1) & 1) won't evaluate due to unevaluatable_sym and
141// would verbosely print the full expression; however, KnownBits should deduce
142// the value to be 1. Particularly useful for AMDGPU metadata MCExprs.
143void printAMDGPUMCExpr(const MCExpr *Expr, raw_ostream &OS,
144 const MCAsmInfo *MAI);
145
146const MCExpr *foldAMDGPUMCExpr(const MCExpr *Expr, MCContext &Ctx);
147
149 return AMDGPUMCExpr::Specifier(SRE->getKind());
150}
151
152LLVM_READONLY bool isLitExpr(const MCExpr *Expr);
153
154LLVM_READONLY int64_t getLitValue(const MCExpr *Expr);
155
157
158} // end namespace AMDGPU
159} // end namespace llvm
160
161#endif // LLVM_LIB_TARGET_AMDGPU_MCTARGETDESC_AMDGPUMCEXPR_H
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
#define LLVM_READONLY
Definition Compiler.h:334
std::unique_ptr< MCStreamer > && Streamer
AMDGPU target specific MCExpr operations.
ArrayRef< const MCExpr * > getArgs() const
static const AMDGPUMCExpr * createMin(ArrayRef< const MCExpr * > Args, MCContext &Ctx)
MCFragment * findAssociatedFragment() const override
static const AMDGPUMCExpr * createInstPrefSize(const MCExpr *CodeSizeBytes, MCContext &Ctx)
Create an expression for instruction prefetch size computation: min(divideCeil(CodeSizeBytes,...
static const AMDGPUMCExpr * createMax(ArrayRef< const MCExpr * > Args, MCContext &Ctx)
void visitUsedExpr(MCStreamer &Streamer) const override
static unsigned getNumExpectedArgs(VariantKind Kind)
static const AMDGPUMCExpr * createTotalNumVGPR(const MCExpr *NumAGPR, const MCExpr *NumVGPR, MCContext &Ctx)
static const AMDGPUMCExpr * createLit(LitModifier Lit, int64_t Value, MCContext &Ctx)
static const AMDGPUMCExpr * create(VariantKind Kind, ArrayRef< const MCExpr * > Args, MCContext &Ctx)
bool evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm) const override
MCContext & getCtx() const
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)
static const AMDGPUMCExpr * createOr(ArrayRef< const MCExpr * > Args, MCContext &Ctx)
const MCExpr * getSubExpr(size_t Index) const
void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override
static bool classof(const MCExpr *E)
VariantKind getKind() const
static bool isSymbolUsedInExpression(const MCSymbol *Sym, const MCExpr *E)
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition MCAsmInfo.h:69
Context object for machine code objects.
Definition MCContext.h:84
Base class for the full range of assembler expressions which are needed for parsing.
Definition MCExpr.h:31
@ Target
Target specific expression.
Definition MCExpr.h:43
Streaming machine code generation interface.
Definition MCStreamer.h:221
Represent a reference to a symbol from inside an expression.
Definition MCExpr.h:187
VariantKind getKind() const
Definition MCExpr.h:228
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition MCSymbol.h:42
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)
LLVM_READONLY bool isLitExpr(const MCExpr *Expr)
void printAMDGPUMCExpr(const MCExpr *Expr, raw_ostream &OS, const MCAsmInfo *MAI)
LLVM_READONLY AMDGPUMCExpr::VariantKind getExprKind(const MCExpr *Expr)
LLVM_READONLY int64_t getLitValue(const MCExpr *Expr)
const MCExpr * foldAMDGPUMCExpr(const MCExpr *Expr, MCContext &Ctx)
This is an optimization pass for GlobalISel generic memory operations.
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39