LLVM 23.0.0git
DemandedBits.cpp
Go to the documentation of this file.
1//===- DemandedBits.cpp - Determine demanded bits -------------------------===//
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// This pass implements a demanded bits analysis. A demanded bit is one that
10// contributes to a result; bits that are not demanded can be either zero or
11// one without affecting control or data flow. For example in this sequence:
12//
13// %1 = add i32 %x, %y
14// %2 = trunc i32 %1 to i16
15//
16// Only the lowest 16 bits of %1 are demanded; the rest are removed by the
17// trunc.
18//
19//===----------------------------------------------------------------------===//
20
22#include "llvm/ADT/APInt.h"
23#include "llvm/ADT/SetVector.h"
26#include "llvm/IR/DataLayout.h"
27#include "llvm/IR/Dominators.h"
29#include "llvm/IR/Instruction.h"
31#include "llvm/IR/Operator.h"
32#include "llvm/IR/PassManager.h"
34#include "llvm/IR/Type.h"
35#include "llvm/IR/Use.h"
37#include "llvm/Support/Debug.h"
40#include <algorithm>
41#include <cstdint>
42
43using namespace llvm;
44using namespace llvm::PatternMatch;
45
46#define DEBUG_TYPE "demanded-bits"
47
48static bool isAlwaysLive(Instruction *I) {
49 return I->isTerminator() || I->isEHPad() || I->mayHaveSideEffects();
50}
51
52void DemandedBits::determineLiveOperandBits(
53 const Instruction *UserI, const Value *Val, unsigned OperandNo,
54 const APInt &AOut, APInt &AB, KnownBits &Known, KnownBits &Known2,
55 bool &KnownBitsComputed) {
56 unsigned BitWidth = AB.getBitWidth();
57
58 // We're called once per operand, but for some instructions, we need to
59 // compute known bits of both operands in order to determine the live bits of
60 // either (when both operands are instructions themselves). We don't,
61 // however, want to do this twice, so we cache the result in APInts that live
62 // in the caller. For the two-relevant-operands case, both operand values are
63 // provided here.
64 auto ComputeKnownBits =
65 [&](unsigned BitWidth, const Value *V1, const Value *V2) {
66 if (KnownBitsComputed)
67 return;
68 KnownBitsComputed = true;
69
70 const DataLayout &DL = UserI->getDataLayout();
71 Known = KnownBits(BitWidth);
72 computeKnownBits(V1, Known, DL, &AC, UserI, &DT);
73
74 if (V2) {
75 Known2 = KnownBits(BitWidth);
76 computeKnownBits(V2, Known2, DL, &AC, UserI, &DT);
77 }
78 };
79 auto GetShiftedRange = [&](uint64_t Min, uint64_t Max, bool ShiftLeft) {
80 auto ShiftF = [ShiftLeft](const APInt &Mask, unsigned ShiftAmnt) {
81 return ShiftLeft ? Mask.shl(ShiftAmnt) : Mask.lshr(ShiftAmnt);
82 };
84 uint64_t LoopRange = Max - Min;
85 APInt Mask = AOut;
86 APInt Shifted = AOut; // AOut | (AOut << 1) | ... | (AOut << (ShiftAmnt - 1)
87 for (unsigned ShiftAmnt = 1; ShiftAmnt <= LoopRange; ShiftAmnt <<= 1) {
88 if (LoopRange & ShiftAmnt) {
89 // Account for (LoopRange - ShiftAmnt, LoopRange]
90 Mask |= ShiftF(Shifted, LoopRange - ShiftAmnt + 1);
91 // Clears the low bit.
92 LoopRange -= ShiftAmnt;
93 }
94 // [0, ShiftAmnt) -> [0, ShiftAmnt * 2)
95 Shifted |= ShiftF(Shifted, ShiftAmnt);
96 }
97 AB = ShiftF(Mask, Min);
98 };
99
100 switch (UserI->getOpcode()) {
101 default: break;
102 case Instruction::Call:
103 case Instruction::Invoke:
104 if (const auto *II = dyn_cast<IntrinsicInst>(UserI)) {
105 switch (II->getIntrinsicID()) {
106 default: break;
107 case Intrinsic::bswap:
108 // The alive bits of the input are the swapped alive bits of
109 // the output.
110 AB = AOut.byteSwap();
111 break;
112 case Intrinsic::bitreverse:
113 // The alive bits of the input are the reversed alive bits of
114 // the output.
115 AB = AOut.reverseBits();
116 break;
117 case Intrinsic::clmul:
118 // Output bits only depend on input bits with lower or
119 // equal bit index.
121 break;
122 case Intrinsic::ctlz:
123 if (OperandNo == 0) {
124 // We need some output bits, so we need all bits of the
125 // input to the left of, and including, the leftmost bit
126 // known to be one.
127 ComputeKnownBits(BitWidth, Val, nullptr);
129 std::min(BitWidth, Known.countMaxLeadingZeros()+1));
130 }
131 break;
132 case Intrinsic::cttz:
133 if (OperandNo == 0) {
134 // We need some output bits, so we need all bits of the
135 // input to the right of, and including, the rightmost bit
136 // known to be one.
137 ComputeKnownBits(BitWidth, Val, nullptr);
139 std::min(BitWidth, Known.countMaxTrailingZeros()+1));
140 }
141 break;
142 case Intrinsic::fshl:
143 case Intrinsic::fshr: {
144 const APInt *SA;
145 if (OperandNo == 2) {
146 // Shift amount is modulo the bitwidth. For powers of two we have
147 // SA % BW == SA & (BW - 1).
149 AB = BitWidth - 1;
150 } else if (match(II->getOperand(2), m_APInt(SA))) {
151 // Normalize to funnel shift left. APInt shifts of BitWidth are well-
152 // defined, so no need to special-case zero shifts here.
153 uint64_t ShiftAmt = SA->urem(BitWidth);
154 if (II->getIntrinsicID() == Intrinsic::fshr)
155 ShiftAmt = BitWidth - ShiftAmt;
156
157 if (OperandNo == 0)
158 AB = AOut.lshr(ShiftAmt);
159 else if (OperandNo == 1)
160 AB = AOut.shl(BitWidth - ShiftAmt);
161 }
162 break;
163 }
164 case Intrinsic::umax:
165 case Intrinsic::umin:
166 case Intrinsic::smax:
167 case Intrinsic::smin:
168 // If low bits of result are not demanded, they are also not demanded
169 // for the min/max operands.
171 break;
172 }
173 }
174 break;
175 case Instruction::Add:
176 if (AOut.isMask()) {
177 AB = AOut;
178 } else {
179 ComputeKnownBits(BitWidth, UserI->getOperand(0), UserI->getOperand(1));
180 AB = determineLiveOperandBitsAdd(OperandNo, AOut, Known, Known2);
181 }
182 break;
183 case Instruction::Sub:
184 if (AOut.isMask()) {
185 AB = AOut;
186 } else {
187 ComputeKnownBits(BitWidth, UserI->getOperand(0), UserI->getOperand(1));
188 AB = determineLiveOperandBitsSub(OperandNo, AOut, Known, Known2);
189 }
190 break;
191 case Instruction::Mul:
192 // Find the highest live output bit. We don't need any more input
193 // bits than that (adds, and thus subtracts, ripple only to the
194 // left).
196 break;
197 case Instruction::Shl:
198 if (OperandNo == 0) {
199 const APInt *ShiftAmtC;
200 if (match(UserI->getOperand(1), m_APInt(ShiftAmtC))) {
201 uint64_t ShiftAmt = ShiftAmtC->getLimitedValue(BitWidth - 1);
202 AB = AOut.lshr(ShiftAmt);
203
204 // If the shift is nuw/nsw, then the high bits are not dead
205 // (because we've promised that they *must* be zero).
206 const auto *S = cast<ShlOperator>(UserI);
207 if (S->hasNoSignedWrap())
208 AB |= APInt::getHighBitsSet(BitWidth, ShiftAmt+1);
209 else if (S->hasNoUnsignedWrap())
210 AB |= APInt::getHighBitsSet(BitWidth, ShiftAmt);
211 } else {
212 ComputeKnownBits(BitWidth, UserI->getOperand(1), nullptr);
213 uint64_t Min = Known.getMinValue().getLimitedValue(BitWidth - 1);
214 uint64_t Max = Known.getMaxValue().getLimitedValue(BitWidth - 1);
215 // similar to Lshr case
216 GetShiftedRange(Min, Max, /*ShiftLeft=*/false);
217 const auto *S = cast<ShlOperator>(UserI);
218 if (S->hasNoSignedWrap())
219 AB |= APInt::getHighBitsSet(BitWidth, Max + 1);
220 else if (S->hasNoUnsignedWrap())
222 }
223 }
224 break;
225 case Instruction::LShr:
226 if (OperandNo == 0) {
227 const APInt *ShiftAmtC;
228 if (match(UserI->getOperand(1), m_APInt(ShiftAmtC))) {
229 uint64_t ShiftAmt = ShiftAmtC->getLimitedValue(BitWidth - 1);
230 AB = AOut.shl(ShiftAmt);
231
232 // If the shift is exact, then the low bits are not dead
233 // (they must be zero).
234 if (cast<LShrOperator>(UserI)->isExact())
235 AB |= APInt::getLowBitsSet(BitWidth, ShiftAmt);
236 } else {
237 ComputeKnownBits(BitWidth, UserI->getOperand(1), nullptr);
238 uint64_t Min = Known.getMinValue().getLimitedValue(BitWidth - 1);
239 uint64_t Max = Known.getMaxValue().getLimitedValue(BitWidth - 1);
240 // Suppose AOut == 0b0000 0001
241 // [min, max] = [1, 3]
242 // iteration 1 shift by 1 mask is 0b0000 0011
243 // iteration 2 shift by 2 mask is 0b0000 1111
244 // iteration 3, shiftAmnt = 4 > max - min, we stop.
245 //
246 // After the iterations we need one more shift by min,
247 // to move from 0b0000 1111 to --> 0b0001 1110.
248 // The loop populates the mask relative to (0,...,max-min),
249 // but we need coverage from (min, max).
250 // This is why the shift by min is needed.
251 GetShiftedRange(Min, Max, /*ShiftLeft=*/true);
252 if (cast<LShrOperator>(UserI)->isExact())
254 }
255 }
256 break;
257 case Instruction::AShr:
258 if (OperandNo == 0) {
259 const APInt *ShiftAmtC;
260 if (match(UserI->getOperand(1), m_APInt(ShiftAmtC))) {
261 uint64_t ShiftAmt = ShiftAmtC->getLimitedValue(BitWidth - 1);
262 AB = AOut.shl(ShiftAmt);
263 // Because the high input bit is replicated into the
264 // high-order bits of the result, if we need any of those
265 // bits, then we must keep the highest input bit.
266 if ((AOut & APInt::getHighBitsSet(BitWidth, ShiftAmt))
267 .getBoolValue())
268 AB.setSignBit();
269
270 // If the shift is exact, then the low bits are not dead
271 // (they must be zero).
272 if (cast<AShrOperator>(UserI)->isExact())
273 AB |= APInt::getLowBitsSet(BitWidth, ShiftAmt);
274 } else {
275 ComputeKnownBits(BitWidth, UserI->getOperand(1), nullptr);
276 uint64_t Min = Known.getMinValue().getLimitedValue(BitWidth - 1);
277 uint64_t Max = Known.getMaxValue().getLimitedValue(BitWidth - 1);
278 GetShiftedRange(Min, Max, /*ShiftLeft=*/true);
279 if (Max &&
280 (AOut & APInt::getHighBitsSet(BitWidth, Max)).getBoolValue()) {
281 // Suppose AOut = 0011 1100
282 // [min, max] = [1, 3]
283 // ShiftAmount = 1 : Mask is 1000 0000
284 // ShiftAmount = 2 : Mask is 1100 0000
285 // ShiftAmount = 3 : Mask is 1110 0000
286 // The Mask with Max covers every case in [min, max],
287 // so we are done
288 AB.setSignBit();
289 }
290 // If the shift is exact, then the low bits are not dead
291 // (they must be zero).
292 if (cast<AShrOperator>(UserI)->isExact())
294 }
295 }
296 break;
297 case Instruction::And:
298 AB = AOut;
299
300 // For bits that are known zero, the corresponding bits in the
301 // other operand are dead (unless they're both zero, in which
302 // case they can't both be dead, so just mark the LHS bits as
303 // dead).
304 ComputeKnownBits(BitWidth, UserI->getOperand(0), UserI->getOperand(1));
305 if (OperandNo == 0)
306 AB &= ~Known2.Zero;
307 else
308 AB &= ~(Known.Zero & ~Known2.Zero);
309 break;
310 case Instruction::Or:
311 AB = AOut;
312
313 // For bits that are known one, the corresponding bits in the
314 // other operand are dead (unless they're both one, in which
315 // case they can't both be dead, so just mark the LHS bits as
316 // dead).
317 ComputeKnownBits(BitWidth, UserI->getOperand(0), UserI->getOperand(1));
318 if (OperandNo == 0)
319 AB &= ~Known2.One;
320 else
321 AB &= ~(Known.One & ~Known2.One);
322 break;
323 case Instruction::Xor:
324 case Instruction::PHI:
325 AB = AOut;
326 break;
327 case Instruction::Trunc:
328 AB = AOut.zext(BitWidth);
329 break;
330 case Instruction::ZExt:
331 AB = AOut.trunc(BitWidth);
332 break;
333 case Instruction::SExt:
334 AB = AOut.trunc(BitWidth);
335 // Because the high input bit is replicated into the
336 // high-order bits of the result, if we need any of those
337 // bits, then we must keep the highest input bit.
338 if ((AOut & APInt::getHighBitsSet(AOut.getBitWidth(),
339 AOut.getBitWidth() - BitWidth))
340 .getBoolValue())
341 AB.setSignBit();
342 break;
343 case Instruction::Select:
344 if (OperandNo != 0)
345 AB = AOut;
346 break;
347 case Instruction::ExtractElement:
348 if (OperandNo == 0)
349 AB = AOut;
350 break;
351 case Instruction::InsertElement:
352 case Instruction::ShuffleVector:
353 if (OperandNo == 0 || OperandNo == 1)
354 AB = AOut;
355 break;
356 }
357}
358
359void DemandedBits::performAnalysis() {
360 if (Analyzed)
361 // Analysis already completed for this function.
362 return;
363 Analyzed = true;
364
365 Visited.clear();
366 AliveBits.clear();
367 DeadUses.clear();
368
369 SmallSetVector<Instruction*, 16> Worklist;
370
371 // Collect the set of "root" instructions that are known live.
372 for (Instruction &I : instructions(F)) {
373 if (!isAlwaysLive(&I))
374 continue;
375
376 LLVM_DEBUG(dbgs() << "DemandedBits: Root: " << I << "\n");
377 // For integer-valued instructions, set up an initial empty set of alive
378 // bits and add the instruction to the work list. For other instructions
379 // add their operands to the work list (for integer values operands, mark
380 // all bits as live).
381 Type *T = I.getType();
382 if (T->isIntOrIntVectorTy()) {
383 if (AliveBits.try_emplace(&I, T->getScalarSizeInBits(), 0).second)
384 Worklist.insert(&I);
385
386 continue;
387 }
388
389 // Non-integer-typed instructions...
390 for (Use &OI : I.operands()) {
391 if (auto *J = dyn_cast<Instruction>(OI)) {
392 Type *T = J->getType();
393 if (T->isIntOrIntVectorTy())
394 AliveBits[J] = APInt::getAllOnes(T->getScalarSizeInBits());
395 else
396 Visited.insert(J);
397 Worklist.insert(J);
398 }
399 }
400 // To save memory, we don't add I to the Visited set here. Instead, we
401 // check isAlwaysLive on every instruction when searching for dead
402 // instructions later (we need to check isAlwaysLive for the
403 // integer-typed instructions anyway).
404 }
405
406 // Propagate liveness backwards to operands.
407 while (!Worklist.empty()) {
408 Instruction *UserI = Worklist.pop_back_val();
409
410 LLVM_DEBUG(dbgs() << "DemandedBits: Visiting: " << *UserI);
411 APInt AOut;
412 bool InputIsKnownDead = false;
413 if (UserI->getType()->isIntOrIntVectorTy()) {
414 AOut = AliveBits[UserI];
415 LLVM_DEBUG(dbgs() << " Alive Out: 0x"
417
418 // If all bits of the output are dead, then all bits of the input
419 // are also dead.
420 InputIsKnownDead = !AOut && !isAlwaysLive(UserI);
421 }
422 LLVM_DEBUG(dbgs() << "\n");
423
424 KnownBits Known, Known2;
425 bool KnownBitsComputed = false;
426 // Compute the set of alive bits for each operand. These are anded into the
427 // existing set, if any, and if that changes the set of alive bits, the
428 // operand is added to the work-list.
429 for (Use &OI : UserI->operands()) {
430 // We also want to detect dead uses of arguments, but will only store
431 // demanded bits for instructions.
432 auto *I = dyn_cast<Instruction>(OI);
433 if (!I && !isa<Argument>(OI))
434 continue;
435
436 Type *T = OI->getType();
437 if (T->isIntOrIntVectorTy()) {
438 unsigned BitWidth = T->getScalarSizeInBits();
440 if (InputIsKnownDead) {
441 AB = APInt(BitWidth, 0);
442 } else {
443 // Bits of each operand that are used to compute alive bits of the
444 // output are alive, all others are dead.
445 determineLiveOperandBits(UserI, OI, OI.getOperandNo(), AOut, AB,
446 Known, Known2, KnownBitsComputed);
447
448 // Keep track of uses which have no demanded bits.
449 if (AB.isZero())
450 DeadUses.insert(&OI);
451 else
452 DeadUses.erase(&OI);
453 }
454
455 if (I) {
456 // If we've added to the set of alive bits (or the operand has not
457 // been previously visited), then re-queue the operand to be visited
458 // again.
459 auto Res = AliveBits.try_emplace(I);
460 if (Res.second || (AB |= Res.first->second) != Res.first->second) {
461 Res.first->second = std::move(AB);
462 Worklist.insert(I);
463 }
464 }
465 } else if (I && Visited.insert(I).second) {
466 Worklist.insert(I);
467 }
468 }
469 }
470}
471
473 performAnalysis();
474
475 auto Found = AliveBits.find(I);
476 if (Found != AliveBits.end())
477 return Found->second;
478
479 const DataLayout &DL = I->getDataLayout();
480 return APInt::getAllOnes(DL.getTypeSizeInBits(I->getType()->getScalarType()));
481}
482
484 Type *T = (*U)->getType();
485 auto *UserI = cast<Instruction>(U->getUser());
486 const DataLayout &DL = UserI->getDataLayout();
487 unsigned BitWidth = DL.getTypeSizeInBits(T->getScalarType());
488
489 // We only track integer uses, everything else produces a mask with all bits
490 // set
491 if (!T->isIntOrIntVectorTy())
493
494 if (isUseDead(U))
495 return APInt(BitWidth, 0);
496
497 performAnalysis();
498
499 APInt AOut = getDemandedBits(UserI);
501 KnownBits Known, Known2;
502 bool KnownBitsComputed = false;
503
504 determineLiveOperandBits(UserI, *U, U->getOperandNo(), AOut, AB, Known,
505 Known2, KnownBitsComputed);
506
507 return AB;
508}
509
511 performAnalysis();
512
513 return !Visited.count(I) && !AliveBits.contains(I) && !isAlwaysLive(I);
514}
515
517 // We only track integer uses, everything else is assumed live.
518 if (!(*U)->getType()->isIntOrIntVectorTy())
519 return false;
520
521 // Uses by always-live instructions are never dead.
522 auto *UserI = cast<Instruction>(U->getUser());
523 if (isAlwaysLive(UserI))
524 return false;
525
526 performAnalysis();
527 if (DeadUses.count(U))
528 return true;
529
530 // If no output bits are demanded, no input bits are demanded and the use
531 // is dead. These uses might not be explicitly present in the DeadUses map.
532 if (UserI->getType()->isIntOrIntVectorTy()) {
533 auto Found = AliveBits.find(UserI);
534 if (Found != AliveBits.end() && Found->second.isZero())
535 return true;
536 }
537
538 return false;
539}
540
542 auto PrintDB = [&](const Instruction *I, const APInt &A, Value *V = nullptr) {
543 OS << "DemandedBits: 0x" << Twine::utohexstr(A.getLimitedValue())
544 << " for ";
545 if (V) {
546 V->printAsOperand(OS, false);
547 OS << " in ";
548 }
549 OS << *I << '\n';
550 };
551
552 OS << "Printing analysis 'Demanded Bits Analysis' for function '" << F.getName() << "':\n";
553 performAnalysis();
554 for (auto &KV : AliveBits) {
555 Instruction *I = KV.first;
556 PrintDB(I, KV.second);
557
558 for (Use &OI : I->operands()) {
559 PrintDB(I, getDemandedBits(&OI), OI);
560 }
561 }
562}
563
564static APInt determineLiveOperandBitsAddCarry(unsigned OperandNo,
565 const APInt &AOut,
566 const KnownBits &LHS,
567 const KnownBits &RHS,
568 bool CarryZero, bool CarryOne) {
569 assert(!(CarryZero && CarryOne) &&
570 "Carry can't be zero and one at the same time");
571
572 // The following check should be done by the caller, as it also indicates
573 // that LHS and RHS don't need to be computed.
574 //
575 // if (AOut.isMask())
576 // return AOut;
577
578 // Boundary bits' carry out is unaffected by their carry in.
579 APInt Bound = (LHS.Zero & RHS.Zero) | (LHS.One & RHS.One);
580
581 // First, the alive carry bits are determined from the alive output bits:
582 // Let demand ripple to the right but only up to any set bit in Bound.
583 // AOut = -1----
584 // Bound = ----1-
585 // ACarry&~AOut = --111-
586 APInt RBound = Bound.reverseBits();
587 APInt RAOut = AOut.reverseBits();
588 APInt RProp = RAOut + (RAOut | ~RBound);
589 APInt RACarry = RProp ^ ~RBound;
590 APInt ACarry = RACarry.reverseBits();
591
592 // Then, the alive input bits are determined from the alive carry bits:
593 APInt NeededToMaintainCarryZero;
594 APInt NeededToMaintainCarryOne;
595 if (OperandNo == 0) {
596 NeededToMaintainCarryZero = LHS.Zero | ~RHS.Zero;
597 NeededToMaintainCarryOne = LHS.One | ~RHS.One;
598 } else {
599 NeededToMaintainCarryZero = RHS.Zero | ~LHS.Zero;
600 NeededToMaintainCarryOne = RHS.One | ~LHS.One;
601 }
602
603 // As in computeForAddCarry
604 APInt PossibleSumZero = ~LHS.Zero + ~RHS.Zero + !CarryZero;
605 APInt PossibleSumOne = LHS.One + RHS.One + CarryOne;
606
607 // The below is simplified from
608 //
609 // APInt CarryKnownZero = ~(PossibleSumZero ^ LHS.Zero ^ RHS.Zero);
610 // APInt CarryKnownOne = PossibleSumOne ^ LHS.One ^ RHS.One;
611 // APInt CarryUnknown = ~(CarryKnownZero | CarryKnownOne);
612 //
613 // APInt NeededToMaintainCarry =
614 // (CarryKnownZero & NeededToMaintainCarryZero) |
615 // (CarryKnownOne & NeededToMaintainCarryOne) |
616 // CarryUnknown;
617
618 APInt NeededToMaintainCarry = (~PossibleSumZero | NeededToMaintainCarryZero) &
619 (PossibleSumOne | NeededToMaintainCarryOne);
620
621 APInt AB = AOut | (ACarry & NeededToMaintainCarry);
622 return AB;
623}
624
626 const APInt &AOut,
627 const KnownBits &LHS,
628 const KnownBits &RHS) {
629 return determineLiveOperandBitsAddCarry(OperandNo, AOut, LHS, RHS, true,
630 false);
631}
632
634 const APInt &AOut,
635 const KnownBits &LHS,
636 const KnownBits &RHS) {
637 KnownBits NRHS;
638 NRHS.Zero = RHS.One;
639 NRHS.One = RHS.Zero;
640 return determineLiveOperandBitsAddCarry(OperandNo, AOut, LHS, NRHS, false,
641 true);
642}
643
644AnalysisKey DemandedBitsAnalysis::Key;
645
652
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file implements a class to represent arbitrary precision integral constant values and operations...
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Expand Atomic instructions
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static bool isAlwaysLive(Instruction *I)
static APInt determineLiveOperandBitsAddCarry(unsigned OperandNo, const APInt &AOut, const KnownBits &LHS, const KnownBits &RHS, bool CarryZero, bool CarryOne)
This header defines various interfaces for pass management in LLVM.
This defines the Use class.
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
#define T
uint64_t IntrinsicInst * II
This file implements a set that has insertion order iteration characteristics.
#define LLVM_DEBUG(...)
Definition Debug.h:119
Value * RHS
Value * LHS
Class for arbitrary precision integers.
Definition APInt.h:78
static APInt getAllOnes(unsigned numBits)
Return an APInt of a specified width with all bits set.
Definition APInt.h:235
LLVM_ABI APInt zext(unsigned width) const
Zero extend to a new width.
Definition APInt.cpp:1055
unsigned getActiveBits() const
Compute the number of active bits in the value.
Definition APInt.h:1535
LLVM_ABI APInt trunc(unsigned width) const
Truncate to new width.
Definition APInt.cpp:968
LLVM_ABI APInt urem(const APInt &RHS) const
Unsigned remainder operation.
Definition APInt.cpp:1692
unsigned getBitWidth() const
Return the number of bits in the APInt.
Definition APInt.h:1511
LLVM_ABI APInt reverseBits() const
Definition APInt.cpp:790
unsigned countr_zero() const
Count the number of trailing zero bits.
Definition APInt.h:1662
uint64_t getLimitedValue(uint64_t Limit=UINT64_MAX) const
If this value is smaller than the specified limit, return it, otherwise return the limit value.
Definition APInt.h:476
bool isMask(unsigned numBits) const
Definition APInt.h:489
APInt shl(unsigned shiftAmt) const
Left-shift function.
Definition APInt.h:880
LLVM_ABI APInt byteSwap() const
Definition APInt.cpp:768
static APInt getLowBitsSet(unsigned numBits, unsigned loBitsSet)
Constructs an APInt value that has the bottom loBitsSet bits set.
Definition APInt.h:307
static APInt getHighBitsSet(unsigned numBits, unsigned hiBitsSet)
Constructs an APInt value that has the top hiBitsSet bits set.
Definition APInt.h:297
static APInt getZero(unsigned numBits)
Get the '0' value for the specified bit-width.
Definition APInt.h:201
static APInt getBitsSetFrom(unsigned numBits, unsigned loBit)
Constructs an APInt value that has a contiguous range of bits set.
Definition APInt.h:287
APInt lshr(unsigned shiftAmt) const
Logical right-shift function.
Definition APInt.h:858
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
A function analysis which provides an AssumptionCache.
A parsed version of the target data layout string in and methods for querying it.
Definition DataLayout.h:64
An analysis that produces DemandedBits for a function.
LLVM_ABI DemandedBits run(Function &F, FunctionAnalysisManager &AM)
Run the analysis pass over a function and produce demanded bits information.
LLVM_ABI PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
LLVM_ABI void print(raw_ostream &OS)
LLVM_ABI APInt getDemandedBits(Instruction *I)
Return the bits demanded from instruction I.
static LLVM_ABI APInt determineLiveOperandBitsAdd(unsigned OperandNo, const APInt &AOut, const KnownBits &LHS, const KnownBits &RHS)
Compute alive bits of one addition operand from alive output and known operand bits.
LLVM_ABI bool isInstructionDead(Instruction *I)
Return true if, during analysis, I could not be reached.
static LLVM_ABI APInt determineLiveOperandBitsSub(unsigned OperandNo, const APInt &AOut, const KnownBits &LHS, const KnownBits &RHS)
Compute alive bits of one subtraction operand from alive output and known operand bits.
LLVM_ABI bool isUseDead(Use *U)
Return whether this use is dead by means of not having any demanded bits.
Analysis pass which computes a DominatorTree.
Definition Dominators.h:270
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
LLVM_ABI const DataLayout & getDataLayout() const
Get the data layout of the module this instruction belongs to.
A set of analyses that are preserved following a run of a transformation pass.
Definition Analysis.h:112
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition Analysis.h:118
bool empty() const
Determine if the SetVector is empty or not.
Definition SetVector.h:100
bool insert(const value_type &X)
Insert a new element into the SetVector.
Definition SetVector.h:151
value_type pop_back_val()
Definition SetVector.h:279
static Twine utohexstr(uint64_t Val)
Definition Twine.h:385
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
bool isIntOrIntVectorTy() const
Return true if this is an integer type or a vector of integer types.
Definition Type.h:263
A Use represents the edge between a Value definition and its users.
Definition Use.h:35
op_range operands()
Definition User.h:267
Value * getOperand(unsigned i) const
Definition User.h:207
LLVM Value Representation.
Definition Value.h:75
Type * getType() const
All values are typed, get the type of this value.
Definition Value.h:255
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
constexpr std::underlying_type_t< E > Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
ap_match< APInt > m_APInt(const APInt *&Res)
Match a ConstantInt or splatted ConstantVector, binding the specified pointer to the contained APInt.
bool match(Val *V, const Pattern &P)
friend class Instruction
Iterator for Instructions in a `BasicBlock.
Definition BasicBlock.h:73
This is an optimization pass for GlobalISel generic memory operations.
Printable print(const GCNRegPressure &RP, const GCNSubtarget *ST=nullptr, unsigned DynamicVGPRBlockSize=0)
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Value
Definition InstrProf.h:143
constexpr bool isPowerOf2_32(uint32_t Value)
Return true if the argument is a power of two > 0.
Definition MathExtras.h:279
LLVM_ABI void computeKnownBits(const Value *V, KnownBits &Known, const DataLayout &DL, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr, bool UseInstrInfo=true, unsigned Depth=0)
Determine which bits of V are known to be either zero or one and return them in the KnownZero/KnownOn...
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition Debug.cpp:209
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
Definition Casting.h:547
constexpr unsigned BitWidth
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.
A special type used by analysis passes to provide an address that identifies that particular analysis...
Definition Analysis.h:29
unsigned countMaxTrailingZeros() const
Returns the maximum number of trailing zero bits possible.
Definition KnownBits.h:288
APInt getMaxValue() const
Return the maximal unsigned value possible given these KnownBits.
Definition KnownBits.h:146
APInt getMinValue() const
Return the minimal unsigned value possible given these KnownBits.
Definition KnownBits.h:130
unsigned countMaxLeadingZeros() const
Returns the maximum number of leading zero bits possible.
Definition KnownBits.h:294