LLVM 24.0.0git
SIMachineFunctionInfo.h
Go to the documentation of this file.
1//==- SIMachineFunctionInfo.h - SIMachineFunctionInfo interface --*- 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/// \file
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_LIB_TARGET_AMDGPU_SIMACHINEFUNCTIONINFO_H
14#define LLVM_LIB_TARGET_AMDGPU_SIMACHINEFUNCTIONINFO_H
15
18#include "AMDGPUTargetMachine.h"
19#include "GCNSubtarget.h"
21#include "SIInstrInfo.h"
23#include "llvm/ADT/SetVector.h"
28#include <optional>
29
30namespace llvm {
31
33class MachineFunction;
35class SIRegisterInfo;
36class MCRegisterClass;
38
40public:
45
46protected:
48 : PseudoSourceValue(Kind, TM) {}
49
50public:
51 bool isConstant(const MachineFrameInfo *) const override {
52 // This should probably be true for most images, but we will start by being
53 // conservative.
54 return false;
55 }
56
57 bool isAliased(const MachineFrameInfo *) const override {
58 return true;
59 }
60
61 bool mayAlias(const MachineFrameInfo *) const override {
62 return true;
63 }
64};
65
67public:
70
71 static bool classof(const PseudoSourceValue *V) {
72 return V->kind() == GWSResource;
73 }
74
75 // These are inaccessible memory from IR.
76 bool isAliased(const MachineFrameInfo *) const override {
77 return false;
78 }
79
80 // These are inaccessible memory from IR.
81 bool mayAlias(const MachineFrameInfo *) const override {
82 return false;
83 }
84
85 void printCustom(raw_ostream &OS) const override {
86 OS << "GWSResource";
87 }
88};
89
90namespace yaml {
91
92struct SIArgument {
94 union {
96 unsigned StackOffset;
97 };
98 std::optional<unsigned> Mask;
99
100 // Default constructor, which creates a stack argument.
103 IsRegister = Other.IsRegister;
104 if (IsRegister)
105 new (&RegisterName) StringValue(Other.RegisterName);
106 else
107 StackOffset = Other.StackOffset;
108 Mask = Other.Mask;
109 }
111 // Default-construct or destruct the old RegisterName in case of switching
112 // union members
113 if (IsRegister != Other.IsRegister) {
114 if (Other.IsRegister)
115 new (&RegisterName) StringValue();
116 else
117 RegisterName.~StringValue();
118 }
119 IsRegister = Other.IsRegister;
120 if (IsRegister)
121 RegisterName = Other.RegisterName;
122 else
123 StackOffset = Other.StackOffset;
124 Mask = Other.Mask;
125 return *this;
126 }
128 if (IsRegister)
129 RegisterName.~StringValue();
130 }
131
132 // Helper to create a register or stack argument.
133 static inline SIArgument createArgument(bool IsReg) {
134 if (IsReg)
135 return SIArgument(IsReg);
136 return SIArgument();
137 }
138
139private:
140 // Construct a register argument.
142};
143
144template <> struct MappingTraits<SIArgument> {
145 static void mapping(IO &YamlIO, SIArgument &A) {
146 if (YamlIO.outputting()) {
147 if (A.IsRegister)
148 YamlIO.mapRequired("reg", A.RegisterName);
149 else
150 YamlIO.mapRequired("offset", A.StackOffset);
151 } else {
152 auto Keys = YamlIO.keys();
153 if (is_contained(Keys, "reg")) {
155 YamlIO.mapRequired("reg", A.RegisterName);
156 } else if (is_contained(Keys, "offset"))
157 YamlIO.mapRequired("offset", A.StackOffset);
158 else
159 YamlIO.setError("missing required key 'reg' or 'offset'");
160 }
161 YamlIO.mapOptional("mask", A.Mask);
162 }
163 static const bool flow = true;
164};
165
167 std::optional<SIArgument> PrivateSegmentBuffer;
168 std::optional<SIArgument> DispatchPtr;
169 std::optional<SIArgument> QueuePtr;
170 std::optional<SIArgument> KernargSegmentPtr;
171 std::optional<SIArgument> DispatchID;
172 std::optional<SIArgument> FlatScratchInit;
173 std::optional<SIArgument> PrivateSegmentSize;
174 std::optional<SIArgument> FirstKernArgPreloadReg;
175
176 std::optional<SIArgument> WorkGroupIDX;
177 std::optional<SIArgument> WorkGroupIDY;
178 std::optional<SIArgument> WorkGroupIDZ;
179 std::optional<SIArgument> WorkGroupInfo;
180 std::optional<SIArgument> LDSKernelId;
181 std::optional<SIArgument> PrivateSegmentWaveByteOffset;
182
183 std::optional<SIArgument> ImplicitArgPtr;
184 std::optional<SIArgument> ImplicitBufferPtr;
185
186 std::optional<SIArgument> WorkItemIDX;
187 std::optional<SIArgument> WorkItemIDY;
188 std::optional<SIArgument> WorkItemIDZ;
189};
190
191template <> struct MappingTraits<SIArgumentInfo> {
192 static void mapping(IO &YamlIO, SIArgumentInfo &AI) {
193 YamlIO.mapOptional("privateSegmentBuffer", AI.PrivateSegmentBuffer);
194 YamlIO.mapOptional("dispatchPtr", AI.DispatchPtr);
195 YamlIO.mapOptional("queuePtr", AI.QueuePtr);
196 YamlIO.mapOptional("kernargSegmentPtr", AI.KernargSegmentPtr);
197 YamlIO.mapOptional("dispatchID", AI.DispatchID);
198 YamlIO.mapOptional("flatScratchInit", AI.FlatScratchInit);
199 YamlIO.mapOptional("privateSegmentSize", AI.PrivateSegmentSize);
200 YamlIO.mapOptional("firstKernArgPreloadReg", AI.FirstKernArgPreloadReg);
201
202 YamlIO.mapOptional("workGroupIDX", AI.WorkGroupIDX);
203 YamlIO.mapOptional("workGroupIDY", AI.WorkGroupIDY);
204 YamlIO.mapOptional("workGroupIDZ", AI.WorkGroupIDZ);
205 YamlIO.mapOptional("workGroupInfo", AI.WorkGroupInfo);
206 YamlIO.mapOptional("LDSKernelId", AI.LDSKernelId);
207 YamlIO.mapOptional("privateSegmentWaveByteOffset",
209
210 YamlIO.mapOptional("implicitArgPtr", AI.ImplicitArgPtr);
211 YamlIO.mapOptional("implicitBufferPtr", AI.ImplicitBufferPtr);
212
213 YamlIO.mapOptional("workItemIDX", AI.WorkItemIDX);
214 YamlIO.mapOptional("workItemIDY", AI.WorkItemIDY);
215 YamlIO.mapOptional("workItemIDZ", AI.WorkItemIDZ);
216 }
217};
218
219// Default to default mode for default calling convention.
220struct SIMode {
221 bool IEEE = true;
222 bool DX10Clamp = true;
227
228 SIMode() = default;
229
231 IEEE = Mode.IEEE;
232 DX10Clamp = Mode.DX10Clamp;
233 FP32InputDenormals = Mode.FP32Denormals.Input != DenormalMode::PreserveSign;
235 Mode.FP32Denormals.Output != DenormalMode::PreserveSign;
237 Mode.FP64FP16Denormals.Input != DenormalMode::PreserveSign;
239 Mode.FP64FP16Denormals.Output != DenormalMode::PreserveSign;
240 }
241
242 bool operator ==(const SIMode Other) const {
243 return IEEE == Other.IEEE &&
244 DX10Clamp == Other.DX10Clamp &&
245 FP32InputDenormals == Other.FP32InputDenormals &&
246 FP32OutputDenormals == Other.FP32OutputDenormals &&
247 FP64FP16InputDenormals == Other.FP64FP16InputDenormals &&
248 FP64FP16OutputDenormals == Other.FP64FP16OutputDenormals;
249 }
250};
251
252template <> struct MappingTraits<SIMode> {
253 static void mapping(IO &YamlIO, SIMode &Mode) {
254 YamlIO.mapOptional("ieee", Mode.IEEE, true);
255 YamlIO.mapOptional("dx10-clamp", Mode.DX10Clamp, true);
256 YamlIO.mapOptional("fp32-input-denormals", Mode.FP32InputDenormals, true);
257 YamlIO.mapOptional("fp32-output-denormals", Mode.FP32OutputDenormals, true);
258 YamlIO.mapOptional("fp64-fp16-input-denormals", Mode.FP64FP16InputDenormals, true);
259 YamlIO.mapOptional("fp64-fp16-output-denormals", Mode.FP64FP16OutputDenormals, true);
260 }
261};
262
269 bool IsEntryFunction = false;
270 bool IsChainFunction = false;
271 bool MemoryBound = false;
272 bool WaveLimiter = false;
273 bool HasSpilledSGPRs = false;
274 bool HasSpilledVGPRs = false;
279
280 // TODO: 10 may be a better default since it's the maximum.
281 unsigned Occupancy = 0;
282
285
286 StringValue ScratchRSrcReg = "$private_rsrc_reg";
289
291 bool ReturnsVoid = true;
292
293 std::optional<SIArgumentInfo> ArgInfo;
294
295 unsigned PSInputAddr = 0;
296 unsigned PSInputEnable = 0;
298
300 std::optional<FrameIndex> ScavengeFI;
304
305 bool HasInitWholeWave = false;
307
308 std::optional<unsigned> DynamicVGPRBlockSize;
310
312
313 unsigned MinNumAGPRs = ~0u;
314
317 const TargetRegisterInfo &TRI,
318 const llvm::MachineFunction &MF);
319
320 void mappingImpl(yaml::IO &YamlIO) override;
321 ~SIMachineFunctionInfo() override = default;
322};
323
325 static void mapping(IO &YamlIO, SIMachineFunctionInfo &MFI) {
326 YamlIO.mapOptional("explicitKernArgSize", MFI.ExplicitKernArgSize,
327 UINT64_C(0));
328 YamlIO.mapOptional("maxKernArgAlign", MFI.MaxKernArgAlign);
329 YamlIO.mapOptional("ldsSize", MFI.LDSSize, 0u);
330 YamlIO.mapOptional("gdsSize", MFI.GDSSize, 0u);
331 YamlIO.mapOptional("dynLDSAlign", MFI.DynLDSAlign, Align());
332 YamlIO.mapOptional("isEntryFunction", MFI.IsEntryFunction, false);
333 YamlIO.mapOptional("isChainFunction", MFI.IsChainFunction, false);
334 YamlIO.mapOptional("memoryBound", MFI.MemoryBound, false);
335 YamlIO.mapOptional("waveLimiter", MFI.WaveLimiter, false);
336 YamlIO.mapOptional("hasSpilledSGPRs", MFI.HasSpilledSGPRs, false);
337 YamlIO.mapOptional("hasSpilledVGPRs", MFI.HasSpilledVGPRs, false);
338 YamlIO.mapOptional("hasNoWWMPoolSGPRSpillFallback",
340 YamlIO.mapOptional("numWaveDispatchSGPRs", MFI.NumWaveDispatchSGPRs, false);
341 YamlIO.mapOptional("numWaveDispatchVGPRs", MFI.NumWaveDispatchVGPRs, false);
342 YamlIO.mapOptional("scratchRSrcReg", MFI.ScratchRSrcReg,
343 StringValue("$private_rsrc_reg"));
344 YamlIO.mapOptional("frameOffsetReg", MFI.FrameOffsetReg,
345 StringValue("$fp_reg"));
346 YamlIO.mapOptional("stackPtrOffsetReg", MFI.StackPtrOffsetReg,
347 StringValue("$sp_reg"));
348 YamlIO.mapOptional("bytesInStackArgArea", MFI.BytesInStackArgArea, 0u);
349 YamlIO.mapOptional("returnsVoid", MFI.ReturnsVoid, true);
350 YamlIO.mapOptional("argumentInfo", MFI.ArgInfo);
351 YamlIO.mapOptional("psInputAddr", MFI.PSInputAddr, 0u);
352 YamlIO.mapOptional("psInputEnable", MFI.PSInputEnable, 0u);
353 YamlIO.mapOptional("maxMemoryClusterDWords", MFI.MaxMemoryClusterDWords,
355 YamlIO.mapOptional("mode", MFI.Mode, SIMode());
356 YamlIO.mapOptional("highBitsOf32BitAddress",
357 MFI.HighBitsOf32BitAddress, 0u);
358 YamlIO.mapOptional("occupancy", MFI.Occupancy, 0);
359 YamlIO.mapOptional("spillPhysVGPRs", MFI.SpillPhysVGPRS);
360 YamlIO.mapOptional("wwmReservedRegs", MFI.WWMReservedRegs);
361 YamlIO.mapOptional("scavengeFI", MFI.ScavengeFI);
362 YamlIO.mapOptional("vgprForAGPRCopy", MFI.VGPRForAGPRCopy,
363 StringValue()); // Don't print out when it's empty.
364 YamlIO.mapOptional("sgprForEXECCopy", MFI.SGPRForEXECCopy,
365 StringValue()); // Don't print out when it's empty.
366 YamlIO.mapOptional("longBranchReservedReg", MFI.LongBranchReservedReg,
367 StringValue());
368 YamlIO.mapOptional("hasInitWholeWave", MFI.HasInitWholeWave, false);
369 YamlIO.mapOptional("dynamicVGPRBlockSize", MFI.DynamicVGPRBlockSize);
370 YamlIO.mapOptional("scratchReservedForDynamicVGPRs",
372 YamlIO.mapOptional("numKernargPreloadSGPRs", MFI.NumKernargPreloadSGPRs, 0);
373 YamlIO.mapOptional("isWholeWaveFunction", MFI.IsWholeWaveFunction, false);
374 YamlIO.mapOptional("minNumAGPRs", MFI.MinNumAGPRs, ~0u);
375 }
376};
377
378} // end namespace yaml
379
380// A CSR SGPR value can be preserved inside a callee using one of the following
381// methods.
382// 1. Copy to an unused scratch SGPR.
383// 2. Spill to a VGPR lane.
384// 3. Spill to memory via. a scratch VGPR.
385// class PrologEpilogSGPRSaveRestoreInfo represents the save/restore method used
386// for an SGPR at function prolog/epilog.
392
394 SGPRSaveKind Kind;
395 union {
396 int Index;
398 };
399
400public:
404 Register getReg() const { return Reg; }
405 int getIndex() const { return Index; }
406 SGPRSaveKind getKind() const { return Kind; }
407};
408
411 unsigned operator()(Register Reg) const {
412 assert(AMDGPU::VReg_1024RegClass.contains(Reg) && "Expecting a VGPR block");
413
414 const MCRegister FirstVGPRBlock = AMDGPU::VReg_1024RegClass.getRegister(0);
415 return Reg - FirstVGPRBlock;
416 }
417};
418
419/// This class keeps track of the SPI_SP_INPUT_ADDR config register, which
420/// tells the hardware which interpolation parameters to load.
423 friend class GCNTargetMachine;
424
425 // State of MODE register, assumed FP mode.
427
428 // Registers that may be reserved for spilling purposes. These may be the same
429 // as the input registers.
430 Register ScratchRSrcReg = AMDGPU::PRIVATE_RSRC_REG;
431
432 // This is the unswizzled offset from the current dispatch's scratch wave
433 // base to the beginning of the current function's frame.
434 Register FrameOffsetReg = AMDGPU::FP_REG;
435
436 // This is an ABI register used in the non-entry calling convention to
437 // communicate the unswizzled offset from the current dispatch's scratch wave
438 // base to the beginning of the new function's frame.
439 Register StackPtrOffsetReg = AMDGPU::SP_REG;
440
441 // Registers that may be reserved when RA doesn't allocate enough
442 // registers to plan for the case where an indirect branch ends up
443 // being needed during branch relaxation.
444 Register LongBranchReservedReg;
445
446 AMDGPUFunctionArgInfo ArgInfo;
447
448 // Graphics info.
449 unsigned PSInputAddr = 0;
450 unsigned PSInputEnable = 0;
451
452 /// Number of bytes of arguments this function has on the stack. If the callee
453 /// is expected to restore the argument stack this should be a multiple of 16,
454 /// all usable during a tail call.
455 ///
456 /// The alternative would forbid tail call optimisation in some cases: if we
457 /// want to transfer control from a function with 8-bytes of stack-argument
458 /// space to a function with 16-bytes then misalignment of this value would
459 /// make a stack adjustment necessary, which could not be undone by the
460 /// callee.
461 unsigned BytesInStackArgArea = 0;
462
463 bool ReturnsVoid = true;
464
465 // A pair of default/requested minimum/maximum flat work group sizes.
466 // Minimum - first, maximum - second.
467 std::pair<unsigned, unsigned> FlatWorkGroupSizes = {0, 0};
468
469 // A pair of default/requested minimum/maximum number of waves per execution
470 // unit. Minimum - first, maximum - second.
471 std::pair<unsigned, unsigned> WavesPerEU = {0, 0};
472
473 const AMDGPUGWSResourcePseudoSourceValue GWSResourcePSV;
474
475 // Default/requested number of work groups for the function.
476 SmallVector<unsigned> MaxNumWorkGroups = {0, 0, 0};
477
478 // Requested cluster dimensions.
479 AMDGPU::ClusterDimsAttr ClusterDims;
480
481private:
482 unsigned NumUserSGPRs = 0;
483 unsigned NumSystemSGPRs = 0;
484
485 unsigned NumWaveDispatchSGPRs = 0;
486 unsigned NumWaveDispatchVGPRs = 0;
487
488 bool HasSpilledSGPRs = false;
489 bool HasSpilledVGPRs = false;
490 bool HasNonSpillStackObjects = false;
491 bool IsStackRealigned = false;
492
493 unsigned NumSpilledSGPRs = 0;
494 unsigned NumSpilledVGPRs = 0;
495
496 unsigned DynamicVGPRBlockSize = 0;
497
498 // The size in bytes of the scratch space reserved for the CWSR trap handler
499 // to spill some of the dynamic VGPRs.
500 unsigned ScratchReservedForDynamicVGPRs = 0;
501
502 // Tracks information about user SGPRs that will be setup by hardware which
503 // will apply to all wavefronts of the grid.
504 GCNUserSGPRUsageInfo UserSGPRInfo;
505
506 // Feature bits required for inputs passed in system SGPRs.
507 bool WorkGroupIDX : 1; // Always initialized.
508 bool WorkGroupIDY : 1;
509 bool WorkGroupIDZ : 1;
510 bool WorkGroupInfo : 1;
511 bool LDSKernelId : 1;
512 bool PrivateSegmentWaveByteOffset : 1;
513
514 bool WorkItemIDX : 1; // Always initialized.
515 bool WorkItemIDY : 1;
516 bool WorkItemIDZ : 1;
517
518 // Pointer to where the ABI inserts special kernel arguments separate from the
519 // user arguments. This is an offset from the KernargSegmentPtr.
520 bool ImplicitArgPtr : 1;
521
522 /// Minimum number of AGPRs required to allocate in the function. Only
523 /// relevant for gfx90a-gfx950. For gfx908, this should be infinite.
524 unsigned MinNumAGPRs = ~0u;
525
526 // The hard-wired high half of the address of the global information table
527 // for AMDPAL OS type. 0xffffffff represents no hard-wired high half, since
528 // current hardware only allows a 16 bit value.
529 unsigned GITPtrHigh;
530
531 unsigned HighBitsOf32BitAddress;
532
533 // Flags associated with the virtual registers.
534 IndexedMap<uint8_t, VirtReg2IndexFunctor> VRegFlags;
535
536 // Current recorded maximum possible occupancy.
537 unsigned Occupancy;
538
539 // Maximum number of dwords that can be clusterred during instruction
540 // scheduler stage.
541 unsigned MaxMemoryClusterDWords = DefaultMemoryClusterDWordsLimit;
542
543 MCPhysReg getNextUserSGPR() const;
544
545 MCPhysReg getNextSystemSGPR() const;
546
547 // MachineRegisterInfo callback functions to notify events.
548 void MRI_NoteNewVirtualRegister(Register Reg) override;
549 void MRI_NoteCloneVirtualRegister(Register NewReg, Register SrcReg) override;
550
551public:
552 static bool MFMAVGPRForm;
553
559
560private:
561 // To track virtual VGPR + lane index for each subregister of the SGPR spilled
562 // to frameindex key during SILowerSGPRSpills pass.
564 SGPRSpillsToVirtualVGPRLanes;
565 // To track physical VGPR + lane index for CSR SGPR spills and special SGPRs
566 // like Frame Pointer identified during PrologEpilogInserter.
568 SGPRSpillsToPhysicalVGPRLanes;
569 unsigned NumVirtualVGPRSpillLanes = 0;
570 unsigned NumPhysicalVGPRSpillLanes = 0;
571 SmallVector<Register, 2> SpillVGPRs;
572 SmallVector<Register, 2> SpillPhysVGPRs;
573 using WWMSpillsMap = MapVector<Register, int>;
574 // To track the registers used in instructions that can potentially modify the
575 // inactive lanes. The WWM instructions and the writelane instructions for
576 // spilling SGPRs to VGPRs fall under such category of operations. The VGPRs
577 // modified by them should be spilled/restored at function prolog/epilog to
578 // avoid any undesired outcome. Each entry in this map holds a pair of values,
579 // the VGPR and its stack slot index.
580 WWMSpillsMap WWMSpills;
581
582 // Before allocation, the VGPR registers are partitioned into two distinct
583 // sets, the first one for WWM values and the second set for per-lane values.
584 // The latter set should be reserved during WWM-regalloc.
585 BitVector PerLaneVGPRMask;
586
587 using ReservedRegSet = SmallSetVector<Register, 8>;
588 // To track the VGPRs reserved for WWM instructions. They get stack slots
589 // later during PrologEpilogInserter and get added into the superset WWMSpills
590 // for actual spilling. A separate set makes the register reserved part and
591 // the serialization easier.
592 ReservedRegSet WWMReservedRegs;
593
594 bool IsWholeWaveFunction = false;
595
596 using PrologEpilogSGPRSpill =
597 std::pair<Register, PrologEpilogSGPRSaveRestoreInfo>;
598 // To track the SGPR spill method used for a CSR SGPR register during
599 // frame lowering. Even though the SGPR spills are handled during
600 // SILowerSGPRSpills pass, some special handling needed later during the
601 // PrologEpilogInserter.
602 SmallVector<PrologEpilogSGPRSpill, 3> PrologEpilogSGPRSpills;
603
604 // To save/restore EXEC MASK around WWM spills and copies.
605 Register SGPRForEXECCopy;
606
607 DenseMap<int, VGPRSpillToAGPR> VGPRToAGPRSpills;
608
609 // AGPRs used for VGPR spills.
611
612 // VGPRs used for AGPR spills.
614
615 // Emergency stack slot. Sometimes, we create this before finalizing the stack
616 // frame, so save it here and add it to the RegScavenger later.
617 std::optional<int> ScavengeFI;
618
619 // Ordinary SGPR spills fell back to memory because no WWM VGPR pool was
620 // available. This path may require additional nested VGPR scavenging slots
621 // during frame-index elimination.
622 bool HasNoWWMPoolSGPRSpillFallback = false;
623
624 // Map each VGPR CSR to the mask needed to save and restore it using block
625 // load/store instructions. Only used if the subtarget feature for VGPR block
626 // load/store is enabled.
628
629private:
630 Register VGPRForAGPRCopy;
631
632 bool allocateVirtualVGPRForSGPRSpills(MachineFunction &MF, int FI,
633 unsigned LaneIndex);
634 bool allocatePhysicalVGPRForSGPRSpills(MachineFunction &MF, int FI,
635 unsigned LaneIndex,
636 bool IsPrologEpilog);
637
638public:
640 return VGPRForAGPRCopy;
641 }
642
643 void setVGPRForAGPRCopy(Register NewVGPRForAGPRCopy) {
644 VGPRForAGPRCopy = NewVGPRForAGPRCopy;
645 }
646
647 bool isCalleeSavedReg(const MCPhysReg *CSRegs, MCPhysReg Reg) const;
648
649 void setMaskForVGPRBlockOps(Register RegisterBlock, uint32_t Mask) {
650 MaskForVGPRBlockOps.grow(RegisterBlock);
651 MaskForVGPRBlockOps[RegisterBlock] = Mask;
652 }
653
655 return MaskForVGPRBlockOps[RegisterBlock];
656 }
657
658 bool hasMaskForVGPRBlockOps(Register RegisterBlock) const {
659 return MaskForVGPRBlockOps.inBounds(RegisterBlock);
660 }
661
662public:
664 SIMachineFunctionInfo(const Function &F, const GCNSubtarget *STI);
665
669 const override;
670
672 const MachineFunction &MF,
674 SMDiagnostic &Error, SMRange &SourceRange);
675
676 void reserveWWMRegister(Register Reg) { WWMReservedRegs.insert(Reg); }
677 bool isWWMReg(Register Reg) const {
678 return Reg.isVirtual() ? checkFlag(Reg, AMDGPU::VirtRegFlag::WWM_REG)
679 : WWMReservedRegs.contains(Reg);
680 }
681
682 void updatePerLaneVGPRMask(BitVector &RegMask) { PerLaneVGPRMask = RegMask; }
683 BitVector getPerLaneVGPRMask() const { return PerLaneVGPRMask; }
684 void clearPerLaneVGPRAllocMask() { PerLaneVGPRMask.clear(); }
685
686 SIModeRegisterDefaults getMode() const { return Mode; }
687
689 getSGPRSpillToVirtualVGPRLanes(int FrameIndex) const {
690 auto I = SGPRSpillsToVirtualVGPRLanes.find(FrameIndex);
691 return (I == SGPRSpillsToVirtualVGPRLanes.end())
693 : ArrayRef(I->second);
694 }
695
696 ArrayRef<Register> getSGPRSpillVGPRs() const { return SpillVGPRs; }
697 ArrayRef<Register> getSGPRSpillPhysVGPRs() const { return SpillPhysVGPRs; }
698
699 const WWMSpillsMap &getWWMSpills() const { return WWMSpills; }
700 const ReservedRegSet &getWWMReservedRegs() const { return WWMReservedRegs; }
701
703 return WWMReservedRegs.contains(Reg);
704 }
705
706 bool isWholeWaveFunction() const { return IsWholeWaveFunction; }
707
709 assert(is_sorted(PrologEpilogSGPRSpills, llvm::less_first()));
710 return PrologEpilogSGPRSpills;
711 }
712
713 GCNUserSGPRUsageInfo &getUserSGPRInfo() { return UserSGPRInfo; }
714
715 const GCNUserSGPRUsageInfo &getUserSGPRInfo() const { return UserSGPRInfo; }
716
720
721 // Insert a new entry in the right place to keep the vector in sorted order.
722 // This should be cheap since the vector is expected to be very short.
723 PrologEpilogSGPRSpills.insert(
725 PrologEpilogSGPRSpills, Reg,
726 [](const auto &LHS, const auto &RHS) { return LHS < RHS.first; }),
727 std::make_pair(Reg, SI));
728 }
729
730 // Check if an entry created for \p Reg in PrologEpilogSGPRSpills. Return true
731 // on success and false otherwise.
733 const auto *I = find_if(PrologEpilogSGPRSpills, [&Reg](const auto &Spill) {
734 return Spill.first == Reg;
735 });
736 return I != PrologEpilogSGPRSpills.end();
737 }
738
739 // Get the scratch SGPR if allocated to save/restore \p Reg.
741 const auto *I = find_if(PrologEpilogSGPRSpills, [&Reg](const auto &Spill) {
742 return Spill.first == Reg;
743 });
744 if (I != PrologEpilogSGPRSpills.end() &&
745 I->second.getKind() == SGPRSaveKind::COPY_TO_SCRATCH_SGPR)
746 return I->second.getReg();
747
748 return AMDGPU::NoRegister;
749 }
750
751 // Get all scratch SGPRs allocated to copy/restore the SGPR spills.
753 for (const auto &SI : PrologEpilogSGPRSpills) {
754 if (SI.second.getKind() == SGPRSaveKind::COPY_TO_SCRATCH_SGPR)
755 Regs.push_back(SI.second.getReg());
756 }
757 }
758
759 // Check if \p FI is allocated for any SGPR spill to a VGPR lane during PEI.
761 return find_if(PrologEpilogSGPRSpills,
762 [FI](const std::pair<Register,
764 return SI.second.getKind() ==
766 SI.second.getIndex() == FI;
767 }) != PrologEpilogSGPRSpills.end();
768 }
769
770 // Remove if an entry created for \p Reg.
772 auto I = find_if(PrologEpilogSGPRSpills,
773 [&Reg](const auto &Spill) { return Spill.first == Reg; });
774 if (I == PrologEpilogSGPRSpills.end())
775 return;
776
777 PrologEpilogSGPRSpills.erase(I);
778 }
779
782 const auto *I = find_if(PrologEpilogSGPRSpills, [&Reg](const auto &Spill) {
783 return Spill.first == Reg;
784 });
785 assert(I != PrologEpilogSGPRSpills.end());
786
787 return I->second;
788 }
789
791 getSGPRSpillToPhysicalVGPRLanes(int FrameIndex) const {
792 auto I = SGPRSpillsToPhysicalVGPRLanes.find(FrameIndex);
793 return (I == SGPRSpillsToPhysicalVGPRLanes.end())
795 : ArrayRef(I->second);
796 }
797
799 assert(Reg.isVirtual());
800 if (VRegFlags.inBounds(Reg))
801 VRegFlags[Reg] |= Flag;
802 }
803
804 bool checkFlag(Register Reg, uint8_t Flag) const {
805 if (Reg.isPhysical())
806 return false;
807
808 return VRegFlags.inBounds(Reg) && VRegFlags[Reg] & Flag;
809 }
810
811 bool hasVRegFlags() { return VRegFlags.size(); }
812
814 Align Alignment = Align(4));
815
817 MachineFunction &MF,
818 SmallVectorImpl<std::pair<Register, int>> &CalleeSavedRegs,
819 SmallVectorImpl<std::pair<Register, int>> &ScratchRegs) const;
820
822 return SpillAGPR;
823 }
824
825 Register getSGPRForEXECCopy() const { return SGPRForEXECCopy; }
826
827 void setSGPRForEXECCopy(Register Reg) { SGPRForEXECCopy = Reg; }
828
830 return SpillVGPR;
831 }
832
833 MCPhysReg getVGPRToAGPRSpill(int FrameIndex, unsigned Lane) const {
834 auto I = VGPRToAGPRSpills.find(FrameIndex);
835 return (I == VGPRToAGPRSpills.end()) ? (MCPhysReg)AMDGPU::NoRegister
836 : I->second.Lanes[Lane];
837 }
838
839 void setVGPRToAGPRSpillDead(int FrameIndex) {
840 auto I = VGPRToAGPRSpills.find(FrameIndex);
841 if (I != VGPRToAGPRSpills.end())
842 I->second.IsDead = true;
843 }
844
845 // To bring the allocated WWM registers in \p WWMVGPRs to the lowest available
846 // range.
849 BitVector &SavedVGPRs);
850
852 bool SpillToPhysVGPRLane = false,
853 bool IsPrologEpilog = false);
854 bool allocateVGPRSpillToAGPR(MachineFunction &MF, int FI, bool isAGPRtoVGPR);
855
856 /// If \p ResetSGPRSpillStackIDs is true, reset the stack ID from sgpr-spill
857 /// to the default stack.
859 bool ResetSGPRSpillStackIDs);
860
862 std::optional<int> getOptionalScavengeFI() const { return ScavengeFI; }
863
864 void setNoWWMPoolSGPRSpillFallback() { HasNoWWMPoolSGPRSpillFallback = true; }
866 return HasNoWWMPoolSGPRSpillFallback;
867 }
868
869 unsigned getBytesInStackArgArea() const {
870 return BytesInStackArgArea;
871 }
872
873 void setBytesInStackArgArea(unsigned Bytes) {
874 BytesInStackArgArea = Bytes;
875 }
876
877 bool isDynamicVGPREnabled() const { return DynamicVGPRBlockSize != 0; }
878 unsigned getDynamicVGPRBlockSize() const { return DynamicVGPRBlockSize; }
879
880 // This is only used if we need to save any dynamic VGPRs in scratch.
882 return ScratchReservedForDynamicVGPRs;
883 }
884
885 void setScratchReservedForDynamicVGPRs(unsigned SizeInBytes) {
886 ScratchReservedForDynamicVGPRs = SizeInBytes;
887 }
888
889 // Add user SGPRs.
901 unsigned AllocSizeDWord, int KernArgIdx,
902 int PaddingSGPRs);
903
904 /// Increment user SGPRs used for padding the argument list only.
906 Register Next = getNextUserSGPR();
907 ++NumUserSGPRs;
908 return Next;
909 }
910
911 // Add system SGPRs.
913 ArgInfo.WorkGroupIDX = ArgDescriptor::createRegister(getNextSystemSGPR());
914 NumSystemSGPRs += 1;
915 return ArgInfo.WorkGroupIDX.getRegister();
916 }
917
919 ArgInfo.WorkGroupIDY = ArgDescriptor::createRegister(getNextSystemSGPR());
920 NumSystemSGPRs += 1;
921 return ArgInfo.WorkGroupIDY.getRegister();
922 }
923
925 ArgInfo.WorkGroupIDZ = ArgDescriptor::createRegister(getNextSystemSGPR());
926 NumSystemSGPRs += 1;
927 return ArgInfo.WorkGroupIDZ.getRegister();
928 }
929
931 ArgInfo.WorkGroupInfo = ArgDescriptor::createRegister(getNextSystemSGPR());
932 NumSystemSGPRs += 1;
933 return ArgInfo.WorkGroupInfo.getRegister();
934 }
935
936 bool hasLDSKernelId() const { return LDSKernelId; }
937
938 // Add special VGPR inputs
940 ArgInfo.WorkItemIDX = Arg;
941 }
942
944 ArgInfo.WorkItemIDY = Arg;
945 }
946
948 ArgInfo.WorkItemIDZ = Arg;
949 }
950
952 ArgInfo.PrivateSegmentWaveByteOffset
953 = ArgDescriptor::createRegister(getNextSystemSGPR());
954 NumSystemSGPRs += 1;
955 return ArgInfo.PrivateSegmentWaveByteOffset.getRegister();
956 }
957
959 ArgInfo.PrivateSegmentWaveByteOffset = ArgDescriptor::createRegister(Reg);
960 }
961
962 bool hasWorkGroupIDX() const {
963 return WorkGroupIDX;
964 }
965
966 bool hasWorkGroupIDY() const {
967 return WorkGroupIDY;
968 }
969
970 bool hasWorkGroupIDZ() const {
971 return WorkGroupIDZ;
972 }
973
974 bool hasWorkGroupInfo() const {
975 return WorkGroupInfo;
976 }
977
979 return PrivateSegmentWaveByteOffset;
980 }
981
982 bool hasWorkItemIDX() const {
983 return WorkItemIDX;
984 }
985
986 bool hasWorkItemIDY() const {
987 return WorkItemIDY;
988 }
989
990 bool hasWorkItemIDZ() const {
991 return WorkItemIDZ;
992 }
993
994 bool hasImplicitArgPtr() const {
995 return ImplicitArgPtr;
996 }
997
999 return ArgInfo;
1000 }
1001
1003 return ArgInfo;
1004 }
1005
1006 std::tuple<const ArgDescriptor *, const TargetRegisterClass *, LLT>
1008 return ArgInfo.getPreloadedValue(Value);
1009 }
1010
1012 const auto *Arg = std::get<0>(ArgInfo.getPreloadedValue(Value));
1013 return Arg ? Arg->getRegister() : MCRegister();
1014 }
1015
1016 unsigned getGITPtrHigh() const {
1017 return GITPtrHigh;
1018 }
1019
1020 Register getGITPtrLoReg(const MachineFunction &MF) const;
1021
1023 return HighBitsOf32BitAddress;
1024 }
1025
1026 unsigned getNumUserSGPRs() const {
1027 return NumUserSGPRs;
1028 }
1029
1030 unsigned getNumPreloadedSGPRs() const {
1031 return NumUserSGPRs + NumSystemSGPRs;
1032 }
1033
1035 return UserSGPRInfo.getNumKernargPreloadSGPRs();
1036 }
1037
1038 unsigned getNumWaveDispatchSGPRs() const { return NumWaveDispatchSGPRs; }
1039
1040 void setNumWaveDispatchSGPRs(unsigned Count) { NumWaveDispatchSGPRs = Count; }
1041
1042 unsigned getNumWaveDispatchVGPRs() const { return NumWaveDispatchVGPRs; }
1043
1044 void setNumWaveDispatchVGPRs(unsigned Count) { NumWaveDispatchVGPRs = Count; }
1045
1047 if (ArgInfo.PrivateSegmentWaveByteOffset)
1048 return ArgInfo.PrivateSegmentWaveByteOffset.getRegister();
1049 return MCRegister();
1050 }
1051
1052 /// Returns the physical register reserved for use as the resource
1053 /// descriptor for scratch accesses.
1055 return ScratchRSrcReg;
1056 }
1057
1059 assert(Reg != 0 && "Should never be unset");
1060 ScratchRSrcReg = Reg;
1061 }
1062
1064 return FrameOffsetReg;
1065 }
1066
1068 assert(Reg != 0 && "Should never be unset");
1069 FrameOffsetReg = Reg;
1070 }
1071
1073 assert(Reg != 0 && "Should never be unset");
1074 StackPtrOffsetReg = Reg;
1075 }
1076
1077 void setLongBranchReservedReg(Register Reg) { LongBranchReservedReg = Reg; }
1078
1079 // Note the unset value for this is AMDGPU::SP_REG rather than
1080 // NoRegister. This is mostly a workaround for MIR tests where state that
1081 // can't be directly computed from the function is not preserved in serialized
1082 // MIR.
1084 return StackPtrOffsetReg;
1085 }
1086
1087 Register getLongBranchReservedReg() const { return LongBranchReservedReg; }
1088
1090 return ArgInfo.QueuePtr.getRegister();
1091 }
1092
1094 return ArgInfo.ImplicitBufferPtr.getRegister();
1095 }
1096
1097 bool hasSpilledSGPRs() const {
1098 return HasSpilledSGPRs;
1099 }
1100
1101 void setHasSpilledSGPRs(bool Spill = true) {
1102 HasSpilledSGPRs = Spill;
1103 }
1104
1105 bool hasSpilledVGPRs() const {
1106 return HasSpilledVGPRs;
1107 }
1108
1109 void setHasSpilledVGPRs(bool Spill = true) {
1110 HasSpilledVGPRs = Spill;
1111 }
1112
1114 return HasNonSpillStackObjects;
1115 }
1116
1117 void setHasNonSpillStackObjects(bool StackObject = true) {
1118 HasNonSpillStackObjects = StackObject;
1119 }
1120
1121 bool isStackRealigned() const {
1122 return IsStackRealigned;
1123 }
1124
1125 void setIsStackRealigned(bool Realigned = true) {
1126 IsStackRealigned = Realigned;
1127 }
1128
1129 unsigned getNumSpilledSGPRs() const {
1130 return NumSpilledSGPRs;
1131 }
1132
1133 unsigned getNumSpilledVGPRs() const {
1134 return NumSpilledVGPRs;
1135 }
1136
1137 void addToSpilledSGPRs(unsigned num) {
1138 NumSpilledSGPRs += num;
1139 }
1140
1141 void addToSpilledVGPRs(unsigned num) {
1142 NumSpilledVGPRs += num;
1143 }
1144
1145 unsigned getPSInputAddr() const {
1146 return PSInputAddr;
1147 }
1148
1149 unsigned getPSInputEnable() const {
1150 return PSInputEnable;
1151 }
1152
1153 bool isPSInputAllocated(unsigned Index) const {
1154 return PSInputAddr & (1 << Index);
1155 }
1156
1157 void markPSInputAllocated(unsigned Index) {
1158 PSInputAddr |= 1 << Index;
1159 }
1160
1161 void markPSInputEnabled(unsigned Index) {
1162 PSInputEnable |= 1 << Index;
1163 }
1164
1165 bool returnsVoid() const {
1166 return ReturnsVoid;
1167 }
1168
1170 ReturnsVoid = Value;
1171 }
1172
1173 /// \returns A pair of default/requested minimum/maximum flat work group sizes
1174 /// for this function.
1175 std::pair<unsigned, unsigned> getFlatWorkGroupSizes() const {
1176 return FlatWorkGroupSizes;
1177 }
1178
1179 /// \returns Default/requested minimum flat work group size for this function.
1180 unsigned getMinFlatWorkGroupSize() const {
1181 return FlatWorkGroupSizes.first;
1182 }
1183
1184 /// \returns Default/requested maximum flat work group size for this function.
1185 unsigned getMaxFlatWorkGroupSize() const {
1186 return FlatWorkGroupSizes.second;
1187 }
1188
1189 /// \returns A pair of default/requested minimum/maximum number of waves per
1190 /// execution unit.
1191 std::pair<unsigned, unsigned> getWavesPerEU() const {
1192 return WavesPerEU;
1193 }
1194
1195 /// \returns Default/requested minimum number of waves per execution unit.
1196 unsigned getMinWavesPerEU() const {
1197 return WavesPerEU.first;
1198 }
1199
1200 /// \returns Default/requested maximum number of waves per execution unit.
1201 unsigned getMaxWavesPerEU() const {
1202 return WavesPerEU.second;
1203 }
1204
1207 return &GWSResourcePSV;
1208 }
1209
1210 unsigned getOccupancy() const {
1211 return Occupancy;
1212 }
1213
1214 unsigned getMinAllowedOccupancy() const {
1215 if (!isMemoryBound() && !needsWaveLimiter())
1216 return Occupancy;
1217 return (Occupancy < 4) ? Occupancy : 4;
1218 }
1219
1220 void limitOccupancy(const MachineFunction &MF);
1221
1222 void limitOccupancy(unsigned Limit) {
1223 if (Occupancy > Limit)
1224 Occupancy = Limit;
1225 }
1226
1227 void increaseOccupancy(const MachineFunction &MF, unsigned Limit) {
1228 if (Occupancy < Limit)
1229 Occupancy = Limit;
1230 limitOccupancy(MF);
1231 }
1232
1233 unsigned getMaxMemoryClusterDWords() const { return MaxMemoryClusterDWords; }
1234
1235 unsigned getMinNumAGPRs() const { return MinNumAGPRs; }
1236
1237 /// Return true if an MFMA that requires at least \p NumRegs should select to
1238 /// the AGPR form, instead of the VGPR form.
1239 bool selectAGPRFormMFMA(unsigned NumRegs) const {
1240 return !MFMAVGPRForm && getMinNumAGPRs() >= NumRegs;
1241 }
1242
1243 // \returns true if a function has a use of AGPRs via inline asm or
1244 // has a call which may use it.
1245 bool mayUseAGPRs(const Function &F) const;
1246
1247 /// \returns Default/requested number of work groups for this function.
1248 SmallVector<unsigned> getMaxNumWorkGroups() const { return MaxNumWorkGroups; }
1249
1250 unsigned getMaxNumWorkGroupsX() const { return MaxNumWorkGroups[0]; }
1251 unsigned getMaxNumWorkGroupsY() const { return MaxNumWorkGroups[1]; }
1252 unsigned getMaxNumWorkGroupsZ() const { return MaxNumWorkGroups[2]; }
1253
1254 AMDGPU::ClusterDimsAttr getClusterDims() const { return ClusterDims; }
1255};
1256
1257} // end namespace llvm
1258
1259#endif // LLVM_LIB_TARGET_AMDGPU_SIMACHINEFUNCTIONINFO_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
Provides AMDGPU specific target descriptions.
The AMDGPU TargetMachine interface definition for hw codegen targets.
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
AMD GCN specific subclass of TargetSubtarget.
static bool IsRegister(const MCParsedAsmOperand &op)
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
Register Reg
Register const TargetRegisterInfo * TRI
Promote Memory to Register
Definition Mem2Reg.cpp:110
Basic Register Allocator
static cl::opt< RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode > Mode("regalloc-enable-advisor", cl::Hidden, cl::init(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Default), cl::desc("Enable regalloc advisor mode"), cl::values(clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Default, "default", "Default"), clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Release, "release", "precompiled"), clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Development, "development", "for training")))
Interface definition for SIInstrInfo.
static bool contains(SmallPtrSetImpl< ConstantExpr * > &Cache, ConstantExpr *Expr, Constant *C)
Definition Value.cpp:484
This file implements a set that has insertion order iteration characteristics.
This file defines the SmallVector class.
Value * RHS
Value * LHS
void printCustom(raw_ostream &OS) const override
Implement printing for PseudoSourceValue.
static bool classof(const PseudoSourceValue *V)
AMDGPUGWSResourcePseudoSourceValue(const AMDGPUTargetMachine &TM)
bool mayAlias(const MachineFrameInfo *) const override
Return true if the memory pointed to by this PseudoSourceValue can ever alias an LLVM IR Value.
bool isAliased(const MachineFrameInfo *) const override
Test whether the memory pointed to by this PseudoSourceValue may also be pointed to by an LLVM IR Val...
AMDGPUMachineFunctionInfo(const Function &F, const AMDGPUSubtarget &ST)
bool isConstant(const MachineFrameInfo *) const override
Test whether the memory pointed to by this PseudoSourceValue has a constant value.
AMDGPUPseudoSourceValue(unsigned Kind, const AMDGPUTargetMachine &TM)
bool mayAlias(const MachineFrameInfo *) const override
Return true if the memory pointed to by this PseudoSourceValue can ever alias an LLVM IR Value.
bool isAliased(const MachineFrameInfo *) const override
Test whether the memory pointed to by this PseudoSourceValue may also be pointed to by an LLVM IR Val...
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
Lightweight error class with error context and mandatory checking.
Definition Error.h:159
MCRegisterClass - Base class of TargetRegisterClass.
Wrapper class representing physical registers. Should be passed by value.
Definition MCRegister.h:41
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted.
This class implements a map that also provides access to all stored values in a deterministic order.
Definition MapVector.h:38
PrologEpilogSGPRSaveRestoreInfo(SGPRSaveKind K, Register R)
PrologEpilogSGPRSaveRestoreInfo(SGPRSaveKind K, int I)
Special value supplied for machine level alias analysis.
PseudoSourceValue(unsigned Kind, const TargetMachine &TM)
Wrapper class representing virtual and physical registers.
Definition Register.h:20
This class keeps track of the SPI_SP_INPUT_ADDR config register, which tells the hardware which inter...
ArrayRef< PrologEpilogSGPRSpill > getPrologEpilogSGPRSpills() const
const WWMSpillsMap & getWWMSpills() const
bool isPSInputAllocated(unsigned Index) const
void getAllScratchSGPRCopyDstRegs(SmallVectorImpl< Register > &Regs) const
ArrayRef< MCPhysReg > getAGPRSpillVGPRs() const
bool initializeBaseYamlFields(const yaml::SIMachineFunctionInfo &YamlMFI, const MachineFunction &MF, PerFunctionMIParsingState &PFS, SMDiagnostic &Error, SMRange &SourceRange)
void removePrologEpilogSGPRSpillEntry(Register Reg)
void shiftWwmVGPRsToLowestRange(MachineFunction &MF, SmallVectorImpl< Register > &WWMVGPRs, BitVector &SavedVGPRs)
void setWorkItemIDY(ArgDescriptor Arg)
void increaseOccupancy(const MachineFunction &MF, unsigned Limit)
Register addPrivateSegmentSize(const SIRegisterInfo &TRI)
void setWorkItemIDZ(ArgDescriptor Arg)
std::pair< unsigned, unsigned > getWavesPerEU() const
void setMaskForVGPRBlockOps(Register RegisterBlock, uint32_t Mask)
MCPhysReg getVGPRToAGPRSpill(int FrameIndex, unsigned Lane) const
GCNUserSGPRUsageInfo & getUserSGPRInfo()
void allocateWWMSpill(MachineFunction &MF, Register VGPR, uint64_t Size=4, Align Alignment=Align(4))
Register addDispatchPtr(const SIRegisterInfo &TRI)
void setFlag(Register Reg, uint8_t Flag)
void setVGPRToAGPRSpillDead(int FrameIndex)
std::pair< unsigned, unsigned > getFlatWorkGroupSizes() const
Register addFlatScratchInit(const SIRegisterInfo &TRI)
Register getScratchRSrcReg() const
Returns the physical register reserved for use as the resource descriptor for scratch accesses.
Register addReservedUserSGPR()
Increment user SGPRs used for padding the argument list only.
ArrayRef< MCPhysReg > getVGPRSpillAGPRs() const
ArrayRef< Register > getSGPRSpillPhysVGPRs() const
int getScavengeFI(MachineFrameInfo &MFI, const SIRegisterInfo &TRI)
Register addQueuePtr(const SIRegisterInfo &TRI)
ArrayRef< SIRegisterInfo::SpilledReg > getSGPRSpillToVirtualVGPRLanes(int FrameIndex) const
uint32_t getMaskForVGPRBlockOps(Register RegisterBlock) const
SIMachineFunctionInfo(const SIMachineFunctionInfo &MFI)=default
bool hasMaskForVGPRBlockOps(Register RegisterBlock) const
AMDGPU::ClusterDimsAttr getClusterDims() const
SmallVector< unsigned > getMaxNumWorkGroups() const
bool hasPrologEpilogSGPRSpillEntry(Register Reg) const
Register getGITPtrLoReg(const MachineFunction &MF) const
void setVGPRForAGPRCopy(Register NewVGPRForAGPRCopy)
bool allocateVGPRSpillToAGPR(MachineFunction &MF, int FI, bool isAGPRtoVGPR)
Reserve AGPRs or VGPRs to support spilling for FrameIndex FI.
void splitWWMSpillRegisters(MachineFunction &MF, SmallVectorImpl< std::pair< Register, int > > &CalleeSavedRegs, SmallVectorImpl< std::pair< Register, int > > &ScratchRegs) const
void setBytesInStackArgArea(unsigned Bytes)
void setNumWaveDispatchSGPRs(unsigned Count)
SIModeRegisterDefaults getMode() const
bool isWWMReservedRegister(Register Reg) const
ArrayRef< SIRegisterInfo::SpilledReg > getSGPRSpillToPhysicalVGPRLanes(int FrameIndex) const
std::tuple< const ArgDescriptor *, const TargetRegisterClass *, LLT > getPreloadedValue(AMDGPUFunctionArgInfo::PreloadedValue Value) const
bool mayUseAGPRs(const Function &F) const
bool isCalleeSavedReg(const MCPhysReg *CSRegs, MCPhysReg Reg) const
const GCNUserSGPRUsageInfo & getUserSGPRInfo() const
bool allocateSGPRSpillToVGPRLane(MachineFunction &MF, int FI, bool SpillToPhysVGPRLane=false, bool IsPrologEpilog=false)
void setPrivateSegmentWaveByteOffset(Register Reg)
void setLongBranchReservedReg(Register Reg)
const AMDGPUFunctionArgInfo & getArgInfo() const
Register addKernargSegmentPtr(const SIRegisterInfo &TRI)
Register addDispatchID(const SIRegisterInfo &TRI)
void setHasSpilledVGPRs(bool Spill=true)
bool removeDeadFrameIndices(MachineFrameInfo &MFI, bool ResetSGPRSpillStackIDs)
If ResetSGPRSpillStackIDs is true, reset the stack ID from sgpr-spill to the default stack.
void setScratchReservedForDynamicVGPRs(unsigned SizeInBytes)
void markPSInputAllocated(unsigned Index)
void setWorkItemIDX(ArgDescriptor Arg)
bool isWWMReg(Register Reg) const
MachineFunctionInfo * clone(BumpPtrAllocator &Allocator, MachineFunction &DestMF, const DenseMap< MachineBasicBlock *, MachineBasicBlock * > &Src2DstMBB) const override
Make a functionally equivalent copy of this MachineFunctionInfo in MF.
bool checkFlag(Register Reg, uint8_t Flag) const
void setNumWaveDispatchVGPRs(unsigned Count)
void markPSInputEnabled(unsigned Index)
MCRegister getPreloadedReg(AMDGPUFunctionArgInfo::PreloadedValue Value) const
void setHasSpilledSGPRs(bool Spill=true)
bool checkIndexInPrologEpilogSGPRSpills(int FI) const
bool selectAGPRFormMFMA(unsigned NumRegs) const
Return true if an MFMA that requires at least NumRegs should select to the AGPR form,...
Register addPrivateSegmentBuffer(const SIRegisterInfo &TRI)
unsigned getScratchReservedForDynamicVGPRs() const
const ReservedRegSet & getWWMReservedRegs() const
void updatePerLaneVGPRMask(BitVector &RegMask)
std::optional< int > getOptionalScavengeFI() const
Register addImplicitBufferPtr(const SIRegisterInfo &TRI)
AMDGPUFunctionArgInfo & getArgInfo()
const PrologEpilogSGPRSaveRestoreInfo & getPrologEpilogSGPRSaveRestoreInfo(Register Reg) const
void setHasNonSpillStackObjects(bool StackObject=true)
void setIsStackRealigned(bool Realigned=true)
void limitOccupancy(const MachineFunction &MF)
ArrayRef< Register > getSGPRSpillVGPRs() const
SmallVectorImpl< MCRegister > * addPreloadedKernArg(const SIRegisterInfo &TRI, const TargetRegisterClass *RC, unsigned AllocSizeDWord, int KernArgIdx, int PaddingSGPRs)
void addToPrologEpilogSGPRSpills(Register Reg, PrologEpilogSGPRSaveRestoreInfo SI)
Register getScratchSGPRCopyDstReg(Register Reg) const
Register getPrivateSegmentWaveByteOffsetSystemSGPR() const
const AMDGPUGWSResourcePseudoSourceValue * getGWSPSV(const AMDGPUTargetMachine &TM)
Instances of this class encapsulate one diagnostic report, allowing printing to a raw_ostream as a ca...
Definition SourceMgr.h:308
Represents a range in source code.
Definition SMLoc.h:47
A SetVector that performs no allocations if smaller than a certain size.
Definition SetVector.h:345
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
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
virtual bool outputting() const =0
void mapOptional(StringRef Key, T &Val)
Definition YAMLTraits.h:800
virtual void setError(const Twine &)=0
void mapRequired(StringRef Key, T &Val)
Definition YAMLTraits.h:790
virtual std::vector< StringRef > keys()=0
This is an optimization pass for GlobalISel generic memory operations.
auto upper_bound(R &&Range, T &&Value)
Provide wrappers to std::upper_bound which take ranges instead of having to pass begin/end explicitly...
Definition STLExtras.h:2065
bool is_sorted(R &&Range, Compare C)
Wrapper function around std::is_sorted to check if elements in a range R are sorted with respect to a...
Definition STLExtras.h:1970
@ Other
Any other memory.
Definition ModRef.h:68
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
Definition MCRegister.h:21
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Count
Definition InstrProf.h:145
ArrayRef(const T &OneElt) -> ArrayRef< T >
constexpr unsigned DefaultMemoryClusterDWordsLimit
Definition SIInstrInfo.h:42
auto find_if(R &&Range, UnaryPredicate P)
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1772
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
Definition STLExtras.h:1947
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Next
Definition InstrProf.h:147
BumpPtrAllocatorImpl<> BumpPtrAllocator
The standard BumpPtrAllocator which just uses the default template parameters.
Definition Allocator.h:390
MCRegisterClass TargetRegisterClass
Definition FastISel.h:58
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39
static ArgDescriptor createRegister(Register Reg, unsigned Mask=~0u)
@ PreserveSign
The sign of a flushed-to-zero number is preserved in the sign of 0.
MachineFunctionInfo - This class can be derived from and used by targets to hold private target-speci...
unsigned operator()(Register Reg) const
Function object to check whether the first component of a container supported by std::get (like std::...
Definition STLExtras.h:1439
Targets should override this in a way that mirrors the implementation of llvm::MachineFunctionInfo.
static void mapping(IO &YamlIO, SIArgumentInfo &AI)
static void mapping(IO &YamlIO, SIArgument &A)
static void mapping(IO &YamlIO, SIMachineFunctionInfo &MFI)
static void mapping(IO &YamlIO, SIMode &Mode)
This class should be specialized by any type that needs to be converted to/from a YAML mapping.
Definition YAMLTraits.h:63
std::optional< SIArgument > PrivateSegmentWaveByteOffset
std::optional< SIArgument > WorkGroupIDY
std::optional< SIArgument > FlatScratchInit
std::optional< SIArgument > DispatchPtr
std::optional< SIArgument > DispatchID
std::optional< SIArgument > WorkItemIDY
std::optional< SIArgument > WorkGroupIDX
std::optional< SIArgument > ImplicitArgPtr
std::optional< SIArgument > QueuePtr
std::optional< SIArgument > WorkGroupInfo
std::optional< SIArgument > LDSKernelId
std::optional< SIArgument > ImplicitBufferPtr
std::optional< SIArgument > WorkItemIDX
std::optional< SIArgument > KernargSegmentPtr
std::optional< SIArgument > WorkItemIDZ
std::optional< SIArgument > PrivateSegmentSize
std::optional< SIArgument > PrivateSegmentBuffer
std::optional< SIArgument > FirstKernArgPreloadReg
std::optional< SIArgument > WorkGroupIDZ
std::optional< unsigned > Mask
SIArgument(const SIArgument &Other)
SIArgument & operator=(const SIArgument &Other)
static SIArgument createArgument(bool IsReg)
~SIMachineFunctionInfo() override=default
SmallVector< StringValue > WWMReservedRegs
void mappingImpl(yaml::IO &YamlIO) override
std::optional< SIArgumentInfo > ArgInfo
std::optional< unsigned > DynamicVGPRBlockSize
SmallVector< StringValue, 2 > SpillPhysVGPRS
std::optional< FrameIndex > ScavengeFI
SIMode(const SIModeRegisterDefaults &Mode)
bool operator==(const SIMode Other) const
A wrapper around std::string which contains a source range that's being set during parsing.