60 if (
MI->mayStore() ||
MI->isBranch() ||
MI->isCall() ||
MI->isReturn())
62 if (
MI->hasOrderedMemoryRef() ||
MI->hasUnmodeledSideEffects() ||
67 for (
auto &
Op :
MI->operands()) {
68 if (
Op.isReg() &&
MRI.isReserved(
Op.getReg()))
72 for (
unsigned R = 0, RN = DFG.getTRI().getNumRegs(); R != RN; ++R) {
73 if (BM[R/32] & (1u << (R%32)))
75 if (
MRI.isReserved(R))
83void DeadCodeElimination::scanInstr(NodeAddr<InstrNode*> IA,
84 SetQueue<NodeId> &WorkQ) {
89 for (NodeAddr<RefNode*>
RA :
IA.Addr->members(DFG)) {
90 if (!LiveNodes.count(
RA.Id))
91 WorkQ.push_back(
RA.Id);
95void DeadCodeElimination::processDef(NodeAddr<DefNode*> DA,
96 SetQueue<NodeId> &WorkQ) {
97 NodeAddr<InstrNode*>
IA =
DA.Addr->getOwner(DFG);
98 for (NodeAddr<UseNode*> UA :
IA.Addr->members_if(DFG.IsUse, DFG)) {
99 if (!LiveNodes.count(UA.Id))
100 WorkQ.push_back(UA.Id);
102 for (NodeAddr<DefNode*> TA : DFG.getRelatedRefs(IA, DA))
103 LiveNodes.insert(
TA.Id);
106void DeadCodeElimination::processUse(NodeAddr<UseNode*> UA,
107 SetQueue<NodeId> &WorkQ) {
108 for (NodeAddr<DefNode*> DA : LV.getAllReachingDefs(UA)) {
109 if (!LiveNodes.count(
DA.Id))
110 WorkQ.push_back(
DA.Id);
128 SetQueue<NodeId> WorkQ;
131 scanInstr(IA, WorkQ);
133 while (!WorkQ.empty()) {
138 processDef(
RA, WorkQ);
144 dbgs() <<
"Live nodes:\n";
153 if (LiveNodes.count(DA.Id))
161 if (!LiveNodes.count(
RA.Id))
162 DeadNodes.insert(
RA.Id);
164 if (isLiveInstr(IA) || DFG.hasUntrackedRef(IA))
167 DeadInstrs.insert(IA.Id);
174 return !DeadNodes.empty();
188 for (
auto I : Nodes) {
210 uint16_t KindA =
A.Addr->getKind(), KindB =
B.Addr->getKind();
220 dbgs() <<
"Removing dead ref nodes:\n";
225 DFG.unlinkUse(
RA,
true);
226 else if (DFG.IsDef(
RA))
227 DFG.unlinkDef(
RA,
true);
233 BA.
Addr->removeMember(IA, DFG);
239 dbgs() <<
"erasing: " << *
MI;
240 MI->eraseFromParent();
unsigned const MachineRegisterInfo * MRI
static bool processUse(CallInst *CI, bool IsV5OrAbove)
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
SI optimize exec mask operations pre RA
This file implements a set that has insertion order iteration characteristics.
Implements a dense probed hash-table based set.
Representation of each machine instruction.
A vector that has set insertion semantics.
bool empty() const
Determine if the SetVector is empty or not.
void push_back(const T &Elt)
The instances of the Type class are immutable: once they are created, they are never changed.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
SmallVector< Node, 4 > NodeList
This is an optimization pass for GlobalISel generic memory operations.
void append_range(Container &C, Range &&R)
Wrapper function to append range R to container C.
void sort(IteratorTy Start, IteratorTy End)
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
DWARFExpression::Operation Op
bool erase(const SetVector< NodeId > &Nodes)