Merge pull request #31989 from georgepaw:hlo_dce
PiperOrigin-RevId: 266199694
This commit is contained in:
commit
f0ebc5b745
@ -35,13 +35,10 @@ limitations under the License.
|
||||
|
||||
namespace xla {
|
||||
|
||||
StatusOr<bool> HloDCE::Run(HloModule* module) {
|
||||
StatusOr<bool> HloDCE::RunOnComputation(HloComputation* computation) {
|
||||
bool changed = false;
|
||||
|
||||
VLOG(2) << "Before dce:";
|
||||
XLA_VLOG_LINES(2, module->ToString());
|
||||
|
||||
for (auto* computation : module->MakeComputationPostOrder()) {
|
||||
VLOG(3) << "Before dce:";
|
||||
XLA_VLOG_LINES(3, computation->ToString());
|
||||
// Remove any dead roots and their dead transitive operands. Collect them
|
||||
// into a separate list first to avoid problems with iterating through the
|
||||
// computation's instruction while simultaneously removing instructions.
|
||||
@ -62,6 +59,24 @@ StatusOr<bool> HloDCE::Run(HloModule* module) {
|
||||
computation->RemoveInstructionAndUnusedOperands(dead_root));
|
||||
changed = true;
|
||||
}
|
||||
if (changed) {
|
||||
VLOG(3) << "After dce:";
|
||||
XLA_VLOG_LINES(3, computation->ToString());
|
||||
}
|
||||
return changed;
|
||||
}
|
||||
|
||||
StatusOr<bool> HloDCE::Run(HloModule* module) {
|
||||
bool changed = false;
|
||||
|
||||
VLOG(2) << "Before dce:";
|
||||
XLA_VLOG_LINES(2, module->ToString());
|
||||
|
||||
// Run DCE on each computation.
|
||||
for (auto* computation : module->MakeComputationPostOrder()) {
|
||||
TF_ASSIGN_OR_RETURN(bool changed_for_computation,
|
||||
RunOnComputation(computation));
|
||||
changed |= changed_for_computation;
|
||||
}
|
||||
|
||||
// Now DCE HloComputations. First, collect the computations that are
|
||||
|
@ -38,6 +38,9 @@ class HloDCE : public HloModulePass {
|
||||
~HloDCE() override {}
|
||||
absl::string_view name() const override { return "dce"; }
|
||||
|
||||
// Run DCE on a computation.
|
||||
static StatusOr<bool> RunOnComputation(HloComputation* computation);
|
||||
|
||||
// Run the pass on the given module. Returns whether the module was changed
|
||||
// (instructions were removed).
|
||||
StatusOr<bool> Run(HloModule* module) override;
|
||||
|
Loading…
x
Reference in New Issue
Block a user