File indexing completed on 2026-05-10 08:43:24
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #ifndef LLVM_CODEGEN_GLOBALISEL_GISELKNOWNBITS_H
0015 #define LLVM_CODEGEN_GLOBALISEL_GISELKNOWNBITS_H
0016
0017 #include "llvm/ADT/DenseMap.h"
0018 #include "llvm/CodeGen/GlobalISel/GISelChangeObserver.h"
0019 #include "llvm/CodeGen/MachineFunctionPass.h"
0020 #include "llvm/CodeGen/Register.h"
0021 #include "llvm/InitializePasses.h"
0022 #include "llvm/Support/KnownBits.h"
0023
0024 namespace llvm {
0025
0026 class TargetLowering;
0027 class DataLayout;
0028
0029 class GISelKnownBits : public GISelChangeObserver {
0030 MachineFunction &MF;
0031 MachineRegisterInfo &MRI;
0032 const TargetLowering &TL;
0033 const DataLayout &DL;
0034 unsigned MaxDepth;
0035
0036 SmallDenseMap<Register, KnownBits, 16> ComputeKnownBitsCache;
0037
0038 void computeKnownBitsMin(Register Src0, Register Src1, KnownBits &Known,
0039 const APInt &DemandedElts,
0040 unsigned Depth = 0);
0041
0042 unsigned computeNumSignBitsMin(Register Src0, Register Src1,
0043 const APInt &DemandedElts, unsigned Depth = 0);
0044
0045 public:
0046 GISelKnownBits(MachineFunction &MF, unsigned MaxDepth = 6);
0047 virtual ~GISelKnownBits() = default;
0048
0049 const MachineFunction &getMachineFunction() const {
0050 return MF;
0051 }
0052
0053 const DataLayout &getDataLayout() const {
0054 return DL;
0055 }
0056
0057 virtual void computeKnownBitsImpl(Register R, KnownBits &Known,
0058 const APInt &DemandedElts,
0059 unsigned Depth = 0);
0060
0061 unsigned computeNumSignBits(Register R, const APInt &DemandedElts,
0062 unsigned Depth = 0);
0063 unsigned computeNumSignBits(Register R, unsigned Depth = 0);
0064
0065
0066 KnownBits getKnownBits(Register R);
0067 KnownBits getKnownBits(Register R, const APInt &DemandedElts,
0068 unsigned Depth = 0);
0069
0070
0071 KnownBits getKnownBits(MachineInstr &MI);
0072 APInt getKnownZeroes(Register R);
0073 APInt getKnownOnes(Register R);
0074
0075
0076
0077
0078 bool maskedValueIsZero(Register Val, const APInt &Mask) {
0079 return Mask.isSubsetOf(getKnownBits(Val).Zero);
0080 }
0081
0082
0083
0084 bool signBitIsZero(Register Op);
0085
0086 static void computeKnownBitsForAlignment(KnownBits &Known,
0087 Align Alignment) {
0088
0089 Known.Zero.setLowBits(Log2(Alignment));
0090 }
0091
0092
0093 Align computeKnownAlignment(Register R, unsigned Depth = 0);
0094
0095
0096 void erasingInstr(MachineInstr &MI) override {}
0097 void createdInstr(MachineInstr &MI) override {}
0098 void changingInstr(MachineInstr &MI) override {}
0099 void changedInstr(MachineInstr &MI) override {}
0100
0101 protected:
0102 unsigned getMaxDepth() const { return MaxDepth; }
0103 };
0104
0105
0106
0107
0108
0109
0110
0111
0112
0113 class GISelKnownBitsAnalysis : public MachineFunctionPass {
0114 std::unique_ptr<GISelKnownBits> Info;
0115
0116 public:
0117 static char ID;
0118 GISelKnownBitsAnalysis() : MachineFunctionPass(ID) {
0119 initializeGISelKnownBitsAnalysisPass(*PassRegistry::getPassRegistry());
0120 }
0121 GISelKnownBits &get(MachineFunction &MF);
0122 void getAnalysisUsage(AnalysisUsage &AU) const override;
0123 bool runOnMachineFunction(MachineFunction &MF) override;
0124 void releaseMemory() override { Info.reset(); }
0125 };
0126 }
0127
0128 #endif