28 assert(
Args.size() >= 1 &&
"Needs a minimum of one expression.");
29 assert(Kind != AGVK_None &&
"Cannot construct AMDGPUMCExpr of kind none.");
36 RawArgs =
static_cast<const MCExpr **
>(
38 std::uninitialized_copy(
Args.begin(),
Args.end(), RawArgs);
42AMDGPUMCExpr::~AMDGPUMCExpr() { Ctx.
deallocate(RawArgs); }
51 assert(
Index < Args.size() &&
"Indexing out of bounds AMDGPUMCExpr sub-expr");
69 OS <<
"totalnumvgprs(";
78 for (
auto It = Args.begin(); It != Args.end(); ++It) {
79 (*It)->print(
OS, MAI,
false);
80 if ((It + 1) != Args.end())
91 return std::max(Arg1, Arg2);
99 auto TryGetMCExprValue = [&](
const MCExpr *Arg,
uint64_t &ConstantValue) {
109 "AMDGPUMCExpr Argument count incorrect for ExtraSGPRs");
111 uint64_t VCCUsed = 0, FlatScrUsed = 0, XNACKUsed = 0;
113 bool Success = TryGetMCExprValue(Args[2], XNACKUsed);
115 assert(
Success &&
"Arguments 3 for ExtraSGPRs should be a known constant");
116 if (!
Success || !TryGetMCExprValue(Args[0], VCCUsed) ||
117 !TryGetMCExprValue(Args[1], FlatScrUsed))
121 STI, (
bool)VCCUsed, (
bool)FlatScrUsed, (
bool)XNACKUsed);
128 auto TryGetMCExprValue = [&](
const MCExpr *Arg,
uint64_t &ConstantValue) {
137 "AMDGPUMCExpr Argument count incorrect for TotalNumVGPRs");
143 if (!TryGetMCExprValue(Args[0], NumAGPR) ||
144 !TryGetMCExprValue(Args[1], NumVGPR))
147 uint64_t TotalNum = Has90AInsts && NumAGPR ?
alignTo(NumVGPR, 4) + NumAGPR
148 : std::max(NumVGPR, NumAGPR);
155 auto TryGetMCExprValue = [&](
const MCExpr *Arg,
uint64_t &ConstantValue) {
165 "AMDGPUMCExpr Argument count incorrect for AlignTo");
167 if (!TryGetMCExprValue(Args[0],
Value) || !TryGetMCExprValue(Args[1],
Align))
176 auto TryGetMCExprValue = [&](
const MCExpr *Arg,
uint64_t &ConstantValue) {
185 "AMDGPUMCExpr Argument count incorrect for Occupancy");
186 uint64_t InitOccupancy, MaxWaves, Granule, TargetTotalNumVGPRs, Generation,
190 Success &= TryGetMCExprValue(Args[0], MaxWaves);
191 Success &= TryGetMCExprValue(Args[1], Granule);
192 Success &= TryGetMCExprValue(Args[2], TargetTotalNumVGPRs);
193 Success &= TryGetMCExprValue(Args[3], Generation);
194 Success &= TryGetMCExprValue(Args[4], InitOccupancy);
196 assert(
Success &&
"Arguments 1 to 5 for Occupancy should be known constants");
198 if (!
Success || !TryGetMCExprValue(Args[5], NumSGPRs) ||
199 !TryGetMCExprValue(Args[6], NumVGPRs))
202 unsigned Occupancy = InitOccupancy;
204 Occupancy = std::min(
209 Occupancy = std::min(Occupancy,
211 NumVGPRs, Granule, MaxWaves, TargetTotalNumVGPRs));
220 std::optional<int64_t>
Total;
225 return evaluateExtraSGPRs(Res, Asm,
Fixup);
227 return evaluateAlignTo(Res, Asm,
Fixup);
229 return evaluateTotalNumVGPR(Res, Asm,
Fixup);
231 return evaluateOccupancy(Res, Asm,
Fixup);
234 for (
const MCExpr *Arg : Args) {
239 if (!
Total.has_value())
249 for (
const MCExpr *Arg : Args)
254 for (
const MCExpr *Arg : Args) {
266 const MCExpr *FlatScrUsed,
296 auto CreateExpr = [&Ctx](
unsigned Value) {
301 {CreateExpr(MaxWaves), CreateExpr(Granule),
302 CreateExpr(TargetTotalNumVGPRs), CreateExpr(Generation),
303 CreateExpr(InitOcc), NumSGPRs, NumVGPRs},
This file defines the BumpPtrAllocator interface.
AMD GCN specific subclass of TargetSubtarget.
PowerPC TLS Dynamic Call Fixup
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
AMDGPU target specific MCExpr operations.
MCFragment * findAssociatedFragment() const override
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.
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...
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
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Generation getGeneration() const
This class is intended to be used as a base class for asm properties and features specific to the tar...
static const MCConstantExpr * create(int64_t Value, MCContext &Ctx, bool PrintInHex=false, unsigned SizeInBytes=0)
Context object for machine code objects.
void * allocate(unsigned Size, unsigned Align=8)
void deallocate(void *Ptr)
const MCSubtargetInfo * getSubtargetInfo() const
Base class for the full range of assembler expressions which are needed for parsing.
bool evaluateAsRelocatable(MCValue &Res, const MCAssembler *Asm, const MCFixup *Fixup) const
Try to evaluate the expression to a relocatable value, i.e.
MCFragment * findAssociatedFragment() const
Find the "associated section" for this expression, which is currently defined as the absolute section...
Encode information on a single operation to perform on a byte sequence (e.g., an encoded instruction)...
Streaming machine code generation interface.
void visitUsedExpr(const MCExpr &Expr)
Generic base class for all target subtargets.
This represents an "assembler immediate".
int64_t getConstant() const
static MCValue get(const MCSymbolRefExpr *SymA, const MCSymbolRefExpr *SymB=nullptr, int64_t Val=0, uint32_t RefKind=0)
bool isAbsolute() const
Is this an absolute (as opposed to relocatable) value.
LLVM Value Representation.
This class implements an extremely fast bulk output stream that can only output to a stream.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char NumVGPRs[]
Key for Kernel::CodeProps::Metadata::mNumVGPRs.
constexpr char NumSGPRs[]
Key for Kernel::CodeProps::Metadata::mNumSGPRs.
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
unsigned getTotalNumVGPRs(const MCSubtargetInfo *STI)
unsigned getMaxWavesPerEU(const MCSubtargetInfo *STI)
unsigned getNumExtraSGPRs(const MCSubtargetInfo *STI, bool VCCUsed, bool FlatScrUsed, bool XNACKUsed)
unsigned getNumWavesPerEUWithNumVGPRs(const MCSubtargetInfo *STI, unsigned NumVGPRs)
unsigned getOccupancyWithNumSGPRs(unsigned SGPRs, unsigned MaxWaves, AMDGPUSubtarget::Generation Gen)
unsigned getVGPRAllocGranule(const MCSubtargetInfo *STI, std::optional< bool > EnableWavefrontSize32)
bool isGFX90A(const MCSubtargetInfo &STI)
This is an optimization pass for GlobalISel generic memory operations.
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
This struct is a compact representation of a valid (non-zero power of two) alignment.