LLVM 20.0.0git
AMDGPUResourceUsageAnalysis.cpp
Go to the documentation of this file.
1//===- AMDGPUResourceUsageAnalysis.h ---- analysis of resources -----------===//
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/// \brief Analyzes how many registers and other resources are used by
11/// functions.
12///
13/// The results of this analysis are used to fill the register usage, flat
14/// usage, etc. into hardware registers.
15///
16/// The analysis takes callees into account. E.g. if a function A that needs 10
17/// VGPRs calls a function B that needs 20 VGPRs, querying the VGPR usage of A
18/// will return 20.
19/// It is assumed that an indirect call can go into any function except
20/// hardware-entrypoints. Therefore the register usage of functions with
21/// indirect calls is estimated as the maximum of all non-entrypoint functions
22/// in the module.
23///
24//===----------------------------------------------------------------------===//
25
27#include "AMDGPU.h"
28#include "GCNSubtarget.h"
34#include "llvm/IR/GlobalAlias.h"
35#include "llvm/IR/GlobalValue.h"
37
38using namespace llvm;
39using namespace llvm::AMDGPU;
40
41#define DEBUG_TYPE "amdgpu-resource-usage"
42
45
46// In code object v4 and older, we need to tell the runtime some amount ahead of
47// time if we don't know the true stack size. Assume a smaller number if this is
48// only due to dynamic / non-entry block allocas.
50 "amdgpu-assume-external-call-stack-size",
51 cl::desc("Assumed stack use of any external call (in bytes)"), cl::Hidden,
52 cl::init(16384));
53
55 "amdgpu-assume-dynamic-stack-object-size",
56 cl::desc("Assumed extra stack use if there are any "
57 "variable sized objects (in bytes)"),
58 cl::Hidden, cl::init(4096));
59
61 "Function register usage analysis", true, true)
62
63static const Function *getCalleeFunction(const MachineOperand &Op) {
64 if (Op.isImm()) {
65 assert(Op.getImm() == 0);
66 return nullptr;
67 }
68 return cast<Function>(Op.getGlobal()->stripPointerCastsAndAliases());
69}
70
72 const SIInstrInfo &TII, unsigned Reg) {
73 for (const MachineOperand &UseOp : MRI.reg_operands(Reg)) {
74 if (!UseOp.isImplicit() || !TII.isFLAT(*UseOp.getParent()))
75 return true;
76 }
77
78 return false;
79}
80
82 const GCNSubtarget &ST) const {
83 return NumExplicitSGPR +
85 ST.getTargetID().isXnackOnOrAny());
86}
87
89 const GCNSubtarget &ST) const {
90 return AMDGPU::getTotalNumVGPRs(ST.hasGFX90AInsts(), NumAGPR, NumVGPR);
91}
92
94 auto *TPC = getAnalysisIfAvailable<TargetPassConfig>();
95 if (!TPC)
96 return false;
97
98 MachineModuleInfo &MMI = getAnalysis<MachineModuleInfoWrapperPass>().getMMI();
99 const TargetMachine &TM = TPC->getTM<TargetMachine>();
100 const MCSubtargetInfo &STI = *TM.getMCSubtargetInfo();
101 bool HasIndirectCall = false;
102
103 CallGraph CG = CallGraph(M);
104 auto End = po_end(&CG);
105
106 // By default, for code object v5 and later, track only the minimum scratch
107 // size
108 uint32_t AssumedStackSizeForDynamicSizeObjects =
110 uint32_t AssumedStackSizeForExternalCall = clAssumedStackSizeForExternalCall;
112 STI.getTargetTriple().getOS() == Triple::AMDPAL) {
113 if (clAssumedStackSizeForDynamicSizeObjects.getNumOccurrences() == 0)
114 AssumedStackSizeForDynamicSizeObjects = 0;
115 if (clAssumedStackSizeForExternalCall.getNumOccurrences() == 0)
116 AssumedStackSizeForExternalCall = 0;
117 }
118
119 for (auto IT = po_begin(&CG); IT != End; ++IT) {
120 Function *F = IT->getFunction();
121 if (!F || F->isDeclaration())
122 continue;
123
125 assert(MF && "function must have been generated already");
126
127 auto CI =
128 CallGraphResourceInfo.insert(std::pair(F, SIFunctionResourceInfo()));
129 SIFunctionResourceInfo &Info = CI.first->second;
130 assert(CI.second && "should only be called once per function");
131 Info = analyzeResourceUsage(*MF, TM, AssumedStackSizeForDynamicSizeObjects,
132 AssumedStackSizeForExternalCall);
133 HasIndirectCall |= Info.HasIndirectCall;
134 }
135
136 // It's possible we have unreachable functions in the module which weren't
137 // visited by the PO traversal. Make sure we have some resource counts to
138 // report.
139 for (const auto &IT : CG) {
140 const Function *F = IT.first;
141 if (!F || F->isDeclaration())
142 continue;
143
144 auto CI =
145 CallGraphResourceInfo.insert(std::pair(F, SIFunctionResourceInfo()));
146 if (!CI.second) // Skip already visited functions
147 continue;
148
149 SIFunctionResourceInfo &Info = CI.first->second;
151 assert(MF && "function must have been generated already");
152 Info = analyzeResourceUsage(*MF, TM, AssumedStackSizeForDynamicSizeObjects,
153 AssumedStackSizeForExternalCall);
154 HasIndirectCall |= Info.HasIndirectCall;
155 }
156
157 if (HasIndirectCall)
158 propagateIndirectCallRegisterUsage();
159
160 return false;
161}
162
164AMDGPUResourceUsageAnalysis::analyzeResourceUsage(
165 const MachineFunction &MF, const TargetMachine &TM,
166 uint32_t AssumedStackSizeForDynamicSizeObjects,
167 uint32_t AssumedStackSizeForExternalCall) const {
168 SIFunctionResourceInfo Info;
169
171 const GCNSubtarget &ST = MF.getSubtarget<GCNSubtarget>();
172 const MachineFrameInfo &FrameInfo = MF.getFrameInfo();
173 const MachineRegisterInfo &MRI = MF.getRegInfo();
174 const SIInstrInfo *TII = ST.getInstrInfo();
175 const SIRegisterInfo &TRI = TII->getRegisterInfo();
176
177 Info.UsesFlatScratch = MRI.isPhysRegUsed(AMDGPU::FLAT_SCR_LO) ||
178 MRI.isPhysRegUsed(AMDGPU::FLAT_SCR_HI) ||
179 MRI.isLiveIn(MFI->getPreloadedReg(
181
182 // Even if FLAT_SCRATCH is implicitly used, it has no effect if flat
183 // instructions aren't used to access the scratch buffer. Inline assembly may
184 // need it though.
185 //
186 // If we only have implicit uses of flat_scr on flat instructions, it is not
187 // really needed.
188 if (Info.UsesFlatScratch && !MFI->getUserSGPRInfo().hasFlatScratchInit() &&
189 (!hasAnyNonFlatUseOfReg(MRI, *TII, AMDGPU::FLAT_SCR) &&
190 !hasAnyNonFlatUseOfReg(MRI, *TII, AMDGPU::FLAT_SCR_LO) &&
191 !hasAnyNonFlatUseOfReg(MRI, *TII, AMDGPU::FLAT_SCR_HI))) {
192 Info.UsesFlatScratch = false;
193 }
194
195 Info.PrivateSegmentSize = FrameInfo.getStackSize();
196
197 // Assume a big number if there are any unknown sized objects.
198 Info.HasDynamicallySizedStack = FrameInfo.hasVarSizedObjects();
199 if (Info.HasDynamicallySizedStack)
200 Info.PrivateSegmentSize += AssumedStackSizeForDynamicSizeObjects;
201
202 if (MFI->isStackRealigned())
203 Info.PrivateSegmentSize += FrameInfo.getMaxAlign().value();
204
205 Info.UsesVCC =
206 MRI.isPhysRegUsed(AMDGPU::VCC_LO) || MRI.isPhysRegUsed(AMDGPU::VCC_HI);
207
208 // If there are no calls, MachineRegisterInfo can tell us the used register
209 // count easily.
210 // A tail call isn't considered a call for MachineFrameInfo's purposes.
211 if (!FrameInfo.hasCalls() && !FrameInfo.hasTailCall()) {
212 MCPhysReg HighestVGPRReg = AMDGPU::NoRegister;
213 for (MCPhysReg Reg : reverse(AMDGPU::VGPR_32RegClass.getRegisters())) {
214 if (MRI.isPhysRegUsed(Reg)) {
215 HighestVGPRReg = Reg;
216 break;
217 }
218 }
219
220 if (ST.hasMAIInsts()) {
221 MCPhysReg HighestAGPRReg = AMDGPU::NoRegister;
222 for (MCPhysReg Reg : reverse(AMDGPU::AGPR_32RegClass.getRegisters())) {
223 if (MRI.isPhysRegUsed(Reg)) {
224 HighestAGPRReg = Reg;
225 break;
226 }
227 }
228 Info.NumAGPR = HighestAGPRReg == AMDGPU::NoRegister
229 ? 0
230 : TRI.getHWRegIndex(HighestAGPRReg) + 1;
231 }
232
233 MCPhysReg HighestSGPRReg = AMDGPU::NoRegister;
234 for (MCPhysReg Reg : reverse(AMDGPU::SGPR_32RegClass.getRegisters())) {
235 if (MRI.isPhysRegUsed(Reg)) {
236 HighestSGPRReg = Reg;
237 break;
238 }
239 }
240
241 // We found the maximum register index. They start at 0, so add one to get
242 // the number of registers.
243 Info.NumVGPR = HighestVGPRReg == AMDGPU::NoRegister
244 ? 0
245 : TRI.getHWRegIndex(HighestVGPRReg) + 1;
246 Info.NumExplicitSGPR = HighestSGPRReg == AMDGPU::NoRegister
247 ? 0
248 : TRI.getHWRegIndex(HighestSGPRReg) + 1;
249
250 return Info;
251 }
252
253 int32_t MaxVGPR = -1;
254 int32_t MaxAGPR = -1;
255 int32_t MaxSGPR = -1;
256 uint64_t CalleeFrameSize = 0;
257
258 for (const MachineBasicBlock &MBB : MF) {
259 for (const MachineInstr &MI : MBB) {
260 // TODO: Check regmasks? Do they occur anywhere except calls?
261 for (const MachineOperand &MO : MI.operands()) {
262 unsigned Width = 0;
263 bool IsSGPR = false;
264 bool IsAGPR = false;
265
266 if (!MO.isReg())
267 continue;
268
269 Register Reg = MO.getReg();
270 switch (Reg) {
271 case AMDGPU::EXEC:
272 case AMDGPU::EXEC_LO:
273 case AMDGPU::EXEC_HI:
274 case AMDGPU::SCC:
275 case AMDGPU::M0:
276 case AMDGPU::M0_LO16:
277 case AMDGPU::M0_HI16:
278 case AMDGPU::SRC_SHARED_BASE_LO:
279 case AMDGPU::SRC_SHARED_BASE:
280 case AMDGPU::SRC_SHARED_LIMIT_LO:
281 case AMDGPU::SRC_SHARED_LIMIT:
282 case AMDGPU::SRC_PRIVATE_BASE_LO:
283 case AMDGPU::SRC_PRIVATE_BASE:
284 case AMDGPU::SRC_PRIVATE_LIMIT_LO:
285 case AMDGPU::SRC_PRIVATE_LIMIT:
286 case AMDGPU::SRC_POPS_EXITING_WAVE_ID:
287 case AMDGPU::SGPR_NULL:
288 case AMDGPU::SGPR_NULL64:
289 case AMDGPU::MODE:
290 continue;
291
292 case AMDGPU::NoRegister:
293 assert(MI.isDebugInstr() &&
294 "Instruction uses invalid noreg register");
295 continue;
296
297 case AMDGPU::VCC:
298 case AMDGPU::VCC_LO:
299 case AMDGPU::VCC_HI:
300 case AMDGPU::VCC_LO_LO16:
301 case AMDGPU::VCC_LO_HI16:
302 case AMDGPU::VCC_HI_LO16:
303 case AMDGPU::VCC_HI_HI16:
304 Info.UsesVCC = true;
305 continue;
306
307 case AMDGPU::FLAT_SCR:
308 case AMDGPU::FLAT_SCR_LO:
309 case AMDGPU::FLAT_SCR_HI:
310 continue;
311
312 case AMDGPU::XNACK_MASK:
313 case AMDGPU::XNACK_MASK_LO:
314 case AMDGPU::XNACK_MASK_HI:
315 llvm_unreachable("xnack_mask registers should not be used");
316
317 case AMDGPU::LDS_DIRECT:
318 llvm_unreachable("lds_direct register should not be used");
319
320 case AMDGPU::TBA:
321 case AMDGPU::TBA_LO:
322 case AMDGPU::TBA_HI:
323 case AMDGPU::TMA:
324 case AMDGPU::TMA_LO:
325 case AMDGPU::TMA_HI:
326 llvm_unreachable("trap handler registers should not be used");
327
328 case AMDGPU::SRC_VCCZ:
329 llvm_unreachable("src_vccz register should not be used");
330
331 case AMDGPU::SRC_EXECZ:
332 llvm_unreachable("src_execz register should not be used");
333
334 case AMDGPU::SRC_SCC:
335 llvm_unreachable("src_scc register should not be used");
336
337 default:
338 break;
339 }
340
341 if (AMDGPU::SGPR_32RegClass.contains(Reg) ||
342 AMDGPU::SGPR_LO16RegClass.contains(Reg) ||
343 AMDGPU::SGPR_HI16RegClass.contains(Reg)) {
344 IsSGPR = true;
345 Width = 1;
346 } else if (AMDGPU::VGPR_32RegClass.contains(Reg) ||
347 AMDGPU::VGPR_16RegClass.contains(Reg)) {
348 IsSGPR = false;
349 Width = 1;
350 } else if (AMDGPU::AGPR_32RegClass.contains(Reg) ||
351 AMDGPU::AGPR_LO16RegClass.contains(Reg)) {
352 IsSGPR = false;
353 IsAGPR = true;
354 Width = 1;
355 } else if (AMDGPU::SGPR_64RegClass.contains(Reg)) {
356 IsSGPR = true;
357 Width = 2;
358 } else if (AMDGPU::VReg_64RegClass.contains(Reg)) {
359 IsSGPR = false;
360 Width = 2;
361 } else if (AMDGPU::AReg_64RegClass.contains(Reg)) {
362 IsSGPR = false;
363 IsAGPR = true;
364 Width = 2;
365 } else if (AMDGPU::VReg_96RegClass.contains(Reg)) {
366 IsSGPR = false;
367 Width = 3;
368 } else if (AMDGPU::SReg_96RegClass.contains(Reg)) {
369 IsSGPR = true;
370 Width = 3;
371 } else if (AMDGPU::AReg_96RegClass.contains(Reg)) {
372 IsSGPR = false;
373 IsAGPR = true;
374 Width = 3;
375 } else if (AMDGPU::SGPR_128RegClass.contains(Reg)) {
376 IsSGPR = true;
377 Width = 4;
378 } else if (AMDGPU::VReg_128RegClass.contains(Reg)) {
379 IsSGPR = false;
380 Width = 4;
381 } else if (AMDGPU::AReg_128RegClass.contains(Reg)) {
382 IsSGPR = false;
383 IsAGPR = true;
384 Width = 4;
385 } else if (AMDGPU::VReg_160RegClass.contains(Reg)) {
386 IsSGPR = false;
387 Width = 5;
388 } else if (AMDGPU::SReg_160RegClass.contains(Reg)) {
389 IsSGPR = true;
390 Width = 5;
391 } else if (AMDGPU::AReg_160RegClass.contains(Reg)) {
392 IsSGPR = false;
393 IsAGPR = true;
394 Width = 5;
395 } else if (AMDGPU::VReg_192RegClass.contains(Reg)) {
396 IsSGPR = false;
397 Width = 6;
398 } else if (AMDGPU::SReg_192RegClass.contains(Reg)) {
399 IsSGPR = true;
400 Width = 6;
401 } else if (AMDGPU::AReg_192RegClass.contains(Reg)) {
402 IsSGPR = false;
403 IsAGPR = true;
404 Width = 6;
405 } else if (AMDGPU::VReg_224RegClass.contains(Reg)) {
406 IsSGPR = false;
407 Width = 7;
408 } else if (AMDGPU::SReg_224RegClass.contains(Reg)) {
409 IsSGPR = true;
410 Width = 7;
411 } else if (AMDGPU::AReg_224RegClass.contains(Reg)) {
412 IsSGPR = false;
413 IsAGPR = true;
414 Width = 7;
415 } else if (AMDGPU::SReg_256RegClass.contains(Reg)) {
416 IsSGPR = true;
417 Width = 8;
418 } else if (AMDGPU::VReg_256RegClass.contains(Reg)) {
419 IsSGPR = false;
420 Width = 8;
421 } else if (AMDGPU::AReg_256RegClass.contains(Reg)) {
422 IsSGPR = false;
423 IsAGPR = true;
424 Width = 8;
425 } else if (AMDGPU::VReg_288RegClass.contains(Reg)) {
426 IsSGPR = false;
427 Width = 9;
428 } else if (AMDGPU::SReg_288RegClass.contains(Reg)) {
429 IsSGPR = true;
430 Width = 9;
431 } else if (AMDGPU::AReg_288RegClass.contains(Reg)) {
432 IsSGPR = false;
433 IsAGPR = true;
434 Width = 9;
435 } else if (AMDGPU::VReg_320RegClass.contains(Reg)) {
436 IsSGPR = false;
437 Width = 10;
438 } else if (AMDGPU::SReg_320RegClass.contains(Reg)) {
439 IsSGPR = true;
440 Width = 10;
441 } else if (AMDGPU::AReg_320RegClass.contains(Reg)) {
442 IsSGPR = false;
443 IsAGPR = true;
444 Width = 10;
445 } else if (AMDGPU::VReg_352RegClass.contains(Reg)) {
446 IsSGPR = false;
447 Width = 11;
448 } else if (AMDGPU::SReg_352RegClass.contains(Reg)) {
449 IsSGPR = true;
450 Width = 11;
451 } else if (AMDGPU::AReg_352RegClass.contains(Reg)) {
452 IsSGPR = false;
453 IsAGPR = true;
454 Width = 11;
455 } else if (AMDGPU::VReg_384RegClass.contains(Reg)) {
456 IsSGPR = false;
457 Width = 12;
458 } else if (AMDGPU::SReg_384RegClass.contains(Reg)) {
459 IsSGPR = true;
460 Width = 12;
461 } else if (AMDGPU::AReg_384RegClass.contains(Reg)) {
462 IsSGPR = false;
463 IsAGPR = true;
464 Width = 12;
465 } else if (AMDGPU::SReg_512RegClass.contains(Reg)) {
466 IsSGPR = true;
467 Width = 16;
468 } else if (AMDGPU::VReg_512RegClass.contains(Reg)) {
469 IsSGPR = false;
470 Width = 16;
471 } else if (AMDGPU::AReg_512RegClass.contains(Reg)) {
472 IsSGPR = false;
473 IsAGPR = true;
474 Width = 16;
475 } else if (AMDGPU::SReg_1024RegClass.contains(Reg)) {
476 IsSGPR = true;
477 Width = 32;
478 } else if (AMDGPU::VReg_1024RegClass.contains(Reg)) {
479 IsSGPR = false;
480 Width = 32;
481 } else if (AMDGPU::AReg_1024RegClass.contains(Reg)) {
482 IsSGPR = false;
483 IsAGPR = true;
484 Width = 32;
485 } else {
486 // We only expect TTMP registers or registers that do not belong to
487 // any RC.
488 assert((AMDGPU::TTMP_32RegClass.contains(Reg) ||
489 AMDGPU::TTMP_64RegClass.contains(Reg) ||
490 AMDGPU::TTMP_128RegClass.contains(Reg) ||
491 AMDGPU::TTMP_256RegClass.contains(Reg) ||
492 AMDGPU::TTMP_512RegClass.contains(Reg) ||
493 !TRI.getPhysRegBaseClass(Reg)) &&
494 "Unknown register class");
495 }
496 unsigned HWReg = TRI.getHWRegIndex(Reg);
497 int MaxUsed = HWReg + Width - 1;
498 if (IsSGPR) {
499 MaxSGPR = MaxUsed > MaxSGPR ? MaxUsed : MaxSGPR;
500 } else if (IsAGPR) {
501 MaxAGPR = MaxUsed > MaxAGPR ? MaxUsed : MaxAGPR;
502 } else {
503 MaxVGPR = MaxUsed > MaxVGPR ? MaxUsed : MaxVGPR;
504 }
505 }
506
507 if (MI.isCall()) {
508 // Pseudo used just to encode the underlying global. Is there a better
509 // way to track this?
510
511 const MachineOperand *CalleeOp =
512 TII->getNamedOperand(MI, AMDGPU::OpName::callee);
513
514 const Function *Callee = getCalleeFunction(*CalleeOp);
516 CallGraphResourceInfo.end();
517
518 // Avoid crashing on undefined behavior with an illegal call to a
519 // kernel. If a callsite's calling convention doesn't match the
520 // function's, it's undefined behavior. If the callsite calling
521 // convention does match, that would have errored earlier.
522 if (Callee && AMDGPU::isEntryFunctionCC(Callee->getCallingConv()))
523 report_fatal_error("invalid call to entry function");
524
525 bool IsIndirect = !Callee || Callee->isDeclaration();
526 if (!IsIndirect)
527 I = CallGraphResourceInfo.find(Callee);
528
529 // FIXME: Call site could have norecurse on it
530 if (!Callee || !Callee->doesNotRecurse()) {
531 Info.HasRecursion = true;
532
533 // TODO: If we happen to know there is no stack usage in the
534 // callgraph, we don't need to assume an infinitely growing stack.
535 if (!MI.isReturn()) {
536 // We don't need to assume an unknown stack size for tail calls.
537
538 // FIXME: This only benefits in the case where the kernel does not
539 // directly call the tail called function. If a kernel directly
540 // calls a tail recursive function, we'll assume maximum stack size
541 // based on the regular call instruction.
542 CalleeFrameSize = std::max(
543 CalleeFrameSize,
544 static_cast<uint64_t>(AssumedStackSizeForExternalCall));
545 }
546 }
547
548 if (IsIndirect || I == CallGraphResourceInfo.end()) {
549 CalleeFrameSize =
550 std::max(CalleeFrameSize,
551 static_cast<uint64_t>(AssumedStackSizeForExternalCall));
552
553 // Register usage of indirect calls gets handled later
554 Info.UsesVCC = true;
555 Info.UsesFlatScratch = ST.hasFlatAddressSpace();
556 Info.HasDynamicallySizedStack = true;
557 Info.HasIndirectCall = true;
558 } else {
559 // We force CodeGen to run in SCC order, so the callee's register
560 // usage etc. should be the cumulative usage of all callees.
561 MaxSGPR = std::max(I->second.NumExplicitSGPR - 1, MaxSGPR);
562 MaxVGPR = std::max(I->second.NumVGPR - 1, MaxVGPR);
563 MaxAGPR = std::max(I->second.NumAGPR - 1, MaxAGPR);
564 CalleeFrameSize =
565 std::max(I->second.PrivateSegmentSize, CalleeFrameSize);
566 Info.UsesVCC |= I->second.UsesVCC;
567 Info.UsesFlatScratch |= I->second.UsesFlatScratch;
568 Info.HasDynamicallySizedStack |= I->second.HasDynamicallySizedStack;
569 Info.HasRecursion |= I->second.HasRecursion;
570 Info.HasIndirectCall |= I->second.HasIndirectCall;
571 }
572 }
573 }
574 }
575
576 Info.NumExplicitSGPR = MaxSGPR + 1;
577 Info.NumVGPR = MaxVGPR + 1;
578 Info.NumAGPR = MaxAGPR + 1;
579 Info.PrivateSegmentSize += CalleeFrameSize;
580
581 return Info;
582}
583
584void AMDGPUResourceUsageAnalysis::propagateIndirectCallRegisterUsage() {
585 // Collect the maximum number of registers from non-hardware-entrypoints.
586 // All these functions are potential targets for indirect calls.
587 int32_t NonKernelMaxSGPRs = 0;
588 int32_t NonKernelMaxVGPRs = 0;
589 int32_t NonKernelMaxAGPRs = 0;
590
591 for (const auto &I : CallGraphResourceInfo) {
592 if (!AMDGPU::isEntryFunctionCC(I.getFirst()->getCallingConv())) {
593 auto &Info = I.getSecond();
594 NonKernelMaxSGPRs = std::max(NonKernelMaxSGPRs, Info.NumExplicitSGPR);
595 NonKernelMaxVGPRs = std::max(NonKernelMaxVGPRs, Info.NumVGPR);
596 NonKernelMaxAGPRs = std::max(NonKernelMaxAGPRs, Info.NumAGPR);
597 }
598 }
599
600 // Add register usage for functions with indirect calls.
601 // For calls to unknown functions, we assume the maximum register usage of
602 // all non-hardware-entrypoints in the current module.
603 for (auto &I : CallGraphResourceInfo) {
604 auto &Info = I.getSecond();
605 if (Info.HasIndirectCall) {
606 Info.NumExplicitSGPR = std::max(Info.NumExplicitSGPR, NonKernelMaxSGPRs);
607 Info.NumVGPR = std::max(Info.NumVGPR, NonKernelMaxVGPRs);
608 Info.NumAGPR = std::max(Info.NumAGPR, NonKernelMaxAGPRs);
609 }
610 }
611}
unsigned const MachineRegisterInfo * MRI
aarch64 promote const
static cl::opt< uint32_t > clAssumedStackSizeForDynamicSizeObjects("amdgpu-assume-dynamic-stack-object-size", cl::desc("Assumed extra stack use if there are any " "variable sized objects (in bytes)"), cl::Hidden, cl::init(4096))
static bool hasAnyNonFlatUseOfReg(const MachineRegisterInfo &MRI, const SIInstrInfo &TII, unsigned Reg)
static cl::opt< uint32_t > clAssumedStackSizeForExternalCall("amdgpu-assume-external-call-stack-size", cl::desc("Assumed stack use of any external call (in bytes)"), cl::Hidden, cl::init(16384))
#define DEBUG_TYPE
Analyzes how many registers and other resources are used by functions.
MachineBasicBlock & MBB
static cl::opt< ITMode > IT(cl::desc("IT block support"), cl::Hidden, cl::init(DefaultIT), cl::values(clEnumValN(DefaultIT, "arm-default-it", "Generate any type of IT block"), clEnumValN(RestrictedIT, "arm-restrict-it", "Disallow complex IT blocks")))
Analysis containing CSE Info
Definition: CSEInfo.cpp:27
This file provides interfaces used to build and manipulate a call graph, which is a very useful tool ...
bool End
Definition: ELF_riscv.cpp:480
AMD GCN specific subclass of TargetSubtarget.
const HexagonInstrInfo * TII
IRTranslator LLVM IR MI
#define F(x, y, z)
Definition: MD5.cpp:55
#define I(x, y, z)
Definition: MD5.cpp:58
unsigned const TargetRegisterInfo * TRI
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
Definition: PassSupport.h:38
This file builds on the ADT/GraphTraits.h file to build a generic graph post order iterator.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Target-Independent Code Generator Pass Configuration Options pass.
static bool contains(SmallPtrSetImpl< ConstantExpr * > &Cache, ConstantExpr *Expr, Constant *C)
Definition: Value.cpp:469
The basic data container for the call graph of a Module of IR.
Definition: CallGraph.h:71
This class represents an Operation in the Expression.
Generic base class for all target subtargets.
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
Representation of each machine instruction.
Definition: MachineInstr.h:69
This class contains meta information specific to a module.
MachineFunction * getMachineFunction(const Function &F) const
Returns the MachineFunction associated to IR function F if there is one, otherwise nullptr.
MachineOperand class - Representation of each machine instruction operand.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
Wrapper class representing virtual and physical registers.
Definition: Register.h:19
This class keeps track of the SPI_SP_INPUT_ADDR config register, which tells the hardware which inter...
GCNUserSGPRUsageInfo & getUserSGPRInfo()
MCRegister getPreloadedReg(AMDGPUFunctionArgInfo::PreloadedValue Value) const
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:77
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
unsigned getNumExtraSGPRs(const MCSubtargetInfo *STI, bool VCCUsed, bool FlatScrUsed, bool XNACKUsed)
int32_t getTotalNumVGPRs(bool has90AInsts, int32_t ArgNumAGPR, int32_t ArgNumVGPR)
bool isEntryFunctionCC(CallingConv::ID CC)
unsigned getAMDHSACodeObjectVersion(const Module &M)
Reg
All possible values of the reg field in the ModR/M byte.
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:443
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
char & AMDGPUResourceUsageAnalysisID
po_iterator< T > po_begin(const T &G)
auto reverse(ContainerTy &&C)
Definition: STLExtras.h:419
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:167
po_iterator< T > po_end(const T &G)
bool runOnModule(Module &M) override
runOnModule - Virtual method overriden by subclasses to process the module being operated on.