Thanks to visit codestin.com
Credit goes to llvm.org

LLVM 22.0.0git
DetectDeadLanes.h
Go to the documentation of this file.
1//===- DetectDeadLanes.h - SubRegister Lane Usage Analysis --*- C++ -*-----===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9/// \file
10/// Analysis that tracks defined/used subregister lanes across COPY instructions
11/// and instructions that get lowered to a COPY (PHI, REG_SEQUENCE,
12/// INSERT_SUBREG, EXTRACT_SUBREG).
13/// The information is used to detect dead definitions and the usage of
14/// (completely) undefined values and mark the operands as such.
15/// This pass is necessary because the dead/undef status is not obvious anymore
16/// when subregisters are involved.
17///
18/// Example:
19/// %0 = some definition
20/// %1 = IMPLICIT_DEF
21/// %2 = REG_SEQUENCE %0, sub0, %1, sub1
22/// %3 = EXTRACT_SUBREG %2, sub1
23/// = use %3
24/// The %0 definition is dead and %3 contains an undefined value.
25//
26//===----------------------------------------------------------------------===//
27
28#ifndef LLVM_CODEGEN_DETECTDEADLANES_H
29#define LLVM_CODEGEN_DETECTDEADLANES_H
30
31#include "llvm/ADT/BitVector.h"
33#include "llvm/MC/LaneBitmask.h"
34#include <deque>
35
36namespace llvm {
37
38class MachineInstr;
39class MachineOperand;
41class Register;
43
45public:
46 /// Contains a bitmask of which lanes of a given virtual register are
47 /// defined and which ones are actually used.
52
54 const TargetRegisterInfo *TRI);
55
56 /// Update the \p DefinedLanes and the \p UsedLanes for all virtual registers.
58
59 const VRegInfo &getVRegInfo(unsigned RegIdx) const {
60 return VRegInfos[RegIdx];
61 }
62
63 bool isDefinedByCopy(unsigned RegIdx) const {
64 return DefinedByCopy.test(RegIdx);
65 }
66
67private:
68 /// Add used lane bits on the register used by operand \p MO. This translates
69 /// the bitmask based on the operands subregister, and puts the register into
70 /// the worklist if any new bits were added.
71 void addUsedLanesOnOperand(const MachineOperand &MO, LaneBitmask UsedLanes);
72
73 /// Given a bitmask \p UsedLanes for the used lanes on a def output of a
74 /// COPY-like instruction determine the lanes used on the use operands
75 /// and call addUsedLanesOnOperand() for them.
76 void transferUsedLanesStep(const MachineInstr &MI, LaneBitmask UsedLanes);
77
78 /// Given a use regiser operand \p Use and a mask of defined lanes, check
79 /// if the operand belongs to a lowersToCopies() instruction, transfer the
80 /// mask to the def and put the instruction into the worklist.
81 void transferDefinedLanesStep(const MachineOperand &Use,
82 LaneBitmask DefinedLanes);
83
84public:
85 /// Given a mask \p DefinedLanes of lanes defined at operand \p OpNum
86 /// of COPY-like instruction, determine which lanes are defined at the output
87 /// operand \p Def.
88 LaneBitmask transferDefinedLanes(const MachineOperand &Def, unsigned OpNum,
89 LaneBitmask DefinedLanes) const;
90
91 /// Given a mask \p UsedLanes used from the output of instruction \p MI
92 /// determine which lanes are used from operand \p MO of this instruction.
94 const MachineOperand &MO) const;
95
96private:
97 LaneBitmask determineInitialDefinedLanes(Register Reg);
98 LaneBitmask determineInitialUsedLanes(Register Reg);
99
101 const TargetRegisterInfo *TRI;
102
103 void PutInWorklist(unsigned RegIdx) {
104 if (WorklistMembers.test(RegIdx))
105 return;
106 WorklistMembers.set(RegIdx);
107 Worklist.push_back(RegIdx);
108 }
109
110 std::unique_ptr<VRegInfo[]> VRegInfos;
111 /// Worklist containing virtreg indexes.
112 std::deque<unsigned> Worklist;
113 BitVector WorklistMembers;
114 /// This bitvector is set for each vreg index where the vreg is defined
115 /// by an instruction where lowersToCopies()==true.
116 BitVector DefinedByCopy;
117};
118
119class DetectDeadLanesPass : public PassInfoMixin<DetectDeadLanesPass> {
120public:
123 static bool isRequired() { return true; }
124};
125
126} // end namespace llvm
127
128#endif // LLVM_CODEGEN_DETECTDEADLANES_H
unsigned const MachineRegisterInfo * MRI
This file implements the BitVector class.
IRTranslator LLVM IR MI
A common definition of LaneBitmask for use in TableGen and CodeGen.
Register Reg
Register const TargetRegisterInfo * TRI
bool test(unsigned Idx) const
Definition BitVector.h:461
BitVector & set()
Definition BitVector.h:351
LaneBitmask transferUsedLanes(const MachineInstr &MI, LaneBitmask UsedLanes, const MachineOperand &MO) const
Given a mask UsedLanes used from the output of instruction MI determine which lanes are used from ope...
void computeSubRegisterLaneBitInfo()
Update the DefinedLanes and the UsedLanes for all virtual registers.
DeadLaneDetector(const MachineRegisterInfo *MRI, const TargetRegisterInfo *TRI)
bool isDefinedByCopy(unsigned RegIdx) const
LaneBitmask transferDefinedLanes(const MachineOperand &Def, unsigned OpNum, LaneBitmask DefinedLanes) const
Given a mask DefinedLanes of lanes defined at operand OpNum of COPY-like instruction,...
const VRegInfo & getVRegInfo(unsigned RegIdx) const
PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
Representation of each machine instruction.
MachineOperand class - Representation of each machine instruction operand.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
A set of analyses that are preserved following a run of a transformation pass.
Definition Analysis.h:112
Wrapper class representing virtual and physical registers.
Definition Register.h:19
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
A Use represents the edge between a Value definition and its users.
Definition Use.h:35
This is an optimization pass for GlobalISel generic memory operations.
AnalysisManager< MachineFunction > MachineFunctionAnalysisManager
Contains a bitmask of which lanes of a given virtual register are defined and which ones are actually...
A CRTP mix-in to automatically provide informational APIs needed for passes.
Definition PassManager.h:70