File indexing completed on 2026-05-10 08:43:12
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021 #ifndef LLVM_ANALYSIS_DEMANDEDBITS_H
0022 #define LLVM_ANALYSIS_DEMANDEDBITS_H
0023
0024 #include "llvm/ADT/APInt.h"
0025 #include "llvm/ADT/DenseMap.h"
0026 #include "llvm/ADT/SmallPtrSet.h"
0027 #include "llvm/IR/PassManager.h"
0028
0029 namespace llvm {
0030
0031 class AssumptionCache;
0032 class DominatorTree;
0033 class Function;
0034 class Instruction;
0035 struct KnownBits;
0036 class raw_ostream;
0037 class Use;
0038 class Value;
0039
0040 class DemandedBits {
0041 public:
0042 DemandedBits(Function &F, AssumptionCache &AC, DominatorTree &DT) :
0043 F(F), AC(AC), DT(DT) {}
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054 APInt getDemandedBits(Instruction *I);
0055
0056
0057 APInt getDemandedBits(Use *U);
0058
0059
0060 bool isInstructionDead(Instruction *I);
0061
0062
0063 bool isUseDead(Use *U);
0064
0065 void print(raw_ostream &OS);
0066
0067
0068
0069 static APInt determineLiveOperandBitsAdd(unsigned OperandNo,
0070 const APInt &AOut,
0071 const KnownBits &LHS,
0072 const KnownBits &RHS);
0073
0074
0075
0076 static APInt determineLiveOperandBitsSub(unsigned OperandNo,
0077 const APInt &AOut,
0078 const KnownBits &LHS,
0079 const KnownBits &RHS);
0080
0081 private:
0082 void performAnalysis();
0083 void determineLiveOperandBits(const Instruction *UserI,
0084 const Value *Val, unsigned OperandNo,
0085 const APInt &AOut, APInt &AB,
0086 KnownBits &Known, KnownBits &Known2, bool &KnownBitsComputed);
0087
0088 Function &F;
0089 AssumptionCache ∾
0090 DominatorTree &DT;
0091
0092 bool Analyzed = false;
0093
0094
0095 SmallPtrSet<Instruction*, 32> Visited;
0096 DenseMap<Instruction *, APInt> AliveBits;
0097
0098
0099 SmallPtrSet<Use *, 16> DeadUses;
0100 };
0101
0102
0103 class DemandedBitsAnalysis : public AnalysisInfoMixin<DemandedBitsAnalysis> {
0104 friend AnalysisInfoMixin<DemandedBitsAnalysis>;
0105
0106 static AnalysisKey Key;
0107
0108 public:
0109
0110 using Result = DemandedBits;
0111
0112
0113
0114 DemandedBits run(Function &F, FunctionAnalysisManager &AM);
0115 };
0116
0117
0118 class DemandedBitsPrinterPass : public PassInfoMixin<DemandedBitsPrinterPass> {
0119 raw_ostream &OS;
0120
0121 public:
0122 explicit DemandedBitsPrinterPass(raw_ostream &OS) : OS(OS) {}
0123
0124 PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
0125
0126 static bool isRequired() { return true; }
0127 };
0128
0129 }
0130
0131 #endif