LLVM 23.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"
11#include "llvm/MC/MCAsmInfo.h"
12#include "llvm/MC/MCAssembler.h"
13#include "llvm/MC/MCContext.h"
14#include "llvm/MC/MCStreamer.h"
15#include "llvm/MC/MCSymbol.h"
16#include "llvm/MC/MCValue.h"
19#include <functional>
20#include <optional>
21
22using namespace llvm;
23using namespace llvm::AMDGPU;
24
25AMDGPUMCExpr::AMDGPUMCExpr(VariantKind Kind, ArrayRef<const MCExpr *> Args,
26 MCContext &Ctx)
27 : Kind(Kind), Ctx(Ctx) {
28 assert(Args.size() >= 1 && "Needs a minimum of one expression.");
29 assert(Kind != AGVK_None && "Cannot construct AMDGPUMCExpr of kind none.");
30
31 // Allocating the variadic arguments through the same allocation mechanism
32 // that the object itself is allocated with so they end up in the same memory.
33 //
34 // Will result in an asan failure if allocated on the heap through standard
35 // allocation (e.g., through SmallVector's grow).
36 RawArgs = static_cast<const MCExpr **>(
37 Ctx.allocate(sizeof(const MCExpr *) * Args.size()));
38 llvm::uninitialized_copy(Args, RawArgs);
39 this->Args = ArrayRef<const MCExpr *>(RawArgs, Args.size());
40}
41
42AMDGPUMCExpr::~AMDGPUMCExpr() { Ctx.deallocate(RawArgs); }
43
44const AMDGPUMCExpr *AMDGPUMCExpr::create(VariantKind Kind,
46 MCContext &Ctx) {
47 return new (Ctx) AMDGPUMCExpr(Kind, Args, Ctx);
48}
49
50const MCExpr *AMDGPUMCExpr::getSubExpr(size_t Index) const {
51 assert(Index < Args.size() && "Indexing out of bounds AMDGPUMCExpr sub-expr");
52 return Args[Index];
53}
54
55void AMDGPUMCExpr::printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const {
56 switch (Kind) {
57 default:
58 llvm_unreachable("Unknown AMDGPUMCExpr kind.");
59 case AGVK_Or:
60 OS << "or(";
61 break;
62 case AGVK_Max:
63 OS << "max(";
64 break;
65 case AGVK_ExtraSGPRs:
66 OS << "extrasgprs(";
67 break;
69 OS << "totalnumvgprs(";
70 break;
71 case AGVK_AlignTo:
72 OS << "alignto(";
73 break;
74 case AGVK_Occupancy:
75 OS << "occupancy(";
76 break;
77 case AGVK_Lit:
78 OS << "lit(";
79 break;
80 case AGVK_Lit64:
81 OS << "lit64(";
82 break;
83 }
84 for (const auto *It = Args.begin(); It != Args.end(); ++It) {
85 MAI->printExpr(OS, **It);
86 if ((It + 1) != Args.end())
87 OS << ", ";
88 }
89 OS << ')';
90}
91
92static int64_t op(AMDGPUMCExpr::VariantKind Kind, int64_t Arg1, int64_t Arg2) {
93 switch (Kind) {
94 default:
95 llvm_unreachable("Unknown AMDGPUMCExpr kind.");
97 return std::max(Arg1, Arg2);
99 return Arg1 | Arg2;
100 }
101}
102
103static bool
105 std::initializer_list<std::reference_wrapper<uint64_t>> Vals) {
106 return llvm::all_of(llvm::zip_equal(Exprs, Vals), [&](const auto &Pair) {
107 auto [Expr, ValRef] = Pair;
108 uint64_t &Val = ValRef.get();
109 MCValue MCVal;
110 if (!Expr->evaluateAsRelocatable(MCVal, Asm) || !MCVal.isAbsolute())
111 return false;
112 Val = MCVal.getConstant();
113 return true;
114 });
115}
116
117bool AMDGPUMCExpr::evaluateExtraSGPRs(MCValue &Res,
118 const MCAssembler *Asm) const {
119 assert(Args.size() == 3 &&
120 "AMDGPUMCExpr Argument count incorrect for ExtraSGPRs");
121 const MCSubtargetInfo *STI = Ctx.getSubtargetInfo();
122 uint64_t VCCUsed = 0, FlatScrUsed = 0, XNACKUsed = 0;
123
124 if (!evaluateMCExprs(Args, Asm, {VCCUsed, FlatScrUsed, XNACKUsed}))
125 return false;
126
127 uint64_t ExtraSGPRs = IsaInfo::getNumExtraSGPRs(
128 STI, (bool)VCCUsed, (bool)FlatScrUsed, (bool)XNACKUsed);
129 Res = MCValue::get(ExtraSGPRs);
130 return true;
131}
132
133bool AMDGPUMCExpr::evaluateTotalNumVGPR(MCValue &Res,
134 const MCAssembler *Asm) const {
135 assert(Args.size() == 2 &&
136 "AMDGPUMCExpr Argument count incorrect for TotalNumVGPRs");
137 const MCSubtargetInfo *STI = Ctx.getSubtargetInfo();
138 uint64_t NumAGPR = 0, NumVGPR = 0;
139
140 bool Has90AInsts = AMDGPU::isGFX90A(*STI);
141
142 if (!evaluateMCExprs(Args, Asm, {NumAGPR, NumVGPR}))
143 return false;
144
145 uint64_t TotalNum = Has90AInsts && NumAGPR ? alignTo(NumVGPR, 4) + NumAGPR
146 : std::max(NumVGPR, NumAGPR);
147 Res = MCValue::get(TotalNum);
148 return true;
149}
150
151bool AMDGPUMCExpr::evaluateAlignTo(MCValue &Res, const MCAssembler *Asm) const {
152 assert(Args.size() == 2 &&
153 "AMDGPUMCExpr Argument count incorrect for AlignTo");
154 uint64_t Value = 0, Align = 0;
155 if (!evaluateMCExprs(Args, Asm, {Value, Align}))
156 return false;
157
158 Res = MCValue::get(alignTo(Value, Align));
159 return true;
160}
161
162bool AMDGPUMCExpr::evaluateOccupancy(MCValue &Res,
163 const MCAssembler *Asm) const {
164 assert(Args.size() == 7 &&
165 "AMDGPUMCExpr Argument count incorrect for Occupancy");
166 uint64_t InitOccupancy, MaxWaves, Granule, TargetTotalNumVGPRs, Generation,
168
170 Args.slice(0, 5), Asm,
171 {MaxWaves, Granule, TargetTotalNumVGPRs, Generation, InitOccupancy});
172
173 assert(Success && "Arguments 1 to 5 for Occupancy should be known constants");
174
175 if (!Success || !evaluateMCExprs(Args.slice(5, 2), Asm, {NumSGPRs, NumVGPRs}))
176 return false;
177
178 unsigned Occupancy = InitOccupancy;
179 if (NumSGPRs)
180 Occupancy = std::min(
182 NumSGPRs, MaxWaves,
183 static_cast<AMDGPUSubtarget::Generation>(Generation)));
184 if (NumVGPRs)
185 Occupancy = std::min(Occupancy,
187 NumVGPRs, Granule, MaxWaves, TargetTotalNumVGPRs));
188
189 Res = MCValue::get(Occupancy);
190 return true;
191}
192
194 const MCExpr *E) {
195 switch (E->getKind()) {
196 case MCExpr::Constant:
197 return false;
198 case MCExpr::Unary:
200 Sym, static_cast<const MCUnaryExpr *>(E)->getSubExpr());
201 case MCExpr::Binary: {
202 const MCBinaryExpr *BE = static_cast<const MCBinaryExpr *>(E);
203 return isSymbolUsedInExpression(Sym, BE->getLHS()) ||
205 }
206 case MCExpr::SymbolRef: {
207 const MCSymbol &S = static_cast<const MCSymbolRefExpr *>(E)->getSymbol();
208 if (S.isVariable())
210 return &S == Sym;
211 }
213 case MCExpr::Target: {
214 auto *TE = static_cast<const AMDGPUMCExpr *>(E);
215 for (const MCExpr *E : TE->getArgs())
216 if (isSymbolUsedInExpression(Sym, E))
217 return true;
218 return false;
219 }
220 }
221 llvm_unreachable("Unknown expr kind!");
222}
223
225 const MCAssembler *Asm) const {
226 std::optional<int64_t> Total;
227 switch (Kind) {
228 default:
229 break;
230 case AGVK_ExtraSGPRs:
231 return evaluateExtraSGPRs(Res, Asm);
232 case AGVK_AlignTo:
233 return evaluateAlignTo(Res, Asm);
235 return evaluateTotalNumVGPR(Res, Asm);
236 case AGVK_Occupancy:
237 return evaluateOccupancy(Res, Asm);
238 case AGVK_Lit:
239 case AGVK_Lit64:
240 return Args[0]->evaluateAsRelocatable(Res, Asm);
241 }
242
243 for (const MCExpr *Arg : Args) {
244 MCValue ArgRes;
245 if (!Arg->evaluateAsRelocatable(ArgRes, Asm) || !ArgRes.isAbsolute())
246 return false;
247
248 if (!Total.has_value())
249 Total = ArgRes.getConstant();
250 Total = op(Kind, *Total, ArgRes.getConstant());
251 }
252
253 Res = MCValue::get(*Total);
254 return true;
255}
256
258 for (const MCExpr *Arg : Args)
259 Streamer.visitUsedExpr(*Arg);
260}
261
263 for (const MCExpr *Arg : Args) {
264 if (Arg->findAssociatedFragment())
265 return Arg->findAssociatedFragment();
266 }
267 return nullptr;
268}
269
270/// Allow delayed MCExpr resolve of ExtraSGPRs (in case VCCUsed or FlatScrUsed
271/// are unresolvable but needed for further MCExprs). Derived from
272/// implementation of IsaInfo::getNumExtraSGPRs in AMDGPUBaseInfo.cpp.
273///
274const AMDGPUMCExpr *AMDGPUMCExpr::createExtraSGPRs(const MCExpr *VCCUsed,
275 const MCExpr *FlatScrUsed,
276 bool XNACKUsed,
277 MCContext &Ctx) {
278
279 return create(AGVK_ExtraSGPRs,
280 {VCCUsed, FlatScrUsed, MCConstantExpr::create(XNACKUsed, Ctx)},
281 Ctx);
282}
283
284const AMDGPUMCExpr *AMDGPUMCExpr::createTotalNumVGPR(const MCExpr *NumAGPR,
285 const MCExpr *NumVGPR,
286 MCContext &Ctx) {
287 return create(AGVK_TotalNumVGPRs, {NumAGPR, NumVGPR}, Ctx);
288}
289
290const AMDGPUMCExpr *AMDGPUMCExpr::createLit(LitModifier Lit, int64_t Value,
291 MCContext &Ctx) {
295 {MCConstantExpr::create(Value, Ctx, /*PrintInHex=*/true)}, Ctx);
296}
297
298static KnownBits fromOptionalToKnownBits(std::optional<bool> CompareResult) {
299 static constexpr unsigned BitWidth = 64;
300 const APInt True(BitWidth, 1);
301 const APInt False(BitWidth, 0);
302 if (CompareResult) {
303 return *CompareResult ? KnownBits::makeConstant(True)
305 }
306
307 KnownBits UnknownBool(/*BitWidth=*/1);
308 return UnknownBool.zext(BitWidth);
309}
310
312static void knownBitsMapHelper(const MCExpr *Expr, KnownBitsMap &KBM,
313 unsigned Depth = 0);
314
315static void binaryOpKnownBitsMapHelper(const MCExpr *Expr, KnownBitsMap &KBM,
316 unsigned Depth) {
317 static constexpr unsigned BitWidth = 64;
318 const MCBinaryExpr *BExpr = cast<MCBinaryExpr>(Expr);
319 const MCExpr *LHS = BExpr->getLHS();
320 const MCExpr *RHS = BExpr->getRHS();
321
322 knownBitsMapHelper(LHS, KBM, Depth + 1);
323 knownBitsMapHelper(RHS, KBM, Depth + 1);
324 KnownBits LHSKnown = KBM[LHS];
325 KnownBits RHSKnown = KBM[RHS];
326
327 switch (BExpr->getOpcode()) {
328 default:
329 KBM[Expr] = KnownBits(BitWidth);
330 return;
332 KBM[Expr] = KnownBits::add(LHSKnown, RHSKnown);
333 return;
335 KBM[Expr] = LHSKnown & RHSKnown;
336 return;
338 KBM[Expr] = KnownBits::sdiv(LHSKnown, RHSKnown);
339 return;
341 std::optional<bool> CompareRes = KnownBits::eq(LHSKnown, RHSKnown);
342 KBM[Expr] = fromOptionalToKnownBits(CompareRes);
343 return;
344 }
346 std::optional<bool> CompareRes = KnownBits::ne(LHSKnown, RHSKnown);
347 KBM[Expr] = fromOptionalToKnownBits(CompareRes);
348 return;
349 }
351 std::optional<bool> CompareRes = KnownBits::sgt(LHSKnown, RHSKnown);
352 KBM[Expr] = fromOptionalToKnownBits(CompareRes);
353 return;
354 }
356 std::optional<bool> CompareRes = KnownBits::sge(LHSKnown, RHSKnown);
357 KBM[Expr] = fromOptionalToKnownBits(CompareRes);
358 return;
359 }
361 std::optional<bool> CompareRes;
362 const APInt False(BitWidth, 0);
363 std::optional<bool> LHSBool =
364 KnownBits::ne(LHSKnown, KnownBits::makeConstant(False));
365 std::optional<bool> RHSBool =
366 KnownBits::ne(RHSKnown, KnownBits::makeConstant(False));
367 if (LHSBool && RHSBool)
368 CompareRes = *LHSBool && *RHSBool;
369 KBM[Expr] = fromOptionalToKnownBits(CompareRes);
370 return;
371 }
373 const APInt False(BitWidth, 0);
374 KnownBits Bits = LHSKnown | RHSKnown;
375 std::optional<bool> CompareRes =
377 KBM[Expr] = fromOptionalToKnownBits(CompareRes);
378 return;
379 }
381 std::optional<bool> CompareRes = KnownBits::slt(LHSKnown, RHSKnown);
382 KBM[Expr] = fromOptionalToKnownBits(CompareRes);
383 return;
384 }
386 std::optional<bool> CompareRes = KnownBits::sle(LHSKnown, RHSKnown);
387 KBM[Expr] = fromOptionalToKnownBits(CompareRes);
388 return;
389 }
391 KBM[Expr] = KnownBits::srem(LHSKnown, RHSKnown);
392 return;
394 KBM[Expr] = KnownBits::mul(LHSKnown, RHSKnown);
395 return;
397 KBM[Expr] = LHSKnown | RHSKnown;
398 return;
400 KBM[Expr] = KnownBits::shl(LHSKnown, RHSKnown);
401 return;
403 KBM[Expr] = KnownBits::ashr(LHSKnown, RHSKnown);
404 return;
406 KBM[Expr] = KnownBits::lshr(LHSKnown, RHSKnown);
407 return;
409 KBM[Expr] = KnownBits::sub(LHSKnown, RHSKnown);
410 return;
412 KBM[Expr] = LHSKnown ^ RHSKnown;
413 return;
414 }
415}
416
417static void unaryOpKnownBitsMapHelper(const MCExpr *Expr, KnownBitsMap &KBM,
418 unsigned Depth) {
419 static constexpr unsigned BitWidth = 64;
420 const MCUnaryExpr *UExpr = cast<MCUnaryExpr>(Expr);
421 knownBitsMapHelper(UExpr->getSubExpr(), KBM, Depth + 1);
422 KnownBits KB = KBM[UExpr->getSubExpr()];
423
424 switch (UExpr->getOpcode()) {
425 default:
426 KBM[Expr] = KnownBits(BitWidth);
427 return;
429 KB.makeNegative();
430 KBM[Expr] = std::move(KB);
431 return;
432 }
435 AllOnes.setAllOnes();
436 KBM[Expr] = KB ^ AllOnes;
437 return;
438 }
440 KB.makeNonNegative();
441 KBM[Expr] = std::move(KB);
442 return;
443 }
444 }
445}
446
447static void targetOpKnownBitsMapHelper(const MCExpr *Expr, KnownBitsMap &KBM,
448 unsigned Depth) {
449 static constexpr unsigned BitWidth = 64;
450 const AMDGPUMCExpr *AGVK = cast<AMDGPUMCExpr>(Expr);
451
452 switch (AGVK->getKind()) {
453 default:
454 KBM[Expr] = KnownBits(BitWidth);
455 return;
457 knownBitsMapHelper(AGVK->getSubExpr(0), KBM, Depth + 1);
458 KnownBits KB = KBM[AGVK->getSubExpr(0)];
459 for (const MCExpr *Arg : AGVK->getArgs()) {
460 knownBitsMapHelper(Arg, KBM, Depth + 1);
461 KB |= KBM[Arg];
462 }
463 KBM[Expr] = std::move(KB);
464 return;
465 }
467 knownBitsMapHelper(AGVK->getSubExpr(0), KBM, Depth + 1);
468 KnownBits KB = KBM[AGVK->getSubExpr(0)];
469 for (const MCExpr *Arg : AGVK->getArgs()) {
470 knownBitsMapHelper(Arg, KBM, Depth + 1);
471 KB = KnownBits::umax(KB, KBM[Arg]);
472 }
473 KBM[Expr] = std::move(KB);
474 return;
475 }
482 int64_t Val;
483 if (AGVK->evaluateAsAbsolute(Val)) {
484 APInt APValue(BitWidth, Val);
485 KBM[Expr] = KnownBits::makeConstant(APValue);
486 return;
487 }
488 KBM[Expr] = KnownBits(BitWidth);
489 return;
490 }
491 }
492}
493
494static void knownBitsMapHelper(const MCExpr *Expr, KnownBitsMap &KBM,
495 unsigned Depth) {
496 static constexpr unsigned BitWidth = 64;
497
498 int64_t Val;
499 if (Expr->evaluateAsAbsolute(Val)) {
500 APInt APValue(BitWidth, Val, /*isSigned=*/true);
501 KBM[Expr] = KnownBits::makeConstant(APValue);
502 return;
503 }
504
505 if (Depth == 16) {
506 KBM[Expr] = KnownBits(BitWidth);
507 return;
508 }
509
510 switch (Expr->getKind()) {
513 return;
514 }
516 const MCConstantExpr *CE = cast<MCConstantExpr>(Expr);
517 APInt APValue(BitWidth, CE->getValue(), /*isSigned=*/true);
518 KBM[Expr] = KnownBits::makeConstant(APValue);
519 return;
520 }
522 const MCSymbolRefExpr *RExpr = cast<MCSymbolRefExpr>(Expr);
523 const MCSymbol &Sym = RExpr->getSymbol();
524 if (!Sym.isVariable()) {
525 KBM[Expr] = KnownBits(BitWidth);
526 return;
527 }
528
529 // Variable value retrieval is not for actual use but only for knownbits
530 // analysis.
531 const MCExpr *SymVal = Sym.getVariableValue();
532 knownBitsMapHelper(SymVal, KBM, Depth + 1);
533
534 // Explicitly copy-construct so that there exists a local KnownBits in case
535 // KBM[SymVal] gets invalidated after a potential growth through KBM[Expr].
536 KBM[Expr] = KnownBits(KBM[SymVal]);
537 return;
538 }
541 return;
542 }
545 return;
547 llvm_unreachable("unused by this backend");
548 }
549 }
550}
551
552static const MCExpr *tryFoldHelper(const MCExpr *Expr, KnownBitsMap &KBM,
553 MCContext &Ctx) {
554 if (!KBM.count(Expr))
555 return Expr;
556
557 auto ValueCheckKnownBits = [](KnownBits &KB, unsigned Value) -> bool {
558 if (!KB.isConstant())
559 return false;
560
561 return Value == KB.getConstant();
562 };
563
564 if (Expr->getKind() == MCExpr::ExprKind::Constant)
565 return Expr;
566
567 // Resolving unary operations to constants may make the value more ambiguous.
568 // For example, `~62` becomes `-63`; however, to me it's more ambiguous if a
569 // bit mask value is represented through a negative number.
570 if (Expr->getKind() != MCExpr::ExprKind::Unary) {
571 if (KBM[Expr].isConstant()) {
572 APInt ConstVal = KBM[Expr].getConstant();
573 return MCConstantExpr::create(ConstVal.getSExtValue(), Ctx);
574 }
575
576 int64_t EvalValue;
577 if (Expr->evaluateAsAbsolute(EvalValue))
578 return MCConstantExpr::create(EvalValue, Ctx);
579 }
580
581 switch (Expr->getKind()) {
582 default:
583 return Expr;
585 const MCBinaryExpr *BExpr = cast<MCBinaryExpr>(Expr);
586 const MCExpr *LHS = BExpr->getLHS();
587 const MCExpr *RHS = BExpr->getRHS();
588
589 switch (BExpr->getOpcode()) {
590 default:
591 return Expr;
593 if (ValueCheckKnownBits(KBM[RHS], 0))
594 return tryFoldHelper(LHS, KBM, Ctx);
595 break;
596 }
599 if (ValueCheckKnownBits(KBM[LHS], 0))
600 return tryFoldHelper(RHS, KBM, Ctx);
601 if (ValueCheckKnownBits(KBM[RHS], 0))
602 return tryFoldHelper(LHS, KBM, Ctx);
603 break;
604 }
606 if (ValueCheckKnownBits(KBM[LHS], 1))
607 return tryFoldHelper(RHS, KBM, Ctx);
608 if (ValueCheckKnownBits(KBM[RHS], 1))
609 return tryFoldHelper(LHS, KBM, Ctx);
610 break;
611 }
615 if (ValueCheckKnownBits(KBM[RHS], 0))
616 return tryFoldHelper(LHS, KBM, Ctx);
617 if (ValueCheckKnownBits(KBM[LHS], 0))
618 return MCConstantExpr::create(0, Ctx);
619 break;
620 }
622 if (ValueCheckKnownBits(KBM[LHS], 0) || ValueCheckKnownBits(KBM[RHS], 0))
623 return MCConstantExpr::create(0, Ctx);
624 break;
625 }
626 }
627 const MCExpr *NewLHS = tryFoldHelper(LHS, KBM, Ctx);
628 const MCExpr *NewRHS = tryFoldHelper(RHS, KBM, Ctx);
629 if (NewLHS != LHS || NewRHS != RHS)
630 return MCBinaryExpr::create(BExpr->getOpcode(), NewLHS, NewRHS, Ctx,
631 BExpr->getLoc());
632 return Expr;
633 }
635 const MCUnaryExpr *UExpr = cast<MCUnaryExpr>(Expr);
636 const MCExpr *SubExpr = UExpr->getSubExpr();
637 const MCExpr *NewSubExpr = tryFoldHelper(SubExpr, KBM, Ctx);
638 if (SubExpr != NewSubExpr)
639 return MCUnaryExpr::create(UExpr->getOpcode(), NewSubExpr, Ctx,
640 UExpr->getLoc());
641 return Expr;
642 }
644 const AMDGPUMCExpr *AGVK = cast<AMDGPUMCExpr>(Expr);
646 bool Changed = false;
647 for (const MCExpr *Arg : AGVK->getArgs()) {
648 const MCExpr *NewArg = tryFoldHelper(Arg, KBM, Ctx);
649 NewArgs.push_back(NewArg);
650 Changed |= Arg != NewArg;
651 }
652 return Changed ? AMDGPUMCExpr::create(AGVK->getKind(), NewArgs, Ctx) : Expr;
653 }
654 }
655 return Expr;
656}
657
659 MCContext &Ctx) {
660 KnownBitsMap KBM;
661 knownBitsMapHelper(Expr, KBM);
662 const MCExpr *NewExpr = tryFoldHelper(Expr, KBM, Ctx);
663
664 return Expr != NewExpr ? NewExpr : Expr;
665}
666
668 const MCAsmInfo *MAI) {
669 int64_t Val;
670 if (Expr->evaluateAsAbsolute(Val)) {
671 OS << Val;
672 return;
673 }
674
675 MAI->printExpr(OS, *Expr);
676}
677
678bool AMDGPU::isLitExpr(const MCExpr *Expr) {
679 const auto *E = dyn_cast<AMDGPUMCExpr>(Expr);
680 return E && (E->getKind() == AMDGPUMCExpr::AGVK_Lit ||
681 E->getKind() == AMDGPUMCExpr::AGVK_Lit64);
682}
683
684int64_t AMDGPU::getLitValue(const MCExpr *Expr) {
685 assert(isLitExpr(Expr));
686 return cast<MCConstantExpr>(cast<AMDGPUMCExpr>(Expr)->getArgs()[0])
687 ->getValue();
688}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
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)
static bool evaluateMCExprs(ArrayRef< const MCExpr * > Exprs, const MCAssembler *Asm, std::initializer_list< std::reference_wrapper< uint64_t > > Vals)
DenseMap< const MCExpr *, KnownBits > KnownBitsMap
#define op(i)
Value * RHS
Value * LHS
AMDGPU target specific MCExpr operations.
ArrayRef< const MCExpr * > getArgs() const
MCFragment * findAssociatedFragment() const override
void visitUsedExpr(MCStreamer &Streamer) const override
static const AMDGPUMCExpr * createTotalNumVGPR(const MCExpr *NumAGPR, const MCExpr *NumVGPR, MCContext &Ctx)
static const AMDGPUMCExpr * createLit(LitModifier Lit, int64_t Value, MCContext &Ctx)
static const AMDGPUMCExpr * create(VariantKind Kind, ArrayRef< const MCExpr * > Args, MCContext &Ctx)
bool evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm) const override
static const AMDGPUMCExpr * createExtraSGPRs(const MCExpr *VCCUsed, const MCExpr *FlatScrUsed, bool XNACKUsed, MCContext &Ctx)
Allow delayed MCExpr resolve of ExtraSGPRs (in case VCCUsed or FlatScrUsed are unresolvable but neede...
const MCExpr * getSubExpr(size_t Index) const
void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override
VariantKind getKind() const
static bool isSymbolUsedInExpression(const MCSymbol *Sym, const MCExpr *E)
Class for arbitrary precision integers.
Definition APInt.h:78
int64_t getSExtValue() const
Get sign extended value.
Definition APInt.h:1585
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
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:174
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition MCAsmInfo.h:64
void printExpr(raw_ostream &, const MCExpr &) const
Binary assembler expressions.
Definition MCExpr.h:299
const MCExpr * getLHS() const
Get the left-hand side expression of the binary operator.
Definition MCExpr.h:446
const MCExpr * getRHS() const
Get the right-hand side expression of the binary operator.
Definition MCExpr.h:449
Opcode getOpcode() const
Get the kind of this binary expression.
Definition MCExpr.h:443
static LLVM_ABI const MCBinaryExpr * create(Opcode Op, const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx, SMLoc Loc=SMLoc())
Definition MCExpr.cpp:201
@ Div
Signed division.
Definition MCExpr.h:304
@ Shl
Shift left.
Definition MCExpr.h:321
@ AShr
Arithmetic shift right.
Definition MCExpr.h:322
@ LShr
Logical shift right.
Definition MCExpr.h:323
@ GTE
Signed greater than or equal comparison (result is either 0 or some target-specific non-zero value).
Definition MCExpr.h:308
@ EQ
Equality comparison.
Definition MCExpr.h:305
@ Sub
Subtraction.
Definition MCExpr.h:324
@ Mul
Multiplication.
Definition MCExpr.h:317
@ GT
Signed greater than comparison (result is either 0 or some target-specific non-zero value)
Definition MCExpr.h:306
@ Mod
Signed remainder.
Definition MCExpr.h:316
@ And
Bitwise and.
Definition MCExpr.h:303
@ Or
Bitwise or.
Definition MCExpr.h:319
@ Xor
Bitwise exclusive or.
Definition MCExpr.h:325
@ LAnd
Logical and.
Definition MCExpr.h:310
@ LOr
Logical or.
Definition MCExpr.h:311
@ LT
Signed less than comparison (result is either 0 or some target-specific non-zero value).
Definition MCExpr.h:312
@ Add
Addition.
Definition MCExpr.h:302
@ LTE
Signed less than or equal comparison (result is either 0 or some target-specific non-zero value).
Definition MCExpr.h:314
@ NE
Inequality comparison.
Definition MCExpr.h:318
static LLVM_ABI const MCConstantExpr * create(int64_t Value, MCContext &Ctx, bool PrintInHex=false, unsigned SizeInBytes=0)
Definition MCExpr.cpp:212
Context object for machine code objects.
Definition MCContext.h:83
Base class for the full range of assembler expressions which are needed for parsing.
Definition MCExpr.h:34
@ Unary
Unary expressions.
Definition MCExpr.h:44
@ Constant
Constant expressions.
Definition MCExpr.h:42
@ SymbolRef
References to labels and assigned expressions.
Definition MCExpr.h:43
@ Target
Target specific expression.
Definition MCExpr.h:46
@ Specifier
Expression with a relocation specifier.
Definition MCExpr.h:45
@ Binary
Binary expressions.
Definition MCExpr.h:41
LLVM_ABI bool evaluateAsAbsolute(int64_t &Res) const
Try to evaluate the expression to an absolute value.
Definition MCExpr.cpp:238
ExprKind getKind() const
Definition MCExpr.h:85
SMLoc getLoc() const
Definition MCExpr.h:86
Streaming machine code generation interface.
Definition MCStreamer.h:222
void visitUsedExpr(const MCExpr &Expr)
Represent a reference to a symbol from inside an expression.
Definition MCExpr.h:190
const MCSymbol & getSymbol() const
Definition MCExpr.h:227
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition MCSymbol.h:42
bool isVariable() const
isVariable - Check if this is a variable symbol.
Definition MCSymbol.h:267
const MCExpr * getVariableValue() const
Get the expression of the variable symbol.
Definition MCSymbol.h:270
Unary assembler expressions.
Definition MCExpr.h:243
Opcode getOpcode() const
Get the kind of this unary expression.
Definition MCExpr.h:286
static LLVM_ABI const MCUnaryExpr * create(Opcode Op, const MCExpr *Expr, MCContext &Ctx, SMLoc Loc=SMLoc())
Definition MCExpr.cpp:207
@ Minus
Unary minus.
Definition MCExpr.h:247
@ Plus
Unary plus.
Definition MCExpr.h:249
@ Not
Bitwise negation.
Definition MCExpr.h:248
const MCExpr * getSubExpr() const
Get the child of this unary expression.
Definition MCExpr.h:289
static MCValue get(const MCSymbol *SymA, const MCSymbol *SymB=nullptr, int64_t Val=0, uint32_t Specifier=0)
Definition MCValue.h:56
int64_t getConstant() const
Definition MCValue.h:44
bool isAbsolute() const
Is this an absolute (as opposed to relocatable) value.
Definition MCValue.h:54
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
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
Changed
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
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 getNumWavesPerEUWithNumVGPRs(const MCSubtargetInfo *STI, unsigned NumVGPRs, unsigned DynamicVGPRBlockSize)
unsigned getNumExtraSGPRs(const MCSubtargetInfo *STI, bool VCCUsed, bool FlatScrUsed, bool XNACKUsed)
unsigned getOccupancyWithNumSGPRs(unsigned SGPRs, unsigned MaxWaves, AMDGPUSubtarget::Generation Gen)
LLVM_READONLY bool isLitExpr(const MCExpr *Expr)
void printAMDGPUMCExpr(const MCExpr *Expr, raw_ostream &OS, const MCAsmInfo *MAI)
bool isGFX90A(const MCSubtargetInfo &STI)
LLVM_READONLY int64_t getLitValue(const MCExpr *Expr)
const MCExpr * foldAMDGPUMCExpr(const MCExpr *Expr, MCContext &Ctx)
This is an optimization pass for GlobalISel generic memory operations.
FunctionAddr VTableAddr Value
Definition InstrProf.h:137
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1739
detail::zippy< detail::zip_first, T, U, Args... > zip_equal(T &&t, U &&u, Args &&...args)
zip iterator that assumes that all iteratees have the same length.
Definition STLExtras.h:841
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
auto uninitialized_copy(R &&Src, IterTy Dst)
Definition STLExtras.h:2111
constexpr uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
Definition Alignment.h:144
@ Success
The lock was released successfully.
ArrayRef(const T &OneElt) -> ArrayRef< T >
constexpr unsigned BitWidth
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
static KnownBits makeConstant(const APInt &C)
Create known bits from a known constant.
Definition KnownBits.h:315
static LLVM_ABI std::optional< bool > eq(const KnownBits &LHS, const KnownBits &RHS)
Determine if these known bits always give the same ICMP_EQ result.
void makeNonNegative()
Make this value non-negative.
Definition KnownBits.h:125
static LLVM_ABI KnownBits ashr(const KnownBits &LHS, const KnownBits &RHS, bool ShAmtNonZero=false, bool Exact=false)
Compute known bits for ashr(LHS, RHS).
static LLVM_ABI std::optional< bool > ne(const KnownBits &LHS, const KnownBits &RHS)
Determine if these known bits always give the same ICMP_NE result.
void makeNegative()
Make this value negative.
Definition KnownBits.h:120
static LLVM_ABI std::optional< bool > sge(const KnownBits &LHS, const KnownBits &RHS)
Determine if these known bits always give the same ICMP_SGE result.
static LLVM_ABI KnownBits umax(const KnownBits &LHS, const KnownBits &RHS)
Compute known bits for umax(LHS, RHS).
KnownBits zext(unsigned BitWidth) const
Return known bits for a zero extension of the value we're tracking.
Definition KnownBits.h:176
bool isConstant() const
Returns true if we know the value of all bits.
Definition KnownBits.h:54
static KnownBits add(const KnownBits &LHS, const KnownBits &RHS, bool NSW=false, bool NUW=false, bool SelfAdd=false)
Compute knownbits resulting from addition of LHS and RHS.
Definition KnownBits.h:361
static LLVM_ABI KnownBits lshr(const KnownBits &LHS, const KnownBits &RHS, bool ShAmtNonZero=false, bool Exact=false)
Compute known bits for lshr(LHS, RHS).
static LLVM_ABI KnownBits srem(const KnownBits &LHS, const KnownBits &RHS)
Compute known bits for srem(LHS, RHS).
static LLVM_ABI std::optional< bool > slt(const KnownBits &LHS, const KnownBits &RHS)
Determine if these known bits always give the same ICMP_SLT result.
static LLVM_ABI KnownBits sdiv(const KnownBits &LHS, const KnownBits &RHS, bool Exact=false)
Compute known bits for sdiv(LHS, RHS).
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:376
static LLVM_ABI KnownBits mul(const KnownBits &LHS, const KnownBits &RHS, bool NoUndefSelfMultiply=false)
Compute known bits resulting from multiplying LHS and RHS.
static LLVM_ABI std::optional< bool > sle(const KnownBits &LHS, const KnownBits &RHS)
Determine if these known bits always give the same ICMP_SLE result.
static LLVM_ABI std::optional< bool > sgt(const KnownBits &LHS, const KnownBits &RHS)
Determine if these known bits always give the same ICMP_SGT result.
static LLVM_ABI KnownBits shl(const KnownBits &LHS, const KnownBits &RHS, bool NUW=false, bool NSW=false, bool ShAmtNonZero=false)
Compute known bits for shl(LHS, RHS).
const APInt & getConstant() const
Returns the value when all bits have a known value.
Definition KnownBits.h:58