diff options
| author | Richard-Qin-X <richard.qin.001@gmail.com> | 2026-08-14 20:35:54 +0800 |
|---|---|---|
| committer | Richard-Qin-X <richard.qin.001@gmail.com> | 2026-08-14 20:35:54 +0800 |
| commit | 97e5fbaa55b4672db36123c2425d05a4738452ab (patch) | |
| tree | c2750bd49922edc8c76bc831ad7bfc8b0bf42bb8 /backend/include/rcc/CodeGen/GlobalISel/GISelValueTracking.h | |
| parent | 8be4d04455f70892a94d1e0798e266c948b4750a (diff) | |
| download | rcc-project-97e5fbaa55b4672db36123c2425d05a4738452ab.tar.gz rcc-project-97e5fbaa55b4672db36123c2425d05a4738452ab.tar.xz | |
[GlobalISel] Match LLVM legalization value tracking
Diffstat (limited to 'backend/include/rcc/CodeGen/GlobalISel/GISelValueTracking.h')
| -rw-r--r-- | backend/include/rcc/CodeGen/GlobalISel/GISelValueTracking.h | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/backend/include/rcc/CodeGen/GlobalISel/GISelValueTracking.h b/backend/include/rcc/CodeGen/GlobalISel/GISelValueTracking.h new file mode 100644 index 0000000..aa02fe3 --- /dev/null +++ b/backend/include/rcc/CodeGen/GlobalISel/GISelValueTracking.h @@ -0,0 +1,53 @@ +// SPDX-License-Identifier: GPL-3.0-or-later + +#ifndef RCC_CODEGEN_GLOBALISEL_GISELVALUETRACKING_H +#define RCC_CODEGEN_GLOBALISEL_GISELVALUETRACKING_H + +#include "rcc/ADT/APInt.h" +#include "rcc/CodeGen/GlobalISel/GISelChangeObserver.h" +#include "rcc/CodeGen/Register.h" +#include "rcc/Support/Error.h" + +#include <cstdint> + +namespace rcc { + +class MachineFunction; +class MachineRegisterInfo; +class TargetDescription; + +class GISelValueTracking final : public GISelChangeObserver { +public: + GISelValueTracking(MachineFunction &Function, const TargetDescription &Target, + unsigned MaxDepth = 6) noexcept; + + [[nodiscard]] const MachineFunction &getMachineFunction() const noexcept { + return Function; + } + + [[nodiscard]] Expected<APInt> getKnownZeroes(Register Reg) const; + [[nodiscard]] Expected<std::uint32_t> computeNumSignBits(Register Reg, unsigned Depth = 0) const; + + void erasingInstr(MachineInstr &) override {} + void createdInstr(MachineInstr &) override {} + void changingInstr(MachineInstr &) override {} + void changedInstr(MachineInstr &) override {} + +private: + struct KnownBits final { + APInt Zero; + APInt One; + }; + + [[nodiscard]] Expected<KnownBits> makeUnknown(std::uint32_t BitWidth) const; + [[nodiscard]] Expected<KnownBits> getKnownBits(Register Reg, unsigned Depth = 0) const; + + MachineFunction &Function; + MachineRegisterInfo &MRI; + const TargetDescription &Target; + unsigned MaxDepth; +}; + +} // namespace rcc + +#endif // RCC_CODEGEN_GLOBALISEL_GISELVALUETRACKING_H |
