aboutsummaryrefslogtreecommitdiff
path: root/backend/include/rcc/CodeGen/GlobalISel/GISelValueTracking.h
blob: aa02fe3c39e87e5b00aee6a7cc826b64e9243416 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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