1 //===- HexagonBitTracker.h --------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #ifndef LLVM_LIB_TARGET_HEXAGON_HEXAGONBITTRACKER_H
11 #define LLVM_LIB_TARGET_HEXAGON_HEXAGONBITTRACKER_H
12 
13 #include "BitTracker.h"
14 #include "llvm/ADT/DenseMap.h"
15 #include <cstdint>
16 
17 namespace llvm {
18 
19 class HexagonInstrInfo;
20 class HexagonRegisterInfo;
21 class MachineFrameInfo;
22 class MachineFunction;
23 class MachineInstr;
24 class MachineRegisterInfo;
25 
26 struct HexagonEvaluator : public BitTracker::MachineEvaluator {
27   using CellMapType = BitTracker::CellMapType;
28   using RegisterRef = BitTracker::RegisterRef;
29   using RegisterCell = BitTracker::RegisterCell;
30   using BranchTargetList = BitTracker::BranchTargetList;
31 
32   HexagonEvaluator(const HexagonRegisterInfo &tri, MachineRegisterInfo &mri,
33                    const HexagonInstrInfo &tii, MachineFunction &mf);
34 
35   bool evaluate(const MachineInstr &MI, const CellMapType &Inputs,
36                 CellMapType &Outputs) const override;
37   bool evaluate(const MachineInstr &BI, const CellMapType &Inputs,
38                 BranchTargetList &Targets, bool &FallsThru) const override;
39 
40   BitTracker::BitMask mask(unsigned Reg, unsigned Sub) const override;
41 
42   uint16_t getPhysRegBitWidth(unsigned Reg) const override;
43 
44   const TargetRegisterClass &composeWithSubRegIndex(
45         const TargetRegisterClass &RC, unsigned Idx) const override;
46 
47   MachineFunction &MF;
48   MachineFrameInfo &MFI;
49   const HexagonInstrInfo &TII;
50 
51 private:
52   unsigned getUniqueDefVReg(const MachineInstr &MI) const;
53   bool evaluateLoad(const MachineInstr &MI, const CellMapType &Inputs,
54                     CellMapType &Outputs) const;
55   bool evaluateFormalCopy(const MachineInstr &MI, const CellMapType &Inputs,
56                           CellMapType &Outputs) const;
57 
58   unsigned getNextPhysReg(unsigned PReg, unsigned Width) const;
59   unsigned getVirtRegFor(unsigned PReg) const;
60 
61   // Type of formal parameter extension.
62   struct ExtType {
63     enum { SExt, ZExt };
64 
65     ExtType() = default;
ExtTypeHexagonEvaluator::ExtType66     ExtType(char t, uint16_t w) : Type(t), Width(w) {}
67 
68     char Type = 0;
69     uint16_t Width = 0;
70   };
71   // Map VR -> extension type.
72   using RegExtMap = DenseMap<unsigned, ExtType>;
73   RegExtMap VRX;
74 };
75 
76 } // end namespace llvm
77 
78 #endif // LLVM_LIB_TARGET_HEXAGON_HEXAGONBITTRACKER_H
79