27 assert(
Args.size() >= 1 &&
"Needs a minimum of one expression.");
28 assert(Kind != AGVK_None &&
"Cannot construct AMDGPUMCExpr of kind none.");
35 RawArgs =
static_cast<const MCExpr **
>(
37 std::uninitialized_copy(
Args.begin(),
Args.end(), RawArgs);
41AMDGPUMCExpr::~AMDGPUMCExpr() { Ctx.
deallocate(RawArgs); }
50 assert(
Index < Args.size() &&
"Indexing out of bounds AMDGPUMCExpr sub-expr");
68 OS <<
"totalnumvgprs(";
77 for (
auto It = Args.begin(); It != Args.end(); ++It) {
78 (*It)->print(
OS, MAI,
false);
79 if ((It + 1) != Args.end())
90 return std::max(Arg1, Arg2);
98 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) {
138 "AMDGPUMCExpr Argument count incorrect for TotalNumVGPRs");
144 if (!TryGetMCExprValue(Args[0], NumAGPR) ||
145 !TryGetMCExprValue(Args[1], NumVGPR))
148 uint64_t TotalNum = Has90AInsts && NumAGPR ?
alignTo(NumVGPR, 4) + NumAGPR
149 : std::max(NumVGPR, NumAGPR);
156 auto TryGetMCExprValue = [&](
const MCExpr *Arg,
uint64_t &ConstantValue) {
167 "AMDGPUMCExpr Argument count incorrect for AlignTo");
169 if (!TryGetMCExprValue(Args[0],
Value) || !TryGetMCExprValue(Args[1],
Align))
178 auto TryGetMCExprValue = [&](
const MCExpr *Arg,
uint64_t &ConstantValue) {
188 "AMDGPUMCExpr Argument count incorrect for Occupancy");
189 uint64_t InitOccupancy, MaxWaves, Granule, TargetTotalNumVGPRs, Generation,
193 Success &= TryGetMCExprValue(Args[0], MaxWaves);
194 Success &= TryGetMCExprValue(Args[1], Granule);
195 Success &= TryGetMCExprValue(Args[2], TargetTotalNumVGPRs);
196 Success &= TryGetMCExprValue(Args[3], Generation);
197 Success &= TryGetMCExprValue(Args[4], InitOccupancy);
199 assert(
Success &&
"Arguments 1 to 5 for Occupancy should be known constants");
201 if (!
Success || !TryGetMCExprValue(Args[5], NumSGPRs) ||
202 !TryGetMCExprValue(Args[6], NumVGPRs))
205 unsigned Occupancy = InitOccupancy;
207 Occupancy = std::min(
212 Occupancy = std::min(Occupancy,
214 NumVGPRs, Granule, MaxWaves, TargetTotalNumVGPRs));
223 std::optional<int64_t>
Total;
229 return evaluateExtraSGPRs(Res, Layout,
Fixup);
231 return evaluateAlignTo(Res, Layout,
Fixup);
233 return evaluateTotalNumVGPR(Res, Layout,
Fixup);
235 return evaluateOccupancy(Res, Layout,
Fixup);
238 for (
const MCExpr *Arg : Args) {
244 if (!
Total.has_value())
254 for (
const MCExpr *Arg : Args)
259 for (
const MCExpr *Arg : Args) {
271 const MCExpr *FlatScrUsed,
301 auto CreateExpr = [&Ctx](
unsigned Value) {
306 {CreateExpr(MaxWaves), CreateExpr(Granule),
307 CreateExpr(TargetTotalNumVGPRs), CreateExpr(Generation),
308 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
void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override
bool evaluateAsRelocatableImpl(MCValue &Res, const MCAsmLayout *Layout, const MCFixup *Fixup) 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...
Encapsulates the layout of an assembly file at a particular point in time.
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 MCAsmLayout *Layout, 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.