LLVM 20.0.0git
AMDGPUMCExpr.cpp
Go to the documentation of this file.
1//===- AMDGPUMCExpr.cpp - AMDGPU specific MC expression classes -----------===//
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#include "AMDGPUMCExpr.h"
10#include "GCNSubtarget.h"
12#include "llvm/IR/Function.h"
13#include "llvm/MC/MCAsmInfo.h"
14#include "llvm/MC/MCAssembler.h"
15#include "llvm/MC/MCContext.h"
16#include "llvm/MC/MCStreamer.h"
17#include "llvm/MC/MCSymbol.h"
18#include "llvm/MC/MCValue.h"
22#include <optional>
23
24using namespace llvm;
25using namespace llvm::AMDGPU;
26
27AMDGPUMCExpr::AMDGPUMCExpr(VariantKind Kind, ArrayRef<const MCExpr *> Args,
28 MCContext &Ctx)
29 : Kind(Kind), Ctx(Ctx) {
30 assert(Args.size() >= 1 && "Needs a minimum of one expression.");
31 assert(Kind != AGVK_None && "Cannot construct AMDGPUMCExpr of kind none.");
32
33 // Allocating the variadic arguments through the same allocation mechanism
34 // that the object itself is allocated with so they end up in the same memory.
35 //
36 // Will result in an asan failure if allocated on the heap through standard
37 // allocation (e.g., through SmallVector's grow).
38 RawArgs = static_cast<const MCExpr **>(
39 Ctx.allocate(sizeof(const MCExpr *) * Args.size()));
40 std::uninitialized_copy(Args.begin(), Args.end(), RawArgs);
41 this->Args = ArrayRef<const MCExpr *>(RawArgs, Args.size());
42}
43
44AMDGPUMCExpr::~AMDGPUMCExpr() { Ctx.deallocate(RawArgs); }
45
48 MCContext &Ctx) {
49 return new (Ctx) AMDGPUMCExpr(Kind, Args, Ctx);
50}
51
53 assert(Index < Args.size() && "Indexing out of bounds AMDGPUMCExpr sub-expr");
54 return Args[Index];
55}
56
58 switch (Kind) {
59 default:
60 llvm_unreachable("Unknown AMDGPUMCExpr kind.");
61 case AGVK_Or:
62 OS << "or(";
63 break;
64 case AGVK_Max:
65 OS << "max(";
66 break;
67 case AGVK_ExtraSGPRs:
68 OS << "extrasgprs(";
69 break;
71 OS << "totalnumvgprs(";
72 break;
73 case AGVK_AlignTo:
74 OS << "alignto(";
75 break;
76 case AGVK_Occupancy:
77 OS << "occupancy(";
78 break;
79 }
80 for (auto It = Args.begin(); It != Args.end(); ++It) {
81 (*It)->print(OS, MAI, /*InParens=*/false);
82 if ((It + 1) != Args.end())
83 OS << ", ";
84 }
85 OS << ')';
86}
87
88static int64_t op(AMDGPUMCExpr::VariantKind Kind, int64_t Arg1, int64_t Arg2) {
89 switch (Kind) {
90 default:
91 llvm_unreachable("Unknown AMDGPUMCExpr kind.");
93 return std::max(Arg1, Arg2);
95 return Arg1 | Arg2;
96 }
97}
98
99bool AMDGPUMCExpr::evaluateExtraSGPRs(MCValue &Res, const MCAssembler *Asm,
100 const MCFixup *Fixup) const {
101 auto TryGetMCExprValue = [&](const MCExpr *Arg, uint64_t &ConstantValue) {
102 MCValue MCVal;
103 if (!Arg->evaluateAsRelocatable(MCVal, Asm, Fixup) || !MCVal.isAbsolute())
104 return false;
105
106 ConstantValue = MCVal.getConstant();
107 return true;
108 };
109
110 assert(Args.size() == 3 &&
111 "AMDGPUMCExpr Argument count incorrect for ExtraSGPRs");
112 const MCSubtargetInfo *STI = Ctx.getSubtargetInfo();
113 uint64_t VCCUsed = 0, FlatScrUsed = 0, XNACKUsed = 0;
114
115 bool Success = TryGetMCExprValue(Args[2], XNACKUsed);
116
117 assert(Success && "Arguments 3 for ExtraSGPRs should be a known constant");
118 if (!Success || !TryGetMCExprValue(Args[0], VCCUsed) ||
119 !TryGetMCExprValue(Args[1], FlatScrUsed))
120 return false;
121
123 STI, (bool)VCCUsed, (bool)FlatScrUsed, (bool)XNACKUsed);
124 Res = MCValue::get(ExtraSGPRs);
125 return true;
126}
127
128bool AMDGPUMCExpr::evaluateTotalNumVGPR(MCValue &Res, const MCAssembler *Asm,
129 const MCFixup *Fixup) const {
130 auto TryGetMCExprValue = [&](const MCExpr *Arg, uint64_t &ConstantValue) {
131 MCValue MCVal;
132 if (!Arg->evaluateAsRelocatable(MCVal, Asm, Fixup) || !MCVal.isAbsolute())
133 return false;
134
135 ConstantValue = MCVal.getConstant();
136 return true;
137 };
138 assert(Args.size() == 2 &&
139 "AMDGPUMCExpr Argument count incorrect for TotalNumVGPRs");
140 const MCSubtargetInfo *STI = Ctx.getSubtargetInfo();
141 uint64_t NumAGPR = 0, NumVGPR = 0;
142
143 bool Has90AInsts = AMDGPU::isGFX90A(*STI);
144
145 if (!TryGetMCExprValue(Args[0], NumAGPR) ||
146 !TryGetMCExprValue(Args[1], NumVGPR))
147 return false;
148
149 uint64_t TotalNum = Has90AInsts && NumAGPR ? alignTo(NumVGPR, 4) + NumAGPR
150 : std::max(NumVGPR, NumAGPR);
151 Res = MCValue::get(TotalNum);
152 return true;
153}
154
155bool AMDGPUMCExpr::evaluateAlignTo(MCValue &Res, const MCAssembler *Asm,
156 const MCFixup *Fixup) const {
157 auto TryGetMCExprValue = [&](const MCExpr *Arg, uint64_t &ConstantValue) {
158 MCValue MCVal;
159 if (!Arg->evaluateAsRelocatable(MCVal, Asm, Fixup) || !MCVal.isAbsolute())
160 return false;
161
162 ConstantValue = MCVal.getConstant();
163 return true;
164 };
165
166 assert(Args.size() == 2 &&
167 "AMDGPUMCExpr Argument count incorrect for AlignTo");
168 uint64_t Value = 0, Align = 0;
169 if (!TryGetMCExprValue(Args[0], Value) || !TryGetMCExprValue(Args[1], Align))
170 return false;
171
173 return true;
174}
175
176bool AMDGPUMCExpr::evaluateOccupancy(MCValue &Res, const MCAssembler *Asm,
177 const MCFixup *Fixup) const {
178 auto TryGetMCExprValue = [&](const MCExpr *Arg, uint64_t &ConstantValue) {
179 MCValue MCVal;
180 if (!Arg->evaluateAsRelocatable(MCVal, Asm, Fixup) || !MCVal.isAbsolute())
181 return false;
182
183 ConstantValue = MCVal.getConstant();
184 return true;
185 };
186 assert(Args.size() == 7 &&
187 "AMDGPUMCExpr Argument count incorrect for Occupancy");
188 uint64_t InitOccupancy, MaxWaves, Granule, TargetTotalNumVGPRs, Generation,
190
191 bool Success = true;
192 Success &= TryGetMCExprValue(Args[0], MaxWaves);
193 Success &= TryGetMCExprValue(Args[1], Granule);
194 Success &= TryGetMCExprValue(Args[2], TargetTotalNumVGPRs);
195 Success &= TryGetMCExprValue(Args[3], Generation);
196 Success &= TryGetMCExprValue(Args[4], InitOccupancy);
197
198 assert(Success && "Arguments 1 to 5 for Occupancy should be known constants");
199
200 if (!Success || !TryGetMCExprValue(Args[5], NumSGPRs) ||
201 !TryGetMCExprValue(Args[6], NumVGPRs))
202 return false;
203
204 unsigned Occupancy = InitOccupancy;
205 if (NumSGPRs)
206 Occupancy = std::min(
208 NumSGPRs, MaxWaves,
209 static_cast<AMDGPUSubtarget::Generation>(Generation)));
210 if (NumVGPRs)
211 Occupancy = std::min(Occupancy,
213 NumVGPRs, Granule, MaxWaves, TargetTotalNumVGPRs));
214
215 Res = MCValue::get(Occupancy);
216 return true;
217}
218
220 const MCAssembler *Asm,
221 const MCFixup *Fixup) const {
222 std::optional<int64_t> Total;
223 switch (Kind) {
224 default:
225 break;
226 case AGVK_ExtraSGPRs:
227 return evaluateExtraSGPRs(Res, Asm, Fixup);
228 case AGVK_AlignTo:
229 return evaluateAlignTo(Res, Asm, Fixup);
231 return evaluateTotalNumVGPR(Res, Asm, Fixup);
232 case AGVK_Occupancy:
233 return evaluateOccupancy(Res, Asm, Fixup);
234 }
235
236 for (const MCExpr *Arg : Args) {
237 MCValue ArgRes;
238 if (!Arg->evaluateAsRelocatable(ArgRes, Asm, Fixup) || !ArgRes.isAbsolute())
239 return false;
240
241 if (!Total.has_value())
242 Total = ArgRes.getConstant();
243 Total = op(Kind, *Total, ArgRes.getConstant());
244 }
245
246 Res = MCValue::get(*Total);
247 return true;
248}
249
251 for (const MCExpr *Arg : Args)
252 Streamer.visitUsedExpr(*Arg);
253}
254
256 for (const MCExpr *Arg : Args) {
257 if (Arg->findAssociatedFragment())
258 return Arg->findAssociatedFragment();
259 }
260 return nullptr;
261}
262
263/// Allow delayed MCExpr resolve of ExtraSGPRs (in case VCCUsed or FlatScrUsed
264/// are unresolvable but needed for further MCExprs). Derived from
265/// implementation of IsaInfo::getNumExtraSGPRs in AMDGPUBaseInfo.cpp.
266///
268 const MCExpr *FlatScrUsed,
269 bool XNACKUsed,
270 MCContext &Ctx) {
271
272 return create(AGVK_ExtraSGPRs,
273 {VCCUsed, FlatScrUsed, MCConstantExpr::create(XNACKUsed, Ctx)},
274 Ctx);
275}
276
278 const MCExpr *NumVGPR,
279 MCContext &Ctx) {
280 return create(AGVK_TotalNumVGPRs, {NumAGPR, NumVGPR}, Ctx);
281}
282
283/// Mimics GCNSubtarget::computeOccupancy for MCExpr.
284///
285/// Remove dependency on GCNSubtarget and depend only only the necessary values
286/// for said occupancy computation. Should match computeOccupancy implementation
287/// without passing \p STM on.
289 const MCExpr *NumSGPRs,
290 const MCExpr *NumVGPRs,
291 const GCNSubtarget &STM,
292 MCContext &Ctx) {
293 unsigned MaxWaves = IsaInfo::getMaxWavesPerEU(&STM);
294 unsigned Granule = IsaInfo::getVGPRAllocGranule(&STM);
295 unsigned TargetTotalNumVGPRs = IsaInfo::getTotalNumVGPRs(&STM);
296 unsigned Generation = STM.getGeneration();
297
298 auto CreateExpr = [&Ctx](unsigned Value) {
299 return MCConstantExpr::create(Value, Ctx);
300 };
301
302 return create(AGVK_Occupancy,
303 {CreateExpr(MaxWaves), CreateExpr(Granule),
304 CreateExpr(TargetTotalNumVGPRs), CreateExpr(Generation),
305 CreateExpr(InitOcc), NumSGPRs, NumVGPRs},
306 Ctx);
307}
308
309static KnownBits fromOptionalToKnownBits(std::optional<bool> CompareResult) {
310 static constexpr unsigned BitWidth = 64;
311 const APInt True(BitWidth, 1);
312 const APInt False(BitWidth, 0);
313 if (CompareResult) {
314 return *CompareResult ? KnownBits::makeConstant(True)
316 }
317
318 KnownBits UnknownBool(/*BitWidth=*/1);
319 return UnknownBool.zext(BitWidth);
320}
321
323static void knownBitsMapHelper(const MCExpr *Expr, KnownBitsMap &KBM,
324 unsigned Depth = 0);
325
326static void binaryOpKnownBitsMapHelper(const MCExpr *Expr, KnownBitsMap &KBM,
327 unsigned Depth) {
328 static constexpr unsigned BitWidth = 64;
329 const MCBinaryExpr *BExpr = cast<MCBinaryExpr>(Expr);
330 const MCExpr *LHS = BExpr->getLHS();
331 const MCExpr *RHS = BExpr->getRHS();
332
333 knownBitsMapHelper(LHS, KBM, Depth + 1);
334 knownBitsMapHelper(RHS, KBM, Depth + 1);
335 KnownBits LHSKnown = KBM[LHS];
336 KnownBits RHSKnown = KBM[RHS];
337
338 switch (BExpr->getOpcode()) {
339 default:
340 KBM[Expr] = KnownBits(BitWidth);
341 return;
343 KBM[Expr] = KnownBits::add(LHSKnown, RHSKnown);
344 return;
346 KBM[Expr] = LHSKnown & RHSKnown;
347 return;
349 KBM[Expr] = KnownBits::sdiv(LHSKnown, RHSKnown);
350 return;
352 std::optional<bool> CompareRes = KnownBits::eq(LHSKnown, RHSKnown);
353 KBM[Expr] = fromOptionalToKnownBits(CompareRes);
354 return;
355 }
357 std::optional<bool> CompareRes = KnownBits::ne(LHSKnown, RHSKnown);
358 KBM[Expr] = fromOptionalToKnownBits(CompareRes);
359 return;
360 }
362 std::optional<bool> CompareRes = KnownBits::sgt(LHSKnown, RHSKnown);
363 KBM[Expr] = fromOptionalToKnownBits(CompareRes);
364 return;
365 }
367 std::optional<bool> CompareRes = KnownBits::sge(LHSKnown, RHSKnown);
368 KBM[Expr] = fromOptionalToKnownBits(CompareRes);
369 return;
370 }
372 std::optional<bool> CompareRes;
373 const APInt False(BitWidth, 0);
374 std::optional<bool> LHSBool =
375 KnownBits::ne(LHSKnown, KnownBits::makeConstant(False));
376 std::optional<bool> RHSBool =
377 KnownBits::ne(RHSKnown, KnownBits::makeConstant(False));
378 if (LHSBool && RHSBool)
379 CompareRes = *LHSBool && *RHSBool;
380 KBM[Expr] = fromOptionalToKnownBits(CompareRes);
381 return;
382 }
384 const APInt False(BitWidth, 0);
385 KnownBits Bits = LHSKnown | RHSKnown;
386 std::optional<bool> CompareRes =
388 KBM[Expr] = fromOptionalToKnownBits(CompareRes);
389 return;
390 }
392 std::optional<bool> CompareRes = KnownBits::slt(LHSKnown, RHSKnown);
393 KBM[Expr] = fromOptionalToKnownBits(CompareRes);
394 return;
395 }
397 std::optional<bool> CompareRes = KnownBits::sle(LHSKnown, RHSKnown);
398 KBM[Expr] = fromOptionalToKnownBits(CompareRes);
399 return;
400 }
402 KBM[Expr] = KnownBits::srem(LHSKnown, RHSKnown);
403 return;
405 KBM[Expr] = KnownBits::mul(LHSKnown, RHSKnown);
406 return;
408 KBM[Expr] = LHSKnown | RHSKnown;
409 return;
411 KBM[Expr] = KnownBits::shl(LHSKnown, RHSKnown);
412 return;
414 KBM[Expr] = KnownBits::ashr(LHSKnown, RHSKnown);
415 return;
417 KBM[Expr] = KnownBits::lshr(LHSKnown, RHSKnown);
418 return;
420 KBM[Expr] = KnownBits::sub(LHSKnown, RHSKnown);
421 return;
423 KBM[Expr] = LHSKnown ^ RHSKnown;
424 return;
425 }
426}
427
428static void unaryOpKnownBitsMapHelper(const MCExpr *Expr, KnownBitsMap &KBM,
429 unsigned Depth) {
430 static constexpr unsigned BitWidth = 64;
431 const MCUnaryExpr *UExpr = cast<MCUnaryExpr>(Expr);
432 knownBitsMapHelper(UExpr->getSubExpr(), KBM, Depth + 1);
433 KnownBits KB = KBM[UExpr->getSubExpr()];
434
435 switch (UExpr->getOpcode()) {
436 default:
437 KBM[Expr] = KnownBits(BitWidth);
438 return;
440 KB.makeNegative();
441 KBM[Expr] = KB;
442 return;
443 }
446 AllOnes.setAllOnes();
447 KBM[Expr] = KB ^ AllOnes;
448 return;
449 }
451 KB.makeNonNegative();
452 KBM[Expr] = KB;
453 return;
454 }
455 }
456}
457
458static void targetOpKnownBitsMapHelper(const MCExpr *Expr, KnownBitsMap &KBM,
459 unsigned Depth) {
460 static constexpr unsigned BitWidth = 64;
461 const AMDGPUMCExpr *AGVK = cast<AMDGPUMCExpr>(Expr);
462
463 switch (AGVK->getKind()) {
464 default:
465 KBM[Expr] = KnownBits(BitWidth);
466 return;
468 knownBitsMapHelper(AGVK->getSubExpr(0), KBM, Depth + 1);
469 KnownBits KB = KBM[AGVK->getSubExpr(0)];
470 for (const MCExpr *Arg : AGVK->getArgs()) {
471 knownBitsMapHelper(Arg, KBM, Depth + 1);
472 KB |= KBM[Arg];
473 }
474 KBM[Expr] = KB;
475 return;
476 }
478 knownBitsMapHelper(AGVK->getSubExpr(0), KBM, Depth + 1);
479 KnownBits KB = KBM[AGVK->getSubExpr(0)];
480 for (const MCExpr *Arg : AGVK->getArgs()) {
481 knownBitsMapHelper(Arg, KBM, Depth + 1);
482 KB = KnownBits::umax(KB, KBM[Arg]);
483 }
484 KBM[Expr] = KB;
485 return;
486 }
491 int64_t Val;
492 if (AGVK->evaluateAsAbsolute(Val)) {
493 APInt APValue(BitWidth, Val);
494 KBM[Expr] = KnownBits::makeConstant(APValue);
495 return;
496 }
497 KBM[Expr] = KnownBits(BitWidth);
498 return;
499 }
500 }
501}
502
503static void knownBitsMapHelper(const MCExpr *Expr, KnownBitsMap &KBM,
504 unsigned Depth) {
505 static constexpr unsigned BitWidth = 64;
506
507 int64_t Val;
508 if (Expr->evaluateAsAbsolute(Val)) {
509 APInt APValue(BitWidth, Val, /*isSigned=*/true);
510 KBM[Expr] = KnownBits::makeConstant(APValue);
511 return;
512 }
513
514 if (Depth == 16) {
515 KBM[Expr] = KnownBits(BitWidth);
516 return;
517 }
518
519 switch (Expr->getKind()) {
522 return;
523 }
525 const MCConstantExpr *CE = cast<MCConstantExpr>(Expr);
526 APInt APValue(BitWidth, CE->getValue(), /*isSigned=*/true);
527 KBM[Expr] = KnownBits::makeConstant(APValue);
528 return;
529 }
531 const MCSymbolRefExpr *RExpr = cast<MCSymbolRefExpr>(Expr);
532 const MCSymbol &Sym = RExpr->getSymbol();
533 if (!Sym.isVariable()) {
534 KBM[Expr] = KnownBits(BitWidth);
535 return;
536 }
537
538 // Variable value retrieval is not for actual use but only for knownbits
539 // analysis.
540 knownBitsMapHelper(Sym.getVariableValue(/*SetUsed=*/false), KBM, Depth + 1);
541 KBM[Expr] = KBM[Sym.getVariableValue(/*SetUsed=*/false)];
542 return;
543 }
546 return;
547 }
550 return;
551 }
552 }
553}
554
555static const MCExpr *tryFoldHelper(const MCExpr *Expr, KnownBitsMap &KBM,
556 MCContext &Ctx) {
557 if (!KBM.count(Expr))
558 return Expr;
559
560 auto ValueCheckKnownBits = [](KnownBits &KB, unsigned Value) -> bool {
561 if (!KB.isConstant())
562 return false;
563
564 return Value == KB.getConstant();
565 };
566
567 if (Expr->getKind() == MCExpr::ExprKind::Constant)
568 return Expr;
569
570 // Resolving unary operations to constants may make the value more ambiguous.
571 // For example, `~62` becomes `-63`; however, to me it's more ambiguous if a
572 // bit mask value is represented through a negative number.
573 if (Expr->getKind() != MCExpr::ExprKind::Unary) {
574 if (KBM[Expr].isConstant()) {
575 APInt ConstVal = KBM[Expr].getConstant();
576 return MCConstantExpr::create(ConstVal.getSExtValue(), Ctx);
577 }
578
579 int64_t EvalValue;
580 if (Expr->evaluateAsAbsolute(EvalValue))
581 return MCConstantExpr::create(EvalValue, Ctx);
582 }
583
584 switch (Expr->getKind()) {
585 default:
586 return Expr;
588 const MCBinaryExpr *BExpr = cast<MCBinaryExpr>(Expr);
589 const MCExpr *LHS = BExpr->getLHS();
590 const MCExpr *RHS = BExpr->getRHS();
591
592 switch (BExpr->getOpcode()) {
593 default:
594 return Expr;
596 if (ValueCheckKnownBits(KBM[RHS], 0))
597 return tryFoldHelper(LHS, KBM, Ctx);
598 break;
599 }
602 if (ValueCheckKnownBits(KBM[LHS], 0))
603 return tryFoldHelper(RHS, KBM, Ctx);
604 if (ValueCheckKnownBits(KBM[RHS], 0))
605 return tryFoldHelper(LHS, KBM, Ctx);
606 break;
607 }
609 if (ValueCheckKnownBits(KBM[LHS], 1))
610 return tryFoldHelper(RHS, KBM, Ctx);
611 if (ValueCheckKnownBits(KBM[RHS], 1))
612 return tryFoldHelper(LHS, KBM, Ctx);
613 break;
614 }
618 if (ValueCheckKnownBits(KBM[RHS], 0))
619 return tryFoldHelper(LHS, KBM, Ctx);
620 if (ValueCheckKnownBits(KBM[LHS], 0))
621 return MCConstantExpr::create(0, Ctx);
622 break;
623 }
625 if (ValueCheckKnownBits(KBM[LHS], 0) || ValueCheckKnownBits(KBM[RHS], 0))
626 return MCConstantExpr::create(0, Ctx);
627 break;
628 }
629 }
630 const MCExpr *NewLHS = tryFoldHelper(LHS, KBM, Ctx);
631 const MCExpr *NewRHS = tryFoldHelper(RHS, KBM, Ctx);
632 if (NewLHS != LHS || NewRHS != RHS)
633 return MCBinaryExpr::create(BExpr->getOpcode(), NewLHS, NewRHS, Ctx,
634 BExpr->getLoc());
635 return Expr;
636 }
638 const MCUnaryExpr *UExpr = cast<MCUnaryExpr>(Expr);
639 const MCExpr *SubExpr = UExpr->getSubExpr();
640 const MCExpr *NewSubExpr = tryFoldHelper(SubExpr, KBM, Ctx);
641 if (SubExpr != NewSubExpr)
642 return MCUnaryExpr::create(UExpr->getOpcode(), NewSubExpr, Ctx,
643 UExpr->getLoc());
644 return Expr;
645 }
647 const AMDGPUMCExpr *AGVK = cast<AMDGPUMCExpr>(Expr);
649 bool Changed = false;
650 for (const MCExpr *Arg : AGVK->getArgs()) {
651 const MCExpr *NewArg = tryFoldHelper(Arg, KBM, Ctx);
652 NewArgs.push_back(NewArg);
653 Changed |= Arg != NewArg;
654 }
655 return Changed ? AMDGPUMCExpr::create(AGVK->getKind(), NewArgs, Ctx) : Expr;
656 }
657 }
658 return Expr;
659}
660
662 MCContext &Ctx) {
663 KnownBitsMap KBM;
664 knownBitsMapHelper(Expr, KBM);
665 const MCExpr *NewExpr = tryFoldHelper(Expr, KBM, Ctx);
666
667 return Expr != NewExpr ? NewExpr : Expr;
668}
669
671 const MCAsmInfo *MAI) {
672 int64_t Val;
673 if (Expr->evaluateAsAbsolute(Val)) {
674 OS << Val;
675 return;
676 }
677
678 Expr->print(OS, MAI);
679}
#define Success
static bool isConstant(const MachineInstr &MI)
static void targetOpKnownBitsMapHelper(const MCExpr *Expr, KnownBitsMap &KBM, unsigned Depth)
static void unaryOpKnownBitsMapHelper(const MCExpr *Expr, KnownBitsMap &KBM, unsigned Depth)
static KnownBits fromOptionalToKnownBits(std::optional< bool > CompareResult)
static void binaryOpKnownBitsMapHelper(const MCExpr *Expr, KnownBitsMap &KBM, unsigned Depth)
static const MCExpr * tryFoldHelper(const MCExpr *Expr, KnownBitsMap &KBM, MCContext &Ctx)
static void knownBitsMapHelper(const MCExpr *Expr, KnownBitsMap &KBM, unsigned Depth=0)
This file defines the BumpPtrAllocator interface.
Symbol * Sym
Definition: ELF_riscv.cpp:479
AMD GCN specific subclass of TargetSubtarget.
#define op(i)
PowerPC TLS Dynamic Call Fixup
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
raw_pwrite_stream & OS
Value * RHS
Value * LHS
AMDGPU target specific MCExpr operations.
Definition: AMDGPUMCExpr.h:30
ArrayRef< const MCExpr * > getArgs() const
Definition: AMDGPUMCExpr.h:93
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
VariantKind getKind() const
Definition: AMDGPUMCExpr.h:94
Class for arbitrary precision integers.
Definition: APInt.h:78
int64_t getSExtValue() const
Get sign extended value.
Definition: APInt.h:1522
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
Definition: DenseMap.h:151
Generation getGeneration() const
Definition: GCNSubtarget.h:317
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition: MCAsmInfo.h:56
Binary assembler expressions.
Definition: MCExpr.h:488
const MCExpr * getLHS() const
Get the left-hand side expression of the binary operator.
Definition: MCExpr.h:635
const MCExpr * getRHS() const
Get the right-hand side expression of the binary operator.
Definition: MCExpr.h:638
Opcode getOpcode() const
Get the kind of this binary expression.
Definition: MCExpr.h:632
static const MCBinaryExpr * create(Opcode Op, const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx, SMLoc Loc=SMLoc())
Definition: MCExpr.cpp:182
@ Div
Signed division.
Definition: MCExpr.h:493
@ Shl
Shift left.
Definition: MCExpr.h:510
@ AShr
Arithmetic shift right.
Definition: MCExpr.h:511
@ LShr
Logical shift right.
Definition: MCExpr.h:512
@ GTE
Signed greater than or equal comparison (result is either 0 or some target-specific non-zero value).
Definition: MCExpr.h:497
@ EQ
Equality comparison.
Definition: MCExpr.h:494
@ Sub
Subtraction.
Definition: MCExpr.h:513
@ Mul
Multiplication.
Definition: MCExpr.h:506
@ GT
Signed greater than comparison (result is either 0 or some target-specific non-zero value)
Definition: MCExpr.h:495
@ Mod
Signed remainder.
Definition: MCExpr.h:505
@ And
Bitwise and.
Definition: MCExpr.h:492
@ Or
Bitwise or.
Definition: MCExpr.h:508
@ Xor
Bitwise exclusive or.
Definition: MCExpr.h:514
@ LAnd
Logical and.
Definition: MCExpr.h:499
@ LOr
Logical or.
Definition: MCExpr.h:500
@ LT
Signed less than comparison (result is either 0 or some target-specific non-zero value).
Definition: MCExpr.h:501
@ Add
Addition.
Definition: MCExpr.h:491
@ LTE
Signed less than or equal comparison (result is either 0 or some target-specific non-zero value).
Definition: MCExpr.h:503
@ NE
Inequality comparison.
Definition: MCExpr.h:507
static const MCConstantExpr * create(int64_t Value, MCContext &Ctx, bool PrintInHex=false, unsigned SizeInBytes=0)
Definition: MCExpr.cpp:193
Context object for machine code objects.
Definition: MCContext.h:83
void * allocate(unsigned Size, unsigned Align=8)
Definition: MCContext.h:816
void deallocate(void *Ptr)
Definition: MCContext.h:820
const MCSubtargetInfo * getSubtargetInfo() const
Definition: MCContext.h:418
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:34
bool evaluateAsAbsolute(int64_t &Res, const MCAssembler &Asm, const SectionAddrMap &Addrs) const
Try to evaluate the expression to an absolute value.
Definition: MCExpr.cpp:550
@ Unary
Unary expressions.
Definition: MCExpr.h:40
@ Constant
Constant expressions.
Definition: MCExpr.h:38
@ SymbolRef
References to labels and assigned expressions.
Definition: MCExpr.h:39
@ Target
Target specific expression.
Definition: MCExpr.h:41
@ Binary
Binary expressions.
Definition: MCExpr.h:37
bool evaluateAsRelocatable(MCValue &Res, const MCAssembler *Asm, const MCFixup *Fixup) const
Try to evaluate the expression to a relocatable value, i.e.
Definition: MCExpr.cpp:788
void print(raw_ostream &OS, const MCAsmInfo *MAI, bool InParens=false) const
Definition: MCExpr.cpp:40
MCFragment * findAssociatedFragment() const
Find the "associated section" for this expression, which is currently defined as the absolute section...
Definition: MCExpr.cpp:1029
ExprKind getKind() const
Definition: MCExpr.h:78
SMLoc getLoc() const
Definition: MCExpr.h:79
Encode information on a single operation to perform on a byte sequence (e.g., an encoded instruction)...
Definition: MCFixup.h:71
Streaming machine code generation interface.
Definition: MCStreamer.h:213
void visitUsedExpr(const MCExpr &Expr)
Generic base class for all target subtargets.
Represent a reference to a symbol from inside an expression.
Definition: MCExpr.h:188
const MCSymbol & getSymbol() const
Definition: MCExpr.h:406
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
Unary assembler expressions.
Definition: MCExpr.h:432
Opcode getOpcode() const
Get the kind of this unary expression.
Definition: MCExpr.h:475
static const MCUnaryExpr * create(Opcode Op, const MCExpr *Expr, MCContext &Ctx, SMLoc Loc=SMLoc())
Definition: MCExpr.cpp:188
@ Minus
Unary minus.
Definition: MCExpr.h:436
@ Plus
Unary plus.
Definition: MCExpr.h:438
@ Not
Bitwise negation.
Definition: MCExpr.h:437
const MCExpr * getSubExpr() const
Get the child of this unary expression.
Definition: MCExpr.h:478
This represents an "assembler immediate".
Definition: MCValue.h:36
int64_t getConstant() const
Definition: MCValue.h:43
static MCValue get(const MCSymbolRefExpr *SymA, const MCSymbolRefExpr *SymB=nullptr, int64_t Val=0, uint32_t RefKind=0)
Definition: MCValue.h:59
bool isAbsolute() const
Is this an absolute (as opposed to relocatable) value.
Definition: MCValue.h:49
void push_back(const T &Elt)
Definition: SmallVector.h:427
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1210
LLVM Value Representation.
Definition: Value.h:74
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
#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)
void printAMDGPUMCExpr(const MCExpr *Expr, raw_ostream &OS, const MCAsmInfo *MAI)
bool isGFX90A(const MCSubtargetInfo &STI)
const MCExpr * foldAMDGPUMCExpr(const MCExpr *Expr, MCContext &Ctx)
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
Definition: Alignment.h:155
constexpr unsigned BitWidth
Definition: BitmaskEnum.h:191
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39
static KnownBits makeConstant(const APInt &C)
Create known bits from a known constant.
Definition: KnownBits.h:290
static std::optional< bool > eq(const KnownBits &LHS, const KnownBits &RHS)
Determine if these known bits always give the same ICMP_EQ result.
Definition: KnownBits.cpp:488
void makeNonNegative()
Make this value non-negative.
Definition: KnownBits.h:113
static KnownBits ashr(const KnownBits &LHS, const KnownBits &RHS, bool ShAmtNonZero=false, bool Exact=false)
Compute known bits for ashr(LHS, RHS).
Definition: KnownBits.cpp:428
static std::optional< bool > ne(const KnownBits &LHS, const KnownBits &RHS)
Determine if these known bits always give the same ICMP_NE result.
Definition: KnownBits.cpp:496
void makeNegative()
Make this value negative.
Definition: KnownBits.h:108
static std::optional< bool > sge(const KnownBits &LHS, const KnownBits &RHS)
Determine if these known bits always give the same ICMP_SGE result.
Definition: KnownBits.cpp:536
static KnownBits umax(const KnownBits &LHS, const KnownBits &RHS)
Compute known bits for umax(LHS, RHS).
Definition: KnownBits.cpp:178
KnownBits zext(unsigned BitWidth) const
Return known bits for a zero extension of the value we're tracking.
Definition: KnownBits.h:161
bool isConstant() const
Returns true if we know the value of all bits.
Definition: KnownBits.h:50
static KnownBits lshr(const KnownBits &LHS, const KnownBits &RHS, bool ShAmtNonZero=false, bool Exact=false)
Compute known bits for lshr(LHS, RHS).
Definition: KnownBits.cpp:370
static KnownBits add(const KnownBits &LHS, const KnownBits &RHS, bool NSW=false, bool NUW=false)
Compute knownbits resulting from addition of LHS and RHS.
Definition: KnownBits.h:333
static KnownBits srem(const KnownBits &LHS, const KnownBits &RHS)
Compute known bits for srem(LHS, RHS).
Definition: KnownBits.cpp:1059
static std::optional< bool > slt(const KnownBits &LHS, const KnownBits &RHS)
Determine if these known bits always give the same ICMP_SLT result.
Definition: KnownBits.cpp:542
static KnownBits sdiv(const KnownBits &LHS, const KnownBits &RHS, bool Exact=false)
Compute known bits for sdiv(LHS, RHS).
Definition: KnownBits.cpp:946
static KnownBits sub(const KnownBits &LHS, const KnownBits &RHS, bool NSW=false, bool NUW=false)
Compute knownbits resulting from subtraction of LHS and RHS.
Definition: KnownBits.h:339
static KnownBits mul(const KnownBits &LHS, const KnownBits &RHS, bool NoUndefSelfMultiply=false)
Compute known bits resulting from multiplying LHS and RHS.
Definition: KnownBits.cpp:797
static std::optional< bool > sle(const KnownBits &LHS, const KnownBits &RHS)
Determine if these known bits always give the same ICMP_SLE result.
Definition: KnownBits.cpp:546
static std::optional< bool > sgt(const KnownBits &LHS, const KnownBits &RHS)
Determine if these known bits always give the same ICMP_SGT result.
Definition: KnownBits.cpp:526
static KnownBits shl(const KnownBits &LHS, const KnownBits &RHS, bool NUW=false, bool NSW=false, bool ShAmtNonZero=false)
Compute known bits for shl(LHS, RHS).
Definition: KnownBits.cpp:285
const APInt & getConstant() const
Returns the value when all bits have a known value.
Definition: KnownBits.h:56