#include"pypto/ir/transforms/utils/var_collectors.h"usingnamespacepypto::ir;// Single traversal gives defs, uses, and ordered defsvar_collectors::VarDefUseCollectorcollector;collector.VisitStmt(scope_body);// Inputs = uses not satisfied by local defsfor(constVar*use:collector.var_uses){if(!collector.var_defs.count(use)){// 'use' comes from the enclosing scope}}// SSA: find assign-only defs (excludes loop vars, iter_args)for(constVar*v:collector.var_assign_defs){// candidate for loop-carried state or escaping var}// Deterministic def ordering for rename mapsfor(constVar*def:collector.var_defs_ordered){rename_map[def]=next_name();}
VisitTypeExprFields(visitor, type) dispatches a visitor over all
expression fields in a type. CollectTypeVars(type) is a convenience
wrapper returning all Var pointers found. These operate on types
(not IR statements), so they remain free functions.
#include"pypto/ir/transforms/utils/memref_collectors.h"usingnamespacepypto::ir;// Collect all MemRefs with their memory spacesautomemrefs=memref_collectors::CollectMemRefsWithSpace(func->body_);// Collect non-DDR MemRefs (e.g., for tile.alloc emission)autonon_ddr=memref_collectors::CollectNonDDRMemRefsWithSpace(func->body_);// Multi-visit: collect from both params and bodymemref_collectors::MemRefWithSpaceCollectorcollector(/*skip_ddr=*/true);for(constauto¶m:func->params_)collector.VisitExpr(param);collector.VisitStmt(func->body_);// Results in collector.memrefs// Collect from expressions (works with both TensorType and TileType)autoexpr_memrefs=memref_collectors::CollectShapedTypeMemRefs(expr);// Raw base Ptr set for fast membership checks (unused alloc detection)autoused=memref_collectors::CollectUsedBasePtrs(func->body_);