| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
#ifndef LLVM_CODEGEN_GLOBALISEL_GISELKNOWNBITS_H |
| 15 |
#define LLVM_CODEGEN_GLOBALISEL_GISELKNOWNBITS_H |
| 16 |
|
| 17 |
#include "llvm/ADT/DenseMap.h" |
| 18 |
#include "llvm/CodeGen/GlobalISel/GISelChangeObserver.h" |
| 19 |
#include "llvm/CodeGen/MachineFunctionPass.h" |
| 20 |
#include "llvm/CodeGen/Register.h" |
| 21 |
#include "llvm/InitializePasses.h" |
| 22 |
#include "llvm/Support/KnownBits.h" |
| 23 |
|
| 24 |
namespace llvm { |
| 25 |
|
| 26 |
class TargetLowering; |
| 27 |
class DataLayout; |
| 28 |
|
| 29 |
class GISelKnownBits : public GISelChangeObserver { |
| 30 |
MachineFunction &MF; |
| 31 |
MachineRegisterInfo &MRI; |
| 32 |
const TargetLowering &TL; |
| 33 |
const DataLayout &DL; |
| 34 |
unsigned MaxDepth; |
| 35 |
|
| 36 |
SmallDenseMap<Register, KnownBits, 16> ComputeKnownBitsCache; |
| 37 |
|
| 38 |
void computeKnownBitsMin(Register Src0, Register Src1, KnownBits &Known, |
| 39 |
const APInt &DemandedElts, |
| 40 |
unsigned Depth = 0); |
| 41 |
|
| 42 |
unsigned computeNumSignBitsMin(Register Src0, Register Src1, |
| 43 |
const APInt &DemandedElts, unsigned Depth = 0); |
| 44 |
|
| 45 |
public: |
| 46 |
GISelKnownBits(MachineFunction &MF, unsigned MaxDepth = 6); |
| 47 |
virtual ~GISelKnownBits() = default; |
| 48 |
|
| 49 |
const MachineFunction &getMachineFunction() const { |
| 50 |
return MF; |
| 51 |
} |
| 52 |
|
| 53 |
const DataLayout &getDataLayout() const { |
| 54 |
return DL; |
| 55 |
} |
| 56 |
|
| 57 |
virtual void computeKnownBitsImpl(Register R, KnownBits &Known, |
| 58 |
const APInt &DemandedElts, |
| 59 |
unsigned Depth = 0); |
| 60 |
|
| 61 |
unsigned computeNumSignBits(Register R, const APInt &DemandedElts, |
| 62 |
unsigned Depth = 0); |
| 63 |
unsigned computeNumSignBits(Register R, unsigned Depth = 0); |
| 64 |
|
| 65 |
|
| 66 |
KnownBits getKnownBits(Register R); |
| 67 |
KnownBits getKnownBits(Register R, const APInt &DemandedElts, |
| 68 |
unsigned Depth = 0); |
| 69 |
|
| 70 |
|
| 71 |
KnownBits getKnownBits(MachineInstr &MI); |
| 72 |
APInt getKnownZeroes(Register R); |
| 73 |
APInt getKnownOnes(Register R); |
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
bool maskedValueIsZero(Register Val, const APInt &Mask) { |
| 79 |
return Mask.isSubsetOf(getKnownBits(Val).Zero); |
| 80 |
} |
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
bool signBitIsZero(Register Op); |
| 85 |
|
| 86 |
static void computeKnownBitsForAlignment(KnownBits &Known, |
| 87 |
Align Alignment) { |
| 88 |
|
| 89 |
Known.Zero.setLowBits(Log2(Alignment)); |
| 90 |
} |
| 91 |
|
| 92 |
|
| 93 |
Align computeKnownAlignment(Register R, unsigned Depth = 0); |
| 94 |
|
| 95 |
|
| 96 |
void erasingInstr(MachineInstr &MI) override{}; |
| 97 |
void createdInstr(MachineInstr &MI) override{}; |
| 98 |
void changingInstr(MachineInstr &MI) override{}; |
| 99 |
void changedInstr(MachineInstr &MI) override{}; |
| 100 |
|
| 101 |
protected: |
| 102 |
unsigned getMaxDepth() const { return MaxDepth; } |
| 103 |
}; |
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
class GISelKnownBitsAnalysis : public MachineFunctionPass { |
| 114 |
std::unique_ptr<GISelKnownBits> Info; |
| 115 |
|
| 116 |
public: |
| 117 |
static char ID; |
| 118 |
GISelKnownBitsAnalysis() : MachineFunctionPass(ID) { |
| 119 |
initializeGISelKnownBitsAnalysisPass(*PassRegistry::getPassRegistry()); |
| 120 |
} |
| 121 |
GISelKnownBits &get(MachineFunction &MF) { |
| 122 |
if (!Info) |
| 123 |
Info = std::make_unique<GISelKnownBits>(MF); |
| 124 |
return *Info.get(); |
| 125 |
} |
| 126 |
void getAnalysisUsage(AnalysisUsage &AU) const override; |
| 127 |
bool runOnMachineFunction(MachineFunction &MF) override; |
| 128 |
void releaseMemory() override { Info.reset(); } |
| 129 |
}; |
| 130 |
} |
| 131 |
|
| 132 |
#endif |