58bool DeadCodeElimination::isLiveInstr(
const MachineInstr *
MI)
const {
59 if (
MI->mayStore() ||
MI->isBranch() ||
MI->isCall() ||
MI->isReturn())
61 if (
MI->hasOrderedMemoryRef() ||
MI->hasUnmodeledSideEffects() ||
66 for (
auto &Op :
MI->operands()) {
67 if (Op.isReg() &&
MRI.isReserved(Op.getReg()))
70 const uint32_t *BM = Op.getRegMask();
71 for (
unsigned R = 0, RN = DFG.getTRI().getNumRegs(); R != RN; ++R) {
72 if (BM[R/32] & (1u << (R%32)))
74 if (
MRI.isReserved(R))
83 SetQueue<NodeId> &WorkQ) {
89 if (!LiveNodes.count(
RA.Id))
90 WorkQ.push_back(
RA.Id);
95 SetQueue<NodeId> &WorkQ) {
98 if (!LiveNodes.count(UA.Id))
99 WorkQ.push_back(UA.Id);
102 LiveNodes.insert(
TA.Id);
106 SetQueue<NodeId> &WorkQ) {
108 if (!LiveNodes.count(
DA.Id))
109 WorkQ.push_back(
DA.Id);
116bool DeadCodeElimination::collect() {
127 SetQueue<NodeId> WorkQ;
130 scanInstr(IA, WorkQ);
132 while (!WorkQ.empty()) {
137 processDef(
RA, WorkQ);
143 dbgs() <<
"Live nodes:\n";
152 if (LiveNodes.count(DA.Id))
160 if (!LiveNodes.count(
RA.Id))
161 DeadNodes.insert(
RA.Id);
166 DeadInstrs.insert(IA.Id);
173 return !DeadNodes.empty();
187 for (
auto I : Nodes) {
209 uint16_t KindA =
A.Addr->getKind(), KindB =
B.Addr->getKind();
219 dbgs() <<
"Removing dead ref nodes:\n";
224 DFG.unlinkUse(
RA,
true);
225 else if (DFG.IsDef(
RA))
226 DFG.unlinkDef(
RA,
true);
232 BA.
Addr->removeMember(IA, DFG);
238 dbgs() <<
"erasing: " << *
MI;
239 MI->eraseFromParent();
unsigned const MachineRegisterInfo * MRI
static bool processUse(CallInst *CI, bool IsV5OrAbove)
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
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)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
The instances of the Type class are immutable: once they are created, they are never changed.
std::pair< iterator, bool > insert(const ValueT &V)
bool erase(const ValueT &V)
size_type count(const_arg_type_t< ValueT > V) const
Return 1 if the specified key is in the set, 0 otherwise.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
This is an optimization pass for GlobalISel generic memory operations.
void append_range(Container &C, Range &&R)
Wrapper function to append a range to a container.
void sort(IteratorTy Start, IteratorTy End)
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.