//===--- RDFDeadCode.cpp --------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // // RDF-based generic dead code elimination. #include "RDFDeadCode.h" #include "llvm/ADT/SetVector.h" #include "llvm/CodeGen/MachineBasicBlock.h" #include "llvm/CodeGen/MachineFunction.h" #include "llvm/CodeGen/MachineRegisterInfo.h" #include "llvm/CodeGen/RDFGraph.h" #include "llvm/CodeGen/RDFLiveness.h" #include "llvm/Support/Debug.h" #include <queue> usingnamespacellvm; usingnamespacerdf; // This drastically improves execution time in "collect" over using // SetVector as a work queue, and popping the first element from it. template<typename T> struct DeadCodeElimination::SetQueue { … }; // Check if the given instruction has observable side-effects, i.e. if // it should be considered "live". It is safe for this function to be // overly conservative (i.e. return "true" for all instructions), but it // is not safe to return "false" for an instruction that should not be // considered removable. bool DeadCodeElimination::isLiveInstr(NodeAddr<StmtNode *> S) const { … } void DeadCodeElimination::scanInstr(NodeAddr<InstrNode*> IA, SetQueue<NodeId> &WorkQ) { … } void DeadCodeElimination::processDef(NodeAddr<DefNode*> DA, SetQueue<NodeId> &WorkQ) { … } void DeadCodeElimination::processUse(NodeAddr<UseNode*> UA, SetQueue<NodeId> &WorkQ) { … } // Traverse the DFG and collect the set dead RefNodes and the set of // dead instructions. Return "true" if any of these sets is non-empty, // "false" otherwise. bool DeadCodeElimination::collect() { … } // Erase the nodes given in the Nodes set from DFG. In addition to removing // them from the DFG, if a node corresponds to a statement, the corresponding // machine instruction is erased from the function. bool DeadCodeElimination::erase(const SetVector<NodeId> &Nodes) { … }