From f191880d4fb9a75d1d820476ce7688870aae3d01 Mon Sep 17 00:00:00 2001 From: Yi Xu Date: Tue, 20 Dec 2022 21:00:21 +0800 Subject: [PATCH] Add comments --- taichi/analysis/gather_immutable_local_vars.cpp | 4 ++++ taichi/transforms/eliminate_immutable_local_vars.cpp | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/taichi/analysis/gather_immutable_local_vars.cpp b/taichi/analysis/gather_immutable_local_vars.cpp index 47393d80627c5..82234a87999af 100644 --- a/taichi/analysis/gather_immutable_local_vars.cpp +++ b/taichi/analysis/gather_immutable_local_vars.cpp @@ -5,6 +5,10 @@ namespace taichi::lang { +// The GatherImmutableLocalVars pass gathers all immutable local vars as input +// to the EliminateImmutableLocalVars pass. An immutable local var is an alloca +// which is stored only once (in the same block) and only loaded after that +// store. class GatherImmutableLocalVars : public BasicStmtVisitor { private: using BasicStmtVisitor::visit; diff --git a/taichi/transforms/eliminate_immutable_local_vars.cpp b/taichi/transforms/eliminate_immutable_local_vars.cpp index a4f727187fb3b..036e96459f574 100644 --- a/taichi/transforms/eliminate_immutable_local_vars.cpp +++ b/taichi/transforms/eliminate_immutable_local_vars.cpp @@ -6,12 +6,16 @@ namespace taichi::lang { +// The EliminateImmutableLocalVars pass eliminates all immutable local vars +// calculated from the GatherImmutableLocalVars pass. An immutable local var +// can be eliminated by forwarding the value of its only store to all loads +// after that store. See https://github.com/taichi-dev/taichi/pull/6926 for the +// background of this optimization. class EliminateImmutableLocalVars : public BasicStmtVisitor { private: using BasicStmtVisitor::visit; DelayedIRModifier modifier_; - std::unordered_set immutable_local_vars_; std::unordered_map immutable_local_var_to_value_;